@averyyy/pi-ai 0.86.1-piclient.1 → 0.86.1-piclient.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import type { Context } from "../index.ts";
1
+ import type { TranscriptContext } from "../types.ts";
2
2
  import { type ChatThinking } from "./devin-thinking.ts";
3
3
  export interface ContentPart {
4
4
  type: "text" | "image";
@@ -29,5 +29,5 @@ export interface MappedChat {
29
29
  messages: ChatHistoryItem[];
30
30
  tools: ToolDef[];
31
31
  }
32
- export declare function mapContextToChat(context: Context, modelId?: string): MappedChat;
32
+ export declare function mapContextToChat(context: TranscriptContext, modelId?: string): MappedChat;
33
33
  //# sourceMappingURL=devin-context-map.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"devin-context-map.d.ts","sourceRoot":"","sources":["../../src/api/devin-context-map.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,OAAO,EAAiB,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,KAAK,YAAY,EAA2B,MAAM,qBAAqB,CAAC;AAEjF,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IACpC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpE,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IAC1B,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,KAAK,EAAE,OAAO,EAAE,CAAC;CACjB;AAgBD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAgE/E","sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Kashyab Ambarani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n*/\nimport type { Context, Message, Tool } from \"../index.ts\";\nimport { type ChatThinking, unpackThinkingSignature } from \"./devin-thinking.ts\";\n\nexport interface ContentPart {\n\ttype: \"text\" | \"image\";\n\ttext?: string;\n\tmimeType?: string;\n\tbase64Data?: string;\n}\n\nexport interface ChatHistoryItem {\n\trole: \"user\" | \"assistant\" | \"tool\";\n\tcontent: string | ContentPart[];\n\ttool_call_id?: string;\n\ttool_calls?: Array<{ id: string; name: string; arguments: string }>;\n\t/** Prior reasoning, replayed so the server can verify and continue it. */\n\tthinking?: ChatThinking;\n}\n\nexport interface ToolDef {\n\tname: string;\n\tdescription: string;\n\tparameters: unknown;\n}\n\nexport interface MappedChat {\n\t/** Goes into GetChatMessageRequest.prompt, the server's system slot. */\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools: ToolDef[];\n}\n\nfunction userContent(content: Message[\"content\"]): string | ContentPart[] {\n\tif (typeof content === \"string\") return content;\n\tif (!Array.isArray(content)) return \"\";\n\tconst parts: ContentPart[] = [];\n\tfor (const part of content) {\n\t\tif (!part || typeof part !== \"object\") continue;\n\t\tif (part.type === \"text\") parts.push({ type: \"text\", text: part.text });\n\t\tif (part.type === \"image\") {\n\t\t\tparts.push({ type: \"image\", mimeType: part.mimeType, base64Data: part.data });\n\t\t}\n\t}\n\treturn parts;\n}\n\nexport function mapContextToChat(context: Context, modelId?: string): MappedChat {\n\tconst messages: ChatHistoryItem[] = [];\n\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"user\") {\n\t\t\tmessages.push({ role: \"user\", content: userContent(message.content) });\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"assistant\") {\n\t\t\tconst texts: string[] = [];\n\t\t\tconst toolCalls: Array<{ id: string; name: string; arguments: string }> = [];\n\t\t\tlet thinking: ChatThinking | undefined;\n\t\t\tfor (const part of message.content) {\n\t\t\t\tif (part.type === \"text\") texts.push(part.text);\n\t\t\t\tif (part.type === \"toolCall\") {\n\t\t\t\t\ttoolCalls.push({\n\t\t\t\t\t\tid: part.id,\n\t\t\t\t\t\tname: part.name,\n\t\t\t\t\t\targuments: JSON.stringify(part.arguments ?? {}),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tpart.type === \"thinking\" &&\n\t\t\t\t\tmessage.provider === \"devin\" &&\n\t\t\t\t\tmessage.api === \"devin\" &&\n\t\t\t\t\t(!modelId || message.model === modelId)\n\t\t\t\t) {\n\t\t\t\t\tconst decoded = unpackThinkingSignature(part.thinkingSignature);\n\t\t\t\t\t// One thinking slot per message on the wire, and an unsigned trace is\n\t\t\t\t\t// not replayable — keep the newest block that the server can verify.\n\t\t\t\t\tif (decoded.signature) {\n\t\t\t\t\t\tthinking = {\n\t\t\t\t\t\t\ttext: part.thinking,\n\t\t\t\t\t\t\tsignature: decoded.signature,\n\t\t\t\t\t\t\tsignatureType: decoded.signatureType,\n\t\t\t\t\t\t\tredacted: part.redacted,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tmessages.push({\n\t\t\t\trole: \"assistant\",\n\t\t\t\tcontent: texts.join(\"\\n\"),\n\t\t\t\ttool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n\t\t\t\tthinking,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"toolResult\") {\n\t\t\tmessages.push({\n\t\t\t\trole: \"tool\",\n\t\t\t\tcontent: userContent(message.content),\n\t\t\t\ttool_call_id: message.toolCallId,\n\t\t\t});\n\t\t}\n\t}\n\n\tconst tools: ToolDef[] = (context.tools ?? []).map((tool: Tool) => ({\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters,\n\t}));\n\n\treturn { systemPrompt: context.systemPrompt || undefined, messages, tools };\n}\n"]}
1
+ {"version":3,"file":"devin-context-map.d.ts","sourceRoot":"","sources":["../../src/api/devin-context-map.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAiB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,EAAE,KAAK,YAAY,EAA2B,MAAM,qBAAqB,CAAC;AAEjF,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;IACpC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpE,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IAC1B,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,KAAK,EAAE,OAAO,EAAE,CAAC;CACjB;AAgBD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,UAAU,CAiEzF","sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Kashyab Ambarani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n*/\nimport type { Message, Tool, TranscriptContext } from \"../types.ts\";\nimport { getCurrentSystemPrompt, getCurrentTools } from \"../utils/transcript.ts\";\nimport { type ChatThinking, unpackThinkingSignature } from \"./devin-thinking.ts\";\n\nexport interface ContentPart {\n\ttype: \"text\" | \"image\";\n\ttext?: string;\n\tmimeType?: string;\n\tbase64Data?: string;\n}\n\nexport interface ChatHistoryItem {\n\trole: \"user\" | \"assistant\" | \"tool\";\n\tcontent: string | ContentPart[];\n\ttool_call_id?: string;\n\ttool_calls?: Array<{ id: string; name: string; arguments: string }>;\n\t/** Prior reasoning, replayed so the server can verify and continue it. */\n\tthinking?: ChatThinking;\n}\n\nexport interface ToolDef {\n\tname: string;\n\tdescription: string;\n\tparameters: unknown;\n}\n\nexport interface MappedChat {\n\t/** Goes into GetChatMessageRequest.prompt, the server's system slot. */\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools: ToolDef[];\n}\n\nfunction userContent(content: Message[\"content\"]): string | ContentPart[] {\n\tif (typeof content === \"string\") return content;\n\tif (!Array.isArray(content)) return \"\";\n\tconst parts: ContentPart[] = [];\n\tfor (const part of content) {\n\t\tif (!part || typeof part !== \"object\") continue;\n\t\tif (part.type === \"text\") parts.push({ type: \"text\", text: part.text });\n\t\tif (part.type === \"image\") {\n\t\t\tparts.push({ type: \"image\", mimeType: part.mimeType, base64Data: part.data });\n\t\t}\n\t}\n\treturn parts;\n}\n\nexport function mapContextToChat(context: TranscriptContext, modelId?: string): MappedChat {\n\tconst messages: ChatHistoryItem[] = [];\n\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"user\") {\n\t\t\tmessages.push({ role: \"user\", content: userContent(message.content) });\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"assistant\") {\n\t\t\tconst texts: string[] = [];\n\t\t\tconst toolCalls: Array<{ id: string; name: string; arguments: string }> = [];\n\t\t\tlet thinking: ChatThinking | undefined;\n\t\t\tfor (const part of message.content) {\n\t\t\t\tif (part.type === \"text\") texts.push(part.text);\n\t\t\t\tif (part.type === \"toolCall\") {\n\t\t\t\t\ttoolCalls.push({\n\t\t\t\t\t\tid: part.id,\n\t\t\t\t\t\tname: part.name,\n\t\t\t\t\t\targuments: JSON.stringify(part.arguments ?? {}),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tpart.type === \"thinking\" &&\n\t\t\t\t\tmessage.provider === \"devin\" &&\n\t\t\t\t\tmessage.api === \"devin\" &&\n\t\t\t\t\t(!modelId || message.model === modelId)\n\t\t\t\t) {\n\t\t\t\t\tconst decoded = unpackThinkingSignature(part.thinkingSignature);\n\t\t\t\t\t// One thinking slot per message on the wire, and an unsigned trace is\n\t\t\t\t\t// not replayable — keep the newest block that the server can verify.\n\t\t\t\t\tif (decoded.signature) {\n\t\t\t\t\t\tthinking = {\n\t\t\t\t\t\t\ttext: part.thinking,\n\t\t\t\t\t\t\tsignature: decoded.signature,\n\t\t\t\t\t\t\tsignatureType: decoded.signatureType,\n\t\t\t\t\t\t\tredacted: part.redacted,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tmessages.push({\n\t\t\t\trole: \"assistant\",\n\t\t\t\tcontent: texts.join(\"\\n\"),\n\t\t\t\ttool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n\t\t\t\tthinking,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"toolResult\") {\n\t\t\tmessages.push({\n\t\t\t\trole: \"tool\",\n\t\t\t\tcontent: userContent(message.content),\n\t\t\t\ttool_call_id: message.toolCallId,\n\t\t\t});\n\t\t}\n\t}\n\n\tconst tools: ToolDef[] = getCurrentTools(context.messages).map((tool: Tool) => ({\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters,\n\t}));\n\n\tconst systemPrompt = getCurrentSystemPrompt(context.messages);\n\treturn { systemPrompt: systemPrompt || undefined, messages, tools };\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { getCurrentSystemPrompt, getCurrentTools } from "../utils/transcript.js";
1
2
  import { unpackThinkingSignature } from "./devin-thinking.js";
2
3
  function userContent(content) {
3
4
  if (typeof content === "string")
@@ -70,11 +71,12 @@ export function mapContextToChat(context, modelId) {
70
71
  });
71
72
  }
72
73
  }
73
- const tools = (context.tools ?? []).map((tool) => ({
74
+ const tools = getCurrentTools(context.messages).map((tool) => ({
74
75
  name: tool.name,
75
76
  description: tool.description,
76
77
  parameters: tool.parameters,
77
78
  }));
78
- return { systemPrompt: context.systemPrompt || undefined, messages, tools };
79
+ const systemPrompt = getCurrentSystemPrompt(context.messages);
80
+ return { systemPrompt: systemPrompt || undefined, messages, tools };
79
81
  }
80
82
  //# sourceMappingURL=devin-context-map.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"devin-context-map.js","sourceRoot":"","sources":["../../src/api/devin-context-map.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAqB,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AA+BjF,SAAS,WAAW,CAAC,OAA2B,EAA0B;IACzE,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,MAAM,KAAK,GAAkB,EAAE,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;YAA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AAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAU,EAAE,EAAE,CAAC,CAAC;QACnE,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;KAC3B,CAAC,CAAC,CAAC;IAEJ,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAAA,CAC5E","sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Kashyab Ambarani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n*/\nimport type { Context, Message, Tool } from \"../index.ts\";\nimport { type ChatThinking, unpackThinkingSignature } from \"./devin-thinking.ts\";\n\nexport interface ContentPart {\n\ttype: \"text\" | \"image\";\n\ttext?: string;\n\tmimeType?: string;\n\tbase64Data?: string;\n}\n\nexport interface ChatHistoryItem {\n\trole: \"user\" | \"assistant\" | \"tool\";\n\tcontent: string | ContentPart[];\n\ttool_call_id?: string;\n\ttool_calls?: Array<{ id: string; name: string; arguments: string }>;\n\t/** Prior reasoning, replayed so the server can verify and continue it. */\n\tthinking?: ChatThinking;\n}\n\nexport interface ToolDef {\n\tname: string;\n\tdescription: string;\n\tparameters: unknown;\n}\n\nexport interface MappedChat {\n\t/** Goes into GetChatMessageRequest.prompt, the server's system slot. */\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools: ToolDef[];\n}\n\nfunction userContent(content: Message[\"content\"]): string | ContentPart[] {\n\tif (typeof content === \"string\") return content;\n\tif (!Array.isArray(content)) return \"\";\n\tconst parts: ContentPart[] = [];\n\tfor (const part of content) {\n\t\tif (!part || typeof part !== \"object\") continue;\n\t\tif (part.type === \"text\") parts.push({ type: \"text\", text: part.text });\n\t\tif (part.type === \"image\") {\n\t\t\tparts.push({ type: \"image\", mimeType: part.mimeType, base64Data: part.data });\n\t\t}\n\t}\n\treturn parts;\n}\n\nexport function mapContextToChat(context: Context, modelId?: string): MappedChat {\n\tconst messages: ChatHistoryItem[] = [];\n\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"user\") {\n\t\t\tmessages.push({ role: \"user\", content: userContent(message.content) });\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"assistant\") {\n\t\t\tconst texts: string[] = [];\n\t\t\tconst toolCalls: Array<{ id: string; name: string; arguments: string }> = [];\n\t\t\tlet thinking: ChatThinking | undefined;\n\t\t\tfor (const part of message.content) {\n\t\t\t\tif (part.type === \"text\") texts.push(part.text);\n\t\t\t\tif (part.type === \"toolCall\") {\n\t\t\t\t\ttoolCalls.push({\n\t\t\t\t\t\tid: part.id,\n\t\t\t\t\t\tname: part.name,\n\t\t\t\t\t\targuments: JSON.stringify(part.arguments ?? {}),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tpart.type === \"thinking\" &&\n\t\t\t\t\tmessage.provider === \"devin\" &&\n\t\t\t\t\tmessage.api === \"devin\" &&\n\t\t\t\t\t(!modelId || message.model === modelId)\n\t\t\t\t) {\n\t\t\t\t\tconst decoded = unpackThinkingSignature(part.thinkingSignature);\n\t\t\t\t\t// One thinking slot per message on the wire, and an unsigned trace is\n\t\t\t\t\t// not replayable — keep the newest block that the server can verify.\n\t\t\t\t\tif (decoded.signature) {\n\t\t\t\t\t\tthinking = {\n\t\t\t\t\t\t\ttext: part.thinking,\n\t\t\t\t\t\t\tsignature: decoded.signature,\n\t\t\t\t\t\t\tsignatureType: decoded.signatureType,\n\t\t\t\t\t\t\tredacted: part.redacted,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tmessages.push({\n\t\t\t\trole: \"assistant\",\n\t\t\t\tcontent: texts.join(\"\\n\"),\n\t\t\t\ttool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n\t\t\t\tthinking,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"toolResult\") {\n\t\t\tmessages.push({\n\t\t\t\trole: \"tool\",\n\t\t\t\tcontent: userContent(message.content),\n\t\t\t\ttool_call_id: message.toolCallId,\n\t\t\t});\n\t\t}\n\t}\n\n\tconst tools: ToolDef[] = (context.tools ?? []).map((tool: Tool) => ({\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters,\n\t}));\n\n\treturn { systemPrompt: context.systemPrompt || undefined, messages, tools };\n}\n"]}
1
+ {"version":3,"file":"devin-context-map.js","sourceRoot":"","sources":["../../src/api/devin-context-map.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAqB,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AA+BjF,SAAS,WAAW,CAAC,OAA2B,EAA0B;IACzE,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;IAChD,IAAI,CAAC,KAAK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,CAAC,IAAI,CAAC;gBACb,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC;gBACrC,YAAY,EAAE,OAAO,CAAC,UAAU;aAChC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;IAED,MAAM,KAAK,GAAc,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAAU,EAAE,EAAE,CAAC,CAAC;QAC/E,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;KAC3B,CAAC,CAAC,CAAC;IAEJ,MAAM,YAAY,GAAG,sBAAsB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9D,OAAO,EAAE,YAAY,EAAE,YAAY,IAAI,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAAA,CACpE","sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Kashyab Ambarani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n*/\nimport type { Message, Tool, TranscriptContext } from \"../types.ts\";\nimport { getCurrentSystemPrompt, getCurrentTools } from \"../utils/transcript.ts\";\nimport { type ChatThinking, unpackThinkingSignature } from \"./devin-thinking.ts\";\n\nexport interface ContentPart {\n\ttype: \"text\" | \"image\";\n\ttext?: string;\n\tmimeType?: string;\n\tbase64Data?: string;\n}\n\nexport interface ChatHistoryItem {\n\trole: \"user\" | \"assistant\" | \"tool\";\n\tcontent: string | ContentPart[];\n\ttool_call_id?: string;\n\ttool_calls?: Array<{ id: string; name: string; arguments: string }>;\n\t/** Prior reasoning, replayed so the server can verify and continue it. */\n\tthinking?: ChatThinking;\n}\n\nexport interface ToolDef {\n\tname: string;\n\tdescription: string;\n\tparameters: unknown;\n}\n\nexport interface MappedChat {\n\t/** Goes into GetChatMessageRequest.prompt, the server's system slot. */\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools: ToolDef[];\n}\n\nfunction userContent(content: Message[\"content\"]): string | ContentPart[] {\n\tif (typeof content === \"string\") return content;\n\tif (!Array.isArray(content)) return \"\";\n\tconst parts: ContentPart[] = [];\n\tfor (const part of content) {\n\t\tif (!part || typeof part !== \"object\") continue;\n\t\tif (part.type === \"text\") parts.push({ type: \"text\", text: part.text });\n\t\tif (part.type === \"image\") {\n\t\t\tparts.push({ type: \"image\", mimeType: part.mimeType, base64Data: part.data });\n\t\t}\n\t}\n\treturn parts;\n}\n\nexport function mapContextToChat(context: TranscriptContext, modelId?: string): MappedChat {\n\tconst messages: ChatHistoryItem[] = [];\n\n\tfor (const message of context.messages) {\n\t\tif (message.role === \"user\") {\n\t\t\tmessages.push({ role: \"user\", content: userContent(message.content) });\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"assistant\") {\n\t\t\tconst texts: string[] = [];\n\t\t\tconst toolCalls: Array<{ id: string; name: string; arguments: string }> = [];\n\t\t\tlet thinking: ChatThinking | undefined;\n\t\t\tfor (const part of message.content) {\n\t\t\t\tif (part.type === \"text\") texts.push(part.text);\n\t\t\t\tif (part.type === \"toolCall\") {\n\t\t\t\t\ttoolCalls.push({\n\t\t\t\t\t\tid: part.id,\n\t\t\t\t\t\tname: part.name,\n\t\t\t\t\t\targuments: JSON.stringify(part.arguments ?? {}),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tpart.type === \"thinking\" &&\n\t\t\t\t\tmessage.provider === \"devin\" &&\n\t\t\t\t\tmessage.api === \"devin\" &&\n\t\t\t\t\t(!modelId || message.model === modelId)\n\t\t\t\t) {\n\t\t\t\t\tconst decoded = unpackThinkingSignature(part.thinkingSignature);\n\t\t\t\t\t// One thinking slot per message on the wire, and an unsigned trace is\n\t\t\t\t\t// not replayable — keep the newest block that the server can verify.\n\t\t\t\t\tif (decoded.signature) {\n\t\t\t\t\t\tthinking = {\n\t\t\t\t\t\t\ttext: part.thinking,\n\t\t\t\t\t\t\tsignature: decoded.signature,\n\t\t\t\t\t\t\tsignatureType: decoded.signatureType,\n\t\t\t\t\t\t\tredacted: part.redacted,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tmessages.push({\n\t\t\t\trole: \"assistant\",\n\t\t\t\tcontent: texts.join(\"\\n\"),\n\t\t\t\ttool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n\t\t\t\tthinking,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tif (message.role === \"toolResult\") {\n\t\t\tmessages.push({\n\t\t\t\trole: \"tool\",\n\t\t\t\tcontent: userContent(message.content),\n\t\t\t\ttool_call_id: message.toolCallId,\n\t\t\t});\n\t\t}\n\t}\n\n\tconst tools: ToolDef[] = getCurrentTools(context.messages).map((tool: Tool) => ({\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters,\n\t}));\n\n\tconst systemPrompt = getCurrentSystemPrompt(context.messages);\n\treturn { systemPrompt: systemPrompt || undefined, messages, tools };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { type Api, type AssistantMessageEventStream, type Context, type Model, type SimpleStreamOptions } from "../index.ts";
1
+ import { type Api, type AssistantMessageEventStream, type Model, type SimpleStreamOptions, type TranscriptContext } from "../index.ts";
2
2
  export type CloudChatEvent = {
3
3
  kind: "text";
4
4
  text: string;
@@ -29,5 +29,5 @@ export type CloudChatEvent = {
29
29
  cachedInputTokens?: number;
30
30
  cacheCreationInputTokens?: number;
31
31
  };
32
- export declare function streamDevin(model: Model<Api>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;
32
+ export declare function streamDevin(model: Model<Api>, context: TranscriptContext, options?: SimpleStreamOptions): AssistantMessageEventStream;
33
33
  //# sourceMappingURL=devin-stream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"devin-stream.d.ts","sourceRoot":"","sources":["../../src/api/devin-stream.ts"],"names":[],"mappings":"AA0BA,OAAO,EACN,KAAK,GAAG,EAER,KAAK,2BAA2B,EAChC,KAAK,OAAO,EAGZ,KAAK,KAAK,EACV,KAAK,mBAAmB,EACxB,MAAM,aAAa,CAAC;AAqBrB,MAAM,MAAM,cAAc,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,QAAQ,GAAG,gBAAgB,CAAA;CAAE,GAC/E;IACA,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC;AAgXL,wBAAgB,WAAW,CAC1B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,2BAA2B,CA+N7B","sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Kashyab Ambarani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n*/\nimport { randomUUID } from \"node:crypto\";\nimport * as zlib from \"node:zlib\";\nimport {\n\ttype Api,\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tcreateAssistantMessageEventStream,\n\ttype JsonObject,\n\ttype Model,\n\ttype SimpleStreamOptions,\n} from \"../index.ts\";\nimport { type ChatHistoryItem, type ContentPart, mapContextToChat, type ToolDef } from \"./devin-context-map.ts\";\nimport { mintUserJwt } from \"./devin-jwt.ts\";\nimport { buildMetadata } from \"./devin-metadata.ts\";\n\nimport { type ChatThinking, packThinkingSignature, unpackThinkingSignature } from \"./devin-thinking.ts\";\nimport {\n\tencodeFixed64Field,\n\tencodeMessage,\n\tencodeString,\n\tencodeVarintField,\n\tframeConnectStream,\n\titerFields,\n} from \"./devin-wire.ts\";\n\nconst SOURCE_BY_ROLE: Record<string, number> = {\n\tuser: 1,\n\tassistant: 2,\n\ttool: 4,\n};\n\nexport type CloudChatEvent =\n\t| { kind: \"text\"; text: string }\n\t| { kind: \"reasoning\"; text: string }\n\t| { kind: \"reasoning_signature\"; signature: string; signatureType?: string }\n\t| { kind: \"reasoning_redacted\" }\n\t| { kind: \"tool_call_start\"; id: string; name: string }\n\t| { kind: \"tool_call_args\"; argsDelta: string; id?: string }\n\t| { kind: \"finish\"; reason: \"stop\" | \"tool_calls\" | \"length\" | \"content_filter\" }\n\t| {\n\t\t\tkind: \"usage\";\n\t\t\tpromptTokens?: number;\n\t\t\tcompletionTokens?: number;\n\t\t\tcachedInputTokens?: number;\n\t\t\tcacheCreationInputTokens?: number;\n\t };\n\nfunction normalizeContent(content: string | ContentPart[]): ContentPart[] {\n\tif (typeof content === \"string\") return [{ type: \"text\", text: content }];\n\treturn content;\n}\n\nfunction encodeImageData(img: { mimeType?: string; base64Data?: string }): Buffer {\n\treturn Buffer.concat([encodeString(1, img.base64Data ?? \"\"), encodeString(2, img.mimeType ?? \"image/png\")]);\n}\n\nfunction encodeChatToolCall(tc: { id: string; name: string; arguments: string }): Buffer {\n\treturn Buffer.concat([encodeString(1, tc.id), encodeString(2, tc.name), encodeString(3, tc.arguments)]);\n}\n\nfunction encodeChatMessagePrompt(\n\tcontent: ContentPart[],\n\tsource: number,\n\topts?: {\n\t\ttoolCallId?: string;\n\t\ttoolCalls?: Array<{ id: string; name: string; arguments: string }>;\n\t\tthinking?: ChatThinking;\n\t},\n): Buffer {\n\tconst text = content\n\t\t.filter((part) => part.type === \"text\")\n\t\t.map((part) => part.text ?? \"\")\n\t\t.join(\"\\n\");\n\tconst parts: Buffer[] = [encodeVarintField(2, source), encodeString(3, text), encodeVarintField(5, 1)];\n\tif (opts?.toolCallId) parts.push(encodeString(7, opts.toolCallId));\n\tfor (const tc of opts?.toolCalls ?? []) parts.push(encodeMessage(6, encodeChatToolCall(tc)));\n\tfor (const img of content.filter((part) => part.type === \"image\")) {\n\t\tparts.push(encodeMessage(10, encodeImageData(img)));\n\t}\n\t// 11 thinking / 12 signature / 13 thinking_redacted / 18 signature_type — the\n\t// same quartet the Devin CLI replays so the model keeps its own reasoning.\n\tif (opts?.thinking) {\n\t\tparts.push(encodeString(11, opts.thinking.text));\n\t\tparts.push(encodeString(12, opts.thinking.signature));\n\t\tif (opts.thinking.redacted) parts.push(encodeVarintField(13, 1));\n\t\tif (opts.thinking.signatureType) parts.push(encodeString(18, opts.thinking.signatureType));\n\t}\n\treturn Buffer.concat(parts);\n}\n\n/** Mirrors the Devin CLI: num_completions / max_tokens / max_newlines plus\n * temperature / top_k / top_p, and nothing else. */\nfunction encodeCompletionConfiguration(maxOutputTokens?: number, temperature?: number): Buffer {\n\treturn Buffer.concat([\n\t\tencodeVarintField(1, 1),\n\t\tencodeVarintField(2, maxOutputTokens ?? 128_000),\n\t\tencodeVarintField(3, 400),\n\t\tencodeFixed64Field(5, temperature ?? 1.0),\n\t\tencodeVarintField(7, 40),\n\t\tencodeFixed64Field(8, 0.95),\n\t]);\n}\n\n/** CortexTrajectoryReference: cascade trajectory, user-input step. */\nfunction encodeTrajectoryReference(trajectoryId: string): Buffer {\n\treturn Buffer.concat([encodeString(1, trajectoryId), encodeVarintField(3, 4), encodeVarintField(4, 14)]);\n}\n\nfunction encodeToolDef(tool: ToolDef): Buffer {\n\tconst description = tool.description;\n\treturn Buffer.concat([\n\t\tencodeString(1, tool.name),\n\t\tencodeString(2, description),\n\t\tencodeString(3, JSON.stringify(tool.parameters ?? {})),\n\t]);\n}\n\nfunction buildGetChatMessageRequest(args: {\n\tapiKey: string;\n\tuserJwt: string;\n\tmodelUid: string;\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools?: ToolDef[];\n\tcascadeId: string;\n\ttrajectoryId: string;\n\tsessionId: string;\n\trequestId: bigint;\n\ttriggerId: string;\n\tmaxOutputTokens?: number;\n\ttemperature?: number;\n}): Buffer {\n\tconst metadata = buildMetadata({\n\t\tapiKey: args.apiKey,\n\t\tuserJwt: args.userJwt,\n\t\tsessionId: args.sessionId,\n\t\trequestId: args.requestId,\n\t\ttriggerId: args.triggerId,\n\t});\n\tconst prompts = args.messages.map((message) =>\n\t\tencodeMessage(\n\t\t\t3,\n\t\t\tencodeChatMessagePrompt(normalizeContent(message.content), SOURCE_BY_ROLE[message.role], {\n\t\t\t\ttoolCallId: message.role === \"tool\" ? message.tool_call_id : undefined,\n\t\t\t\ttoolCalls: message.role === \"assistant\" ? message.tool_calls : undefined,\n\t\t\t\tthinking: message.role === \"assistant\" ? message.thinking : undefined,\n\t\t\t}),\n\t\t),\n\t);\n\treturn Buffer.concat([\n\t\tencodeMessage(1, metadata),\n\t\t// 2 prompt — the server's system slot, same place the Devin CLI puts its own\n\t\t// system prompt. Collapsing it into the first user turn is not equivalent.\n\t\t...(args.systemPrompt ? [encodeString(2, args.systemPrompt)] : []),\n\t\t...prompts,\n\t\tencodeVarintField(7, 5),\n\t\tencodeMessage(8, encodeCompletionConfiguration(args.maxOutputTokens, args.temperature)),\n\t\t...(args.tools ?? []).map((tool) => encodeMessage(10, encodeToolDef(tool))),\n\t\tencodeMessage(15, encodeTrajectoryReference(args.trajectoryId)),\n\t\tencodeString(16, args.cascadeId),\n\t\tencodeVarintField(20, 1),\n\t\tencodeString(21, args.modelUid),\n\t]);\n}\n\nfunction* decodeChatFrame(proto: Buffer): Generator<CloudChatEvent> {\n\tlet signature: string | undefined;\n\tlet signatureType: string | undefined;\n\tfor (const field of iterFields(proto)) {\n\t\tif (field.num === 3 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) yield { kind: \"text\", text };\n\t\t} else if (field.num === 9 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) yield { kind: \"reasoning\", text };\n\t\t} else if (field.num === 11 && field.wire === 0) {\n\t\t\t// GetChatMessageResponse.thinking_redacted\n\t\t\tif (Number(field.value) !== 0) yield { kind: \"reasoning_redacted\" };\n\t\t} else if (field.num === 10 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) signature = text;\n\t\t} else if (field.num === 21 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) signatureType = text;\n\t\t} else if (field.num === 6 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tlet id: string | undefined;\n\t\t\tlet name: string | undefined;\n\t\t\tlet argsDelta: string | undefined;\n\t\t\tfor (const inner of iterFields(field.value)) {\n\t\t\t\tif (inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\t\tconst text = inner.value.toString(\"utf8\");\n\t\t\t\t\tif (inner.num === 1) id = text;\n\t\t\t\t\telse if (inner.num === 2) name = text;\n\t\t\t\t\telse if (inner.num === 3) argsDelta = text;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (id !== undefined && name !== undefined) yield { kind: \"tool_call_start\", id, name };\n\t\t\tif (argsDelta !== undefined) yield { kind: \"tool_call_args\", argsDelta, ...(id ? { id } : {}) };\n\t\t} else if (field.num === 5 && field.wire === 0) {\n\t\t\tconst value = Number(field.value);\n\t\t\tlet reason: Extract<CloudChatEvent, { kind: \"finish\" }>[\"reason\"] = \"stop\";\n\t\t\tif (value === 10) reason = \"tool_calls\";\n\t\t\telse if (value === 11) reason = \"content_filter\";\n\t\t\telse if ([1, 3, 5, 9].includes(value)) reason = \"length\";\n\t\t\telse if (![0, 2, 4, 6, 8, 12].includes(value)) throw new Error(`Devin returned failure stop reason ${value}`);\n\t\t\tyield { kind: \"finish\", reason };\n\t\t} else if (field.num === 28 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst usage = decodeUsage(field.value);\n\t\t\tif (usage) yield usage;\n\t\t}\n\t}\n\t// The signature trails the thinking text, so it is yielded once the frame is\n\t// fully read and gets attached to the block that is already closed.\n\tif (signature !== undefined || signatureType !== undefined)\n\t\tyield { kind: \"reasoning_signature\", signature: signature ?? \"\", signatureType };\n}\n\nfunction decodeUsage(buf: Buffer): CloudChatEvent | null {\n\tlet promptTokens: number | undefined;\n\tlet completionTokens: number | undefined;\n\tlet cachedInputTokens: number | undefined;\n\tlet cacheCreationInputTokens: number | undefined;\n\tfor (const field of iterFields(buf)) {\n\t\tif (field.num !== 2 || field.wire !== 2 || !Buffer.isBuffer(field.value)) continue;\n\t\tlet metric: string | undefined;\n\t\tlet value: number | undefined;\n\t\tfor (const inner of iterFields(field.value)) {\n\t\t\tif (inner.num === 5 && inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\tmetric = inner.value.toString(\"utf8\");\n\t\t\t} else if (inner.num === 4 && inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\t// Protobuf omits the scalar field when a present numeric metric is zero.\n\t\t\t\tvalue = 0;\n\t\t\t\tfor (const dim of iterFields(inner.value)) {\n\t\t\t\t\tif (dim.num === 2 && dim.wire === 5 && Buffer.isBuffer(dim.value)) {\n\t\t\t\t\t\tvalue = dim.value.readFloatLE(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!metric || value === undefined || !Number.isFinite(value)) continue;\n\t\tconst n = Math.round(value);\n\t\tif (metric === \"input_tokens\") promptTokens = n;\n\t\telse if (metric === \"output_tokens\") completionTokens = n;\n\t\telse if (metric === \"cached_input_tokens\" || metric === \"cache_read_input_tokens\") cachedInputTokens = n;\n\t\telse if (metric === \"cache_creation_input_tokens\") cacheCreationInputTokens = n;\n\t}\n\tif (\n\t\tpromptTokens === undefined &&\n\t\tcompletionTokens === undefined &&\n\t\tcachedInputTokens === undefined &&\n\t\tcacheCreationInputTokens === undefined\n\t)\n\t\treturn null;\n\treturn {\n\t\tkind: \"usage\",\n\t\tpromptTokens,\n\t\tcompletionTokens,\n\t\tcachedInputTokens,\n\t\tcacheCreationInputTokens,\n\t};\n}\n\nasync function* streamChatEvents(args: {\n\tapiKey: string;\n\thost: string;\n\tmodelUid: string;\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools?: ToolDef[];\n\tmaxOutputTokens?: number;\n\tsignal?: AbortSignal;\n\tsessionId?: string;\n\tfetchImpl: typeof fetch;\n\ttemperature?: number;\n}): AsyncGenerator<CloudChatEvent> {\n\tconst host = args.host.replace(/\\/$/, \"\");\n\tconst userJwt = await mintUserJwt(args.apiKey, host, args.signal, args.fetchImpl);\n\tconst sessionId = args.sessionId ?? randomUUID();\n\tconst ids = { sessionId, cascadeId: sessionId, trajectoryId: sessionId };\n\tconst proto = buildGetChatMessageRequest({\n\t\tapiKey: args.apiKey,\n\t\tuserJwt,\n\t\tmodelUid: args.modelUid,\n\t\tsystemPrompt: args.systemPrompt,\n\t\tmessages: args.messages,\n\t\ttools: args.tools,\n\t\tcascadeId: ids.cascadeId,\n\t\ttrajectoryId: ids.trajectoryId,\n\t\tsessionId: ids.sessionId,\n\t\trequestId: BigInt(Date.now()),\n\t\ttriggerId: randomUUID(),\n\t\tmaxOutputTokens: args.maxOutputTokens,\n\t\ttemperature: args.temperature,\n\t});\n\n\tconst resp = await args.fetchImpl(`${host}/exa.api_server_pb.ApiServerService/GetChatMessage`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/connect+proto\",\n\t\t\t\"Connect-Protocol-Version\": \"1\",\n\t\t\t\"Connect-Content-Encoding\": \"gzip\",\n\t\t\t\"Connect-Accept-Encoding\": \"gzip\",\n\t\t},\n\t\tbody: new Uint8Array(frameConnectStream(proto, true)),\n\t\tsignal: args.signal,\n\t});\n\tif (!resp.ok) {\n\t\tthrow new Error(`Devin GetChatMessage failed (HTTP ${resp.status})`);\n\t}\n\tif (!resp.body) throw new Error(\"GetChatMessage returned an empty body\");\n\n\tconst reader = resp.body.getReader();\n\t// reader.closed rejects with the stream's storedError when the socket dies\n\t// mid-response; nothing awaits it -> unhandledRejection crashes the process.\n\tvoid reader.closed.catch(() => {});\n\tconst queue: Buffer[] = [];\n\tlet queued = 0;\n\tlet sawEos = false;\n\tlet trailerError: string | null = null;\n\n\tconst peek = (n: number): Buffer | null => {\n\t\tif (queued < n) return null;\n\t\tif (queue.length === 1 && queue[0].length >= n) return queue[0].subarray(0, n);\n\t\tconst parts: Buffer[] = [];\n\t\tlet remaining = n;\n\t\tfor (const chunk of queue) {\n\t\t\tif (remaining <= 0) break;\n\t\t\tif (chunk.length <= remaining) {\n\t\t\t\tparts.push(chunk);\n\t\t\t\tremaining -= chunk.length;\n\t\t\t} else {\n\t\t\t\tparts.push(chunk.subarray(0, remaining));\n\t\t\t\tremaining = 0;\n\t\t\t}\n\t\t}\n\t\treturn Buffer.concat(parts, n);\n\t};\n\n\tconst drop = (n: number): void => {\n\t\tqueued -= n;\n\t\tlet remaining = n;\n\t\twhile (remaining > 0 && queue.length > 0) {\n\t\t\tconst head = queue[0];\n\t\t\tif (head.length <= remaining) {\n\t\t\t\tqueue.shift();\n\t\t\t\tremaining -= head.length;\n\t\t\t} else {\n\t\t\t\tqueue[0] = head.subarray(remaining);\n\t\t\t\tremaining = 0;\n\t\t\t}\n\t\t}\n\t};\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { value, done } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tif (value) {\n\t\t\t\tqueue.push(Buffer.from(value));\n\t\t\t\tqueued += value.length;\n\t\t\t}\n\t\t\twhile (queued >= 5) {\n\t\t\t\tconst header = peek(5);\n\t\t\t\tif (!header) break;\n\t\t\t\tconst flags = header[0];\n\t\t\t\tconst len = header.readUInt32BE(1);\n\t\t\t\tif (flags & ~3) throw new Error(\"Invalid Devin Connect frame flags\");\n\t\t\t\tif (len > 16 * 1024 * 1024) throw new Error(\"Devin Connect frame exceeds 16 MiB\");\n\t\t\t\tif (queued < 5 + len) break;\n\t\t\t\tdrop(5);\n\t\t\t\tconst raw = peek(len) ?? Buffer.alloc(0);\n\t\t\t\tdrop(len);\n\t\t\t\tlet payload = raw;\n\t\t\t\tif (flags & 0x01) payload = zlib.gunzipSync(raw, { maxOutputLength: 16 * 1024 * 1024 });\n\t\t\t\tif (sawEos) throw new Error(\"Devin returned data after its EOS trailer\");\n\t\t\t\tif (flags & 0x02) {\n\t\t\t\t\tsawEos = true;\n\t\t\t\t\tconst parsed = JSON.parse(payload.toString(\"utf8\")) as { error?: { code?: string; message?: string } };\n\t\t\t\t\tif (parsed.error) {\n\t\t\t\t\t\tconst detail =\n\t\t\t\t\t\t\ttypeof parsed.error.message === \"string\"\n\t\t\t\t\t\t\t\t? parsed.error.message\n\t\t\t\t\t\t\t\t\t\t.replaceAll(args.apiKey, \"[redacted]\")\n\t\t\t\t\t\t\t\t\t\t.replaceAll(userJwt, \"[redacted]\")\n\t\t\t\t\t\t\t\t\t\t.slice(0, 500)\n\t\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\ttrailerError = `Devin stream failed (${parsed.error.code ?? \"unknown\"})${detail ? `: ${detail}` : \"\"}`;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tyield* decodeChatFrame(payload);\n\t\t\t}\n\t\t}\n\t} finally {\n\t\ttry {\n\t\t\treader.releaseLock();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t\ttry {\n\t\t\t// await: on an errored stream cancel() returns a rejected promise;\n\t\t\t// `void`-ing it escapes the try/catch as an unhandled rejection.\n\t\t\tawait resp.body?.cancel();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tif (trailerError) throw new Error(trailerError);\n\tif (queued) throw new Error(\"Truncated Devin Connect frame\");\n\tif (!sawEos) throw new Error(\"Devin stream ended without an EOS trailer\");\n}\n\nexport function streamDevin(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\n\tvoid (async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: model.api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\tlet textOpen = false;\n\t\tlet thinkingOpen = false;\n\t\tlet thinkingIndex = -1;\n\t\tlet toolId = \"\";\n\t\tconst toolStates = new Map<string, { index: number; json: string }>();\n\n\t\tconst closeText = () => {\n\t\t\tif (!textOpen) return;\n\t\t\tconst idx = output.content.length - 1;\n\t\t\tconst block = output.content[idx];\n\t\t\tif (block.type === \"text\") {\n\t\t\t\tstream.push({ type: \"text_end\", contentIndex: idx, content: block.text, partial: output });\n\t\t\t}\n\t\t\ttextOpen = false;\n\t\t};\n\t\tconst closeThinking = () => {\n\t\t\tif (!thinkingOpen) return;\n\t\t\tconst idx = output.content.length - 1;\n\t\t\tconst block = output.content[idx];\n\t\t\tif (block.type === \"thinking\") {\n\t\t\t\tstream.push({ type: \"thinking_end\", contentIndex: idx, content: block.thinking, partial: output });\n\t\t\t}\n\t\t\tthinkingOpen = false;\n\t\t};\n\t\tconst closeTool = () => {\n\t\t\tfor (const state of toolStates.values()) {\n\t\t\t\tconst block = output.content[state.index];\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\tconst parsed: unknown = JSON.parse(state.json);\n\t\t\t\t\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed))\n\t\t\t\t\t\tthrow new Error(\"Invalid Devin tool arguments\");\n\t\t\t\t\tblock.arguments = parsed as JsonObject;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\t\tcontentIndex: state.index,\n\t\t\t\t\t\ttoolCall: block,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoolStates.clear();\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (process.env.PI_SERVER_MODE === \"true\")\n\t\t\t\tthrow new Error(\"Devin inference must use pi-server in PI_SERVER_MODE\");\n\t\t\tif (!apiKey) throw new Error(\"No Devin credentials. Run /login devin.\");\n\t\t\tconst host = model.baseUrl.replace(/\\/$/, \"\");\n\t\t\tif (options?.reasoning && model.thinkingLevelMap && model.thinkingLevelMap[options.reasoning] !== model.id)\n\t\t\t\tthrow new Error(\"Select the Devin model variant for the requested reasoning effort\");\n\t\t\tif (options?.onPayload) throw new Error(\"Devin does not support onPayload overrides\");\n\t\t\tconst modelUid = model.id;\n\t\t\tconst mapped = mapContextToChat(context, model.id);\n\t\t\tstream.push({ type: \"start\", partial: output });\n\n\t\t\tfor await (const event of streamChatEvents({\n\t\t\t\tapiKey,\n\t\t\t\thost,\n\t\t\t\tmodelUid,\n\t\t\t\tsystemPrompt: mapped.systemPrompt,\n\t\t\t\tmessages: mapped.messages,\n\t\t\t\ttools: mapped.tools.length > 0 ? mapped.tools : undefined,\n\t\t\t\tmaxOutputTokens: options?.maxTokens ?? model.maxTokens,\n\t\t\t\tsignal: options?.signal\n\t\t\t\t\t? AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs ?? 600_000)])\n\t\t\t\t\t: AbortSignal.timeout(options?.timeoutMs ?? 600_000),\n\t\t\t\tsessionId: options?.sessionId,\n\t\t\t\tfetchImpl: options?.fetch ?? fetch,\n\t\t\t\ttemperature: options?.temperature,\n\t\t\t})) {\n\t\t\t\tif (event.kind === \"text\") {\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\tif (!textOpen) {\n\t\t\t\t\t\toutput.content.push({ type: \"text\", text: \"\" });\n\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t\t\t\ttextOpen = true;\n\t\t\t\t\t}\n\t\t\t\t\tconst idx = output.content.length - 1;\n\t\t\t\t\tconst block = output.content[idx];\n\t\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\t\tblock.text += event.text;\n\t\t\t\t\t\tstream.push({ type: \"text_delta\", contentIndex: idx, delta: event.text, partial: output });\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning\") {\n\t\t\t\t\tcloseText();\n\t\t\t\t\tif (!thinkingOpen) {\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t}\n\t\t\t\t\tconst idx = output.content.length - 1;\n\t\t\t\t\tconst block = output.content[idx];\n\t\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\t\tblock.thinking += event.text;\n\t\t\t\t\t\tstream.push({ type: \"thinking_delta\", contentIndex: idx, delta: event.text, partial: output });\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning_signature\") {\n\t\t\t\t\tif (thinkingIndex < 0) {\n\t\t\t\t\t\tcloseText();\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: thinkingIndex, partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tconst block = output.content[thinkingIndex];\n\t\t\t\t\tif (block?.type === \"thinking\") {\n\t\t\t\t\t\tconst previous = unpackThinkingSignature(block.thinkingSignature);\n\t\t\t\t\t\tblock.thinkingSignature = packThinkingSignature(\n\t\t\t\t\t\t\t(previous.signature ?? \"\") + event.signature,\n\t\t\t\t\t\t\tevent.signatureType ?? previous.signatureType,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning_redacted\") {\n\t\t\t\t\tif (thinkingIndex < 0) {\n\t\t\t\t\t\tcloseText();\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: thinkingIndex, partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tconst block = thinkingIndex >= 0 ? output.content[thinkingIndex] : undefined;\n\t\t\t\t\tif (block?.type === \"thinking\") block.redacted = true;\n\t\t\t\t} else if (event.kind === \"tool_call_start\") {\n\t\t\t\t\tcloseText();\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\ttoolId = event.id;\n\t\t\t\t\tconst existing = toolStates.get(toolId);\n\t\t\t\t\tif (existing) {\n\t\t\t\t\t\tconst block = output.content[existing.index];\n\t\t\t\t\t\tif (block.type !== \"toolCall\" || block.name !== event.name)\n\t\t\t\t\t\t\tthrow new Error(\"Devin changed a tool call's name\");\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (!toolId || !event.name) throw new Error(\"Devin returned an empty tool identity\");\n\t\t\t\t\toutput.content.push({ type: \"toolCall\", id: event.id, name: event.name, arguments: {} });\n\t\t\t\t\tconst toolIndex = output.content.length - 1;\n\t\t\t\t\ttoolStates.set(toolId, { index: toolIndex, json: \"\" });\n\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: toolIndex, partial: output });\n\t\t\t\t} else if (event.kind === \"tool_call_args\") {\n\t\t\t\t\tconst state = toolStates.get(event.id ?? toolId);\n\t\t\t\t\tif (!state) throw new Error(\"Devin tool argument delta has no matching call\");\n\t\t\t\t\tstate.json += event.argsDelta;\n\t\t\t\t\tconst block = output.content[state.index];\n\t\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tblock.arguments = JSON.parse(state.json);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// incomplete json\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\tcontentIndex: state.index,\n\t\t\t\t\t\tdelta: event.argsDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else if (event.kind === \"finish\") {\n\t\t\t\t\tif (event.reason === \"content_filter\")\n\t\t\t\t\t\tthrow new Error(\"Devin response was blocked by content filtering\");\n\t\t\t\t\tcloseText();\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\toutput.stopReason =\n\t\t\t\t\t\tevent.reason === \"tool_calls\" ? \"toolUse\" : event.reason === \"length\" ? \"length\" : \"stop\";\n\t\t\t\t} else if (event.kind === \"usage\") {\n\t\t\t\t\t// Metrics are reported counts, not deltas. Absent fields retain earlier reports.\n\t\t\t\t\tif (event.promptTokens !== undefined) output.usage.input = event.promptTokens;\n\t\t\t\t\tif (event.completionTokens !== undefined) output.usage.output = event.completionTokens;\n\t\t\t\t\tif (event.cachedInputTokens !== undefined) output.usage.cacheRead = event.cachedInputTokens;\n\t\t\t\t\tif (event.cacheCreationInputTokens !== undefined)\n\t\t\t\t\t\toutput.usage.cacheWrite = event.cacheCreationInputTokens;\n\t\t\t\t\toutput.usage.totalTokens =\n\t\t\t\t\t\toutput.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcloseText();\n\t\t\tcloseThinking();\n\t\t\tcloseTool();\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tif (!output.content.length) throw new Error(\"Devin returned an empty completion\");\n\t\t\tfor (const key of [\"input\", \"output\", \"cacheRead\", \"cacheWrite\"] as const) {\n\t\t\t\toutput.usage.cost[key] = (output.usage[key] * model.cost[key]) / 1_000_000;\n\t\t\t}\n\t\t\toutput.usage.cost.total =\n\t\t\t\toutput.usage.cost.input +\n\t\t\t\toutput.usage.cost.output +\n\t\t\t\toutput.usage.cost.cacheRead +\n\t\t\t\toutput.usage.cost.cacheWrite;\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason as \"stop\" | \"length\" | \"toolUse\", message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : String(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason as \"aborted\" | \"error\", error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n}\n"]}
1
+ {"version":3,"file":"devin-stream.d.ts","sourceRoot":"","sources":["../../src/api/devin-stream.ts"],"names":[],"mappings":"AA0BA,OAAO,EACN,KAAK,GAAG,EAER,KAAK,2BAA2B,EAGhC,KAAK,KAAK,EACV,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,MAAM,aAAa,CAAC;AAqBrB,MAAM,MAAM,cAAc,GACvB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1E;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,QAAQ,GAAG,gBAAgB,CAAA;CAAE,GAC/E;IACA,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC;AAgXL,wBAAgB,WAAW,CAC1B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,CAAC,EAAE,mBAAmB,GAC3B,2BAA2B,CA+N7B","sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Kashyab Ambarani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n*/\nimport { randomUUID } from \"node:crypto\";\nimport * as zlib from \"node:zlib\";\nimport {\n\ttype Api,\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\tcreateAssistantMessageEventStream,\n\ttype JsonObject,\n\ttype Model,\n\ttype SimpleStreamOptions,\n\ttype TranscriptContext,\n} from \"../index.ts\";\nimport { type ChatHistoryItem, type ContentPart, mapContextToChat, type ToolDef } from \"./devin-context-map.ts\";\nimport { mintUserJwt } from \"./devin-jwt.ts\";\nimport { buildMetadata } from \"./devin-metadata.ts\";\n\nimport { type ChatThinking, packThinkingSignature, unpackThinkingSignature } from \"./devin-thinking.ts\";\nimport {\n\tencodeFixed64Field,\n\tencodeMessage,\n\tencodeString,\n\tencodeVarintField,\n\tframeConnectStream,\n\titerFields,\n} from \"./devin-wire.ts\";\n\nconst SOURCE_BY_ROLE: Record<string, number> = {\n\tuser: 1,\n\tassistant: 2,\n\ttool: 4,\n};\n\nexport type CloudChatEvent =\n\t| { kind: \"text\"; text: string }\n\t| { kind: \"reasoning\"; text: string }\n\t| { kind: \"reasoning_signature\"; signature: string; signatureType?: string }\n\t| { kind: \"reasoning_redacted\" }\n\t| { kind: \"tool_call_start\"; id: string; name: string }\n\t| { kind: \"tool_call_args\"; argsDelta: string; id?: string }\n\t| { kind: \"finish\"; reason: \"stop\" | \"tool_calls\" | \"length\" | \"content_filter\" }\n\t| {\n\t\t\tkind: \"usage\";\n\t\t\tpromptTokens?: number;\n\t\t\tcompletionTokens?: number;\n\t\t\tcachedInputTokens?: number;\n\t\t\tcacheCreationInputTokens?: number;\n\t };\n\nfunction normalizeContent(content: string | ContentPart[]): ContentPart[] {\n\tif (typeof content === \"string\") return [{ type: \"text\", text: content }];\n\treturn content;\n}\n\nfunction encodeImageData(img: { mimeType?: string; base64Data?: string }): Buffer {\n\treturn Buffer.concat([encodeString(1, img.base64Data ?? \"\"), encodeString(2, img.mimeType ?? \"image/png\")]);\n}\n\nfunction encodeChatToolCall(tc: { id: string; name: string; arguments: string }): Buffer {\n\treturn Buffer.concat([encodeString(1, tc.id), encodeString(2, tc.name), encodeString(3, tc.arguments)]);\n}\n\nfunction encodeChatMessagePrompt(\n\tcontent: ContentPart[],\n\tsource: number,\n\topts?: {\n\t\ttoolCallId?: string;\n\t\ttoolCalls?: Array<{ id: string; name: string; arguments: string }>;\n\t\tthinking?: ChatThinking;\n\t},\n): Buffer {\n\tconst text = content\n\t\t.filter((part) => part.type === \"text\")\n\t\t.map((part) => part.text ?? \"\")\n\t\t.join(\"\\n\");\n\tconst parts: Buffer[] = [encodeVarintField(2, source), encodeString(3, text), encodeVarintField(5, 1)];\n\tif (opts?.toolCallId) parts.push(encodeString(7, opts.toolCallId));\n\tfor (const tc of opts?.toolCalls ?? []) parts.push(encodeMessage(6, encodeChatToolCall(tc)));\n\tfor (const img of content.filter((part) => part.type === \"image\")) {\n\t\tparts.push(encodeMessage(10, encodeImageData(img)));\n\t}\n\t// 11 thinking / 12 signature / 13 thinking_redacted / 18 signature_type — the\n\t// same quartet the Devin CLI replays so the model keeps its own reasoning.\n\tif (opts?.thinking) {\n\t\tparts.push(encodeString(11, opts.thinking.text));\n\t\tparts.push(encodeString(12, opts.thinking.signature));\n\t\tif (opts.thinking.redacted) parts.push(encodeVarintField(13, 1));\n\t\tif (opts.thinking.signatureType) parts.push(encodeString(18, opts.thinking.signatureType));\n\t}\n\treturn Buffer.concat(parts);\n}\n\n/** Mirrors the Devin CLI: num_completions / max_tokens / max_newlines plus\n * temperature / top_k / top_p, and nothing else. */\nfunction encodeCompletionConfiguration(maxOutputTokens?: number, temperature?: number): Buffer {\n\treturn Buffer.concat([\n\t\tencodeVarintField(1, 1),\n\t\tencodeVarintField(2, maxOutputTokens ?? 128_000),\n\t\tencodeVarintField(3, 400),\n\t\tencodeFixed64Field(5, temperature ?? 1.0),\n\t\tencodeVarintField(7, 40),\n\t\tencodeFixed64Field(8, 0.95),\n\t]);\n}\n\n/** CortexTrajectoryReference: cascade trajectory, user-input step. */\nfunction encodeTrajectoryReference(trajectoryId: string): Buffer {\n\treturn Buffer.concat([encodeString(1, trajectoryId), encodeVarintField(3, 4), encodeVarintField(4, 14)]);\n}\n\nfunction encodeToolDef(tool: ToolDef): Buffer {\n\tconst description = tool.description;\n\treturn Buffer.concat([\n\t\tencodeString(1, tool.name),\n\t\tencodeString(2, description),\n\t\tencodeString(3, JSON.stringify(tool.parameters ?? {})),\n\t]);\n}\n\nfunction buildGetChatMessageRequest(args: {\n\tapiKey: string;\n\tuserJwt: string;\n\tmodelUid: string;\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools?: ToolDef[];\n\tcascadeId: string;\n\ttrajectoryId: string;\n\tsessionId: string;\n\trequestId: bigint;\n\ttriggerId: string;\n\tmaxOutputTokens?: number;\n\ttemperature?: number;\n}): Buffer {\n\tconst metadata = buildMetadata({\n\t\tapiKey: args.apiKey,\n\t\tuserJwt: args.userJwt,\n\t\tsessionId: args.sessionId,\n\t\trequestId: args.requestId,\n\t\ttriggerId: args.triggerId,\n\t});\n\tconst prompts = args.messages.map((message) =>\n\t\tencodeMessage(\n\t\t\t3,\n\t\t\tencodeChatMessagePrompt(normalizeContent(message.content), SOURCE_BY_ROLE[message.role], {\n\t\t\t\ttoolCallId: message.role === \"tool\" ? message.tool_call_id : undefined,\n\t\t\t\ttoolCalls: message.role === \"assistant\" ? message.tool_calls : undefined,\n\t\t\t\tthinking: message.role === \"assistant\" ? message.thinking : undefined,\n\t\t\t}),\n\t\t),\n\t);\n\treturn Buffer.concat([\n\t\tencodeMessage(1, metadata),\n\t\t// 2 prompt — the server's system slot, same place the Devin CLI puts its own\n\t\t// system prompt. Collapsing it into the first user turn is not equivalent.\n\t\t...(args.systemPrompt ? [encodeString(2, args.systemPrompt)] : []),\n\t\t...prompts,\n\t\tencodeVarintField(7, 5),\n\t\tencodeMessage(8, encodeCompletionConfiguration(args.maxOutputTokens, args.temperature)),\n\t\t...(args.tools ?? []).map((tool) => encodeMessage(10, encodeToolDef(tool))),\n\t\tencodeMessage(15, encodeTrajectoryReference(args.trajectoryId)),\n\t\tencodeString(16, args.cascadeId),\n\t\tencodeVarintField(20, 1),\n\t\tencodeString(21, args.modelUid),\n\t]);\n}\n\nfunction* decodeChatFrame(proto: Buffer): Generator<CloudChatEvent> {\n\tlet signature: string | undefined;\n\tlet signatureType: string | undefined;\n\tfor (const field of iterFields(proto)) {\n\t\tif (field.num === 3 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) yield { kind: \"text\", text };\n\t\t} else if (field.num === 9 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) yield { kind: \"reasoning\", text };\n\t\t} else if (field.num === 11 && field.wire === 0) {\n\t\t\t// GetChatMessageResponse.thinking_redacted\n\t\t\tif (Number(field.value) !== 0) yield { kind: \"reasoning_redacted\" };\n\t\t} else if (field.num === 10 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) signature = text;\n\t\t} else if (field.num === 21 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) signatureType = text;\n\t\t} else if (field.num === 6 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tlet id: string | undefined;\n\t\t\tlet name: string | undefined;\n\t\t\tlet argsDelta: string | undefined;\n\t\t\tfor (const inner of iterFields(field.value)) {\n\t\t\t\tif (inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\t\tconst text = inner.value.toString(\"utf8\");\n\t\t\t\t\tif (inner.num === 1) id = text;\n\t\t\t\t\telse if (inner.num === 2) name = text;\n\t\t\t\t\telse if (inner.num === 3) argsDelta = text;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (id !== undefined && name !== undefined) yield { kind: \"tool_call_start\", id, name };\n\t\t\tif (argsDelta !== undefined) yield { kind: \"tool_call_args\", argsDelta, ...(id ? { id } : {}) };\n\t\t} else if (field.num === 5 && field.wire === 0) {\n\t\t\tconst value = Number(field.value);\n\t\t\tlet reason: Extract<CloudChatEvent, { kind: \"finish\" }>[\"reason\"] = \"stop\";\n\t\t\tif (value === 10) reason = \"tool_calls\";\n\t\t\telse if (value === 11) reason = \"content_filter\";\n\t\t\telse if ([1, 3, 5, 9].includes(value)) reason = \"length\";\n\t\t\telse if (![0, 2, 4, 6, 8, 12].includes(value)) throw new Error(`Devin returned failure stop reason ${value}`);\n\t\t\tyield { kind: \"finish\", reason };\n\t\t} else if (field.num === 28 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst usage = decodeUsage(field.value);\n\t\t\tif (usage) yield usage;\n\t\t}\n\t}\n\t// The signature trails the thinking text, so it is yielded once the frame is\n\t// fully read and gets attached to the block that is already closed.\n\tif (signature !== undefined || signatureType !== undefined)\n\t\tyield { kind: \"reasoning_signature\", signature: signature ?? \"\", signatureType };\n}\n\nfunction decodeUsage(buf: Buffer): CloudChatEvent | null {\n\tlet promptTokens: number | undefined;\n\tlet completionTokens: number | undefined;\n\tlet cachedInputTokens: number | undefined;\n\tlet cacheCreationInputTokens: number | undefined;\n\tfor (const field of iterFields(buf)) {\n\t\tif (field.num !== 2 || field.wire !== 2 || !Buffer.isBuffer(field.value)) continue;\n\t\tlet metric: string | undefined;\n\t\tlet value: number | undefined;\n\t\tfor (const inner of iterFields(field.value)) {\n\t\t\tif (inner.num === 5 && inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\tmetric = inner.value.toString(\"utf8\");\n\t\t\t} else if (inner.num === 4 && inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\t// Protobuf omits the scalar field when a present numeric metric is zero.\n\t\t\t\tvalue = 0;\n\t\t\t\tfor (const dim of iterFields(inner.value)) {\n\t\t\t\t\tif (dim.num === 2 && dim.wire === 5 && Buffer.isBuffer(dim.value)) {\n\t\t\t\t\t\tvalue = dim.value.readFloatLE(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!metric || value === undefined || !Number.isFinite(value)) continue;\n\t\tconst n = Math.round(value);\n\t\tif (metric === \"input_tokens\") promptTokens = n;\n\t\telse if (metric === \"output_tokens\") completionTokens = n;\n\t\telse if (metric === \"cached_input_tokens\" || metric === \"cache_read_input_tokens\") cachedInputTokens = n;\n\t\telse if (metric === \"cache_creation_input_tokens\") cacheCreationInputTokens = n;\n\t}\n\tif (\n\t\tpromptTokens === undefined &&\n\t\tcompletionTokens === undefined &&\n\t\tcachedInputTokens === undefined &&\n\t\tcacheCreationInputTokens === undefined\n\t)\n\t\treturn null;\n\treturn {\n\t\tkind: \"usage\",\n\t\tpromptTokens,\n\t\tcompletionTokens,\n\t\tcachedInputTokens,\n\t\tcacheCreationInputTokens,\n\t};\n}\n\nasync function* streamChatEvents(args: {\n\tapiKey: string;\n\thost: string;\n\tmodelUid: string;\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools?: ToolDef[];\n\tmaxOutputTokens?: number;\n\tsignal?: AbortSignal;\n\tsessionId?: string;\n\tfetchImpl: typeof fetch;\n\ttemperature?: number;\n}): AsyncGenerator<CloudChatEvent> {\n\tconst host = args.host.replace(/\\/$/, \"\");\n\tconst userJwt = await mintUserJwt(args.apiKey, host, args.signal, args.fetchImpl);\n\tconst sessionId = args.sessionId ?? randomUUID();\n\tconst ids = { sessionId, cascadeId: sessionId, trajectoryId: sessionId };\n\tconst proto = buildGetChatMessageRequest({\n\t\tapiKey: args.apiKey,\n\t\tuserJwt,\n\t\tmodelUid: args.modelUid,\n\t\tsystemPrompt: args.systemPrompt,\n\t\tmessages: args.messages,\n\t\ttools: args.tools,\n\t\tcascadeId: ids.cascadeId,\n\t\ttrajectoryId: ids.trajectoryId,\n\t\tsessionId: ids.sessionId,\n\t\trequestId: BigInt(Date.now()),\n\t\ttriggerId: randomUUID(),\n\t\tmaxOutputTokens: args.maxOutputTokens,\n\t\ttemperature: args.temperature,\n\t});\n\n\tconst resp = await args.fetchImpl(`${host}/exa.api_server_pb.ApiServerService/GetChatMessage`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/connect+proto\",\n\t\t\t\"Connect-Protocol-Version\": \"1\",\n\t\t\t\"Connect-Content-Encoding\": \"gzip\",\n\t\t\t\"Connect-Accept-Encoding\": \"gzip\",\n\t\t},\n\t\tbody: new Uint8Array(frameConnectStream(proto, true)),\n\t\tsignal: args.signal,\n\t});\n\tif (!resp.ok) {\n\t\tthrow new Error(`Devin GetChatMessage failed (HTTP ${resp.status})`);\n\t}\n\tif (!resp.body) throw new Error(\"GetChatMessage returned an empty body\");\n\n\tconst reader = resp.body.getReader();\n\t// reader.closed rejects with the stream's storedError when the socket dies\n\t// mid-response; nothing awaits it -> unhandledRejection crashes the process.\n\tvoid reader.closed.catch(() => {});\n\tconst queue: Buffer[] = [];\n\tlet queued = 0;\n\tlet sawEos = false;\n\tlet trailerError: string | null = null;\n\n\tconst peek = (n: number): Buffer | null => {\n\t\tif (queued < n) return null;\n\t\tif (queue.length === 1 && queue[0].length >= n) return queue[0].subarray(0, n);\n\t\tconst parts: Buffer[] = [];\n\t\tlet remaining = n;\n\t\tfor (const chunk of queue) {\n\t\t\tif (remaining <= 0) break;\n\t\t\tif (chunk.length <= remaining) {\n\t\t\t\tparts.push(chunk);\n\t\t\t\tremaining -= chunk.length;\n\t\t\t} else {\n\t\t\t\tparts.push(chunk.subarray(0, remaining));\n\t\t\t\tremaining = 0;\n\t\t\t}\n\t\t}\n\t\treturn Buffer.concat(parts, n);\n\t};\n\n\tconst drop = (n: number): void => {\n\t\tqueued -= n;\n\t\tlet remaining = n;\n\t\twhile (remaining > 0 && queue.length > 0) {\n\t\t\tconst head = queue[0];\n\t\t\tif (head.length <= remaining) {\n\t\t\t\tqueue.shift();\n\t\t\t\tremaining -= head.length;\n\t\t\t} else {\n\t\t\t\tqueue[0] = head.subarray(remaining);\n\t\t\t\tremaining = 0;\n\t\t\t}\n\t\t}\n\t};\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { value, done } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tif (value) {\n\t\t\t\tqueue.push(Buffer.from(value));\n\t\t\t\tqueued += value.length;\n\t\t\t}\n\t\t\twhile (queued >= 5) {\n\t\t\t\tconst header = peek(5);\n\t\t\t\tif (!header) break;\n\t\t\t\tconst flags = header[0];\n\t\t\t\tconst len = header.readUInt32BE(1);\n\t\t\t\tif (flags & ~3) throw new Error(\"Invalid Devin Connect frame flags\");\n\t\t\t\tif (len > 16 * 1024 * 1024) throw new Error(\"Devin Connect frame exceeds 16 MiB\");\n\t\t\t\tif (queued < 5 + len) break;\n\t\t\t\tdrop(5);\n\t\t\t\tconst raw = peek(len) ?? Buffer.alloc(0);\n\t\t\t\tdrop(len);\n\t\t\t\tlet payload = raw;\n\t\t\t\tif (flags & 0x01) payload = zlib.gunzipSync(raw, { maxOutputLength: 16 * 1024 * 1024 });\n\t\t\t\tif (sawEos) throw new Error(\"Devin returned data after its EOS trailer\");\n\t\t\t\tif (flags & 0x02) {\n\t\t\t\t\tsawEos = true;\n\t\t\t\t\tconst parsed = JSON.parse(payload.toString(\"utf8\")) as { error?: { code?: string; message?: string } };\n\t\t\t\t\tif (parsed.error) {\n\t\t\t\t\t\tconst detail =\n\t\t\t\t\t\t\ttypeof parsed.error.message === \"string\"\n\t\t\t\t\t\t\t\t? parsed.error.message\n\t\t\t\t\t\t\t\t\t\t.replaceAll(args.apiKey, \"[redacted]\")\n\t\t\t\t\t\t\t\t\t\t.replaceAll(userJwt, \"[redacted]\")\n\t\t\t\t\t\t\t\t\t\t.slice(0, 500)\n\t\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\ttrailerError = `Devin stream failed (${parsed.error.code ?? \"unknown\"})${detail ? `: ${detail}` : \"\"}`;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tyield* decodeChatFrame(payload);\n\t\t\t}\n\t\t}\n\t} finally {\n\t\ttry {\n\t\t\treader.releaseLock();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t\ttry {\n\t\t\t// await: on an errored stream cancel() returns a rejected promise;\n\t\t\t// `void`-ing it escapes the try/catch as an unhandled rejection.\n\t\t\tawait resp.body?.cancel();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tif (trailerError) throw new Error(trailerError);\n\tif (queued) throw new Error(\"Truncated Devin Connect frame\");\n\tif (!sawEos) throw new Error(\"Devin stream ended without an EOS trailer\");\n}\n\nexport function streamDevin(\n\tmodel: Model<Api>,\n\tcontext: TranscriptContext,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\n\tvoid (async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: model.api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\tlet textOpen = false;\n\t\tlet thinkingOpen = false;\n\t\tlet thinkingIndex = -1;\n\t\tlet toolId = \"\";\n\t\tconst toolStates = new Map<string, { index: number; json: string }>();\n\n\t\tconst closeText = () => {\n\t\t\tif (!textOpen) return;\n\t\t\tconst idx = output.content.length - 1;\n\t\t\tconst block = output.content[idx];\n\t\t\tif (block.type === \"text\") {\n\t\t\t\tstream.push({ type: \"text_end\", contentIndex: idx, content: block.text, partial: output });\n\t\t\t}\n\t\t\ttextOpen = false;\n\t\t};\n\t\tconst closeThinking = () => {\n\t\t\tif (!thinkingOpen) return;\n\t\t\tconst idx = output.content.length - 1;\n\t\t\tconst block = output.content[idx];\n\t\t\tif (block.type === \"thinking\") {\n\t\t\t\tstream.push({ type: \"thinking_end\", contentIndex: idx, content: block.thinking, partial: output });\n\t\t\t}\n\t\t\tthinkingOpen = false;\n\t\t};\n\t\tconst closeTool = () => {\n\t\t\tfor (const state of toolStates.values()) {\n\t\t\t\tconst block = output.content[state.index];\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\tconst parsed: unknown = JSON.parse(state.json);\n\t\t\t\t\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed))\n\t\t\t\t\t\tthrow new Error(\"Invalid Devin tool arguments\");\n\t\t\t\t\tblock.arguments = parsed as JsonObject;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\t\tcontentIndex: state.index,\n\t\t\t\t\t\ttoolCall: block,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoolStates.clear();\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (process.env.PI_SERVER_MODE === \"true\")\n\t\t\t\tthrow new Error(\"Devin inference must use pi-server in PI_SERVER_MODE\");\n\t\t\tif (!apiKey) throw new Error(\"No Devin credentials. Run /login devin.\");\n\t\t\tconst host = model.baseUrl.replace(/\\/$/, \"\");\n\t\t\tif (options?.reasoning && model.thinkingLevelMap && model.thinkingLevelMap[options.reasoning] !== model.id)\n\t\t\t\tthrow new Error(\"Select the Devin model variant for the requested reasoning effort\");\n\t\t\tif (options?.onPayload) throw new Error(\"Devin does not support onPayload overrides\");\n\t\t\tconst modelUid = model.id;\n\t\t\tconst mapped = mapContextToChat(context, model.id);\n\t\t\tstream.push({ type: \"start\", partial: output });\n\n\t\t\tfor await (const event of streamChatEvents({\n\t\t\t\tapiKey,\n\t\t\t\thost,\n\t\t\t\tmodelUid,\n\t\t\t\tsystemPrompt: mapped.systemPrompt,\n\t\t\t\tmessages: mapped.messages,\n\t\t\t\ttools: mapped.tools.length > 0 ? mapped.tools : undefined,\n\t\t\t\tmaxOutputTokens: options?.maxTokens ?? model.maxTokens,\n\t\t\t\tsignal: options?.signal\n\t\t\t\t\t? AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs ?? 600_000)])\n\t\t\t\t\t: AbortSignal.timeout(options?.timeoutMs ?? 600_000),\n\t\t\t\tsessionId: options?.sessionId,\n\t\t\t\tfetchImpl: options?.fetch ?? fetch,\n\t\t\t\ttemperature: options?.temperature,\n\t\t\t})) {\n\t\t\t\tif (event.kind === \"text\") {\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\tif (!textOpen) {\n\t\t\t\t\t\toutput.content.push({ type: \"text\", text: \"\" });\n\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t\t\t\ttextOpen = true;\n\t\t\t\t\t}\n\t\t\t\t\tconst idx = output.content.length - 1;\n\t\t\t\t\tconst block = output.content[idx];\n\t\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\t\tblock.text += event.text;\n\t\t\t\t\t\tstream.push({ type: \"text_delta\", contentIndex: idx, delta: event.text, partial: output });\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning\") {\n\t\t\t\t\tcloseText();\n\t\t\t\t\tif (!thinkingOpen) {\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t}\n\t\t\t\t\tconst idx = output.content.length - 1;\n\t\t\t\t\tconst block = output.content[idx];\n\t\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\t\tblock.thinking += event.text;\n\t\t\t\t\t\tstream.push({ type: \"thinking_delta\", contentIndex: idx, delta: event.text, partial: output });\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning_signature\") {\n\t\t\t\t\tif (thinkingIndex < 0) {\n\t\t\t\t\t\tcloseText();\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: thinkingIndex, partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tconst block = output.content[thinkingIndex];\n\t\t\t\t\tif (block?.type === \"thinking\") {\n\t\t\t\t\t\tconst previous = unpackThinkingSignature(block.thinkingSignature);\n\t\t\t\t\t\tblock.thinkingSignature = packThinkingSignature(\n\t\t\t\t\t\t\t(previous.signature ?? \"\") + event.signature,\n\t\t\t\t\t\t\tevent.signatureType ?? previous.signatureType,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning_redacted\") {\n\t\t\t\t\tif (thinkingIndex < 0) {\n\t\t\t\t\t\tcloseText();\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: thinkingIndex, partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tconst block = thinkingIndex >= 0 ? output.content[thinkingIndex] : undefined;\n\t\t\t\t\tif (block?.type === \"thinking\") block.redacted = true;\n\t\t\t\t} else if (event.kind === \"tool_call_start\") {\n\t\t\t\t\tcloseText();\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\ttoolId = event.id;\n\t\t\t\t\tconst existing = toolStates.get(toolId);\n\t\t\t\t\tif (existing) {\n\t\t\t\t\t\tconst block = output.content[existing.index];\n\t\t\t\t\t\tif (block.type !== \"toolCall\" || block.name !== event.name)\n\t\t\t\t\t\t\tthrow new Error(\"Devin changed a tool call's name\");\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (!toolId || !event.name) throw new Error(\"Devin returned an empty tool identity\");\n\t\t\t\t\toutput.content.push({ type: \"toolCall\", id: event.id, name: event.name, arguments: {} });\n\t\t\t\t\tconst toolIndex = output.content.length - 1;\n\t\t\t\t\ttoolStates.set(toolId, { index: toolIndex, json: \"\" });\n\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: toolIndex, partial: output });\n\t\t\t\t} else if (event.kind === \"tool_call_args\") {\n\t\t\t\t\tconst state = toolStates.get(event.id ?? toolId);\n\t\t\t\t\tif (!state) throw new Error(\"Devin tool argument delta has no matching call\");\n\t\t\t\t\tstate.json += event.argsDelta;\n\t\t\t\t\tconst block = output.content[state.index];\n\t\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tblock.arguments = JSON.parse(state.json);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// incomplete json\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\tcontentIndex: state.index,\n\t\t\t\t\t\tdelta: event.argsDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else if (event.kind === \"finish\") {\n\t\t\t\t\tif (event.reason === \"content_filter\")\n\t\t\t\t\t\tthrow new Error(\"Devin response was blocked by content filtering\");\n\t\t\t\t\tcloseText();\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\toutput.stopReason =\n\t\t\t\t\t\tevent.reason === \"tool_calls\" ? \"toolUse\" : event.reason === \"length\" ? \"length\" : \"stop\";\n\t\t\t\t} else if (event.kind === \"usage\") {\n\t\t\t\t\t// Metrics are reported counts, not deltas. Absent fields retain earlier reports.\n\t\t\t\t\tif (event.promptTokens !== undefined) output.usage.input = event.promptTokens;\n\t\t\t\t\tif (event.completionTokens !== undefined) output.usage.output = event.completionTokens;\n\t\t\t\t\tif (event.cachedInputTokens !== undefined) output.usage.cacheRead = event.cachedInputTokens;\n\t\t\t\t\tif (event.cacheCreationInputTokens !== undefined)\n\t\t\t\t\t\toutput.usage.cacheWrite = event.cacheCreationInputTokens;\n\t\t\t\t\toutput.usage.totalTokens =\n\t\t\t\t\t\toutput.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcloseText();\n\t\t\tcloseThinking();\n\t\t\tcloseTool();\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tif (!output.content.length) throw new Error(\"Devin returned an empty completion\");\n\t\t\tfor (const key of [\"input\", \"output\", \"cacheRead\", \"cacheWrite\"] as const) {\n\t\t\t\toutput.usage.cost[key] = (output.usage[key] * model.cost[key]) / 1_000_000;\n\t\t\t}\n\t\t\toutput.usage.cost.total =\n\t\t\t\toutput.usage.cost.input +\n\t\t\t\toutput.usage.cost.output +\n\t\t\t\toutput.usage.cost.cacheRead +\n\t\t\t\toutput.usage.cost.cacheWrite;\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason as \"stop\" | \"length\" | \"toolUse\", message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : String(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason as \"aborted\" | \"error\", error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"devin-stream.js","sourceRoot":"","sources":["../../src/api/devin-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;EAuBE;AACF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAKN,iCAAiC,GAIjC,MAAM,aAAa,CAAC;AACrB,OAAO,EAA0C,gBAAgB,EAAgB,MAAM,wBAAwB,CAAC;AAChH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAqB,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACxG,OAAO,EACN,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,GACV,MAAM,iBAAiB,CAAC;AAEzB,MAAM,cAAc,GAA2B;IAC9C,IAAI,EAAE,CAAC;IACP,SAAS,EAAE,CAAC;IACZ,IAAI,EAAE,CAAC;CACP,CAAC;AAkBF,SAAS,gBAAgB,CAAC,OAA+B,EAAiB;IACzE,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1E,OAAO,OAAO,CAAC;AAAA,CACf;AAED,SAAS,eAAe,CAAC,GAA+C,EAAU;IACjF,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,EAAE,GAAG,CAAC,UAAU,IA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AK,CAAC,CAAC;YAC7E,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,UAAiC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;YAChG,MAAM,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;IAAA,CACD,CAAC,EAAE,CAAC;IAEL,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Kashyab Ambarani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n*/\nimport { randomUUID } from \"node:crypto\";\nimport * as zlib from \"node:zlib\";\nimport {\n\ttype Api,\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tcreateAssistantMessageEventStream,\n\ttype JsonObject,\n\ttype Model,\n\ttype SimpleStreamOptions,\n} from \"../index.ts\";\nimport { type ChatHistoryItem, type ContentPart, mapContextToChat, type ToolDef } from \"./devin-context-map.ts\";\nimport { mintUserJwt } from \"./devin-jwt.ts\";\nimport { buildMetadata } from \"./devin-metadata.ts\";\n\nimport { type ChatThinking, packThinkingSignature, unpackThinkingSignature } from \"./devin-thinking.ts\";\nimport {\n\tencodeFixed64Field,\n\tencodeMessage,\n\tencodeString,\n\tencodeVarintField,\n\tframeConnectStream,\n\titerFields,\n} from \"./devin-wire.ts\";\n\nconst SOURCE_BY_ROLE: Record<string, number> = {\n\tuser: 1,\n\tassistant: 2,\n\ttool: 4,\n};\n\nexport type CloudChatEvent =\n\t| { kind: \"text\"; text: string }\n\t| { kind: \"reasoning\"; text: string }\n\t| { kind: \"reasoning_signature\"; signature: string; signatureType?: string }\n\t| { kind: \"reasoning_redacted\" }\n\t| { kind: \"tool_call_start\"; id: string; name: string }\n\t| { kind: \"tool_call_args\"; argsDelta: string; id?: string }\n\t| { kind: \"finish\"; reason: \"stop\" | \"tool_calls\" | \"length\" | \"content_filter\" }\n\t| {\n\t\t\tkind: \"usage\";\n\t\t\tpromptTokens?: number;\n\t\t\tcompletionTokens?: number;\n\t\t\tcachedInputTokens?: number;\n\t\t\tcacheCreationInputTokens?: number;\n\t };\n\nfunction normalizeContent(content: string | ContentPart[]): ContentPart[] {\n\tif (typeof content === \"string\") return [{ type: \"text\", text: content }];\n\treturn content;\n}\n\nfunction encodeImageData(img: { mimeType?: string; base64Data?: string }): Buffer {\n\treturn Buffer.concat([encodeString(1, img.base64Data ?? \"\"), encodeString(2, img.mimeType ?? \"image/png\")]);\n}\n\nfunction encodeChatToolCall(tc: { id: string; name: string; arguments: string }): Buffer {\n\treturn Buffer.concat([encodeString(1, tc.id), encodeString(2, tc.name), encodeString(3, tc.arguments)]);\n}\n\nfunction encodeChatMessagePrompt(\n\tcontent: ContentPart[],\n\tsource: number,\n\topts?: {\n\t\ttoolCallId?: string;\n\t\ttoolCalls?: Array<{ id: string; name: string; arguments: string }>;\n\t\tthinking?: ChatThinking;\n\t},\n): Buffer {\n\tconst text = content\n\t\t.filter((part) => part.type === \"text\")\n\t\t.map((part) => part.text ?? \"\")\n\t\t.join(\"\\n\");\n\tconst parts: Buffer[] = [encodeVarintField(2, source), encodeString(3, text), encodeVarintField(5, 1)];\n\tif (opts?.toolCallId) parts.push(encodeString(7, opts.toolCallId));\n\tfor (const tc of opts?.toolCalls ?? []) parts.push(encodeMessage(6, encodeChatToolCall(tc)));\n\tfor (const img of content.filter((part) => part.type === \"image\")) {\n\t\tparts.push(encodeMessage(10, encodeImageData(img)));\n\t}\n\t// 11 thinking / 12 signature / 13 thinking_redacted / 18 signature_type — the\n\t// same quartet the Devin CLI replays so the model keeps its own reasoning.\n\tif (opts?.thinking) {\n\t\tparts.push(encodeString(11, opts.thinking.text));\n\t\tparts.push(encodeString(12, opts.thinking.signature));\n\t\tif (opts.thinking.redacted) parts.push(encodeVarintField(13, 1));\n\t\tif (opts.thinking.signatureType) parts.push(encodeString(18, opts.thinking.signatureType));\n\t}\n\treturn Buffer.concat(parts);\n}\n\n/** Mirrors the Devin CLI: num_completions / max_tokens / max_newlines plus\n * temperature / top_k / top_p, and nothing else. */\nfunction encodeCompletionConfiguration(maxOutputTokens?: number, temperature?: number): Buffer {\n\treturn Buffer.concat([\n\t\tencodeVarintField(1, 1),\n\t\tencodeVarintField(2, maxOutputTokens ?? 128_000),\n\t\tencodeVarintField(3, 400),\n\t\tencodeFixed64Field(5, temperature ?? 1.0),\n\t\tencodeVarintField(7, 40),\n\t\tencodeFixed64Field(8, 0.95),\n\t]);\n}\n\n/** CortexTrajectoryReference: cascade trajectory, user-input step. */\nfunction encodeTrajectoryReference(trajectoryId: string): Buffer {\n\treturn Buffer.concat([encodeString(1, trajectoryId), encodeVarintField(3, 4), encodeVarintField(4, 14)]);\n}\n\nfunction encodeToolDef(tool: ToolDef): Buffer {\n\tconst description = tool.description;\n\treturn Buffer.concat([\n\t\tencodeString(1, tool.name),\n\t\tencodeString(2, description),\n\t\tencodeString(3, JSON.stringify(tool.parameters ?? {})),\n\t]);\n}\n\nfunction buildGetChatMessageRequest(args: {\n\tapiKey: string;\n\tuserJwt: string;\n\tmodelUid: string;\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools?: ToolDef[];\n\tcascadeId: string;\n\ttrajectoryId: string;\n\tsessionId: string;\n\trequestId: bigint;\n\ttriggerId: string;\n\tmaxOutputTokens?: number;\n\ttemperature?: number;\n}): Buffer {\n\tconst metadata = buildMetadata({\n\t\tapiKey: args.apiKey,\n\t\tuserJwt: args.userJwt,\n\t\tsessionId: args.sessionId,\n\t\trequestId: args.requestId,\n\t\ttriggerId: args.triggerId,\n\t});\n\tconst prompts = args.messages.map((message) =>\n\t\tencodeMessage(\n\t\t\t3,\n\t\t\tencodeChatMessagePrompt(normalizeContent(message.content), SOURCE_BY_ROLE[message.role], {\n\t\t\t\ttoolCallId: message.role === \"tool\" ? message.tool_call_id : undefined,\n\t\t\t\ttoolCalls: message.role === \"assistant\" ? message.tool_calls : undefined,\n\t\t\t\tthinking: message.role === \"assistant\" ? message.thinking : undefined,\n\t\t\t}),\n\t\t),\n\t);\n\treturn Buffer.concat([\n\t\tencodeMessage(1, metadata),\n\t\t// 2 prompt — the server's system slot, same place the Devin CLI puts its own\n\t\t// system prompt. Collapsing it into the first user turn is not equivalent.\n\t\t...(args.systemPrompt ? [encodeString(2, args.systemPrompt)] : []),\n\t\t...prompts,\n\t\tencodeVarintField(7, 5),\n\t\tencodeMessage(8, encodeCompletionConfiguration(args.maxOutputTokens, args.temperature)),\n\t\t...(args.tools ?? []).map((tool) => encodeMessage(10, encodeToolDef(tool))),\n\t\tencodeMessage(15, encodeTrajectoryReference(args.trajectoryId)),\n\t\tencodeString(16, args.cascadeId),\n\t\tencodeVarintField(20, 1),\n\t\tencodeString(21, args.modelUid),\n\t]);\n}\n\nfunction* decodeChatFrame(proto: Buffer): Generator<CloudChatEvent> {\n\tlet signature: string | undefined;\n\tlet signatureType: string | undefined;\n\tfor (const field of iterFields(proto)) {\n\t\tif (field.num === 3 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) yield { kind: \"text\", text };\n\t\t} else if (field.num === 9 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) yield { kind: \"reasoning\", text };\n\t\t} else if (field.num === 11 && field.wire === 0) {\n\t\t\t// GetChatMessageResponse.thinking_redacted\n\t\t\tif (Number(field.value) !== 0) yield { kind: \"reasoning_redacted\" };\n\t\t} else if (field.num === 10 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) signature = text;\n\t\t} else if (field.num === 21 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) signatureType = text;\n\t\t} else if (field.num === 6 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tlet id: string | undefined;\n\t\t\tlet name: string | undefined;\n\t\t\tlet argsDelta: string | undefined;\n\t\t\tfor (const inner of iterFields(field.value)) {\n\t\t\t\tif (inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\t\tconst text = inner.value.toString(\"utf8\");\n\t\t\t\t\tif (inner.num === 1) id = text;\n\t\t\t\t\telse if (inner.num === 2) name = text;\n\t\t\t\t\telse if (inner.num === 3) argsDelta = text;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (id !== undefined && name !== undefined) yield { kind: \"tool_call_start\", id, name };\n\t\t\tif (argsDelta !== undefined) yield { kind: \"tool_call_args\", argsDelta, ...(id ? { id } : {}) };\n\t\t} else if (field.num === 5 && field.wire === 0) {\n\t\t\tconst value = Number(field.value);\n\t\t\tlet reason: Extract<CloudChatEvent, { kind: \"finish\" }>[\"reason\"] = \"stop\";\n\t\t\tif (value === 10) reason = \"tool_calls\";\n\t\t\telse if (value === 11) reason = \"content_filter\";\n\t\t\telse if ([1, 3, 5, 9].includes(value)) reason = \"length\";\n\t\t\telse if (![0, 2, 4, 6, 8, 12].includes(value)) throw new Error(`Devin returned failure stop reason ${value}`);\n\t\t\tyield { kind: \"finish\", reason };\n\t\t} else if (field.num === 28 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst usage = decodeUsage(field.value);\n\t\t\tif (usage) yield usage;\n\t\t}\n\t}\n\t// The signature trails the thinking text, so it is yielded once the frame is\n\t// fully read and gets attached to the block that is already closed.\n\tif (signature !== undefined || signatureType !== undefined)\n\t\tyield { kind: \"reasoning_signature\", signature: signature ?? \"\", signatureType };\n}\n\nfunction decodeUsage(buf: Buffer): CloudChatEvent | null {\n\tlet promptTokens: number | undefined;\n\tlet completionTokens: number | undefined;\n\tlet cachedInputTokens: number | undefined;\n\tlet cacheCreationInputTokens: number | undefined;\n\tfor (const field of iterFields(buf)) {\n\t\tif (field.num !== 2 || field.wire !== 2 || !Buffer.isBuffer(field.value)) continue;\n\t\tlet metric: string | undefined;\n\t\tlet value: number | undefined;\n\t\tfor (const inner of iterFields(field.value)) {\n\t\t\tif (inner.num === 5 && inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\tmetric = inner.value.toString(\"utf8\");\n\t\t\t} else if (inner.num === 4 && inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\t// Protobuf omits the scalar field when a present numeric metric is zero.\n\t\t\t\tvalue = 0;\n\t\t\t\tfor (const dim of iterFields(inner.value)) {\n\t\t\t\t\tif (dim.num === 2 && dim.wire === 5 && Buffer.isBuffer(dim.value)) {\n\t\t\t\t\t\tvalue = dim.value.readFloatLE(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!metric || value === undefined || !Number.isFinite(value)) continue;\n\t\tconst n = Math.round(value);\n\t\tif (metric === \"input_tokens\") promptTokens = n;\n\t\telse if (metric === \"output_tokens\") completionTokens = n;\n\t\telse if (metric === \"cached_input_tokens\" || metric === \"cache_read_input_tokens\") cachedInputTokens = n;\n\t\telse if (metric === \"cache_creation_input_tokens\") cacheCreationInputTokens = n;\n\t}\n\tif (\n\t\tpromptTokens === undefined &&\n\t\tcompletionTokens === undefined &&\n\t\tcachedInputTokens === undefined &&\n\t\tcacheCreationInputTokens === undefined\n\t)\n\t\treturn null;\n\treturn {\n\t\tkind: \"usage\",\n\t\tpromptTokens,\n\t\tcompletionTokens,\n\t\tcachedInputTokens,\n\t\tcacheCreationInputTokens,\n\t};\n}\n\nasync function* streamChatEvents(args: {\n\tapiKey: string;\n\thost: string;\n\tmodelUid: string;\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools?: ToolDef[];\n\tmaxOutputTokens?: number;\n\tsignal?: AbortSignal;\n\tsessionId?: string;\n\tfetchImpl: typeof fetch;\n\ttemperature?: number;\n}): AsyncGenerator<CloudChatEvent> {\n\tconst host = args.host.replace(/\\/$/, \"\");\n\tconst userJwt = await mintUserJwt(args.apiKey, host, args.signal, args.fetchImpl);\n\tconst sessionId = args.sessionId ?? randomUUID();\n\tconst ids = { sessionId, cascadeId: sessionId, trajectoryId: sessionId };\n\tconst proto = buildGetChatMessageRequest({\n\t\tapiKey: args.apiKey,\n\t\tuserJwt,\n\t\tmodelUid: args.modelUid,\n\t\tsystemPrompt: args.systemPrompt,\n\t\tmessages: args.messages,\n\t\ttools: args.tools,\n\t\tcascadeId: ids.cascadeId,\n\t\ttrajectoryId: ids.trajectoryId,\n\t\tsessionId: ids.sessionId,\n\t\trequestId: BigInt(Date.now()),\n\t\ttriggerId: randomUUID(),\n\t\tmaxOutputTokens: args.maxOutputTokens,\n\t\ttemperature: args.temperature,\n\t});\n\n\tconst resp = await args.fetchImpl(`${host}/exa.api_server_pb.ApiServerService/GetChatMessage`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/connect+proto\",\n\t\t\t\"Connect-Protocol-Version\": \"1\",\n\t\t\t\"Connect-Content-Encoding\": \"gzip\",\n\t\t\t\"Connect-Accept-Encoding\": \"gzip\",\n\t\t},\n\t\tbody: new Uint8Array(frameConnectStream(proto, true)),\n\t\tsignal: args.signal,\n\t});\n\tif (!resp.ok) {\n\t\tthrow new Error(`Devin GetChatMessage failed (HTTP ${resp.status})`);\n\t}\n\tif (!resp.body) throw new Error(\"GetChatMessage returned an empty body\");\n\n\tconst reader = resp.body.getReader();\n\t// reader.closed rejects with the stream's storedError when the socket dies\n\t// mid-response; nothing awaits it -> unhandledRejection crashes the process.\n\tvoid reader.closed.catch(() => {});\n\tconst queue: Buffer[] = [];\n\tlet queued = 0;\n\tlet sawEos = false;\n\tlet trailerError: string | null = null;\n\n\tconst peek = (n: number): Buffer | null => {\n\t\tif (queued < n) return null;\n\t\tif (queue.length === 1 && queue[0].length >= n) return queue[0].subarray(0, n);\n\t\tconst parts: Buffer[] = [];\n\t\tlet remaining = n;\n\t\tfor (const chunk of queue) {\n\t\t\tif (remaining <= 0) break;\n\t\t\tif (chunk.length <= remaining) {\n\t\t\t\tparts.push(chunk);\n\t\t\t\tremaining -= chunk.length;\n\t\t\t} else {\n\t\t\t\tparts.push(chunk.subarray(0, remaining));\n\t\t\t\tremaining = 0;\n\t\t\t}\n\t\t}\n\t\treturn Buffer.concat(parts, n);\n\t};\n\n\tconst drop = (n: number): void => {\n\t\tqueued -= n;\n\t\tlet remaining = n;\n\t\twhile (remaining > 0 && queue.length > 0) {\n\t\t\tconst head = queue[0];\n\t\t\tif (head.length <= remaining) {\n\t\t\t\tqueue.shift();\n\t\t\t\tremaining -= head.length;\n\t\t\t} else {\n\t\t\t\tqueue[0] = head.subarray(remaining);\n\t\t\t\tremaining = 0;\n\t\t\t}\n\t\t}\n\t};\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { value, done } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tif (value) {\n\t\t\t\tqueue.push(Buffer.from(value));\n\t\t\t\tqueued += value.length;\n\t\t\t}\n\t\t\twhile (queued >= 5) {\n\t\t\t\tconst header = peek(5);\n\t\t\t\tif (!header) break;\n\t\t\t\tconst flags = header[0];\n\t\t\t\tconst len = header.readUInt32BE(1);\n\t\t\t\tif (flags & ~3) throw new Error(\"Invalid Devin Connect frame flags\");\n\t\t\t\tif (len > 16 * 1024 * 1024) throw new Error(\"Devin Connect frame exceeds 16 MiB\");\n\t\t\t\tif (queued < 5 + len) break;\n\t\t\t\tdrop(5);\n\t\t\t\tconst raw = peek(len) ?? Buffer.alloc(0);\n\t\t\t\tdrop(len);\n\t\t\t\tlet payload = raw;\n\t\t\t\tif (flags & 0x01) payload = zlib.gunzipSync(raw, { maxOutputLength: 16 * 1024 * 1024 });\n\t\t\t\tif (sawEos) throw new Error(\"Devin returned data after its EOS trailer\");\n\t\t\t\tif (flags & 0x02) {\n\t\t\t\t\tsawEos = true;\n\t\t\t\t\tconst parsed = JSON.parse(payload.toString(\"utf8\")) as { error?: { code?: string; message?: string } };\n\t\t\t\t\tif (parsed.error) {\n\t\t\t\t\t\tconst detail =\n\t\t\t\t\t\t\ttypeof parsed.error.message === \"string\"\n\t\t\t\t\t\t\t\t? parsed.error.message\n\t\t\t\t\t\t\t\t\t\t.replaceAll(args.apiKey, \"[redacted]\")\n\t\t\t\t\t\t\t\t\t\t.replaceAll(userJwt, \"[redacted]\")\n\t\t\t\t\t\t\t\t\t\t.slice(0, 500)\n\t\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\ttrailerError = `Devin stream failed (${parsed.error.code ?? \"unknown\"})${detail ? `: ${detail}` : \"\"}`;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tyield* decodeChatFrame(payload);\n\t\t\t}\n\t\t}\n\t} finally {\n\t\ttry {\n\t\t\treader.releaseLock();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t\ttry {\n\t\t\t// await: on an errored stream cancel() returns a rejected promise;\n\t\t\t// `void`-ing it escapes the try/catch as an unhandled rejection.\n\t\t\tawait resp.body?.cancel();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tif (trailerError) throw new Error(trailerError);\n\tif (queued) throw new Error(\"Truncated Devin Connect frame\");\n\tif (!sawEos) throw new Error(\"Devin stream ended without an EOS trailer\");\n}\n\nexport function streamDevin(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\n\tvoid (async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: model.api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\tlet textOpen = false;\n\t\tlet thinkingOpen = false;\n\t\tlet thinkingIndex = -1;\n\t\tlet toolId = \"\";\n\t\tconst toolStates = new Map<string, { index: number; json: string }>();\n\n\t\tconst closeText = () => {\n\t\t\tif (!textOpen) return;\n\t\t\tconst idx = output.content.length - 1;\n\t\t\tconst block = output.content[idx];\n\t\t\tif (block.type === \"text\") {\n\t\t\t\tstream.push({ type: \"text_end\", contentIndex: idx, content: block.text, partial: output });\n\t\t\t}\n\t\t\ttextOpen = false;\n\t\t};\n\t\tconst closeThinking = () => {\n\t\t\tif (!thinkingOpen) return;\n\t\t\tconst idx = output.content.length - 1;\n\t\t\tconst block = output.content[idx];\n\t\t\tif (block.type === \"thinking\") {\n\t\t\t\tstream.push({ type: \"thinking_end\", contentIndex: idx, content: block.thinking, partial: output });\n\t\t\t}\n\t\t\tthinkingOpen = false;\n\t\t};\n\t\tconst closeTool = () => {\n\t\t\tfor (const state of toolStates.values()) {\n\t\t\t\tconst block = output.content[state.index];\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\tconst parsed: unknown = JSON.parse(state.json);\n\t\t\t\t\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed))\n\t\t\t\t\t\tthrow new Error(\"Invalid Devin tool arguments\");\n\t\t\t\t\tblock.arguments = parsed as JsonObject;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\t\tcontentIndex: state.index,\n\t\t\t\t\t\ttoolCall: block,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoolStates.clear();\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (process.env.PI_SERVER_MODE === \"true\")\n\t\t\t\tthrow new Error(\"Devin inference must use pi-server in PI_SERVER_MODE\");\n\t\t\tif (!apiKey) throw new Error(\"No Devin credentials. Run /login devin.\");\n\t\t\tconst host = model.baseUrl.replace(/\\/$/, \"\");\n\t\t\tif (options?.reasoning && model.thinkingLevelMap && model.thinkingLevelMap[options.reasoning] !== model.id)\n\t\t\t\tthrow new Error(\"Select the Devin model variant for the requested reasoning effort\");\n\t\t\tif (options?.onPayload) throw new Error(\"Devin does not support onPayload overrides\");\n\t\t\tconst modelUid = model.id;\n\t\t\tconst mapped = mapContextToChat(context, model.id);\n\t\t\tstream.push({ type: \"start\", partial: output });\n\n\t\t\tfor await (const event of streamChatEvents({\n\t\t\t\tapiKey,\n\t\t\t\thost,\n\t\t\t\tmodelUid,\n\t\t\t\tsystemPrompt: mapped.systemPrompt,\n\t\t\t\tmessages: mapped.messages,\n\t\t\t\ttools: mapped.tools.length > 0 ? mapped.tools : undefined,\n\t\t\t\tmaxOutputTokens: options?.maxTokens ?? model.maxTokens,\n\t\t\t\tsignal: options?.signal\n\t\t\t\t\t? AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs ?? 600_000)])\n\t\t\t\t\t: AbortSignal.timeout(options?.timeoutMs ?? 600_000),\n\t\t\t\tsessionId: options?.sessionId,\n\t\t\t\tfetchImpl: options?.fetch ?? fetch,\n\t\t\t\ttemperature: options?.temperature,\n\t\t\t})) {\n\t\t\t\tif (event.kind === \"text\") {\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\tif (!textOpen) {\n\t\t\t\t\t\toutput.content.push({ type: \"text\", text: \"\" });\n\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t\t\t\ttextOpen = true;\n\t\t\t\t\t}\n\t\t\t\t\tconst idx = output.content.length - 1;\n\t\t\t\t\tconst block = output.content[idx];\n\t\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\t\tblock.text += event.text;\n\t\t\t\t\t\tstream.push({ type: \"text_delta\", contentIndex: idx, delta: event.text, partial: output });\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning\") {\n\t\t\t\t\tcloseText();\n\t\t\t\t\tif (!thinkingOpen) {\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t}\n\t\t\t\t\tconst idx = output.content.length - 1;\n\t\t\t\t\tconst block = output.content[idx];\n\t\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\t\tblock.thinking += event.text;\n\t\t\t\t\t\tstream.push({ type: \"thinking_delta\", contentIndex: idx, delta: event.text, partial: output });\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning_signature\") {\n\t\t\t\t\tif (thinkingIndex < 0) {\n\t\t\t\t\t\tcloseText();\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: thinkingIndex, partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tconst block = output.content[thinkingIndex];\n\t\t\t\t\tif (block?.type === \"thinking\") {\n\t\t\t\t\t\tconst previous = unpackThinkingSignature(block.thinkingSignature);\n\t\t\t\t\t\tblock.thinkingSignature = packThinkingSignature(\n\t\t\t\t\t\t\t(previous.signature ?? \"\") + event.signature,\n\t\t\t\t\t\t\tevent.signatureType ?? previous.signatureType,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning_redacted\") {\n\t\t\t\t\tif (thinkingIndex < 0) {\n\t\t\t\t\t\tcloseText();\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: thinkingIndex, partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tconst block = thinkingIndex >= 0 ? output.content[thinkingIndex] : undefined;\n\t\t\t\t\tif (block?.type === \"thinking\") block.redacted = true;\n\t\t\t\t} else if (event.kind === \"tool_call_start\") {\n\t\t\t\t\tcloseText();\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\ttoolId = event.id;\n\t\t\t\t\tconst existing = toolStates.get(toolId);\n\t\t\t\t\tif (existing) {\n\t\t\t\t\t\tconst block = output.content[existing.index];\n\t\t\t\t\t\tif (block.type !== \"toolCall\" || block.name !== event.name)\n\t\t\t\t\t\t\tthrow new Error(\"Devin changed a tool call's name\");\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (!toolId || !event.name) throw new Error(\"Devin returned an empty tool identity\");\n\t\t\t\t\toutput.content.push({ type: \"toolCall\", id: event.id, name: event.name, arguments: {} });\n\t\t\t\t\tconst toolIndex = output.content.length - 1;\n\t\t\t\t\ttoolStates.set(toolId, { index: toolIndex, json: \"\" });\n\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: toolIndex, partial: output });\n\t\t\t\t} else if (event.kind === \"tool_call_args\") {\n\t\t\t\t\tconst state = toolStates.get(event.id ?? toolId);\n\t\t\t\t\tif (!state) throw new Error(\"Devin tool argument delta has no matching call\");\n\t\t\t\t\tstate.json += event.argsDelta;\n\t\t\t\t\tconst block = output.content[state.index];\n\t\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tblock.arguments = JSON.parse(state.json);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// incomplete json\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\tcontentIndex: state.index,\n\t\t\t\t\t\tdelta: event.argsDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else if (event.kind === \"finish\") {\n\t\t\t\t\tif (event.reason === \"content_filter\")\n\t\t\t\t\t\tthrow new Error(\"Devin response was blocked by content filtering\");\n\t\t\t\t\tcloseText();\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\toutput.stopReason =\n\t\t\t\t\t\tevent.reason === \"tool_calls\" ? \"toolUse\" : event.reason === \"length\" ? \"length\" : \"stop\";\n\t\t\t\t} else if (event.kind === \"usage\") {\n\t\t\t\t\t// Metrics are reported counts, not deltas. Absent fields retain earlier reports.\n\t\t\t\t\tif (event.promptTokens !== undefined) output.usage.input = event.promptTokens;\n\t\t\t\t\tif (event.completionTokens !== undefined) output.usage.output = event.completionTokens;\n\t\t\t\t\tif (event.cachedInputTokens !== undefined) output.usage.cacheRead = event.cachedInputTokens;\n\t\t\t\t\tif (event.cacheCreationInputTokens !== undefined)\n\t\t\t\t\t\toutput.usage.cacheWrite = event.cacheCreationInputTokens;\n\t\t\t\t\toutput.usage.totalTokens =\n\t\t\t\t\t\toutput.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcloseText();\n\t\t\tcloseThinking();\n\t\t\tcloseTool();\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tif (!output.content.length) throw new Error(\"Devin returned an empty completion\");\n\t\t\tfor (const key of [\"input\", \"output\", \"cacheRead\", \"cacheWrite\"] as const) {\n\t\t\t\toutput.usage.cost[key] = (output.usage[key] * model.cost[key]) / 1_000_000;\n\t\t\t}\n\t\t\toutput.usage.cost.total =\n\t\t\t\toutput.usage.cost.input +\n\t\t\t\toutput.usage.cost.output +\n\t\t\t\toutput.usage.cost.cacheRead +\n\t\t\t\toutput.usage.cost.cacheWrite;\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason as \"stop\" | \"length\" | \"toolUse\", message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : String(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason as \"aborted\" | \"error\", error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n}\n"]}
1
+ {"version":3,"file":"devin-stream.js","sourceRoot":"","sources":["../../src/api/devin-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;EAuBE;AACF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAIN,iCAAiC,GAKjC,MAAM,aAAa,CAAC;AACrB,OAAO,EAA0C,gBAAgB,EAAgB,MAAM,wBAAwB,CAAC;AAChH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAqB,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACxG,OAAO,EACN,kBAA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,CAAC,IAAI,CAAC,SAAS;oBAC3B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;YAC9B,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,UAA2C,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3G,MAAM,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,CAAC,UAAU,GAAG,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;YACnE,MAAM,CAAC,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7E,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,UAAiC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;YAChG,MAAM,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;IAAA,CACD,CAAC,EAAE,CAAC;IAEL,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Kashyab Ambarani\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n*/\nimport { randomUUID } from \"node:crypto\";\nimport * as zlib from \"node:zlib\";\nimport {\n\ttype Api,\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\tcreateAssistantMessageEventStream,\n\ttype JsonObject,\n\ttype Model,\n\ttype SimpleStreamOptions,\n\ttype TranscriptContext,\n} from \"../index.ts\";\nimport { type ChatHistoryItem, type ContentPart, mapContextToChat, type ToolDef } from \"./devin-context-map.ts\";\nimport { mintUserJwt } from \"./devin-jwt.ts\";\nimport { buildMetadata } from \"./devin-metadata.ts\";\n\nimport { type ChatThinking, packThinkingSignature, unpackThinkingSignature } from \"./devin-thinking.ts\";\nimport {\n\tencodeFixed64Field,\n\tencodeMessage,\n\tencodeString,\n\tencodeVarintField,\n\tframeConnectStream,\n\titerFields,\n} from \"./devin-wire.ts\";\n\nconst SOURCE_BY_ROLE: Record<string, number> = {\n\tuser: 1,\n\tassistant: 2,\n\ttool: 4,\n};\n\nexport type CloudChatEvent =\n\t| { kind: \"text\"; text: string }\n\t| { kind: \"reasoning\"; text: string }\n\t| { kind: \"reasoning_signature\"; signature: string; signatureType?: string }\n\t| { kind: \"reasoning_redacted\" }\n\t| { kind: \"tool_call_start\"; id: string; name: string }\n\t| { kind: \"tool_call_args\"; argsDelta: string; id?: string }\n\t| { kind: \"finish\"; reason: \"stop\" | \"tool_calls\" | \"length\" | \"content_filter\" }\n\t| {\n\t\t\tkind: \"usage\";\n\t\t\tpromptTokens?: number;\n\t\t\tcompletionTokens?: number;\n\t\t\tcachedInputTokens?: number;\n\t\t\tcacheCreationInputTokens?: number;\n\t };\n\nfunction normalizeContent(content: string | ContentPart[]): ContentPart[] {\n\tif (typeof content === \"string\") return [{ type: \"text\", text: content }];\n\treturn content;\n}\n\nfunction encodeImageData(img: { mimeType?: string; base64Data?: string }): Buffer {\n\treturn Buffer.concat([encodeString(1, img.base64Data ?? \"\"), encodeString(2, img.mimeType ?? \"image/png\")]);\n}\n\nfunction encodeChatToolCall(tc: { id: string; name: string; arguments: string }): Buffer {\n\treturn Buffer.concat([encodeString(1, tc.id), encodeString(2, tc.name), encodeString(3, tc.arguments)]);\n}\n\nfunction encodeChatMessagePrompt(\n\tcontent: ContentPart[],\n\tsource: number,\n\topts?: {\n\t\ttoolCallId?: string;\n\t\ttoolCalls?: Array<{ id: string; name: string; arguments: string }>;\n\t\tthinking?: ChatThinking;\n\t},\n): Buffer {\n\tconst text = content\n\t\t.filter((part) => part.type === \"text\")\n\t\t.map((part) => part.text ?? \"\")\n\t\t.join(\"\\n\");\n\tconst parts: Buffer[] = [encodeVarintField(2, source), encodeString(3, text), encodeVarintField(5, 1)];\n\tif (opts?.toolCallId) parts.push(encodeString(7, opts.toolCallId));\n\tfor (const tc of opts?.toolCalls ?? []) parts.push(encodeMessage(6, encodeChatToolCall(tc)));\n\tfor (const img of content.filter((part) => part.type === \"image\")) {\n\t\tparts.push(encodeMessage(10, encodeImageData(img)));\n\t}\n\t// 11 thinking / 12 signature / 13 thinking_redacted / 18 signature_type — the\n\t// same quartet the Devin CLI replays so the model keeps its own reasoning.\n\tif (opts?.thinking) {\n\t\tparts.push(encodeString(11, opts.thinking.text));\n\t\tparts.push(encodeString(12, opts.thinking.signature));\n\t\tif (opts.thinking.redacted) parts.push(encodeVarintField(13, 1));\n\t\tif (opts.thinking.signatureType) parts.push(encodeString(18, opts.thinking.signatureType));\n\t}\n\treturn Buffer.concat(parts);\n}\n\n/** Mirrors the Devin CLI: num_completions / max_tokens / max_newlines plus\n * temperature / top_k / top_p, and nothing else. */\nfunction encodeCompletionConfiguration(maxOutputTokens?: number, temperature?: number): Buffer {\n\treturn Buffer.concat([\n\t\tencodeVarintField(1, 1),\n\t\tencodeVarintField(2, maxOutputTokens ?? 128_000),\n\t\tencodeVarintField(3, 400),\n\t\tencodeFixed64Field(5, temperature ?? 1.0),\n\t\tencodeVarintField(7, 40),\n\t\tencodeFixed64Field(8, 0.95),\n\t]);\n}\n\n/** CortexTrajectoryReference: cascade trajectory, user-input step. */\nfunction encodeTrajectoryReference(trajectoryId: string): Buffer {\n\treturn Buffer.concat([encodeString(1, trajectoryId), encodeVarintField(3, 4), encodeVarintField(4, 14)]);\n}\n\nfunction encodeToolDef(tool: ToolDef): Buffer {\n\tconst description = tool.description;\n\treturn Buffer.concat([\n\t\tencodeString(1, tool.name),\n\t\tencodeString(2, description),\n\t\tencodeString(3, JSON.stringify(tool.parameters ?? {})),\n\t]);\n}\n\nfunction buildGetChatMessageRequest(args: {\n\tapiKey: string;\n\tuserJwt: string;\n\tmodelUid: string;\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools?: ToolDef[];\n\tcascadeId: string;\n\ttrajectoryId: string;\n\tsessionId: string;\n\trequestId: bigint;\n\ttriggerId: string;\n\tmaxOutputTokens?: number;\n\ttemperature?: number;\n}): Buffer {\n\tconst metadata = buildMetadata({\n\t\tapiKey: args.apiKey,\n\t\tuserJwt: args.userJwt,\n\t\tsessionId: args.sessionId,\n\t\trequestId: args.requestId,\n\t\ttriggerId: args.triggerId,\n\t});\n\tconst prompts = args.messages.map((message) =>\n\t\tencodeMessage(\n\t\t\t3,\n\t\t\tencodeChatMessagePrompt(normalizeContent(message.content), SOURCE_BY_ROLE[message.role], {\n\t\t\t\ttoolCallId: message.role === \"tool\" ? message.tool_call_id : undefined,\n\t\t\t\ttoolCalls: message.role === \"assistant\" ? message.tool_calls : undefined,\n\t\t\t\tthinking: message.role === \"assistant\" ? message.thinking : undefined,\n\t\t\t}),\n\t\t),\n\t);\n\treturn Buffer.concat([\n\t\tencodeMessage(1, metadata),\n\t\t// 2 prompt — the server's system slot, same place the Devin CLI puts its own\n\t\t// system prompt. Collapsing it into the first user turn is not equivalent.\n\t\t...(args.systemPrompt ? [encodeString(2, args.systemPrompt)] : []),\n\t\t...prompts,\n\t\tencodeVarintField(7, 5),\n\t\tencodeMessage(8, encodeCompletionConfiguration(args.maxOutputTokens, args.temperature)),\n\t\t...(args.tools ?? []).map((tool) => encodeMessage(10, encodeToolDef(tool))),\n\t\tencodeMessage(15, encodeTrajectoryReference(args.trajectoryId)),\n\t\tencodeString(16, args.cascadeId),\n\t\tencodeVarintField(20, 1),\n\t\tencodeString(21, args.modelUid),\n\t]);\n}\n\nfunction* decodeChatFrame(proto: Buffer): Generator<CloudChatEvent> {\n\tlet signature: string | undefined;\n\tlet signatureType: string | undefined;\n\tfor (const field of iterFields(proto)) {\n\t\tif (field.num === 3 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) yield { kind: \"text\", text };\n\t\t} else if (field.num === 9 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) yield { kind: \"reasoning\", text };\n\t\t} else if (field.num === 11 && field.wire === 0) {\n\t\t\t// GetChatMessageResponse.thinking_redacted\n\t\t\tif (Number(field.value) !== 0) yield { kind: \"reasoning_redacted\" };\n\t\t} else if (field.num === 10 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) signature = text;\n\t\t} else if (field.num === 21 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst text = field.value.toString(\"utf8\");\n\t\t\tif (text) signatureType = text;\n\t\t} else if (field.num === 6 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tlet id: string | undefined;\n\t\t\tlet name: string | undefined;\n\t\t\tlet argsDelta: string | undefined;\n\t\t\tfor (const inner of iterFields(field.value)) {\n\t\t\t\tif (inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\t\tconst text = inner.value.toString(\"utf8\");\n\t\t\t\t\tif (inner.num === 1) id = text;\n\t\t\t\t\telse if (inner.num === 2) name = text;\n\t\t\t\t\telse if (inner.num === 3) argsDelta = text;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (id !== undefined && name !== undefined) yield { kind: \"tool_call_start\", id, name };\n\t\t\tif (argsDelta !== undefined) yield { kind: \"tool_call_args\", argsDelta, ...(id ? { id } : {}) };\n\t\t} else if (field.num === 5 && field.wire === 0) {\n\t\t\tconst value = Number(field.value);\n\t\t\tlet reason: Extract<CloudChatEvent, { kind: \"finish\" }>[\"reason\"] = \"stop\";\n\t\t\tif (value === 10) reason = \"tool_calls\";\n\t\t\telse if (value === 11) reason = \"content_filter\";\n\t\t\telse if ([1, 3, 5, 9].includes(value)) reason = \"length\";\n\t\t\telse if (![0, 2, 4, 6, 8, 12].includes(value)) throw new Error(`Devin returned failure stop reason ${value}`);\n\t\t\tyield { kind: \"finish\", reason };\n\t\t} else if (field.num === 28 && field.wire === 2 && Buffer.isBuffer(field.value)) {\n\t\t\tconst usage = decodeUsage(field.value);\n\t\t\tif (usage) yield usage;\n\t\t}\n\t}\n\t// The signature trails the thinking text, so it is yielded once the frame is\n\t// fully read and gets attached to the block that is already closed.\n\tif (signature !== undefined || signatureType !== undefined)\n\t\tyield { kind: \"reasoning_signature\", signature: signature ?? \"\", signatureType };\n}\n\nfunction decodeUsage(buf: Buffer): CloudChatEvent | null {\n\tlet promptTokens: number | undefined;\n\tlet completionTokens: number | undefined;\n\tlet cachedInputTokens: number | undefined;\n\tlet cacheCreationInputTokens: number | undefined;\n\tfor (const field of iterFields(buf)) {\n\t\tif (field.num !== 2 || field.wire !== 2 || !Buffer.isBuffer(field.value)) continue;\n\t\tlet metric: string | undefined;\n\t\tlet value: number | undefined;\n\t\tfor (const inner of iterFields(field.value)) {\n\t\t\tif (inner.num === 5 && inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\tmetric = inner.value.toString(\"utf8\");\n\t\t\t} else if (inner.num === 4 && inner.wire === 2 && Buffer.isBuffer(inner.value)) {\n\t\t\t\t// Protobuf omits the scalar field when a present numeric metric is zero.\n\t\t\t\tvalue = 0;\n\t\t\t\tfor (const dim of iterFields(inner.value)) {\n\t\t\t\t\tif (dim.num === 2 && dim.wire === 5 && Buffer.isBuffer(dim.value)) {\n\t\t\t\t\t\tvalue = dim.value.readFloatLE(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (!metric || value === undefined || !Number.isFinite(value)) continue;\n\t\tconst n = Math.round(value);\n\t\tif (metric === \"input_tokens\") promptTokens = n;\n\t\telse if (metric === \"output_tokens\") completionTokens = n;\n\t\telse if (metric === \"cached_input_tokens\" || metric === \"cache_read_input_tokens\") cachedInputTokens = n;\n\t\telse if (metric === \"cache_creation_input_tokens\") cacheCreationInputTokens = n;\n\t}\n\tif (\n\t\tpromptTokens === undefined &&\n\t\tcompletionTokens === undefined &&\n\t\tcachedInputTokens === undefined &&\n\t\tcacheCreationInputTokens === undefined\n\t)\n\t\treturn null;\n\treturn {\n\t\tkind: \"usage\",\n\t\tpromptTokens,\n\t\tcompletionTokens,\n\t\tcachedInputTokens,\n\t\tcacheCreationInputTokens,\n\t};\n}\n\nasync function* streamChatEvents(args: {\n\tapiKey: string;\n\thost: string;\n\tmodelUid: string;\n\tsystemPrompt?: string;\n\tmessages: ChatHistoryItem[];\n\ttools?: ToolDef[];\n\tmaxOutputTokens?: number;\n\tsignal?: AbortSignal;\n\tsessionId?: string;\n\tfetchImpl: typeof fetch;\n\ttemperature?: number;\n}): AsyncGenerator<CloudChatEvent> {\n\tconst host = args.host.replace(/\\/$/, \"\");\n\tconst userJwt = await mintUserJwt(args.apiKey, host, args.signal, args.fetchImpl);\n\tconst sessionId = args.sessionId ?? randomUUID();\n\tconst ids = { sessionId, cascadeId: sessionId, trajectoryId: sessionId };\n\tconst proto = buildGetChatMessageRequest({\n\t\tapiKey: args.apiKey,\n\t\tuserJwt,\n\t\tmodelUid: args.modelUid,\n\t\tsystemPrompt: args.systemPrompt,\n\t\tmessages: args.messages,\n\t\ttools: args.tools,\n\t\tcascadeId: ids.cascadeId,\n\t\ttrajectoryId: ids.trajectoryId,\n\t\tsessionId: ids.sessionId,\n\t\trequestId: BigInt(Date.now()),\n\t\ttriggerId: randomUUID(),\n\t\tmaxOutputTokens: args.maxOutputTokens,\n\t\ttemperature: args.temperature,\n\t});\n\n\tconst resp = await args.fetchImpl(`${host}/exa.api_server_pb.ApiServerService/GetChatMessage`, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/connect+proto\",\n\t\t\t\"Connect-Protocol-Version\": \"1\",\n\t\t\t\"Connect-Content-Encoding\": \"gzip\",\n\t\t\t\"Connect-Accept-Encoding\": \"gzip\",\n\t\t},\n\t\tbody: new Uint8Array(frameConnectStream(proto, true)),\n\t\tsignal: args.signal,\n\t});\n\tif (!resp.ok) {\n\t\tthrow new Error(`Devin GetChatMessage failed (HTTP ${resp.status})`);\n\t}\n\tif (!resp.body) throw new Error(\"GetChatMessage returned an empty body\");\n\n\tconst reader = resp.body.getReader();\n\t// reader.closed rejects with the stream's storedError when the socket dies\n\t// mid-response; nothing awaits it -> unhandledRejection crashes the process.\n\tvoid reader.closed.catch(() => {});\n\tconst queue: Buffer[] = [];\n\tlet queued = 0;\n\tlet sawEos = false;\n\tlet trailerError: string | null = null;\n\n\tconst peek = (n: number): Buffer | null => {\n\t\tif (queued < n) return null;\n\t\tif (queue.length === 1 && queue[0].length >= n) return queue[0].subarray(0, n);\n\t\tconst parts: Buffer[] = [];\n\t\tlet remaining = n;\n\t\tfor (const chunk of queue) {\n\t\t\tif (remaining <= 0) break;\n\t\t\tif (chunk.length <= remaining) {\n\t\t\t\tparts.push(chunk);\n\t\t\t\tremaining -= chunk.length;\n\t\t\t} else {\n\t\t\t\tparts.push(chunk.subarray(0, remaining));\n\t\t\t\tremaining = 0;\n\t\t\t}\n\t\t}\n\t\treturn Buffer.concat(parts, n);\n\t};\n\n\tconst drop = (n: number): void => {\n\t\tqueued -= n;\n\t\tlet remaining = n;\n\t\twhile (remaining > 0 && queue.length > 0) {\n\t\t\tconst head = queue[0];\n\t\t\tif (head.length <= remaining) {\n\t\t\t\tqueue.shift();\n\t\t\t\tremaining -= head.length;\n\t\t\t} else {\n\t\t\t\tqueue[0] = head.subarray(remaining);\n\t\t\t\tremaining = 0;\n\t\t\t}\n\t\t}\n\t};\n\n\ttry {\n\t\twhile (true) {\n\t\t\tconst { value, done } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tif (value) {\n\t\t\t\tqueue.push(Buffer.from(value));\n\t\t\t\tqueued += value.length;\n\t\t\t}\n\t\t\twhile (queued >= 5) {\n\t\t\t\tconst header = peek(5);\n\t\t\t\tif (!header) break;\n\t\t\t\tconst flags = header[0];\n\t\t\t\tconst len = header.readUInt32BE(1);\n\t\t\t\tif (flags & ~3) throw new Error(\"Invalid Devin Connect frame flags\");\n\t\t\t\tif (len > 16 * 1024 * 1024) throw new Error(\"Devin Connect frame exceeds 16 MiB\");\n\t\t\t\tif (queued < 5 + len) break;\n\t\t\t\tdrop(5);\n\t\t\t\tconst raw = peek(len) ?? Buffer.alloc(0);\n\t\t\t\tdrop(len);\n\t\t\t\tlet payload = raw;\n\t\t\t\tif (flags & 0x01) payload = zlib.gunzipSync(raw, { maxOutputLength: 16 * 1024 * 1024 });\n\t\t\t\tif (sawEos) throw new Error(\"Devin returned data after its EOS trailer\");\n\t\t\t\tif (flags & 0x02) {\n\t\t\t\t\tsawEos = true;\n\t\t\t\t\tconst parsed = JSON.parse(payload.toString(\"utf8\")) as { error?: { code?: string; message?: string } };\n\t\t\t\t\tif (parsed.error) {\n\t\t\t\t\t\tconst detail =\n\t\t\t\t\t\t\ttypeof parsed.error.message === \"string\"\n\t\t\t\t\t\t\t\t? parsed.error.message\n\t\t\t\t\t\t\t\t\t\t.replaceAll(args.apiKey, \"[redacted]\")\n\t\t\t\t\t\t\t\t\t\t.replaceAll(userJwt, \"[redacted]\")\n\t\t\t\t\t\t\t\t\t\t.slice(0, 500)\n\t\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\ttrailerError = `Devin stream failed (${parsed.error.code ?? \"unknown\"})${detail ? `: ${detail}` : \"\"}`;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tyield* decodeChatFrame(payload);\n\t\t\t}\n\t\t}\n\t} finally {\n\t\ttry {\n\t\t\treader.releaseLock();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t\ttry {\n\t\t\t// await: on an errored stream cancel() returns a rejected promise;\n\t\t\t// `void`-ing it escapes the try/catch as an unhandled rejection.\n\t\t\tawait resp.body?.cancel();\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\tif (trailerError) throw new Error(trailerError);\n\tif (queued) throw new Error(\"Truncated Devin Connect frame\");\n\tif (!sawEos) throw new Error(\"Devin stream ended without an EOS trailer\");\n}\n\nexport function streamDevin(\n\tmodel: Model<Api>,\n\tcontext: TranscriptContext,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\n\tvoid (async () => {\n\t\tconst output: AssistantMessage = {\n\t\t\trole: \"assistant\",\n\t\t\tcontent: [],\n\t\t\tapi: model.api,\n\t\t\tprovider: model.provider,\n\t\t\tmodel: model.id,\n\t\t\tusage: {\n\t\t\t\tinput: 0,\n\t\t\t\toutput: 0,\n\t\t\t\tcacheRead: 0,\n\t\t\t\tcacheWrite: 0,\n\t\t\t\ttotalTokens: 0,\n\t\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t\t},\n\t\t\tstopReason: \"stop\",\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\n\t\tlet textOpen = false;\n\t\tlet thinkingOpen = false;\n\t\tlet thinkingIndex = -1;\n\t\tlet toolId = \"\";\n\t\tconst toolStates = new Map<string, { index: number; json: string }>();\n\n\t\tconst closeText = () => {\n\t\t\tif (!textOpen) return;\n\t\t\tconst idx = output.content.length - 1;\n\t\t\tconst block = output.content[idx];\n\t\t\tif (block.type === \"text\") {\n\t\t\t\tstream.push({ type: \"text_end\", contentIndex: idx, content: block.text, partial: output });\n\t\t\t}\n\t\t\ttextOpen = false;\n\t\t};\n\t\tconst closeThinking = () => {\n\t\t\tif (!thinkingOpen) return;\n\t\t\tconst idx = output.content.length - 1;\n\t\t\tconst block = output.content[idx];\n\t\t\tif (block.type === \"thinking\") {\n\t\t\t\tstream.push({ type: \"thinking_end\", contentIndex: idx, content: block.thinking, partial: output });\n\t\t\t}\n\t\t\tthinkingOpen = false;\n\t\t};\n\t\tconst closeTool = () => {\n\t\t\tfor (const state of toolStates.values()) {\n\t\t\t\tconst block = output.content[state.index];\n\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\tconst parsed: unknown = JSON.parse(state.json);\n\t\t\t\t\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed))\n\t\t\t\t\t\tthrow new Error(\"Invalid Devin tool arguments\");\n\t\t\t\t\tblock.arguments = parsed as JsonObject;\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\t\tcontentIndex: state.index,\n\t\t\t\t\t\ttoolCall: block,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\ttoolStates.clear();\n\t\t};\n\n\t\ttry {\n\t\t\tconst apiKey = options?.apiKey;\n\t\t\tif (process.env.PI_SERVER_MODE === \"true\")\n\t\t\t\tthrow new Error(\"Devin inference must use pi-server in PI_SERVER_MODE\");\n\t\t\tif (!apiKey) throw new Error(\"No Devin credentials. Run /login devin.\");\n\t\t\tconst host = model.baseUrl.replace(/\\/$/, \"\");\n\t\t\tif (options?.reasoning && model.thinkingLevelMap && model.thinkingLevelMap[options.reasoning] !== model.id)\n\t\t\t\tthrow new Error(\"Select the Devin model variant for the requested reasoning effort\");\n\t\t\tif (options?.onPayload) throw new Error(\"Devin does not support onPayload overrides\");\n\t\t\tconst modelUid = model.id;\n\t\t\tconst mapped = mapContextToChat(context, model.id);\n\t\t\tstream.push({ type: \"start\", partial: output });\n\n\t\t\tfor await (const event of streamChatEvents({\n\t\t\t\tapiKey,\n\t\t\t\thost,\n\t\t\t\tmodelUid,\n\t\t\t\tsystemPrompt: mapped.systemPrompt,\n\t\t\t\tmessages: mapped.messages,\n\t\t\t\ttools: mapped.tools.length > 0 ? mapped.tools : undefined,\n\t\t\t\tmaxOutputTokens: options?.maxTokens ?? model.maxTokens,\n\t\t\t\tsignal: options?.signal\n\t\t\t\t\t? AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs ?? 600_000)])\n\t\t\t\t\t: AbortSignal.timeout(options?.timeoutMs ?? 600_000),\n\t\t\t\tsessionId: options?.sessionId,\n\t\t\t\tfetchImpl: options?.fetch ?? fetch,\n\t\t\t\ttemperature: options?.temperature,\n\t\t\t})) {\n\t\t\t\tif (event.kind === \"text\") {\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\tif (!textOpen) {\n\t\t\t\t\t\toutput.content.push({ type: \"text\", text: \"\" });\n\t\t\t\t\t\tstream.push({ type: \"text_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t\t\t\ttextOpen = true;\n\t\t\t\t\t}\n\t\t\t\t\tconst idx = output.content.length - 1;\n\t\t\t\t\tconst block = output.content[idx];\n\t\t\t\t\tif (block.type === \"text\") {\n\t\t\t\t\t\tblock.text += event.text;\n\t\t\t\t\t\tstream.push({ type: \"text_delta\", contentIndex: idx, delta: event.text, partial: output });\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning\") {\n\t\t\t\t\tcloseText();\n\t\t\t\t\tif (!thinkingOpen) {\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: output.content.length - 1, partial: output });\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t}\n\t\t\t\t\tconst idx = output.content.length - 1;\n\t\t\t\t\tconst block = output.content[idx];\n\t\t\t\t\tif (block.type === \"thinking\") {\n\t\t\t\t\t\tblock.thinking += event.text;\n\t\t\t\t\t\tstream.push({ type: \"thinking_delta\", contentIndex: idx, delta: event.text, partial: output });\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning_signature\") {\n\t\t\t\t\tif (thinkingIndex < 0) {\n\t\t\t\t\t\tcloseText();\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: thinkingIndex, partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tconst block = output.content[thinkingIndex];\n\t\t\t\t\tif (block?.type === \"thinking\") {\n\t\t\t\t\t\tconst previous = unpackThinkingSignature(block.thinkingSignature);\n\t\t\t\t\t\tblock.thinkingSignature = packThinkingSignature(\n\t\t\t\t\t\t\t(previous.signature ?? \"\") + event.signature,\n\t\t\t\t\t\t\tevent.signatureType ?? previous.signatureType,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"reasoning_redacted\") {\n\t\t\t\t\tif (thinkingIndex < 0) {\n\t\t\t\t\t\tcloseText();\n\t\t\t\t\t\toutput.content.push({ type: \"thinking\", thinking: \"\" });\n\t\t\t\t\t\tthinkingIndex = output.content.length - 1;\n\t\t\t\t\t\tthinkingOpen = true;\n\t\t\t\t\t\tstream.push({ type: \"thinking_start\", contentIndex: thinkingIndex, partial: output });\n\t\t\t\t\t}\n\t\t\t\t\tconst block = thinkingIndex >= 0 ? output.content[thinkingIndex] : undefined;\n\t\t\t\t\tif (block?.type === \"thinking\") block.redacted = true;\n\t\t\t\t} else if (event.kind === \"tool_call_start\") {\n\t\t\t\t\tcloseText();\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\ttoolId = event.id;\n\t\t\t\t\tconst existing = toolStates.get(toolId);\n\t\t\t\t\tif (existing) {\n\t\t\t\t\t\tconst block = output.content[existing.index];\n\t\t\t\t\t\tif (block.type !== \"toolCall\" || block.name !== event.name)\n\t\t\t\t\t\t\tthrow new Error(\"Devin changed a tool call's name\");\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (!toolId || !event.name) throw new Error(\"Devin returned an empty tool identity\");\n\t\t\t\t\toutput.content.push({ type: \"toolCall\", id: event.id, name: event.name, arguments: {} });\n\t\t\t\t\tconst toolIndex = output.content.length - 1;\n\t\t\t\t\ttoolStates.set(toolId, { index: toolIndex, json: \"\" });\n\t\t\t\t\tstream.push({ type: \"toolcall_start\", contentIndex: toolIndex, partial: output });\n\t\t\t\t} else if (event.kind === \"tool_call_args\") {\n\t\t\t\t\tconst state = toolStates.get(event.id ?? toolId);\n\t\t\t\t\tif (!state) throw new Error(\"Devin tool argument delta has no matching call\");\n\t\t\t\t\tstate.json += event.argsDelta;\n\t\t\t\t\tconst block = output.content[state.index];\n\t\t\t\t\tif (block.type === \"toolCall\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tblock.arguments = JSON.parse(state.json);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// incomplete json\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tstream.push({\n\t\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\t\tcontentIndex: state.index,\n\t\t\t\t\t\tdelta: event.argsDelta,\n\t\t\t\t\t\tpartial: output,\n\t\t\t\t\t});\n\t\t\t\t} else if (event.kind === \"finish\") {\n\t\t\t\t\tif (event.reason === \"content_filter\")\n\t\t\t\t\t\tthrow new Error(\"Devin response was blocked by content filtering\");\n\t\t\t\t\tcloseText();\n\t\t\t\t\tcloseThinking();\n\t\t\t\t\toutput.stopReason =\n\t\t\t\t\t\tevent.reason === \"tool_calls\" ? \"toolUse\" : event.reason === \"length\" ? \"length\" : \"stop\";\n\t\t\t\t} else if (event.kind === \"usage\") {\n\t\t\t\t\t// Metrics are reported counts, not deltas. Absent fields retain earlier reports.\n\t\t\t\t\tif (event.promptTokens !== undefined) output.usage.input = event.promptTokens;\n\t\t\t\t\tif (event.completionTokens !== undefined) output.usage.output = event.completionTokens;\n\t\t\t\t\tif (event.cachedInputTokens !== undefined) output.usage.cacheRead = event.cachedInputTokens;\n\t\t\t\t\tif (event.cacheCreationInputTokens !== undefined)\n\t\t\t\t\t\toutput.usage.cacheWrite = event.cacheCreationInputTokens;\n\t\t\t\t\toutput.usage.totalTokens =\n\t\t\t\t\t\toutput.usage.input + output.usage.output + output.usage.cacheRead + output.usage.cacheWrite;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcloseText();\n\t\t\tcloseThinking();\n\t\t\tcloseTool();\n\t\t\toptions?.signal?.throwIfAborted();\n\t\t\tif (!output.content.length) throw new Error(\"Devin returned an empty completion\");\n\t\t\tfor (const key of [\"input\", \"output\", \"cacheRead\", \"cacheWrite\"] as const) {\n\t\t\t\toutput.usage.cost[key] = (output.usage[key] * model.cost[key]) / 1_000_000;\n\t\t\t}\n\t\t\toutput.usage.cost.total =\n\t\t\t\toutput.usage.cost.input +\n\t\t\t\toutput.usage.cost.output +\n\t\t\t\toutput.usage.cost.cacheRead +\n\t\t\t\toutput.usage.cost.cacheWrite;\n\t\t\tstream.push({ type: \"done\", reason: output.stopReason as \"stop\" | \"length\" | \"toolUse\", message: output });\n\t\t\tstream.end();\n\t\t} catch (error) {\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = error instanceof Error ? error.message : String(error);\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason as \"aborted\" | \"error\", error: output });\n\t\t\tstream.end();\n\t\t}\n\t})();\n\n\treturn stream;\n}\n"]}
@@ -1 +1 @@
1
- {"schemaVersion":3,"generatedAt":"2026-09-20T15:23:27.672Z","structureHash":"618c1f6945b6722ad8ce39aad35a55c3834a67c7f7a98e71e1a762e2909b9e22","files":{"amazon-bedrock.json":"843ede349a0435b8a4228733dfde8cff3baea7c134cb46fe7409ceef1b424f9c","ant-ling.json":"4979fe79d99ed97382d7ce40170c6132e932e77906de1eb54464c042e7d63633","anthropic.json":"06034879a67b6ce37e80c91ec0894e30baff97f2640b4c4f8868180ca39eb0e9","azure-openai-responses.json":"2f42741e47dbebd8491cf40bff1de313fc2221f55e16bc02fd6e5d50b5f8fefe","baseten.json":"c71a236e1fbd57bc095dd9bf1db6a9f9588a27aa6cb4f6352697ac6682b38227","cerebras.json":"d3a3806cb44b89d16e35101300af132a3c6c27114751b1c9d9cb892365806535","cloudflare-ai-gateway.json":"b24435335ff0791aebd8f160196dcd5f82ef507a070c7ebd2af52f080d72f8e1","cloudflare-workers-ai.json":"07ef63208ff7517fd1a80962f18143e21de399640423329490b157f459ccf995","deepseek.json":"34e2b56e6676a7a9b37d6c32696e409dc2c1b042c246b59c47d1f736344e9443","fireworks.json":"94e00c4cb0dbad84aec605919bcb97419c2b7c2c5ff080fc0835cabbeddaf246","github-copilot.json":"85daa6f2999fac5ef7ddd5d3efd99e82082a2ca42bbc27418ccaa3cbdf413d9b","google-vertex.json":"5e513b89f9f7e09914fb8e3683349706d3c328c152649b9279cb384b51ae4718","google.json":"d81fcd0248d3c8650d073030c1535d59e3d850423b8139175b9d057427b9e638","groq.json":"e4728fd72e358cd8f25e9a518e9b49a521ef44523d3debe38a7db9e0663c4077","huggingface.json":"a488b6f175b382277ccf7d487f877ef0c698994576bb55d2410838bf9c8c7c41","kimi-coding.json":"202d4b9a3e3327cebb01626fb1818f92627e59800f27858902c4ce69105f0bd7","meta.json":"c3a9d3edac83109bdba2c3f65616233291d6abe7439e4597ea2d44c305fcb1e6","minimax-cn.json":"65d37e55a6d9585855f94b3fb7739308d107fe248ebd9e1001d1c5d4606ad2c4","minimax.json":"c7dc5765995ae77242916430929c7cc9a782589f7e483e13f7e01663190d028e","mistral.json":"be522597b22bceeb0bb9a0ba1781647649ffd19637d0c8e67b056d7b0ec33d52","moonshotai-cn.json":"42541779c529a1fc956cfb6f73c7409ac630395a8ace29a267c5f46d8f40264b","moonshotai.json":"ff3ae0910f462dbdbf240df116c021cd8a3bcae9563e01da0aa091d773a47351","nvidia.json":"2ff6862206269af88a694e627c4b54753055357710adaf49ac8518d102c17407","openai-codex.json":"4cc31a022b60eb6419bd00e7f4823cc944957b97838c596a2232a4e62f3fdfa0","openai.json":"1b0a4795b3c36ca34bdc1a8b407d215c3192e51a1d04b16d474d3c25c88a2713","opencode-go.json":"29d0720f79fd01af91ce1542b5fa84991967b21f68f0cb305db2682ed1c25370","opencode.json":"c9fe302ea6031bf25d55b25f59dc2ad6c83dc1135ef013cbd0670538a692f545","openrouter.json":"932a8be10c44a1fa16468247895ea09c08daac381f2b54f021aedf698cdf1cc9","qwen-token-plan-cn.json":"c6bf63501837149d212795f26da3c492472bb79062b350f8a51f4d8dc7127ed3","qwen-token-plan-individual.json":"eb040e78595853e980011308b1bf9caacae6dc8a91abbac5ffebd402515dd2a6","qwen-token-plan.json":"d72a4a85dd473bbabb380add830f280442ac3bdc00cb47b7a44a5bdd4e1952ed","radius.json":"10fc983d8f63f4ada56eac198585b20566f169d26e8109e59641b7bf649a815d","together.json":"927c707d06f2236cdab13f14c870fb58bce0614ba7287bbcd57cc9fd66d191ed","vercel-ai-gateway.json":"e4454c40314de15450de7164f131be72f462ae3a6e23aa68c4d9a89812f83aba","xai.json":"037bde3de5ea72814c3f0b79da8b244c89feb708cc0cbf8596cdfac7682477b6","xiaomi-token-plan-ams.json":"a36446cb9e3cb4f7054617676fd711092245a74f703ba89573f21d2673b85fa8","xiaomi-token-plan-cn.json":"c295dadf4097b5d86af15e924fb2a1a6342bae9e0a9a5839c9fca216308c51e5","xiaomi-token-plan-sgp.json":"93d359575c2348c97d79a2b14e1e9437199bd4aee948d58611b3fbab75cd9fb3","xiaomi.json":"f06f1011d606d22311b1f4c50eb36d38b8cd99abf5760faee657d5559e87452b","zai-coding-cn.json":"69c572aa75104f16ccbddbaace60c267f4bcc74f86d34891ca43110d312fb1ad","zai.json":"15c8182a88e58bdc1b1c3eb0603c690475342c8a826ceddfe9af1b36b28345ee"}}
1
+ {"schemaVersion":3,"generatedAt":"2026-09-21T09:16:30.397Z","structureHash":"83b4c1ff771a4dd84eaf2b736b2ea486799ec267ac54bf8ae4de92c2cbc59935","files":{"amazon-bedrock.json":"843ede349a0435b8a4228733dfde8cff3baea7c134cb46fe7409ceef1b424f9c","ant-ling.json":"4979fe79d99ed97382d7ce40170c6132e932e77906de1eb54464c042e7d63633","anthropic.json":"06034879a67b6ce37e80c91ec0894e30baff97f2640b4c4f8868180ca39eb0e9","azure-openai-responses.json":"2f42741e47dbebd8491cf40bff1de313fc2221f55e16bc02fd6e5d50b5f8fefe","baseten.json":"c71a236e1fbd57bc095dd9bf1db6a9f9588a27aa6cb4f6352697ac6682b38227","cerebras.json":"d3a3806cb44b89d16e35101300af132a3c6c27114751b1c9d9cb892365806535","cloudflare-ai-gateway.json":"b24435335ff0791aebd8f160196dcd5f82ef507a070c7ebd2af52f080d72f8e1","cloudflare-workers-ai.json":"07ef63208ff7517fd1a80962f18143e21de399640423329490b157f459ccf995","deepseek.json":"34e2b56e6676a7a9b37d6c32696e409dc2c1b042c246b59c47d1f736344e9443","fireworks.json":"94e00c4cb0dbad84aec605919bcb97419c2b7c2c5ff080fc0835cabbeddaf246","github-copilot.json":"85daa6f2999fac5ef7ddd5d3efd99e82082a2ca42bbc27418ccaa3cbdf413d9b","google-vertex.json":"5e513b89f9f7e09914fb8e3683349706d3c328c152649b9279cb384b51ae4718","google.json":"d81fcd0248d3c8650d073030c1535d59e3d850423b8139175b9d057427b9e638","groq.json":"e4728fd72e358cd8f25e9a518e9b49a521ef44523d3debe38a7db9e0663c4077","huggingface.json":"a488b6f175b382277ccf7d487f877ef0c698994576bb55d2410838bf9c8c7c41","kimi-coding.json":"202d4b9a3e3327cebb01626fb1818f92627e59800f27858902c4ce69105f0bd7","meta.json":"c3a9d3edac83109bdba2c3f65616233291d6abe7439e4597ea2d44c305fcb1e6","minimax-cn.json":"65d37e55a6d9585855f94b3fb7739308d107fe248ebd9e1001d1c5d4606ad2c4","minimax.json":"c7dc5765995ae77242916430929c7cc9a782589f7e483e13f7e01663190d028e","mistral.json":"be522597b22bceeb0bb9a0ba1781647649ffd19637d0c8e67b056d7b0ec33d52","moonshotai-cn.json":"42541779c529a1fc956cfb6f73c7409ac630395a8ace29a267c5f46d8f40264b","moonshotai.json":"ff3ae0910f462dbdbf240df116c021cd8a3bcae9563e01da0aa091d773a47351","nvidia.json":"6493e09b5db8b8fe9c8fae5bc15dc287645f37f83a4ed3a1ad1181e5830b5ff7","openai-codex.json":"4cc31a022b60eb6419bd00e7f4823cc944957b97838c596a2232a4e62f3fdfa0","openai.json":"1b0a4795b3c36ca34bdc1a8b407d215c3192e51a1d04b16d474d3c25c88a2713","opencode-go.json":"e0b87e02ada95fff56cbc261aff5bd31dce62097ad7204503f835b7b1ab542fe","opencode.json":"c9fe302ea6031bf25d55b25f59dc2ad6c83dc1135ef013cbd0670538a692f545","openrouter.json":"a545483958d29565e76f46cc4165bc4dfc3f64f875764ec91f59b901c23947e2","qwen-token-plan-cn.json":"c6bf63501837149d212795f26da3c492472bb79062b350f8a51f4d8dc7127ed3","qwen-token-plan-individual.json":"eb040e78595853e980011308b1bf9caacae6dc8a91abbac5ffebd402515dd2a6","qwen-token-plan.json":"d72a4a85dd473bbabb380add830f280442ac3bdc00cb47b7a44a5bdd4e1952ed","radius.json":"10fc983d8f63f4ada56eac198585b20566f169d26e8109e59641b7bf649a815d","together.json":"927c707d06f2236cdab13f14c870fb58bce0614ba7287bbcd57cc9fd66d191ed","vercel-ai-gateway.json":"e4454c40314de15450de7164f131be72f462ae3a6e23aa68c4d9a89812f83aba","xai.json":"037bde3de5ea72814c3f0b79da8b244c89feb708cc0cbf8596cdfac7682477b6","xiaomi-token-plan-ams.json":"a36446cb9e3cb4f7054617676fd711092245a74f703ba89573f21d2673b85fa8","xiaomi-token-plan-cn.json":"c295dadf4097b5d86af15e924fb2a1a6342bae9e0a9a5839c9fca216308c51e5","xiaomi-token-plan-sgp.json":"93d359575c2348c97d79a2b14e1e9437199bd4aee948d58611b3fbab75cd9fb3","xiaomi.json":"f06f1011d606d22311b1f4c50eb36d38b8cd99abf5760faee657d5559e87452b","zai-coding-cn.json":"69c572aa75104f16ccbddbaace60c267f4bcc74f86d34891ca43110d312fb1ad","zai.json":"15c8182a88e58bdc1b1c3eb0603c690475342c8a826ceddfe9af1b36b28345ee"}}