@tensorpass/aiconnect 0.0.0-stage → 0.1.0

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.
Files changed (124) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +18 -2
  4. package/dist/callback.d.ts +2 -0
  5. package/dist/callback.js +4 -0
  6. package/dist/callback.js.map +1 -0
  7. package/dist/chatContent.d.ts +9 -0
  8. package/dist/chatContent.js +23 -0
  9. package/dist/chatContent.js.map +1 -0
  10. package/dist/cli/loopbackSignIn.d.ts +11 -0
  11. package/dist/cli/loopbackSignIn.js +94 -0
  12. package/dist/cli/loopbackSignIn.js.map +1 -0
  13. package/dist/cli/main.d.ts +2 -0
  14. package/dist/cli/main.js +41 -0
  15. package/dist/cli/main.js.map +1 -0
  16. package/dist/cli/siteKeyCommand.d.ts +11 -0
  17. package/dist/cli/siteKeyCommand.js +31 -0
  18. package/dist/cli/siteKeyCommand.js.map +1 -0
  19. package/dist/cli/siteKeyPlacement.d.ts +3 -0
  20. package/dist/cli/siteKeyPlacement.js +56 -0
  21. package/dist/cli/siteKeyPlacement.js.map +1 -0
  22. package/dist/client.d.ts +43 -0
  23. package/dist/client.js +211 -0
  24. package/dist/client.js.map +1 -0
  25. package/dist/connectionState.d.ts +31 -0
  26. package/dist/connectionState.js +4 -0
  27. package/dist/connectionState.js.map +1 -0
  28. package/dist/guards/answerGuard.d.ts +14 -0
  29. package/dist/guards/answerGuard.js +189 -0
  30. package/dist/guards/answerGuard.js.map +1 -0
  31. package/dist/guards/chatGuard.d.ts +18 -0
  32. package/dist/guards/chatGuard.js +62 -0
  33. package/dist/guards/chatGuard.js.map +1 -0
  34. package/dist/guards/envelopes.d.ts +8 -0
  35. package/dist/guards/envelopes.js +49 -0
  36. package/dist/guards/envelopes.js.map +1 -0
  37. package/dist/guards/index.d.ts +8 -0
  38. package/dist/guards/index.js +8 -0
  39. package/dist/guards/index.js.map +1 -0
  40. package/dist/guards/policy.d.ts +28 -0
  41. package/dist/guards/policy.js +20 -0
  42. package/dist/guards/policy.js.map +1 -0
  43. package/dist/guards/questionGuard.d.ts +8 -0
  44. package/dist/guards/questionGuard.js +53 -0
  45. package/dist/guards/questionGuard.js.map +1 -0
  46. package/dist/index.d.ts +22 -0
  47. package/dist/index.js +16 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/mcpToolSource.d.ts +13 -0
  50. package/dist/mcpToolSource.js +54 -0
  51. package/dist/mcpToolSource.js.map +1 -0
  52. package/dist/toolLoop.d.ts +18 -0
  53. package/dist/toolLoop.js +153 -0
  54. package/dist/toolLoop.js.map +1 -0
  55. package/dist/types.d.ts +98 -0
  56. package/dist/types.js +6 -0
  57. package/dist/types.js.map +1 -0
  58. package/dist/visitorBrowser.d.ts +17 -0
  59. package/dist/visitorBrowser.js +72 -0
  60. package/dist/visitorBrowser.js.map +1 -0
  61. package/dist/walletProvider.d.ts +25 -0
  62. package/dist/walletProvider.js +42 -0
  63. package/dist/walletProvider.js.map +1 -0
  64. package/dist/webAccounts/finishSignIn.d.ts +2 -0
  65. package/dist/webAccounts/finishSignIn.js +46 -0
  66. package/dist/webAccounts/finishSignIn.js.map +1 -0
  67. package/dist/webAccounts/openAiCompatibleSession.d.ts +15 -0
  68. package/dist/webAccounts/openAiCompatibleSession.js +84 -0
  69. package/dist/webAccounts/openAiCompatibleSession.js.map +1 -0
  70. package/dist/webAccounts/openAiWire.d.ts +39 -0
  71. package/dist/webAccounts/openAiWire.js +133 -0
  72. package/dist/webAccounts/openAiWire.js.map +1 -0
  73. package/dist/webAccounts/openRouterAccount.d.ts +3 -0
  74. package/dist/webAccounts/openRouterAccount.js +64 -0
  75. package/dist/webAccounts/openRouterAccount.js.map +1 -0
  76. package/dist/webAccounts/pkce.d.ts +2 -0
  77. package/dist/webAccounts/pkce.js +17 -0
  78. package/dist/webAccounts/pkce.js.map +1 -0
  79. package/dist/webAccounts/serverSentEvents.d.ts +1 -0
  80. package/dist/webAccounts/serverSentEvents.js +62 -0
  81. package/dist/webAccounts/serverSentEvents.js.map +1 -0
  82. package/dist/webAccounts/signInWindow.d.ts +27 -0
  83. package/dist/webAccounts/signInWindow.js +164 -0
  84. package/dist/webAccounts/signInWindow.js.map +1 -0
  85. package/dist/webAccounts/tensorPassAccount.d.ts +9 -0
  86. package/dist/webAccounts/tensorPassAccount.js +128 -0
  87. package/dist/webAccounts/tensorPassAccount.js.map +1 -0
  88. package/dist/webAccounts/tensorPassPlan.d.ts +27 -0
  89. package/dist/webAccounts/tensorPassPlan.js +36 -0
  90. package/dist/webAccounts/tensorPassPlan.js.map +1 -0
  91. package/dist/webAccounts/webAccount.d.ts +30 -0
  92. package/dist/webAccounts/webAccount.js +19 -0
  93. package/dist/webAccounts/webAccount.js.map +1 -0
  94. package/dist/webAccounts/webAccountSource.d.ts +43 -0
  95. package/dist/webAccounts/webAccountSource.js +216 -0
  96. package/dist/webAccounts/webAccountSource.js.map +1 -0
  97. package/dist/webAccounts/webAccountStore.d.ts +27 -0
  98. package/dist/webAccounts/webAccountStore.js +84 -0
  99. package/dist/webAccounts/webAccountStore.js.map +1 -0
  100. package/dist/wireProtocols/anthropicMessages.d.ts +2 -0
  101. package/dist/wireProtocols/anthropicMessages.js +181 -0
  102. package/dist/wireProtocols/anthropicMessages.js.map +1 -0
  103. package/dist/wireProtocols/eventStream.d.ts +4 -0
  104. package/dist/wireProtocols/eventStream.js +32 -0
  105. package/dist/wireProtocols/eventStream.js.map +1 -0
  106. package/dist/wireProtocols/geminiContents.d.ts +2 -0
  107. package/dist/wireProtocols/geminiContents.js +201 -0
  108. package/dist/wireProtocols/geminiContents.js.map +1 -0
  109. package/dist/wireProtocols/openAiChat.d.ts +2 -0
  110. package/dist/wireProtocols/openAiChat.js +161 -0
  111. package/dist/wireProtocols/openAiChat.js.map +1 -0
  112. package/dist/wireProtocols/openAiResponses.d.ts +2 -0
  113. package/dist/wireProtocols/openAiResponses.js +226 -0
  114. package/dist/wireProtocols/openAiResponses.js.map +1 -0
  115. package/dist/wireProtocols/walletAnswer.d.ts +7 -0
  116. package/dist/wireProtocols/walletAnswer.js +50 -0
  117. package/dist/wireProtocols/walletAnswer.js.map +1 -0
  118. package/dist/wireProtocols/walletFetch.d.ts +3 -0
  119. package/dist/wireProtocols/walletFetch.js +101 -0
  120. package/dist/wireProtocols/walletFetch.js.map +1 -0
  121. package/dist/wireProtocols/wireProtocol.d.ts +31 -0
  122. package/dist/wireProtocols/wireProtocol.js +44 -0
  123. package/dist/wireProtocols/wireProtocol.js.map +1 -0
  124. package/package.json +56 -4
