@cydm/pie 4.14.0 → 4.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +5 -5
  2. package/dist/builtin/extensions/ask-user/index.js +4 -4
  3. package/dist/builtin/extensions/cron/index.js +70 -17
  4. package/dist/builtin/extensions/im-forward/index.js +889 -205
  5. package/dist/builtin/extensions/memory/index.js +6 -6
  6. package/dist/builtin/extensions/memory/package.json +1 -2
  7. package/dist/builtin/extensions/pie-proc/README.md +12 -3
  8. package/dist/builtin/extensions/pie-proc/index.js +88 -45
  9. package/dist/builtin/extensions/plan-mode/index.js +4 -4
  10. package/dist/builtin/extensions/subagent/index.js +5 -5
  11. package/dist/builtin/extensions/todo/index.js +4 -4
  12. package/dist/chunks/{chunk-FD3KBPDR.js → chunk-6AYPNTCO.js} +8 -8
  13. package/dist/chunks/{chunk-JJH77AUU.js → chunk-J6EZ335F.js} +8 -7
  14. package/dist/chunks/{chunk-EZZTMDWZ.js → chunk-JE53PC46.js} +1064 -161
  15. package/dist/chunks/{chunk-BOQIGMGQ.js → chunk-LIA52LJU.js} +3 -3
  16. package/dist/chunks/{chunk-26KRUYZH.js → chunk-MTH6QSYD.js} +1 -1
  17. package/dist/chunks/{chunk-UYDS75SI.js → chunk-NAMH667S.js} +11 -15
  18. package/dist/chunks/{chunk-IK2FR2YF.js → chunk-VWDCKHCC.js} +1 -1
  19. package/dist/chunks/{chunk-MCR4JYI6.js → chunk-YKV45EMY.js} +313 -149
  20. package/dist/chunks/{chunk-JKO42HZW.js → chunk-ZBIR5YS7.js} +1 -1
  21. package/dist/chunks/{chunk-KGWKRO7Z.js → chunk-ZH6EAKVM.js} +2 -2
  22. package/dist/chunks/{host-image-fallback-LPHB5CTL.js → host-image-fallback-GX2KXZXQ.js} +1 -1
  23. package/dist/chunks/{memory-git-ZJN6SPIU.js → memory-git-BJMYZHIE.js} +5 -5
  24. package/dist/chunks/{model-registry-GLBIUOJR.js → model-registry-T6EMM66I.js} +2 -2
  25. package/dist/chunks/{read-file-understanding-DFJPTTSB.js → read-file-understanding-ZRE5KDG3.js} +5 -5
  26. package/dist/chunks/{src-KZ7YID3I.js → src-DLAIQCKP.js} +3 -3
  27. package/dist/chunks/{src-ALHMJZ5R.js → src-FWL3LCBK.js} +2 -2
  28. package/dist/chunks/{src-LEXKDSFV.js → src-OP6LFLR6.js} +8 -4
  29. package/dist/chunks/{src-76Q33OY5.js → src-XJKZIY3S.js} +11 -1
  30. package/dist/chunks/{test-stream-OVGDTXOY.js → test-stream-P3CUEGEE.js} +1 -1
  31. package/dist/cli.js +408 -52
  32. package/models.schema.json +4 -0
  33. package/package.json +2 -2
@@ -5099,6 +5099,31 @@ function formatResponsesErrorEvent(event) {
5099
5099
  }
5100
5100
  return metadata.length > 0 ? `${message} (${metadata.join(", ")})` : message;
5101
5101
  }
5102
+ function extractResponsesOutputText(parsed) {
5103
+ if (!isRecord(parsed)) return "";
5104
+ if (typeof parsed.output_text === "string" && parsed.output_text.trim()) {
5105
+ return parsed.output_text.trim();
5106
+ }
5107
+ if (Array.isArray(parsed.output)) {
5108
+ const parts = [];
5109
+ for (const item of parsed.output) {
5110
+ if (!isRecord(item)) continue;
5111
+ if (item.type !== void 0 && item.type !== "message") continue;
5112
+ if (typeof item.content === "string") {
5113
+ if (item.content.trim()) parts.push(item.content);
5114
+ continue;
5115
+ }
5116
+ if (!Array.isArray(item.content)) continue;
5117
+ for (const part of item.content) {
5118
+ if (!isRecord(part)) continue;
5119
+ if (part.type !== void 0 && part.type !== "output_text" && part.type !== "text") continue;
5120
+ if (typeof part.text === "string" && part.text.trim()) parts.push(part.text);
5121
+ }
5122
+ }
5123
+ return parts.join("\n").trim();
5124
+ }
5125
+ return "";
5126
+ }
5102
5127
 
5103
5128
  // ../../packages/ai/src/providers/responses/responses-remote-failure.ts
5104
5129
  var MAX_TEXT = 4096;
@@ -5115,16 +5140,28 @@ var transientCodes = /* @__PURE__ */ new Set([
5115
5140
  "gateway_timeout",
5116
5141
  "request_timeout"
5117
5142
  ]);
