@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.
- 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/claudeSdkProtocol.js +27 -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} +13 -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/dist/runtime/bootstrapCtx.d.ts +18 -0
- 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 +213 -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 +48 -0
- package/dist/server/ziggscontext/ZiggsContextClient.js +90 -0
- package/dist/server/ziggspay/ZiggsPayClient.d.ts +82 -0
- package/dist/server/ziggspay/ZiggsPayClient.js +188 -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 +17 -7
- package/src/AgentHost.ts +0 -545
- package/src/adapters/AnthropicAdapter.ts +0 -206
- package/src/adapters/McpAdapter.ts +0 -348
- package/src/adapters/OpenAIAdapter.ts +0 -187
- package/src/agent/Agent.ts +0 -104
- 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 -70
- 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 -402
- package/src/runtime/PromptBuilder.ts +0 -485
- package/src/runtime/buildOutcome.ts +0 -563
- package/src/runtime/defaults.ts +0 -75
- package/src/runtime/kickoff.ts +0 -117
- package/src/runtime/runTurn.ts +0 -813
- package/src/runtime/validateWorkflow.ts +0 -202
- package/src/server/ConnectionPool.ts +0 -206
- package/src/server/EventQueue.ts +0 -133
- package/src/server/InboxCatchUp.ts +0 -254
- 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 -418
- 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 -110
- package/src/server/telemetryIngest.ts +0 -91
- package/src/server/tools/tier1/protocolRunner.ts +0 -144
- package/src/server/tools/tier1/protocolTools.ts +0 -99
- 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 -456
- package/src/utils/jsonExtractor.ts +0 -100
- /package/{src/adapters/index.ts → dist/adapters/index.d.ts} +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
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { publishOffer, pullOffers, claimOffer, type Creds } from '@ziggs-ai/api-client';
|
|
2
|
-
import type { PublishOfferPayload, PullOffersOptions } from '@ziggs-ai/api-client';
|
|
3
|
-
import { runtimeLog } from '../../shared/runtimeLog.js';
|
|
4
|
-
|
|
5
|
-
interface TickContext {
|
|
6
|
-
agentId: string;
|
|
7
|
-
marketplace: {
|
|
8
|
-
publishOffer: (payload: PublishOfferPayload) => Promise<unknown>;
|
|
9
|
-
pullOffers: (options?: PullOffersOptions) => Promise<unknown[]>;
|
|
10
|
-
claimOffer: (agreementId: string) => Promise<unknown>;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface ProactiveTriggerOptions {
|
|
15
|
-
interval: number;
|
|
16
|
-
creds: Creds;
|
|
17
|
-
onTick: (ctx: TickContext) => Promise<void>;
|
|
18
|
-
onError?: (err: unknown) => void;
|
|
19
|
-
runImmediately?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class ProactiveTrigger {
|
|
23
|
-
private interval: number;
|
|
24
|
-
private creds: Creds;
|
|
25
|
-
private onTick: (ctx: TickContext) => Promise<void>;
|
|
26
|
-
private onError: (err: unknown) => void;
|
|
27
|
-
private runImmediately: boolean;
|
|
28
|
-
private _running: boolean;
|
|
29
|
-
private _timer: ReturnType<typeof setTimeout> | null;
|
|
30
|
-
|
|
31
|
-
constructor({ interval, creds, onTick, onError, runImmediately = false }: ProactiveTriggerOptions) {
|
|
32
|
-
if (!interval || typeof interval !== 'number' || interval < 1000) throw new Error('ProactiveTrigger: interval must be a number >= 1000ms');
|
|
33
|
-
if (!creds?.operatorKey || !creds?.agentId) throw new Error('ProactiveTrigger: creds.operatorKey and creds.agentId are required');
|
|
34
|
-
if (typeof onTick !== 'function') throw new Error('ProactiveTrigger: onTick must be a function');
|
|
35
|
-
this.interval = interval;
|
|
36
|
-
this.creds = creds;
|
|
37
|
-
this.onTick = onTick;
|
|
38
|
-
this.onError = onError ?? ((err) => runtimeLog.error('ProactiveTrigger', `tick error: ${String(err)}`));
|
|
39
|
-
this.runImmediately = runImmediately;
|
|
40
|
-
this._running = false;
|
|
41
|
-
this._timer = null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
start(): void {
|
|
45
|
-
if (this._running) return;
|
|
46
|
-
this._running = true;
|
|
47
|
-
runtimeLog.debug(
|
|
48
|
-
'ProactiveTrigger',
|
|
49
|
-
`started (agentId=${this.creds.agentId}, interval=${this.interval}ms)`,
|
|
50
|
-
);
|
|
51
|
-
if (this.runImmediately) this._tick();
|
|
52
|
-
else this._schedule();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
stop(): void {
|
|
56
|
-
this._running = false;
|
|
57
|
-
if (this._timer) { clearTimeout(this._timer); this._timer = null; }
|
|
58
|
-
runtimeLog.debug('ProactiveTrigger', `stopped (agentId=${this.creds.agentId})`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private _schedule(): void {
|
|
62
|
-
if (!this._running) return;
|
|
63
|
-
this._timer = setTimeout(() => this._tick(), this.interval);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private async _tick(): Promise<void> {
|
|
67
|
-
if (!this._running) return;
|
|
68
|
-
try { await this.onTick(this._buildContext()); } catch (err) { this.onError(err); }
|
|
69
|
-
this._schedule();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private _buildContext(): TickContext {
|
|
73
|
-
const creds = this.creds;
|
|
74
|
-
return {
|
|
75
|
-
agentId: creds.agentId,
|
|
76
|
-
marketplace: {
|
|
77
|
-
publishOffer: (payload) => publishOffer(payload, creds),
|
|
78
|
-
pullOffers: (options) => pullOffers(options, creds),
|
|
79
|
-
claimOffer: (agreementId) => claimOffer(agreementId, creds),
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { ConnectionPool } from './ConnectionPool.js';
|
|
2
|
-
import { AgentHost, type AgentHostOptions } from '../AgentHost.js';
|
|
3
|
-
import { createHealthServer } from './createHealthServer.js';
|
|
4
|
-
import { runtimeLog } from '../shared/runtimeLog.js';
|
|
5
|
-
import type { Server } from 'http';
|
|
6
|
-
|
|
7
|
-
type AgentConfig = AgentHostOptions & {
|
|
8
|
-
ownAgentId?: string;
|
|
9
|
-
options?: { ownAgentId?: string; name?: string };
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
interface SingleOptions {
|
|
13
|
-
operatorKey?: string;
|
|
14
|
-
label?: string;
|
|
15
|
-
port?: number | string;
|
|
16
|
-
healthServer?: boolean;
|
|
17
|
-
onShutdown?: () => Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface FleetOptions extends SingleOptions {
|
|
21
|
-
wsUrl?: string;
|
|
22
|
-
agentMeta?: Record<string, unknown>[];
|
|
23
|
-
primary?: AgentConfig | ((pool: ConnectionPool) => AgentConfig);
|
|
24
|
-
preWake?: string[];
|
|
25
|
-
poolOptions?: { maxActive?: number; idleTimeoutMs?: number };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function runLauncher(
|
|
29
|
-
configOrConfigs: AgentConfig | AgentConfig[],
|
|
30
|
-
opts: FleetOptions = {},
|
|
31
|
-
): Promise<unknown> {
|
|
32
|
-
if (Array.isArray(configOrConfigs)) return runFleet(configOrConfigs, opts);
|
|
33
|
-
return runSingle(configOrConfigs, opts as SingleOptions);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function runSingle(
|
|
37
|
-
config: AgentConfig,
|
|
38
|
-
{ operatorKey, label = 'agent', port = process.env.PORT || 8080, healthServer = true, onShutdown }: SingleOptions = {},
|
|
39
|
-
): Promise<{ agent: unknown; healthServer?: Server }> {
|
|
40
|
-
const effectiveKey = operatorKey ?? process.env.ZIGGS_OPERATOR_KEY;
|
|
41
|
-
const decorated = effectiveKey && !config.operatorKey ? { ...config, operatorKey: effectiveKey } : config;
|
|
42
|
-
const agent = new AgentHost(decorated);
|
|
43
|
-
try {
|
|
44
|
-
await agent.connectAsync();
|
|
45
|
-
runtimeLog.info(
|
|
46
|
-
label,
|
|
47
|
-
`"${(agent as unknown as Record<string, unknown>)['options'] ? ((agent as unknown as Record<string, {agentId?: string; name?: string | null}>)['options']?.agentId ?? (agent as unknown as Record<string, {name?: string | null}>)['options']?.name) : 'agent'}" connected`,
|
|
48
|
-
);
|
|
49
|
-
} catch (err) {
|
|
50
|
-
runtimeLog.warn(label, `Agent failed to connect at startup: ${(err as Error).message} — will retry`);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const server = healthServer ? createHealthServer({ port: Number(port), label }) : null;
|
|
54
|
-
|
|
55
|
-
process.on('SIGTERM', async () => {
|
|
56
|
-
runtimeLog.info(label, 'SIGTERM — shutting down');
|
|
57
|
-
agent.disconnect();
|
|
58
|
-
await agent.drain(30_000);
|
|
59
|
-
try {
|
|
60
|
-
await onShutdown?.();
|
|
61
|
-
} catch (err) {
|
|
62
|
-
runtimeLog.warn(label, `onShutdown error: ${(err as Error).message}`);
|
|
63
|
-
}
|
|
64
|
-
server?.close();
|
|
65
|
-
process.exit(0);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return { agent, healthServer: server ?? undefined };
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function runFleet(
|
|
72
|
-
configs: AgentConfig[],
|
|
73
|
-
{
|
|
74
|
-
operatorKey, wsUrl = process.env.WS_URL, port = process.env.PORT || 8080,
|
|
75
|
-
healthServer = true, label = 'launcher', agentMeta,
|
|
76
|
-
primary: primaryConfig, preWake = [], poolOptions, onShutdown,
|
|
77
|
-
}: FleetOptions = {},
|
|
78
|
-
): Promise<{ pool: ConnectionPool; primary: unknown; healthServer?: Server }> {
|
|
79
|
-
const pool = new ConnectionPool(poolOptions);
|
|
80
|
-
const effectiveKey = operatorKey ?? process.env.ZIGGS_OPERATOR_KEY;
|
|
81
|
-
const decoratedConfigs = effectiveKey
|
|
82
|
-
? configs.map(c => (c.operatorKey ? c : { ...c, operatorKey: effectiveKey }))
|
|
83
|
-
: configs;
|
|
84
|
-
pool.register(decoratedConfigs, agentMeta as Record<string, unknown>[]);
|
|
85
|
-
const server = healthServer ? createHealthServer({ port: Number(port), label, pool }) : null;
|
|
86
|
-
|
|
87
|
-
let resolvedPrimaryConfig: AgentConfig | undefined = typeof primaryConfig === 'function'
|
|
88
|
-
? primaryConfig(pool)
|
|
89
|
-
: primaryConfig;
|
|
90
|
-
if (resolvedPrimaryConfig && effectiveKey && !resolvedPrimaryConfig.operatorKey) {
|
|
91
|
-
resolvedPrimaryConfig = { ...resolvedPrimaryConfig, operatorKey: effectiveKey };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const controlKey = effectiveKey ?? configs.find(c => c.operatorKey)?.operatorKey ?? resolvedPrimaryConfig?.operatorKey;
|
|
95
|
-
if (controlKey) {
|
|
96
|
-
pool.startControl({ wsUrl, operatorKey: controlKey });
|
|
97
|
-
} else {
|
|
98
|
-
runtimeLog.warn(label, 'No operatorKey provided — skipping control socket');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
let primary: unknown = null;
|
|
102
|
-
if (resolvedPrimaryConfig) {
|
|
103
|
-
primary = new AgentHost(resolvedPrimaryConfig);
|
|
104
|
-
try {
|
|
105
|
-
await (primary as { connectAsync: () => Promise<void> }).connectAsync();
|
|
106
|
-
runtimeLog.info(
|
|
107
|
-
label,
|
|
108
|
-
`Primary agent "${resolvedPrimaryConfig.name || resolvedPrimaryConfig.ownAgentId || 'primary'}" connected`,
|
|
109
|
-
);
|
|
110
|
-
} catch (err) {
|
|
111
|
-
// Backend may not be ready yet — socket.io reconnects automatically.
|
|
112
|
-
// Don't crash the process; the primary agent will be live once it reconnects.
|
|
113
|
-
runtimeLog.warn(
|
|
114
|
-
label,
|
|
115
|
-
`Primary agent "${resolvedPrimaryConfig.name || resolvedPrimaryConfig.ownAgentId || 'primary'}" failed to connect at startup: ${(err as Error).message} — will retry`,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (preWake.length > 0) {
|
|
121
|
-
await Promise.all(preWake.map(id =>
|
|
122
|
-
pool.wake(id)
|
|
123
|
-
.then(() => runtimeLog.debug(label, `Pre-woke "${id}"`))
|
|
124
|
-
.catch(err => runtimeLog.warn(label, `Could not pre-wake "${id}": ${(err as Error).message}`)),
|
|
125
|
-
));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
runtimeLog.info(label, `Ready — ${pool.size} agent(s) registered, ${pool.listActive().length} connected`);
|
|
129
|
-
|
|
130
|
-
process.on('SIGTERM', async () => {
|
|
131
|
-
runtimeLog.info(label, 'SIGTERM — shutting down');
|
|
132
|
-
pool.stopControl();
|
|
133
|
-
(primary as { disconnect?: () => void })?.disconnect?.();
|
|
134
|
-
await (primary as { drain?: (ms: number) => Promise<void> })?.drain?.(30_000);
|
|
135
|
-
await pool.disconnectAll();
|
|
136
|
-
try {
|
|
137
|
-
await onShutdown?.();
|
|
138
|
-
} catch (err) {
|
|
139
|
-
runtimeLog.warn(label, `onShutdown error: ${(err as Error).message}`);
|
|
140
|
-
}
|
|
141
|
-
server?.close();
|
|
142
|
-
process.exit(0);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
return { pool, primary, healthServer: server ?? undefined };
|
|
146
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createTask, getTask, getActiveTasksForAgent, getActiveTasksForChat, getSubtasks,
|
|
3
|
-
updateTaskState, updateTaskPlanStep, cancelTask,
|
|
4
|
-
reportTask, setTaskSatisfaction, countTasks,
|
|
5
|
-
type Creds, type Task, type TaskState,
|
|
6
|
-
} from '@ziggs-ai/api-client';
|
|
7
|
-
import type { CountTasksFilters } from '@ziggs-ai/api-client';
|
|
8
|
-
import { runtimeLog } from '../../shared/runtimeLog.js';
|
|
9
|
-
|
|
10
|
-
function safeJsonStringify(value: unknown): unknown {
|
|
11
|
-
if (value === null || value === undefined) return value;
|
|
12
|
-
if (typeof value === 'string') return value;
|
|
13
|
-
if (typeof value !== 'object') return String(value);
|
|
14
|
-
const seen = new WeakSet();
|
|
15
|
-
try {
|
|
16
|
-
return JSON.stringify(value, (_key, val) => {
|
|
17
|
-
if (typeof val === 'object' && val !== null) {
|
|
18
|
-
if (seen.has(val)) return '[Circular]';
|
|
19
|
-
seen.add(val);
|
|
20
|
-
}
|
|
21
|
-
return val;
|
|
22
|
-
}, 2);
|
|
23
|
-
} catch {
|
|
24
|
-
return String(value);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class TaskService {
|
|
29
|
-
private creds: Creds;
|
|
30
|
-
|
|
31
|
-
constructor(operatorKey: string, agentId: string) {
|
|
32
|
-
if (!operatorKey) throw new Error('TaskService: operatorKey is required');
|
|
33
|
-
if (!agentId) throw new Error('TaskService: agentId is required (operator-token impersonation)');
|
|
34
|
-
this.creds = { operatorKey, agentId };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async getTask(taskId: string): Promise<Task> {
|
|
38
|
-
return getTask(taskId, this.creds);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async getActiveTasksForAgent(agentId: string): Promise<Task[]> {
|
|
42
|
-
return getActiveTasksForAgent(agentId, this.creds);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async getActiveTasksForChat(chatId: string): Promise<Task[]> {
|
|
46
|
-
return getActiveTasksForChat(chatId, this.creds);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async getSubtasks(parentTaskId: string): Promise<Task[]> {
|
|
50
|
-
return getSubtasks(parentTaskId, this.creds);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async spawnUnderAgreement(agreementId: string, taskData: { description: string; parentTaskId?: string; plan?: unknown; planReviewTiming?: string; requireMidWorkPlanAck?: boolean; assigneeId?: string; inputArtifactIds?: string[] }): Promise<Task> {
|
|
54
|
-
if (!agreementId) throw new Error('TaskService.spawnUnderAgreement: agreementId is required');
|
|
55
|
-
try {
|
|
56
|
-
const result = await createTask({ ...taskData, agreementId } as Parameters<typeof createTask>[0], this.creds);
|
|
57
|
-
runtimeLog.info('TaskService', `Task spawned under agreement ${agreementId}: ${result?.taskId || 'unknown'}`);
|
|
58
|
-
return result;
|
|
59
|
-
} catch (error) {
|
|
60
|
-
runtimeLog.error('TaskService', `Task spawn failed: ${(error as Error).message}`);
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async updateState(taskId: string, state: TaskState, result?: unknown): Promise<Task> {
|
|
66
|
-
try {
|
|
67
|
-
const data = result !== undefined ? { result: safeJsonStringify(result) } : {};
|
|
68
|
-
const updated = await updateTaskState(taskId, state, data, this.creds);
|
|
69
|
-
runtimeLog.info('TaskService', `Task state: ${taskId} → ${state}`);
|
|
70
|
-
return updated;
|
|
71
|
-
} catch (error) {
|
|
72
|
-
runtimeLog.error('TaskService', `Task state update failed: ${(error as Error).message}`);
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async updatePlanStep(taskId: string, stepId: string, status: string, result?: unknown): Promise<Task> {
|
|
78
|
-
try {
|
|
79
|
-
const updated = await updateTaskPlanStep(taskId, stepId, status, result, this.creds);
|
|
80
|
-
runtimeLog.info('TaskService', `Task plan step: ${taskId}/${stepId} → ${status}`);
|
|
81
|
-
return updated;
|
|
82
|
-
} catch (error) {
|
|
83
|
-
runtimeLog.error('TaskService', `Task plan step update failed: ${(error as Error).message}`);
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async cancel(taskId: string): Promise<Task> {
|
|
89
|
-
try {
|
|
90
|
-
const updated = await cancelTask(taskId, this.creds);
|
|
91
|
-
runtimeLog.info('TaskService', `Task cancelled: ${taskId}`);
|
|
92
|
-
return updated;
|
|
93
|
-
} catch (error) {
|
|
94
|
-
runtimeLog.error('TaskService', `Task cancel failed: ${(error as Error).message}`);
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async report(taskId: string, message = ''): Promise<Task> {
|
|
100
|
-
return reportTask(taskId, message, this.creds);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async setSatisfaction(taskId: string, satisfaction: 'positive' | 'negative'): Promise<Task> {
|
|
104
|
-
return setTaskSatisfaction(taskId, satisfaction, this.creds);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async count(filters: CountTasksFilters = {}): Promise<number> {
|
|
108
|
-
return countTasks(filters, this.creds);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { LlmResponse } from '../types.js';
|
|
2
|
-
import type { TelemetryClient } from '@ziggs-ai/api-client';
|
|
3
|
-
|
|
4
|
-
export function isTelemetryIngestEnabled(
|
|
5
|
-
explicit?: boolean,
|
|
6
|
-
): boolean {
|
|
7
|
-
if (explicit === false) return false;
|
|
8
|
-
if (explicit === true) return true;
|
|
9
|
-
const env = process.env.ZIGGS_TELEMETRY_INGEST;
|
|
10
|
-
if (env === '0' || env === 'false') return false;
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function usageFromLlmResponse(response: LlmResponse): {
|
|
15
|
-
tokensTotal: number;
|
|
16
|
-
tokensInput: number;
|
|
17
|
-
tokensOutput: number;
|
|
18
|
-
} {
|
|
19
|
-
const u = response.usage;
|
|
20
|
-
const tokensInput =
|
|
21
|
-
Number(u?.prompt_tokens ?? u?.promptTokens ?? 0) || 0;
|
|
22
|
-
const tokensOutput =
|
|
23
|
-
Number(u?.completion_tokens ?? u?.completionTokens ?? 0) || 0;
|
|
24
|
-
const tokensTotal =
|
|
25
|
-
Number(u?.total_tokens ?? u?.totalTokens ?? 0) ||
|
|
26
|
-
tokensInput + tokensOutput;
|
|
27
|
-
return { tokensTotal, tokensInput, tokensOutput };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function buildLlmIngestPayload(
|
|
31
|
-
response: LlmResponse,
|
|
32
|
-
ctx: { sessionId?: string; durationMs: number; runId?: string; stateId?: string },
|
|
33
|
-
): Record<string, unknown> {
|
|
34
|
-
const { tokensTotal, tokensInput, tokensOutput } =
|
|
35
|
-
usageFromLlmResponse(response);
|
|
36
|
-
const chatId = ctx.sessionId ?? null;
|
|
37
|
-
return {
|
|
38
|
-
source: 'agent',
|
|
39
|
-
chatId,
|
|
40
|
-
sessionId: chatId,
|
|
41
|
-
execution: {
|
|
42
|
-
llmCallsTotal: 1,
|
|
43
|
-
tokensTotal,
|
|
44
|
-
tokensInput,
|
|
45
|
-
tokensOutput,
|
|
46
|
-
...(tokensTotal > 0 ? { tokensPerLlmCall: [tokensTotal] } : {}),
|
|
47
|
-
},
|
|
48
|
-
resource: { durationMs: Math.max(0, Math.round(ctx.durationMs)) },
|
|
49
|
-
meta: {
|
|
50
|
-
effect: 'llm-call',
|
|
51
|
-
...(ctx.runId ? { runId: ctx.runId } : {}),
|
|
52
|
-
...(ctx.stateId ? { stateId: ctx.stateId } : {}),
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function buildToolIngestPayload(
|
|
58
|
-
ctx: {
|
|
59
|
-
sessionId: string;
|
|
60
|
-
tool: string;
|
|
61
|
-
durationMs: number;
|
|
62
|
-
ok: boolean;
|
|
63
|
-
runId?: string;
|
|
64
|
-
stateId?: string;
|
|
65
|
-
},
|
|
66
|
-
): Record<string, unknown> {
|
|
67
|
-
return {
|
|
68
|
-
source: 'agent',
|
|
69
|
-
chatId: ctx.sessionId,
|
|
70
|
-
sessionId: ctx.sessionId,
|
|
71
|
-
execution: { executionLoops: 1 },
|
|
72
|
-
resource: { durationMs: Math.max(0, Math.round(ctx.durationMs)) },
|
|
73
|
-
meta: {
|
|
74
|
-
effect: 'tool-call',
|
|
75
|
-
tool: ctx.tool,
|
|
76
|
-
ok: ctx.ok,
|
|
77
|
-
...(ctx.runId ? { runId: ctx.runId } : {}),
|
|
78
|
-
...(ctx.stateId ? { stateId: ctx.stateId } : {}),
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Fire-and-forget; never throws to the effect handler. */
|
|
84
|
-
export function sendTelemetry(
|
|
85
|
-
client: TelemetryClient | undefined,
|
|
86
|
-
payload: Record<string, unknown>,
|
|
87
|
-
enabled: boolean,
|
|
88
|
-
): void {
|
|
89
|
-
if (!enabled || !client) return;
|
|
90
|
-
void client.send(payload).catch(() => {});
|
|
91
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import type { AgreementService } from '../../agreements/AgreementService.js';
|
|
2
|
-
import type { TaskService } from '../../tasks/TaskService.js';
|
|
3
|
-
import {
|
|
4
|
-
applyFleetCounterPricing,
|
|
5
|
-
applyFleetPricingForProtocol,
|
|
6
|
-
} from '../../../pricing/fleetDefaults.js';
|
|
7
|
-
|
|
8
|
-
// Map legacy task-state aliases onto the canonical set.
|
|
9
|
-
function normalizeState(state: string): string {
|
|
10
|
-
if (state === 'done') return 'completed';
|
|
11
|
-
if (state === 'error') return 'failed';
|
|
12
|
-
return state;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface Services {
|
|
16
|
-
agreementService: AgreementService;
|
|
17
|
-
taskService: TaskService;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface ProtocolPayload {
|
|
21
|
-
operation?: string;
|
|
22
|
-
agreementId?: string;
|
|
23
|
-
description?: string;
|
|
24
|
-
proposedTo?: string;
|
|
25
|
-
executorId?: string;
|
|
26
|
-
action?: 'approve' | 'reject';
|
|
27
|
-
price?: number;
|
|
28
|
-
lifecycle?: string;
|
|
29
|
-
expiresAt?: string;
|
|
30
|
-
maxExecutions?: number;
|
|
31
|
-
agreementDescription?: string;
|
|
32
|
-
parentAgreementId?: string;
|
|
33
|
-
parentTaskId?: string;
|
|
34
|
-
taskId?: string;
|
|
35
|
-
stepId?: string;
|
|
36
|
-
assigneeId?: string;
|
|
37
|
-
status?: string;
|
|
38
|
-
result?: unknown;
|
|
39
|
-
plan?: unknown;
|
|
40
|
-
planReviewTiming?: string;
|
|
41
|
-
requireMidWorkPlanAck?: boolean;
|
|
42
|
-
engagementKind?: 'hire' | 'service';
|
|
43
|
-
subtasks?: (string | { description?: string })[];
|
|
44
|
-
[key: string]: unknown;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function dispatchProtocolOp(
|
|
48
|
-
services: Services,
|
|
49
|
-
payload: ProtocolPayload,
|
|
50
|
-
chatId: string | null,
|
|
51
|
-
agents: unknown[] = [],
|
|
52
|
-
actingAgentId: string | null = null,
|
|
53
|
-
): Promise<unknown> {
|
|
54
|
-
if (!payload?.operation) return null;
|
|
55
|
-
const { operation } = payload;
|
|
56
|
-
const { agreementService, taskService } = services;
|
|
57
|
-
const actorId = actingAgentId?.trim() || null;
|
|
58
|
-
|
|
59
|
-
switch (operation) {
|
|
60
|
-
case 'agreement-propose':
|
|
61
|
-
return proposeAgreement(services, payload, chatId, agents, actorId);
|
|
62
|
-
case 'agreement-subcontract':
|
|
63
|
-
return subcontractAgreement(services, payload, chatId, agents, actorId);
|
|
64
|
-
case 'agreement-respond':
|
|
65
|
-
if (!payload.agreementId || !payload.action) return null;
|
|
66
|
-
return agreementService.respond(payload.agreementId, payload.action);
|
|
67
|
-
case 'agreement-counter-proposal':
|
|
68
|
-
if (!payload.agreementId) return null;
|
|
69
|
-
{
|
|
70
|
-
const counterPayload =
|
|
71
|
-
actorId != null
|
|
72
|
-
? applyFleetCounterPricing(payload, actorId)
|
|
73
|
-
: payload;
|
|
74
|
-
return agreementService.counter(payload.agreementId, {
|
|
75
|
-
price: counterPayload.price,
|
|
76
|
-
agreementDescription: counterPayload.agreementDescription,
|
|
77
|
-
expiresAt: counterPayload.expiresAt,
|
|
78
|
-
lifecycle: counterPayload.lifecycle,
|
|
79
|
-
maxExecutions: counterPayload.maxExecutions,
|
|
80
|
-
description: counterPayload.description,
|
|
81
|
-
plan: counterPayload.plan,
|
|
82
|
-
planReviewTiming: counterPayload.planReviewTiming as import('@ziggs-ai/api-client').PlanReviewTiming | undefined,
|
|
83
|
-
requireMidWorkPlanAck: counterPayload.requireMidWorkPlanAck,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
case 'agreement-check-proposal':
|
|
87
|
-
if (!payload.agreementId) return null;
|
|
88
|
-
return agreementService.getStatus(payload.agreementId);
|
|
89
|
-
case 'agreement-revoke':
|
|
90
|
-
if (!payload.agreementId) return null;
|
|
91
|
-
return agreementService.revoke(payload.agreementId);
|
|
92
|
-
case 'task-spawn':
|
|
93
|
-
if (!payload.agreementId || !payload.description) return null;
|
|
94
|
-
return taskService.spawnUnderAgreement(payload.agreementId, {
|
|
95
|
-
description: payload.description,
|
|
96
|
-
parentTaskId: payload.parentTaskId,
|
|
97
|
-
plan: payload.plan,
|
|
98
|
-
planReviewTiming: payload.planReviewTiming,
|
|
99
|
-
requireMidWorkPlanAck: payload.requireMidWorkPlanAck,
|
|
100
|
-
assigneeId: payload.assigneeId,
|
|
101
|
-
inputArtifactIds: Array.isArray(payload.inputArtifactIds)
|
|
102
|
-
? (payload.inputArtifactIds as string[])
|
|
103
|
-
: undefined,
|
|
104
|
-
});
|
|
105
|
-
case 'task-update':
|
|
106
|
-
if (!payload.taskId || !payload.status) return null;
|
|
107
|
-
return taskService.updateState(payload.taskId, normalizeState(payload.status) as Parameters<typeof taskService.updateState>[1], payload.result);
|
|
108
|
-
case 'task-update-plan-step':
|
|
109
|
-
if (!payload.taskId) throw new Error('task-update-plan-step requires `taskId`');
|
|
110
|
-
if (!payload.stepId) throw new Error('task-update-plan-step requires `stepId`');
|
|
111
|
-
if (!payload.status) throw new Error('task-update-plan-step requires `status`');
|
|
112
|
-
return taskService.updatePlanStep(payload.taskId, payload.stepId, payload.status, payload.result);
|
|
113
|
-
default:
|
|
114
|
-
throw new Error(`Unknown protocol operation: ${operation}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async function proposeAgreement(
|
|
119
|
-
services: Services,
|
|
120
|
-
payload: ProtocolPayload,
|
|
121
|
-
chatId: string | null,
|
|
122
|
-
_agents: unknown[],
|
|
123
|
-
actingAgentId: string | null,
|
|
124
|
-
): Promise<unknown> {
|
|
125
|
-
if (!payload.description) throw new Error('agreement-propose requires `description`');
|
|
126
|
-
if (!payload.proposedTo) throw new Error('agreement-propose requires `proposedTo` (userId or agentId). To spawn a task under an existing agreement, use `task_spawn` instead.');
|
|
127
|
-
const priced = applyFleetPricingForProtocol('agreement-propose', payload, actingAgentId);
|
|
128
|
-
const { operation: _op, ...fields } = priced;
|
|
129
|
-
return services.agreementService.propose({ ...fields, chatId } as Parameters<typeof services.agreementService.propose>[0]);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function subcontractAgreement(
|
|
133
|
-
services: Services,
|
|
134
|
-
payload: ProtocolPayload,
|
|
135
|
-
chatId: string | null,
|
|
136
|
-
_agents: unknown[],
|
|
137
|
-
actingAgentId: string | null,
|
|
138
|
-
): Promise<unknown> {
|
|
139
|
-
if (!payload.description || !payload.executorId) return null;
|
|
140
|
-
const priced = applyFleetPricingForProtocol('agreement-subcontract', payload, actingAgentId);
|
|
141
|
-
const { operation: _op, ...fields } = priced;
|
|
142
|
-
return services.agreementService.delegate({ ...fields, chatId } as Parameters<typeof services.agreementService.delegate>[0]);
|
|
143
|
-
}
|
|
144
|
-
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { defineTool, type ToolDefinition } from '../../../tools/defineTool.js';
|
|
2
|
-
import { dispatchProtocolOp } from './protocolRunner.js';
|
|
3
|
-
import type { AgreementService } from '../../agreements/AgreementService.js';
|
|
4
|
-
import type { TaskService } from '../../tasks/TaskService.js';
|
|
5
|
-
|
|
6
|
-
interface ToolContext extends Record<string, unknown> {
|
|
7
|
-
taskService: TaskService;
|
|
8
|
-
agreementService: AgreementService;
|
|
9
|
-
chatId?: string | null;
|
|
10
|
-
agents?: unknown[];
|
|
11
|
-
/** Acting agent (ZIG-368 default pricing). */
|
|
12
|
-
agentId?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function handlerFor(operation: string) {
|
|
16
|
-
return async (args: Record<string, unknown>, ctx: Record<string, unknown>): Promise<unknown> => {
|
|
17
|
-
const c = ctx as ToolContext;
|
|
18
|
-
if (!c.taskService) throw new Error('taskService missing from tool context (expected when running under Agent)');
|
|
19
|
-
if (!c.agreementService) throw new Error('agreementService missing from tool context (expected when running under Agent)');
|
|
20
|
-
const result = await dispatchProtocolOp(
|
|
21
|
-
{ taskService: c.taskService, agreementService: c.agreementService },
|
|
22
|
-
{ operation, ...args },
|
|
23
|
-
c.chatId ?? null,
|
|
24
|
-
c.agents ?? [],
|
|
25
|
-
typeof c.agentId === 'string' ? c.agentId : null,
|
|
26
|
-
);
|
|
27
|
-
if (result == null) throw new Error(`Operation ${operation} returned no result`);
|
|
28
|
-
return result;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const agreementProposeTool: ToolDefinition = defineTool(
|
|
33
|
-
'agreement_propose',
|
|
34
|
-
{ description: { type: 'string', required: true }, proposedTo: { type: 'string', required: true }, engagementKind: { type: 'string', enum: ['hire', 'service'], description: 'Contract type. Defaults to service when omitted.' }, parentAgreementId: 'string', parentTaskId: 'string', payerId: 'string', providerId: 'string', price: 'number', lifecycle: 'string', expiresAt: 'string', maxExecutions: 'number', agreementDescription: 'string', plan: { type: 'object' }, planReviewTiming: 'string', requireMidWorkPlanAck: 'boolean' },
|
|
35
|
-
handlerFor('agreement-propose'),
|
|
36
|
-
{ description: 'Propose a contract to a user, agent, or as an open broadcast. For a broadcast set proposedTo="everyone" (fully public — any agent may claim) or proposedTo="org" (scoped to your org — only members of your org see and claim it). engagementKind defaults to service.', isAgreementCreation: true },
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
export const agreementSubcontractTool: ToolDefinition = defineTool(
|
|
40
|
-
'agreement_subcontract',
|
|
41
|
-
{ description: { type: 'string', required: true }, executorId: { type: 'string', required: true }, parentAgreementId: { type: 'string', required: true }, parentTaskId: 'string', payerId: 'string', price: 'number', lifecycle: 'string', expiresAt: 'string', maxExecutions: 'number', agreementDescription: 'string', plan: { type: 'object' }, planReviewTiming: 'string', requireMidWorkPlanAck: 'boolean' },
|
|
42
|
-
handlerFor('agreement-subcontract'),
|
|
43
|
-
{ description: 'Delegate work to another agent under an existing parent agreement. Requires parentAgreementId.', isAgreementCreation: true },
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
export const agreementRespondTool: ToolDefinition = defineTool(
|
|
47
|
-
'agreement_respond',
|
|
48
|
-
{ agreementId: { type: 'string', required: true }, action: { type: 'string', required: true, enum: ['approve', 'reject'] } },
|
|
49
|
-
handlerFor('agreement-respond'),
|
|
50
|
-
{ description: 'Approve or reject a pending agreement proposal.' },
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
export const taskUpdateTool: ToolDefinition = defineTool(
|
|
54
|
-
'task_update',
|
|
55
|
-
{ taskId: { type: 'string', required: true }, status: { type: 'string', required: true, enum: ['completed', 'failed', 'cancelled'] }, result: 'string' },
|
|
56
|
-
handlerFor('task-update'),
|
|
57
|
-
{ description: 'Transition a task to completed, failed, or cancelled. Include a result string for completed tasks.' },
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
export const agreementCounterProposalTool: ToolDefinition = defineTool(
|
|
61
|
-
'agreement_counter_proposal',
|
|
62
|
-
{ agreementId: { type: 'string', required: true }, price: 'number', agreementDescription: 'string', expiresAt: 'string', lifecycle: 'string', maxExecutions: 'number', description: 'string', plan: { type: 'object' }, planReviewTiming: 'string', requireMidWorkPlanAck: 'boolean' },
|
|
63
|
-
handlerFor('agreement-counter-proposal'),
|
|
64
|
-
{ description: 'Counter a pending proposal with revised terms instead of approving or rejecting. Check status first with agreement_check_proposal.' },
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
export const agreementCheckProposalTool: ToolDefinition = defineTool(
|
|
68
|
-
'agreement_check_proposal',
|
|
69
|
-
{ agreementId: { type: 'string', required: true } },
|
|
70
|
-
handlerFor('agreement-check-proposal'),
|
|
71
|
-
{ description: 'Read the current proposal status for an agreement (pending, approved, rejected, countered, expired).' },
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
export const agreementRevokeTool: ToolDefinition = defineTool(
|
|
75
|
-
'agreement_revoke',
|
|
76
|
-
{ agreementId: { type: 'string', required: true } },
|
|
77
|
-
handlerFor('agreement-revoke'),
|
|
78
|
-
{ description: 'Revoke a pending proposal you created so it can no longer be approved. Use when the user has clearly moved on to a different request before responding to the previous proposal card.' },
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
export const taskUpdatePlanStepTool: ToolDefinition = defineTool(
|
|
82
|
-
'task_update_plan_step',
|
|
83
|
-
{ taskId: { type: 'string', required: true }, stepId: { type: 'string', required: true }, status: { type: 'string', required: true }, result: 'string' },
|
|
84
|
-
handlerFor('task-update-plan-step'),
|
|
85
|
-
{ description: "Update the status of a single step within a task's plan." },
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
export const taskSpawnTool: ToolDefinition = defineTool(
|
|
89
|
-
'task_spawn',
|
|
90
|
-
{ agreementId: { type: 'string', required: true }, description: { type: 'string', required: true }, parentTaskId: 'string', assigneeId: { type: 'string', description: 'Explicitly hand this task to one specific agent (e.g. a worker your orchestrator selected via agent search) instead of leaving it unassigned. Must be a party on the agreement (payer, provider, creator, or creator agent).' }, inputArtifactIds: { type: 'array', items: { type: 'string' }, description: 'ZIG-734: prior-step output artifact handles for structured input links.' }, plan: { type: 'object' }, planReviewTiming: 'string', requireMidWorkPlanAck: 'boolean' },
|
|
91
|
-
handlerFor('task-spawn'),
|
|
92
|
-
{ description: 'Spawn a new task under an existing approved agreement. Use when the contract is already in place. Pass assigneeId to delegate the task to a specific agent rather than leaving it open.' },
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
export const PROTOCOL_TOOLS: ToolDefinition[] = [
|
|
96
|
-
agreementProposeTool, agreementSubcontractTool,
|
|
97
|
-
agreementRespondTool, agreementCounterProposalTool, agreementCheckProposalTool, agreementRevokeTool,
|
|
98
|
-
taskSpawnTool, taskUpdateTool, taskUpdatePlanStepTool,
|
|
99
|
-
];
|