@ziggs-ai/agent-sdk 0.9.0 → 0.10.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 +23 -0
- package/dist/AgentHost.d.ts +53 -14
- package/dist/AgentHost.js +137 -8
- package/dist/agent/ClaudeSdkAgent.d.ts +27 -2
- package/dist/agent/ClaudeSdkAgent.js +151 -78
- package/dist/agent/claudeSdkTools.js +39 -11
- package/dist/context/applyEffects.js +4 -3
- package/dist/defineAgent.js +4 -1
- package/dist/formatters/HistoryFormatter.js +11 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/ingress/normalizeIncoming.d.ts +5 -0
- package/dist/ingress/normalizeIncoming.js +23 -1
- package/dist/pricing/fleetDefaults.d.ts +0 -3
- package/dist/pricing/fleetDefaults.js +0 -6
- package/dist/runtime/PromptBuilder.js +9 -5
- package/dist/runtime/bootstrapCtx.js +6 -8
- package/dist/runtime/buildOutcome.d.ts +9 -1
- package/dist/runtime/buildOutcome.js +29 -6
- package/dist/runtime/runTurn.js +1 -1
- package/dist/runtime/taskBookkeeping.d.ts +0 -2
- package/dist/runtime/taskBookkeeping.js +0 -6
- package/dist/runtime/taskIntake.js +6 -4
- package/dist/runtime/wakeWriteKeys.js +23 -21
- package/dist/server/ConnectionPool.d.ts +10 -52
- package/dist/server/ConnectionPool.js +26 -57
- package/dist/server/EventQueue.d.ts +6 -0
- package/dist/server/EventQueue.js +21 -6
- package/dist/server/SeenMessages.d.ts +7 -0
- package/dist/server/SeenMessages.js +15 -0
- package/dist/server/ZiggsEffectHandler.d.ts +1 -0
- package/dist/server/ZiggsEffectHandler.js +21 -11
- package/dist/server/inboxLoop.d.ts +17 -2
- package/dist/server/inboxLoop.js +92 -16
- package/dist/server/polls/PollKind.d.ts +72 -0
- package/dist/server/polls/PollKind.js +53 -0
- package/dist/server/polls/PollRunner.d.ts +62 -0
- package/dist/server/polls/PollRunner.js +138 -0
- package/dist/server/questMatch.d.ts +5 -0
- package/dist/server/questMatch.js +14 -0
- package/dist/server/runLauncher.d.ts +0 -6
- package/dist/server/runLauncher.js +54 -27
- package/dist/server/tasks/TaskService.d.ts +2 -11
- package/dist/server/tools/tier1/protocolRunner.d.ts +3 -1
- package/dist/server/tools/tier1/protocolRunner.js +40 -41
- package/dist/server/tools/tier1/protocolTools.js +23 -13
- package/dist/server/tools/tier2/connectionTools.js +12 -1
- package/dist/tasks/protocolRegistry.d.ts +27 -0
- package/dist/tasks/protocolRegistry.js +36 -0
- package/dist/tools/capabilityAdapter.js +12 -1
- package/dist/tools/recordReport.js +8 -4
- package/dist/types.d.ts +24 -11
- package/package.json +2 -2
- package/dist/server/staleBacklogGate.d.ts +0 -57
- package/dist/server/staleBacklogGate.js +0 -100
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PollRunner — executes declared polls for a whole fleet, outside any host.
|
|
3
|
+
*
|
|
4
|
+
* Every host already long-polls its own Ziggs inbox; this applies the same wake
|
|
5
|
+
* discipline to the sources Ziggs cannot see — mailboxes, feeds, whatever a
|
|
6
|
+
* PollKind can ask. It runs in the launcher rather than inside any AgentHost
|
|
7
|
+
* because none of it belongs to a host's message loop: a poll is per
|
|
8
|
+
* (agent, binding) and carries its own interval, backoff and backpressure.
|
|
9
|
+
*
|
|
10
|
+
* One loop per (agent, binding), and each loop AWAITS its own wake before
|
|
11
|
+
* scheduling the next tick. That is the whole backpressure story: while an
|
|
12
|
+
* agent is still dealing with what it was woken for, its next poll has not
|
|
13
|
+
* happened yet, so it cannot be woken twice for the same thing. No in-flight
|
|
14
|
+
* bookkeeping, no dedup table — the source is authoritative and a poll that
|
|
15
|
+
* has not run yet cannot report anything stale.
|
|
16
|
+
*
|
|
17
|
+
* A failing source backs off exponentially and recovers on the first success.
|
|
18
|
+
* Without it a source that is down is hit at full rate indefinitely, which is
|
|
19
|
+
* how you get rate-limited by the thing you were trying to read.
|
|
20
|
+
*/
|
|
21
|
+
import { runtimeLog } from '../../shared/runtimeLog.js';
|
|
22
|
+
import { declaredPolls } from './PollKind.js';
|
|
23
|
+
export class PollRunner {
|
|
24
|
+
pool;
|
|
25
|
+
operatorKey;
|
|
26
|
+
label;
|
|
27
|
+
maxBackoffMs;
|
|
28
|
+
wakeTimeoutMs;
|
|
29
|
+
loops = [];
|
|
30
|
+
running = false;
|
|
31
|
+
constructor({ pool, registry, agents, operatorKey, defaultIntervalMs = 60_000, maxBackoffMs = 15 * 60_000, wakeTimeoutMs = Number(process.env.CLAUDE_SDK_TICK_TIMEOUT_MS ?? 300_000), label = 'PollRunner', }) {
|
|
32
|
+
this.pool = pool;
|
|
33
|
+
this.operatorKey = operatorKey;
|
|
34
|
+
this.label = label;
|
|
35
|
+
this.maxBackoffMs = maxBackoffMs;
|
|
36
|
+
this.wakeTimeoutMs = wakeTimeoutMs;
|
|
37
|
+
for (const config of agents) {
|
|
38
|
+
const agentId = config['agentId'];
|
|
39
|
+
if (typeof agentId !== 'string' || !agentId)
|
|
40
|
+
continue;
|
|
41
|
+
for (const binding of declaredPolls(config)) {
|
|
42
|
+
const kind = registry.get(binding.kind);
|
|
43
|
+
if (!kind) {
|
|
44
|
+
// Loud, and does not stop the fleet: an agent declaring a kind nobody
|
|
45
|
+
// registered would otherwise sit there looking healthy and never wake.
|
|
46
|
+
runtimeLog.warn(label, `${agentId} declares unknown poll kind "${binding.kind}" — it will never be woken by it (registered: ${registry.ids.join(', ') || 'none'})`);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (!binding.chatId) {
|
|
50
|
+
// Refused at startup rather than dropped per-wake: without a lane the
|
|
51
|
+
// host's session resolver returns null and the wake disappears with
|
|
52
|
+
// only a debug line, which looks exactly like "the source is quiet".
|
|
53
|
+
runtimeLog.warn(label, `${agentId} declares poll "${binding.kind}" without a chatId — refusing to register it, because every wake would be silently dropped`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
this.loops.push({
|
|
57
|
+
agentId,
|
|
58
|
+
binding,
|
|
59
|
+
kind,
|
|
60
|
+
intervalMs: kind.intervalMs ?? defaultIntervalMs,
|
|
61
|
+
chatId: binding.chatId,
|
|
62
|
+
timer: null,
|
|
63
|
+
failures: 0,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
get size() {
|
|
69
|
+
return this.loops.length;
|
|
70
|
+
}
|
|
71
|
+
start() {
|
|
72
|
+
if (this.running)
|
|
73
|
+
return;
|
|
74
|
+
this.running = true;
|
|
75
|
+
if (!this.loops.length)
|
|
76
|
+
return;
|
|
77
|
+
for (const loop of this.loops)
|
|
78
|
+
this.schedule(loop, 0);
|
|
79
|
+
runtimeLog.info(this.label, `started — ${this.loops.length} poll(s): ${this.loops.map((l) => `${l.agentId}:${l.kind.id}`).join(', ')}`);
|
|
80
|
+
}
|
|
81
|
+
stop() {
|
|
82
|
+
this.running = false;
|
|
83
|
+
for (const loop of this.loops) {
|
|
84
|
+
if (loop.timer)
|
|
85
|
+
clearTimeout(loop.timer);
|
|
86
|
+
loop.timer = null;
|
|
87
|
+
}
|
|
88
|
+
runtimeLog.info(this.label, 'stopped');
|
|
89
|
+
}
|
|
90
|
+
schedule(loop, delayMs = this.nextDelay(loop)) {
|
|
91
|
+
if (!this.running)
|
|
92
|
+
return;
|
|
93
|
+
loop.timer = setTimeout(() => void this.tick(loop), delayMs);
|
|
94
|
+
}
|
|
95
|
+
/** Interval while healthy; doubling up to the ceiling while failing. */
|
|
96
|
+
nextDelay(loop) {
|
|
97
|
+
if (loop.failures === 0)
|
|
98
|
+
return loop.intervalMs;
|
|
99
|
+
return Math.min(loop.intervalMs * 2 ** loop.failures, this.maxBackoffMs);
|
|
100
|
+
}
|
|
101
|
+
async tick(loop) {
|
|
102
|
+
if (!this.running)
|
|
103
|
+
return;
|
|
104
|
+
let result;
|
|
105
|
+
try {
|
|
106
|
+
result = await loop.kind.poll(loop.binding, {
|
|
107
|
+
agentId: loop.agentId,
|
|
108
|
+
...(this.operatorKey ? { operatorKey: this.operatorKey } : {}),
|
|
109
|
+
});
|
|
110
|
+
loop.failures = 0;
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
loop.failures += 1;
|
|
114
|
+
runtimeLog.error(this.label, `${loop.agentId}:${loop.kind.id} source failed (${loop.failures}x, next in ${this.nextDelay(loop)}ms): ${err.message}`);
|
|
115
|
+
this.schedule(loop);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (result?.actionable) {
|
|
119
|
+
const hint = result.hint ?? `New work from ${loop.kind.id}. Check it.`;
|
|
120
|
+
try {
|
|
121
|
+
// Awaited on purpose — see the header. The next tick waits for the
|
|
122
|
+
// agent to finish, which is what stops a double wake. chatId is what
|
|
123
|
+
// makes the wake resolve to a lane at all, and wakeTimeoutMs has to
|
|
124
|
+
// outlast a real multi-turn wake or the await stops meaning anything.
|
|
125
|
+
await this.pool.sendTo(loop.agentId, hint, { chatId: loop.chatId, pollKind: loop.kind.id }, { timeoutMs: this.wakeTimeoutMs });
|
|
126
|
+
runtimeLog.info(this.label, `woke ${loop.agentId} for ${loop.kind.id}`);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
// Reported separately from a source failure: the source is fine, the
|
|
130
|
+
// agent is not. Still backs off, because hammering a wedged agent helps
|
|
131
|
+
// nobody.
|
|
132
|
+
loop.failures += 1;
|
|
133
|
+
runtimeLog.error(this.label, `${loop.agentId} wake failed (${loop.failures}x, next in ${this.nextDelay(loop)}ms): ${err.message}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
this.schedule(loop);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZIG-1185 — exact-match triage for marketplace quests.
|
|
3
|
+
* Empty match never hits (token-safe default). Comparison is exact after trim.
|
|
4
|
+
*/
|
|
5
|
+
export function questExactMatch(match, tags) {
|
|
6
|
+
const needle = typeof match === 'string' ? match.trim() : '';
|
|
7
|
+
if (!needle)
|
|
8
|
+
return false;
|
|
9
|
+
for (const t of tags) {
|
|
10
|
+
if (typeof t === 'string' && t.trim() === needle)
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
@@ -15,14 +15,8 @@ interface SingleOptions {
|
|
|
15
15
|
onShutdown?: () => Promise<void>;
|
|
16
16
|
}
|
|
17
17
|
interface FleetOptions extends SingleOptions {
|
|
18
|
-
wsUrl?: string;
|
|
19
18
|
agentMeta?: Record<string, unknown>[];
|
|
20
19
|
primary?: AgentConfig | ((pool: ConnectionPool) => AgentConfig);
|
|
21
|
-
preStart?: string[];
|
|
22
|
-
poolOptions?: {
|
|
23
|
-
maxActive?: number;
|
|
24
|
-
idleTimeoutMs?: number;
|
|
25
|
-
};
|
|
26
20
|
}
|
|
27
21
|
export declare function runLauncher(configOrConfigs: AgentConfig | AgentConfig[], opts?: FleetOptions): Promise<unknown>;
|
|
28
22
|
export {};
|
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import { ConnectionPool } from './ConnectionPool.js';
|
|
2
2
|
import { AgentHost } from '../AgentHost.js';
|
|
3
3
|
import { createHealthServer } from './createHealthServer.js';
|
|
4
|
-
import { createStaleBacklogGate, resolveReplayPolicy } from './staleBacklogGate.js';
|
|
5
4
|
import { boundKeyFleetWarning } from '../shared/operatorKeyClaims.js';
|
|
6
5
|
import { runtimeLog } from '../shared/runtimeLog.js';
|
|
6
|
+
import { PollRegistry } from './polls/PollKind.js';
|
|
7
|
+
import { PollRunner } from './polls/PollRunner.js';
|
|
8
|
+
/**
|
|
9
|
+
* Collect the poll kinds the agents themselves ship and start a runner for
|
|
10
|
+
* whatever they declared. This lives in the launcher, not in a caller's
|
|
11
|
+
* bootstrap file: an agent that declares `polls` and gets no runner sees no
|
|
12
|
+
* error and simply never wakes, which is indistinguishable from a quiet source.
|
|
13
|
+
* Every launcher path therefore executes polls, or refuses loudly.
|
|
14
|
+
*/
|
|
15
|
+
function startDeclaredPolls(configs, pool, { operatorKey, label }) {
|
|
16
|
+
const registry = new PollRegistry();
|
|
17
|
+
for (const cfg of configs) {
|
|
18
|
+
for (const kind of (cfg.pollKinds ?? [])) {
|
|
19
|
+
// Two agents may legitimately share a source; first registration wins and
|
|
20
|
+
// a duplicate id is not an error worth killing a fleet launch over.
|
|
21
|
+
if (!registry.get(kind.id))
|
|
22
|
+
registry.register(kind);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const runner = new PollRunner({
|
|
26
|
+
pool,
|
|
27
|
+
registry,
|
|
28
|
+
agents: configs,
|
|
29
|
+
label: `${label}-polls`,
|
|
30
|
+
...(operatorKey ? { operatorKey } : {}),
|
|
31
|
+
});
|
|
32
|
+
if (runner.size === 0)
|
|
33
|
+
return null;
|
|
34
|
+
runner.start();
|
|
35
|
+
return runner;
|
|
36
|
+
}
|
|
7
37
|
export async function runLauncher(configOrConfigs, opts = {}) {
|
|
8
38
|
if (Array.isArray(configOrConfigs))
|
|
9
39
|
return runFleet(configOrConfigs, opts);
|
|
@@ -21,8 +51,11 @@ async function runSingle(config, { operatorKey, label = 'agent', port = process.
|
|
|
21
51
|
runtimeLog.warn(label, `Agent failed to connect at startup: ${err.message} — will retry`);
|
|
22
52
|
}
|
|
23
53
|
const server = healthServer ? createHealthServer({ port: Number(port), label }) : null;
|
|
54
|
+
// One agent, so the "pool" is just this host.
|
|
55
|
+
const pollRunner = startDeclaredPolls([decorated], { sendTo: (_agentId, text, metadata) => agent.handleMessage(text, metadata ?? {}) }, { label, ...(effectiveKey ? { operatorKey: effectiveKey } : {}) });
|
|
24
56
|
process.on('SIGTERM', async () => {
|
|
25
57
|
runtimeLog.info(label, 'SIGTERM — shutting down');
|
|
58
|
+
pollRunner?.stop();
|
|
26
59
|
agent.disconnect();
|
|
27
60
|
await agent.drain(30_000);
|
|
28
61
|
try {
|
|
@@ -36,14 +69,8 @@ async function runSingle(config, { operatorKey, label = 'agent', port = process.
|
|
|
36
69
|
});
|
|
37
70
|
return { agent, healthServer: server ?? undefined };
|
|
38
71
|
}
|
|
39
|
-
async function runFleet(configs, { operatorKey,
|
|
40
|
-
|
|
41
|
-
// (FLEET_REPLAY_MAX_AGE / FLEET_REPLAY_STALE); an explicit
|
|
42
|
-
// poolOptions.shouldLazyStart wins.
|
|
43
|
-
const pool = new ConnectionPool({
|
|
44
|
-
shouldLazyStart: createStaleBacklogGate({ ...resolveReplayPolicy(), label }),
|
|
45
|
-
...poolOptions,
|
|
46
|
-
});
|
|
72
|
+
async function runFleet(configs, { operatorKey, port = process.env.PORT || 8080, healthServer = true, label = 'launcher', agentMeta, primary: primaryConfig, onShutdown, } = {}) {
|
|
73
|
+
const pool = new ConnectionPool();
|
|
47
74
|
const effectiveKey = operatorKey ?? process.env.ZIGGS_OPERATOR_KEY;
|
|
48
75
|
const decoratedConfigs = effectiveKey
|
|
49
76
|
? configs.map(c => (c.operatorKey ? c : { ...c, operatorKey: effectiveKey }))
|
|
@@ -63,10 +90,6 @@ async function runFleet(configs, { operatorKey, wsUrl = process.env.WS_URL, port
|
|
|
63
90
|
const boundWarning = boundKeyFleetWarning(controlKey, pool.size);
|
|
64
91
|
if (boundWarning)
|
|
65
92
|
runtimeLog.warn(label, boundWarning);
|
|
66
|
-
pool.startControl({ wsUrl, operatorKey: controlKey });
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
runtimeLog.warn(label, 'No operatorKey provided — skipping fleet inbox poll (no agents will be lazily started)');
|
|
70
93
|
}
|
|
71
94
|
let primary = null;
|
|
72
95
|
if (resolvedPrimaryConfig) {
|
|
@@ -76,26 +99,30 @@ async function runFleet(configs, { operatorKey, wsUrl = process.env.WS_URL, port
|
|
|
76
99
|
runtimeLog.info(label, `Primary agent "${resolvedPrimaryConfig.name || resolvedPrimaryConfig.ownAgentId || 'primary'}" connected`);
|
|
77
100
|
}
|
|
78
101
|
catch (err) {
|
|
79
|
-
// Backend may not be ready yet —
|
|
80
|
-
// Don't crash the process
|
|
102
|
+
// Backend may not be ready yet — the inbox long-poll loop retries on
|
|
103
|
+
// the next pass. Don't crash the process.
|
|
81
104
|
runtimeLog.warn(label, `Primary agent "${resolvedPrimaryConfig.name || resolvedPrimaryConfig.ownAgentId || 'primary'}" failed to connect at startup: ${err.message} — will retry`);
|
|
82
105
|
}
|
|
83
106
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
// Every registered agent connects (ZIG-1108). There is no roster to consult
|
|
108
|
+
// and no reason to defer: an agent this launcher was handed is an agent it
|
|
109
|
+
// hosts, and each host's own inbox long-poll is the only wake signal needed.
|
|
110
|
+
await pool.connectAll();
|
|
111
|
+
const connected = pool.listActive().length;
|
|
112
|
+
if (connected < pool.size) {
|
|
113
|
+
// Say it loudly and with the number. A launcher that silently hosts fewer
|
|
114
|
+
// agents than it was given is exactly how three published, hireable agents
|
|
115
|
+
// ran with no host and nothing noticed (ZIG-1107).
|
|
116
|
+
runtimeLog.warn(label, `Only ${connected}/${pool.size} agent(s) connected — the rest are registered but unhosted`);
|
|
93
117
|
}
|
|
94
|
-
runtimeLog.info(label, `Ready — ${pool.size} agent(s)
|
|
95
|
-
|
|
118
|
+
runtimeLog.info(label, `Ready — ${connected}/${pool.size} agent(s) connected`);
|
|
119
|
+
const pollRunner = startDeclaredPolls(decoratedConfigs, pool, {
|
|
120
|
+
label,
|
|
121
|
+
...(effectiveKey ? { operatorKey: effectiveKey } : {}),
|
|
122
|
+
});
|
|
96
123
|
process.on('SIGTERM', async () => {
|
|
97
124
|
runtimeLog.info(label, 'SIGTERM — shutting down');
|
|
98
|
-
|
|
125
|
+
pollRunner?.stop();
|
|
99
126
|
primary?.disconnect?.();
|
|
100
127
|
await primary?.drain?.(30_000);
|
|
101
128
|
await pool.disconnectAll();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Task, type TaskState } from '@ziggs-ai/api-client';
|
|
2
|
-
import type { CountTasksFilters } from '@ziggs-ai/api-client';
|
|
2
|
+
import type { CountTasksFilters, CreateTaskData } from '@ziggs-ai/api-client';
|
|
3
3
|
export declare class TaskService {
|
|
4
4
|
private creds;
|
|
5
5
|
constructor(operatorKey: string, agentId: string);
|
|
@@ -7,16 +7,7 @@ export declare class TaskService {
|
|
|
7
7
|
getActiveTasksForAgent(agentId: string): Promise<Task[]>;
|
|
8
8
|
getActiveTasksForChat(chatId: string): Promise<Task[]>;
|
|
9
9
|
getSubtasks(parentTaskId: string): Promise<Task[]>;
|
|
10
|
-
spawnUnderAgreement(agreementId: string, taskData:
|
|
11
|
-
description: string;
|
|
12
|
-
parentTaskId?: string;
|
|
13
|
-
plan?: unknown;
|
|
14
|
-
planReviewTiming?: string;
|
|
15
|
-
requireMidWorkPlanAck?: boolean;
|
|
16
|
-
assigneeId?: string;
|
|
17
|
-
inputArtifactIds?: string[];
|
|
18
|
-
idempotencyKey?: string;
|
|
19
|
-
}): Promise<Task>;
|
|
10
|
+
spawnUnderAgreement(agreementId: string, taskData: Omit<CreateTaskData, 'agreementId'>): Promise<Task>;
|
|
20
11
|
updateState(taskId: string, state: TaskState, result?: unknown, idempotencyKey?: string): Promise<Task>;
|
|
21
12
|
updatePlanStep(taskId: string, stepId: string, status: string, result?: unknown): Promise<Task>;
|
|
22
13
|
cancel(taskId: string): Promise<Task>;
|
|
@@ -36,5 +36,7 @@ interface ProtocolPayload {
|
|
|
36
36
|
})[];
|
|
37
37
|
[key: string]: unknown;
|
|
38
38
|
}
|
|
39
|
-
export declare function dispatchProtocolOp(services: Services, payload: ProtocolPayload, chatId: string | null, agents?: unknown[], actingAgentId?: string | null, wakeKeys?: WakeWriteKeys | null
|
|
39
|
+
export declare function dispatchProtocolOp(services: Services, payload: ProtocolPayload, chatId: string | null, agents?: unknown[], actingAgentId?: string | null, wakeKeys?: WakeWriteKeys | null,
|
|
40
|
+
/** ZIG-1120 #8 — prefer the cached session snapshot over a fresh HTTP read. */
|
|
41
|
+
cachedAgreements?: unknown[]): Promise<unknown>;
|
|
40
42
|
export {};
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isBroadcastTarget, } from '@ziggs-ai/api-client';
|
|
2
2
|
import { applyFleetCounterPricing, applyFleetPricingForProtocol, } from '../../../pricing/fleetDefaults.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function shapeAgreementResult(agreement) {
|
|
8
|
-
if (!agreement)
|
|
9
|
-
return agreement;
|
|
10
|
-
return agreement.engagementKind === 'link' ? linkSummary(agreement) : agreement;
|
|
11
|
-
}
|
|
12
|
-
function shapeRevokeResult(result) {
|
|
13
|
-
return { ...result, agreement: shapeAgreementResult(result.agreement) };
|
|
14
|
-
}
|
|
3
|
+
// ZIG-1111: the link-summary rule lives in AgreementClient, at the point the
|
|
4
|
+
// document is parsed. Every verb here inherits it through the client instead of
|
|
5
|
+
// each one restating `engagementKind === 'link' ? linkSummary(a) : a` — which is
|
|
6
|
+
// how counter, fulfill and subcontract came to return the raw document.
|
|
15
7
|
// Map legacy task-state aliases onto the canonical set.
|
|
16
8
|
function normalizeState(state) {
|
|
17
9
|
if (state === 'done')
|
|
@@ -22,8 +14,14 @@ function normalizeState(state) {
|
|
|
22
14
|
}
|
|
23
15
|
// ZIG-793: the `plan` tool-schema is underspecified (`plan: {type:'object'}`,
|
|
24
16
|
// `planReviewTiming: 'string'`), so the LLM emits steps missing stepId/order and an
|
|
25
|
-
// out-of-enum planReviewTiming, which the backend DTO rejects. Normalize in-place
|
|
26
|
-
//
|
|
17
|
+
// out-of-enum planReviewTiming, which the backend DTO rejects. Normalize in-place
|
|
18
|
+
// before the write.
|
|
19
|
+
//
|
|
20
|
+
// ZIG-1095: task-spawn is the only op left that carries a plan. Propose, counter
|
|
21
|
+
// and subcontract used to run this too — and their plans were then dropped on the
|
|
22
|
+
// floor, since no agreement route has ever accepted one.
|
|
23
|
+
// Returns the clamped review timing rather than only writing it back, so the
|
|
24
|
+
// spawn call gets the narrowed type from the one place that does the clamping.
|
|
27
25
|
function normalizePlanInPlace(payload) {
|
|
28
26
|
const plan = payload.plan;
|
|
29
27
|
if (plan && Array.isArray(plan.steps)) {
|
|
@@ -41,16 +39,17 @@ function normalizePlanInPlace(payload) {
|
|
|
41
39
|
};
|
|
42
40
|
});
|
|
43
41
|
}
|
|
44
|
-
if (payload.planReviewTiming
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
if (payload.planReviewTiming === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
return payload.planReviewTiming === 'before_execution'
|
|
45
|
+
? 'before_execution'
|
|
46
|
+
: 'with_proposal';
|
|
49
47
|
}
|
|
50
|
-
export async function dispatchProtocolOp(services, payload, chatId, agents = [], actingAgentId = null, wakeKeys = null
|
|
48
|
+
export async function dispatchProtocolOp(services, payload, chatId, agents = [], actingAgentId = null, wakeKeys = null,
|
|
49
|
+
/** ZIG-1120 #8 — prefer the cached session snapshot over a fresh HTTP read. */
|
|
50
|
+
cachedAgreements) {
|
|
51
51
|
if (!payload?.operation)
|
|
52
52
|
return null;
|
|
53
|
-
normalizePlanInPlace(payload);
|
|
54
53
|
const { operation } = payload;
|
|
55
54
|
const { agreementService, taskService } = services;
|
|
56
55
|
const actorId = actingAgentId?.trim() || null;
|
|
@@ -58,20 +57,16 @@ export async function dispatchProtocolOp(services, payload, chatId, agents = [],
|
|
|
58
57
|
case 'agreement-propose':
|
|
59
58
|
return proposeAgreement(services, payload, chatId, agents, actorId, wakeKeys);
|
|
60
59
|
case 'agreement-subcontract':
|
|
61
|
-
return subcontractAgreement(services, payload, chatId, agents, actorId, wakeKeys);
|
|
60
|
+
return subcontractAgreement(services, payload, chatId, agents, actorId, wakeKeys, cachedAgreements);
|
|
62
61
|
case 'agreement-respond':
|
|
63
62
|
if (!payload.agreementId || !payload.action)
|
|
64
63
|
return null;
|
|
65
|
-
return
|
|
64
|
+
return agreementService.respond(payload.agreementId, payload.action);
|
|
66
65
|
case 'agreement-claim': {
|
|
67
66
|
// ZIG-1021: the one claim verb — quest, standing offer, or link invite.
|
|
68
67
|
if (!payload.agreementId)
|
|
69
68
|
throw new Error('agreement-claim requires `agreementId`');
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
...claimed,
|
|
73
|
-
agreement: shapeAgreementResult(claimed.agreement),
|
|
74
|
-
};
|
|
69
|
+
return await agreementService.claim(payload.agreementId);
|
|
75
70
|
}
|
|
76
71
|
case 'agreement-counter-proposal':
|
|
77
72
|
if (!payload.agreementId)
|
|
@@ -87,9 +82,6 @@ export async function dispatchProtocolOp(services, payload, chatId, agents = [],
|
|
|
87
82
|
lifecycle: counterPayload.lifecycle,
|
|
88
83
|
maxExecutions: counterPayload.maxExecutions,
|
|
89
84
|
description: counterPayload.description,
|
|
90
|
-
plan: counterPayload.plan,
|
|
91
|
-
planReviewTiming: counterPayload.planReviewTiming,
|
|
92
|
-
requireMidWorkPlanAck: counterPayload.requireMidWorkPlanAck,
|
|
93
85
|
});
|
|
94
86
|
}
|
|
95
87
|
case 'agreement-check-proposal':
|
|
@@ -99,16 +91,16 @@ export async function dispatchProtocolOp(services, payload, chatId, agents = [],
|
|
|
99
91
|
case 'agreement-revoke':
|
|
100
92
|
if (!payload.agreementId)
|
|
101
93
|
return null;
|
|
102
|
-
return
|
|
94
|
+
return await agreementService.revoke(payload.agreementId);
|
|
103
95
|
case 'agreement-fulfill':
|
|
104
96
|
if (!payload.agreementId)
|
|
105
97
|
return null;
|
|
106
|
-
return
|
|
98
|
+
return await agreementService.fulfill(payload.agreementId);
|
|
107
99
|
case 'task-spawn': {
|
|
108
100
|
if (!payload.agreementId || !payload.description)
|
|
109
101
|
return null;
|
|
110
102
|
let spawnAgreementId = payload.agreementId;
|
|
111
|
-
const ags = await agreementsInChat(services, chatId);
|
|
103
|
+
const ags = await agreementsInChat(services, chatId, cachedAgreements);
|
|
112
104
|
// b2 (ZIG-832): if the assignee is not a party on the cited agreement,
|
|
113
105
|
// redirect the spawn to the ACTIVE sub-agreement (same root) where the
|
|
114
106
|
// assignee IS the provider — the orchestrator often cites the top-level
|
|
@@ -159,11 +151,12 @@ export async function dispatchProtocolOp(services, payload, chatId, agents = [],
|
|
|
159
151
|
agreementId: spawnAgreementId,
|
|
160
152
|
};
|
|
161
153
|
}
|
|
154
|
+
const planReviewTiming = normalizePlanInPlace(payload);
|
|
162
155
|
return taskService.spawnUnderAgreement(spawnAgreementId, {
|
|
163
156
|
description: payload.description,
|
|
164
157
|
parentTaskId: payload.parentTaskId,
|
|
165
158
|
plan: payload.plan,
|
|
166
|
-
planReviewTiming
|
|
159
|
+
planReviewTiming,
|
|
167
160
|
requireMidWorkPlanAck: payload.requireMidWorkPlanAck,
|
|
168
161
|
assigneeId: payload.assigneeId,
|
|
169
162
|
inputArtifactIds: Array.isArray(payload.inputArtifactIds)
|
|
@@ -219,14 +212,14 @@ async function proposeAgreement(services, payload, chatId, _agents, actingAgentI
|
|
|
219
212
|
throw new Error('agreement-propose requires `description`');
|
|
220
213
|
if (!payload.proposedTo)
|
|
221
214
|
throw new Error('agreement-propose requires `proposedTo` (userId or agentId). To create a task under an existing agreement, use `task_create` instead.');
|
|
222
|
-
const isBroadcast = payload.proposedTo
|
|
215
|
+
const isBroadcast = isBroadcastTarget(payload.proposedTo);
|
|
223
216
|
// ZIG-1022: a link proposal is an agreement with engagementKind 'link' —
|
|
224
217
|
// no chat, no money; the target owner approves. Folds the old request_link.
|
|
225
218
|
if (payload.engagementKind === 'link') {
|
|
226
219
|
if (isBroadcast) {
|
|
227
220
|
throw new Error('A broadcast link is an invite — use link_create_invite instead; propose links to one agent id.');
|
|
228
221
|
}
|
|
229
|
-
return
|
|
222
|
+
return services.agreementService.requestLink(payload.proposedTo, payload.description);
|
|
230
223
|
}
|
|
231
224
|
if (!isBroadcast && !payload.providerId) {
|
|
232
225
|
throw new Error('agreement-propose requires `providerId` — name who does the work: your own id (you are offering to work) or the proposedTo id (you are commissioning the recipient).');
|
|
@@ -271,9 +264,15 @@ async function proposeAgreement(services, payload, chatId, _agents, actingAgentI
|
|
|
271
264
|
// rejects with 400 "assignee is not a party". Both are made deterministic here
|
|
272
265
|
// using the chat's existing agreements.
|
|
273
266
|
const TERMINAL_STATUS = new Set(['fulfilled', 'cancelled', 'refunded', 'rejected']);
|
|
274
|
-
async function agreementsInChat(services, chatId) {
|
|
267
|
+
async function agreementsInChat(services, chatId, cachedAgreements) {
|
|
275
268
|
if (!chatId)
|
|
276
269
|
return [];
|
|
270
|
+
// ZIG-1120 #8 — createZiggsEffectHandler already cached the session snapshot;
|
|
271
|
+
// prefer that over another GET /context/snapshot just for the agreements array.
|
|
272
|
+
// Empty array is a real answer ("none in this chat") — do not re-fetch.
|
|
273
|
+
if (cachedAgreements !== undefined) {
|
|
274
|
+
return Array.isArray(cachedAgreements) ? cachedAgreements : [];
|
|
275
|
+
}
|
|
277
276
|
try {
|
|
278
277
|
const snap = await services.contextReadClient.snapshot(chatId, { maxMessages: 1 });
|
|
279
278
|
const ags = snap.agreements;
|
|
@@ -302,7 +301,7 @@ function agActive(a) {
|
|
|
302
301
|
function agIsActiveStatus(a) {
|
|
303
302
|
return String(a.status ?? '') === 'active';
|
|
304
303
|
}
|
|
305
|
-
async function subcontractAgreement(services, payload, chatId, _agents, actingAgentId, wakeKeys = null) {
|
|
304
|
+
async function subcontractAgreement(services, payload, chatId, _agents, actingAgentId, wakeKeys = null, cachedAgreements) {
|
|
306
305
|
if (!payload.description || !payload.executorId)
|
|
307
306
|
return null;
|
|
308
307
|
// b1 (ZIG-832): idempotent subcontract — if a non-terminal sub-agreement for
|
|
@@ -310,7 +309,7 @@ async function subcontractAgreement(services, payload, chatId, _agents, actingAg
|
|
|
310
309
|
// creating a duplicate (which bloats the chain and blocks the fulfill cascade).
|
|
311
310
|
if (chatId) {
|
|
312
311
|
const parent = payload.parentAgreementId;
|
|
313
|
-
const existing = (await agreementsInChat(services, chatId)).find((a) => agActive(a) && agIsProvider(a, payload.executorId) &&
|
|
312
|
+
const existing = (await agreementsInChat(services, chatId, cachedAgreements)).find((a) => agActive(a) && agIsProvider(a, payload.executorId) &&
|
|
314
313
|
(!parent || a.parentAgreementId === parent || a.rootAgreementId === parent));
|
|
315
314
|
if (existing?.agreementId)
|
|
316
315
|
return existing;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineTool } from '../../../tools/defineTool.js';
|
|
2
|
+
import { requireProtocolOperation } from '../../../tasks/protocolRegistry.js';
|
|
2
3
|
import { dispatchProtocolOp } from './protocolRunner.js';
|
|
3
4
|
/** ZIG-957 — keep these enums in lockstep with MCP ziggs_agreement_* / ziggs_task_create. */
|
|
4
5
|
const LIFECYCLE_ENUM = ['open', 'time-bound', 'count-bound'];
|
|
@@ -13,7 +14,16 @@ const planReviewTimingParam = {
|
|
|
13
14
|
enum: [...PLAN_REVIEW_TIMING_ENUM],
|
|
14
15
|
description: 'When the buyer reviews the plan: with_proposal | before_execution',
|
|
15
16
|
};
|
|
16
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The handler for a protocol verb, looked up by tool name in the registry
|
|
19
|
+
* (ZIG-1110). Keying off the tool name rather than restating the operation is
|
|
20
|
+
* what makes half-registration impossible: a verb missing from
|
|
21
|
+
* PROTOCOL_TOOL_TO_OPERATION throws here, while this module loads, instead of
|
|
22
|
+
* dispatching correctly and then being unrecognised as protocol at every
|
|
23
|
+
* consumer that decides whether its result reaches context.
|
|
24
|
+
*/
|
|
25
|
+
function handlerFor(toolName) {
|
|
26
|
+
const operation = requireProtocolOperation(toolName);
|
|
17
27
|
return async (args, ctx) => {
|
|
18
28
|
const c = ctx;
|
|
19
29
|
if (!c.taskService)
|
|
@@ -26,16 +36,16 @@ function handlerFor(operation) {
|
|
|
26
36
|
taskService: c.taskService,
|
|
27
37
|
agreementService: c.agreementService,
|
|
28
38
|
contextReadClient: c.contextReadClient,
|
|
29
|
-
}, { operation, ...args }, c.chatId ?? null, c.agents ?? [], typeof c.agentId === 'string' ? c.agentId : null, c.wakeKeys ?? null);
|
|
39
|
+
}, { operation, ...args }, c.chatId ?? null, c.agents ?? [], typeof c.agentId === 'string' ? c.agentId : null, c.wakeKeys ?? null, Array.isArray(c.agreements) ? c.agreements : undefined);
|
|
30
40
|
if (result == null)
|
|
31
41
|
throw new Error(`Operation ${operation} returned no result`);
|
|
32
42
|
return result;
|
|
33
43
|
};
|
|
34
44
|
}
|
|
35
|
-
export const agreementProposeTool = defineTool('agreement_propose', { description: { type: 'string', required: true }, proposedTo: { type: 'string', required: true }, engagementKind: { type: 'string', enum: ['hire', 'service', 'link'], description: "Contract type. Defaults to service. 'link' proposes a bilateral trust link (no work, no money)." }, parentAgreementId: 'string',
|
|
36
|
-
export const agreementSubcontractTool = defineTool('agreement_subcontract', { description: { type: 'string', required: true }, executorId: { type: 'string', required: true }, parentAgreementId: { type: 'string', required: true },
|
|
37
|
-
export const agreementRespondTool = defineTool('agreement_respond', { agreementId: { type: 'string', required: true }, action: { type: 'string', required: true, enum: ['approve', 'reject'] } }, handlerFor('
|
|
38
|
-
export const agreementClaimTool = defineTool('agreement_claim', { agreementId: { type: 'string', required: true, description: 'The open agreement to claim (quest / offer / link invite id)' } }, handlerFor('
|
|
45
|
+
export const agreementProposeTool = defineTool('agreement_propose', { description: { type: 'string', required: true }, proposedTo: { type: 'string', required: true }, engagementKind: { type: 'string', enum: ['hire', 'service', 'link'], description: "Contract type. Defaults to service. 'link' proposes a bilateral trust link (no work, no money)." }, parentAgreementId: 'string', providerId: { type: 'string', description: 'Who does the work — required on direct proposals. Pass your own id when YOU are offering to do the work, or the proposedTo id when you are commissioning the RECIPIENT (any other third party needs a matching published offer). On a broadcast: omit for a quest (the claimer works, you pay), or pass your own id to publish a standing offer (you work, the claimer pays). The payer is always derived as the non-providing side.' }, price: { type: 'number', description: 'Amount in CENTS — 500 means $5.00, shown as ϟ5.00 in the UI. Convert both ways: a human asking for "ϟ2" or "$2 per task" means 200, not 2. ϟ is the currency symbol, not a cent.' }, lifecycle: lifecycleParam, expiresAt: 'string', maxExecutions: 'integer', billing: { type: 'string', enum: ['total', 'per_task'], description: "How price reads: 'total' (default, escrowed and paid at the end) or 'per_task' (a rate settled as each task completes — standing agreements only, and the default for a hire)." }, agreementDescription: 'string' }, handlerFor('agreement_propose'), { description: 'Propose an agreement — direct, broadcast, or link; there are no separate publish tools. Direction is stated, never guessed: providerId = your own id ("I work, you pay") or providerId = proposedTo ("you work, I pay") on direct proposals. Broadcast with proposedTo="everyone" (fully public) or "org" (your org only): no providerId publishes a QUEST any agent may claim; providerId = your own id publishes a STANDING OFFER (claiming is agreement_claim; browsing is marketplace_view). engagementKind "link" with proposedTo = an agent id proposes bilateral trust. engagementKind defaults to service. Agreements are STANDING by default (no expiry, unlimited tasks under one agreement); set expiresAt or maxExecutions only when the engagement should end on its own.', isAgreementCreation: true });
|
|
46
|
+
export const agreementSubcontractTool = defineTool('agreement_subcontract', { description: { type: 'string', required: true }, executorId: { type: 'string', required: true }, parentAgreementId: { type: 'string', required: true }, payerId: 'string', price: { type: 'number', description: 'Amount in CENTS — 500 means $5.00, shown as ϟ5.00 in the UI. Convert both ways: a human asking for "ϟ2" or "$2 per task" means 200, not 2. ϟ is the currency symbol, not a cent.' }, lifecycle: lifecycleParam, expiresAt: 'string', maxExecutions: 'integer', agreementDescription: 'string' }, handlerFor('agreement_subcontract'), { description: 'Delegate work to another agent under an existing parent agreement. Requires parentAgreementId.', isAgreementCreation: true });
|
|
47
|
+
export const agreementRespondTool = defineTool('agreement_respond', { agreementId: { type: 'string', required: true }, action: { type: 'string', required: true, enum: ['approve', 'reject'] } }, handlerFor('agreement_respond'), { description: 'Approve or reject a pending DIRECT agreement proposal addressed to you. Open broadcasts (quests, standing offers, link invites) have no personal approval slot — claim those with agreement_claim instead, or ignore them to pass. ONE exception: a hand-off that pins YOU as provider carries your pending approval even as an open broadcast — approving consents to serving whoever claims it (the row stays open for claims); rejecting cancels the hand-off. Ignoring it leaves the hand-off unclaimable, so always respond.' });
|
|
48
|
+
export const agreementClaimTool = defineTool('agreement_claim', { agreementId: { type: 'string', required: true, description: 'The open agreement to claim (quest / offer / link invite id)' } }, handlerFor('agreement_claim'), { description: 'Claim an open broadcast agreement by id — a quest (you do the work, the publisher pays), a standing offer (you buy, the publisher works), a hand-off (providerPinned: the publisher\'s hired agent works FOR you — you become the customer, and the payer when it is priced), or a link invite (bilateral trust forms immediately). You become the open party and the agreement activates. A hand-off is claimable only after its provider has accepted (409 until then). Find quests/offers with marketplace_view; direct proposals are approved with agreement_respond instead, not claimed.' });
|
|
39
49
|
export const taskSetResultTool = defineTool('task_set_result', {
|
|
40
50
|
taskId: { type: 'string', required: true },
|
|
41
51
|
// ZIG-957: same param name as MCP ziggs_task_set_result / PATCH /tasks/:id/state.
|
|
@@ -45,11 +55,11 @@ export const taskSetResultTool = defineTool('task_set_result', {
|
|
|
45
55
|
type: 'object',
|
|
46
56
|
description: 'Outcome payload (summary, status, links, …). Finished work is the task result — never a chat message.',
|
|
47
57
|
},
|
|
48
|
-
}, handlerFor('
|
|
49
|
-
export const agreementCounterTool = defineTool('agreement_counter', { agreementId: { type: 'string', required: true }, price: { type: 'number', description: 'Amount in CENTS — 500 means $5.00.
|
|
50
|
-
export const agreementGetTool = defineTool('agreement_get', { agreementId: { type: 'string', required: true } }, handlerFor('
|
|
51
|
-
export const agreementRevokeTool = defineTool('agreement_revoke', { agreementId: { type: 'string', required: true } }, handlerFor('
|
|
52
|
-
export const agreementFulfillTool = defineTool('agreement_fulfill', { agreementId: { type: 'string', required: true } }, handlerFor('
|
|
58
|
+
}, handlerFor('task_set_result'), { description: 'Transition a task to its terminal state — completed, failed, or cancelled — and record the result. Finished work is the task result: set it here as an object ({ summary, status, links }), never as a chat message. Pass state (not status).' });
|
|
59
|
+
export const agreementCounterTool = defineTool('agreement_counter', { agreementId: { type: 'string', required: true }, price: { type: 'number', description: 'Amount in CENTS — 500 means $5.00, shown as ϟ5.00 in the UI. Convert both ways: a human asking for "ϟ2" or "$2 per task" means 200, not 2. ϟ is the currency symbol, not a cent.' }, agreementDescription: 'string', expiresAt: 'string', lifecycle: lifecycleParam, maxExecutions: 'integer', description: 'string' }, handlerFor('agreement_counter'), { description: 'Counter a pending proposal with revised terms instead of approving or rejecting. Check status first with agreement_get.' });
|
|
60
|
+
export const agreementGetTool = defineTool('agreement_get', { agreementId: { type: 'string', required: true } }, handlerFor('agreement_get'), { description: 'Read the current proposal status for an agreement (pending, approved, rejected, countered, expired).' });
|
|
61
|
+
export const agreementRevokeTool = defineTool('agreement_revoke', { agreementId: { type: 'string', required: true } }, handlerFor('agreement_revoke'), { 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.' });
|
|
62
|
+
export const agreementFulfillTool = defineTool('agreement_fulfill', { agreementId: { type: 'string', required: true } }, handlerFor('agreement_fulfill'), { description: 'END an agreement you provide — permanently. Fulfilling terminates the whole relationship, not one deliverable: every grant it conferred is revoked, its shared space is torn down, and it cannot be reopened. Finished WORK is reported via task_set_result (the task closes; the agreement stays standing for the next task). Only fulfill when the engagement\'s full scope is delivered and nothing more is expected — never a standing hire that just finished a task.' });
|
|
53
63
|
// `status` names its four values here because nothing else does: the backend is
|
|
54
64
|
// the only place the vocabulary was written down, and it now rejects anything
|
|
55
65
|
// outside it. Every reader (the chat step badge, the SDK's own plan formatter)
|
|
@@ -64,8 +74,8 @@ export const taskUpdatePlanStepTool = defineTool('task_update_plan_step', {
|
|
|
64
74
|
enum: ['pending', 'in_progress', 'completed', 'skipped'],
|
|
65
75
|
},
|
|
66
76
|
result: 'string',
|
|
67
|
-
}, handlerFor('
|
|
68
|
-
export const taskCreateTool = defineTool('task_create', { 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: '
|
|
77
|
+
}, handlerFor('task_update_plan_step'), { description: "Update the status of a single step within a task's plan." });
|
|
78
|
+
export const taskCreateTool = defineTool('task_create', { 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: 'Prior-step output artifact handles, for structured input links.' }, plan: { type: 'object' }, planReviewTiming: planReviewTimingParam, requireMidWorkPlanAck: 'boolean' }, handlerFor('task_create'), { description: 'Create 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.' });
|
|
69
79
|
export const PROTOCOL_TOOLS = [
|
|
70
80
|
agreementProposeTool, agreementSubcontractTool,
|
|
71
81
|
agreementRespondTool, agreementClaimTool, agreementCounterTool, agreementGetTool, agreementRevokeTool,
|