@songsid/agend 2.4.0-beta.11 → 2.4.0-beta.12

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 (165) hide show
  1. package/dist/accounts-view.d.ts +29 -0
  2. package/dist/accounts-view.js +2 -14
  3. package/dist/accounts-view.js.map +1 -1
  4. package/dist/agent-endpoint.d.ts +1 -0
  5. package/dist/agent-endpoint.js +4 -2
  6. package/dist/agent-endpoint.js.map +1 -1
  7. package/dist/auth-api.d.ts +2 -0
  8. package/dist/auth-api.js +28 -2
  9. package/dist/auth-api.js.map +1 -1
  10. package/dist/build-provenance.json +1 -1
  11. package/dist/channel/mcp-server.js +1 -1
  12. package/dist/channel/mcp-server.js.map +1 -1
  13. package/dist/channel/mcp-tools.js +3 -1
  14. package/dist/channel/mcp-tools.js.map +1 -1
  15. package/dist/claude-install-kind.d.ts +19 -0
  16. package/dist/claude-install-kind.js +54 -0
  17. package/dist/claude-install-kind.js.map +1 -0
  18. package/dist/daemon.d.ts +5 -0
  19. package/dist/daemon.js +20 -2
  20. package/dist/daemon.js.map +1 -1
  21. package/dist/fleet-manager.d.ts +105 -1
  22. package/dist/fleet-manager.js +366 -24
  23. package/dist/fleet-manager.js.map +1 -1
  24. package/dist/general-knowledge/skills/hub/SKILL.md +25 -0
  25. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +6 -0
  26. package/dist/hub/agent-intro-model.d.ts +38 -0
  27. package/dist/hub/agent-intro-model.js +14 -0
  28. package/dist/hub/agent-intro-model.js.map +1 -0
  29. package/dist/hub/agent-intro-tool.d.ts +35 -0
  30. package/dist/hub/agent-intro-tool.js +83 -0
  31. package/dist/hub/agent-intro-tool.js.map +1 -0
  32. package/dist/hub/client.d.ts +1 -0
  33. package/dist/hub/client.js +26 -0
  34. package/dist/hub/client.js.map +1 -1
  35. package/dist/hub/compose/member.d.ts +13 -5
  36. package/dist/hub/compose/member.js +28 -5
  37. package/dist/hub/compose/member.js.map +1 -1
  38. package/dist/hub/compose/server.d.ts +1 -0
  39. package/dist/hub/compose/server.js +5 -1
  40. package/dist/hub/compose/server.js.map +1 -1
  41. package/dist/hub/http/compose.d.ts +1 -0
  42. package/dist/hub/http/compose.js +28 -5
  43. package/dist/hub/http/compose.js.map +1 -1
  44. package/dist/hub/http/schema.js +6 -0
  45. package/dist/hub/http/schema.js.map +1 -1
  46. package/dist/hub/member/agent-intro.d.ts +28 -0
  47. package/dist/hub/member/agent-intro.js +66 -0
  48. package/dist/hub/member/agent-intro.js.map +1 -0
  49. package/dist/hub/member/room-ask.d.ts +10 -0
  50. package/dist/hub/member/room-ask.js +70 -7
  51. package/dist/hub/member/room-ask.js.map +1 -1
  52. package/dist/hub/member/room-notification.d.ts +1 -1
  53. package/dist/hub/member/room-post.d.ts +6 -3
  54. package/dist/hub/member/room-post.js +9 -3
  55. package/dist/hub/member/room-post.js.map +1 -1
  56. package/dist/hub/protocol.d.ts +172 -4
  57. package/dist/hub/protocol.js +10 -5
  58. package/dist/hub/protocol.js.map +1 -1
  59. package/dist/hub/room-answer-status-model.d.ts +3 -0
  60. package/dist/hub/room-answer-status-model.js +4 -0
  61. package/dist/hub/room-answer-status-model.js.map +1 -0
  62. package/dist/hub/room-brief-model.d.ts +30 -0
  63. package/dist/hub/room-brief-model.js +37 -0
  64. package/dist/hub/room-brief-model.js.map +1 -0
  65. package/dist/hub/room-context-model.d.ts +2 -0
  66. package/dist/hub/room-context-model.js +2 -2
  67. package/dist/hub/room-context-model.js.map +1 -1
  68. package/dist/hub/room-members-model.d.ts +63 -0
  69. package/dist/hub/room-members-model.js +7 -0
  70. package/dist/hub/room-members-model.js.map +1 -0
  71. package/dist/hub/rooms/agents.js +50 -10
  72. package/dist/hub/rooms/agents.js.map +1 -1
  73. package/dist/hub/rooms/brief.d.ts +18 -0
  74. package/dist/hub/rooms/brief.js +39 -0
  75. package/dist/hub/rooms/brief.js.map +1 -0
  76. package/dist/hub/rooms/members-page.d.ts +33 -0
  77. package/dist/hub/rooms/members-page.js +37 -0
  78. package/dist/hub/rooms/members-page.js.map +1 -0
  79. package/dist/hub/rooms/purpose.d.ts +7 -0
  80. package/dist/hub/rooms/purpose.js +14 -0
  81. package/dist/hub/rooms/purpose.js.map +1 -0
  82. package/dist/hub/rooms/service.d.ts +11 -0
  83. package/dist/hub/rooms/service.js +56 -12
  84. package/dist/hub/rooms/service.js.map +1 -1
  85. package/dist/hub/rooms/types.d.ts +6 -2
  86. package/dist/hub/runtime.d.ts +1 -1
  87. package/dist/hub/server.js +27 -1
  88. package/dist/hub/server.js.map +1 -1
  89. package/dist/hub/types.d.ts +9 -5
  90. package/dist/hub-room-reply-warning.d.ts +2 -0
  91. package/dist/hub-room-reply-warning.js +16 -0
  92. package/dist/hub-room-reply-warning.js.map +1 -0
  93. package/dist/instance-lifecycle.d.ts +15 -0
  94. package/dist/instance-lifecycle.js +36 -1
  95. package/dist/instance-lifecycle.js.map +1 -1
  96. package/dist/locale.js +20 -0
  97. package/dist/locale.js.map +1 -1
  98. package/dist/login-controller.d.ts +26 -0
  99. package/dist/login-controller.js +72 -2
  100. package/dist/login-controller.js.map +1 -1
  101. package/dist/native-mcp.js +1 -1
  102. package/dist/native-mcp.js.map +1 -1
  103. package/dist/needs-you-hub.js +1 -1
  104. package/dist/needs-you-hub.js.map +1 -1
  105. package/dist/needs-you.d.ts +8 -1
  106. package/dist/needs-you.js +5 -0
  107. package/dist/needs-you.js.map +1 -1
  108. package/dist/outbound-handlers.d.ts +2 -1
  109. package/dist/outbound-handlers.js +17 -4
  110. package/dist/outbound-handlers.js.map +1 -1
  111. package/dist/outbound-schemas.d.ts +10 -0
  112. package/dist/outbound-schemas.js +3 -1
  113. package/dist/outbound-schemas.js.map +1 -1
  114. package/dist/public-web-gateway.js +5 -1
  115. package/dist/public-web-gateway.js.map +1 -1
  116. package/dist/restart-progress.d.ts +6 -0
  117. package/dist/restart-progress.js +5 -0
  118. package/dist/restart-progress.js.map +1 -1
  119. package/dist/settings-effect.js +17 -1
  120. package/dist/settings-effect.js.map +1 -1
  121. package/dist/tool-permissions.js +3 -3
  122. package/dist/tool-permissions.js.map +1 -1
  123. package/dist/ui/chat-quote.js +3 -261
  124. package/dist/ui/host-install.js +77 -3
  125. package/dist/ui/hub-agent-intro.js +15 -6
  126. package/dist/ui/hub-attachments.js +81 -3
  127. package/dist/ui/hub-client.js +4 -0
  128. package/dist/ui/hub-intro-notice.js +16 -0
  129. package/dist/ui/hub-my-agents.js +5 -2
  130. package/dist/ui/hub-room-composer.js +10 -2
  131. package/dist/ui/hub-room-list.js +1 -1
  132. package/dist/ui/hub-room-members.js +2 -0
  133. package/dist/ui/hub-room-new.js +7 -4
  134. package/dist/ui/hub-room-purpose.js +19 -0
  135. package/dist/ui/hub-room-search.js +1 -1
  136. package/dist/ui/hub-room-settings.js +9 -0
  137. package/dist/ui/hub-room-strings.js +6 -4
  138. package/dist/ui/hub-room-thread.js +68 -17
  139. package/dist/ui/panel-chat.js +19 -5
  140. package/dist/ui/panel-hub.js +61 -18
  141. package/dist/ui/shared/app-i18n.js +2 -2
  142. package/dist/ui/shared/app-shell.js +6 -0
  143. package/dist/ui/shared/app.js +3 -1
  144. package/dist/ui/shared/chat-msg-actions.js +3 -1
  145. package/dist/ui/shared/chat-quote.js +261 -0
  146. package/dist/ui/shared/hub-chat.css +28 -0
  147. package/dist/ui/shared/hub-rooms-u2.css +5 -0
  148. package/dist/ui/shared/module-warm.d.ts +3 -0
  149. package/dist/ui/shared/module-warm.js +39 -0
  150. package/dist/web-api.d.ts +17 -4
  151. package/dist/web-api.js +83 -6
  152. package/dist/web-api.js.map +1 -1
  153. package/dist/web-asset-version.d.ts +65 -0
  154. package/dist/web-asset-version.js +259 -0
  155. package/dist/web-asset-version.js.map +1 -0
  156. package/dist/web-host-guard.js +3 -1
  157. package/dist/web-host-guard.js.map +1 -1
  158. package/dist/web-host-install.d.ts +30 -3
  159. package/dist/web-host-install.js +50 -4
  160. package/dist/web-host-install.js.map +1 -1
  161. package/dist/web-terminal.d.ts +5 -0
  162. package/dist/web-terminal.js +11 -0
  163. package/dist/web-terminal.js.map +1 -1
  164. package/launcher/agend-install.cjs +48 -7
  165. package/package.json +1 -1
