@swirls/looms 0.25.0 → 0.26.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/actor/cell.d.ts +3 -1
  3. package/dist/actor/cell.js +1 -0
  4. package/dist/actor/host.d.ts +3 -1
  5. package/dist/actor/host.js +2 -1
  6. package/dist/actor/routing.d.ts +6 -3
  7. package/dist/actor/routing.js +6 -4
  8. package/dist/agent/agent-session.js +2 -2
  9. package/dist/agent/debugger/agent-chat.js +4 -3
  10. package/dist/agent/definitions.d.ts +3 -1
  11. package/dist/agent/effects.js +5 -3
  12. package/dist/agent/module.d.ts +730 -730
  13. package/dist/approval/steps.d.ts +3 -1
  14. package/dist/approval/steps.js +2 -2
  15. package/dist/client/client.d.ts +7 -1
  16. package/dist/client/client.js +5 -2
  17. package/dist/cloudflare/durable-object.d.ts +3 -1
  18. package/dist/cloudflare/durable-object.js +1 -0
  19. package/dist/cloudflare/queue-consumer.d.ts +3 -1
  20. package/dist/cloudflare/queue-consumer.js +2 -1
  21. package/dist/cloudflare/router.d.ts +3 -1
  22. package/dist/cloudflare/router.js +1 -1
  23. package/dist/core/compose.d.ts +8 -2
  24. package/dist/core/compose.js +6 -3
  25. package/dist/core/effects.d.ts +3 -0
  26. package/dist/core/envelope.d.ts +2 -0
  27. package/dist/core/envelope.js +2 -2
  28. package/dist/core/event-codec.d.ts +4 -3
  29. package/dist/core/event-codec.js +7 -7
  30. package/dist/core/fold.d.ts +3 -0
  31. package/dist/core/fold.js +3 -1
  32. package/dist/core/fork.js +1 -1
  33. package/dist/core/ids.d.ts +70 -5
  34. package/dist/core/ids.js +164 -41
  35. package/dist/core/snapshots.d.ts +2 -0
  36. package/dist/core/snapshots.js +2 -1
  37. package/dist/core/thread.d.ts +8 -0
  38. package/dist/debugger/app/assets/{index-GLtrulmj.js → index-D_FKxPrN.js} +2 -2
  39. package/dist/debugger/app/assets/routes-CkwzFejg.js +47 -0
  40. package/dist/debugger/app/index.html +1 -1
  41. package/dist/debugger/context.d.ts +4 -1
  42. package/dist/debugger/context.js +4 -4
  43. package/dist/debugger/shell/debugger-shell.d.ts +4 -1
  44. package/dist/debugger/shell/debugger-shell.js +2 -2
  45. package/dist/debugger/shell/use-start-run.d.ts +1 -1
  46. package/dist/debugger/shell/use-start-run.js +1 -2
  47. package/dist/evaluator/effects.d.ts +33 -33
  48. package/dist/evaluator/module.d.ts +66 -66
  49. package/dist/evaluator/steps.d.ts +2 -2
  50. package/dist/evaluator/steps.js +3 -3
  51. package/dist/react/react.d.ts +8 -3
  52. package/dist/react/react.js +15 -2
  53. package/dist/react/store.d.ts +5 -1
  54. package/dist/react/store.js +5 -4
  55. package/dist/runtime/cancellation.js +5 -5
  56. package/dist/runtime/deadline-transition-planner.d.ts +1 -0
  57. package/dist/runtime/deadline-transition-planner.js +8 -7
  58. package/dist/runtime/effect-admission.js +1 -0
  59. package/dist/runtime/helpers.d.ts +6 -5
  60. package/dist/runtime/helpers.js +8 -8
  61. package/dist/runtime/local-effect-executor.js +15 -10
  62. package/dist/runtime/looms.d.ts +6 -1
  63. package/dist/runtime/looms.js +4 -1
  64. package/dist/runtime/retry-policy.d.ts +2 -1
  65. package/dist/runtime/retry-policy.js +2 -1
  66. package/dist/runtime/runtime.js +10 -10
  67. package/dist/runtime/server/routes/runs.js +5 -5
  68. package/dist/runtime/types.d.ts +7 -1
  69. package/dist/runtime/wake-engine.js +10 -9
  70. package/dist/runtime/worker-callbacks.js +9 -8
  71. package/dist/runtime/worker-effect-dispatch.d.ts +3 -2
  72. package/dist/runtime/worker-effect-dispatch.js +7 -5
  73. package/dist/schedule/module.d.ts +36 -36
  74. package/dist/swarm/steps.d.ts +3 -3
  75. package/dist/swarm/steps.js +5 -5
  76. package/dist/swarm/tools.d.ts +3 -2
  77. package/dist/swarm/tools.js +13 -13
  78. package/dist/workflow/effects.js +6 -5
  79. package/dist/workflow/graph.d.ts +3 -3
  80. package/dist/workflow/graph.js +5 -5
  81. package/dist/workflow/module.d.ts +8 -2
  82. package/dist/workflow/threads.d.ts +14 -2
  83. package/dist/workflow/threads.js +54 -44
  84. package/package.json +1 -1
  85. package/dist/debugger/app/assets/routes-CECZJJob.js +0 -47
