@alvin0/ai-agent-sdk-protocol-responses 0.1.15 → 0.1.17
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/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +116 -20
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -355,6 +355,13 @@ interface ResponsesReasoningState {
|
|
|
355
355
|
encryptedContent?: string;
|
|
356
356
|
/** Summary paragraphs, in order. */
|
|
357
357
|
summary?: readonly string[];
|
|
358
|
+
/**
|
|
359
|
+
* Raw reasoning paragraphs (`reasoning_text` parts), in order. Open-weight
|
|
360
|
+
* servers (vLLM, gpt-oss, gateways in front of DeepSeek/Qwen) return the
|
|
361
|
+
* thoughts themselves instead of an encrypted blob, and expect them back the
|
|
362
|
+
* same way.
|
|
363
|
+
*/
|
|
364
|
+
content?: readonly string[];
|
|
358
365
|
}
|
|
359
366
|
//#endregion
|
|
360
367
|
//#region src/serialize.d.ts
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/contract.ts","../src/wire.ts","../src/protocol.ts","../src/serialize-types.ts","../src/serialize.ts","../src/translate.ts"],"mappings":";;;;UAGiB;WACN,SAAS;;WAET;;;UAIM;WACN;WACA;;;KAIC,sBACR,QAAQ;WAAwB;;WACrB;WAAwB,OAAO;;;UAG7B,mBAAmB;WACzB;WACA,gBAAgB;EACzB,aAAa,SAAS,iBAAiB,SAAS;EAChD,iBAAiB,SAAS,UAAU;EACpC,UAAU,SAAS,iBAAiB,SAAS,oBAAoB;EACjE,UACE,QAAQ,cAAc,mBACtB,SAAS,iBACT,sBACC,eAAe;;;;;;;;;;;;;;;;;;;KCfR;;KAGA;EACN;EAAoB;;EACpB;EAAqB;EAAmB,SAAS;;EACjD;EAAqB;EAAiB,SAAS;;;;;;;EAK/C;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D,mBAAmB,SAAS,qBAAqB,SAAS;WAC1D,YACP,SAAS,wBACT,SAAS,qBACN,SAAS;WACL,YACP,QAAQ,cAAc,mBACtB,SAAS,wBACT,wBACG,eAAe;;;cAIT,yBAAyB,mBAAmB,oBACrD;;;;;;;UCnEa;;EAEf;;EAEA;;EAEA;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/contract.ts","../src/wire.ts","../src/protocol.ts","../src/serialize-types.ts","../src/serialize.ts","../src/translate.ts"],"mappings":";;;;UAGiB;WACN,SAAS;;WAET;;;UAIM;WACN;WACA;;;KAIC,sBACR,QAAQ;WAAwB;;WACrB;WAAwB,OAAO;;;UAG7B,mBAAmB;WACzB;WACA,gBAAgB;EACzB,aAAa,SAAS,iBAAiB,SAAS;EAChD,iBAAiB,SAAS,UAAU;EACpC,UAAU,SAAS,iBAAiB,SAAS,oBAAoB;EACjE,UACE,QAAQ,cAAc,mBACtB,SAAS,iBACT,sBACC,eAAe;;;;;;;;;;;;;;;;;;;KCfR;;KAGA;EACN;EAAoB;;EACpB;EAAqB;EAAmB,SAAS;;EACjD;EAAqB;EAAiB,SAAS;;;;;;;EAK/C;EAAoB;EAAkB;;EACtC;EAAoB;;EACpB;EAAoB;;EACpB;EAAqB;EAAc,cAAc;;UAEtC;EACf;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;;;UAIe;EACf;EACA;;;;;;;;;;;KAYU;EAER;EACA;EACA,SAAS;EACT;;EAGA;;EAEA;EACA;;EAEA;;EAEA;;EAGA;EACA;;EAEA,iBAAiB;;EAGjB;EACA;EACA,SAAS;EACT,UAAU;;;;;;;EAOV;;;EAIA;EACA;EACA;EACA;;;EAIA;EACA;EACA;EACA;;;UAIa;EACf;EACA;EACA;EACA;EACA,YAAY;;UAGG;EACf;GACC;;KAGS,WAAW,mBAAmB;;KAG9B;EAIN;EAAkB;;EAClB;;;UAGW;EACf;EACA;;;UAIe;EACf,SAAS;EACT;;KAGU;EACN;;EAEF;EACA;EACA,QAAQ,SAAS;EACjB;;;UAIa;EACf;;EAEA;EACA,OAAO;EACP,QAAQ;EACR,cAAc;EACd;EACA,YAAY;EACZ,OAAO;;EAEP;EACA;;EAEA;;EAEA;EACA;EACA;EACA;;;UAIe;;EAEf;;EAEA;;;UAIe;EACf;;;UAIe;EACf;EACA,uBAAuB;EACvB;EACA,wBAAwB;EACxB;;;UAIe;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;UAIe;EACf;EACA;EACA;;;UAIe;EACf;;;UAIe;EACf;EACA;EACA,QAAQ;EACR,QAAQ;EACR,qBAAqB;;;UAIN;EACf;EACA,WAAW;EACX,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EAEA;EACA;;;;;;;;;UAUe;;;;;;;WAON;;WAEA;;WAEA;;;;;WAKA;;WAEA;;WAEA;;WAEA;;;;;;;;WAQA;;;;;cCjRE;UAmBH,+BAA+B;WAC9B,OAAO;WACP;aACE;aACA,SAAS,SAAS;;;;UAKd;WACN;WACA;WACA;WACA,gBAAgB;WAChB,eAAe;WACf,eAAe,SAAS,wBAAwB,SAAS;WACzD,mBAAmB,SAAS,qBAAqB,SAAS;WAC1D,YACP,SAAS,wBACT,SAAS,qBACN,SAAS;WACL,YACP,QAAQ,cAAc,mBACtB,SAAS,wBACT,wBACG,eAAe;;;cAIT,yBAAyB,mBAAmB,oBACrD;;;;;;;UCnEa;;EAEf;;EAEA;;EAEA;;;;;;;EAOA;;;;iBCec,0BAA0B,SAAS,iBAAiB,SAAS,mBAAmB;;;iBCNzE,yBACrB,QAAQ,cAAc,mBAAmB,qBAAqB,UAAU,kBACvE,eAAe"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONTEXT_WINDOW_EXCEEDED_CODE, MODEL_ERROR_CODES, ModelError, QUOTA_EXCEEDED_CODE, ToolCallId, isJsonValue, isNativeToolSchema } from "@alvin0/ai-agent-sdk-core";
|
|
1
|
+
import { CONTEXT_WINDOW_EXCEEDED_CODE, MODEL_ERROR_CODES, ModelError, QUOTA_EXCEEDED_CODE, TextAccumulator, ToolCallId, isJsonValue, isNativeToolSchema } from "@alvin0/ai-agent-sdk-core";
|
|
2
2
|
|
|
3
3
|
//#region src/request-content.ts
|
|
4
4
|
const DEFAULT_DOCUMENT_FILENAME = "document.pdf";
|
|
@@ -8,9 +8,16 @@ function reasoningStateOf(value) {
|
|
|
8
8
|
return {
|
|
9
9
|
...typeof state.id === "string" ? { id: state.id } : {},
|
|
10
10
|
...typeof state.encryptedContent === "string" ? { encryptedContent: state.encryptedContent } : {},
|
|
11
|
-
...Array.isArray(state.summary) ? { summary: state.summary } : {}
|
|
11
|
+
...Array.isArray(state.summary) ? { summary: state.summary } : {},
|
|
12
|
+
...nonEmptyStrings(state.content)
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
/** Raw reasoning parts that are usable on the wire; persisted state is not trusted. */
|
|
16
|
+
function nonEmptyStrings(value) {
|
|
17
|
+
if (!Array.isArray(value)) return {};
|
|
18
|
+
const content = value.filter((part) => typeof part === "string" && part.length > 0);
|
|
19
|
+
return content.length === 0 ? {} : { content };
|
|
20
|
+
}
|
|
14
21
|
function textAnnotations$1(block) {
|
|
15
22
|
return block.annotations?.flatMap((annotation) => annotation.type === "url-citation" ? [{
|
|
16
23
|
type: "url_citation",
|
|
@@ -161,8 +168,9 @@ function appendControl(block, state) {
|
|
|
161
168
|
}
|
|
162
169
|
function appendReasoning(block, items) {
|
|
163
170
|
const state = reasoningStateOf(block.providerState);
|
|
171
|
+
const content = reasoningContent(state, block);
|
|
164
172
|
if (state.id === void 0 && state.encryptedContent === void 0) return;
|
|
165
|
-
const summary = reasoningSummary(state, block
|
|
173
|
+
const summary = reasoningSummary(state, block, content);
|
|
166
174
|
items.push({
|
|
167
175
|
type: "reasoning",
|
|
168
176
|
...state.id === void 0 ? {} : { id: state.id },
|
|
@@ -170,12 +178,29 @@ function appendReasoning(block, items) {
|
|
|
170
178
|
type: "summary_text",
|
|
171
179
|
text
|
|
172
180
|
})),
|
|
181
|
+
...content === void 0 ? {} : { content: content.map((text) => ({
|
|
182
|
+
type: "reasoning_text",
|
|
183
|
+
text
|
|
184
|
+
})) },
|
|
173
185
|
...state.encryptedContent === void 0 ? {} : { encrypted_content: state.encryptedContent }
|
|
174
186
|
});
|
|
175
187
|
}
|
|
176
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Raw reasoning to replay as `reasoning_text`, never relabelled as a summary.
|
|
190
|
+
*
|
|
191
|
+
* A block read before raw content was tracked still says `kind: 'content'`,
|
|
192
|
+
* which is enough to put its text back where it came from.
|
|
193
|
+
*/
|
|
194
|
+
function reasoningContent(state, block) {
|
|
195
|
+
if (state.content !== void 0) return state.id === void 0 ? void 0 : state.content;
|
|
196
|
+
if (state.encryptedContent !== void 0 || state.summary !== void 0) return void 0;
|
|
197
|
+
if (state.id === void 0 || block.kind !== "content" || block.text.length === 0) return void 0;
|
|
198
|
+
return [block.text];
|
|
199
|
+
}
|
|
200
|
+
function reasoningSummary(state, block, content) {
|
|
177
201
|
if (state.summary !== void 0 && state.summary.length > 0) return state.summary;
|
|
178
|
-
|
|
202
|
+
if (content !== void 0 || state.content !== void 0 || block.kind === "content") return [];
|
|
203
|
+
return block.text.length > 0 ? [block.text] : [];
|
|
179
204
|
}
|
|
180
205
|
|
|
181
206
|
//#endregion
|
|
@@ -377,29 +402,52 @@ function doneText(item, open) {
|
|
|
377
402
|
const phase = textPhase(item.phase) ?? open.phase;
|
|
378
403
|
return {
|
|
379
404
|
type: "text",
|
|
380
|
-
text: text.length > 0 ? text : open.text,
|
|
405
|
+
text: text.length > 0 ? text : open.text.text,
|
|
381
406
|
...phase === void 0 ? {} : { phase },
|
|
382
407
|
...textAnnotations(item).length === 0 ? {} : { annotations: textAnnotations(item) }
|
|
383
408
|
};
|
|
384
409
|
}
|
|
385
410
|
function doneReasoning(item, open) {
|
|
386
411
|
const summary = itemSummary(item);
|
|
412
|
+
const content = itemReasoningContent(item);
|
|
387
413
|
const state = {
|
|
388
414
|
...typeof item.id === "string" ? { id: item.id } : {},
|
|
389
415
|
...typeof item.encrypted_content === "string" ? { encryptedContent: item.encrypted_content } : {},
|
|
390
|
-
...summary.length > 0 ? { summary } : {}
|
|
416
|
+
...summary.length > 0 ? { summary } : {},
|
|
417
|
+
...content.length > 0 ? { content } : {}
|
|
391
418
|
};
|
|
392
|
-
const
|
|
393
|
-
const kind = summary.length > 0 ? "summary" : streamed;
|
|
419
|
+
const kind = reasoningKindOf(open, summary, content);
|
|
394
420
|
return {
|
|
395
421
|
type: "reasoning",
|
|
396
|
-
text: summary
|
|
422
|
+
text: reasoningTextOf(open, summary, content),
|
|
397
423
|
...kind === void 0 ? {} : { kind },
|
|
398
424
|
providerState: state
|
|
399
425
|
};
|
|
400
426
|
}
|
|
427
|
+
function reasoningKindOf(open, summary, content) {
|
|
428
|
+
if (summary.length > 0) return "summary";
|
|
429
|
+
if (open.reasoningKind === "mixed") return void 0;
|
|
430
|
+
if (open.reasoningKind !== void 0) return open.reasoningKind;
|
|
431
|
+
return content.length > 0 ? "content" : void 0;
|
|
432
|
+
}
|
|
433
|
+
/** A server that skips the delta events still puts the thoughts on the done item. */
|
|
434
|
+
function reasoningTextOf(open, summary, content) {
|
|
435
|
+
if (summary.length > 0) return summary.join("\n\n");
|
|
436
|
+
if (open.text.length > 0) return open.text.text;
|
|
437
|
+
return content.join("\n\n");
|
|
438
|
+
}
|
|
439
|
+
/** `reasoning_text` parts of a done reasoning item, in order. */
|
|
440
|
+
function itemReasoningContent(item) {
|
|
441
|
+
const content = item.content;
|
|
442
|
+
if (!Array.isArray(content)) return [];
|
|
443
|
+
return content.flatMap((part) => {
|
|
444
|
+
if (typeof part !== "object" || part === null) return [];
|
|
445
|
+
const record = part;
|
|
446
|
+
return record.type === "reasoning_text" && typeof record.text === "string" && record.text.length > 0 ? [record.text] : [];
|
|
447
|
+
});
|
|
448
|
+
}
|
|
401
449
|
function doneTool(item, open) {
|
|
402
|
-
const args = typeof item.arguments === "string" && item.arguments.length > 0 ? item.arguments : open.args;
|
|
450
|
+
const args = typeof item.arguments === "string" && item.arguments.length > 0 ? item.arguments : open.args.text;
|
|
403
451
|
return {
|
|
404
452
|
type: "tool-call",
|
|
405
453
|
id: ToolCallId(item.call_id ?? open.callId),
|
|
@@ -557,7 +605,7 @@ function* itemAdded(state, event) {
|
|
|
557
605
|
function* textDelta(state, event) {
|
|
558
606
|
const entry = event.item_id === void 0 ? void 0 : state.open.get(event.item_id);
|
|
559
607
|
if (entry === void 0 || event.delta === void 0) return;
|
|
560
|
-
entry.text
|
|
608
|
+
entry.text.append(event.delta);
|
|
561
609
|
yield {
|
|
562
610
|
type: "text-delta",
|
|
563
611
|
index: entry.index,
|
|
@@ -571,7 +619,7 @@ function* summaryDelta(state, event) {
|
|
|
571
619
|
const separator = entry.summaryIndex !== void 0 && event.summary_index !== void 0 && event.summary_index !== entry.summaryIndex ? "\n\n" : "";
|
|
572
620
|
entry.summaryIndex = event.summary_index;
|
|
573
621
|
const text = `${separator}${event.delta}`;
|
|
574
|
-
entry.text
|
|
622
|
+
entry.text.append(text);
|
|
575
623
|
entry.reasoningKind = mergeKind(entry.reasoningKind, "summary");
|
|
576
624
|
yield {
|
|
577
625
|
type: "reasoning-delta",
|
|
@@ -583,12 +631,15 @@ function* summaryDelta(state, event) {
|
|
|
583
631
|
function* reasoningDelta(state, event) {
|
|
584
632
|
const entry = event.item_id === void 0 ? void 0 : state.open.get(event.item_id);
|
|
585
633
|
if (entry === void 0 || event.delta === void 0) return;
|
|
586
|
-
entry.
|
|
634
|
+
const separator = entry.contentIndex !== void 0 && event.content_index !== void 0 && event.content_index !== entry.contentIndex ? "\n\n" : "";
|
|
635
|
+
if (event.content_index !== void 0) entry.contentIndex = event.content_index;
|
|
636
|
+
const text = `${separator}${event.delta}`;
|
|
637
|
+
entry.text.append(text);
|
|
587
638
|
entry.reasoningKind = mergeKind(entry.reasoningKind, "content");
|
|
588
639
|
yield {
|
|
589
640
|
type: "reasoning-delta",
|
|
590
641
|
index: entry.index,
|
|
591
|
-
text
|
|
642
|
+
text,
|
|
592
643
|
kind: "content"
|
|
593
644
|
};
|
|
594
645
|
}
|
|
@@ -598,7 +649,7 @@ function mergeKind(current, next) {
|
|
|
598
649
|
function* toolDelta(state, event) {
|
|
599
650
|
const entry = event.item_id === void 0 ? void 0 : state.open.get(event.item_id);
|
|
600
651
|
if (entry === void 0 || event.delta === void 0) return;
|
|
601
|
-
entry.args
|
|
652
|
+
entry.args.append(event.delta);
|
|
602
653
|
yield {
|
|
603
654
|
type: "tool-call-delta",
|
|
604
655
|
index: entry.index,
|
|
@@ -626,13 +677,17 @@ function* itemDone(state, event) {
|
|
|
626
677
|
const entry = id === void 0 ? void 0 : state.open.get(id);
|
|
627
678
|
if (item === void 0 || entry === void 0) return;
|
|
628
679
|
const block = doneBlock(item, entry, state.imageMediaType);
|
|
629
|
-
if (block
|
|
680
|
+
if (block === void 0) return;
|
|
681
|
+
if (block.type === "text" && block.text.length > 0) state.sawText = true;
|
|
682
|
+
if (block.type === "reasoning") state.lastReasoning = block.text;
|
|
683
|
+
yield {
|
|
630
684
|
type: "block-end",
|
|
631
685
|
index: entry.index,
|
|
632
686
|
block
|
|
633
687
|
};
|
|
634
688
|
}
|
|
635
689
|
function* completed(state, event) {
|
|
690
|
+
if (state.jsonOutput && !state.sawText && !state.sawToolCall) yield* recoveredJsonAnswer(state);
|
|
636
691
|
const usage = event.response?.usage ?? void 0;
|
|
637
692
|
const mapped = usage === void 0 ? void 0 : mapUsage(usage);
|
|
638
693
|
if (mapped !== void 0) yield {
|
|
@@ -644,6 +699,43 @@ function* completed(state, event) {
|
|
|
644
699
|
reason: state.sawToolCall ? { kind: "tool-calls" } : { kind: "stop" }
|
|
645
700
|
};
|
|
646
701
|
}
|
|
702
|
+
/**
|
|
703
|
+
* Recover a structured answer that a reasoning parser misfiled.
|
|
704
|
+
*
|
|
705
|
+
* vLLM-style servers running a reasoning parser alongside guided decoding can
|
|
706
|
+
* put the whole JSON answer in the reasoning item and emit no message at all
|
|
707
|
+
* (seen live on DeepSeek V4 behind FPT AI Marketplace). The caller asked for
|
|
708
|
+
* JSON and is about to parse the text, so when the reasoning IS a JSON
|
|
709
|
+
* document it is also emitted as the answer.
|
|
710
|
+
*/
|
|
711
|
+
function* recoveredJsonAnswer(state) {
|
|
712
|
+
const trimmed = state.lastReasoning?.trim();
|
|
713
|
+
if (trimmed === void 0 || !/^[[{]/.test(trimmed)) return;
|
|
714
|
+
try {
|
|
715
|
+
JSON.parse(trimmed);
|
|
716
|
+
} catch {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const index = state.nextIndex++;
|
|
720
|
+
yield {
|
|
721
|
+
type: "block-start",
|
|
722
|
+
index,
|
|
723
|
+
blockType: "text"
|
|
724
|
+
};
|
|
725
|
+
yield {
|
|
726
|
+
type: "text-delta",
|
|
727
|
+
index,
|
|
728
|
+
text: trimmed
|
|
729
|
+
};
|
|
730
|
+
yield {
|
|
731
|
+
type: "block-end",
|
|
732
|
+
index,
|
|
733
|
+
block: {
|
|
734
|
+
type: "text",
|
|
735
|
+
text: trimmed
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
}
|
|
647
739
|
function* incomplete(event, displayName) {
|
|
648
740
|
const usage = event.response?.usage ?? void 0;
|
|
649
741
|
const mapped = usage === void 0 ? void 0 : mapUsage(usage);
|
|
@@ -702,12 +794,13 @@ function createOpenItem(state, item, identity) {
|
|
|
702
794
|
return {
|
|
703
795
|
index: state.nextIndex++,
|
|
704
796
|
kind,
|
|
705
|
-
text:
|
|
706
|
-
args:
|
|
797
|
+
text: new TextAccumulator(),
|
|
798
|
+
args: new TextAccumulator(),
|
|
707
799
|
callId: item.call_id ?? id,
|
|
708
800
|
name: item.name ?? "",
|
|
709
801
|
nativeName: nativeName(item.type),
|
|
710
802
|
summaryIndex: void 0,
|
|
803
|
+
contentIndex: void 0,
|
|
711
804
|
phase: textPhase(item.phase),
|
|
712
805
|
reasoningKind: void 0
|
|
713
806
|
};
|
|
@@ -739,7 +832,10 @@ async function* translateResponsesStream(events, displayName, request) {
|
|
|
739
832
|
open: /* @__PURE__ */ new Map(),
|
|
740
833
|
nextIndex: 0,
|
|
741
834
|
sawToolCall: false,
|
|
742
|
-
imageMediaType: requestedImageMediaType(request)
|
|
835
|
+
imageMediaType: requestedImageMediaType(request),
|
|
836
|
+
sawText: false,
|
|
837
|
+
lastReasoning: void 0,
|
|
838
|
+
jsonOutput: request?.options.outputFormat?.type === "json_schema"
|
|
743
839
|
};
|
|
744
840
|
for await (const raw of events) {
|
|
745
841
|
const event = parseEvent(raw, displayName);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["textAnnotations"],"sources":["../src/request-content.ts","../src/request-messages.ts","../src/serialize-options.ts","../src/serialize.ts","../src/stream-items.ts","../src/stream-usage.ts","../src/stream-errors.ts","../src/stream-events.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["import type {\n ContentBlock, DocumentBlock, ImageBlock, NativeToolCallBlock, TextBlock,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { WireContentPart, WireInputItem } from './wire.ts'\nimport type { ResponsesReasoningState } from './serialize-types.ts'\n\nconst DEFAULT_DOCUMENT_FILENAME = 'document.pdf'\n\nexport function reasoningStateOf(value: unknown): ResponsesReasoningState {\n if (typeof value !== 'object' || value === null) return {}\n const state = value as ResponsesReasoningState\n return {\n ...typeof state.id === 'string' ? { id: state.id } : {},\n ...typeof state.encryptedContent === 'string'\n ? { encryptedContent: state.encryptedContent }\n : {},\n ...Array.isArray(state.summary) ? { summary: state.summary } : {},\n }\n}\n\nexport function textAnnotations(block: TextBlock) {\n return block.annotations?.flatMap(annotation => annotation.type === 'url-citation'\n ? [{\n type: 'url_citation' as const,\n url: annotation.url,\n ...annotation.title === undefined ? {} : { title: annotation.title },\n ...annotation.startIndex === undefined ? {} : { start_index: annotation.startIndex },\n ...annotation.endIndex === undefined ? {} : { end_index: annotation.endIndex },\n }]\n : [])\n}\n\nexport function imagePart(block: ImageBlock): WireContentPart {\n const detail = block.detail\n if (block.source.kind === 'file') {\n return { type: 'input_image', file_id: block.source.fileId, ...detail === undefined ? {} : { detail } }\n }\n const image_url = block.source.kind === 'url'\n ? block.source.url\n : `data:${block.source.mediaType};base64,${block.source.data}`\n return { type: 'input_image', image_url, ...detail === undefined ? {} : { detail } }\n}\n\nexport function documentPart(block: DocumentBlock): WireContentPart {\n if (block.source.kind === 'file') return { type: 'input_file', file_id: block.source.fileId }\n if (block.source.kind === 'url') return { type: 'input_file', file_url: block.source.url }\n return {\n type: 'input_file',\n // The API reads the file type from the extension here, so a name is required\n // rather than optional; a neutral default beats a rejected request.\n filename: block.filename ?? DEFAULT_DOCUMENT_FILENAME,\n file_data: `data:${block.source.mediaType};base64,${block.source.data}`,\n }\n}\n\nexport function contentPart(block: ContentBlock, role: 'user' | 'assistant'): WireContentPart | undefined {\n if (block.type === 'text') {\n // An assistant turn's own text must come back as `output_text`; sending it as\n // `input_text` would present the model's prior words as if the user said them.\n if (role !== 'assistant') return { type: 'input_text', text: block.text }\n const annotations = textAnnotations(block)\n return {\n type: 'output_text', text: block.text,\n ...annotations === undefined ? {} : { annotations },\n }\n }\n if (block.type === 'image') return imagePart(block)\n if (block.type === 'document') return documentPart(block)\n return undefined\n}\n\nexport function toolResultOutput(blocks: readonly ContentBlock[]): string | WireContentPart[] {\n const hasBinary = blocks.some(block => block.type === 'image' || block.type === 'document')\n if (!hasBinary) {\n // The common case. A plain string keeps the payload small and is what the\n // API documents first.\n return blocks\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n .join('\\n')\n }\n return blocks\n .map(block => contentPart(block, 'user'))\n .filter((part): part is WireContentPart => part !== undefined)\n}\n\nexport function nativeReplayItem(block: NativeToolCallBlock): WireInputItem | undefined {\n const value = block.providerState\n if (typeof value !== 'object' || value === null) return undefined\n const item = value as Record<string, unknown>\n if (item.type === 'web_search_call') {\n return {\n type: 'web_search_call',\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...item.action === undefined ? {} : { action: structuredClone(item.action) },\n }\n }\n if (item.type === 'image_generation_call') return imageReplayItem(item, generatedImage(block))\n return undefined\n}\n\n/** The generated image, as base64; histories recorded before it moved there keep it in the item. */\nfunction generatedImage(block: NativeToolCallBlock): string | undefined {\n const image = block.content.find(content => content.type === 'image' && content.source.kind === 'base64')\n return image?.type === 'image' && image.source.kind === 'base64' ? image.source.data : undefined\n}\n\nfunction imageReplayItem(item: Record<string, unknown>, image: string | undefined): WireInputItem {\n const result = image ?? item.result\n return {\n type: 'image_generation_call',\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...typeof result === 'string' || result === null ? { result } : {},\n }\n}\n","import type { ContentBlock, TextBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { Message } from '@alvin0/ai-agent-sdk-core'\nimport type { WireContentPart, WireInputItem } from './wire.ts'\nimport type { ResponsesReasoningState } from './serialize-types.ts'\nimport { contentPart, reasoningStateOf, toolResultOutput, nativeReplayItem } from './request-content.ts'\n\ninterface MessageState {\n role: 'user' | 'assistant'\n parts: WireContentPart[]\n phase: TextBlock['phase']\n items: WireInputItem[]\n dialectMessagePhase: boolean\n}\n\n/** Flush content at standalone-item boundaries to preserve conversation order. */\nexport function appendMessage(message: Message, items: WireInputItem[], dialectMessagePhase: boolean): void {\n const state: MessageState = {\n role: message.role === 'assistant' ? 'assistant' : 'user', parts: [], phase: undefined,\n items, dialectMessagePhase,\n }\n for (const block of message.content) {\n if (block.type === 'text' || block.type === 'image' || block.type === 'document') appendContent(block, state)\n else appendControl(block, state)\n }\n flushMessage(state)\n}\n\nfunction flushMessage(state: MessageState): void {\n if (state.parts.length === 0) return\n state.items.push({\n type: 'message', role: state.role, content: state.parts,\n ...state.role === 'assistant' && state.dialectMessagePhase && state.phase !== undefined\n ? { phase: state.phase === 'final-answer' ? 'final_answer' as const : state.phase } : {},\n })\n state.parts = []\n state.phase = undefined\n}\n\nfunction appendContent(block: ContentBlock, state: MessageState): void {\n if (block.type === 'text' && block.phase !== undefined && state.phase !== undefined && state.phase !== block.phase) {\n flushMessage(state)\n }\n if (block.type === 'text' && block.phase !== undefined) state.phase = block.phase\n const part = contentPart(block, state.role)\n if (part !== undefined) state.parts.push(part)\n}\n\nfunction appendControl(block: ContentBlock, state: MessageState): void {\n switch (block.type) {\n case 'reasoning':\n flushMessage(state)\n appendReasoning(block, state.items)\n return\n case 'tool-call':\n flushMessage(state)\n state.items.push({ type: 'function_call', call_id: block.id, name: block.name,\n arguments: block.arguments.length > 0 ? block.arguments : '{}' })\n return\n case 'tool-result':\n flushMessage(state)\n state.items.push({ type: 'function_call_output', call_id: block.toolCallId,\n output: toolResultOutput(block.content) })\n return\n case 'native-tool-call': {\n flushMessage(state)\n const replay = nativeReplayItem(block)\n if (replay !== undefined) state.items.push(replay)\n return\n }\n default: return\n }\n}\n\nfunction appendReasoning(block: Extract<ContentBlock, { type: 'reasoning' }>, items: WireInputItem[]): void {\n const state = reasoningStateOf(block.providerState)\n // Unfinished reasoning has no replay identity and cannot be sent back.\n if (state.id === undefined && state.encryptedContent === undefined) return\n const summary = reasoningSummary(state, block.text)\n items.push({\n type: 'reasoning',\n ...state.id === undefined ? {} : { id: state.id },\n summary: summary.map(text => ({ type: 'summary_text' as const, text })),\n ...state.encryptedContent === undefined ? {} : { encrypted_content: state.encryptedContent },\n })\n}\n\nfunction reasoningSummary(state: ResponsesReasoningState, text: string): readonly string[] {\n if (state.summary !== undefined && state.summary.length > 0) return state.summary\n return text.length > 0 ? [text] : []\n}\n","import type { ProtocolRequest } from './contract.ts'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport {\n isNativeToolSchema, type ModelOutputFormat, type ModelToolSchema, type NativeImageGenerationTool,\n type NativeWebSearchTool, type ToolChoice, type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ResponsesDialect, WireTool, WireToolChoice, WireTextControls } from './wire.ts'\n\nexport function toolChoiceOf(choice: ToolChoice): WireToolChoice {\n if (typeof choice === 'string') return choice\n if (choice.type === 'native') return { type: nativeWireType(choice.name) }\n return { type: 'function', name: choice.name }\n}\n\nexport function functionTool(tool: ToolSchema): WireTool {\n return {\n type: 'function',\n name: tool.name,\n description: tool.description,\n // Strict mode imposes real JSON-Schema restrictions (no optional fields\n // without null, `additionalProperties: false` required). Opting a caller's\n // schema in silently would turn a working tool into a request rejection.\n strict: false,\n parameters: tool.parameters,\n }\n}\n\nexport function nativeWireType(name: string): string {\n if (name === 'web-search') return 'web_search'\n if (name === 'image-generation') return 'image_generation'\n return name.replaceAll('-', '_')\n}\n\nexport function webSearchTool(tool: NativeWebSearchTool): WireTool {\n if (tool.blockedDomains !== undefined) {\n throw new ModelError(\n 'OpenAI Responses web search does not support blockedDomains; use allowedDomains',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n if (tool.maxUses !== undefined) {\n throw new ModelError(\n 'OpenAI Responses web search does not support maxUses',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n type: 'web_search',\n ...tool.searchContextSize === undefined ? {} : { search_context_size: tool.searchContextSize },\n ...tool.allowedDomains === undefined ? {} : { filters: { allowed_domains: [...tool.allowedDomains] } },\n ...tool.userLocation === undefined ? {} : {\n user_location: { type: 'approximate', ...tool.userLocation },\n },\n ...tool.searchContentTypes === undefined ? {} : { search_content_types: [...tool.searchContentTypes] },\n }\n}\n\nexport function imageGenerationTool(tool: NativeImageGenerationTool): WireTool {\n return {\n type: 'image_generation',\n ...tool.size === undefined ? {} : { size: tool.size },\n ...tool.quality === undefined ? {} : { quality: tool.quality },\n ...tool.format === undefined ? {} : { output_format: tool.format },\n ...tool.background === undefined ? {} : { background: tool.background },\n ...tool.partialImages === undefined ? {} : { partial_images: tool.partialImages },\n }\n}\n\nexport function toolOf(tool: ModelToolSchema): WireTool {\n if (!isNativeToolSchema(tool)) return functionTool(tool)\n if (tool.name === 'web-search') return webSearchTool(tool)\n return imageGenerationTool(tool)\n}\n\nexport function textControls(\n format: ModelOutputFormat | undefined,\n dialect: ResponsesDialect,\n): WireTextControls | undefined {\n if (format === undefined) return undefined\n if (format.type === 'text') {\n return dialect.structuredOutputs ? { format: { type: 'text' } } : undefined\n }\n if (!dialect.structuredOutputs) {\n throw new ModelError(\n 'This Responses endpoint does not support JSON Schema output',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n format: {\n type: 'json_schema',\n name: format.name,\n schema: format.schema,\n strict: true,\n },\n }\n}\n\nexport function toolsOptions(request: ProtocolRequest) {\n const options = request.options\n const tools = options.tools === undefined || options.tools.length === 0 ? undefined : options.tools.map(toolOf)\n return {\n ...tools === undefined ? {} : { tools, parallel_tool_calls: true },\n ...options.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(options.toolChoice) },\n }\n}\n\nexport function reasoningOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const effort = request.options.reasoningEffort\n if (effort === undefined && dialect.reasoningSummary === undefined) return {}\n return { reasoning: {\n ...effort === undefined ? {} : { effort: String(effort) },\n ...dialect.reasoningSummary === undefined ? {} : { summary: dialect.reasoningSummary },\n } }\n}\n\nexport function dialectOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const text = textControls(request.options.outputFormat, dialect)\n return {\n ...text === undefined ? {} : { text },\n ...dialect.store === undefined ? {} : { store: dialect.store },\n ...dialect.include.length === 0 ? {} : { include: [...dialect.include] },\n ...dialect.promptCacheKey === undefined ? {} : { prompt_cache_key: dialect.promptCacheKey },\n ...dialect.maxOutputTokens && request.maxTokens !== undefined ? { max_output_tokens: request.maxTokens } : {},\n }\n}\n\nexport function samplingOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const options = request.options\n return {\n ...dialect.sampling && options.temperature !== undefined ? { temperature: options.temperature } : {},\n ...dialect.sampling && options.topP !== undefined ? { top_p: options.topP } : {},\n }\n}\n","/**\n * Normalized request to Responses API wire JSON.\n *\n * The interesting work is flattening. Our conversation is a list of messages,\n * each holding an ordered list of content blocks; the wire wants a FLAT list of\n * items where a tool result and a tool call are peers of a message rather than\n * parts of one. So one assistant message that reasoned, spoke, and called two\n * tools expands to four items, and their relative order must be preserved\n * because the model reads it as its own prior turn.\n *\n * @module ai-agent-sdk/providers/responses/serialize\n */\n\nimport type { ProtocolRequest } from './contract.ts'\nimport type { ContentBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { ResponsesDialect, WireInputItem, WireRequest } from './wire.ts'\nexport type { ResponsesReasoningState } from './serialize-types.ts'\nimport { appendMessage } from './request-messages.ts'\nimport { toolsOptions, reasoningOptions, dialectOptions, samplingOptions } from './serialize-options.ts'\n\nfunction instructionsOf(request: ProtocolRequest): string {\n const fromMessages = request.options.messages\n .filter(message => message.role === 'system')\n .flatMap(message => message.content)\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n const all = request.options.system === undefined\n ? fromMessages\n : [request.options.system, ...fromMessages]\n return all.join('\\n\\n')\n}\n\nexport function serializeResponsesRequest(request: ProtocolRequest, dialect: ResponsesDialect): WireRequest {\n const input: WireInputItem[] = []\n for (const message of request.options.messages) {\n if (message.role === 'system') continue\n appendMessage(message, input, dialect.messagePhase === true)\n }\n const instructions = instructionsOf(request)\n return {\n model: request.options.model,\n ...instructions.length === 0 ? {} : { instructions },\n input,\n ...toolsOptions(request),\n ...reasoningOptions(request, dialect),\n ...dialectOptions(request, dialect),\n ...samplingOptions(request, dialect),\n stream: true,\n }\n}\n","import { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport { isJsonValue } from '@alvin0/ai-agent-sdk-core'\nimport type {\n AssistantTextPhase, ContentBlock, ImageMediaType, ReasoningKind, TextAnnotation,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type { ResponsesReasoningState } from './serialize.ts'\nimport type { WireOutputItem } from './wire.ts'\n\nexport type ItemKind = 'text' | 'reasoning' | 'tool-call' | 'native-tool-call'\n\nexport interface OpenItem {\n readonly index: number\n readonly kind: ItemKind\n text: string\n args: string\n callId: string\n name: string\n nativeName: string\n /** Last `summary_index` seen, so a new paragraph gets a separator. */\n summaryIndex: number | undefined\n phase: AssistantTextPhase | undefined\n /**\n * Which reasoning stream filled `text`; `mixed` when both did, which leaves\n * the block unlabelled. The done item's summary still overrides it.\n */\n reasoningKind: ReasoningKind | 'mixed' | undefined\n}\n\nexport function textPhase(value: string | undefined): AssistantTextPhase | undefined {\n if (value === 'commentary') return 'commentary'\n if (value === 'final_answer') return 'final-answer'\n return undefined\n}\n\nexport function itemKind(type: string | undefined): ItemKind | undefined {\n switch (type) {\n case 'message': return 'text'\n case 'reasoning': return 'reasoning'\n case 'function_call': return 'tool-call'\n case 'web_search_call': return 'native-tool-call'\n case 'image_generation_call': return 'native-tool-call'\n default: return undefined\n }\n}\n\nexport function nativeName(type: string | undefined): string {\n if (type === 'web_search_call') return 'web-search'\n if (type === 'image_generation_call') return 'image-generation'\n return type?.replace(/_call$/, '').replaceAll('_', '-') ?? 'native-tool'\n}\n\nexport function textAnnotations(item: WireOutputItem): TextAnnotation[] {\n if (!Array.isArray(item.content)) return []\n return item.content.flatMap((part) => {\n if (typeof part !== 'object' || part === null) return []\n const annotations = (part as Record<string, unknown>).annotations\n if (!Array.isArray(annotations)) return []\n return annotations.flatMap((annotation): TextAnnotation[] => {\n if (typeof annotation !== 'object' || annotation === null) return []\n const record = annotation as Record<string, unknown>\n if (record.type !== 'url_citation' || typeof record.url !== 'string') return []\n return [{\n type: 'url-citation',\n url: record.url,\n ...typeof record.title === 'string' ? { title: record.title } : {},\n ...typeof record.start_index === 'number' ? { startIndex: record.start_index } : {},\n ...typeof record.end_index === 'number' ? { endIndex: record.end_index } : {},\n }]\n })\n })\n}\n\nexport function itemText(item: WireOutputItem): string {\n const content = item.content\n if (!Array.isArray(content)) return ''\n return content\n .map((part) => {\n if (typeof part !== 'object' || part === null) return ''\n const record = part as Record<string, unknown>\n return typeof record.text === 'string' ? record.text : ''\n })\n .join('')\n}\n\nexport function itemSummary(item: WireOutputItem): string[] {\n const summary = item.summary\n if (!Array.isArray(summary)) return []\n return summary\n .map((part) => {\n if (typeof part !== 'object' || part === null) return ''\n const record = part as Record<string, unknown>\n return typeof record.text === 'string' ? record.text : ''\n })\n .filter(text => text.length > 0)\n}\n\nexport function doneBlock(\n item: WireOutputItem, open: OpenItem, imageMediaType: ImageMediaType,\n): ContentBlock | undefined {\n switch (open.kind) {\n case 'text': return doneText(item, open)\n case 'reasoning': return doneReasoning(item, open)\n case 'tool-call': return doneTool(item, open)\n case 'native-tool-call': return doneNative(item, open, imageMediaType)\n default: return undefined\n }\n}\n\nfunction doneText(item: WireOutputItem, open: OpenItem): ContentBlock {\n const text = itemText(item)\n const phase = textPhase(item.phase) ?? open.phase\n return {\n type: 'text',\n text: text.length > 0 ? text : open.text,\n ...phase === undefined ? {} : { phase },\n ...textAnnotations(item).length === 0 ? {} : { annotations: textAnnotations(item) },\n }\n}\n\nfunction doneReasoning(item: WireOutputItem, open: OpenItem): ContentBlock {\n const summary = itemSummary(item)\n const state: ResponsesReasoningState = {\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.encrypted_content === 'string'\n ? { encryptedContent: item.encrypted_content }\n : {},\n ...summary.length > 0 ? { summary } : {},\n }\n const streamed = open.reasoningKind === 'mixed' ? undefined : open.reasoningKind\n const kind = summary.length > 0 ? 'summary' : streamed\n return {\n type: 'reasoning',\n text: summary.length > 0 ? summary.join('\\n\\n') : open.text,\n ...kind === undefined ? {} : { kind },\n providerState: state,\n }\n}\n\nfunction doneTool(item: WireOutputItem, open: OpenItem): ContentBlock {\n const args = typeof item.arguments === 'string' && item.arguments.length > 0\n ? item.arguments\n : open.args\n return {\n type: 'tool-call',\n id: ToolCallId(item.call_id ?? open.callId),\n name: item.name ?? open.name,\n arguments: args.length > 0 ? args : '{}',\n }\n}\n\nfunction doneNative(item: WireOutputItem, open: OpenItem, imageMediaType: ImageMediaType): ContentBlock {\n const content: ContentBlock[] = open.nativeName === 'image-generation'\n && typeof item.result === 'string' && item.result.length > 0\n ? [{\n type: 'image',\n source: { kind: 'base64', mediaType: imageMediaType, data: item.result },\n }]\n : []\n return {\n type: 'native-tool-call',\n id: item.id ?? open.callId,\n name: open.nativeName,\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...isJsonValue(item.action) ? { arguments: item.action } : {},\n content,\n // The image is kept once, as public content; replay reads it back from there.\n providerState: content.length > 0 ? withoutResult(item) : item,\n }\n}\n\nfunction withoutResult(item: WireOutputItem): WireOutputItem {\n const { result: _result, ...rest } = item\n return rest\n}\n\n\nexport function kindToBlockType(kind: ItemKind): 'text' | 'reasoning' | 'tool-call' | 'native-tool-call' {\n return kind\n}\n\nexport function requestedImageMediaType(request: ProtocolRequest | undefined): ImageMediaType {\n const tool = request?.options.tools?.find(candidate => 'type' in candidate\n && candidate.type === 'native'\n && candidate.name === 'image-generation')\n if (tool === undefined || !('format' in tool)) return 'image/png'\n if (tool.format === 'jpeg') return 'image/jpeg'\n if (tool.format === 'webp') return 'image/webp'\n return 'image/png'\n}","import type { UsageCounters } from '@alvin0/ai-agent-sdk-core'\nimport type { WireUsage } from './wire.ts'\n\nexport function mapUsage(usage: WireUsage): UsageCounters | undefined {\n const source = usage as unknown as Record<string, unknown>\n const details = recordOrUndefined(source.input_tokens_details)\n const rawInput = source.input_tokens\n const outputTokens = source.output_tokens\n const cacheRead = details?.cached_tokens\n const cacheWrite = details?.cache_write_tokens\n const reasoning = reasoningCounter(source)\n const totalTokens = source.total_tokens\n const hasAny = [rawInput, outputTokens, cacheRead, cacheWrite, reasoning, totalTokens]\n .some(value => value !== undefined)\n if (!hasAny) return undefined\n\n const normalized: Record<string, unknown> = {\n ...outputTokens === undefined ? {} : { outputTokens },\n ...totalTokens === undefined ? {} : { totalTokens },\n // Omitted cache details are authoritative zero for Responses. Present\n // malformed values are retained for the accounting validator.\n ...omittedCounter(cacheRead) ? {} : { cacheReadTokens: cacheRead },\n ...omittedCounter(cacheWrite) ? {} : { cacheWriteTokens: cacheWrite },\n ...omittedCounter(reasoning) ? {} : { reasoningTokens: reasoning },\n }\n if (rawInput !== undefined) {\n normalized.inputTokens = disjointInput(rawInput, cacheRead, cacheWrite)\n }\n return normalized as UsageCounters\n}\n\nfunction recordOrUndefined(value: unknown): Record<string, unknown> | undefined {\n return typeof value === 'object' && value !== null ? value as Record<string, unknown> : undefined\n}\n\nfunction omittedCounter(value: unknown): boolean { return value === undefined || value === 0 }\n\nfunction disjointInput(rawInput: unknown, cacheRead: unknown, cacheWrite: unknown): unknown {\n // Responses includes both cache buckets in input_tokens. The SDK accounts\n // for them separately; do not count cache writes twice or clamp invalid data.\n return typeof rawInput === 'number' && (cacheRead === undefined || typeof cacheRead === 'number')\n && (cacheWrite === undefined || typeof cacheWrite === 'number')\n ? rawInput - (cacheRead ?? 0) - (cacheWrite ?? 0) : rawInput\n}\n\nfunction reasoningCounter(source: Record<string, unknown>): unknown {\n return recordOrUndefined(source.output_tokens_details)?.reasoning_tokens\n}\n","import { CONTEXT_WINDOW_EXCEEDED_CODE, QUOTA_EXCEEDED_CODE } from '@alvin0/ai-agent-sdk-core'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { WireResponse } from './wire.ts'\n\nconst TERMINAL_ERROR_CODES: Readonly<Record<string, string>> = Object.freeze({\n context_length_exceeded: CONTEXT_WINDOW_EXCEEDED_CODE,\n insufficient_quota: QUOTA_EXCEEDED_CODE,\n invalid_prompt: MODEL_ERROR_CODES.INVALID_REQUEST,\n bio_policy: MODEL_ERROR_CODES.INVALID_REQUEST,\n cyber_policy: MODEL_ERROR_CODES.INVALID_REQUEST,\n misalignment_policy_violation: MODEL_ERROR_CODES.INVALID_REQUEST,\n rate_limit_exceeded: MODEL_ERROR_CODES.RATE_LIMIT,\n})\n\n\nexport function failedError(response: WireResponse | undefined, displayName: string): ModelError {\n const error = response?.error ?? undefined\n const code = error?.code ?? error?.type\n const message = error?.message ?? `${displayName} reported a failed response${failureContext(response, code)}`\n const mapped = code === undefined ? undefined : TERMINAL_ERROR_CODES[code]\n return new ModelError(\n message,\n // An unrecognized failure defaults to SERVER, which IS in the retryable set:\n // the request produced nothing, so repeating it is safe and often works.\n mapped ?? MODEL_ERROR_CODES.SERVER,\n {},\n )\n}\n\nfunction failureContext(response: WireResponse | undefined, code: string | undefined): string {\n const facts = [\n code === undefined ? 'no error detail' : `code ${code}`,\n ...typeof response?.id === 'string' && /^[\\w.:-]{1,128}$/.test(response.id) ? [`response ${response.id}`] : [],\n ...typeof response?.status === 'string' && /^[\\w-]{1,32}$/.test(response.status)\n ? [`status ${response.status}`] : [],\n ]\n return ` (${facts.join(', ')})`\n}","import type { WireOutputItem } from './wire.ts'\nimport type { ItemKind } from './stream-items.ts'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport { ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport type { ImageMediaType } from '@alvin0/ai-agent-sdk-core'\nimport type { FinishReason } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolStreamChunk } from './contract.ts'\nimport type { WireErrorBody, WireStreamEvent } from './wire.ts'\nimport { textPhase, itemKind, nativeName, kindToBlockType, doneBlock, type OpenItem } from './stream-items.ts'\nimport { mapUsage } from './stream-usage.ts'\nimport { failedError } from './stream-errors.ts'\n\nexport interface StreamState {\n open: Map<string, OpenItem>\n nextIndex: number\n sawToolCall: boolean\n imageMediaType: ImageMediaType\n}\n\nexport function* translateEvent(\n state: StreamState, event: WireStreamEvent, displayName: string,\n): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'response.output_item.added': yield* itemAdded(state, event); return\n case 'response.output_item.done': yield* itemDone(state, event); return\n case 'response.completed': yield* completed(state, event); return\n case 'response.incomplete': yield* incomplete(event, displayName); return\n case 'response.failed': yield* failed(event, displayName); return\n case 'error': yield* inlineError(event, displayName); return\n default: yield* deltaEvent(state, event); return\n }\n}\n\nfunction* itemAdded(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const item = event.item\n const id = item?.id ?? event.item_id\n const kind = itemKind(item?.type)\n if (item === undefined || id === undefined || kind === undefined) return\n if (state.open.has(id)) return\n const entry = createOpenItem(state, item, { id, kind })\n state.open.set(id, entry)\n if (kind === 'tool-call') state.sawToolCall = true\n yield { type: 'block-start', index: entry.index, blockType: kindToBlockType(kind) }\n}\n\nfunction* textDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.text += event.delta\n yield {\n type: 'text-delta', index: entry.index, text: event.delta,\n ...entry.phase === undefined ? {} : { phase: entry.phase },\n }\n}\n\nfunction* summaryDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n // A new summary paragraph starts; separate it from the previous one so the\n // assembled text does not run two thoughts together.\n const separator = entry.summaryIndex !== undefined\n && event.summary_index !== undefined\n && event.summary_index !== entry.summaryIndex\n ? '\\n\\n'\n : ''\n entry.summaryIndex = event.summary_index\n const text = `${separator}${event.delta}`\n entry.text += text\n entry.reasoningKind = mergeKind(entry.reasoningKind, 'summary')\n yield { type: 'reasoning-delta', index: entry.index, text, kind: 'summary' }\n}\n\nfunction* reasoningDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.text += event.delta\n entry.reasoningKind = mergeKind(entry.reasoningKind, 'content')\n yield { type: 'reasoning-delta', index: entry.index, text: event.delta, kind: 'content' }\n}\n\nfunction mergeKind(current: OpenItem['reasoningKind'], next: 'summary' | 'content'): OpenItem['reasoningKind'] {\n return current === undefined || current === next ? next : 'mixed'\n}\n\nfunction* toolDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.args += event.delta\n yield {\n type: 'tool-call-delta',\n index: entry.index,\n id: ToolCallId(entry.callId),\n ...entry.name.length > 0 ? { name: entry.name } : {},\n argumentsDelta: event.delta,\n }\n}\n\nfunction* partialImage(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const itemId = event.item_id\n const entry = itemId === undefined ? undefined : state.open.get(itemId)\n if (itemId === undefined || entry === undefined || event.partial_image_b64 === undefined) return\n yield {\n type: 'image-delta',\n index: entry.index,\n itemId,\n data: event.partial_image_b64,\n mediaType: state.imageMediaType,\n ...event.partial_image_index === undefined\n ? {}\n : { partialIndex: event.partial_image_index },\n }\n}\n\nfunction* itemDone(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const item = event.item\n const id = item?.id ?? event.item_id\n const entry = id === undefined ? undefined : state.open.get(id)\n if (item === undefined || entry === undefined) return\n const block = doneBlock(item, entry, state.imageMediaType)\n if (block !== undefined) yield { type: 'block-end', index: entry.index, block }\n}\n\nfunction* completed(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n // This API has no explicit stop reason. Tool calls in the output ARE the\n // signal that the turn expects results back, which is what an agent loop\n // branches on.\n const reason: FinishReason = state.sawToolCall ? { kind: 'tool-calls' } : { kind: 'stop' }\n yield { type: 'finish', reason }\n}\n\nfunction* incomplete(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n const why = event.response?.incomplete_details?.reason\n if (why === 'max_output_tokens') {\n yield { type: 'finish', reason: { kind: 'max-tokens' } }\n return\n }\n throw new ModelError(\n `${displayName} returned an incomplete response (${why ?? 'unknown reason'})`,\n MODEL_ERROR_CODES.SERVER,\n )\n}\n\nfunction* failed(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n // A failed generation can still be billed. Preserve the provider's\n // counters before the transport records the failure and retry admission.\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n throw failedError(event.response, displayName)\n}\n\nfunction* inlineError(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n // A top-level error event carries its fields inline rather than under a\n // `response` object, so it is reshaped to reuse the same classifier.\n const inline: WireErrorBody = {\n ...event.code === undefined ? {} : { code: event.code },\n ...event.message === undefined ? {} : { message: event.message },\n }\n throw failedError({ error: inline }, displayName)\n}\n\nfunction* deltaEvent(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'response.output_text.delta': yield* textDelta(state, event); return\n case 'response.reasoning_summary_text.delta': yield* summaryDelta(state, event); return\n case 'response.reasoning_text.delta': yield* reasoningDelta(state, event); return\n case 'response.function_call_arguments.delta': yield* toolDelta(state, event); return\n case 'response.image_generation_call.partial_image': yield* partialImage(state, event); return\n default: return\n }\n}\n\nfunction createOpenItem(\n state: StreamState, item: WireOutputItem, identity: { id: string; kind: ItemKind },\n): OpenItem {\n const { id, kind } = identity\n return {\n index: state.nextIndex++,\n kind,\n text: '',\n args: '',\n callId: item.call_id ?? id,\n name: item.name ?? '',\n nativeName: nativeName(item.type),\n summaryIndex: undefined,\n phase: textPhase(item.phase),\n reasoningKind: undefined,\n }\n}\n","/**\n * Responses API SSE events to the SDK's chunk protocol.\n *\n * Two design notes worth reading before changing anything here.\n *\n * First, block correlation is keyed on `item_id`, not on the provider's\n * `output_index`. Item ids are stable and present on every delta event, whereas\n * index fields vary by event type, so keying on the id and assigning our OWN\n * indices in first-seen order is both simpler and closer to what our protocol\n * promises.\n *\n * Second, reasoning state is carried on the reasoning BLOCK\n * (`ReasoningBlock.providerState`) rather than in the stream's `replayState`\n * envelope. The envelope has to stay positionally aligned with emitted blocks and\n * is discarded whole when it drifts; attaching the state to the block it belongs\n * to cannot drift, and it survives assembly for free.\n *\n * @module ai-agent-sdk/providers/responses/translate\n */\n\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest, ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type { WireStreamEvent } from './wire.ts'\nimport { requestedImageMediaType } from './stream-items.ts'\nimport { translateEvent, type StreamState } from './stream-events.ts'\n\nexport async function* translateResponsesStream(\n events: AsyncIterable<ProtocolSseEvent>, displayName: string, request?: ProtocolRequest,\n): AsyncGenerator<ProtocolStreamChunk> {\n const state: StreamState = {\n open: new Map(), nextIndex: 0, sawToolCall: false, imageMediaType: requestedImageMediaType(request),\n }\n for await (const raw of events) {\n const event = parseEvent(raw, displayName)\n yield* translateEvent(state, event, displayName)\n if (event.type === 'response.completed' || event.type === 'response.incomplete') return\n }\n throw new ModelError(\n `${displayName} stream ended before the response completed`,\n MODEL_ERROR_CODES.STREAM_CLOSED,\n )\n}\n\nfunction parseEvent(raw: ProtocolSseEvent, displayName: string): WireStreamEvent {\n try { return JSON.parse(raw.data) as WireStreamEvent }\n catch (error: unknown) {\n throw new ModelError(\n `${displayName} sent a malformed stream event`,\n MODEL_ERROR_CODES.MALFORMED_RESPONSE, { cause: error },\n )\n }\n}\n","/**\n * The OpenAI Responses protocol, as a reusable {@link WireProtocol}.\n *\n * Spoken by `api.openai.com`, by the ChatGPT-backed Codex endpoint, and by a\n * growing number of compatible gateways. None of them needs its own translation\n * code — they differ only in the dialect knobs below.\n *\n * @module ai-agent-sdk/providers/protocols/openai-responses\n */\n\nimport type {\n ProtocolDefinition,\n ProtocolRequest,\n ProtocolSseEvent,\n ProtocolStreamChunk,\n} from './contract.ts'\nimport type { ModelTarget, ResolvedModelInfo } from '@alvin0/ai-agent-sdk-core/provider'\nimport { serializeResponsesRequest } from './serialize.ts'\nimport { translateResponsesStream } from './translate.ts'\nimport type { ResponsesDialect } from './wire.ts'\n\n/** Protocol id, usable as a stable string in configuration. */\nexport const OPENAI_RESPONSES_PROTOCOL_ID = 'openai-responses'\n\n/**\n * Conservative defaults.\n *\n * `store: false` because retaining prompts server-side should be an explicit\n * decision, not something an SDK turns on for you. `include` carries\n * `reasoning.encrypted_content` because without it a reasoning model loses its\n * chain of thought between a tool call and the tool's result.\n */\nconst DEFAULT_DIALECT: ResponsesDialect = Object.freeze({\n sampling: true,\n maxOutputTokens: true,\n structuredOutputs: true,\n store: false,\n include: Object.freeze(['reasoning.encrypted_content']),\n reasoningSummary: 'auto',\n})\n\ninterface RuntimeProtocolRequest extends ProtocolRequest {\n readonly model: ResolvedModelInfo\n readonly connection: {\n readonly baseUrl: string\n readonly headers: Readonly<Record<string, string>>\n }\n}\n\n/** Marker-based runtime view, kept structurally independent from provider-http. */\nexport interface ResponsesProtocolDefinition {\n readonly kind: 'http-wire-protocol'\n readonly apiVersion: 1\n readonly id: string\n readonly defaultDialect: ResponsesDialect\n readonly exampleModel?: ModelTarget\n readonly endpointPath: (request: RuntimeProtocolRequest, dialect: ResponsesDialect) => string\n readonly protocolHeaders?: (dialect: ResponsesDialect) => Readonly<Record<string, string>>\n readonly serialize: (\n request: RuntimeProtocolRequest,\n dialect: ResponsesDialect,\n ) => Readonly<Record<string, unknown>>\n readonly translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: RuntimeProtocolRequest,\n displayName: string,\n ) => AsyncGenerator<ProtocolStreamChunk>\n}\n\n/** The OpenAI Responses wire protocol. */\nexport const openAiResponsesProtocol: ProtocolDefinition<ResponsesDialect>\n & ResponsesProtocolDefinition = Object.freeze({\n kind: 'http-wire-protocol' as const,\n apiVersion: 1 as const,\n id: OPENAI_RESPONSES_PROTOCOL_ID,\n defaultDialect: DEFAULT_DIALECT,\n endpointPath: () => '/responses',\n serialize(request: ProtocolRequest, dialect: ResponsesDialect): Readonly<Record<string, unknown>> {\n return serializeResponsesRequest(request, dialect) as unknown as Readonly<Record<string, unknown>>\n },\n // Params are annotated because `Object.freeze` erases the contextual typing the\n // `WireProtocol` annotation would otherwise supply.\n translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: ProtocolRequest,\n displayName: string,\n ): AsyncGenerator<ProtocolStreamChunk> => translateResponsesStream(events, displayName, request),\n})\n\nexport type { ResponsesDialect }\n"],"mappings":";;;AAMA,MAAM,4BAA4B;AAElC,SAAgB,iBAAiB,OAAyC;CACxE,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,CAAC;CACzD,MAAM,QAAQ;CACd,OAAO;EACL,GAAG,OAAO,MAAM,OAAO,WAAW,EAAE,IAAI,MAAM,GAAG,IAAI,CAAC;EACtD,GAAG,OAAO,MAAM,qBAAqB,WACjC,EAAE,kBAAkB,MAAM,iBAAiB,IAC3C,CAAC;EACL,GAAG,MAAM,QAAQ,MAAM,OAAO,IAAI,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;CAClE;AACF;AAEA,SAAgBA,kBAAgB,OAAkB;CAChD,OAAO,MAAM,aAAa,SAAQ,eAAc,WAAW,SAAS,iBAChE,CAAC;EACD,MAAM;EACN,KAAK,WAAW;EAChB,GAAG,WAAW,UAAU,SAAY,CAAC,IAAI,EAAE,OAAO,WAAW,MAAM;EACnE,GAAG,WAAW,eAAe,SAAY,CAAC,IAAI,EAAE,aAAa,WAAW,WAAW;EACnF,GAAG,WAAW,aAAa,SAAY,CAAC,IAAI,EAAE,WAAW,WAAW,SAAS;CAC/E,CAAC,IACC,CAAC,CAAC;AACR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AAI,WACR,GAAG,YAAY,8CACf,kBAAkB,aACpB;AACF;AAEA,SAAS,WAAW,KAAuB,aAAsC;CAC/E,IAAI;EAAE,OAAO,KAAK,MAAM,IAAI,IAAI;CAAqB,SAC9C,OAAgB;EACrB,MAAM,IAAI,WACR,GAAG,YAAY,iCACf,kBAAkB,oBAAoB,EAAE,OAAO,MAAM,CACvD;CACF;AACF;;;;;AC7BA,MAAa,+BAA+B;;;;;;;;;AAU5C,MAAM,kBAAoC,OAAO,OAAO;CACtD,UAAU;CACV,iBAAiB;CACjB,mBAAmB;CACnB,OAAO;CACP,SAAS,OAAO,OAAO,CAAC,6BAA6B,CAAC;CACtD,kBAAkB;AACpB,CAAC;;AA+BD,MAAa,0BACqB,OAAO,OAAO;CAC9C,MAAM;CACN,YAAY;CACZ,IAAI;CACJ,gBAAgB;CAChB,oBAAoB;CACpB,UAAU,SAA0B,SAA8D;EAChG,OAAO,0BAA0B,SAAS,OAAO;CACnD;CAGA,YACE,QACA,SACA,gBACwC,yBAAyB,QAAQ,aAAa,OAAO;AACjG,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["textAnnotations"],"sources":["../src/request-content.ts","../src/request-messages.ts","../src/serialize-options.ts","../src/serialize.ts","../src/stream-items.ts","../src/stream-usage.ts","../src/stream-errors.ts","../src/stream-events.ts","../src/translate.ts","../src/protocol.ts"],"sourcesContent":["import type {\n ContentBlock, DocumentBlock, ImageBlock, NativeToolCallBlock, TextBlock,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { WireContentPart, WireInputItem } from './wire.ts'\nimport type { ResponsesReasoningState } from './serialize-types.ts'\n\nconst DEFAULT_DOCUMENT_FILENAME = 'document.pdf'\n\nexport function reasoningStateOf(value: unknown): ResponsesReasoningState {\n if (typeof value !== 'object' || value === null) return {}\n const state = value as ResponsesReasoningState\n return {\n ...typeof state.id === 'string' ? { id: state.id } : {},\n ...typeof state.encryptedContent === 'string'\n ? { encryptedContent: state.encryptedContent }\n : {},\n ...Array.isArray(state.summary) ? { summary: state.summary } : {},\n ...nonEmptyStrings(state.content),\n }\n}\n\n/** Raw reasoning parts that are usable on the wire; persisted state is not trusted. */\nfunction nonEmptyStrings(value: unknown): { content?: readonly string[] } {\n if (!Array.isArray(value)) return {}\n const content = value.filter((part): part is string => typeof part === 'string' && part.length > 0)\n return content.length === 0 ? {} : { content }\n}\n\nexport function textAnnotations(block: TextBlock) {\n return block.annotations?.flatMap(annotation => annotation.type === 'url-citation'\n ? [{\n type: 'url_citation' as const,\n url: annotation.url,\n ...annotation.title === undefined ? {} : { title: annotation.title },\n ...annotation.startIndex === undefined ? {} : { start_index: annotation.startIndex },\n ...annotation.endIndex === undefined ? {} : { end_index: annotation.endIndex },\n }]\n : [])\n}\n\nexport function imagePart(block: ImageBlock): WireContentPart {\n const detail = block.detail\n if (block.source.kind === 'file') {\n return { type: 'input_image', file_id: block.source.fileId, ...detail === undefined ? {} : { detail } }\n }\n const image_url = block.source.kind === 'url'\n ? block.source.url\n : `data:${block.source.mediaType};base64,${block.source.data}`\n return { type: 'input_image', image_url, ...detail === undefined ? {} : { detail } }\n}\n\nexport function documentPart(block: DocumentBlock): WireContentPart {\n if (block.source.kind === 'file') return { type: 'input_file', file_id: block.source.fileId }\n if (block.source.kind === 'url') return { type: 'input_file', file_url: block.source.url }\n return {\n type: 'input_file',\n // The API reads the file type from the extension here, so a name is required\n // rather than optional; a neutral default beats a rejected request.\n filename: block.filename ?? DEFAULT_DOCUMENT_FILENAME,\n file_data: `data:${block.source.mediaType};base64,${block.source.data}`,\n }\n}\n\nexport function contentPart(block: ContentBlock, role: 'user' | 'assistant'): WireContentPart | undefined {\n if (block.type === 'text') {\n // An assistant turn's own text must come back as `output_text`; sending it as\n // `input_text` would present the model's prior words as if the user said them.\n if (role !== 'assistant') return { type: 'input_text', text: block.text }\n const annotations = textAnnotations(block)\n return {\n type: 'output_text', text: block.text,\n ...annotations === undefined ? {} : { annotations },\n }\n }\n if (block.type === 'image') return imagePart(block)\n if (block.type === 'document') return documentPart(block)\n return undefined\n}\n\nexport function toolResultOutput(blocks: readonly ContentBlock[]): string | WireContentPart[] {\n const hasBinary = blocks.some(block => block.type === 'image' || block.type === 'document')\n if (!hasBinary) {\n // The common case. A plain string keeps the payload small and is what the\n // API documents first.\n return blocks\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n .join('\\n')\n }\n return blocks\n .map(block => contentPart(block, 'user'))\n .filter((part): part is WireContentPart => part !== undefined)\n}\n\nexport function nativeReplayItem(block: NativeToolCallBlock): WireInputItem | undefined {\n const value = block.providerState\n if (typeof value !== 'object' || value === null) return undefined\n const item = value as Record<string, unknown>\n if (item.type === 'web_search_call') {\n return {\n type: 'web_search_call',\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...item.action === undefined ? {} : { action: structuredClone(item.action) },\n }\n }\n if (item.type === 'image_generation_call') return imageReplayItem(item, generatedImage(block))\n return undefined\n}\n\n/** The generated image, as base64; histories recorded before it moved there keep it in the item. */\nfunction generatedImage(block: NativeToolCallBlock): string | undefined {\n const image = block.content.find(content => content.type === 'image' && content.source.kind === 'base64')\n return image?.type === 'image' && image.source.kind === 'base64' ? image.source.data : undefined\n}\n\nfunction imageReplayItem(item: Record<string, unknown>, image: string | undefined): WireInputItem {\n const result = image ?? item.result\n return {\n type: 'image_generation_call',\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...typeof result === 'string' || result === null ? { result } : {},\n }\n}\n","import type { ContentBlock, TextBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { Message } from '@alvin0/ai-agent-sdk-core'\nimport type { WireContentPart, WireInputItem } from './wire.ts'\nimport type { ResponsesReasoningState } from './serialize-types.ts'\nimport { contentPart, reasoningStateOf, toolResultOutput, nativeReplayItem } from './request-content.ts'\n\ninterface MessageState {\n role: 'user' | 'assistant'\n parts: WireContentPart[]\n phase: TextBlock['phase']\n items: WireInputItem[]\n dialectMessagePhase: boolean\n}\n\n/** Flush content at standalone-item boundaries to preserve conversation order. */\nexport function appendMessage(message: Message, items: WireInputItem[], dialectMessagePhase: boolean): void {\n const state: MessageState = {\n role: message.role === 'assistant' ? 'assistant' : 'user', parts: [], phase: undefined,\n items, dialectMessagePhase,\n }\n for (const block of message.content) {\n if (block.type === 'text' || block.type === 'image' || block.type === 'document') appendContent(block, state)\n else appendControl(block, state)\n }\n flushMessage(state)\n}\n\nfunction flushMessage(state: MessageState): void {\n if (state.parts.length === 0) return\n state.items.push({\n type: 'message', role: state.role, content: state.parts,\n ...state.role === 'assistant' && state.dialectMessagePhase && state.phase !== undefined\n ? { phase: state.phase === 'final-answer' ? 'final_answer' as const : state.phase } : {},\n })\n state.parts = []\n state.phase = undefined\n}\n\nfunction appendContent(block: ContentBlock, state: MessageState): void {\n if (block.type === 'text' && block.phase !== undefined && state.phase !== undefined && state.phase !== block.phase) {\n flushMessage(state)\n }\n if (block.type === 'text' && block.phase !== undefined) state.phase = block.phase\n const part = contentPart(block, state.role)\n if (part !== undefined) state.parts.push(part)\n}\n\nfunction appendControl(block: ContentBlock, state: MessageState): void {\n switch (block.type) {\n case 'reasoning':\n flushMessage(state)\n appendReasoning(block, state.items)\n return\n case 'tool-call':\n flushMessage(state)\n state.items.push({ type: 'function_call', call_id: block.id, name: block.name,\n arguments: block.arguments.length > 0 ? block.arguments : '{}' })\n return\n case 'tool-result':\n flushMessage(state)\n state.items.push({ type: 'function_call_output', call_id: block.toolCallId,\n output: toolResultOutput(block.content) })\n return\n case 'native-tool-call': {\n flushMessage(state)\n const replay = nativeReplayItem(block)\n if (replay !== undefined) state.items.push(replay)\n return\n }\n default: return\n }\n}\n\nfunction appendReasoning(block: Extract<ContentBlock, { type: 'reasoning' }>, items: WireInputItem[]): void {\n const state = reasoningStateOf(block.providerState)\n const content = reasoningContent(state, block)\n // Unfinished reasoning has no replay identity and cannot be sent back.\n if (state.id === undefined && state.encryptedContent === undefined) return\n const summary = reasoningSummary(state, block, content)\n items.push({\n type: 'reasoning',\n ...state.id === undefined ? {} : { id: state.id },\n summary: summary.map(text => ({ type: 'summary_text' as const, text })),\n ...content === undefined\n ? {}\n : { content: content.map(text => ({ type: 'reasoning_text' as const, text })) },\n ...state.encryptedContent === undefined ? {} : { encrypted_content: state.encryptedContent },\n })\n}\n\n/**\n * Raw reasoning to replay as `reasoning_text`, never relabelled as a summary.\n *\n * A block read before raw content was tracked still says `kind: 'content'`,\n * which is enough to put its text back where it came from.\n */\nfunction reasoningContent(\n state: ResponsesReasoningState,\n block: Extract<ContentBlock, { type: 'reasoning' }>,\n): readonly string[] | undefined {\n // Raw content needs the item id it belongs to; without one it is not a replay.\n if (state.content !== undefined) return state.id === undefined ? undefined : state.content\n if (state.encryptedContent !== undefined || state.summary !== undefined) return undefined\n if (state.id === undefined || block.kind !== 'content' || block.text.length === 0) return undefined\n return [block.text]\n}\n\nfunction reasoningSummary(\n state: ResponsesReasoningState,\n block: Extract<ContentBlock, { type: 'reasoning' }>,\n content: readonly string[] | undefined,\n): readonly string[] {\n if (state.summary !== undefined && state.summary.length > 0) return state.summary\n // Raw content — tracked, or only known from `reasoning_text` deltas — is never\n // relabelled as a summary, even when it cannot be replayed.\n if (content !== undefined || state.content !== undefined || block.kind === 'content') return []\n return block.text.length > 0 ? [block.text] : []\n}\n","import type { ProtocolRequest } from './contract.ts'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport {\n isNativeToolSchema, type ModelOutputFormat, type ModelToolSchema, type NativeImageGenerationTool,\n type NativeWebSearchTool, type ToolChoice, type ToolSchema,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ResponsesDialect, WireTool, WireToolChoice, WireTextControls } from './wire.ts'\n\nexport function toolChoiceOf(choice: ToolChoice): WireToolChoice {\n if (typeof choice === 'string') return choice\n if (choice.type === 'native') return { type: nativeWireType(choice.name) }\n return { type: 'function', name: choice.name }\n}\n\nexport function functionTool(tool: ToolSchema): WireTool {\n return {\n type: 'function',\n name: tool.name,\n description: tool.description,\n // Strict mode imposes real JSON-Schema restrictions (no optional fields\n // without null, `additionalProperties: false` required). Opting a caller's\n // schema in silently would turn a working tool into a request rejection.\n strict: false,\n parameters: tool.parameters,\n }\n}\n\nexport function nativeWireType(name: string): string {\n if (name === 'web-search') return 'web_search'\n if (name === 'image-generation') return 'image_generation'\n return name.replaceAll('-', '_')\n}\n\nexport function webSearchTool(tool: NativeWebSearchTool): WireTool {\n if (tool.blockedDomains !== undefined) {\n throw new ModelError(\n 'OpenAI Responses web search does not support blockedDomains; use allowedDomains',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n if (tool.maxUses !== undefined) {\n throw new ModelError(\n 'OpenAI Responses web search does not support maxUses',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n type: 'web_search',\n ...tool.searchContextSize === undefined ? {} : { search_context_size: tool.searchContextSize },\n ...tool.allowedDomains === undefined ? {} : { filters: { allowed_domains: [...tool.allowedDomains] } },\n ...tool.userLocation === undefined ? {} : {\n user_location: { type: 'approximate', ...tool.userLocation },\n },\n ...tool.searchContentTypes === undefined ? {} : { search_content_types: [...tool.searchContentTypes] },\n }\n}\n\nexport function imageGenerationTool(tool: NativeImageGenerationTool): WireTool {\n return {\n type: 'image_generation',\n ...tool.size === undefined ? {} : { size: tool.size },\n ...tool.quality === undefined ? {} : { quality: tool.quality },\n ...tool.format === undefined ? {} : { output_format: tool.format },\n ...tool.background === undefined ? {} : { background: tool.background },\n ...tool.partialImages === undefined ? {} : { partial_images: tool.partialImages },\n }\n}\n\nexport function toolOf(tool: ModelToolSchema): WireTool {\n if (!isNativeToolSchema(tool)) return functionTool(tool)\n if (tool.name === 'web-search') return webSearchTool(tool)\n return imageGenerationTool(tool)\n}\n\nexport function textControls(\n format: ModelOutputFormat | undefined,\n dialect: ResponsesDialect,\n): WireTextControls | undefined {\n if (format === undefined) return undefined\n if (format.type === 'text') {\n return dialect.structuredOutputs ? { format: { type: 'text' } } : undefined\n }\n if (!dialect.structuredOutputs) {\n throw new ModelError(\n 'This Responses endpoint does not support JSON Schema output',\n MODEL_ERROR_CODES.INVALID_REQUEST,\n )\n }\n return {\n format: {\n type: 'json_schema',\n name: format.name,\n schema: format.schema,\n strict: true,\n },\n }\n}\n\nexport function toolsOptions(request: ProtocolRequest) {\n const options = request.options\n const tools = options.tools === undefined || options.tools.length === 0 ? undefined : options.tools.map(toolOf)\n return {\n ...tools === undefined ? {} : { tools, parallel_tool_calls: true },\n ...options.toolChoice === undefined ? {} : { tool_choice: toolChoiceOf(options.toolChoice) },\n }\n}\n\nexport function reasoningOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const effort = request.options.reasoningEffort\n if (effort === undefined && dialect.reasoningSummary === undefined) return {}\n return { reasoning: {\n ...effort === undefined ? {} : { effort: String(effort) },\n ...dialect.reasoningSummary === undefined ? {} : { summary: dialect.reasoningSummary },\n } }\n}\n\nexport function dialectOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const text = textControls(request.options.outputFormat, dialect)\n return {\n ...text === undefined ? {} : { text },\n ...dialect.store === undefined ? {} : { store: dialect.store },\n ...dialect.include.length === 0 ? {} : { include: [...dialect.include] },\n ...dialect.promptCacheKey === undefined ? {} : { prompt_cache_key: dialect.promptCacheKey },\n ...dialect.maxOutputTokens && request.maxTokens !== undefined ? { max_output_tokens: request.maxTokens } : {},\n }\n}\n\nexport function samplingOptions(request: ProtocolRequest, dialect: ResponsesDialect) {\n const options = request.options\n return {\n ...dialect.sampling && options.temperature !== undefined ? { temperature: options.temperature } : {},\n ...dialect.sampling && options.topP !== undefined ? { top_p: options.topP } : {},\n }\n}\n","/**\n * Normalized request to Responses API wire JSON.\n *\n * The interesting work is flattening. Our conversation is a list of messages,\n * each holding an ordered list of content blocks; the wire wants a FLAT list of\n * items where a tool result and a tool call are peers of a message rather than\n * parts of one. So one assistant message that reasoned, spoke, and called two\n * tools expands to four items, and their relative order must be preserved\n * because the model reads it as its own prior turn.\n *\n * @module ai-agent-sdk/providers/responses/serialize\n */\n\nimport type { ProtocolRequest } from './contract.ts'\nimport type { ContentBlock } from '@alvin0/ai-agent-sdk-core'\nimport type { ResponsesDialect, WireInputItem, WireRequest } from './wire.ts'\nexport type { ResponsesReasoningState } from './serialize-types.ts'\nimport { appendMessage } from './request-messages.ts'\nimport { toolsOptions, reasoningOptions, dialectOptions, samplingOptions } from './serialize-options.ts'\n\nfunction instructionsOf(request: ProtocolRequest): string {\n const fromMessages = request.options.messages\n .filter(message => message.role === 'system')\n .flatMap(message => message.content)\n .filter((block): block is Extract<ContentBlock, { type: 'text' }> => block.type === 'text')\n .map(block => block.text)\n const all = request.options.system === undefined\n ? fromMessages\n : [request.options.system, ...fromMessages]\n return all.join('\\n\\n')\n}\n\nexport function serializeResponsesRequest(request: ProtocolRequest, dialect: ResponsesDialect): WireRequest {\n const input: WireInputItem[] = []\n for (const message of request.options.messages) {\n if (message.role === 'system') continue\n appendMessage(message, input, dialect.messagePhase === true)\n }\n const instructions = instructionsOf(request)\n return {\n model: request.options.model,\n ...instructions.length === 0 ? {} : { instructions },\n input,\n ...toolsOptions(request),\n ...reasoningOptions(request, dialect),\n ...dialectOptions(request, dialect),\n ...samplingOptions(request, dialect),\n stream: true,\n }\n}\n","import { ToolCallId, type TextAccumulator } from '@alvin0/ai-agent-sdk-core'\nimport { isJsonValue } from '@alvin0/ai-agent-sdk-core'\nimport type {\n AssistantTextPhase, ContentBlock, ImageMediaType, ReasoningKind, TextAnnotation,\n} from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest } from './contract.ts'\nimport type { ResponsesReasoningState } from './serialize.ts'\nimport type { WireOutputItem } from './wire.ts'\n\nexport type ItemKind = 'text' | 'reasoning' | 'tool-call' | 'native-tool-call'\n\nexport interface OpenItem {\n readonly index: number\n readonly kind: ItemKind\n text: TextAccumulator\n args: TextAccumulator\n callId: string\n name: string\n nativeName: string\n /** Last `summary_index` seen, so a new paragraph gets a separator. */\n summaryIndex: number | undefined\n /** Last reasoning `content_index` seen, joined the same way as the done item's parts. */\n contentIndex: number | undefined\n phase: AssistantTextPhase | undefined\n /**\n * Which reasoning stream filled `text`; `mixed` when both did, which leaves\n * the block unlabelled. The done item's summary still overrides it.\n */\n reasoningKind: ReasoningKind | 'mixed' | undefined\n}\n\nexport function textPhase(value: string | undefined): AssistantTextPhase | undefined {\n if (value === 'commentary') return 'commentary'\n if (value === 'final_answer') return 'final-answer'\n return undefined\n}\n\nexport function itemKind(type: string | undefined): ItemKind | undefined {\n switch (type) {\n case 'message': return 'text'\n case 'reasoning': return 'reasoning'\n case 'function_call': return 'tool-call'\n case 'web_search_call': return 'native-tool-call'\n case 'image_generation_call': return 'native-tool-call'\n default: return undefined\n }\n}\n\nexport function nativeName(type: string | undefined): string {\n if (type === 'web_search_call') return 'web-search'\n if (type === 'image_generation_call') return 'image-generation'\n return type?.replace(/_call$/, '').replaceAll('_', '-') ?? 'native-tool'\n}\n\nexport function textAnnotations(item: WireOutputItem): TextAnnotation[] {\n if (!Array.isArray(item.content)) return []\n return item.content.flatMap((part) => {\n if (typeof part !== 'object' || part === null) return []\n const annotations = (part as Record<string, unknown>).annotations\n if (!Array.isArray(annotations)) return []\n return annotations.flatMap((annotation): TextAnnotation[] => {\n if (typeof annotation !== 'object' || annotation === null) return []\n const record = annotation as Record<string, unknown>\n if (record.type !== 'url_citation' || typeof record.url !== 'string') return []\n return [{\n type: 'url-citation',\n url: record.url,\n ...typeof record.title === 'string' ? { title: record.title } : {},\n ...typeof record.start_index === 'number' ? { startIndex: record.start_index } : {},\n ...typeof record.end_index === 'number' ? { endIndex: record.end_index } : {},\n }]\n })\n })\n}\n\nexport function itemText(item: WireOutputItem): string {\n const content = item.content\n if (!Array.isArray(content)) return ''\n return content\n .map((part) => {\n if (typeof part !== 'object' || part === null) return ''\n const record = part as Record<string, unknown>\n return typeof record.text === 'string' ? record.text : ''\n })\n .join('')\n}\n\nexport function itemSummary(item: WireOutputItem): string[] {\n const summary = item.summary\n if (!Array.isArray(summary)) return []\n return summary\n .map((part) => {\n if (typeof part !== 'object' || part === null) return ''\n const record = part as Record<string, unknown>\n return typeof record.text === 'string' ? record.text : ''\n })\n .filter(text => text.length > 0)\n}\n\nexport function doneBlock(\n item: WireOutputItem, open: OpenItem, imageMediaType: ImageMediaType,\n): ContentBlock | undefined {\n switch (open.kind) {\n case 'text': return doneText(item, open)\n case 'reasoning': return doneReasoning(item, open)\n case 'tool-call': return doneTool(item, open)\n case 'native-tool-call': return doneNative(item, open, imageMediaType)\n default: return undefined\n }\n}\n\nfunction doneText(item: WireOutputItem, open: OpenItem): ContentBlock {\n const text = itemText(item)\n const phase = textPhase(item.phase) ?? open.phase\n return {\n type: 'text',\n text: text.length > 0 ? text : open.text.text,\n ...phase === undefined ? {} : { phase },\n ...textAnnotations(item).length === 0 ? {} : { annotations: textAnnotations(item) },\n }\n}\n\nfunction doneReasoning(item: WireOutputItem, open: OpenItem): ContentBlock {\n const summary = itemSummary(item)\n const content = itemReasoningContent(item)\n const state: ResponsesReasoningState = {\n ...typeof item.id === 'string' ? { id: item.id } : {},\n ...typeof item.encrypted_content === 'string'\n ? { encryptedContent: item.encrypted_content }\n : {},\n ...summary.length > 0 ? { summary } : {},\n ...content.length > 0 ? { content } : {},\n }\n const kind = reasoningKindOf(open, summary, content)\n return {\n type: 'reasoning',\n text: reasoningTextOf(open, summary, content),\n ...kind === undefined ? {} : { kind },\n providerState: state,\n }\n}\n\nfunction reasoningKindOf(open: OpenItem, summary: readonly string[], content: readonly string[])\n : ReasoningKind | undefined {\n if (summary.length > 0) return 'summary'\n if (open.reasoningKind === 'mixed') return undefined\n if (open.reasoningKind !== undefined) return open.reasoningKind\n return content.length > 0 ? 'content' : undefined\n}\n\n/** A server that skips the delta events still puts the thoughts on the done item. */\nfunction reasoningTextOf(open: OpenItem, summary: readonly string[], content: readonly string[]): string {\n if (summary.length > 0) return summary.join('\\n\\n')\n if (open.text.length > 0) return open.text.text\n return content.join('\\n\\n')\n}\n\n/** `reasoning_text` parts of a done reasoning item, in order. */\nexport function itemReasoningContent(item: WireOutputItem): string[] {\n const content = item.content\n if (!Array.isArray(content)) return []\n return content.flatMap((part) => {\n if (typeof part !== 'object' || part === null) return []\n const record = part as Record<string, unknown>\n return record.type === 'reasoning_text' && typeof record.text === 'string' && record.text.length > 0\n ? [record.text]\n : []\n })\n}\n\nfunction doneTool(item: WireOutputItem, open: OpenItem): ContentBlock {\n const args = typeof item.arguments === 'string' && item.arguments.length > 0\n ? item.arguments\n : open.args.text\n return {\n type: 'tool-call',\n id: ToolCallId(item.call_id ?? open.callId),\n name: item.name ?? open.name,\n arguments: args.length > 0 ? args : '{}',\n }\n}\n\nfunction doneNative(item: WireOutputItem, open: OpenItem, imageMediaType: ImageMediaType): ContentBlock {\n const content: ContentBlock[] = open.nativeName === 'image-generation'\n && typeof item.result === 'string' && item.result.length > 0\n ? [{\n type: 'image',\n source: { kind: 'base64', mediaType: imageMediaType, data: item.result },\n }]\n : []\n return {\n type: 'native-tool-call',\n id: item.id ?? open.callId,\n name: open.nativeName,\n ...typeof item.status === 'string' ? { status: item.status } : {},\n ...isJsonValue(item.action) ? { arguments: item.action } : {},\n content,\n // The image is kept once, as public content; replay reads it back from there.\n providerState: content.length > 0 ? withoutResult(item) : item,\n }\n}\n\nfunction withoutResult(item: WireOutputItem): WireOutputItem {\n const { result: _result, ...rest } = item\n return rest\n}\n\n\nexport function kindToBlockType(kind: ItemKind): 'text' | 'reasoning' | 'tool-call' | 'native-tool-call' {\n return kind\n}\n\nexport function requestedImageMediaType(request: ProtocolRequest | undefined): ImageMediaType {\n const tool = request?.options.tools?.find(candidate => 'type' in candidate\n && candidate.type === 'native'\n && candidate.name === 'image-generation')\n if (tool === undefined || !('format' in tool)) return 'image/png'\n if (tool.format === 'jpeg') return 'image/jpeg'\n if (tool.format === 'webp') return 'image/webp'\n return 'image/png'\n}","import type { UsageCounters } from '@alvin0/ai-agent-sdk-core'\nimport type { WireUsage } from './wire.ts'\n\nexport function mapUsage(usage: WireUsage): UsageCounters | undefined {\n const source = usage as unknown as Record<string, unknown>\n const details = recordOrUndefined(source.input_tokens_details)\n const rawInput = source.input_tokens\n const outputTokens = source.output_tokens\n const cacheRead = details?.cached_tokens\n const cacheWrite = details?.cache_write_tokens\n const reasoning = reasoningCounter(source)\n const totalTokens = source.total_tokens\n const hasAny = [rawInput, outputTokens, cacheRead, cacheWrite, reasoning, totalTokens]\n .some(value => value !== undefined)\n if (!hasAny) return undefined\n\n const normalized: Record<string, unknown> = {\n ...outputTokens === undefined ? {} : { outputTokens },\n ...totalTokens === undefined ? {} : { totalTokens },\n // Omitted cache details are authoritative zero for Responses. Present\n // malformed values are retained for the accounting validator.\n ...omittedCounter(cacheRead) ? {} : { cacheReadTokens: cacheRead },\n ...omittedCounter(cacheWrite) ? {} : { cacheWriteTokens: cacheWrite },\n ...omittedCounter(reasoning) ? {} : { reasoningTokens: reasoning },\n }\n if (rawInput !== undefined) {\n normalized.inputTokens = disjointInput(rawInput, cacheRead, cacheWrite)\n }\n return normalized as UsageCounters\n}\n\nfunction recordOrUndefined(value: unknown): Record<string, unknown> | undefined {\n return typeof value === 'object' && value !== null ? value as Record<string, unknown> : undefined\n}\n\nfunction omittedCounter(value: unknown): boolean { return value === undefined || value === 0 }\n\nfunction disjointInput(rawInput: unknown, cacheRead: unknown, cacheWrite: unknown): unknown {\n // Responses includes both cache buckets in input_tokens. The SDK accounts\n // for them separately; do not count cache writes twice or clamp invalid data.\n return typeof rawInput === 'number' && (cacheRead === undefined || typeof cacheRead === 'number')\n && (cacheWrite === undefined || typeof cacheWrite === 'number')\n ? rawInput - (cacheRead ?? 0) - (cacheWrite ?? 0) : rawInput\n}\n\nfunction reasoningCounter(source: Record<string, unknown>): unknown {\n return recordOrUndefined(source.output_tokens_details)?.reasoning_tokens\n}\n","import { CONTEXT_WINDOW_EXCEEDED_CODE, QUOTA_EXCEEDED_CODE } from '@alvin0/ai-agent-sdk-core'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { WireResponse } from './wire.ts'\n\nconst TERMINAL_ERROR_CODES: Readonly<Record<string, string>> = Object.freeze({\n context_length_exceeded: CONTEXT_WINDOW_EXCEEDED_CODE,\n insufficient_quota: QUOTA_EXCEEDED_CODE,\n invalid_prompt: MODEL_ERROR_CODES.INVALID_REQUEST,\n bio_policy: MODEL_ERROR_CODES.INVALID_REQUEST,\n cyber_policy: MODEL_ERROR_CODES.INVALID_REQUEST,\n misalignment_policy_violation: MODEL_ERROR_CODES.INVALID_REQUEST,\n rate_limit_exceeded: MODEL_ERROR_CODES.RATE_LIMIT,\n})\n\n\nexport function failedError(response: WireResponse | undefined, displayName: string): ModelError {\n const error = response?.error ?? undefined\n const code = error?.code ?? error?.type\n const message = error?.message ?? `${displayName} reported a failed response${failureContext(response, code)}`\n const mapped = code === undefined ? undefined : TERMINAL_ERROR_CODES[code]\n return new ModelError(\n message,\n // An unrecognized failure defaults to SERVER, which IS in the retryable set:\n // the request produced nothing, so repeating it is safe and often works.\n mapped ?? MODEL_ERROR_CODES.SERVER,\n {},\n )\n}\n\nfunction failureContext(response: WireResponse | undefined, code: string | undefined): string {\n const facts = [\n code === undefined ? 'no error detail' : `code ${code}`,\n ...typeof response?.id === 'string' && /^[\\w.:-]{1,128}$/.test(response.id) ? [`response ${response.id}`] : [],\n ...typeof response?.status === 'string' && /^[\\w-]{1,32}$/.test(response.status)\n ? [`status ${response.status}`] : [],\n ]\n return ` (${facts.join(', ')})`\n}","import type { WireOutputItem } from './wire.ts'\nimport type { ItemKind } from './stream-items.ts'\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport { TextAccumulator, ToolCallId } from '@alvin0/ai-agent-sdk-core'\nimport type { ImageMediaType } from '@alvin0/ai-agent-sdk-core'\nimport type { FinishReason } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolStreamChunk } from './contract.ts'\nimport type { WireErrorBody, WireStreamEvent } from './wire.ts'\nimport { textPhase, itemKind, nativeName, kindToBlockType, doneBlock, type OpenItem } from './stream-items.ts'\nimport { mapUsage } from './stream-usage.ts'\nimport { failedError } from './stream-errors.ts'\n\nexport interface StreamState {\n open: Map<string, OpenItem>\n nextIndex: number\n sawToolCall: boolean\n imageMediaType: ImageMediaType\n /** An answer text block was completed. */\n sawText: boolean\n /** Text of the latest completed reasoning block. */\n lastReasoning: string | undefined\n /** The caller asked for JSON output. */\n jsonOutput: boolean\n}\n\nexport function* translateEvent(\n state: StreamState, event: WireStreamEvent, displayName: string,\n): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'response.output_item.added': yield* itemAdded(state, event); return\n case 'response.output_item.done': yield* itemDone(state, event); return\n case 'response.completed': yield* completed(state, event); return\n case 'response.incomplete': yield* incomplete(event, displayName); return\n case 'response.failed': yield* failed(event, displayName); return\n case 'error': yield* inlineError(event, displayName); return\n default: yield* deltaEvent(state, event); return\n }\n}\n\nfunction* itemAdded(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const item = event.item\n const id = item?.id ?? event.item_id\n const kind = itemKind(item?.type)\n if (item === undefined || id === undefined || kind === undefined) return\n if (state.open.has(id)) return\n const entry = createOpenItem(state, item, { id, kind })\n state.open.set(id, entry)\n if (kind === 'tool-call') state.sawToolCall = true\n yield { type: 'block-start', index: entry.index, blockType: kindToBlockType(kind) }\n}\n\nfunction* textDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.text.append(event.delta)\n yield {\n type: 'text-delta', index: entry.index, text: event.delta,\n ...entry.phase === undefined ? {} : { phase: entry.phase },\n }\n}\n\nfunction* summaryDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n // A new summary paragraph starts; separate it from the previous one so the\n // assembled text does not run two thoughts together.\n const separator = entry.summaryIndex !== undefined\n && event.summary_index !== undefined\n && event.summary_index !== entry.summaryIndex\n ? '\\n\\n'\n : ''\n entry.summaryIndex = event.summary_index\n const text = `${separator}${event.delta}`\n entry.text.append(text)\n entry.reasoningKind = mergeKind(entry.reasoningKind, 'summary')\n yield { type: 'reasoning-delta', index: entry.index, text, kind: 'summary' }\n}\n\nfunction* reasoningDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n // A new raw-reasoning part: separate it the way the done item's parts are joined.\n const separator = entry.contentIndex !== undefined\n && event.content_index !== undefined\n && event.content_index !== entry.contentIndex\n ? '\\n\\n'\n : ''\n if (event.content_index !== undefined) entry.contentIndex = event.content_index\n const text = `${separator}${event.delta}`\n entry.text.append(text)\n entry.reasoningKind = mergeKind(entry.reasoningKind, 'content')\n yield { type: 'reasoning-delta', index: entry.index, text, kind: 'content' }\n}\n\nfunction mergeKind(current: OpenItem['reasoningKind'], next: 'summary' | 'content'): OpenItem['reasoningKind'] {\n return current === undefined || current === next ? next : 'mixed'\n}\n\nfunction* toolDelta(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const entry = event.item_id === undefined ? undefined : state.open.get(event.item_id)\n if (entry === undefined || event.delta === undefined) return\n entry.args.append(event.delta)\n yield {\n type: 'tool-call-delta',\n index: entry.index,\n id: ToolCallId(entry.callId),\n ...entry.name.length > 0 ? { name: entry.name } : {},\n argumentsDelta: event.delta,\n }\n}\n\nfunction* partialImage(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const itemId = event.item_id\n const entry = itemId === undefined ? undefined : state.open.get(itemId)\n if (itemId === undefined || entry === undefined || event.partial_image_b64 === undefined) return\n yield {\n type: 'image-delta',\n index: entry.index,\n itemId,\n data: event.partial_image_b64,\n mediaType: state.imageMediaType,\n ...event.partial_image_index === undefined\n ? {}\n : { partialIndex: event.partial_image_index },\n }\n}\n\nfunction* itemDone(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n const item = event.item\n const id = item?.id ?? event.item_id\n const entry = id === undefined ? undefined : state.open.get(id)\n if (item === undefined || entry === undefined) return\n const block = doneBlock(item, entry, state.imageMediaType)\n if (block === undefined) return\n if (block.type === 'text' && block.text.length > 0) state.sawText = true\n if (block.type === 'reasoning') state.lastReasoning = block.text\n yield { type: 'block-end', index: entry.index, block }\n}\n\nfunction* completed(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n if (state.jsonOutput && !state.sawText && !state.sawToolCall) yield* recoveredJsonAnswer(state)\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n // This API has no explicit stop reason. Tool calls in the output ARE the\n // signal that the turn expects results back, which is what an agent loop\n // branches on.\n const reason: FinishReason = state.sawToolCall ? { kind: 'tool-calls' } : { kind: 'stop' }\n yield { type: 'finish', reason }\n}\n\n/**\n * Recover a structured answer that a reasoning parser misfiled.\n *\n * vLLM-style servers running a reasoning parser alongside guided decoding can\n * put the whole JSON answer in the reasoning item and emit no message at all\n * (seen live on DeepSeek V4 behind FPT AI Marketplace). The caller asked for\n * JSON and is about to parse the text, so when the reasoning IS a JSON\n * document it is also emitted as the answer.\n */\nfunction* recoveredJsonAnswer(state: StreamState): Generator<ProtocolStreamChunk> {\n const trimmed = state.lastReasoning?.trim()\n if (trimmed === undefined || !/^[[{]/.test(trimmed)) return\n try { JSON.parse(trimmed) } catch { return }\n const index = state.nextIndex++\n yield { type: 'block-start', index, blockType: 'text' }\n yield { type: 'text-delta', index, text: trimmed }\n yield { type: 'block-end', index, block: { type: 'text', text: trimmed } }\n}\n\nfunction* incomplete(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n const why = event.response?.incomplete_details?.reason\n if (why === 'max_output_tokens') {\n yield { type: 'finish', reason: { kind: 'max-tokens' } }\n return\n }\n throw new ModelError(\n `${displayName} returned an incomplete response (${why ?? 'unknown reason'})`,\n MODEL_ERROR_CODES.SERVER,\n )\n}\n\nfunction* failed(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n // A failed generation can still be billed. Preserve the provider's\n // counters before the transport records the failure and retry admission.\n const usage = event.response?.usage ?? undefined\n const mapped = usage === undefined ? undefined : mapUsage(usage)\n if (mapped !== undefined) yield { type: 'usage', usage: mapped }\n throw failedError(event.response, displayName)\n}\n\nfunction* inlineError(event: WireStreamEvent, displayName: string): Generator<ProtocolStreamChunk> {\n // A top-level error event carries its fields inline rather than under a\n // `response` object, so it is reshaped to reuse the same classifier.\n const inline: WireErrorBody = {\n ...event.code === undefined ? {} : { code: event.code },\n ...event.message === undefined ? {} : { message: event.message },\n }\n throw failedError({ error: inline }, displayName)\n}\n\nfunction* deltaEvent(state: StreamState, event: WireStreamEvent): Generator<ProtocolStreamChunk> {\n switch (event.type) {\n case 'response.output_text.delta': yield* textDelta(state, event); return\n case 'response.reasoning_summary_text.delta': yield* summaryDelta(state, event); return\n case 'response.reasoning_text.delta': yield* reasoningDelta(state, event); return\n case 'response.function_call_arguments.delta': yield* toolDelta(state, event); return\n case 'response.image_generation_call.partial_image': yield* partialImage(state, event); return\n default: return\n }\n}\n\nfunction createOpenItem(\n state: StreamState, item: WireOutputItem, identity: { id: string; kind: ItemKind },\n): OpenItem {\n const { id, kind } = identity\n return {\n index: state.nextIndex++,\n kind,\n text: new TextAccumulator(),\n args: new TextAccumulator(),\n callId: item.call_id ?? id,\n name: item.name ?? '',\n nativeName: nativeName(item.type),\n summaryIndex: undefined,\n contentIndex: undefined,\n phase: textPhase(item.phase),\n reasoningKind: undefined,\n }\n}\n","/**\n * Responses API SSE events to the SDK's chunk protocol.\n *\n * Two design notes worth reading before changing anything here.\n *\n * First, block correlation is keyed on `item_id`, not on the provider's\n * `output_index`. Item ids are stable and present on every delta event, whereas\n * index fields vary by event type, so keying on the id and assigning our OWN\n * indices in first-seen order is both simpler and closer to what our protocol\n * promises.\n *\n * Second, reasoning state is carried on the reasoning BLOCK\n * (`ReasoningBlock.providerState`) rather than in the stream's `replayState`\n * envelope. The envelope has to stay positionally aligned with emitted blocks and\n * is discarded whole when it drifts; attaching the state to the block it belongs\n * to cannot drift, and it survives assembly for free.\n *\n * @module ai-agent-sdk/providers/responses/translate\n */\n\nimport { MODEL_ERROR_CODES, ModelError } from '@alvin0/ai-agent-sdk-core'\nimport type { ProtocolRequest, ProtocolSseEvent, ProtocolStreamChunk } from './contract.ts'\nimport type { WireStreamEvent } from './wire.ts'\nimport { requestedImageMediaType } from './stream-items.ts'\nimport { translateEvent, type StreamState } from './stream-events.ts'\n\nexport async function* translateResponsesStream(\n events: AsyncIterable<ProtocolSseEvent>, displayName: string, request?: ProtocolRequest,\n): AsyncGenerator<ProtocolStreamChunk> {\n const state: StreamState = {\n open: new Map(), nextIndex: 0, sawToolCall: false, imageMediaType: requestedImageMediaType(request),\n sawText: false, lastReasoning: undefined,\n jsonOutput: request?.options.outputFormat?.type === 'json_schema',\n }\n for await (const raw of events) {\n const event = parseEvent(raw, displayName)\n yield* translateEvent(state, event, displayName)\n if (event.type === 'response.completed' || event.type === 'response.incomplete') return\n }\n throw new ModelError(\n `${displayName} stream ended before the response completed`,\n MODEL_ERROR_CODES.STREAM_CLOSED,\n )\n}\n\nfunction parseEvent(raw: ProtocolSseEvent, displayName: string): WireStreamEvent {\n try { return JSON.parse(raw.data) as WireStreamEvent }\n catch (error: unknown) {\n throw new ModelError(\n `${displayName} sent a malformed stream event`,\n MODEL_ERROR_CODES.MALFORMED_RESPONSE, { cause: error },\n )\n }\n}\n","/**\n * The OpenAI Responses protocol, as a reusable {@link WireProtocol}.\n *\n * Spoken by `api.openai.com`, by the ChatGPT-backed Codex endpoint, and by a\n * growing number of compatible gateways. None of them needs its own translation\n * code — they differ only in the dialect knobs below.\n *\n * @module ai-agent-sdk/providers/protocols/openai-responses\n */\n\nimport type {\n ProtocolDefinition,\n ProtocolRequest,\n ProtocolSseEvent,\n ProtocolStreamChunk,\n} from './contract.ts'\nimport type { ModelTarget, ResolvedModelInfo } from '@alvin0/ai-agent-sdk-core/provider'\nimport { serializeResponsesRequest } from './serialize.ts'\nimport { translateResponsesStream } from './translate.ts'\nimport type { ResponsesDialect } from './wire.ts'\n\n/** Protocol id, usable as a stable string in configuration. */\nexport const OPENAI_RESPONSES_PROTOCOL_ID = 'openai-responses'\n\n/**\n * Conservative defaults.\n *\n * `store: false` because retaining prompts server-side should be an explicit\n * decision, not something an SDK turns on for you. `include` carries\n * `reasoning.encrypted_content` because without it a reasoning model loses its\n * chain of thought between a tool call and the tool's result.\n */\nconst DEFAULT_DIALECT: ResponsesDialect = Object.freeze({\n sampling: true,\n maxOutputTokens: true,\n structuredOutputs: true,\n store: false,\n include: Object.freeze(['reasoning.encrypted_content']),\n reasoningSummary: 'auto',\n})\n\ninterface RuntimeProtocolRequest extends ProtocolRequest {\n readonly model: ResolvedModelInfo\n readonly connection: {\n readonly baseUrl: string\n readonly headers: Readonly<Record<string, string>>\n }\n}\n\n/** Marker-based runtime view, kept structurally independent from provider-http. */\nexport interface ResponsesProtocolDefinition {\n readonly kind: 'http-wire-protocol'\n readonly apiVersion: 1\n readonly id: string\n readonly defaultDialect: ResponsesDialect\n readonly exampleModel?: ModelTarget\n readonly endpointPath: (request: RuntimeProtocolRequest, dialect: ResponsesDialect) => string\n readonly protocolHeaders?: (dialect: ResponsesDialect) => Readonly<Record<string, string>>\n readonly serialize: (\n request: RuntimeProtocolRequest,\n dialect: ResponsesDialect,\n ) => Readonly<Record<string, unknown>>\n readonly translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: RuntimeProtocolRequest,\n displayName: string,\n ) => AsyncGenerator<ProtocolStreamChunk>\n}\n\n/** The OpenAI Responses wire protocol. */\nexport const openAiResponsesProtocol: ProtocolDefinition<ResponsesDialect>\n & ResponsesProtocolDefinition = Object.freeze({\n kind: 'http-wire-protocol' as const,\n apiVersion: 1 as const,\n id: OPENAI_RESPONSES_PROTOCOL_ID,\n defaultDialect: DEFAULT_DIALECT,\n endpointPath: () => '/responses',\n serialize(request: ProtocolRequest, dialect: ResponsesDialect): Readonly<Record<string, unknown>> {\n return serializeResponsesRequest(request, dialect) as unknown as Readonly<Record<string, unknown>>\n },\n // Params are annotated because `Object.freeze` erases the contextual typing the\n // `WireProtocol` annotation would otherwise supply.\n translate: (\n events: AsyncIterable<ProtocolSseEvent>,\n request: ProtocolRequest,\n displayName: string,\n ): AsyncGenerator<ProtocolStreamChunk> => translateResponsesStream(events, displayName, request),\n})\n\nexport type { ResponsesDialect }\n"],"mappings":";;;AAMA,MAAM,4BAA4B;AAElC,SAAgB,iBAAiB,OAAyC;CACxE,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,CAAC;CACzD,MAAM,QAAQ;CACd,OAAO;EACL,GAAG,OAAO,MAAM,OAAO,WAAW,EAAE,IAAI,MAAM,GAAG,IAAI,CAAC;EACtD,GAAG,OAAO,MAAM,qBAAqB,WACjC,EAAE,kBAAkB,MAAM,iBAAiB,IAC3C,CAAC;EACL,GAAG,MAAM,QAAQ,MAAM,OAAO,IAAI,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;EAChE,GAAG,gBAAgB,MAAM,OAAO;CAClC;AACF;;AAGA,SAAS,gBAAgB,OAAiD;CACxE,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC;CACnC,MAAM,UAAU,MAAM,QAAQ,SAAyB,OAAO,SAAS,YAAY,KAAK,SAAS,CAAC;CAClG,OAAO,QAAQ,WAAW,IAAI,CAAC,IAAI,EAAE,QAAQ;AAC/C;AAEA,SAAgBA,kBAAgB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IAAI,MAAM,SAAS,wBAAwB,MAAM,SAAS,uBAAuB;CACnF;CACA,MAAM,IAAI,WACR,GAAG,YAAY,8CACf,kBAAkB,aACpB;AACF;AAEA,SAAS,WAAW,KAAuB,aAAsC;CAC/E,IAAI;EAAE,OAAO,KAAK,MAAM,IAAI,IAAI;CAAqB,SAC9C,OAAgB;EACrB,MAAM,IAAI,WACR,GAAG,YAAY,iCACf,kBAAkB,oBAAoB,EAAE,OAAO,MAAM,CACvD;CACF;AACF;;;;;AC/BA,MAAa,+BAA+B;;;;;;;;;AAU5C,MAAM,kBAAoC,OAAO,OAAO;CACtD,UAAU;CACV,iBAAiB;CACjB,mBAAmB;CACnB,OAAO;CACP,SAAS,OAAO,OAAO,CAAC,6BAA6B,CAAC;CACtD,kBAAkB;AACpB,CAAC;;AA+BD,MAAa,0BACqB,OAAO,OAAO;CAC9C,MAAM;CACN,YAAY;CACZ,IAAI;CACJ,gBAAgB;CAChB,oBAAoB;CACpB,UAAU,SAA0B,SAA8D;EAChG,OAAO,0BAA0B,SAAS,OAAO;CACnD;CAGA,YACE,QACA,SACA,gBACwC,yBAAyB,QAAQ,aAAa,OAAO;AACjG,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"name": "alvin0 - chaulamdinhai",
|
|
5
5
|
"email": "chaulamdinhai@gmail.com"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.17",
|
|
8
8
|
"description": "Universal OpenAI Responses and Codex wire schema, serializer, translator, and dialect for ai-agent-sdk",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"provenance": true
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@alvin0/ai-agent-sdk-core": "^0.1.
|
|
41
|
+
"@alvin0/ai-agent-sdk-core": "^0.1.17"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@alvin0/ai-agent-sdk-core": "^0.1.
|
|
44
|
+
"@alvin0/ai-agent-sdk-core": "^0.1.17",
|
|
45
45
|
"@arethetypeswrong/cli": "0.18.5",
|
|
46
46
|
"playwright": "1.62.1",
|
|
47
47
|
"publint": "0.3.24",
|