@deepagents/experimental 7.0.2 → 7.1.1
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/README.md +8 -4
- package/dist/coding-agent-reminders/evaluate.d.ts.map +1 -1
- package/dist/coding-agent-reminders/index.js +2 -2
- package/dist/coding-agent-reminders/index.js.map +2 -2
- package/dist/index.js +233 -180
- package/dist/index.js.map +3 -3
- package/dist/providers/account-tokens.d.ts +45 -0
- package/dist/providers/account-tokens.d.ts.map +1 -0
- package/dist/providers/claude/accounts.d.ts +59 -0
- package/dist/providers/claude/accounts.d.ts.map +1 -0
- package/dist/providers/claude/errors.d.ts +7 -0
- package/dist/providers/claude/errors.d.ts.map +1 -0
- package/dist/providers/claude/index.d.ts +2 -0
- package/dist/providers/claude/index.d.ts.map +1 -1
- package/dist/providers/claude/index.js +540 -52
- package/dist/providers/claude/index.js.map +4 -4
- package/dist/providers/claude/local-credentials.d.ts.map +1 -1
- package/dist/providers/claude/oauth.d.ts +3 -0
- package/dist/providers/claude/oauth.d.ts.map +1 -0
- package/dist/providers/claude/provider.d.ts +4 -0
- package/dist/providers/claude/provider.d.ts.map +1 -0
- package/dist/providers/codex/accounts.d.ts +39 -0
- package/dist/providers/codex/accounts.d.ts.map +1 -0
- package/dist/providers/codex/errors.d.ts +7 -0
- package/dist/providers/codex/errors.d.ts.map +1 -0
- package/dist/providers/codex/index.d.ts +2 -0
- package/dist/providers/codex/index.d.ts.map +1 -1
- package/dist/providers/codex/index.js +472 -168
- package/dist/providers/codex/index.js.map +4 -4
- package/dist/providers/codex/local-credentials.d.ts.map +1 -1
- package/dist/providers/codex/provider.d.ts +3 -0
- package/dist/providers/codex/provider.d.ts.map +1 -0
- package/dist/providers/request-signal.d.ts +2 -0
- package/dist/providers/request-signal.d.ts.map +1 -0
- package/dist/zukhruf/control-plane/agent-control-plane.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/agent-history-forker.d.ts.map +1 -1
- package/dist/zukhruf/index.js +231 -178
- package/dist/zukhruf/index.js.map +3 -3
- package/dist/zukhruf/mailbox/coordinator.d.ts.map +1 -1
- package/dist/zukhruf/mailbox/sqlite.store.d.ts.map +1 -1
- package/dist/zukhruf/mailbox/types.d.ts +4 -4
- package/dist/zukhruf/mailbox/types.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/index.js +18 -2
- package/dist/zukhruf/plugins/conversation-scheduling/index.js.map +2 -2
- package/dist/zukhruf/plugins/http/index.js +16 -17
- package/dist/zukhruf/plugins/http/index.js.map +3 -3
- package/dist/zukhruf/plugins/http/validator.d.ts +14 -44
- package/dist/zukhruf/plugins/http/validator.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/http.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/http.js +22 -22
- package/dist/zukhruf/plugins/schedules/http.js.map +3 -3
- package/dist/zukhruf/plugins/schedules/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/index.js +173 -51
- package/dist/zukhruf/plugins/schedules/index.js.map +3 -3
- package/dist/zukhruf/plugins/schedules/scheduled-tasks.d.ts +3 -0
- package/dist/zukhruf/plugins/schedules/scheduled-tasks.d.ts.map +1 -1
- package/dist/zukhruf/plugins/uploads/http.js +17 -20
- package/dist/zukhruf/plugins/uploads/http.js.map +3 -3
- package/dist/zukhruf/plugins/uploads/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/uploads/index.js +1 -3
- package/dist/zukhruf/plugins/uploads/index.js.map +2 -2
- package/dist/zukhruf/queue/pg-boss-notifications.d.ts.map +1 -1
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts.map +1 -1
- package/dist/zukhruf/render-turn.d.ts.map +1 -1
- package/dist/zukhruf/runtime/agent-runtime.d.ts +3 -0
- package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/zukhruf/runtime/agent-turn-executor.d.ts.map +1 -1
- package/dist/zukhruf/runtime/compaction.d.ts +4 -4
- package/dist/zukhruf/runtime/compaction.d.ts.map +1 -1
- package/dist/zukhruf/runtime/conversation-status/projector.d.ts.map +1 -1
- package/dist/zukhruf/runtime/plugin/plugin-bindings.d.ts.map +1 -1
- package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts.map +1 -1
- package/dist/zukhruf/tool.d.ts +1 -1
- package/dist/zukhruf/tool.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// packages/experimental/src/zukhruf/plugins/schedules/index.ts
|
|
2
2
|
import { isToolUIPart as isToolUIPart2 } from "ai";
|
|
3
|
+
import { z as z11 } from "zod";
|
|
3
4
|
|
|
4
5
|
// packages/experimental/src/zukhruf/runtime/agent-runtime.ts
|
|
5
6
|
import {
|
|
@@ -105,6 +106,7 @@ import {
|
|
|
105
106
|
} from "@deepagents/context";
|
|
106
107
|
|
|
107
108
|
// packages/experimental/src/zukhruf/runtime/conversation-status/projector.ts
|
|
109
|
+
import { MemoryStore, Mutex } from "@zukhruf/mutex";
|
|
108
110
|
import {
|
|
109
111
|
ContextEngine as ContextEngine4
|
|
110
112
|
} from "@deepagents/context";
|
|
@@ -225,11 +227,25 @@ import { parseFrontmatter as parseFrontmatter2, role as role2 } from "@deepagent
|
|
|
225
227
|
// packages/experimental/src/zukhruf/runtime/agent-runtime.ts
|
|
226
228
|
var AgentPluginCapability = class {
|
|
227
229
|
name;
|
|
230
|
+
/** Each value this capability bound, keyed by the binding that carries it. */
|
|
231
|
+
#bound = /* @__PURE__ */ new WeakMap();
|
|
228
232
|
constructor(name) {
|
|
229
233
|
this.name = name;
|
|
230
234
|
}
|
|
231
235
|
bind(value) {
|
|
232
|
-
|
|
236
|
+
const binding = { capability: this, value };
|
|
237
|
+
this.#bound.set(binding, { value });
|
|
238
|
+
return binding;
|
|
239
|
+
}
|
|
240
|
+
/** Reads the value of a binding this capability created with `bind`. */
|
|
241
|
+
read(binding) {
|
|
242
|
+
const bound = this.#bound.get(binding);
|
|
243
|
+
if (!bound) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`AgentRuntime: binding for capability "${this.name}" was not created by its bind()`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
return bound.value;
|
|
233
249
|
}
|
|
234
250
|
};
|
|
235
251
|
|
|
@@ -238,9 +254,11 @@ import { CronExpressionParser } from "cron-parser";
|
|
|
238
254
|
import { randomUUID } from "node:crypto";
|
|
239
255
|
import { isDeepStrictEqual } from "node:util";
|
|
240
256
|
import rrulePackage from "rrule";
|
|
257
|
+
import { z as z9 } from "zod";
|
|
241
258
|
|
|
242
259
|
// packages/experimental/src/zukhruf/queue/pg-boss-notifications.ts
|
|
243
260
|
import { EventEmitter, on } from "node:events";
|
|
261
|
+
var RESET = /* @__PURE__ */ Symbol("reset");
|
|
244
262
|
async function pgBossNotifications(boss, channel, parse, signal) {
|
|
245
263
|
signal.throwIfAborted();
|
|
246
264
|
const db = boss.getDb();
|
|
@@ -254,13 +272,10 @@ async function pgBossNotifications(boss, channel, parse, signal) {
|
|
|
254
272
|
const handle = await listen(
|
|
255
273
|
channel,
|
|
256
274
|
(payload) => {
|
|
257
|
-
|
|
258
|
-
if (value !== void 0) {
|
|
259
|
-
emitter.emit("notification", { type: "change", value });
|
|
260
|
-
}
|
|
275
|
+
emitter.emit("notification", payload);
|
|
261
276
|
},
|
|
262
277
|
() => {
|
|
263
|
-
if (ready) emitter.emit("notification",
|
|
278
|
+
if (ready) emitter.emit("notification", RESET);
|
|
264
279
|
}
|
|
265
280
|
);
|
|
266
281
|
ready = true;
|
|
@@ -271,8 +286,14 @@ async function pgBossNotifications(boss, channel, parse, signal) {
|
|
|
271
286
|
return {
|
|
272
287
|
async *[Symbol.asyncIterator]() {
|
|
273
288
|
try {
|
|
274
|
-
for await (const
|
|
275
|
-
|
|
289
|
+
for await (const event of notifications) {
|
|
290
|
+
const [payload] = event;
|
|
291
|
+
if (payload === RESET) {
|
|
292
|
+
yield { type: "reset" };
|
|
293
|
+
} else if (typeof payload === "string") {
|
|
294
|
+
const value = parse(payload);
|
|
295
|
+
if (value !== void 0) yield { type: "change", value };
|
|
296
|
+
}
|
|
276
297
|
}
|
|
277
298
|
} finally {
|
|
278
299
|
await handle.close();
|
|
@@ -393,9 +414,94 @@ var ScheduledTasksError = class extends Error {
|
|
|
393
414
|
this.resource = resource;
|
|
394
415
|
}
|
|
395
416
|
};
|
|
417
|
+
var millisColumn = z9.union([z9.number(), z9.string(), z9.bigint()]);
|
|
418
|
+
var taskRowSchema = z9.object({
|
|
419
|
+
id: z9.string(),
|
|
420
|
+
owner_id: z9.string(),
|
|
421
|
+
idempotency_key: z9.string(),
|
|
422
|
+
name: z9.string(),
|
|
423
|
+
prompt: z9.string(),
|
|
424
|
+
recurrence: z9.string(),
|
|
425
|
+
timezone: z9.string(),
|
|
426
|
+
execution_config: z9.unknown(),
|
|
427
|
+
status: z9.enum([
|
|
428
|
+
"active",
|
|
429
|
+
"paused",
|
|
430
|
+
"completed",
|
|
431
|
+
"archived"
|
|
432
|
+
]),
|
|
433
|
+
generation: z9.union([z9.number(), z9.string()]),
|
|
434
|
+
next_run_at: millisColumn.nullable(),
|
|
435
|
+
next_wake_id: z9.string().nullable(),
|
|
436
|
+
created_at: millisColumn,
|
|
437
|
+
updated_at: millisColumn,
|
|
438
|
+
archived_at: millisColumn.nullable()
|
|
439
|
+
});
|
|
440
|
+
var runStatusSchema = z9.enum([
|
|
441
|
+
"dispatching",
|
|
442
|
+
"running",
|
|
443
|
+
"completed",
|
|
444
|
+
"failed",
|
|
445
|
+
"cancelled"
|
|
446
|
+
]);
|
|
447
|
+
var reviewStatusSchema = z9.enum([
|
|
448
|
+
"pending_review",
|
|
449
|
+
"reviewed",
|
|
450
|
+
"archived"
|
|
451
|
+
]);
|
|
452
|
+
var runRowSchema = z9.object({
|
|
453
|
+
id: z9.string(),
|
|
454
|
+
task_id: z9.string(),
|
|
455
|
+
owner_id: z9.string(),
|
|
456
|
+
trigger: z9.enum(["scheduled", "manual"]),
|
|
457
|
+
idempotency_key: z9.string().nullable(),
|
|
458
|
+
occurrence_at: millisColumn,
|
|
459
|
+
prompt: z9.string(),
|
|
460
|
+
execution_config: z9.unknown(),
|
|
461
|
+
status: runStatusSchema,
|
|
462
|
+
review_status: reviewStatusSchema.nullable(),
|
|
463
|
+
external_execution_id: z9.string().nullable(),
|
|
464
|
+
dispatch_job_id: z9.string(),
|
|
465
|
+
reconciliation_job_id: z9.string().nullable(),
|
|
466
|
+
next_check_at: millisColumn.nullable(),
|
|
467
|
+
started_at: millisColumn.nullable(),
|
|
468
|
+
finished_at: millisColumn.nullable(),
|
|
469
|
+
title: z9.string().nullable(),
|
|
470
|
+
summary: z9.string().nullable(),
|
|
471
|
+
error: z9.string().nullable(),
|
|
472
|
+
created_at: millisColumn,
|
|
473
|
+
updated_at: millisColumn
|
|
474
|
+
});
|
|
475
|
+
var taskRowsSchema = z9.array(taskRowSchema);
|
|
476
|
+
var runRowsSchema = z9.array(runRowSchema);
|
|
477
|
+
var runJobsRowSchema = runRowSchema.pick({
|
|
478
|
+
dispatch_job_id: true,
|
|
479
|
+
reconciliation_job_id: true,
|
|
480
|
+
status: true
|
|
481
|
+
});
|
|
482
|
+
var scheduledJobSchema = z9.discriminatedUnion("kind", [
|
|
483
|
+
z9.object({
|
|
484
|
+
kind: z9.literal("occurrence"),
|
|
485
|
+
ownerId: z9.string(),
|
|
486
|
+
taskId: z9.string(),
|
|
487
|
+
occurrenceAt: z9.number(),
|
|
488
|
+
generation: z9.number()
|
|
489
|
+
}),
|
|
490
|
+
z9.object({
|
|
491
|
+
kind: z9.literal("dispatch"),
|
|
492
|
+
ownerId: z9.string(),
|
|
493
|
+
runId: z9.string()
|
|
494
|
+
}),
|
|
495
|
+
z9.object({
|
|
496
|
+
kind: z9.literal("reconcile"),
|
|
497
|
+
ownerId: z9.string(),
|
|
498
|
+
runId: z9.string()
|
|
499
|
+
})
|
|
500
|
+
]);
|
|
396
501
|
var ScheduledTasks = class {
|
|
397
502
|
#boss;
|
|
398
503
|
#database;
|
|
504
|
+
#executionConfigSchema;
|
|
399
505
|
#executor;
|
|
400
506
|
#queue;
|
|
401
507
|
#queueOptions;
|
|
@@ -410,6 +516,7 @@ var ScheduledTasks = class {
|
|
|
410
516
|
}
|
|
411
517
|
this.#boss = options.boss;
|
|
412
518
|
this.#database = options.boss.getDb();
|
|
519
|
+
this.#executionConfigSchema = options.executionConfigSchema;
|
|
413
520
|
this.#executor = options.executor;
|
|
414
521
|
this.#queueOptions = options.queueOptions;
|
|
415
522
|
this.#reconciliationIntervalMs = options.reconciliationIntervalMs;
|
|
@@ -509,8 +616,8 @@ var ScheduledTasks = class {
|
|
|
509
616
|
now
|
|
510
617
|
]
|
|
511
618
|
);
|
|
512
|
-
const inserted = rows[0];
|
|
513
|
-
if (inserted) return
|
|
619
|
+
const inserted = taskRowSchema.optional().parse(rows[0]);
|
|
620
|
+
if (inserted) return this.#task(inserted);
|
|
514
621
|
await this.#cancelJob(database, wakeId);
|
|
515
622
|
const concurrent = await this.#taskByKey(
|
|
516
623
|
database,
|
|
@@ -532,7 +639,7 @@ var ScheduledTasks = class {
|
|
|
532
639
|
ORDER BY created_at, id`,
|
|
533
640
|
[required(ownerId, "Scheduled Task owner")]
|
|
534
641
|
);
|
|
535
|
-
return rows.map(
|
|
642
|
+
return taskRowsSchema.parse(rows).map((row) => this.#task(row));
|
|
536
643
|
}
|
|
537
644
|
async listRuns(ownerId, taskId) {
|
|
538
645
|
const { rows } = await this.#database.executeSql(
|
|
@@ -544,7 +651,7 @@ var ScheduledTasks = class {
|
|
|
544
651
|
required(taskId, "Scheduled Task id")
|
|
545
652
|
]
|
|
546
653
|
);
|
|
547
|
-
return rows.map(
|
|
654
|
+
return runRowsSchema.parse(rows).map((row) => this.#run(row));
|
|
548
655
|
}
|
|
549
656
|
async getRun(ownerId, runId) {
|
|
550
657
|
return this.#requiredRun(this.#database, ownerId, runId, false);
|
|
@@ -561,7 +668,7 @@ var ScheduledTasks = class {
|
|
|
561
668
|
ORDER BY finished_at DESC, id`,
|
|
562
669
|
[required(ownerId, "Scheduled Task owner")]
|
|
563
670
|
);
|
|
564
|
-
return rows.map(
|
|
671
|
+
return runRowsSchema.parse(rows).map((row) => this.#run(row));
|
|
565
672
|
}
|
|
566
673
|
async pause(ownerId, taskId) {
|
|
567
674
|
return this.#transaction(async (database) => {
|
|
@@ -586,7 +693,7 @@ var ScheduledTasks = class {
|
|
|
586
693
|
RETURNING *`,
|
|
587
694
|
[now, task.id, task.ownerId]
|
|
588
695
|
);
|
|
589
|
-
return
|
|
696
|
+
return this.#task(requiredRow(taskRowSchema, rows, "pause"));
|
|
590
697
|
});
|
|
591
698
|
}
|
|
592
699
|
async resume(ownerId, taskId) {
|
|
@@ -632,7 +739,7 @@ var ScheduledTasks = class {
|
|
|
632
739
|
RETURNING *`,
|
|
633
740
|
[generation, nextRunAt, wakeId, Date.now(), task.id, task.ownerId]
|
|
634
741
|
);
|
|
635
|
-
return
|
|
742
|
+
return this.#task(requiredRow(taskRowSchema, rows, "resume"));
|
|
636
743
|
});
|
|
637
744
|
}
|
|
638
745
|
async update(ownerId, taskId, input) {
|
|
@@ -705,7 +812,7 @@ var ScheduledTasks = class {
|
|
|
705
812
|
task.ownerId
|
|
706
813
|
]
|
|
707
814
|
);
|
|
708
|
-
return
|
|
815
|
+
return this.#task(requiredRow(taskRowSchema, rows, "update"));
|
|
709
816
|
});
|
|
710
817
|
}
|
|
711
818
|
async runNow(ownerId, taskId, idempotencyKey) {
|
|
@@ -750,8 +857,8 @@ var ScheduledTasks = class {
|
|
|
750
857
|
dispatchJobId
|
|
751
858
|
]
|
|
752
859
|
);
|
|
753
|
-
const inserted = rows[0];
|
|
754
|
-
if (inserted) return
|
|
860
|
+
const inserted = runRowSchema.optional().parse(rows[0]);
|
|
861
|
+
if (inserted) return this.#run(inserted);
|
|
755
862
|
await this.#cancelJob(database, dispatchJobId);
|
|
756
863
|
const concurrent = await this.#manualRun(database, task.id, key);
|
|
757
864
|
if (!concurrent) throw new Error("Scheduled Run create lost its row");
|
|
@@ -775,7 +882,7 @@ var ScheduledTasks = class {
|
|
|
775
882
|
RETURNING *`,
|
|
776
883
|
[now, task.id, task.ownerId]
|
|
777
884
|
);
|
|
778
|
-
return
|
|
885
|
+
return this.#task(requiredRow(taskRowSchema, rows, "archive"));
|
|
779
886
|
});
|
|
780
887
|
}
|
|
781
888
|
async purge(ownerId, taskId) {
|
|
@@ -794,7 +901,7 @@ var ScheduledTasks = class {
|
|
|
794
901
|
WHERE task_id = $1 AND owner_id = $2`,
|
|
795
902
|
[task.id, task.ownerId]
|
|
796
903
|
);
|
|
797
|
-
const runs = rows;
|
|
904
|
+
const runs = z9.array(runJobsRowSchema).parse(rows);
|
|
798
905
|
if (runs.some(
|
|
799
906
|
({ status }) => status === "dispatching" || status === "running"
|
|
800
907
|
)) {
|
|
@@ -898,7 +1005,7 @@ var ScheduledTasks = class {
|
|
|
898
1005
|
if (!row || row.status !== "active" || Number(row.generation) !== job.generation || toMillis(row.next_run_at) !== job.occurrenceAt || row.next_wake_id !== jobId) {
|
|
899
1006
|
return;
|
|
900
1007
|
}
|
|
901
|
-
const task =
|
|
1008
|
+
const task = this.#task(row);
|
|
902
1009
|
const now = Date.now();
|
|
903
1010
|
const runId = randomUUID();
|
|
904
1011
|
const dispatchJobId = await this.#sendNow(database, {
|
|
@@ -973,7 +1080,7 @@ var ScheduledTasks = class {
|
|
|
973
1080
|
if (!row || row.status !== "dispatching" || row.dispatch_job_id !== jobId) {
|
|
974
1081
|
return;
|
|
975
1082
|
}
|
|
976
|
-
const run =
|
|
1083
|
+
const run = this.#run(row);
|
|
977
1084
|
let executionId;
|
|
978
1085
|
try {
|
|
979
1086
|
const launched = await this.#executor.launch({
|
|
@@ -1053,7 +1160,7 @@ var ScheduledTasks = class {
|
|
|
1053
1160
|
if (!row || row.status !== "running" || row.reconciliation_job_id !== job.id || !row.external_execution_id) {
|
|
1054
1161
|
return;
|
|
1055
1162
|
}
|
|
1056
|
-
const run =
|
|
1163
|
+
const run = this.#run(row);
|
|
1057
1164
|
let observed;
|
|
1058
1165
|
try {
|
|
1059
1166
|
observed = await this.#executor.inspect({
|
|
@@ -1168,7 +1275,7 @@ var ScheduledTasks = class {
|
|
|
1168
1275
|
RETURNING *`,
|
|
1169
1276
|
[reviewStatus, Date.now(), run.id, run.ownerId]
|
|
1170
1277
|
);
|
|
1171
|
-
return
|
|
1278
|
+
return this.#run(requiredRow(runRowSchema, rows, "review"));
|
|
1172
1279
|
});
|
|
1173
1280
|
}
|
|
1174
1281
|
async #finishCancelled(database, run) {
|
|
@@ -1182,7 +1289,7 @@ var ScheduledTasks = class {
|
|
|
1182
1289
|
RETURNING *`,
|
|
1183
1290
|
[now, run.id, run.ownerId]
|
|
1184
1291
|
);
|
|
1185
|
-
return
|
|
1292
|
+
return this.#run(requiredRow(runRowSchema, rows, "cancel"));
|
|
1186
1293
|
}
|
|
1187
1294
|
async #sendNow(database, data) {
|
|
1188
1295
|
const id = await this.#boss.send(this.#queue, data, { db: database });
|
|
@@ -1216,7 +1323,7 @@ var ScheduledTasks = class {
|
|
|
1216
1323
|
`Scheduled Task "${taskId}" was not found`
|
|
1217
1324
|
);
|
|
1218
1325
|
}
|
|
1219
|
-
return
|
|
1326
|
+
return this.#task(row);
|
|
1220
1327
|
}
|
|
1221
1328
|
async #taskRow(database, taskId, ownerId, forUpdate) {
|
|
1222
1329
|
const { rows } = await database.executeSql(
|
|
@@ -1224,7 +1331,7 @@ var ScheduledTasks = class {
|
|
|
1224
1331
|
WHERE id = $1 AND owner_id = $2${forUpdate ? " FOR UPDATE" : ""}`,
|
|
1225
1332
|
[taskId, ownerId]
|
|
1226
1333
|
);
|
|
1227
|
-
return rows[0];
|
|
1334
|
+
return taskRowSchema.optional().parse(rows[0]);
|
|
1228
1335
|
}
|
|
1229
1336
|
async #taskByKey(database, ownerId, idempotencyKey) {
|
|
1230
1337
|
const { rows } = await database.executeSql(
|
|
@@ -1232,8 +1339,8 @@ var ScheduledTasks = class {
|
|
|
1232
1339
|
WHERE owner_id = $1 AND idempotency_key = $2`,
|
|
1233
1340
|
[ownerId, idempotencyKey]
|
|
1234
1341
|
);
|
|
1235
|
-
const row = rows[0];
|
|
1236
|
-
return row ?
|
|
1342
|
+
const row = taskRowSchema.optional().parse(rows[0]);
|
|
1343
|
+
return row ? this.#task(row) : void 0;
|
|
1237
1344
|
}
|
|
1238
1345
|
async #requiredRun(database, ownerId, runId, forUpdate) {
|
|
1239
1346
|
const row = await this.#runRow(
|
|
@@ -1249,7 +1356,7 @@ var ScheduledTasks = class {
|
|
|
1249
1356
|
`Scheduled Run "${runId}" was not found`
|
|
1250
1357
|
);
|
|
1251
1358
|
}
|
|
1252
|
-
return
|
|
1359
|
+
return this.#run(row);
|
|
1253
1360
|
}
|
|
1254
1361
|
async #runRow(database, runId, ownerId, forUpdate) {
|
|
1255
1362
|
const { rows } = await database.executeSql(
|
|
@@ -1257,7 +1364,7 @@ var ScheduledTasks = class {
|
|
|
1257
1364
|
WHERE id = $1 AND owner_id = $2${forUpdate ? " FOR UPDATE" : ""}`,
|
|
1258
1365
|
[runId, ownerId]
|
|
1259
1366
|
);
|
|
1260
|
-
return rows[0];
|
|
1367
|
+
return runRowSchema.optional().parse(rows[0]);
|
|
1261
1368
|
}
|
|
1262
1369
|
async #manualRun(database, taskId, idempotencyKey) {
|
|
1263
1370
|
const { rows } = await database.executeSql(
|
|
@@ -1265,8 +1372,14 @@ var ScheduledTasks = class {
|
|
|
1265
1372
|
WHERE task_id = $1 AND trigger = 'manual' AND idempotency_key = $2`,
|
|
1266
1373
|
[taskId, idempotencyKey]
|
|
1267
1374
|
);
|
|
1268
|
-
const row = rows[0];
|
|
1269
|
-
return row ?
|
|
1375
|
+
const row = runRowSchema.optional().parse(rows[0]);
|
|
1376
|
+
return row ? this.#run(row) : void 0;
|
|
1377
|
+
}
|
|
1378
|
+
#task(row) {
|
|
1379
|
+
return toTask(row, this.#executionConfigSchema.parse(row.execution_config));
|
|
1380
|
+
}
|
|
1381
|
+
#run(row) {
|
|
1382
|
+
return toRun(row, this.#executionConfigSchema.parse(row.execution_config));
|
|
1270
1383
|
}
|
|
1271
1384
|
};
|
|
1272
1385
|
function normalizeCreate(input) {
|
|
@@ -1423,14 +1536,13 @@ function validateJob(value) {
|
|
|
1423
1536
|
if (!value || typeof value !== "object") {
|
|
1424
1537
|
throw new Error("Scheduled Tasks job payload must be an object");
|
|
1425
1538
|
}
|
|
1426
|
-
const job = value;
|
|
1427
|
-
if (
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
return job;
|
|
1539
|
+
const job = scheduledJobSchema.safeParse(value);
|
|
1540
|
+
if (!job.success) {
|
|
1541
|
+
throw new Error("Scheduled Tasks job payload is invalid", {
|
|
1542
|
+
cause: job.error
|
|
1543
|
+
});
|
|
1432
1544
|
}
|
|
1433
|
-
|
|
1545
|
+
return job.data;
|
|
1434
1546
|
}
|
|
1435
1547
|
function parseScheduledChange(payload) {
|
|
1436
1548
|
let value;
|
|
@@ -1461,7 +1573,7 @@ function parseScheduledChange(payload) {
|
|
|
1461
1573
|
}
|
|
1462
1574
|
return void 0;
|
|
1463
1575
|
}
|
|
1464
|
-
function toTask(row) {
|
|
1576
|
+
function toTask(row, executionConfig) {
|
|
1465
1577
|
return {
|
|
1466
1578
|
id: row.id,
|
|
1467
1579
|
ownerId: row.owner_id,
|
|
@@ -1470,7 +1582,7 @@ function toTask(row) {
|
|
|
1470
1582
|
prompt: row.prompt,
|
|
1471
1583
|
recurrence: row.recurrence,
|
|
1472
1584
|
timezone: row.timezone,
|
|
1473
|
-
executionConfig
|
|
1585
|
+
executionConfig,
|
|
1474
1586
|
status: row.status,
|
|
1475
1587
|
generation: Number(row.generation),
|
|
1476
1588
|
nextRunAt: toMillis(row.next_run_at),
|
|
@@ -1479,7 +1591,7 @@ function toTask(row) {
|
|
|
1479
1591
|
archivedAt: toMillis(row.archived_at)
|
|
1480
1592
|
};
|
|
1481
1593
|
}
|
|
1482
|
-
function toRun(row) {
|
|
1594
|
+
function toRun(row, executionConfig) {
|
|
1483
1595
|
return {
|
|
1484
1596
|
id: row.id,
|
|
1485
1597
|
taskId: row.task_id,
|
|
@@ -1487,7 +1599,7 @@ function toRun(row) {
|
|
|
1487
1599
|
trigger: row.trigger,
|
|
1488
1600
|
occurrenceAt: Number(row.occurrence_at),
|
|
1489
1601
|
prompt: row.prompt,
|
|
1490
|
-
executionConfig
|
|
1602
|
+
executionConfig,
|
|
1491
1603
|
status: row.status,
|
|
1492
1604
|
reviewStatus: row.review_status,
|
|
1493
1605
|
externalExecutionId: row.external_execution_id,
|
|
@@ -1503,8 +1615,8 @@ function toRun(row) {
|
|
|
1503
1615
|
function toMillis(value) {
|
|
1504
1616
|
return value === null ? null : Number(value);
|
|
1505
1617
|
}
|
|
1506
|
-
function requiredRow(rows, operation) {
|
|
1507
|
-
const row = rows[0];
|
|
1618
|
+
function requiredRow(schema, rows, operation) {
|
|
1619
|
+
const row = schema.optional().parse(rows[0]);
|
|
1508
1620
|
if (!row)
|
|
1509
1621
|
throw new Error(`Scheduled Tasks ${operation} did not return a row`);
|
|
1510
1622
|
return row;
|
|
@@ -1521,12 +1633,12 @@ import { readFile, readdir } from "node:fs/promises";
|
|
|
1521
1633
|
import { basename, extname, join } from "node:path";
|
|
1522
1634
|
import { fileURLToPath } from "node:url";
|
|
1523
1635
|
import YAML from "yaml";
|
|
1524
|
-
import { z as
|
|
1636
|
+
import { z as z10 } from "zod";
|
|
1525
1637
|
var FILE_KEY_PREFIX = "zukhruf:schedule-file:";
|
|
1526
|
-
var frontmatterSchema =
|
|
1527
|
-
name:
|
|
1528
|
-
cron:
|
|
1529
|
-
timezone:
|
|
1638
|
+
var frontmatterSchema = z10.object({
|
|
1639
|
+
name: z10.string().trim().min(1).optional(),
|
|
1640
|
+
cron: z10.string().trim().min(1),
|
|
1641
|
+
timezone: z10.string().trim().min(1)
|
|
1530
1642
|
}).strict();
|
|
1531
1643
|
function scheduleFiles({
|
|
1532
1644
|
directory,
|
|
@@ -1600,6 +1712,15 @@ async function syncScheduleFiles(directory, ownerId, scheduled) {
|
|
|
1600
1712
|
|
|
1601
1713
|
// packages/experimental/src/zukhruf/plugins/schedules/index.ts
|
|
1602
1714
|
var SCHEDULED_TASK_ORIGIN = "scheduled-task";
|
|
1715
|
+
var executionConfigSchema = z11.object({
|
|
1716
|
+
target: z11.discriminatedUnion("kind", [
|
|
1717
|
+
z11.object({ kind: z11.literal("new-conversation") }),
|
|
1718
|
+
z11.object({
|
|
1719
|
+
kind: z11.literal("existing-conversation"),
|
|
1720
|
+
chatId: z11.string()
|
|
1721
|
+
})
|
|
1722
|
+
]).optional()
|
|
1723
|
+
});
|
|
1603
1724
|
var schedulesCapabilities = {
|
|
1604
1725
|
boss: new AgentPluginCapability("schedules.boss"),
|
|
1605
1726
|
transaction: new AgentPluginCapability(
|
|
@@ -1635,6 +1756,7 @@ var SchedulesPlugin = class {
|
|
|
1635
1756
|
this.#workerOptions = workerOptions;
|
|
1636
1757
|
this.#scheduled = new ScheduledTasks({
|
|
1637
1758
|
...options,
|
|
1759
|
+
executionConfigSchema,
|
|
1638
1760
|
executor: {
|
|
1639
1761
|
launch: (input) => this.#launch(input),
|
|
1640
1762
|
inspect: (input) => this.#inspect(input),
|