@declarion/react 0.182.0 → 0.185.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.
@@ -38,9 +38,9 @@ function s({ open: s, onClose: c, conversations: l, activeId: u, onSelect: d, on
38
38
  children: [/* @__PURE__ */ a("div", {
39
39
  className: "text-sm font-medium truncate",
40
40
  children: e.title || m("agent.drawer.untitled", "Untitled")
41
- }), /* @__PURE__ */ o("div", {
41
+ }), /* @__PURE__ */ a("div", {
42
42
  className: "text-xs text-muted-foreground",
43
- children: [e.agent ? `${e.agent} · ` : "", e.status]
43
+ children: [e.agent_name && m(e.agent_name) || e.agent, e.status].filter(Boolean).join(" · ")
44
44
  })]
45
45
  }, e.id))]
46
46
  }),
@@ -949,7 +949,7 @@ function _t({ title: e, editing: t, isNew: n, isRecordDeleted: a, dirty: s, isSa
949
949
  gap: 8,
950
950
  marginTop: 10
951
951
  },
952
- children: [w ? null : Pe, /* @__PURE__ */ M(ge, {
952
+ children: [w || !a && !t ? null : Pe, /* @__PURE__ */ M(ge, {
953
953
  layout: C,
954
954
  row: m,
955
955
  onRun: Ne,
@@ -424,7 +424,8 @@ function $({ userId: t, associated: n }) {
424
424
  return i ? /* @__PURE__ */ G(M, {
425
425
  node: {
426
426
  associated: n,
427
- foreign_key: "user_id"
427
+ foreign_key: "user_id",
428
+ sort: "created_at:desc"
428
429
  },
429
430
  ctx: {
430
431
  schema: r,
@@ -32,6 +32,7 @@ function c({ title: c, subtitle: l, right: u, badge: d, count: f, children: p, f
32
32
  style: {
33
33
  display: "flex",
34
34
  alignItems: "center",
35
+ flexWrap: "wrap",
35
36
  gap: 10,
36
37
  padding: "10px 14px",
37
38
  borderBottom: S ? "1px solid var(--divider)" : "none",
@@ -43,7 +44,7 @@ function c({ title: c, subtitle: l, right: u, badge: d, count: f, children: p, f
43
44
  "aria-level": y,
44
45
  style: {
45
46
  display: "flex",
46
- flex: 1,
47
+ flex: "1 1 140px",
47
48
  minWidth: 0
48
49
  },
49
50
  children: /* @__PURE__ */ o("div", {
@@ -1,15 +1,15 @@
1
- import { approveInvocation as e, cancelConversation as t, cancelInvocation as n, createConversation as r, listAvailableAgents as i, listConversations as a, loadConversationInvocations as o, loadConversationTurns as s, loadHistory as c, rejectInvocation as ee, sendElicitResponse as l, sendMessage as te } from "../api/agents.js";
1
+ import { approveInvocation as e, cancelConversation as t, cancelInvocation as n, createConversation as r, listAvailableAgents as i, listConversations as a, loadConversation as o, loadConversationInvocations as s, loadConversationTurns as c, loadHistory as l, rejectInvocation as ee, sendElicitResponse as te, sendMessage as ne } from "../api/agents.js";
2
2
  import { AGENT_FRAME_EVENT as u, AGENT_MESSAGE_CHANGED_EVENT as d, agentBus as f } from "../api/events.js";
3
- import { useAuthStore as ne } from "../stores/auth.js";
4
- import { ApiError as p } from "../types/api.js";
3
+ import { useAuthStore as p } from "../stores/auth.js";
4
+ import { ApiError as m } from "../types/api.js";
5
5
  import { coerceDisplayString as re } from "../lib/display-value.js";
6
- import { useCallback as m, useEffect as h, useMemo as g, useRef as _, useState as v } from "react";
6
+ import { useCallback as h, useEffect as g, useMemo as ie, useRef as _, useState as v } from "react";
7
7
  // src/hooks/useAgentConversation.ts
8
8
  var y = { streaming: !1 }, b = "declarion.agents.conversation_id";
9
9
  function x(e) {
10
10
  if (e) return `${b}:${e}`;
11
11
  }
12
- function ie(e) {
12
+ function ae(e) {
13
13
  if (typeof window > "u") return;
14
14
  let t = x(e);
15
15
  if (t) try {
@@ -18,17 +18,17 @@ function ie(e) {
18
18
  return;
19
19
  }
20
20
  }
21
- function ae(e, t) {
21
+ function S(e, t) {
22
22
  if (typeof window > "u") return;
23
23
  let n = x(e);
24
24
  if (n) try {
25
25
  t ? window.localStorage.setItem(n, t) : window.localStorage.removeItem(n);
26
26
  } catch {}
27
27
  }
28
- function S(e) {
29
- return !(e instanceof p) || e.code !== "entity.foreign_key_violation" ? !1 : e.ext("constraint") === "agent_messages_tenant_conv_fk";
28
+ function C(e) {
29
+ return !(e instanceof m) || e.code !== "entity.foreign_key_violation" ? !1 : e.ext("constraint") === "agent_messages_tenant_conv_fk";
30
30
  }
31
- function C(e, t) {
31
+ function w(e, t) {
32
32
  return {
33
33
  id: e,
34
34
  conversation_id: t,
@@ -39,14 +39,14 @@ function C(e, t) {
39
39
  streaming: !0
40
40
  };
41
41
  }
42
- function w(e, t) {
42
+ function T(e, t) {
43
43
  let n = !1, r = e.map((e) => e.role !== "assistant" || !e.streaming || e.id === t ? e : (n = !0, {
44
44
  ...e,
45
45
  streaming: !1
46
46
  }));
47
47
  return n ? r : e;
48
48
  }
49
- function T(e, t) {
49
+ function E(e, t) {
50
50
  let n = !1, r = [];
51
51
  for (let i of e) i.id !== t || i.role !== "assistant" ? r.push(i) : (n = !0, i.content.length !== 0 && (i.streaming ? r.push({
52
52
  ...i,
@@ -54,19 +54,19 @@ function T(e, t) {
54
54
  }) : r.push(i)));
55
55
  return n ? r : e;
56
56
  }
57
- function E(e) {
57
+ function D(e) {
58
58
  let t = e;
59
- for (let n of e) n.role === "assistant" && n.streaming && (t = T(t, n.id));
59
+ for (let n of e) n.role === "assistant" && n.streaming && (t = E(t, n.id));
60
60
  return t;
61
61
  }
62
- function D(e, t, n, r) {
62
+ function O(e, t, n, r) {
63
63
  let i = !1, a = e.map((e) => e.id === n ? (i = !0, r(e)) : e);
64
- return i ? a : [...e, r(C(n, t))];
64
+ return i ? a : [...e, r(w(n, t))];
65
65
  }
66
66
  function oe(e, t, n, r) {
67
67
  if (!r) return e;
68
68
  let i = e.find((e) => e.id === n);
69
- return i && !i.streaming ? e : D(w(e, n), t, n, (e) => {
69
+ return i && !i.streaming ? e : O(T(e, n), t, n, (e) => {
70
70
  let t = [...e.content], n = t[t.length - 1];
71
71
  return n?.type === "text" ? t[t.length - 1] = {
72
72
  ...n,
@@ -81,9 +81,9 @@ function oe(e, t, n, r) {
81
81
  };
82
82
  });
83
83
  }
84
- function O(e, t, n, r, i, a) {
84
+ function se(e, t, n, r, i, a) {
85
85
  let o = e.find((e) => e.id === n);
86
- return o && !o.streaming ? e : D(w(e, n), t, n, (e) => r && e.content.some((e) => e.type === "tool_use" && e.id === r) ? e.streaming ? e : {
86
+ return o && !o.streaming ? e : O(T(e, n), t, n, (e) => r && e.content.some((e) => e.type === "tool_use" && e.id === r) ? e.streaming ? e : {
87
87
  ...e,
88
88
  streaming: !0
89
89
  } : {
@@ -97,7 +97,7 @@ function O(e, t, n, r, i, a) {
97
97
  }]
98
98
  });
99
99
  }
100
- function k(e, t) {
100
+ function ce(e, t) {
101
101
  let n = /* @__PURE__ */ new Map();
102
102
  for (let e of t) e.response_message_id && e.provider_call_id && n.set(`${e.response_message_id}\u0000${e.provider_call_id}`, e);
103
103
  return e.map((e) => {
@@ -120,7 +120,7 @@ function k(e, t) {
120
120
  } : e;
121
121
  });
122
122
  }
123
- function A(e, t) {
123
+ function le(e, t) {
124
124
  let n = e.map((e) => e.streaming ? {
125
125
  ...e,
126
126
  streaming: !1
@@ -137,20 +137,35 @@ function A(e, t) {
137
137
  }
138
138
  return n;
139
139
  }
140
- function j(e) {
140
+ function k(e) {
141
141
  let t = e.payload?.message_id;
142
142
  return typeof t == "string" && t ? t : void 0;
143
143
  }
144
- function M(p) {
145
- let b = ne.getState().activeTenant?.id, [x, C] = v(p ?? ie(b)), M = m((e) => {
146
- ae(b, e), C(e);
147
- }, [b]), [N, P] = v([]), [se, F] = v(y), [I, L] = v([]), [R, z] = v([]), [B, V] = v([]), [H, U] = v([]), [W, G] = v(), K = _(/* @__PURE__ */ new Set()), q = _(0), J = _(null), ce = (e) => (J.current?.fingerprint !== e && (J.current = {
144
+ function A(m) {
145
+ let b = p.getState().activeTenant?.id, [x, w] = v(m ?? ae(b)), A = h((e) => {
146
+ S(b, e), w(e);
147
+ }, [b]), [j, M] = v([]), [ue, N] = v(y), [de, P] = v([]), [F, I] = v([]), [L, R] = v([]), [z, B] = v(1), [V, H] = v(!1), [fe, U] = v();
148
+ g(() => {
149
+ if (!x) {
150
+ U(void 0);
151
+ return;
152
+ }
153
+ let e = !1;
154
+ return o(x).then((t) => {
155
+ e || U(t);
156
+ }, () => {
157
+ e || U(void 0);
158
+ }), () => {
159
+ e = !0;
160
+ };
161
+ }, [x]);
162
+ let [pe, me] = v([]), [W, G] = v(), K = _(/* @__PURE__ */ new Set()), q = _(0), J = _(null), he = (e) => (J.current?.fingerprint !== e && (J.current = {
148
163
  key: crypto.randomUUID(),
149
164
  fingerprint: e
150
165
  }), J.current.key);
151
- h(() => {
166
+ g(() => {
152
167
  if (!x) {
153
- P([]), F(y), L([]), z([]);
168
+ M([]), N(y), P([]), I([]);
154
169
  return;
155
170
  }
156
171
  if (K.current.has(x)) {
@@ -159,27 +174,27 @@ function M(p) {
159
174
  }
160
175
  let e = !1, t = ++q.current;
161
176
  return Promise.all([
177
+ l(x),
162
178
  c(x),
163
- s(x),
164
- o(x)
179
+ s(x)
165
180
  ]).then(([n, r, i]) => {
166
181
  if (e || t !== q.current) return;
167
182
  let a = n.map((e) => e.streaming ? {
168
183
  ...e,
169
184
  streaming: !1
170
185
  } : e);
171
- P(a), L(r), z(i);
186
+ M(a), P(r), I(i);
172
187
  }, (t) => {
173
- e || t?.status === 404 && (M(void 0), P([]));
188
+ e || t?.status === 404 && (A(void 0), M([]));
174
189
  }), () => {
175
190
  e = !0;
176
191
  };
177
- }, [x, M]);
192
+ }, [x, A]);
178
193
  let Y = _(x);
179
- h(() => {
194
+ g(() => {
180
195
  Y.current = x;
181
196
  }, [x]);
182
- let X = _(!1), Z = _(null), Q = m((e) => {
197
+ let X = _(!1), Z = _(null), Q = h((e) => {
183
198
  if (X.current) {
184
199
  Z.current = e;
185
200
  return;
@@ -187,18 +202,18 @@ function M(p) {
187
202
  X.current = !0;
188
203
  let t = ++q.current;
189
204
  Promise.all([
205
+ l(e),
190
206
  c(e),
191
- s(e),
192
- o(e)
207
+ s(e)
193
208
  ]).then(([n, r, i]) => {
194
- e === Y.current && t === q.current && (P((e) => A(n, e)), L(r), z(i));
209
+ e === Y.current && t === q.current && (M((e) => le(n, e)), P(r), I(i));
195
210
  }, () => {}).finally(() => {
196
211
  X.current = !1;
197
212
  let e = Z.current;
198
213
  Z.current = null, e && Q(e);
199
214
  });
200
215
  }, []);
201
- h(() => {
216
+ g(() => {
202
217
  let e = (e) => {
203
218
  let { convId: n, kind: r, turnId: i, payload: a } = e.detail;
204
219
  n === Y.current && t(n, {
@@ -211,24 +226,24 @@ function M(p) {
211
226
  let t = (e, t) => {
212
227
  switch (t.kind) {
213
228
  case "turn.started":
214
- F((e) => ({
229
+ N((e) => ({
215
230
  ...e,
216
231
  streaming: !0
217
- })), P((e) => w(e));
232
+ })), M((e) => T(e));
218
233
  break;
219
234
  case "assistant.message.created": {
220
235
  let n = typeof t.payload?.message_id == "string" ? t.payload.message_id : "";
221
236
  if (!n) break;
222
- P((t) => D(w(t, n), e, n, (e) => ({
237
+ M((t) => O(T(t, n), e, n, (e) => ({
223
238
  ...e,
224
239
  streaming: !0
225
240
  })));
226
241
  break;
227
242
  }
228
243
  case "text.delta": {
229
- let n = re(t.payload?.text), r = j(t);
244
+ let n = re(t.payload?.text), r = k(t);
230
245
  if (!r || !n) break;
231
- P((t) => oe(t, e, r, n));
246
+ M((t) => oe(t, e, r, n));
232
247
  break;
233
248
  }
234
249
  case "elicit.pending":
@@ -238,9 +253,9 @@ function M(p) {
238
253
  Q(e);
239
254
  break;
240
255
  case "tool.proposed": {
241
- let n = j(t), r = typeof t.payload?.tool == "string" ? t.payload.tool : "", i = t.payload?.params ?? {}, a = typeof t.payload?.tool_use_id == "string" ? t.payload.tool_use_id : "";
256
+ let n = k(t), r = typeof t.payload?.tool == "string" ? t.payload.tool : "", i = t.payload?.params ?? {}, a = typeof t.payload?.tool_use_id == "string" ? t.payload.tool_use_id : "";
242
257
  if (!n || !r) break;
243
- P((t) => O(t, e, n, a, r, i));
258
+ M((t) => se(t, e, n, a, r, i));
244
259
  break;
245
260
  }
246
261
  case "tool.result":
@@ -249,12 +264,12 @@ function M(p) {
249
264
  Q(e);
250
265
  break;
251
266
  case "turn.finished": {
252
- F(y);
253
- let e = j(t);
254
- e && P((t) => T(t, e));
267
+ N(y);
268
+ let e = k(t);
269
+ e && M((t) => E(t, e));
255
270
  break;
256
271
  }
257
- case "error": P((e) => E(e)), F((e) => ({
272
+ case "error": M((e) => D(e)), N((e) => ({
258
273
  ...e,
259
274
  streaming: !1
260
275
  }));
@@ -267,10 +282,10 @@ function M(p) {
267
282
  f.removeEventListener(u, e), f.removeEventListener(d, n);
268
283
  };
269
284
  }, [Q]);
270
- let $ = m(async (e, t, n = []) => {
285
+ let $ = h(async (e, t, n = []) => {
271
286
  let i = n.map((e) => e.id), a = x;
272
- a || (a = (await r({ agent_id: W })).id, K.current.add(a), Y.current = a, M(a));
273
- let o, s = (n) => te(e, n, t, i, ce(JSON.stringify([
287
+ a || (a = (await r({ agent_id: W })).id, K.current.add(a), Y.current = a, A(a));
288
+ let o, s = (n) => ne(e, n, t, i, he(JSON.stringify([
274
289
  n,
275
290
  e,
276
291
  t ?? null,
@@ -279,10 +294,10 @@ function M(p) {
279
294
  try {
280
295
  o = await s(a);
281
296
  } catch (e) {
282
- if (!S(e)) throw e;
283
- a = (await r({ agent_id: W })).id, K.current.add(a), Y.current = a, M(a), o = await s(a);
297
+ if (!C(e)) throw e;
298
+ a = (await r({ agent_id: W })).id, K.current.add(a), Y.current = a, A(a), o = await s(a);
284
299
  }
285
- J.current = null, P((t) => {
300
+ J.current = null, M((t) => {
286
301
  if (t.some((e) => e.id === o.id)) return t;
287
302
  let r = e ? [{
288
303
  type: "text",
@@ -296,27 +311,31 @@ function M(p) {
296
311
  });
297
312
  }, [
298
313
  x,
299
- M,
314
+ A,
300
315
  W
301
- ]), le = m(async (t, n) => {
316
+ ]), ge = h(async (t, n) => {
302
317
  await e(t, n), x && Q(x);
303
- }, [x, Q]), ue = m(async (e, t) => {
318
+ }, [x, Q]), _e = h(async (e, t) => {
304
319
  await ee(e, t), x && Q(x);
305
- }, [x, Q]), de = m(async (e, t) => {
306
- x && (await l(x, e, t), Q(x));
307
- }, [x, Q]), fe = m(async (e) => {
320
+ }, [x, Q]), ve = h(async (e, t) => {
321
+ x && (await te(x, e, t), Q(x));
322
+ }, [x, Q]), ye = h(async (e) => {
308
323
  x && (await n(e), Q(x));
309
- }, [x, Q]), pe = m(async () => {
324
+ }, [x, Q]), be = h(async () => {
310
325
  x && await t(x);
311
- }, [x]), me = m(async () => {
312
- V(await a());
313
- }, []), he = m(() => {
314
- M(void 0), P([]), F(y);
315
- }, [M]);
316
- return h(() => {
326
+ }, [x]), xe = h(async () => {
327
+ let e = await a();
328
+ R(e), B(1), H(e.length === 50);
329
+ }, []), Se = h(async () => {
330
+ let e = await a(z + 1);
331
+ R((t) => [...t, ...e.filter((e) => !t.some((t) => t.id === e.id))]), B(z + 1), H(e.length === 50);
332
+ }, [z]), Ce = h(() => {
333
+ A(void 0), M([]), N(y);
334
+ }, [A]);
335
+ return g(() => {
317
336
  let e = !0;
318
337
  return i().then((t) => {
319
- e && (U(t), G((e) => e ?? t.find((e) => e.is_default)?.id));
338
+ e && (me(t), G((e) => e ?? t.find((e) => e.is_default)?.id));
320
339
  }).catch((e) => {
321
340
  console.warn("agents.list_available failed; the agent picker is unavailable", e);
322
341
  }), () => {
@@ -324,23 +343,26 @@ function M(p) {
324
343
  };
325
344
  }, []), {
326
345
  conversationId: x,
327
- messages: g(() => k(N, R), [N, R]),
328
- turn: se,
329
- turns: I,
330
- invocations: R,
331
- conversations: B,
346
+ messages: ie(() => ce(j, F), [j, F]),
347
+ turn: ue,
348
+ turns: de,
349
+ invocations: F,
350
+ conversations: L,
351
+ openedConversation: fe,
352
+ moreConversations: V,
353
+ showMoreConversations: Se,
332
354
  send: $,
333
- approve: le,
334
- reject: ue,
335
- submitInput: de,
336
- cancelInput: fe,
337
- cancel: pe,
338
- refreshConversations: me,
339
- startNew: he,
340
- agents: H,
355
+ approve: ge,
356
+ reject: _e,
357
+ submitInput: ve,
358
+ cancelInput: ye,
359
+ cancel: be,
360
+ refreshConversations: xe,
361
+ startNew: Ce,
362
+ agents: pe,
341
363
  selectedAgentId: W,
342
364
  selectAgent: G,
343
- setConversationId: M
365
+ setConversationId: A
344
366
  };
345
367
  }
346
- export { M as useAgentConversation };
368
+ export { A as useAgentConversation };
@@ -2126,6 +2126,7 @@ interface AgentConversation {
2126
2126
  created_by?: string;
2127
2127
  agent_id?: string;
2128
2128
  agent?: string;
2129
+ agent_name?: LocalizedString;
2129
2130
  chat_id?: string | null;
2130
2131
  topic_id?: string | null;
2131
2132
  updated_at?: string;
@@ -2164,7 +2165,7 @@ export declare function approveInvocation(id: string, scope?: ApprovalScope): Pr
2164
2165
  export declare function rejectInvocation(id: string, note?: string): Promise<void>;
2165
2166
  export declare function cancelInvocation(id: string): Promise<void>;
2166
2167
  export declare function cancelConversation(id: string): Promise<void>;
2167
- export declare function listConversations(): Promise<AgentConversation[]>;
2168
+ export declare function listConversations(page?: number): Promise<AgentConversation[]>;
2168
2169
  export declare function loadConversationTurns(conversationId: string): Promise<AgentTurn[]>;
2169
2170
  export declare function loadConversationInvocations(conversationId: string): Promise<AgentToolInvocation[]>;
2170
2171
  export declare function loadHistory(conversationId: string): Promise<AgentMessage[]>;
@@ -2234,6 +2235,9 @@ export declare function useAgentConversation(initialConversationId?: string): {
2234
2235
  turns: AgentTurn[];
2235
2236
  invocations: AgentToolInvocation[];
2236
2237
  conversations: AgentConversation[];
2238
+ openedConversation: AgentConversation | undefined;
2239
+ moreConversations: boolean;
2240
+ showMoreConversations: () => Promise<void>;
2237
2241
  send: (text: string, context?: AgentMessageContext, attachments?: HydratedFile[]) => Promise<void>;
2238
2242
  approve: (invocationId: string, scope?: ApprovalScope) => Promise<void>;
2239
2243
  reject: (invocationId: string, note?: string) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@declarion/react",
3
- "version": "0.182.0",
3
+ "version": "0.185.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "React SDK for Declarion, the schema-driven business apps platform.",