@swirls/looms 0.13.1 → 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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @swirls/looms
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9e870dc: Agent messages can carry attachments: images, recordings, documents and other files. A message's `attachments` is a list of references (`id`, `mediaType`, and optionally `name`, `size` and `url`), so the event log never holds the bytes. `userMessage`, `steer` and agent session messages accept `attachments`, and an agent started with input shaped `{ text, attachments }` begins on a message that has them. `vercelLlm` takes a `resolveAttachment` option that reads an attachment's bytes for a model call; images are sent as image parts and everything else as file parts. An attachment the resolver returns `null` for is sent by its `url` when it has one and is named in the message text otherwise. Adapters that build their own model call can use `resolveAttachments` with `toModelMessages(messages, { attachments })`.
8
+
9
+ ## 0.13.2
10
+
11
+ ### Patch Changes
12
+
13
+ - 06942de: An in-process effect whose attempts keep being lost now fails instead of being re-attempted without limit. When a wake finds an attempt that an earlier wake started and never finished, because its process was lost or the wake failed, it still starts the next attempt, but only while attempts remain: up to the effect's `maxAttempts`, or three attempts when the effect has no retry policy. After that the effect fails with `attempt N was lost before it finished, and no attempts remain`. Attempts ended by a signal in the same wake, such as steering an agent, are not treated as lost.
14
+
3
15
  ## 0.13.1
4
16
 
5
17
  ### Patch Changes
@@ -1,6 +1,7 @@
1
1
  import { Predicate } from 'effect';
2
2
  import { cancel, createWaitId, deterministicThreadId, emit, spawn, wait, } from '@swirls/looms/core';
3
3
  import { agentModule } from './scope.js';
4
+ import { attachmentsField, userLine } from './types.js';
4
5
  function objectPayload(event) {
5
6
  return Predicate.isObject(event.payload) ? event.payload : {};
6
7
  }
@@ -10,6 +11,7 @@ function messageFrom(value) {
10
11
  ? {
11
12
  messageId: payload.messageId,
12
13
  text: payload.text,
14
+ ...attachmentsField(payload.attachments),
13
15
  delivery: payload.delivery === 'steer' ||
14
16
  payload.delivery === 'followUp' ||
15
17
  payload.delivery === 'nextTurn'
@@ -113,17 +115,16 @@ export function createAgentSessionThread(definitions) {
113
115
  case 'agent.session.turn.started': {
114
116
  const messageId = event.payload.messageId;
115
117
  const admitted = state.pendingMessages.find((message) => message.messageId === messageId);
116
- const text = [...state.nextTurnMessages, ...(admitted ? [admitted] : [])]
117
- .map((message) => message.text)
118
- .join('\n');
118
+ const turnMessages = [...state.nextTurnMessages, ...(admitted ? [admitted] : [])];
119
+ const text = turnMessages.map((message) => message.text).join('\n');
120
+ const attachments = turnMessages.flatMap((message) => message.attachments ?? []);
121
+ const activeTurn = attachments.length > 0
122
+ ? { messageId, childThreadId: event.payload.childThreadId, text, attachments }
123
+ : { messageId, childThreadId: event.payload.childThreadId, text };
119
124
  return {
120
125
  ...state,
121
126
  pendingMessages: state.pendingMessages.filter((message) => message.messageId !== messageId),
122
- activeTurn: {
123
- messageId,
124
- childThreadId: event.payload.childThreadId,
125
- text,
126
- },
127
+ activeTurn,
127
128
  nextTurnMessages: [],
128
129
  lastSequence: state.lastSequence + 1,
129
130
  cancelling: false,
@@ -198,12 +199,12 @@ export function createAgentSessionThread(definitions) {
198
199
  effects.push(emit(agentModule.input('steered', {
199
200
  turn: 0,
200
201
  messageId: message.messageId,
201
- message: { role: 'user', content: message.text },
202
+ message: userLine(message.text, message.attachments),
202
203
  interrupt: true,
203
204
  }, { threadId: state.activeTurn.childThreadId }), `session_steer_${message.messageId}`), emit(agentModule.input('session.steer.delivered', { messageId: message.messageId, activeMessageId: state.activeTurn.messageId }, { threadId: ctx.threadId }), `session_steer_delivered_${message.messageId}`));
204
205
  }
205
206
  if (state.activeTurn) {
206
- const { childThreadId: turnThreadId, messageId, text } = state.activeTurn;
207
+ const { childThreadId: turnThreadId, messageId, text, attachments } = state.activeTurn;
207
208
  const definition = definitions.get(state.definitionName, state.definitionVersion);
208
209
  if (state.cancelling) {
209
210
  effects.push(cancel(turnThreadId));
@@ -214,7 +215,7 @@ export function createAgentSessionThread(definitions) {
214
215
  kind: 'agent',
215
216
  definitionName: definition.agent.name,
216
217
  definitionVersion: definition.agent.version,
217
- input: { text },
218
+ input: attachments ? { text, attachments: [...attachments] } : { text },
218
219
  }));
219
220
  }
220
221
  // The turn wait must survive cancellation: the child's cancelled event is what closes it.