@ziggs-ai/agent-sdk 0.46.6 → 0.47.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 +5 -0
- package/README.md +1 -1
- package/dist/Agent.d.ts +5 -7
- package/dist/Agent.js +29 -60
- package/dist/brain/ClaudeBrain.d.ts +3 -3
- package/dist/brain/ClaudeBrain.js +4 -5
- package/dist/brain/claudeCognition.js +2 -2
- package/dist/brain/claudeSdkProtocol.js +5 -5
- package/dist/brain/claudeSdkTools.d.ts +0 -1
- package/dist/brain/claudeSdkTools.js +6 -4
- package/dist/brain/wakeGate.d.ts +0 -3
- package/dist/brain/wakeGate.js +0 -6
- package/dist/ingress/normalizeIncoming.d.ts +0 -2
- package/dist/ingress/normalizeIncoming.js +0 -9
- package/dist/mcp/createMcpAgent.js +2 -2
- package/dist/memory/MemoryStore.d.ts +5 -5
- package/dist/memory/MemoryStore.js +4 -4
- package/dist/platform/OutboxBuffer.d.ts +2 -2
- package/dist/platform/OutboxBuffer.js +17 -17
- package/dist/platform/WakeLedger.d.ts +0 -2
- package/dist/platform/WakeLedger.js +0 -1
- package/dist/platform/ZiggsEffectHandler.d.ts +0 -1
- package/dist/platform/ZiggsEffectHandler.js +8 -12
- package/dist/platform/inboxLoop.js +1 -2
- package/dist/platform/polls/PollKind.d.ts +2 -2
- package/dist/platform/polls/PollKind.js +1 -1
- package/dist/platform/telemetryIngest.js +1 -4
- package/dist/platform/tools/tier1/protocolRunner.d.ts +3 -1
- package/dist/platform/tools/tier1/protocolRunner.js +10 -23
- package/dist/platform/tools/tier1/protocolTools.js +2 -2
- package/dist/platform/tools/tier1/wakeTools.d.ts +0 -1
- package/dist/platform/tools/tier2/listingTools.js +1 -1
- package/dist/platform/tools/tier2/mcpConnectionTools.js +1 -1
- package/dist/platform/tools/tier2/partyTools.js +2 -2
- package/dist/platform/tools/tier2/planTools.d.ts +2 -2
- package/dist/platform/tools/tier2/planTools.js +3 -3
- package/dist/runtime/AgentMachine.d.ts +1 -1
- package/dist/runtime/AgentMachine.js +1 -1
- package/dist/runtime/PromptBuilder.d.ts +1 -1
- package/dist/runtime/PromptBuilder.js +7 -9
- package/dist/runtime/agreementContext.d.ts +4 -4
- package/dist/runtime/agreementContext.js +4 -4
- package/dist/runtime/buildOutcome.d.ts +0 -1
- package/dist/runtime/deliveryWriteKeys.d.ts +1 -2
- package/dist/runtime/deliveryWriteKeys.js +1 -2
- package/dist/runtime/kickoff.d.ts +2 -2
- package/dist/runtime/kickoff.js +2 -2
- package/dist/runtime/messageCommand.d.ts +1 -1
- package/dist/runtime/messageCommand.js +1 -1
- package/dist/runtime/runTurn.js +5 -18
- package/dist/runtime/wakeEffects.d.ts +1 -1
- package/dist/runtime/wakeEffects.js +1 -1
- package/dist/runtime/wakeOutcome.js +0 -1
- package/dist/tools/recordReport.d.ts +3 -5
- package/dist/tools/recordReport.js +4 -11
- package/dist/tools/toolCreds.d.ts +4 -4
- package/dist/tools/toolCreds.js +5 -7
- package/dist/types.d.ts +7 -9
- package/package.json +2 -2
|
@@ -84,7 +84,7 @@ export class FileMemoryStore {
|
|
|
84
84
|
* hire. Processing lane names do not grant a memory partition. Exactly one agreement gives that agreement's
|
|
85
85
|
* section. None, or several, gives null: notes are bound to an agreement,
|
|
86
86
|
* so such a wake has nowhere to keep them, and says so on a write rather
|
|
87
|
-
* than landing in a
|
|
87
|
+
* than landing in a shared drawer for the agent.
|
|
88
88
|
*/
|
|
89
89
|
export function memorySectionForWake(input) {
|
|
90
90
|
const ids = uniqueHireIds([
|
|
@@ -121,9 +121,9 @@ export function uniqueHireIds(raw) {
|
|
|
121
121
|
return out;
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
|
-
* Hire ids the waking event already named. A
|
|
125
|
-
*
|
|
126
|
-
*
|
|
124
|
+
* Hire ids the waking event already named. A message that carries the
|
|
125
|
+
* delivery's `agreementId` is how two customers' conversations partition
|
|
126
|
+
* without a pinned ctx.
|
|
127
127
|
*/
|
|
128
128
|
export function hireIdsFromEvent(event) {
|
|
129
129
|
if (!event || typeof event !== 'object')
|
|
@@ -22,11 +22,11 @@ export declare class OutboxBuffer {
|
|
|
22
22
|
private _pending;
|
|
23
23
|
private _ttlMs;
|
|
24
24
|
constructor(options?: OutboxBufferOptions);
|
|
25
|
-
track(
|
|
25
|
+
track(laneId: string, msg: {
|
|
26
26
|
text: string;
|
|
27
27
|
receiverId?: string;
|
|
28
28
|
}): void;
|
|
29
|
-
merge(
|
|
29
|
+
merge(laneId: string, history: HistoryEntryShape[], agentId: string | null): void;
|
|
30
30
|
gc(): void;
|
|
31
31
|
private _gcChat;
|
|
32
32
|
}
|
|
@@ -10,15 +10,15 @@ export class OutboxBuffer {
|
|
|
10
10
|
constructor(options = {}) {
|
|
11
11
|
this._ttlMs = Number.isFinite(options.ttlMs) ? Math.max(1_000, options.ttlMs) : 10 * 60 * 1000;
|
|
12
12
|
}
|
|
13
|
-
track(
|
|
14
|
-
this._gcChat(
|
|
15
|
-
if (!this._pending.has(
|
|
16
|
-
this._pending.set(
|
|
17
|
-
this._pending.get(
|
|
13
|
+
track(laneId, msg) {
|
|
14
|
+
this._gcChat(laneId);
|
|
15
|
+
if (!this._pending.has(laneId))
|
|
16
|
+
this._pending.set(laneId, []);
|
|
17
|
+
this._pending.get(laneId).push({ text: msg.text, receiverId: msg.receiverId, timestamp: Date.now() });
|
|
18
18
|
}
|
|
19
|
-
merge(
|
|
20
|
-
this._gcChat(
|
|
21
|
-
const pending = this._pending.get(
|
|
19
|
+
merge(laneId, history, agentId) {
|
|
20
|
+
this._gcChat(laneId);
|
|
21
|
+
const pending = this._pending.get(laneId);
|
|
22
22
|
if (!pending || pending.length === 0)
|
|
23
23
|
return;
|
|
24
24
|
const matchedIndices = new Set();
|
|
@@ -42,27 +42,27 @@ export class OutboxBuffer {
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
if (remaining.length === 0)
|
|
45
|
-
this._pending.delete(
|
|
45
|
+
this._pending.delete(laneId);
|
|
46
46
|
else
|
|
47
|
-
this._pending.set(
|
|
47
|
+
this._pending.set(laneId, remaining);
|
|
48
48
|
}
|
|
49
49
|
gc() {
|
|
50
|
-
for (const
|
|
51
|
-
this._gcChat(
|
|
50
|
+
for (const laneId of this._pending.keys())
|
|
51
|
+
this._gcChat(laneId);
|
|
52
52
|
}
|
|
53
|
-
_gcChat(
|
|
54
|
-
const pending = this._pending.get(
|
|
53
|
+
_gcChat(laneId) {
|
|
54
|
+
const pending = this._pending.get(laneId);
|
|
55
55
|
if (!pending?.length)
|
|
56
56
|
return;
|
|
57
57
|
const cutoff = Date.now() - this._ttlMs;
|
|
58
58
|
const fresh = pending.filter(msg => msg.timestamp >= cutoff);
|
|
59
59
|
if (fresh.length === 0) {
|
|
60
|
-
this._pending.delete(
|
|
61
|
-
runtimeLog.warn('OutboxBuffer', `expired all pending messages
|
|
60
|
+
this._pending.delete(laneId);
|
|
61
|
+
runtimeLog.warn('OutboxBuffer', `expired all pending messages laneId=${laneId}`);
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
if (fresh.length !== pending.length) {
|
|
65
|
-
this._pending.set(
|
|
65
|
+
this._pending.set(laneId, fresh);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -10,8 +10,6 @@ export interface SavedWake {
|
|
|
10
10
|
firesAt: number;
|
|
11
11
|
reason: string | null;
|
|
12
12
|
scope?: WorkScope;
|
|
13
|
-
/** The conversation the lane's own messages came from, when it has one. */
|
|
14
|
-
addressId?: string;
|
|
15
13
|
executionContext?: WorkExecutionContext;
|
|
16
14
|
/** The bucket a bucket lane carries, so a restart names the same lane. */
|
|
17
15
|
bucket?: LaneBucket;
|
|
@@ -61,7 +61,6 @@ export class WakeLedger {
|
|
|
61
61
|
firesAt: saved.firesAt,
|
|
62
62
|
reason: saved.reason ?? null,
|
|
63
63
|
...(saved.scope ? { scope: saved.scope } : {}),
|
|
64
|
-
...(typeof saved.addressId === 'string' && saved.addressId ? { addressId: saved.addressId } : {}),
|
|
65
64
|
...(saved.executionContext ? { executionContext: saved.executionContext } : {}),
|
|
66
65
|
...(isLaneBucket(saved.bucket) ? { bucket: { bucketId: saved.bucket.bucketId, revision: saved.bucket.revision } } : {}),
|
|
67
66
|
});
|
|
@@ -131,17 +131,17 @@ function previewToolArgs(args) {
|
|
|
131
131
|
* Chat timeline: `Message.tsx` parses `entryType: artifact`, `contentType: operation` with
|
|
132
132
|
* `operation_*:{json}` where json includes `state` and `tool`.
|
|
133
133
|
*/
|
|
134
|
-
async function emitToolOperationArtifact(client,
|
|
135
|
-
// Operation history belongs to selected work
|
|
134
|
+
async function emitToolOperationArtifact(client, phase, payload, idempotencyKey, serviceAgreementId, taskId) {
|
|
135
|
+
// Operation history belongs to selected work.
|
|
136
136
|
// An unbound processing lane must not accumulate shared private context.
|
|
137
|
-
if (!
|
|
137
|
+
if (!serviceAgreementId && !taskId)
|
|
138
138
|
return;
|
|
139
139
|
const prefix = phase === 'started' ? 'operation_started' : phase === 'completed' ? 'operation_completed' : 'operation_error';
|
|
140
140
|
const text = `${prefix}:${JSON.stringify(payload)}`;
|
|
141
141
|
try {
|
|
142
142
|
await client.write({
|
|
143
|
-
// The wake's own
|
|
144
|
-
//
|
|
143
|
+
// The wake's own work. A processing lane is a routing key, never a
|
|
144
|
+
// destination: a breadcrumb without work is refused here.
|
|
145
145
|
...artifactScope({ agreementId: serviceAgreementId }),
|
|
146
146
|
text,
|
|
147
147
|
contentType: 'operation',
|
|
@@ -174,9 +174,6 @@ async function emitToolOperationArtifact(client, addressId, phase, payload, idem
|
|
|
174
174
|
export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
175
175
|
const toolT0 = Date.now();
|
|
176
176
|
let args = effect.args || {};
|
|
177
|
-
// The wake's explicit conversation, when it has one. The effect's session
|
|
178
|
-
// is the processing lane, which routes effects and is never an address.
|
|
179
|
-
const addressId = deps.conversationFor?.(effect.sessionId)?.addressId;
|
|
180
177
|
const controller = executionControllers.getStore();
|
|
181
178
|
let binding;
|
|
182
179
|
let argsPreview;
|
|
@@ -194,7 +191,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
|
194
191
|
args = Object.fromEntries(Object.entries(args).filter(([key]) => key !== 'taskId'));
|
|
195
192
|
}
|
|
196
193
|
argsPreview = previewToolArgs(args);
|
|
197
|
-
void emitToolOperationArtifact(deps.artifactsClient,
|
|
194
|
+
void emitToolOperationArtifact(deps.artifactsClient, 'started', {
|
|
198
195
|
state: 'started',
|
|
199
196
|
tool: effect.name,
|
|
200
197
|
...(argsPreview ? { args: argsPreview } : {}),
|
|
@@ -218,7 +215,6 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
|
218
215
|
const result = await deps.toolManager.executeTool(effect.name, args, {
|
|
219
216
|
operatorKey: deps.operatorKey,
|
|
220
217
|
agentId: deps.agentId,
|
|
221
|
-
...(addressId ? { addressId } : {}),
|
|
222
218
|
sessionId: effect.sessionId,
|
|
223
219
|
taskService: deps.taskService,
|
|
224
220
|
agreementService: deps.agreementService,
|
|
@@ -248,7 +244,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
|
248
244
|
// One clip per tool call: this is a full JSON.stringify of the untruncated
|
|
249
245
|
// result, and the artifact body and the idempotency key want the same string.
|
|
250
246
|
const clipped = clipForOperationArtifact(result);
|
|
251
|
-
void emitToolOperationArtifact(deps.artifactsClient,
|
|
247
|
+
void emitToolOperationArtifact(deps.artifactsClient, 'completed', {
|
|
252
248
|
state: 'completed',
|
|
253
249
|
tool: effect.name,
|
|
254
250
|
result: clipped,
|
|
@@ -266,7 +262,7 @@ export async function executeToolWithSideEffects(deps, eff, effect, roster) {
|
|
|
266
262
|
catch (error) {
|
|
267
263
|
const errMsg = toolFailureText(error);
|
|
268
264
|
runtimeLog.warn('ZiggsEffectHandler', `tool-call "${effect.name}" failed: ${errMsg}`);
|
|
269
|
-
void emitToolOperationArtifact(deps.artifactsClient,
|
|
265
|
+
void emitToolOperationArtifact(deps.artifactsClient, 'error', {
|
|
270
266
|
state: 'failed',
|
|
271
267
|
tool: effect.name,
|
|
272
268
|
error: errMsg,
|
|
@@ -174,7 +174,7 @@ async function deliverAssignedMessage(deps, ref, reader, attempt, handledIds, tu
|
|
|
174
174
|
const sentIn = bucketOfRows([ref]);
|
|
175
175
|
const metadata = { messageId: row.messageId, ...(row.mandate ?? {}),
|
|
176
176
|
sender: { id: row.sender.ref, type: row.sender.kind }, receiver: { id: deps.ownAgentId, type: 'agent' },
|
|
177
|
-
entryType: 'message', intent: row.intent, timestamp: row.timestamp,
|
|
177
|
+
entryType: 'message', intent: row.intent, timestamp: row.timestamp, fromInbox: true,
|
|
178
178
|
...(sentIn ? { bucket: sentIn } : {}) };
|
|
179
179
|
// Hand over in dispatch order; only the read above runs ahead.
|
|
180
180
|
await turn.ready;
|
|
@@ -439,7 +439,6 @@ export async function pollInboxOnce(deps, waitSeconds = 0, opts = {}) {
|
|
|
439
439
|
ts: d.ts,
|
|
440
440
|
resourceId: d.resourceId,
|
|
441
441
|
...(d.receiptId ? { receiptId: d.receiptId, executionContext } : {}),
|
|
442
|
-
...(d.addressId ? { addressId: d.addressId } : {}),
|
|
443
442
|
...(d.agreementId ? { agreementId: d.agreementId } : {}),
|
|
444
443
|
...(d.taskId ? { taskId: d.taskId } : {}),
|
|
445
444
|
// claim/listing wakes carry reason + claimer; host needs
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
* A source may report an existing task action for authorized host processing.
|
|
13
13
|
* A mechanical source may dispatch through its existing domain owner and return
|
|
14
14
|
* actionable:false; the resulting owner delivery supplies work to its assignee.
|
|
15
|
-
* It never creates a
|
|
15
|
+
* It never creates a bucket or borrows the execution that started the timer.
|
|
16
16
|
*
|
|
17
17
|
* WHERE THE CURSOR LIVES: in the source, whenever the source has one. Sente
|
|
18
18
|
* has `archived` on a message, so "already handled" is a fact about the
|
|
19
19
|
* mailbox, not something we mirror. A kind whose source has no such notion has
|
|
20
20
|
* to keep a cursor, and then it is the kind's business — never the agent's.
|
|
21
21
|
*/
|
|
22
|
-
/** Kind-specific source configuration. It carries no
|
|
22
|
+
/** Kind-specific source configuration. It carries no execution authority. */
|
|
23
23
|
export interface PollBinding {
|
|
24
24
|
kind: string;
|
|
25
25
|
[key: string]: unknown;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* A source may report an existing task action for authorized host processing.
|
|
13
13
|
* A mechanical source may dispatch through its existing domain owner and return
|
|
14
14
|
* actionable:false; the resulting owner delivery supplies work to its assignee.
|
|
15
|
-
* It never creates a
|
|
15
|
+
* It never creates a bucket or borrows the execution that started the timer.
|
|
16
16
|
*
|
|
17
17
|
* WHERE THE CURSOR LIVES: in the source, whenever the source has one. Sente
|
|
18
18
|
* has `archived` on a message, so "already handled" is a fact about the
|
|
@@ -18,11 +18,9 @@ export function usageFromLlmResponse(response) {
|
|
|
18
18
|
}
|
|
19
19
|
export function buildLlmIngestPayload(response, ctx) {
|
|
20
20
|
const { tokensTotal, tokensInput, tokensOutput } = usageFromLlmResponse(response);
|
|
21
|
-
const addressId = ctx.sessionId ?? null;
|
|
22
21
|
return {
|
|
23
22
|
source: 'agent',
|
|
24
|
-
|
|
25
|
-
sessionId: addressId,
|
|
23
|
+
sessionId: ctx.sessionId ?? null,
|
|
26
24
|
execution: {
|
|
27
25
|
llmCallsTotal: 1,
|
|
28
26
|
tokensTotal,
|
|
@@ -41,7 +39,6 @@ export function buildLlmIngestPayload(response, ctx) {
|
|
|
41
39
|
export function buildToolIngestPayload(ctx) {
|
|
42
40
|
return {
|
|
43
41
|
source: 'agent',
|
|
44
|
-
addressId: ctx.sessionId,
|
|
45
42
|
sessionId: ctx.sessionId,
|
|
46
43
|
execution: { executionLoops: 1 },
|
|
47
44
|
resource: { durationMs: Math.max(0, Math.round(ctx.durationMs)) },
|
|
@@ -36,7 +36,9 @@ interface ProtocolPayload {
|
|
|
36
36
|
})[];
|
|
37
37
|
[key: string]: unknown;
|
|
38
38
|
}
|
|
39
|
-
export declare function dispatchProtocolOp(services: Services, payload: ProtocolPayload,
|
|
39
|
+
export declare function dispatchProtocolOp(services: Services, payload: ProtocolPayload,
|
|
40
|
+
/** The wake's processing lane. Kept for call compatibility; nothing is sent from it. */
|
|
41
|
+
_lane: string | null, _agents?: unknown[], actingAgentId?: string | null, writeKeys?: DeliveryWriteKeys | null,
|
|
40
42
|
/** #8 — prefer the cached session snapshot over a fresh HTTP read. */
|
|
41
43
|
cachedAgreements?: unknown[]): Promise<unknown>;
|
|
42
44
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AGREEMENT_TERMINAL_STATES } from '@ziggs-ai/contracts';
|
|
2
|
-
import {
|
|
2
|
+
import { currentWorkExecution, isBroadcastTarget, partyActorIds, presentClaimResult, } from '@ziggs-ai/api-client';
|
|
3
3
|
// the link-summary rule lives in AgreementClient, at the point the
|
|
4
4
|
// document is parsed. Every verb here inherits it through the client instead of
|
|
5
5
|
// each one restating `engagementKind === 'link' ? linkSummary(a) : a` — which is
|
|
@@ -56,7 +56,9 @@ function sourcesOf(payload) {
|
|
|
56
56
|
? { sources: payload.sources }
|
|
57
57
|
: {};
|
|
58
58
|
}
|
|
59
|
-
export async function dispatchProtocolOp(services, payload,
|
|
59
|
+
export async function dispatchProtocolOp(services, payload,
|
|
60
|
+
/** The wake's processing lane. Kept for call compatibility; nothing is sent from it. */
|
|
61
|
+
_lane, _agents = [], actingAgentId = null, writeKeys = null,
|
|
60
62
|
/** #8 — prefer the cached session snapshot over a fresh HTTP read. */
|
|
61
63
|
cachedAgreements) {
|
|
62
64
|
if (!payload?.operation)
|
|
@@ -66,9 +68,9 @@ cachedAgreements) {
|
|
|
66
68
|
const actorId = actingAgentId?.trim() || null;
|
|
67
69
|
switch (operation) {
|
|
68
70
|
case 'agreement-propose':
|
|
69
|
-
return proposeAgreement(services, payload,
|
|
71
|
+
return proposeAgreement(services, payload, writeKeys);
|
|
70
72
|
case 'agreement-subcontract':
|
|
71
|
-
return subcontractAgreement(services, payload,
|
|
73
|
+
return subcontractAgreement(services, payload, writeKeys);
|
|
72
74
|
case 'agreement-respond':
|
|
73
75
|
if (!payload.agreementId || !payload.action)
|
|
74
76
|
return null;
|
|
@@ -255,7 +257,7 @@ cachedAgreements) {
|
|
|
255
257
|
throw new Error(`Unknown protocol operation: ${operation}`);
|
|
256
258
|
}
|
|
257
259
|
}
|
|
258
|
-
async function proposeAgreement(services, payload,
|
|
260
|
+
async function proposeAgreement(services, payload, writeKeys = null) {
|
|
259
261
|
if (!payload.description)
|
|
260
262
|
throw new Error('agreement-propose requires `description`');
|
|
261
263
|
if (!payload.proposedTo)
|
|
@@ -297,7 +299,6 @@ async function proposeAgreement(services, payload, addressId, writeKeys = null)
|
|
|
297
299
|
const interactionMode = oneOf(payload['interactionMode'], ['messages', 'tasks', 'both']);
|
|
298
300
|
const { agreement, shape } = await services.agreementService.proposeUnified({
|
|
299
301
|
proposedTo: payload.proposedTo,
|
|
300
|
-
addressId: addressId ?? undefined,
|
|
301
302
|
description: String(payload.description),
|
|
302
303
|
providerId: payload.providerId,
|
|
303
304
|
price: typeof payload.price === 'number' ? payload.price : undefined,
|
|
@@ -358,20 +359,6 @@ function agIsParty(a, agentId) {
|
|
|
358
359
|
function agIsActiveStatus(a) {
|
|
359
360
|
return String(a.status ?? '') === 'active';
|
|
360
361
|
}
|
|
361
|
-
/**
|
|
362
|
-
* The room a new agreement is discussed in. An agreement lane (`agrn-…`) is
|
|
363
|
-
* a session key, not a room, so it names none.
|
|
364
|
-
*/
|
|
365
|
-
function roomOf(addressId) {
|
|
366
|
-
return addressId && !isAgreementLaneId(addressId) ? addressId : null;
|
|
367
|
-
}
|
|
368
|
-
/** A named room on the call wins; otherwise the wake's chat. Empty is omit. */
|
|
369
|
-
function namedSubcontractChat(payload, wakeChatId) {
|
|
370
|
-
const named = payload.addressId;
|
|
371
|
-
if (typeof named === 'string' && named.trim())
|
|
372
|
-
return named.trim();
|
|
373
|
-
return wakeChatId;
|
|
374
|
-
}
|
|
375
362
|
/**
|
|
376
363
|
* A sub-agreement under the agreement this wake works for, with exactly the
|
|
377
364
|
* terms the model stated. When it states neither an end date nor a task count
|
|
@@ -386,18 +373,18 @@ function namedSubcontractChat(payload, wakeChatId) {
|
|
|
386
373
|
* request over MCP stays open. A crash replay is still covered by the
|
|
387
374
|
* wake-derived idempotency key.
|
|
388
375
|
*/
|
|
389
|
-
async function subcontractAgreement(services, payload,
|
|
376
|
+
async function subcontractAgreement(services, payload, writeKeys = null) {
|
|
390
377
|
if (!payload.description || !payload.executorId)
|
|
391
378
|
return null;
|
|
392
379
|
// The price the model stated, or none; the server falls back to the
|
|
393
380
|
// executor's listing price, then to free.
|
|
394
|
-
const { operation: _op, ...fields } = payload;
|
|
381
|
+
const { operation: _op, addressId: _retired, ...fields } = payload;
|
|
395
382
|
const idempotencyKey = writeKeys?.agreementSubcontractKey({
|
|
396
383
|
executorId: payload.executorId,
|
|
397
384
|
description: payload.description,
|
|
398
385
|
parentAgreementId: payload.parentAgreementId ?? '',
|
|
399
386
|
});
|
|
400
|
-
return services.agreementService.delegate({ ...fields,
|
|
387
|
+
return services.agreementService.delegate({ ...fields, idempotencyKey });
|
|
401
388
|
}
|
|
402
389
|
/**
|
|
403
390
|
* A charge statement as the model wrote it, or nothing. A task with no stated
|
|
@@ -47,7 +47,7 @@ function handlerFor(toolName) {
|
|
|
47
47
|
taskService: c.taskService,
|
|
48
48
|
agreementService: c.agreementService,
|
|
49
49
|
contextReadClient: c.contextReadClient,
|
|
50
|
-
}, { operation, ...args }, c.
|
|
50
|
+
}, { operation, ...args }, c.sessionId ?? null, c.agents ?? [], typeof c.agentId === 'string' ? c.agentId : null, c.writeKeys ?? null, Array.isArray(c.agreements) ? c.agreements : undefined);
|
|
51
51
|
if (result == null)
|
|
52
52
|
throw new Error(`Operation ${operation} returned no result`);
|
|
53
53
|
return result;
|
|
@@ -101,7 +101,7 @@ export const agreementCounterTool = defineTool('agreement_counter', {
|
|
|
101
101
|
}, handlerFor('agreement_counter'), { description: 'Counter a pending proposal with revised terms instead of approving or rejecting. Check status first with agreement_get.' });
|
|
102
102
|
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).' });
|
|
103
103
|
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.' });
|
|
104
|
-
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 and it cannot be reopened. Linked
|
|
104
|
+
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 and it cannot be reopened. Linked conversations keep their own grants. 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.' });
|
|
105
105
|
// `status` names its four values here because nothing else does: the backend is
|
|
106
106
|
// the only place the vocabulary was written down, and it now rejects anything
|
|
107
107
|
// outside it. Every reader (the chat step badge, the SDK's own plan formatter)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { agreementBidCapability } from '@ziggs-ai/api-client';
|
|
2
2
|
import { toolsFromCapabilities } from '../../../tools/capabilityAdapter.js';
|
|
3
3
|
// What a listed agent needs to answer a stranger whose ask the listing does not
|
|
4
|
-
// cover: terms offered to them directly,
|
|
4
|
+
// cover: terms offered to them directly, which they approve. The
|
|
5
5
|
// listing itself stays take-it-or-leave-it. The work brief names this as its
|
|
6
6
|
// propose_terms action; without the tool the agent can only refuse.
|
|
7
7
|
export const LISTING_TOOLS = toolsFromCapabilities([agreementBidCapability]);
|
|
@@ -66,7 +66,7 @@ async function withClient(ctx, toolName, connectionId, grantId, run) {
|
|
|
66
66
|
* The lane comes from `credsFromToolContext`, the same reader every other
|
|
67
67
|
* tool uses. Reading it off a field of its own (`ctx.laneId`) is how this
|
|
68
68
|
* door came to send no lane at all: the executor states the lane as
|
|
69
|
-
* `
|
|
69
|
+
* `sessionId`, so a key by any other name is always undefined,
|
|
70
70
|
* and the gateway then resolves the wake to the agent's own operator and
|
|
71
71
|
* refuses every grant its customer gave it.
|
|
72
72
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PARTY_CAPABILITIES, partyNoteCapability } from '@ziggs-ai/api-client';
|
|
2
2
|
import { toolFromCapability, toolsFromCapabilities } from '../../../tools/capabilityAdapter.js';
|
|
3
3
|
// A person who is not on Ziggs yet: someone your workspace reaches by mail or
|
|
4
|
-
// Slack. What your workspace knows about them rides in every
|
|
5
|
-
//
|
|
4
|
+
// Slack. What your workspace knows about them rides in every snapshot they
|
|
5
|
+
// appear in. Defined once in api-client's capability layer.
|
|
6
6
|
export const partyNoteTool = toolFromCapability(partyNoteCapability);
|
|
7
7
|
export const PARTY_TOOLS = toolsFromCapabilities(PARTY_CAPABILITIES);
|
|
@@ -6,7 +6,7 @@ import { type ToolDefinition } from '../../../tools/defineTool.js';
|
|
|
6
6
|
* (`task_update_plan_step` takes a stepId), and a task created without a plan
|
|
7
7
|
* has none, so an agent had no way to record anything about its own work on
|
|
8
8
|
* the task row. That mattered the moment one agent served two customers: from
|
|
9
|
-
* the second customer's
|
|
9
|
+
* the second customer's conversation it could not find the approval request it had
|
|
10
10
|
* sent under the first customer's hire, and told them it had never been sent
|
|
11
11
|
* (store-opening lab, 2026-09-15). The MCP surface has had
|
|
12
12
|
* `ziggs_task_replace_plan` all along; this is the same client call for the
|
|
@@ -14,7 +14,7 @@ import { type ToolDefinition } from '../../../tools/defineTool.js';
|
|
|
14
14
|
*
|
|
15
15
|
* The plan is the agent's own notebook on the task: step results can carry
|
|
16
16
|
* ids (an approval agreement, an artifact), and `task_list` reads the plan back
|
|
17
|
-
* from any
|
|
17
|
+
* from any conversation the agent is woken in.
|
|
18
18
|
*/
|
|
19
19
|
export declare const taskReplacePlanTool: ToolDefinition;
|
|
20
20
|
export declare const PLAN_TOOLS: ToolDefinition[];
|
|
@@ -8,7 +8,7 @@ import { credsFromToolContext } from '../../../tools/toolCreds.js';
|
|
|
8
8
|
* (`task_update_plan_step` takes a stepId), and a task created without a plan
|
|
9
9
|
* has none, so an agent had no way to record anything about its own work on
|
|
10
10
|
* the task row. That mattered the moment one agent served two customers: from
|
|
11
|
-
* the second customer's
|
|
11
|
+
* the second customer's conversation it could not find the approval request it had
|
|
12
12
|
* sent under the first customer's hire, and told them it had never been sent
|
|
13
13
|
* (store-opening lab, 2026-09-15). The MCP surface has had
|
|
14
14
|
* `ziggs_task_replace_plan` all along; this is the same client call for the
|
|
@@ -16,7 +16,7 @@ import { credsFromToolContext } from '../../../tools/toolCreds.js';
|
|
|
16
16
|
*
|
|
17
17
|
* The plan is the agent's own notebook on the task: step results can carry
|
|
18
18
|
* ids (an approval agreement, an artifact), and `task_list` reads the plan back
|
|
19
|
-
* from any
|
|
19
|
+
* from any conversation the agent is woken in.
|
|
20
20
|
*/
|
|
21
21
|
export const taskReplacePlanTool = defineTool('task_replace_plan', {
|
|
22
22
|
taskId: { type: 'string', required: true, minLength: 1, pattern: '\\S' },
|
|
@@ -60,6 +60,6 @@ export const taskReplacePlanTool = defineTool('task_replace_plan', {
|
|
|
60
60
|
throw new Error('task_replace_plan: steps must be an array');
|
|
61
61
|
return replaceTaskPlan(taskId, steps, creds);
|
|
62
62
|
}, {
|
|
63
|
-
description: 'Replace the plan of a task you hold with the full ordered step list. Use it to write your own checklist on a task that arrived without one, and to record what a step produced (an approval agreement id, an artifact id) so a later wake
|
|
63
|
+
description: 'Replace the plan of a task you hold with the full ordered step list. Use it to write your own checklist on a task that arrived without one, and to record what a step produced (an approval agreement id, an artifact id) so a later wake, from any conversation, can find it with task_list. Steps you do not send are removed; mark finished steps completed so closing the task does not rewrite them as skipped.',
|
|
64
64
|
});
|
|
65
65
|
export const PLAN_TOOLS = [taskReplacePlanTool];
|
|
@@ -146,7 +146,7 @@ export declare class AgentMachine {
|
|
|
146
146
|
*
|
|
147
147
|
* Both runaway guards used to just `return`, which left `this.state` AT the
|
|
148
148
|
* state that had run away. Parking inside a thinking state is not parking —
|
|
149
|
-
* it is a lane stuck in a
|
|
149
|
+
* it is a lane stuck in a state whose transitions were written for one
|
|
150
150
|
* occasion, so every later event is evaluated against the wrong state and
|
|
151
151
|
* anything that state does not route is swallowed. Measured: three lab
|
|
152
152
|
* workers tripped the depth guard inside an injected claim greeting (since
|
|
@@ -153,7 +153,7 @@ export class AgentMachine {
|
|
|
153
153
|
*
|
|
154
154
|
* Both runaway guards used to just `return`, which left `this.state` AT the
|
|
155
155
|
* state that had run away. Parking inside a thinking state is not parking —
|
|
156
|
-
* it is a lane stuck in a
|
|
156
|
+
* it is a lane stuck in a state whose transitions were written for one
|
|
157
157
|
* occasion, so every later event is evaluated against the wrong state and
|
|
158
158
|
* anything that state does not route is swallowed. Measured: three lab
|
|
159
159
|
* workers tripped the depth guard inside an injected claim greeting (since
|
|
@@ -330,12 +330,10 @@ ${this._renderDecisionSchemaFromActions(actions, senderMeta, ctxObj, omitMessage
|
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
-
// Chat keeps the full directory
|
|
334
|
-
//
|
|
335
|
-
//
|
|
336
|
-
|
|
337
|
-
// against them 400s.
|
|
338
|
-
const addressIds = new Set([...userIds, ...agentIds]);
|
|
333
|
+
// Chat keeps the full directory, including opaque `psn_*` refs the
|
|
334
|
+
// persona layer may surface. Transfer (and any account-id action) must
|
|
335
|
+
// never list opaque refs: lookup / wake / pay against them 400s.
|
|
336
|
+
const chatIds = new Set([...userIds, ...agentIds]);
|
|
339
337
|
const transferIds = new Set([...userIds, ...agentIds].filter((id) => !isOpaquePresentationRef(id)));
|
|
340
338
|
const lines = ['<recipients>'];
|
|
341
339
|
lines.push('<users>');
|
|
@@ -353,10 +351,10 @@ ${this._renderDecisionSchemaFromActions(actions, senderMeta, ctxObj, omitMessage
|
|
|
353
351
|
lines.push(` - ${agentLabels.get(id)}`);
|
|
354
352
|
lines.push('</agents>');
|
|
355
353
|
lines.push('<chat>');
|
|
356
|
-
if (
|
|
354
|
+
if (chatIds.size === 0)
|
|
357
355
|
lines.push(' (none)');
|
|
358
356
|
else
|
|
359
|
-
for (const id of
|
|
357
|
+
for (const id of chatIds)
|
|
360
358
|
lines.push(` - ${tagged(id)}`);
|
|
361
359
|
lines.push('</chat>');
|
|
362
360
|
lines.push('<agreement>');
|
|
@@ -393,7 +391,7 @@ ${this._renderDecisionSchemaFromActions(actions, senderMeta, ctxObj, omitMessage
|
|
|
393
391
|
// refused by some providers as reasoning extraction, which fails the turn.
|
|
394
392
|
lines.push('Return ONE JSON object.');
|
|
395
393
|
lines.push('Set "action" to exactly one of the action names below.');
|
|
396
|
-
lines.push('Name "receiverId" only when you mean a specific recipient. Leave it out to
|
|
394
|
+
lines.push('Name "receiverId" only when you mean a specific recipient. Leave it out to answer the message that woke you; an answer without one is sent without one.');
|
|
397
395
|
lines.push('Message text is rendered as markdown (CommonMark + GFM). You MAY use **bold**, *italic*, `code`, fenced code blocks, lists, links, and tables when they improve clarity — plain text is also fine.\n');
|
|
398
396
|
const pendingProposals = (ctxObj.agreements || []).filter((a) => a.proposal?.status === 'pending' && (a.proposedToIsYou || isBroadcastTarget(a.parties?.proposedTo?.principal)));
|
|
399
397
|
if (pendingProposals.length > 0) {
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* A seller's standing offer: open to everyone (`everyone`) or one
|
|
3
3
|
* company (`org`). A listing is never work: claiming it gives each claimer
|
|
4
4
|
* their own hire, so nothing is done or spent under the listing itself. Reads
|
|
5
|
-
* both party shapes: an agreement row (`{ principal }`) and a
|
|
6
|
-
* row (the principal as a string).
|
|
5
|
+
* both party shapes: an agreement row (`{ principal }`) and a context
|
|
6
|
+
* snapshot row (the principal as a string).
|
|
7
7
|
*/
|
|
8
8
|
export declare function isListing(agreement: unknown): boolean;
|
|
9
|
-
/** Enrich each wake from the agreement it actually names, never from the
|
|
10
|
-
* latest deal. Reads use the agent's credentials; no grants are inferred here. */
|
|
9
|
+
/** Enrich each wake from the agreement it actually names, never from the
|
|
10
|
+
* conversation's latest deal. Reads use the agent's credentials; no grants are inferred here. */
|
|
11
11
|
export declare function withAgreementContext(event: unknown, read: (agreementId: string) => Promise<unknown>): Promise<unknown>;
|
|
12
12
|
/** A link or a listing supplies conversation context, never consent to another engagement. */
|
|
13
13
|
export declare function permitsAutomaticMandate(event: unknown): boolean;
|
|
@@ -3,8 +3,8 @@ const row = (value) => value && typeof value === 'object' ? value : {};
|
|
|
3
3
|
* A seller's standing offer: open to everyone (`everyone`) or one
|
|
4
4
|
* company (`org`). A listing is never work: claiming it gives each claimer
|
|
5
5
|
* their own hire, so nothing is done or spent under the listing itself. Reads
|
|
6
|
-
* both party shapes: an agreement row (`{ principal }`) and a
|
|
7
|
-
* row (the principal as a string).
|
|
6
|
+
* both party shapes: an agreement row (`{ principal }`) and a context
|
|
7
|
+
* snapshot row (the principal as a string).
|
|
8
8
|
*/
|
|
9
9
|
export function isListing(agreement) {
|
|
10
10
|
const a = row(agreement);
|
|
@@ -13,8 +13,8 @@ export function isListing(agreement) {
|
|
|
13
13
|
return ((principal === 'everyone' || principal === 'org' || principal === 'company') &&
|
|
14
14
|
a.engagementKind !== 'link');
|
|
15
15
|
}
|
|
16
|
-
/** Enrich each wake from the agreement it actually names, never from the
|
|
17
|
-
* latest deal. Reads use the agent's credentials; no grants are inferred here. */
|
|
16
|
+
/** Enrich each wake from the agreement it actually names, never from the
|
|
17
|
+
* conversation's latest deal. Reads use the agent's credentials; no grants are inferred here. */
|
|
18
18
|
export async function withAgreementContext(event, read) {
|
|
19
19
|
const reads = new Map();
|
|
20
20
|
const context = (id) => {
|
|
@@ -10,8 +10,7 @@ import type { DeliveryWriteKeys } from '../types.js';
|
|
|
10
10
|
* the transition itself, so it dedups regardless of the order in which the
|
|
11
11
|
* replayed wake happens to re-issue its tool calls.
|
|
12
12
|
* - chat messages: `sdk_idem_wk_<wake-hash>_m_<hash(chat, receiver, text)>`
|
|
13
|
-
* — used directly as the messageId (the backend dedups on
|
|
14
|
-
*). Content-derived, not ordinal: a wake may emit several
|
|
13
|
+
* — used directly as the messageId (the backend dedups on messageId). Content-derived, not ordinal: a wake may emit several
|
|
15
14
|
* distinct messages without colliding, and a crash-replay that re-sends the
|
|
16
15
|
* same text reuses the key; a re-think with different text gets a new key
|
|
17
16
|
* instead of 409-dropping on the old ordinal slot. The prefix matches the
|
|
@@ -79,8 +79,7 @@ function sha(input) {
|
|
|
79
79
|
* the transition itself, so it dedups regardless of the order in which the
|
|
80
80
|
* replayed wake happens to re-issue its tool calls.
|
|
81
81
|
* - chat messages: `sdk_idem_wk_<wake-hash>_m_<hash(chat, receiver, text)>`
|
|
82
|
-
* — used directly as the messageId (the backend dedups on
|
|
83
|
-
*). Content-derived, not ordinal: a wake may emit several
|
|
82
|
+
* — used directly as the messageId (the backend dedups on messageId). Content-derived, not ordinal: a wake may emit several
|
|
84
83
|
* distinct messages without colliding, and a crash-replay that re-sends the
|
|
85
84
|
* same text reuses the key; a re-think with different text gets a new key
|
|
86
85
|
* instead of 409-dropping on the old ordinal slot. The prefix matches the
|