@ziggs-ai/agent-sdk 0.1.12 → 0.2.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.
- package/CHANGELOG.md +14 -0
- package/README.md +41 -2
- package/dist/AgentHost.d.ts +201 -0
- package/dist/AgentHost.js +652 -0
- package/dist/adapters/AnthropicAdapter.d.ts +39 -0
- package/dist/adapters/AnthropicAdapter.js +200 -0
- package/dist/adapters/McpAdapter.d.ts +199 -0
- package/dist/adapters/McpAdapter.js +468 -0
- package/dist/adapters/OpenAIAdapter.d.ts +26 -0
- package/dist/adapters/OpenAIAdapter.js +158 -0
- package/dist/adapters/index.js +2 -0
- package/dist/agent/Agent.d.ts +78 -0
- package/dist/agent/Agent.js +58 -0
- package/dist/agent/ClaudeSdkAgent.d.ts +38 -0
- package/dist/agent/ClaudeSdkAgent.js +322 -0
- package/dist/agent/claudeCognition.d.ts +67 -0
- package/dist/agent/claudeCognition.js +103 -0
- package/dist/agent/claudeSdkProtocol.d.ts +11 -0
- package/dist/agent/claudeSdkTools.d.ts +19 -0
- package/dist/agent/claudeSdkTools.js +57 -0
- package/dist/agent/hostedAgentConnection.d.ts +15 -0
- package/dist/agent/hostedAgentConnection.js +29 -0
- package/dist/agent/toolManagerToSdkMcp.d.ts +12 -0
- package/dist/agent/toolManagerToSdkMcp.js +123 -0
- package/dist/brain/index.d.ts +50 -0
- package/dist/brain/index.js +45 -0
- package/dist/cognition/validateContext.d.ts +11 -0
- package/dist/cognition/validateContext.js +117 -0
- package/dist/context/applyEffects.d.ts +2 -0
- package/dist/context/applyEffects.js +89 -0
- package/dist/context/batch.d.ts +2 -0
- package/dist/context/batch.js +18 -0
- package/dist/context/classifyEnvelope.d.ts +1 -0
- package/dist/context/classifyEnvelope.js +58 -0
- package/dist/context/routingLabels.d.ts +4 -0
- package/dist/context/routingLabels.js +48 -0
- package/dist/defineAgent.d.ts +14 -0
- package/dist/defineAgent.js +68 -0
- package/dist/formatters/AgreementFormatter.d.ts +18 -0
- package/dist/formatters/AgreementFormatter.js +130 -0
- package/dist/formatters/HistoryFormatter.d.ts +26 -0
- package/dist/formatters/HistoryFormatter.js +173 -0
- package/dist/formatters/index.js +2 -0
- package/{src/index.ts → dist/index.d.ts} +7 -53
- package/dist/index.js +66 -0
- package/dist/ingress/normalizeIncoming.d.ts +65 -0
- package/dist/ingress/normalizeIncoming.js +88 -0
- package/dist/memory/MemoryStore.d.ts +55 -0
- package/dist/memory/MemoryStore.js +78 -0
- package/dist/pricing/fleetDefaults.d.ts +46 -0
- package/dist/pricing/fleetDefaults.js +168 -0
- package/dist/pricing/fleetEvalFree.d.ts +7 -0
- package/dist/pricing/fleetEvalFree.js +24 -0
- package/dist/pricing/fleetFreeTierA.gen.d.ts +6 -0
- package/{src/pricing/fleetFreeTierA.gen.ts → dist/pricing/fleetFreeTierA.gen.js} +5 -6
- package/dist/pricing/fleetTierByAgentId.gen.d.ts +7 -0
- package/dist/pricing/fleetTierByAgentId.gen.js +768 -0
- package/dist/runtime/AgentMachine.d.ts +143 -0
- package/dist/runtime/AgentMachine.js +400 -0
- package/dist/runtime/PromptBuilder.d.ts +96 -0
- package/dist/runtime/PromptBuilder.js +439 -0
- package/{src/runtime/bootstrapCtx.ts → dist/runtime/bootstrapCtx.d.ts} +1 -22
- package/dist/runtime/bootstrapCtx.js +37 -0
- package/dist/runtime/buildOutcome.d.ts +68 -0
- package/dist/runtime/buildOutcome.js +464 -0
- package/dist/runtime/defaults.d.ts +54 -0
- package/dist/runtime/defaults.js +47 -0
- package/dist/runtime/deriveRespondsToProposals.d.ts +9 -0
- package/dist/runtime/deriveRespondsToProposals.js +38 -0
- package/dist/runtime/kickoff.d.ts +15 -0
- package/dist/runtime/kickoff.js +112 -0
- package/dist/runtime/runMechanical.d.ts +25 -0
- package/dist/runtime/runMechanical.js +74 -0
- package/dist/runtime/runTurn.d.ts +63 -0
- package/dist/runtime/runTurn.js +800 -0
- package/dist/runtime/validateWorkflow.d.ts +17 -0
- package/dist/runtime/validateWorkflow.js +209 -0
- package/dist/server/ConnectionPool.d.ts +68 -0
- package/dist/server/ConnectionPool.js +166 -0
- package/dist/server/EventQueue.d.ts +33 -0
- package/dist/server/EventQueue.js +98 -0
- package/dist/server/InboxCatchUp.d.ts +24 -0
- package/dist/server/InboxCatchUp.js +214 -0
- package/dist/server/OutboxBuffer.d.ts +33 -0
- package/dist/server/OutboxBuffer.js +68 -0
- package/dist/server/SeenMessages.d.ts +13 -0
- package/dist/server/SeenMessages.js +31 -0
- package/dist/server/StateTimers.d.ts +34 -0
- package/dist/server/StateTimers.js +70 -0
- package/dist/server/ZiggsEffectHandler.d.ts +79 -0
- package/dist/server/ZiggsEffectHandler.js +319 -0
- package/dist/server/agreements/AgreementService.d.ts +50 -0
- package/dist/server/agreements/AgreementService.js +85 -0
- package/dist/server/createHealthServer.d.ts +7 -0
- package/dist/server/createHealthServer.js +75 -0
- package/dist/server/proactive/ProactiveTrigger.d.ts +33 -0
- package/dist/server/proactive/ProactiveTrigger.js +71 -0
- package/dist/server/runLauncher.d.ts +28 -0
- package/dist/server/runLauncher.js +93 -0
- package/dist/server/tasks/TaskService.d.ts +25 -0
- package/dist/server/tasks/TaskService.js +103 -0
- package/dist/server/tasks/index.js +1 -0
- package/dist/server/telemetryIngest.d.ts +24 -0
- package/dist/server/telemetryIngest.js +62 -0
- package/dist/server/tools/index.d.ts +24 -0
- package/{src/server/tools/index.ts → dist/server/tools/index.js} +4 -24
- package/dist/server/tools/tier1/protocolRunner.d.ts +39 -0
- package/dist/server/tools/tier1/protocolRunner.js +288 -0
- package/dist/server/tools/tier1/protocolTools.d.ts +12 -0
- package/dist/server/tools/tier1/protocolTools.js +37 -0
- package/dist/server/tools/tier2/connectionTools.d.ts +4 -0
- package/dist/server/tools/tier2/connectionTools.js +63 -0
- package/dist/server/tools/tier2/contextTools.d.ts +4 -0
- package/dist/server/tools/tier2/contextTools.js +46 -0
- package/dist/server/tools/tier2/discoveryTools.d.ts +4 -0
- package/dist/server/tools/tier2/discoveryTools.js +25 -0
- package/dist/server/tools/tier2/marketplaceTools.d.ts +3 -0
- package/dist/server/tools/tier2/marketplaceTools.js +22 -0
- package/dist/server/tools/tier2/paymentTools.d.ts +12 -0
- package/dist/server/tools/tier2/paymentTools.js +165 -0
- package/dist/server/ziggsconnect/ZiggsConnectClient.d.ts +35 -0
- package/dist/server/ziggsconnect/ZiggsConnectClient.js +95 -0
- package/dist/server/ziggscontext/ZiggsContextClient.d.ts +53 -0
- package/dist/server/ziggscontext/ZiggsContextClient.js +124 -0
- package/dist/server/ziggspay/ZiggsPayClient.d.ts +82 -0
- package/dist/server/ziggspay/ZiggsPayClient.js +203 -0
- package/dist/shared/ids.d.ts +1 -0
- package/dist/shared/ids.js +3 -0
- package/dist/shared/runtimeLog.d.ts +18 -0
- package/dist/shared/runtimeLog.js +68 -0
- package/dist/shared/types.d.ts +22 -0
- package/dist/shared/types.js +23 -0
- package/dist/tasks/protocolRegistry.d.ts +16 -0
- package/dist/tasks/protocolRegistry.js +20 -0
- package/dist/tools/ToolManager.d.ts +12 -0
- package/dist/tools/ToolManager.js +74 -0
- package/dist/tools/ToolProvider.d.ts +6 -0
- package/dist/tools/ToolProvider.js +21 -0
- package/dist/tools/defineTool.d.ts +27 -0
- package/dist/tools/defineTool.js +62 -0
- package/{src/tools/index.ts → dist/tools/index.d.ts} +0 -1
- package/dist/tools/index.js +6 -0
- package/dist/tools/recordReport.d.ts +41 -0
- package/dist/tools/recordReport.js +30 -0
- package/dist/types.d.ts +466 -0
- package/dist/types.js +7 -0
- package/dist/utils/jsonExtractor.d.ts +2 -0
- package/dist/utils/jsonExtractor.js +111 -0
- package/package.json +14 -6
- package/src/AgentHost.ts +0 -814
- package/src/adapters/AnthropicAdapter.ts +0 -238
- package/src/adapters/McpAdapter.ts +0 -678
- package/src/adapters/OpenAIAdapter.ts +0 -194
- package/src/agent/Agent.ts +0 -112
- package/src/agent/ClaudeSdkAgent.ts +0 -401
- package/src/agent/claudeCognition.ts +0 -139
- package/src/agent/claudeSdkTools.ts +0 -81
- package/src/agent/hostedAgentConnection.ts +0 -41
- package/src/agent/toolManagerToSdkMcp.ts +0 -136
- package/src/cognition/validateContext.ts +0 -95
- package/src/context/applyEffects.ts +0 -80
- package/src/context/batch.ts +0 -19
- package/src/context/classifyEnvelope.ts +0 -38
- package/src/context/routingLabels.ts +0 -46
- package/src/defineAgent.ts +0 -77
- package/src/formatters/AgreementFormatter.ts +0 -111
- package/src/formatters/HistoryFormatter.ts +0 -172
- package/src/ingress/normalizeIncoming.ts +0 -162
- package/src/memory/MemoryStore.ts +0 -104
- package/src/pricing/fleetDefaults.ts +0 -225
- package/src/pricing/fleetEvalFree.ts +0 -24
- package/src/pricing/fleetTierByAgentId.gen.ts +0 -775
- package/src/runtime/AgentMachine.ts +0 -484
- package/src/runtime/PromptBuilder.ts +0 -522
- package/src/runtime/buildOutcome.ts +0 -563
- package/src/runtime/defaults.ts +0 -86
- package/src/runtime/deriveRespondsToProposals.ts +0 -35
- package/src/runtime/kickoff.ts +0 -117
- package/src/runtime/runMechanical.ts +0 -106
- package/src/runtime/runTurn.ts +0 -870
- package/src/runtime/validateWorkflow.ts +0 -221
- package/src/server/ConnectionPool.ts +0 -206
- package/src/server/EventQueue.ts +0 -133
- package/src/server/InboxCatchUp.ts +0 -291
- package/src/server/OutboxBuffer.ts +0 -90
- package/src/server/SeenMessages.ts +0 -27
- package/src/server/StateTimers.ts +0 -85
- package/src/server/ZiggsEffectHandler.ts +0 -427
- package/src/server/agreements/AgreementService.ts +0 -118
- package/src/server/createHealthServer.ts +0 -85
- package/src/server/proactive/ProactiveTrigger.ts +0 -83
- package/src/server/runLauncher.ts +0 -146
- package/src/server/tasks/TaskService.ts +0 -111
- package/src/server/telemetryIngest.ts +0 -91
- package/src/server/tools/tier1/protocolRunner.ts +0 -353
- package/src/server/tools/tier1/protocolTools.ts +0 -114
- package/src/server/tools/tier2/connectionTools.ts +0 -75
- package/src/server/tools/tier2/contextTools.ts +0 -63
- package/src/server/tools/tier2/discoveryTools.ts +0 -34
- package/src/server/tools/tier2/marketplaceTools.ts +0 -27
- package/src/server/tools/tier2/paymentTools.ts +0 -170
- package/src/server/ziggsconnect/ZiggsConnectClient.ts +0 -126
- package/src/server/ziggscontext/ZiggsContextClient.ts +0 -129
- package/src/server/ziggspay/ZiggsPayClient.ts +0 -193
- package/src/shared/ids.ts +0 -3
- package/src/shared/runtimeLog.ts +0 -72
- package/src/shared/types.ts +0 -29
- package/src/tasks/protocolRegistry.ts +0 -25
- package/src/tools/ToolManager.ts +0 -95
- package/src/tools/ToolProvider.ts +0 -19
- package/src/tools/defineTool.ts +0 -90
- package/src/tools/recordReport.ts +0 -82
- package/src/types.ts +0 -483
- package/src/utils/jsonExtractor.ts +0 -100
- /package/{src/adapters/index.ts → dist/adapters/index.d.ts} +0 -0
- /package/{src/agent/claudeSdkProtocol.ts → dist/agent/claudeSdkProtocol.js} +0 -0
- /package/{src/formatters/index.ts → dist/formatters/index.d.ts} +0 -0
- /package/{src/server/tasks/index.ts → dist/server/tasks/index.d.ts} +0 -0
package/src/runtime/kickoff.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import type { Outcome, State, ThinkingState, Transition, Workflow } from '../types.js';
|
|
2
|
-
import { thinkingDefaults } from './defaults.js';
|
|
3
|
-
import { PROBE_CTX } from './validateWorkflow.js';
|
|
4
|
-
|
|
5
|
-
/** Reserved state name for the injected agreement-kickoff default. */
|
|
6
|
-
export const KICKOFF_STATE = 'kickingOff';
|
|
7
|
-
|
|
8
|
-
// Synthetic outcome used to ask "does this state already handle a proposer-side
|
|
9
|
-
// approval?" — the same probe pattern validateWorkflow uses for the wait/error
|
|
10
|
-
// fallthrough checks.
|
|
11
|
-
const PROBE_APPROVE: Outcome = {
|
|
12
|
-
kind: 'proposal-resolved',
|
|
13
|
-
action: 'approve',
|
|
14
|
-
proposal: { agreementId: '__kickoff_probe__' },
|
|
15
|
-
proposedByMe: true,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const KICKOFF_TRANSITION: Transition = {
|
|
19
|
-
to: KICKOFF_STATE,
|
|
20
|
-
when: (o, ctx) =>
|
|
21
|
-
o.kind === 'proposal-resolved' &&
|
|
22
|
-
o.action === 'approve' &&
|
|
23
|
-
o.proposedByMe === true &&
|
|
24
|
-
// "first task" guard — both branches cover one exact scenario: a task under
|
|
25
|
-
// THIS agreement already exists because a racing task_result frame was
|
|
26
|
-
// applied to ctx before this approval frame.
|
|
27
|
-
// (1) we already delegated under it:
|
|
28
|
-
!ctx.delegatedAgreementIds.includes(o.proposal.agreementId) &&
|
|
29
|
-
// (2) we already hold an assigned task bound to it (task-assigned sets
|
|
30
|
-
// activeTaskId + activeAgreementId together in applyOutcomeToCtx):
|
|
31
|
-
!(ctx.activeTaskId !== null && ctx.activeAgreementId === o.proposal.agreementId),
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// A state "handles" proposer-approval if some transition would fire for it.
|
|
35
|
-
// An unconditional (when-less) transition counts: it catches every outcome,
|
|
36
|
-
// so the kickoff transition — appended LAST — would be unreachable dead code
|
|
37
|
-
// there anyway. Consequence to know: a state whose only route for a
|
|
38
|
-
// proposal-resolved/approve is an unconditional fallthrough to an UNRELATED
|
|
39
|
-
// state will NOT auto-kickoff (the approval follows the fallthrough instead).
|
|
40
|
-
// Authors who want guaranteed kickoff in such a state must add an explicit
|
|
41
|
-
// `when: o => o.kind === 'proposal-resolved' && o.action === 'approve'`
|
|
42
|
-
// transition (which this probe then respects) — or route approval into a
|
|
43
|
-
// thinking state that spawns the task itself.
|
|
44
|
-
function stateHandlesProposerApproval(state: State): boolean {
|
|
45
|
-
return state.transitions.some(t => {
|
|
46
|
-
if (!t.when) return true;
|
|
47
|
-
try { return !!t.when(PROBE_APPROVE, PROBE_CTX); }
|
|
48
|
-
catch { return false; }
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function buildKickoffState(initial: string): ThinkingState {
|
|
53
|
-
const dflt = thinkingDefaults({ initial });
|
|
54
|
-
return {
|
|
55
|
-
kind: 'thinking',
|
|
56
|
-
prompt: {
|
|
57
|
-
role: 'The counterparty just approved an agreement you proposed. The platform never auto-starts work — as the proposer, you spawn the first task now.',
|
|
58
|
-
goal: 'Spawn exactly one task under the just-approved agreement so work begins.',
|
|
59
|
-
constraints:
|
|
60
|
-
'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.',
|
|
61
|
-
},
|
|
62
|
-
actions: {
|
|
63
|
-
...dflt.actions,
|
|
64
|
-
spawnFirstTask: {
|
|
65
|
-
prompt: {
|
|
66
|
-
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.',
|
|
67
|
-
instruction: 'Spawn the first task under the approved agreement so work starts.',
|
|
68
|
-
format: '{"agreementId": "<the agreement whose proposal was just approved>", "description": "<concrete work + all counterparty specifics from history>"}',
|
|
69
|
-
},
|
|
70
|
-
tool: 'task_spawn',
|
|
71
|
-
// Function form so a failed task_spawn surfaces as an error outcome
|
|
72
|
-
// (→ dflt error transition + machine warn log) instead of a fake
|
|
73
|
-
// task-delegated with an empty task.
|
|
74
|
-
produces: (result) => {
|
|
75
|
-
const r = result as { taskId?: string; task?: { taskId?: string } } | undefined;
|
|
76
|
-
return r?.taskId || r?.task?.taskId ? 'task-delegated' : 'error';
|
|
77
|
-
},
|
|
78
|
-
terminatesLoop: true,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
transitions: [
|
|
82
|
-
{ to: initial, when: o => o.kind === 'task-delegated' },
|
|
83
|
-
...dflt.transitions, // wait / message-sent / error → initial
|
|
84
|
-
],
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Agreement-kickoff default. For every state whose transitions do not already
|
|
90
|
-
* match a proposer-side approval (probe above), append a transition to the
|
|
91
|
-
* injected `kickingOff` state. Appended LAST so any user transition on the same
|
|
92
|
-
* outcome always wins (first match wins in AgentMachine._evaluateTransitions).
|
|
93
|
-
* Returns a NEW workflow — input states are not mutated. After kickoff the
|
|
94
|
-
* machine returns to `initial`; when this agent is itself the provider the
|
|
95
|
-
* backend then assigns the spawned task back to it as a normal task-assigned
|
|
96
|
-
* event, which the author's existing work loop handles.
|
|
97
|
-
*/
|
|
98
|
-
export function injectKickoffDefault(workflow: Workflow): Workflow {
|
|
99
|
-
if (workflow.states[KICKOFF_STATE]) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
`[defineAgent] state name "${KICKOFF_STATE}" is reserved for the injected agreement-kickoff default — rename the state`,
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
const states: Record<string, State> = {};
|
|
105
|
-
let injected = false;
|
|
106
|
-
for (const [name, state] of Object.entries(workflow.states)) {
|
|
107
|
-
if (stateHandlesProposerApproval(state)) {
|
|
108
|
-
states[name] = state;
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
states[name] = { ...state, transitions: [...state.transitions, KICKOFF_TRANSITION] } as State;
|
|
112
|
-
injected = true;
|
|
113
|
-
}
|
|
114
|
-
if (!injected) return workflow; // every state handles approval — nothing to add, no dead state
|
|
115
|
-
states[KICKOFF_STATE] = buildKickoffState(workflow.initial);
|
|
116
|
-
return { ...workflow, states };
|
|
117
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Action,
|
|
3
|
-
Ctx,
|
|
4
|
-
EffectHandler,
|
|
5
|
-
MechanicalState,
|
|
6
|
-
Outcome,
|
|
7
|
-
ToolResultEntry,
|
|
8
|
-
} from '../types.js';
|
|
9
|
-
import type { MemoryStore } from '../memory/MemoryStore.js';
|
|
10
|
-
import { outcomeFromActionResult, type EmittedEvent, type RawEvent, type WireResult } from './buildOutcome.js';
|
|
11
|
-
import { runtimeLog } from '../shared/runtimeLog.js';
|
|
12
|
-
import type { ToolCallResult } from '../types.js';
|
|
13
|
-
|
|
14
|
-
export interface RunMechanicalResult {
|
|
15
|
-
outcome: Outcome;
|
|
16
|
-
toolResults: ToolResultEntry[];
|
|
17
|
-
llmCalls: number;
|
|
18
|
-
tokens: { total: number; input: number; output: number };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* ZIG-764: run a mechanical state — invoke one bound tool with no LLM turn.
|
|
23
|
-
* Used by dumb coordinators whose only job is a fixed tool call on task-assigned.
|
|
24
|
-
*/
|
|
25
|
-
export async function runMechanical(input: {
|
|
26
|
-
stateId: string;
|
|
27
|
-
state: MechanicalState;
|
|
28
|
-
ctx: Ctx;
|
|
29
|
-
eff: EffectHandler;
|
|
30
|
-
memory?: MemoryStore;
|
|
31
|
-
incomingEvent: RawEvent | null;
|
|
32
|
-
}): Promise<RunMechanicalResult> {
|
|
33
|
-
const { stateId, state, ctx, eff, memory, incomingEvent } = input;
|
|
34
|
-
const sessionId = ctx.identity.sessionId;
|
|
35
|
-
const runId = crypto.randomUUID();
|
|
36
|
-
|
|
37
|
-
const effWithTrace: typeof eff = (effect) => {
|
|
38
|
-
if (effect.kind === 'tool-call') {
|
|
39
|
-
return eff({ ...effect, runId, stateId } as typeof effect);
|
|
40
|
-
}
|
|
41
|
-
return eff(effect);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
runtimeLog.info('runMechanical', `enter state=${stateId} tool=${state.tool}`);
|
|
45
|
-
|
|
46
|
-
const args =
|
|
47
|
-
typeof state.buildArgs === 'function'
|
|
48
|
-
? state.buildArgs(ctx, ctx.lastOutcome)
|
|
49
|
-
: { ...(state.args ?? {}) };
|
|
50
|
-
|
|
51
|
-
const pseudoAction: Action = {
|
|
52
|
-
prompt: { instruction: '' },
|
|
53
|
-
tool: state.tool,
|
|
54
|
-
produces: state.produces,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
let emitted: EmittedEvent[] = [];
|
|
58
|
-
try {
|
|
59
|
-
const r = await effWithTrace({
|
|
60
|
-
kind: 'tool-call',
|
|
61
|
-
sessionId,
|
|
62
|
-
name: state.tool,
|
|
63
|
-
args,
|
|
64
|
-
memory,
|
|
65
|
-
senderId: incomingEvent?.senderId != null ? String(incomingEvent.senderId) : undefined,
|
|
66
|
-
senderType: incomingEvent?.senderType != null ? String(incomingEvent.senderType) : undefined,
|
|
67
|
-
}) as ToolCallResult;
|
|
68
|
-
|
|
69
|
-
if (!r.ok) {
|
|
70
|
-
emitted = [{ type: 'tool_error', tool: state.tool, error: r.error || 'unknown', senderId: 'system' }];
|
|
71
|
-
} else if (r.events && (r.events as unknown[]).length > 0) {
|
|
72
|
-
emitted = r.events as unknown as EmittedEvent[];
|
|
73
|
-
} else {
|
|
74
|
-
emitted = [{ type: 'tool_result', tool: state.tool, result: r.result as WireResult | undefined, senderId: 'system' }];
|
|
75
|
-
}
|
|
76
|
-
} catch (error: unknown) {
|
|
77
|
-
emitted = [
|
|
78
|
-
{
|
|
79
|
-
type: 'tool_error',
|
|
80
|
-
tool: state.tool,
|
|
81
|
-
error: (error as Error)?.message ?? String(error),
|
|
82
|
-
senderId: 'system',
|
|
83
|
-
},
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const toolResults: ToolResultEntry[] = [];
|
|
88
|
-
let outcome = outcomeFromActionResult('__mechanical__', pseudoAction, args, emitted, toolResults);
|
|
89
|
-
if (emitted.some((e) => e?.type === 'tool_error')) {
|
|
90
|
-
outcome = {
|
|
91
|
-
kind: 'error',
|
|
92
|
-
source: 'tool',
|
|
93
|
-
cause: emitted.find((e) => e?.type === 'tool_error')?.error ?? 'tool failed',
|
|
94
|
-
retryable: false,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
runtimeLog.info('runMechanical', `done state=${stateId} outcome=${outcome.kind} llmCalls=0`);
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
outcome,
|
|
102
|
-
toolResults,
|
|
103
|
-
llmCalls: 0,
|
|
104
|
-
tokens: { total: 0, input: 0, output: 0 },
|
|
105
|
-
};
|
|
106
|
-
}
|