@meetopenbot/openbot 1.0.2 → 1.0.3

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 (2) hide show
  1. package/dist/images.js +22 -7
  2. package/package.json +1 -1
package/dist/images.js CHANGED
@@ -28,23 +28,38 @@ export function pickVisionModel(authMode, env = process.env) {
28
28
  return 'anthropic/claude-haiku-4-5';
29
29
  return undefined;
30
30
  }
31
+ function invokeRole(role) {
32
+ return role === 'agent' ? 'user' : role;
33
+ }
31
34
  /** Put image files on matching user messages as AI SDK `file` parts. */
32
35
  export async function addImageParts(messages, events, read) {
33
36
  const result = [...messages];
34
- let userIndex = 0;
37
+ let userCursor = 0;
38
+ const takeNextUserMessageIndex = () => {
39
+ while (userCursor < result.length) {
40
+ const index = userCursor;
41
+ userCursor += 1;
42
+ if (result[index]?.role === 'user')
43
+ return index;
44
+ }
45
+ return -1;
46
+ };
35
47
  for (const event of events) {
36
48
  if (event.meta?.parentToolCallId)
37
49
  continue;
38
50
  if (event.type !== 'agent:invoke' || !event.data?.role)
39
51
  continue;
40
- const files = (event.data.attachments ?? []).filter(isImageAttachment);
52
+ const attachments = event.data.attachments ?? [];
41
53
  const text = event.data.content ?? '';
42
- if (!text && files.length === 0)
54
+ if (!text && attachments.length === 0)
55
+ continue;
56
+ if (invokeRole(event.data.role) !== 'user')
43
57
  continue;
44
- const current = result[userIndex];
45
- userIndex += 1;
46
- if (!current || files.length === 0)
58
+ const index = takeNextUserMessageIndex();
59
+ const files = attachments.filter(isImageAttachment);
60
+ if (index === -1 || files.length === 0)
47
61
  continue;
62
+ const current = result[index];
48
63
  const parts = [];
49
64
  if (typeof current.content === 'string' && current.content) {
50
65
  parts.push({ type: 'text', text: current.content });
@@ -60,7 +75,7 @@ export async function addImageParts(messages, events, read) {
60
75
  });
61
76
  }
62
77
  if (parts.some((part) => part.type === 'file')) {
63
- result[userIndex - 1] = { role: current.role, content: parts };
78
+ result[index] = { role: 'user', content: parts };
64
79
  }
65
80
  }
66
81
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/openbot",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "OpenBot coordinator runtime: ask specialists, route work into Spaces, and track todos.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",