@sema-agent/core 5.7.0 → 5.9.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 (102) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/dist/agents/cascade.d.ts +1 -1
  3. package/dist/agents/cascade.js +24 -0
  4. package/dist/agents/subagent.d.ts +7 -7
  5. package/dist/agents/subagent.js +74 -33
  6. package/dist/agents/teacher.js +3 -3
  7. package/dist/agents/team.d.ts +1 -1
  8. package/dist/agents/team.js +1 -1
  9. package/dist/agents/verify.js +1 -1
  10. package/dist/brain/anthropic.js +24 -35
  11. package/dist/brain/open-responses.d.ts +11 -0
  12. package/dist/brain/open-responses.js +721 -0
  13. package/dist/brain/openai.js +22 -33
  14. package/dist/brain/request-params.d.ts +1 -0
  15. package/dist/brain/request-params.js +16 -0
  16. package/dist/brain/stream-engine.d.ts +0 -2
  17. package/dist/brain/stream-engine.js +5 -47
  18. package/dist/brain/stream-shared.d.ts +0 -10
  19. package/dist/brain/stream-shared.js +0 -23
  20. package/dist/brain/terminal-cause.d.ts +0 -1
  21. package/dist/brain/terminal-cause.js +0 -3
  22. package/dist/brain/timeout.d.ts +4 -2
  23. package/dist/brain/timeout.js +4 -14
  24. package/dist/config/catalog.d.ts +3 -11
  25. package/dist/config/catalog.js +30 -69
  26. package/dist/config/defaults.d.ts +0 -3
  27. package/dist/config/defaults.js +0 -3
  28. package/dist/core/auto-compaction.d.ts +2 -11
  29. package/dist/core/auto-compaction.js +3 -67
  30. package/dist/core/checkpoint-store.d.ts +10 -8
  31. package/dist/core/checkpoint-store.js +7 -7
  32. package/dist/core/fs-write-gate-policy.js +2 -2
  33. package/dist/core/lsp-diagnostics.d.ts +3 -2
  34. package/dist/core/lsp-diagnostics.js +20 -7
  35. package/dist/core/memory-engine/file-backend.js +20 -17
  36. package/dist/core/memory-engine/layout.d.ts +5 -0
  37. package/dist/core/memory-engine/layout.js +72 -47
  38. package/dist/core/runner/assemble-result.d.ts +3 -8
  39. package/dist/core/runner/assemble-result.js +24 -18
  40. package/dist/core/runner/prepare-task.d.ts +27 -6
  41. package/dist/core/runner/prepare-task.js +209 -144
  42. package/dist/core/runner/runtask.d.ts +0 -2
  43. package/dist/core/runner/runtask.js +228 -266
  44. package/dist/core/runner/session-rule-policy.d.ts +1 -0
  45. package/dist/core/runner/session-rule-policy.js +4 -3
  46. package/dist/core/session-policy-store.d.ts +5 -0
  47. package/dist/core/session-policy-store.js +3 -1
  48. package/dist/core/store-contracts/checkpoint-store-contract.js +2 -2
  49. package/dist/core/task-registry-agent.d.ts +2 -0
  50. package/dist/core/task-registry-agent.js +33 -1
  51. package/dist/core/task-registry-shared.d.ts +0 -1
  52. package/dist/core/task-registry.d.ts +2 -0
  53. package/dist/core/task-registry.js +9 -1
  54. package/dist/core/tool-errors.js +10 -2
  55. package/dist/core/tool-policy.d.ts +8 -0
  56. package/dist/core/tool-policy.js +11 -0
  57. package/dist/core/trace.d.ts +1 -10
  58. package/dist/core/types.d.ts +27 -30
  59. package/dist/core/usage-window-store.d.ts +39 -0
  60. package/dist/core/usage-window-store.js +115 -0
  61. package/dist/engine/execution-env/node-execution-env.js +0 -22
  62. package/dist/engine/harness/agent-harness.d.ts +1 -7
  63. package/dist/engine/harness/agent-harness.js +16 -53
  64. package/dist/engine/harness/types.d.ts +3 -15
  65. package/dist/engine/llm/types.d.ts +3 -75
  66. package/dist/engine/loop/agent-loop.d.ts +1 -1
  67. package/dist/engine/loop/agent-loop.js +7 -173
  68. package/dist/engine/loop/types.d.ts +1 -18
  69. package/dist/engine/session/repo-utils.d.ts +1 -2
  70. package/dist/engine/session/repo-utils.js +0 -7
  71. package/dist/index.d.ts +13 -7
  72. package/dist/index.js +10 -5
  73. package/dist/internal/llm.d.ts +1 -1
  74. package/dist/orchestration/goal.js +1 -5
  75. package/dist/orchestration/run-workflow-tool.d.ts +1 -1
  76. package/dist/orchestration/run-workflow-tool.js +1 -2
  77. package/dist/orchestration/workflow-governance.d.ts +6 -6
  78. package/dist/orchestration/workflow-governance.js +33 -47
  79. package/dist/orchestration/workflow.js +14 -5
  80. package/dist/prompt-assembly/event-registry.js +2 -3
  81. package/dist/stores/cc/lockfile.js +9 -11
  82. package/dist/stores/cc/mailbox-store.js +49 -38
  83. package/dist/stores/file/index.d.ts +3 -0
  84. package/dist/stores/file/index.js +4 -0
  85. package/dist/stores/file/usage-window-store.d.ts +9 -0
  86. package/dist/stores/file/usage-window-store.js +86 -0
  87. package/dist/tools/fs/fs-bash.d.ts +1 -10
  88. package/dist/tools/fs/fs-bash.js +20 -60
  89. package/dist/tools/fs/index.d.ts +0 -2
  90. package/dist/tools/fs/index.js +1 -2
  91. package/dist/tools/web.js +20 -19
  92. package/package.json +4 -5
  93. package/dist/bin/sema-tb.d.ts +0 -31
  94. package/dist/bin/sema-tb.js +0 -448
  95. package/dist/bin/tb-env.d.ts +0 -2
  96. package/dist/bin/tb-env.js +0 -17
  97. package/dist/brain/walltime.d.ts +0 -1
  98. package/dist/brain/walltime.js +0 -1
  99. package/dist/core/runner/call-cap.d.ts +0 -67
  100. package/dist/core/runner/call-cap.js +0 -145
  101. package/dist/core/runner/cut-kill.d.ts +0 -10
  102. package/dist/core/runner/cut-kill.js +0 -37
