@swirls/looms 0.13.2 → 0.14.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 +6 -0
- package/dist/agent/agent-session.js +12 -11
- package/dist/agent/effects.d.ts +77 -0
- package/dist/agent/events.d.ts +70 -0
- package/dist/agent/events.js +2 -1
- package/dist/agent/module.d.ts +329 -0
- package/dist/agent/projections.d.ts +7 -0
- package/dist/agent/projections.js +2 -1
- package/dist/agent/scope.d.ts +70 -0
- package/dist/agent/signals.d.ts +63 -0
- package/dist/agent/signals.js +7 -4
- package/dist/agent/threads.js +8 -11
- package/dist/agent/types.d.ts +49 -0
- package/dist/agent/types.js +33 -0
- package/dist/ai-vercel/index.d.ts +1 -1
- package/dist/ai-vercel/index.js +1 -1
- package/dist/ai-vercel/messages.d.ts +19 -2
- package/dist/ai-vercel/messages.js +60 -2
- package/dist/ai-vercel/vercel-llm.d.ts +6 -0
- package/dist/ai-vercel/vercel-llm.js +9 -2
- package/dist/debugger/app/assets/{index-Dqg2e5oY.js → index-CtGiJU8b.js} +2 -2
- package/dist/debugger/app/assets/{routes-DMDW7tFG.js → routes-Bg0vNEOr.js} +2 -2
- package/dist/debugger/app/index.html +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Predicate } from 'effect';
|
|
2
2
|
import { agentModule } from './scope.js';
|
|
3
3
|
import { closeOpenToolCalls, insertToolResult } from './transcript.js';
|
|
4
|
-
import { ConversationSchema, TokenUsageSchema, TurnActivitySchema, } from './types.js';
|
|
4
|
+
import { attachmentsField, ConversationSchema, TokenUsageSchema, TurnActivitySchema, } from './types.js';
|
|
5
5
|
export const conversation = agentModule.projection({
|
|
6
6
|
name: 'conversation',
|
|
7
7
|
shape: ConversationSchema,
|
|
@@ -40,6 +40,7 @@ export const conversation = agentModule.projection({
|
|
|
40
40
|
toolCallId: raw.toolCallId ?? undefined,
|
|
41
41
|
name: raw.name ?? undefined,
|
|
42
42
|
toolCalls,
|
|
43
|
+
...attachmentsField(raw.attachments),
|
|
43
44
|
};
|
|
44
45
|
const interrupted = event.type === 'agent.steered' && event.payload.interrupt === true;
|
|
45
46
|
return { lines: [...(interrupted ? closeOpenToolCalls(state.lines) : state.lines), line] };
|
package/dist/agent/scope.d.ts
CHANGED
|
@@ -4,6 +4,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
4
4
|
readonly message: import("effect/Schema").Struct<{
|
|
5
5
|
readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
|
|
6
6
|
readonly content: import("effect/Schema").String;
|
|
7
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
8
|
+
readonly id: import("effect/Schema").String;
|
|
9
|
+
readonly mediaType: import("effect/Schema").String;
|
|
10
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
11
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
12
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
13
|
+
}>>>;
|
|
7
14
|
readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
8
15
|
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
9
16
|
readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -29,6 +36,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
29
36
|
readonly message: import("effect/Schema").Struct<{
|
|
30
37
|
readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
|
|
31
38
|
readonly content: import("effect/Schema").String;
|
|
39
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
40
|
+
readonly id: import("effect/Schema").String;
|
|
41
|
+
readonly mediaType: import("effect/Schema").String;
|
|
42
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
43
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
44
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
45
|
+
}>>>;
|
|
32
46
|
readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
33
47
|
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
34
48
|
readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -63,6 +77,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
63
77
|
readonly message: import("effect/Schema").Struct<{
|
|
64
78
|
readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
|
|
65
79
|
readonly content: import("effect/Schema").String;
|
|
80
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
81
|
+
readonly id: import("effect/Schema").String;
|
|
82
|
+
readonly mediaType: import("effect/Schema").String;
|
|
83
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
84
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
85
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
86
|
+
}>>>;
|
|
66
87
|
readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
67
88
|
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
68
89
|
readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -77,6 +98,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
77
98
|
'session.message.submitted': import("effect/Schema").Struct<{
|
|
78
99
|
readonly messageId: import("effect/Schema").String;
|
|
79
100
|
readonly text: import("effect/Schema").String;
|
|
101
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
102
|
+
readonly id: import("effect/Schema").String;
|
|
103
|
+
readonly mediaType: import("effect/Schema").String;
|
|
104
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
105
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
106
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
107
|
+
}>>>;
|
|
80
108
|
readonly delivery: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"steer">, import("effect/Schema").Literal<"followUp">, import("effect/Schema").Literal<"nextTurn">]>>;
|
|
81
109
|
readonly activeChildThreadId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
82
110
|
}>;
|
|
@@ -196,6 +224,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
196
224
|
readonly messages: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
197
225
|
readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
|
|
198
226
|
readonly content: import("effect/Schema").String;
|
|
227
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
228
|
+
readonly id: import("effect/Schema").String;
|
|
229
|
+
readonly mediaType: import("effect/Schema").String;
|
|
230
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
231
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
232
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
233
|
+
}>>>;
|
|
199
234
|
readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
200
235
|
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
201
236
|
readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -215,6 +250,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
215
250
|
readonly message: import("effect/Schema").Struct<{
|
|
216
251
|
readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
|
|
217
252
|
readonly content: import("effect/Schema").String;
|
|
253
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
254
|
+
readonly id: import("effect/Schema").String;
|
|
255
|
+
readonly mediaType: import("effect/Schema").String;
|
|
256
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
257
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
258
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
259
|
+
}>>>;
|
|
218
260
|
readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
219
261
|
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
220
262
|
readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -240,6 +282,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
240
282
|
readonly message: import("effect/Schema").Struct<{
|
|
241
283
|
readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
|
|
242
284
|
readonly content: import("effect/Schema").String;
|
|
285
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
286
|
+
readonly id: import("effect/Schema").String;
|
|
287
|
+
readonly mediaType: import("effect/Schema").String;
|
|
288
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
289
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
290
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
291
|
+
}>>>;
|
|
243
292
|
readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
244
293
|
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
245
294
|
readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -274,6 +323,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
274
323
|
readonly message: import("effect/Schema").Struct<{
|
|
275
324
|
readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
|
|
276
325
|
readonly content: import("effect/Schema").String;
|
|
326
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
327
|
+
readonly id: import("effect/Schema").String;
|
|
328
|
+
readonly mediaType: import("effect/Schema").String;
|
|
329
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
330
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
331
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
332
|
+
}>>>;
|
|
277
333
|
readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
278
334
|
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
279
335
|
readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -288,6 +344,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
288
344
|
'session.message.submitted': import("effect/Schema").Struct<{
|
|
289
345
|
readonly messageId: import("effect/Schema").String;
|
|
290
346
|
readonly text: import("effect/Schema").String;
|
|
347
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
348
|
+
readonly id: import("effect/Schema").String;
|
|
349
|
+
readonly mediaType: import("effect/Schema").String;
|
|
350
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
351
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
352
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
353
|
+
}>>>;
|
|
291
354
|
readonly delivery: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"steer">, import("effect/Schema").Literal<"followUp">, import("effect/Schema").Literal<"nextTurn">]>>;
|
|
292
355
|
readonly activeChildThreadId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
293
356
|
}>;
|
|
@@ -407,6 +470,13 @@ export declare const agentModule: import("@swirls/looms/core").ModuleScope<"agen
|
|
|
407
470
|
readonly messages: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
408
471
|
readonly role: import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"system">, import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"assistant">, import("effect/Schema").Literal<"tool">]>;
|
|
409
472
|
readonly content: import("effect/Schema").String;
|
|
473
|
+
readonly attachments: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
474
|
+
readonly id: import("effect/Schema").String;
|
|
475
|
+
readonly mediaType: import("effect/Schema").String;
|
|
476
|
+
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
477
|
+
readonly size: import("effect/Schema").optional<import("effect/Schema").Finite>;
|
|
478
|
+
readonly url: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
479
|
+
}>>>;
|
|
410
480
|
readonly toolCallId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
411
481
|
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
412
482
|
readonly toolCalls: import("effect/Schema").optional<import("effect/Schema").mutable<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
package/dist/agent/signals.d.ts
CHANGED
|
@@ -7,12 +7,26 @@ import type { AgentMessageDelivery } from './types';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const userMessage: import("@swirls/looms/core").SignalDefinition<{
|
|
9
9
|
readonly content: string;
|
|
10
|
+
readonly attachments?: readonly {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly mediaType: string;
|
|
13
|
+
readonly name?: string | undefined;
|
|
14
|
+
readonly size?: number | undefined;
|
|
15
|
+
readonly url?: string | undefined;
|
|
16
|
+
}[] | undefined;
|
|
10
17
|
}, Omit<EventInput, "payload" | "type"> & {
|
|
11
18
|
readonly type: "agent.message.received";
|
|
12
19
|
readonly payload: {
|
|
13
20
|
readonly message: {
|
|
14
21
|
readonly role: "assistant" | "system" | "tool" | "user";
|
|
15
22
|
readonly content: string;
|
|
23
|
+
readonly attachments?: readonly {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly mediaType: string;
|
|
26
|
+
readonly name?: string | undefined;
|
|
27
|
+
readonly size?: number | undefined;
|
|
28
|
+
readonly url?: string | undefined;
|
|
29
|
+
}[] | undefined;
|
|
16
30
|
readonly toolCallId?: string | undefined;
|
|
17
31
|
readonly name?: string | undefined;
|
|
18
32
|
readonly toolCalls?: {
|
|
@@ -33,6 +47,13 @@ export declare const userMessage: import("@swirls/looms/core").SignalDefinition<
|
|
|
33
47
|
*/
|
|
34
48
|
export declare const steer: import("@swirls/looms/core").SignalDefinition<{
|
|
35
49
|
readonly content: string;
|
|
50
|
+
readonly attachments?: readonly {
|
|
51
|
+
readonly id: string;
|
|
52
|
+
readonly mediaType: string;
|
|
53
|
+
readonly name?: string | undefined;
|
|
54
|
+
readonly size?: number | undefined;
|
|
55
|
+
readonly url?: string | undefined;
|
|
56
|
+
}[] | undefined;
|
|
36
57
|
readonly interrupt?: boolean | undefined;
|
|
37
58
|
}, Omit<EventInput, "payload" | "type"> & {
|
|
38
59
|
readonly type: "agent.steered";
|
|
@@ -42,6 +63,13 @@ export declare const steer: import("@swirls/looms/core").SignalDefinition<{
|
|
|
42
63
|
readonly message: {
|
|
43
64
|
readonly role: "assistant" | "system" | "tool" | "user";
|
|
44
65
|
readonly content: string;
|
|
66
|
+
readonly attachments?: readonly {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly mediaType: string;
|
|
69
|
+
readonly name?: string | undefined;
|
|
70
|
+
readonly size?: number | undefined;
|
|
71
|
+
readonly url?: string | undefined;
|
|
72
|
+
}[] | undefined;
|
|
45
73
|
readonly toolCallId?: string | undefined;
|
|
46
74
|
readonly name?: string | undefined;
|
|
47
75
|
readonly toolCalls?: {
|
|
@@ -70,6 +98,13 @@ export interface AgentSessionMessageOptions {
|
|
|
70
98
|
export declare const submitAgentMessage: import("@swirls/looms/core").SignalDefinition<{
|
|
71
99
|
readonly messageId: string;
|
|
72
100
|
readonly text: string;
|
|
101
|
+
readonly attachments?: readonly {
|
|
102
|
+
readonly id: string;
|
|
103
|
+
readonly mediaType: string;
|
|
104
|
+
readonly name?: string | undefined;
|
|
105
|
+
readonly size?: number | undefined;
|
|
106
|
+
readonly url?: string | undefined;
|
|
107
|
+
}[] | undefined;
|
|
73
108
|
readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
|
|
74
109
|
readonly activeChildThreadId?: string | undefined;
|
|
75
110
|
}, Omit<EventInput, "payload" | "type"> & {
|
|
@@ -77,6 +112,13 @@ export declare const submitAgentMessage: import("@swirls/looms/core").SignalDefi
|
|
|
77
112
|
readonly payload: {
|
|
78
113
|
readonly messageId: string;
|
|
79
114
|
readonly text: string;
|
|
115
|
+
readonly attachments?: readonly {
|
|
116
|
+
readonly id: string;
|
|
117
|
+
readonly mediaType: string;
|
|
118
|
+
readonly name?: string | undefined;
|
|
119
|
+
readonly size?: number | undefined;
|
|
120
|
+
readonly url?: string | undefined;
|
|
121
|
+
}[] | undefined;
|
|
80
122
|
readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
|
|
81
123
|
readonly activeChildThreadId?: string | undefined;
|
|
82
124
|
};
|
|
@@ -108,6 +150,13 @@ interface AgentSessionSignalClient<Result> {
|
|
|
108
150
|
export declare const agentSessionMessageEvents: import("@swirls/looms/core").SignalDefinition<{
|
|
109
151
|
readonly messageId: string;
|
|
110
152
|
readonly text: string;
|
|
153
|
+
readonly attachments?: readonly {
|
|
154
|
+
readonly id: string;
|
|
155
|
+
readonly mediaType: string;
|
|
156
|
+
readonly name?: string | undefined;
|
|
157
|
+
readonly size?: number | undefined;
|
|
158
|
+
readonly url?: string | undefined;
|
|
159
|
+
}[] | undefined;
|
|
111
160
|
readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
|
|
112
161
|
readonly activeChildThreadId?: string | undefined;
|
|
113
162
|
}, ((Omit<EventInput, "payload" | "type"> & {
|
|
@@ -115,6 +164,13 @@ export declare const agentSessionMessageEvents: import("@swirls/looms/core").Sig
|
|
|
115
164
|
readonly payload: {
|
|
116
165
|
readonly messageId: string;
|
|
117
166
|
readonly text: string;
|
|
167
|
+
readonly attachments?: readonly {
|
|
168
|
+
readonly id: string;
|
|
169
|
+
readonly mediaType: string;
|
|
170
|
+
readonly name?: string | undefined;
|
|
171
|
+
readonly size?: number | undefined;
|
|
172
|
+
readonly url?: string | undefined;
|
|
173
|
+
}[] | undefined;
|
|
118
174
|
readonly delivery?: "followUp" | "nextTurn" | "steer" | undefined;
|
|
119
175
|
readonly activeChildThreadId?: string | undefined;
|
|
120
176
|
};
|
|
@@ -126,6 +182,13 @@ export declare const agentSessionMessageEvents: import("@swirls/looms/core").Sig
|
|
|
126
182
|
readonly message: {
|
|
127
183
|
readonly role: "assistant" | "system" | "tool" | "user";
|
|
128
184
|
readonly content: string;
|
|
185
|
+
readonly attachments?: readonly {
|
|
186
|
+
readonly id: string;
|
|
187
|
+
readonly mediaType: string;
|
|
188
|
+
readonly name?: string | undefined;
|
|
189
|
+
readonly size?: number | undefined;
|
|
190
|
+
readonly url?: string | undefined;
|
|
191
|
+
}[] | undefined;
|
|
129
192
|
readonly toolCallId?: string | undefined;
|
|
130
193
|
readonly name?: string | undefined;
|
|
131
194
|
readonly toolCalls?: {
|
package/dist/agent/signals.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Predicate, Schema } from 'effect';
|
|
2
2
|
import { AgentSessionMessageSubmittedPayloadSchema } from './events.js';
|
|
3
3
|
import { agentModule } from './scope.js';
|
|
4
|
+
import { AttachmentSchema, userLine } from './types.js';
|
|
4
5
|
const UserMessageInputSchema = Schema.Struct({
|
|
5
6
|
content: Schema.String,
|
|
7
|
+
attachments: Schema.optional(Schema.Array(AttachmentSchema)),
|
|
6
8
|
});
|
|
7
9
|
const SteerInputSchema = Schema.Struct({
|
|
8
10
|
content: Schema.String,
|
|
11
|
+
attachments: Schema.optional(Schema.Array(AttachmentSchema)),
|
|
9
12
|
interrupt: Schema.optional(Schema.Boolean),
|
|
10
13
|
});
|
|
11
14
|
const CancelAgentTurnInputSchema = Schema.Struct({
|
|
@@ -18,7 +21,7 @@ const CancelAgentTurnInputSchema = Schema.Struct({
|
|
|
18
21
|
export const userMessage = agentModule.signal({
|
|
19
22
|
description: 'Append a user message to a conversational agent.',
|
|
20
23
|
input: UserMessageInputSchema,
|
|
21
|
-
build: ({ content }) => agentModule.input('message.received', { message:
|
|
24
|
+
build: ({ content, attachments }) => agentModule.input('message.received', { message: userLine(content, attachments) }),
|
|
22
25
|
});
|
|
23
26
|
/**
|
|
24
27
|
* Build the `agent.steered` event: inject a user message mid-run.
|
|
@@ -31,10 +34,10 @@ export const userMessage = agentModule.signal({
|
|
|
31
34
|
export const steer = agentModule.signal({
|
|
32
35
|
description: 'Inject a user message mid-run. Interrupt abandons the current turn; otherwise the message waits for the next turn (which starts immediately if the agent is idle).',
|
|
33
36
|
input: SteerInputSchema,
|
|
34
|
-
build: ({ content, interrupt }) => agentModule.input('steered', {
|
|
37
|
+
build: ({ content, attachments, interrupt }) => agentModule.input('steered', {
|
|
35
38
|
turn: 0,
|
|
36
39
|
interrupt: interrupt ?? true,
|
|
37
|
-
message:
|
|
40
|
+
message: userLine(content, attachments),
|
|
38
41
|
}),
|
|
39
42
|
});
|
|
40
43
|
/**
|
|
@@ -92,7 +95,7 @@ export const agentSessionMessageEvents = agentModule.signal({
|
|
|
92
95
|
agentModule.input('steered', {
|
|
93
96
|
turn: 0,
|
|
94
97
|
messageId: input.messageId,
|
|
95
|
-
message:
|
|
98
|
+
message: userLine(input.text, input.attachments),
|
|
96
99
|
interrupt: true,
|
|
97
100
|
}, { threadId: input.activeChildThreadId }),
|
|
98
101
|
];
|
package/dist/agent/threads.js
CHANGED
|
@@ -4,6 +4,7 @@ import { STRUCTURED_OUTPUT_TOOL_NAME } from './definitions.js';
|
|
|
4
4
|
import { callLlmEffect, executeToolEffect } from './effects.js';
|
|
5
5
|
import { agentModule } from './scope.js';
|
|
6
6
|
import { closeOpenToolCalls, insertToolResult } from './transcript.js';
|
|
7
|
+
import { attachmentsFrom, userLine } from './types.js';
|
|
7
8
|
function inputToLine(input) {
|
|
8
9
|
if (input === null) {
|
|
9
10
|
return null;
|
|
@@ -12,17 +13,13 @@ function inputToLine(input) {
|
|
|
12
13
|
return { role: 'user', content: input };
|
|
13
14
|
}
|
|
14
15
|
if (Predicate.isObject(input)) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return { role: 'user', content: input.topic };
|
|
23
|
-
}
|
|
24
|
-
if (Predicate.isString(input.prompt)) {
|
|
25
|
-
return { role: 'user', content: input.prompt };
|
|
16
|
+
// Input shaped `{ text, attachments }` starts the agent on a message with files.
|
|
17
|
+
const attachments = attachmentsFrom(input.attachments);
|
|
18
|
+
for (const key of ['text', 'task', 'topic', 'prompt']) {
|
|
19
|
+
const content = input[key];
|
|
20
|
+
if (Predicate.isString(content)) {
|
|
21
|
+
return userLine(content, attachments);
|
|
22
|
+
}
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
return { role: 'user', content: JSON.stringify(input) };
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -8,9 +8,37 @@ export declare const ToolCallSchema: Schema.Struct<{
|
|
|
8
8
|
export type ToolCall = Schema.Schema.Type<typeof ToolCallSchema>;
|
|
9
9
|
export declare const MessageRoleSchema: Schema.Union<readonly [Schema.Literal<"system">, Schema.Literal<"user">, Schema.Literal<"assistant">, Schema.Literal<"tool">]>;
|
|
10
10
|
export type MessageRole = Schema.Schema.Type<typeof MessageRoleSchema>;
|
|
11
|
+
/**
|
|
12
|
+
* A file that travels with a message: an image, a recording, a document. The event log holds
|
|
13
|
+
* only this reference. The bytes stay wherever the application stored them, and the LLM adapter
|
|
14
|
+
* reads them back by `id` (or from `url`) when it builds a model call.
|
|
15
|
+
*/
|
|
16
|
+
export declare const AttachmentSchema: Schema.Struct<{
|
|
17
|
+
/** The application's handle on the stored bytes. */
|
|
18
|
+
readonly id: Schema.String;
|
|
19
|
+
/** IANA media type, e.g. `image/png`. */
|
|
20
|
+
readonly mediaType: Schema.String;
|
|
21
|
+
readonly name: Schema.optional<Schema.String>;
|
|
22
|
+
/** Size in bytes. */
|
|
23
|
+
readonly size: Schema.optional<Schema.Finite>;
|
|
24
|
+
/** Where a model provider can fetch the bytes itself, when the application has such a URL. */
|
|
25
|
+
readonly url: Schema.optional<Schema.String>;
|
|
26
|
+
}>;
|
|
27
|
+
export type Attachment = Schema.Schema.Type<typeof AttachmentSchema>;
|
|
11
28
|
export declare const MessageSchema: Schema.Struct<{
|
|
12
29
|
readonly role: Schema.Union<readonly [Schema.Literal<"system">, Schema.Literal<"user">, Schema.Literal<"assistant">, Schema.Literal<"tool">]>;
|
|
13
30
|
readonly content: Schema.String;
|
|
31
|
+
readonly attachments: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
32
|
+
/** The application's handle on the stored bytes. */
|
|
33
|
+
readonly id: Schema.String;
|
|
34
|
+
/** IANA media type, e.g. `image/png`. */
|
|
35
|
+
readonly mediaType: Schema.String;
|
|
36
|
+
readonly name: Schema.optional<Schema.String>;
|
|
37
|
+
/** Size in bytes. */
|
|
38
|
+
readonly size: Schema.optional<Schema.Finite>;
|
|
39
|
+
/** Where a model provider can fetch the bytes itself, when the application has such a URL. */
|
|
40
|
+
readonly url: Schema.optional<Schema.String>;
|
|
41
|
+
}>>>;
|
|
14
42
|
readonly toolCallId: Schema.optional<Schema.String>;
|
|
15
43
|
readonly name: Schema.optional<Schema.String>;
|
|
16
44
|
readonly toolCalls: Schema.optional<Schema.mutable<Schema.$Array<Schema.Struct<{
|
|
@@ -24,6 +52,17 @@ export declare const ConversationSchema: Schema.Struct<{
|
|
|
24
52
|
readonly lines: Schema.mutable<Schema.$Array<Schema.Struct<{
|
|
25
53
|
readonly role: Schema.Union<readonly [Schema.Literal<"system">, Schema.Literal<"user">, Schema.Literal<"assistant">, Schema.Literal<"tool">]>;
|
|
26
54
|
readonly content: Schema.String;
|
|
55
|
+
readonly attachments: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
56
|
+
/** The application's handle on the stored bytes. */
|
|
57
|
+
readonly id: Schema.String;
|
|
58
|
+
/** IANA media type, e.g. `image/png`. */
|
|
59
|
+
readonly mediaType: Schema.String;
|
|
60
|
+
readonly name: Schema.optional<Schema.String>;
|
|
61
|
+
/** Size in bytes. */
|
|
62
|
+
readonly size: Schema.optional<Schema.Finite>;
|
|
63
|
+
/** Where a model provider can fetch the bytes itself, when the application has such a URL. */
|
|
64
|
+
readonly url: Schema.optional<Schema.String>;
|
|
65
|
+
}>>>;
|
|
27
66
|
readonly toolCallId: Schema.optional<Schema.String>;
|
|
28
67
|
readonly name: Schema.optional<Schema.String>;
|
|
29
68
|
readonly toolCalls: Schema.optional<Schema.mutable<Schema.$Array<Schema.Struct<{
|
|
@@ -123,6 +162,7 @@ export type AgentSessionTurnStatus = 'completed' | 'failed' | 'cancelled';
|
|
|
123
162
|
export interface AgentSessionMessage {
|
|
124
163
|
readonly messageId: string;
|
|
125
164
|
readonly text: string;
|
|
165
|
+
readonly attachments?: readonly Attachment[];
|
|
126
166
|
readonly delivery?: AgentMessageDelivery;
|
|
127
167
|
readonly steeredIntoMessageId?: string;
|
|
128
168
|
}
|
|
@@ -130,6 +170,7 @@ export interface AgentSessionActiveTurn {
|
|
|
130
170
|
readonly messageId: string;
|
|
131
171
|
readonly childThreadId: string;
|
|
132
172
|
readonly text: string;
|
|
173
|
+
readonly attachments?: readonly Attachment[];
|
|
133
174
|
}
|
|
134
175
|
export interface AgentSessionClosure {
|
|
135
176
|
readonly messageId: string;
|
|
@@ -160,3 +201,11 @@ export interface AgentSessionSnapshot {
|
|
|
160
201
|
readonly lastSequence: number;
|
|
161
202
|
readonly parked: boolean;
|
|
162
203
|
}
|
|
204
|
+
/** A user line, carrying `attachments` only when there are some. */
|
|
205
|
+
export declare function userLine(content: string, attachments?: readonly Attachment[]): Message;
|
|
206
|
+
/** The attachments in untyped JSON, dropping anything that is not one. */
|
|
207
|
+
export declare function attachmentsFrom(value: JsonValue | undefined): Attachment[];
|
|
208
|
+
/** `{ attachments }` when `value` holds any, for spreading into a record that omits empty lists. */
|
|
209
|
+
export declare function attachmentsField(value: JsonValue | undefined): {
|
|
210
|
+
attachments?: Attachment[];
|
|
211
|
+
};
|
package/dist/agent/types.js
CHANGED
|
@@ -11,9 +11,26 @@ export const MessageRoleSchema = Schema.Union([
|
|
|
11
11
|
Schema.Literal('assistant'),
|
|
12
12
|
Schema.Literal('tool'),
|
|
13
13
|
]);
|
|
14
|
+
/**
|
|
15
|
+
* A file that travels with a message: an image, a recording, a document. The event log holds
|
|
16
|
+
* only this reference. The bytes stay wherever the application stored them, and the LLM adapter
|
|
17
|
+
* reads them back by `id` (or from `url`) when it builds a model call.
|
|
18
|
+
*/
|
|
19
|
+
export const AttachmentSchema = Schema.Struct({
|
|
20
|
+
/** The application's handle on the stored bytes. */
|
|
21
|
+
id: Schema.String,
|
|
22
|
+
/** IANA media type, e.g. `image/png`. */
|
|
23
|
+
mediaType: Schema.String,
|
|
24
|
+
name: Schema.optional(Schema.String),
|
|
25
|
+
/** Size in bytes. */
|
|
26
|
+
size: Schema.optional(Schema.Finite),
|
|
27
|
+
/** Where a model provider can fetch the bytes itself, when the application has such a URL. */
|
|
28
|
+
url: Schema.optional(Schema.String),
|
|
29
|
+
});
|
|
14
30
|
export const MessageSchema = Schema.Struct({
|
|
15
31
|
role: MessageRoleSchema,
|
|
16
32
|
content: Schema.String,
|
|
33
|
+
attachments: Schema.optional(Schema.Array(AttachmentSchema)),
|
|
17
34
|
toolCallId: Schema.optional(Schema.String),
|
|
18
35
|
name: Schema.optional(Schema.String),
|
|
19
36
|
toolCalls: Schema.optional(Schema.mutable(Schema.Array(ToolCallSchema))),
|
|
@@ -34,3 +51,19 @@ export const ThreadStartedPayloadSchema = Schema.Struct({
|
|
|
34
51
|
definitionVersion: Schema.String.pipe(Schema.withDecodingDefaultKey(Effect.succeed(DEFAULT_DEFINITION_VERSION))),
|
|
35
52
|
input: Schema.optional(Schema.Unknown),
|
|
36
53
|
});
|
|
54
|
+
/** A user line, carrying `attachments` only when there are some. */
|
|
55
|
+
export function userLine(content, attachments) {
|
|
56
|
+
return attachments && attachments.length > 0
|
|
57
|
+
? { role: 'user', content, attachments }
|
|
58
|
+
: { role: 'user', content };
|
|
59
|
+
}
|
|
60
|
+
const isAttachment = Schema.is(AttachmentSchema);
|
|
61
|
+
/** The attachments in untyped JSON, dropping anything that is not one. */
|
|
62
|
+
export function attachmentsFrom(value) {
|
|
63
|
+
return Array.isArray(value) ? value.filter((item) => isAttachment(item)) : [];
|
|
64
|
+
}
|
|
65
|
+
/** `{ attachments }` when `value` holds any, for spreading into a record that omits empty lists. */
|
|
66
|
+
export function attachmentsField(value) {
|
|
67
|
+
const attachments = attachmentsFrom(value);
|
|
68
|
+
return attachments.length > 0 ? { attachments } : {};
|
|
69
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { vercelLlm, type VercelLlmOptions } from './vercel-llm';
|
|
2
2
|
export { toEvaluatorAnswers, vercelEvaluator, type EvaluationModelProvider, type VercelEvaluatorOptions, } from './vercel-evaluator';
|
|
3
|
-
export { toLoomsToolCalls, toModelMessages } from './messages';
|
|
3
|
+
export { resolveAttachments, toLoomsToolCalls, toModelMessages, type AttachmentData, type AttachmentResolver, type ToModelMessagesOptions, } from './messages';
|
package/dist/ai-vercel/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { vercelLlm } from './vercel-llm.js';
|
|
2
2
|
export { toEvaluatorAnswers, vercelEvaluator, } from './vercel-evaluator.js';
|
|
3
|
-
export { toLoomsToolCalls, toModelMessages } from './messages.js';
|
|
3
|
+
export { resolveAttachments, toLoomsToolCalls, toModelMessages, } from './messages.js';
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { type ModelMessage } from 'ai';
|
|
2
|
-
import type { Message, ToolCall } from '@swirls/looms/agent';
|
|
2
|
+
import type { Attachment, Message, ToolCall } from '@swirls/looms/agent';
|
|
3
3
|
import type { JsonValue } from '@swirls/looms/core';
|
|
4
|
-
|
|
4
|
+
/** An attachment's bytes (or base64 text), or a URL the model provider can fetch. */
|
|
5
|
+
export type AttachmentData = Uint8Array | ArrayBuffer | string | URL;
|
|
6
|
+
/**
|
|
7
|
+
* Reads an attachment for a model call. Return `null` for a file the model should not be sent:
|
|
8
|
+
* one that is gone, too large, or of a type the model cannot read. The message then names the
|
|
9
|
+
* file in its text so the model knows it exists.
|
|
10
|
+
*/
|
|
11
|
+
export type AttachmentResolver = (attachment: Attachment) => AttachmentData | null | Promise<AttachmentData | null>;
|
|
12
|
+
export interface ToModelMessagesOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Attachment contents by attachment id, from `resolveAttachments`. An attachment missing here
|
|
15
|
+
* is sent by its `url` when it has one and named in the text otherwise.
|
|
16
|
+
*/
|
|
17
|
+
readonly attachments?: ReadonlyMap<string, AttachmentData>;
|
|
18
|
+
}
|
|
19
|
+
/** Resolves every attachment in `messages` once, for `toModelMessages`. */
|
|
20
|
+
export declare function resolveAttachments(messages: readonly Message[], resolve: AttachmentResolver): Promise<Map<string, AttachmentData>>;
|
|
21
|
+
export declare function toModelMessages(messages: readonly Message[], options?: ToModelMessagesOptions): ModelMessage[];
|
|
5
22
|
export declare function toLoomsToolCalls(calls: ReadonlyArray<{
|
|
6
23
|
toolCallId: string;
|
|
7
24
|
toolName: string;
|
|
@@ -17,14 +17,72 @@ function toAiJson(value) {
|
|
|
17
17
|
}
|
|
18
18
|
return converted;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
/** Resolves every attachment in `messages` once, for `toModelMessages`. */
|
|
21
|
+
export function resolveAttachments(messages, resolve) {
|
|
22
|
+
const pending = new Map();
|
|
23
|
+
for (const message of messages) {
|
|
24
|
+
for (const attachment of message.attachments ?? []) {
|
|
25
|
+
if (!pending.has(attachment.id)) {
|
|
26
|
+
// Called inside a promise so a resolver that throws rejects instead of throwing here.
|
|
27
|
+
pending.set(attachment.id, Promise.resolve().then(() => resolve(attachment)));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return Promise.all([...pending].map(([id, data]) => data.then((value) => ({ id, value })))).then((entries) => {
|
|
32
|
+
const resolved = new Map();
|
|
33
|
+
for (const { id, value } of entries) {
|
|
34
|
+
if (value !== null) {
|
|
35
|
+
resolved.set(id, value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return resolved;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function describeAttachment(attachment) {
|
|
42
|
+
return `${attachment.name ?? attachment.id} (${attachment.mediaType})`;
|
|
43
|
+
}
|
|
44
|
+
function userContent(message, attachments) {
|
|
45
|
+
const files = message.attachments ?? [];
|
|
46
|
+
if (files.length === 0) {
|
|
47
|
+
return message.content;
|
|
48
|
+
}
|
|
49
|
+
const parts = [];
|
|
50
|
+
const unsent = [];
|
|
51
|
+
for (const attachment of files) {
|
|
52
|
+
const data = attachments?.get(attachment.id) ?? (attachment.url ? new URL(attachment.url) : null);
|
|
53
|
+
if (data === null) {
|
|
54
|
+
unsent.push(describeAttachment(attachment));
|
|
55
|
+
}
|
|
56
|
+
else if (attachment.mediaType.startsWith('image/')) {
|
|
57
|
+
parts.push({ type: 'image', image: data, mediaType: attachment.mediaType });
|
|
58
|
+
}
|
|
59
|
+
else if (attachment.name) {
|
|
60
|
+
parts.push({
|
|
61
|
+
type: 'file',
|
|
62
|
+
data,
|
|
63
|
+
mediaType: attachment.mediaType,
|
|
64
|
+
filename: attachment.name,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
parts.push({ type: 'file', data, mediaType: attachment.mediaType });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const note = unsent.length > 0 ? `[Attached, not shown to the model: ${unsent.join(', ')}]` : '';
|
|
72
|
+
const text = [message.content, note].filter(Boolean).join('\n\n');
|
|
73
|
+
if (parts.length === 0) {
|
|
74
|
+
return text;
|
|
75
|
+
}
|
|
76
|
+
return text ? [{ type: 'text', text }, ...parts] : parts;
|
|
77
|
+
}
|
|
78
|
+
export function toModelMessages(messages, options = {}) {
|
|
21
79
|
const converted = [];
|
|
22
80
|
for (const message of messages) {
|
|
23
81
|
switch (message.role) {
|
|
24
82
|
case 'system':
|
|
25
83
|
break;
|
|
26
84
|
case 'user':
|
|
27
|
-
converted.push({ role: 'user', content: message.
|
|
85
|
+
converted.push({ role: 'user', content: userContent(message, options.attachments) });
|
|
28
86
|
break;
|
|
29
87
|
case 'assistant': {
|
|
30
88
|
const toolCalls = message.toolCalls ?? [];
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { type LanguageModel } from 'ai';
|
|
2
2
|
import type { LlmAdapter } from '@swirls/looms/agent';
|
|
3
|
+
import { type AttachmentResolver } from './messages';
|
|
3
4
|
export interface VercelLlmOptions {
|
|
4
5
|
readonly model: LanguageModel;
|
|
5
6
|
/** Prefer streamText when the turn supplies `onTextDelta`. Default true. */
|
|
6
7
|
readonly stream?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Reads the files attached to messages. Without it, an attachment is sent by its `url` when
|
|
10
|
+
* it has one and is only named to the model otherwise.
|
|
11
|
+
*/
|
|
12
|
+
readonly resolveAttachment?: AttachmentResolver;
|
|
7
13
|
}
|
|
8
14
|
export declare function vercelLlm(options: VercelLlmOptions): LlmAdapter;
|