@swirls/looms 0.9.0 → 0.11.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 (118) hide show
  1. package/CHANGELOG.md +32 -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 +1 -0
  6. package/dist/actor/routing.js +2 -1
  7. package/dist/agent/debugger/agent-chat.js +6 -5
  8. package/dist/agent/debugger/index.js +2 -1
  9. package/dist/agent/module.d.ts +207 -1
  10. package/dist/agent/module.js +31 -0
  11. package/dist/agent/scope.js +1 -0
  12. package/dist/agent/signals.d.ts +108 -15
  13. package/dist/agent/signals.js +70 -47
  14. package/dist/approval/debugger/approvals-view.js +1 -1
  15. package/dist/approval/index.d.ts +1 -0
  16. package/dist/approval/index.js +1 -0
  17. package/dist/approval/module.d.ts +42 -1
  18. package/dist/approval/module.js +53 -0
  19. package/dist/approval/scope.js +1 -0
  20. package/dist/approval/signals.d.ts +19 -13
  21. package/dist/approval/signals.js +25 -45
  22. package/dist/approval/steps.d.ts +11 -0
  23. package/dist/approval/steps.js +39 -0
  24. package/dist/cli/commands.d.ts +1 -1
  25. package/dist/cli/commands.js +49 -14
  26. package/dist/client/client.d.ts +231 -21
  27. package/dist/client/client.js +20 -2
  28. package/dist/cloudflare/delete-terminal-run-storage.d.ts +39 -0
  29. package/dist/cloudflare/delete-terminal-run-storage.js +98 -0
  30. package/dist/cloudflare/durable-object.d.ts +11 -1
  31. package/dist/cloudflare/durable-object.js +23 -0
  32. package/dist/cloudflare/index.d.ts +1 -0
  33. package/dist/cloudflare/index.js +1 -0
  34. package/dist/core/index.d.ts +1 -0
  35. package/dist/core/index.js +1 -0
  36. package/dist/core/module-scope.d.ts +50 -5
  37. package/dist/core/module-scope.js +22 -2
  38. package/dist/core/module.d.ts +29 -2
  39. package/dist/core/projection.d.ts +1 -0
  40. package/dist/core/published.d.ts +59 -1
  41. package/dist/core/published.js +97 -1
  42. package/dist/core/run-context.d.ts +50 -0
  43. package/dist/core/run-context.js +21 -1
  44. package/dist/core/signals.d.ts +56 -0
  45. package/dist/core/signals.js +93 -0
  46. package/dist/core/validate-event.d.ts +12 -1
  47. package/dist/core/validate-event.js +34 -11
  48. package/dist/debugger/app/assets/index-CO5gIvV8.css +2 -0
  49. package/dist/debugger/app/assets/{index-CMRl_aWQ.js → index-VTotlHcm.js} +2 -2
  50. package/dist/debugger/app/assets/routes-CEdsN9DO.js +47 -0
  51. package/dist/debugger/app/index.html +2 -2
  52. package/dist/debugger/index.d.ts +1 -1
  53. package/dist/debugger/index.js +1 -1
  54. package/dist/debugger/lib/cn.d.ts +1 -1
  55. package/dist/debugger/lib/cn.js +12 -1
  56. package/dist/debugger/plugin.d.ts +11 -1
  57. package/dist/debugger/plugin.js +41 -0
  58. package/dist/debugger/shell/debugger-shell.js +1 -1
  59. package/dist/debugger/shell/form-fields.d.ts +17 -0
  60. package/dist/debugger/shell/form-fields.js +38 -0
  61. package/dist/debugger/shell/run-action.d.ts +6 -0
  62. package/dist/debugger/shell/run-action.js +15 -0
  63. package/dist/debugger/shell/run-controls.js +3 -55
  64. package/dist/debugger/shell/schema-form.d.ts +10 -1
  65. package/dist/debugger/shell/schema-form.js +108 -10
  66. package/dist/debugger/shell/signal-form.d.ts +18 -0
  67. package/dist/debugger/shell/signal-form.js +185 -0
  68. package/dist/debugger/shell/start-form.js +2 -32
  69. package/dist/debugger/shell/use-debounced-preview.d.ts +22 -0
  70. package/dist/debugger/shell/use-debounced-preview.js +68 -0
  71. package/dist/evaluator/index.d.ts +1 -1
  72. package/dist/evaluator/index.js +1 -1
  73. package/dist/evaluator/module.d.ts +8 -1
  74. package/dist/evaluator/module.js +33 -0
  75. package/dist/evaluator/scope.js +1 -0
  76. package/dist/projectors/event-log-ops.d.ts +0 -6
  77. package/dist/projectors/event-log-ops.js +2 -12
  78. package/dist/projectors/event-log.d.ts +10 -5
  79. package/dist/projectors/event-log.js +26 -22
  80. package/dist/projectors/replica/columns.d.ts +41 -0
  81. package/dist/projectors/replica/columns.js +77 -0
  82. package/dist/projectors/replica/drizzle.d.ts +328 -57
  83. package/dist/projectors/replica/drizzle.js +18 -14
  84. package/dist/projectors/replica/migrations.d.ts +25 -5
  85. package/dist/projectors/replica/migrations.js +62 -14
  86. package/dist/projectors/replica/postgres.d.ts +12 -11
  87. package/dist/projectors/replica/postgres.js +12 -26
  88. package/dist/projectors/replica/sqlite-bun.d.ts +3 -1
  89. package/dist/projectors/replica/sqlite-bun.js +6 -2
  90. package/dist/projectors/replica/sqlite-migrations.d.ts +5 -5
  91. package/dist/projectors/replica/sqlite-migrations.js +22 -9
  92. package/dist/projectors/replica/sqlite.d.ts +12 -11
  93. package/dist/projectors/replica/sqlite.js +23 -16
  94. package/dist/runtime/looms.d.ts +27 -36
  95. package/dist/runtime/looms.js +1 -0
  96. package/dist/runtime/runtime.js +7 -1
  97. package/dist/runtime/server/http.js +4 -2
  98. package/dist/runtime/server/routes/definitions.d.ts +1 -1
  99. package/dist/runtime/server/routes/definitions.js +58 -2
  100. package/dist/runtime/server/routes/runs.js +25 -1
  101. package/dist/runtime/types.d.ts +6 -1
  102. package/dist/schedule/module.d.ts +117 -1
  103. package/dist/schedule/module.js +30 -0
  104. package/dist/schedule/scope.js +1 -0
  105. package/dist/schedule/signals.d.ts +59 -7
  106. package/dist/schedule/signals.js +35 -17
  107. package/dist/testing/corpus-module.d.ts +1 -1
  108. package/dist/testing/index.js +2 -1
  109. package/dist/testing/module-examples.d.ts +6 -0
  110. package/dist/testing/module-examples.js +66 -0
  111. package/dist/workflow/module.d.ts +3 -1
  112. package/dist/workflow/module.js +13 -0
  113. package/dist/workflow/scope.js +1 -0
  114. package/package.json +1 -1
  115. package/dist/debugger/app/assets/index-B7GdT1UA.css +0 -2
  116. package/dist/debugger/app/assets/routes-CfXxKG45.js +0 -47
  117. /package/dist/evaluator/{signals.d.ts → steps.d.ts} +0 -0
  118. /package/dist/evaluator/{signals.js → steps.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @swirls/looms
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7f412db: Declare your own run attributes and give them replica columns, and clear Durable Object storage for terminal runs.
8
+
9
+ **Breaking:** the replica and `postgresEventLog` no longer have built-in `tenant`, `project`, and `org` columns. Declare the attributes you need with `defineRunAttributes` and pass them as `additionalFields`:
10
+
11
+ ```ts
12
+ const attributes = defineRunAttributes({
13
+ tenantId: { required: true, index: true },
14
+ })
15
+
16
+ createLooms({ modules, attributes })
17
+ postgresReplica({ url, additionalFields: attributes })
18
+ loomsReplicaTables({ additionalFields: attributes })
19
+ ```
20
+
21
+ - Each attribute is a text column named in snake_case unless `fieldName` is set. `index: true` adds an index. Each column and index is its own migration, and a new column is backfilled from the `attributes` JSON. `postgresEventLog` records these migrations in `looms_schema_migrations` and applies each one once.
22
+ - Once attributes are declared, `start`, `startRun`, `launchRun`, and the client only accept declared keys, and `required` keys must be passed. The host refuses other starts with `InvalidRunAttributesError`, which `POST /runs` reports as 400.
23
+ - `replica.purge({ finishedBefore, where })` filters on declared attributes.
24
+ - `looms replica generate`, `migrate`, and `status` take `--config <module>` to read the declaration.
25
+ - `deleteTerminalRunStorage` deletes a terminal run's Durable Object storage once the listed projectors attached to the object have caught up.
26
+
27
+ Replicas created by an earlier version keep their `tenant`, `project`, and `org` columns, and Looms stops writing them. On Postgres, declaring an attribute with one of those column names reuses the column. On SQLite, use another `fieldName` or drop the old column first.
28
+
29
+ ## 0.10.0
30
+
31
+ ### Minor Changes
32
+
33
+ - ddcb70f: Schema-first signals: declare builders with `m.signal` / `defineSignal`, publish and run them over HTTP, and use a schema-aware debugger signal picker. Built-in signal helpers take object input. Modules also publish a description and keep signals, steps, and example traces as first-class members.
34
+
3
35
  ## 0.9.0
4
36
 
5
37
  ### Minor Changes
@@ -1,4 +1,4 @@
1
- import { type AnyRuntimeModule, type DefinitionResolver, type EventInput, type EventStore, type EventStoreTrimCoverage, type LaunchRunArgs, type RunLauncher, type RunState, type RunStatusSnapshot, type SnapshotStore } from '@swirls/looms/core';
1
+ import { type AnyRuntimeModule, type DefinitionResolver, type EventInput, type EventStore, type EventStoreTrimCoverage, type LaunchRunArgs, type RunAttributeFields, type RunLauncher, type RunState, type RunStatusSnapshot, type SnapshotStore } from '@swirls/looms/core';
2
2
  import { type Authorize, type EffectWorker, type LoomsRuntime, type StartResult, type StartRunArgs, type WakeScheduler } from '@swirls/looms/runtime';
3
3
  export interface ActorCellOptions<TModules extends readonly AnyRuntimeModule[] = readonly AnyRuntimeModule[]> {
4
4
  readonly runId: string;
@@ -24,6 +24,8 @@ export interface ActorCellOptions<TModules extends readonly AnyRuntimeModule[] =
24
24
  * Cloudflare Queue producer). Without it, worker effects cannot leave the object.
25
25
  */
26
26
  readonly worker?: EffectWorker;
27
+ /** Declared run attributes. See `CreateRuntimeOptions`. */
28
+ readonly attributes?: RunAttributeFields;
27
29
  }
