@swirls/looms 0.24.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 (116) hide show
  1. package/CHANGELOG.md +34 -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/agent/threads.js +4 -1
  14. package/dist/approval/effects.d.ts +26 -26
  15. package/dist/approval/module.d.ts +52 -52
  16. package/dist/approval/steps.d.ts +3 -1
  17. package/dist/approval/steps.js +2 -2
  18. package/dist/client/client.d.ts +7 -1
  19. package/dist/client/client.js +5 -2
  20. package/dist/cloudflare/durable-object.d.ts +3 -1
  21. package/dist/cloudflare/durable-object.js +1 -0
  22. package/dist/cloudflare/queue-consumer.d.ts +3 -1
  23. package/dist/cloudflare/queue-consumer.js +2 -1
  24. package/dist/cloudflare/router.d.ts +3 -1
  25. package/dist/cloudflare/router.js +1 -1
  26. package/dist/core/compose.d.ts +8 -2
  27. package/dist/core/compose.js +6 -3
  28. package/dist/core/effects.d.ts +3 -0
  29. package/dist/core/envelope.d.ts +2 -0
  30. package/dist/core/envelope.js +2 -2
  31. package/dist/core/event-codec.d.ts +4 -3
  32. package/dist/core/event-codec.js +7 -7
  33. package/dist/core/fold.d.ts +3 -0
  34. package/dist/core/fold.js +3 -1
  35. package/dist/core/fork.js +1 -1
  36. package/dist/core/ids.d.ts +70 -5
  37. package/dist/core/ids.js +164 -41
  38. package/dist/core/snapshots.d.ts +2 -0
  39. package/dist/core/snapshots.js +2 -1
  40. package/dist/core/thread.d.ts +8 -0
  41. package/dist/debugger/app/assets/index-D_FKxPrN.js +23 -0
  42. package/dist/debugger/app/assets/routes-CkwzFejg.js +47 -0
  43. package/dist/debugger/app/index.html +1 -1
  44. package/dist/debugger/context.d.ts +4 -1
  45. package/dist/debugger/context.js +4 -4
  46. package/dist/debugger/shell/debugger-shell.d.ts +4 -1
  47. package/dist/debugger/shell/debugger-shell.js +2 -2
  48. package/dist/debugger/shell/use-start-run.d.ts +1 -1
  49. package/dist/debugger/shell/use-start-run.js +1 -2
  50. package/dist/evaluator/steps.d.ts +2 -2
  51. package/dist/evaluator/steps.js +3 -3
  52. package/dist/react/react.d.ts +8 -3
  53. package/dist/react/react.js +15 -2
  54. package/dist/react/store.d.ts +5 -1
  55. package/dist/react/store.js +5 -4
  56. package/dist/runtime/cancellation.js +5 -5
  57. package/dist/runtime/deadline-transition-planner.d.ts +1 -0
  58. package/dist/runtime/deadline-transition-planner.js +8 -7
  59. package/dist/runtime/effect-admission.js +1 -0
  60. package/dist/runtime/helpers.d.ts +6 -5
  61. package/dist/runtime/helpers.js +8 -8
  62. package/dist/runtime/local-effect-executor.js +15 -10
  63. package/dist/runtime/looms.d.ts +6 -1
  64. package/dist/runtime/looms.js +4 -1
  65. package/dist/runtime/retry-policy.d.ts +2 -1
  66. package/dist/runtime/retry-policy.js +2 -1
  67. package/dist/runtime/runtime.js +10 -10
  68. package/dist/runtime/server/routes/runs.js +5 -5
  69. package/dist/runtime/types.d.ts +7 -1
  70. package/dist/runtime/wake-engine.js +10 -9
  71. package/dist/runtime/worker-callbacks.js +9 -8
  72. package/dist/runtime/worker-effect-dispatch.d.ts +3 -2
  73. package/dist/runtime/worker-effect-dispatch.js +7 -5
  74. package/dist/swarm/board.d.ts +292 -0
  75. package/dist/swarm/board.js +123 -0
  76. package/dist/swarm/conformance.d.ts +15 -0
  77. package/dist/swarm/conformance.js +225 -0
  78. package/dist/swarm/definitions.d.ts +94 -0
  79. package/dist/swarm/definitions.js +51 -0
  80. package/dist/swarm/effects.d.ts +4720 -0
  81. package/dist/swarm/effects.js +296 -0
  82. package/dist/swarm/ensure.d.ts +16 -0
  83. package/dist/swarm/ensure.js +24 -0
  84. package/dist/swarm/events.d.ts +240 -0
  85. package/dist/swarm/events.js +49 -0
  86. package/dist/swarm/index.d.ts +15 -0
  87. package/dist/swarm/index.js +15 -0
  88. package/dist/swarm/memory-board.d.ts +10 -0
  89. package/dist/swarm/memory-board.js +344 -0
  90. package/dist/swarm/module.d.ts +9593 -0
  91. package/dist/swarm/module.js +94 -0
  92. package/dist/swarm/projections.d.ts +60 -0
  93. package/dist/swarm/projections.js +102 -0
  94. package/dist/swarm/prompt.d.ts +4 -0
  95. package/dist/swarm/prompt.js +35 -0
  96. package/dist/swarm/scope.d.ts +357 -0
  97. package/dist/swarm/scope.js +8 -0
  98. package/dist/swarm/services.d.ts +29 -0
  99. package/dist/swarm/services.js +40 -0
  100. package/dist/swarm/signals.d.ts +14 -0
  101. package/dist/swarm/signals.js +15 -0
  102. package/dist/swarm/steps.d.ts +15 -0
  103. package/dist/swarm/steps.js +27 -0
  104. package/dist/swarm/threads.d.ts +41 -0
  105. package/dist/swarm/threads.js +244 -0
  106. package/dist/swarm/tools.d.ts +20 -0
  107. package/dist/swarm/tools.js +100 -0
  108. package/dist/workflow/effects.js +6 -5
  109. package/dist/workflow/graph.d.ts +3 -3
  110. package/dist/workflow/graph.js +5 -5
  111. package/dist/workflow/module.d.ts +8 -2
  112. package/dist/workflow/threads.d.ts +14 -2
  113. package/dist/workflow/threads.js +54 -44
  114. package/package.json +7 -2
  115. package/dist/debugger/app/assets/index-CxbIGkpY.js +0 -22
  116. package/dist/debugger/app/assets/routes-Ch30UGik.js +0 -47