@@ -1,9 +1,8 @@
1
1
  import {} from "../internal/llm.js";
2
2
  import { BrainError } from "./errors.js";
3
3
  import { DEGENERATE_MESSAGE, trimDegenerateTail } from "./repetition.js";
4
- import { createRepetitionPoll, createWalltimeGate, parseStreamedToolArgs } from "./stream-shared.js";
4
+ import { createRepetitionPoll, parseStreamedToolArgs } from "./stream-shared.js";
5
5
  import { mintFallbackToolCallId } from "./tool-call-id.js";
6
- import { WALLTIME_CUTOFF_MESSAGE } from "./walltime.js";
7
6
  import { emitBrainTelemetry } from "./status-sink.js";
8
7
  import { errorResultMediaNote, IMAGE_OMITTED_NO_VISION, modelSupportsVision, sendableImages } from "./media-degrade.js";
9
8
  import { ANTHROPIC_RESERVED, applyExtraBody, stripAuthHeaders } from "./request-params.js";
@@ -233,7 +232,6 @@ export function createAnthropicBrain(config = {}) {
233
232
  signal: options?.signal,
234
233
  config,
235
234
  httpLabel: "anthropic",
236
- callDeadlineMs: options?.callDeadlineMs,
237
235
  stallTimeouts: options?.stallTimeouts,
238
236
  buildRequest: () => {
239
237
  const apiKey = options?.apiKey ?? config.apiKey;
@@ -342,7 +340,6 @@ export function createAnthropicBrain(config = {}) {
342
340
  let degenerate = false;
343
341
  let degenTextBlock;
344
342
  const rep = createRepetitionPoll();
345
- const walltime = createWalltimeGate({ callDeadlineMs: options?.callDeadlineMs, isDegenerate: () => degenerate, cancel: () => ctrl.cancel() });
346
343
  let lastDegenCheck = 0;
347
344
  let lastDegenCheckThinking = 0;
348
345
  const detectRep = config.detectRepetition !== false;
@@ -497,10 +494,7 @@ export function createAnthropicBrain(config = {}) {
497
494
  }
498
495
  }
499
496
  },
500
- onDeadline: () => walltime.onDeadline(),
501
497
  onLine(rawLine) {
502
- if (walltime.shouldDropLine())
503
- return;
504
498
  const line = rawLine.trim();
505
499
  if (!line.startsWith("data:"))
506
500
  return;
@@ -576,40 +570,35 @@ export function createAnthropicBrain(config = {}) {
576
570
  const staticReasoningCut = truncatedEmpty && !dynamicCut && reasoningSeen && options?.staticReasoningCutDowngrade === true;
577
571
  const safetyCut = stopReason === "refusal";
578
572
  const contextWindowExceeded = stopReason === "model_context_window_exceeded";
579
- const emptyNoFinish = noUsableContent && stopReason == null && !degenerate && !walltime.cut;
573
+ const emptyNoFinish = noUsableContent && stopReason == null && !degenerate;
580
574
  const maxTokensNote = `effective max_tokens=${sentMaxTokens ?? "?"} (from ${sentMaxTokensLane === "options" ? "options.maxTokens" : sentMaxTokensLane === "model" ? "model.maxTokens" : "config default"})`;
581
- const errorMessage = walltime.cut
582
- ? WALLTIME_CUTOFF_MESSAGE
583
- : degenerate
584
- ? DEGENERATE_MESSAGE
585
- : safetyCut
586
- ? `[refusal] response refused by the model (stop_reason="refusal"${stopDetails?.category ? `, category="${stopDetails.category}"` : ""}) — ${stopDetails?.explanation ?? "the output was withheld for policy and is unreliable"}`
587
- : contextWindowExceeded
588
- ? `[invalid_request] model context window exceeded (stop_reason="model_context_window_exceeded") the conversation no longer fits the model's context window`
589
- : (toolError ??
590
- (truncatedEmpty && !dynamicCut && !staticReasoningCut
591
- ? thinkingRequested
592
- ? `[length_empty] response truncated at max_tokens with no answer text (${maxTokensNote}) — extended thinking likely consumed the entire budget; raise max_tokens or lower thinkingBudgetShare`
593
- : reasoningSeen
594
- ? `[length_empty] response truncated at max_tokens with no answer text (${maxTokensNote}) — the model emitted reasoning although no thinking was requested (a budget-ignoring gateway?) and it consumed the entire output budget; raise max_tokens`
595
- : `[length_empty] response truncated at max_tokens with no answer text (${maxTokensNote}); raise max_tokens`
596
- : emptyNoFinish
597
- ? `[stream_torn] model stream ended with no content and no stop_reason — the response was lost (a torn stream or an in-band provider error frame)${malformedFrames > 0 ? ` — ${malformedFrames} unparseable data frame(s) were dropped on this stream (first sample: ${JSON.stringify(malformedSample)})` : ""}`
598
- : undefined));
599
- const errored = walltime.cut ||
600
- degenerate ||
575
+ const errorMessage = degenerate
576
+ ? DEGENERATE_MESSAGE
577
+ : safetyCut
578
+ ? `[refusal] response refused by the model (stop_reason="refusal"${stopDetails?.category ? `, category="${stopDetails.category}"` : ""}) — ${stopDetails?.explanation ?? "the output was withheld for policy and is unreliable"}`
579
+ : contextWindowExceeded
580
+ ? `[invalid_request] model context window exceeded (stop_reason="model_context_window_exceeded") — the conversation no longer fits the model's context window`
581
+ : (toolError ??
582
+ (truncatedEmpty && !dynamicCut && !staticReasoningCut
583
+ ? thinkingRequested
584
+ ? `[length_empty] response truncated at max_tokens with no answer text (${maxTokensNote}) extended thinking likely consumed the entire budget; raise max_tokens or lower thinkingBudgetShare`
585
+ : reasoningSeen
586
+ ? `[length_empty] response truncated at max_tokens with no answer text (${maxTokensNote}) — the model emitted reasoning although no thinking was requested (a budget-ignoring gateway?) and it consumed the entire output budget; raise max_tokens`
587
+ : `[length_empty] response truncated at max_tokens with no answer text (${maxTokensNote}); raise max_tokens`
588
+ : emptyNoFinish
589
+ ? `[stream_torn] model stream ended with no content and no stop_reason — the response was lost (a torn stream or an in-band provider error frame)${malformedFrames > 0 ? ` — ${malformedFrames} unparseable data frame(s) were dropped on this stream (first sample: ${JSON.stringify(malformedSample)})` : ""}`
590
+ : undefined));
591
+ const errored = degenerate ||
601
592
  safetyCut ||
602
593
  contextWindowExceeded ||
603
594
  emptyNoFinish ||
604
595
  (toolError !== undefined && noUsableContent) ||
605
596
  (truncatedEmpty && !dynamicCut && !staticReasoningCut);
606
- const errorKind = walltime.cut
607
- ? "walltime_cutoff"
608
- : degenerate
609
- ? "degenerate"
610
- : !safetyCut && toolError === undefined && truncatedEmpty && !dynamicCut && !staticReasoningCut
611
- ? "length_empty"
612
- : undefined;
597
+ const errorKind = degenerate
598
+ ? "degenerate"
599
+ : !safetyCut && toolError === undefined && truncatedEmpty && !dynamicCut && !staticReasoningCut
600
+ ? "length_empty"
601
+ : undefined;
613
602
  const finalMessage = {
614
603
  ...partial,
615
604
  content: finalContent.length > 0 ? finalContent : [{ type: "text", text: "" }],
@@ -0,0 +1,11 @@
1
+ import type { Brain } from "../core/types.js";
2
+ import { type StreamEngineConfig } from "./stream-engine.js";
3
+ export interface OpenResponsesBrainConfig extends StreamEngineConfig {
4
+ baseUrl?: string;
5
+ apiKey?: string;
6
+ headers?: Record<string, string>;
7
+ fetchImpl?: typeof fetch;
8
+ replayReasoning?: boolean;
9
+ detectRepetition?: boolean;
10
+ }
11
+ export declare function createOpenResponsesBrain(config?: OpenResponsesBrainConfig): Brain;