28
30
  export interface ActorCell<TModules extends readonly AnyRuntimeModule[] = readonly AnyRuntimeModule[]> {
29
31
  readonly runId: string;
@@ -20,6 +20,7 @@ export function createActorCell(options) {
20
20
  maxPendingRunOperations: options.maxPendingRunOperations,
21
21
  snapshotStore: options.snapshotStore,
22
22
  trimAfterSnapshot: options.trimAfterSnapshot,
23
+ attributes: options.attributes,
23
24
  });
24
25
  const provide = (effect) => Effect.runPromise(Effect.provideService(effect, EventStoreTag, store));
25
26
  const fetchHandler = createFetchHandler({ runtime, store, authorize: options.authorize });
@@ -1,4 +1,4 @@
1
- import type { AnyRuntimeModule, DefinitionResolver, EventInput, EventStore, EventStoreTrimCoverage, RunLauncher, RunState, SnapshotStore } from '@swirls/looms/core';
1
+ import type { AnyRuntimeModule, DefinitionResolver, EventInput, EventStore, EventStoreTrimCoverage, RunAttributeFields, RunLauncher, RunState, SnapshotStore } from '@swirls/looms/core';
2
2
  import { type Authorize, type StartResult, type StartRunArgs } from '@swirls/looms/runtime';