5118
- var QUOTA_OR_BILLING_FIELDS = /billing|insufficient_quota|insufficient_balance|plan_quota_exhausted|credit_protection|credit|usage_limit|spend_limit|arrearage/;
5119
- var QUOTA_OR_BILLING_MESSAGE = /billing|insufficient[_ ]quota|plan[_ ]quota[_ ](?:exhausted|exceeded|depleted)|fresh plan quota.*required|credit protection|credits are disabled|exceeded[_ ]current[_ ]quota|billing[_ ]hard[_ ]limit|(?:account|monthly|plan) quota (?:has been |is )?(?:exhausted|exceeded|depleted)|exceeded your current quota|insufficient[_ ](?:credit|balance)|credit balance|spend(?:ing)? limit|\barrearage\b|余额不足/;
5143
+ var QUOTA_OR_BILLING_FIELDS = /billing_(?:hard_limit|not_active|limit|error)|insufficient_quota|insufficient_balance|insufficient_credit|plan_quota_(?:exhausted|exceeded|depleted)|credit_protection|credit_balance|spend_limit|arrearage/;
5144
+ var QUOTA_OR_BILLING_MESSAGE = /insufficient[_ ]quota|plan[_ ]quota[_ ](?:exhausted|exceeded|depleted)|fresh plan quota.*required|credit[_ ]protection|credits are disabled|exceeded[_ ]current[_ ]quota|exceeded your current quota|billing[_ ]hard[_ ]limit|billing[_ ](?:limit|not active|disabled|required)|(?:account|monthly|billing|plan) quota (?:has been |is )?(?:exhausted|exceeded|depleted)|insufficient[_ ](?:credit|balance)|credit balance(?: is)? (?:too low|exhausted|depleted|insufficient)|spend(?:ing)? limit|\barrearage\b|余额不足|周限额|月限额|套餐配额|(?:您)?已达到.{0,12}(?:5\s*小时|每周|每月|本周|本月).{0,6}(?:使用)?上限|\b(?:5[\s-]?hour|5h|weekly|monthly)\s+(?:plan\s+|subscription\s+)?(?:usage\s+)?limit\b|\bplan\s+usage\s+limit\b/;
5120
5145
  var STREAM_LOSS_ERROR_PATTERN = /(?:sse|upstream) stream (?:aborted|closed before end|ended before response completed)|upstream_stream_error|\bsse_abort\b|ClientPayloadError|premature close|socket hang up|other side closed|(?:read\s+)?ECONNRESET|ETIMEDOUT|terminated/i;