@@ -99,7 +99,7 @@ export function planWorkerEffects(input) {
99
99
  threadId: item.threadId,
100
100
  causationId: item.causingEventId,
101
101
  origin: { type: 'system' },
102
- }),
102
+ }, { ids: input.registry.ids }),
103
103
  task: workerTask(input.runId, item, attempt, {
104
104
  details: existing?.heartbeatDetails,
105
105
  attributes: input.state.attributes,
@@ -139,7 +139,8 @@ function withinInFlightLimit(input, workerItems, due) {
139
139
  * arrived, so a later `started` from `dispatch_wait` is accepted.
140
140
  * - Missing worker: ambiguous (misconfiguration).
141
141
  */
142
- export function dispatchWorkerEffect(runId, plan, worker, now, options = {}) {
142
+ export function dispatchWorkerEffect(runId, plan, worker, now, options) {
143
+ const { ids } = options;
143
144
  const dispatched = createEvent(runId, {
144
145
  type: 'runtime.effect.dispatched',
145
146
  payload: {
@@ -150,14 +151,14 @@ export function dispatchWorkerEffect(runId, plan, worker, now, options = {}) {
150
151
  threadId: plan.item.threadId,
151
152
  causationId: plan.item.causingEventId,
152
153
  origin: { type: 'system' },
153
- });
154
+ }, { ids });
154
155
  const ambiguous = (error) => createEvent(runId, {
155
156
  type: 'runtime.effect.ambiguous',
156
157
  payload: { effectId: plan.item.effectId, attempt: plan.attempt, error },
157
158
  threadId: plan.item.threadId,
158
159
  causationId: plan.item.causingEventId,
159
160
  origin: { type: 'system' },
160
- });
161
+ }, { ids });
161
162
  if (!worker) {
162
163
  return Effect.succeed(ambiguous(`no effect worker is configured for "${plan.item.effect.type}"`));
163
164
  }
@@ -168,6 +169,7 @@ export function dispatchWorkerEffect(runId, plan, worker, now, options = {}) {
168
169
  onFailure: (error) => {
169
170
  if (worker.dispatchSemantics === 'acknowledged') {
170
171
  return planAttemptFailure({
172
+ ids: ids,
171
173
  runId,
172
174
  item: plan.item,
173
175
  attempt: plan.attempt,
@@ -193,7 +195,7 @@ export function dispatchWorkerEffect(runId, plan, worker, now, options = {}) {
193
195
  threadId: plan.item.threadId,
194
196
  causationId: plan.item.causingEventId,
195
197
  origin: { type: 'system' },
196
- });
198
+ }, { ids });
197
199
  },
198
200
  onSuccess: () => dispatched,
199
201
  }));
@@ -342,15 +342,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
342
342
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
343
343
  readonly type: "schedule.paused";
344
344
  readonly payload: {};
345
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
346
- readonly type: "schedule.resumed";
347
- readonly payload: {};
348
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
349
- readonly type: "schedule.retired";
350
- readonly payload: {};
351
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
352
- readonly type: "schedule.triggered";
353
- readonly payload: {};
354
345
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
355
346
  readonly type: "schedule.planned";
356
347
  readonly payload: {
@@ -374,6 +365,12 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
374
365
  readonly payload: {
375
366
  readonly reason: string;
376
367
  };
368
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
369
+ readonly type: "schedule.resumed";
370
+ readonly payload: {};
371
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
372
+ readonly type: "schedule.retired";
373
+ readonly payload: {};
377
374
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
378
375
  readonly type: "schedule.skipped";
379
376
  readonly payload: {
@@ -384,6 +381,9 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
384
381
  readonly manual: boolean;
385
382
  readonly triggerId?: string | undefined;
386
383
  };
384
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
385
+ readonly type: "schedule.triggered";
386
+ readonly payload: {};
387
387
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
388
388
  readonly type: "schedule.updated";
389
389
  readonly payload: {
@@ -693,15 +693,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
693
693
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
694
694
  readonly type: "schedule.paused";
695
695
  readonly payload: {};
696
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
697
- readonly type: "schedule.resumed";
698
- readonly payload: {};
699
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
700
- readonly type: "schedule.retired";
701
- readonly payload: {};
702
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
703
- readonly type: "schedule.triggered";
704
- readonly payload: {};
705
696
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
706
697
  readonly type: "schedule.planned";
707
698
  readonly payload: {
@@ -725,6 +716,12 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
725
716
  readonly payload: {
726
717
  readonly reason: string;
727
718
  };
719
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
720
+ readonly type: "schedule.resumed";
721
+ readonly payload: {};
722
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
723
+ readonly type: "schedule.retired";
724
+ readonly payload: {};
728
725
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
729
726
  readonly type: "schedule.skipped";
730
727
  readonly payload: {
@@ -735,6 +732,9 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
735
732
  readonly manual: boolean;
736
733
  readonly triggerId?: string | undefined;
737
734
  };
735
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
736
+ readonly type: "schedule.triggered";
737
+ readonly payload: {};
738
738
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
739
739
  readonly type: "schedule.updated";
740
740
  readonly payload: {
@@ -1120,15 +1120,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1120
1120
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1121
1121
  readonly type: "schedule.paused";
1122
1122
  readonly payload: {};
1123
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1124
- readonly type: "schedule.resumed";
1125
- readonly payload: {};
1126
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1127
- readonly type: "schedule.retired";
1128
- readonly payload: {};
1129
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1130
- readonly type: "schedule.triggered";
1131
- readonly payload: {};
1132
1123
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1133
1124
  readonly type: "schedule.planned";
1134
1125
  readonly payload: {
@@ -1152,6 +1143,12 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1152
1143
  readonly payload: {
1153
1144
  readonly reason: string;
1154
1145
  };
1146
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1147
+ readonly type: "schedule.resumed";
1148
+ readonly payload: {};
1149
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1150
+ readonly type: "schedule.retired";
1151
+ readonly payload: {};
1155
1152
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1156
1153
  readonly type: "schedule.skipped";
1157
1154
  readonly payload: {
@@ -1162,6 +1159,9 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1162
1159
  readonly manual: boolean;
1163
1160
  readonly triggerId?: string | undefined;
1164
1161
  };
1162
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1163
+ readonly type: "schedule.triggered";
1164
+ readonly payload: {};
1165
1165
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1166
1166
  readonly type: "schedule.updated";
1167
1167
  readonly payload: {
@@ -1471,15 +1471,6 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1471
1471
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1472
1472
  readonly type: "schedule.paused";
1473
1473
  readonly payload: {};
1474
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1475
- readonly type: "schedule.resumed";
1476
- readonly payload: {};
1477
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1478
- readonly type: "schedule.retired";
1479
- readonly payload: {};
1480
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1481
- readonly type: "schedule.triggered";
1482
- readonly payload: {};
1483
1474
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1484
1475
  readonly type: "schedule.planned";
1485
1476
  readonly payload: {
@@ -1503,6 +1494,12 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1503
1494
  readonly payload: {
1504
1495
  readonly reason: string;
1505
1496
  };
1497
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1498
+ readonly type: "schedule.resumed";
1499
+ readonly payload: {};
1500
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1501
+ readonly type: "schedule.retired";
1502
+ readonly payload: {};
1506
1503
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1507
1504
  readonly type: "schedule.skipped";
1508
1505
  readonly payload: {
@@ -1513,6 +1510,9 @@ export declare function schedule(options?: ScheduleModuleOptions): import("@swir
1513
1510
  readonly manual: boolean;
1514
1511
  readonly triggerId?: string | undefined;
1515
1512
  };
1513
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1514
+ readonly type: "schedule.triggered";
1515
+ readonly payload: {};
1516
1516
  }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
1517
1517
  readonly type: "schedule.updated";
1518
1518
  readonly payload: {
@@ -1,5 +1,5 @@
1
1
  import type { Schema } from 'effect';
2
- import { type RuntimeEffect } from '@swirls/looms/core';
2
+ import { type LoomsIds, type RuntimeEffect } from '@swirls/looms/core';
3
3
  import { type CreateTaskArgsSchema, type PostArgsSchema } from './effects';
4
4
  /** Which board a step writes to and the name it writes under. */
5
5
  export interface BoardBinding {
@@ -10,6 +10,6 @@ export interface BoardBinding {
10
10
  * Post to a board from a thread or workflow node, and park until the board has answered.
11
11
  * The node resumes with the posted message, or fails if the board refused the post.
12
12
  */
13
- export declare function post(binding: BoardBinding, args: Schema.Schema.Type<typeof PostArgsSchema>): RuntimeEffect[];
13
+ export declare function post(binding: BoardBinding, args: Schema.Schema.Type<typeof PostArgsSchema>, ids?: LoomsIds): RuntimeEffect[];
14
14
  /** Create a board task from a thread or workflow node, and park until the board has answered. */
15
- export declare function createTask(binding: BoardBinding, args: Schema.Schema.Type<typeof CreateTaskArgsSchema>): RuntimeEffect[];
15
+ export declare function createTask(binding: BoardBinding, args: Schema.Schema.Type<typeof CreateTaskArgsSchema>, ids?: LoomsIds): RuntimeEffect[];
@@ -1,11 +1,11 @@
1
- import { createWaitId, invoke, wait } from '@swirls/looms/core';
1
+ import { invoke, typeIds, wait } from '@swirls/looms/core';
2
2
  import { createTaskEffect, postEffect, } from './effects.js';
3
3
  /**
4
4
  * Post to a board from a thread or workflow node, and park until the board has answered.
5
5
  * The node resumes with the posted message, or fails if the board refused the post.
6
6
  */
7
- export function post(binding, args) {
8
- const callId = createWaitId('swarm');
7
+ export function post(binding, args, ids = typeIds) {
8
+ const callId = ids.create('wait');
9
9
  return [
10
10
  invoke(postEffect, { callId, ...binding, ...args }, `post_${callId}`),
11
11
  wait({
@@ -15,8 +15,8 @@ export function post(binding, args) {
15
15
  ];
16
16
  }
17
17
  /** Create a board task from a thread or workflow node, and park until the board has answered. */
18
- export function createTask(binding, args) {
19
- const callId = createWaitId('swarm');
18
+ export function createTask(binding, args, ids = typeIds) {
19
+ const callId = ids.create('wait');
20
20
  return [
21
21
  invoke(createTaskEffect, { callId, ...binding, ...args }, `task_${callId}`),
22
22
  wait({
@@ -1,11 +1,11 @@
1
1
  import { type EffectsTool } from '@swirls/looms/agent';
2
- import { type JsonValue } from '@swirls/looms/core';
2
+ import { type JsonValue, type LoomsIds } from '@swirls/looms/core';
3
3
  import type { BoardBinding } from './steps';
4
4
  /**
5
5
  * The board as agent tools, writing as `binding.as` on `binding.board`. Build a fresh set for
6
6
  * each turn (`resolveTools` does), because every tool carries the id of the one call it serves.
7
7
  */
8
- export declare function boardTools(binding: BoardBinding): EffectsTool[];
8
+ export declare function boardTools(binding: BoardBinding, ids?: LoomsIds): EffectsTool[];
9
9
  /**
10
10
  * The board tools of the swarm member a run was started for, or none when the run was not
11
11
  * started by a swarm. Pass it as an agent's `resolveTools`:
@@ -16,4 +16,5 @@ export declare function boardTools(binding: BoardBinding): EffectsTool[];
16
16
  */
17
17
  export declare function memberTools(ctx: {
18
18
  readonly input: JsonValue;
19
+ readonly ids?: LoomsIds;
19
20
  }): EffectsTool[];
@@ -1,14 +1,14 @@
1
1
  import { Predicate } from 'effect';
2
2
  import { asEffectsTool } from '@swirls/looms/agent';
3
- import { createWaitId, invoke } from '@swirls/looms/core';
3
+ import { invoke, typeIds } from '@swirls/looms/core';
4
4
  import { readActivation } from './definitions.js';
5
5
  import { ClaimTaskArgsSchema, CreateTaskArgsSchema, LabelArgsSchema, ListTasksArgsSchema, PostArgsSchema, ReadArgsSchema, ReplyArgsSchema, SettleTaskArgsSchema, claimTaskEffect, createTaskEffect, labelEffect, listTasksEffect, postEffect, readEffect, replyEffect, settleTaskEffect, } from './effects.js';
6
6
  /**
7
7
  * A tool whose call becomes one board effect. The agent waits for the event that carries the
8
8
  * same `callId`: the board's answer, or `swarm.call.rejected` when the board refused.
9
9
  */
10
- function boardTool(binding, def) {
11
- const callId = createWaitId('swarm');
10
+ function boardTool(binding, def, ids) {
11
+ const callId = ids.create('wait');
12
12
  return asEffectsTool({
13
13
  name: def.name,
14
14
  description: def.description,
@@ -24,7 +24,7 @@ function boardTool(binding, def) {
24
24
  * The board as agent tools, writing as `binding.as` on `binding.board`. Build a fresh set for
25
25
  * each turn (`resolveTools` does), because every tool carries the id of the one call it serves.
26
26
  */
27
- export function boardTools(binding) {
27
+ export function boardTools(binding, ids = typeIds) {
28
28
  return [
29
29
  boardTool(binding, {
30
30
  name: 'board_read',
@@ -32,56 +32,56 @@ export function boardTools(binding) {
32
32
  input: ReadArgsSchema,
33
33
  effect: readEffect,
34
34
  answer: 'swarm.messages.read',
35
- }),
35
+ }, ids),
36
36
  boardTool(binding, {
37
37
  name: 'board_post',
38
38
  description: 'Start a new thread in a channel. Mention a member with @name to wake them. To continue an existing thread, use board_reply.',
39
39
  input: PostArgsSchema,
40
40
  effect: postEffect,
41
41
  answer: 'swarm.message.posted',
42
- }),
42
+ }, ids),
43
43
  boardTool(binding, {
44
44
  name: 'board_reply',
45
45
  description: 'Reply in the thread of message `to`. Use it to answer, report progress on a task, or mention a member with @name.',
46
46
  input: ReplyArgsSchema,
47
47
  effect: replyEffect,
48
48
  answer: 'swarm.message.posted',
49
- }),
49
+ }, ids),
50
50
  boardTool(binding, {
51
51
  name: 'board_label',
52
52
  description: 'Set or unset key=value labels on a message to track state. Pass `if` to change them only when the labels still have the values you expect (null means unset).',
53
53
  input: LabelArgsSchema,
54
54
  effect: labelEffect,
55
55
  answer: 'swarm.message.labeled',
56
- }),
56
+ }, ids),
57
57
  boardTool(binding, {
58
58
  name: 'board_create_task',
59
59
  description: 'Put a unit of work on the board for a member to claim. Pass `for` to assign it to one member, and `needs` with task ids that must complete first. The text is the instructions for whoever claims it.',
60
60
  input: CreateTaskArgsSchema,
61
61
  effect: createTaskEffect,
62
62
  answer: 'swarm.task.created',
63
- }),
63
+ }, ids),
64
64
  boardTool(binding, {
65
65
  name: 'board_list_tasks',
66
66
  description: 'List tasks, oldest first, filtered by channel, state, or assignee.',
67
67
  input: ListTasksArgsSchema,
68
68
  effect: listTasksEffect,
69
69
  answer: 'swarm.tasks.listed',
70
- }),
70
+ }, ids),
71
71
  boardTool(binding, {
72
72
  name: 'board_claim_task',
73
73
  description: 'Claim a task before working on it, so no other member does the same work. Pass `task` to claim one task, or `channel` to take the oldest ready task you may work on. The result has a `token`: keep it for board_settle_task. `claim` is null when nothing is ready.',
74
74
  input: ClaimTaskArgsSchema,
75
75
  effect: claimTaskEffect,
76
76
  answer: 'swarm.task.claimed',
77
- }),
77
+ }, ids),
78
78
  boardTool(binding, {
79
79
  name: 'board_settle_task',
80
80
  description: 'Finish a task you claimed, using the token from board_claim_task. Outcome "completed" with the result in `note`, "failed" with the reason, "blocked" with what it is waiting on, or "released" to return it to the queue untouched.',
81
81
  input: SettleTaskArgsSchema,
82
82
  effect: settleTaskEffect,
83
83
  answer: 'swarm.task.settled',
84
- }),
84
+ }, ids),
85
85
  ];
86
86
  }
87
87
  /**
@@ -95,6 +95,6 @@ export function boardTools(binding) {
95
95
  export function memberTools(ctx) {
96
96
  const activation = readActivation(ctx.input);
97
97
  return activation
98
- ? boardTools({ board: activation.swarm.board, as: activation.swarm.member })
98
+ ? boardTools({ board: activation.swarm.board, as: activation.swarm.member }, ctx.ids)
99
99
  : [];
100
100
  }
@@ -1,5 +1,5 @@
1
1
  import { Clock, Data, Effect, Predicate, Schema } from 'effect';
2
- import { createThreadId, createWaitId, DEFAULT_DEFINITION_VERSION, } from '@swirls/looms/core';
2
+ import { createWaitId, DEFAULT_DEFINITION_VERSION, } from '@swirls/looms/core';
3
3
  import { NodeStateSchema, nodeResultBuilders, } from './definitions.js';
4
4
  import { WorkflowDefinitionsTag } from './definitions-store.js';
5
5
  import { assertJsonWithinLimit, DEFAULT_CHECKPOINT_SIZE_LIMIT_BYTES, DEFAULT_GRAPH_CONCURRENCY, getReadyNodeIds, getSkippableNodeIds, getUnusedFallbackIds, iterationChildWorkflowId, nodeChildWorkflowId, nodeResults, nodeRunKey, } from './graph.js';
@@ -158,6 +158,7 @@ export const runNodeEffect = workflowModule.effect({
158
158
  : undefined;
159
159
  const run = {
160
160
  threadId: ctx.threadId,
161
+ ids: ctx.ids,
161
162
  nodeId: input.nodeId,
162
163
  attempt: input.attempt,
163
164
  iteration: input.iteration,
@@ -207,7 +208,7 @@ function runNode(definition, run) {
207
208
  }
208
209
  function nodeResultEvents(definition, nodeType, run, result) {
209
210
  return Effect.gen(function* () {
210
- const { threadId, nodeId, attempt } = run;
211
+ const { threadId, ids, nodeId, attempt } = run;
211
212
  const outputLabel = `Node ${nodeId} output`;
212
213
  switch (result.type) {
213
214
  case 'value':
@@ -227,8 +228,8 @@ function nodeResultEvents(definition, nodeType, run, result) {
227
228
  case 'spawn': {
228
229
  const childThreadId = result.childThreadId ??
229
230
  (nodeType === 'workflow'
230
- ? nodeChildWorkflowId(threadId, nodeId, attempt)
231
- : createThreadId());
231
+ ? nodeChildWorkflowId(threadId, nodeId, attempt, ids)
232
+ : ids.create('thread'));
232
233
  return spawnRequested(definition, run, childThreadId, result, result.input);
233
234
  }
234
235
  case 'sleep': {
@@ -283,7 +284,7 @@ function nodeResultEvents(definition, nodeType, run, result) {
283
284
  if (index >= result.maxIterations) {
284
285
  return finished(run, run.iteration?.previous ?? null, null);
285
286
  }
286
- const childThreadId = iterationChildWorkflowId(threadId, nodeId, 'loop', attempt, index);
287
+ const childThreadId = iterationChildWorkflowId(threadId, nodeId, 'loop', attempt, index, ids);
287
288
  return spawnRequested(definition, run, childThreadId, result, result.input, index);
288
289
  }
289
290
  default: {
@@ -1,5 +1,5 @@
1
1
  import { Effect } from 'effect';
2
- import { type JsonValue } from '@swirls/looms/core';
2
+ import { type JsonValue, type LoomsIds } from '@swirls/looms/core';
3
3
  import type { NodeState, WorkflowDefinition, WorkflowNodeDefinition } from './definitions';
4
4
  export declare const MIN_GRAPH_CONCURRENCY = 1;
5
5
  export declare const MAX_GRAPH_CONCURRENCY = 64;
@@ -34,8 +34,8 @@ export interface WorkflowEdge {
34
34
  export type GraphNodeStatuses = Record<string, NodeState['status']>;
35
35
  /** Distinguishes each attempt, and each loop iteration within it, of one node. */
36
36
  export declare function nodeRunKey(nodeId: string, attempt: number, iteration?: number): string;
37
- export declare function iterationChildWorkflowId(parentThreadId: string, nodeId: string, kind: 'map' | 'loop', attempt: number, index: number): string;
38
- export declare function nodeChildWorkflowId(parentThreadId: string, nodeId: string, attempt: number): string;
37
+ export declare function iterationChildWorkflowId(parentThreadId: string, nodeId: string, kind: 'map' | 'loop', attempt: number, index: number, ids?: LoomsIds): string;
38
+ export declare function nodeChildWorkflowId(parentThreadId: string, nodeId: string, attempt: number, ids?: LoomsIds): string;
39
39
  export declare function assertJsonWithinLimit(value: JsonValue | Readonly<object>, label: string, limitBytes?: number): Effect.Effect<void, WorkflowValueTooLargeError>;
40
40
  export declare function resolveGraphConcurrency(value?: number): number;
41
41
  export declare function workflowEdges<TInput>(definition: WorkflowDefinition<string, TInput>): WorkflowEdge[];
@@ -1,5 +1,5 @@
1
1
  import { Data, Effect } from 'effect';
2
- import { deterministicThreadId, isJsonString, utf8JsonBytes } from '@swirls/looms/core';
2
+ import { isJsonString, typeIds, utf8JsonBytes } from '@swirls/looms/core';
3
3
  export const MIN_GRAPH_CONCURRENCY = 1;
4
4
  export const MAX_GRAPH_CONCURRENCY = 64;
5
5
  export const DEFAULT_GRAPH_CONCURRENCY = 8;
@@ -24,11 +24,11 @@ export class WorkflowValueTooLargeError extends Data.TaggedError('WorkflowValueT
24
24
  export function nodeRunKey(nodeId, attempt, iteration) {
25
25
  return iteration === undefined ? `${nodeId}_${attempt}` : `${nodeId}_${attempt}_${iteration}`;
26
26
  }
27
- export function iterationChildWorkflowId(parentThreadId, nodeId, kind, attempt, index) {
28
- return deterministicThreadId(parentThreadId, nodeId, kind, attempt, index);
27
+ export function iterationChildWorkflowId(parentThreadId, nodeId, kind, attempt, index, ids = typeIds) {
28
+ return ids.derive('thread', [parentThreadId, nodeId, kind, attempt, index]);
29
29
  }
30
- export function nodeChildWorkflowId(parentThreadId, nodeId, attempt) {
31
- return deterministicThreadId(parentThreadId, nodeId, 'workflow', attempt);
30
+ export function nodeChildWorkflowId(parentThreadId, nodeId, attempt, ids = typeIds) {
31
+ return ids.derive('thread', [parentThreadId, nodeId, 'workflow', attempt]);
32
32
  }
33
33
  export function assertJsonWithinLimit(value, label, limitBytes = DEFAULT_VALUE_SIZE_LIMIT_BYTES) {
34
34
  const actualBytes = utf8JsonBytes(value);
@@ -1089,7 +1089,10 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
1089
1089
  readonly idempotencyKey?: string | null | undefined;
1090
1090
  };
1091
1091
  }[];
1092
- readonly pendingCancels: string[];
1092
+ readonly pendingCancels: {
1093
+ readonly target: string;
1094
+ readonly execution: "run" | "thread";
1095
+ }[];
1093
1096
  readonly status: "completed" | "failed" | "running";
1094
1097
  readonly error: string | null;
1095
1098
  }>;
@@ -2078,7 +2081,10 @@ export declare function workflow(options?: WorkflowModuleOptions): import("@swir
2078
2081
  readonly idempotencyKey?: string | null | undefined;
2079
2082
  };
2080
2083
  }[];
2081
- readonly pendingCancels: string[];
2084
+ readonly pendingCancels: {
2085
+ readonly target: string;
2086
+ readonly execution: "run" | "thread";
2087
+ }[];
2082
2088
  readonly status: "completed" | "failed" | "running";
2083
2089
  readonly error: string | null;
2084
2090
  }>;
@@ -29,6 +29,12 @@ export declare const WorkflowPendingMapSchema: Schema.Struct<{
29
29
  readonly close: Schema.withDecodingDefaultKey<Schema.Union<readonly [Schema.Literal<"terminate">, Schema.Literal<"wait">]>, never>;
30
30
  }>;
31
31
  export type WorkflowPendingMap = Schema.Schema.Type<typeof WorkflowPendingMapSchema>;
32
+ /** A child to cancel: a thread of this run, or a run of its own. */
33
+ export declare const WorkflowPendingCancelSchema: Schema.Struct<{
34
+ readonly target: Schema.String;
35
+ readonly execution: Schema.Union<readonly [Schema.Literal<"thread">, Schema.Literal<"run">]>;
36
+ }>;
37
+ export type WorkflowPendingCancel = Schema.Schema.Type<typeof WorkflowPendingCancelSchema>;
32
38
  export declare const WorkflowPendingSleepSchema: Schema.Struct<{
33
39
  readonly waitId: Schema.String;
34
40
  readonly wakeAt: Schema.Finite;
@@ -300,7 +306,10 @@ export declare const WorkflowStateSchema: Schema.Struct<{
300
306
  }>;
301
307
  }>>>;
302
308
  /** Children of stopped nodes that were still running; each is cancelled once. */
303
- readonly pendingCancels: Schema.withDecodingDefaultKey<Schema.mutable<Schema.$Array<Schema.String>>, never>;
309
+ readonly pendingCancels: Schema.withDecodingDefaultKey<Schema.mutable<Schema.$Array<Schema.Struct<{
310
+ readonly target: Schema.String;
311
+ readonly execution: Schema.Union<readonly [Schema.Literal<"thread">, Schema.Literal<"run">]>;
312
+ }>>>, never>;
304
313
  readonly status: Schema.Union<readonly [Schema.Literal<"running">, Schema.Literal<"completed">, Schema.Literal<"failed">]>;
305
314
  readonly error: Schema.NullOr<Schema.String>;
306
315
  }>;
@@ -465,7 +474,10 @@ export declare const workflowThread: import("@swirls/looms/core").ThreadDefiniti
465
474
  readonly idempotencyKey?: string | null | undefined;
466
475
  };
467
476
  }[];
468
- readonly pendingCancels: string[];
477
+ readonly pendingCancels: {
478
+ readonly target: string;
479
+ readonly execution: "run" | "thread";
480
+ }[];
469
481
  readonly status: "completed" | "failed" | "running";
470
482
  readonly error: string | null;
471
483
  }>;