@@ -444,7 +444,10 @@ export const agentThread = agentModule.thread({
444
444
  effects.push(wait({
445
445
  waitId: createWaitId(ctx.threadId, `effects_${effectReq.toolCallId}`),
446
446
  on: { type: effectReq.waitOn.type, match: effectReq.waitOn.match },
447
- tag: { toolCallId: effectReq.toolCallId },
447
+ tag: {
448
+ toolCallId: effectReq.toolCallId,
449
+ name: state.pendingEffectTools[effectReq.toolCallId]?.name ?? 'tool',
450
+ },
448
451
  }));
449
452
  }
450
453
  }
@@ -9,6 +9,32 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
9
9
  }[];
10
10
  readonly schema?: import("effect/Schema").Json | undefined;
11
11
  }, never, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
12
+ readonly type: "approval.decided";
13
+ readonly payload: {
14
+ readonly approvalId: string;
15
+ readonly actionId: string;
16
+ readonly outcome: "approve" | "reject";
17
+ readonly payload?: import("effect/Schema").Json | undefined;
18
+ };
19
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
20
+ readonly type: "approval.requested";
21
+ readonly payload: {
22
+ readonly approvalId: string;
23
+ readonly title: string;
24
+ readonly description?: string | undefined;
25
+ readonly actions: readonly {
26
+ readonly id: string;
27
+ readonly label: string;
28
+ readonly outcome: "approve" | "reject";
29
+ }[];
30
+ readonly schema?: import("effect/Schema").Json | undefined;
31
+ };
32
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
33
+ readonly type: "approval.timed_out";
34
+ readonly payload: {
35
+ readonly approvalId: string;
36
+ };
37
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
12
38
  readonly type: "runtime.child.close.requested";
13
39
  readonly payload: {
14
40
  readonly policy: "terminate" | "wait";
@@ -254,30 +280,4 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
254
280
  readonly payload: import("effect/Schema").Json;
255
281
  };
256
282
  };
257
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
258
- readonly type: "approval.decided";
259
- readonly payload: {
260
- readonly approvalId: string;
261
- readonly actionId: string;
262
- readonly outcome: "approve" | "reject";
263
- readonly payload?: import("effect/Schema").Json | undefined;
264
- };
265
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
266
- readonly type: "approval.requested";
267
- readonly payload: {
268
- readonly approvalId: string;
269
- readonly title: string;
270
- readonly description?: string | undefined;
271
- readonly actions: readonly {
272
- readonly id: string;
273
- readonly label: string;
274
- readonly outcome: "approve" | "reject";
275
- }[];
276
- readonly schema?: import("effect/Schema").Json | undefined;
277
- };
278
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
279
- readonly type: "approval.timed_out";
280
- readonly payload: {
281
- readonly approvalId: string;
282
- };
283
283
  })>>;
@@ -32,6 +32,32 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
32
32
  }[];
33
33
  readonly schema?: import("effect/Schema").Json | undefined;
34
34
  }, never, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