3
3
  import { type ActorCell } from './cell';
4
4
  export interface LocalActorHostOptions<TModules extends readonly AnyRuntimeModule[] = readonly AnyRuntimeModule[]> {
@@ -6,6 +6,8 @@ export interface LocalActorHostOptions<TModules extends readonly AnyRuntimeModul
6
6
  readonly modules: TModules;
7
7
  /** Loads definitions that were not registered on a module. See `CreateRuntimeOptions`. */
8
8
  readonly definitionResolver?: DefinitionResolver;
9
+ /** Declared run attributes. See `CreateRuntimeOptions`. */
10
+ readonly attributes?: RunAttributeFields;
9
11
  readonly snapshotStore?: SnapshotStore;
10
12
  readonly snapshotEvery?: number;
11
13
  readonly maxWakeIterations?: number;
@@ -59,6 +59,7 @@ export function createLocalActorHost(options) {
59
59
  scheduler,
60
60
  modules: options.modules,
61
61
  definitionResolver: options.definitionResolver,
62
+ attributes: options.attributes,
62
63
  snapshotStore: options.snapshotStore,
63
64
  snapshotEvery: options.snapshotEvery,
64
65
  maxWakeIterations: options.maxWakeIterations,
@@ -1,5 +1,5 @@
1
1
  import { Data, Effect, Option, Predicate, Schema } from 'effect';
2
- import { composeModules, createRunId, isJsonObject, publishDefinition, publishEffects, stringifyJson, } from '@swirls/looms/core';
2
+ import { composeModules, createRunId, isJsonObject, publishDefinition, publishEffects, publishModules, stringifyJson, } from '@swirls/looms/core';
3
3
  const RunTargetBodySchema = Schema.Struct({
4
4
  runId: Schema.optional(Schema.NonEmptyString),
5
5
  });
@@ -56,6 +56,7 @@ export function definitionsResponse(req, modules) {
56
56
  return Response.json({
57
57
  definitions: registry.definitions.map(publishDefinition),
58
58
  projections: [...registry.projections.keys()],
59
+ modules: publishModules(registry.modules),
59
60
  });
60
61
  }
61
62
  export class RunTargetError extends Data.TaggedError('RunTargetError') {
@@ -115,7 +115,7 @@ export function AgentChat(context) {
115
115
  }
116
116
  setDraft('');
117
117
  start(input, session
118
- ? (started) => client.signal(started.runId, agentSessionMessageEvents(createEventId(), content, { threadId: started.threadId }))
118
+ ? (started) => client.signal(started.runId, agentSessionMessageEvents({ messageId: createEventId(), text: content }, { threadId: started.threadId }))
119
119
  : undefined);
120
120
  }
121
121
  return (_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [runId ? (_jsx(Transcript, { runId: runId })) : (_jsx("div", { className: "min-h-0 flex-1", children: _jsx(EmptyState, { icon: _jsx(MessageSquare, {}), title: `Talk to ${definition.name}`, children: "Your first message starts a new run." }) })), runId ? (_jsx(FollowUp, { runId: runId, session: session, delivery: delivery, setDelivery: setDelivery, startError: error, onForked: context.onStarted })) : (_jsx(Composer, { value: draft, onChange: setDraft, onSubmit: send, pending: pending, placeholder: `Message ${definition.name}…`, submitLabel: "Start", error: error }))] }));
