@silverprotocol/openai-agents 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -116,7 +116,9 @@ import {
116
116
  // the underlying OpenAI Responses streaming events the runtime would emit.
117
117
  // ─────────────────────────────────────────────────────────────────────────────
118
118
 
119
- /** Assistant message content part (protocol `OutputText`). */
119
+ /** Assistant message content part (protocol `OutputText`).
120
+ * @beta
121
+ */
120
122
  export interface OpenAIOutputText {
121
123
  type: "output_text";
122
124
  text: string;
@@ -124,7 +126,9 @@ export interface OpenAIOutputText {
124
126
  annotations?: OpenAIAnnotation[];
125
127
  }
126
128
 
127
- /** url_citation annotation on an output_text part (openai-node `ResponseCitationAnnotation`). */
129
+ /** url_citation annotation on an output_text part (openai-node `ResponseCitationAnnotation`).
130
+ * @beta
131
+ */
128
132
  export interface OpenAIUrlCitationAnnotation {
129
133
  type: "url_citation";
130
134
  url: string;
@@ -133,7 +137,9 @@ export interface OpenAIUrlCitationAnnotation {
133
137
  end_index?: number;
134
138
  }
135
139
 
136
- /** file_citation annotation on an output_text part. */
140
+ /** file_citation annotation on an output_text part.
141
+ * @beta
142
+ */
137
143
  export interface OpenAIFileCitationAnnotation {
138
144
  type: "file_citation";
139
145
  file_id?: string;
@@ -141,19 +147,27 @@ export interface OpenAIFileCitationAnnotation {
141
147
  index?: number;
142
148
  }
143
149
 
144
- /** The subset of annotations that the normalizer handles. */
150
+ /** The subset of annotations that the normalizer handles.
151
+ * @beta
152
+ */
145
153
  export type OpenAIAnnotation = OpenAIUrlCitationAnnotation | OpenAIFileCitationAnnotation;
146
154
 
147
- /** `Refusal` content part — the model refused to answer (openai-node `ResponseOutputRefusal`). */
155
+ /** `Refusal` content part — the model refused to answer (openai-node `ResponseOutputRefusal`).
156
+ * @beta
157
+ */
148
158
  export interface OpenAIRefusal {
149
159
  type: "refusal";
150
160
  refusal: string;
151
161
  }
152
162
 
153
- /** Union of assistant message content parts the normalizer handles. */
163
+ /** Union of assistant message content parts the normalizer handles.
164
+ * @beta
165
+ */
154
166
  export type OpenAIContentPart = OpenAIOutputText | OpenAIRefusal;
155
167
 
156
- /** protocol `AssistantMessageItem` (the `rawItem` of a message_output_item). */
168
+ /** protocol `AssistantMessageItem` (the `rawItem` of a message_output_item).
169
+ * @beta
170
+ */
157
171
  export interface OpenAIAssistantMessageItem {
158
172
  type?: "message";
159
173
  role: "assistant";
@@ -179,11 +193,15 @@ export interface OpenAIAssistantMessageItem {
179
193
  * items (verified against 0.14.0's `dist/types/protocol.d.ts` — NOT the
180
194
  * computer_call/computer_call_result or tool_search items). Carried on
181
195
  * `tool.start`/`tool.done` `providerMetadata` (wire names verbatim, the
182
- * claude facet's wrapper-carry precedent); absent caller ⇒ no metadata key. */
196
+ * claude facet's wrapper-carry precedent); absent caller ⇒ no metadata key.
197
+ * @beta
198
+ */
183
199
  export type OpenAIToolCaller = { type: "direct" } | { type: "program"; callerId: string };
184
200
 
185
201
  /** protocol `FunctionCallItem` (the `rawItem` of a tool_call_item). `callId` is
186
- * the model's call_id; `id` is the Responses `fc_…` item id (DISTINCT). */
202
+ * the model's call_id; `id` is the Responses `fc_…` item id (DISTINCT).
203
+ * @beta
204
+ */
187
205
  export interface OpenAIFunctionCallItem {
188
206
  type: "function_call";
189
207
  callId: string;
@@ -196,7 +214,9 @@ export interface OpenAIFunctionCallItem {
196
214
  }
197
215
 
198
216
  /** protocol `ToolOutputText` — the BARE-OBJECT arm of `FunctionCallResultItem.
199
- * output` (`output: {type:"text", text}`, not wrapped in an array). */
217
+ * output` (`output: {type:"text", text}`, not wrapped in an array).
218
+ * @beta
219
+ */
200
220
  export interface OpenAIToolOutputText {
201
221
  type: "text";
202
222
  text: string;
@@ -222,6 +242,7 @@ export interface OpenAIToolOutputText {
222
242
  * modeled/handled here, matching the PRE-EXISTING scope of the bare-object
223
243
  * arm (which also only maps `type:"text"`, never `type:"image"`/`"file"`) —
224
244
  * `input_image`/`input_file` array elements remain intentionally unhandled.
245
+ * @beta
225
246
  */
226
247
  export interface OpenAIToolOutputInputText {
227
248
  type: "input_text";
@@ -231,7 +252,9 @@ export interface OpenAIToolOutputInputText {
231
252
  /** protocol `FunctionCallResultItem` (the `rawItem` of a tool_call_output_item).
232
253
  * `output` is a string, a bare content object ({@link OpenAIToolOutputText}),
233
254
  * or a content-part ARRAY ({@link OpenAIToolOutputInputText}[]) — the wrapper's
234
- * own `output` field carries the stringified primary output. */
255
+ * own `output` field carries the stringified primary output.
256
+ * @beta
257
+ */
235
258
  export interface OpenAIFunctionCallResultItem {
236
259
  type: "function_call_result";
237
260
  name: string;
@@ -250,7 +273,9 @@ export interface OpenAIFunctionCallResultItem {
250
273
  // `types/protocol.ts`: `ShellCallItem` / `ShellCallResultItem` /
251
274
  // `ApplyPatchCallItem` / `ApplyPatchCallResultItem` / `HostedToolCallItem`).
252
275
 
253
- /** protocol `ShellAction` — the shell tool's per-call command spec. */
276
+ /** protocol `ShellAction` — the shell tool's per-call command spec.
277
+ * @beta
278
+ */
254
279
  export interface OpenAIShellAction {
255
280
  commands: string[];
256
281
  timeoutMs?: number;
@@ -263,7 +288,9 @@ export interface OpenAIShellAction {
263
288
  * Unlike `function_call`, there is no per-fragment argument-delta stream for
264
289
  * this shape on this seam — the whole `action` arrives complete on this ONE
265
290
  * wrapper, so this run-item (not the raw stream) is the sole tool-start
266
- * source for it. */
291
+ * source for it.
292
+ * @beta
293
+ */
267
294
  export interface OpenAIShellCallItem {
268
295
  type: "shell_call";
269
296
  callId: string;
@@ -274,13 +301,17 @@ export interface OpenAIShellCallItem {
274
301
  providerData?: { [k: string]: JsonValue };
275
302
  }
276
303
 
277
- /** protocol `ShellCallOutcome` (per-command exit signal). */
304
+ /** protocol `ShellCallOutcome` (per-command exit signal).
305
+ * @beta
306
+ */
278
307
  export interface OpenAIShellCallOutcome {
279
308
  type: "timeout" | "exit";
280
309
  exitCode?: number | null;
281
310
  }
282
311
 
283
- /** protocol `ShellCallOutputContent` (one command's stdout/stderr/outcome). */
312
+ /** protocol `ShellCallOutputContent` (one command's stdout/stderr/outcome).
313
+ * @beta
314
+ */
284
315
  export interface OpenAIShellCallOutputContent {
285
316
  stdout: string;
286
317
  stderr: string;
@@ -292,7 +323,9 @@ export interface OpenAIShellCallOutputContent {
292
323
  * DIFFERENT shape from `OpenAIFunctionCallResultItem.output` (a bare string /
293
324
  * content-part union); the two must NOT be handled by the same generic path
294
325
  * (that was the orphan-hazard: shape-compatible-enough field NAMES let a
295
- * `tool.done` fire with silently-empty content). */
326
+ * `tool.done` fire with silently-empty content).
327
+ * @beta
328
+ */
296
329
  export interface OpenAIShellCallResultItem {
297
330
  type: "shell_call_output";
298
331
  callId: string;
@@ -309,7 +342,9 @@ export interface OpenAIShellCallResultItem {
309
342
  providerData?: { [k: string]: JsonValue };
310
343
  }
311
344
 
312
- /** protocol `ApplyPatchOperation` (one file edit — create/update/delete). */
345
+ /** protocol `ApplyPatchOperation` (one file edit — create/update/delete).
346
+ * @beta
347
+ */
313
348
  export interface OpenAIApplyPatchOperation {
314
349
  type: "create_file" | "update_file" | "delete_file";
315
350
  path: string;
@@ -320,7 +355,9 @@ export interface OpenAIApplyPatchOperation {
320
355
  /** protocol `ApplyPatchCallItem` (a `tool_called` rawItem for OpenAI's native
321
356
  * apply-patch built-in tool). Carries NO `name` field; the facet synthesizes
322
357
  * `name:"builtin:apply_patch"` (§8 quirk). Same single-wrapper-is-authoritative
323
- * rationale as {@link OpenAIShellCallItem}. */
358
+ * rationale as {@link OpenAIShellCallItem}.
359
+ * @beta
360
+ */
324
361
  export interface OpenAIApplyPatchCallItem {
325
362
  type: "apply_patch_call";
326
363
  callId: string;
@@ -332,7 +369,9 @@ export interface OpenAIApplyPatchCallItem {
332
369
  }
333
370
 
334
371
  /** protocol `ApplyPatchCallResultItem` (the `rawItem` of a `tool_output`
335
- * run-item for a completed apply-patch call). */
372
+ * run-item for a completed apply-patch call).
373
+ * @beta
374
+ */
336
375
  export interface OpenAIApplyPatchCallResultItem {
337
376
  type: "apply_patch_call_output";
338
377
  callId: string;
@@ -357,7 +396,9 @@ export interface OpenAIApplyPatchCallResultItem {
357
396
  * against @openai/agents-core 0.12.0's `runner/modelOutputs.mjs`: a
358
397
  * `hosted_tool_call` output item is pushed as a single `RunToolCallItem`,
359
398
  * never paired with a `RunToolCallOutputItem`). The facet emits
360
- * `tool.start` + `tool.done` TOGETHER from this one event. */
399
+ * `tool.start` + `tool.done` TOGETHER from this one event.
400
+ * @beta
401
+ */
361
402
  export interface OpenAIHostedToolCallItem {
362
403
  type: "hosted_tool_call";
363
404
  id?: string;
@@ -391,7 +432,9 @@ export interface OpenAIHostedToolCallItem {
391
432
  * precedent). Same single-wrapper-is-authoritative rationale as
392
433
  * {@link OpenAIShellCallItem}: no per-fragment argument-delta stream exists
393
434
  * for this shape on this seam, and the raw `output_item.added` carrier
394
- * no-ops on the (function_call-only) raw path. */
435
+ * no-ops on the (function_call-only) raw path.
436
+ * @beta
437
+ */
395
438
  export interface OpenAIProgramCallItem {
396
439
  type: "program";
397
440
  callId: string;
@@ -407,7 +450,9 @@ export interface OpenAIProgramCallItem {
407
450
  * `'completed'|'incomplete'` enum — `incomplete` maps to `outcome:"error"`
408
451
  * (the same rule as `function_call_result`'s incomplete arm: a truncated
409
452
  * program run must never fold as success). Carries NO `caller` field
410
- * (the program is the caller, not the callee). */
453
+ * (the program is the caller, not the callee).
454
+ * @beta
455
+ */
411
456
  export interface OpenAIProgramCallResultItem {
412
457
  type: "program_output";
413
458
  callId: string;
@@ -435,7 +480,9 @@ export interface OpenAIProgramCallResultItem {
435
480
  * (fixture discipline: type only what is consumed — the facet never branches on a
436
481
  * specific action kind). Same single-wrapper-is-authoritative rationale as
437
482
  * {@link OpenAIShellCallItem}: no per-fragment argument-delta stream exists for this
438
- * shape on this seam. The normalizer MUST mirror the SDK's precedence: `actions ?? action ?? {}`. */
483
+ * shape on this seam. The normalizer MUST mirror the SDK's precedence: `actions ?? action ?? {}`.
484
+ * @beta
485
+ */
439
486
  export interface OpenAIComputerCallItem {
440
487
  type: "computer_call";
441
488
  callId: string;
@@ -450,7 +497,9 @@ export interface OpenAIComputerCallItem {
450
497
  * for a completed Computer-Use call). `output` is ALWAYS the
451
498
  * `computer_screenshot` shape (a base64-encoded PNG screenshot) — NO
452
499
  * `status`/error discriminant exists on this wire arm (unlike shell/apply-
453
- * patch results), so the facet maps every occurrence to `outcome:"ok"`. */
500
+ * patch results), so the facet maps every occurrence to `outcome:"ok"`.
501
+ * @beta
502
+ */
454
503
  export interface OpenAIComputerCallResultItem {
455
504
  type: "computer_call_result";
456
505
  callId: string;
@@ -501,7 +550,9 @@ export interface OpenAIComputerCallResultItem {
501
550
  * arguments`) — provider-defined (`{paths, query}` for the built-in hosted
502
551
  * loader; a custom shape for a registered `toolSearchTool`) — carried
503
552
  * through verbatim like `computer_call`'s `action`/`actions`, never
504
- * JSON.parsed. */
553
+ * JSON.parsed.
554
+ * @beta
555
+ */
505
556
  export interface OpenAIToolSearchCallItem {
506
557
  type: "tool_search_call";
507
558
  id?: string;
@@ -529,7 +580,9 @@ export interface OpenAIToolSearchCallItem {
529
580
  * string (unlike shell/apply-patch's closed `'in_progress'|'completed'|
530
581
  * 'incomplete'` enum) — no documented error discriminant exists on this
531
582
  * wire arm, so — mirroring `computer_call_result`'s identical precedent —
532
- * every occurrence maps to `outcome:"ok"`. */
583
+ * every occurrence maps to `outcome:"ok"`.
584
+ * @beta
585
+ */
533
586
  export interface OpenAIToolSearchOutputItem {
534
587
  type: "tool_search_output";
535
588
  id?: string;
@@ -556,7 +609,9 @@ export interface OpenAIToolSearchOutputItem {
556
609
  providerData?: { [k: string]: JsonValue };
557
610
  }
558
611
 
559
- /** protocol `InputText` (the visible reasoning content part). */
612
+ /** protocol `InputText` (the visible reasoning content part).
613
+ * @beta
614
+ */
560
615
  export interface OpenAIReasoningTextPart {
561
616
  type: "input_text";
562
617
  text: string;
@@ -564,7 +619,9 @@ export interface OpenAIReasoningTextPart {
564
619
 
565
620
  /** protocol `ReasoningItem` (the `rawItem` of a reasoning_item). The `rs_…` id +
566
621
  * the `encrypted_content` (under `providerData`, the Responses stateless-replay
567
- * payload) are replay-load-bearing (spec §8.2/§10.4). */
622
+ * payload) are replay-load-bearing (spec §8.2/§10.4).
623
+ * @beta
624
+ */
568
625
  export interface OpenAIReasoningItem {
569
626
  type: "reasoning";
570
627
  id?: string; // rs_… Responses reasoning item id
@@ -703,7 +760,9 @@ interface OpenAICompactionItemCreatedEvent {
703
760
  * consumed anywhere on this seam (fixture discipline: type ONLY what you
704
761
  * consume). Rides on `handoff_requested`'s wrapper (`agent`, the SOURCE
705
762
  * agent) and `handoff_occurred`'s wrapper (`sourceAgent`/`targetAgent`) —
706
- * audit M48 review, Finding 1. */
763
+ * audit M48 review, Finding 1.
764
+ * @beta
765
+ */
707
766
  export interface OpenAIAgentRef {
708
767
  name: string;
709
768
  }
@@ -1081,7 +1140,9 @@ export interface OpenAIHostError {
1081
1140
  usage?: AgUsage;
1082
1141
  }
1083
1142
 
1084
- /** The fixture-contract input union (verified shapes; see file header). */
1143
+ /** The fixture-contract input union (verified shapes; see file header).
1144
+ * @beta
1145
+ */
1085
1146
  export type OpenAIStreamEvent =
1086
1147
  | OpenAIMessageOutputEvent
1087
1148
  | OpenAIToolCalledEvent
@@ -1117,14 +1178,14 @@ export function mapFinishReason(reason: string | undefined | null): AgFinishReas
1117
1178
  }
1118
1179
 
1119
1180
  /**
1120
- * OA-15 (draft.4 — SPEC.md §8.0 graceful degradation, §10 item 23; sp-protocol
1181
+ * OA-15 (draft.4 — SPEC.md §8.0 graceful degradation, §10 item 23; spec
1121
1182
  * 89c57db): the `turn.done` finish fields for a native reason. `finishReason`
1122
1183
  * is `mapFinishReason(reason)`; `finishReasonRaw` — the native value byte for
1123
1184
  * byte — rides along ONLY when that mapping fell back ("other"/"unknown") AND a
1124
1185
  * native string exists. A real mapping (max_output_tokens → token_limit, a bare
1125
1186
  * completion → stop, content_filter → safety_blocked) sets nothing: the companion
1126
1187
  * is for a value with no AgJSON target, not a second copy of a mapped one
1127
- * (sp-protocol's scope ruling; widening it would be a new normative sentence).
1188
+ * (the spec's scope ruling; widening it would be a new normative sentence).
1128
1189
  */
1129
1190
  function finishReasonFields(
1130
1191
  reason: string | undefined | null,
@@ -1219,7 +1280,7 @@ function mapAnnotationsToCitations(
1219
1280
  * string, verbatim — or `undefined`. openai-node types it
1220
1281
  * `'commentary' | 'final_answer' | null`; null and "" carry no marker, so they
1221
1282
  * yield neither a `providerMetadata.phase` carry nor an ext.openai.late-phase
1222
- * (sp-protocol ruling (a), SPEC §10 item 26). Read through `unknown`: the
1283
+ * (spec ruling (a), SPEC §10 item 26). Read through `unknown`: the
1223
1284
  * run-item field is envelope-only-validated wire data (JsonValue boundary). */
1224
1285
  function vendorPhase(value: unknown): string | undefined {
1225
1286
  return typeof value === "string" && value.length > 0 ? value : undefined;
@@ -1346,7 +1407,7 @@ function extractStructuredContent(
1346
1407
  * at `dist/mcp.mjs`:700); guuey's worker and this repo's capture agent return it
1347
1408
  * as `customData._meta`. It is a host/protocol annotation (MCP-Apps `ui.*`), so
1348
1409
  * it rides the tool-result block's own `_meta` VERBATIM (SPEC.md:338; §8.0
1349
- * no-drop). sp-protocol ruled this option A on 2026-09-23. A non-object `_meta`
1410
+ * no-drop). Ruled option A on 2026-09-23. A non-object `_meta`
1350
1411
  * (null, string, array) is not a `_meta` → `undefined`, and the block is
1351
1412
  * byte-identical to the pre-#21 output. Mirrors the claude facet's sibling
1352
1413
  * `_meta` parse (claude-agent-sdk/src/index.ts:1872-1876).
@@ -1421,7 +1482,7 @@ function isOpenAIStreamEvent(v: unknown): v is OpenAIStreamEvent {
1421
1482
  /**
1422
1483
  * The OpenAI Agents SDK normalizer. The inner, deterministic normalizer
1423
1484
  * (`createInnerOpenaiNormalizer` below) is wrapped in core's `withAtomicPush`
1424
- * (sp-probe; sp-main's binding guard ruling, 2026-09-24). Every `push()` is
1485
+ * (the binding guard ruling, 2026-09-24). Every `push()` is
1425
1486
  * atomic, and none of it lives in the facet:
1426
1487
  * - The native is normalized with `toJsonValueSafe`, so LIVE SDK objects map
1427
1488
  * exactly like the JSON corpus.
@@ -1446,7 +1507,7 @@ export interface OpenaiNormalizerOptions {
1446
1507
  * rnd-14 ruling and INV-BLOCK's collision-free derived ids require it: guuey
1447
1508
  * folds a whole conversation into ONE Reducer, and a repeated turn id
1448
1509
  * re-opens a closed turn, which parks INV-TURN / INV-MSG consumers.
1449
- * sp-protocol's D3 bar (wf_9722b7bc-ba9, DC-10) found the old per-normalizer
1510
+ * The D3 review (finding DC-10) found the old per-normalizer
1450
1511
  * counters (`turn_openai_<n>`, `turn_handoff_<n>`) repeating across invokes.
1451
1512
  *
1452
1513
  * By default each normalizer draws a fresh `openai_<16 hex>` stem from
@@ -1685,13 +1746,13 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
1685
1746
 
1686
1747
  /**
1687
1748
  * O1 — release a close deferred under §8.0 item 14 at END OF STREAM (flush) or
1688
- * ahead of a host-fed error, per INV-FLUSH (2) as sp-protocol's fold/flush
1689
- * package words it (A.5; founder: Q1 option 1, "honest flush"). A flush never
1749
+ * ahead of a host-fed error, per INV-FLUSH (2) as the fold/flush ruling
1750
+ * words it (A.5; ruled option 1, "honest flush"). A flush never
1690
1751
  * emits a success turn.done:
1691
1752
  * - an approval `hitl.ask` was emitted for a still-pending call of this
1692
1753
  * round ⇒ `turn.done{outcome:{type:"paused", asks}}`, with the deferred
1693
1754
  * finishReason and usage (the OpenAI approval interruption — the run ends
1694
- * with no tool_output; sp-probe's live leg-1 capture);
1755
+ * with no tool_output; the live leg-1 capture, approval-tool-gpt6sol);
1695
1756
  * - else a non-success deferred outcome (the content_filter arm) ⇒ released
1696
1757
  * verbatim;
1697
1758
  * - else ⇒ `message.end` carrying the round's usage (a per-message usage
@@ -1775,10 +1836,10 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
1775
1836
  }
1776
1837
 
1777
1838
  /**
1778
- * INV-TURN (SPEC:743) for a RESUMED invoke — sp-protocol's c20 package, A.6
1839
+ * INV-TURN (SPEC:743) for a RESUMED invoke — the c20 ruling, A.6
1779
1840
  * (openai): when a tool result's round is unknown to this invoke
1780
1841
  * (`resolvePendingTurnId` misses) and no response is open, the result is the
1781
- * resumed stream's LEADING event (sp-probe's live approval-resume capture,
1842
+ * resumed stream's LEADING event (the live approval-resume capture,
1782
1843
  * 2026-09-24: after `RunState.fromString` + approve/reject, the approved or
1783
1844
  * rejected call's `tool_output` arrives before any `response.created`). Open a
1784
1845
  * turn for it — `turn_resume_<callId>`: deterministic, and never a leg-1
@@ -1796,7 +1857,7 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
1796
1857
  a.openTurn(opened, threadId);
1797
1858
  return { turnId: opened, messageId: `${callId}:result` };
1798
1859
  }
1799
- // Approve-all (sp-protocol's D3 pin, 2026-09-24): the resuming invoke can
1860
+ // Approve-all (the D3 pin, 2026-09-24): the resuming invoke can
1800
1861
  // replay SEVERAL results before its response. While the resume turn is
1801
1862
  // open with no assistant message yet (turnId set, msgId unset — a state
1802
1863
  // only this helper creates), each further result joins THAT turn as its
@@ -1876,7 +1937,7 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
1876
1937
  if (!openTextStreams.has(ev.item_id)) {
1877
1938
  openTextStreams.add(ev.item_id);
1878
1939
  // OA-14: the phase announced at output_item.added rides text.start
1879
- // (rnd 13+17 Stage 1, founder ruling 2026-09-23; vercel parity c4f5981).
1940
+ // (R&D items 13+17, stage 1, ruled 2026-09-23; vercel parity c4f5981).
1880
1941
  const phase = pendingPhase.get(ev.item_id);
1881
1942
  const startMeta = openaiProviderMeta({ phase });
1882
1943
  // PH-2 (draft.4, SPEC §8.0 item 27 + §5 "phase timing"): known before
@@ -2308,14 +2369,14 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
2308
2369
  // OA-14: RETIRED when this id's SAME phase already rode its text.start
2309
2370
  // (the live case); kept — lossless — when only the run-item knows it,
2310
2371
  // or knows a different value.
2311
- // PH-2: null/"" is no marker at all (sp-protocol ruling (a)) — neither
2372
+ // PH-2: null/"" is no marker at all (spec ruling (a)) — neither
2312
2373
  // a carry nor a late-phase ext.
2313
2374
  const lateItemPhase = vendorPhase(item.phase);
2314
2375
  if (lateItemPhase !== undefined && carriedPhase.get(item.id) !== lateItemPhase) {
2315
2376
  if (isStashedTextStream(item.id)) {
2316
2377
  // PH-2 case (ii): the round close is STASHED (a deferred tool
2317
2378
  // round), so this block's text.end is NOT yet emitted — the §5
2318
- // timing rule makes the end the phase's home (sp-protocol,
2379
+ // timing rule makes the end the phase's home (ruled
2319
2380
  // 2026-09-23). The marker has a first-class home, so no late-phase.
2320
2381
  const interim = interimAtStart.has(item.id) ? undefined : interimPhase(lateItemPhase);
2321
2382
  const endMeta = openaiProviderMeta({ phase: lateItemPhase });
@@ -2380,7 +2441,7 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
2380
2441
  * OA-11: fill + seal an OPEN reasoning block: one `reasoning.delta` per
2381
2442
  * non-empty summary part (`partIndex` = the wire `summary_index`), then
2382
2443
  * `reasoning.opaque` (the replayable ciphertext, `itemId` = rs_) BEFORE
2383
- * `reasoning.end`, so "sealed" means complete (sp-protocol's recommendation;
2444
+ * `reasoning.end`, so "sealed" means complete (the spec's recommendation;
2384
2445
  * the Claude signature-before-stop order). The facet never consumes
2385
2446
  * `response.reasoning_summary_text.delta` (the raw default arm drops it), so
2386
2447
  * this is the ONLY place summary text is emitted — no double under INV-DELTA.
@@ -3031,7 +3092,7 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
3031
3092
  // workspace#21: `customData._meta` → block `_meta`; with `_meta.ui` the
3032
3093
  // payload is MCP-Apps view data → ALSO `uiData` (SPEC.md:332), leaving
3033
3094
  // `structuredContent` as it was (the :340 mapping; ggui's cache marker
3034
- // rides it). §2.1's "exactly one consumer" is per channel (sp-protocol,
3095
+ // rides it). §2.1's "exactly one consumer" is per channel (ruled
3035
3096
  // option A). Mirrors claude-agent-sdk/src/index.ts:1926-1946.
3036
3097
  const resultMeta = extractResultMeta(event.item.customData);
3037
3098
  // A CLONE, not an alias: the two channels reach different consumers, and
@@ -3153,11 +3214,19 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
3153
3214
  // `subagentDone` in the `handoff_occurred` case below.
3154
3215
  const ordinal = ++handoffOrdinal;
3155
3216
  const handoffTurnId = `turn_${invokeStem}_handoff_${ordinal}`;
3156
- // A handoff_requested before any turn of this invoke opened (a resumed
3157
- // invoke can stream one first) gets a facet-local, invoke-unique parent
3158
- // label: never the host thread, which is a partition root, not a turn.
3159
- const parentTurnId = lastTopLevelTurnId ?? `turn_${invokeStem}_handoff_parent`;
3160
- openHandoffs.push({ turnId: handoffTurnId, parentTurnId, callId: event.item.rawItem.callId });
3217
+ // A handoff_requested before any turn of this invoke opened: a resumed
3218
+ // invoke streams step items without the raw model stream
3219
+ // (resumeAcceptedModelResponse), so the transfer can be the first thing
3220
+ // seen. Open the resumed invoke's own turn here, the same
3221
+ // `turn_resume_<callId>` its transfer result would otherwise open at
3222
+ // handoff_occurred, so the bracket's parent is a real turn carrying the
3223
+ // host thread (SPEC §1.2: a nested turn's parentTurnId points at the
3224
+ // enclosing turn; Partition root: nested turns included). The label is
3225
+ // an unreachable fallback: with no turn open the helper always opens one.
3226
+ const callId = event.item.rawItem.callId;
3227
+ const parentTurnId =
3228
+ lastTopLevelTurnId ?? openTurnForLeadingResult(callId)?.turnId ?? `turn_${invokeStem}_handoff_parent`;
3229
+ openHandoffs.push({ turnId: handoffTurnId, parentTurnId, callId });
3161
3230
  a.subagentStart(handoffTurnId, parentTurnId);
3162
3231
  return;
3163
3232
  }
@@ -3173,7 +3242,7 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
3173
3242
  const item = event.item;
3174
3243
  const open = takeOpenHandoff(item.rawItem.callId); // by callId — see openHandoffs' doc.
3175
3244
  if (open !== undefined) {
3176
- // draft.4 nested-run closure (§8.0 item 29, §10 item 36; sp-protocol's
3245
+ // draft.4 nested-run closure (§8.0 item 29, §10 item 36; the
3177
3246
  // nested-turn package A.6): the bracket closes with its own terminal,
3178
3247
  // immediately followed by `subagent.done`. `handoff_occurred` IS the
3179
3248
  // SDK's report that the transfer ran (the handoff span closed and the
@@ -3182,7 +3251,7 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
3182
3251
  a.closeTurnDone(open.turnId, { outcome: { type: "success" }, finishReason: "unknown" });
3183
3252
  a.subagentDone(open.turnId, open.parentTurnId);
3184
3253
  }
3185
- // HO (0.7.0 regression, sp-probe's live handoff-gpt6sol): the transfer is
3254
+ // HO (0.7.0 regression, the live handoff-gpt6sol capture): the transfer is
3186
3255
  // an ordinary function_call the model emitted (tool.start from
3187
3256
  // `response.output_item.added`, registered pending), and THIS item's
3188
3257
  // rawItem is its result — the SDK never sends a `tool_output` for it.
@@ -3308,7 +3377,7 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
3308
3377
  // LV: a host may push the SDK's LIVE stream objects (undefined members,
3309
3378
  // Dates, class instances, cycles), not the JSON round-tripped shape the
3310
3379
  // corpus records, and the carried-member `JsonValue.parse` sites threw a
3311
- // ZodError on them (sp-main's no-throw check, 2026-09-24: 6 of 9 live
3380
+ // ZodError on them (a no-throw check, 2026-09-24: 6 of 9 live
3312
3381
  // shapes). The native arrives already normalized: `withAtomicPush` ran core's
3313
3382
  // `toJsonValueSafe` on it (JSON semantics per node: toJSON honoured,
3314
3383
  // undefined dropped, Date → ISO string), and it owns the no-throw
@@ -3321,7 +3390,7 @@ function createInnerOpenaiNormalizer(invokeStem: string, threadId: string): Norm
3321
3390
  // A COPY via JsonValue.parse, like every other carry path: plain input
3322
3391
  // arrives by reference, so carrying it as-is would alias the host's
3323
3392
  // object into an emitted event, and would forward an own `__proto__`
3324
- // key (sp-cto's checks, 2026-09-24).
3393
+ // key (review checks, 2026-09-24).
3325
3394
  a.emitExt("openai", "unparsed", { native: JsonValue.parse(native) });
3326
3395
  return a.drain();
3327
3396
  }