@deepagents/experimental 7.8.0 → 7.8.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 +16 -5
- package/dist/index.js +140 -120
- package/dist/index.js.map +4 -4
- package/dist/zukhruf/control-plane/agent-control-plane.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/agent-thread-limit-error.d.ts +6 -0
- package/dist/zukhruf/control-plane/agent-thread-limit-error.d.ts.map +1 -0
- package/dist/zukhruf/control-plane/agent-turn-id.d.ts +3 -0
- package/dist/zukhruf/control-plane/agent-turn-id.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/stale-turn-error.d.ts +7 -0
- package/dist/zukhruf/control-plane/stale-turn-error.d.ts.map +1 -0
- package/dist/zukhruf/control-plane/turn-not-found-error.d.ts +7 -0
- package/dist/zukhruf/control-plane/turn-not-found-error.d.ts.map +1 -0
- package/dist/zukhruf/index.d.ts +3 -0
- package/dist/zukhruf/index.d.ts.map +1 -1
- package/dist/zukhruf/index.js +140 -120
- package/dist/zukhruf/index.js.map +4 -4
- package/dist/zukhruf/is-named-error.d.ts +7 -0
- package/dist/zukhruf/is-named-error.d.ts.map +1 -0
- package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/index.js +142 -136
- package/dist/zukhruf/plugins/conversation-scheduling/index.js.map +3 -3
- package/dist/zukhruf/plugins/http/index.d.ts +2 -2
- package/dist/zukhruf/plugins/http/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/http/index.js +72 -17
- package/dist/zukhruf/plugins/http/index.js.map +4 -4
- package/dist/zukhruf/plugins/schedules/http.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/http.js +44 -32
- package/dist/zukhruf/plugins/schedules/http.js.map +4 -4
- package/dist/zukhruf/plugins/schedules/index.d.ts +2 -2
- package/dist/zukhruf/plugins/schedules/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/index.js +138 -143
- package/dist/zukhruf/plugins/schedules/index.js.map +3 -3
- package/dist/zukhruf/plugins/uploads/http.js +30 -19
- package/dist/zukhruf/plugins/uploads/http.js.map +4 -4
- package/dist/zukhruf/plugins/uploads/index.d.ts +2 -2
- package/dist/zukhruf/plugins/uploads/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/uploads/index.js +48 -55
- package/dist/zukhruf/plugins/uploads/index.js.map +2 -2
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts +4 -1
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts.map +1 -1
- package/dist/zukhruf/runtime/agent-runtime.d.ts +19 -11
- package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts +4 -4
- package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// packages/experimental/src/zukhruf/plugins/schedules/index.ts
|
|
2
2
|
import { isToolUIPart as isToolUIPart2 } from "ai";
|
|
3
|
-
import
|
|
4
|
-
import { z as z11 } from "zod";
|
|
3
|
+
import { z as z12 } from "zod";
|
|
5
4
|
|
|
6
5
|
// packages/experimental/src/zukhruf/runtime/agent-runtime.ts
|
|
7
6
|
import {
|
|
@@ -38,7 +37,13 @@ var listedAgentSchema = z.object({
|
|
|
38
37
|
}).strict();
|
|
39
38
|
|
|
40
39
|
// packages/experimental/src/zukhruf/control-plane/agent-turn-id.ts
|
|
41
|
-
import { v5 as uuidv53 } from "uuid";
|
|
40
|
+
import { v5 as uuidv53, validate as validateUuid } from "uuid";
|
|
41
|
+
import { z as z2 } from "zod";
|
|
42
|
+
var prefix = "zukhruf-turn";
|
|
43
|
+
var agentTurnIdSchema = z2.string().refine((value) => {
|
|
44
|
+
const [head, scope, turn, ...rest] = value.split(":");
|
|
45
|
+
return head === prefix && rest.length === 0 && validateUuid(scope) && validateUuid(turn);
|
|
46
|
+
});
|
|
42
47
|
|
|
43
48
|
// packages/experimental/src/zukhruf/mailbox/coordinator.ts
|
|
44
49
|
import pMemoize from "p-memoize";
|
|
@@ -68,7 +73,7 @@ import {
|
|
|
68
73
|
asSchema,
|
|
69
74
|
modelMessageSchema as modelMessageSchema2
|
|
70
75
|
} from "ai";
|
|
71
|
-
import { z as
|
|
76
|
+
import { z as z3 } from "zod";
|
|
72
77
|
|
|
73
78
|
// packages/compaction/dist/index.js
|
|
74
79
|
import {
|
|
@@ -77,21 +82,21 @@ import {
|
|
|
77
82
|
} from "ai";
|
|
78
83
|
|
|
79
84
|
// packages/experimental/src/zukhruf/runtime/compaction.ts
|
|
80
|
-
var checkpointSchema =
|
|
81
|
-
sourceCount:
|
|
82
|
-
sourceHash:
|
|
83
|
-
replacement:
|
|
85
|
+
var checkpointSchema = z3.object({
|
|
86
|
+
sourceCount: z3.number().int().positive(),
|
|
87
|
+
sourceHash: z3.string(),
|
|
88
|
+
replacement: z3.array(z3.unknown()).transform(
|
|
84
89
|
(messages) => messages.map((message) => modelMessageSchema2.parse(message))
|
|
85
90
|
)
|
|
86
91
|
});
|
|
87
|
-
var cacheObservationSchema =
|
|
88
|
-
scope:
|
|
89
|
-
prefixLength:
|
|
90
|
-
prefixHash:
|
|
91
|
-
startedAt:
|
|
92
|
-
retentionMs:
|
|
92
|
+
var cacheObservationSchema = z3.object({
|
|
93
|
+
scope: z3.string(),
|
|
94
|
+
prefixLength: z3.number().int().nonnegative(),
|
|
95
|
+
prefixHash: z3.string(),
|
|
96
|
+
startedAt: z3.number().int().nonnegative(),
|
|
97
|
+
retentionMs: z3.number().int().positive().optional()
|
|
93
98
|
});
|
|
94
|
-
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens:
|
|
99
|
+
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens: z3.number().int().nonnegative() });
|
|
95
100
|
|
|
96
101
|
// packages/experimental/src/zukhruf/runtime/plugin/agent-skills.ts
|
|
97
102
|
import {
|
|
@@ -118,21 +123,21 @@ import {
|
|
|
118
123
|
} from "@deepagents/context";
|
|
119
124
|
|
|
120
125
|
// packages/experimental/src/zukhruf/runtime/conversation-status/child-progress.ts
|
|
121
|
-
import { z as
|
|
122
|
-
var childActivitySchema =
|
|
123
|
-
id:
|
|
124
|
-
type:
|
|
125
|
-
at:
|
|
126
|
-
actorPath:
|
|
127
|
-
targetPath:
|
|
128
|
-
streamId:
|
|
129
|
-
outcome:
|
|
126
|
+
import { z as z4 } from "zod";
|
|
127
|
+
var childActivitySchema = z4.object({
|
|
128
|
+
id: z4.string(),
|
|
129
|
+
type: z4.enum(["spawn", "message", "followup", "interrupt", "completion"]),
|
|
130
|
+
at: z4.number(),
|
|
131
|
+
actorPath: z4.string(),
|
|
132
|
+
targetPath: z4.string(),
|
|
133
|
+
streamId: z4.string(),
|
|
134
|
+
outcome: z4.enum(["completed", "failed", "cancelled"]).optional()
|
|
130
135
|
});
|
|
131
|
-
var childActivitiesSchema =
|
|
136
|
+
var childActivitiesSchema = z4.partialRecord(
|
|
132
137
|
childActivitySchema.shape.type,
|
|
133
138
|
childActivitySchema
|
|
134
139
|
);
|
|
135
|
-
var childActivityMetadataSchema =
|
|
140
|
+
var childActivityMetadataSchema = z4.looseObject({
|
|
136
141
|
childActivities: childActivitiesSchema.default({})
|
|
137
142
|
});
|
|
138
143
|
|
|
@@ -146,13 +151,13 @@ var DETACHED = new Detached();
|
|
|
146
151
|
|
|
147
152
|
// packages/experimental/src/zukhruf/collaboration/interrupt-agent.ts
|
|
148
153
|
import { tool as tool2 } from "ai";
|
|
149
|
-
import { z as
|
|
150
|
-
var interruptAgentInputSchema =
|
|
151
|
-
target:
|
|
154
|
+
import { z as z5 } from "zod";
|
|
155
|
+
var interruptAgentInputSchema = z5.object({
|
|
156
|
+
target: z5.string().trim().min(1).describe(
|
|
152
157
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
153
158
|
)
|
|
154
159
|
});
|
|
155
|
-
var interruptAgentOutputSchema =
|
|
160
|
+
var interruptAgentOutputSchema = z5.object({ previous_status: listedAgentStatusSchema }).strict();
|
|
156
161
|
var interruptAgentTool = tool2({
|
|
157
162
|
description: "Interrupt an agent's current turn, if any, and return its previous status. The agent remains available for messages and follow-up tasks.",
|
|
158
163
|
inputSchema: interruptAgentInputSchema,
|
|
@@ -162,13 +167,13 @@ var interruptAgentTool = tool2({
|
|
|
162
167
|
|
|
163
168
|
// packages/experimental/src/zukhruf/collaboration/list-agents.ts
|
|
164
169
|
import { tool as tool3 } from "ai";
|
|
165
|
-
import { z as
|
|
166
|
-
var listAgentsInputSchema =
|
|
167
|
-
path_prefix:
|
|
170
|
+
import { z as z6 } from "zod";
|
|
171
|
+
var listAgentsInputSchema = z6.object({
|
|
172
|
+
path_prefix: z6.string().trim().min(1).describe(
|
|
168
173
|
"Task-path prefix without a trailing slash. Omit to list the whole tree."
|
|
169
174
|
).optional()
|
|
170
175
|
});
|
|
171
|
-
var listAgentsOutputSchema =
|
|
176
|
+
var listAgentsOutputSchema = z6.object({ agents: z6.array(listedAgentSchema) }).strict();
|
|
172
177
|
var listAgentsTool = tool3({
|
|
173
178
|
description: "List live agents in the current root thread tree. Optionally filter by task-path prefix.",
|
|
174
179
|
inputSchema: listAgentsInputSchema,
|
|
@@ -178,12 +183,12 @@ var listAgentsTool = tool3({
|
|
|
178
183
|
|
|
179
184
|
// packages/experimental/src/zukhruf/collaboration/message-tools.ts
|
|
180
185
|
import { tool as tool4 } from "ai";
|
|
181
|
-
import { z as
|
|
182
|
-
var agentMessageInputSchema =
|
|
183
|
-
target:
|
|
186
|
+
import { z as z7 } from "zod";
|
|
187
|
+
var agentMessageInputSchema = z7.object({
|
|
188
|
+
target: z7.string().trim().min(1).describe(
|
|
184
189
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
185
190
|
),
|
|
186
|
-
message:
|
|
191
|
+
message: z7.string().trim().min(1).describe("The message or follow-up task.")
|
|
187
192
|
});
|
|
188
193
|
var sendMessageTool = tool4({
|
|
189
194
|
description: "Queue a message for another agent. Address siblings with their canonical /root/... path.",
|
|
@@ -204,7 +209,7 @@ var followupTaskTool = tool4({
|
|
|
204
209
|
|
|
205
210
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
206
211
|
import { tool as tool5 } from "ai";
|
|
207
|
-
import { z as
|
|
212
|
+
import { z as z8 } from "zod";
|
|
208
213
|
|
|
209
214
|
// packages/experimental/src/zukhruf/control-plane/fork-turns.ts
|
|
210
215
|
var forkTurnsError = "fork_turns must be `none`, `all`, or a positive integer string";
|
|
@@ -217,23 +222,23 @@ function parseForkTurns(value) {
|
|
|
217
222
|
}
|
|
218
223
|
|
|
219
224
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
220
|
-
var spawnAgentInputSchema =
|
|
221
|
-
agent_type:
|
|
222
|
-
task_name:
|
|
225
|
+
var spawnAgentInputSchema = z8.object({
|
|
226
|
+
agent_type: z8.string().trim().min(1).describe("The name of one available subagent declaration."),
|
|
227
|
+
task_name: z8.string().trim().min(1).refine(
|
|
223
228
|
(value) => value !== "." && value !== ".." && !value.includes("/"),
|
|
224
229
|
"task_name must be one non-empty path segment"
|
|
225
230
|
).describe("One path segment naming this independent agent task."),
|
|
226
|
-
message:
|
|
227
|
-
fork_turns:
|
|
231
|
+
message: z8.string().refine((value) => value.trim().length > 0, "message cannot be empty").describe("The initial task for the spawned agent."),
|
|
232
|
+
fork_turns: z8.string().trim().refine((value) => parseForkTurns(value) !== void 0, forkTurnsError).describe(
|
|
228
233
|
"Required number of parent turns to fork. Use `none`, `all`, or a positive integer string such as `3`."
|
|
229
234
|
)
|
|
230
235
|
});
|
|
231
|
-
var spawnAgentOutputSchema =
|
|
236
|
+
var spawnAgentOutputSchema = z8.object({ task_name: z8.string() }).strict();
|
|
232
237
|
|
|
233
238
|
// packages/experimental/src/zukhruf/collaboration/wait-agent.ts
|
|
234
239
|
import { tool as tool6 } from "ai";
|
|
235
|
-
import { z as
|
|
236
|
-
var waitAgentOutputSchema =
|
|
240
|
+
import { z as z9 } from "zod";
|
|
241
|
+
var waitAgentOutputSchema = z9.object({ message: z9.string(), timed_out: z9.boolean() }).strict();
|
|
237
242
|
|
|
238
243
|
// packages/experimental/src/zukhruf/runtime/plugin/plugin-agents.ts
|
|
239
244
|
import { parseFrontmatter as parseFrontmatter2, role as role2 } from "@deepagents/context";
|
|
@@ -268,7 +273,7 @@ import { CronExpressionParser } from "cron-parser";
|
|
|
268
273
|
import { randomUUID } from "node:crypto";
|
|
269
274
|
import { isDeepStrictEqual } from "node:util";
|
|
270
275
|
import rrulePackage from "rrule";
|
|
271
|
-
import { z as
|
|
276
|
+
import { z as z10 } from "zod";
|
|
272
277
|
import { lockSchemaDDL } from "@deepagents/context";
|
|
273
278
|
|
|
274
279
|
// packages/experimental/src/zukhruf/queue/pg-boss-notifications.ts
|
|
@@ -429,88 +434,88 @@ var ScheduledTasksError = class extends Error {
|
|
|
429
434
|
this.resource = resource;
|
|
430
435
|
}
|
|
431
436
|
};
|
|
432
|
-
var millisColumn =
|
|
433
|
-
var taskRowSchema =
|
|
434
|
-
id:
|
|
435
|
-
owner_id:
|
|
436
|
-
idempotency_key:
|
|
437
|
-
name:
|
|
438
|
-
prompt:
|
|
439
|
-
recurrence:
|
|
440
|
-
timezone:
|
|
441
|
-
execution_config:
|
|
442
|
-
status:
|
|
437
|
+
var millisColumn = z10.union([z10.number(), z10.string(), z10.bigint()]);
|
|
438
|
+
var taskRowSchema = z10.object({
|
|
439
|
+
id: z10.string(),
|
|
440
|
+
owner_id: z10.string(),
|
|
441
|
+
idempotency_key: z10.string(),
|
|
442
|
+
name: z10.string(),
|
|
443
|
+
prompt: z10.string(),
|
|
444
|
+
recurrence: z10.string(),
|
|
445
|
+
timezone: z10.string(),
|
|
446
|
+
execution_config: z10.unknown(),
|
|
447
|
+
status: z10.enum([
|
|
443
448
|
"active",
|
|
444
449
|
"paused",
|
|
445
450
|
"completed",
|
|
446
451
|
"archived"
|
|
447
452
|
]),
|
|
448
|
-
generation:
|
|
453
|
+
generation: z10.union([z10.number(), z10.string()]),
|
|
449
454
|
next_run_at: millisColumn.nullable(),
|
|
450
|
-
next_wake_id:
|
|
455
|
+
next_wake_id: z10.string().nullable(),
|
|
451
456
|
created_at: millisColumn,
|
|
452
457
|
updated_at: millisColumn,
|
|
453
458
|
archived_at: millisColumn.nullable()
|
|
454
459
|
});
|
|
455
|
-
var runStatusSchema =
|
|
460
|
+
var runStatusSchema = z10.enum([
|
|
456
461
|
"dispatching",
|
|
457
462
|
"running",
|
|
458
463
|
"completed",
|
|
459
464
|
"failed",
|
|
460
465
|
"cancelled"
|
|
461
466
|
]);
|
|
462
|
-
var reviewStatusSchema =
|
|
467
|
+
var reviewStatusSchema = z10.enum([
|
|
463
468
|
"pending_review",
|
|
464
469
|
"reviewed",
|
|
465
470
|
"archived"
|
|
466
471
|
]);
|
|
467
|
-
var runRowSchema =
|
|
468
|
-
id:
|
|
469
|
-
task_id:
|
|
470
|
-
owner_id:
|
|
471
|
-
trigger:
|
|
472
|
-
idempotency_key:
|
|
472
|
+
var runRowSchema = z10.object({
|
|
473
|
+
id: z10.string(),
|
|
474
|
+
task_id: z10.string(),
|
|
475
|
+
owner_id: z10.string(),
|
|
476
|
+
trigger: z10.enum(["scheduled", "manual"]),
|
|
477
|
+
idempotency_key: z10.string().nullable(),
|
|
473
478
|
occurrence_at: millisColumn,
|
|
474
|
-
prompt:
|
|
475
|
-
execution_config:
|
|
479
|
+
prompt: z10.string(),
|
|
480
|
+
execution_config: z10.unknown(),
|
|
476
481
|
status: runStatusSchema,
|
|
477
482
|
review_status: reviewStatusSchema.nullable(),
|
|
478
|
-
external_execution_id:
|
|
479
|
-
dispatch_job_id:
|
|
480
|
-
reconciliation_job_id:
|
|
483
|
+
external_execution_id: z10.string().nullable(),
|
|
484
|
+
dispatch_job_id: z10.string(),
|
|
485
|
+
reconciliation_job_id: z10.string().nullable(),
|
|
481
486
|
next_check_at: millisColumn.nullable(),
|
|
482
487
|
started_at: millisColumn.nullable(),
|
|
483
488
|
finished_at: millisColumn.nullable(),
|
|
484
|
-
title:
|
|
485
|
-
summary:
|
|
486
|
-
error:
|
|
489
|
+
title: z10.string().nullable(),
|
|
490
|
+
summary: z10.string().nullable(),
|
|
491
|
+
error: z10.string().nullable(),
|
|
487
492
|
created_at: millisColumn,
|
|
488
493
|
updated_at: millisColumn
|
|
489
494
|
});
|
|
490
|
-
var taskRowsSchema =
|
|
491
|
-
var runRowsSchema =
|
|
495
|
+
var taskRowsSchema = z10.array(taskRowSchema);
|
|
496
|
+
var runRowsSchema = z10.array(runRowSchema);
|
|
492
497
|
var runJobsRowSchema = runRowSchema.pick({
|
|
493
498
|
dispatch_job_id: true,
|
|
494
499
|
reconciliation_job_id: true,
|
|
495
500
|
status: true
|
|
496
501
|
});
|
|
497
|
-
var scheduledJobSchema =
|
|
498
|
-
|
|
499
|
-
kind:
|
|
500
|
-
ownerId:
|
|
501
|
-
taskId:
|
|
502
|
-
occurrenceAt:
|
|
503
|
-
generation:
|
|
502
|
+
var scheduledJobSchema = z10.discriminatedUnion("kind", [
|
|
503
|
+
z10.object({
|
|
504
|
+
kind: z10.literal("occurrence"),
|
|
505
|
+
ownerId: z10.string(),
|
|
506
|
+
taskId: z10.string(),
|
|
507
|
+
occurrenceAt: z10.number(),
|
|
508
|
+
generation: z10.number()
|
|
504
509
|
}),
|
|
505
|
-
|
|
506
|
-
kind:
|
|
507
|
-
ownerId:
|
|
508
|
-
runId:
|
|
510
|
+
z10.object({
|
|
511
|
+
kind: z10.literal("dispatch"),
|
|
512
|
+
ownerId: z10.string(),
|
|
513
|
+
runId: z10.string()
|
|
509
514
|
}),
|
|
510
|
-
|
|
511
|
-
kind:
|
|
512
|
-
ownerId:
|
|
513
|
-
runId:
|
|
515
|
+
z10.object({
|
|
516
|
+
kind: z10.literal("reconcile"),
|
|
517
|
+
ownerId: z10.string(),
|
|
518
|
+
runId: z10.string()
|
|
514
519
|
})
|
|
515
520
|
]);
|
|
516
521
|
var ScheduledTasks = class {
|
|
@@ -916,7 +921,7 @@ var ScheduledTasks = class {
|
|
|
916
921
|
WHERE task_id = $1 AND owner_id = $2`,
|
|
917
922
|
[task.id, task.ownerId]
|
|
918
923
|
);
|
|
919
|
-
const runs =
|
|
924
|
+
const runs = z10.array(runJobsRowSchema).parse(rows);
|
|
920
925
|
if (runs.some(
|
|
921
926
|
({ status }) => status === "dispatching" || status === "running"
|
|
922
927
|
)) {
|
|
@@ -1648,12 +1653,12 @@ import { readFile, readdir } from "node:fs/promises";
|
|
|
1648
1653
|
import { basename, extname, join } from "node:path";
|
|
1649
1654
|
import { fileURLToPath } from "node:url";
|
|
1650
1655
|
import YAML from "yaml";
|
|
1651
|
-
import { z as
|
|
1656
|
+
import { z as z11 } from "zod";
|
|
1652
1657
|
var FILE_KEY_PREFIX = "zukhruf:schedule-file:";
|
|
1653
|
-
var frontmatterSchema =
|
|
1654
|
-
name:
|
|
1655
|
-
cron:
|
|
1656
|
-
timezone:
|
|
1658
|
+
var frontmatterSchema = z11.object({
|
|
1659
|
+
name: z11.string().trim().min(1).optional(),
|
|
1660
|
+
cron: z11.string().trim().min(1),
|
|
1661
|
+
timezone: z11.string().trim().min(1)
|
|
1657
1662
|
}).strict();
|
|
1658
1663
|
function scheduleFiles({
|
|
1659
1664
|
directory,
|
|
@@ -1727,12 +1732,12 @@ async function syncScheduleFiles(directory, ownerId, scheduled) {
|
|
|
1727
1732
|
|
|
1728
1733
|
// packages/experimental/src/zukhruf/plugins/schedules/index.ts
|
|
1729
1734
|
var SCHEDULED_TASK_ORIGIN = "scheduled-task";
|
|
1730
|
-
var executionConfigSchema =
|
|
1731
|
-
target:
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
kind:
|
|
1735
|
-
chatId:
|
|
1735
|
+
var executionConfigSchema = z12.object({
|
|
1736
|
+
target: z12.discriminatedUnion("kind", [
|
|
1737
|
+
z12.object({ kind: z12.literal("new-conversation") }),
|
|
1738
|
+
z12.object({
|
|
1739
|
+
kind: z12.literal("existing-conversation"),
|
|
1740
|
+
chatId: z12.string()
|
|
1736
1741
|
})
|
|
1737
1742
|
]).optional()
|
|
1738
1743
|
});
|
|
@@ -1749,30 +1754,33 @@ function schedules(options) {
|
|
|
1749
1754
|
schedulesCapabilities.boss,
|
|
1750
1755
|
schedulesCapabilities.transaction
|
|
1751
1756
|
],
|
|
1752
|
-
create: (bindings) =>
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
+
create: (bindings) => {
|
|
1758
|
+
const boss = bindings.get(schedulesCapabilities.boss);
|
|
1759
|
+
const transaction = bindings.get(schedulesCapabilities.transaction);
|
|
1760
|
+
return {
|
|
1761
|
+
initialize: (host) => RunningSchedules.start(host, { ...options, boss, transaction })
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1757
1764
|
};
|
|
1758
1765
|
}
|
|
1759
|
-
var
|
|
1766
|
+
var RunningSchedules = class _RunningSchedules {
|
|
1767
|
+
#host;
|
|
1760
1768
|
#scheduled;
|
|
1761
|
-
#sources;
|
|
1762
1769
|
#workerOptions;
|
|
1763
|
-
|
|
1764
|
-
require() {
|
|
1765
|
-
throw new Error("schedules plugin is not initialized");
|
|
1766
|
-
},
|
|
1767
|
-
is: () => false
|
|
1768
|
-
};
|
|
1769
|
-
#initializeOnce = pMemoize2(() => this.#initialize());
|
|
1770
|
-
constructor({
|
|
1770
|
+
static async start(host, {
|
|
1771
1771
|
sources,
|
|
1772
|
+
...options
|
|
1773
|
+
}) {
|
|
1774
|
+
const running = new _RunningSchedules(host, options);
|
|
1775
|
+
await running.#scheduled.initialize();
|
|
1776
|
+
for (const source of sources ?? []) await source(running);
|
|
1777
|
+
return running;
|
|
1778
|
+
}
|
|
1779
|
+
constructor(host, {
|
|
1772
1780
|
workerOptions,
|
|
1773
1781
|
...options
|
|
1774
1782
|
}) {
|
|
1775
|
-
this.#
|
|
1783
|
+
this.#host = host;
|
|
1776
1784
|
this.#workerOptions = workerOptions;
|
|
1777
1785
|
this.#scheduled = new ScheduledTasks({
|
|
1778
1786
|
...options,
|
|
@@ -1784,16 +1792,7 @@ var SchedulesPlugin = class {
|
|
|
1784
1792
|
}
|
|
1785
1793
|
});
|
|
1786
1794
|
}
|
|
1787
|
-
|
|
1788
|
-
this.#host = { require: () => host, is: (other) => other === host };
|
|
1789
|
-
return this.#initializeOnce();
|
|
1790
|
-
}
|
|
1791
|
-
work(host, waitForActive) {
|
|
1792
|
-
if (!this.#host.is(host)) {
|
|
1793
|
-
throw new Error(
|
|
1794
|
-
"schedules plugin must be initialized before work starts"
|
|
1795
|
-
);
|
|
1796
|
-
}
|
|
1795
|
+
work(waitForActive) {
|
|
1797
1796
|
return this.#scheduled.work(this.#workerOptions, waitForActive);
|
|
1798
1797
|
}
|
|
1799
1798
|
async create(ownerId, input) {
|
|
@@ -1854,11 +1853,6 @@ var SchedulesPlugin = class {
|
|
|
1854
1853
|
archiveRun(ownerId, runId) {
|
|
1855
1854
|
return this.#scheduled.archiveRun(ownerId, runId);
|
|
1856
1855
|
}
|
|
1857
|
-
async #initialize() {
|
|
1858
|
-
await this.#scheduled.initialize();
|
|
1859
|
-
if (!this.#sources) return;
|
|
1860
|
-
for (const source of this.#sources) await source(this);
|
|
1861
|
-
}
|
|
1862
1856
|
async #launch({
|
|
1863
1857
|
runId,
|
|
1864
1858
|
taskId,
|
|
@@ -1868,14 +1862,13 @@ var SchedulesPlugin = class {
|
|
|
1868
1862
|
prompt,
|
|
1869
1863
|
executionConfig
|
|
1870
1864
|
}) {
|
|
1871
|
-
const host = this.#host.require();
|
|
1872
1865
|
const conversation = executionConversation(runId, ownerId, executionConfig);
|
|
1873
|
-
if (executionConfig.target?.kind === "existing-conversation" && !await host.conversationExists(conversation)) {
|
|
1866
|
+
if (executionConfig.target?.kind === "existing-conversation" && !await this.#host.conversationExists(conversation)) {
|
|
1874
1867
|
throw new Error(
|
|
1875
1868
|
`Scheduled target conversation "${conversation.chatId}" was not found`
|
|
1876
1869
|
);
|
|
1877
1870
|
}
|
|
1878
|
-
const execution = await host.enqueue(conversation, {
|
|
1871
|
+
const execution = await this.#host.enqueue(conversation, {
|
|
1879
1872
|
message: {
|
|
1880
1873
|
id: runId,
|
|
1881
1874
|
role: "user",
|
|
@@ -1897,7 +1890,9 @@ var SchedulesPlugin = class {
|
|
|
1897
1890
|
executionId,
|
|
1898
1891
|
executionConfig
|
|
1899
1892
|
}) {
|
|
1900
|
-
const observation = this.#host.
|
|
1893
|
+
const observation = this.#host.observe(
|
|
1894
|
+
executionConversation(runId, ownerId, executionConfig)
|
|
1895
|
+
);
|
|
1901
1896
|
const execution = await observation.status(executionId);
|
|
1902
1897
|
if (!execution) {
|
|
1903
1898
|
throw new Error(`Scheduled execution "${executionId}" was not found`);
|
|
@@ -1939,7 +1934,7 @@ var SchedulesPlugin = class {
|
|
|
1939
1934
|
executionId,
|
|
1940
1935
|
executionConfig
|
|
1941
1936
|
}) {
|
|
1942
|
-
await this.#host.
|
|
1937
|
+
await this.#host.observe(executionConversation(runId, ownerId, executionConfig)).cancel(executionId);
|
|
1943
1938
|
}
|
|
1944
1939
|
async #assertTarget(ownerId, executionConfig) {
|
|
1945
1940
|
if (executionConfig.target?.kind !== "existing-conversation") return;
|
|
@@ -1947,7 +1942,7 @@ var SchedulesPlugin = class {
|
|
|
1947
1942
|
chatId: executionConfig.target.chatId,
|
|
1948
1943
|
userId: ownerId
|
|
1949
1944
|
};
|
|
1950
|
-
if (await this.#host.
|
|
1945
|
+
if (await this.#host.conversationExists(conversation)) return;
|
|
1951
1946
|
throw new ScheduledTasksError(
|
|
1952
1947
|
"invalid-input",
|
|
1953
1948
|
"task",
|