@@ -166,12 +166,13 @@ function Reply({ runId, session, delivery, setDelivery, startError }) {
166
166
  setPending(true);
167
167
  setError(null);
168
168
  const events = session
169
- ? agentSessionMessageEvents(createEventId(), content, {
169
+ ? agentSessionMessageEvents({
170
+ messageId: createEventId(),
171
+ text: content,
170
172
  delivery,
171
- threadId: rootThreadId,
172
173
  activeChildThreadId: delivery === 'steer' ? activeSessionChild(store.events()) : undefined,
173
- })
174
- : [userMessage(content, { threadId: rootThreadId })];
174
+ }, { threadId: rootThreadId })
175
+ : [userMessage({ content }, { threadId: rootThreadId })];
175
176
  const [only] = events;
176
177
  const commit = events.length === 1 && only ? store.commit(only) : store.commit(events);
177
178
  commit
@@ -1,5 +1,5 @@
1
1
  import { inputForm, messageInput } from '@swirls/looms/debugger';
2
- import { tokenUsage } from '../projections.js';
2
+ import { conversation, tokenUsage, turnActivity } from '../projections.js';
3
3
  import { AgentChat } from './agent-chat.js';
4
4
  import { summarizeAgentEvent } from './summarize.js';
5
5
  import { TokenUsageView } from './token-usage.js';
@@ -15,5 +15,6 @@ export const agentDebugger = {
15
15
  component: AgentChat,
16
16
  },
17
17
  projections: [{ name: tokenUsage.name, component: TokenUsageView }],
18
+ headlessProjections: [conversation.name, turnActivity.name],
18
19
  };
19
20
  export { AgentChat, TokenUsageView };
@@ -1248,7 +1248,109 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
1248
1248
  readonly rootThreadId: string | null;
1249
1249
  readonly active: boolean;
1250
1250
  }>;
