@ziggs-ai/agent-sdk 0.1.11 → 0.2.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 (211) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +41 -2
  3. package/dist/AgentHost.d.ts +201 -0
  4. package/dist/AgentHost.js +652 -0
  5. package/dist/adapters/AnthropicAdapter.d.ts +39 -0
  6. package/dist/adapters/AnthropicAdapter.js +200 -0
  7. package/dist/adapters/McpAdapter.d.ts +199 -0
  8. package/dist/adapters/McpAdapter.js +468 -0
  9. package/dist/adapters/OpenAIAdapter.d.ts +26 -0
  10. package/dist/adapters/OpenAIAdapter.js +158 -0
  11. package/dist/adapters/index.js +2 -0
  12. package/dist/agent/Agent.d.ts +78 -0
  13. package/dist/agent/Agent.js +58 -0
  14. package/dist/agent/ClaudeSdkAgent.d.ts +38 -0
  15. package/dist/agent/ClaudeSdkAgent.js +322 -0
  16. package/dist/agent/claudeCognition.d.ts +67 -0
  17. package/dist/agent/claudeCognition.js +103 -0
  18. package/dist/agent/claudeSdkProtocol.d.ts +11 -0
  19. package/dist/agent/claudeSdkProtocol.js +27 -0
  20. package/dist/agent/claudeSdkTools.d.ts +19 -0
  21. package/dist/agent/claudeSdkTools.js +57 -0
  22. package/dist/agent/hostedAgentConnection.d.ts +15 -0
  23. package/dist/agent/hostedAgentConnection.js +29 -0
  24. package/dist/agent/toolManagerToSdkMcp.d.ts +12 -0
  25. package/dist/agent/toolManagerToSdkMcp.js +123 -0
  26. package/dist/brain/index.d.ts +50 -0
  27. package/dist/brain/index.js +45 -0
  28. package/dist/cognition/validateContext.d.ts +11 -0
  29. package/dist/cognition/validateContext.js +117 -0
  30. package/dist/context/applyEffects.d.ts +2 -0
  31. package/dist/context/applyEffects.js +89 -0
  32. package/dist/context/batch.d.ts +2 -0
  33. package/dist/context/batch.js +18 -0
  34. package/dist/context/classifyEnvelope.d.ts +1 -0
  35. package/dist/context/classifyEnvelope.js +58 -0
  36. package/dist/context/routingLabels.d.ts +4 -0
  37. package/dist/context/routingLabels.js +48 -0
  38. package/dist/defineAgent.d.ts +14 -0
  39. package/dist/defineAgent.js +68 -0
  40. package/dist/formatters/AgreementFormatter.d.ts +18 -0
  41. package/dist/formatters/AgreementFormatter.js +130 -0
  42. package/dist/formatters/HistoryFormatter.d.ts +26 -0
  43. package/dist/formatters/HistoryFormatter.js +173 -0
  44. package/dist/formatters/index.js +2 -0
  45. package/{src/index.ts → dist/index.d.ts} +13 -53
  46. package/dist/index.js +66 -0
  47. package/dist/ingress/normalizeIncoming.d.ts +65 -0
  48. package/dist/ingress/normalizeIncoming.js +88 -0
  49. package/dist/memory/MemoryStore.d.ts +55 -0
  50. package/dist/memory/MemoryStore.js +78 -0
  51. package/dist/pricing/fleetDefaults.d.ts +46 -0
  52. package/dist/pricing/fleetDefaults.js +168 -0
  53. package/dist/pricing/fleetEvalFree.d.ts +7 -0
  54. package/dist/pricing/fleetEvalFree.js +24 -0
  55. package/dist/pricing/fleetFreeTierA.gen.d.ts +6 -0
  56. package/{src/pricing/fleetFreeTierA.gen.ts → dist/pricing/fleetFreeTierA.gen.js} +5 -6
  57. package/dist/pricing/fleetTierByAgentId.gen.d.ts +7 -0
  58. package/dist/pricing/fleetTierByAgentId.gen.js +768 -0
  59. package/dist/runtime/AgentMachine.d.ts +143 -0
  60. package/dist/runtime/AgentMachine.js +400 -0
  61. package/dist/runtime/PromptBuilder.d.ts +96 -0
  62. package/dist/runtime/PromptBuilder.js +439 -0
  63. package/dist/runtime/bootstrapCtx.d.ts +18 -0
  64. package/dist/runtime/bootstrapCtx.js +37 -0
  65. package/dist/runtime/buildOutcome.d.ts +68 -0
  66. package/dist/runtime/buildOutcome.js +464 -0
  67. package/dist/runtime/defaults.d.ts +54 -0
  68. package/dist/runtime/defaults.js +47 -0
  69. package/dist/runtime/deriveRespondsToProposals.d.ts +9 -0
  70. package/dist/runtime/deriveRespondsToProposals.js +38 -0
  71. package/dist/runtime/kickoff.d.ts +15 -0
  72. package/dist/runtime/kickoff.js +112 -0
  73. package/dist/runtime/runMechanical.d.ts +25 -0
  74. package/dist/runtime/runMechanical.js +74 -0
  75. package/dist/runtime/runTurn.d.ts +63 -0
  76. package/dist/runtime/runTurn.js +800 -0
  77. package/dist/runtime/validateWorkflow.d.ts +17 -0
  78. package/dist/runtime/validateWorkflow.js +209 -0
  79. package/dist/server/ConnectionPool.d.ts +68 -0
  80. package/dist/server/ConnectionPool.js +166 -0
  81. package/dist/server/EventQueue.d.ts +33 -0
  82. package/dist/server/EventQueue.js +98 -0
  83. package/dist/server/InboxCatchUp.d.ts +24 -0
  84. package/dist/server/InboxCatchUp.js +213 -0
  85. package/dist/server/OutboxBuffer.d.ts +33 -0
  86. package/dist/server/OutboxBuffer.js +68 -0
  87. package/dist/server/SeenMessages.d.ts +13 -0
  88. package/dist/server/SeenMessages.js +31 -0
  89. package/dist/server/StateTimers.d.ts +34 -0
  90. package/dist/server/StateTimers.js +70 -0
  91. package/dist/server/ZiggsEffectHandler.d.ts +79 -0
  92. package/dist/server/ZiggsEffectHandler.js +319 -0
  93. package/dist/server/agreements/AgreementService.d.ts +50 -0
  94. package/dist/server/agreements/AgreementService.js +85 -0
  95. package/dist/server/createHealthServer.d.ts +7 -0
  96. package/dist/server/createHealthServer.js +75 -0
  97. package/dist/server/proactive/ProactiveTrigger.d.ts +33 -0
  98. package/dist/server/proactive/ProactiveTrigger.js +71 -0
  99. package/dist/server/runLauncher.d.ts +28 -0
  100. package/dist/server/runLauncher.js +93 -0
  101. package/dist/server/tasks/TaskService.d.ts +25 -0
  102. package/dist/server/tasks/TaskService.js +103 -0
  103. package/dist/server/tasks/index.js +1 -0
  104. package/dist/server/telemetryIngest.d.ts +24 -0
  105. package/dist/server/telemetryIngest.js +62 -0
  106. package/dist/server/tools/index.d.ts +24 -0
  107. package/{src/server/tools/index.ts → dist/server/tools/index.js} +4 -24
  108. package/dist/server/tools/tier1/protocolRunner.d.ts +39 -0
  109. package/dist/server/tools/tier1/protocolRunner.js +288 -0
  110. package/dist/server/tools/tier1/protocolTools.d.ts +12 -0
  111. package/dist/server/tools/tier1/protocolTools.js +37 -0
  112. package/dist/server/tools/tier2/connectionTools.d.ts +4 -0
  113. package/dist/server/tools/tier2/connectionTools.js +63 -0
  114. package/dist/server/tools/tier2/contextTools.d.ts +4 -0
  115. package/dist/server/tools/tier2/contextTools.js +46 -0
  116. package/dist/server/tools/tier2/discoveryTools.d.ts +4 -0
  117. package/dist/server/tools/tier2/discoveryTools.js +25 -0
  118. package/dist/server/tools/tier2/marketplaceTools.d.ts +3 -0
  119. package/dist/server/tools/tier2/marketplaceTools.js +22 -0
  120. package/dist/server/tools/tier2/paymentTools.d.ts +12 -0
  121. package/dist/server/tools/tier2/paymentTools.js +165 -0
  122. package/dist/server/ziggsconnect/ZiggsConnectClient.d.ts +35 -0
  123. package/dist/server/ziggsconnect/ZiggsConnectClient.js +95 -0
  124. package/dist/server/ziggscontext/ZiggsContextClient.d.ts +48 -0
  125. package/dist/server/ziggscontext/ZiggsContextClient.js +90 -0
  126. package/dist/server/ziggspay/ZiggsPayClient.d.ts +82 -0
  127. package/dist/server/ziggspay/ZiggsPayClient.js +188 -0
  128. package/dist/shared/ids.d.ts +1 -0
  129. package/dist/shared/ids.js +3 -0
  130. package/dist/shared/runtimeLog.d.ts +18 -0
  131. package/dist/shared/runtimeLog.js +68 -0
  132. package/dist/shared/types.d.ts +22 -0
  133. package/dist/shared/types.js +23 -0
  134. package/dist/tasks/protocolRegistry.d.ts +16 -0
  135. package/dist/tasks/protocolRegistry.js +20 -0
  136. package/dist/tools/ToolManager.d.ts +12 -0
  137. package/dist/tools/ToolManager.js +74 -0
  138. package/dist/tools/ToolProvider.d.ts +6 -0
  139. package/dist/tools/ToolProvider.js +21 -0
  140. package/dist/tools/defineTool.d.ts +27 -0
  141. package/dist/tools/defineTool.js +62 -0
  142. package/{src/tools/index.ts → dist/tools/index.d.ts} +0 -1
  143. package/dist/tools/index.js +6 -0
  144. package/dist/tools/recordReport.d.ts +41 -0
  145. package/dist/tools/recordReport.js +30 -0
  146. package/dist/types.d.ts +466 -0
  147. package/dist/types.js +7 -0
  148. package/dist/utils/jsonExtractor.d.ts +2 -0
  149. package/dist/utils/jsonExtractor.js +111 -0
  150. package/package.json +17 -7
  151. package/src/AgentHost.ts +0 -545
  152. package/src/adapters/AnthropicAdapter.ts +0 -206
  153. package/src/adapters/McpAdapter.ts +0 -348
  154. package/src/adapters/OpenAIAdapter.ts +0 -187
  155. package/src/agent/Agent.ts +0 -104
  156. package/src/cognition/validateContext.ts +0 -95
  157. package/src/context/applyEffects.ts +0 -80
  158. package/src/context/batch.ts +0 -19
  159. package/src/context/classifyEnvelope.ts +0 -38
  160. package/src/context/routingLabels.ts +0 -46
  161. package/src/defineAgent.ts +0 -70
  162. package/src/formatters/AgreementFormatter.ts +0 -111
  163. package/src/formatters/HistoryFormatter.ts +0 -172
  164. package/src/ingress/normalizeIncoming.ts +0 -162
  165. package/src/memory/MemoryStore.ts +0 -104
  166. package/src/pricing/fleetDefaults.ts +0 -225
  167. package/src/pricing/fleetEvalFree.ts +0 -24
  168. package/src/pricing/fleetTierByAgentId.gen.ts +0 -775
  169. package/src/runtime/AgentMachine.ts +0 -402
  170. package/src/runtime/PromptBuilder.ts +0 -485
  171. package/src/runtime/buildOutcome.ts +0 -563
  172. package/src/runtime/defaults.ts +0 -75
  173. package/src/runtime/kickoff.ts +0 -117
  174. package/src/runtime/runTurn.ts +0 -813
  175. package/src/runtime/validateWorkflow.ts +0 -202
  176. package/src/server/ConnectionPool.ts +0 -206
  177. package/src/server/EventQueue.ts +0 -133
  178. package/src/server/InboxCatchUp.ts +0 -254
  179. package/src/server/OutboxBuffer.ts +0 -90
  180. package/src/server/SeenMessages.ts +0 -27
  181. package/src/server/StateTimers.ts +0 -85
  182. package/src/server/ZiggsEffectHandler.ts +0 -418
  183. package/src/server/agreements/AgreementService.ts +0 -118
  184. package/src/server/createHealthServer.ts +0 -85
  185. package/src/server/proactive/ProactiveTrigger.ts +0 -83
  186. package/src/server/runLauncher.ts +0 -146
  187. package/src/server/tasks/TaskService.ts +0 -110
  188. package/src/server/telemetryIngest.ts +0 -91
  189. package/src/server/tools/tier1/protocolRunner.ts +0 -144
  190. package/src/server/tools/tier1/protocolTools.ts +0 -99
  191. package/src/server/tools/tier2/connectionTools.ts +0 -75
  192. package/src/server/tools/tier2/contextTools.ts +0 -63
  193. package/src/server/tools/tier2/discoveryTools.ts +0 -34
  194. package/src/server/tools/tier2/marketplaceTools.ts +0 -27
  195. package/src/server/tools/tier2/paymentTools.ts +0 -170
  196. package/src/server/ziggsconnect/ZiggsConnectClient.ts +0 -126
  197. package/src/server/ziggscontext/ZiggsContextClient.ts +0 -129
  198. package/src/server/ziggspay/ZiggsPayClient.ts +0 -193
  199. package/src/shared/ids.ts +0 -3
  200. package/src/shared/runtimeLog.ts +0 -72
  201. package/src/shared/types.ts +0 -29
  202. package/src/tasks/protocolRegistry.ts +0 -25
  203. package/src/tools/ToolManager.ts +0 -95
  204. package/src/tools/ToolProvider.ts +0 -19
  205. package/src/tools/defineTool.ts +0 -90
  206. package/src/tools/recordReport.ts +0 -82
  207. package/src/types.ts +0 -456
  208. package/src/utils/jsonExtractor.ts +0 -100
  209. /package/{src/adapters/index.ts → dist/adapters/index.d.ts} +0 -0
  210. /package/{src/formatters/index.ts → dist/formatters/index.d.ts} +0 -0
  211. /package/{src/server/tasks/index.ts → dist/server/tasks/index.d.ts} +0 -0
