@economic/agents 2.2.3 → 2.2.4
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/dist/index.d.mts +17 -17
- package/dist/index.mjs +46 -45
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -235,16 +235,31 @@ declare abstract class Assistant extends Agent$1<Cloudflare.Env & AgentEnv, Agen
|
|
|
235
235
|
onStart(): void;
|
|
236
236
|
onClose(): Promise<void>;
|
|
237
237
|
onConnect(connection: Connection, ctx: ConnectionContext): Promise<void>;
|
|
238
|
+
createChat(): Promise<string>;
|
|
239
|
+
deleteChat(id: string): Promise<void>;
|
|
240
|
+
getChats(): Promise<Chat[]>;
|
|
241
|
+
recordChatTurn(durableObjectName: string, messages: UIMessage[]): Promise<void>;
|
|
242
|
+
private [DELETE_CHAT_CALLBACK];
|
|
243
|
+
private scheduleChatForAutoDeletion;
|
|
244
|
+
/**
|
|
245
|
+
* Self-registers this Assistant in the global `agent_registry`. An Assistant
|
|
246
|
+
* is a top-level DO keyed directly by user id, so the DO name *is* the actor.
|
|
247
|
+
*
|
|
248
|
+
* Runs pre-auth in onStart (the DO has already persisted state by this point,
|
|
249
|
+
* so it must be tracked regardless of whether auth later succeeds).
|
|
250
|
+
* Best-effort and idempotent: no-ops on conflict, retried on the next start.
|
|
251
|
+
*/
|
|
252
|
+
private registerInstance;
|
|
238
253
|
/**
|
|
239
254
|
* Binding of the legacy v1 chat Durable Object class, used to migrate a
|
|
240
255
|
* user's v1 chats into facets the first time they connect. Set this on the
|
|
241
256
|
* concrete subclass to enable lazy v1 -> v2 migration; leave undefined to
|
|
242
257
|
* disable it (e.g. for greenfield deployments with no v1 data).
|
|
243
258
|
*/
|
|
244
|
-
protected
|
|
259
|
+
protected getMigrationBinding(_env: Cloudflare.Env & AgentEnv): {
|
|
245
260
|
binding: DurableObjectNamespace;
|
|
246
261
|
db: D1Database;
|
|
247
|
-
};
|
|
262
|
+
} | undefined;
|
|
248
263
|
/** In-flight migration, shared across concurrent connections to this DO. */
|
|
249
264
|
private _migrationPromise?;
|
|
250
265
|
/**
|
|
@@ -255,21 +270,6 @@ declare abstract class Assistant extends Agent$1<Cloudflare.Env & AgentEnv, Agen
|
|
|
255
270
|
*/
|
|
256
271
|
private ensureMigrated;
|
|
257
272
|
private runMigration;
|
|
258
|
-
createChat(): Promise<string>;
|
|
259
|
-
deleteChat(id: string): Promise<void>;
|
|
260
|
-
getChats(): Promise<Chat[]>;
|
|
261
|
-
recordChatTurn(durableObjectName: string, messages: UIMessage[]): Promise<void>;
|
|
262
|
-
private [DELETE_CHAT_CALLBACK];
|
|
263
|
-
private scheduleChatForAutoDeletion;
|
|
264
|
-
/**
|
|
265
|
-
* Self-registers this Assistant in the global `agent_registry`. An Assistant
|
|
266
|
-
* is a top-level DO keyed directly by user id, so the DO name *is* the actor.
|
|
267
|
-
*
|
|
268
|
-
* Runs pre-auth in onStart (the DO has already persisted state by this point,
|
|
269
|
-
* so it must be tracked regardless of whether auth later succeeds).
|
|
270
|
-
* Best-effort and idempotent: no-ops on conflict, retried on the next start.
|
|
271
|
-
*/
|
|
272
|
-
private registerInstance;
|
|
273
273
|
}
|
|
274
274
|
//#endregion
|
|
275
275
|
//#region src/server/index.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -559,51 +559,6 @@ var Assistant = class extends Agent$1 {
|
|
|
559
559
|
subAgentName: this.agent.name
|
|
560
560
|
});
|
|
561
561
|
}
|
|
562
|
-
/**
|
|
563
|
-
* Binding of the legacy v1 chat Durable Object class, used to migrate a
|
|
564
|
-
* user's v1 chats into facets the first time they connect. Set this on the
|
|
565
|
-
* concrete subclass to enable lazy v1 -> v2 migration; leave undefined to
|
|
566
|
-
* disable it (e.g. for greenfield deployments with no v1 data).
|
|
567
|
-
*/
|
|
568
|
-
migrationBinding;
|
|
569
|
-
/** In-flight migration, shared across concurrent connections to this DO. */
|
|
570
|
-
_migrationPromise;
|
|
571
|
-
/**
|
|
572
|
-
* Runs the lazy v1 -> v2 migration for this user. Concurrent connections to
|
|
573
|
-
* this DO share a single in-flight run. Idempotency across runs/restarts is
|
|
574
|
-
* handled by `migrateUserFromV1` deleting each chat's v1 `conversations` row,
|
|
575
|
-
* so an already-migrated chat is never re-enumerated.
|
|
576
|
-
*/
|
|
577
|
-
async ensureMigrated() {
|
|
578
|
-
if (!this.migrationBinding) return;
|
|
579
|
-
this._migrationPromise ??= this.runMigration().finally(() => {
|
|
580
|
-
this._migrationPromise = void 0;
|
|
581
|
-
});
|
|
582
|
-
await this._migrationPromise;
|
|
583
|
-
}
|
|
584
|
-
async runMigration() {
|
|
585
|
-
if (!this.migrationBinding) return;
|
|
586
|
-
try {
|
|
587
|
-
const result = await migrateUserFromV1({
|
|
588
|
-
sql: this.sql.bind(this),
|
|
589
|
-
db: this.migrationBinding.db,
|
|
590
|
-
userId: this.name,
|
|
591
|
-
durableObjectBinding: this.migrationBinding.binding,
|
|
592
|
-
createFacet: async (chatId) => {
|
|
593
|
-
return await this.subAgent(this.agent, chatId);
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
if (result.migrated > 0 || result.failed > 0) console.info("[Assistant] v1 -> v2 migration complete", {
|
|
597
|
-
userId: this.name,
|
|
598
|
-
...result
|
|
599
|
-
});
|
|
600
|
-
} catch (error) {
|
|
601
|
-
console.error("[Assistant] v1 -> v2 migration failed", {
|
|
602
|
-
userId: this.name,
|
|
603
|
-
error
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
562
|
@callable() async createChat() {
|
|
608
563
|
const id = nanoid();
|
|
609
564
|
const now = Date.now();
|
|
@@ -652,6 +607,52 @@ var Assistant = class extends Agent$1 {
|
|
|
652
607
|
console.error("[Assistant] Failed to register in agent_registry", error);
|
|
653
608
|
}
|
|
654
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* Binding of the legacy v1 chat Durable Object class, used to migrate a
|
|
612
|
+
* user's v1 chats into facets the first time they connect. Set this on the
|
|
613
|
+
* concrete subclass to enable lazy v1 -> v2 migration; leave undefined to
|
|
614
|
+
* disable it (e.g. for greenfield deployments with no v1 data).
|
|
615
|
+
*/
|
|
616
|
+
getMigrationBinding(_env) {}
|
|
617
|
+
/** In-flight migration, shared across concurrent connections to this DO. */
|
|
618
|
+
_migrationPromise;
|
|
619
|
+
/**
|
|
620
|
+
* Runs the lazy v1 -> v2 migration for this user. Concurrent connections to
|
|
621
|
+
* this DO share a single in-flight run. Idempotency across runs/restarts is
|
|
622
|
+
* handled by `migrateUserFromV1` deleting each chat's v1 `conversations` row,
|
|
623
|
+
* so an already-migrated chat is never re-enumerated.
|
|
624
|
+
*/
|
|
625
|
+
async ensureMigrated() {
|
|
626
|
+
if (!this.getMigrationBinding(this.env)) return;
|
|
627
|
+
this._migrationPromise ??= this.runMigration().finally(() => {
|
|
628
|
+
this._migrationPromise = void 0;
|
|
629
|
+
});
|
|
630
|
+
await this._migrationPromise;
|
|
631
|
+
}
|
|
632
|
+
async runMigration() {
|
|
633
|
+
const migrationBinding = this.getMigrationBinding(this.env);
|
|
634
|
+
if (!migrationBinding) return;
|
|
635
|
+
try {
|
|
636
|
+
const result = await migrateUserFromV1({
|
|
637
|
+
sql: this.sql.bind(this),
|
|
638
|
+
db: migrationBinding.db,
|
|
639
|
+
userId: this.name,
|
|
640
|
+
durableObjectBinding: migrationBinding.binding,
|
|
641
|
+
createFacet: async (chatId) => {
|
|
642
|
+
return await this.subAgent(this.agent, chatId);
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
if (result.migrated > 0 || result.failed > 0) console.info("[Assistant] v1 -> v2 migration complete", {
|
|
646
|
+
userId: this.name,
|
|
647
|
+
...result
|
|
648
|
+
});
|
|
649
|
+
} catch (error) {
|
|
650
|
+
console.error("[Assistant] v1 -> v2 migration failed", {
|
|
651
|
+
userId: this.name,
|
|
652
|
+
error
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
}
|
|
655
656
|
};
|
|
656
657
|
//#endregion
|
|
657
658
|
//#region src/server/features/messages.ts
|