@deepagents/experimental 7.7.2 → 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.
Files changed (54) hide show
  1. package/README.md +16 -5
  2. package/dist/index.js +400 -177
  3. package/dist/index.js.map +4 -4
  4. package/dist/zukhruf/control-plane/agent-control-plane.d.ts.map +1 -1
  5. package/dist/zukhruf/control-plane/agent-thread-limit-error.d.ts +6 -0
  6. package/dist/zukhruf/control-plane/agent-thread-limit-error.d.ts.map +1 -0
  7. package/dist/zukhruf/control-plane/agent-turn-id.d.ts +3 -0
  8. package/dist/zukhruf/control-plane/agent-turn-id.d.ts.map +1 -1
  9. package/dist/zukhruf/control-plane/stale-turn-error.d.ts +7 -0
  10. package/dist/zukhruf/control-plane/stale-turn-error.d.ts.map +1 -0
  11. package/dist/zukhruf/control-plane/turn-not-found-error.d.ts +7 -0
  12. package/dist/zukhruf/control-plane/turn-not-found-error.d.ts.map +1 -0
  13. package/dist/zukhruf/index.d.ts +4 -0
  14. package/dist/zukhruf/index.d.ts.map +1 -1
  15. package/dist/zukhruf/index.js +400 -177
  16. package/dist/zukhruf/index.js.map +4 -4
  17. package/dist/zukhruf/is-named-error.d.ts +7 -0
  18. package/dist/zukhruf/is-named-error.d.ts.map +1 -0
  19. package/dist/zukhruf/mailbox/communication-schema.d.ts +26 -0
  20. package/dist/zukhruf/mailbox/communication-schema.d.ts.map +1 -0
  21. package/dist/zukhruf/mailbox/ddl.postgres.d.ts +2 -0
  22. package/dist/zukhruf/mailbox/ddl.postgres.d.ts.map +1 -0
  23. package/dist/zukhruf/mailbox/postgres.store.d.ts +23 -0
  24. package/dist/zukhruf/mailbox/postgres.store.d.ts.map +1 -0
  25. package/dist/zukhruf/mailbox/sqlite.store.d.ts.map +1 -1
  26. package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts +1 -1
  27. package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts.map +1 -1
  28. package/dist/zukhruf/plugins/conversation-scheduling/index.d.ts.map +1 -1
  29. package/dist/zukhruf/plugins/conversation-scheduling/index.js +142 -136
  30. package/dist/zukhruf/plugins/conversation-scheduling/index.js.map +3 -3
  31. package/dist/zukhruf/plugins/http/index.d.ts +2 -2
  32. package/dist/zukhruf/plugins/http/index.d.ts.map +1 -1
  33. package/dist/zukhruf/plugins/http/index.js +72 -17
  34. package/dist/zukhruf/plugins/http/index.js.map +4 -4
  35. package/dist/zukhruf/plugins/schedules/http.d.ts.map +1 -1
  36. package/dist/zukhruf/plugins/schedules/http.js +44 -32
  37. package/dist/zukhruf/plugins/schedules/http.js.map +4 -4
  38. package/dist/zukhruf/plugins/schedules/index.d.ts +2 -2
  39. package/dist/zukhruf/plugins/schedules/index.d.ts.map +1 -1
  40. package/dist/zukhruf/plugins/schedules/index.js +138 -143
  41. package/dist/zukhruf/plugins/schedules/index.js.map +3 -3
  42. package/dist/zukhruf/plugins/uploads/http.js +30 -19
  43. package/dist/zukhruf/plugins/uploads/http.js.map +4 -4
  44. package/dist/zukhruf/plugins/uploads/index.d.ts +2 -2
  45. package/dist/zukhruf/plugins/uploads/index.d.ts.map +1 -1
  46. package/dist/zukhruf/plugins/uploads/index.js +48 -55
  47. package/dist/zukhruf/plugins/uploads/index.js.map +2 -2
  48. package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts +4 -1
  49. package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts.map +1 -1
  50. package/dist/zukhruf/runtime/agent-runtime.d.ts +19 -11
  51. package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
  52. package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts +4 -4
  53. package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts.map +1 -1
  54. package/package.json +20 -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 pMemoize2 from "p-memoize";
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 z2 } from "zod";
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 = z2.object({
81
- sourceCount: z2.number().int().positive(),
82
- sourceHash: z2.string(),
83
- replacement: z2.array(z2.unknown()).transform(
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 = z2.object({
88
- scope: z2.string(),
89
- prefixLength: z2.number().int().nonnegative(),
90
- prefixHash: z2.string(),
91
- startedAt: z2.number().int().nonnegative(),
92
- retentionMs: z2.number().int().positive().optional()
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: z2.number().int().nonnegative() });
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 z3 } from "zod";
122
- var childActivitySchema = z3.object({
123
- id: z3.string(),
124
- type: z3.enum(["spawn", "message", "followup", "interrupt", "completion"]),
125
- at: z3.number(),
126
- actorPath: z3.string(),
127
- targetPath: z3.string(),
128
- streamId: z3.string(),
129
- outcome: z3.enum(["completed", "failed", "cancelled"]).optional()
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 = z3.partialRecord(
136
+ var childActivitiesSchema = z4.partialRecord(
132
137
  childActivitySchema.shape.type,
133
138
  childActivitySchema
134
139
  );
135
- var childActivityMetadataSchema = z3.looseObject({
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 z4 } from "zod";
150
- var interruptAgentInputSchema = z4.object({
151
- target: z4.string().trim().min(1).describe(
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 = z4.object({ previous_status: listedAgentStatusSchema }).strict();
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 z5 } from "zod";
166
- var listAgentsInputSchema = z5.object({
167
- path_prefix: z5.string().trim().min(1).describe(
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 = z5.object({ agents: z5.array(listedAgentSchema) }).strict();
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 z6 } from "zod";
182
- var agentMessageInputSchema = z6.object({
183
- target: z6.string().trim().min(1).describe(
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: z6.string().trim().min(1).describe("The message or follow-up task.")
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 z7 } from "zod";
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 = z7.object({
221
- agent_type: z7.string().trim().min(1).describe("The name of one available subagent declaration."),
222
- task_name: z7.string().trim().min(1).refine(
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: z7.string().refine((value) => value.trim().length > 0, "message cannot be empty").describe("The initial task for the spawned agent."),
227
- fork_turns: z7.string().trim().refine((value) => parseForkTurns(value) !== void 0, forkTurnsError).describe(
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 = z7.object({ task_name: z7.string() }).strict();
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 z8 } from "zod";
236
- var waitAgentOutputSchema = z8.object({ message: z8.string(), timed_out: z8.boolean() }).strict();
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 z9 } from "zod";
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 = z9.union([z9.number(), z9.string(), z9.bigint()]);
433
- var taskRowSchema = z9.object({
434
- id: z9.string(),
435
- owner_id: z9.string(),
436
- idempotency_key: z9.string(),
437
- name: z9.string(),
438
- prompt: z9.string(),
439
- recurrence: z9.string(),
440
- timezone: z9.string(),
441
- execution_config: z9.unknown(),
442
- status: z9.enum([
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: z9.union([z9.number(), z9.string()]),
453
+ generation: z10.union([z10.number(), z10.string()]),
449
454
  next_run_at: millisColumn.nullable(),
450
- next_wake_id: z9.string().nullable(),
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 = z9.enum([
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 = z9.enum([
467
+ var reviewStatusSchema = z10.enum([
463
468
  "pending_review",
464
469
  "reviewed",
465
470
  "archived"
466
471
  ]);
467
- var runRowSchema = z9.object({
468
- id: z9.string(),
469
- task_id: z9.string(),
470
- owner_id: z9.string(),
471
- trigger: z9.enum(["scheduled", "manual"]),
472
- idempotency_key: z9.string().nullable(),
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: z9.string(),
475
- execution_config: z9.unknown(),
479
+ prompt: z10.string(),
480
+ execution_config: z10.unknown(),
476
481
  status: runStatusSchema,
477
482
  review_status: reviewStatusSchema.nullable(),
478
- external_execution_id: z9.string().nullable(),
479
- dispatch_job_id: z9.string(),
480
- reconciliation_job_id: z9.string().nullable(),
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: z9.string().nullable(),
485
- summary: z9.string().nullable(),
486
- error: z9.string().nullable(),
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 = z9.array(taskRowSchema);
491
- var runRowsSchema = z9.array(runRowSchema);
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 = z9.discriminatedUnion("kind", [
498
- z9.object({
499
- kind: z9.literal("occurrence"),
500
- ownerId: z9.string(),
501
- taskId: z9.string(),
502
- occurrenceAt: z9.number(),
503
- generation: z9.number()
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
- z9.object({
506
- kind: z9.literal("dispatch"),
507
- ownerId: z9.string(),
508
- runId: z9.string()
510
+ z10.object({
511
+ kind: z10.literal("dispatch"),
512
+ ownerId: z10.string(),
513
+ runId: z10.string()
509
514
  }),
510
- z9.object({
511
- kind: z9.literal("reconcile"),
512
- ownerId: z9.string(),
513
- runId: z9.string()
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 = z9.array(runJobsRowSchema).parse(rows);
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 z10 } from "zod";
1656
+ import { z as z11 } from "zod";
1652
1657
  var FILE_KEY_PREFIX = "zukhruf:schedule-file:";
1653
- var frontmatterSchema = z10.object({
1654
- name: z10.string().trim().min(1).optional(),
1655
- cron: z10.string().trim().min(1),
1656
- timezone: z10.string().trim().min(1)
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 = z11.object({
1731
- target: z11.discriminatedUnion("kind", [
1732
- z11.object({ kind: z11.literal("new-conversation") }),
1733
- z11.object({
1734
- kind: z11.literal("existing-conversation"),
1735
- chatId: z11.string()
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) => new SchedulesPlugin({
1753
- ...options,
1754
- boss: bindings.get(schedulesCapabilities.boss),
1755
- transaction: bindings.get(schedulesCapabilities.transaction)
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 SchedulesPlugin = class {
1766
+ var RunningSchedules = class _RunningSchedules {
1767
+ #host;
1760
1768
  #scheduled;
1761
- #sources;
1762
1769
  #workerOptions;
1763
- #host = {
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.#sources = sources;
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
- initialize(host) {
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.require().observe(executionConversation(runId, ownerId, executionConfig));
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.require().observe(executionConversation(runId, ownerId, executionConfig)).cancel(executionId);
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.require().conversationExists(conversation)) return;
1945
+ if (await this.#host.conversationExists(conversation)) return;
1951
1946
  throw new ScheduledTasksError(
1952
1947
  "invalid-input",
1953
1948
  "task",