@swirls/looms 0.26.0 → 0.27.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.
- package/CHANGELOG.md +24 -0
- package/dist/agent/definitions.d.ts +14 -4
- package/dist/agent/effects.js +16 -7
- package/dist/agent/llm.d.ts +3 -1
- package/dist/agent/module.d.ts +727 -727
- package/dist/agent/threads.js +4 -1
- package/dist/ai-vercel/messages.d.ts +3 -3
- package/dist/ai-vercel/messages.js +23 -6
- package/dist/ai-vercel/vercel-llm.js +1 -1
- package/dist/evaluator/effects.d.ts +33 -33
- package/dist/evaluator/module.d.ts +66 -66
- package/dist/schedule/module.d.ts +36 -36
- package/dist/swarm/board.d.ts +51 -3
- package/dist/swarm/board.js +8 -0
- package/dist/swarm/conformance.js +54 -1
- package/dist/swarm/definitions.d.ts +15 -0
- package/dist/swarm/definitions.js +3 -0
- package/dist/swarm/effects.d.ts +1009 -31
- package/dist/swarm/effects.js +73 -18
- package/dist/swarm/ensure.d.ts +9 -2
- package/dist/swarm/ensure.js +2 -1
- package/dist/swarm/events.d.ts +51 -0
- package/dist/swarm/events.js +10 -0
- package/dist/swarm/index.d.ts +1 -0
- package/dist/swarm/index.js +1 -0
- package/dist/swarm/memory-board.js +18 -2
- package/dist/swarm/module.d.ts +2055 -115
- package/dist/swarm/module.js +3 -1
- package/dist/swarm/prompt.d.ts +5 -0
- package/dist/swarm/prompt.js +27 -2
- package/dist/swarm/scope.d.ts +80 -0
- package/dist/swarm/services.d.ts +2 -2
- package/dist/swarm/services.js +5 -2
- package/dist/swarm/threads.d.ts +4 -0
- package/dist/swarm/threads.js +24 -2
- package/dist/swarm/tools.js +12 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @swirls/looms
|
|
2
2
|
|
|
3
|
+
## 0.27.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a72ee36: Board messages and tasks can carry files, so swarm members can send each other screenshots, recordings, and documents.
|
|
8
|
+
|
|
9
|
+
`post`, `reply`, and `createTask` on `MessageBoard` take `attachments`, a list of the agent module's `Attachment` references, and every `BoardMessage` now has an `attachments` list. The board keeps the references and never the bytes. A member that is woken by a message with files gets them on its first message, the new `board_view` tool shows it the files on any other message, and `board_post`, `board_reply`, and `board_create_task` accept `attachments`.
|
|
10
|
+
|
|
11
|
+
A tool result with an `attachments` list at its top level now shows those files to the model: the agent keeps them on the tool message, and the Vercel AI adapter sends them beside the result.
|
|
12
|
+
|
|
13
|
+
Breaking for board implementations: `BoardMessage.attachments` is required, `MessageQuery` gains `id`, and `boardConformance` checks both.
|
|
14
|
+
|
|
15
|
+
- a72ee36: Swarms, agent tools, and the model adapter now know which run they work for, so a host with many tenants can keep each tenant's boards and files apart.
|
|
16
|
+
|
|
17
|
+
- `resolveAttachment(attachment, run)` receives the run the model call is made for: `runId`, `threadId`, `attributes`, and `secrets`. `LlmCompleteArgs` carries it as `run`.
|
|
18
|
+
- A tool's `handler(input, ctx)` and an agent's `resolveTools(ctx)` receive the same values.
|
|
19
|
+
- The swarm `boards` resolver is called as `boards(boardId, caller)`. Throw `BoardError` with the new code `board_denied` for a board the caller's tenant does not own. A swarm whose own board is refused fails.
|
|
20
|
+
- `ensureSwarm` takes `{ attributes }` as a fifth argument. Member runs inherit them.
|
|
21
|
+
- A member's run id is now derived in the host's id format, so it is a valid id under a custom format. It was `<swarm run id>:<member>:<n>`. `activationRunId` returns it.
|
|
22
|
+
- A board write's idempotency key now names the run as well as the effect, so two runs that share a board cannot collide.
|
|
23
|
+
- A swarm that cannot read its board tries again with a growing delay, up to 15 minutes. It used to stop reading after five attempts.
|
|
24
|
+
|
|
25
|
+
Breaking: `LlmCompleteArgs.run` is required, and `resolveAttachments` takes the run as a third argument.
|
|
26
|
+
|
|
3
27
|
## 0.26.0
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { Schema } from 'effect';
|
|
3
|
-
import { type JsonValue, type RuntimeEffect, type SchemaInput, type LoomsIds } from '@swirls/looms/core';
|
|
3
|
+
import { type JsonValue, type RuntimeEffect, type SchemaInput, type LoomsIds, type RunAttributes, type SecretContext } from '@swirls/looms/core';
|
|
4
4
|
import type { StopWhen } from './stop-when';
|
|
5
5
|
import type { Message, ToolCall } from './types';
|
|
6
6
|
export declare const TEAM_MEMBER_MAX_DEPTH: 3;
|
|
@@ -25,8 +25,19 @@ export declare function defaultAgentCompactor(ctx: AgentCompactionContext): Agen
|
|
|
25
25
|
/** Whether a model error reports that the prompt exceeded the model's context window. */
|
|
26
26
|
export declare function isContextOverflowError(error: Error): boolean;
|
|
27
27
|
export declare function buildStructuredOutputInstructions(toolName?: "submit_output"): string;
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* The run an agent is working in. A host that serves many tenants reads the tenant from
|
|
30
|
+
* `attributes`, which a run is started with and which the runs it launches inherit.
|
|
31
|
+
*/
|
|
32
|
+
export interface AgentRunContext {
|
|
33
|
+
readonly runId: string;
|
|
29
34
|
readonly threadId: string;
|
|
35
|
+
/** Labels safe for every reader of the run. */
|
|
36
|
+
readonly attributes: RunAttributes;
|
|
37
|
+
/** Bearer material for this attempt. Never copy it into a tool result or an event. */
|
|
38
|
+
readonly secrets: SecretContext;
|
|
39
|
+
}
|
|
40
|
+
export interface ToolContext extends AgentRunContext {
|
|
30
41
|
readonly turn: number;
|
|
31
42
|
readonly signal?: AbortSignal;
|
|
32
43
|
}
|
|
@@ -82,8 +93,7 @@ export interface AgentTurnContext<TInput = JsonValue> {
|
|
|
82
93
|
readonly signal?: AbortSignal;
|
|
83
94
|
}
|
|
84
95
|
/** What `resolveTools` sees. It runs before each model turn and again when a tool executes. */
|
|
85
|
-
export interface AgentToolResolutionContext<TInput = JsonValue> {
|
|
86
|
-
readonly threadId: string;
|
|
96
|
+
export interface AgentToolResolutionContext<TInput = JsonValue> extends AgentRunContext {
|
|
87
97
|
readonly turn: number;
|
|
88
98
|
readonly input: TInput;
|
|
89
99
|
/** The id format the host was configured with. */
|
package/dist/agent/effects.js
CHANGED
|
@@ -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
|
-
|
|
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, {
|
|
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
|
-
|
|
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 }),
|
package/dist/agent/llm.d.ts
CHANGED
|
@@ -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
|
}
|