5121
5146
  function extractErrorParts(value, status) {
5122
- const root = isRecord(value) ? value : {};
5147
+ let normalizedValue = value;
5148
+ if (typeof value === "string" && value.trimStart().startsWith("{")) {
5149
+ const parsed = parseResponsesErrorBody(value);
5150
+ if (isRecord(parsed)) normalizedValue = parsed;
5151
+ }
5152
+ const root = isRecord(normalizedValue) ? normalizedValue : {};
5123
5153
  const response = isRecord(root.response) ? root.response : {};
5124
- const error = isRecord(root.error) ? root.error : isRecord(response.error) ? response.error : root;
5154
+ const error = isRecord(root.error) ? root.error : isRecord(response.error) ? response.error : isRecord(root.detail) ? root.detail : root;
5125
5155
  const code = typeof error.code === "string" ? error.code.slice(0, 128).toLowerCase() : "";
5126
5156
  const type = typeof error.type === "string" ? error.type.slice(0, 128).toLowerCase() : "";
5127
- const rawMessage = typeof value === "string" ? value : typeof error.message === "string" ? error.message : typeof root.message === "string" ? root.message : "";
5157
+ const rawMessage = typeof normalizedValue === "string" ? normalizedValue : [
5158
+ error.message,
5159
+ error.detail,
5160
+ root.message,
5161
+ root.error,
5162
+ response.error,
5163
+ root.detail
5164
+ ].filter((part) => typeof part === "string" && part.length > 0).join(" ");
5128
5165
  const message = rawMessage.slice(0, MAX_TEXT).toLowerCase();
5129
5166
  const httpStatus = status ?? root.status ?? root.statusCode;
5130
5167
  return { root, code, type, fields: `${code} ${type}`, message, httpStatus };
@@ -5139,12 +5176,23 @@ function isStreamLossErrorText(text) {
5139
5176
  function responsesRemoteFailure(value, status, headers) {
5140
5177
  const { root, code, type, fields, message, httpStatus } = extractErrorParts(value, status);
5141
5178
  let category = "other";
5142
- if (/context_length_exceeded|context_window_exceeded|context_overflow/.test(fields) || /context (?:length|window).{0,60}(?:exceed|too (?:long|large))|maximum context length|exceeds.{0,30}context window/.test(message)) category = "context_overflow";
5143
- else if (QUOTA_OR_BILLING_FIELDS.test(fields) || QUOTA_OR_BILLING_MESSAGE.test(message)) category = "other";
5144
- else if (typeof httpStatus === "number" && httpStatus >= 400 && httpStatus < 500 && httpStatus !== 429 && httpStatus !== 408) category = "other";
5145
- else if (httpStatus === 429 || httpStatus === 408 || typeof httpStatus === "number" && httpStatus >= 500 && httpStatus <= 599 && httpStatus !== 501 || transientCodes.has(code) || transientCodes.has(type) || /server (?:is )?overloaded|temporarily unavailable|internal server error|rate limit (?:exceeded|reached)|upstream stream aborted|clientpayloaderror/.test(message)) category = "transient";
5179
+ let quotaExhausted = false;
5180
+ if (/context_length_exceeded|context_window_exceeded|context_overflow/.test(fields) || /context (?:length|window).{0,60}(?:exceed|too (?:long|large))|maximum context length|exceeds.{0,30}context window/.test(message)) {
5181
+ category = "context_overflow";
5182
+ } else if (QUOTA_OR_BILLING_FIELDS.test(fields) || QUOTA_OR_BILLING_MESSAGE.test(message)) {
5183
+ category = "other";
5184
+ quotaExhausted = true;
5185
+ } else if (typeof httpStatus === "number" && httpStatus >= 400 && httpStatus < 500 && httpStatus !== 429 && httpStatus !== 408) {
5186
+ category = "other";
5187
+ } else if (httpStatus === 429 || httpStatus === 408 || typeof httpStatus === "number" && httpStatus >= 500 && httpStatus <= 599 && httpStatus !== 501 || transientCodes.has(code) || transientCodes.has(type) || /server (?:is )?overloaded|temporarily unavailable|internal server error|rate limit (?:exceeded|reached)|upstream stream aborted|clientpayloaderror/.test(message)) {
5188
+ category = "transient";
5189
+ }
5146
5190
  const retryAfterMs = parseRetryAfter(headers ?? root.headers);
5147
- return { category, ...retryAfterMs !== void 0 ? { retryAfterMs } : {} };
5191
+ return {
5192
+ category,
5193
+ ...quotaExhausted ? { quotaExhausted: true } : {},
5194
+ ...retryAfterMs !== void 0 ? { retryAfterMs } : {}
5195
+ };
5148
5196
  }
5149
5197
  function parseRetryAfter(headers) {
5150
5198
  if (!headers || typeof headers !== "object") return void 0;
@@ -5300,12 +5348,13 @@ var ResponsesEventReducer = class {
5300
5348
  events.push(...this.appendTextDelta(raw, "text"));
5301
5349
  break;
5302
5350
  case "response.output_text.done":
5303
- this.validateTextDone(raw);
5351
+ events.push(...this.onTextDone(raw, "text"));
5304
5352
  break;
5305
5353
  case "response.refusal.delta":
5306
5354
  events.push(...this.appendTextDelta(raw, "refusal"));
5307
5355
  break;
5308
5356
  case "response.refusal.done":
5357
+ events.push(...this.onTextDone(raw, "refusal"));
5309
5358
  break;
5310
5359
  case "response.reasoning_summary_text.delta":
5311
5360
  case "response.reasoning_text.delta":
@@ -5435,16 +5484,30 @@ var ResponsesEventReducer = class {
5435
5484
  throw new ResponsesProtocolError("response.content_part.added is missing a valid content_index.");
5436
5485
  }
5437
5486
  if (state.kind !== "message") return [];
5438
- if (state.blocks.has(partIndex)) {
5487
+ const existing = state.blocks.get(partIndex);
5488
+ if (existing?.started) {
5439
5489
  throw new ResponsesProtocolError(`Responses stream reused content_index ${partIndex} on one message item.`);
5440
5490
  }
5441
5491
  if (partType !== "output_text" && partType !== "refusal") {
5442
5492
  return [];
5443
5493
  }
5494
+ if (existing) {
5495
+ existing.started = true;
5496
+ return [{ type: "text_start", contentIndex: existing.contentIndex, partial: this.output }];
5497
+ }
5498
+ if (partIndex > 0 && partIndex <= 32) {
5499
+ for (let idx = 0; idx < partIndex; idx += 1) {
5500
+ if (state.blocks.has(idx)) continue;
5501
+ const placeholder = { type: "text", text: "" };
5502
+ this.output.content.push(placeholder);
5503
+ state.blocks.set(idx, { block: placeholder, contentIndex: this.output.content.length - 1, started: false });
5504
+ }
5505
+ }
5444
5506
  const block = { type: "text", text: "" };
5445
5507
  this.output.content.push(block);
5446
- state.blocks.set(partIndex, { block, contentIndex: this.output.content.length - 1 });
5447
- return [{ type: "text_start", contentIndex: this.output.content.length - 1, partial: this.output }];
5508
+ const contentIndex = this.output.content.length - 1;
5509
+ state.blocks.set(partIndex, { block, contentIndex, started: true });
5510
+ return [{ type: "text_start", contentIndex, partial: this.output }];
5448
5511
  }
5449
5512
  messageBlockFor(raw) {
5450
5513
  const { state } = this.lookupItem(raw, ["message"], "message");
@@ -5454,7 +5517,7 @@ var ResponsesEventReducer = class {
5454
5517
  throw new ResponsesProtocolError(`Responses event "${raw.type}" is missing a valid content_index.`);
5455
5518
  }
5456
5519
  const entry = state.blocks.get(partIndex);
5457
- if (!entry) {
5520
+ if (!entry || !entry.started) {
5458
5521
  throw new ResponsesProtocolError(
5459
5522
  `Responses event "${raw.type}" references content_index ${partIndex} that was never added.`
5460
5523
  );
@@ -5468,8 +5531,16 @@ var ResponsesEventReducer = class {
5468
5531
  entry.block.text += delta;
5469
5532
  return [{ type: "text_delta", contentIndex: entry.contentIndex, delta, partial: this.output }];
5470
5533
  }
5471
- validateTextDone(raw) {
5472
- this.messageBlockFor(raw);
5534
+ onTextDone(raw, kind) {
5535
+ const entry = this.messageBlockFor(raw);
5536
+ if (entry.block.text.length === 0) {
5537
+ const fallback = kind === "refusal" ? raw.refusal : raw.text;
5538
+ if (typeof fallback === "string" && fallback.length > 0) {
5539
+ entry.block.text = fallback;
5540
+ return [{ type: "text_delta", contentIndex: entry.contentIndex, delta: fallback, partial: this.output }];
5541
+ }
5542
+ }
5543
+ return [];
5473
5544
  }
5474
5545
  appendReasoningDelta(raw) {
5475
5546
  const delta = raw.delta;
@@ -5519,7 +5590,39 @@ ${delta}`;
5519
5590
  switch (state.kind) {
5520
5591
  case "message": {
5521
5592
  const events = [];
5522
- for (const { block, contentIndex } of state.blocks.values()) {
5593
+ const doneParts = Array.isArray(item.content) ? item.content : [];
5594
+ for (let idx = 0; idx < doneParts.length; idx += 1) {
5595
+ const part = doneParts[idx];
5596
+ if (!isRecord(part)) continue;
5597
+ const partType = part.type;
5598
+ if (partType !== "output_text" && partType !== "refusal") continue;
5599
+ const fallback = partType === "refusal" ? typeof part.refusal === "string" ? part.refusal : "" : typeof part.text === "string" ? part.text : "";
5600
+ const existing = state.blocks.get(idx);
5601
+ if (existing) {
5602
+ if (!existing.started) {
5603
+ existing.started = true;
5604
+ existing.block.text = fallback;
5605
+ events.push({ type: "text_start", contentIndex: existing.contentIndex, partial: this.output });
5606
+ if (fallback.length > 0) {
5607
+ events.push({ type: "text_delta", contentIndex: existing.contentIndex, delta: fallback, partial: this.output });
5608
+ }
5609
+ } else if (existing.block.text.length === 0 && fallback.length > 0) {
5610
+ existing.block.text = fallback;
5611
+ events.push({ type: "text_delta", contentIndex: existing.contentIndex, delta: fallback, partial: this.output });
5612
+ }
5613
+ } else {
5614
+ const block = { type: "text", text: fallback };
5615
+ this.output.content.push(block);
5616
+ const contentIndex = this.output.content.length - 1;
5617
+ state.blocks.set(idx, { block, contentIndex, started: true });
5618
+ events.push({ type: "text_start", contentIndex, partial: this.output });
5619
+ if (fallback.length > 0) {
5620
+ events.push({ type: "text_delta", contentIndex, delta: fallback, partial: this.output });
5621
+ }
5622
+ }
5623
+ }
5624
+ const ordered = [...state.blocks.entries()].filter(([, entry]) => entry.started).sort((a, b) => a[0] - b[0]);
5625
+ for (const [, { block, contentIndex }] of ordered) {
5523
5626
  events.push({ type: "text_end", contentIndex, content: block.text, partial: this.output });
5524
5627
  }
5525
5628
  return events;
@@ -5600,15 +5703,15 @@ ${delta}`;
5600
5703
  this.diagnostics.terminalType = "response.incomplete";
5601
5704
  const response = this.requireTerminalResponse(raw);
5602
5705
  const reason = response?.incomplete_details?.reason;
5603
- if (reason === "content_filter" || reason === "steered" || reason === void 0) {
5604
- this.terminal = {
5605
- reason: "error",
5606
- response,
5607
- errorText: reason === "steered" ? "Response ended incomplete with reason 'steered' but no steering was sent." : `Response ended incomplete${reason ? ` (${reason})` : " without a reason"}.`
5608
- };
5706
+ if (reason === "max_output_tokens" || reason === "max_tokens" || reason === "max_messages") {
5707
+ this.terminal = { reason: "length", response };
5609
5708
  return this.closeResponse("response.incomplete");
5610
5709
  }
5611
- this.terminal = { reason: "length", response };
5710
+ this.terminal = {
5711
+ reason: "error",
5712
+ response,
5713
+ errorText: reason === "steered" ? "Response ended incomplete with reason 'steered' but no steering was sent." : `Response ended incomplete${reason ? ` (${reason})` : " without a reason"}.`
5714
+ };
5612
5715
  return this.closeResponse("response.incomplete");
5613
5716
  }
5614
5717
  failedText(raw) {
@@ -5663,6 +5766,11 @@ ${delta}`;
5663
5766
  if (stopReason === "toolUse" && this.toolCallStates.length === 0) {
5664
5767
  stopReason = "stop";
5665
5768
  }
5769
+ if (stopReason === "stop" && !hasAssistantContent(this.output)) {
5770
+ this.output.stopReason = "error";
5771
+ this.output.errorMessage = EMPTY_ASSISTANT_CONTENT_ERROR;
5772
+ return [{ type: "error", reason: "error", error: this.output }];
5773
+ }
5666
5774
  this.output.stopReason = stopReason;
5667
5775
  void terminalType;
5668
5776
  return [{ type: "done", reason: stopReason, message: this.output }];
@@ -7104,12 +7212,144 @@ function getResponsesCompat(model) {
7104
7212
  responsesContinuation: compat.responsesContinuation ?? false,
7105
7213
  supportsReasoningSummary: compat.supportsReasoningSummary ?? false,
7106
7214
  reasoningSummary: compat.reasoningSummary ?? "auto",
7107
- timeoutReplay: compat.timeoutReplay ?? false
7215
+ timeoutReplay: compat.timeoutReplay ?? false,
7216
+ supportsPromptCacheKey: compat.supportsPromptCacheKey ?? false
7108
7217
  };
7109
7218
  }
7110
7219
 
7220
+ // ../../packages/ai/src/providers/responses/responses-continuation.ts
7221
+ function jsonSha256(value) {
7222
+ return hashJson(value);
7223
+ }
7224
+ function hashJson(value, parts) {
7225
+ const utf8 = tryCreateUtf8Sha256Hasher();
7226
+ try {
7227
+ const hash = utf8 ? void 0 : createSha256Hasher();
7228
+ const bytes = new Uint8Array(utf8 ? 0 : 8192);
7229
+ let fragments = "";
7230
+ let used = 0;
7231
+ const byte = (n) => {
7232
+ bytes[used++] = n;
7233
+ if (used === bytes.length) {
7234
+ hash.update(bytes);
7235
+ used = 0;
7236
+ }
7237
+ };
7238
+ const emit = (text) => {
7239
+ if (utf8) {
7240
+ if (fragments.length + text.length > 8192) {
7241
+ if (fragments) utf8.updateUtf8(fragments);
7242
+ fragments = "";
7243
+ }
7244
+ if (text.length >= 8192) utf8.updateUtf8(text);
7245
+ else fragments += text;
7246
+ return;
7247
+ }
7248
+ for (let i = 0; i < text.length; i++) {
7249
+ const cp = text.codePointAt(i);
7250
+ if (cp < 128) byte(cp);
7251
+ else if (cp < 2048) {
7252
+ byte(192 | cp >> 6);
7253
+ byte(128 | cp & 63);
7254
+ } else if (cp < 65536) {
7255
+ byte(224 | cp >> 12);
7256
+ byte(128 | cp >> 6 & 63);
7257
+ byte(128 | cp & 63);
7258
+ } else {
7259
+ byte(240 | cp >> 18);
7260
+ byte(128 | cp >> 12 & 63);
7261
+ byte(128 | cp >> 6 & 63);
7262
+ byte(128 | cp & 63);
7263
+ i++;
7264
+ }
7265
+ }
7266
+ };
7267
+ const string = (text) => {
7268
+ emit('"');
7269
+ for (let start = 0; start < text.length; ) {
7270
+ let end = Math.min(start + 2048, text.length);
7271
+ if (end < text.length && text.charCodeAt(end - 1) >= 55296 && text.charCodeAt(end - 1) <= 56319) end--;
7272
+ const escaped = JSON.stringify(text.slice(start, end));
7273
+ emit(escaped.slice(1, -1));
7274
+ start = end;
7275
+ }
7276
+ emit('"');
7277
+ };
7278
+ const ancestors = /* @__PURE__ */ new Set();
7279
+ const omitted = (v) => v === void 0 || typeof v === "function" || typeof v === "symbol";
7280
+ const visit = (v) => {
7281
+ if (typeof v === "string") {
7282
+ string(v);
7283
+ return;
7284
+ }
7285
+ if (v === null || typeof v !== "object") {
7286
+ const encoded = JSON.stringify(v);
7287
+ if (encoded === void 0) throw new TypeError("Not a JSON value");
7288
+ emit(encoded);
7289
+ return;
7290
+ }
7291
+ const prototype = Object.getPrototypeOf(v);
7292
+ if (!Array.isArray(v) && prototype !== Object.prototype && prototype !== null || typeof v.toJSON === "function") throw new TypeError("Not a JSON snapshot");
7293
+ if (ancestors.has(v)) throw new TypeError("Circular JSON snapshot");
7294
+ ancestors.add(v);
7295
+ if (Array.isArray(v)) {
7296
+ emit("[");
7297
+ for (let i = 0; i < v.length; i++) {
7298
+ if (Object.getOwnPropertyDescriptor(v, i)?.get) throw new TypeError("Not a JSON snapshot");
7299
+ if (i) emit(",");
7300
+ visit(omitted(v[i]) ? null : v[i]);
7301
+ }
7302
+ emit("]");
7303
+ } else {
7304
+ emit("{");
7305
+ let first = true;
7306
+ for (const key of Object.keys(v)) {
7307
+ if (Object.getOwnPropertyDescriptor(v, key)?.get) throw new TypeError("Not a JSON snapshot");
7308
+ const entry = v[key];
7309
+ if (omitted(entry)) continue;
7310
+ if (!first) emit(",");
7311
+ first = false;
7312
+ string(key);
7313
+ emit(":");
7314
+ visit(entry);
7315
+ }
7316
+ emit("}");
7317
+ }
7318
+ ancestors.delete(v);
7319
+ };
7320
+ if (parts) {
7321
+ emit("[");
7322
+ for (let i = 0; i < parts.count + parts.output.length; i++) {
7323
+ if (i) emit(",");
7324
+ const item = i < parts.count ? parts.input[i] : parts.output[i - parts.count];
7325
+ visit(omitted(item) ? null : item);
7326
+ }
7327
+ emit("]");
7328
+ } else visit(value);
7329
+ if (utf8) {
7330
+ if (fragments) utf8.updateUtf8(fragments);
7331
+ return utf8.digestHex();
7332
+ }
7333
+ if (used) hash.update(bytes.subarray(0, used));
7334
+ return hash.digestHex();
7335
+ } finally {
7336
+ utf8?.dispose();
7337
+ }
7338
+ }
7339
+ function inputSha256(input, count = input.length, output = []) {
7340
+ return hashJson(void 0, { input, count, output });
7341
+ }
7342
+
7111
7343
  // ../../packages/ai/src/providers/responses/responses-request.ts
7112
7344
  var MAX_REASONING_ENVELOPE_BYTES = 512 * 1024;
7345
+ var MAX_PROMPT_CACHE_KEY_LEN = 64;
7346
+ var SAFE_PROMPT_CACHE_KEY_RE = /^[\x21-\x7E]{1,64}$/;
7347
+ function normalizePromptCacheKey(sessionId) {
7348
+ const trimmed = sessionId.trim();
7349
+ if (!trimmed) return void 0;
7350
+ if (SAFE_PROMPT_CACHE_KEY_RE.test(trimmed)) return trimmed;
7351
+ return `pie-${jsonSha256(trimmed).slice(0, MAX_PROMPT_CACHE_KEY_LEN - 4)}`;
7352
+ }
7113
7353
  function decodeReasoningEnvelope(signature) {
7114
7354
  if (typeof signature !== "string" || signature.length === 0 || signature.length > MAX_REASONING_ENVELOPE_BYTES) {
7115
7355
  return null;
@@ -7258,6 +7498,10 @@ function buildResponsesRequest(model, context, options, compat = getResponsesCom
7258
7498
  if (compat.supportsStore) {
7259
7499
  params.store = compat.store;
7260
7500
  }
7501
+ if (compat.supportsPromptCacheKey && options?.cacheRetention !== "none" && typeof options?.sessionId === "string") {
7502
+ const cacheKey = normalizePromptCacheKey(options.sessionId);
7503
+ if (cacheKey) params.prompt_cache_key = cacheKey;
7504
+ }
7261
7505
  if (options?.maxTokens !== void 0 && options.maxTokens > 0) {
7262
7506
  params.max_output_tokens = options.maxTokens;
7263
7507
  }
@@ -7547,6 +7791,9 @@ function streamResponsesSSE(model, context, options) {
7547
7791
  stream2.push(assistantEvent);
7548
7792
  }
7549
7793
  if (reducer.isTerminal) {
7794
+ if (reducer.message.stopReason === "error" && reducer.message.errorMessage === EMPTY_ASSISTANT_CONTENT_ERROR) {
7795
+ logEmptyAssistantContentError(new EmptyAssistantContentError(), model, options);
7796
+ }
7550
7797
  terminalAccepted = true;
7551
7798
  phase = "terminal_accepted";
7552
7799
  clearTotalTimer();
@@ -7612,129 +7859,6 @@ function streamResponsesSSE(model, context, options) {
7612
7859
  return stream2;
7613
7860
  }
7614
7861
 
7615
- // ../../packages/ai/src/providers/responses/responses-continuation.ts
7616
- function jsonSha256(value) {
7617
- return hashJson(value);
7618
- }
7619
- function hashJson(value, parts) {
7620
- const utf8 = tryCreateUtf8Sha256Hasher();
7621
- try {
7622
- const hash = utf8 ? void 0 : createSha256Hasher();
7623
- const bytes = new Uint8Array(utf8 ? 0 : 8192);
7624
- let fragments = "";
7625
- let used = 0;
7626
- const byte = (n) => {
7627
- bytes[used++] = n;
7628
- if (used === bytes.length) {
7629
- hash.update(bytes);
7630
- used = 0;
7631
- }
7632
- };
7633
- const emit = (text) => {
7634
- if (utf8) {
7635
- if (fragments.length + text.length > 8192) {
7636
- if (fragments) utf8.updateUtf8(fragments);
7637
- fragments = "";
7638
- }
7639
- if (text.length >= 8192) utf8.updateUtf8(text);
7640
- else fragments += text;
7641
- return;
7642
- }
7643
- for (let i = 0; i < text.length; i++) {
7644
- const cp = text.codePointAt(i);
7645
- if (cp < 128) byte(cp);
7646
- else if (cp < 2048) {
7647
- byte(192 | cp >> 6);
7648
- byte(128 | cp & 63);
7649
- } else if (cp < 65536) {
7650
- byte(224 | cp >> 12);
7651
- byte(128 | cp >> 6 & 63);
7652
- byte(128 | cp & 63);
7653
- } else {
7654
- byte(240 | cp >> 18);
7655
- byte(128 | cp >> 12 & 63);
7656
- byte(128 | cp >> 6 & 63);
7657
- byte(128 | cp & 63);
7658
- i++;
7659
- }
7660
- }
7661
- };
7662
- const string = (text) => {
7663
- emit('"');
7664
- for (let start = 0; start < text.length; ) {
7665
- let end = Math.min(start + 2048, text.length);
7666
- if (end < text.length && text.charCodeAt(end - 1) >= 55296 && text.charCodeAt(end - 1) <= 56319) end--;
7667
- const escaped = JSON.stringify(text.slice(start, end));
7668
- emit(escaped.slice(1, -1));
7669
- start = end;
7670
- }
7671
- emit('"');
7672
- };
7673
- const ancestors = /* @__PURE__ */ new Set();
7674
- const omitted = (v) => v === void 0 || typeof v === "function" || typeof v === "symbol";
7675
- const visit = (v) => {
7676
- if (typeof v === "string") {
7677
- string(v);
7678
- return;
7679
- }
7680
- if (v === null || typeof v !== "object") {
7681
- const encoded = JSON.stringify(v);
7682
- if (encoded === void 0) throw new TypeError("Not a JSON value");
7683
- emit(encoded);
7684
- return;
7685
- }
7686
- const prototype = Object.getPrototypeOf(v);
7687
- if (!Array.isArray(v) && prototype !== Object.prototype && prototype !== null || typeof v.toJSON === "function") throw new TypeError("Not a JSON snapshot");
7688
- if (ancestors.has(v)) throw new TypeError("Circular JSON snapshot");
7689
- ancestors.add(v);
7690
- if (Array.isArray(v)) {
7691
- emit("[");
7692
- for (let i = 0; i < v.length; i++) {
7693
- if (Object.getOwnPropertyDescriptor(v, i)?.get) throw new TypeError("Not a JSON snapshot");
7694
- if (i) emit(",");
7695
- visit(omitted(v[i]) ? null : v[i]);
7696
- }
7697
- emit("]");
7698
- } else {
7699
- emit("{");
7700
- let first = true;
7701
- for (const key of Object.keys(v)) {
7702
- if (Object.getOwnPropertyDescriptor(v, key)?.get) throw new TypeError("Not a JSON snapshot");
7703
- const entry = v[key];
7704
- if (omitted(entry)) continue;
7705
- if (!first) emit(",");
7706
- first = false;
7707
- string(key);
7708
- emit(":");
7709
- visit(entry);
7710
- }
7711
- emit("}");
7712
- }
7713
- ancestors.delete(v);
7714
- };
7715
- if (parts) {
7716
- emit("[");
7717
- for (let i = 0; i < parts.count + parts.output.length; i++) {
7718
- if (i) emit(",");
7719
- const item = i < parts.count ? parts.input[i] : parts.output[i - parts.count];
7720
- visit(omitted(item) ? null : item);
7721
- }
7722
- emit("]");
7723
- } else visit(value);
7724
- if (utf8) {
7725
- if (fragments) utf8.updateUtf8(fragments);
7726
- return utf8.digestHex();
7727
- }
7728
- if (used) hash.update(bytes.subarray(0, used));
7729
- return hash.digestHex();
7730
- } finally {
7731
- utf8?.dispose();
7732
- }
7733
- }
7734
- function inputSha256(input, count = input.length, output = []) {
7735
- return hashJson(void 0, { input, count, output });
7736
- }
7737
-
7738
7862
  // ../../packages/ai/src/providers/responses/responses-ws.ts
7739
7863
  var owners = /* @__PURE__ */ new WeakMap();
7740
7864
  var DEFAULT_CONNECT_TIMEOUT_MS = 3e4;
@@ -8245,6 +8369,9 @@ function streamResponsesWS(model, context, options) {
8245
8369
  }
8246
8370
  }
8247
8371
  finished = true;
8372
+ if (reducer.message.stopReason === "error" && reducer.message.errorMessage === EMPTY_ASSISTANT_CONTENT_ERROR) {
8373
+ logEmptyAssistantContentError(new EmptyAssistantContentError(), model, options);
8374
+ }
8248
8375
  clearRequestTimers();
8249
8376
  retryDecision = reducer.message.remoteFailure ? `remote_${reducer.message.remoteFailure.category}` : "terminal";
8250
8377
  lifecycle("terminal_accepted", {
@@ -8372,6 +8499,38 @@ var streamSimpleResponses = (model, context, options) => {
8372
8499
  });
8373
8500
  };
8374
8501
 
8502
+ // ../../packages/ai/src/compat-merge.ts
8503
+ var FORBIDDEN_MERGE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
8504
+ function isPlainRecord(value) {
8505
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
8506
+ const proto = Object.getPrototypeOf(value);
8507
+ return proto === Object.prototype || proto === null;
8508
+ }
8509
+ function deepMergePlainRecords(base, patch) {
8510
+ const result = {};
8511
+ if (isPlainRecord(base)) {
8512
+ for (const [key, value] of Object.entries(base)) {
8513
+ if (FORBIDDEN_MERGE_KEYS.has(key)) continue;
8514
+ result[key] = isPlainRecord(value) ? deepMergePlainRecords({}, value) : value;
8515
+ }
8516
+ }
8517
+ if (!isPlainRecord(patch)) return result;
8518
+ for (const [key, value] of Object.entries(patch)) {
8519
+ if (FORBIDDEN_MERGE_KEYS.has(key)) continue;
8520
+ const current = result[key];
8521
+ result[key] = isPlainRecord(current) && isPlainRecord(value) ? deepMergePlainRecords(current, value) : isPlainRecord(value) ? deepMergePlainRecords({}, value) : value;
8522
+ }
8523
+ return result;
8524
+ }
8525
+ function mergeModelCompat(...layers) {
8526
+ let merged;
8527
+ for (const layer of layers) {
8528
+ if (!isPlainRecord(layer)) continue;
8529
+ merged = merged ? deepMergePlainRecords(merged, layer) : deepMergePlainRecords({}, layer);
8530
+ }
8531
+ return merged;
8532
+ }
8533
+
8375
8534
  // ../../packages/ai/src/stream.ts
8376
8535
  function resolveApiProvider(api) {
8377
8536
  const provider = getApiProvider(api);
@@ -11934,6 +12093,9 @@ export {
11934
12093
  logEmptyAssistantContentError,
11935
12094
  RESPONSES_PROTOCOL_ERROR_CODE,
11936
12095
  ResponsesProtocolError,
12096
+ extractResponsesOutputText,
12097
+ isQuotaOrBillingFailure,
12098
+ parseResponsesErrorBody,
11937
12099
  OPENAI_COMPAT_PROTOCOL_ERROR_CODE,
11938
12100
  OpenAICompatProtocolError,
11939
12101
  streamOpenAICompletions,
@@ -11944,6 +12106,8 @@ export {
11944
12106
  disposeModelTransports,
11945
12107
  streamResponses,
11946
12108
  streamSimpleResponses,
12109
+ deepMergePlainRecords,
12110
+ mergeModelCompat,
11947
12111
  stream,
11948
12112
  complete,
11949
12113
  streamSimple,
@@ -5,7 +5,7 @@ import {
5
5
  validateModelsDocumentShape,
6
6
  validateProfileConfig,
7
7
  validatedRemoteCatalogs
8
- } from "./chunk-UYDS75SI.js";
8
+ } from "./chunk-NAMH667S.js";
9
9
 
10
10
  // src/core/worker-lifecycle-bridge.ts
11
11
  var activeBridge;
@@ -5,10 +5,10 @@ import {
5
5
  import {
6
6
  createReadFileUnderstandingHandler,
7
7
  modalityForReadFileUnderstandingKind
8
- } from "./chunk-EZZTMDWZ.js";
8
+ } from "./chunk-JE53PC46.js";
9
9
  import {
10
10
  getLogger
11
- } from "./chunk-MCR4JYI6.js";
11
+ } from "./chunk-YKV45EMY.js";
12
12
 
13
13
  // src/capabilities/read-file-understanding.ts
14
14
  import * as path10 from "node:path";
@@ -5,7 +5,7 @@ import "./chunk-LZQXQOPJ.js";
5
5
  import * as os from "node:os";
6
6
  async function describeImageViaUnderstandingChain(options) {
7
7
  try {
8
- const { understandReadFile } = await import("./read-file-understanding-DFJPTTSB.js");
8
+ const { understandReadFile } = await import("./read-file-understanding-ZRE5KDG3.js");
9
9
  const ext = options.filePath.toLowerCase().split(".").pop() ?? "";
10
10
  const mimeType = ext === "png" ? "image/png" : ext === "gif" ? "image/gif" : ext === "webp" ? "image/webp" : "image/jpeg";
11
11
  const result = await understandReadFile(
@@ -4,11 +4,11 @@ import {
4
4
  ensureMemoryGitIgnore,
5
5
  isMemoryGitInitialized,
6
6
  readCuratedMemoryGitLog
7
- } from "./chunk-IK2FR2YF.js";
8
- import "./chunk-EZZTMDWZ.js";
9
- import "./chunk-JJH77AUU.js";
10
- import "./chunk-26KRUYZH.js";
11
- import "./chunk-MCR4JYI6.js";
7
+ } from "./chunk-VWDCKHCC.js";
8
+ import "./chunk-JE53PC46.js";
9
+ import "./chunk-J6EZ335F.js";
10
+ import "./chunk-MTH6QSYD.js";
11
+ import "./chunk-YKV45EMY.js";
12
12
  import "./chunk-XXGYUYXI.js";
13
13
  import "./chunk-LZQXQOPJ.js";
14
14
  export {
@@ -8,9 +8,9 @@ import {
8
8
  validateModelsDocumentShape,
9
9
  validateProfileConfig,
10
10
  validatedRemoteCatalogs
11
- } from "./chunk-UYDS75SI.js";
11
+ } from "./chunk-NAMH667S.js";
12
12
  import "./chunk-CBDQJMUI.js";
13
- import "./chunk-MCR4JYI6.js";
13
+ import "./chunk-YKV45EMY.js";
14
14
  import "./chunk-XXGYUYXI.js";
15
15
  import "./chunk-LZQXQOPJ.js";
16
16
  export {