@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.
@@ -1,4 +1,4 @@
1
- import { BOARD_ACTOR, BoardError, TASK_LABEL, } from './board.js';
1
+ import { BOARD_ACTOR, BoardError, MAX_ATTACHMENTS, TASK_LABEL, } from './board.js';
2
2
  class Mismatch extends Error {
3
3
  }
4
4
  function expect(condition, message) {
@@ -19,6 +19,9 @@ async function refused(attempt, code) {
19
19
  }
20
20
  throw new Mismatch(`expected a BoardError with code "${code}", but the call succeeded`);
21
21
  }
22
+ function sameFiles(actual, expected) {
23
+ return JSON.stringify(actual) === JSON.stringify(expected);
24
+ }
22
25
  const checks = {
23
26
  'a post is read back with its mentions': async (board) => {
24
27
  const posted = await board.post({ by: 'ada', channel: 'ops', text: 'ping @Bo and @cy, @bo' });
@@ -63,6 +66,56 @@ const checks = {
63
66
  expect(latest.map((item) => item.text).join(',') === '2,3', 'limit must keep the latest');
64
67
  expect(after.map((item) => item.text).join(',') === '2', 'after must page forward');
65
68
  },
69
+ 'attachments are read back with their message': async (board) => {
70
+ const shot = { id: 'files/1', mediaType: 'image/png', name: 'login.png', size: 2_048 };
71
+ const clip = { id: 'files/2', mediaType: 'video/mp4', url: 'https://files.example/2' };
72
+ const root = await board.post({
73
+ by: 'ada',
74
+ channel: 'ops',
75
+ text: 'see these',
76
+ attachments: [shot, clip],
77
+ });
78
+ const reply = await board.reply({
79
+ by: 'bo',
80
+ to: root.id,
81
+ text: 'and this',
82
+ attachments: [clip],
83
+ });
84
+ const plain = await board.reply({ by: 'bo', to: root.id, text: 'no files' });
85
+ const task = await board.createTask({
86
+ by: 'ada',
87
+ channel: 'ops',
88
+ text: 'fix',
89
+ attachments: [shot],
90
+ });
91
+ const [read] = await board.messages({ id: root.id });
92
+ const [taskRoot] = await board.messages({ id: task.id });
93
+ const page = await board.events();
94
+ const created = page.events.find((event) => event.type === 'task.created');
95
+ expect(sameFiles(root.attachments, [shot, clip]), 'a post did not return its attachments in order');
96
+ expect(sameFiles(read?.attachments, [shot, clip]), 'a post was not read back with its attachments');
97
+ expect(sameFiles(reply.attachments, [clip]), 'a reply did not keep its attachments');
98
+ expect(sameFiles(plain.attachments, []), 'a message without files must have an empty list');
99
+ expect(sameFiles(taskRoot?.attachments, [shot]), "a task's root message lost its attachments");
100
+ expect(sameFiles(created?.message?.attachments, [shot]), 'task.created lost the attachments');
101
+ await refused(board.post({
102
+ by: 'ada',
103
+ channel: 'ops',
104
+ text: 'too many',
105
+ attachments: Array.from({ length: MAX_ATTACHMENTS + 1 }, (_, index) => ({
106
+ id: `files/many-${index}`,
107
+ mediaType: 'image/png',
108
+ })),
109
+ }), 'invalid_input');
110
+ },
111
+ 'a message is read by its id': async (board) => {
112
+ const root = await board.post({ by: 'ada', channel: 'ops', text: 'root' });
113
+ const reply = await board.reply({ by: 'bo', to: root.id, text: 'reply' });
114
+ const one = await board.messages({ id: reply.id });
115
+ const none = await board.messages({ id: 'missing' });
116
+ expect(one.length === 1 && one[0]?.text === 'reply', 'a reply was not read by its id');
117
+ expect(none.length === 0, 'an unknown id must match nothing');
118
+ },
66
119
  'labels compare and set': async (board) => {
67
120
  const message = await board.post({ by: 'ada', channel: 'ops', text: 'x' });
68
121
  await board.label({ by: 'ada', message: message.id, set: { state: 'open' } });
@@ -70,6 +70,13 @@ export declare const ActivationSchema: Schema.Struct<{
70
70
  readonly re: Schema.NullOr<Schema.String>;
71
71
  readonly mentions: Schema.$Array<Schema.String>;
72
72
  readonly labels: Schema.$Record<Schema.String, Schema.String>;
73
+ readonly attachments: Schema.$Array<Schema.Struct<{
74
+ readonly id: Schema.String;
75
+ readonly mediaType: Schema.String;
76
+ readonly name: Schema.optional<Schema.String>;
77
+ readonly size: Schema.optional<Schema.Finite>;
78
+ readonly url: Schema.optional<Schema.String>;
79
+ }>>;
73
80
  readonly createdAt: Schema.Finite;
74
81
  }>>;
75
82
  readonly task: Schema.optional<Schema.Struct<{
@@ -88,6 +95,14 @@ export declare const ActivationSchema: Schema.Struct<{
88
95
  readonly updatedAt: Schema.Finite;
89
96
  }>>;
90
97
  }>>;
98
+ /** Files on the messages that woke the member. They travel with its first user message. */
99
+ readonly attachments: Schema.optional<Schema.$Array<Schema.Struct<{
100
+ readonly id: Schema.String;
101
+ readonly mediaType: Schema.String;
102
+ readonly name: Schema.optional<Schema.String>;
103
+ readonly size: Schema.optional<Schema.Finite>;
104
+ readonly url: Schema.optional<Schema.String>;
105
+ }>>>;
91
106
  }>;
92
107
  export type Activation = Schema.Schema.Type<typeof ActivationSchema>;
93
108
  /** The activation in a member run's input, or null when the run was not started by a swarm. */
@@ -1,4 +1,5 @@
1
1
  import { Option, Schema } from 'effect';
2
+ import { AttachmentSchema } from '@swirls/looms/agent';
2
3
  import { DEFAULT_DEFINITION_VERSION, createKind, } from '@swirls/looms/core';
3
4
  import { BoardEventSchema } from './board.js';
4
5
  const swarmKind = createKind('swarm');
@@ -43,6 +44,8 @@ export const ActivationSchema = Schema.Struct({
43
44
  activation: Schema.Finite,
44
45
  }),
45
46
  events: Schema.Array(BoardEventSchema),
47
+ /** Files on the messages that woke the member. They travel with its first user message. */
48
+ attachments: Schema.optional(Schema.Array(AttachmentSchema)),
46
49
  });
47
50
  const decodeActivation = Schema.decodeUnknownOption(ActivationSchema);
48
51
  /** The activation in a member run's input, or null when the run was not started by a swarm. */