@@ -0,0 +1,112 @@
1
+ import { thinkingDefaults } from './defaults.js';
2
+ import { PROBE_CTX } from './validateWorkflow.js';
3
+ /** Reserved state name for the injected agreement-kickoff default. */
4
+ export const KICKOFF_STATE = 'kickingOff';
5
+ // Synthetic outcome used to ask "does this state already handle a proposer-side
6
+ // approval?" — the same probe pattern validateWorkflow uses for the wait/error
7
+ // fallthrough checks.
8
+ const PROBE_APPROVE = {
9
+ kind: 'proposal-resolved',
10
+ action: 'approve',
11
+ proposal: { agreementId: '__kickoff_probe__' },
12
+ proposedByMe: true,
13
+ };
14
+ const KICKOFF_TRANSITION = {
15
+ to: KICKOFF_STATE,
16
+ when: (o, ctx) => o.kind === 'proposal-resolved' &&
17
+ o.action === 'approve' &&
18
+ o.proposedByMe === true &&
19
+ // "first task" guard — both branches cover one exact scenario: a task under
20
+ // THIS agreement already exists because a racing task_result frame was
21
+ // applied to ctx before this approval frame.
22
+ // (1) we already delegated under it:
23
+ !ctx.delegatedAgreementIds.includes(o.proposal.agreementId) &&
24
+ // (2) we already hold an assigned task bound to it (task-assigned sets
25
+ // activeTaskId + activeAgreementId together in applyOutcomeToCtx):
26
+ !(ctx.activeTaskId !== null && ctx.activeAgreementId === o.proposal.agreementId),
27
+ };
28
+ // A state "handles" proposer-approval if some transition would fire for it.
29
+ // An unconditional (when-less) transition counts: it catches every outcome,
30
+ // so the kickoff transition — appended LAST — would be unreachable dead code
31
+ // there anyway. Consequence to know: a state whose only route for a
32
+ // proposal-resolved/approve is an unconditional fallthrough to an UNRELATED
33
+ // state will NOT auto-kickoff (the approval follows the fallthrough instead).
34
+ // Authors who want guaranteed kickoff in such a state must add an explicit
35
+ // `when: o => o.kind === 'proposal-resolved' && o.action === 'approve'`
36
+ // transition (which this probe then respects) — or route approval into a
37
+ // thinking state that spawns the task itself.
38
+ function stateHandlesProposerApproval(state) {
39
+ return state.transitions.some(t => {
40
+ if (!t.when)
41
+ return true;
42
+ try {
43
+ return !!t.when(PROBE_APPROVE, PROBE_CTX);
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ });
49
+ }
50
+ export function buildKickoffState(initial) {
51
+ const dflt = thinkingDefaults({ initial });
52
+ return {
53
+ kind: 'thinking',
54
+ prompt: {
55
+ role: 'The counterparty just approved an agreement you proposed. The platform never auto-starts work — as the proposer, you spawn the first task now.',
56
+ goal: 'Spawn exactly one task under the just-approved agreement so work begins.',
57
+ constraints: 'The approved agreement id is in <event> and as activeAgreementId in <machine_context>; the agreement row is in <agreements>. Call task_spawn with that agreementId and a description of the concrete work the agreement covers. Include ALL specifics the counterparty provided in <history> (addresses, quantities, times, item names, deliverables) — the executor has no other way to get them. Plain natural language, no step numbering. Do not re-negotiate — the agreement is active. Do not send a chat message instead of spawning. If <agreements> or <history> show a task already running under this agreement, choose wait.',
58
+ },
59
+ actions: {
60
+ ...dflt.actions,
61
+ spawnFirstTask: {
62
+ prompt: {
63
+ when: 'Always — this state exists only to spawn the first task under the agreement whose proposal was just approved. Pick wait only if a task already exists under it.',
64
+ instruction: 'Spawn the first task under the approved agreement so work starts.',
65
+ format: '{"agreementId": "<the agreement whose proposal was just approved>", "description": "<concrete work + all counterparty specifics from history>"}',
66
+ },
67
+ tool: 'task_spawn',
68
+ // Function form so a failed task_spawn surfaces as an error outcome
69
+ // (→ dflt error transition + machine warn log) instead of a fake
70
+ // task-delegated with an empty task.
71
+ produces: (result) => {
72
+ const r = result;
73
+ return r?.taskId || r?.task?.taskId ? 'task-delegated' : 'error';
74
+ },
75
+ terminatesLoop: true,
76
+ },
77
+ },
78
+ transitions: [
79
+ { to: initial, when: o => o.kind === 'task-delegated' },
80
+ ...dflt.transitions, // wait / message-sent / error → initial
81
+ ],
82
+ };
83
+ }
84
+ /**
85
+ * Agreement-kickoff default. For every state whose transitions do not already
86
+ * match a proposer-side approval (probe above), append a transition to the
87
+ * injected `kickingOff` state. Appended LAST so any user transition on the same
88
+ * outcome always wins (first match wins in AgentMachine._evaluateTransitions).
89
+ * Returns a NEW workflow — input states are not mutated. After kickoff the
90
+ * machine returns to `initial`; when this agent is itself the provider the
91
+ * backend then assigns the spawned task back to it as a normal task-assigned
92
+ * event, which the author's existing work loop handles.
93
+ */
94
+ export function injectKickoffDefault(workflow) {
95
+ if (workflow.states[KICKOFF_STATE]) {
96
+ throw new Error(`[defineAgent] state name "${KICKOFF_STATE}" is reserved for the injected agreement-kickoff default — rename the state`);
97
+ }
98
+ const states = {};
99
+ let injected = false;
100
+ for (const [name, state] of Object.entries(workflow.states)) {
101
+ if (stateHandlesProposerApproval(state)) {
102
+ states[name] = state;
103
+ continue;
104
+ }
105
+ states[name] = { ...state, transitions: [...state.transitions, KICKOFF_TRANSITION] };
106
+ injected = true;
107
+ }
108
+ if (!injected)
109
+ return workflow; // every state handles approval — nothing to add, no dead state
110
+ states[KICKOFF_STATE] = buildKickoffState(workflow.initial);
111
+ return { ...workflow, states };
112
+ }
@@ -0,0 +1,25 @@
1
+ import type { Ctx, EffectHandler, MechanicalState, Outcome, ToolResultEntry } from '../types.js';
2
+ import type { MemoryStore } from '../memory/MemoryStore.js';
3
+ import { type RawEvent } from './buildOutcome.js';
4
+ export interface RunMechanicalResult {
5
+ outcome: Outcome;
6
+ toolResults: ToolResultEntry[];
7
+ llmCalls: number;
8
+ tokens: {
9
+ total: number;
10
+ input: number;
11
+ output: number;
12
+ };
13
+ }
14
+ /**
15
+ * ZIG-764: run a mechanical state — invoke one bound tool with no LLM turn.
16
+ * Used by dumb coordinators whose only job is a fixed tool call on task-assigned.
17
+ */
18
+ export declare function runMechanical(input: {
19
+ stateId: string;
20
+ state: MechanicalState;
21
+ ctx: Ctx;
22
+ eff: EffectHandler;
23
+ memory?: MemoryStore;
24
+ incomingEvent: RawEvent | null;
25
+ }): Promise<RunMechanicalResult>;
@@ -0,0 +1,74 @@
1
+ import { outcomeFromActionResult } from './buildOutcome.js';
2
+ import { runtimeLog } from '../shared/runtimeLog.js';
3
+ /**
4
+ * ZIG-764: run a mechanical state — invoke one bound tool with no LLM turn.
5
+ * Used by dumb coordinators whose only job is a fixed tool call on task-assigned.
6
+ */
7
+ export async function runMechanical(input) {
8
+ const { stateId, state, ctx, eff, memory, incomingEvent } = input;
9
+ const sessionId = ctx.identity.sessionId;
10
+ const runId = crypto.randomUUID();
11
+ const effWithTrace = (effect) => {
12
+ if (effect.kind === 'tool-call') {
13
+ return eff({ ...effect, runId, stateId });
14
+ }
15
+ return eff(effect);
16
+ };
17
+ runtimeLog.info('runMechanical', `enter state=${stateId} tool=${state.tool}`);
18
+ const args = typeof state.buildArgs === 'function'
19
+ ? state.buildArgs(ctx, ctx.lastOutcome)
20
+ : { ...(state.args ?? {}) };
21
+ const pseudoAction = {
22
+ prompt: { instruction: '' },
23
+ tool: state.tool,
24
+ produces: state.produces,
25
+ };
26
+ let emitted = [];
27
+ try {
28
+ const r = await effWithTrace({
29
+ kind: 'tool-call',
30
+ sessionId,
31
+ name: state.tool,
32
+ args,
33
+ memory,
34
+ senderId: incomingEvent?.senderId != null ? String(incomingEvent.senderId) : undefined,
35
+ senderType: incomingEvent?.senderType != null ? String(incomingEvent.senderType) : undefined,
36
+ });
37
+ if (!r.ok) {
38
+ emitted = [{ type: 'tool_error', tool: state.tool, error: r.error || 'unknown', senderId: 'system' }];
39
+ }
40
+ else if (r.events && r.events.length > 0) {
41
+ emitted = r.events;
42
+ }
43
+ else {
44
+ emitted = [{ type: 'tool_result', tool: state.tool, result: r.result, senderId: 'system' }];
45
+ }
46
+ }
47
+ catch (error) {
48
+ emitted = [
49
+ {
50
+ type: 'tool_error',
51
+ tool: state.tool,
52
+ error: error?.message ?? String(error),
53
+ senderId: 'system',
54
+ },
55
+ ];
56
+ }
57
+ const toolResults = [];
58
+ let outcome = outcomeFromActionResult('__mechanical__', pseudoAction, args, emitted, toolResults);
59
+ if (emitted.some((e) => e?.type === 'tool_error')) {
60
+ outcome = {
61
+ kind: 'error',
62
+ source: 'tool',
63
+ cause: emitted.find((e) => e?.type === 'tool_error')?.error ?? 'tool failed',
64
+ retryable: false,
65
+ };
66
+ }
67
+ runtimeLog.info('runMechanical', `done state=${stateId} outcome=${outcome.kind} llmCalls=0`);
68
+ return {
69
+ outcome,
70
+ toolResults,
71
+ llmCalls: 0,
72
+ tokens: { total: 0, input: 0, output: 0 },
73
+ };
74
+ }
@@ -0,0 +1,63 @@
1
+ import type { Action, Ctx, Outcome, ToolResultEntry, EffectHandler } from '../types.js';
2
+ import type { MemoryStore } from '../memory/MemoryStore.js';
3
+ import { type RawEvent } from './buildOutcome.js';
4
+ import { PromptBuilder } from './PromptBuilder.js';
5
+ import type { ToolManager } from '../tools/ToolManager.js';
6
+ interface RunTurnInput {
7
+ stateId: string;
8
+ statePrompt: import('../types.js').PromptDef;
9
+ actions: Record<string, Action>;
10
+ incomingEvent: RawEvent | null;
11
+ ctx: Ctx;
12
+ /** The only side channel. Every I/O — context, LLM, tools, send, record — flows through here. */
13
+ eff: EffectHandler;
14
+ /** Pure metadata: tool schemas, flags. Owned by the Agent. */
15
+ toolManager: ToolManager;
16
+ promptBuilder: PromptBuilder;
17
+ /**
18
+ * Agent-private long-term memory, threaded from AgentHost. Currently
19
+ * surfaced into `eff` as part of the tool-call effect payload so tools
20
+ * can read/write notes; the prompt builder doesn't consume it yet.
21
+ */
22
+ memory?: MemoryStore;
23
+ definition: {
24
+ description?: string;
25
+ };
26
+ /**
27
+ * Respond actions use 2-call streaming: Call 1 picks action+receiverId,
28
+ * Call 2 streams the text (ZIG-471). On by default (ZIG-838); pass false
29
+ * (or set ENABLE_LLM_STREAMING=false) to fold the reply text back into the
30
+ * single decision call. The env flag is a deployment kill-switch — the
31
+ * streaming path once broke long replies in production, so ops keeps a way
32
+ * to disable it without a code change.
33
+ */
34
+ streamRespondActions?: boolean;
35
+ }
36
+ interface RunTurnResult {
37
+ outcome: Outcome;
38
+ toolResults: ToolResultEntry[];
39
+ llmCalls: number;
40
+ tokens: {
41
+ total: number;
42
+ input: number;
43
+ output: number;
44
+ };
45
+ }
46
+ /**
47
+ * Run a single thinking-state turn.
48
+ *
49
+ * Reads context → builds prompt → tool loop with the LLM → executes one
50
+ * action → returns exactly one Outcome via outcomeFromActionResult.
51
+ *
52
+ * No direct service calls. Every impure operation goes through `eff`:
53
+ * • eff('read-context') — history/agreements/agents snapshot
54
+ * • eff('llm-call') — model invocation
55
+ * • eff('tool-call') — tool execution (Server runs the tool body)
56
+ * • eff('send-message') — outbound peer message
57
+ * • eff('record-event') — persist a thought / decision marker
58
+ *
59
+ * The Server is responsible for turning each effect into the right HTTP/WS
60
+ * call and (optionally) wrapping it in telemetry / dedup / retries.
61
+ */
62
+ export declare function runTurn(input: RunTurnInput): Promise<RunTurnResult>;
63
+ export {};