@molecule/api-ai-openai 1.3.0 → 1.4.1
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.
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +6 -2
- package/dist/responses.d.ts +18 -9
- package/dist/responses.d.ts.map +1 -1
- package/dist/responses.js +117 -13
- package/package.json +2 -2
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EACV,UAAU,EAGV,SAAS,EAET,UAAU,EAEX,MAAM,kBAAkB,CAAA;AAQzB,OAAO,KAAK,EAAa,YAAY,EAAE,MAAM,YAAY,CAAA;AAkCzD;;GAEG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,QAAQ,CAAC,IAAI,YAAW;IACxB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,WAAW,CAAC,CAAqB;IACzC,OAAO,CAAC,GAAG,CAAW;gBAEV,MAAM,GAAE,YAAiB;IAsBrC;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;IAgEhC;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EACV,UAAU,EAGV,SAAS,EAET,UAAU,EAEX,MAAM,kBAAkB,CAAA;AAQzB,OAAO,KAAK,EAAa,YAAY,EAAE,MAAM,YAAY,CAAA;AAkCzD;;GAEG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,QAAQ,CAAC,IAAI,YAAW;IACxB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,WAAW,CAAC,CAAqB;IACzC,OAAO,CAAC,GAAG,CAAW;gBAEV,MAAM,GAAE,YAAiB;IAsBrC;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;IAgEhC;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC;IA6HzD;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,cAAc;IA+DtB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IA6BnB,uEAAuE;IACvE,OAAO,CAAC,WAAW;IAWnB;;;;;OAKG;IACH,OAAO,CAAE,yBAAyB;IA8ClC;;;;;OAKG;YACY,sBAAsB;IA4ErC;;;;;;OAMG;IACH,OAAO,CAAE,eAAe;CAqEzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,UAAU,CAEhE"}
|
package/dist/provider.js
CHANGED
|
@@ -240,10 +240,14 @@ export class OpenaiAIProvider {
|
|
|
240
240
|
}
|
|
241
241
|
if (!useStream) {
|
|
242
242
|
const data = (await response.json());
|
|
243
|
-
yield* isResponses
|
|
243
|
+
yield* isResponses
|
|
244
|
+
? parseResponsesNonStreaming(data, model)
|
|
245
|
+
: this.parseNonStreamingResponse(data);
|
|
244
246
|
return;
|
|
245
247
|
}
|
|
246
|
-
yield* isResponses
|
|
248
|
+
yield* isResponses
|
|
249
|
+
? parseResponsesStream(response, model)
|
|
250
|
+
: this.parseStreamingResponse(response);
|
|
247
251
|
}
|
|
248
252
|
/**
|
|
249
253
|
* Convert internal `ChatMessage` objects to the OpenAI message format.
|
package/dist/responses.d.ts
CHANGED
|
@@ -11,10 +11,16 @@
|
|
|
11
11
|
* server-side tools (`web_search`). Verified live 2026-09-24.
|
|
12
12
|
*
|
|
13
13
|
* Requests are stateless (`store: false`): the full conversation is sent each
|
|
14
|
-
* time, as with chat/completions.
|
|
15
|
-
* `function_call`
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* time, as with chat/completions. A prior tool call is replayed as a
|
|
15
|
+
* `function_call` item rebuilt from its `tool_use` block, preceded by the
|
|
16
|
+
* reasoning and `web_search_call` items the model produced before it. Those
|
|
17
|
+
* travel in the tool call's `signature` (the provider-opaque replay token
|
|
18
|
+
* callers persist with each `tool_use`), and reasoning is requested in its
|
|
19
|
+
* encrypted form so it survives without server-side storage. Without them the
|
|
20
|
+
* model cannot see that it already searched: after a tool result it searched
|
|
21
|
+
* again and re-issued the same call, turn after turn (reproduced live
|
|
22
|
+
* 2026-09-26 on gpt-6-luna and gpt-6-astra; replaying them ended the loop).
|
|
23
|
+
* Reasoning is only replayed to the model that produced it.
|
|
18
24
|
*
|
|
19
25
|
* @module
|
|
20
26
|
*/
|
|
@@ -41,12 +47,14 @@ export declare function buildResponsesBody(params: ChatParams, model: string, ma
|
|
|
41
47
|
/**
|
|
42
48
|
* Convert `ChatMessage`s to Responses API input items. Text and images become
|
|
43
49
|
* message items; `tool_use` blocks become `function_call` items and
|
|
44
|
-
* `tool_result` blocks `function_call_output` items, in block order.
|
|
50
|
+
* `tool_result` blocks `function_call_output` items, in block order. A tool
|
|
51
|
+
* call's replay items (see the module docs) go immediately before it.
|
|
45
52
|
*
|
|
46
53
|
* @param messages - The conversation.
|
|
54
|
+
* @param model - The model this request targets.
|
|
47
55
|
* @returns The `input` array.
|
|
48
56
|
*/
|
|
49
|
-
export declare function formatResponsesInput(messages: ChatMessage[]): Array<Record<string, unknown>>;
|
|
57
|
+
export declare function formatResponsesInput(messages: ChatMessage[], model: string): Array<Record<string, unknown>>;
|
|
50
58
|
/**
|
|
51
59
|
* Convert function tools and provider-native server tools to the Responses
|
|
52
60
|
* API `tools` array.
|
|
@@ -69,20 +77,21 @@ export declare function formatResponsesTools(tools: AITool[], serverTools: Serve
|
|
|
69
77
|
* @param usage - The `usage` object of a completed response.
|
|
70
78
|
* @returns The normalized usage.
|
|
71
79
|
*/
|
|
72
|
-
export declare function responsesUsage(usage: ResponsesUsage | undefined | null): TokenUsage;
|
|
80
|
+
export declare function responsesUsage(usage: ResponsesUsage | undefined | null, webSearchCalls?: number): TokenUsage;
|
|
73
81
|
/**
|
|
74
82
|
* Parse a non-streaming `/v1/responses` result.
|
|
75
83
|
*
|
|
76
84
|
* @param data - The parsed JSON response body.
|
|
77
85
|
* @yields {ChatEvent} Text, tool-use, and done events.
|
|
78
86
|
*/
|
|
79
|
-
export declare function parseResponsesNonStreaming(data: Record<string, unknown
|
|
87
|
+
export declare function parseResponsesNonStreaming(data: Record<string, unknown>, model: string): Iterable<ChatEvent>;
|
|
80
88
|
/**
|
|
81
89
|
* Parse a streaming SSE response from `/v1/responses`.
|
|
82
90
|
*
|
|
83
91
|
* @param response - The fetch Response whose body is an SSE stream.
|
|
92
|
+
* @param model - The model the request targeted.
|
|
84
93
|
* @yields {ChatEvent} Text, tool-call progress, tool-use, keep-alive, and done events.
|
|
85
94
|
*/
|
|
86
|
-
export declare function parseResponsesStream(response: Response): AsyncIterable<ChatEvent>;
|
|
95
|
+
export declare function parseResponsesStream(response: Response, model: string): AsyncIterable<ChatEvent>;
|
|
87
96
|
export {};
|
|
88
97
|
//# sourceMappingURL=responses.d.ts.map
|
package/dist/responses.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../src/responses.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../src/responses.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EACV,MAAM,EACN,SAAS,EACT,WAAW,EACX,UAAU,EAEV,UAAU,EACV,UAAU,EACX,MAAM,kBAAkB,CAAA;AA6EzB,8DAA8D;AAC9D,UAAU,cAAc;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,oBAAoB,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,kBAAkB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAC/E;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,OAAO,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA6BzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,MAAM,GACZ,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgDhC;AA6BD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,UAAU,EAAE,GACxB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAWhC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,EACxC,cAAc,SAAI,GACjB,UAAU,CAUZ;AAiBD;;;;;GAKG;AACH,wBAAiB,0BAA0B,CACzC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,MAAM,GACZ,QAAQ,CAAC,SAAS,CAAC,CA2BrB;AAED;;;;;;GAMG;AACH,wBAAuB,oBAAoB,CACzC,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,MAAM,GACZ,aAAa,CAAC,SAAS,CAAC,CA4J1B"}
|
package/dist/responses.js
CHANGED
|
@@ -11,16 +11,86 @@
|
|
|
11
11
|
* server-side tools (`web_search`). Verified live 2026-09-24.
|
|
12
12
|
*
|
|
13
13
|
* Requests are stateless (`store: false`): the full conversation is sent each
|
|
14
|
-
* time, as with chat/completions.
|
|
15
|
-
* `function_call`
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* time, as with chat/completions. A prior tool call is replayed as a
|
|
15
|
+
* `function_call` item rebuilt from its `tool_use` block, preceded by the
|
|
16
|
+
* reasoning and `web_search_call` items the model produced before it. Those
|
|
17
|
+
* travel in the tool call's `signature` (the provider-opaque replay token
|
|
18
|
+
* callers persist with each `tool_use`), and reasoning is requested in its
|
|
19
|
+
* encrypted form so it survives without server-side storage. Without them the
|
|
20
|
+
* model cannot see that it already searched: after a tool result it searched
|
|
21
|
+
* again and re-issued the same call, turn after turn (reproduced live
|
|
22
|
+
* 2026-09-26 on gpt-6-luna and gpt-6-astra; replaying them ended the loop).
|
|
23
|
+
* Reasoning is only replayed to the model that produced it.
|
|
18
24
|
*
|
|
19
25
|
* @module
|
|
20
26
|
*/
|
|
21
27
|
import { getLogger } from '@molecule/api-bond';
|
|
22
28
|
import { streamErrorEvent } from './utilities.js';
|
|
23
29
|
const logger = getLogger();
|
|
30
|
+
/** Prefix marking a `tool_use.signature` that carries Responses API items to replay. */
|
|
31
|
+
const REPLAY_PREFIX = 'openai-responses-items:v1:';
|
|
32
|
+
/** Output item types replayed ahead of the function call they preceded. */
|
|
33
|
+
const REPLAYED_ITEM_TYPES = new Set(['reasoning', 'web_search_call']);
|
|
34
|
+
/**
|
|
35
|
+
* Collects the reasoning and web search items that precede each function call
|
|
36
|
+
* in a response, so they can ride on that call's `signature`.
|
|
37
|
+
*/
|
|
38
|
+
class ReplayItems {
|
|
39
|
+
model;
|
|
40
|
+
items = [];
|
|
41
|
+
/**
|
|
42
|
+
* Start an empty collector for one response.
|
|
43
|
+
*
|
|
44
|
+
* @param model - The model producing the response (reasoning is model-bound).
|
|
45
|
+
*/
|
|
46
|
+
constructor(model) {
|
|
47
|
+
this.model = model;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Record an output item if it is one that must be replayed.
|
|
51
|
+
*
|
|
52
|
+
* @param item - A completed output item.
|
|
53
|
+
*/
|
|
54
|
+
add(item) {
|
|
55
|
+
if (REPLAYED_ITEM_TYPES.has(String(item.type)))
|
|
56
|
+
this.items.push(item);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The `signature` partial for the next function call, emptying the buffer.
|
|
60
|
+
*
|
|
61
|
+
* @returns `{ signature }` when items preceded the call, else `{}`.
|
|
62
|
+
*/
|
|
63
|
+
take() {
|
|
64
|
+
if (this.items.length === 0)
|
|
65
|
+
return {};
|
|
66
|
+
const signature = REPLAY_PREFIX + JSON.stringify({ model: this.model, items: this.items });
|
|
67
|
+
this.items = [];
|
|
68
|
+
return { signature };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The items to replay ahead of a prior tool call, decoded from its signature.
|
|
73
|
+
* A signature from another provider (no prefix) yields nothing; reasoning from
|
|
74
|
+
* a different model is dropped, since encrypted reasoning is bound to the model
|
|
75
|
+
* that produced it, while its web search items are kept.
|
|
76
|
+
*
|
|
77
|
+
* @param signature - The stored `tool_use.signature`.
|
|
78
|
+
* @param model - The model this request targets.
|
|
79
|
+
* @returns The items to place before the `function_call`.
|
|
80
|
+
*/
|
|
81
|
+
function replayedItems(signature, model) {
|
|
82
|
+
if (!signature?.startsWith(REPLAY_PREFIX))
|
|
83
|
+
return [];
|
|
84
|
+
try {
|
|
85
|
+
const payload = JSON.parse(signature.slice(REPLAY_PREFIX.length));
|
|
86
|
+
const items = Array.isArray(payload.items) ? payload.items : [];
|
|
87
|
+
return payload.model === model ? items : items.filter((i) => i.type !== 'reasoning');
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
logger.warn('Dropping an unreadable OpenAI replay signature', { error });
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
24
94
|
/**
|
|
25
95
|
* Build the request body for `POST /v1/responses`.
|
|
26
96
|
*
|
|
@@ -38,9 +108,11 @@ export function buildResponsesBody(params, model, maxTokens, useStream) {
|
|
|
38
108
|
...(params.extraBody ?? {}),
|
|
39
109
|
...(params.endUserId ? { safety_identifier: params.endUserId } : {}),
|
|
40
110
|
model,
|
|
41
|
-
input: formatResponsesInput(params.messages),
|
|
111
|
+
input: formatResponsesInput(params.messages, model),
|
|
42
112
|
max_output_tokens: maxTokens,
|
|
43
113
|
store: false,
|
|
114
|
+
// Encrypted reasoning, so it can be replayed without server-side storage.
|
|
115
|
+
include: ['reasoning.encrypted_content'],
|
|
44
116
|
};
|
|
45
117
|
if (params.system)
|
|
46
118
|
body.instructions = params.system;
|
|
@@ -65,12 +137,14 @@ export function buildResponsesBody(params, model, maxTokens, useStream) {
|
|
|
65
137
|
/**
|
|
66
138
|
* Convert `ChatMessage`s to Responses API input items. Text and images become
|
|
67
139
|
* message items; `tool_use` blocks become `function_call` items and
|
|
68
|
-
* `tool_result` blocks `function_call_output` items, in block order.
|
|
140
|
+
* `tool_result` blocks `function_call_output` items, in block order. A tool
|
|
141
|
+
* call's replay items (see the module docs) go immediately before it.
|
|
69
142
|
*
|
|
70
143
|
* @param messages - The conversation.
|
|
144
|
+
* @param model - The model this request targets.
|
|
71
145
|
* @returns The `input` array.
|
|
72
146
|
*/
|
|
73
|
-
export function formatResponsesInput(messages) {
|
|
147
|
+
export function formatResponsesInput(messages, model) {
|
|
74
148
|
const out = [];
|
|
75
149
|
for (const m of messages) {
|
|
76
150
|
if (m.role === 'system') {
|
|
@@ -94,6 +168,7 @@ export function formatResponsesInput(messages) {
|
|
|
94
168
|
switch (block.type) {
|
|
95
169
|
case 'tool_use':
|
|
96
170
|
flush();
|
|
171
|
+
out.push(...replayedItems(block.signature, model));
|
|
97
172
|
out.push({
|
|
98
173
|
type: 'function_call',
|
|
99
174
|
call_id: block.id,
|
|
@@ -176,7 +251,7 @@ export function formatResponsesTools(tools, serverTools) {
|
|
|
176
251
|
* @param usage - The `usage` object of a completed response.
|
|
177
252
|
* @returns The normalized usage.
|
|
178
253
|
*/
|
|
179
|
-
export function responsesUsage(usage) {
|
|
254
|
+
export function responsesUsage(usage, webSearchCalls = 0) {
|
|
180
255
|
const cached = usage?.input_tokens_details?.cached_tokens ?? 0;
|
|
181
256
|
const written = usage?.input_tokens_details?.cache_write_tokens ?? 0;
|
|
182
257
|
return {
|
|
@@ -184,6 +259,7 @@ export function responsesUsage(usage) {
|
|
|
184
259
|
outputTokens: usage?.output_tokens ?? 0,
|
|
185
260
|
cacheReadInputTokens: cached,
|
|
186
261
|
...(written > 0 ? { cacheCreationInputTokens: written } : {}),
|
|
262
|
+
...(webSearchCalls > 0 ? { webSearchRequests: webSearchCalls } : {}),
|
|
187
263
|
};
|
|
188
264
|
}
|
|
189
265
|
/**
|
|
@@ -207,9 +283,14 @@ function parseArgs(args) {
|
|
|
207
283
|
* @param data - The parsed JSON response body.
|
|
208
284
|
* @yields {ChatEvent} Text, tool-use, and done events.
|
|
209
285
|
*/
|
|
210
|
-
export function* parseResponsesNonStreaming(data) {
|
|
286
|
+
export function* parseResponsesNonStreaming(data, model) {
|
|
211
287
|
const output = data.output ?? [];
|
|
288
|
+
const replay = new ReplayItems(model);
|
|
289
|
+
let webSearchCalls = 0;
|
|
212
290
|
for (const item of output) {
|
|
291
|
+
if (item.type === 'web_search_call')
|
|
292
|
+
webSearchCalls++;
|
|
293
|
+
replay.add(item);
|
|
213
294
|
if (item.type === 'message') {
|
|
214
295
|
for (const part of item.content ?? []) {
|
|
215
296
|
if (part.type === 'output_text' && typeof part.text === 'string' && part.text.length > 0) {
|
|
@@ -223,18 +304,23 @@ export function* parseResponsesNonStreaming(data) {
|
|
|
223
304
|
id: String(item.call_id ?? ''),
|
|
224
305
|
name: String(item.name ?? ''),
|
|
225
306
|
input: parseArgs(item.arguments),
|
|
307
|
+
...replay.take(),
|
|
226
308
|
};
|
|
227
309
|
}
|
|
228
310
|
}
|
|
229
|
-
yield {
|
|
311
|
+
yield {
|
|
312
|
+
type: 'done',
|
|
313
|
+
usage: responsesUsage(data.usage, webSearchCalls),
|
|
314
|
+
};
|
|
230
315
|
}
|
|
231
316
|
/**
|
|
232
317
|
* Parse a streaming SSE response from `/v1/responses`.
|
|
233
318
|
*
|
|
234
319
|
* @param response - The fetch Response whose body is an SSE stream.
|
|
320
|
+
* @param model - The model the request targeted.
|
|
235
321
|
* @yields {ChatEvent} Text, tool-call progress, tool-use, keep-alive, and done events.
|
|
236
322
|
*/
|
|
237
|
-
export async function* parseResponsesStream(response) {
|
|
323
|
+
export async function* parseResponsesStream(response, model) {
|
|
238
324
|
const reader = response.body?.getReader();
|
|
239
325
|
if (!reader) {
|
|
240
326
|
yield {
|
|
@@ -249,6 +335,12 @@ export async function* parseResponsesStream(response) {
|
|
|
249
335
|
let usage = null;
|
|
250
336
|
/** Function calls in progress, keyed by output item id. */
|
|
251
337
|
const calls = new Map();
|
|
338
|
+
const replay = new ReplayItems(model);
|
|
339
|
+
/**
|
|
340
|
+
* `web_search_call` items started — OpenAI bills each one. Counted when the
|
|
341
|
+
* call starts so a stream cut mid-search still meters it.
|
|
342
|
+
*/
|
|
343
|
+
let webSearchCalls = 0;
|
|
252
344
|
/**
|
|
253
345
|
* Turn one SSE data payload into zero or more ChatEvents.
|
|
254
346
|
*
|
|
@@ -272,7 +364,15 @@ export async function* parseResponsesStream(response) {
|
|
|
272
364
|
}
|
|
273
365
|
return;
|
|
274
366
|
case 'response.output_item.added':
|
|
275
|
-
if (item?.type === '
|
|
367
|
+
if (item?.type === 'web_search_call') {
|
|
368
|
+
webSearchCalls++;
|
|
369
|
+
// Metering snapshot: the search is billed even if the turn is cut.
|
|
370
|
+
yield {
|
|
371
|
+
type: 'usage',
|
|
372
|
+
usage: { inputTokens: 0, outputTokens: 0, webSearchRequests: webSearchCalls },
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
else if (item?.type === 'function_call') {
|
|
276
376
|
const callId = String(item.call_id ?? '');
|
|
277
377
|
const name = String(item.name ?? '');
|
|
278
378
|
calls.set(String(item.id ?? ''), { callId, name });
|
|
@@ -299,13 +399,17 @@ export async function* parseResponsesStream(response) {
|
|
|
299
399
|
id: String(item.call_id ?? ''),
|
|
300
400
|
name: String(item.name ?? ''),
|
|
301
401
|
input: parseArgs(item.arguments),
|
|
402
|
+
...replay.take(),
|
|
302
403
|
};
|
|
303
404
|
}
|
|
405
|
+
else if (item) {
|
|
406
|
+
replay.add(item);
|
|
407
|
+
}
|
|
304
408
|
return;
|
|
305
409
|
case 'response.completed':
|
|
306
410
|
case 'response.incomplete': {
|
|
307
411
|
const res = event.response;
|
|
308
|
-
usage = responsesUsage(res?.usage);
|
|
412
|
+
usage = responsesUsage(res?.usage, webSearchCalls);
|
|
309
413
|
if (event.type === 'response.incomplete') {
|
|
310
414
|
logger.warn('OpenAI response incomplete', { details: res?.incomplete_details });
|
|
311
415
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-ai-openai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/api-ai-openai",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"directory": "packages/api/bonds/ai/openai"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@molecule/api-ai": "1.
|
|
36
|
+
"@molecule/api-ai": "1.3.0",
|
|
37
37
|
"@molecule/api-bond": "1.0.2",
|
|
38
38
|
"@types/node": "26.1.2",
|
|
39
39
|
"typescript": "6.0.3",
|