@deepagents/experimental 7.1.2 → 7.1.3
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.js +69 -66
- package/dist/index.js.map +2 -2
- package/dist/zukhruf/index.js +69 -66
- package/dist/zukhruf/index.js.map +2 -2
- package/dist/zukhruf/mailbox/sqlite.store.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/index.js +2 -1
- package/dist/zukhruf/plugins/schedules/index.js.map +2 -2
- package/dist/zukhruf/plugins/schedules/scheduled-tasks.d.ts.map +1 -1
- package/package.json +13 -12
package/dist/zukhruf/index.js
CHANGED
|
@@ -188,6 +188,7 @@ function defineInstructions(...fragments) {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
// packages/experimental/src/zukhruf/mailbox/sqlite.store.ts
|
|
191
|
+
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
191
192
|
import { DatabaseSync } from "node:sqlite";
|
|
192
193
|
import { z } from "zod";
|
|
193
194
|
|
|
@@ -305,52 +306,64 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
305
306
|
this.#database.exec(DDL);
|
|
306
307
|
}
|
|
307
308
|
async beginTurn(recipient, turnId) {
|
|
308
|
-
|
|
309
|
-
this.#database
|
|
310
|
-
|
|
309
|
+
transaction(
|
|
310
|
+
this.#database,
|
|
311
|
+
() => {
|
|
312
|
+
this.#database.prepare(
|
|
313
|
+
`INSERT INTO zukhruf_mailbox_activity (
|
|
311
314
|
recipient_chat_id,
|
|
312
315
|
recipient_user_id,
|
|
313
316
|
turn_id
|
|
314
317
|
) VALUES (?, ?, ?)
|
|
315
318
|
ON CONFLICT (recipient_chat_id, recipient_user_id)
|
|
316
319
|
DO UPDATE SET turn_id = excluded.turn_id`
|
|
317
|
-
|
|
318
|
-
|
|
320
|
+
).run(recipient.chatId, recipient.userId, turnId);
|
|
321
|
+
},
|
|
322
|
+
{ mode: "immediate" }
|
|
323
|
+
);
|
|
319
324
|
}
|
|
320
325
|
async enqueue(communication) {
|
|
321
|
-
return
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
this.#
|
|
325
|
-
|
|
326
|
+
return transaction(
|
|
327
|
+
this.#database,
|
|
328
|
+
() => {
|
|
329
|
+
const consumedTerminal = communication.type === InterAgentCommunicationTypes.FinalAnswer && this.#hasConsumedTerminal(communication.id);
|
|
330
|
+
if (!consumedTerminal) {
|
|
331
|
+
this.#database.prepare(
|
|
332
|
+
`INSERT OR IGNORE INTO zukhruf_mailbox_items (
|
|
326
333
|
recipient_chat_id,
|
|
327
334
|
recipient_user_id,
|
|
328
335
|
communication
|
|
329
336
|
) VALUES (?, ?, ?)`
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
337
|
+
).run(
|
|
338
|
+
communication.recipient.chatId,
|
|
339
|
+
communication.recipient.userId,
|
|
340
|
+
JSON.stringify(communication)
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
recipientActive: this.#isTurnActive(communication.recipient)
|
|
345
|
+
};
|
|
346
|
+
},
|
|
347
|
+
{ mode: "immediate" }
|
|
348
|
+
);
|
|
340
349
|
}
|
|
341
350
|
async endTurn(recipient, turnId) {
|
|
342
|
-
return
|
|
343
|
-
|
|
344
|
-
|
|
351
|
+
return transaction(
|
|
352
|
+
this.#database,
|
|
353
|
+
() => {
|
|
354
|
+
const result = this.#database.prepare(
|
|
355
|
+
`DELETE FROM zukhruf_mailbox_activity
|
|
345
356
|
WHERE recipient_chat_id = ?
|
|
346
357
|
AND recipient_user_id = ?
|
|
347
358
|
AND turn_id = ?`
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
359
|
+
).run(recipient.chatId, recipient.userId, turnId);
|
|
360
|
+
return {
|
|
361
|
+
hasPending: this.#hasPending(recipient),
|
|
362
|
+
turnEnded: result.changes > 0
|
|
363
|
+
};
|
|
364
|
+
},
|
|
365
|
+
{ mode: "immediate" }
|
|
366
|
+
);
|
|
354
367
|
}
|
|
355
368
|
async hasPending(recipient) {
|
|
356
369
|
return this.#hasPending(recipient);
|
|
@@ -391,53 +404,43 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
391
404
|
return this.#drain(recipient, true);
|
|
392
405
|
}
|
|
393
406
|
#drain(recipient, leadingQueueOnly) {
|
|
394
|
-
return
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
407
|
+
return transaction(
|
|
408
|
+
this.#database,
|
|
409
|
+
() => {
|
|
410
|
+
const items = mailboxItemRowsSchema.parse(
|
|
411
|
+
this.#database.prepare(
|
|
412
|
+
`SELECT sequence, communication
|
|
398
413
|
FROM zukhruf_mailbox_items
|
|
399
414
|
WHERE recipient_chat_id = ?
|
|
400
415
|
AND recipient_user_id = ?
|
|
401
416
|
ORDER BY sequence`
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
417
|
+
).all(recipient.chatId, recipient.userId)
|
|
418
|
+
);
|
|
419
|
+
const firstTrigger = leadingQueueOnly ? items.findIndex(({ communication }) => communication.triggerTurn) : -1;
|
|
420
|
+
const consumed = firstTrigger === -1 ? items : items.slice(0, firstTrigger);
|
|
421
|
+
const lastConsumed = consumed.at(-1);
|
|
422
|
+
if (lastConsumed) {
|
|
423
|
+
const tombstone = this.#database.prepare(
|
|
424
|
+
`INSERT OR IGNORE
|
|
410
425
|
INTO zukhruf_mailbox_consumed_terminal_ids (communication_id)
|
|
411
426
|
VALUES (?)`
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
427
|
+
);
|
|
428
|
+
for (const { communication } of consumed) {
|
|
429
|
+
if (communication.type === InterAgentCommunicationTypes.FinalAnswer) {
|
|
430
|
+
tombstone.run(communication.id);
|
|
431
|
+
}
|
|
416
432
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
`DELETE FROM zukhruf_mailbox_items
|
|
433
|
+
this.#database.prepare(
|
|
434
|
+
`DELETE FROM zukhruf_mailbox_items
|
|
420
435
|
WHERE recipient_chat_id = ?
|
|
421
436
|
AND recipient_user_id = ?
|
|
422
437
|
AND sequence <= ?`
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
this.#database.exec("BEGIN IMMEDIATE");
|
|
430
|
-
try {
|
|
431
|
-
const result = operation();
|
|
432
|
-
this.#database.exec("COMMIT");
|
|
433
|
-
return result;
|
|
434
|
-
} catch (error) {
|
|
435
|
-
try {
|
|
436
|
-
this.#database.exec("ROLLBACK");
|
|
437
|
-
} catch {
|
|
438
|
-
}
|
|
439
|
-
throw error;
|
|
440
|
-
}
|
|
438
|
+
).run(recipient.chatId, recipient.userId, lastConsumed.sequence);
|
|
439
|
+
}
|
|
440
|
+
return consumed.map(({ communication }) => communication);
|
|
441
|
+
},
|
|
442
|
+
{ mode: "immediate" }
|
|
443
|
+
);
|
|
441
444
|
}
|
|
442
445
|
close() {
|
|
443
446
|
if (!this.#database.isOpen) return;
|