35
+ readonly type: "approval.decided";
36
+ readonly payload: {
37
+ readonly approvalId: string;
38
+ readonly actionId: string;
39
+ readonly outcome: "approve" | "reject";
40
+ readonly payload?: import("effect/Schema").Json | undefined;
41
+ };
42
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
43
+ readonly type: "approval.requested";
44
+ readonly payload: {
45
+ readonly approvalId: string;
46
+ readonly title: string;
47
+ readonly description?: string | undefined;
48
+ readonly actions: readonly {
49
+ readonly id: string;
50
+ readonly label: string;
51
+ readonly outcome: "approve" | "reject";
52
+ }[];
53
+ readonly schema?: import("effect/Schema").Json | undefined;
54
+ };
55
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
56
+ readonly type: "approval.timed_out";
57
+ readonly payload: {
58
+ readonly approvalId: string;
59
+ };
60
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
35
61
  readonly type: "runtime.child.close.requested";
36
62
  readonly payload: {
37
63
  readonly policy: "terminate" | "wait";
@@ -277,32 +303,6 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
277
303
  readonly payload: import("effect/Schema").Json;
278
304
  };
279
305
  };
280
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
281
- readonly type: "approval.decided";
282
- readonly payload: {
283
- readonly approvalId: string;
284
- readonly actionId: string;
285
- readonly outcome: "approve" | "reject";
286
- readonly payload?: import("effect/Schema").Json | undefined;
287
- };
288
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
289
- readonly type: "approval.requested";
290
- readonly payload: {
291
- readonly approvalId: string;
292
- readonly title: string;
293
- readonly description?: string | undefined;
294
- readonly actions: readonly {
295
- readonly id: string;
296
- readonly label: string;
297
- readonly outcome: "approve" | "reject";
298
- }[];
299
- readonly schema?: import("effect/Schema").Json | undefined;
300
- };
301
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
302
- readonly type: "approval.timed_out";
303
- readonly payload: {
304
- readonly approvalId: string;
305
- };
306
306
  })>;
307
307
  }, {}, {
308
308
  pendingApprovals: import("@swirls/looms/core").ProjectionDefinition<{
@@ -346,6 +346,32 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
346
346
  }[];
347
347
  readonly schema?: import("effect/Schema").Json | undefined;
348
348
  }, never, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
349
+ readonly type: "approval.decided";
350
+ readonly payload: {
351
+ readonly approvalId: string;
352
+ readonly actionId: string;
353
+ readonly outcome: "approve" | "reject";
354
+ readonly payload?: import("effect/Schema").Json | undefined;
355
+ };
356
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
357
+ readonly type: "approval.requested";
358
+ readonly payload: {
359
+ readonly approvalId: string;
360
+ readonly title: string;
361
+ readonly description?: string | undefined;
362
+ readonly actions: readonly {
363
+ readonly id: string;
364
+ readonly label: string;
365
+ readonly outcome: "approve" | "reject";
366
+ }[];
367
+ readonly schema?: import("effect/Schema").Json | undefined;
368
+ };
369
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
370
+ readonly type: "approval.timed_out";
371
+ readonly payload: {
372
+ readonly approvalId: string;
373
+ };
374
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
349
375
  readonly type: "runtime.child.close.requested";
350
376
  readonly payload: {
351
377
  readonly policy: "terminate" | "wait";
@@ -591,32 +617,6 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
591
617
  readonly payload: import("effect/Schema").Json;
592
618
  };
593
619
  };
594
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
595
- readonly type: "approval.decided";
596
- readonly payload: {
597
- readonly approvalId: string;
598
- readonly actionId: string;
599
- readonly outcome: "approve" | "reject";
600
- readonly payload?: import("effect/Schema").Json | undefined;
601
- };
602
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
603
- readonly type: "approval.requested";
604
- readonly payload: {
605
- readonly approvalId: string;
606
- readonly title: string;
607
- readonly description?: string | undefined;
608
- readonly actions: readonly {
609
- readonly id: string;
610
- readonly label: string;
611
- readonly outcome: "approve" | "reject";
612
- }[];
613
- readonly schema?: import("effect/Schema").Json | undefined;
614
- };
615
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
616
- readonly type: "approval.timed_out";
617
- readonly payload: {
618
- readonly approvalId: string;
619
- };
620
620
  })>;
621
621
  };
622
622
  readonly threads: {};
@@ -1,4 +1,4 @@
1
- import { type JsonValue, type RuntimeEffect } from '@swirls/looms/core';
1
+ import { type JsonValue, type LoomsIds, type RuntimeEffect } from '@swirls/looms/core';
2
2
  import type { ApprovalAction } from './events';