@@ -94,6 +94,7 @@ export declare class HubGroupRooms {
94
94
  private agentRoomChoices;
95
95
  agentPost(input: unknown, link: HubLinkContext): Promise<HubRoomPostResult>;
96
96
  private insert;
97
+ private recordPurpose;
97
98
  private summary;
98
99
  private addAssistant;
99
100
  private assistantRoom;
@@ -102,6 +103,7 @@ export declare class HubGroupRooms {
102
103
  id: string;
103
104
  kind: "group";
104
105
  name: string;
106
+ purpose: string;
105
107
  people: number;
106
108
  agents: number;
107
109
  online: number;
@@ -115,6 +117,7 @@ export declare class HubGroupRooms {
115
117
  } | {
116
118
  id: string;
117
119
  name: string;
120
+ purpose: string;
118
121
  people: number;
119
122
  agents: number;
120
123
  online: number;
@@ -173,6 +176,7 @@ export declare class HubGroupRooms {
173
176
  id: string;
174
177
  kind: "group";
175
178
  name: string;
179
+ purpose: string;
176
180
  people: number;
177
181
  agents: number;
178
182
  online: number;
@@ -186,6 +190,7 @@ export declare class HubGroupRooms {
186
190
  } | {
187
191
  id: string;
188
192
  name: string;
193
+ purpose: string;
189
194
  people: number;
190
195
  agents: number;
191
196
  online: number;
@@ -206,6 +211,7 @@ export declare class HubGroupRooms {
206
211
  id: string;
207
212
  kind: "group";
208
213
  name: string;
214
+ purpose: string;
209
215
  people: number;
210
216
  agents: number;
211
217
  online: number;
@@ -220,6 +226,7 @@ export declare class HubGroupRooms {
220
226
  } | {
221
227
  id: string;
222
228
  name: string;
229
+ purpose: string;
223
230
  people: number;
224
231
  agents: number;
225
232
  online: number;
@@ -319,6 +326,7 @@ export declare class HubGroupRooms {
319
326
  id: string;
320
327
  kind: "group";
321
328
  name: string;
329
+ purpose: string;
322
330
  people: number;
323
331
  agents: number;
324
332
  online: number;
@@ -333,6 +341,7 @@ export declare class HubGroupRooms {
333
341
  } | {
334
342
  id: string;
335
343
  name: string;
344
+ purpose: string;
336
345
  people: number;
337
346
  agents: number;
338
347
  online: number;
@@ -432,6 +441,7 @@ export declare class HubGroupRooms {
432
441
  id: string;
433
442
  kind: "group";
434
443
  name: string;
444
+ purpose: string;
435
445
  people: number;
436
446
  agents: number;
437
447
  online: number;
@@ -446,6 +456,7 @@ export declare class HubGroupRooms {
446
456
  } | {
447
457
  id: string;
448
458
  name: string;
459
+ purpose: string;
449
460
  people: number;
450
461
  agents: number;
451
462
  online: number;
@@ -1,3 +1,6 @@
1
+ import { HUB_ROOM_MEMBERS_CAPABILITY } from "../room-members-model.js";
2
+ import { pageRoomMembers } from "./members-page.js";
3
+ import { normalizeRoomPurpose } from "./purpose.js";
1
4
  import { agentIntro } from "../agent-intro.js";
2
5
  import { countChainStop } from "../admin-dashboard.js";
3
6
  import { createHash, randomUUID } from "node:crypto";
@@ -24,7 +27,8 @@ import { HUB_ROOM_MENTION_FEEDBACK_CAPABILITY } from "../room-mention-feedback-m
24
27
  import { personalMentionRefusals, recordPersonalMentionRefusals } from "../personal/refusals.js";
25
28
  const label = plain(120).transform(s => s.trim()).refine(s => s.length > 0 && !/[\u0000-\u001f\u007f]/.test(s));
26
29
  const personId = z.string().max(128).refine(s => /^[a-z][a-z0-9_-]{0,63}\/[a-f0-9-]{36}$/.test(s));
27
- const createSchema = z.strictObject({ name: label, people: z.array(personId).max(100).default([]), teams: z.array(uuid).max(100).default([]),
30
+ const purpose = z.string().transform(normalizeRoomPurpose);
31
+ const createSchema = z.strictObject({ name: label, purpose: purpose.default(""), people: z.array(personId).max(100).default([]), teams: z.array(uuid).max(100).default([]),
28
32
  groups: z.array(uuid).max(100).default([]), agents: z.array(uuid).max(64).default([]), assistant: z.boolean().default(false) });
29
33
  // M-3125: a post carries up to 10 of the poster's own pending uploads in this room; with files the text may be empty.
30
34
  const postSchema = z.strictObject({ text: plain(64 * 1024), mentions: z.array(z.string().max(128)).max(100).default([]),
@@ -75,7 +79,7 @@ export function validRoomEmoji(s) {
75
79
  return false;
76
80
  return [...new Intl.Segmenter("en", { granularity: "grapheme" }).segment(s)].length === 1;
77
81
  }
78
- const patchSchema = z.strictObject({ name: label.optional(), allMention: z.boolean().optional(), historyForNew: z.enum(["since-join", "all"]).optional(), archived: z.boolean().optional(), assistant: z.boolean().optional() });
82
+ const patchSchema = z.strictObject({ name: label.optional(), purpose: purpose.optional(), allMention: z.boolean().optional(), historyForNew: z.enum(["since-join", "all"]).optional(), archived: z.boolean().optional(), assistant: z.boolean().optional() });
79
83
  export class HubRoomRefusal extends Error {
80
84
  status;
81
85
  code;
@@ -215,8 +219,13 @@ export class HubGroupRooms {
215
219
  }
216
220
  maximum(db, id) { return db.prepare("SELECT COALESCE(MAX(sequence),0) AS n FROM hub_room_posts WHERE room_id=?").get(id).n; }
217
221
  projection(row) {
218
- const system = row.author_kind === "system" && ["room-created", "member-joined", "admin-joined", "poll-closed", "app-rate-limited"].includes(row.author_id)
222
+ let system = row.author_kind === "system" && ["room-created", "member-joined", "admin-joined", "poll-closed", "app-rate-limited"].includes(row.author_id)
219
223
  ? { kind: row.author_id, name: row.author_name } : undefined;
224
+ if (row.author_kind === "system" && row.author_id === "purpose-changed") {
225
+ const event = this.core.atomic(db => db.prepare("SELECT purpose FROM hub_room_purpose_events WHERE post_id=?").get(row.id));
226
+ if (event)
227
+ system = { kind: "purpose-changed", name: row.author_name, purpose: event.purpose };
228
+ }
220
229
  // Agent rows retain their owner-at-message in author_subject; a later exposure transfer must not relabel history.
221
230
  const agent = row.author_kind === "agent" ? this.core.atomic(db => {
222
231
  const e = readExposure(db, row.author_id);
@@ -239,8 +248,9 @@ export class HubGroupRooms {
239
248
  (SELECT 1 FROM hub_room_agent_operations op WHERE op.post_id=p.id AND op.member_id=p.author_id)`)
240
249
  .get(row.answer_to, row.room_id) : undefined;
241
250
  const stopped = row.delivery_id && row.stage === "not-answered" ? db.prepare("SELECT 1 FROM hub_room_deliveries WHERE id=? AND reason_code='owner-stopped-sharing'").get(row.delivery_id) : null;
251
+ const missing = row.delivery_id && row.stage === "not-answered" ? db.prepare("SELECT 1 FROM hub_room_deliveries WHERE id=? AND reason_code='finished-without-answer'").get(row.delivery_id) : null;
242
252
  const reactions = this.reactions(db, row.id), buttons = row.author_kind === "agent" ? this.buttons.view(db, row.id, id => this.memberName(db, id)) : undefined;
243
- return { ...(stopped ? { reasonCode: "owner-stopped-sharing" } : {}), ...(ask ? { ask } : {}), ...(asker ? { askedBy: asker.id } : {}), ...(this.assistant.warning(db, row.id) ? { warning: "assistant-unavailable" } : {}), ...(reactions.length ? { reactions } : {}), ...(buttons ? { buttons } : {}) };
253
+ return { ...(missing ? { reasonCode: "finished-without-answer" } : {}), ...(stopped ? { reasonCode: "owner-stopped-sharing" } : {}), ...(ask ? { ask } : {}), ...(asker ? { askedBy: asker.id } : {}), ...(this.assistant.warning(db, row.id) ? { warning: "assistant-unavailable" } : {}), ...(reactions.length ? { reactions } : {}), ...(buttons ? { buttons } : {}) };
244
254
  }) };
245
255
  }
246
256
  /** M-3127: a post's reactions, each emoji in the order it first appeared, its members in the order they reacted. */
@@ -400,13 +410,34 @@ export class HubGroupRooms {
400
410
  this.agentReadBuckets.set(owner, { at: b?.at ?? at, count: (b?.count ?? 0) + 1 });
401
411
  }
402
412
  async agentMembers(input, link) {
403
- const body = validated(roomMembersSchema, input), { source, fence } = await this.agentSource(body.exposureId, link);
413
+ const body = validated(roomMembersSchema, input);
414
+ if (body.v2 && !link.features.has(HUB_ROOM_MEMBERS_CAPABILITY))
415
+ throw new HubProtocolError("incompatible");
416
+ const { source, fence } = await this.agentSource(body.exposureId, link);
404
417
  this.agentRead(source.owner);
405
418
  return this.core.atomic(db => {
406
419
  const rows = db.prepare(`SELECT r.id,r.name FROM hub_room_members m JOIN hub_group_rooms r ON r.id=m.room_id WHERE m.kind='agent' AND m.subject=? AND m.owner_at_join=? AND r.archived=0 AND r.assistant_for IS NULL AND (r.id=? OR r.name=?) ORDER BY r.id LIMIT 201`).all(source.id, source.owner, body.room, body.room);
407
420
  const room = rows.find(r => r.id === body.room) ?? (rows.length === 1 ? rows[0] : undefined);
408
- if (!room)
409
- return rows.length ? { ok: false, code: "ambiguous-room", rooms: rows.slice(0, 200) } : { ok: false, code: "not-found" };
421
+ if (!room) {
422
+ const choices = rows.slice(0, 200);
423
+ if (body.v2)
424
+ while (Buffer.byteLength(JSON.stringify({ ok: false, code: "ambiguous-room", rooms: choices })) > 8192)
425
+ choices.pop();
426
+ return rows.length ? { ok: false, code: "ambiguous-room", rooms: choices } : { ok: false, code: "not-found" };
427
+ }
428
+ if (body.v2) {
429
+ const roomRow = this.room(db, room.id);
430
+ const roster = db.prepare("SELECT * FROM hub_room_members WHERE room_id=? ORDER BY kind,id").all(room.id).map(m => {
431
+ if (m.kind === "assistant")
432
+ return { id: "assistant", kind: "assistant", name: "Hub assistant", presence: this.assistant.presence(room.id), intro: "Hub assistant. Answers from this room's chat.", mentionable: false };
433
+ if (m.kind === "agent") {
434
+ const e = readExposure(db, m.subject);
435
+ return { id: m.subject, kind: m.kind, name: e?.display_name ?? m.subject, presence: this.agents.presence(m.subject).presence, owner: { name: this.name(db, m.owner_at_join ?? "") }, intro: agentIntro(db, m.subject).intro };
436
+ }
437
+ return { id: m.id, kind: m.kind, name: this.name(db, m.subject), presence: db.prepare("SELECT 1 FROM hub_sessions WHERE person=? AND state='active' AND expires_at>?").get(m.subject, this.core.now()) ? "online" : "offline" };
438
+ });
439
+ return pageRoomMembers(room.id, roomRow.purpose, roster, body, JSON.stringify([source.id, source.owner]));
440
+ }
410
441
  const members = db.prepare("SELECT * FROM hub_room_members WHERE room_id=? ORDER BY kind,id LIMIT 201").all(room.id).map(m => {
411
442
  if (m.kind === "assistant")
412
443
  return { id: "assistant", kind: m.kind, name: "Hub assistant", presence: this.assistant.presence(room.id) };
@@ -522,6 +553,13 @@ export class HubGroupRooms {
522
553
  VALUES(@id,@room_id,@sequence,@author_kind,@author_id,@author_subject,@author_name,@content_ref,@digest,@mentions,@reply_to,@idempotency_key,@created_at)`).run(row);
523
554
  return row;
524
555
  }
556
+ recordPurpose(db, tx, id, me, purpose, requestId) {
557
+ const name = this.name(db, me), text = purpose ? `${name} set the purpose: ${purpose}` : `${name} cleared the purpose.`;
558
+ const post = this.insert(db, tx, id, { kind: "system", id: "purpose-changed", subject: me, name }, text);
559
+ db.prepare("INSERT INTO hub_room_purpose_events VALUES(?,?)").run(post.id, purpose);
560
+ this.core.audit(tx, { requestId, actor: { kind: "person", person: personFromString(me) }, action: "room.purpose-changed", result: "completed", roomId: id, messageId: post.id, contentRef: post.content_ref });
561
+ return post;
562
+ }
525
563
  summary(db, room, member) {
526
564
  const counts = db.prepare("SELECT kind,COUNT(*) AS n FROM hub_room_members WHERE room_id=? GROUP BY kind").all(room.id);
527
565
  const floor = member.joined_sequence;
@@ -533,7 +571,7 @@ export class HubGroupRooms {
533
571
  const online = db.prepare(`SELECT COUNT(*) AS n FROM hub_room_members m WHERE m.room_id=? AND m.kind='person' AND EXISTS
534
572
  (SELECT 1 FROM hub_sessions s WHERE s.person=m.subject AND s.state='active' AND s.expires_at>?)`).get(room.id, this.core.now()).n;
535
573
  const projected = last ? this.projection(last) : undefined;
536
- const summary = { id: room.id, kind: "group", name: room.name, people: counts.find(c => c.kind === "person")?.n ?? 0,
574
+ const summary = { id: room.id, kind: "group", name: room.name, purpose: room.purpose ?? "", people: counts.find(c => c.kind === "person")?.n ?? 0,
537
575
  agents: counts.find(c => c.kind === "agent")?.n ?? 0, online, unread, lastAt: last?.created_at ?? room.created_at,
538
576
  lastText: projected?.text.slice(0, 240) ?? "", ...(projected?.system ? { lastSystem: projected.system } : {}), lastAuthor: last?.author_name ?? "", mentioned, archived: room.archived === 1 };
539
577
  return room.assistant_for ? { ...summary, kind: "direct", assistant: true, presence: this.assistant.presence(room.id) } : summary;
@@ -668,7 +706,7 @@ export class HubGroupRooms {
668
706
  throw new HubRoomRefusal(403, "denied");
669
707
  rememberRoomPeople(db, selectedPeople, this.core.now());
670
708
  const id = randomUUID();
671
- db.prepare("INSERT INTO hub_group_rooms(id,name,created_by,created_at) VALUES(?,?,?,?)").run(id, body.name, me, this.core.now());
709
+ db.prepare("INSERT INTO hub_group_rooms(id,name,purpose,created_by,created_at) VALUES(?,?,?,?,?)").run(id, body.name, body.purpose, me, this.core.now());
672
710
  for (const person of people)
673
711
  db.prepare("INSERT INTO hub_room_members(id,room_id,kind,subject,role,joined_sequence) VALUES(?,?,'person',?,?,0)").run(randomUUID(), id, person, person === me ? "manager" : "member");
674
712
  this.insert(db, tx, id, { kind: "system", id: "room-created", subject: me, name: this.name(db, me) }, `${this.name(db, me)} created this room.`);
@@ -676,6 +714,8 @@ export class HubGroupRooms {
676
714
  this.addAgentMember(db, tx, id, agent, me);
677
715
  if (body.assistant)
678
716
  this.addAssistant(db, id);
717
+ if (body.purpose)
718
+ this.recordPurpose(db, tx, id, me, body.purpose, ctx.requestId);
679
719
  this.core.audit(tx, { requestId: ctx.requestId, actor: { kind: "person", person: personFromString(me) }, action: "room.created", result: "completed", roomId: id });
680
720
  return this.summary(db, this.room(db, id), this.member(db, id, me));
681
721
  }, { assertCurrent: () => { this.fence(ctx).assertCurrent(); for (const permit of permits)
@@ -725,7 +765,7 @@ export class HubGroupRooms {
725
765
  }
726
766
  async patch(ctx, id, input) {
727
767
  const body = validated(patchSchema, input), me = await this.who(ctx);
728
- this.core.atomic((db, tx) => {
768
+ const purposePost = this.core.atomic((db, tx) => {
729
769
  this.member(db, id, me, true);
730
770
  const row = this.room(db, id);
731
771
  if (row.assistant_for)
@@ -734,13 +774,17 @@ export class HubGroupRooms {
734
774
  this.addAssistant(db, id);
735
775
  else if (body.assistant === false)
736
776
  db.prepare("DELETE FROM hub_room_members WHERE room_id=? AND kind='assistant'").run(id);
737
- db.prepare("UPDATE hub_group_rooms SET name=?,all_mention=?,history_for_new=?,archived=? WHERE id=?")
738
- .run(body.name ?? row.name, body.allMention === undefined ? row.all_mention : Number(body.allMention), body.historyForNew ?? row.history_for_new, body.archived === undefined ? row.archived : Number(body.archived), id);
777
+ db.prepare("UPDATE hub_group_rooms SET name=?,purpose=?,all_mention=?,history_for_new=?,archived=? WHERE id=?")
778
+ .run(body.name ?? row.name, body.purpose ?? row.purpose, body.allMention === undefined ? row.all_mention : Number(body.allMention), body.historyForNew ?? row.history_for_new, body.archived === undefined ? row.archived : Number(body.archived), id);
779
+ const changed = body.purpose !== undefined && body.purpose !== row.purpose ? this.recordPurpose(db, tx, id, me, body.purpose, ctx.requestId) : null;
739
780
  this.core.audit(tx, { requestId: ctx.requestId, actor: { kind: "person", person: personFromString(me) }, action: "room.updated", result: "completed", roomId: id });
781
+ return changed;
740
782
  }, this.fence(ctx));
741
783
  if (body.archived || body.assistant === false)
742
784
  this.assistant.forget(id);
743
785
  this.agents.sweep(id);
786
+ if (purposePost)
787
+ this.emit({ type: "message.added", roomId: id, data: { roomId: id, message: this.projection(purposePost) }, sequence: purposePost.sequence });
744
788
  this.emit({ type: "room.changed", roomId: id, data: { roomId: id } });
745
789
  return this.detail(ctx, id);
746
790
  }