@theoremjs/agents 0.3.4-next.693.g4ab1526 → 0.3.4-next.715.geef22fd

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 (54) hide show
  1. package/README.md +1 -1
  2. package/esm/mod.d.ts +3 -2
  3. package/esm/mod.js +1 -1
  4. package/esm/src/guardrails/labels.d.ts +1 -1
  5. package/esm/src/guardrails/labels.js +6 -0
  6. package/esm/src/interface/history.d.ts +2 -2
  7. package/esm/src/interface/history.js +7 -4
  8. package/esm/src/interface/mod.d.ts +1 -1
  9. package/esm/src/interface/mod.js +1 -1
  10. package/esm/src/interface/tool-calls.d.ts +3 -3
  11. package/esm/src/interface/tool-calls.js +5 -8
  12. package/esm/src/interface/tool-invoke.d.ts +11 -1
  13. package/esm/src/interface/tool-invoke.js +13 -1
  14. package/esm/src/interface/types.d.ts +1 -1
  15. package/esm/src/kernel/api-catalog.js +12 -0
  16. package/esm/src/kernel/engine/background.d.ts +7 -0
  17. package/esm/src/kernel/engine/background.js +18 -0
  18. package/esm/src/kernel/engine/runner/gates.js +4 -3
  19. package/esm/src/kernel/engine/runner/mod.js +24 -1
  20. package/esm/src/kernel/engine/runner/state.d.ts +4 -0
  21. package/esm/src/kernel/engine/runner/state.js +1 -0
  22. package/esm/src/kernel/engine/runner/step-order.d.ts +8 -0
  23. package/esm/src/kernel/engine/runner/step-order.js +1 -1
  24. package/esm/src/kernel/engine/runner/steps.js +5 -0
  25. package/esm/src/kernel/engine/session/mod.d.ts +2 -0
  26. package/esm/src/kernel/engine/session/mod.js +19 -2
  27. package/esm/src/kernel/mod.d.ts +3 -2
  28. package/esm/src/kernel/mod.js +1 -1
  29. package/esm/src/kernel/schema.js +12 -0
  30. package/esm/src/kernel/tools/background.d.ts +81 -0
  31. package/esm/src/kernel/tools/background.js +70 -0
  32. package/esm/src/kernel/tools/call-order.d.ts +3 -1
  33. package/esm/src/kernel/tools/call-order.js +10 -6
  34. package/esm/src/kernel/tools/coordinate.d.ts +8 -1
  35. package/esm/src/kernel/tools/coordinate.js +274 -34
  36. package/esm/src/kernel/tools/execute.d.ts +2 -0
  37. package/esm/src/kernel/tools/execute.js +17 -4
  38. package/esm/src/kernel/tools/invoke.js +40 -13
  39. package/esm/src/kernel/tools/memory-execution.js +10 -1
  40. package/esm/src/kernel/tools/operation.d.ts +21 -0
  41. package/esm/src/kernel/tools/operation.js +19 -10
  42. package/esm/src/kernel/tools/registry.js +20 -1
  43. package/esm/src/kernel/tools/resolve.d.ts +4 -2
  44. package/esm/src/kernel/tools/resolve.js +23 -7
  45. package/esm/src/kernel/tools/run.d.ts +2 -2
  46. package/esm/src/kernel/tools/run.js +4 -1
  47. package/esm/src/kernel/tools/stage-run.d.ts +2 -0
  48. package/esm/src/kernel/tools/stage-run.js +1 -0
  49. package/esm/src/kernel/tools/types.d.ts +7 -0
  50. package/esm/src/kernel/turn-events.d.ts +10 -1
  51. package/esm/src/kernel/turn-events.js +3 -0
  52. package/esm/src/kernel/types.d.ts +13 -0
  53. package/esm/src/providers/open-ai/protocol.js +8 -4
  54. package/package.json +1 -1
@@ -2,6 +2,7 @@ import type { ProviderCheckpoint, ProviderContinuationPolicy } from './checkpoin
2
2
  import type { JsonObject } from './json.js';
3
3
  import type { CacheMode, CacheTtl, CompactionMeter, CompactionOutcome, CompactionTiming, ContextSender, ContinueStopKind, FieldMeta, KeySlot, KeyVault, LiveActivityHandling, LiveEndSensitivity, LiveStartSensitivity, MediaInputKind, ProfileType, SpeechAudioFormat, StreamMode, SummaryMode, ThinkingLevel, ToolLoadTier, TurnStage, TurnStopKind } from './schema.js';