3
3
  export declare function gate(args: {
4
4
  title: string;
@@ -8,4 +8,6 @@ export declare function gate(args: {
8
8
  schema?: JsonValue;
9
9
  /** Absolute epoch milliseconds. Decision and timer waits race; the first wins. */
10
10
  timeoutAt?: number;
11
+ /** The id format to draw `approvalId` from. Pass `ctx.ids`. Defaults to `typeIds`. */
12
+ ids?: LoomsIds;
11
13
  }): RuntimeEffect[];
@@ -1,7 +1,7 @@
1
- import { createWaitId, invoke, wait } from '@swirls/looms/core';
1
+ import { createWaitId, invoke, typeIds, wait, } from '@swirls/looms/core';
2
2
  import { requestApprovalEffect } from './effects.js';
3
3
  export function gate(args) {
4
- const approvalId = args.approvalId ?? createWaitId('approval');
4
+ const approvalId = args.approvalId ?? (args.ids ?? typeIds).create('wait');
5
5
  const actions = args.actions ?? [
6
6
  { id: 'approve', label: 'Approve', outcome: 'approve' },
7
7
  { id: 'reject', label: 'Reject', outcome: 'reject' },
@@ -1,5 +1,5 @@
1
1
  import { Schema } from 'effect';
2
- import { type DefinitionInput, type DefinitionRef, type EventEnvelope, type EventInput, type HasRequiredAttributes, type JsonValue, type RunAttributeFields, type RunAttributesOption, type RunState, type SecretContext, type SubscriptionTransport, type TraceContext, type WorkerCallback, type WorkerCallbackInput, type WorkerCallbackResult, type WorkerSecretsResult } from '@swirls/looms/core';
2
+ import { type LoomsIds, type DefinitionInput, type DefinitionRef, type EventEnvelope, type EventInput, type HasRequiredAttributes, type JsonValue, type RunAttributeFields, type RunAttributesOption, type RunState, type SecretContext, type SubscriptionTransport, type TraceContext, type WorkerCallback, type WorkerCallbackInput, type WorkerCallbackResult, type WorkerSecretsResult } from '@swirls/looms/core';
3
3
  export interface LoomsClientOptions<Fields extends RunAttributeFields = RunAttributeFields> {
4
4
  baseUrl?: string;
5
5
  fetch?: typeof fetch;
@@ -11,6 +11,10 @@ export interface LoomsClientOptions<Fields extends RunAttributeFields = RunAttri
11
11
  grant?: string;
12
12
  /** Declared run attributes, from `defineRunAttributes`. Types `attributes` on starts. */
13
13
  attributes?: Fields;
14
+ /**
15
+ * The id format for the run id of a `stream` started without one. Match the host's `ids`. Defaults to `typeIds` (TypeID).
16
+ */
17
+ ids?: LoomsIds;
14
18
  }
15
19
  type ClientStartArgs<Fields extends RunAttributeFields> = {
16
20
  kind: string;
@@ -32,6 +36,8 @@ export interface StreamHandle extends AsyncIterable<EventEnvelope> {
32
36
  readonly runId: string;
33
37
  }
34
38
  export declare function createLoomsClient<const Fields extends RunAttributeFields = RunAttributeFields>(options?: LoomsClientOptions<Fields>): {
39
+ /** The id format this client draws from. */
40
+ ids: LoomsIds;
35
41
  /**
36
42
  * Start a run by `{ kind, definitionName }` when you only have names. Answers after the first
37
43
  * wake, so a short run can come back finished.
@@ -1,5 +1,5 @@
1
1
  import { Data, Effect, Option, Predicate, Schema, Stream } from 'effect';
2
- import { createRunId, DefinitionCatalogSchema, EffectCatalogSchema, EventEnvelopeSchema, cleanUndefined, EventTypeCatalogSchema, JsonValueSchema, readSubscriptionData, ReplayStepSchema, RunStateSchema, RunSummariesSchema, SecretContextSchema, SignalCatalogSchema, stringifyJson, traceHeaders, } from '@swirls/looms/core';
2
+ import { resolveIds, DefinitionCatalogSchema, EffectCatalogSchema, EventEnvelopeSchema, cleanUndefined, EventTypeCatalogSchema, JsonValueSchema, readSubscriptionData, ReplayStepSchema, RunStateSchema, RunSummariesSchema, SecretContextSchema, SignalCatalogSchema, stringifyJson, traceHeaders, } from '@swirls/looms/core';
3
3
  import { consumeSseStreamEffect, eventsFromSseData, sseFrames } from './sse.js';
4
4
  class LoomsClientError extends Data.TaggedError('LoomsClientError') {
5
5
  constructor(message, cause) {
@@ -91,6 +91,7 @@ const PreviewEventsResultSchema = Schema.Struct({
91
91
  export function createLoomsClient(options = {}) {
92
92
  const baseUrl = (options.baseUrl ?? '').replace(/\/$/, '');
93
93
  const fetchImpl = options.fetch ?? fetch;
94
+ const ids = resolveIds(options.ids);
94
95
  function request(path, schema, init) {
95
96
  const headers = new Headers(init?.headers);
96
97
  if (!headers.has('content-type')) {
@@ -211,7 +212,7 @@ export function createLoomsClient(options = {}) {
211
212
  });
212
213
  const streamRun = (args) => {
213
214
  const { trace, ...body } = args;
214
- const runId = body.runId ?? createRunId();
215
+ const runId = body.runId ?? ids.create('run');
215
216
  const stream = Stream.unwrap(Effect.tryPromise({
216
217
  try: (signal) => fetchImpl(`${baseUrl}/runs`, {
217
218
  method: 'POST',
@@ -236,6 +237,8 @@ export function createLoomsClient(options = {}) {
236
237
  return Object.assign(Stream.toAsyncIterable(stream), { runId });
237
238
  };
238
239
  return {
240
+ /** The id format this client draws from. */
241
+ ids,
239
242
  /**
240
243
  * Start a run by `{ kind, definitionName }` when you only have names. Answers after the first
241
244
  * wake, so a short run can come back finished.
@@ -1,5 +1,5 @@
1
1
  import { DurableObject } from 'cloudflare:workers';
2
- import { type AnyRuntimeModule, type DefinitionResolver, type EventInput, type BlobStore, type EventStoreTrimCoverage, type LaunchRunArgs, type RunAttributeFields, type RunLauncher, type RunState, type RunStatusSnapshot } from '@swirls/looms/core';
2
+ import { type AnyRuntimeModule, type DefinitionResolver, type EventInput, type BlobStore, type EventStoreTrimCoverage, type LaunchRunArgs, type RunAttributeFields, type RunLauncher, type RunState, type RunStatusSnapshot, type LoomsIds } from '@swirls/looms/core';
3
3
  import type { Projector } from '@swirls/looms/projectors';
4
4
  import { type Authorize, type EffectWorker, type RunSignalOptions, type StartResult, type StartRunArgs, type RuntimeObserver, type SecretProvider, type SecretSealer } from '@swirls/looms/runtime';
5
5
  import { type DeleteTerminalRunStorageOptions } from './delete-terminal-run-storage';
@@ -7,6 +7,8 @@ export interface LoomsDurableObjectConfig {
7
7
  readonly modules: readonly AnyRuntimeModule[];
8
8
  /** Loads definitions that were not registered on a module. See `CreateRuntimeOptions`. */
9
9
  readonly definitionResolver?: DefinitionResolver;
10
+ /** The id format. See `CreateRuntimeOptions.ids`. */
11
+ readonly ids?: LoomsIds;
10
12
  /** Declared run attributes. Pass the same declaration to the replica. */
11
13
  readonly attributes?: RunAttributeFields;
12
14
  /** Told about wakes, appends, snapshots and effect attempts. See `CreateRuntimeOptions`. */
@@ -53,6 +53,7 @@ export class LoomsDurableObject extends DurableObject {
53
53
  scheduler: alarms.scheduler,
54
54
  modules: config.modules,
55
55
  definitionResolver: config.definitionResolver,
56
+ ids: config.ids,
56
57
  attributes: config.attributes,
57
58
  observer: config.observer,
58
59
  secretProvider: config.secretProvider,
@@ -1,5 +1,5 @@
1
1
  import { Effect } from 'effect';
2
- import { type BlobStore, type EventInput, type JsonValue, type WorkerCallback, type WorkerCallbackInput, type WorkerCallbackResult, type WorkerEffectContext, type WorkerEffectDefinition, type WorkerSecretsResult } from '@swirls/looms/core';
2
+ import { type BlobStore, type EventInput, type JsonValue, type WorkerCallback, type WorkerCallbackInput, type WorkerCallbackResult, type WorkerEffectContext, type WorkerEffectDefinition, type WorkerSecretsResult, type LoomsIds } from '@swirls/looms/core';
3
3
  import { type QueueEffectMessage, type QueueMessageLike } from './queue-message';
4
4
  /** The worker half of the Looms HTTP API. `createLoomsClient({ baseUrl, workerCallbackToken })` is one. */
5
5
  export interface WorkerCallbackClient {
@@ -43,6 +43,8 @@ export interface QueueConsumerOptions {
43
43
  readonly callbacks: WorkerCallbackClient;
44
44
  /** Reads inputs the producer offloaded. Use the store the producer writes to. */
45
45
  readonly blobs?: BlobStore;
46
+ /** The id format handlers see as `ctx.ids`. Match the host's `ids`. Defaults to `typeIds`. */
47
+ readonly ids?: LoomsIds;
46
48
  }
47
49
  export interface QueueBatchLike {
48
50
  readonly messages: ReadonlyArray<QueueMessageLike>;
@@ -1,5 +1,5 @@
1
1
  import { Data, Effect } from 'effect';
2
- import { resolveJson, validateInput, } from '@swirls/looms/core';
2
+ import { resolveJson, validateInput, resolveIds, } from '@swirls/looms/core';
3
3
  import { readQueueEffectMessage, } from './queue-message.js';
4
4
  /**
5
5
  * Build a `handlers` map from **worker-placed** effect definitions. Input is validated with each
@@ -93,6 +93,7 @@ function runAttempt(task, attempt, handler, cancelRequested, options) {
93
93
  attributes: task.attributes ?? {},
94
94
  secrets,
95
95
  trace: task.trace ?? null,
96
+ ids: resolveIds(options.ids),
96
97
  heartbeat: (details) => Effect.runPromise(callback(() => options.callbacks.workerCallback(task.runId, details === undefined
97
98
  ? { ...attempt, kind: 'heartbeat' }
98
99
  : { ...attempt, kind: 'heartbeat', details })).pipe(Effect.map((result) => {
@@ -1,4 +1,4 @@
1
- import type { AnyRuntimeModule } from '@swirls/looms/core';
1
+ import type { AnyRuntimeModule, LoomsIds } from '@swirls/looms/core';
2
2
  import { type AuthDecision, type RouteInfo } from '@swirls/looms/runtime';
3
3
  export interface DurableObjectStubLike {
4
4
  fetch(request: Request): Promise<Response>;
@@ -26,4 +26,6 @@ export type RouteAuthorize = (request: Request, route: RouteInfo) => AuthDecisio
26
26
  export declare function routeToDurableObject(namespace: DurableObjectNamespaceLike, req: Request, options?: {
27
27
  readonly modules?: readonly AnyRuntimeModule[] | (() => readonly AnyRuntimeModule[]);
28
28
  readonly authorize?: RouteAuthorize;
29
+ /** The id format for a run started without a `runId`. Match the Durable Object's `ids`. */
30
+ readonly ids?: LoomsIds;
29
31
  }): Promise<Response | null>;
@@ -49,7 +49,7 @@ function forward(namespace, req, options) {
49
49
  if (unsupported) {
50
50
  return Promise.resolve(unsupported);
51
51
  }
52
- return resolveRunTarget(req)
52
+ return resolveRunTarget(req, { ids: options?.ids })
53
53
  .then(({ runId, request }) => namespace.getByName(runId).fetch(request))
54
54
  .catch((error) => {
55
55
  if (error instanceof RunTargetError) {
@@ -3,6 +3,7 @@ import type { CatalogEvent, EventCatalog } from './catalog';
3
3
  import type { EffectDefinition } from './effects';
4
4
  import type { EventEnvelope } from './envelope';
5
5
  import type { FoldRegistry } from './fold';
6
+ import { type LoomsIds } from './ids';
6
7
  import type { AnyRuntimeModule, EffectAdmission, EffectMiddleware, RuntimeModule, RegisteredDefinition, SignalInterruptRule } from './module';
7
8
  import type { ProjectionDefinition } from './projection';
8
9
  import { protocolCatalog } from './protocol';
@@ -24,9 +25,14 @@ export interface ComposedRegistry extends FoldRegistry {
24
25
  readonly middleware: readonly EffectMiddleware[];
25
26
  readonly admission: readonly EffectAdmission[];
26
27
  readonly interruptRules: readonly SignalInterruptRule[];
28
+ readonly ids: LoomsIds;
27
29
  }
28
- export declare function composeModules(modules: readonly AnyRuntimeModule[]): ComposedRegistry;
29
- export declare function composeModulesEffect(modules: readonly AnyRuntimeModule[]): Effect.Effect<ComposedRegistry, ModuleCompositionError>;
30
+ export interface ComposeModulesOptions {
31
+ /** The id format for everything this registry names. Defaults to `typeIds`. */
32
+ readonly ids?: LoomsIds;
33
+ }
34
+ export declare function composeModules(modules: readonly AnyRuntimeModule[], options?: ComposeModulesOptions): ComposedRegistry;
35
+ export declare function composeModulesEffect(modules: readonly AnyRuntimeModule[], options?: ComposeModulesOptions): Effect.Effect<ComposedRegistry, ModuleCompositionError>;
30
36
  export type ProtocolEvents = CatalogEvent<'runtime', typeof protocolCatalog.entries>;
31
37
  export type ModuleEvents<T> = T extends {
32
38
  readonly events?: infer C;
@@ -1,4 +1,5 @@
1
1
  import { Data, Effect } from 'effect';
2
+ import { resolveIds } from './ids.js';
2
3
  import { DEFAULT_DEFINITION_VERSION, definitionKey } from './module.js';
3
4
  import { protocolCatalog } from './protocol.js';
4
5
  export class ModuleCompositionError extends Data.TaggedError('ModuleCompositionError') {
@@ -7,7 +8,8 @@ export class ModuleCompositionError extends Data.TaggedError('ModuleCompositionE
7
8
  this.name = 'ModuleCompositionError';
8
9
  }
9
10
  }
10
- export function composeModules(modules) {
11
+ export function composeModules(modules, options) {
12
+ const ids = resolveIds(options?.ids);
11
13
  const definitions = [];
12
14
  const definitionKeys = new Set();
13
15
  const namespaces = new Set();
@@ -107,11 +109,12 @@ export function composeModules(modules) {
107
109
  middleware,
108
110
  admission,
109
111
  interruptRules,
112
+ ids,
110
113
  };
111
114
  }
112
- export function composeModulesEffect(modules) {
115
+ export function composeModulesEffect(modules, options) {
113
116
  return Effect.try({
114
- try: () => composeModules(modules),
117
+ try: () => composeModules(modules, options),
115
118
  catch: (cause) => cause instanceof ModuleCompositionError
116
119
  ? cause
117
120
  : new ModuleCompositionError(cause instanceof Error ? cause.message : String(cause)),
@@ -1,5 +1,6 @@
1
1
  import { Effect, Schema, type Context } from 'effect';
2
2
  import { type EventInput } from './envelope';
3
+ import type { LoomsIds } from './ids';
3
4
  import type { RunAttributes, SecretContext } from './run-context';
4
5
  import { type InferDefinedSchema, type InvalidInputError, type SchemaInput } from './schema';
5
6
  import type { TraceContext } from './trace';
@@ -183,6 +184,8 @@ export interface EffectContextBase {
183
184
  readonly secrets: SecretContext;
184
185
  /** The W3C trace context of the caller that started the run, to parent spans the handler starts. */
185
186
  readonly trace: TraceContext | null;
187
+ /** The id format the host was configured with. */
188
+ readonly ids: LoomsIds;
186
189
  }
187
190
  /**
188
191
  * Context for an effect that runs in the host actor cell (for example a Durable Object).
@@ -1,4 +1,5 @@
1
1
  import { Schema } from 'effect';
2
+ import { type LoomsIds } from './ids';
2
3
  import { type JsonValue } from './types';
3
4
  export declare const JsonValueSchema: Schema.Codec<Schema.Json, Schema.Json, never, never>;
4
5
  export declare const EventOriginSchema: Schema.Union<readonly [Schema.Struct<{
@@ -104,5 +105,6 @@ export declare function payloadAsJson(payload: JsonValue): JsonValue;
104
105
  export declare function withAssignedSeq(partial: AppendableEvent, runId: string, seq: number): EventEnvelope;
105
106
  export declare function createEvent<TType extends string, TPayload = JsonValue>(runId: string, input: EventInput<TType, TPayload>, options?: {
106
107
  seq?: number;
108
+ ids?: LoomsIds;
107
109
  }): EventEnvelope<TType, TPayload>;
108
110
  export declare function fromWireEvent(wire: Schema.Schema.Type<typeof EventEnvelopeSchema>): EventEnvelope;
@@ -1,5 +1,5 @@
1
1
  import { DateTime, Schema } from 'effect';
2
- import { createEventId } from './ids.js';
2
+ import { typeIds } from './ids.js';
3
3
  import { cleanUndefined } from './types.js';
4
4
  export const JsonValueSchema = Schema.Json;
5
5
  export const EventOriginSchema = Schema.Union([
@@ -59,7 +59,7 @@ export function createEvent(runId, input, options) {
59
59
  const threadId = input.threadId ?? null;
60
60
  const parentThreadId = input.parentThreadId ?? null;
61
61
  return {
62
- id: input.id ?? createEventId(),
62
+ id: input.id ?? (options?.ids ?? typeIds).create('event'),
63
63
  runId,
64
64
  seq: options?.seq ?? 0,
65
65
  ts: input.ts ?? DateTime.toEpochMillis(DateTime.nowUnsafe()),
@@ -1,10 +1,11 @@
1
1
  import type { AppendableEvent, EventEnvelope } from './envelope';
2
+ import { type LoomsIds } from './ids';
2
3
  import type { JsonValue } from './types';
3
4
  /** JSON-safe event envelope for SSE and pull responses. */
4
5
  export type EncodedLoomsEvent = EventEnvelope;
5
6
  type EventWireInput = JsonValue | Partial<EncodedLoomsEvent>;
6
7
  export declare function encodeLoomsEvent(event: EventEnvelope): EncodedLoomsEvent;
7
- export declare function encodeAppendableEvent(event: AppendableEvent): EncodedLoomsEvent;
8
- export declare function decodeLoomsEvent(raw: EventWireInput, runId: string): EventEnvelope;
9
- export declare function decodeAppendableEvent(raw: EventWireInput, runId: string): AppendableEvent | undefined;
8
+ export declare function encodeAppendableEvent(event: AppendableEvent, ids?: LoomsIds): EncodedLoomsEvent;
9
+ export declare function decodeLoomsEvent(raw: EventWireInput, runId: string, ids?: LoomsIds): EventEnvelope;
10
+ export declare function decodeAppendableEvent(raw: EventWireInput, runId: string, ids?: LoomsIds): AppendableEvent | undefined;
10
11
  export {};
@@ -1,6 +1,6 @@
1
1
  import { DateTime, Predicate, Schema } from 'effect';
2
2
  import { createEvent, payloadAsJson } from './envelope.js';
3
- import { createEventId } from './ids.js';
3
+ import { typeIds } from './ids.js';
4
4
  const decodeJsonValue = Schema.decodeUnknownSync(Schema.Json);
5
5
  export function encodeLoomsEvent(event) {
6
6
  return {
@@ -8,9 +8,9 @@ export function encodeLoomsEvent(event) {
8
8
  payload: payloadAsJson(event.payload),
9
9
  };
10
10
  }
11
- export function encodeAppendableEvent(event) {
11
+ export function encodeAppendableEvent(event, ids = typeIds) {
12
12
  return {
13
- id: event.id ?? createEventId(),
13
+ id: event.id ?? ids.create('event'),
14
14
  runId: event.runId,
15
15
  seq: event.seq ?? 0,
16
16
  ts: event.ts ?? DateTime.toEpochMillis(DateTime.nowUnsafe()),
@@ -42,14 +42,14 @@ function readOrigin(raw) {
42
42
  }
43
43
  return { type: 'system' };
44
44
  }
45
- export function decodeLoomsEvent(raw, runId) {
45
+ export function decodeLoomsEvent(raw, runId, ids = typeIds) {
46
46
  if (!Predicate.isReadonlyObject(raw)) {
47
47
  throw new Error('Invalid event payload: expected object');
48
48
  }
49
49
  if ('type' in raw && Predicate.isString(raw.type)) {
50
50
  const rawPayload = 'payload' in raw ? raw.payload : {};
51
51
  const payload = decodeJsonValue(rawPayload);
52
- const id = 'id' in raw && Predicate.isString(raw.id) ? raw.id : createEventId();
52
+ const id = 'id' in raw && Predicate.isString(raw.id) ? raw.id : ids.create('event');
53
53
  const ts = 'ts' in raw && Predicate.isNumber(raw.ts)
54
54
  ? raw.ts
55
55
  : DateTime.toEpochMillis(DateTime.nowUnsafe());
@@ -82,9 +82,9 @@ export function decodeLoomsEvent(raw, runId) {
82
82
  }
83
83
  throw new Error('Invalid event payload: missing type');
84
84
  }
85
- export function decodeAppendableEvent(raw, runId) {
85
+ export function decodeAppendableEvent(raw, runId, ids = typeIds) {
86
86
  try {
87
- const { seq: _seq, ...rest } = decodeLoomsEvent(raw, runId);
87
+ const { seq: _seq, ...rest } = decodeLoomsEvent(raw, runId, ids);
88
88
  return rest;
89
89
  }
90
90
  catch {
@@ -1,10 +1,13 @@
1
1
  import { Stream, type Effect } from 'effect';
2
2
  import { type RuntimeEffect } from './effects';
3
3
  import type { EventEnvelope } from './envelope';
4
+ import { type LoomsIds } from './ids';
4
5
  import type { RunState } from './state';
5
6
  import { type ThreadDefinition } from './thread';
6
7
  export interface FoldRegistry {
7
8
  readonly threads: ReadonlyMap<string, ThreadDefinition>;
9
+ /** The id format reducers see as `ctx.ids`. Defaults to `typeIds`. */
10
+ readonly ids?: LoomsIds;
8
11
  }
9
12
  /** The id an effect keeps across folds when it names itself by tag, wait id, or child thread. */
10
13
  export declare function stableEffectId(threadId: string, effect: RuntimeEffect): string | undefined;
package/dist/core/fold.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Option, Predicate, Schema, Stream } from 'effect';
2
2
  import { isWithdrawnError, WaitConditionSchema } from './effects.js';
3
- import { createEffectId } from './ids.js';
3
+ import { createEffectId, typeIds } from './ids.js';
4
4
  import { readRunLaunchSource } from './launcher.js';
5
5
  import { DEFAULT_DEFINITION_VERSION } from './module.js';
6
6
  import { readAttributes } from './run-context.js';
@@ -174,6 +174,7 @@ function applyProtocol(state, event, registry) {
174
174
  definitionName,
175
175
  definitionVersion,
176
176
  input,
177
+ ids: registry.ids ?? typeIds,
177
178
  })
178
179
  : {},
179
180
  };
@@ -585,6 +586,7 @@ function deliver(state, event, registry, settled) {
585
586
  runId: state.runId,
586
587
  threadId,
587
588
  parentThreadId: record.parentThreadId,
589
+ ids: registry.ids ?? typeIds,
588
590
  };
589
591
  const nextState = definition.step(record.state, event, ctx);
590
592
  const enabled = definition.effects(nextState, ctx);
package/dist/core/fork.js CHANGED
@@ -120,7 +120,7 @@ export function planFork(input) {
120
120
  payload: { sourceRunId, sourceSeq: cut },
121
121
  threadId: null,
122
122
  origin: { type: 'system' },
123
- }, { seq: cut + 1 });
123
+ }, { seq: cut + 1, ids: registry.ids });
124
124
  return Effect.succeed({
125
125
  events: [...prefix.map((event) => copyEvent(event, runId, reissued)), marker],
126
126
  sourceSeq: cut,