@@ -0,0 +1,161 @@
1
+ // The OpenAI chat completions protocol, as the OpenAI SDK, LangChain's ChatOpenAI, LlamaIndex and
2
+ // the Vercel AI SDK's `openai.chat()` speak it. Streamed answers go as `chat.completion.chunk`
3
+ // events ending with `[DONE]`; tool calls and the finish reason come on the last chunks.
4
+ import { textOf } from "../chatContent.js";
5
+ import { EMPTY_PARAMETERS, errorType, parseToolArguments, toolNameOf, unsupported, userContent, } from "./wireProtocol.js";
6
+ const FINISH_REASONS = {
7
+ stop: 'stop',
8
+ length: 'length',
9
+ toolCalls: 'tool_calls',
10
+ contentFilter: 'content_filter',
11
+ };
12
+ function partOf(part) {
13
+ if (part.type === 'text') {
14
+ return { type: 'text', text: part.text ?? '' };
15
+ }
16
+ if (part.type === 'refusal') {
17
+ return { type: 'text', text: part.refusal ?? '' };
18
+ }
19
+ if (part.type === 'image_url' && part.image_url) {
20
+ return { type: 'image', url: typeof part.image_url === 'string' ? part.image_url : part.image_url.url };
21
+ }
22
+ throw unsupported(`${part.type} content`);
23
+ }
24
+ function partsOf(content) {
25
+ if (typeof content === 'string') {
26
+ return content ? [{ type: 'text', text: content }] : [];
27
+ }
28
+ return (content ?? []).map(partOf);
29
+ }
30
+ function assistantMessage(message, names) {
31
+ const toolCalls = (message.tool_calls ?? []).map((call) => ({
32
+ id: call.id, name: call.function.name, arguments: parseToolArguments(call.function.arguments),
33
+ }));
34
+ toolCalls.forEach((call) => names.set(call.id, call.name));
35
+ return { role: 'assistant', content: textOf(partsOf(message.content)), ...(toolCalls.length ? { toolCalls } : {}) };
36
+ }
37
+ function readMessages(messages) {
38
+ const names = new Map();
39
+ return messages.map((message) => {
40
+ switch (message.role) {
41
+ case 'system':
42
+ case 'developer':
43
+ return { role: 'system', content: textOf(partsOf(message.content)) };
44
+ case 'user':
45
+ return { role: 'user', content: userContent(partsOf(message.content)) };
46
+ case 'assistant':
47
+ return assistantMessage(message, names);
48
+ case 'tool': {
49
+ const toolCallId = message.tool_call_id ?? '';
50
+ const content = textOf(partsOf(message.content));
51
+ return { role: 'tool', toolCallId, name: toolNameOf(names, toolCallId), content };
52
+ }
53
+ default:
54
+ throw unsupported(`${message.role} messages`);
55
+ }
56
+ });
57
+ }
58
+ function readTools(tools) {
59
+ return tools?.map((tool) => {
60
+ if (tool.type !== 'function' || !tool.function) {
61
+ throw unsupported(`${tool.type} tools`);
62
+ }
63
+ const { name, description = '', parameters = EMPTY_PARAMETERS } = tool.function;
64
+ return { name, description, inputSchema: parameters };
65
+ });
66
+ }
67
+ function readToolChoice(choice) {
68
+ return typeof choice === 'object' ? { name: choice.function.name } : choice;
69
+ }
70
+ function readFormat(format) {
71
+ if (!format || format.type === 'text') {
72
+ return undefined;
73
+ }
74
+ return { type: 'json', ...format.json_schema };
75
+ }
76
+ function read(body) {
77
+ const chat = body;
78
+ if ((chat.n ?? 1) > 1) {
79
+ throw unsupported('several choices per request');
80
+ }
81
+ return {
82
+ request: {
83
+ messages: readMessages(chat.messages ?? []),
84
+ tools: readTools(chat.tools),
85
+ options: {
86
+ maxTokens: chat.max_completion_tokens ?? chat.max_tokens,
87
+ temperature: chat.temperature,
88
+ topP: chat.top_p,
89
+ stop: typeof chat.stop === 'string' ? [chat.stop] : chat.stop,
90
+ toolChoice: readToolChoice(chat.tool_choice),
91
+ responseFormat: readFormat(chat.response_format),
92
+ },
93
+ },
94
+ stream: chat.stream === true,
95
+ includeUsage: chat.stream_options?.include_usage === true,
96
+ };
97
+ }
98
+ function wireUsage(usage) {
99
+ return {
100
+ prompt_tokens: usage.inputTokens,
101
+ completion_tokens: usage.outputTokens,
102
+ total_tokens: usage.inputTokens + usage.outputTokens,
103
+ prompt_tokens_details: { cached_tokens: usage.cachedInputTokens },
104
+ };
105
+ }
106
+ function wireToolCall(call) {
107
+ return { id: call.id, type: 'function', function: { name: call.name, arguments: JSON.stringify(call.arguments) } };
108
+ }
109
+ function chunk(context, model, delta, finish = null) {
110
+ return {
111
+ id: `chatcmpl-${context.id}`,
112
+ object: 'chat.completion.chunk',
113
+ created: context.created,
114
+ model,
115
+ choices: [{ index: 0, delta, finish_reason: finish, logprobs: null }],
116
+ };
117
+ }
118
+ async function stream(answer, write, context) {
119
+ const answering = (await answer.started).model;
120
+ write.send(chunk(context, answering, { role: 'assistant', content: '' }));
121
+ for await (const text of answer.texts()) {
122
+ write.send(chunk(context, answering, { content: text }));
123
+ }
124
+ const { message, finishReason, model, usage } = await answer.result;
125
+ // One chunk per call, as OpenAI streams them.
126
+ (message.toolCalls ?? []).forEach((call, index) => {
127
+ write.send(chunk(context, model, { tool_calls: [{ index, ...wireToolCall(call) }] }));
128
+ });
129
+ write.send(chunk(context, model, {}, FINISH_REASONS[finishReason]));
130
+ if (context.wire.includeUsage && usage) {
131
+ write.send({ ...chunk(context, model, {}), choices: [], usage: wireUsage(usage) });
132
+ }
133
+ write.send('[DONE]');
134
+ }
135
+ function body({ message, finishReason, model, usage }, context) {
136
+ const toolCalls = message.toolCalls?.length ? message.toolCalls.map(wireToolCall) : undefined;
137
+ return {
138
+ id: `chatcmpl-${context.id}`,
139
+ object: 'chat.completion',
140
+ created: context.created,
141
+ model,
142
+ choices: [{
143
+ index: 0,
144
+ message: { role: 'assistant', content: message.content || null, refusal: null, tool_calls: toolCalls },
145
+ finish_reason: FINISH_REASONS[finishReason],
146
+ logprobs: null,
147
+ }],
148
+ usage: usage ? wireUsage(usage) : undefined,
149
+ };
150
+ }
151
+ function errorBody(error) {
152
+ return { error: { message: error.message, type: errorType(error.status), param: null, code: null } };
153
+ }
154
+ export const openAiChat = {
155
+ read,
156
+ stream,
157
+ body,
158
+ error: errorBody,
159
+ streamError: (error) => ({ data: errorBody(error) }),
160
+ };
161
+ //# sourceMappingURL=openAiChat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openAiChat.js","sourceRoot":"","sources":["../../src/wireProtocols/openAiChat.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,+FAA+F;AAC/F,yFAAyF;AAEzF,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAQ3C,OAAO,EACL,gBAAgB,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,GACtF,MAAM,mBAAmB,CAAC;AA+C3B,MAAM,cAAc,GAAiC;IACnD,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,SAAS,EAAE,YAAY;IACvB,aAAa,EAAE,gBAAgB;CAChC,CAAC;AAEF,SAAS,MAAM,CAAC,IAAc;IAC5B,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;IACjD,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;IACpD,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QAChD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC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ent":["// The OpenAI chat completions protocol, as the OpenAI SDK, LangChain's ChatOpenAI, LlamaIndex and\n// the Vercel AI SDK's `openai.chat()` speak it. Streamed answers go as `chat.completion.chunk`\n// events ending with `[DONE]`; tool calls and the finish reason come on the last chunks.\n\nimport { textOf } from '../chatContent.ts';\nimport type {\n ChatMessage, ChatResponse, ContentPart, FinishReason, JsonSchema, ResponseFormat, ToolCall, ToolChoice,\n ToolDefinition, Usage,\n} from '../types.ts';\nimport type { WalletRequestError } from '../walletProvider.ts';\nimport type { EventWriter } from './eventStream.ts';\nimport type { WalletAnswer } from './walletAnswer.ts';\nimport {\n EMPTY_PARAMETERS, errorType, parseToolArguments, toolNameOf, unsupported, userContent,\n} from './wireProtocol.ts';\nimport type { AnswerContext, WireProtocol, WireRequest } from './wireProtocol.ts';\n\ninterface WirePart {\n type: string;\n text?: string;\n refusal?: string;\n image_url?: string | { url: string };\n}\n\ninterface WireToolCall {\n id: string;\n function: { name: string; arguments?: string };\n}\n\ninterface WireMessage {\n role: string;\n content?: string | WirePart[] | null;\n tool_calls?: WireToolCall[];\n tool_call_id?: string;\n}\n\ninterface WireTool {\n type: string;\n function?: { name: string; description?: string; parameters?: JsonSchema };\n}\n\ninterface WireFormat {\n type: string;\n json_schema?: { name?: string; schema?: JsonSchema; strict?: boolean };\n}\n\ninterface ChatBody {\n messages?: WireMessage[];\n tools?: WireTool[];\n tool_choice?: string | { function: { name: string } };\n response_format?: WireFormat;\n max_tokens?: number;\n max_completion_tokens?: number;\n temperature?: number;\n top_p?: number;\n stop?: string | string[];\n n?: number;\n stream?: boolean;\n stream_options?: { include_usage?: boolean };\n}\n\nconst FINISH_REASONS: Record<FinishReason, string> = {\n stop: 'stop',\n length: 'length',\n toolCalls: 'tool_calls',\n contentFilter: 'content_filter',\n};\n\nfunction partOf(part: WirePart): ContentPart {\n if (part.type === 'text') {\n return { type: 'text', text: part.text ?? '' };\n }\n if (part.type === 'refusal') {\n return { type: 'text', text: part.refusal ?? '' };\n }\n if (part.type === 'image_url' && part.image_url) {\n return { type: 'image', url: typeof part.image_url === 'string' ? part.image_url : part.image_url.url };\n }\n throw unsupported(`${part.type} content`);\n}\n\nfunction partsOf(content: WireMessage['content']): ContentPart[] {\n if (typeof content === 'string') {\n return content ? [{ type: 'text', text: content }] : [];\n }\n return (content ?? []).map(partOf);\n}\n\nfunction assistantMessage(message: WireMessage, names: Map<string, string>): ChatMessage {\n const toolCalls: ToolCall[] = (message.tool_calls ?? []).map((call) => ({\n id: call.id, name: call.function.name, arguments: parseToolArguments(call.function.arguments),\n }));\n toolCalls.forEach((call) => names.set(call.id, call.name));\n return { role: 'assistant', content: textOf(partsOf(message.content)), ...(toolCalls.length ? { toolCalls } : {}) };\n}\n\nfunction readMessages(messages: WireMessage[]): ChatMessage[] {\n const names = new Map<string, string>();\n return messages.map((message): ChatMessage => {\n switch (message.role) {\n case 'system':\n case 'developer':\n return { role: 'system', content: textOf(partsOf(message.content)) };\n case 'user':\n return { role: 'user', content: userContent(partsOf(message.content)) };\n case 'assistant':\n return assistantMessage(message, names);\n case 'tool': {\n const toolCallId = message.tool_call_id ?? '';\n const content = textOf(partsOf(message.content));\n return { role: 'tool', toolCallId, name: toolNameOf(names, toolCallId), content };\n }\n default:\n throw unsupported(`${message.role} messages`);\n }\n });\n}\n\nfunction readTools(tools?: WireTool[]): ToolDefinition[] | undefined {\n return tools?.map((tool) => {\n if (tool.type !== 'function' || !tool.function) {\n throw unsupported(`${tool.type} tools`);\n }\n const { name, description = '', parameters = EMPTY_PARAMETERS } = tool.function;\n return { name, description, inputSchema: parameters };\n });\n}\n\nfunction readToolChoice(choice: ChatBody['tool_choice']): ToolChoice | undefined {\n return typeof choice === 'object' ? { name: choice.function.name } : choice as ToolChoice | undefined;\n}\n\nfunction readFormat(format?: WireFormat): ResponseFormat | undefined {\n if (!format || format.type === 'text') {\n return undefined;\n }\n return { type: 'json', ...format.json_schema };\n}\n\nfunction read(body: Record<string, unknown>): WireRequest {\n const chat = body as ChatBody;\n if ((chat.n ?? 1) > 1) {\n throw unsupported('several choices per request');\n }\n return {\n request: {\n messages: readMessages(chat.messages ?? []),\n tools: readTools(chat.tools),\n options: {\n maxTokens: chat.max_completion_tokens ?? chat.max_tokens,\n temperature: chat.temperature,\n topP: chat.top_p,\n stop: typeof chat.stop === 'string' ? [chat.stop] : chat.stop,\n toolChoice: readToolChoice(chat.tool_choice),\n responseFormat: readFormat(chat.response_format),\n },\n },\n stream: chat.stream === true,\n includeUsage: chat.stream_options?.include_usage === true,\n };\n}\n\nfunction wireUsage(usage: Usage) {\n return {\n prompt_tokens: usage.inputTokens,\n completion_tokens: usage.outputTokens,\n total_tokens: usage.inputTokens + usage.outputTokens,\n prompt_tokens_details: { cached_tokens: usage.cachedInputTokens },\n };\n}\n\nfunction wireToolCall(call: ToolCall) {\n return { id: call.id, type: 'function', function: { name: call.name, arguments: JSON.stringify(call.arguments) } };\n}\n\nfunction chunk(context: AnswerContext, model: string, delta: Record<string, unknown>, finish: string | null = null) {\n return {\n id: `chatcmpl-${context.id}`,\n object: 'chat.completion.chunk',\n created: context.created,\n model,\n choices: [{ index: 0, delta, finish_reason: finish, logprobs: null }],\n };\n}\n\nasync function stream(answer: WalletAnswer, write: EventWriter, context: AnswerContext): Promise<void> {\n const answering = (await answer.started).model;\n write.send(chunk(context, answering, { role: 'assistant', content: '' }));\n for await (const text of answer.texts()) {\n write.send(chunk(context, answering, { content: text }));\n }\n const { message, finishReason, model, usage } = await answer.result;\n // One chunk per call, as OpenAI streams them.\n (message.toolCalls ?? []).forEach((call, index) => {\n write.send(chunk(context, model, { tool_calls: [{ index, ...wireToolCall(call) }] }));\n });\n write.send(chunk(context, model, {}, FINISH_REASONS[finishReason]));\n if (context.wire.includeUsage && usage) {\n write.send({ ...chunk(context, model, {}), choices: [], usage: wireUsage(usage) });\n }\n write.send('[DONE]');\n}\n\nfunction body({ message, finishReason, model, usage }: ChatResponse, context: AnswerContext) {\n const toolCalls = message.toolCalls?.length ? message.toolCalls.map(wireToolCall) : undefined;\n return {\n id: `chatcmpl-${context.id}`,\n object: 'chat.completion',\n created: context.created,\n model,\n choices: [{\n index: 0,\n message: { role: 'assistant', content: message.content || null, refusal: null, tool_calls: toolCalls },\n finish_reason: FINISH_REASONS[finishReason],\n logprobs: null,\n }],\n usage: usage ? wireUsage(usage) : undefined,\n };\n}\n\nfunction errorBody(error: WalletRequestError) {\n return { error: { message: error.message, type: errorType(error.status), param: null, code: null } };\n}\n\nexport const openAiChat: WireProtocol = {\n read,\n stream,\n body,\n error: errorBody,\n streamError: (error) => ({ data: errorBody(error) }),\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import type { WireProtocol } from './wireProtocol.ts';
2
+ export declare const openAiResponses: WireProtocol;
@@ -0,0 +1,226 @@
1
+ // The OpenAI Responses protocol, the default path of the Vercel AI SDK's `openai()` models and of
2
+ // the OpenAI SDK's `responses` API. The wallet keeps no conversation, so a request carries its
3
+ // whole input. Streamed answers go as typed events: the message item and its text deltas, one item
4
+ // per tool call, then `response.completed` with the usage.
5
+ import { textOf } from "../chatContent.js";
6
+ import { EMPTY_PARAMETERS, errorType, parseToolArguments, toolNameOf, unsupported, userContent, } from "./wireProtocol.js";
7
+ function partOf(part) {
8
+ if (part.type === 'input_text' || part.type === 'output_text') {
9
+ return { type: 'text', text: part.text ?? '' };
10
+ }
11
+ if (part.type === 'refusal') {
12
+ return { type: 'text', text: part.refusal ?? '' };
13
+ }
14
+ if (part.type === 'input_image' && part.image_url) {
15
+ return { type: 'image', url: part.image_url };
16
+ }
17
+ throw unsupported(`${part.type} content`);
18
+ }
19
+ function partsOf(content) {
20
+ if (typeof content === 'string') {
21
+ return content ? [{ type: 'text', text: content }] : [];
22
+ }
23
+ return (content ?? []).map(partOf);
24
+ }
25
+ // A function call joins the assistant turn just before it, as the provider produced them together.
26
+ function readFunctionCall({ messages, names }, item) {
27
+ const call = {
28
+ id: item.call_id ?? '', name: item.name ?? '', arguments: parseToolArguments(item.arguments),
29
+ };
30
+ names.set(call.id, call.name);
31
+ const last = messages.at(-1);
32
+ if (last?.role === 'assistant') {
33
+ last.toolCalls = [...(last.toolCalls ?? []), call];
34
+ }
35
+ else {
36
+ messages.push({ role: 'assistant', content: '', toolCalls: [call] });
37
+ }
38
+ }
39
+ function readMessage(item) {
40
+ const parts = partsOf(item.content);
41
+ switch (item.role) {
42
+ case 'system':
43
+ case 'developer':
44
+ return { role: 'system', content: textOf(parts) };
45
+ case 'user':
46
+ return { role: 'user', content: userContent(parts) };
47
+ case 'assistant':
48
+ return { role: 'assistant', content: textOf(parts) };
49
+ default:
50
+ throw unsupported(`${item.role} messages`);
51
+ }
52
+ }
53
+ // Reasoning items hold the provider's own thinking, which another account cannot read.
54
+ function readItem(reading, item) {
55
+ if (item.type === 'function_call') {
56
+ readFunctionCall(reading, item);
57
+ }
58
+ else if (item.type === 'function_call_output') {
59
+ const toolCallId = item.call_id ?? '';
60
+ const content = textOf(partsOf(item.output));
61
+ reading.messages.push({ role: 'tool', toolCallId, name: toolNameOf(reading.names, toolCallId), content });
62
+ }
63
+ else if (item.type === undefined || item.type === 'message') {
64
+ reading.messages.push(readMessage(item));
65
+ }
66
+ else if (item.type !== 'reasoning') {
67
+ throw unsupported(`${item.type} input items`);
68
+ }
69
+ }
70
+ function readInput(body) {
71
+ const reading = { messages: [], names: new Map() };
72
+ if (body.instructions) {
73
+ reading.messages.push({ role: 'system', content: body.instructions });
74
+ }
75
+ const items = typeof body.input === 'string' ? [{ role: 'user', content: body.input }] : body.input ?? [];
76
+ items.forEach((item) => readItem(reading, item));
77
+ return reading.messages;
78
+ }
79
+ function readTools(tools) {
80
+ return tools?.map((tool) => {
81
+ if (tool.type !== 'function' || !tool.name) {
82
+ throw unsupported(`${tool.type} tools`);
83
+ }
84
+ return { name: tool.name, description: tool.description ?? '', inputSchema: tool.parameters ?? EMPTY_PARAMETERS };
85
+ });
86
+ }
87
+ function readToolChoice(choice) {
88
+ if (typeof choice !== 'object') {
89
+ return choice;
90
+ }
91
+ if (choice.type !== 'function' || !choice.name) {
92
+ throw unsupported(`a ${choice.type} tool choice`);
93
+ }
94
+ return { name: choice.name };
95
+ }
96
+ function readFormat(format) {
97
+ if (!format || format.type === 'text') {
98
+ return undefined;
99
+ }
100
+ return { type: 'json', name: format.name, schema: format.schema, strict: format.strict };
101
+ }
102
+ function read(raw) {
103
+ const body = raw;
104
+ if (body.previous_response_id) {
105
+ throw unsupported('previous_response_id: send the whole conversation, AI Wallet keeps none');
106
+ }
107
+ return {
108
+ request: {
109
+ messages: readInput(body),
110
+ tools: readTools(body.tools),
111
+ options: {
112
+ maxTokens: body.max_output_tokens,
113
+ temperature: body.temperature,
114
+ topP: body.top_p,
115
+ toolChoice: readToolChoice(body.tool_choice),
116
+ responseFormat: readFormat(body.text?.format),
117
+ },
118
+ },
119
+ stream: body.stream === true,
120
+ };
121
+ }
122
+ function messageItem(id, text) {
123
+ return {
124
+ id, type: 'message', status: 'completed', role: 'assistant',
125
+ content: [{ type: 'output_text', text, annotations: [] }],
126
+ };
127
+ }
128
+ function functionCallItem(call) {
129
+ return {
130
+ id: `fc_${call.id}`, type: 'function_call', status: 'completed',
131
+ call_id: call.id, name: call.name, arguments: JSON.stringify(call.arguments),
132
+ };
133
+ }
134
+ function wireUsage(usage) {
135
+ if (!usage) {
136
+ return null;
137
+ }
138
+ const { inputTokens, outputTokens, cachedInputTokens } = usage;
139
+ return {
140
+ input_tokens: inputTokens,
141
+ input_tokens_details: { cached_tokens: cachedInputTokens },
142
+ output_tokens: outputTokens,
143
+ total_tokens: inputTokens + outputTokens,
144
+ };
145
+ }
146
+ function responseObject(context, model, response, output = []) {
147
+ const incomplete = response?.finishReason === 'length' || response?.finishReason === 'contentFilter';
148
+ const reason = response?.finishReason === 'length' ? 'max_output_tokens' : 'content_filter';
149
+ return {
150
+ id: `resp_${context.id}`,
151
+ object: 'response',
152
+ created_at: context.created,
153
+ status: response ? (incomplete ? 'incomplete' : 'completed') : 'in_progress',
154
+ model,
155
+ output,
156
+ error: null,
157
+ incomplete_details: incomplete ? { reason } : null,
158
+ usage: wireUsage(response?.usage),
159
+ };
160
+ }
161
+ function outputItems(context, { message }) {
162
+ const text = message.content ? [messageItem(`msg_${context.id}`, message.content)] : [];
163
+ return [...text, ...(message.toolCalls ?? []).map(functionCallItem)];
164
+ }
165
+ // Each event carries its type and a sequence number, as the provider numbers them.
166
+ function eventSender(write) {
167
+ let sequence = 0;
168
+ return (type, fields) => {
169
+ write.send({ type, sequence_number: sequence, ...fields }, type);
170
+ sequence += 1;
171
+ };
172
+ }
173
+ function writeMessageEnd(send, id, text) {
174
+ const part = { type: 'output_text', text, annotations: [] };
175
+ send('response.output_text.done', { item_id: id, output_index: 0, content_index: 0, text, logprobs: [] });
176
+ send('response.content_part.done', { item_id: id, output_index: 0, content_index: 0, part });
177
+ send('response.output_item.done', { output_index: 0, item: messageItem(id, text) });
178
+ }
179
+ function writeFunctionCall(send, call, index) {
180
+ const item = functionCallItem(call);
181
+ send('response.output_item.added', { output_index: index, item: { ...item, status: 'in_progress', arguments: '' } });
182
+ send('response.function_call_arguments.delta', { item_id: item.id, output_index: index, delta: item.arguments });
183
+ send('response.function_call_arguments.done', { item_id: item.id, output_index: index, arguments: item.arguments });
184
+ send('response.output_item.done', { output_index: index, item });
185
+ }
186
+ async function stream(answer, write, context) {
187
+ const send = eventSender(write);
188
+ const id = `msg_${context.id}`;
189
+ send('response.created', { response: responseObject(context, (await answer.started).model) });
190
+ let streamed = false;
191
+ for await (const delta of answer.texts()) {
192
+ if (!streamed) {
193
+ const part = { type: 'output_text', text: '', annotations: [] };
194
+ const item = { ...messageItem(id, ''), status: 'in_progress', content: [] };
195
+ send('response.output_item.added', { output_index: 0, item });
196
+ send('response.content_part.added', { item_id: id, output_index: 0, content_index: 0, part });
197
+ streamed = true;
198
+ }
199
+ send('response.output_text.delta', { item_id: id, output_index: 0, content_index: 0, delta, logprobs: [] });
200
+ }
201
+ const response = await answer.result;
202
+ if (streamed) {
203
+ writeMessageEnd(send, id, response.message.content);
204
+ }
205
+ const offset = streamed ? 1 : 0;
206
+ (response.message.toolCalls ?? []).forEach((call, index) => writeFunctionCall(send, call, index + offset));
207
+ const final = responseObject(context, response.model, response, outputItems(context, response));
208
+ send(final.status === 'completed' ? 'response.completed' : 'response.incomplete', { response: final });
209
+ }
210
+ function body(response, context) {
211
+ return responseObject(context, response.model, response, outputItems(context, response));
212
+ }
213
+ function errorBody(error) {
214
+ return { error: { message: error.message, type: errorType(error.status), param: null, code: null } };
215
+ }
216
+ export const openAiResponses = {
217
+ read,
218
+ stream,
219
+ body,
220
+ error: errorBody,
221
+ streamError: (error) => ({
222
+ data: { type: 'error', code: errorType(error.status), message: error.message, param: null },
223
+ event: 'error',
224
+ }),
225
+ };
226
+ //# sourceMappingURL=openAiResponses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openAiResponses.js","sourceRoot":"","sources":["../../src/wireProtocols/openAiResponses.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,+FAA+F;AAC/F,mGAAmG;AACnG,2DAA2D;AAE3D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAQ3C,OAAO,EACL,gBAAgB,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,GACtF,MAAM,mBAAmB,CAAC;AA8C3B,SAAS,MAAM,CAAC,IAAe;IAC7B,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;QAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;IACjD,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;IACpD,CAAC;IACD,IAAI,IAA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,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;AACvG,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAiB;IAC3C,IAAI;IACJ,MAAM;IACN,IAAI;IACJ,KAAK,EAAE,SAAS;IAChB,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE;QAC3F,KAAK,EAAE,OAAO;KACf,CAAC;CACH,CAAC","sourcesContent":["// The OpenAI Responses protocol, the default path of the Vercel AI SDK's `openai()` models and of\n// the OpenAI SDK's `responses` API. The wallet keeps no conversation, so a request carries its\n// whole input. Streamed answers go as typed events: the message item and its text deltas, one item\n// per tool call, then `response.completed` with the usage.\n\nimport { textOf } from '../chatContent.ts';\nimport type {\n AssistantMessage, ChatMessage, ChatResponse, ContentPart, JsonSchema, ResponseFormat, ToolCall, ToolChoice,\n ToolDefinition, Usage,\n} from '../types.ts';\nimport type { WalletRequestError } from '../walletProvider.ts';\nimport type { EventWriter } from './eventStream.ts';\nimport type { WalletAnswer } from './walletAnswer.ts';\nimport {\n EMPTY_PARAMETERS, errorType, parseToolArguments, toolNameOf, unsupported, userContent,\n} from './wireProtocol.ts';\nimport type { AnswerContext, WireProtocol, WireRequest } from './wireProtocol.ts';\n\ninterface InputPart {\n type: string;\n text?: string;\n refusal?: string;\n image_url?: string;\n}\n\ninterface InputItem {\n type?: string;\n role?: string;\n content?: string | InputPart[];\n call_id?: string;\n name?: string;\n arguments?: string;\n output?: string | InputPart[];\n}\n\ninterface WireTool {\n type: string;\n name?: string;\n description?: string;\n parameters?: JsonSchema;\n}\n\ninterface ResponsesBody {\n input?: string | InputItem[];\n instructions?: string;\n tools?: WireTool[];\n tool_choice?: string | { type: string; name?: string };\n text?: { format?: { type: string; name?: string; schema?: JsonSchema; strict?: boolean } };\n max_output_tokens?: number;\n temperature?: number;\n top_p?: number;\n previous_response_id?: string;\n stream?: boolean;\n}\n\n// The conversation being read, with the name of each tool call for the results that answer it.\ninterface Reading {\n messages: ChatMessage[];\n names: Map<string, string>;\n}\n\nfunction partOf(part: InputPart): ContentPart {\n if (part.type === 'input_text' || part.type === 'output_text') {\n return { type: 'text', text: part.text ?? '' };\n }\n if (part.type === 'refusal') {\n return { type: 'text', text: part.refusal ?? '' };\n }\n if (part.type === 'input_image' && part.image_url) {\n return { type: 'image', url: part.image_url };\n }\n throw unsupported(`${part.type} content`);\n}\n\nfunction partsOf(content: string | InputPart[] | undefined): ContentPart[] {\n if (typeof content === 'string') {\n return content ? [{ type: 'text', text: content }] : [];\n }\n return (content ?? []).map(partOf);\n}\n\n// A function call joins the assistant turn just before it, as the provider produced them together.\nfunction readFunctionCall({ messages, names }: Reading, item: InputItem): void {\n const call: ToolCall = {\n id: item.call_id ?? '', name: item.name ?? '', arguments: parseToolArguments(item.arguments),\n };\n names.set(call.id, call.name);\n const last = messages.at(-1);\n if (last?.role === 'assistant') {\n last.toolCalls = [...(last.toolCalls ?? []), call];\n } else {\n messages.push({ role: 'assistant', content: '', toolCalls: [call] });\n }\n}\n\nfunction readMessage(item: InputItem): ChatMessage {\n const parts = partsOf(item.content);\n switch (item.role) {\n case 'system':\n case 'developer':\n return { role: 'system', content: textOf(parts) };\n case 'user':\n return { role: 'user', content: userContent(parts) };\n case 'assistant':\n return { role: 'assistant', content: textOf(parts) } satisfies AssistantMessage;\n default:\n throw unsupported(`${item.role} messages`);\n }\n}\n\n// Reasoning items hold the provider's own thinking, which another account cannot read.\nfunction readItem(reading: Reading, item: InputItem): void {\n if (item.type === 'function_call') {\n readFunctionCall(reading, item);\n } else if (item.type === 'function_call_output') {\n const toolCallId = item.call_id ?? '';\n const content = textOf(partsOf(item.output));\n reading.messages.push({ role: 'tool', toolCallId, name: toolNameOf(reading.names, toolCallId), content });\n } else if (item.type === undefined || item.type === 'message') {\n reading.messages.push(readMessage(item));\n } else if (item.type !== 'reasoning') {\n throw unsupported(`${item.type} input items`);\n }\n}\n\nfunction readInput(body: ResponsesBody): ChatMessage[] {\n const reading: Reading = { messages: [], names: new Map() };\n if (body.instructions) {\n reading.messages.push({ role: 'system', content: body.instructions });\n }\n const items = typeof body.input === 'string' ? [{ role: 'user', content: body.input }] : body.input ?? [];\n items.forEach((item) => readItem(reading, item));\n return reading.messages;\n}\n\nfunction readTools(tools?: WireTool[]): ToolDefinition[] | undefined {\n return tools?.map((tool) => {\n if (tool.type !== 'function' || !tool.name) {\n throw unsupported(`${tool.type} tools`);\n }\n return { name: tool.name, description: tool.description ?? '', inputSchema: tool.parameters ?? EMPTY_PARAMETERS };\n });\n}\n\nfunction readToolChoice(choice: ResponsesBody['tool_choice']): ToolChoice | undefined {\n if (typeof choice !== 'object') {\n return choice as ToolChoice | undefined;\n }\n if (choice.type !== 'function' || !choice.name) {\n throw unsupported(`a ${choice.type} tool choice`);\n }\n return { name: choice.name };\n}\n\nfunction readFormat(format: NonNullable<ResponsesBody['text']>['format']): ResponseFormat | undefined {\n if (!format || format.type === 'text') {\n return undefined;\n }\n return { type: 'json', name: format.name, schema: format.schema, strict: format.strict };\n}\n\nfunction read(raw: Record<string, unknown>): WireRequest {\n const body = raw as ResponsesBody;\n if (body.previous_response_id) {\n throw unsupported('previous_response_id: send the whole conversation, AI Wallet keeps none');\n }\n return {\n request: {\n messages: readInput(body),\n tools: readTools(body.tools),\n options: {\n maxTokens: body.max_output_tokens,\n temperature: body.temperature,\n topP: body.top_p,\n toolChoice: readToolChoice(body.tool_choice),\n responseFormat: readFormat(body.text?.format),\n },\n },\n stream: body.stream === true,\n };\n}\n\nfunction messageItem(id: string, text: string) {\n return {\n id, type: 'message', status: 'completed', role: 'assistant',\n content: [{ type: 'output_text', text, annotations: [] }],\n };\n}\n\nfunction functionCallItem(call: ToolCall) {\n return {\n id: `fc_${call.id}`, type: 'function_call', status: 'completed',\n call_id: call.id, name: call.name, arguments: JSON.stringify(call.arguments),\n };\n}\n\nfunction wireUsage(usage: Usage | undefined) {\n if (!usage) {\n return null;\n }\n const { inputTokens, outputTokens, cachedInputTokens } = usage;\n return {\n input_tokens: inputTokens,\n input_tokens_details: { cached_tokens: cachedInputTokens },\n output_tokens: outputTokens,\n total_tokens: inputTokens + outputTokens,\n };\n}\n\nfunction responseObject(context: AnswerContext, model: string, response?: ChatResponse, output: unknown[] = []) {\n const incomplete = response?.finishReason === 'length' || response?.finishReason === 'contentFilter';\n const reason = response?.finishReason === 'length' ? 'max_output_tokens' : 'content_filter';\n return {\n id: `resp_${context.id}`,\n object: 'response',\n created_at: context.created,\n status: response ? (incomplete ? 'incomplete' : 'completed') : 'in_progress',\n model,\n output,\n error: null,\n incomplete_details: incomplete ? { reason } : null,\n usage: wireUsage(response?.usage),\n };\n}\n\nfunction outputItems(context: AnswerContext, { message }: ChatResponse) {\n const text = message.content ? [messageItem(`msg_${context.id}`, message.content)] : [];\n return [...text, ...(message.toolCalls ?? []).map(functionCallItem)];\n}\n\n// Each event carries its type and a sequence number, as the provider numbers them.\nfunction eventSender(write: EventWriter) {\n let sequence = 0;\n return (type: string, fields: Record<string, unknown>) => {\n write.send({ type, sequence_number: sequence, ...fields }, type);\n sequence += 1;\n };\n}\n\nfunction writeMessageEnd(send: ReturnType<typeof eventSender>, id: string, text: string): void {\n const part = { type: 'output_text', text, annotations: [] };\n send('response.output_text.done', { item_id: id, output_index: 0, content_index: 0, text, logprobs: [] });\n send('response.content_part.done', { item_id: id, output_index: 0, content_index: 0, part });\n send('response.output_item.done', { output_index: 0, item: messageItem(id, text) });\n}\n\nfunction writeFunctionCall(send: ReturnType<typeof eventSender>, call: ToolCall, index: number): void {\n const item = functionCallItem(call);\n send('response.output_item.added', { output_index: index, item: { ...item, status: 'in_progress', arguments: '' } });\n send('response.function_call_arguments.delta', { item_id: item.id, output_index: index, delta: item.arguments });\n send('response.function_call_arguments.done', { item_id: item.id, output_index: index, arguments: item.arguments });\n send('response.output_item.done', { output_index: index, item });\n}\n\nasync function stream(answer: WalletAnswer, write: EventWriter, context: AnswerContext): Promise<void> {\n const send = eventSender(write);\n const id = `msg_${context.id}`;\n send('response.created', { response: responseObject(context, (await answer.started).model) });\n let streamed = false;\n for await (const delta of answer.texts()) {\n if (!streamed) {\n const part = { type: 'output_text', text: '', annotations: [] };\n const item = { ...messageItem(id, ''), status: 'in_progress', content: [] };\n send('response.output_item.added', { output_index: 0, item });\n send('response.content_part.added', { item_id: id, output_index: 0, content_index: 0, part });\n streamed = true;\n }\n send('response.output_text.delta', { item_id: id, output_index: 0, content_index: 0, delta, logprobs: [] });\n }\n const response = await answer.result;\n if (streamed) {\n writeMessageEnd(send, id, response.message.content);\n }\n const offset = streamed ? 1 : 0;\n (response.message.toolCalls ?? []).forEach((call, index) => writeFunctionCall(send, call, index + offset));\n const final = responseObject(context, response.model, response, outputItems(context, response));\n send(final.status === 'completed' ? 'response.completed' : 'response.incomplete', { response: final });\n}\n\nfunction body(response: ChatResponse, context: AnswerContext) {\n return responseObject(context, response.model, response, outputItems(context, response));\n}\n\nfunction errorBody(error: WalletRequestError) {\n return { error: { message: error.message, type: errorType(error.status), param: null, code: null } };\n}\n\nexport const openAiResponses: WireProtocol = {\n read,\n stream,\n body,\n error: errorBody,\n streamError: (error) => ({\n data: { type: 'error', code: errorType(error.status), message: error.message, param: null },\n event: 'error',\n }),\n};\n"]}
@@ -0,0 +1,7 @@
1
+ import type { ChatRequest, ChatResponse, ChatStart, ProviderSession } from '../types.ts';
2
+ export interface WalletAnswer {
3
+ started: Promise<ChatStart>;
4
+ texts(): AsyncGenerator<string>;
5
+ result: Promise<ChatResponse>;
6
+ }
7
+ export declare function askWallet(session: ProviderSession, request: Omit<ChatRequest, 'onStart' | 'onText'>): WalletAnswer;
@@ -0,0 +1,50 @@
1
+ // The wallet's answer as a protocol reads it: who answers, the text as it streams, then the full
2
+ // result. The wallet names who answers before the first text and before the result, so a protocol
3
+ // whose stream names the model in its first event writes the model that answers. An answer that
4
+ // fails before the wallet named anyone fails its start too, so the failure can still become an
5
+ // HTTP error.
6
+ import { WalletRequestError } from "../walletProvider.js";
7
+ const UNNAMED = 'AI Wallet answered without naming the account that answers';
8
+ export function askWallet(session, request) {
9
+ const queue = [];
10
+ let settled = false;
11
+ let wake = () => { };
12
+ let start = () => { };
13
+ let fail = () => { };
14
+ const started = new Promise((resolve, reject) => {
15
+ start = resolve;
16
+ fail = reject;
17
+ });
18
+ // A whole answer never reads its start, which must not leave the failure unhandled.
19
+ started.catch(() => undefined);
20
+ const result = session.chat({
21
+ ...request,
22
+ onStart: start,
23
+ onText: (delta) => {
24
+ queue.push(delta);
25
+ wake();
26
+ },
27
+ });
28
+ const settle = () => {
29
+ settled = true;
30
+ wake();
31
+ };
32
+ result.then(settle, settle);
33
+ // Once the start is set, neither of these changes it.
34
+ result.then(() => fail(new WalletRequestError(UNNAMED, 502)), fail);
35
+ async function* texts() {
36
+ for (;;) {
37
+ while (queue.length) {
38
+ yield queue.shift();
39
+ }
40
+ if (settled) {
41
+ return;
42
+ }
43
+ await new Promise((resolve) => {
44
+ wake = resolve;
45
+ });
46
+ }
47
+ }
48
+ return { started, texts, result };
49
+ }
50
+ //# sourceMappingURL=walletAnswer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walletAnswer.js","sourceRoot":"","sources":["../../src/wireProtocols/walletAnswer.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,kGAAkG;AAClG,gGAAgG;AAChG,+FAA+F;AAC/F,cAAc;AAGd,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAQ1D,MAAM,OAAO,GAAG,4DAA4D,CAAC;AAE7E,MAAM,UAAU,SAAS,CAAC,OAAwB,EAAE,OAAgD;IAClG,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,I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jB,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AACpC,CAAC","sourcesContent":["// The wallet's answer as a protocol reads it: who answers, the text as it streams, then the full\n// result. The wallet names who answers before the first text and before the result, so a protocol\n// whose stream names the model in its first event writes the model that answers. An answer that\n// fails before the wallet named anyone fails its start too, so the failure can still become an\n// HTTP error.\n\nimport type { ChatRequest, ChatResponse, ChatStart, ProviderSession } from '../types.ts';\nimport { WalletRequestError } from '../walletProvider.ts';\n\nexport interface WalletAnswer {\n started: Promise<ChatStart>;\n texts(): AsyncGenerator<string>;\n result: Promise<ChatResponse>;\n}\n\nconst UNNAMED = 'AI Wallet answered without naming the account that answers';\n\nexport function askWallet(session: ProviderSession, request: Omit<ChatRequest, 'onStart' | 'onText'>): WalletAnswer {\n const queue: string[] = [];\n let settled = false;\n let wake = () => {};\n let start: (answering: ChatStart) => void = () => {};\n let fail: (error: unknown) => void = () => {};\n const started = new Promise<ChatStart>((resolve, reject) => {\n start = resolve;\n fail = reject;\n });\n // A whole answer never reads its start, which must not leave the failure unhandled.\n started.catch(() => undefined);\n const result = session.chat({\n ...request,\n onStart: start,\n onText: (delta) => {\n queue.push(delta);\n wake();\n },\n });\n const settle = () => {\n settled = true;\n wake();\n };\n result.then(settle, settle);\n // Once the start is set, neither of these changes it.\n result.then(() => fail(new WalletRequestError(UNNAMED, 502)), fail);\n\n async function* texts(): AsyncGenerator<string> {\n for (;;) {\n while (queue.length) {\n yield queue.shift()!;\n }\n if (settled) {\n return;\n }\n await new Promise<void>((resolve) => {\n wake = resolve;\n });\n }\n }\n\n return { started, texts, result };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { ProviderSession } from '../types.ts';
2
+ export type WalletFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
3
+ export declare function createWalletFetch(connectedSession: () => Promise<ProviderSession>): WalletFetch;
@@ -0,0 +1,101 @@
1
+ // A `fetch` for the AI SDKs. It recognises the protocol an SDK speaks from the path of its request,
2
+ // reads the request into the wallet's chat format, asks the wallet, and answers in the same
3
+ // protocol, streamed or whole. Nothing reaches the network: the host the SDK targets does not
4
+ // matter, and its API key is never read. An answer that fails before any text comes back as an
5
+ // HTTP error with the wallet's status, so each SDK raises its own typed error.
6
+ import { WalletRequestError } from "../walletProvider.js";
7
+ import { anthropicMessages } from "./anthropicMessages.js";
8
+ import { eventStream } from "./eventStream.js";
9
+ import { geminiContents } from "./geminiContents.js";
10
+ import { openAiChat } from "./openAiChat.js";
11
+ import { openAiResponses } from "./openAiResponses.js";
12
+ import { askWallet } from "./walletAnswer.js";
13
+ const ROUTES = [
14
+ { path: /\/chat\/completions$/, protocol: openAiChat },
15
+ { path: /\/responses$/, protocol: openAiResponses },
16
+ { path: /\/messages$/, protocol: anthropicMessages },
17
+ { path: /:(stream)?generateContent$/i, protocol: geminiContents },
18
+ ];
19
+ const JSON_HEADERS = { 'content-type': 'application/json' };
20
+ function protocolFor(request, url) {
21
+ return request.method === 'POST' ? ROUTES.find((route) => route.path.test(url.pathname))?.protocol : undefined;
22
+ }
23
+ function jsonResponse(status, body) {
24
+ return new Response(JSON.stringify(body), { status, headers: JSON_HEADERS });
25
+ }
26
+ // An endpoint the wallet does not answer, in the error shape the OpenAI, Anthropic and Google
27
+ // SDKs all read.
28
+ function notAnswered(request, url) {
29
+ const message = `AI Wallet answers chat requests only, not ${request.method} ${url.pathname}`;
30
+ return jsonResponse(404, { type: 'error', error: { type: 'not_found_error', message, code: 404 } });
31
+ }
32
+ // The wallet's errors carry their status; anything else is a failure of the page itself.
33
+ function walletError(error) {
34
+ const { message, status } = error;
35
+ return new WalletRequestError(message ?? String(error), typeof status === 'number' ? status : 500);
36
+ }
37
+ // The SDK's body may be a stream, which a request built from it must read in half duplex.
38
+ function asRequest(input, init) {
39
+ const streamed = init?.body instanceof ReadableStream;
40
+ return new Request(input, streamed ? { ...init, duplex: 'half' } : init);
41
+ }
42
+ async function jsonBody(request) {
43
+ try {
44
+ return await request.json();
45
+ }
46
+ catch {
47
+ throw new WalletRequestError('The request body is not JSON', 400);
48
+ }
49
+ }
50
+ function streamResponse(protocol, answer, context, stop) {
51
+ const body = eventStream(async (writer) => {
52
+ try {
53
+ await protocol.stream(answer, writer, context);
54
+ }
55
+ catch (error) {
56
+ if (!protocol.streamError || error?.name === 'AbortError') {
57
+ throw error;
58
+ }
59
+ const { data, event } = protocol.streamError(walletError(error));
60
+ writer.send(data, event);
61
+ }
62
+ }, stop);
63
+ return new Response(body, { status: 200, headers: { 'content-type': 'text/event-stream' } });
64
+ }
65
+ async function answer(protocol, wire, session, signal) {
66
+ // Stopped by the SDK's signal, or by the SDK cancelling the stream it reads.
67
+ const controller = new AbortController();
68
+ signal.addEventListener('abort', () => controller.abort(signal.reason), { once: true });
69
+ const stop = () => controller.abort(new DOMException('The SDK stopped reading the answer', 'AbortError'));
70
+ const context = { id: crypto.randomUUID(), created: Math.floor(Date.now() / 1000), wire };
71
+ const walletAnswer = askWallet(session, { ...wire.request, signal: controller.signal });
72
+ if (!wire.stream) {
73
+ return jsonResponse(200, protocol.body(await walletAnswer.result, context));
74
+ }
75
+ // The stream opens once the wallet names who answers; a failure before that is an HTTP error.
76
+ await walletAnswer.started;
77
+ return streamResponse(protocol, walletAnswer, context, stop);
78
+ }
79
+ export function createWalletFetch(connectedSession) {
80
+ return async (input, init) => {
81
+ const request = asRequest(input, init);
82
+ request.signal.throwIfAborted();
83
+ const url = new URL(request.url);
84
+ const protocol = protocolFor(request, url);
85
+ if (!protocol) {
86
+ return notAnswered(request, url);
87
+ }
88
+ try {
89
+ const wire = protocol.read(await jsonBody(request), url);
90
+ return await answer(protocol, wire, await connectedSession(), request.signal);
91
+ }
92
+ catch (error) {
93
+ if (request.signal.aborted) {
94
+ throw request.signal.reason;
95
+ }
96
+ const failure = walletError(error);
97
+ return jsonResponse(failure.status, protocol.error(failure));
98
+ }
99
+ };
100
+ }
101
+ //# sourceMappingURL=walletFetch.js.map