@ziggs-ai/agent-sdk 0.46.3 → 0.46.5
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 +13 -0
- package/dist/Agent.d.ts +10 -2
- package/dist/Agent.js +52 -29
- package/dist/brain/ClaudeBrain.js +6 -3
- package/dist/brain/claudeCognition.d.ts +7 -0
- package/dist/brain/claudeCognition.js +47 -14
- package/dist/brain/claudeSdkProtocol.js +1 -1
- package/dist/brain/claudeSdkTools.js +8 -0
- package/dist/brain/toolFailureText.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/ingress/normalizeIncoming.d.ts +6 -5
- package/dist/ingress/normalizeIncoming.js +4 -1
- package/dist/platform/WakeLedger.d.ts +3 -2
- package/dist/platform/WakeLedger.js +5 -1
- package/dist/platform/inboxLoop.d.ts +5 -1
- package/dist/platform/inboxLoop.js +22 -9
- package/dist/platform/laneKey.d.ts +19 -13
- package/dist/platform/laneKey.js +16 -21
- package/dist/platform/tools/index.d.ts +1 -0
- package/dist/platform/tools/index.js +1 -0
- package/dist/platform/tools/tier2/bucketTools.d.ts +2 -0
- package/dist/platform/tools/tier2/bucketTools.js +6 -0
- package/dist/skills/createSkillAgent.js +0 -1
- package/dist/types.d.ts +2 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.46.5
|
|
6
|
+
|
|
7
|
+
- Every hosted Claude agent has `bucket_create` and `bucket_send`, loaded with their schemas, and its instructions say a new conversation starts in a bucket made on purpose. Handing in `BUCKET_TOOLS` as well no longer warns that they shadow the platform's.
|
|
8
|
+
- The bucket block in a wake names the agreements the work in the bucket is under, and who is waiting to join when their hire starts.
|
|
9
|
+
|
|
10
|
+
## 0.46.4
|
|
11
|
+
|
|
12
|
+
- `ARTIFACT_TOOLS` no longer includes `artifact_share`, and skill agents are no longer offered it: an artifact reaches people only by being added to a bucket. What an agent makes while working in a bucket lands in that bucket on its own.
|
|
13
|
+
- A message or task wake runs on the lane of the bucket it was put in, `bkt-<bucketId>-r<revision>`; the inbox row says which bucket. Wakes in one bucket run in order on its lane, and the agent's notes for the bucket carry over, kept under `bucket:<bucketId>-r<revision>`. The Claude session does not carry over: each wake starts with its own threads in the bucket loaded and everything else in it listed, read under the wake's run. The revision goes up when the bucket's audience changes or an item leaves, which starts a new lane. A wake in none of the agent's buckets runs on its execution lane.
|
|
14
|
+
- Thread lanes are removed: `threadLaneId` is gone, `laneKeyFor` takes `{ execution, bucket }`, and the inbox no longer reads or requires a message's thread root. `bucketLaneId` and `LaneBucket` are exported.
|
|
15
|
+
- `BUCKET_TOOLS` gives an agent the bucket tools; a run uses its bucket without them.
|
|
16
|
+
- A tool failure that carries `impact` (what the refusal is about, such as a bucket's misfits) is reported as the whole refusal, as one with `choices` or `recovery` already was, so the agent can list it.
|
|
17
|
+
|
|
5
18
|
## 0.46.3
|
|
6
19
|
|
|
7
20
|
- A `proposal_approved` or `proposal_rejected` wake now reads as the answer to the agent's own proposal or claim, which is the only agent the server hands it to. Approved: do the next step (create the first task under the hire, reading the request with `message_list` if the wake does not carry it). Declined: tell the person and ask what to change. It used to read as a provider's "your listing was claimed, wait for the buyer", so a hire the agent had just been approved for stalled.
|
package/dist/Agent.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { type BrainSelection } from './brain/index.js';
|
|
|
8
8
|
export { DEFAULT_MODEL, resolveFleetModel } from './shared/fleetModel.js';
|
|
9
9
|
export type { CognitionKind };
|
|
10
10
|
import { type WaitForIdleResult } from './platform/EventQueue.js';
|
|
11
|
+
import { type LaneBucket } from './platform/laneKey.js';
|
|
11
12
|
import { type NormalizedEvent } from './ingress/normalizeIncoming.js';
|
|
12
13
|
import { type MemoryStore } from './memory/MemoryStore.js';
|
|
13
14
|
/**
|
|
@@ -222,8 +223,8 @@ export interface WakeRecord {
|
|
|
222
223
|
sessionId: string;
|
|
223
224
|
laneKey: string;
|
|
224
225
|
executionContext?: WorkExecutionContext;
|
|
225
|
-
/** The
|
|
226
|
-
|
|
226
|
+
/** The bucket a message wake was sent in, when it runs on a bucket lane. */
|
|
227
|
+
bucket?: LaneBucket;
|
|
227
228
|
/** The event frame that woke the agent. */
|
|
228
229
|
event: unknown;
|
|
229
230
|
/** FSM context carried into the tick — undefined on a cold lane. */
|
|
@@ -355,6 +356,12 @@ export declare class Agent {
|
|
|
355
356
|
* suppression costs tokens, while a wrongly suppressed turn drops work.
|
|
356
357
|
*/
|
|
357
358
|
private recordWakeOutcome;
|
|
359
|
+
/**
|
|
360
|
+
* What is in the wake's bucket as this run can read it. The message being
|
|
361
|
+
* answered is named so its thread, which the snapshot already carries, is
|
|
362
|
+
* marked rather than repeated.
|
|
363
|
+
*/
|
|
364
|
+
private bucketContents;
|
|
358
365
|
private memoryForWake;
|
|
359
366
|
/**
|
|
360
367
|
* A chat-lane session that still carries a cancelled hire from a previous
|
|
@@ -501,6 +508,7 @@ export declare class Agent {
|
|
|
501
508
|
wakeTaskAssignment(taskId: string, options?: {
|
|
502
509
|
fromInbox?: boolean;
|
|
503
510
|
inputs?: import('./types.js').TaskInputRef[];
|
|
511
|
+
bucket?: LaneBucket;
|
|
504
512
|
}): Promise<void>;
|
|
505
513
|
/**
|
|
506
514
|
* Stop taking work. Timers and polls stop at once; the inbox loop cancels
|
package/dist/Agent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { runWorkExecution } from '@ziggs-ai/api-client';
|
|
2
|
-
import { MessageRecordsClient } from '@ziggs-ai/api-client/http';
|
|
2
|
+
import { BucketsClient, MessageRecordsClient } from '@ziggs-ai/api-client/http';
|
|
3
3
|
import { responseCommand } from './runtime/messageCommand.js';
|
|
4
4
|
import { validateWorkExecution, withWorkExecution, currentWorkExecution } from '@ziggs-ai/api-client';
|
|
5
5
|
import { SERVER_EVENTS } from '@ziggs-ai/contracts';
|
|
@@ -21,7 +21,7 @@ export { DEFAULT_MODEL, resolveFleetModel } from './shared/fleetModel.js';
|
|
|
21
21
|
import { contextReadTool, openTool, accessExplainTool } from './platform/tools/tier2/contextTools.js';
|
|
22
22
|
import { EventQueue } from './platform/EventQueue.js';
|
|
23
23
|
import { StateTimers } from './platform/StateTimers.js';
|
|
24
|
-
import { laneKeyFor, runInLane
|
|
24
|
+
import { bucketLaneId, laneKeyFor, runInLane } from './platform/laneKey.js';
|
|
25
25
|
import { WakeLedger } from './platform/WakeLedger.js';
|
|
26
26
|
import { WAKE_TOOLS } from './platform/tools/tier1/wakeTools.js';
|
|
27
27
|
import { createZiggsEffectHandler } from './platform/ZiggsEffectHandler.js';
|
|
@@ -58,7 +58,7 @@ async function loadConnectionPool() {
|
|
|
58
58
|
}
|
|
59
59
|
const DEFAULT_SESSION_RESOLVER = (normalized) => normalized.addressId
|
|
60
60
|
?? (normalized.event.agreementId ? `agrn-${normalized.event.agreementId}`
|
|
61
|
-
: normalized.event.
|
|
61
|
+
: normalized.event.bucket ? `bkt-${normalized.event.bucket.bucketId}`
|
|
62
62
|
: normalized.event.messageId ? `msgn-${normalized.event.messageId}` : null);
|
|
63
63
|
/**
|
|
64
64
|
* one lane key per unit of work, derived the same way as inbox wakes.
|
|
@@ -142,10 +142,15 @@ function createToolManager(options) {
|
|
|
142
142
|
export function warnOnShadowedPlatformTools(platformTools, ownTools, agentId) {
|
|
143
143
|
if (ownTools.length === 0)
|
|
144
144
|
return;
|
|
145
|
-
const platform = new
|
|
145
|
+
const platform = new Map(platformTools.map((t) => [t.schema.function.name, t]));
|
|
146
|
+
// Handing in the platform's own tool (BUCKET_TOOLS beside the hosted
|
|
147
|
+
// defaults) shadows nothing.
|
|
146
148
|
const shadowed = ownTools
|
|
147
|
-
.
|
|
148
|
-
|
|
149
|
+
.filter((t) => {
|
|
150
|
+
const same = platform.get(t.schema.function.name);
|
|
151
|
+
return same !== undefined && same !== t;
|
|
152
|
+
})
|
|
153
|
+
.map((t) => t.schema.function.name);
|
|
149
154
|
if (shadowed.length === 0)
|
|
150
155
|
return;
|
|
151
156
|
console.warn(`[Agent] ${agentId}: tool name(s) ${shadowed.join(', ')} shadow the platform tools of the same name — ` +
|
|
@@ -698,16 +703,15 @@ export class Agent {
|
|
|
698
703
|
return;
|
|
699
704
|
}
|
|
700
705
|
const executionContext = metadata.executionContext;
|
|
701
|
-
// A request in a
|
|
702
|
-
// it knew from the
|
|
703
|
-
const
|
|
704
|
-
const laneKey = laneKeyFor(ownAgentId, sessionId, { execution: executionContext,
|
|
706
|
+
// A request sent in a bucket runs on the bucket's lane, so the agent keeps
|
|
707
|
+
// what it knew from the bucket's earlier messages (see laneKeyFor).
|
|
708
|
+
const bucket = normalized.event.bucket;
|
|
709
|
+
const laneKey = laneKeyFor(ownAgentId, sessionId, { execution: executionContext, bucket });
|
|
705
710
|
if (!this.sessions.has(laneKey)) {
|
|
706
711
|
this.sessions.set(laneKey, { sessionId, ownAgentId, executionContext });
|
|
707
712
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
this.sessions.get(laneKey).thread = { rootMessageId: threadRootId, laneId };
|
|
713
|
+
if (bucket && bucketLaneId(executionContext ?? currentWorkExecution(), bucket))
|
|
714
|
+
this.sessions.get(laneKey).bucket = bucket;
|
|
711
715
|
if (roomlessAgreementId)
|
|
712
716
|
this.sessions.get(laneKey).roomlessAgreementId = roomlessAgreementId;
|
|
713
717
|
// The inbox loop owns ack (act-before-ack, delivery law); the agent only
|
|
@@ -762,12 +766,23 @@ export class Agent {
|
|
|
762
766
|
llmCalls,
|
|
763
767
|
}), isTelemetryIngestEnabled(this.options.telemetryIngest));
|
|
764
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
* What is in the wake's bucket as this run can read it. The message being
|
|
771
|
+
* answered is named so its thread, which the snapshot already carries, is
|
|
772
|
+
* marked rather than repeated.
|
|
773
|
+
*/
|
|
774
|
+
async bucketContents(bucket) {
|
|
775
|
+
const action = currentWorkExecution()?.action;
|
|
776
|
+
return new BucketsClient(this.options.operatorKey, this.options.agentId).contents(bucket.bucketId, {
|
|
777
|
+
...(action?.kind === 'message' ? { current: action.id } : {}),
|
|
778
|
+
});
|
|
779
|
+
}
|
|
765
780
|
memoryForWake(session, event) {
|
|
766
781
|
const execution = currentWorkExecution();
|
|
767
|
-
// A
|
|
768
|
-
//
|
|
769
|
-
if (execution && session.
|
|
770
|
-
return partitionMemoryStore(this.memory, `
|
|
782
|
+
// A bucket lane keeps its notes for the bucket at this revision, as the
|
|
783
|
+
// lane is named: same bucket, same people, same items.
|
|
784
|
+
if (execution && session.bucket)
|
|
785
|
+
return partitionMemoryStore(this.memory, `bucket:${session.bucket.bucketId}-r${session.bucket.revision}`);
|
|
771
786
|
if (execution)
|
|
772
787
|
return partitionMemoryStore(this.memory, `execution:${execution.contextId}`);
|
|
773
788
|
const fromEvent = hireIdsFromEvent(event);
|
|
@@ -1227,7 +1242,7 @@ export class Agent {
|
|
|
1227
1242
|
try {
|
|
1228
1243
|
this.options.wakeTap({
|
|
1229
1244
|
executionContext: session.executionContext,
|
|
1230
|
-
...(session.
|
|
1245
|
+
...(session.bucket ? { bucket: session.bucket } : {}),
|
|
1231
1246
|
agentId: identity.agentId,
|
|
1232
1247
|
sessionId: identity.sessionId,
|
|
1233
1248
|
laneKey,
|
|
@@ -1342,7 +1357,11 @@ export class Agent {
|
|
|
1342
1357
|
: effect;
|
|
1343
1358
|
const operation = this.eff(scopedEffect);
|
|
1344
1359
|
pendingEffects.add(operation);
|
|
1345
|
-
|
|
1360
|
+
let response = await operation.finally(() => { pendingEffects.delete(operation); });
|
|
1361
|
+
// A wake on a bucket lane starts from the bucket: its own threads loaded
|
|
1362
|
+
// and the rest listed, read under this run.
|
|
1363
|
+
if (sameRoom && effect.kind === 'read-context' && session.bucket && response && typeof response === 'object')
|
|
1364
|
+
response = { ...response, bucket: await this.bucketContents(session.bucket) };
|
|
1346
1365
|
marks.observe(effect, response);
|
|
1347
1366
|
for (const key of marks.sentMessageKeys)
|
|
1348
1367
|
this.outboundMessages.mark(key);
|
|
@@ -1593,11 +1612,11 @@ export class Agent {
|
|
|
1593
1612
|
runtimeLog.info(this.options.name || 'agent', `replay: no wake on ${record.sessionId} — ${suppressed.because}`);
|
|
1594
1613
|
return { state: record.state };
|
|
1595
1614
|
}
|
|
1596
|
-
const
|
|
1615
|
+
const replayBucket = bucketLaneId(record.executionContext, record.bucket) ? record.bucket : undefined;
|
|
1597
1616
|
const memory = this.memoryForWake({
|
|
1598
1617
|
sessionId: record.sessionId,
|
|
1599
1618
|
ctx: record.ctx,
|
|
1600
|
-
...(
|
|
1619
|
+
...(replayBucket ? { bucket: replayBucket } : {}),
|
|
1601
1620
|
}, record.event);
|
|
1602
1621
|
// Same watchdog as a live wake, for the same reason: an unaborted Claude
|
|
1603
1622
|
// query outlives the promise that abandoned it and keeps spending.
|
|
@@ -1702,9 +1721,9 @@ export class Agent {
|
|
|
1702
1721
|
// work delivered by the inbox's task channel, not by a chat
|
|
1703
1722
|
// row — this is what reaches a task under a chat-less agreement or one
|
|
1704
1723
|
// the agent assigned to itself.
|
|
1705
|
-
onTask: async (task, inputs) => {
|
|
1724
|
+
onTask: async (task, inputs, wake) => {
|
|
1706
1725
|
try {
|
|
1707
|
-
await this.wakeTaskAssignment(task.taskId, { fromInbox: true, inputs });
|
|
1726
|
+
await this.wakeTaskAssignment(task.taskId, { fromInbox: true, inputs, ...(wake?.bucket ? { bucket: wake.bucket } : {}) });
|
|
1708
1727
|
}
|
|
1709
1728
|
catch (err) {
|
|
1710
1729
|
runtimeLog.warn(this.options.name || 'agent', `inbox task ${task.taskId} could not be woken: ${err.message}`);
|
|
@@ -1768,7 +1787,7 @@ export class Agent {
|
|
|
1768
1787
|
// The conversation the lane's messages came from, so a restarted host
|
|
1769
1788
|
// answers there too instead of reading the lane name as an address.
|
|
1770
1789
|
const addressId = this.sessions.get(laneKey)?.addressId;
|
|
1771
|
-
const
|
|
1790
|
+
const bucket = this.sessions.get(laneKey)?.bucket;
|
|
1772
1791
|
this.wakeLedger.arm({
|
|
1773
1792
|
laneKey,
|
|
1774
1793
|
sessionId,
|
|
@@ -1777,7 +1796,7 @@ export class Agent {
|
|
|
1777
1796
|
reason,
|
|
1778
1797
|
...(scope ? { scope } : {}),
|
|
1779
1798
|
...(addressId ? { addressId } : {}),
|
|
1780
|
-
...(
|
|
1799
|
+
...(bucket ? { bucket } : {}),
|
|
1781
1800
|
executionContext: currentWorkExecution() ? { ...currentWorkExecution(), attemptId: undefined } : undefined,
|
|
1782
1801
|
});
|
|
1783
1802
|
return { ...armed, durable: this.wakeLedger.durable };
|
|
@@ -1801,14 +1820,14 @@ export class Agent {
|
|
|
1801
1820
|
return;
|
|
1802
1821
|
}
|
|
1803
1822
|
for (const wake of pending) {
|
|
1804
|
-
if (wake.laneKey !== laneKeyFor(agentId, wake.sessionId, { execution: wake.executionContext,
|
|
1823
|
+
if (wake.laneKey !== laneKeyFor(agentId, wake.sessionId, { execution: wake.executionContext, bucket: wake.bucket }))
|
|
1805
1824
|
continue;
|
|
1806
1825
|
if (this.stateTimers.peek(wake.laneKey))
|
|
1807
1826
|
continue;
|
|
1808
1827
|
if (!this.sessions.has(wake.laneKey)) {
|
|
1809
|
-
const
|
|
1828
|
+
const onBucketLane = bucketLaneId(wake.executionContext, wake.bucket);
|
|
1810
1829
|
this.sessions.set(wake.laneKey, { sessionId: wake.sessionId, ownAgentId: agentId, executionContext: wake.executionContext,
|
|
1811
|
-
...(
|
|
1830
|
+
...(onBucketLane && wake.bucket ? { bucket: wake.bucket } : {}),
|
|
1812
1831
|
...(wake.addressId ? { addressId: wake.addressId } : {}) });
|
|
1813
1832
|
}
|
|
1814
1833
|
try {
|
|
@@ -1860,10 +1879,14 @@ export class Agent {
|
|
|
1860
1879
|
}
|
|
1861
1880
|
const selected = currentWorkExecution();
|
|
1862
1881
|
const sessionId = laneSessionIdForTask(full);
|
|
1863
|
-
|
|
1882
|
+
// A task in a bucket runs on the bucket's lane, like a message in it.
|
|
1883
|
+
const bucket = options?.bucket;
|
|
1884
|
+
const laneKey = laneKeyFor(agentId, sessionId, { execution: selected, bucket });
|
|
1864
1885
|
if (!this.sessions.has(laneKey)) {
|
|
1865
1886
|
this.sessions.set(laneKey, { sessionId, ownAgentId: agentId, executionContext: currentWorkExecution() });
|
|
1866
1887
|
}
|
|
1888
|
+
if (bucket && bucketLaneId(selected, bucket))
|
|
1889
|
+
this.sessions.get(laneKey).bucket = bucket;
|
|
1867
1890
|
await this.eventQueue.enqueue({
|
|
1868
1891
|
type: 'task_result',
|
|
1869
1892
|
// New facts must not disappear behind an unchanged task snapshot version.
|
|
@@ -468,7 +468,10 @@ export class ClaudeBrain {
|
|
|
468
468
|
// stateless-per-wake never resumes — each wake is a fresh
|
|
469
469
|
// transcript, so per-wake input stays flat instead of replaying the whole
|
|
470
470
|
// lane history every turn.
|
|
471
|
-
|
|
471
|
+
// A wake in a bucket starts from the bucket, not from an earlier wake's
|
|
472
|
+
// transcript: its own threads are loaded and the rest is listed.
|
|
473
|
+
const onBucketLane = !!contextSnap?.bucket;
|
|
474
|
+
const resumeId = this.statelessPerWake || onBucketLane ? undefined : nextCtx.claudeSessionId;
|
|
472
475
|
const consumeQuery = async (resume) => {
|
|
473
476
|
// Host watchdog abort (see TickInput.signal): stop consuming AND interrupt
|
|
474
477
|
// the query, so a timed-out wake never lingers as a token-burning zombie
|
|
@@ -606,7 +609,7 @@ export class ClaudeBrain {
|
|
|
606
609
|
}
|
|
607
610
|
catch (err) {
|
|
608
611
|
if (signal?.aborted && signal.reason?.code === 'TASK_CONTROL') {
|
|
609
|
-
nextCtx.claudeSessionId = this.statelessPerWake ? undefined : sessionId;
|
|
612
|
+
nextCtx.claudeSessionId = this.statelessPerWake || onBucketLane ? undefined : sessionId;
|
|
610
613
|
return { ctx: nextCtx, state: state ?? DEFAULT_STATE, parked: true, stateTimeoutUnhandled: false, metrics };
|
|
611
614
|
}
|
|
612
615
|
// Turn exhaustion arrives as a thrown error result, not a break, so it
|
|
@@ -657,7 +660,7 @@ export class ClaudeBrain {
|
|
|
657
660
|
// Stateless-per-wake keeps no session id — clear any carried over from the
|
|
658
661
|
// prior ctx so the next wake starts fresh too. Otherwise remember
|
|
659
662
|
// this wake's session for resume.
|
|
660
|
-
if (this.statelessPerWake)
|
|
663
|
+
if (this.statelessPerWake || onBucketLane)
|
|
661
664
|
nextCtx.claudeSessionId = undefined;
|
|
662
665
|
else if (sessionId)
|
|
663
666
|
nextCtx.claudeSessionId = sessionId;
|
|
@@ -68,6 +68,13 @@ export declare function claudeQueryOptions(params: ClaudeQueryOptionsParams): Op
|
|
|
68
68
|
export declare function extractAssistantText(message: SDKAssistantMessage): string;
|
|
69
69
|
/** One-line digest of a context snapshot for the wake prompt. */
|
|
70
70
|
export declare function summarizeContext(snap: Record<string, unknown> | null | undefined): string;
|
|
71
|
+
/**
|
|
72
|
+
* The bucket a wake runs in: the agent's own threads with their latest
|
|
73
|
+
* messages, and everything else in it listed by title, to read when needed.
|
|
74
|
+
* Being in the bucket means it can read these; nothing here is loaded but
|
|
75
|
+
* its own threads.
|
|
76
|
+
*/
|
|
77
|
+
export declare function bucketBlock(raw: unknown): string;
|
|
71
78
|
/**
|
|
72
79
|
* How a held task's deadline and reminder rule read in the prompt.
|
|
73
80
|
*
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Claude-Agent-SDK cognition pieces.
|
|
3
|
-
*
|
|
4
|
-
* Everything a Claude-brain agent needs to turn a Ziggs wake into a `query()`
|
|
5
|
-
* call, EXCEPT the loop itself. `ClaudeBrain` owns the loop (drive `query()`,
|
|
6
|
-
* collect metrics); this module owns the periphery so it lives in one place and
|
|
7
|
-
* is unit-testable without spinning up the SDK.
|
|
8
|
-
*
|
|
9
|
-
* The lockdown option set (`tools: []`, `strictMcpConfig`, `settingSources: []`,
|
|
10
|
-
* bypass permissions, no local settings) is a security boundary, not a default —
|
|
11
|
-
* it MUST be applied on every Claude-brain wake. Centralizing it here means a
|
|
12
|
-
* caller cannot silently drift from it.
|
|
13
|
-
*/
|
|
14
1
|
import { SERVER_EVENTS } from '@ziggs-ai/contracts';
|
|
15
2
|
import { SYSTEM_PROMPT_DYNAMIC_BOUNDARY, } from '@anthropic-ai/claude-agent-sdk';
|
|
16
3
|
import { decisionWords } from '@ziggs-ai/api-client';
|
|
@@ -103,7 +90,53 @@ export function summarizeContext(snap) {
|
|
|
103
90
|
const agreements = Array.isArray(snap.agreements) ? snap.agreements.length : 0;
|
|
104
91
|
const history = Array.isArray(snap.history) ? snap.history.length : 0;
|
|
105
92
|
const users = Array.isArray(snap.users) ? snap.users.length : 0;
|
|
106
|
-
return `${snap.workBrief ? `Work brief:\n${JSON.stringify(snap.workBrief)}\n` : ''}history=${history} messages, agreements=${agreements}, users=${users}${directArtifactGrantLine(snap)}${snap.work ? `\nWork context (exact scope, governing constraints and required dependencies):\n${JSON.stringify(snap.work)}` : ''}`;
|
|
93
|
+
return `${snap.workBrief ? `Work brief:\n${JSON.stringify(snap.workBrief)}\n` : ''}history=${history} messages, agreements=${agreements}, users=${users}${directArtifactGrantLine(snap)}${snap.work ? `\nWork context (exact scope, governing constraints and required dependencies):\n${JSON.stringify(snap.work)}` : ''}${bucketBlock(snap.bucket)}`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The bucket a wake runs in: the agent's own threads with their latest
|
|
97
|
+
* messages, and everything else in it listed by title, to read when needed.
|
|
98
|
+
* Being in the bucket means it can read these; nothing here is loaded but
|
|
99
|
+
* its own threads.
|
|
100
|
+
*/
|
|
101
|
+
export function bucketBlock(raw) {
|
|
102
|
+
if (!raw || typeof raw !== 'object')
|
|
103
|
+
return '';
|
|
104
|
+
const contents = raw;
|
|
105
|
+
if (!contents.bucket?.bucketId)
|
|
106
|
+
return '';
|
|
107
|
+
const lines = [
|
|
108
|
+
'',
|
|
109
|
+
`Bucket "${contents.bucket.name}" (${contents.bucket.bucketId}), for ${contents.bucket.audience.join(', ')}. Everyone in it can read everything listed here.`,
|
|
110
|
+
];
|
|
111
|
+
const threads = contents.threads ?? [];
|
|
112
|
+
const yours = threads.filter((t) => t.yours && !t.current);
|
|
113
|
+
if (yours.length) {
|
|
114
|
+
lines.push('Your other threads here, latest messages:');
|
|
115
|
+
for (const thread of yours) {
|
|
116
|
+
lines.push(`- ${thread.title} (thread ${thread.rootMessageId}, ${thread.messageCount} messages)`);
|
|
117
|
+
for (const m of thread.recent ?? [])
|
|
118
|
+
lines.push(` ${m.from}: ${m.text}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const others = threads.filter((t) => !t.yours);
|
|
122
|
+
if (others.length) {
|
|
123
|
+
lines.push('Other threads here, not loaded:');
|
|
124
|
+
for (const thread of others)
|
|
125
|
+
lines.push(`- ${thread.title} (thread ${thread.rootMessageId}, ${thread.messageCount} messages)`);
|
|
126
|
+
}
|
|
127
|
+
if (contents.artifacts?.length)
|
|
128
|
+
lines.push(`Artifacts: ${contents.artifacts.map((a) => `${a.artifactId}${a.name ? ` (${a.name})` : ''}`).join(', ')}.`);
|
|
129
|
+
if (contents.tasks?.length)
|
|
130
|
+
lines.push(`Tasks: ${contents.tasks.map((t) => `${t.taskId} (${t.title}, ${t.state})`).join(', ')}.`);
|
|
131
|
+
if (contents.agreements?.length)
|
|
132
|
+
lines.push(`Agreements the work here is under: ${contents.agreements.map((a) => `${a.agreementId} (${a.title}, ${a.status})`).join(', ')}.`);
|
|
133
|
+
if (contents.invites?.length)
|
|
134
|
+
lines.push(`Waiting to join when their hire starts: ${contents.invites.map((i) => `${i.waitingFor.join(', ') || 'whoever claims it'} (${i.agreementId})`).join('; ')}.`);
|
|
135
|
+
if (threads.length > 1 || contents.artifacts?.length || contents.tasks?.length || contents.agreements?.length)
|
|
136
|
+
lines.push('Read a thread with message_list conversationOf=<thread>; an artifact with context_read type=artifacts via=artifact:<id>.');
|
|
137
|
+
if (contents.outOfReach > 0)
|
|
138
|
+
lines.push(`${contents.outOfReach} more item(s) here are out of this run's reach.`);
|
|
139
|
+
return lines.join('\n');
|
|
107
140
|
}
|
|
108
141
|
/** Ids and names only. Absent when the wake has nothing outside the room inventory. */
|
|
109
142
|
function directArtifactGrantLine(snap) {
|
|
@@ -18,7 +18,7 @@ Each wake hands you ONE event (or a small batch). Read workBrief for current wor
|
|
|
18
18
|
|
|
19
19
|
Ziggs tools loaded with their full schemas are ${loadedByName}, plus any tools that belong to you specifically. Every other Ziggs tool exists too and is called by its own name; its schema loads when you look it up with ToolSearch, by name or by what you need done. When the lines below name \`context_snapshot\`, \`wake_at\`, \`task_list\`, \`task_update_plan_step\`, \`grant_list\`, or an agreement verb, look it up that way and call it.
|
|
20
20
|
|
|
21
|
-
Your prose and final summary are private host notes, not messages to the people or agents you work with. To reply, use the reply action in workBrief: it sends your text, and the host links it to the message that woke you and delivers it to that message's readers and sender. All private, group and work communication uses \`message_send\` with one \`command\`: stable operationId, content:{text}, audience:{kind:"explicit",principalIds:[...]}, deliveries:{kind:"explicit",principalIds:[...]}, and intent. Every message carries one flag: intent:"request" wakes the agents it is delivered to; intent:"fyi" is delivered and filed and never wakes anyone. You are woken only for requests; an fyi reaches your inbox without waking you. Flag your own message a request only when you need the other side's agent to act on it; a reply to a person is an fyi. Nothing records whether a request was answered: a reply is a message whose relationships.replyToMessageId names what it answers. Keep an explicitly selected mandate:{agreementId,taskId?}. Reuse the exact command after an uncertain response. Never treat a 409 as success. Reading the question and writing the answer in your final summary does not deliver it: send it.
|
|
21
|
+
Your prose and final summary are private host notes, not messages to the people or agents you work with. To reply, use the reply action in workBrief: it sends your text, and the host links it to the message that woke you and delivers it to that message's readers and sender. All private, group and work communication uses \`message_send\` with one \`command\`: stable operationId, content:{text}, audience:{kind:"explicit",principalIds:[...]}, deliveries:{kind:"explicit",principalIds:[...]}, and intent. Every message carries one flag: intent:"request" wakes the agents it is delivered to; intent:"fyi" is delivered and filed and never wakes anyone. You are woken only for requests; an fyi reaches your inbox without waking you. Flag your own message a request only when you need the other side's agent to act on it; a reply to a person is an fyi. Nothing records whether a request was answered: a reply is a message whose relationships.replyToMessageId names what it answers. Keep an explicitly selected mandate:{agreementId,taskId?}. Reuse the exact command after an uncertain response. Never treat a 409 as success. Reading the question and writing the answer in your final summary does not deliver it: send it. A reply, and a message about the work you were woken for, go into its bucket on their own. A new conversation with people you are not already talking with starts in a bucket made on purpose: \`bucket_create\` with its name and the people it is for, then \`bucket_send\` inside it, which names only who is told, since everyone in a bucket reads it.
|
|
22
22
|
|
|
23
23
|
- The event identifies the assigned action. Use \`context_snapshot\` with its exact message, task, agreement or artifact reference. Readers, delivery recipients and the agents a request wakes are separate. An fyi creates no obligation; a message linked to a task (relationships.taskIds or a task mandate) is that task's input and advances it. Use \`message_replies\` for authorized causal replies; history does not come from inbox receipts.
|
|
24
24
|
- For factual answers, read relevant source artifacts before concluding information is missing. The snapshot's artifact list is a bounded inventory, not document contents; use \`context_read\` on the room's artifacts and follow pagination, or search artifacts when that tool is available. An empty direct \`grant_list\` is not evidence that room documents are unavailable. Report dated information with its date and distinguish it from a fresh confirmation. Check shared sources before repeating another agent's unsupported "no data" conclusion.
|
|
@@ -4,6 +4,7 @@ import { toolsFromCapabilities } from '../tools/capabilityAdapter.js';
|
|
|
4
4
|
import { defineTool } from '../tools/defineTool.js';
|
|
5
5
|
import { listGrantsTool } from '../platform/tools/tier2/grantsTools.js';
|
|
6
6
|
import { cancelTaskTool, listTasksTool, delegateTaskTool } from '../platform/tools/tier2/taskTools.js';
|
|
7
|
+
import { BUCKET_TOOLS } from '../platform/tools/tier2/bucketTools.js';
|
|
7
8
|
// Optional message history stays bounded; deeper history is an explicit read.
|
|
8
9
|
const DEFAULT_SNAPSHOT_MAX_MESSAGES = 12;
|
|
9
10
|
/** Blank selectors do not replace the current wake's exact resource scope. */
|
|
@@ -75,6 +76,12 @@ export const messageSendTool = defineTool('message_send', { command: { type: 'ob
|
|
|
75
76
|
// Claude surface previously had no way to enumerate its own open tasks (reads
|
|
76
77
|
// were prompt-injected only). Same GET /tasks capability as the MCP tool.
|
|
77
78
|
export { listTasksTool, cancelTaskTool, delegateTaskTool };
|
|
79
|
+
/**
|
|
80
|
+
* A new conversation starts in a bucket made on purpose: the agent creates one
|
|
81
|
+
* with the people it is for and sends inside it. Every hosted agent has these
|
|
82
|
+
* two, the same tool objects `BUCKET_TOOLS` hands out.
|
|
83
|
+
*/
|
|
84
|
+
const BUCKET_DEFAULTS = BUCKET_TOOLS.filter((tool) => ['bucket_create', 'bucket_send'].includes(String(tool.schema.function.name)));
|
|
78
85
|
export const CLAUDE_SDK_TOOLS = [
|
|
79
86
|
contextSnapshotTool,
|
|
80
87
|
messageSendTool,
|
|
@@ -83,4 +90,5 @@ export const CLAUDE_SDK_TOOLS = [
|
|
|
83
90
|
cancelTaskTool,
|
|
84
91
|
delegateTaskTool,
|
|
85
92
|
...toolsFromCapabilities(MESSAGING_CAPABILITIES),
|
|
93
|
+
...BUCKET_DEFAULTS,
|
|
86
94
|
];
|
|
@@ -2,7 +2,7 @@ import { describeOperationError } from '@ziggs-ai/api-client';
|
|
|
2
2
|
/** Keep the same refusal and callable recovery on every agent runtime. */
|
|
3
3
|
export function toolFailureText(err) {
|
|
4
4
|
const failure = describeOperationError(err, 'sdk');
|
|
5
|
-
if (failure.recovery || failure.choices)
|
|
5
|
+
if (failure.recovery || failure.choices || failure.impact)
|
|
6
6
|
return JSON.stringify(failure);
|
|
7
7
|
const message = failure.code === 'TOOL_ERROR' || failure.message.startsWith(`${failure.code}:`)
|
|
8
8
|
? failure.message : `${failure.code}: ${failure.message}`;
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export { EventQueue } from './platform/EventQueue.js';
|
|
|
31
31
|
export type { EventQueueBusyLane, WaitForIdleResult } from './platform/EventQueue.js';
|
|
32
32
|
export { StateTimers, MAX_WAKE_DELAY_MS } from './platform/StateTimers.js';
|
|
33
33
|
export type { StateTimeoutEvent, WakeAtEvent, TimerEvent } from './platform/StateTimers.js';
|
|
34
|
-
export { laneKeyFor,
|
|
34
|
+
export { bucketLaneId, laneKeyFor, type LaneBucket } from './platform/laneKey.js';
|
|
35
35
|
export type { LaneWake, LaneExecution } from './platform/laneKey.js';
|
|
36
36
|
export { wakeAtTool, WAKE_TOOLS } from './platform/tools/tier1/wakeTools.js';
|
|
37
37
|
export type { WakeSchedulerPort } from './platform/tools/tier1/wakeTools.js';
|
|
@@ -71,7 +71,7 @@ export { HistoryFormatter, historyFormatter, AgreementFormatter, agreementFormat
|
|
|
71
71
|
export { ProactiveTrigger } from './platform/proactive/ProactiveTrigger.js';
|
|
72
72
|
export { PollRegistry, declaredPolls, type PollBinding, type PollContext, type PollKind, type PollResult, } from './platform/polls/PollKind.js';
|
|
73
73
|
export { PollRunner, type PollRunnerOptions, type WakeTarget } from './platform/polls/PollRunner.js';
|
|
74
|
-
export { PROTOCOL_TOOLS, agreementProposeTool, agreementSubcontractTool, agreementRespondTool, agreementClaimTool, agreementCounterTool, agreementGetTool, agreementRevokeTool, agreementFulfillTool, taskCreateTool, taskSetResultTool, taskUpdatePlanStepTool, dispatchProtocolOp, PAYMENT_TOOLS, paymentBalanceTool, CONNECTION_TOOLS, connectionProxyTool, connectionListGrantsTool, requestConnectionTool, MCP_CONNECTION_TOOLS, mcpToolCallTool, mcpToolsListTool, DISCOVERY_TOOLS, agentSearchTool, agentGetTool, MARKETPLACE_TOOLS, marketplaceViewTool, CONTEXT_TOOLS, contextReadTool, accessRequestTool, contextDelegateTool, contextExpandReachTool, contextDiscoverGrantableTool, GRANTS_TOOLS, listGrantsTool, PLAN_TOOLS, taskReplacePlanTool, LINK_TOOLS, linkProposeTool, linkListTool, INTRODUCTION_TOOLS, introductionMintTool, introductionRedeemTool, introductionListTool, introductionRevokeTool, PARTY_TOOLS, partyNoteTool, ARTIFACT_TOOLS, recordArtifactTool, LISTING_TOOLS, } from './platform/tools/index.js';
|
|
74
|
+
export { PROTOCOL_TOOLS, agreementProposeTool, agreementSubcontractTool, agreementRespondTool, agreementClaimTool, agreementCounterTool, agreementGetTool, agreementRevokeTool, agreementFulfillTool, taskCreateTool, taskSetResultTool, taskUpdatePlanStepTool, dispatchProtocolOp, PAYMENT_TOOLS, paymentBalanceTool, CONNECTION_TOOLS, connectionProxyTool, connectionListGrantsTool, requestConnectionTool, MCP_CONNECTION_TOOLS, mcpToolCallTool, mcpToolsListTool, DISCOVERY_TOOLS, agentSearchTool, agentGetTool, MARKETPLACE_TOOLS, marketplaceViewTool, CONTEXT_TOOLS, contextReadTool, accessRequestTool, contextDelegateTool, contextExpandReachTool, contextDiscoverGrantableTool, GRANTS_TOOLS, listGrantsTool, BUCKET_TOOLS, PLAN_TOOLS, taskReplacePlanTool, LINK_TOOLS, linkProposeTool, linkListTool, INTRODUCTION_TOOLS, introductionMintTool, introductionRedeemTool, introductionListTool, introductionRevokeTool, PARTY_TOOLS, partyNoteTool, ARTIFACT_TOOLS, recordArtifactTool, LISTING_TOOLS, } from './platform/tools/index.js';
|
|
75
75
|
export { CLAUDE_SDK_TOOLS } from './brain/claudeSdkTools.js';
|
|
76
76
|
export { hostedModelTools, isHostedDeferred, hostedToolLane } from './brain/hostedToolSurface.js';
|
|
77
77
|
export { PROTOCOL_TOOL_NAMES, PROTOCOL_TOOL_TO_OPERATION, mapProtocolToolToOperation, isProtocolToolName } from './tasks/protocolRegistry.js';
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ export { handlerBrain, ziggsBrain, claudeBrain, isBrainSelection, isClaudeCognit
|
|
|
31
31
|
export { createZiggsEffectHandler } from './platform/ZiggsEffectHandler.js';
|
|
32
32
|
export { EventQueue } from './platform/EventQueue.js';
|
|
33
33
|
export { StateTimers, MAX_WAKE_DELAY_MS } from './platform/StateTimers.js';
|
|
34
|
-
export {
|
|
34
|
+
export { bucketLaneId, laneKeyFor } from './platform/laneKey.js';
|
|
35
35
|
// "wake me at", for both brains.
|
|
36
36
|
export { wakeAtTool, WAKE_TOOLS } from './platform/tools/tier1/wakeTools.js';
|
|
37
37
|
export { OutboxBuffer } from './platform/OutboxBuffer.js';
|
|
@@ -82,7 +82,7 @@ export {
|
|
|
82
82
|
// Tier 1 — protocol grammar (framework-managed via taskTools).
|
|
83
83
|
PROTOCOL_TOOLS, agreementProposeTool, agreementSubcontractTool, agreementRespondTool, agreementClaimTool, agreementCounterTool, agreementGetTool, agreementRevokeTool, agreementFulfillTool, taskCreateTool, taskSetResultTool, taskUpdatePlanStepTool, dispatchProtocolOp,
|
|
84
84
|
// Tier 2 — opt-in capability bundles (spread into `tools:`).
|
|
85
|
-
PAYMENT_TOOLS, paymentBalanceTool, CONNECTION_TOOLS, connectionProxyTool, connectionListGrantsTool, requestConnectionTool, MCP_CONNECTION_TOOLS, mcpToolCallTool, mcpToolsListTool, DISCOVERY_TOOLS, agentSearchTool, agentGetTool, MARKETPLACE_TOOLS, marketplaceViewTool, CONTEXT_TOOLS, contextReadTool, accessRequestTool, contextDelegateTool, contextExpandReachTool, contextDiscoverGrantableTool, GRANTS_TOOLS, listGrantsTool, PLAN_TOOLS, taskReplacePlanTool, LINK_TOOLS, linkProposeTool, linkListTool, INTRODUCTION_TOOLS, introductionMintTool, introductionRedeemTool, introductionListTool, introductionRevokeTool, PARTY_TOOLS, partyNoteTool, ARTIFACT_TOOLS, recordArtifactTool, LISTING_TOOLS, } from './platform/tools/index.js';
|
|
85
|
+
PAYMENT_TOOLS, paymentBalanceTool, CONNECTION_TOOLS, connectionProxyTool, connectionListGrantsTool, requestConnectionTool, MCP_CONNECTION_TOOLS, mcpToolCallTool, mcpToolsListTool, DISCOVERY_TOOLS, agentSearchTool, agentGetTool, MARKETPLACE_TOOLS, marketplaceViewTool, CONTEXT_TOOLS, contextReadTool, accessRequestTool, contextDelegateTool, contextExpandReachTool, contextDiscoverGrantableTool, GRANTS_TOOLS, listGrantsTool, BUCKET_TOOLS, PLAN_TOOLS, taskReplacePlanTool, LINK_TOOLS, linkProposeTool, linkListTool, INTRODUCTION_TOOLS, introductionMintTool, introductionRedeemTool, introductionListTool, introductionRevokeTool, PARTY_TOOLS, partyNoteTool, ARTIFACT_TOOLS, recordArtifactTool, LISTING_TOOLS, } from './platform/tools/index.js';
|
|
86
86
|
// The always-on toolset for the hosted Claude cognition (parity guard
|
|
87
87
|
// reads this as part of the real SDK registry).
|
|
88
88
|
export { CLAUDE_SDK_TOOLS } from './brain/claudeSdkTools.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LaneBucket } from '../platform/laneKey.js';
|
|
1
2
|
import type { AgreementParties } from '@ziggs-ai/api-client';
|
|
2
3
|
import type { MessageIntent } from '@ziggs-ai/contracts';
|
|
3
4
|
export interface NormalizedEvent {
|
|
@@ -14,10 +15,10 @@ export interface NormalizedEvent {
|
|
|
14
15
|
*/
|
|
15
16
|
messageId?: string;
|
|
16
17
|
/**
|
|
17
|
-
* The
|
|
18
|
-
*
|
|
18
|
+
* The bucket this message was sent in, found through the bucket's own
|
|
19
|
+
* pointer to it. It names the bucket lane; it grants nothing.
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
bucket?: LaneBucket;
|
|
21
22
|
timestamp: number;
|
|
22
23
|
/**
|
|
23
24
|
* `notification` = lifecycle / status notice. Not counterparty
|
|
@@ -56,8 +57,8 @@ interface WireMetadata {
|
|
|
56
57
|
taskId?: string;
|
|
57
58
|
addressId?: string;
|
|
58
59
|
messageId?: string;
|
|
59
|
-
/** The
|
|
60
|
-
|
|
60
|
+
/** The bucket the message was sent in, as the inbox found it. */
|
|
61
|
+
bucket?: LaneBucket;
|
|
61
62
|
entryType?: string;
|
|
62
63
|
contentType?: string;
|
|
63
64
|
operation?: string;
|
|
@@ -115,7 +115,10 @@ export function normalizeIncomingEvent({ text, metadata = {} }) {
|
|
|
115
115
|
receiverId: receiverId || undefined,
|
|
116
116
|
assigneeId: typeof metadata.assigneeId === 'string' ? metadata.assigneeId : undefined,
|
|
117
117
|
messageId: typeof metadata.messageId === 'string' && metadata.messageId ? metadata.messageId : undefined,
|
|
118
|
-
...(typeof metadata.
|
|
118
|
+
...(metadata.bucket && typeof metadata.bucket.bucketId === 'string' && metadata.bucket.bucketId
|
|
119
|
+
&& Number.isInteger(metadata.bucket.revision)
|
|
120
|
+
? { bucket: { bucketId: metadata.bucket.bucketId, revision: metadata.bucket.revision } }
|
|
121
|
+
: {}),
|
|
119
122
|
timestamp: Date.now(),
|
|
120
123
|
...(entryType ? { entryType } : {}),
|
|
121
124
|
...(metadata.intent === 'fyi' || metadata.intent === 'request' ? { intent: metadata.intent } : {}),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { WorkExecutionContext } from '@ziggs-ai/api-client';
|
|
2
2
|
import { type MemoryStore } from '../memory/MemoryStore.js';
|
|
3
3
|
import type { WorkScope } from '../runtime/wakeEffects.js';
|
|
4
|
+
import type { LaneBucket } from './laneKey.js';
|
|
4
5
|
/** One check-back an agent asked for, as it is kept across a restart. */
|
|
5
6
|
export interface SavedWake {
|
|
6
7
|
wakeId: string;
|
|
@@ -12,8 +13,8 @@ export interface SavedWake {
|
|
|
12
13
|
/** The conversation the lane's own messages came from, when it has one. */
|
|
13
14
|
addressId?: string;
|
|
14
15
|
executionContext?: WorkExecutionContext;
|
|
15
|
-
/** The
|
|
16
|
-
|
|
16
|
+
/** The bucket a bucket lane carries, so a restart names the same lane. */
|
|
17
|
+
bucket?: LaneBucket;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Where an agent's own check-backs are kept, so a restart does not lose them.
|
|
@@ -63,7 +63,7 @@ export class WakeLedger {
|
|
|
63
63
|
...(saved.scope ? { scope: saved.scope } : {}),
|
|
64
64
|
...(typeof saved.addressId === 'string' && saved.addressId ? { addressId: saved.addressId } : {}),
|
|
65
65
|
...(saved.executionContext ? { executionContext: saved.executionContext } : {}),
|
|
66
|
-
...(
|
|
66
|
+
...(isLaneBucket(saved.bucket) ? { bucket: { bucketId: saved.bucket.bucketId, revision: saved.bucket.revision } } : {}),
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
return out;
|
|
@@ -86,3 +86,7 @@ export class WakeLedger {
|
|
|
86
86
|
runtimeLog.warn('WakeLedger', `could not ${what} the wake for laneKey=${laneKey}: ${err?.message || err}`);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
function isLaneBucket(raw) {
|
|
90
|
+
const bucket = raw;
|
|
91
|
+
return typeof bucket?.bucketId === 'string' && !!bucket.bucketId && Number.isInteger(bucket.revision);
|
|
92
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type InboxRequestRef, type InboxTaskRef, type Creds } from '@ziggs-ai/api-client';
|
|
2
2
|
import { SeenMessages } from './SeenMessages.js';
|
|
3
|
+
import type { LaneBucket } from './laneKey.js';
|
|
3
4
|
import type { TaskInputRef } from '../types.js';
|
|
4
5
|
/**
|
|
5
6
|
* Per-agent inbox long-poll loop (delivery law, phase 4). This is the ONLY way
|
|
@@ -26,7 +27,10 @@ export interface InboxLoopDeps {
|
|
|
26
27
|
* own task channel, so work reaches the agent even when no chat row exists
|
|
27
28
|
* for it (chat-less agreement, self-assigned task).
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
+
/** `wake.bucket`: the bucket the task was put in, when it is in one of this agent's. */
|
|
31
|
+
onTask?: (task: InboxTaskRef, inputs: TaskInputRef[], wake?: {
|
|
32
|
+
bucket?: LaneBucket;
|
|
33
|
+
}) => Promise<void>;
|
|
30
34
|
/**
|
|
31
35
|
* A marketplace request doorbell. The host MUST triage with a plain
|
|
32
36
|
* string compare and return without an LLM wake on miss — otherwise every
|
|
@@ -145,10 +145,24 @@ function proposalIsMine(proposal, ownAgentId) {
|
|
|
145
145
|
return (proposal.pendingApprovalPartyIds?.includes(ownAgentId) === true ||
|
|
146
146
|
proposal.proposedTo === ownAgentId);
|
|
147
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* The bucket the server says these rows' item was put in, read loosely: a
|
|
150
|
+
* server older than buckets does not send it.
|
|
151
|
+
*/
|
|
152
|
+
function bucketOfRows(rows) {
|
|
153
|
+
for (const row of rows) {
|
|
154
|
+
const bucket = row.bucket;
|
|
155
|
+
if (typeof bucket?.bucketId === 'string' && Number.isInteger(bucket.revision))
|
|
156
|
+
return { bucketId: bucket.bucketId, revision: bucket.revision };
|
|
157
|
+
}
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
148
160
|
/** Read the exact request this agent was assigned and hand it to the host.
|
|
149
161
|
* Historical lookup is optional context, never handoff. A request's wake is
|
|
150
|
-
* its receipt: one receipt, one wake. The message
|
|
151
|
-
*
|
|
162
|
+
* its receipt: one receipt, one wake. The bucket the message was put in
|
|
163
|
+
* comes on the inbox row, worked out by the server from the bucket's pointer,
|
|
164
|
+
* and rides along as `bucket` so the host keeps the bucket on one lane. A
|
|
165
|
+
* message in none of the agent's buckets runs on its own execution. */
|
|
152
166
|
async function deliverAssignedMessage(deps, ref, reader, attempt, handledIds, turn) {
|
|
153
167
|
const receiptId = deliveryHandlingId(ref);
|
|
154
168
|
const handled = await attempt(`message ${ref.resourceId}`, () => (async () => {
|
|
@@ -157,13 +171,11 @@ async function deliverAssignedMessage(deps, ref, reader, attempt, handledIds, tu
|
|
|
157
171
|
const execution = await prepareWorkExecution(ref.action, deps.creds.operatorKey, deps.ownAgentId, deps.baseUrl);
|
|
158
172
|
return withWorkExecution(execution, async () => {
|
|
159
173
|
const row = await reader.get(ref.resourceId);
|
|
160
|
-
|
|
161
|
-
const threadRootId = row.rootMessageId;
|
|
162
|
-
if (typeof threadRootId !== 'string' || !threadRootId)
|
|
163
|
-
throw new Error(`Message ${row.messageId} names no thread root`);
|
|
174
|
+
const sentIn = bucketOfRows([ref]);
|
|
164
175
|
const metadata = { messageId: row.messageId, ...(row.mandate ?? {}),
|
|
165
176
|
sender: { id: row.sender.ref, type: row.sender.kind }, receiver: { id: deps.ownAgentId, type: 'agent' },
|
|
166
|
-
entryType: 'message', intent: row.intent, timestamp: row.timestamp, roomless: true,
|
|
177
|
+
entryType: 'message', intent: row.intent, timestamp: row.timestamp, roomless: true,
|
|
178
|
+
...(sentIn ? { bucket: sentIn } : {}) };
|
|
167
179
|
// Hand over in dispatch order; only the read above runs ahead.
|
|
168
180
|
await turn.ready;
|
|
169
181
|
const handover = deps.onMessage(row.content.text, {
|
|
@@ -362,7 +374,7 @@ export async function pollInboxOnce(deps, waitSeconds = 0, opts = {}) {
|
|
|
362
374
|
// task action instead and reaches the task executor below. Every assigned
|
|
363
375
|
// request is fetched by resource identity; navigation is optional.
|
|
364
376
|
//
|
|
365
|
-
// Oldest first: the messages of one
|
|
377
|
+
// Oldest first: the messages of one bucket must reach their lane in the
|
|
366
378
|
// order they were sent. Each runs as its own wake beside the others.
|
|
367
379
|
const assigned = envelope.deliveries
|
|
368
380
|
.filter(d => d.kind === 'message' && d.action?.kind === 'message' && d.actionState !== 'settled' && d.actionState !== 'waiting' && mine(d) && !d.outOfReach && !d.executionBlocked)
|
|
@@ -503,7 +515,8 @@ export async function pollInboxOnce(deps, waitSeconds = 0, opts = {}) {
|
|
|
503
515
|
startWake(runKey, async () => {
|
|
504
516
|
const handled = await attempt(`task ${task.taskId}`, async () => {
|
|
505
517
|
const executionContext = await prepareWorkExecution({ kind: 'task', id: task.taskId }, deps.creds.operatorKey, deps.ownAgentId, deps.baseUrl);
|
|
506
|
-
|
|
518
|
+
const bucket = bucketOfRows(receipts);
|
|
519
|
+
return withWorkExecution(executionContext, () => deps.onTask({ ...task, executionContext }, receipts.map(receipt => ({ kind: receipt.kind, id: receipt.resourceId, eventId: receipt.eventId ?? receipt.receiptId })), bucket ? { bucket } : undefined));
|
|
507
520
|
});
|
|
508
521
|
if (handled) {
|
|
509
522
|
deps.seen.mark(key);
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import { type WorkExecutionContext } from '@ziggs-ai/api-client';
|
|
2
2
|
/** The parts of an execution a lane is named from. */
|
|
3
3
|
export type LaneExecution = Pick<WorkExecutionContext, 'contextId' | 'agreementId'> & Partial<Pick<WorkExecutionContext, 'action' | 'taskId' | 'audienceIds'>>;
|
|
4
|
+
/** The bucket a message was sent in, as the wake found it. */
|
|
5
|
+
export interface LaneBucket {
|
|
6
|
+
bucketId: string;
|
|
7
|
+
/** Goes up when the bucket's audience changes or an item leaves it. */
|
|
8
|
+
revision: number;
|
|
9
|
+
}
|
|
4
10
|
/** What one wake's lane is computed from. */
|
|
5
11
|
export interface LaneWake {
|
|
6
12
|
/** The execution the wake runs under. Left out, the current one is used. */
|
|
7
13
|
execution?: LaneExecution;
|
|
8
|
-
/** The
|
|
9
|
-
|
|
14
|
+
/** The bucket the message or task a wake runs on was put in. */
|
|
15
|
+
bucket?: LaneBucket;
|
|
10
16
|
}
|
|
11
17
|
/**
|
|
12
|
-
* The
|
|
13
|
-
* wake does not run on one.
|
|
18
|
+
* The bucket lane of a wake: `bkt-<bucketId>-r<revision>`, or undefined when
|
|
19
|
+
* this wake does not run on one.
|
|
14
20
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* changes
|
|
20
|
-
*
|
|
21
|
+
* A wake whose action is a message or a task in a bucket the agent is in gets
|
|
22
|
+
* one; a task wake is a message wake with a bucket. Wakes in one bucket run
|
|
23
|
+
* on its lane one at a time, in order, and the agent's notes for the bucket
|
|
24
|
+
* carry over between them. The revision goes up when the bucket's audience
|
|
25
|
+
* changes or an item leaves, which starts a new lane: an agent carries over
|
|
26
|
+
* only what everyone in the bucket can read now.
|
|
21
27
|
*/
|
|
22
|
-
export declare function
|
|
28
|
+
export declare function bucketLaneId(execution: LaneExecution | undefined, bucket: LaneBucket | undefined): string | undefined;
|
|
23
29
|
/** Run `work` as the wake of `laneKey`, so a lane named inside it names this one. */
|
|
24
30
|
export declare function runInLane<T>(agentId: string, laneKey: string, work: () => T): T;
|
|
25
31
|
/** The lane of the wake running now, if any. */
|
|
@@ -34,8 +40,8 @@ export declare function currentLaneKey(): string | undefined;
|
|
|
34
40
|
* `a:b` while the queue dispatches `a::b` simply never wakes anything, with
|
|
35
41
|
* nothing in the logs to say so.
|
|
36
42
|
*
|
|
37
|
-
* - A message wake
|
|
38
|
-
* {@link
|
|
43
|
+
* - A message or task wake in a bucket runs on its bucket lane (see
|
|
44
|
+
* {@link bucketLaneId}).
|
|
39
45
|
* - Any other wake under an execution runs on that execution's own lane.
|
|
40
46
|
* - A wake under none runs on its session.
|
|
41
47
|
*
|
package/dist/platform/laneKey.js
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
2
|
import { currentWorkExecution } from '@ziggs-ai/api-client';
|
|
4
3
|
/**
|
|
5
|
-
* The
|
|
6
|
-
* wake does not run on one.
|
|
4
|
+
* The bucket lane of a wake: `bkt-<bucketId>-r<revision>`, or undefined when
|
|
5
|
+
* this wake does not run on one.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* changes
|
|
13
|
-
*
|
|
7
|
+
* A wake whose action is a message or a task in a bucket the agent is in gets
|
|
8
|
+
* one; a task wake is a message wake with a bucket. Wakes in one bucket run
|
|
9
|
+
* on its lane one at a time, in order, and the agent's notes for the bucket
|
|
10
|
+
* carry over between them. The revision goes up when the bucket's audience
|
|
11
|
+
* changes or an item leaves, which starts a new lane: an agent carries over
|
|
12
|
+
* only what everyone in the bucket can read now.
|
|
14
13
|
*/
|
|
15
|
-
export function
|
|
16
|
-
|
|
14
|
+
export function bucketLaneId(execution, bucket) {
|
|
15
|
+
const kind = execution?.action?.kind;
|
|
16
|
+
if (!bucket || (kind !== 'message' && kind !== 'task'))
|
|
17
17
|
return undefined;
|
|
18
|
-
|
|
19
|
-
const digest = createHash('sha256')
|
|
20
|
-
.update(JSON.stringify([threadRootId, execution.agreementId ?? null, execution.taskId ?? null, readers]))
|
|
21
|
-
.digest('hex')
|
|
22
|
-
.slice(0, 32);
|
|
23
|
-
return `thr-${digest}`;
|
|
18
|
+
return `bkt-${bucket.bucketId}-r${bucket.revision}`;
|
|
24
19
|
}
|
|
25
20
|
/** The lane a wake is running on right now, for calls that hold only a session id. */
|
|
26
21
|
const runningLane = new AsyncLocalStorage();
|
|
@@ -42,8 +37,8 @@ export function currentLaneKey() {
|
|
|
42
37
|
* `a:b` while the queue dispatches `a::b` simply never wakes anything, with
|
|
43
38
|
* nothing in the logs to say so.
|
|
44
39
|
*
|
|
45
|
-
* - A message wake
|
|
46
|
-
* {@link
|
|
40
|
+
* - A message or task wake in a bucket runs on its bucket lane (see
|
|
41
|
+
* {@link bucketLaneId}).
|
|
47
42
|
* - Any other wake under an execution runs on that execution's own lane.
|
|
48
43
|
* - A wake under none runs on its session.
|
|
49
44
|
*
|
|
@@ -57,6 +52,6 @@ export function laneKeyFor(agentId, sessionId, wake) {
|
|
|
57
52
|
return running.laneKey;
|
|
58
53
|
}
|
|
59
54
|
const execution = wake?.execution ?? currentWorkExecution();
|
|
60
|
-
const
|
|
61
|
-
return `${agentId}:${
|
|
55
|
+
const bucket = bucketLaneId(execution, wake?.bucket);
|
|
56
|
+
return `${agentId}:${bucket ?? execution?.contextId ?? sessionId}`;
|
|
62
57
|
}
|
|
@@ -24,6 +24,7 @@ export { PAYMENT_TOOLS, paymentBalanceTool } from './tier2/paymentTools.js';
|
|
|
24
24
|
export { CONNECTION_TOOLS, connectionProxyTool, connectionListGrantsTool, requestConnectionTool, } from './tier2/connectionTools.js';
|
|
25
25
|
export { CONTEXT_TOOLS, contextReadTool, accessRequestTool, contextDelegateTool, contextExpandReachTool, contextDiscoverGrantableTool, } from './tier2/contextTools.js';
|
|
26
26
|
export { GRANTS_TOOLS, listGrantsTool } from './tier2/grantsTools.js';
|
|
27
|
+
export { BUCKET_TOOLS } from './tier2/bucketTools.js';
|
|
27
28
|
export { TASK_TOOLS, listTasksTool, cancelTaskTool, delegateTaskTool } from './tier2/taskTools.js';
|
|
28
29
|
export { PLAN_TOOLS, taskReplacePlanTool } from './tier2/planTools.js';
|
|
29
30
|
export { LINK_TOOLS, linkProposeTool, linkListTool, } from './tier2/linkTools.js';
|
|
@@ -28,6 +28,7 @@ export { CONTEXT_TOOLS, contextReadTool, accessRequestTool, contextDelegateTool,
|
|
|
28
28
|
// one grant lister across every rail (retires context_discover +
|
|
29
29
|
// payment_list_grants). Always-available on the hosted agent — see CLAUDE_SDK_TOOLS.
|
|
30
30
|
export { GRANTS_TOOLS, listGrantsTool } from './tier2/grantsTools.js';
|
|
31
|
+
export { BUCKET_TOOLS } from './tier2/bucketTools.js';
|
|
31
32
|
export { TASK_TOOLS, listTasksTool, cancelTaskTool, delegateTaskTool } from './tier2/taskTools.js';
|
|
32
33
|
export { PLAN_TOOLS, taskReplacePlanTool } from './tier2/planTools.js';
|
|
33
34
|
// links (agreements with engagementKind 'link') — cross-org reach.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BUCKET_CAPABILITIES } from '@ziggs-ai/api-client';
|
|
2
|
+
import { toolsFromCapabilities } from '../../../tools/capabilityAdapter.js';
|
|
3
|
+
// Buckets: working sets whose whole audience can read every item in them.
|
|
4
|
+
// Opt-in: a run uses the bucket its message was sent in without these; an
|
|
5
|
+
// agent adds them to change buckets itself.
|
|
6
|
+
export const BUCKET_TOOLS = toolsFromCapabilities(BUCKET_CAPABILITIES);
|
package/dist/types.d.ts
CHANGED
|
@@ -371,6 +371,8 @@ export interface ContextSnapshot {
|
|
|
371
371
|
refused?: boolean;
|
|
372
372
|
/** The selector that was refused, e.g. `agreement:<id>`. */
|
|
373
373
|
refusedVia?: string;
|
|
374
|
+
/** On a bucket lane: what is in the bucket as this run can read it. */
|
|
375
|
+
bucket?: import('@ziggs-ai/api-client').BucketContents;
|
|
374
376
|
/** Index signature so PromptBuilder's `ServerContext` can accept it directly. */
|
|
375
377
|
[key: string]: unknown;
|
|
376
378
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ziggs-ai/agent-sdk",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.5",
|
|
4
4
|
"description": "Agent framework SDK for building autonomous agents on the Ziggs platform",
|
|
5
5
|
"homepage": "https://ziggsai.com/docs",
|
|
6
6
|
"bugs": {
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@anthropic-ai/claude-agent-sdk": "^0.3.284",
|
|
31
31
|
"@anthropic-ai/sdk": "^0.110.0",
|
|
32
32
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
33
|
-
"@ziggs-ai/api-client": "0.40.
|
|
34
|
-
"@ziggs-ai/contracts": "0.
|
|
33
|
+
"@ziggs-ai/api-client": "0.40.7",
|
|
34
|
+
"@ziggs-ai/contracts": "0.48.1",
|
|
35
35
|
"ajv": "^8.17.1",
|
|
36
36
|
"dotenv": "^17.2.3",
|
|
37
37
|
"openai": "^4.0.0",
|