@declarion/react 0.245.0 → 0.246.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.
@@ -52,7 +52,7 @@ function j() {
52
52
  e = !1, window.removeEventListener("pageshow", t);
53
53
  };
54
54
  }, [B, G]);
55
- let { setupStatus: J, isSetupPending: Y, ssoProviders: X } = h();
55
+ let { setupStatus: J, isSetupPending: Y, ssoProviders: X } = h(), Z = !!X && X.length > 0;
56
56
  if (b(() => {
57
57
  J?.needs_setup && r("/signup", { replace: !0 });
58
58
  }, [J, r]), b(() => {
@@ -68,7 +68,7 @@ function j() {
68
68
  ]), b(() => {
69
69
  K && e.error(q(K, "Sign-in failed."), void 0, { id: O });
70
70
  }, [q, K]), Y || J?.needs_setup) return /* @__PURE__ */ C(n, {});
71
- function Z(t) {
71
+ function Q(t) {
72
72
  t.preventDefault(), H || a({
73
73
  email: I,
74
74
  password: R,
@@ -78,7 +78,7 @@ function j() {
78
78
  } });
79
79
  }
80
80
  return /* @__PURE__ */ C(t, { children: /* @__PURE__ */ w("form", {
81
- onSubmit: Z,
81
+ onSubmit: Q,
82
82
  children: [
83
83
  /* @__PURE__ */ C("div", {
84
84
  style: {
@@ -105,9 +105,9 @@ function j() {
105
105
  fontSize: 13,
106
106
  color: "var(--text-3)"
107
107
  },
108
- children: F("auth.signin.subtitle", "Use your corporate SSO or email & password.")
108
+ children: Z ? F("auth.signin.subtitle", "Use your corporate SSO or email & password.") : F("auth.signin.subtitle_password", "Use your email and password.")
109
109
  }),
110
- X && X.length > 0 && /* @__PURE__ */ w(S, { children: [/* @__PURE__ */ C("div", {
110
+ Z && /* @__PURE__ */ w(S, { children: [/* @__PURE__ */ C("div", {
111
111
  style: {
112
112
  display: "flex",
113
113
  flexDirection: "column",
@@ -34,6 +34,7 @@ var _ = 150, v = {
34
34
  int: 90,
35
35
  float: 100,
36
36
  decimal: 130,
37
+ timestamp: 180,
37
38
  enum: 130,
38
39
  uuid: 110,
39
40
  text: 240
@@ -2,27 +2,27 @@ import { approveInvocation as e, cancelConversation as t, cancelInvocation as n,
2
2
  import { AGENT_FRAME_EVENT as u, AGENT_MESSAGE_CHANGED_EVENT as d, agentBus as f } from "../api/events.js";
3
3
  import { useAuthStore as p } from "../stores/auth.js";
4
4
  import { ApiError as m } from "../types/api.js";
5
- import { coerceDisplayString as re } from "../lib/display-value.js";
6
- import { useCallback as h, useEffect as g, useMemo as ie, useRef as _, useState as v } from "react";
5
+ import { coerceDisplayString as h } from "../lib/display-value.js";
6
+ import { useCallback as g, useEffect as _, useMemo as re, useRef as v, useState as y } from "react";
7
7
  // src/hooks/useAgentConversation.ts
8
- var y = { streaming: !1 }, b = "declarion.agents.conversation_id";
9
- function x(e) {
10
- if (e) return `${b}:${e}`;
8
+ var b = { streaming: !1 }, x = "declarion.agents.conversation_id";
9
+ function S(e, t) {
10
+ if (e) return t ? `${x}:${e}:${t}` : `${x}:${e}`;
11
11
  }
12
- function ae(e) {
12
+ function ie(e, t) {
13
13
  if (typeof window > "u") return;
14
- let t = x(e);
15
- if (t) try {
16
- return window.localStorage.getItem(t) || void 0;
14
+ let n = S(e, t);
15
+ if (n) try {
16
+ return window.localStorage.getItem(n) || void 0;
17
17
  } catch {
18
18
  return;
19
19
  }
20
20
  }
21
- function S(e, t) {
21
+ function ae(e, t, n) {
22
22
  if (typeof window > "u") return;
23
- let n = x(e);
24
- if (n) try {
25
- t ? window.localStorage.setItem(n, t) : window.localStorage.removeItem(n);
23
+ let r = S(e, t);
24
+ if (r) try {
25
+ n ? window.localStorage.setItem(r, n) : window.localStorage.removeItem(r);
26
26
  } catch {}
27
27
  }
28
28
  function C(e) {
@@ -54,19 +54,19 @@ function E(e, t) {
54
54
  }) : r.push(i)));
55
55
  return n ? r : e;
56
56
  }
57
- function D(e) {
57
+ function oe(e) {
58
58
  let t = e;
59
59
  for (let n of e) n.role === "assistant" && n.streaming && (t = E(t, n.id));
60
60
  return t;
61
61
  }
62
- function O(e, t, n, r) {
62
+ function D(e, t, n, r) {
63
63
  let i = !1, a = e.map((e) => e.id === n ? (i = !0, r(e)) : e);
64
64
  return i ? a : [...e, r(w(n, t))];
65
65
  }
66
- function oe(e, t, n, r) {
66
+ function O(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 : O(T(e, n), t, n, (e) => {
69
+ return i && !i.streaming ? e : D(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,
@@ -83,7 +83,7 @@ function oe(e, t, n, r) {
83
83
  }
84
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 : O(T(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 : D(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
  } : {
@@ -141,60 +141,60 @@ 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 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) {
144
+ function A(m, x) {
145
+ let S = p.getState().activeTenant?.id, [w, A] = y(m ?? ie(S, x)), j = g((e) => {
146
+ ae(S, x, e), A(e);
147
+ }, [S, x]), [M, N] = y([]), [ue, P] = y(b), [de, F] = y([]), [I, L] = y([]), [R, z] = y([]), [B, V] = y(1), [fe, H] = y(!1), [pe, U] = y();
148
+ _(() => {
149
+ if (!w) {
150
150
  U(void 0);
151
151
  return;
152
152
  }
153
153
  let e = !1;
154
- return o(x).then((t) => {
154
+ return o(w).then((t) => {
155
155
  e || U(t);
156
156
  }, () => {
157
157
  e || U(void 0);
158
158
  }), () => {
159
159
  e = !0;
160
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 = {
161
+ }, [w]);
162
+ let [me, he] = y([]), [W, G] = y(), K = v(/* @__PURE__ */ new Set()), q = v(0), J = v(null), ge = (e) => (J.current?.fingerprint !== e && (J.current = {
163
163
  key: crypto.randomUUID(),
164
164
  fingerprint: e
165
165
  }), J.current.key);
166
- g(() => {
167
- if (!x) {
168
- M([]), N(y), P([]), I([]);
166
+ _(() => {
167
+ if (!w) {
168
+ N([]), P(b), F([]), L([]);
169
169
  return;
170
170
  }
171
- if (K.current.has(x)) {
172
- K.current.delete(x);
171
+ if (K.current.has(w)) {
172
+ K.current.delete(w);
173
173
  return;
174
174
  }
175
175
  let e = !1, t = ++q.current;
176
176
  return Promise.all([
177
- l(x),
178
- c(x),
179
- s(x)
177
+ l(w),
178
+ c(w),
179
+ s(w)
180
180
  ]).then(([n, r, i]) => {
181
181
  if (e || t !== q.current) return;
182
182
  let a = n.map((e) => e.streaming ? {
183
183
  ...e,
184
184
  streaming: !1
185
185
  } : e);
186
- M(a), P(r), I(i);
186
+ N(a), F(r), L(i);
187
187
  }, (t) => {
188
- e || t?.status === 404 && (A(void 0), M([]));
188
+ e || t?.status === 404 && (j(void 0), N([]));
189
189
  }), () => {
190
190
  e = !0;
191
191
  };
192
- }, [x, A]);
193
- let Y = _(x);
194
- g(() => {
195
- Y.current = x;
196
- }, [x]);
197
- let X = _(!1), Z = _(null), Q = h((e) => {
192
+ }, [w, j]);
193
+ let Y = v(w);
194
+ _(() => {
195
+ Y.current = w;
196
+ }, [w]);
197
+ let X = v(!1), Z = v(null), Q = g((e) => {
198
198
  if (X.current) {
199
199
  Z.current = e;
200
200
  return;
@@ -206,14 +206,14 @@ function A(m) {
206
206
  c(e),
207
207
  s(e)
208
208
  ]).then(([n, r, i]) => {
209
- e === Y.current && t === q.current && (M((e) => le(n, e)), P(r), I(i));
209
+ e === Y.current && t === q.current && (N((e) => le(n, e)), F(r), L(i));
210
210
  }, () => {}).finally(() => {
211
211
  X.current = !1;
212
212
  let e = Z.current;
213
213
  Z.current = null, e && Q(e);
214
214
  });
215
215
  }, []);
216
- g(() => {
216
+ _(() => {
217
217
  let e = (e) => {
218
218
  let { convId: n, kind: r, turnId: i, payload: a } = e.detail;
219
219
  n === Y.current && t(n, {
@@ -226,24 +226,24 @@ function A(m) {
226
226
  let t = (e, t) => {
227
227
  switch (t.kind) {
228
228
  case "turn.started":
229
- N((e) => ({
229
+ P((e) => ({
230
230
  ...e,
231
231
  streaming: !0
232
- })), M((e) => T(e));
232
+ })), N((e) => T(e));
233
233
  break;
234
234
  case "assistant.message.created": {
235
235
  let n = typeof t.payload?.message_id == "string" ? t.payload.message_id : "";
236
236
  if (!n) break;
237
- M((t) => O(T(t, n), e, n, (e) => ({
237
+ N((t) => D(T(t, n), e, n, (e) => ({
238
238
  ...e,
239
239
  streaming: !0
240
240
  })));
241
241
  break;
242
242
  }
243
243
  case "text.delta": {
244
- let n = re(t.payload?.text), r = k(t);
244
+ let n = h(t.payload?.text), r = k(t);
245
245
  if (!r || !n) break;
246
- M((t) => oe(t, e, r, n));
246
+ N((t) => O(t, e, r, n));
247
247
  break;
248
248
  }
249
249
  case "elicit.pending":
@@ -255,7 +255,7 @@ function A(m) {
255
255
  case "tool.proposed": {
256
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 : "";
257
257
  if (!n || !r) break;
258
- M((t) => se(t, e, n, a, r, i));
258
+ N((t) => se(t, e, n, a, r, i));
259
259
  break;
260
260
  }
261
261
  case "tool.result":
@@ -264,12 +264,12 @@ function A(m) {
264
264
  Q(e);
265
265
  break;
266
266
  case "turn.finished": {
267
- N(y);
267
+ P(b);
268
268
  let e = k(t);
269
- e && M((t) => E(t, e));
269
+ e && N((t) => E(t, e));
270
270
  break;
271
271
  }
272
- case "error": M((e) => D(e)), N((e) => ({
272
+ case "error": N((e) => oe(e)), P((e) => ({
273
273
  ...e,
274
274
  streaming: !1
275
275
  }));
@@ -282,10 +282,10 @@ function A(m) {
282
282
  f.removeEventListener(u, e), f.removeEventListener(d, n);
283
283
  };
284
284
  }, [Q]);
285
- let $ = h(async (e, t, n = []) => {
286
- let i = n.map((e) => e.id), a = x;
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([
285
+ let $ = g(async (e, t, n = []) => {
286
+ let i = n.map((e) => e.id), a = w;
287
+ a || (a = (await r({ agent_id: W })).id, K.current.add(a), Y.current = a, j(a));
288
+ let o, s = (n) => ne(e, n, t, i, ge(JSON.stringify([
289
289
  n,
290
290
  e,
291
291
  t ?? null,
@@ -295,9 +295,9 @@ function A(m) {
295
295
  o = await s(a);
296
296
  } catch (e) {
297
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);
298
+ a = (await r({ agent_id: W })).id, K.current.add(a), Y.current = a, j(a), o = await s(a);
299
299
  }
300
- J.current = null, M((t) => {
300
+ J.current = null, N((t) => {
301
301
  if (t.some((e) => e.id === o.id)) return t;
302
302
  let r = e ? [{
303
303
  type: "text",
@@ -310,59 +310,59 @@ function A(m) {
310
310
  }];
311
311
  });
312
312
  }, [
313
- x,
314
- A,
313
+ w,
314
+ j,
315
315
  W
316
- ]), ge = h(async (t, n) => {
317
- await e(t, n), x && Q(x);
318
- }, [x, Q]), _e = h(async (e, t) => {
319
- await ee(e, t), x && Q(x);
320
- }, [x, Q]), ve = h(async (e, t) => {
321
- x && (await te(x, e, t), Q(x));
322
- }, [x, Q]), ye = h(async (e) => {
323
- x && (await n(e), Q(x));
324
- }, [x, Q]), be = h(async () => {
325
- x && await t(x);
326
- }, [x]), xe = h(async () => {
316
+ ]), _e = g(async (t, n) => {
317
+ await e(t, n), w && Q(w);
318
+ }, [w, Q]), ve = g(async (e, t) => {
319
+ await ee(e, t), w && Q(w);
320
+ }, [w, Q]), ye = g(async (e, t) => {
321
+ w && (await te(w, e, t), Q(w));
322
+ }, [w, Q]), be = g(async (e) => {
323
+ w && (await n(e), Q(w));
324
+ }, [w, Q]), xe = g(async () => {
325
+ w && await t(w);
326
+ }, [w]), Se = g(async () => {
327
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(() => {
328
+ z(e), V(1), H(e.length === 50);
329
+ }, []), Ce = g(async () => {
330
+ let e = await a(B + 1);
331
+ z((t) => [...t, ...e.filter((e) => !t.some((t) => t.id === e.id))]), V(B + 1), H(e.length === 50);
332
+ }, [B]), we = g(() => {
333
+ j(void 0), N([]), P(b);
334
+ }, [j]);
335
+ return _(() => {
336
336
  let e = !0;
337
337
  return i().then((t) => {
338
- e && (me(t), G((e) => e ?? t.find((e) => e.is_default)?.id));
338
+ e && (he(t), G((e) => e ?? t.find((e) => x ? e.code === x : e.is_default)?.id));
339
339
  }).catch((e) => {
340
340
  console.warn("agents.list_available failed; the agent picker is unavailable", e);
341
341
  }), () => {
342
342
  e = !1;
343
343
  };
344
- }, []), {
345
- conversationId: x,
346
- messages: ie(() => ce(j, F), [j, F]),
344
+ }, [x]), {
345
+ conversationId: w,
346
+ messages: re(() => ce(M, I), [M, I]),
347
347
  turn: ue,
348
348
  turns: de,
349
- invocations: F,
350
- conversations: L,
351
- openedConversation: fe,
352
- moreConversations: V,
353
- showMoreConversations: Se,
349
+ invocations: I,
350
+ conversations: R,
351
+ openedConversation: pe,
352
+ moreConversations: fe,
353
+ showMoreConversations: Ce,
354
354
  send: $,
355
- approve: ge,
356
- reject: _e,
357
- submitInput: ve,
358
- cancelInput: ye,
359
- cancel: be,
360
- refreshConversations: xe,
361
- startNew: Ce,
362
- agents: pe,
355
+ approve: _e,
356
+ reject: ve,
357
+ submitInput: ye,
358
+ cancelInput: be,
359
+ cancel: xe,
360
+ refreshConversations: Se,
361
+ startNew: we,
362
+ agents: me,
363
363
  selectedAgentId: W,
364
364
  selectAgent: G,
365
- setConversationId: A
365
+ setConversationId: j
366
366
  };
367
367
  }
368
368
  export { A as useAgentConversation };
@@ -2191,6 +2191,7 @@ interface AgentChatPanelProps {
2191
2191
  * this it opened the panel and threw the question away. */
2192
2192
  askOnOpen?: string;
2193
2193
  docked?: boolean;
2194
+ agentCode?: string;
2194
2195
  }
2195
2196
  export declare function AgentChatPanel(props: AgentChatPanelProps): import("react").JSX.Element | null;
2196
2197
  type JSONSchemaProp = {
@@ -2239,7 +2240,9 @@ export declare function AgentConversationDrawer({ open, onClose, conversations,
2239
2240
  interface AgentTurnState {
2240
2241
  streaming: boolean;
2241
2242
  }
2242
- export declare function useAgentConversation(initialConversationId?: string): {
2243
+ /** agentCode names the agent a screen's own panel talks to: it is preselected instead of the tenant's default, and the
2244
+ * panel remembers its conversation apart from the general one. */
2245
+ export declare function useAgentConversation(initialConversationId?: string, agentCode?: string): {
2243
2246
  conversationId: string | undefined;
2244
2247
  messages: AgentMessage[];
2245
2248
  turn: AgentTurnState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@declarion/react",
3
- "version": "0.245.0",
3
+ "version": "0.246.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "React SDK for Declarion, the schema-driven business apps platform.",