@songsid/agend 2.4.0-beta.10 → 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 (298) 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 +29 -2
  9. package/dist/auth-api.js.map +1 -1
  10. package/dist/backend/claude-code.js +35 -9
  11. package/dist/backend/claude-code.js.map +1 -1
  12. package/dist/backend/codex-precaution.d.ts +7 -0
  13. package/dist/backend/codex-precaution.js +102 -0
  14. package/dist/backend/codex-precaution.js.map +1 -0
  15. package/dist/backend/codex.d.ts +1 -0
  16. package/dist/backend/codex.js +18 -0
  17. package/dist/backend/codex.js.map +1 -1
  18. package/dist/backend/grok.js +21 -6
  19. package/dist/backend/grok.js.map +1 -1
  20. package/dist/backend/types.d.ts +9 -1
  21. package/dist/backend/types.js.map +1 -1
  22. package/dist/build-provenance.json +1 -1
  23. package/dist/channel/mcp-server.js +1 -1
  24. package/dist/channel/mcp-server.js.map +1 -1
  25. package/dist/channel/mcp-tools.js +3 -1
  26. package/dist/channel/mcp-tools.js.map +1 -1
  27. package/dist/claude-install-kind.d.ts +19 -0
  28. package/dist/claude-install-kind.js +54 -0
  29. package/dist/claude-install-kind.js.map +1 -0
  30. package/dist/cli-audited.js +3 -3
  31. package/dist/cli-audited.js.map +1 -1
  32. package/dist/daemon.d.ts +5 -0
  33. package/dist/daemon.js +22 -4
  34. package/dist/daemon.js.map +1 -1
  35. package/dist/event-log.d.ts +12 -0
  36. package/dist/event-log.js +40 -0
  37. package/dist/event-log.js.map +1 -1
  38. package/dist/fleet-manager.d.ts +122 -2
  39. package/dist/fleet-manager.js +482 -27
  40. package/dist/fleet-manager.js.map +1 -1
  41. package/dist/general-knowledge/skills/hub/SKILL.md +38 -6
  42. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +16 -1
  43. package/dist/hub/admin-dashboard.js +3 -3
  44. package/dist/hub/admin-dashboard.js.map +1 -1
  45. package/dist/hub/agent-catalog-model.d.ts +276 -0
  46. package/dist/hub/agent-catalog-model.js +49 -0
  47. package/dist/hub/agent-catalog-model.js.map +1 -0
  48. package/dist/hub/agent-catalog.d.ts +137 -0
  49. package/dist/hub/agent-catalog.js +118 -0
  50. package/dist/hub/agent-catalog.js.map +1 -0
  51. package/dist/hub/agent-intro-model.d.ts +38 -0
  52. package/dist/hub/agent-intro-model.js +14 -0
  53. package/dist/hub/agent-intro-model.js.map +1 -0
  54. package/dist/hub/agent-intro-tool.d.ts +35 -0
  55. package/dist/hub/agent-intro-tool.js +83 -0
  56. package/dist/hub/agent-intro-tool.js.map +1 -0
  57. package/dist/hub/agent-intro.d.ts +31 -0
  58. package/dist/hub/agent-intro.js +51 -0
  59. package/dist/hub/agent-intro.js.map +1 -0
  60. package/dist/hub/catalog.d.ts +4 -2
  61. package/dist/hub/catalog.js +19 -3
  62. package/dist/hub/catalog.js.map +1 -1
  63. package/dist/hub/client.d.ts +3 -0
  64. package/dist/hub/client.js +47 -1
  65. package/dist/hub/client.js.map +1 -1
  66. package/dist/hub/compose/member.d.ts +19 -5
  67. package/dist/hub/compose/member.js +94 -13
  68. package/dist/hub/compose/member.js.map +1 -1
  69. package/dist/hub/compose/server.d.ts +5 -0
  70. package/dist/hub/compose/server.js +6 -1
  71. package/dist/hub/compose/server.js.map +1 -1
  72. package/dist/hub/execution/service.d.ts +1 -1
  73. package/dist/hub/execution/service.js +1 -0
  74. package/dist/hub/execution/service.js.map +1 -1
  75. package/dist/hub/http/compose.d.ts +3 -0
  76. package/dist/hub/http/compose.js +122 -15
  77. package/dist/hub/http/compose.js.map +1 -1
  78. package/dist/hub/http/schema.js +15 -0
  79. package/dist/hub/http/schema.js.map +1 -1
  80. package/dist/hub/mcp/tools.js +2 -1
  81. package/dist/hub/mcp/tools.js.map +1 -1
  82. package/dist/hub/member/agent-catalog.d.ts +28 -0
  83. package/dist/hub/member/agent-catalog.js +80 -0
  84. package/dist/hub/member/agent-catalog.js.map +1 -0
  85. package/dist/hub/member/agent-intro.d.ts +28 -0
  86. package/dist/hub/member/agent-intro.js +66 -0
  87. package/dist/hub/member/agent-intro.js.map +1 -0
  88. package/dist/hub/member/exposure-api.d.ts +3 -3
  89. package/dist/hub/member/exposure-api.js +4 -4
  90. package/dist/hub/member/exposure-api.js.map +1 -1
  91. package/dist/hub/member/exposures.d.ts +12 -4
  92. package/dist/hub/member/exposures.js +27 -13
  93. package/dist/hub/member/exposures.js.map +1 -1
  94. package/dist/hub/member/room-ask.d.ts +14 -1
  95. package/dist/hub/member/room-ask.js +76 -10
  96. package/dist/hub/member/room-ask.js.map +1 -1
  97. package/dist/hub/member/room-context-budget.d.ts +5 -0
  98. package/dist/hub/member/room-context-budget.js +34 -0
  99. package/dist/hub/member/room-context-budget.js.map +1 -0
  100. package/dist/hub/member/room-notification.d.ts +1 -1
  101. package/dist/hub/member/room-post.d.ts +6 -3
  102. package/dist/hub/member/room-post.js +9 -3
  103. package/dist/hub/member/room-post.js.map +1 -1
  104. package/dist/hub/member/sharing-journal.d.ts +252 -0
  105. package/dist/hub/member/sharing-journal.js +212 -0
  106. package/dist/hub/member/sharing-journal.js.map +1 -0
  107. package/dist/hub/member/sharing-link.d.ts +25 -0
  108. package/dist/hub/member/sharing-link.js +68 -0
  109. package/dist/hub/member/sharing-link.js.map +1 -0
  110. package/dist/hub/member/sharing-result.d.ts +6 -0
  111. package/dist/hub/member/sharing-result.js +46 -0
  112. package/dist/hub/member/sharing-result.js.map +1 -0
  113. package/dist/hub/member/sharing.d.ts +37 -0
  114. package/dist/hub/member/sharing.js +181 -0
  115. package/dist/hub/member/sharing.js.map +1 -0
  116. package/dist/hub/personal/owner-host.d.ts +6 -0
  117. package/dist/hub/personal/owner-host.js +4 -2
  118. package/dist/hub/personal/owner-host.js.map +1 -1
  119. package/dist/hub/protocol.d.ts +398 -4
  120. package/dist/hub/protocol.js +13 -5
  121. package/dist/hub/protocol.js.map +1 -1
  122. package/dist/hub/room-answer-status-model.d.ts +3 -0
  123. package/dist/hub/room-answer-status-model.js +4 -0
  124. package/dist/hub/room-answer-status-model.js.map +1 -0
  125. package/dist/hub/room-brief-model.d.ts +30 -0
  126. package/dist/hub/room-brief-model.js +37 -0
  127. package/dist/hub/room-brief-model.js.map +1 -0
  128. package/dist/hub/room-context-model.d.ts +2 -0
  129. package/dist/hub/room-context-model.js +2 -2
  130. package/dist/hub/room-context-model.js.map +1 -1
  131. package/dist/hub/room-members-model.d.ts +63 -0
  132. package/dist/hub/room-members-model.js +7 -0
  133. package/dist/hub/room-members-model.js.map +1 -0
  134. package/dist/hub/rooms/agents.d.ts +1 -0
  135. package/dist/hub/rooms/agents.js +62 -11
  136. package/dist/hub/rooms/agents.js.map +1 -1
  137. package/dist/hub/rooms/brief.d.ts +18 -0
  138. package/dist/hub/rooms/brief.js +39 -0
  139. package/dist/hub/rooms/brief.js.map +1 -0
  140. package/dist/hub/rooms/direct-view.d.ts +5 -1
  141. package/dist/hub/rooms/direct-view.js +2 -2
  142. package/dist/hub/rooms/direct-view.js.map +1 -1
  143. package/dist/hub/rooms/members-page.d.ts +33 -0
  144. package/dist/hub/rooms/members-page.js +37 -0
  145. package/dist/hub/rooms/members-page.js.map +1 -0
  146. package/dist/hub/rooms/purpose.d.ts +7 -0
  147. package/dist/hub/rooms/purpose.js +14 -0
  148. package/dist/hub/rooms/purpose.js.map +1 -0
  149. package/dist/hub/rooms/service.d.ts +43 -0
  150. package/dist/hub/rooms/service.js +80 -22
  151. package/dist/hub/rooms/service.js.map +1 -1
  152. package/dist/hub/rooms/types.d.ts +6 -1
  153. package/dist/hub/rooms.d.ts +1 -0
  154. package/dist/hub/rooms.js +9 -4
  155. package/dist/hub/rooms.js.map +1 -1
  156. package/dist/hub/runtime.d.ts +1 -1
  157. package/dist/hub/server.js +49 -1
  158. package/dist/hub/server.js.map +1 -1
  159. package/dist/hub/sharing-previous-access.d.ts +22 -0
  160. package/dist/hub/sharing-previous-access.js +93 -0
  161. package/dist/hub/sharing-previous-access.js.map +1 -0
  162. package/dist/hub/sharing-requests.d.ts +171 -0
  163. package/dist/hub/sharing-requests.js +311 -0
  164. package/dist/hub/sharing-requests.js.map +1 -0
  165. package/dist/hub/sharing-retention.d.ts +47 -0
  166. package/dist/hub/sharing-retention.js +83 -0
  167. package/dist/hub/sharing-retention.js.map +1 -0
  168. package/dist/hub/sharing-withdrawal.d.ts +14 -0
  169. package/dist/hub/sharing-withdrawal.js +28 -0
  170. package/dist/hub/sharing-withdrawal.js.map +1 -0
  171. package/dist/hub/types.d.ts +13 -5
  172. package/dist/hub-page-sharing-settings.d.ts +6 -0
  173. package/dist/hub-page-sharing-settings.js +19 -0
  174. package/dist/hub-page-sharing-settings.js.map +1 -0
  175. package/dist/hub-room-reply-warning.d.ts +2 -0
  176. package/dist/hub-room-reply-warning.js +16 -0
  177. package/dist/hub-room-reply-warning.js.map +1 -0
  178. package/dist/hub-sharing-notice.d.ts +43 -0
  179. package/dist/hub-sharing-notice.js +34 -0
  180. package/dist/hub-sharing-notice.js.map +1 -0
  181. package/dist/instance-lifecycle.d.ts +15 -0
  182. package/dist/instance-lifecycle.js +36 -1
  183. package/dist/instance-lifecycle.js.map +1 -1
  184. package/dist/locale.js +78 -0
  185. package/dist/locale.js.map +1 -1
  186. package/dist/login-controller.d.ts +26 -0
  187. package/dist/login-controller.js +72 -2
  188. package/dist/login-controller.js.map +1 -1
  189. package/dist/login-flows.js +1 -1
  190. package/dist/login-flows.js.map +1 -1
  191. package/dist/native-mcp.js +1 -1
  192. package/dist/native-mcp.js.map +1 -1
  193. package/dist/needs-you-hub.js +1 -1
  194. package/dist/needs-you-hub.js.map +1 -1
  195. package/dist/needs-you.d.ts +8 -1
  196. package/dist/needs-you.js +6 -0
  197. package/dist/needs-you.js.map +1 -1
  198. package/dist/office-share-page.js +1 -1
  199. package/dist/office-share-page.js.map +1 -1
  200. package/dist/outbound-handlers.d.ts +2 -1
  201. package/dist/outbound-handlers.js +17 -4
  202. package/dist/outbound-handlers.js.map +1 -1
  203. package/dist/outbound-schemas.d.ts +10 -0
  204. package/dist/outbound-schemas.js +3 -1
  205. package/dist/outbound-schemas.js.map +1 -1
  206. package/dist/public-web-gateway.js +9 -3
  207. package/dist/public-web-gateway.js.map +1 -1
  208. package/dist/remote-card-answer.d.ts +1 -1
  209. package/dist/remote-card-answer.js +8 -1
  210. package/dist/remote-card-answer.js.map +1 -1
  211. package/dist/remote-card-prompt.js +1 -1
  212. package/dist/remote-card-prompt.js.map +1 -1
  213. package/dist/restart-progress.d.ts +6 -0
  214. package/dist/restart-progress.js +5 -0
  215. package/dist/restart-progress.js.map +1 -1
  216. package/dist/settings-api.d.ts +1 -0
  217. package/dist/settings-api.js +84 -10
  218. package/dist/settings-api.js.map +1 -1
  219. package/dist/settings-baseline.d.ts +3 -0
  220. package/dist/settings-baseline.js +2 -2
  221. package/dist/settings-baseline.js.map +1 -1
  222. package/dist/settings-change.js +1 -0
  223. package/dist/settings-change.js.map +1 -1
  224. package/dist/settings-effect.d.ts +3 -0
  225. package/dist/settings-effect.js +33 -2
  226. package/dist/settings-effect.js.map +1 -1
  227. package/dist/tool-permissions.js +3 -3
  228. package/dist/tool-permissions.js.map +1 -1
  229. package/dist/ui/chat-quote.js +3 -261
  230. package/dist/ui/fleet-office-card.js +8 -4
  231. package/dist/ui/fleet-office-pack.d.ts +1 -0
  232. package/dist/ui/fleet-office-pack.js +6 -2
  233. package/dist/ui/fleet-office-play.js +84 -0
  234. package/dist/ui/fleet-office-store.js +23 -0
  235. package/dist/ui/fleet-office-zones.js +5 -1
  236. package/dist/ui/fleet-office.js +78 -8
  237. package/dist/ui/host-install.js +77 -3
  238. package/dist/ui/hub-agent-intro.js +35 -0
  239. package/dist/ui/hub-attachments.js +81 -3
  240. package/dist/ui/hub-chat-strings.js +4 -4
  241. package/dist/ui/hub-client.js +16 -1
  242. package/dist/ui/hub-grant-picker.js +25 -11
  243. package/dist/ui/hub-group-strings.js +3 -3
  244. package/dist/ui/hub-intro-notice.js +16 -0
  245. package/dist/ui/hub-my-agents-model.js +42 -0
  246. package/dist/ui/hub-my-agents-strings.js +18 -0
  247. package/dist/ui/hub-my-agents.js +144 -0
  248. package/dist/ui/hub-owner-strings.js +5 -5
  249. package/dist/ui/hub-personal-agent.js +5 -4
  250. package/dist/ui/hub-room-composer.js +37 -6
  251. package/dist/ui/hub-room-list.js +4 -3
  252. package/dist/ui/hub-room-members.js +5 -2
  253. package/dist/ui/hub-room-new.js +8 -5
  254. package/dist/ui/hub-room-purpose.js +19 -0
  255. package/dist/ui/hub-room-search.js +1 -1
  256. package/dist/ui/hub-room-settings.js +9 -0
  257. package/dist/ui/hub-room-strings.js +6 -4
  258. package/dist/ui/hub-room-thread.js +70 -17
  259. package/dist/ui/hub-strings.js +5 -5
  260. package/dist/ui/hub-welcome.js +6 -6
  261. package/dist/ui/notice-hub-sharing.js +81 -0
  262. package/dist/ui/panel-chat.js +19 -5
  263. package/dist/ui/panel-hub.js +77 -29
  264. package/dist/ui/panel-notices.js +2 -1
  265. package/dist/ui/settings-hub-connection.js +2 -2
  266. package/dist/ui/settings-hub-page-sharing.js +52 -0
  267. package/dist/ui/settings-hub.js +4 -2
  268. package/dist/ui/settings-registry.js +1 -0
  269. package/dist/ui/shared/app-i18n.js +2 -2
  270. package/dist/ui/shared/app-shell.js +14 -2
  271. package/dist/ui/shared/app-store.js +6 -2
  272. package/dist/ui/shared/app.js +3 -1
  273. package/dist/ui/shared/chat-msg-actions.js +3 -1
  274. package/dist/ui/shared/chat-quote.js +261 -0
  275. package/dist/ui/shared/hub-chat.css +31 -0
  276. package/dist/ui/shared/hub-my-agents.css +35 -0
  277. package/dist/ui/shared/hub-rooms-u2.css +5 -0
  278. package/dist/ui/shared/module-warm.d.ts +3 -0
  279. package/dist/ui/shared/module-warm.js +39 -0
  280. package/dist/web-api.d.ts +21 -5
  281. package/dist/web-api.js +138 -7
  282. package/dist/web-api.js.map +1 -1
  283. package/dist/web-asset-version.d.ts +65 -0
  284. package/dist/web-asset-version.js +259 -0
  285. package/dist/web-asset-version.js.map +1 -0
  286. package/dist/web-host-guard.js +3 -1
  287. package/dist/web-host-guard.js.map +1 -1
  288. package/dist/web-host-install.d.ts +30 -3
  289. package/dist/web-host-install.js +50 -4
  290. package/dist/web-host-install.js.map +1 -1
  291. package/dist/web-notices.d.ts +17 -0
  292. package/dist/web-notices.js +47 -6
  293. package/dist/web-notices.js.map +1 -1
  294. package/dist/web-terminal.d.ts +5 -0
  295. package/dist/web-terminal.js +11 -0
  296. package/dist/web-terminal.js.map +1 -1
  297. package/launcher/agend-install.cjs +48 -7
  298. package/package.json +1 -1
