@openllmsh/sdk 2.10.16-alpha.3 → 2.10.17-alpha.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.
@@ -12291,17 +12291,35 @@
12291
12291
  "prompt": {
12292
12292
  "type": "string"
12293
12293
  },
12294
- "image": {
12295
- "type": "object",
12296
- "properties": {
12297
- "url": {
12298
- "type": "string"
12294
+ "images": {
12295
+ "type": "array",
12296
+ "prefixItems": [
12297
+ {
12298
+ "type": "object",
12299
+ "properties": {
12300
+ "url": {
12301
+ "type": "string"
12302
+ }
12303
+ },
12304
+ "required": [
12305
+ "url"
12306
+ ],
12307
+ "additionalProperties": false
12299
12308
  }
12300
- },
12301
- "required": [
12302
- "url"
12303
12309
  ],
12304
- "additionalProperties": false
12310
+ "minItems": 1,
12311
+ "items": {
12312
+ "type": "object",
12313
+ "properties": {
12314
+ "url": {
12315
+ "type": "string"
12316
+ }
12317
+ },
12318
+ "required": [
12319
+ "url"
12320
+ ],
12321
+ "additionalProperties": false
12322
+ }
12305
12323
  },
12306
12324
  "n": {
12307
12325
  "anyOf": [
@@ -12356,7 +12374,7 @@
12356
12374
  },
12357
12375
  "required": [
12358
12376
  "prompt",
12359
- "image"
12377
+ "images"
12360
12378
  ],
12361
12379
  "additionalProperties": false
12362
12380
  }
@@ -219,6 +219,11 @@ export declare const AgentSendCommand: S.Struct<{
219
219
  /** Absolute path on the device, admitted on any transport. */
220
220
  readonly path: S.optional<S.String>;
221
221
  }>>>;
222
+ /**
223
+ * Mid-turn: queue this prompt and send now (Claude's ctrl+enter), as one
224
+ * command — so a refused send never interrupts for an older queued one.
225
+ */
226
+ readonly send_now: S.optional<S.Boolean>;
222
227
  }>;
223
228
  export type TAgentSendCommand = S.Schema.Type<typeof AgentSendCommand>;
224
229
  /**
@@ -404,6 +409,11 @@ export declare const AgentCommand: S.Union<readonly [S.Struct<{
404
409
  /** Absolute path on the device, admitted on any transport. */
405
410
  readonly path: S.optional<S.String>;
406
411
  }>>>;
412
+ /**
413
+ * Mid-turn: queue this prompt and send now (Claude's ctrl+enter), as one
414
+ * command — so a refused send never interrupts for an older queued one.
415
+ */
416
+ readonly send_now: S.optional<S.Boolean>;
407
417
  }>, S.Struct<{
408
418
  readonly type: S.Literal<"attachment_put">;
409
419
  readonly id: S.optional<S.String>;
@@ -581,6 +591,11 @@ export declare const AgentQueuedPrompt: S.Struct<{
581
591
  /** Clipped preview, never the complete prompt. */
582
592
  readonly prompt: S.String;
583
593
  readonly attachment_count: S.Number;
594
+ /**
595
+ * Handed to the engine's own queue (Claude folds it in at the next tool
596
+ * boundary): no longer cancellable, but Send now still applies to it.
597
+ */
598
+ readonly in_engine: S.optional<S.Boolean>;
584
599
  }>;
585
600
  export type TAgentQueuedPrompt = S.Schema.Type<typeof AgentQueuedPrompt>;
586
601
  export declare const AgentQueueUpdatedEvent: S.Struct<{
@@ -603,6 +618,11 @@ export declare const AgentQueueUpdatedEvent: S.Struct<{
603
618
  /** Clipped preview, never the complete prompt. */
604
619
  readonly prompt: S.String;
605
620
  readonly attachment_count: S.Number;
621
+ /**
622
+ * Handed to the engine's own queue (Claude folds it in at the next tool
623
+ * boundary): no longer cancellable, but Send now still applies to it.
624
+ */
625
+ readonly in_engine: S.optional<S.Boolean>;
606
626
  }>, S.String]>>;
607
627
  /** An interrupt pauses automatic draining until `resume_queue`. */
608
628
  readonly held: S.optional<S.Boolean>;
@@ -1185,6 +1205,11 @@ export declare const AgentEvent: S.Union<readonly [S.Struct<{
1185
1205
  /** Clipped preview, never the complete prompt. */
1186
1206
  readonly prompt: S.String;
1187
1207
  readonly attachment_count: S.Number;
1208
+ /**
1209
+ * Handed to the engine's own queue (Claude folds it in at the next tool
1210
+ * boundary): no longer cancellable, but Send now still applies to it.
1211
+ */
1212
+ readonly in_engine: S.optional<S.Boolean>;
1188
1213
  }>, S.String]>>;
1189
1214
  /** An interrupt pauses automatic draining until `resume_queue`. */
1190
1215
  readonly held: S.optional<S.Boolean>;
@@ -247,6 +247,11 @@ export const AgentSendCommand = S.Struct({
247
247
  id: S.optional(AgentCommandId),
248
248
  prompt: S.String.check(S.isMaxLength(AGENT_MAX_PROMPT_LENGTH)),
249
249
  attachments: S.optional(S.Array(AgentAttachment).check(S.isMaxLength(AGENT_MAX_ATTACHMENTS))),
250
+ /**
251
+ * Mid-turn: queue this prompt and send now (Claude's ctrl+enter), as one
252
+ * command — so a refused send never interrupts for an older queued one.
253
+ */
254
+ send_now: S.optional(S.Boolean),
250
255
  }).check(S.makeFilter((command) => lineEncoder.encode(`${JSON.stringify(command)}\n`).byteLength <=
251
256
  AGENT_MAX_LINE_BYTES, { message: "send command exceeds the agent line size bound" }));
252
257
  /**
@@ -497,6 +502,11 @@ export const AgentQueuedPrompt = S.Struct({
497
502
  /** Clipped preview, never the complete prompt. */
498
503
  prompt: ShortText,
499
504
  attachment_count: S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0), S.isLessThanOrEqualTo(AGENT_MAX_ATTACHMENTS)),
