@useago/sdk 1.0.8 → 1.0.10

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.
@@ -468,6 +468,17 @@ export declare interface DevPanelOptions {
468
468
  client: Pick<AgoClient, "on" | "getRegisteredFunctions" | "getContextSnapshot">;
469
469
  /** Where to mount: a CSS selector, an Element, or `document.body` (default). */
470
470
  target?: string | Element;
471
+ /**
472
+ * Which screen edge the panels pin to: `"right"` (default) or `"left"`. With
473
+ * several widgets on a page, give each panel the same side as its widget. Panels
474
+ * on the same side stack beside each other automatically.
475
+ */
476
+ side?: "left" | "right";
477
+ /**
478
+ * Optional caption shown in the panel header. Handy when several panels share a
479
+ * page (one per widget): pass e.g. the agent or widget name to tell them apart.
480
+ */
481
+ label?: string;
471
482
  }
472
483
 
473
484
  /**
@@ -495,7 +506,7 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
495
506
 
496
507
  /**
497
508
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
498
- * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
509
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes from the LLM tool's `parameters` (the full schema still reaches the agent via dynamic context).
499
510
  */
500
511
  declare interface FormCollectorSchema {
501
512
  type: "object";
@@ -512,17 +523,32 @@ declare interface FormField {
512
523
  }
513
524
 
514
525
  /**
515
- * A field's conditional-requiredness rule. The field becomes required exactly
516
- * when the controlling `property` matches `value` against the answers collected
517
- * so far:
526
+ * A field's conditional-requiredness rule: either a single {@link FormFieldLeafCondition}
527
+ * or a boolean combination of rules. `anyOf` is OR (true when any nested rule
528
+ * holds); `allOf` is AND (true when every nested rule holds). Both nest
529
+ * arbitrarily, so you can mix them, e.g.
530
+ * `{ anyOf: [{ property: "a", op: ">=", value: 1 }, { property: "b", value: "1" }] }`.
531
+ * An empty `anyOf` is never required; an empty `allOf` is always required.
532
+ *
533
+ * Stripped from the LLM tool's `parameters` (see {@link toWireParameters}), but the
534
+ * full schema, `requiredWhen` included, still reaches the agent via the dynamic
535
+ * context so it knows when each field becomes required.
536
+ */
537
+ declare type FormFieldCondition = FormFieldLeafCondition | {
538
+ anyOf: FormFieldCondition[];
539
+ } | {
540
+ allOf: FormFieldCondition[];
541
+ };
542
+
543
+ /**
544
+ * A single leaf comparison. The field it guards becomes required exactly when the
545
+ * controlling `property` matches `value` against the answers collected so far:
518
546
  * - a single `value`, no `op` — equality (compared as strings);
519
547
  * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
520
548
  * - an array `value`, no `op` — "one of": matches when the property equals any
521
549
  * listed value.
522
- *
523
- * SDK-only — it is stripped from the schema before it reaches the LLM tool
524
550
  */
525
- declare interface FormFieldCondition {
551
+ declare interface FormFieldLeafCondition {
526
552
  /** The controlling field whose value the rule tests. */
527
553
  property: string;
528
554
  /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
@@ -543,7 +569,8 @@ declare interface FormFieldSchema {
543
569
  default?: unknown;
544
570
  /**
545
571
  * Makes the field required only while this condition holds. Drives the dynamic
546
- * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
572
+ * `missing` list; stripped from the LLM tool's `parameters` (still sent to the
573
+ * agent via dynamic context). See {@link toWireParameters}.
547
574
  */
548
575
  requiredWhen?: FormFieldCondition;
549
576
  }
@@ -468,6 +468,17 @@ export declare interface DevPanelOptions {
468
468
  client: Pick<AgoClient, "on" | "getRegisteredFunctions" | "getContextSnapshot">;
469
469
  /** Where to mount: a CSS selector, an Element, or `document.body` (default). */
470
470
  target?: string | Element;
471
+ /**
472
+ * Which screen edge the panels pin to: `"right"` (default) or `"left"`. With
473
+ * several widgets on a page, give each panel the same side as its widget. Panels
474
+ * on the same side stack beside each other automatically.
475
+ */
476
+ side?: "left" | "right";
477
+ /**
478
+ * Optional caption shown in the panel header. Handy when several panels share a
479
+ * page (one per widget): pass e.g. the agent or widget name to tell them apart.
480
+ */
481
+ label?: string;
471
482
  }
472
483
 
473
484
  /**
@@ -495,7 +506,7 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
495
506
 
496
507
  /**
497
508
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
498
- * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
509
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes from the LLM tool's `parameters` (the full schema still reaches the agent via dynamic context).
499
510
  */
500
511
  declare interface FormCollectorSchema {
501
512
  type: "object";
@@ -512,17 +523,32 @@ declare interface FormField {
512
523
  }
513
524
 
514
525
  /**
515
- * A field's conditional-requiredness rule. The field becomes required exactly
516
- * when the controlling `property` matches `value` against the answers collected
517
- * so far:
526
+ * A field's conditional-requiredness rule: either a single {@link FormFieldLeafCondition}
527
+ * or a boolean combination of rules. `anyOf` is OR (true when any nested rule
528
+ * holds); `allOf` is AND (true when every nested rule holds). Both nest
529
+ * arbitrarily, so you can mix them, e.g.
530
+ * `{ anyOf: [{ property: "a", op: ">=", value: 1 }, { property: "b", value: "1" }] }`.
531
+ * An empty `anyOf` is never required; an empty `allOf` is always required.
532
+ *
533
+ * Stripped from the LLM tool's `parameters` (see {@link toWireParameters}), but the
534
+ * full schema, `requiredWhen` included, still reaches the agent via the dynamic
535
+ * context so it knows when each field becomes required.
536
+ */
537
+ declare type FormFieldCondition = FormFieldLeafCondition | {
538
+ anyOf: FormFieldCondition[];
539
+ } | {
540
+ allOf: FormFieldCondition[];
541
+ };
542
+
543
+ /**
544
+ * A single leaf comparison. The field it guards becomes required exactly when the
545
+ * controlling `property` matches `value` against the answers collected so far:
518
546
  * - a single `value`, no `op` — equality (compared as strings);
519
547
  * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
520
548
  * - an array `value`, no `op` — "one of": matches when the property equals any
521
549
  * listed value.
522
- *
523
- * SDK-only — it is stripped from the schema before it reaches the LLM tool
524
550
  */
525
- declare interface FormFieldCondition {
551
+ declare interface FormFieldLeafCondition {
526
552
  /** The controlling field whose value the rule tests. */
527
553
  property: string;
528
554
  /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
@@ -543,7 +569,8 @@ declare interface FormFieldSchema {
543
569
  default?: unknown;
544
570
  /**
545
571
  * Makes the field required only while this condition holds. Drives the dynamic
546
- * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
572
+ * `missing` list; stripped from the LLM tool's `parameters` (still sent to the
573
+ * agent via dynamic context). See {@link toWireParameters}.
547
574
  */
548
575
  requiredWhen?: FormFieldCondition;
549
576
  }
package/dist/devtools.js CHANGED
@@ -1,94 +1,97 @@
1
- var v, x, p, h = () => ({});
2
- function i() {
3
- v && (v.textContent = JSON.stringify(h(), null, 2));
4
- }
5
- function m(e, t, d) {
1
+ function E(e, t, d) {
6
2
  if (!e) return;
7
- const n = document.createElement("div");
8
- n.className = `dev-log-line dev-log-${d}`, n.textContent = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${t}`, e.appendChild(n), e.scrollTop = e.scrollHeight;
9
- }
10
- function c(e, t) {
11
- m(x, e, t);
3
+ const a = document.createElement("div");
4
+ a.className = `dev-log-line dev-log-${d}`, a.textContent = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${t}`, e.appendChild(a), e.scrollTop = e.scrollHeight;
12
5
  }
13
- function y(e) {
6
+ function O(e) {
14
7
  let t;
15
8
  return e.type ? t = e.type : e.content !== void 0 ? t = "content" : e.full_content !== void 0 ? t = "full_content" : e.status ? t = `status:${e.status}` : t = "event", `${t} ${JSON.stringify(e)}`;
16
9
  }
17
- var S = "ago_dev_panel_collapsed", E = "ago_dev_events_collapsed";
18
- function g(e, t, d, n) {
10
+ var T = "ago_dev_panel_collapsed", N = "ago_dev_events_collapsed";
11
+ function u(e, t, d, a) {
19
12
  e.classList.toggle("collapsed", t);
20
- const o = e.querySelector(".dev-toggle");
21
- o && (o.textContent = t ? "▢" : "—", o.title = t ? `Expand ${n}` : `Collapse ${n}`, o.setAttribute("aria-expanded", String(!t)));
13
+ const l = e.querySelector(".dev-toggle");
14
+ l && (l.textContent = t ? "▢" : "—", l.title = t ? `Expand ${a}` : `Collapse ${a}`, l.setAttribute("aria-expanded", String(!t)));
22
15
  try {
23
16
  localStorage.setItem(d, t ? "1" : "0");
24
17
  } catch {
25
18
  }
26
19
  }
27
- function u(e, t, d) {
28
- e.querySelector(".dev-toggle")?.addEventListener("click", (o) => {
29
- o.stopPropagation(), g(e, !e.classList.contains("collapsed"), t, d);
20
+ function $(e, t, d) {
21
+ e.querySelector(".dev-toggle")?.addEventListener("click", (l) => {
22
+ l.stopPropagation(), u(e, !e.classList.contains("collapsed"), t, d);
30
23
  }), e.addEventListener("click", () => {
31
- e.classList.contains("collapsed") && g(e, !1, t, d);
24
+ e.classList.contains("collapsed") && u(e, !1, t, d);
32
25
  });
33
- let n = !1;
26
+ let a = !1;
34
27
  try {
35
- n = localStorage.getItem(t) === "1";
28
+ a = localStorage.getItem(t) === "1";
36
29
  } catch {
37
30
  }
38
- g(e, n, t, d);
31
+ u(e, a, t, d);
39
32
  }
40
- function L(e) {
41
- const { client: t, target: d } = e;
42
- h = () => {
43
- const a = t.getContextSnapshot()?.entries ?? {};
44
- return Object.fromEntries(Object.entries(a).map(([l, { name: r, data: b }]) => [l, {
45
- name: r,
46
- data: b
33
+ function z(e) {
34
+ const { client: t, target: d, label: a, side: l = "right" } = e, f = document.querySelectorAll("#ago-dev-panel").length, x = f === 0 ? "" : `-${f + 1}`, h = document.querySelectorAll(`#ago-dev-panel[data-ago-dev-side="${l}"]`).length, r = h > 0 ? `${16 + h * 376}px` : "";
35
+ let g = null, m = null, b = null;
36
+ const L = () => {
37
+ const o = t.getContextSnapshot()?.entries ?? {};
38
+ return Object.fromEntries(Object.entries(o).map(([n, { name: p, data: k }]) => [n, {
39
+ name: p,
40
+ data: k
47
41
  }]));
48
- }, C();
49
- const n = typeof d == "string" ? document.querySelector(d) : d instanceof Element ? d : document.body, o = document.createElement("aside");
50
- o.id = "ago-dev-panel", o.className = "ago-dev-card", (n ?? document.body).appendChild(o), o.innerHTML = `
42
+ }, c = () => {
43
+ g && (g.textContent = JSON.stringify(L(), null, 2));
44
+ }, v = (o, n) => {
45
+ E(m, o, n);
46
+ };
47
+ _();
48
+ const y = typeof d == "string" ? document.querySelector(d) : d instanceof Element ? d : document.body, S = (o) => {
49
+ o.dataset.agoDevSide = l, l === "left" ? (o.style.right = "auto", o.style.left = r || "16px") : r && (o.style.right = r);
50
+ }, s = document.createElement("aside");
51
+ s.id = "ago-dev-panel", s.className = "ago-dev-card", S(s), (y ?? document.body).appendChild(s);
52
+ const w = (t.getRegisteredFunctions?.() ?? []).map((o) => o.name).join(", ") || "—";
53
+ s.innerHTML = `
51
54
  <div class="dev-head">
52
55
  <span class="dev-badge">DEV</span>
53
- <span class="dev-title">DEV TOOLS · client-side function state — not for production</span>
56
+ <span class="dev-title">${a ? `DEV TOOLS · ${a}` : "DEV TOOLS · client-side function state — not for production"}</span>
54
57
  <button type="button" class="dev-toggle" aria-label="Toggle dev tools">—</button>
55
58
  </div>
56
59
  <div class="dev-body">
57
- <div class="dev-fns">Registered functions: <code>${(t.getRegisteredFunctions?.() ?? []).map((a) => a.name).join(", ") || "—"}</code></div>
60
+ <div class="dev-fns">Registered functions: <code>${w}</code></div>
58
61
  <div class="dev-section-label">JSON object (built by the agent)</div>
59
62
  <pre class="dev-state" id="ago-dev-state"></pre>
60
63
  <div class="dev-section-label">Function calls</div>
61
64
  <div class="dev-log" id="ago-dev-log"></div>
62
65
  </div>
63
- `, v = o.querySelector("#ago-dev-state"), x = o.querySelector("#ago-dev-log"), u(o, S, "dev tools");
64
- const s = document.createElement("aside");
65
- s.id = "ago-dev-events", s.className = "ago-dev-card", (n ?? document.body).appendChild(s), s.innerHTML = `
66
+ `, g = s.querySelector(".dev-state"), m = s.querySelector(".dev-log"), $(s, T + x, "dev tools");
67
+ const i = document.createElement("aside");
68
+ i.id = "ago-dev-events", i.className = "ago-dev-card", S(i), (y ?? document.body).appendChild(i), i.innerHTML = `
66
69
  <div class="dev-head">
67
70
  <span class="dev-badge">SSE</span>
68
- <span class="dev-title">SSE EVENT LOG · raw stream messages</span>
71
+ <span class="dev-title">${a ? `SSE EVENT LOG · ${a}` : "SSE EVENT LOG · raw stream messages"}</span>
69
72
  <button type="button" class="dev-toggle" aria-label="Toggle SSE event log">—</button>
70
73
  </div>
71
74
  <div class="dev-body">
72
75
  <div class="dev-log" id="ago-dev-event-log"></div>
73
76
  </div>
74
- `, p = s.querySelector("#ago-dev-event-log"), u(s, E, "SSE event log"), t.on("stream:message", (a) => {
75
- m(p, y(a), "event");
76
- }), t.on("function:invoke", ({ functionName: a, arguments: l }) => {
77
- c(`→ ${a}(${JSON.stringify(l ?? {})})`, "invoke");
78
- }), t.on("function:result", ({ result: a, error: l }) => {
79
- c(l ? `✗ error: ${l}` : `← ${JSON.stringify(a)}`, l ? "error" : "result"), i();
80
- }), t.on("context:changed", i), t.on("conversation:loaded", (a) => {
81
- const l = (a.messages ?? []).flatMap((r) => r.toolCalls ?? []);
82
- c(`⟳ hydrated "${a.title || a.id}" — replayed ${l.length} tool call${l.length === 1 ? "" : "s"}`, "hydrate"), i();
83
- }), i();
77
+ `, b = i.querySelector(".dev-log"), $(i, N + x, "SSE event log"), t.on("stream:message", (o) => {
78
+ E(b, O(o), "event");
79
+ }), t.on("function:invoke", ({ functionName: o, arguments: n }) => {
80
+ v(`→ ${o}(${JSON.stringify(n ?? {})})`, "invoke");
81
+ }), t.on("function:result", ({ result: o, error: n }) => {
82
+ v(n ? `✗ error: ${n}` : `← ${JSON.stringify(o)}`, n ? "error" : "result"), c();
83
+ }), t.on("context:changed", c), t.on("conversation:loaded", (o) => {
84
+ const n = (o.messages ?? []).flatMap((p) => p.toolCalls ?? []);
85
+ v(`⟳ hydrated "${o.title || o.id}" — replayed ${n.length} tool call${n.length === 1 ? "" : "s"}`, "hydrate"), c();
86
+ }), c();
84
87
  }
85
- var f = "ago-dev-panel-styles";
86
- function C() {
87
- if (document.getElementById(f)) return;
88
+ var C = "ago-dev-panel-styles";
89
+ function _() {
90
+ if (document.getElementById(C)) return;
88
91
  const e = document.createElement("style");
89
- e.id = f, e.textContent = w, document.head.appendChild(e);
92
+ e.id = C, e.textContent = q, document.head.appendChild(e);
90
93
  }
91
- var w = `
94
+ var q = `
92
95
  .ago-dev-card {
93
96
  position: fixed;
94
97
  right: 16px;
@@ -190,5 +193,5 @@ var w = `
190
193
  .ago-dev-card .dev-log-event { color: #7c8a99; }
191
194
  `;
192
195
  export {
193
- L as initDevPanel
196
+ z as initDevPanel
194
197
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./AgoClient-B3-WGVne.cjs"),f=require("./createFormCollector-BHHEW6uX.cjs"),p=require("./createConversationSession-BwYNMZWq.cjs"),w=require("./createMockClient-zHQ0cjUH.cjs");require("./testing.cjs");const g=require("./functions-Djnq-JAo.cjs");function h(e){return e}function E(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function S(e,o){return e.on("message:chunk",o),()=>e.off("message:chunk",o)}function y(e,o){return e.on("message:start",o),()=>e.off("message:start",o)}function b(e,o){return e.on("message:error",o),()=>e.off("message:error",o)}function F(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function v(e,o){return e.on("form:submitted",o),()=>e.off("form:submitted",o)}function M(e,o){return e.on("form:error",o),()=>e.off("form:error",o)}function q(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*k(e,o,l){const a=[];let r=null,s=!1;const m=i=>{a.push(i),r?.()},c=i=>m({type:"start",data:i}),t=i=>m({type:"chunk",data:i}),u=i=>{m({type:"complete",data:i}),s=!0,r?.()},d=i=>{m({type:"error",data:i}),s=!0,r?.()},C=i=>m({type:"toolCall",data:i});e.on("message:start",c),e.on("message:chunk",t),e.on("message:complete",u),e.on("message:error",d),e.on("toolCall:received",C),e.sendMessage(o,l).catch(()=>{s=!0,r?.()});try{for(;!s||a.length>0;)a.length>0?yield a.shift():(await new Promise(i=>{r=i}),r=null)}finally{e.off("message:start",c),e.off("message:chunk",t),e.off("message:complete",u),e.off("message:error",d),e.off("toolCall:received",C)}}function A(e){let o,l,a,r,s,m;if(typeof window<"u"&&window.AGO){const t=window.AGO;o=t.basepath,l=t.widgetId,a=t.agent||t.defaultAgent,r=t.permission,s=t.email,m=t.jwt}if(typeof document<"u"){const t=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||t("ago-base-url"),l=l||t("ago-widget-id"),a=a||t("ago-agent")||t("ago-agent-id"),r=r||t("ago-permission"),s=s||t("ago-user-email")}if(typeof document<"u"){const t=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of t)u&&(o=o||u.getAttribute("data-ago-base-url")||void 0,l=l||u.getAttribute("data-ago-widget-id")||void 0,a=a||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,r=r||u.getAttribute("data-ago-permission")||void 0,s=s||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,a=e?.agent||e?.defaultAgentId||a,r=e?.permission||r,s=e?.userEmail||s,m=e?.userJwt||m;const c=e?.debug;return o?{baseUrl:o,widgetId:l,agent:a,permission:r,userEmail:s,userJwt:m,debug:c}:null}function T(e){const o=A(e);if(!o)throw new n.AgoError('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.',"config_missing_base_url");return new n.AgoClient(o)}function _(e,o){return{...e,handler:o}}exports.AgoApiError=n.AgoApiError;exports.AgoClient=n.AgoClient;exports.AgoError=n.AgoError;exports.AgoFunctionError=n.AgoFunctionError;exports.AgoNetworkError=n.AgoNetworkError;exports.AgoStreamError=n.AgoStreamError;exports.ClientContextRegistry=n.ClientContextRegistry;exports.EventEmitter=n.EventEmitter;exports.FunctionRegistry=n.FunctionRegistry;exports.SSEHandler=n.SSEHandler;exports.autoDetectConfig=A;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=T;exports.createConversationSession=p.createConversationSession;exports.createFormCollector=f.createFormCollector;exports.createMessageStream=k;exports.createMockClient=w.createMockClient;exports.createStore=f.createStore;exports.defineFunction=h;exports.deriveFormStatus=f.deriveFormStatus;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=n.isStreamNetworkError;exports.loadFormCollector=f.loadFormCollector;exports.logger=n.logger;exports.onFormError=M;exports.onFormSubmitted=v;exports.onFunctionInvoke=q;exports.onMessage=E;exports.onMessageChunk=S;exports.onMessageError=b;exports.onMessageStart=y;exports.onToolCall=F;exports.openUrl=g.openUrl;exports.scrollToElement=g.scrollToElement;exports.setLocalStorage=g.setLocalStorage;exports.setTheme=g.setTheme;exports.showConfirmDialog=g.showConfirmDialog;exports.showNotification=g.showNotification;exports.showToast=g.showToast;exports.submitForm=g.submitForm;exports.trackEvent=g.trackEvent;exports.validateConfig=n.validateConfig;exports.withHandler=_;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./AgoClient-B3-WGVne.cjs"),f=require("./createFormCollector-BI3DXaew.cjs"),p=require("./createConversationSession-C0diFTUk.cjs"),w=require("./createMockClient-zHQ0cjUH.cjs");require("./testing.cjs");const g=require("./functions-Djnq-JAo.cjs");function h(e){return e}function E(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function S(e,o){return e.on("message:chunk",o),()=>e.off("message:chunk",o)}function y(e,o){return e.on("message:start",o),()=>e.off("message:start",o)}function b(e,o){return e.on("message:error",o),()=>e.off("message:error",o)}function F(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function v(e,o){return e.on("form:submitted",o),()=>e.off("form:submitted",o)}function M(e,o){return e.on("form:error",o),()=>e.off("form:error",o)}function q(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*k(e,o,l){const a=[];let r=null,s=!1;const m=i=>{a.push(i),r?.()},c=i=>m({type:"start",data:i}),t=i=>m({type:"chunk",data:i}),u=i=>{m({type:"complete",data:i}),s=!0,r?.()},d=i=>{m({type:"error",data:i}),s=!0,r?.()},C=i=>m({type:"toolCall",data:i});e.on("message:start",c),e.on("message:chunk",t),e.on("message:complete",u),e.on("message:error",d),e.on("toolCall:received",C),e.sendMessage(o,l).catch(()=>{s=!0,r?.()});try{for(;!s||a.length>0;)a.length>0?yield a.shift():(await new Promise(i=>{r=i}),r=null)}finally{e.off("message:start",c),e.off("message:chunk",t),e.off("message:complete",u),e.off("message:error",d),e.off("toolCall:received",C)}}function A(e){let o,l,a,r,s,m;if(typeof window<"u"&&window.AGO){const t=window.AGO;o=t.basepath,l=t.widgetId,a=t.agent||t.defaultAgent,r=t.permission,s=t.email,m=t.jwt}if(typeof document<"u"){const t=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||t("ago-base-url"),l=l||t("ago-widget-id"),a=a||t("ago-agent")||t("ago-agent-id"),r=r||t("ago-permission"),s=s||t("ago-user-email")}if(typeof document<"u"){const t=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of t)u&&(o=o||u.getAttribute("data-ago-base-url")||void 0,l=l||u.getAttribute("data-ago-widget-id")||void 0,a=a||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,r=r||u.getAttribute("data-ago-permission")||void 0,s=s||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,a=e?.agent||e?.defaultAgentId||a,r=e?.permission||r,s=e?.userEmail||s,m=e?.userJwt||m;const c=e?.debug;return o?{baseUrl:o,widgetId:l,agent:a,permission:r,userEmail:s,userJwt:m,debug:c}:null}function T(e){const o=A(e);if(!o)throw new n.AgoError('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.',"config_missing_base_url");return new n.AgoClient(o)}function _(e,o){return{...e,handler:o}}exports.AgoApiError=n.AgoApiError;exports.AgoClient=n.AgoClient;exports.AgoError=n.AgoError;exports.AgoFunctionError=n.AgoFunctionError;exports.AgoNetworkError=n.AgoNetworkError;exports.AgoStreamError=n.AgoStreamError;exports.ClientContextRegistry=n.ClientContextRegistry;exports.EventEmitter=n.EventEmitter;exports.FunctionRegistry=n.FunctionRegistry;exports.SSEHandler=n.SSEHandler;exports.autoDetectConfig=A;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=T;exports.createConversationSession=p.createConversationSession;exports.createFormCollector=f.createFormCollector;exports.createMessageStream=k;exports.createMockClient=w.createMockClient;exports.createStore=f.createStore;exports.defineFunction=h;exports.deriveFormStatus=f.deriveFormStatus;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=n.isStreamNetworkError;exports.loadFormCollector=f.loadFormCollector;exports.logger=n.logger;exports.onFormError=M;exports.onFormSubmitted=v;exports.onFunctionInvoke=q;exports.onMessage=E;exports.onMessageChunk=S;exports.onMessageError=b;exports.onMessageStart=y;exports.onToolCall=F;exports.openUrl=g.openUrl;exports.scrollToElement=g.scrollToElement;exports.setLocalStorage=g.setLocalStorage;exports.setTheme=g.setTheme;exports.showConfirmDialog=g.showConfirmDialog;exports.showNotification=g.showNotification;exports.showToast=g.showToast;exports.submitForm=g.submitForm;exports.trackEvent=g.trackEvent;exports.validateConfig=n.validateConfig;exports.withHandler=_;
package/dist/index.d.cts CHANGED
@@ -935,7 +935,7 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
935
935
 
936
936
  /**
937
937
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
938
- * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
938
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes from the LLM tool's `parameters` (the full schema still reaches the agent via dynamic context).
939
939
  */
940
940
  export declare interface FormCollectorSchema {
941
941
  type: "object";
@@ -975,17 +975,32 @@ export declare interface FormField {
975
975
  }
976
976
 
977
977
  /**
978
- * A field's conditional-requiredness rule. The field becomes required exactly
979
- * when the controlling `property` matches `value` against the answers collected
980
- * so far:
978
+ * A field's conditional-requiredness rule: either a single {@link FormFieldLeafCondition}
979
+ * or a boolean combination of rules. `anyOf` is OR (true when any nested rule
980
+ * holds); `allOf` is AND (true when every nested rule holds). Both nest
981
+ * arbitrarily, so you can mix them, e.g.
982
+ * `{ anyOf: [{ property: "a", op: ">=", value: 1 }, { property: "b", value: "1" }] }`.
983
+ * An empty `anyOf` is never required; an empty `allOf` is always required.
984
+ *
985
+ * Stripped from the LLM tool's `parameters` (see {@link toWireParameters}), but the
986
+ * full schema, `requiredWhen` included, still reaches the agent via the dynamic
987
+ * context so it knows when each field becomes required.
988
+ */
989
+ export declare type FormFieldCondition = FormFieldLeafCondition | {
990
+ anyOf: FormFieldCondition[];
991
+ } | {
992
+ allOf: FormFieldCondition[];
993
+ };
994
+
995
+ /**
996
+ * A single leaf comparison. The field it guards becomes required exactly when the
997
+ * controlling `property` matches `value` against the answers collected so far:
981
998
  * - a single `value`, no `op` — equality (compared as strings);
982
999
  * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
983
1000
  * - an array `value`, no `op` — "one of": matches when the property equals any
984
1001
  * listed value.
985
- *
986
- * SDK-only — it is stripped from the schema before it reaches the LLM tool
987
1002
  */
988
- declare interface FormFieldCondition {
1003
+ export declare interface FormFieldLeafCondition {
989
1004
  /** The controlling field whose value the rule tests. */
990
1005
  property: string;
991
1006
  /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
@@ -999,14 +1014,15 @@ declare interface FormFieldCondition {
999
1014
  }
1000
1015
 
1001
1016
  /** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
1002
- declare interface FormFieldSchema {
1017
+ export declare interface FormFieldSchema {
1003
1018
  type: string;
1004
1019
  description?: string;
1005
1020
  enum?: string[];
1006
1021
  default?: unknown;
1007
1022
  /**
1008
1023
  * Makes the field required only while this condition holds. Drives the dynamic
1009
- * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
1024
+ * `missing` list; stripped from the LLM tool's `parameters` (still sent to the
1025
+ * agent via dynamic context). See {@link toWireParameters}.
1010
1026
  */
1011
1027
  requiredWhen?: FormFieldCondition;
1012
1028
  }
package/dist/index.d.ts CHANGED
@@ -935,7 +935,7 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
935
935
 
936
936
  /**
937
937
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
938
- * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
938
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes from the LLM tool's `parameters` (the full schema still reaches the agent via dynamic context).
939
939
  */
940
940
  export declare interface FormCollectorSchema {
941
941
  type: "object";
@@ -975,17 +975,32 @@ export declare interface FormField {
975
975
  }
976
976
 
977
977
  /**
978
- * A field's conditional-requiredness rule. The field becomes required exactly
979
- * when the controlling `property` matches `value` against the answers collected
980
- * so far:
978
+ * A field's conditional-requiredness rule: either a single {@link FormFieldLeafCondition}
979
+ * or a boolean combination of rules. `anyOf` is OR (true when any nested rule
980
+ * holds); `allOf` is AND (true when every nested rule holds). Both nest
981
+ * arbitrarily, so you can mix them, e.g.
982
+ * `{ anyOf: [{ property: "a", op: ">=", value: 1 }, { property: "b", value: "1" }] }`.
983
+ * An empty `anyOf` is never required; an empty `allOf` is always required.
984
+ *
985
+ * Stripped from the LLM tool's `parameters` (see {@link toWireParameters}), but the
986
+ * full schema, `requiredWhen` included, still reaches the agent via the dynamic
987
+ * context so it knows when each field becomes required.
988
+ */
989
+ export declare type FormFieldCondition = FormFieldLeafCondition | {
990
+ anyOf: FormFieldCondition[];
991
+ } | {
992
+ allOf: FormFieldCondition[];
993
+ };
994
+
995
+ /**
996
+ * A single leaf comparison. The field it guards becomes required exactly when the
997
+ * controlling `property` matches `value` against the answers collected so far:
981
998
  * - a single `value`, no `op` — equality (compared as strings);
982
999
  * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
983
1000
  * - an array `value`, no `op` — "one of": matches when the property equals any
984
1001
  * listed value.
985
- *
986
- * SDK-only — it is stripped from the schema before it reaches the LLM tool
987
1002
  */
988
- declare interface FormFieldCondition {
1003
+ export declare interface FormFieldLeafCondition {
989
1004
  /** The controlling field whose value the rule tests. */
990
1005
  property: string;
991
1006
  /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
@@ -999,14 +1014,15 @@ declare interface FormFieldCondition {
999
1014
  }
1000
1015
 
1001
1016
  /** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
1002
- declare interface FormFieldSchema {
1017
+ export declare interface FormFieldSchema {
1003
1018
  type: string;
1004
1019
  description?: string;
1005
1020
  enum?: string[];
1006
1021
  default?: unknown;
1007
1022
  /**
1008
1023
  * Makes the field required only while this condition holds. Drives the dynamic
1009
- * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
1024
+ * `missing` list; stripped from the LLM tool's `parameters` (still sent to the
1025
+ * agent via dynamic context). See {@link toWireParameters}.
1010
1026
  */
1011
1027
  requiredWhen?: FormFieldCondition;
1012
1028
  }
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as h, c as A, d as y, f as C, i as E, l as b, m as S, o as v, p as F, r as M, s as k, t as T, u as I } from "./functions-CApuQZ2b.js";
2
2
  import { a as G, c as O, d as q, f as x, i as L, l as N, n as _, o as D, p as H, r as J, s as R, t as d, u as c } from "./AgoClient-QcTtrN7u.js";
3
- import { i as B, n as P, r as $, t as z } from "./createFormCollector-QyojCH_-.js";
4
- import { t as Q } from "./createConversationSession-DrCMdwkV.js";
3
+ import { i as B, n as P, r as $, t as z } from "./createFormCollector-CFt1_QSL.js";
4
+ import { t as Q } from "./createConversationSession-CR-71aLR.js";
5
5
  import { t as W } from "./createMockClient-DwdxNwEn.js";
6
6
  import "./testing.js";
7
7
  function Y(e) {
package/dist/react.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),J=require("./AgoClient-B3-WGVne.cjs"),M=require("./createFormCollector-BHHEW6uX.cjs"),V=require("./createMockClient-zHQ0cjUH.cjs");let n=require("react");n=P.__toESM(n,1);let o=require("react/jsx-runtime"),F=require("react-markdown");F=P.__toESM(F,1);let N=require("remark-gfm");N=P.__toESM(N,1);function q(e){const[t,s]=(0,n.useState)(!1),r=(0,n.useRef)(null),a=(0,n.useMemo)(()=>{if(r.current&&(r.current.destroy(),r.current=null),!e)return null;const l=new J.AgoClient(e);return r.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(s(!0),()=>{r.current?.destroy(),r.current=null}),[a]),(0,n.useEffect)(()=>{r.current&&e&&r.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:a,isReady:t}}var T=(0,n.createContext)(null),G=({children:e,client:t,tools:s,helpers:r,pageContext:a,...l})=>{const{client:u}=q(t?null:l),i=t||u;return(0,n.useEffect)(()=>{if(!(!s||s.length===0)){for(const p of s)i.register(p);return()=>{for(const p of s)i.unregisterFunction(p.name)}}},[i,s]),(0,n.useEffect)(()=>{if(!r)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(d=>d.functions_exports).then(d=>{for(const[h,C]of Object.entries(r)){const k=d[h];if(!k){console.warn(`[AGO] Unknown helper: "${h}"`);continue}const m=C===!0?k:{...k,handler:C};i.register(m),p.push(m.name)}}),()=>{for(const d of p)i.unregisterFunction(d)}},[i,r]),(0,n.useEffect)(()=>{a==="auto"&&i.enableAutoPageContext()},[i,a]),(0,o.jsx)(T.Provider,{value:i,children:e})};function A(){const e=(0,n.useContext)(T);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function R(){return(0,n.useContext)(T)}function L({client:e,conversationId:t}={}){const s=R(),r=e||s;if(!r)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(t),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&t!==u&&(i(t),k(t))},[t]);const k=async m=>{try{l(await r.getMessages(m))}catch(v){C(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const m=x=>{u||i(x.conversationId)},v=x=>{l(f=>{const w=f[f.length-1];return w&&w.id===x.messageId?[...f.slice(0,-1),{...w,content:w.content+x.content}]:f})},c=x=>{l(f=>{let w=-1;for(let S=f.length-1;S>=0;S--)if(f[S].role==="assistant"&&f[S].status==="IN_PROGRESS"){w=S;break}return w<0?f:[...f.slice(0,w),{...f[w],...x},...f.slice(w+1)]})},y=x=>{l(f=>{const w=f.findIndex(S=>S.id===x.id);return w>=0?[...f.slice(0,w),x,...f.slice(w+1)]:[...f,x]}),d(!1)},g=x=>{C(new Error(x.error)),d(!1)};return r.on("message:start",m),r.on("message:chunk",v),r.on("message:answer-complete",c),r.on("message:complete",y),r.on("message:error",g),()=>{r.off("message:start",m),r.off("message:chunk",v),r.off("message:answer-complete",c),r.off("message:complete",y),r.off("message:error",g)}},[r,u]),{messages:a,isLoading:p,error:h,sendMessage:(0,n.useCallback)(async(m,v)=>{d(!0),C(null);const c={id:`temp-${Date.now()}`,conversationId:u||"",content:m,role:"user",status:"DONE",createdAt:new Date},y={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(g=>[...g,c,y]);try{const g=await r.sendMessage(m,{conversationId:u,files:v});return g.conversationId&&!u&&i(g.conversationId),l(x=>{const f=x.filter(S=>!S.id.startsWith("temp-")),w={...c,id:c.id.replace("temp-","user-"),conversationId:g.conversationId};return f.some(S=>S.id===g.id)?[...f,w].sort((S,_)=>new Date(S.createdAt).getTime()-new Date(_.createdAt).getTime()):[...f,w,g]}),g}catch(g){return C(g instanceof Error?g:new Error("Failed to send message")),d(!1),l(x=>x.filter(f=>!f.id.startsWith("temp-"))),null}},[r,u]),clearMessages:(0,n.useCallback)(()=>{l([]),i(void 0),C(null)},[]),conversationId:u}}var W=({onSend:e,disabled:t=!1,placeholder:s="Type a message...",allowFiles:r=!1,className:a=""})=>{const[l,u]=(0,n.useState)(""),[i,p]=(0,n.useState)([]),d=(0,n.useRef)(null),h=(0,n.useCallback)(c=>{c.preventDefault(),(l.trim()||i.length>0)&&(e(l.trim(),i.length>0?i:void 0),u(""),p([]))},[l,i,e]),C=(0,n.useCallback)(c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),h(c))},[h]),k=(0,n.useCallback)(c=>{const y=Array.from(c.target.files||[]);p(g=>[...g,...y])},[]),m=(0,n.useCallback)(c=>{p(y=>y.filter((g,x)=>x!==c))},[]),v=l.trim()||i.length>0;return(0,o.jsxs)("form",{onSubmit:h,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[i.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((c,y)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,o.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.name}),(0,o.jsx)("button",{type:"button",onClick:()=>m(y),style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},y))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>d.current?.click(),disabled:t,style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,o.jsx)("input",{ref:d,type:"file",multiple:!0,onChange:k,style:{display:"none"}})]}),(0,o.jsx)("textarea",{value:l,onChange:c=>u(c.target.value),onKeyDown:C,placeholder:s,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",fontFamily:"inherit",fontSize:"16px",color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:c=>{c.currentTarget.style.borderColor="#1b5fc4"},onBlur:c=>{c.currentTarget.style.borderColor="#dee3e8"}}),(0,o.jsx)("button",{type:"submit",disabled:t||!v,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!v?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!v?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},X=({href:e,children:t,...s})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...s,children:t}),Y=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),I=(e,t)=>{const s=({children:r,...a})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},r);return s.displayName=`MarkdownHeading${e}`,s},Q=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),Z=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),te=({className:e,children:t,...s})=>e!==void 0||String(t).includes(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),J=require("./AgoClient-B3-WGVne.cjs"),M=require("./createFormCollector-BI3DXaew.cjs"),V=require("./createMockClient-zHQ0cjUH.cjs");let n=require("react");n=P.__toESM(n,1);let o=require("react/jsx-runtime"),F=require("react-markdown");F=P.__toESM(F,1);let N=require("remark-gfm");N=P.__toESM(N,1);function q(e){const[t,s]=(0,n.useState)(!1),r=(0,n.useRef)(null),a=(0,n.useMemo)(()=>{if(r.current&&(r.current.destroy(),r.current=null),!e)return null;const l=new J.AgoClient(e);return r.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,n.useEffect)(()=>(s(!0),()=>{r.current?.destroy(),r.current=null}),[a]),(0,n.useEffect)(()=>{r.current&&e&&r.current.updateConfig({agent:e.agent,defaultAgentId:e.defaultAgentId,permission:e.permission,userEmail:e.userEmail,userJwt:e.userJwt,debug:e.debug,warnOnEmptyReply:e.warnOnEmptyReply})},[e?.agent,e?.defaultAgentId,e?.permission,e?.userEmail,e?.userJwt,e?.debug,e?.warnOnEmptyReply]),{client:a,isReady:t}}var T=(0,n.createContext)(null),G=({children:e,client:t,tools:s,helpers:r,pageContext:a,...l})=>{const{client:u}=q(t?null:l),i=t||u;return(0,n.useEffect)(()=>{if(!(!s||s.length===0)){for(const p of s)i.register(p);return()=>{for(const p of s)i.unregisterFunction(p.name)}}},[i,s]),(0,n.useEffect)(()=>{if(!r)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(d=>d.functions_exports).then(d=>{for(const[h,C]of Object.entries(r)){const k=d[h];if(!k){console.warn(`[AGO] Unknown helper: "${h}"`);continue}const m=C===!0?k:{...k,handler:C};i.register(m),p.push(m.name)}}),()=>{for(const d of p)i.unregisterFunction(d)}},[i,r]),(0,n.useEffect)(()=>{a==="auto"&&i.enableAutoPageContext()},[i,a]),(0,o.jsx)(T.Provider,{value:i,children:e})};function A(){const e=(0,n.useContext)(T);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function R(){return(0,n.useContext)(T)}function L({client:e,conversationId:t}={}){const s=R(),r=e||s;if(!r)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,n.useState)([]),[u,i]=(0,n.useState)(t),[p,d]=(0,n.useState)(!1),[h,C]=(0,n.useState)(null);(0,n.useEffect)(()=>{t&&t!==u&&(i(t),k(t))},[t]);const k=async m=>{try{l(await r.getMessages(m))}catch(v){C(v instanceof Error?v:new Error("Failed to load messages"))}};return(0,n.useEffect)(()=>{const m=x=>{u||i(x.conversationId)},v=x=>{l(f=>{const w=f[f.length-1];return w&&w.id===x.messageId?[...f.slice(0,-1),{...w,content:w.content+x.content}]:f})},c=x=>{l(f=>{let w=-1;for(let S=f.length-1;S>=0;S--)if(f[S].role==="assistant"&&f[S].status==="IN_PROGRESS"){w=S;break}return w<0?f:[...f.slice(0,w),{...f[w],...x},...f.slice(w+1)]})},y=x=>{l(f=>{const w=f.findIndex(S=>S.id===x.id);return w>=0?[...f.slice(0,w),x,...f.slice(w+1)]:[...f,x]}),d(!1)},g=x=>{C(new Error(x.error)),d(!1)};return r.on("message:start",m),r.on("message:chunk",v),r.on("message:answer-complete",c),r.on("message:complete",y),r.on("message:error",g),()=>{r.off("message:start",m),r.off("message:chunk",v),r.off("message:answer-complete",c),r.off("message:complete",y),r.off("message:error",g)}},[r,u]),{messages:a,isLoading:p,error:h,sendMessage:(0,n.useCallback)(async(m,v)=>{d(!0),C(null);const c={id:`temp-${Date.now()}`,conversationId:u||"",content:m,role:"user",status:"DONE",createdAt:new Date},y={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(g=>[...g,c,y]);try{const g=await r.sendMessage(m,{conversationId:u,files:v});return g.conversationId&&!u&&i(g.conversationId),l(x=>{const f=x.filter(S=>!S.id.startsWith("temp-")),w={...c,id:c.id.replace("temp-","user-"),conversationId:g.conversationId};return f.some(S=>S.id===g.id)?[...f,w].sort((S,_)=>new Date(S.createdAt).getTime()-new Date(_.createdAt).getTime()):[...f,w,g]}),g}catch(g){return C(g instanceof Error?g:new Error("Failed to send message")),d(!1),l(x=>x.filter(f=>!f.id.startsWith("temp-"))),null}},[r,u]),clearMessages:(0,n.useCallback)(()=>{l([]),i(void 0),C(null)},[]),conversationId:u}}var W=({onSend:e,disabled:t=!1,placeholder:s="Type a message...",allowFiles:r=!1,className:a=""})=>{const[l,u]=(0,n.useState)(""),[i,p]=(0,n.useState)([]),d=(0,n.useRef)(null),h=(0,n.useCallback)(c=>{c.preventDefault(),(l.trim()||i.length>0)&&(e(l.trim(),i.length>0?i:void 0),u(""),p([]))},[l,i,e]),C=(0,n.useCallback)(c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),h(c))},[h]),k=(0,n.useCallback)(c=>{const y=Array.from(c.target.files||[]);p(g=>[...g,...y])},[]),m=(0,n.useCallback)(c=>{p(y=>y.filter((g,x)=>x!==c))},[]),v=l.trim()||i.length>0;return(0,o.jsxs)("form",{onSubmit:h,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[i.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:i.map((c,y)=>(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,o.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.name}),(0,o.jsx)("button",{type:"button",onClick:()=>m(y),style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},y))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[r&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>d.current?.click(),disabled:t,style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:t?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,o.jsx)("input",{ref:d,type:"file",multiple:!0,onChange:k,style:{display:"none"}})]}),(0,o.jsx)("textarea",{value:l,onChange:c=>u(c.target.value),onKeyDown:C,placeholder:s,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",fontFamily:"inherit",fontSize:"16px",color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:c=>{c.currentTarget.style.borderColor="#1b5fc4"},onBlur:c=>{c.currentTarget.style.borderColor="#dee3e8"}}),(0,o.jsx)("button",{type:"submit",disabled:t||!v,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:t||!v?"#b5bfc8":"#03182f",color:"#fff",cursor:t||!v?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},X=({href:e,children:t,...s})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...s,children:t}),Y=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),I=(e,t)=>{const s=({children:r,...a})=>n.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},r);return s.displayName=`MarkdownHeading${e}`,s},Q=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),Z=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),te=({className:e,children:t,...s})=>e!==void 0||String(t).includes(`
2
2
  `)?(0,o.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...s,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...s,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),ne=({children:e,...t})=>(0,o.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...t,children:e}),oe=({children:e,...t})=>(0,o.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,o.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...t,children:e})}),se=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ae=({children:e,...t})=>(0,o.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...t,children:e}),le=({alt:e,...t})=>(0,o.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...t}),ie=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),ce={a:X,p:Y,h1:I(1,"20px"),h2:I(2,"18px"),h3:I(3,"16px"),h4:I(4,"15px"),h5:I(5,"14px"),h6:I(6,"13px"),ul:Q,ol:Z,li:ee,code:te,pre:re,blockquote:ne,table:oe,th:se,td:ae,img:le,hr:ie},de=[N.default],z=({content:e})=>(0,o.jsx)(F.default,{remarkPlugins:de,components:ce,children:e}),ue=({source:e,index:t})=>{const s=(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,o.jsx)("div",{style:{flexShrink:0,width:"18px",height:"18px",borderRadius:"3px",border:"1px solid #1b5fc4",color:"#1b5fc4",fontSize:"11px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"},children:t+1}),(0,o.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),r={display:"flex",alignItems:"center",padding:"8px 10px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:e.url?"pointer":"default",textDecoration:"none",color:"inherit",minWidth:0,transition:"border-color 0.15s"};return e.url?(0,o.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:r,onMouseEnter:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:a=>{a.currentTarget.style.borderColor="#dee3e8"},children:s}):(0,o.jsx)("div",{style:r,children:s})},fe=()=>(0,o.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,o.jsx)("div",{style:{width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`}},e)),(0,o.jsx)("style",{children:`
3
3
  @keyframes ago-pulse {
4
4
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
package/dist/react.d.cts CHANGED
@@ -705,7 +705,7 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
705
705
 
706
706
  /**
707
707
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
708
- * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
708
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes from the LLM tool's `parameters` (the full schema still reaches the agent via dynamic context).
709
709
  */
710
710
  export declare interface FormCollectorSchema {
711
711
  type: "object";
@@ -745,17 +745,32 @@ declare interface FormField {
745
745
  }
746
746
 
747
747
  /**
748
- * A field's conditional-requiredness rule. The field becomes required exactly
749
- * when the controlling `property` matches `value` against the answers collected
750
- * so far:
748
+ * A field's conditional-requiredness rule: either a single {@link FormFieldLeafCondition}
749
+ * or a boolean combination of rules. `anyOf` is OR (true when any nested rule
750
+ * holds); `allOf` is AND (true when every nested rule holds). Both nest
751
+ * arbitrarily, so you can mix them, e.g.
752
+ * `{ anyOf: [{ property: "a", op: ">=", value: 1 }, { property: "b", value: "1" }] }`.
753
+ * An empty `anyOf` is never required; an empty `allOf` is always required.
754
+ *
755
+ * Stripped from the LLM tool's `parameters` (see {@link toWireParameters}), but the
756
+ * full schema, `requiredWhen` included, still reaches the agent via the dynamic
757
+ * context so it knows when each field becomes required.
758
+ */
759
+ export declare type FormFieldCondition = FormFieldLeafCondition | {
760
+ anyOf: FormFieldCondition[];
761
+ } | {
762
+ allOf: FormFieldCondition[];
763
+ };
764
+
765
+ /**
766
+ * A single leaf comparison. The field it guards becomes required exactly when the
767
+ * controlling `property` matches `value` against the answers collected so far:
751
768
  * - a single `value`, no `op` — equality (compared as strings);
752
769
  * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
753
770
  * - an array `value`, no `op` — "one of": matches when the property equals any
754
771
  * listed value.
755
- *
756
- * SDK-only — it is stripped from the schema before it reaches the LLM tool
757
772
  */
758
- declare interface FormFieldCondition {
773
+ export declare interface FormFieldLeafCondition {
759
774
  /** The controlling field whose value the rule tests. */
760
775
  property: string;
761
776
  /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
@@ -769,14 +784,15 @@ declare interface FormFieldCondition {
769
784
  }
770
785
 
771
786
  /** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
772
- declare interface FormFieldSchema {
787
+ export declare interface FormFieldSchema {
773
788
  type: string;
774
789
  description?: string;
775
790
  enum?: string[];
776
791
  default?: unknown;
777
792
  /**
778
793
  * Makes the field required only while this condition holds. Drives the dynamic
779
- * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
794
+ * `missing` list; stripped from the LLM tool's `parameters` (still sent to the
795
+ * agent via dynamic context). See {@link toWireParameters}.
780
796
  */
781
797
  requiredWhen?: FormFieldCondition;
782
798
  }