@ziggs-ai/agent-sdk 0.48.5 → 0.48.6
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 +2 -0
- package/dist/Agent.d.ts +7 -0
- package/dist/Agent.js +40 -3
- package/dist/platform/laneKey.d.ts +4 -3
- package/dist/platform/laneKey.js +4 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/Agent.d.ts
CHANGED
|
@@ -361,6 +361,13 @@ export declare class Agent {
|
|
|
361
361
|
* marked rather than repeated.
|
|
362
362
|
*/
|
|
363
363
|
private bucketContents;
|
|
364
|
+
/**
|
|
365
|
+
* Keeps a bucket's notes honest across revisions. The notes carry over a
|
|
366
|
+
* join or a leave. When an item the notes were written under is no longer
|
|
367
|
+
* readable in the bucket, the notes are cleared, since they may hold what
|
|
368
|
+
* came from it. The items seen are kept beside the notes.
|
|
369
|
+
*/
|
|
370
|
+
private syncBucketNotes;
|
|
364
371
|
private memoryForWake;
|
|
365
372
|
/**
|
|
366
373
|
* A chat-lane session that still carries a cancelled hire from a previous
|
package/dist/Agent.js
CHANGED
|
@@ -56,6 +56,7 @@ async function loadConnectionPool() {
|
|
|
56
56
|
const mod = await import(/* @vite-ignore */ modPath);
|
|
57
57
|
return mod.ConnectionPool;
|
|
58
58
|
}
|
|
59
|
+
const BUCKET_MARKER_KEY = '__bucket_items';
|
|
59
60
|
const DEFAULT_SESSION_RESOLVER = (normalized) => normalized.event.agreementId ? `agrn-${normalized.event.agreementId}`
|
|
60
61
|
: normalized.event.bucket ? `bkt-${normalized.event.bucket.bucketId}`
|
|
61
62
|
: normalized.event.messageId ? `msgn-${normalized.event.messageId}` : null;
|
|
@@ -776,12 +777,46 @@ export class Agent {
|
|
|
776
777
|
...(action?.kind === 'message' ? { current: action.id } : {}),
|
|
777
778
|
});
|
|
778
779
|
}
|
|
780
|
+
/**
|
|
781
|
+
* Keeps a bucket's notes honest across revisions. The notes carry over a
|
|
782
|
+
* join or a leave. When an item the notes were written under is no longer
|
|
783
|
+
* readable in the bucket, the notes are cleared, since they may hold what
|
|
784
|
+
* came from it. The items seen are kept beside the notes.
|
|
785
|
+
*/
|
|
786
|
+
async syncBucketNotes(bucket) {
|
|
787
|
+
const notes = partitionMemoryStore(this.memory, `bucket:${bucket.bucketId}`);
|
|
788
|
+
const marker = (await notes.get(BUCKET_MARKER_KEY));
|
|
789
|
+
if (marker && marker.revision === bucket.revision)
|
|
790
|
+
return;
|
|
791
|
+
let items;
|
|
792
|
+
try {
|
|
793
|
+
const c = await this.bucketContents(bucket);
|
|
794
|
+
items = [
|
|
795
|
+
...c.threads.map((t) => `thread:${t.rootMessageId}`),
|
|
796
|
+
...c.artifacts.map((a) => `artifact:${a.artifactId}`),
|
|
797
|
+
...c.tasks.map((t) => `task:${t.taskId}`),
|
|
798
|
+
];
|
|
799
|
+
}
|
|
800
|
+
catch {
|
|
801
|
+
items = undefined;
|
|
802
|
+
}
|
|
803
|
+
const itemLeft = !items || (marker ? marker.items.some((i) => !items.includes(i)) : false);
|
|
804
|
+
if (itemLeft) {
|
|
805
|
+
for (const row of await notes.list(''))
|
|
806
|
+
if (row.key !== BUCKET_MARKER_KEY)
|
|
807
|
+
await notes.delete?.(row.key);
|
|
808
|
+
}
|
|
809
|
+
if (items)
|
|
810
|
+
await notes.put(BUCKET_MARKER_KEY, { revision: bucket.revision, items });
|
|
811
|
+
else
|
|
812
|
+
await notes.delete?.(BUCKET_MARKER_KEY);
|
|
813
|
+
}
|
|
779
814
|
memoryForWake(session, event) {
|
|
780
815
|
const execution = currentWorkExecution();
|
|
781
|
-
// A bucket
|
|
782
|
-
//
|
|
816
|
+
// A bucket keeps its notes across revisions: someone joining or leaving
|
|
817
|
+
// does not empty them. `syncBucketNotes` clears them when an item left.
|
|
783
818
|
if (execution && session.bucket)
|
|
784
|
-
return partitionMemoryStore(this.memory, `bucket:${session.bucket.bucketId}
|
|
819
|
+
return partitionMemoryStore(this.memory, `bucket:${session.bucket.bucketId}`);
|
|
785
820
|
if (execution)
|
|
786
821
|
return partitionMemoryStore(this.memory, `execution:${execution.contextId}`);
|
|
787
822
|
const fromEvent = hireIdsFromEvent(event);
|
|
@@ -1216,6 +1251,8 @@ export class Agent {
|
|
|
1216
1251
|
}
|
|
1217
1252
|
if (runnable.length !== frames.length)
|
|
1218
1253
|
frame = runnable.length === 1 ? runnable[0] : { type: 'batch', events: runnable };
|
|
1254
|
+
if (session.bucket && currentWorkExecution())
|
|
1255
|
+
await this.syncBucketNotes(session.bucket);
|
|
1219
1256
|
const memory = this.memoryForWake(session, frame);
|
|
1220
1257
|
const wakeTaskId = workScopeFromWake(frame, session.sessionId).taskId;
|
|
1221
1258
|
// A checkout agent gets its box before the brain runs: the task names the
|
|
@@ -21,9 +21,10 @@ export interface LaneWake {
|
|
|
21
21
|
* A wake whose action is a message or a task in a bucket the agent is in gets
|
|
22
22
|
* one; a task wake is a message wake with a bucket. Wakes in one bucket run
|
|
23
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
|
|
25
|
-
* changes or an item leaves, which starts a new
|
|
26
|
-
* only
|
|
24
|
+
* carry over between them, and over a join or a leave. The revision goes up
|
|
25
|
+
* when the bucket's audience changes or an item leaves, which starts a new
|
|
26
|
+
* lane. The notes are cleared only when an item they were written under is
|
|
27
|
+
* no longer readable in the bucket.
|
|
27
28
|
*/
|
|
28
29
|
export declare function bucketLaneId(execution: LaneExecution | undefined, bucket: LaneBucket | undefined): string | undefined;
|
|
29
30
|
/** Run `work` as the wake of `laneKey`, so a lane named inside it names this one. */
|
package/dist/platform/laneKey.js
CHANGED
|
@@ -7,9 +7,10 @@ import { currentWorkExecution } from '@ziggs-ai/api-client';
|
|
|
7
7
|
* A wake whose action is a message or a task in a bucket the agent is in gets
|
|
8
8
|
* one; a task wake is a message wake with a bucket. Wakes in one bucket run
|
|
9
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
|
|
11
|
-
* changes or an item leaves, which starts a new
|
|
12
|
-
* only
|
|
10
|
+
* carry over between them, and over a join or a leave. The revision goes up
|
|
11
|
+
* when the bucket's audience changes or an item leaves, which starts a new
|
|
12
|
+
* lane. The notes are cleared only when an item they were written under is
|
|
13
|
+
* no longer readable in the bucket.
|
|
13
14
|
*/
|
|
14
15
|
export function bucketLaneId(execution, bucket) {
|
|
15
16
|
const kind = execution?.action?.kind;
|