505
+ /**
506
+ * Handed to the engine's own queue (Claude folds it in at the next tool
507
+ * boundary): no longer cancellable, but Send now still applies to it.
508
+ */
509
+ in_engine: S.optional(S.Boolean),
500
510
  });
501
511
  export const AgentQueueUpdatedEvent = S.Struct({
502
512
  ...eventBase,
@@ -1,8 +1,8 @@
1
1
  import type { TImageEditParseResult, TImageEditRequest } from "./images.js";
2
2
  /**
3
3
  * Normalize documented multipart fields and a narrow JSON convenience into
4
- * the canonical single-image {@link TImageEditRequest}. Masks and extra
5
- * references fail explicitly — they are never dropped.
4
+ * the canonical {@link TImageEditRequest} with one or more references.
5
+ * Masks fail explicitly — they are never dropped.
6
6
  */
7
7
  export declare const parseImageEditInput: (raw: unknown) => TImageEditParseResult;
8
8
  export type TImageEditMultipartFile = {
@@ -12,7 +12,12 @@ export type TImageEditMultipartFile = {
12
12
  };
13
13
  export declare const bytesToDataUrl: (bytes: Uint8Array, contentType: string | undefined) => string;
14
14
  /**
15
- * Map OpenAI-style multipart edits (`image` file + string fields) onto the
15
+ * Multipart field names that carry a reference image: OpenAI's `image` /
16
+ * `image[]` (repeat the part once per image), plus the `images` spelling.
17
+ */
18
+ export declare const IMAGE_EDIT_MULTIPART_IMAGE_FIELDS: ReadonlySet<string>;
19
+ /**
20
+ * Map OpenAI-style multipart edits (`image` / `image[]` files + string fields) onto the
16
21
  * same canonical parser as JSON.
17
22
  */
18
23
  export declare const parseImageEditMultipart: (input: {
@@ -1,5 +1,5 @@
1
1
  import * as Result from "effect/Result";
2
- import { decodeImageEditRequest, IMAGE_EDIT_MAX_BODY_BYTES } from "./images.js";
2
+ import { decodeImageEditRequest, IMAGE_EDIT_MAX_BODY_BYTES, IMAGE_EDIT_MAX_REFERENCES, } from "./images.js";
3
3
  const asRecord = (value) => {
4
4
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
5
5
  return null;
@@ -14,18 +14,6 @@ const isPresent = (value) => {
14
14
  return false;
15
15
  return true;
16
16
  };
17
- const referenceCount = (body) => {
18
- let count = 0;
19
- if (isPresent(body.image)) {
20
- if (Array.isArray(body.image))
21
- count += body.image.length;
22
- else
23
- count += 1;
24
- }
25
- if (Array.isArray(body.images))
26
- count += body.images.length;
27
- return count;
28
- };
29
17
  // Strict `data:[<mime>][;charset=<x>];base64,<payload>` matcher. The base64
30
18
  // group is validated for charset AND padding shape (0-2 trailing `=`, only at
31
19
  // the end) — a loose regex would let a malformed/truncated payload through to
@@ -52,35 +40,48 @@ const estimateDataUrlBytes = (url) => {
52
40
  const padding = base64.endsWith("==") ? 2 : base64.endsWith("=") ? 1 : 0;
53
41
  return (base64.length / 4) * 3 - padding;
54
42
  };
55
- const referenceUrl = (body) => {
56
- const image = body.image;
57
- if (typeof image === "string" && image.length > 0)
58
- return image;
59
- const imageObj = asRecord(image);
60
- if (imageObj !== null) {
61
- if (typeof imageObj.url === "string")
62
- return imageObj.url;
63
- if (typeof imageObj.image_url === "string")
64
- return imageObj.image_url;
65
- }
66
- const images = body.images;
67
- if (Array.isArray(images) && images.length === 1) {
68
- const first = asRecord(images[0]);
69
- if (first !== null) {
70
- if (typeof first.image_url === "string")
71
- return first.image_url;
72
- if (typeof first.url === "string")
73
- return first.url;
74
- }
75
- if (typeof images[0] === "string")
76
- return images[0];
43
+ const referenceItemUrl = (item) => {
44
+ if (typeof item === "string")
45
+ return item.length > 0 ? item : null;
46
+ const obj = asRecord(item);
47
+ if (obj === null)
48
+ return null;
49
+ if (typeof obj.url === "string" && obj.url.length > 0)
50
+ return obj.url;
51
+ if (typeof obj.image_url === "string" && obj.image_url.length > 0) {
52
+ return obj.image_url;
77
53
  }
78
54
  return null;
79
55
  };
56
+ /**
57
+ * Every reference image in the body, in order: `image` (one, or an array,
58
+ * the JSON form of multipart `image[]`) then `images`. `null` when any
59
+ * present entry is not a usable reference — a bad entry fails the request
60
+ * rather than being dropped.
61
+ */
62
+ const referenceUrls = (body) => {
63
+ const items = [];
64
+ for (const value of [body.image, body.images]) {
65
+ if (!isPresent(value))
66
+ continue;
67
+ if (Array.isArray(value))
68
+ items.push(...value);
69
+ else
70
+ items.push(value);
71
+ }
72
+ const urls = [];
73
+ for (const item of items) {
74
+ const url = referenceItemUrl(item);
75
+ if (url === null)
76
+ return null;
77
+ urls.push(url);
78
+ }
79
+ return urls;
80
+ };
80
81
  /**
81
82
  * Normalize documented multipart fields and a narrow JSON convenience into
82
- * the canonical single-image {@link TImageEditRequest}. Masks and extra
83
- * references fail explicitly — they are never dropped.
83
+ * the canonical {@link TImageEditRequest} with one or more references.
84
+ * Masks fail explicitly — they are never dropped.
84
85
  */
85
86
  export const parseImageEditInput = (raw) => {
86
87
  const body = asRecord(raw);
@@ -93,25 +94,28 @@ export const parseImageEditInput = (raw) => {
93
94
  if (isPresent(body.style) || isPresent(body.background)) {
94
95
  return fail("image_edit_invalid", "Image edits do not support style or background options.");
95
96
  }
96
- const count = referenceCount(body);
97
- if (count > 1) {
98
- return fail("image_edit_multi_reference_unsupported", "Image edits accept exactly one reference image.");
97
+ const urls = referenceUrls(body);
98
+ if (urls === null || urls.length === 0) {
99
+ return fail("image_edit_invalid", "Image edits require at least one reference image.");
99
100
  }
100
- const url = referenceUrl(body);
101
- if (url === null) {
102
- return fail("image_edit_invalid", "Image edits require exactly one reference image.");
101
+ if (urls.length > IMAGE_EDIT_MAX_REFERENCES) {
102
+ return fail("image_edit_invalid", `Image edits accept at most ${IMAGE_EDIT_MAX_REFERENCES} reference images.`);
103
103
  }
104
- const dataUrlBytes = estimateDataUrlBytes(url);
105
- if (dataUrlBytes === null) {
106
- return fail("image_edit_invalid", "Image edit reference is not a valid base64 data URL.");
104
+ let totalBytes = 0;
105
+ for (const url of urls) {
106
+ const dataUrlBytes = estimateDataUrlBytes(url);
107
+ if (dataUrlBytes === null) {
108
+ return fail("image_edit_invalid", "Image edit reference is not a valid base64 data URL.");
109
+ }
110
+ totalBytes += dataUrlBytes;
107
111
  }
108
- if (dataUrlBytes > IMAGE_EDIT_MAX_BODY_BYTES) {
109
- return fail("image_edit_invalid", `Image edit reference exceeds ${IMAGE_EDIT_MAX_BODY_BYTES} bytes.`);
112
+ if (totalBytes > IMAGE_EDIT_MAX_BODY_BYTES) {
113
+ return fail("image_edit_invalid", `Image edit references exceed ${IMAGE_EDIT_MAX_BODY_BYTES} bytes.`);
110
114
  }
111
115
  const candidate = {
112
116
  model: body.model,
113
117
  prompt: body.prompt,
114
- image: { url },
118
+ images: urls.map((url) => ({ url })),
115
119
  };
116
120
  if (body.n !== undefined)
117
121
  candidate.n = body.n;
@@ -158,31 +162,40 @@ export const bytesToDataUrl = (bytes, contentType) => {
158
162
  const POSITIVE_INTEGER_FIELD_PATTERN = /^[1-9][0-9]*$/;
159
163
  const parseMultipartNField = (raw) => POSITIVE_INTEGER_FIELD_PATTERN.test(raw) ? Number(raw) : null;
160
164
  /**
161
- * Map OpenAI-style multipart edits (`image` file + string fields) onto the
165
+ * Multipart field names that carry a reference image: OpenAI's `image` /
166
+ * `image[]` (repeat the part once per image), plus the `images` spelling.
167
+ */
168
+ export const IMAGE_EDIT_MULTIPART_IMAGE_FIELDS = new Set([
169
+ "image",
170
+ "image[]",
171
+ "images",
172
+ "images[]",
173
+ ]);
174
+ /**
175
+ * Map OpenAI-style multipart edits (`image` / `image[]` files + string fields) onto the
162
176
  * same canonical parser as JSON.
163
177
  */
164
178
  export const parseImageEditMultipart = (input) => {
165
- const imageFiles = input.files.filter((file) => file.fieldName === "image" || file.fieldName === "images");
179
+ const imageFiles = input.files.filter((file) => IMAGE_EDIT_MULTIPART_IMAGE_FIELDS.has(file.fieldName));
166
180
  const maskFiles = input.files.filter((file) => file.fieldName === "mask");
167
181
  if (maskFiles.length > 0 || isPresent(input.fields.mask)) {
168
182
  return fail("image_edit_mask_unsupported", "Image edit masks are not supported.");
169
183
  }
170
- if (imageFiles.length > 1) {
171
- return fail("image_edit_multi_reference_unsupported", "Image edits accept exactly one reference image.");
172
- }
173
- // A file field AND an inline `image`/`images` string field together are an
174
- // ambiguous duplicate reference (which one wins?) — reject explicitly
175
- // rather than silently letting the file overwrite the string field below.
176
- if (imageFiles.length === 1 &&
177
- (isPresent(input.fields.image) || isPresent(input.fields.images))) {
178
- return fail("image_edit_multi_reference_unsupported", "Image edits accept exactly one reference image; do not combine an image file with an inline image field.");
184
+ // Image FILES together with an inline `image`/`images` string field mix
185
+ // two ways of sending references with no defined order between them —
186
+ // reject explicitly rather than silently letting the files win.
187
+ const inlineFields = [...IMAGE_EDIT_MULTIPART_IMAGE_FIELDS].filter((name) => isPresent(input.fields[name]));
188
+ if (imageFiles.length > 0 && inlineFields.length > 0) {
189
+ return fail("image_edit_invalid", "Send reference images either as files or as inline image fields, not both.");
179
190
  }
180
191
  const raw = { ...input.fields };
181
- if (imageFiles.length === 1) {
182
- const file = imageFiles[0];
183
- if (file !== undefined) {
184
- raw.image = bytesToDataUrl(file.bytes, file.contentType);
185
- }
192
+ for (const name of IMAGE_EDIT_MULTIPART_IMAGE_FIELDS)
193
+ delete raw[name];
194
+ if (imageFiles.length > 0) {
195
+ raw.image = imageFiles.map((file) => bytesToDataUrl(file.bytes, file.contentType));
196
+ }
197
+ else {
198
+ raw.image = inlineFields.map((name) => input.fields[name]);
186
199
  }
187
200
  if (typeof input.fields.n === "string") {
188
201
  const n = parseMultipartNField(input.fields.n);
@@ -230,9 +230,15 @@ export type TImageStreamEvent = S.Schema.Type<typeof ImageStreamEvent>;
230
230
  /** SSE event NAME for an image stream event — the spec frames by `type`. */
231
231
  export declare const imageStreamEventName: (event: TImageStreamEvent) => string;
232
232
  /**
233
- * Canonical single-reference image edit. Generation (`ImageGenerationRequest`)
234
- * must not be used as a silent stand-in — edits require an explicit image
235
- * and reject masks / extra references.
233
+ * Most reference images one edit may carry (OpenAI's `image[]` limit for
234
+ * gpt-image models). Their combined decoded size still fits
235
+ * {@link IMAGE_EDIT_MAX_BODY_BYTES}.
236
+ */
237
+ export declare const IMAGE_EDIT_MAX_REFERENCES = 16;
238
+ /**
239
+ * Canonical image edit: one or more reference images, in the caller's order.
240
+ * Generation (`ImageGenerationRequest`) must not be used as a silent
241
+ * stand-in — edits require an explicit image and reject masks.
236
242
  */
237
243
  export declare const ImageEditReference: S.Struct<{
238
244
  readonly url: S.String;
@@ -241,9 +247,9 @@ export type TImageEditReference = S.Schema.Type<typeof ImageEditReference>;
241
247
  export declare const ImageEditRequest: S.Struct<{
242
248
  readonly model: S.String;
243
249
  readonly prompt: S.String;
244
- readonly image: S.Struct<{
250
+ readonly images: S.NonEmptyArray<S.Struct<{
245
251
  readonly url: S.String;
246
- }>;
252
+ }>>;
247
253
  readonly n: S.optional<S.Int>;
248
254
  readonly size: S.optional<S.String>;
249
255
  readonly quality: S.optional<S.String>;
@@ -252,9 +258,9 @@ export declare const ImageEditRequest: S.Struct<{
252
258
  export type TImageEditRequest = S.Schema.Type<typeof ImageEditRequest>;
253
259
  export declare const ImageEditInput: S.Struct<{
254
260
  readonly prompt: S.String;
255
- readonly image: S.Struct<{
261
+ readonly images: S.NonEmptyArray<S.Struct<{
256
262
  readonly url: S.String;
257
- }>;
263
+ }>>;
258
264
  readonly n: S.optional<S.Int>;
259
265
  readonly size: S.optional<S.String>;
260
266
  readonly quality: S.optional<S.String>;
@@ -262,7 +268,7 @@ export declare const ImageEditInput: S.Struct<{
262
268
  readonly model: S.decodeTo<S.optionalKey<S.String>, S.optionalKey<S.String>, never, never>;
263
269
  }>;
264
270
  export type TImageEditInput = S.Schema.Type<typeof ImageEditInput>;
265
- export declare const ImageEditParseErrorCode: S.Literals<readonly ["image_edit_mask_unsupported", "image_edit_multi_reference_unsupported", "image_edit_invalid"]>;
271
+ export declare const ImageEditParseErrorCode: S.Literals<readonly ["image_edit_mask_unsupported", "image_edit_invalid"]>;
266
272
  export type TImageEditParseErrorCode = S.Schema.Type<typeof ImageEditParseErrorCode>;
267
273
  export type TImageEditParseFailure = {
268
274
  readonly code: TImageEditParseErrorCode;
@@ -278,9 +284,11 @@ export type TImageEditParseResult = {
278
284
  export declare const decodeImageEditRequest: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => import("effect/Result").Result<{
279
285
  readonly model: string;
280
286
  readonly prompt: string;
281
- readonly image: {
287
+ readonly images: readonly [{
288
+ readonly url: string;
289
+ }, ...{
282
290
  readonly url: string;
283
- };
291
+ }[]];
284
292
  readonly n?: number | undefined;
285
293
  readonly size?: string | undefined;
286
294
  readonly quality?: string | undefined;
@@ -200,9 +200,15 @@ export const ImageStreamEvent = S.Union([
200
200
  /** SSE event NAME for an image stream event — the spec frames by `type`. */
201
201
  export const imageStreamEventName = (event) => event.type;
202
202
  /**
203
- * Canonical single-reference image edit. Generation (`ImageGenerationRequest`)
204
- * must not be used as a silent stand-in — edits require an explicit image
205
- * and reject masks / extra references.
203
+ * Most reference images one edit may carry (OpenAI's `image[]` limit for
204
+ * gpt-image models). Their combined decoded size still fits
205
+ * {@link IMAGE_EDIT_MAX_BODY_BYTES}.
206
+ */
207
+ export const IMAGE_EDIT_MAX_REFERENCES = 16;
208
+ /**
209
+ * Canonical image edit: one or more reference images, in the caller's order.
210
+ * Generation (`ImageGenerationRequest`) must not be used as a silent
211
+ * stand-in — edits require an explicit image and reject masks.
206
212
  */
207
213
  export const ImageEditReference = S.Struct({
208
214
  url: S.String,
@@ -210,7 +216,7 @@ export const ImageEditReference = S.Struct({
210
216
  export const ImageEditRequest = S.Struct({
211
217
  model: S.String,
212
218
  prompt: S.String,
213
- image: ImageEditReference,
219
+ images: S.NonEmptyArray(ImageEditReference),
214
220
  n: S.optional(S.Int.check(S.isGreaterThan(0))),
215
221
  size: S.optional(ImageSize),
216
222
  quality: S.optional(S.String),
@@ -223,7 +229,6 @@ export const ImageEditInput = S.Struct({
223
229
  });
224
230
  export const ImageEditParseErrorCode = S.Literals([
225
231
  "image_edit_mask_unsupported",
226
- "image_edit_multi_reference_unsupported",
227
232
  "image_edit_invalid",
228
233
  ]);
229
234
  export const decodeImageEditRequest = S.decodeUnknownResult(ImageEditRequest);
@@ -447,7 +447,7 @@ export declare const RelayStatusPushFrame: S.Struct<{
447
447
  readonly status_seq: S.optional<S.Number>;
448
448
  }>;
449
449
  export type TRelayStatusPushFrame = S.Schema.Type<typeof RelayStatusPushFrame>;
450
- /** relay → watcher. A key's daemon presence flipped (socket open/close). */
450
+ /** relay → watcher + the user's other daemons. A key's daemon presence flipped. */
451
451
  export declare const RelayPresenceFrame: S.Struct<{
452
452
  readonly type: S.Literal<"presence">;
453
453
  readonly key_id: S.String;
@@ -271,7 +271,7 @@ export const RelayStatusPushFrame = S.Struct({
271
271
  daemon_session_started_at_ms: S.optional(S.Number),
272
272
  status_seq: S.optional(S.Number),
273
273
  });
274
- /** relay → watcher. A key's daemon presence flipped (socket open/close). */
274
+ /** relay → watcher + the user's other daemons. A key's daemon presence flipped. */
275
275
  export const RelayPresenceFrame = S.Struct({
276
276
  type: S.Literal("presence"),
277
277
  key_id: S.String,
@@ -45,6 +45,14 @@ export type TChatGptStreamState = {
45
45
  url: string;
46
46
  }>;
47
47
  }>;
48
+ /**
49
+ * Reasoning summary parts (`item_id:summary_index`) that streamed ≥1
50
+ * `reasoning_summary_text.delta`. Their `.done` repeats the whole part, so
51
+ * it is emitted only for a part that streamed nothing (done-only backends).
52
+ */
53
+ summaryPartsStreamed: Set<string>;
54
+ /** The summary part the last emitted reasoning text belonged to. */
55
+ lastSummaryPart: string | null;
48
56
  /** Present only when request encoding had to rewrite a client tool name. */
49
57
  readonly toolNameMap?: ReadonlyMap<string, string>;
50
58
  };
@@ -13,6 +13,8 @@ export const newChatGptStreamState = (options) => ({
13
13
  toolNameEmittedIndexes: new Set(),
14
14
  emittedToolCallIds: new Set(),
15
15
  serverSearchById: new Map(),
16
+ summaryPartsStreamed: new Set(),
17
+ lastSummaryPart: null,
16
18
  ...(options.toolNameMap !== undefined && options.toolNameMap.size > 0
17
19
  ? { toolNameMap: options.toolNameMap }
18
20
  : {}),
@@ -443,11 +445,25 @@ export const chatGptEventToChunk = (event, state, options) => {
443
445
  }
444
446
  if (type === "response.reasoning_summary_text.delta" ||
445
447
  type === "response.reasoning_summary_text.done") {
446
- const delta = type === "response.reasoning_summary_text.done"
448
+ const isDone = type === "response.reasoning_summary_text.done";
449
+ const part = `${stringField(event, "item_id") ?? ""}:${numberField(event, "summary_index") ?? ""}`;
450
+ // `.done` repeats the part's full text: only a part that streamed no
451
+ // deltas (done-only backends) takes it, or the summary doubles.
452
+ if (isDone && state.summaryPartsStreamed.has(part))
453
+ return null;
454
+ const text = isDone
447
455
  ? (stringField(event, "text") ?? stringField(event, "delta"))
448
456
  : stringField(event, "delta");
449
- if (delta === undefined || delta.length === 0)
457
+ if (text === undefined || text.length === 0)
450
458
  return null;
459
+ if (!isDone)
460
+ state.summaryPartsStreamed.add(part);
461
+ // Each summary part opens with its own `**Title**` line; a paragraph
462
+ // break keeps it from running onto the previous part's last sentence.
463
+ const delta = state.lastSummaryPart !== null && state.lastSummaryPart !== part
464
+ ? `\n\n${text}`
465
+ : text;
466
+ state.lastSummaryPart = part;
451
467
  return {
452
468
  ...baseChunk(state, options),
453
469
  choices: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openllmsh/sdk",
3
- "version": "2.10.16-alpha.3",
3
+ "version": "2.10.17-alpha.0",
4
4
  "private": false,
5
5
  "description": "The OpenLLM SDK: typed API contracts, wire-format adapters, the device tunnel, client-side vault crypto, the OpenAPI spec and MCP tools.",
6
6
  "keywords": [