@rise-x/apps-sdk 0.6.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.
Files changed (185) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +553 -0
  3. package/build/_internal.d.ts +2 -0
  4. package/build/_internal.js +23 -0
  5. package/build/accessors.d.ts +8 -0
  6. package/build/accessors.js +40 -0
  7. package/build/cli/index.d.ts +13 -0
  8. package/build/cli/index.js +54 -0
  9. package/build/cli/init.d.ts +6 -0
  10. package/build/cli/init.js +179 -0
  11. package/build/cli/templating.d.ts +2 -0
  12. package/build/cli/templating.js +84 -0
  13. package/build/connectors/agents.d.ts +85 -0
  14. package/build/connectors/agents.js +404 -0
  15. package/build/connectors/assets.d.ts +76 -0
  16. package/build/connectors/assets.js +204 -0
  17. package/build/connectors/deps.d.ts +4 -0
  18. package/build/connectors/deps.js +2 -0
  19. package/build/connectors/errors.d.ts +11 -0
  20. package/build/connectors/errors.js +67 -0
  21. package/build/connectors/flows.d.ts +37 -0
  22. package/build/connectors/flows.js +191 -0
  23. package/build/connectors/index.d.ts +8 -0
  24. package/build/connectors/index.js +50 -0
  25. package/build/connectors/sse.d.ts +12 -0
  26. package/build/connectors/sse.js +157 -0
  27. package/build/connectors/types.d.ts +285 -0
  28. package/build/connectors/types.js +419 -0
  29. package/build/connectors/work.d.ts +84 -0
  30. package/build/connectors/work.js +224 -0
  31. package/build/hooks.d.ts +4 -0
  32. package/build/hooks.js +28 -0
  33. package/build/index.d.ts +6 -0
  34. package/build/index.js +34 -0
  35. package/build/lifecycle.d.ts +23 -0
  36. package/build/lifecycle.js +6 -0
  37. package/build/mockShell.d.ts +10 -0
  38. package/build/mockShell.js +55 -0
  39. package/build/query/agents.d.ts +80 -0
  40. package/build/query/agents.js +143 -0
  41. package/build/query/assets.d.ts +73 -0
  42. package/build/query/assets.js +152 -0
  43. package/build/query/client.d.ts +5 -0
  44. package/build/query/client.js +68 -0
  45. package/build/query/context.d.ts +2 -0
  46. package/build/query/context.js +34 -0
  47. package/build/query/flows.d.ts +54 -0
  48. package/build/query/flows.js +81 -0
  49. package/build/query/index.d.ts +10 -0
  50. package/build/query/index.js +85 -0
  51. package/build/query/keys.d.ts +51 -0
  52. package/build/query/keys.js +79 -0
  53. package/build/query/layer.d.ts +175 -0
  54. package/build/query/layer.js +35 -0
  55. package/build/query/shared.d.ts +43 -0
  56. package/build/query/shared.js +116 -0
  57. package/build/query/work.d.ts +75 -0
  58. package/build/query/work.js +172 -0
  59. package/build/shell/index.d.ts +1 -0
  60. package/build/shell/index.js +6 -0
  61. package/build/shell/installShellBridge.d.ts +11 -0
  62. package/build/shell/installShellBridge.js +104 -0
  63. package/build/shellBridge.d.ts +36 -0
  64. package/build/shellBridge.js +10 -0
  65. package/build/topBar.d.ts +25 -0
  66. package/build/topBar.js +17 -0
  67. package/build/ui/components/ai.d.ts +49 -0
  68. package/build/ui/components/alert-dialog.d.ts +27 -0
  69. package/build/ui/components/alert.d.ts +14 -0
  70. package/build/ui/components/avatar.d.ts +17 -0
  71. package/build/ui/components/badge.d.ts +19 -0
  72. package/build/ui/components/button.d.ts +13 -0
  73. package/build/ui/components/calendar.d.ts +21 -0
  74. package/build/ui/components/card.d.ts +16 -0
  75. package/build/ui/components/chart.d.ts +124 -0
  76. package/build/ui/components/checkbox.d.ts +4 -0
  77. package/build/ui/components/data-table.d.ts +70 -0
  78. package/build/ui/components/dialog.d.ts +17 -0
  79. package/build/ui/components/dropdown-menu.d.ts +29 -0
  80. package/build/ui/components/empty-state.d.ts +7 -0
  81. package/build/ui/components/file-upload.d.ts +17 -0
  82. package/build/ui/components/input.d.ts +8 -0
  83. package/build/ui/components/label.d.ts +4 -0
  84. package/build/ui/components/list.d.ts +24 -0
  85. package/build/ui/components/map.d.ts +26 -0
  86. package/build/ui/components/message.d.ts +24 -0
  87. package/build/ui/components/nav.d.ts +12 -0
  88. package/build/ui/components/page-header.d.ts +27 -0
  89. package/build/ui/components/popover.d.ts +10 -0
  90. package/build/ui/components/progress.d.ts +4 -0
  91. package/build/ui/components/radio.d.ts +6 -0
  92. package/build/ui/components/resizable.d.ts +7 -0
  93. package/build/ui/components/scroll-area.d.ts +5 -0
  94. package/build/ui/components/segmented.d.ts +6 -0
  95. package/build/ui/components/select.d.ts +15 -0
  96. package/build/ui/components/separator.d.ts +4 -0
  97. package/build/ui/components/sheet.d.ts +14 -0
  98. package/build/ui/components/skeleton.d.ts +3 -0
  99. package/build/ui/components/slider.d.ts +15 -0
  100. package/build/ui/components/snackbar.d.ts +3 -0
  101. package/build/ui/components/sonner.d.ts +4 -0
  102. package/build/ui/components/spinner.d.ts +5 -0
  103. package/build/ui/components/statistic.d.ts +19 -0
  104. package/build/ui/components/stepper.d.ts +12 -0
  105. package/build/ui/components/switch.d.ts +6 -0
  106. package/build/ui/components/table.d.ts +24 -0
  107. package/build/ui/components/textarea.d.ts +3 -0
  108. package/build/ui/components/timeline.d.ts +15 -0
  109. package/build/ui/components/toggle-group.d.ts +10 -0
  110. package/build/ui/components/toggle.d.ts +9 -0
  111. package/build/ui/components/tooltip.d.ts +7 -0
  112. package/build/ui/index.d.ts +46 -0
  113. package/build/ui/index.js +8 -0
  114. package/build/ui/lib/utils.d.ts +2 -0
  115. package/build/ui/reference/README.md +11 -0
  116. package/build/ui/reference/components/ai.tsx +291 -0
  117. package/build/ui/reference/components/alert-dialog.tsx +208 -0
  118. package/build/ui/reference/components/alert.tsx +112 -0
  119. package/build/ui/reference/components/avatar.tsx +158 -0
  120. package/build/ui/reference/components/badge.tsx +160 -0
  121. package/build/ui/reference/components/button.tsx +100 -0
  122. package/build/ui/reference/components/calendar.tsx +119 -0
  123. package/build/ui/reference/components/card.tsx +144 -0
  124. package/build/ui/reference/components/chart.tsx +1394 -0
  125. package/build/ui/reference/components/checkbox.tsx +44 -0
  126. package/build/ui/reference/components/data-table.tsx +480 -0
  127. package/build/ui/reference/components/dialog.tsx +172 -0
  128. package/build/ui/reference/components/dropdown-menu.tsx +245 -0
  129. package/build/ui/reference/components/empty-state.tsx +63 -0
  130. package/build/ui/reference/components/file-upload.tsx +116 -0
  131. package/build/ui/reference/components/input.tsx +114 -0
  132. package/build/ui/reference/components/label.tsx +19 -0
  133. package/build/ui/reference/components/list.tsx +191 -0
  134. package/build/ui/reference/components/map.css +251 -0
  135. package/build/ui/reference/components/map.tsx +294 -0
  136. package/build/ui/reference/components/message.tsx +171 -0
  137. package/build/ui/reference/components/nav.tsx +113 -0
  138. package/build/ui/reference/components/page-header.tsx +213 -0
  139. package/build/ui/reference/components/popover.tsx +76 -0
  140. package/build/ui/reference/components/progress.tsx +31 -0
  141. package/build/ui/reference/components/radio.tsx +65 -0
  142. package/build/ui/reference/components/resizable.tsx +40 -0
  143. package/build/ui/reference/components/scroll-area.tsx +55 -0
  144. package/build/ui/reference/components/segmented.tsx +45 -0
  145. package/build/ui/reference/components/select.tsx +185 -0
  146. package/build/ui/reference/components/separator.tsx +26 -0
  147. package/build/ui/reference/components/sheet.tsx +173 -0
  148. package/build/ui/reference/components/skeleton.tsx +15 -0
  149. package/build/ui/reference/components/slider.tsx +161 -0
  150. package/build/ui/reference/components/snackbar.tsx +27 -0
  151. package/build/ui/reference/components/sonner.tsx +43 -0
  152. package/build/ui/reference/components/spinner.tsx +27 -0
  153. package/build/ui/reference/components/statistic.tsx +122 -0
  154. package/build/ui/reference/components/stepper.tsx +138 -0
  155. package/build/ui/reference/components/switch.tsx +47 -0
  156. package/build/ui/reference/components/table.tsx +233 -0
  157. package/build/ui/reference/components/textarea.tsx +28 -0
  158. package/build/ui/reference/components/timeline.tsx +94 -0
  159. package/build/ui/reference/components/toggle-group.tsx +86 -0
  160. package/build/ui/reference/components/toggle.tsx +46 -0
  161. package/build/ui/reference/components/tooltip.tsx +53 -0
  162. package/build/ui/reference/index.ts +49 -0
  163. package/build/ui/reference/lib/utils.ts +34 -0
  164. package/build/ui/standalone-stub.js +5 -0
  165. package/build/ui/standalone.js +135 -0
  166. package/build/ui/styles.css +3 -0
  167. package/connectors/package.json +8 -0
  168. package/package.json +114 -0
  169. package/query/package.json +8 -0
  170. package/shell/package.json +8 -0
  171. package/template/AGENTS.md +70 -0
  172. package/template/CLAUDE.md +4 -0
  173. package/template/README.md +102 -0
  174. package/template/_gitignore +6 -0
  175. package/template/commitlint.config.js +12 -0
  176. package/template/package.json +31 -0
  177. package/template/public/index.html +13 -0
  178. package/template/src/App.tsx +171 -0
  179. package/template/src/bootstrap.tsx +13 -0
  180. package/template/src/index.tsx +1 -0
  181. package/template/src/lifecycle.ts +20 -0
  182. package/template/tsconfig.json +31 -0
  183. package/template/webpack.config.js +112 -0
  184. package/template/webpack.local.config.js +68 -0
  185. package/ui/package.json +8 -0
