@swirls/looms 0.26.0 → 0.27.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/agent/definitions.d.ts +14 -4
  3. package/dist/agent/effects.d.ts +266 -266
  4. package/dist/agent/effects.js +16 -7
  5. package/dist/agent/llm.d.ts +3 -1
  6. package/dist/agent/module.d.ts +727 -727
  7. package/dist/agent/threads.js +4 -1
  8. package/dist/ai-vercel/messages.d.ts +3 -3
  9. package/dist/ai-vercel/messages.js +23 -6
  10. package/dist/ai-vercel/vercel-llm.js +1 -1
  11. package/dist/cloudflare/durable-object.js +6 -6
  12. package/dist/cloudflare/event-store.d.ts +4 -3
  13. package/dist/cloudflare/event-store.js +10 -3
  14. package/dist/evaluator/effects.d.ts +33 -33
  15. package/dist/evaluator/module.d.ts +66 -66
  16. package/dist/projectors/delivery.d.ts +6 -0
  17. package/dist/projectors/delivery.js +14 -0
  18. package/dist/swarm/board.d.ts +51 -3
  19. package/dist/swarm/board.js +8 -0
  20. package/dist/swarm/conformance.js +54 -1
  21. package/dist/swarm/definitions.d.ts +15 -0
  22. package/dist/swarm/definitions.js +3 -0
  23. package/dist/swarm/effects.d.ts +1009 -31
  24. package/dist/swarm/effects.js +73 -18
  25. package/dist/swarm/ensure.d.ts +9 -2
  26. package/dist/swarm/ensure.js +2 -1
  27. package/dist/swarm/events.d.ts +51 -0
  28. package/dist/swarm/events.js +10 -0
  29. package/dist/swarm/index.d.ts +1 -0
  30. package/dist/swarm/index.js +1 -0
  31. package/dist/swarm/memory-board.js +18 -2
  32. package/dist/swarm/module.d.ts +2055 -115
  33. package/dist/swarm/module.js +3 -1
  34. package/dist/swarm/prompt.d.ts +5 -0
  35. package/dist/swarm/prompt.js +27 -2
  36. package/dist/swarm/scope.d.ts +80 -0
  37. package/dist/swarm/services.d.ts +2 -2
  38. package/dist/swarm/services.js +5 -2
  39. package/dist/swarm/threads.d.ts +4 -0
  40. package/dist/swarm/threads.js +24 -2
  41. package/dist/swarm/tools.js +12 -5
  42. package/package.json +1 -1
@@ -88,7 +88,12 @@ export const callLlmEffect = agentModule.effect({
88
88
  structuredOutput: input.structuredOutput ?? null,
89
89
  alreadyCompacted: input.alreadyCompacted ?? false,
90
90
  consumedSteerMessageIds: [...(input.consumedSteerMessageIds ?? [])],
91
- runId: ctx.runId,
91
+ run: {
92
+ runId: ctx.runId,
93
+ threadId: ctx.threadId,
94
+ attributes: ctx.attributes,
95
+ secrets: ctx.secrets,
96
+ },
92
97
  threadId: ctx.threadId,
93
98
  ids: ctx.ids,
94
99
  signal: ctx.signal,
@@ -125,7 +130,7 @@ function runCallLlm(args) {
125
130
  },
126
131
  ];
127
132
  }
128
- const tools = yield* agentTools(definition, { threadId, turn, input, ids: args.ids });
133
+ const tools = yield* agentTools(definition, { ...args.run, turn, input, ids: args.ids });
129
134
  const instructions = definition.output
130
135
  ? `${definition.instructions}\n\n${buildStructuredOutputInstructions(STRUCTURED_OUTPUT_TOOL_NAME)}`
131
136
  : definition.instructions;
@@ -162,6 +167,7 @@ function runCallLlm(args) {
162
167
  messages: [{ role: 'system', content: instructions }, ...turnMessages],
163
168
  tools,
164
169
  toolSpecs: toolSpecs(tools),
170
+ run: args.run,
165
171
  signal,
166
172
  onTextDelta: (delta) => emit({
167
173
  type: 'agent.turn.text_delta',
@@ -271,6 +277,12 @@ export const executeToolEffect = agentModule.effect({
271
277
  execute: (input, ctx) => Effect.gen(function* () {
272
278
  const threadId = ctx.threadId;
273
279
  const agents = yield* AgentDefinitionsTag;
280
+ const run = {
281
+ runId: ctx.runId,
282
+ threadId,
283
+ attributes: ctx.attributes,
284
+ secrets: ctx.secrets,
285
+ };
274
286
  const definition = input.definitionName
275
287
  ? yield* agents.resolve(input.definitionName, input.definitionVersion)
276
288
  : undefined;
@@ -290,7 +302,7 @@ export const executeToolEffect = agentModule.effect({
290
302
  ];
291
303
  }
292
304
  const resolved = yield* agentTools(definition, {
293
- threadId,
305
+ ...run,
294
306
  turn: input.turn,
295
307
  input: input.input ?? null,
296
308
  ids: ctx.ids,
@@ -330,10 +342,7 @@ export const executeToolEffect = agentModule.effect({
330
342
  ];
331
343
  }
332
344
  const result = yield* Effect.tryPromise({
333
- try: () => Promise.resolve(tool.handler(validated.value, {
334
- threadId,
335
- turn: input.turn,
336
- })),
345
+ try: () => Promise.resolve(tool.handler(validated.value, { ...run, turn: input.turn, signal: ctx.signal })),
337
346
  catch: (cause) => new AgentExecutionError(`run tool ${tool.name}`, cause),
338
347
  }).pipe(Effect.match({
339
348
  onFailure: (error) => ({ ok: false, error: error.message }),
@@ -1,6 +1,6 @@
1
1
  import { Context, Effect, Layer } from 'effect';
2
2
  import { type JsonValue } from '@swirls/looms/core';
3
- import type { AgentTurnContext, AgentTurnResult, ToolLike } from './definitions';
3
+ import type { AgentRunContext, AgentTurnContext, AgentTurnResult, ToolLike } from './definitions';
4
4
  import type { Message, ToolCall } from './types';
5
5
  export interface LlmToolSpec {
6
6
  readonly name: string;
@@ -13,6 +13,8 @@ export interface LlmCompleteArgs {
13
13
  messages: Message[];
14
14
  tools: ToolLike[];
15
15
  toolSpecs?: LlmToolSpec[];
16
+ /** The run this call is made for, so an adapter can scope what it reads to the run's tenant. */
17
+ run: AgentRunContext;
16
18
  onTextDelta?: (delta: string) => void | Promise<void>;
17
19
  signal?: AbortSignal;
18
20
  }