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