The Open Framework for Building Agents
fix(eve): Update Linear `AgentSession` GQL schema (#849)
Ben Pankow1aa4ba3c1871
diff --git a/packages/eve/src/public/channels/linear/api.ts b/packages/eve/src/public/channels/linear/api.tsindex 8b1d7fd0a..66b5e5e08 100644--- a/packages/eve/src/public/channels/linear/api.ts+++ b/packages/eve/src/public/channels/linear/api.ts@@ -7,6 +7,20 @@ import { parseJsonObject, type JsonObject } from "#shared/json.js";export type LinearFetch = typeof fetch;+/** Shared Agent Session selection for the create-on-issue and create-on-comment mutations. */+const AGENT_SESSION_FIELDS = `+ fragment AgentSessionFields on AgentSession {+ id+ appUser { id }+ comment { id }+ creator { id }+ issue { id identifier title url }+ sourceComment { id }+ status+ url+ }+`;+/** Transport options for Linear GraphQL calls. */export interface LinearApiOptions {/** Defaults to `https://api.linear.app/graphql`. */@@ -62,7 +76,6 @@ export interface LinearAgentSessionRecord {url?: string;} | null;issueId?: string | null;- organizationId?: string;sourceCommentId?: string | null;status?: string;url?: string | null;@@ -212,19 +225,11 @@ export async function createLinearAgentSessionOnIssue(input: {agentSessionCreateOnIssue(input: $input) {successagentSession {- id- appUserId- commentId- creator { id }- issue { id identifier title url }- issueId- organizationId- sourceCommentId- status- url+ ...AgentSessionFields}}}+ ${AGENT_SESSION_FIELDS}`,queryName: "AgentSessionCreateOnIssue",variables: {@@ -260,19 +265,11 @@ export async function createLinearAgentSessionOnComment(input: {agentSessionCreateOnComment(input: $input) {successagentSession {- id- appUserId- commentId- creator { id }- issue { id identifier title url }- issueId- organizationId- sourceCommentId- status- url+ ...AgentSessionFields}}}+ ${AGENT_SESSION_FIELDS}`,queryName: "AgentSessionCreateOnComment",variables: {@@ -336,27 +333,35 @@ function normalizeAgentSessionRecord(value: unknown): LinearAgentSessionRecord {throw new Error("linearChannel: Linear Agent Session response was malformed.");}- const creator = isObject(value.creator) ? value.creator : undefined;const issue = normalizeIssue(value.issue);const record: LinearAgentSessionRecord = { id: value.id };- if (typeof value.appUserId === "string") record.appUserId = value.appUserId;- if (typeof value.commentId === "string" || value.commentId === null) {- record.commentId = value.commentId;- }- if (typeof creator?.id === "string" || creator === undefined) {- record.creatorId = typeof creator?.id === "string" ? creator.id : null;- }+ const appUserId = relationId(value.appUser);+ if (typeof appUserId === "string") record.appUserId = appUserId;+ const commentId = relationId(value.comment);+ if (commentId !== undefined) record.commentId = commentId;+ const creatorId = relationId(value.creator);+ if (creatorId !== undefined) record.creatorId = creatorId;if (issue !== undefined) record.issue = issue;- if (typeof value.issueId === "string" || value.issueId === null) record.issueId = value.issueId;- if (typeof value.organizationId === "string") record.organizationId = value.organizationId;- if (typeof value.sourceCommentId === "string" || value.sourceCommentId === null) {- record.sourceCommentId = value.sourceCommentId;- }+ const issueId = relationId(value.issue);+ if (issueId !== undefined) record.issueId = issueId;+ const sourceCommentId = relationId(value.sourceComment);+ if (sourceCommentId !== undefined) record.sourceCommentId = sourceCommentId;if (typeof value.status === "string") record.status = value.status;if (typeof value.url === "string" || value.url === null) record.url = value.url;return record;}+/**+ * Reads the `id` from a nested Linear relation selected as `{ id }`. Returns+ * `null` when the relation is present but null (Linear's representation of an+ * absent association), and `undefined` when the field was not returned.+ */+function relationId(value: unknown): string | null | undefined {+ if (value === null) return null;+ if (isObject(value) && typeof value.id === "string") return value.id;+ return undefined;+}+function normalizeAgentActivityRecord(value: unknown): LinearAgentActivityRecord | null {if (!isObject(value) || typeof value.id !== "string" || !isObject(value.content)) return null;diff --git a/packages/eve/src/public/channels/linear/linearChannel.test.ts b/packages/eve/src/public/channels/linear/linearChannel.test.tsindex d72bdd1c9..07ef7a91b 100644--- a/packages/eve/src/public/channels/linear/linearChannel.test.ts+++ b/packages/eve/src/public/channels/linear/linearChannel.test.ts@@ -470,8 +470,6 @@ describe("linearChannel default event handlers", () => {agentSession: {id: "agent_session_2",issue: { id: "issue_1", identifier: "EVE-123", title: "Linear work" },- issueId: "issue_1",- organizationId: "org_1",url: "https://linear.app/acme/agent-session/agent_session_2",},success: true,@@ -504,7 +502,7 @@ describe("linearChannel default event handlers", () => {agentSessionId: "agent_session_2",issueId: "issue_1",issueIdentifier: "EVE-123",- organizationId: "org_1",+ organizationId: null,}),});});diff --git a/packages/eve/src/public/channels/linear/linearChannel.ts b/packages/eve/src/public/channels/linear/linearChannel.tsindex 56b2cfaf6..6cbc2d7a9 100644--- a/packages/eve/src/public/channels/linear/linearChannel.ts+++ b/packages/eve/src/public/channels/linear/linearChannel.ts@@ -426,7 +426,8 @@ function stateFromAgentSession(issueIdentifier: session.issue?.identifier ?? null,issueTitle: session.issue?.title ?? null,issueUrl: session.issue?.url ?? null,- organizationId: session.organizationId ?? null,+ // Only the webhook session ref carries an organization id.+ organizationId: "organizationId" in session ? (session.organizationId ?? null) : null,pendingToolCallMessage: null,sourceCommentId: session.sourceCommentId ?? null,};