@foldrun/core 18.0.0 → 18.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -138,6 +138,9 @@ export declare class ToolCallExtras {
138
138
  keep(id: string, extra: unknown): void;
139
139
  get(id: string): Json | undefined;
140
140
  get size(): number;
141
+ /** Every kept call's extras, oldest first — for a caller that keeps them
142
+ * between separate requests (the LLM gateway, per account). */
143
+ entries(): [string, Json][];
141
144
  }
142
145
  export declare class StreamTranslator {
143
146
  private started;
@@ -179,6 +182,10 @@ export declare class ResponsesStreamTranslator {
179
182
  private incomplete;
180
183
  private sawTool;
181
184
  private sawRefusal;
185
+ /** The stream's last word: completed or incomplete (an answer), or the
186
+ * provider's error. None at all means it was cut off. */
187
+ private terminal;
188
+ private failure;
182
189
  private id;
183
190
  private readonly model;
184
191
  constructor(model: string);
@@ -575,6 +575,11 @@ export class ToolCallExtras {
575
575
  get size() {
576
576
  return this.byId.size;
577
577
  }
578
+ /** Every kept call's extras, oldest first — for a caller that keeps them
579
+ * between separate requests (the LLM gateway, per account). */
580
+ entries() {
581
+ return [...this.byId.entries()];
582
+ }
578
583
  }
579
584
  export class StreamTranslator {
580
585
  started = false;
@@ -767,6 +772,10 @@ export class ResponsesStreamTranslator {
767
772
  incomplete = null;
768
773
  sawTool = false;
769
774
  sawRefusal = false;
775
+ /** The stream's last word: completed or incomplete (an answer), or the
776
+ * provider's error. None at all means it was cut off. */
777
+ terminal = null;
778
+ failure = null;
770
779
  id = `msg_${crypto.randomBytes(8).toString("hex")}`;
771
780
  model;
772
781
  constructor(model) {
@@ -869,6 +878,20 @@ export class ResponsesStreamTranslator {
869
878
  const reason = r.incomplete_details?.reason;
870
879
  if (typeof reason === "string")
871
880
  this.incomplete = reason;
881
+ if (type === "response.failed") {
882
+ // A failure is not an answer (Codex review, 10 Nov 2026): it was
883
+ // ended as a normal stop, so the caller read a failed reply as done.
884
+ this.terminal = "failed";
885
+ const err = r.error ?? {};
886
+ this.failure = typeof err.message === "string" ? err.message : "the provider reported the response failed";
887
+ }
888
+ else
889
+ this.terminal = "done";
890
+ return out;
891
+ }
892
+ if (type === "error") {
893
+ this.terminal = "failed";
894
+ this.failure = typeof ev.message === "string" ? ev.message : "the provider sent an error mid-stream";
872
895
  return out;
873
896
  }
874
897
  return out;
@@ -883,6 +906,13 @@ export class ResponsesStreamTranslator {
883
906
  }
884
907
  out.push(this.event("content_block_stop", { type: "content_block_stop", index: entry.block }));
885
908
  }
909
+ // Failed, or cut off before any last word: an Anthropic error event, the
910
+ // shape a client reads as a failed request, never a normal stop.
911
+ if (this.terminal !== "done") {
912
+ const message = this.terminal === "failed" ? this.failure : "the provider's stream ended before the response finished";
913
+ out.push(this.event("error", { type: "error", error: { type: "api_error", message } }));
914
+ return out;
915
+ }
886
916
  const reason = responsesStop(this.incomplete, this.sawTool, this.sawRefusal);
887
917
  out.push(this.event("message_delta", {
888
918
  type: "message_delta",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "18.0.0",
3
+ "version": "18.0.1",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
package/src/translator.ts CHANGED
@@ -615,6 +615,11 @@ export class ToolCallExtras {
615
615
  get size(): number {
616
616
  return this.byId.size;
617
617
  }
618
+ /** Every kept call's extras, oldest first — for a caller that keeps them
619
+ * between separate requests (the LLM gateway, per account). */
620
+ entries(): [string, Json][] {
621
+ return [...this.byId.entries()];
622
+ }
618
623
  }
619
624
 
620
625
  export class StreamTranslator {
@@ -824,6 +829,10 @@ export class ResponsesStreamTranslator {
824
829
  private incomplete: string | null = null;
825
830
  private sawTool = false;
826
831
  private sawRefusal = false;
832
+ /** The stream's last word: completed or incomplete (an answer), or the
833
+ * provider's error. None at all means it was cut off. */
834
+ private terminal: "done" | "failed" | null = null;
835
+ private failure: string | null = null;
827
836
  private id = `msg_${crypto.randomBytes(8).toString("hex")}`;
828
837
  private readonly model: string;
829
838
  constructor(model: string) {
@@ -925,6 +934,18 @@ export class ResponsesStreamTranslator {
925
934
  if (u) this.usage = anthropicUsage(u, "responses");
926
935
  const reason = (r.incomplete_details as Json | undefined)?.reason;
927
936
  if (typeof reason === "string") this.incomplete = reason;
937
+ if (type === "response.failed") {
938
+ // A failure is not an answer (Codex review, 10 Nov 2026): it was
939
+ // ended as a normal stop, so the caller read a failed reply as done.
940
+ this.terminal = "failed";
941
+ const err = (r.error as Json | undefined) ?? {};
942
+ this.failure = typeof err.message === "string" ? err.message : "the provider reported the response failed";
943
+ } else this.terminal = "done";
944
+ return out;
945
+ }
946
+ if (type === "error") {
947
+ this.terminal = "failed";
948
+ this.failure = typeof ev.message === "string" ? ev.message : "the provider sent an error mid-stream";
928
949
  return out;
929
950
  }
930
951
  return out;
@@ -939,6 +960,13 @@ export class ResponsesStreamTranslator {
939
960
  }
940
961
  out.push(this.event("content_block_stop", { type: "content_block_stop", index: entry.block }));
941
962
  }
963
+ // Failed, or cut off before any last word: an Anthropic error event, the
964
+ // shape a client reads as a failed request, never a normal stop.
965
+ if (this.terminal !== "done") {
966
+ const message = this.terminal === "failed" ? this.failure! : "the provider's stream ended before the response finished";
967
+ out.push(this.event("error", { type: "error", error: { type: "api_error", message } }));
968
+ return out;
969
+ }
942
970
  const reason = responsesStop(this.incomplete, this.sawTool, this.sawRefusal);
943
971
  out.push(
944
972
  this.event("message_delta", {