1251
- }, import("effect/Context").Service.Any> & {
1251
+ }, import("effect/Context").Service.Any, {
1252
+ userMessage: import("@swirls/looms/core").SignalDefinition<{
1253
+ readonly content: string;
1254
+ }, Omit<EventInput, "payload" | "type"> & {
1255
+ readonly type: "agent.message.received";
1256
+ readonly payload: {
1257
+ readonly message: {
1258
+ readonly role: "assistant" | "system" | "tool" | "user";
1259
+ readonly content: string;
1260
+ readonly toolCallId?: string | undefined;
1261
+ readonly name?: string | undefined;
1262
+ readonly toolCalls?: {
1263
+ readonly id: string;
1264
+ readonly name: string;
1265
+ readonly arguments: import("effect/Schema").Json;
1266
+ }[] | undefined;
1267
+ };
1268
+ };
1269
+ }>;
1270
+ steer: import("@swirls/looms/core").SignalDefinition<{
1271
+ readonly content: string;
1272
+ readonly interrupt?: boolean | undefined;
1273
+ }, Omit<EventInput, "payload" | "type"> & {
1274
+ readonly type: "agent.steered";
1275
+ readonly payload: {
1276
+ readonly turn: number;
1277
+ readonly messageId?: string | undefined;
1278
+ readonly message: {
1279
+ readonly role: "assistant" | "system" | "tool" | "user";
1280
+ readonly content: string;
1281
+ readonly toolCallId?: string | undefined;
1282
+ readonly name?: string | undefined;
1283
+ readonly toolCalls?: {
1284
+ readonly id: string;
1285
+ readonly name: string;
1286
+ readonly arguments: import("effect/Schema").Json;
1287
+ }[] | undefined;
1288
+ };
1289
+ readonly interrupt?: boolean | undefined;
1290
+ };
1291
+ }>;
1292
+ stopAgentTurn: import("@swirls/looms/core").SignalDefinition<undefined, Omit<EventInput, "payload" | "type"> & {
1293
+ readonly type: "agent.turn.stopped";
1294
+ readonly payload: {};
1295
+ }>;
1296
+ submitAgentMessage: import("@swirls/looms/core").SignalDefinition<{
1297
+ readonly messageId: string;
1298
+ readonly text: string;
1299
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
1300
+ readonly activeChildThreadId?: string | undefined;
1301
+ }, Omit<EventInput, "payload" | "type"> & {
1302
+ readonly type: "agent.session.message.submitted";
1303
+ readonly payload: {
1304
+ readonly messageId: string;
1305
+ readonly text: string;
1306
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
1307
+ readonly activeChildThreadId?: string | undefined;
1308
+ };
1309
+ }>;
1310
+ cancelAgentTurn: import("@swirls/looms/core").SignalDefinition<{
1311
+ readonly childThreadId: string;
1312
+ }, ({
1313
+ type: 'runtime.thread.cancel.requested';
1314
+ payload: {
1315
+ threadId: string;
1316
+ };
1317
+ } | (Omit<EventInput, "payload" | "type"> & {
1318
+ readonly type: "agent.session.cancel.requested";
1319
+ readonly payload: {};
1320
+ }))[]>;
1321
+ agentSessionMessageEvents: import("@swirls/looms/core").SignalDefinition<{
1322
+ readonly messageId: string;
1323
+ readonly text: string;
1324
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
1325
+ readonly activeChildThreadId?: string | undefined;
1326
+ }, ((Omit<EventInput, "payload" | "type"> & {
1327
+ readonly type: "agent.session.message.submitted";
1328
+ readonly payload: {
1329
+ readonly messageId: string;
1330
+ readonly text: string;
1331
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
1332
+ readonly activeChildThreadId?: string | undefined;
1333
+ };
1334
+ }) | (Omit<EventInput, "payload" | "type"> & {
1335
+ readonly type: "agent.steered";
1336
+ readonly payload: {
1337
+ readonly turn: number;
1338
+ readonly messageId?: string | undefined;
1339
+ readonly message: {
1340
+ readonly role: "assistant" | "system" | "tool" | "user";
1341
+ readonly content: string;
1342
+ readonly toolCallId?: string | undefined;
1343
+ readonly name?: string | undefined;
1344
+ readonly toolCalls?: {
1345
+ readonly id: string;
1346
+ readonly name: string;
1347
+ readonly arguments: import("effect/Schema").Json;
1348
+ }[] | undefined;
1349
+ };
1350
+ readonly interrupt?: boolean | undefined;
1351
+ };
1352
+ }))[]>;
1353
+ }, {}> & {
1252
1354
  readonly effects: {
1253
1355
  callLLM: import("@swirls/looms/core").LocalEffectDefinition<{
1254
1356
  readonly turn: number;
@@ -2286,4 +2388,108 @@ export declare function agent(options?: AgentModuleOptions): import("@swirls/loo
2286
2388
  readonly active: boolean;
2287
2389
  }>;
2288
2390
  };
2391
+ readonly signals: {
2392
+ userMessage: import("@swirls/looms/core").SignalDefinition<{
2393
+ readonly content: string;
2394
+ }, Omit<EventInput, "payload" | "type"> & {
2395
+ readonly type: "agent.message.received";
2396
+ readonly payload: {
2397
+ readonly message: {
2398
+ readonly role: "assistant" | "system" | "tool" | "user";
2399
+ readonly content: string;
2400
+ readonly toolCallId?: string | undefined;
2401
+ readonly name?: string | undefined;
2402
+ readonly toolCalls?: {
2403
+ readonly id: string;
2404
+ readonly name: string;
2405
+ readonly arguments: import("effect/Schema").Json;
2406
+ }[] | undefined;
2407
+ };
2408
+ };
2409
+ }>;
2410
+ steer: import("@swirls/looms/core").SignalDefinition<{
2411
+ readonly content: string;
2412
+ readonly interrupt?: boolean | undefined;
2413
+ }, Omit<EventInput, "payload" | "type"> & {
2414
+ readonly type: "agent.steered";
2415
+ readonly payload: {
2416
+ readonly turn: number;
2417
+ readonly messageId?: string | undefined;
2418
+ readonly message: {
2419
+ readonly role: "assistant" | "system" | "tool" | "user";
2420
+ readonly content: string;
2421
+ readonly toolCallId?: string | undefined;
2422
+ readonly name?: string | undefined;
2423
+ readonly toolCalls?: {
2424
+ readonly id: string;
2425
+ readonly name: string;
2426
+ readonly arguments: import("effect/Schema").Json;
2427
+ }[] | undefined;
2428
+ };
2429
+ readonly interrupt?: boolean | undefined;
2430
+ };
2431
+ }>;
2432
+ stopAgentTurn: import("@swirls/looms/core").SignalDefinition<undefined, Omit<EventInput, "payload" | "type"> & {
2433
+ readonly type: "agent.turn.stopped";
2434
+ readonly payload: {};
2435
+ }>;
2436
+ submitAgentMessage: import("@swirls/looms/core").SignalDefinition<{
2437
+ readonly messageId: string;
2438
+ readonly text: string;
2439
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
2440
+ readonly activeChildThreadId?: string | undefined;
2441
+ }, Omit<EventInput, "payload" | "type"> & {
2442
+ readonly type: "agent.session.message.submitted";
2443
+ readonly payload: {
2444
+ readonly messageId: string;
2445
+ readonly text: string;
2446
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
2447
+ readonly activeChildThreadId?: string | undefined;
2448
+ };
2449
+ }>;
2450
+ cancelAgentTurn: import("@swirls/looms/core").SignalDefinition<{
2451
+ readonly childThreadId: string;
2452
+ }, ({
2453
+ type: 'runtime.thread.cancel.requested';
2454
+ payload: {
2455
+ threadId: string;
2456
+ };
2457
+ } | (Omit<EventInput, "payload" | "type"> & {
2458
+ readonly type: "agent.session.cancel.requested";
2459
+ readonly payload: {};
2460
+ }))[]>;
2461
+ agentSessionMessageEvents: import("@swirls/looms/core").SignalDefinition<{
2462
+ readonly messageId: string;
2463
+ readonly text: string;
2464
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
2465
+ readonly activeChildThreadId?: string | undefined;
2466
+ }, ((Omit<EventInput, "payload" | "type"> & {
2467
+ readonly type: "agent.session.message.submitted";
2468
+ readonly payload: {
2469
+ readonly messageId: string;
2470
+ readonly text: string;
2471
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
2472
+ readonly activeChildThreadId?: string | undefined;
2473
+ };
2474
+ }) | (Omit<EventInput, "payload" | "type"> & {
2475
+ readonly type: "agent.steered";
2476
+ readonly payload: {
2477
+ readonly turn: number;
2478
+ readonly messageId?: string | undefined;
2479
+ readonly message: {
2480
+ readonly role: "assistant" | "system" | "tool" | "user";
2481
+ readonly content: string;
2482
+ readonly toolCallId?: string | undefined;
2483
+ readonly name?: string | undefined;
2484
+ readonly toolCalls?: {
2485
+ readonly id: string;
2486
+ readonly name: string;
2487
+ readonly arguments: import("effect/Schema").Json;
2488
+ }[] | undefined;
2489
+ };
2490
+ readonly interrupt?: boolean | undefined;
2491
+ };
2492
+ }))[]>;
2493
+ };
2494
+ readonly steps: {};
2289
2495
  };
@@ -6,6 +6,7 @@ import { callLlmEffect, executeToolEffect } from './effects.js';
6
6
  import { llmFromAdapter, LlmTag, StubLlmLive } from './llm.js';
7
7
  import { conversation, tokenUsage, turnActivity } from './projections.js';
8
8
  import { agentModule } from './scope.js';
9
+ import { agentSessionMessageEvents, cancelAgentTurn, steer, stopAgentTurn, submitAgentMessage, userMessage, } from './signals.js';
9
10
  import { agentThread } from './threads.js';
10
11
  export function agent(options = {}) {
11
12
  const definitions = options.definitions ?? [];
@@ -29,6 +30,36 @@ export function agent(options = {}) {
29
30
  tokenUsage,
30
31
  turnActivity,
31
32
  },
33
+ signals: {
34
+ userMessage,
35
+ steer,
36
+ stopAgentTurn,
37
+ submitAgentMessage,
38
+ cancelAgentTurn,
39
+ agentSessionMessageEvents,
40
+ },
41
+ examples: [
42
+ {
43
+ name: 'a reply updates conversation and token usage',
44
+ events: [
45
+ userMessage({ content: 'Hello' }),
46
+ agentModule.input('message', {
47
+ turn: 1,
48
+ message: { role: 'assistant', content: 'Hi there' },
49
+ usage: { input: 4, output: 2 },
50
+ }),
51
+ ],
52
+ projections: {
53
+ conversation: {
54
+ lines: [
55
+ { role: 'user', content: 'Hello' },
56
+ { role: 'assistant', content: 'Hi there' },
57
+ ],
58
+ },
59
+ tokenUsage: { input: 4, output: 2 },
60
+ },
61
+ },
62
+ ],
32
63
  services: () => Layer.merge(llmLayer, AgentDefinitionsLive(agentDefinitions)),
33
64
  interruptsOnSignal,
34
65
  bindHost(host) {
@@ -3,5 +3,6 @@ import { agentCatalog } from './events.js';
3
3
  export const agentModule = createModuleScope({
4
4
  namespace: 'agent',
5
5
  protocolVersion: '1.0.0',
6
+ description: 'Conversational and tool-using model runs.',
6
7
  events: agentCatalog,
7
8
  });
@@ -1,33 +1,93 @@
1
+ import { Schema } from 'effect';
1
2
  import type { EventInput, JsonValue } from '@swirls/looms/core';
2
3
  import type { AgentMessageDelivery } from './types';
3
- export interface AgentSignalOptions {
4
- /** Target thread. Defaults to the run's root thread when omitted. */
5
- readonly threadId?: string;
6
- }
7
4
  /**
8
5
  * Build the `agent.message.received` event for a conversational agent.
9
- * Send it with `looms.signal(runId, [userMessage('Also greet Maya')])`.
6
+ * Send it with `looms.signal(runId, [userMessage({ content: 'Also greet Maya' })])`.
10
7
  */
11
- export declare function userMessage(content: string, options?: AgentSignalOptions): EventInput;
8
+ export declare const userMessage: import("@swirls/looms/core").SignalDefinition<{
9
+ readonly content: string;
10
+ }, Omit<EventInput, "payload" | "type"> & {
11
+ readonly type: "agent.message.received";
12
+ readonly payload: {
13
+ readonly message: {
14
+ readonly role: "assistant" | "system" | "tool" | "user";
15
+ readonly content: string;
16
+ readonly toolCallId?: string | undefined;
17
+ readonly name?: string | undefined;
18
+ readonly toolCalls?: {
19
+ readonly id: string;
20
+ readonly name: string;
21
+ readonly arguments: Schema.Json;
22
+ }[] | undefined;
23
+ };
24
+ };
25
+ }>;
12
26
  /**
13
27
  * Build the `agent.steered` event: inject a user message mid-run, optionally
14
28
  * interrupting the current turn so the agent replans immediately.
15
29
  */
16
- export declare function steer(content: string, options?: AgentSignalOptions & {
17
- readonly interrupt?: boolean;
18
- }): EventInput;
30
+ export declare const steer: import("@swirls/looms/core").SignalDefinition<{
31
+ readonly content: string;
32
+ readonly interrupt?: boolean | undefined;
33
+ }, Omit<EventInput, "payload" | "type"> & {
34
+ readonly type: "agent.steered";
35
+ readonly payload: {
36
+ readonly turn: number;
37
+ readonly messageId?: string | undefined;
38
+ readonly message: {
39
+ readonly role: "assistant" | "system" | "tool" | "user";
40
+ readonly content: string;
41
+ readonly toolCallId?: string | undefined;
42
+ readonly name?: string | undefined;
43
+ readonly toolCalls?: {
44
+ readonly id: string;
45
+ readonly name: string;
46
+ readonly arguments: Schema.Json;
47
+ }[] | undefined;
48
+ };
49
+ readonly interrupt?: boolean | undefined;
50
+ };
51
+ }>;
19
52
  /**
20
53
  * Build the `agent.turn.stopped` event. A conversational agent aborts its in-flight turn and
21
54
  * waits for the next message; an agent session cancels its active turn and stays open.
22
55
  */
23
- export declare function stopAgentTurn(options?: AgentSignalOptions): EventInput;
24
- export interface AgentSessionMessageOptions extends AgentSignalOptions {
56
+ export declare const stopAgentTurn: import("@swirls/looms/core").SignalDefinition<undefined, Omit<EventInput, "payload" | "type"> & {
57
+ readonly type: "agent.turn.stopped";
58
+ readonly payload: {};
59
+ }>;
60
+ export interface AgentSessionMessageOptions {
61
+ readonly threadId?: string;
25
62
  readonly delivery?: AgentMessageDelivery;
26
63
  /** Set by the client helper when a steer is aimed at an active child. */
27
64
  readonly activeChildThreadId?: string;
28
65
  }
29
- export declare function submitAgentMessage(messageId: string, text: string, options?: AgentSessionMessageOptions): EventInput;
30
- export declare function cancelAgentTurn(childThreadId: string, options?: AgentSignalOptions): EventInput[];
66
+ export declare const submitAgentMessage: import("@swirls/looms/core").SignalDefinition<{
67
+ readonly messageId: string;
68
+ readonly text: string;
69
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
70
+ readonly activeChildThreadId?: string | undefined;
71
+ }, Omit<EventInput, "payload" | "type"> & {
72
+ readonly type: "agent.session.message.submitted";
73
+ readonly payload: {
74
+ readonly messageId: string;
75
+ readonly text: string;
76
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
77
+ readonly activeChildThreadId?: string | undefined;
78
+ };
79
+ }>;
80
+ export declare const cancelAgentTurn: import("@swirls/looms/core").SignalDefinition<{
81
+ readonly childThreadId: string;
82
+ }, ({
83
+ type: 'runtime.thread.cancel.requested';
84
+ payload: {
85
+ threadId: string;
86
+ };
87
+ } | (Omit<EventInput, "payload" | "type"> & {
88
+ readonly type: "agent.session.cancel.requested";
89
+ readonly payload: {};
90
+ }))[]>;
31
91
  interface AgentSessionSignalClient<Result> {
32
92
  getRun(runId: string): Promise<{
33
93
  rootThreadId: string | null;
@@ -41,7 +101,40 @@ interface AgentSessionSignalClient<Result> {
41
101
  cancel?(runId: string, threadId?: string): Promise<Result>;
42
102
  }
43
103
  /** Events for one session message. A steer aimed at `activeChildThreadId` interrupts that turn in the same batch. */
44
- export declare function agentSessionMessageEvents(messageId: string, text: string, options?: AgentSessionMessageOptions): EventInput[];
104
+ export declare const agentSessionMessageEvents: import("@swirls/looms/core").SignalDefinition<{
105
+ readonly messageId: string;
106
+ readonly text: string;
107
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
108
+ readonly activeChildThreadId?: string | undefined;
109
+ }, ((Omit<EventInput, "payload" | "type"> & {
110
+ readonly type: "agent.session.message.submitted";
111
+ readonly payload: {
112
+ readonly messageId: string;
113
+ readonly text: string;
114
+ readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
115
+ readonly activeChildThreadId?: string | undefined;
116
+ };
117
+ }) | (Omit<EventInput, "payload" | "type"> & {
118
+ readonly type: "agent.steered";
119
+ readonly payload: {
120
+ readonly turn: number;
121
+ readonly messageId?: string | undefined;
122
+ readonly message: {
123
+ readonly role: "assistant" | "system" | "tool" | "user";
124
+ readonly content: string;
125
+ readonly toolCallId?: string | undefined;
126
+ readonly name?: string | undefined;
127
+ readonly toolCalls?: {
128
+ readonly id: string;
129
+ readonly name: string;
130
+ readonly arguments: Schema.Json;
131
+ }[] | undefined;
132
+ };
133
+ readonly interrupt?: boolean | undefined;
134
+ };
135
+ }))[]>;
45
136
  export declare function sendAgentSessionMessage<Result>(client: AgentSessionSignalClient<Result>, runId: string, messageId: string, text: string, options?: Omit<AgentSessionMessageOptions, 'activeChildThreadId'>): Promise<Result>;
46
- export declare function cancelActiveAgentTurn<Result>(client: AgentSessionSignalClient<Result>, runId: string, options?: AgentSignalOptions): Promise<Result | Awaited<ReturnType<AgentSessionSignalClient<Result>['getRun']>>>;
137
+ export declare function cancelActiveAgentTurn<Result>(client: AgentSessionSignalClient<Result>, runId: string, options?: {
138
+ readonly threadId?: string;
139
+ }): Promise<Result | Awaited<ReturnType<AgentSessionSignalClient<Result>['getRun']>>>;
47
140
  export {};