@@ -0,0 +1,137 @@
1
+ /** Separate owner-only inventory: never used by the shared-agent directory or app tools. */
2
+ import type Database from "better-sqlite3";
3
+ import type { HubCore } from "./http/core.js";
4
+ import type { HubLinkContext } from "./server.js";
5
+ import type { HubRequestContext } from "./types.js";
6
+ export declare const HUB_AGENT_CATALOG_MIGRATION: Readonly<{
7
+ component: "s3-agent-catalog";
8
+ version: 1;
9
+ up(db: Database.Database): void;
10
+ }>;
11
+ export declare class HubAgentCatalogs {
12
+ private readonly core;
13
+ private readonly links;
14
+ private readonly reports;
15
+ private readonly refreshed;
16
+ constructor(core: HubCore);
17
+ connected(link: HubLinkContext): void;
18
+ prune(): void;
19
+ report(value: unknown, link: HubLinkContext): void;
20
+ owner(ctx: HubRequestContext): Promise<{
21
+ person: import("./types.js").PersonKey;
22
+ actor: {
23
+ kind: "directory";
24
+ person: import("./types.js").PersonKey;
25
+ sessionId: string;
26
+ };
27
+ assertCurrent: () => void;
28
+ }>;
29
+ /** Internal owner queue view; the browser caller is checked separately and never selected from input. */
30
+ reportOf(fleetId: string): {
31
+ fleet: {
32
+ id: string;
33
+ owner: {
34
+ realm: string;
35
+ objectId: string;
36
+ };
37
+ credentialHash: string | null;
38
+ generation: number;
39
+ status: "active" | "revoked";
40
+ label?: string | undefined;
41
+ };
42
+ catalog: {
43
+ revision: string;
44
+ enabled: boolean;
45
+ requests: boolean;
46
+ agents: ({
47
+ instance: string;
48
+ displayName: string;
49
+ description: string;
50
+ avatar: {
51
+ emoji: string | null;
52
+ color: string | null;
53
+ } | null;
54
+ kind: "agent" | "classic-room";
55
+ general: boolean;
56
+ exposure?: {
57
+ id: string;
58
+ revision: number;
59
+ state: "frozen" | "published" | "withdrawn";
60
+ } | null | undefined;
61
+ shareable: true;
62
+ } | {
63
+ instance: string;
64
+ displayName: string;
65
+ description: string;
66
+ avatar: {
67
+ emoji: string | null;
68
+ color: string | null;
69
+ } | null;
70
+ kind: "agent" | "classic-room";
71
+ general: boolean;
72
+ exposure?: {
73
+ id: string;
74
+ revision: number;
75
+ state: "frozen" | "published" | "withdrawn";
76
+ } | null | undefined;
77
+ shareable: false;
78
+ reason: "ambiguous-agent" | "delivery-unavailable" | "remote-windows";
79
+ })[];
80
+ };
81
+ link: HubLinkContext | null;
82
+ } | null;
83
+ view(ctx: HubRequestContext): Promise<{
84
+ fleets: {
85
+ id: string;
86
+ label: string | null;
87
+ connected: boolean;
88
+ catalogSupported: boolean | null;
89
+ catalog: {
90
+ revision: string;
91
+ enabled: boolean;
92
+ requests: boolean;
93
+ agents: ({
94
+ instance: string;
95
+ displayName: string;
96
+ description: string;
97
+ avatar: {
98
+ emoji: string | null;
99
+ color: string | null;
100
+ } | null;
101
+ kind: "agent" | "classic-room";
102
+ general: boolean;
103
+ exposure?: {
104
+ id: string;
105
+ revision: number;
106
+ state: "frozen" | "published" | "withdrawn";
107
+ } | null | undefined;
108
+ shareable: true;
109
+ } | {
110
+ instance: string;
111
+ displayName: string;
112
+ description: string;
113
+ avatar: {
114
+ emoji: string | null;
115
+ color: string | null;
116
+ } | null;
117
+ kind: "agent" | "classic-room";
118
+ general: boolean;
119
+ exposure?: {
120
+ id: string;
121
+ revision: number;
122
+ state: "frozen" | "published" | "withdrawn";
123
+ } | null | undefined;
124
+ shareable: false;
125
+ reason: "ambiguous-agent" | "delivery-unavailable" | "remote-windows";
126
+ })[];
127
+ at: number;
128
+ } | null;
129
+ }[];
130
+ }>;
131
+ /** A send is only a refresh request, never proof of a new report. Old peers receive nothing. */
132
+ refresh(ctx: HubRequestContext, input: unknown): Promise<{
133
+ requested: boolean;
134
+ fleetId: string;
135
+ }>;
136
+ close(): void;
137
+ }
@@ -0,0 +1,118 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { z } from "zod";
3
+ import { uuid } from "./validation.js";
4
+ import { agentCatalogSchema, HUB_AGENT_CATALOG_CAPABILITY, HUB_EXPOSURE_REQUEST_CAPABILITY } from "./agent-catalog-model.js";
5
+ import { canonicalArguments, personKeyString } from "./identity.js";
6
+ import { HubProtocolError, validated } from "./validation.js";
7
+ export const HUB_AGENT_CATALOG_MIGRATION = Object.freeze({ component: "s3-agent-catalog", version: 1, up(db) {
8
+ db.exec("CREATE TABLE hub_agent_catalogs(fleet_id TEXT PRIMARY KEY,owner TEXT NOT NULL,generation INTEGER NOT NULL,revision TEXT NOT NULL,body TEXT NOT NULL,received_at INTEGER NOT NULL)");
9
+ } });
10
+ export class HubAgentCatalogs {
11
+ core;
12
+ links = new Map();
13
+ reports = new WeakSet();
14
+ refreshed = new Map();
15
+ constructor(core) {
16
+ this.core = core;
17
+ }
18
+ connected(link) { if (link.current())
19
+ this.links.set(link.fleetId, link); }
20
+ prune() {
21
+ this.core.atomic(db => {
22
+ const fleets = this.core.deps.store.read().fleets;
23
+ for (const row of db.prepare("SELECT fleet_id,owner,generation FROM hub_agent_catalogs").all()) {
24
+ if (!fleets.some(f => f.id === row.fleet_id && f.status === "active" && f.generation === row.generation && personKeyString(f.owner) === row.owner))
25
+ db.prepare("DELETE FROM hub_agent_catalogs WHERE fleet_id=?").run(row.fleet_id);
26
+ }
27
+ });
28
+ }
29
+ report(value, link) {
30
+ const body = validated(agentCatalogSchema, value);
31
+ if (!link.features.has("welcome-caps-v1") || !link.features.has(HUB_AGENT_CATALOG_CAPABILITY))
32
+ throw new HubProtocolError("incompatible");
33
+ if (body.requests && !link.features.has(HUB_EXPOSURE_REQUEST_CAPABILITY))
34
+ throw new HubProtocolError("incompatible");
35
+ this.core.atomic(db => {
36
+ if (!link.current())
37
+ throw new HubProtocolError("stale");
38
+ const fleet = this.core.deps.store.read().fleets.find(f => f.id === link.fleetId);
39
+ if (!fleet || fleet.status !== "active" || personKeyString(fleet.owner) !== personKeyString(link.owner))
40
+ throw new HubProtocolError("revoked");
41
+ const known = this.links.get(fleet.id);
42
+ if (known && known !== link && known.current())
43
+ throw new HubProtocolError("stale");
44
+ const previous = db.prepare("SELECT * FROM hub_agent_catalogs WHERE fleet_id=?").get(fleet.id);
45
+ const bytes = canonicalArguments(body);
46
+ if (previous?.owner === personKeyString(fleet.owner) && previous.generation === fleet.generation && previous.revision === body.revision && previous.body !== bytes)
47
+ throw new HubProtocolError("conflict");
48
+ db.prepare(`INSERT INTO hub_agent_catalogs VALUES(?,?,?,?,?,?) ON CONFLICT(fleet_id) DO UPDATE SET owner=excluded.owner,generation=excluded.generation,revision=excluded.revision,body=excluded.body,received_at=excluded.received_at`)
49
+ .run(fleet.id, personKeyString(fleet.owner), fleet.generation, body.revision, bytes, this.core.now());
50
+ this.links.set(fleet.id, link);
51
+ this.reports.add(link);
52
+ });
53
+ }
54
+ async owner(ctx) {
55
+ const person = await ctx.requirePerson(), actor = await ctx.current();
56
+ const current = () => this.core.live() && ctx.isCurrent?.() === true;
57
+ if (ctx.application || actor.kind !== "directory" || actor.sessionId.startsWith("mcp:")
58
+ || personKeyString(actor.person) !== personKeyString(person) || !current())
59
+ throw new HubProtocolError("denied");
60
+ const assertCurrent = () => this.core.atomic(db => {
61
+ const session = db.prepare("SELECT person,state,directory_epoch,expires_at FROM hub_sessions WHERE id=?").get(actor.sessionId);
62
+ if (!current() || !session || session.person !== personKeyString(person) || session.state !== "active"
63
+ || session.directory_epoch !== this.core.directoryEpoch || session.expires_at <= this.core.now())
64
+ throw new HubProtocolError("revoked");
65
+ });
66
+ assertCurrent();
67
+ return { person, actor, assertCurrent };
68
+ }
69
+ /** Internal owner queue view; the browser caller is checked separately and never selected from input. */
70
+ reportOf(fleetId) {
71
+ return this.core.atomic(db => {
72
+ const fleet = this.core.deps.store.read().fleets.find(row => row.id === fleetId);
73
+ const row = db.prepare("SELECT * FROM hub_agent_catalogs WHERE fleet_id=?").get(fleetId);
74
+ const link = this.links.get(fleetId);
75
+ if (!fleet || fleet.status !== "active" || !row || row.generation !== fleet.generation || row.owner !== personKeyString(fleet.owner))
76
+ return null;
77
+ return { fleet, catalog: validated(agentCatalogSchema, JSON.parse(row.body)), link: link?.current() && this.reports.has(link) ? link : null };
78
+ });
79
+ }
80
+ async view(ctx) {
81
+ const { person, assertCurrent } = await this.owner(ctx);
82
+ this.prune();
83
+ return this.core.atomic(db => {
84
+ assertCurrent();
85
+ return { fleets: this.core.deps.store.read().fleets.filter(f => f.status === "active" && personKeyString(f.owner) === personKeyString(person)).map(f => {
86
+ const row = db.prepare("SELECT * FROM hub_agent_catalogs WHERE fleet_id=?").get(f.id);
87
+ const link = this.links.get(f.id), connected = link?.current() === true;
88
+ return { id: f.id, label: f.label ?? null, connected, catalogSupported: connected ? this.reports.has(link) : null,
89
+ catalog: row ? { ...validated(agentCatalogSchema, JSON.parse(row.body)), at: row.received_at } : null };
90
+ }) };
91
+ });
92
+ }
93
+ /** A send is only a refresh request, never proof of a new report. Old peers receive nothing. */
94
+ async refresh(ctx, input) {
95
+ const { fleetId } = validated(z.strictObject({ fleetId: uuid }), input);
96
+ const browser = await this.owner(ctx), report = this.reportOf(fleetId);
97
+ if (!report || personKeyString(report.fleet.owner) !== personKeyString(browser.person))
98
+ throw new HubProtocolError("not-found");
99
+ const link = report.link, transport = this.core.deps.transport();
100
+ if (!link?.current() || !link.features.has(HUB_AGENT_CATALOG_CAPABILITY) || !transport)
101
+ throw new HubProtocolError("unavailable");
102
+ const now = this.core.now();
103
+ for (const [id, at] of this.refreshed)
104
+ if (now - at >= 5_000)
105
+ this.refreshed.delete(id);
106
+ if (this.refreshed.has(fleetId))
107
+ throw new HubProtocolError("backpressure");
108
+ browser.assertCurrent();
109
+ this.refreshed.set(fleetId, now);
110
+ await transport.send(fleetId, { v: 1, type: "agent.catalog-refresh", requestId: randomUUID(), linkEpoch: link.linkEpoch, payload: {} });
111
+ browser.assertCurrent();
112
+ if (this.reportOf(fleetId)?.link !== link || !link.current())
113
+ throw new HubProtocolError("unavailable");
114
+ return { requested: true, fleetId };
115
+ }
116
+ close() { this.links.clear(); }
117
+ }
118
+ //# sourceMappingURL=agent-catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-catalog.js","sourceRoot":"","sources":["../../src/hub/agent-catalog.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,+BAA+B,EAAwB,MAAM,0BAA0B,CAAC;AACnJ,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAC,kBAAkB,EAAC,OAAO,EAAC,CAAC,EAAC,EAAE,CAAC,EAAoB;QACvH,EAAE,CAAC,IAAI,CAAC,mLAAmL,CAAC,CAAC;IAC/L,CAAC,EAAE,CAAC,CAAC;AAEL,MAAM,OAAO,gBAAgB;IAIE,IAAI;IAHhB,KAAK,GAAC,IAAI,GAAG,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CAAC;QAC5B,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,SAAS;YAAE,IAAI,GAAG,GAAG,EAAE,IAAI,KAAK;gBAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxF,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,MAAM,IAAI,gBAAgB,CAAC,cAAc,CAAC,CAAC;QAC5E,OAAO,CAAC,aAAa,EAAE,CAAC;QAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC1D,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;QACxI,OAAO,CAAC,aAAa,EAAE,CAAC;QACxB,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YAAE,MAAM,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAAC;QACxG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IACtC,CAAC;IACD,KAAK,KAAS,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAA,CAAC;CACnC"}
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ export declare const HUB_AGENT_INTRO_CAPABILITY = "agent-intro-v1";
3
+ export declare const agentIntroSchema: z.ZodObject<{
4
+ exposureId: z.ZodUUID;
5
+ revision: z.ZodNumber;
6
+ text: z.ZodString;
7
+ source: z.ZodEnum<{
8
+ agent: "agent";
9
+ default: "default";
10
+ }>;
11
+ }, z.core.$strict>;
12
+ export declare const agentIntroResultSchema: z.ZodUnion<readonly [z.ZodObject<{
13
+ ok: z.ZodLiteral<true>;
14
+ intro: z.ZodString;
15
+ introBy: z.ZodEnum<{
16
+ agent: "agent";
17
+ default: "default";
18
+ owner: "owner";
19
+ }>;
20
+ introAt: z.ZodNumber;
21
+ changed: z.ZodBoolean;
22
+ }, z.core.$strict>, z.ZodObject<{
23
+ ok: z.ZodLiteral<false>;
24
+ code: z.ZodEnum<{
25
+ denied: "denied";
26
+ invalid: "invalid";
27
+ limit: "limit";
28
+ stale: "stale";
29
+ unavailable: "unavailable";
30
+ uncertain: "uncertain";
31
+ unsupported: "unsupported";
32
+ }>;
33
+ resetsAt: z.ZodOptional<z.ZodNumber>;
34
+ }, z.core.$strict>]>;
35
+ export type HubAgentIntro = z.infer<typeof agentIntroSchema>;
36
+ export type HubAgentIntroResult = z.infer<typeof agentIntroResultSchema>;
37
+ /** A default is only a starting line; the sharing UI must show it before access is granted. */
38
+ export declare function defaultAgentIntro(description: string): string;
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ export const HUB_AGENT_INTRO_CAPABILITY = "agent-intro-v1";
3
+ export const agentIntroSchema = z.strictObject({ exposureId: z.uuid(), revision: z.number().int().min(1), text: z.string(), source: z.enum(["default", "agent"]) });
4
+ export const agentIntroResultSchema = z.union([
5
+ z.strictObject({ ok: z.literal(true), intro: z.string(), introBy: z.enum(["default", "agent", "owner"]), introAt: z.number().int().min(0), changed: z.boolean() }),
6
+ z.strictObject({ ok: z.literal(false), code: z.enum(["invalid", "limit", "denied", "unavailable", "unsupported", "stale", "uncertain"]), resetsAt: z.number().int().min(0).optional() })
7
+ ]);
8
+ /** A default is only a starting line; the sharing UI must show it before access is granted. */
9
+ export function defaultAgentIntro(description) {
10
+ const line = description.split(/\r\n|[\r\n\u2028\u2029]/u)[0] ?? "";
11
+ const text = line.normalize("NFC").replace(/[\p{Cc}\u202a-\u202e\u2066-\u2069]/gu, " ").replace(/\s+/gu, " ").trim();
12
+ return [...new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(text)].slice(0, 50).map(s => s.segment).join("");
13
+ }
14
+ //# sourceMappingURL=agent-intro-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-intro-model.js","sourceRoot":"","sources":["../../src/hub/agent-intro-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,MAAM,CAAC,MAAM,0BAA0B,GAAC,gBAAgB,CAAC;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAC,CAAC,CAAC,YAAY,CAAC,EAAC,UAAU,EAAC,CAAC,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAC,IAAI,EAAC,CAAC,CAAC,MAAM,EAAE,EAAC,MAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAC,OAAO,CAAC,CAAC,EAAC,CAAC,CAAC;AACxJ,MAAM,CAAC,MAAM,sBAAsB,GAAC,CAAC,CAAC,KAAK,CAAC;IAC3C,CAAC,CAAC,YAAY,CAAC,EAAC,EAAE,EAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAC,KAAK,EAAC,CAAC,CAAC,MAAM,EAAE,EAAC,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAC,OAAO,EAAC,OAAO,CAAC,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC,OAAO,EAAE,EAAC,CAAC;IACrJ,CAAC,CAAC,YAAY,CAAC,EAAC,EAAE,EAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAC,IAAI,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAC,OAAO,EAAC,QAAQ,EAAC,aAAa,EAAC,aAAa,EAAC,OAAO,EAAC,WAAW,CAAC,CAAC,EAAC,QAAQ,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAC,CAAC;CAC3K,CAAC,CAAC;AAGH,+FAA+F;AAC/F,MAAM,UAAU,iBAAiB,CAAC,WAAkB;IACnD,MAAM,IAAI,GAAC,WAAW,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,IAAE,EAAE,CAAC;IAChE,MAAM,IAAI,GAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,sCAAsC,EAAC,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACjH,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,EAAC,EAAC,WAAW,EAAC,UAAU,EAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA,EAAE,CAAA,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzH,CAAC"}
@@ -0,0 +1,35 @@
1
+ /** Negotiated member edits and an owner's single persistent introduction notice. */
2
+ import type Database from "better-sqlite3";
3
+ import { type HubAgentIntroResult } from "./agent-intro-model.js";
4
+ import type { HubCore } from "./http/core.js";
5
+ import type { HubLinkContext } from "./server.js";
6
+ import type { HubRequestContext } from "./types.js";
7
+ export declare const HUB_AGENT_INTRO_TOOL_MIGRATION: Readonly<{
8
+ component: "s3-agent-intro-tool";
9
+ version: 1;
10
+ up(db: Database.Database): void;
11
+ }>;
12
+ interface IntroNoticeBatch {
13
+ fleetId: string;
14
+ fleet: string | null;
15
+ more: boolean;
16
+ agents: {
17
+ id: string;
18
+ name: string;
19
+ }[];
20
+ }
21
+ export declare class HubAgentIntroTool {
22
+ private core;
23
+ constructor(core: HubCore);
24
+ receive(raw: unknown, link: HubLinkContext, operationId: string): HubAgentIntroResult;
25
+ notice(ctx: HubRequestContext): Promise<{
26
+ notice: {
27
+ id: string;
28
+ batches: IntroNoticeBatch[];
29
+ } | null;
30
+ }>;
31
+ acknowledge(ctx: HubRequestContext): Promise<{
32
+ ok: boolean;
33
+ }>;
34
+ }
35
+ export {};
@@ -0,0 +1,83 @@
1
+ import { agentIntro, normalizeAgentIntro } from "./agent-intro.js";
2
+ import { agentIntroSchema, HUB_AGENT_INTRO_CAPABILITY } from "./agent-intro-model.js";
3
+ import { readExposure } from "./catalog.js";
4
+ import { personKeyString } from "./identity.js";
5
+ import { HubProtocolError } from "./validation.js";
6
+ export const HUB_AGENT_INTRO_TOOL_MIGRATION = Object.freeze({ component: "s3-agent-intro-tool", version: 1, up(db) {
7
+ // Historical registries without the personal-agent discriminator contain only Fleet shares.
8
+ const fleetOnly = db.prepare("PRAGMA table_info(hub_exposures)").all().some(c => c.name === "source_kind") ? "source_kind='fleet'" : "1";
9
+ db.exec(`
10
+ CREATE TABLE hub_agent_intro_changes(exposure_id TEXT NOT NULL REFERENCES hub_exposures(id) ON DELETE CASCADE,day INTEGER NOT NULL,changes INTEGER NOT NULL,PRIMARY KEY(exposure_id,day));
11
+ CREATE TABLE hub_agent_intro_operations(fleet_id TEXT NOT NULL,operation_id TEXT NOT NULL,input TEXT NOT NULL,result TEXT NOT NULL,PRIMARY KEY(fleet_id,operation_id));
12
+ CREATE TABLE hub_agent_intro_existing(exposure_id TEXT PRIMARY KEY REFERENCES hub_exposures(id) ON DELETE CASCADE);
13
+ INSERT INTO hub_agent_intro_existing SELECT id FROM hub_exposures WHERE ${fleetOnly} AND state!='withdrawn' AND NOT EXISTS(SELECT 1 FROM hub_agent_intros i WHERE i.exposure_id=hub_exposures.id);
14
+ CREATE TABLE hub_agent_intro_notices(owner TEXT PRIMARY KEY,batches TEXT NOT NULL,acknowledged_at INTEGER,seen INTEGER NOT NULL DEFAULT 0);
15
+ `);
16
+ } });
17
+ export class HubAgentIntroTool {
18
+ core;
19
+ constructor(core) {
20
+ this.core = core;
21
+ }
22
+ receive(raw, link, operationId) {
23
+ if (!link.current())
24
+ return { ok: false, code: "stale" };
25
+ if (!link.features.has(HUB_AGENT_INTRO_CAPABILITY))
26
+ return { ok: false, code: "unsupported" };
27
+ const parsed = agentIntroSchema.safeParse(raw);
28
+ if (!parsed.success)
29
+ return { ok: false, code: "invalid" };
30
+ let text;
31
+ try {
32
+ text = normalizeAgentIntro(parsed.data.text);
33
+ }
34
+ catch {
35
+ return { ok: false, code: "invalid" };
36
+ }
37
+ const value = { ...parsed.data, text }, input = JSON.stringify(value), owner = personKeyString(link.owner);
38
+ return this.core.atomic((db, tx) => {
39
+ const e = readExposure(db, value.exposureId);
40
+ if (!link.current() || !e || e.owner !== owner || e.fleet_id !== link.fleetId || e.state === 'withdrawn' || e.revision !== value.revision)
41
+ return { ok: false, code: "denied" };
42
+ const previous = db.prepare("SELECT input,result FROM hub_agent_intro_operations WHERE fleet_id=? AND operation_id=?").get(link.fleetId, operationId);
43
+ if (previous)
44
+ return previous.input === input ? JSON.parse(previous.result) : { ok: false, code: "invalid" };
45
+ const now = this.core.now(), old = agentIntro(db, e.id), exists = old.introBy !== undefined, changed = !(value.source === "default" && exists) && (!exists || old.intro !== text);
46
+ const day = Math.floor(now / 86400000), row = db.prepare("SELECT changes FROM hub_agent_intro_changes WHERE exposure_id=? AND day=?").get(e.id, day);
47
+ if (changed && value.source === "agent" && (row?.changes ?? 0) >= 5)
48
+ return { ok: false, code: "limit", resetsAt: (day + 1) * 86400000 };
49
+ if (changed) {
50
+ db.prepare("INSERT INTO hub_agent_intros(exposure_id,text,source,updated_at) VALUES(?,?,?,?) ON CONFLICT(exposure_id) DO UPDATE SET text=excluded.text,source=excluded.source,updated_at=excluded.updated_at").run(e.id, text, value.source, now);
51
+ if (value.source === "agent")
52
+ db.prepare("INSERT INTO hub_agent_intro_changes VALUES(?,?,1) ON CONFLICT(exposure_id,day) DO UPDATE SET changes=changes+1").run(e.id, day);
53
+ if (value.source === "default" && text && db.prepare("SELECT 1 FROM hub_agent_intro_existing WHERE exposure_id=?").get(e.id)) {
54
+ const n = db.prepare("SELECT batches,acknowledged_at,seen FROM hub_agent_intro_notices WHERE owner=?").get(owner);
55
+ const batches = n && n.acknowledged_at === null ? JSON.parse(n.batches) : [];
56
+ let batch = batches.find(b => b.fleetId === link.fleetId);
57
+ if (!batch) {
58
+ batch = { fleetId: link.fleetId, fleet: this.core.deps.store.read().fleets.find(f => f.id === link.fleetId)?.label ?? null, more: !!n && (n.seen === 1 || batches.length > 0), agents: [] };
59
+ batches.push(batch);
60
+ }
61
+ if (!batch.agents.some(a => a.id === e.id))
62
+ batch.agents.push({ id: e.id, name: e.display_name });
63
+ db.prepare("INSERT INTO hub_agent_intro_notices(owner,batches) VALUES(?,?) ON CONFLICT(owner) DO UPDATE SET batches=excluded.batches,acknowledged_at=NULL").run(owner, JSON.stringify(batches));
64
+ }
65
+ this.core.audit(tx, { requestId: operationId, actor: { kind: "member", fleetId: link.fleetId }, action: "agent.intro-updated", result: "completed", exposureId: e.id, ownerAtEvent: link.owner });
66
+ }
67
+ const result = { ok: true, ...agentIntro(db, e.id), changed };
68
+ db.prepare("INSERT INTO hub_agent_intro_operations VALUES(?,?,?,?)").run(link.fleetId, operationId, input, JSON.stringify(result));
69
+ db.prepare("DELETE FROM hub_agent_intro_changes WHERE exposure_id=? AND day<?").run(e.id, day - 1);
70
+ return result;
71
+ });
72
+ }
73
+ async notice(ctx) {
74
+ const owner = personKeyString(await ctx.requirePerson());
75
+ return this.core.atomic(db => {
76
+ const row = db.prepare("SELECT batches FROM hub_agent_intro_notices WHERE owner=? AND acknowledged_at IS NULL").get(owner);
77
+ return { notice: row ? { id: "agent-introductions", batches: JSON.parse(row.batches) } : null };
78
+ });
79
+ }
80
+ async acknowledge(ctx) { const owner = personKeyString(await ctx.requirePerson()); this.core.atomic(db => { if (ctx.isCurrent && !ctx.isCurrent())
81
+ throw new HubProtocolError("revoked"); db.prepare("UPDATE hub_agent_intro_notices SET acknowledged_at=?,seen=1 WHERE owner=?").run(this.core.now(), owner); }); return { ok: true }; }
82
+ }
83
+ //# sourceMappingURL=agent-intro-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-intro-tool.js","sourceRoot":"","sources":["../../src/hub/agent-intro-tool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAC,gBAAgB,EAAC,0BAA0B,EAA0B,MAAM,wBAAwB,CAAC;AAC5G,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAI9C,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,MAAM,CAAC,MAAM,8BAA8B,GAAC,MAAM,CAAC,MAAM,CAAC,EAAC,SAAS,EAAC,qBAAqB,EAAC,OAAO,EAAC,CAAC,EAAC,EAAE,CAAC,EAAoB;QAC3H,4FAA4F;QAC5F,MAAM,SAAS,GAAE,EAAE,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC,GAAG,EAAsB,CAAC,IAAI,CAAC,CAAC,CAAA,EAAE,CAAA,CAAC,CAAC,IAAI,KAAG,aAAa,CAAC,CAAA,CAAC,CAAA,qBAAqB,CAAA,CAAC,CAAA,GAAG,CAAC;QACpJ,EAAE,CAAC,IAAI,CAAC;;;;2EAIkE,SAAS;;CAEnF,CAAC,CAAC;IAAA,CAAC,EAAC,CAAC,CAAC;AAEP,MAAM,OAAO,iBAAiB;IACT,IAAI;IAAxB,YAAoB,IAAY;oBAAZ,IAAI;IAAU,CAAC;IACnC,OAAO,CAAC,GAAW,EAAC,IAAmB,EAAC,WAAkB;QACzD,IAAG,CAAC,IAAI,C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CAAC;QACf,CAAC,CAAC,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,GAAqB;QACjC,MAAM,KAAK,GAAC,eAAe,CAAC,MAAM,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAA,EAAE;YAC3B,MAAM,GAAG,GAAC,EAAE,CAAC,OAAO,CAAC,uFAAuF,CAAC,CAAC,GAAG,CAAC,KAAK,CAA+B,CAAC;YACvJ,OAAO,EAAC,MAAM,EAAC,GAAG,CAAA,CAAC,CAAA,EAAC,EAAE,EAAC,qBAAqB,EAAC,OAAO,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAuB,EAAC,CAAA,CAAC,CAAA,IAAI,EAAC,CAAC;QAC3G,CAAC,CAAC,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,WAAW,CAAC,GAAqB,IAAE,MAAM,KAAK,GAAC,eAAe,CAAC,MAAM,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,CAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAA,EAAE,GAAC,IAAG,GAAG,CAAC,SAAS,IAAE,CAAC,GAAG,CAAC,SAAS,EAAE;QAAC,MAAM,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAA,EAAE,CAAC,OAAO,CAAC,2EAA2E,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EAAC,KAAK,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA,OAAO,EAAC,EAAE,EAAC,IAAI,EAAC,CAAC,CAAA,CAAC;CACvU"}
@@ -0,0 +1,31 @@
1
+ /** Hub-owned, explicitly published introductions; never part of a Fleet's private catalog or consent image. */
2
+ import type Database from "better-sqlite3";
3
+ import type { HubCore } from "./http/core.js";
4
+ import type { HubRequestContext } from "./types.js";
5
+ export declare function normalizeAgentIntro(value: unknown): string;
6
+ export declare const HUB_AGENT_INTROS_MIGRATION: Readonly<{
7
+ component: "s3-agent-intros";
8
+ version: 1;
9
+ up(db: Database.Database): void;
10
+ }>;
11
+ export declare function agentIntro(db: Database.Database, id: string): {
12
+ intro: string;
13
+ introBy?: "owner" | "agent" | "default";
14
+ introAt?: number;
15
+ };
16
+ export declare function writeOwnerIntro(db: Database.Database, id: string, text: string, now: number): void;
17
+ export declare class HubAgentIntros {
18
+ private readonly core;
19
+ constructor(core: HubCore);
20
+ /** Call only after the surrounding catalog/room authorization. */
21
+ projection(id: string): {
22
+ intro: string;
23
+ introBy?: "owner" | "agent" | "default";
24
+ introAt?: number;
25
+ };
26
+ save(ctx: HubRequestContext, id: string, revision: number, value: unknown): Promise<{
27
+ intro: string;
28
+ introBy?: "owner" | "agent" | "default";
29
+ introAt?: number;
30
+ }>;
31
+ }
@@ -0,0 +1,51 @@
1
+ import { readExposure } from "./catalog.js";
2
+ import { personKeyString } from "./identity.js";
3
+ import { HubProtocolError } from "./validation.js";
4
+ const segments = new Intl.Segmenter(undefined, { granularity: "grapheme" });
5
+ export function normalizeAgentIntro(value) {
6
+ if (typeof value !== "string")
7
+ throw new HubProtocolError("invalid");
8
+ const text = value.normalize("NFC").replace(/[\p{Cc}\p{Zl}\p{Zp}\u202a-\u202e\u2066-\u2069]/gu, " ").replace(/\s+/gu, " ").trim();
9
+ if ([...segments.segment(text)].length > 50)
10
+ throw new HubProtocolError("invalid");
11
+ return text;
12
+ }
13
+ export const HUB_AGENT_INTROS_MIGRATION = Object.freeze({ component: "s3-agent-intros", version: 1, up(db) {
14
+ db.exec(`CREATE TABLE hub_agent_intros(exposure_id TEXT PRIMARY KEY REFERENCES hub_exposures(id) ON DELETE CASCADE,
15
+ text TEXT NOT NULL, source TEXT NOT NULL CHECK(source IN ('owner','agent','default')), updated_at INTEGER NOT NULL)`);
16
+ } });
17
+ export function agentIntro(db, id) {
18
+ const row = db.prepare("SELECT text,source,updated_at FROM hub_agent_intros WHERE exposure_id=?").get(id);
19
+ return row ? { intro: row.text, introBy: row.source, introAt: row.updated_at } : { intro: "" };
20
+ }
21
+ export function writeOwnerIntro(db, id, text, now) {
22
+ db.prepare(`INSERT INTO hub_agent_intros(exposure_id,text,source,updated_at) VALUES(?,?,'owner',?)
23
+ ON CONFLICT(exposure_id) DO UPDATE SET text=excluded.text,source=excluded.source,updated_at=excluded.updated_at`).run(id, text, now);
24
+ }
25
+ export class HubAgentIntros {
26
+ core;
27
+ constructor(core) {
28
+ this.core = core;
29
+ }
30
+ /** Call only after the surrounding catalog/room authorization. */
31
+ projection(id) { return this.core.atomic(db => agentIntro(db, id)); }
32
+ async save(ctx, id, revision, value) {
33
+ const person = await ctx.requirePerson(), owner = personKeyString(person), text = normalizeAgentIntro(value);
34
+ const permit = { assertCurrent: () => { if (ctx.isCurrent && !ctx.isCurrent())
35
+ throw new HubProtocolError("revoked"); } };
36
+ return this.core.atomic((db, tx) => {
37
+ const e = readExposure(db, id);
38
+ if (!e || e.owner !== owner)
39
+ throw new HubProtocolError("not-found");
40
+ if (e.revision !== revision)
41
+ throw new HubProtocolError("conflict");
42
+ writeOwnerIntro(db, id, text, this.core.now());
43
+ // Personal definitions use this field for display only. Keep both owner editing surfaces in sync.
44
+ if (e.source_kind === "personal")
45
+ db.prepare("UPDATE hub_personal_agents SET description=? WHERE id=?").run(text, e.personal_agent_id);
46
+ this.core.audit(tx, { requestId: ctx.requestId, actor: { kind: "person", person }, action: "agent.intro-updated", result: "completed", exposureId: id });
47
+ return agentIntro(db, id);
48
+ }, permit);
49
+ }
50
+ }
51
+ //# sourceMappingURL=agent-intro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-intro.js","sourceRoot":"","sources":["../../src/hub/agent-intro.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE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AC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YAC5C,kGAAkG;YAClG,IAAG,CAAC,CAAC,WAAW,KAAG,UAAU;gBAAC,EAAE,CAAC,OAAO,CAAC,yDAAyD,CAAC,CAAC,GAAG,CAAC,IAAI,EAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;YAClI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAC,EAAC,SAAS,EAAC,GAAG,CAAC,SAAS,EAAC,KAAK,EAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,MAAM,EAAC,EAAC,MAAM,EAAC,qBAAqB,EAAC,MAAM,EAAC,WAAW,EAAC,UAAU,EAAC,EAAE,EAAC,CAAC,CAAC;YACzI,OAAO,UAAU,CAAC,EAAE,EAAC,EAAE,CAAC,CAAC;QAC3B,CAAC,EAAC,MAAM,CAAC,CAAC;IACZ,CAAC;CACF"}
@@ -1,3 +1,4 @@
1
+ import { type SharingSettlement } from "./sharing-withdrawal.js";
1
2
  import type Database from "better-sqlite3";
2
3
  import { HubProtocolError } from "./validation.js";
3
4
  import type { HubExposure, HubExposureSnapshot, HubGrant, HubRequestContext, PersonKey } from "./types.js";
@@ -10,7 +11,7 @@ export declare const GRANT_MAX_MS: number;
10
11
  export declare class HubPublicationRefusal extends HubProtocolError {
11
12
  constructor(code: "denied" | "unavailable");
12
13
  }
13
- interface ExposureRow {
14
+ export interface ExposureRow {
14
15
  id: string;
15
16
  fleet_id: string | null;
16
17
  owner: string;
@@ -66,7 +67,8 @@ export interface HubCatalogView {
66
67
  }
67
68
  export declare class HubCatalogService {
68
69
  private readonly core;
69
- constructor(core: HubCore);
70
+ private readonly settled?;
71
+ constructor(core: HubCore, settled?: ((value: SharingSettlement) => void) | undefined);
70
72
  /** A member's complete catalog revision, from its authenticated link (S1 already refused another fleet or owner). */
71
73
  receiveSnapshot(input: HubExposureSnapshot, incoming: HubLinkContext, requestId?: string): Promise<void>;
72
74
  /** What this person may see: their own exposures (with the grants on them) and what is granted to them now. */