4
4
  import type { StageHandler } from './stages.js';
5
+ import type { ToolBackgroundService } from './tools/background.js';
5
6
  import type { GateDecision } from './tools/gate-answer.js';
6
7
  import type { PageToolExecution, ToolExecutionCoordinator } from './tools/operation.js';
7
8
  import type { AgentCall, AgentCallHook, AgentCallRequest, AgentToolDef, AgentToolInput, AgentToolOutput, HostProfileToolsSpec, InvokeToolRequest, InvokeToolResume, InvokeToolStepCall, InvokeToolStepRequest, LiveProfileToolsSpec, ModelToolResult, PageAnswer, ProfileToolsSpec, RegisteredTool, ToolCallEvent, ToolFailure, ToolGate, ToolLoadContext, ToolPolicy, TurnToolSnapshot, WireFunctionTool } from './tools/types.js';
@@ -759,6 +760,7 @@ export interface TurnTraceLink {
759
760
  /** A request to `runTurn`: the profile, the input, and the host's hooks and keys. */
760
761
  export interface TurnRequest {
761
762
  execution?: ToolExecutionCoordinator;
763
+ background?: ToolBackgroundService;
762
764
  pageExecution?: PageToolExecution;
763
765
  providerState?: ProviderCheckpoint;
764
766
  profile: ProfileId;
@@ -820,6 +822,17 @@ export interface TurnRequest {
820
822
  * Compared to `profile.turnBehaviour.resumption.maxContinues` when that cap is set.
821
823
  */
822
824
  continuation?: number;
825
+ /**
826
+ * Tools this reply already had when an earlier run of it paused. The turn opens with them on its
827
+ * list, so an answered call does not take back what the model loaded. An id `tools.allow` or the
828
+ * path does not grant is left out, as for `tools.t1Policy`.
829
+ */
830
+ promoted?: ToolId[];
831
+ /**
832
+ * Steps this reply already took when an earlier run of it paused. They count against `maxSteps`,
833
+ * so an answered call does not give the reply its steps back. Read `done.steps`.
834
+ */
835
+ stepsTaken?: number;
823
836
  input?: TurnInput;
824
837
  /** Credentials for authenticated HTTP / MCP tools, read by auth slot when a tool needs one. */
825
838
  credentials?: ToolCredentialSource;
@@ -36,13 +36,17 @@ function requestBody(context, request) {
36
36
  };
37
37
  return JSON.parse(JSON.stringify(body));
38
38
  }
39
- /** An error row inside a 200 reply: thrown, so a quota refusal before any output can still fall back. */
40
- function errorRow(row) {
39
+ /**
40
+ * An error row inside a 200 reply: thrown, so a quota refusal before any output can still fall back.
41
+ * why: a reply the provider already began was accepted, so a 4xx in it is the stream breaking, not a refusal.
42
+ */
43
+ function errorRow(row, reply) {
41
44
  const error = asRecord(row.error);
42
45
  if (!error)
43
46
  return;
44
47
  const status = typeof error.code === 'number' ? error.code : 502;
45
- throw new TheoremError(kindOfHttpStatus(status), statedError(row) ?? JSON.stringify(error));
48
+ const kind = kindOfHttpStatus(status);
49
+ throw new TheoremError(reply.response && kind === 'unsupported' ? 'unavailable' : kind, statedError(row) ?? JSON.stringify(error));
46
50
  }
47
51
  function citations(part, reply) {
48
52
  const sources = (Array.isArray(part.annotations) ? part.annotations : []).flatMap((item) => {
@@ -87,7 +91,7 @@ function partEvents(part, reply, request) {
87
91
  return events;
88
92
  }
89
93
  function rowEvents(row, reply, request, stream) {
90
- errorRow(row);
94
+ errorRow(row, reply);
91
95
  const events = [];
92
96
  const identity = foldResponse(reply.response, openAiResponse(row));
93
97
  reply.response = identity.known;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/agents",
3
- "version": "0.3.4-next.693.g4ab1526",
3
+ "version": "0.3.4-next.715.geef22fd",
4
4
  "description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, registered tools, provider adapters, guardrails, and host-injected traces.",
5
5
  "keywords": [
6
6
  "agent",