@@ -0,0 +1,404 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agents = void 0;
4
+ exports.agentMessageText = agentMessageText;
5
+ exports.agentEndReason = agentEndReason;
6
+ exports.agentErrorText = agentErrorText;
7
+ exports.streamAgentReply = streamAgentReply;
8
+ exports.collectAgentReply = collectAgentReply;
9
+ exports.createAgentsConnector = createAgentsConnector;
10
+ const _internal_1 = require("../_internal");
11
+ const errors_1 = require("./errors");
12
+ const sse_1 = require("./sse");
13
+ const types_1 = require("./types");
14
+ // Agent config registry (rise-x-api, v4 'config' scope).
15
+ const AGENT_PATH = "/api/v4/config/agent";
16
+ // Server-persisted chat store (rise-x-api Phase C). Served by the same
17
+ // api-config deployable as AGENT_PATH, so it rides the same getApiV4('config')
18
+ // client — the ai/* prefix is just the AI-runtime data namespace.
19
+ const AGENT_CHAT_PATH = "/api/v4/ai/agent-chat";
20
+ // The API redacts stored MCP api keys to this sentinel on every read.
21
+ const REDACTED_SECRET = "***";
22
+ // PATCH must never echo the redaction sentinel back — the server would store
23
+ // the literal "***" as the key. Drop redacted apiKey fields from the payload.
24
+ function stripRedactedSecrets(patch) {
25
+ if (!patch.mcpServers)
26
+ return patch;
27
+ return {
28
+ ...patch,
29
+ mcpServers: patch.mcpServers.map((server) => {
30
+ if (server.apiKey !== REDACTED_SECRET)
31
+ return server;
32
+ const { apiKey: _redacted, ...rest } = server;
33
+ return rest;
34
+ }),
35
+ };
36
+ }
37
+ function eventData(raw) {
38
+ // Tolerate non-JSON frames (keep-alive text, partial vendor events) — a bad
39
+ // frame must not kill the stream.
40
+ try {
41
+ return JSON.parse(raw);
42
+ }
43
+ catch {
44
+ return raw;
45
+ }
46
+ }
47
+ // The terminal end_of_stream event carries the server chat id this turn was
48
+ // persisted under (chat_id, snake_case from the FastAPI gateway). Tolerate a
49
+ // camelCase alias too.
50
+ function extractChatId(event) {
51
+ if (event.event !== types_1.AGENT_END_OF_STREAM)
52
+ return undefined;
53
+ const data = event.data;
54
+ const id = data?.chat_id ?? data?.chatId;
55
+ return typeof id === "string" && id !== "" ? id : undefined;
56
+ }
57
+ // --- Run-event readers -----------------------------------------------------
58
+ // agents.run()/chat.send() yield raw AgentRunEvents; these encode the gateway's
59
+ // SSE contract so apps don't hand-roll it (and get the delta semantics wrong).
60
+ // The assistant text DELTA carried by a run event, or null if it carries none.
61
+ // Accumulate these to render the streamed reply: the gateway emits assistant
62
+ // text as `agent_event` frames (event_type "MESSAGE") whose `text` is a
63
+ // per-token delta — it never resends the full string. Reasoning, tool-call,
64
+ // handoff, and lifecycle frames (request_received, end_of_stream, …) yield null.
65
+ function agentMessageText(event) {
66
+ if (event.event !== types_1.AGENT_EVENT)
67
+ return null;
68
+ const data = event.data;
69
+ if (!data || typeof data !== "object" || data.event_type !== "MESSAGE") {
70
+ return null;
71
+ }
72
+ return typeof data.text === "string" ? data.text : null;
73
+ }
74
+ // The four terminal reasons the gateway emits — used to validate the wire value
75
+ // before narrowing to AgentRunEndReason (an unknown reason returns null rather
76
+ // than a mistyped cast).
77
+ const AGENT_RUN_END_REASONS = [
78
+ "COMPLETED",
79
+ "TIMEOUT",
80
+ "CANCELLED",
81
+ "ERROR",
82
+ ];
83
+ // The terminal reason from an `end_of_stream` frame, else null (also null for an
84
+ // unrecognized reason). A non-COMPLETED reason (TIMEOUT | CANCELLED | ERROR)
85
+ // means the reply is incomplete.
86
+ function agentEndReason(event) {
87
+ if (event.event !== types_1.AGENT_END_OF_STREAM)
88
+ return null;
89
+ const data = event.data;
90
+ const reason = data && typeof data === "object" ? data.reason : undefined;
91
+ return typeof reason === "string" &&
92
+ AGENT_RUN_END_REASONS.includes(reason)
93
+ ? reason
94
+ : null;
95
+ }
96
+ // The human-readable message from a mid-stream `error` frame, else null. An
97
+ // `error` frame is always followed by `end_of_stream` with reason "ERROR".
98
+ function agentErrorText(event) {
99
+ if (event.event !== types_1.AGENT_ERROR)
100
+ return null;
101
+ const data = event.data;
102
+ const message = data && typeof data === "object" ? data.error : undefined;
103
+ return typeof message === "string" && message !== "" ? message : null;
104
+ }
105
+ // Consume a run()/send() stream into accumulated snapshots. Yields a fresh
106
+ // AgentReplyState whenever the assistant text grows, an error arrives, or the
107
+ // stream terminates — so callers never hand-roll delta accumulation. Reasoning,
108
+ // tool-call, and handoff frames are skipped here; read the raw stream for those.
109
+ async function* streamAgentReply(events) {
110
+ let text = "";
111
+ let error = null;
112
+ let chatId;
113
+ // Single source of truth for the snapshot shape; closes over the running
114
+ // text/error/chatId so callers only vary delta/done/reason.
115
+ const snap = (delta, done, reason) => ({ text, delta, done, reason, error, chatId });
116
+ for await (const event of events) {
117
+ // An empty-string MESSAGE delta adds nothing — skip it (no redundant snapshot).
118
+ const delta = agentMessageText(event);
119
+ if (delta) {
120
+ text += delta;
121
+ yield snap(delta, false, null);
122
+ continue;
123
+ }
124
+ // Detect the terminal frame by name (not by reason presence) so a malformed
125
+ // end_of_stream still marks done and surfaces the chat id.
126
+ if (event.event === types_1.AGENT_END_OF_STREAM) {
127
+ const id = extractChatId(event);
128
+ if (id)
129
+ chatId = id;
130
+ yield snap("", true, agentEndReason(event));
131
+ continue;
132
+ }
133
+ const errText = agentErrorText(event);
134
+ if (errText !== null) {
135
+ error = errText;
136
+ yield snap("", false, null);
137
+ }
138
+ }
139
+ }
140
+ // Drain a run()/send() stream to completion and return only the final state.
141
+ // For non-streaming callers that just want the whole answer at once.
142
+ async function collectAgentReply(events) {
143
+ let last = {
144
+ text: "",
145
+ delta: "",
146
+ done: false,
147
+ reason: null,
148
+ error: null,
149
+ chatId: undefined,
150
+ };
151
+ for await (const state of streamAgentReply(events)) {
152
+ last = state;
153
+ }
154
+ return last;
155
+ }
156
+ function createAgentsConnector(deps = { shell: _internal_1.requireShell }) {
157
+ const configApi = () => deps.shell().getApiV4("config");
158
+ const resolveAi = () => {
159
+ const shell = deps.shell();
160
+ if (typeof shell.getAi !== "function") {
161
+ throw new errors_1.ConnectorError("SHELL_TOO_OLD", "agents.run requires shell bridge v3 (getAi) — update the Rise-X shell");
162
+ }
163
+ const ai = shell.getAi();
164
+ if (!ai) {
165
+ throw new errors_1.ConnectorError("AI_UNAVAILABLE", "no AI gateway is configured for this deployment");
166
+ }
167
+ return ai;
168
+ };
169
+ const list = async (args = {}) => {
170
+ try {
171
+ const page = args.page ?? 1;
172
+ const pageSize = args.pageSize ?? 20;
173
+ // The server binds the filter from the `search` query parameter
174
+ // (ListAgentsQuery.Search) — there is no `q` alias.
175
+ const { data } = await configApi().get(AGENT_PATH, {
176
+ params: { page, pageSize, search: args.search },
177
+ signal: args.signal,
178
+ });
179
+ return (0, types_1.mapAgentPage)(data, { page, pageSize });
180
+ }
181
+ catch (e) {
182
+ throw (0, errors_1.toConnectorError)(e);
183
+ }
184
+ };
185
+ const get = async (id, opts = {}) => {
186
+ try {
187
+ const { data } = await configApi().get(`${AGENT_PATH}/${id}`, {
188
+ signal: opts.signal,
189
+ });
190
+ return (0, types_1.mapAgent)(data ?? {});
191
+ }
192
+ catch (e) {
193
+ throw (0, errors_1.toConnectorError)(e);
194
+ }
195
+ };
196
+ const create = async (input, opts = {}) => {
197
+ try {
198
+ const { data } = await configApi().post(AGENT_PATH, input, {
199
+ signal: opts.signal,
200
+ });
201
+ return (0, types_1.mapAgent)(data ?? {});
202
+ }
203
+ catch (e) {
204
+ throw (0, errors_1.toConnectorError)(e);
205
+ }
206
+ };
207
+ const update = async (id, patch, opts = {}) => {
208
+ try {
209
+ const { data } = await configApi().patch(`${AGENT_PATH}/${id}`, stripRedactedSecrets(patch), { signal: opts.signal });
210
+ return (0, types_1.mapAgent)(data ?? {});
211
+ }
212
+ catch (e) {
213
+ throw (0, errors_1.toConnectorError)(e);
214
+ }
215
+ };
216
+ const remove = async (id, opts = {}) => {
217
+ try {
218
+ await configApi().delete(`${AGENT_PATH}/${id}`, { signal: opts.signal });
219
+ }
220
+ catch (e) {
221
+ throw (0, errors_1.toConnectorError)(e);
222
+ }
223
+ };
224
+ const run = async function* (args) {
225
+ // Mirror the gateway's 400: continuing a chat requires history.
226
+ if (args.chatId && args.useHistory === false) {
227
+ throw new errors_1.ConnectorError("INVALID_ARG", "agents.run: chatId cannot be combined with useHistory:false");
228
+ }
229
+ const ai = resolveAi();
230
+ let response;
231
+ try {
232
+ // fetch, not axios: the response is an SSE stream read incrementally.
233
+ response = await fetch(`${ai.baseUrl}/api/v1/agent/run`, {
234
+ method: "POST",
235
+ headers: {
236
+ ...ai.getHeaders(),
237
+ "Content-Type": "application/json",
238
+ Accept: "text/event-stream",
239
+ },
240
+ // Gateway is FastAPI — snake_case wire contract. use_history defaults to
241
+ // true server-side, so omit it unless the caller opts out.
242
+ body: JSON.stringify({
243
+ agent_id: args.agentId,
244
+ message: args.message,
245
+ chat_id: args.chatId,
246
+ ...(args.useHistory === false && { use_history: false }),
247
+ session_id: args.sessionId,
248
+ context: args.context,
249
+ }),
250
+ signal: args.signal,
251
+ });
252
+ }
253
+ catch (e) {
254
+ throw (0, errors_1.toConnectorError)(e);
255
+ }
256
+ if (!response.ok) {
257
+ let message = `agent run failed with status ${response.status}`;
258
+ try {
259
+ const body = (await response.json());
260
+ const detail = body?.detail ?? body?.message;
261
+ if (typeof detail === "string" && detail)
262
+ message = detail;
263
+ }
264
+ catch {
265
+ // non-JSON error body — keep the generic message
266
+ }
267
+ throw new errors_1.ConnectorError(response.status === 404 ? "NOT_FOUND" : "HTTP_ERROR", message, {
268
+ status: response.status,
269
+ });
270
+ }
271
+ if (!response.body) {
272
+ throw new errors_1.ConnectorError("NETWORK_ERROR", "agent run response has no body");
273
+ }
274
+ for await (const frame of (0, sse_1.iterateSseResponse)(response.body, args.signal)) {
275
+ yield {
276
+ event: frame.event ?? "message",
277
+ id: frame.id,
278
+ data: eventData(frame.data),
279
+ };
280
+ }
281
+ };
282
+ const createChat = ({ agentId, chatId: initialChatId, sessionId, }) => {
283
+ let chatId = initialChatId;
284
+ return {
285
+ agentId,
286
+ get chatId() {
287
+ return chatId;
288
+ },
289
+ send(message, opts = {}) {
290
+ const chatIdForTurn = chatId;
291
+ return (async function* () {
292
+ for await (const event of run({
293
+ agentId,
294
+ message,
295
+ chatId: chatIdForTurn,
296
+ sessionId,
297
+ context: opts.context,
298
+ signal: opts.signal,
299
+ })) {
300
+ // The first turn's end_of_stream reports the freshly-created chat id;
301
+ // capture it so the next send() continues that server chat.
302
+ const id = extractChatId(event);
303
+ if (id)
304
+ chatId = id;
305
+ yield event;
306
+ }
307
+ })();
308
+ },
309
+ reset() {
310
+ chatId = undefined;
311
+ },
312
+ };
313
+ };
314
+ const listChats = async (args = {}) => {
315
+ try {
316
+ const page = args.page ?? 1;
317
+ const pageSize = args.pageSize ?? 20;
318
+ const { data } = await configApi().get(AGENT_CHAT_PATH, {
319
+ params: { page, pageSize, agentId: args.agentId },
320
+ signal: args.signal,
321
+ });
322
+ return (0, types_1.mapAgentChatPage)(data, { page, pageSize });
323
+ }
324
+ catch (e) {
325
+ throw (0, errors_1.toConnectorError)(e);
326
+ }
327
+ };
328
+ const getChat = async (id, opts = {}) => {
329
+ if (!id) {
330
+ throw new errors_1.ConnectorError("INVALID_ARG", "agents.getChat: id is required");
331
+ }
332
+ try {
333
+ const { data } = await configApi().get(`${AGENT_CHAT_PATH}/${id}`, { signal: opts.signal });
334
+ return (0, types_1.mapAgentChat)(data ?? {});
335
+ }
336
+ catch (e) {
337
+ throw (0, errors_1.toConnectorError)(e);
338
+ }
339
+ };
340
+ const renameChat = async (id, title, opts = {}) => {
341
+ if (!id) {
342
+ throw new errors_1.ConnectorError("INVALID_ARG", "agents.renameChat: id is required");
343
+ }
344
+ if (!title || title.trim() === "") {
345
+ throw new errors_1.ConnectorError("INVALID_ARG", "agents.renameChat: title must be non-empty");
346
+ }
347
+ try {
348
+ const { data } = await configApi().patch(`${AGENT_CHAT_PATH}/${id}`, { title }, { signal: opts.signal });
349
+ return (0, types_1.mapAgentChat)(data ?? {});
350
+ }
351
+ catch (e) {
352
+ throw (0, errors_1.toConnectorError)(e);
353
+ }
354
+ };
355
+ const deleteChat = async (id, opts = {}) => {
356
+ if (!id) {
357
+ throw new errors_1.ConnectorError("INVALID_ARG", "agents.deleteChat: id is required");
358
+ }
359
+ try {
360
+ await configApi().delete(`${AGENT_CHAT_PATH}/${id}`, {
361
+ signal: opts.signal,
362
+ });
363
+ }
364
+ catch (e) {
365
+ throw (0, errors_1.toConnectorError)(e);
366
+ }
367
+ };
368
+ const getChatMessages = async (id, args = {}) => {
369
+ if (!id) {
370
+ throw new errors_1.ConnectorError("INVALID_ARG", "agents.getChatMessages: id is required");
371
+ }
372
+ try {
373
+ const pageSize = args.pageSize ?? 50;
374
+ const { data } = await configApi().get(`${AGENT_CHAT_PATH}/${id}/messages`, {
375
+ params: { fromSeq: args.fromSeq, pageSize },
376
+ signal: args.signal,
377
+ });
378
+ return (0, types_1.mapAgentChatMessagePage)(data, {
379
+ fromSeq: args.fromSeq,
380
+ pageSize,
381
+ chatId: id,
382
+ });
383
+ }
384
+ catch (e) {
385
+ throw (0, errors_1.toConnectorError)(e);
386
+ }
387
+ };
388
+ return {
389
+ list,
390
+ get,
391
+ create,
392
+ update,
393
+ delete: remove,
394
+ run,
395
+ createChat,
396
+ listChats,
397
+ getChat,
398
+ renameChat,
399
+ deleteChat,
400
+ getChatMessages,
401
+ };
402
+ }
403
+ // Ready-made singleton bound to the live shell bridge.
404
+ exports.agents = createAgentsConnector();
@@ -0,0 +1,76 @@
1
+ import type { ConnectorDeps } from "./deps";
2
+ import { type AssetDetail, type AssetSummary, type AssetType, type WorkDetail } from "./types";
3
+ export type AssetTypeRef = string | AssetType;
4
+ export interface SearchAssetsArgs {
5
+ search?: string;
6
+ type?: string;
7
+ typeOriginId?: string;
8
+ dataPaths?: string[];
9
+ pageSize?: number;
10
+ skip?: number;
11
+ signal?: AbortSignal;
12
+ }
13
+ export interface ListAssetRowsArgs {
14
+ type: AssetTypeRef;
15
+ properties?: Record<string, string>;
16
+ sort?: {
17
+ field: string;
18
+ direction: "asc" | "desc";
19
+ };
20
+ pageSize?: number;
21
+ skip?: number;
22
+ signal?: AbortSignal;
23
+ }
24
+ export interface AssetRowPage {
25
+ items: AssetSummary[];
26
+ skip: number;
27
+ pageSize: number;
28
+ hasMore: boolean;
29
+ }
30
+ export interface IterateAssetRowsArgs extends Omit<ListAssetRowsArgs, "skip"> {
31
+ maxItems?: number;
32
+ }
33
+ export interface ListRelatedAssetsArgs {
34
+ assetId: string;
35
+ relationships: string[];
36
+ properties?: Record<string, string>;
37
+ targetDataType?: number;
38
+ skip?: number;
39
+ limit?: number;
40
+ signal?: AbortSignal;
41
+ }
42
+ export interface CreateAssetArgs {
43
+ type: AssetTypeRef;
44
+ signal?: AbortSignal;
45
+ }
46
+ export interface StartEditAssetArgs {
47
+ assetId: string;
48
+ flowOriginId: string;
49
+ signal?: AbortSignal;
50
+ }
51
+ export interface AssetsConnector {
52
+ types(opts?: {
53
+ signal?: AbortSignal;
54
+ }): Promise<AssetType[]>;
55
+ get(assetId: string, opts?: {
56
+ signal?: AbortSignal;
57
+ }): Promise<AssetDetail>;
58
+ search(args: SearchAssetsArgs): Promise<AssetSummary[]>;
59
+ list(args: ListAssetRowsArgs): Promise<AssetRowPage>;
60
+ iterate(args: IterateAssetRowsArgs): AsyncIterable<AssetSummary>;
61
+ listRelated(args: ListRelatedAssetsArgs): Promise<AssetSummary[]>;
62
+ create(args: CreateAssetArgs): Promise<WorkDetail>;
63
+ startEdit(args: StartEditAssetArgs): Promise<WorkDetail>;
64
+ clone(assetId: string, opts?: {
65
+ signal?: AbortSignal;
66
+ }): Promise<AssetDetail>;
67
+ delete(assetId: string, opts?: {
68
+ signal?: AbortSignal;
69
+ }): Promise<void>;
70
+ }
71
+ export declare function createAssetsConnector(deps?: ConnectorDeps): AssetsConnector;
72
+ export declare const ASSET_TARGET_DATA_TYPES: {
73
+ readonly work: 2;
74
+ readonly asset: 16;
75
+ };
76
+ export declare const assets: AssetsConnector;
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ // Assets connector — typed wrappers over the platform's asset ("entity" /
3
+ // "thing") endpoints, all v3 via the shell's getApi() client.
4
+ //
5
+ // Asset types are defined by entity flows; the flow's origin id is the type
6
+ // reference list()/create() take. Creating or editing an asset goes through a
7
+ // draft work item (the platform's edit model): create()/startEdit() return the
8
+ // draft as a WorkDetail — fill it with work.patchData() and save it with
9
+ // work.submit(), exactly like any other work item.
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.assets = exports.ASSET_TARGET_DATA_TYPES = void 0;
12
+ exports.createAssetsConnector = createAssetsConnector;
13
+ const _internal_1 = require("../_internal");
14
+ const errors_1 = require("./errors");
15
+ const work_1 = require("./work");
16
+ const types_1 = require("./types");
17
+ // DianaDataType wire codes for relationship targets.
18
+ const DATA_TYPE_WORK = 2;
19
+ const DATA_TYPE_ASSET = 16;
20
+ const resolveTypeRef = (type) => {
21
+ if (typeof type === "string")
22
+ return type;
23
+ const flowOriginId = type.flow?.flowOriginId || type.flow?.id;
24
+ if (!flowOriginId) {
25
+ // Flow-less types are real server data (integration-endpoint entity types
26
+ // carry no flow) — they just can't be listed/created through this API.
27
+ throw new errors_1.ConnectorError("INVALID_ARG", `asset type '${type.entityType}' carries no flow origin id`);
28
+ }
29
+ return flowOriginId;
30
+ };
31
+ const DEFAULT_PAGE_SIZE = 50;
32
+ function createAssetsConnector(deps = { shell: _internal_1.requireShell }) {
33
+ const api = () => deps.shell().getApi();
34
+ const types = async (opts = {}) => {
35
+ try {
36
+ const { data } = await api().get("/api/v3/asset/typesByEcosystem", { signal: opts.signal });
37
+ return (Array.isArray(data) ? data : []).map(types_1.mapAssetType);
38
+ }
39
+ catch (e) {
40
+ throw (0, errors_1.toConnectorError)(e);
41
+ }
42
+ };
43
+ const get = async (assetId, opts = {}) => {
44
+ try {
45
+ const { data } = await api().get(`/api/v3/asset/${assetId}`, { signal: opts.signal });
46
+ return (0, types_1.mapAssetDetail)(data ?? {});
47
+ }
48
+ catch (e) {
49
+ throw (0, errors_1.toConnectorError)(e);
50
+ }
51
+ };
52
+ const search = async (args) => {
53
+ if (!args.type && !args.typeOriginId) {
54
+ throw new errors_1.ConnectorError("INVALID_ARG", "assets.search needs a type or typeOriginId");
55
+ }
56
+ try {
57
+ const { data } = await api().post(
58
+ // The search endpoint routes on the type name; 'Entity' is the
59
+ // platform's catch-all when only the origin id is known.
60
+ `/api/v3/search/thing/${encodeURIComponent(args.type || "Entity")}`, {
61
+ searchString: args.search ?? "",
62
+ type: args.type ?? "",
63
+ typeOriginId: args.typeOriginId ?? "",
64
+ dataPaths: args.dataPaths,
65
+ ...(args.pageSize !== undefined && { numResults: args.pageSize }),
66
+ ...(args.skip !== undefined && { skip: args.skip }),
67
+ }, { signal: args.signal });
68
+ return (Array.isArray(data) ? data : []).map(types_1.mapAssetSummary);
69
+ }
70
+ catch (e) {
71
+ throw (0, errors_1.toConnectorError)(e);
72
+ }
73
+ };
74
+ const list = async (args) => {
75
+ const flowOriginId = resolveTypeRef(args.type);
76
+ try {
77
+ const skip = args.skip ?? 0;
78
+ const pageSize = args.pageSize ?? DEFAULT_PAGE_SIZE;
79
+ const { data } = await api().post("/api/v3/data-grid/asset-rows", {
80
+ filterProperties: [],
81
+ flowOriginIds: [flowOriginId],
82
+ workIds: [],
83
+ additionalProperties: (0, work_1.buildAdditionalProperties)(args.properties),
84
+ customViewQueries: [],
85
+ isExpandedFeatureEnabled: false,
86
+ showCompleted: true,
87
+ showInProgress: true,
88
+ skip,
89
+ limit: pageSize,
90
+ sortField: args.sort?.field ?? "createdDate",
91
+ sortDirection: args.sort?.direction ?? "desc",
92
+ }, { signal: args.signal });
93
+ const items = (Array.isArray(data) ? data : []).map(types_1.mapAssetSummary);
94
+ return { items, skip, pageSize, hasMore: items.length === pageSize };
95
+ }
96
+ catch (e) {
97
+ throw (0, errors_1.toConnectorError)(e);
98
+ }
99
+ };
100
+ const iterate = async function* (args) {
101
+ const pageSize = args.pageSize ?? DEFAULT_PAGE_SIZE;
102
+ const seen = new Set();
103
+ let skip = 0;
104
+ let yielded = 0;
105
+ for (;;) {
106
+ if (args.signal?.aborted) {
107
+ throw new errors_1.ConnectorError("ABORTED", "asset iteration aborted");
108
+ }
109
+ const page = await list({ ...args, skip, pageSize });
110
+ let newInPage = 0;
111
+ for (const row of page.items) {
112
+ // Sort-shifted pages can repeat rows; ids are stable, dedupe on them.
113
+ if (seen.has(row.id))
114
+ continue;
115
+ seen.add(row.id);
116
+ newInPage += 1;
117
+ yield row;
118
+ yielded += 1;
119
+ if (args.maxItems !== undefined && yielded >= args.maxItems)
120
+ return;
121
+ }
122
+ // A full page of nothing-but-duplicates means we're not making progress
123
+ // (server repeating rows) — bail rather than loop forever.
124
+ if (!page.hasMore || newInPage === 0)
125
+ return;
126
+ // Advance by net-new rows, not pageSize: when rows shift up between
127
+ // pages (delete / sort-field change) a full-page skip overshoots and
128
+ // silently drops the row that moved into the gap.
129
+ skip += newInPage;
130
+ }
131
+ };
132
+ const listRelated = async (args) => {
133
+ try {
134
+ const { data } = await api().post("/api/v3/data-grid/related-assets", {
135
+ sourceId: args.assetId,
136
+ targetDataType: args.targetDataType ?? DATA_TYPE_ASSET,
137
+ relationshipNames: args.relationships,
138
+ filterProperties: [],
139
+ additionalProperties: (0, work_1.buildAdditionalProperties)(args.properties),
140
+ skip: args.skip ?? 0,
141
+ limit: args.limit ?? DEFAULT_PAGE_SIZE,
142
+ }, { signal: args.signal });
143
+ return (Array.isArray(data) ? data : []).map(types_1.mapAssetSummary);
144
+ }
145
+ catch (e) {
146
+ throw (0, errors_1.toConnectorError)(e);
147
+ }
148
+ };
149
+ const create = async (args) => {
150
+ const flowOriginId = resolveTypeRef(args.type);
151
+ try {
152
+ const { data } = await api().post(`/api/v3/entity/create/${flowOriginId}`, undefined, { signal: args.signal });
153
+ return (0, types_1.mapWorkDetail)(data ?? {});
154
+ }
155
+ catch (e) {
156
+ throw (0, errors_1.toConnectorError)(e);
157
+ }
158
+ };
159
+ const startEdit = async (args) => {
160
+ try {
161
+ const { data } = await api().post(`/api/v3/asset/${args.assetId}/edit`, undefined, { params: { flowOriginId: args.flowOriginId }, signal: args.signal });
162
+ return (0, types_1.mapWorkDetail)(data ?? {});
163
+ }
164
+ catch (e) {
165
+ throw (0, errors_1.toConnectorError)(e);
166
+ }
167
+ };
168
+ const clone = async (assetId, opts = {}) => {
169
+ try {
170
+ const { data } = await api().post(`/api/v3/entity/duplicate/${assetId}`, undefined, { signal: opts.signal });
171
+ return (0, types_1.mapAssetDetail)(data ?? {});
172
+ }
173
+ catch (e) {
174
+ throw (0, errors_1.toConnectorError)(e);
175
+ }
176
+ };
177
+ const del = async (assetId, opts = {}) => {
178
+ try {
179
+ await api().delete(`/api/v3/entity/${assetId}`, { signal: opts.signal });
180
+ }
181
+ catch (e) {
182
+ throw (0, errors_1.toConnectorError)(e);
183
+ }
184
+ };
185
+ return {
186
+ types,
187
+ get,
188
+ search,
189
+ list,
190
+ iterate,
191
+ listRelated,
192
+ create,
193
+ startEdit,
194
+ clone,
195
+ delete: del,
196
+ };
197
+ }
198
+ // Export the wire codes so apps can pass targetDataType without magic numbers.
199
+ exports.ASSET_TARGET_DATA_TYPES = {
200
+ work: DATA_TYPE_WORK,
201
+ asset: DATA_TYPE_ASSET,
202
+ };
203
+ // Ready-made singleton bound to the live shell bridge.
204
+ exports.assets = createAssetsConnector();
@@ -0,0 +1,4 @@
1
+ import type { DianaShell } from "../shellBridge";
2
+ export interface ConnectorDeps {
3
+ shell: () => DianaShell;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });