@useago/sdk 0.3.4 → 0.4.2

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 (41) hide show
  1. package/dist/AgoClient-D4EL6nva.cjs +6 -0
  2. package/dist/{AgoClient-DF7M2WAz.js → AgoClient-rvTz2thR.js} +239 -218
  3. package/dist/angular.cjs +1 -1
  4. package/dist/angular.d.cts +27 -0
  5. package/dist/angular.d.ts +27 -0
  6. package/dist/angular.js +1 -1
  7. package/dist/createConversationSession-D9FesBQS.js +58 -0
  8. package/dist/createConversationSession-DtaeA418.cjs +1 -0
  9. package/dist/createFormCollector-BwvkKi48.js +211 -0
  10. package/dist/createFormCollector-Wb8Rr-U2.cjs +1 -0
  11. package/dist/{createMockClient-C50gjV0b.js → createMockClient-DwdxNwEn.js} +5 -2
  12. package/dist/createMockClient-zHQ0cjUH.cjs +1 -0
  13. package/dist/devtools.cjs +5 -4
  14. package/dist/devtools.d.cts +31 -26
  15. package/dist/devtools.d.ts +31 -26
  16. package/dist/devtools.js +39 -35
  17. package/dist/helpers.cjs +1 -1
  18. package/dist/helpers.js +1 -1
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.d.cts +117 -1
  21. package/dist/index.d.ts +117 -1
  22. package/dist/index.js +44 -42
  23. package/dist/react.cjs +1 -1
  24. package/dist/react.d.cts +35 -0
  25. package/dist/react.d.ts +35 -0
  26. package/dist/react.js +4 -4
  27. package/dist/vue.cjs +1 -1
  28. package/dist/vue.d.cts +27 -0
  29. package/dist/vue.d.ts +27 -0
  30. package/dist/vue.js +1 -1
  31. package/dist/widget.cjs +1 -1
  32. package/dist/widget.d.cts +114 -0
  33. package/dist/widget.d.ts +114 -0
  34. package/dist/widget.js +170 -150
  35. package/package.json +58 -15
  36. package/dist/AgoClient-bjN-z2ZQ.cjs +0 -6
  37. package/dist/createFormCollector-ClzHfaBd.js +0 -185
  38. package/dist/createFormCollector-H4Me_2uj.cjs +0 -1
  39. package/dist/createMockClient-DQvFFWnc.cjs +0 -1
  40. /package/dist/{functions-CWSRi3xv.js → functions-C1-5vadY.js} +0 -0
  41. /package/dist/{functions-BH1X5kas.cjs → functions-DsmzgHjC.cjs} +0 -0
@@ -31,6 +31,12 @@ declare class AgoClient {
31
31
  * Get a specific conversation with messages
32
32
  */
33
33
  getConversation(conversationId: string): Promise<Conversation>;
34
+ /**
35
+ * Map the backend's snake_case `tool_call_data` entries onto the camelCase
36
+ * {@link ToolCallData} shape used everywhere else in the SDK. Mirrors
37
+ * `SSEHandler.parseToolCall` so persisted and streamed tool calls match.
38
+ */
39
+ private static mapPersistedToolCalls;
34
40
  /**
35
41
  * Get messages for a conversation
36
42
  */
@@ -141,6 +147,13 @@ declare class AgoClient {
141
147
  * Remove a dynamic context provider.
142
148
  */
143
149
  removeDynamicContext(key: string): boolean;
150
+ /**
151
+ * Broadcast that the client-side context changed by emitting `context:changed`
152
+ * with the fresh snapshot. The context-mutating methods call this automatically;
153
+ * stateful helpers whose context lives in a store (e.g. `createFormCollector`)
154
+ * call it when their store updates so observers like the dev panel stay live.
155
+ */
156
+ notifyContextChanged(): void;
144
157
  /**
145
158
  * Enable automatic capture of the current browser page (URL + title).
146
159
  * Injected as a dynamic context entry named `browser-page`.
@@ -186,6 +199,14 @@ declare class AgoClient {
186
199
  * SDK Events
187
200
  */
188
201
  declare interface AgoClientEvents {
202
+ /**
203
+ * The client-side context changed: a context entry or dynamic provider was
204
+ * added/removed, or a stateful helper (e.g. `createFormCollector`) updated its
205
+ * store. Carries the fresh snapshot so observers — notably the dev panel — can
206
+ * repaint without waiting for the next message. Fires for the form collector's
207
+ * initial install too, so its missing fields show from the start of a conversation.
208
+ */
209
+ "context:changed": ContextSnapshot | null;
189
210
  "message:start": {
190
211
  conversationId: string;
191
212
  messageId: string;
@@ -201,6 +222,12 @@ declare interface AgoClientEvents {
201
222
  conversationId?: string;
202
223
  messageId?: string;
203
224
  };
225
+ /**
226
+ * A full conversation was loaded from the server (e.g. after a page reload).
227
+ * Carries the messages and their persisted tool calls so stateful helpers —
228
+ * notably `createFormCollector` — can replay them to restore their state.
229
+ */
230
+ "conversation:loaded": Conversation;
204
231
  "toolCall:received": ToolCallData;
205
232
  "toolCall:form": ToolCallData;
206
233
  "function:invoke": ClientFunctionInvocation;
@@ -350,13 +377,12 @@ declare interface Conversation {
350
377
 
351
378
  /** Options for {@link initDevPanel}. */
352
379
  export declare interface DevPanelOptions {
353
- /** The store whose state the panel renders live. */
354
- store: Store<unknown>;
355
380
  /**
356
- * Client to read registered functions from and listen to function events on.
357
- * Typed structurally so a mock client works too.
381
+ * The AGO client to debug. The panel lists its registered functions, logs its
382
+ * function events, and renders its live context snapshot
383
+ * (`client.getContextSnapshot()`)
358
384
  */
359
- client: Pick<AgoClient, "on" | "getRegisteredFunctions">;
385
+ client: Pick<AgoClient, "on" | "getRegisteredFunctions" | "getContextSnapshot">;
360
386
  /** Where to mount: a CSS selector, an Element, or `document.body` (default). */
361
387
  target?: string | Element;
362
388
  }
@@ -401,27 +427,6 @@ declare interface SendMessageOptions {
401
427
  files?: File[];
402
428
  }
403
429
 
404
- /**
405
- * A minimal observable store: one value, synchronous subscriptions, and
406
- * optional persistence via {@link PersistOptions} (localStorage by default).
407
- *
408
- * ```ts
409
- * const store = createStore({ count: 0 });
410
- * store.subscribe((state) => save(state));
411
- * store.set({ count: 1 }); // listeners fire synchronously
412
- *
413
- * const cart = createStore({ items: [] }, { key: "cart" }); // persisted
414
- * ```
415
- */
416
- declare interface Store<T> {
417
- /** Current state. */
418
- get(): T;
419
- /** Replace the state and notify subscribers synchronously. */
420
- set(next: T): void;
421
- /** Register a listener; returns a function that removes it. */
422
- subscribe(listener: (state: T) => void): () => void;
423
- }
424
-
425
430
  /**
426
431
  * Tool call data from SSE stream
427
432
  */
package/dist/devtools.js CHANGED
@@ -1,62 +1,65 @@
1
- var r, d, x = () => ({});
2
- function p() {
3
- r && (r.textContent = JSON.stringify(x(), null, 2));
1
+ var c, d, v = () => ({});
2
+ function i() {
3
+ c && (c.textContent = JSON.stringify(v(), null, 2));
4
4
  }
5
- function g(t, a) {
5
+ function s(l, e) {
6
6
  if (!d) return;
7
- const e = document.createElement("div");
8
- e.className = `dev-log-line dev-log-${a}`, e.textContent = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${t}`, d.appendChild(e), d.scrollTop = d.scrollHeight;
7
+ const o = document.createElement("div");
8
+ o.className = `dev-log-line dev-log-${e}`, o.textContent = `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${l}`, d.appendChild(o), d.scrollTop = d.scrollHeight;
9
9
  }
10
- var u = "ago_dev_panel_collapsed";
11
- function s(t, a) {
12
- t.classList.toggle("collapsed", a);
13
- const e = t.querySelector(".dev-toggle");
14
- e && (e.textContent = a ? "▢" : "—", e.title = a ? "Expand dev tools" : "Collapse dev tools", e.setAttribute("aria-expanded", String(!a)));
10
+ var x = "ago_dev_panel_collapsed";
11
+ function r(l, e) {
12
+ l.classList.toggle("collapsed", e);
13
+ const o = l.querySelector(".dev-toggle");
14
+ o && (o.textContent = e ? "▢" : "—", o.title = e ? "Expand dev tools" : "Collapse dev tools", o.setAttribute("aria-expanded", String(!e)));
15
15
  try {
16
- localStorage.setItem(u, a ? "1" : "0");
16
+ localStorage.setItem(x, e ? "1" : "0");
17
17
  } catch {
18
18
  }
19
19
  }
20
- function m(t) {
21
- const { store: a, client: e, target: i } = t;
22
- x = a.get, b();
23
- const f = typeof i == "string" ? document.querySelector(i) : i instanceof Element ? i : document.body, o = document.createElement("aside");
24
- o.id = "ago-dev-panel", (f ?? document.body).appendChild(o), o.innerHTML = `
20
+ function m(l) {
21
+ const { client: e, target: o } = l;
22
+ v = () => e.getContextSnapshot()?.entries ?? {}, h();
23
+ const f = typeof o == "string" ? document.querySelector(o) : o instanceof Element ? o : document.body, t = document.createElement("aside");
24
+ t.id = "ago-dev-panel", (f ?? document.body).appendChild(t), t.innerHTML = `
25
25
  <div class="dev-head">
26
26
  <span class="dev-badge">DEV</span>
27
27
  <span class="dev-title">DEV TOOLS · client-side function state — not for production</span>
28
28
  <button type="button" class="dev-toggle" aria-label="Toggle dev tools">—</button>
29
29
  </div>
30
30
  <div class="dev-body">
31
- <div class="dev-fns">Registered functions: <code>${(e.getRegisteredFunctions?.() ?? []).map((n) => n.name).join(", ") || "—"}</code></div>
31
+ <div class="dev-fns">Registered functions: <code>${(e.getRegisteredFunctions?.() ?? []).map((a) => a.name).join(", ") || "—"}</code></div>
32
32
  <div class="dev-section-label">JSON object (built by the agent)</div>
33
33
  <pre class="dev-state" id="ago-dev-state"></pre>
34
34
  <div class="dev-section-label">Function calls</div>
35
35
  <div class="dev-log" id="ago-dev-log"></div>
36
36
  </div>
37
- `, r = o.querySelector("#ago-dev-state"), d = o.querySelector("#ago-dev-log"), o.querySelector(".dev-toggle")?.addEventListener("click", (n) => {
38
- n.stopPropagation(), s(o, !o.classList.contains("collapsed"));
39
- }), o.addEventListener("click", () => {
40
- o.classList.contains("collapsed") && s(o, !1);
37
+ `, c = t.querySelector("#ago-dev-state"), d = t.querySelector("#ago-dev-log"), t.querySelector(".dev-toggle")?.addEventListener("click", (a) => {
38
+ a.stopPropagation(), r(t, !t.classList.contains("collapsed"));
39
+ }), t.addEventListener("click", () => {
40
+ t.classList.contains("collapsed") && r(t, !1);
41
41
  });
42
- let c = !1;
42
+ let p = !1;
43
43
  try {
44
- c = localStorage.getItem(u) === "1";
44
+ p = localStorage.getItem(x) === "1";
45
45
  } catch {
46
46
  }
47
- s(o, c), e.on("function:invoke", ({ functionName: n, arguments: l }) => {
48
- g(`→ ${n}(${JSON.stringify(l ?? {})})`, "invoke");
49
- }), e.on("function:result", ({ result: n, error: l }) => {
50
- g(l ? `✗ error: ${l}` : `← ${JSON.stringify(n)}`, l ? "error" : "result");
51
- }), a.subscribe(p), p();
47
+ r(t, p), e.on("function:invoke", ({ functionName: a, arguments: n }) => {
48
+ s(`→ ${a}(${JSON.stringify(n ?? {})})`, "invoke");
49
+ }), e.on("function:result", ({ result: a, error: n }) => {
50
+ s(n ? `✗ error: ${n}` : `← ${JSON.stringify(a)}`, n ? "error" : "result"), i();
51
+ }), e.on("context:changed", i), e.on("conversation:loaded", (a) => {
52
+ const n = (a.messages ?? []).flatMap((u) => u.toolCalls ?? []);
53
+ s(`⟳ hydrated "${a.title || a.id}" — replayed ${n.length} tool call${n.length === 1 ? "" : "s"}`, "hydrate"), i();
54
+ }), i();
52
55
  }
53
- var v = "ago-dev-panel-styles";
54
- function b() {
55
- if (document.getElementById(v)) return;
56
- const t = document.createElement("style");
57
- t.id = v, t.textContent = h, document.head.appendChild(t);
56
+ var g = "ago-dev-panel-styles";
57
+ function h() {
58
+ if (document.getElementById(g)) return;
59
+ const l = document.createElement("style");
60
+ l.id = g, l.textContent = b, document.head.appendChild(l);
58
61
  }
59
- var h = `
62
+ var b = `
60
63
  #ago-dev-panel {
61
64
  position: fixed;
62
65
  top: 16px;
@@ -150,6 +153,7 @@ var h = `
150
153
  #ago-dev-panel .dev-log-invoke { color: #9ecbff; }
151
154
  #ago-dev-panel .dev-log-result { color: #86efac; }
152
155
  #ago-dev-panel .dev-log-error { color: #fca5a5; }
156
+ #ago-dev-panel .dev-log-hydrate { color: #d8b4fe; }
153
157
  `;
154
158
  export {
155
159
  m as initDevPanel
package/dist/helpers.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./functions-BH1X5kas.cjs");exports.copyToClipboard=o.copyToClipboard;exports.getLocalStorage=o.getLocalStorage;exports.getUserLocation=o.getUserLocation;exports.highlightElement=o.highlightElement;exports.openUrl=o.openUrl;exports.scrollToElement=o.scrollToElement;exports.setLocalStorage=o.setLocalStorage;exports.setTheme=o.setTheme;exports.showConfirmDialog=o.showConfirmDialog;exports.showNotification=o.showNotification;exports.showToast=o.showToast;exports.submitForm=o.submitForm;exports.trackEvent=o.trackEvent;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./functions-DsmzgHjC.cjs");exports.copyToClipboard=o.copyToClipboard;exports.getLocalStorage=o.getLocalStorage;exports.getUserLocation=o.getUserLocation;exports.highlightElement=o.highlightElement;exports.openUrl=o.openUrl;exports.scrollToElement=o.scrollToElement;exports.setLocalStorage=o.setLocalStorage;exports.setTheme=o.setTheme;exports.showConfirmDialog=o.showConfirmDialog;exports.showNotification=o.showNotification;exports.showToast=o.showToast;exports.submitForm=o.submitForm;exports.trackEvent=o.trackEvent;
package/dist/helpers.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a, c as s, d as t, f as e, i as r, l as i, m as l, o as m, p as c, r as g, s as h, t as n, u as p } from "./functions-CWSRi3xv.js";
1
+ import { a, c as s, d as t, f as e, i as r, l as i, m as l, o as m, p as c, r as g, s as h, t as n, u as p } from "./functions-C1-5vadY.js";
2
2
  export {
3
3
  n as copyToClipboard,
4
4
  g as getLocalStorage,
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./AgoClient-bjN-z2ZQ.cjs"),p=require("./createFormCollector-H4Me_2uj.cjs"),A=require("./createMockClient-DQvFFWnc.cjs"),g=require("./functions-BH1X5kas.cjs");function h(e){return e}function C(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function E(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 S(e,o){return e.on("message:error",o),()=>e.off("message:error",o)}function b(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function M(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*k(e,o,l){const n=[];let r=null,a=!1;const c=s=>{n.push(s),r?.()},f=s=>c({type:"start",data:s}),t=s=>c({type:"chunk",data:s}),u=s=>{c({type:"complete",data:s}),a=!0,r?.()},m=s=>{c({type:"error",data:s}),a=!0,r?.()},d=s=>c({type:"toolCall",data:s});e.on("message:start",f),e.on("message:chunk",t),e.on("message:complete",u),e.on("message:error",m),e.on("toolCall:received",d),e.sendMessage(o,l).catch(()=>{a=!0,r?.()});try{for(;!a||n.length>0;)n.length>0?yield n.shift():(await new Promise(s=>{r=s}),r=null)}finally{e.off("message:start",f),e.off("message:chunk",t),e.off("message:complete",u),e.off("message:error",m),e.off("toolCall:received",d)}}function w(e){let o,l,n,r,a,c;if(typeof window<"u"&&window.AGO){const t=window.AGO;o=t.basepath,l=t.widgetId,n=t.agent||t.defaultAgent,r=t.permission,a=t.email,c=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"),n=n||t("ago-agent")||t("ago-agent-id"),r=r||t("ago-permission"),a=a||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,n=n||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,r=r||u.getAttribute("data-ago-permission")||void 0,a=a||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,n=e?.agent||e?.defaultAgentId||n,r=e?.permission||r,a=e?.userEmail||a,c=e?.userJwt||c;const f=e?.debug;return o?{baseUrl:o,widgetId:l,agent:n,permission:r,userEmail:a,userJwt:c,debug:f}:null}function v(e){const o=w(e);if(!o)throw new Error('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.');return new i.AgoClient(o)}function F(e,o){return{...e,handler:o}}exports.AgoApiError=i.AgoApiError;exports.AgoClient=i.AgoClient;exports.AgoError=i.AgoError;exports.AgoFunctionError=i.AgoFunctionError;exports.AgoNetworkError=i.AgoNetworkError;exports.AgoStreamError=i.AgoStreamError;exports.ClientContextRegistry=i.ClientContextRegistry;exports.EventEmitter=i.EventEmitter;exports.FunctionRegistry=i.FunctionRegistry;exports.SSEHandler=i.SSEHandler;exports.autoDetectConfig=w;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=v;exports.createFormCollector=p.createFormCollector;exports.createMessageStream=k;exports.createMockClient=A.createMockClient;exports.createStore=p.createStore;exports.defineFunction=h;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=i.isStreamNetworkError;exports.logger=i.logger;exports.onFunctionInvoke=M;exports.onMessage=C;exports.onMessageChunk=E;exports.onMessageError=S;exports.onMessageStart=y;exports.onToolCall=b;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.withHandler=F;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./AgoClient-D4EL6nva.cjs"),p=require("./createFormCollector-Wb8Rr-U2.cjs"),A=require("./createConversationSession-DtaeA418.cjs"),C=require("./createMockClient-zHQ0cjUH.cjs"),g=require("./functions-DsmzgHjC.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 v(e,o){return e.on("toolCall:received",o),()=>e.off("toolCall:received",o)}function M(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*k(e,o,l){const n=[];let r=null,a=!1;const c=s=>{n.push(s),r?.()},f=s=>c({type:"start",data:s}),t=s=>c({type:"chunk",data:s}),u=s=>{c({type:"complete",data:s}),a=!0,r?.()},m=s=>{c({type:"error",data:s}),a=!0,r?.()},d=s=>c({type:"toolCall",data:s});e.on("message:start",f),e.on("message:chunk",t),e.on("message:complete",u),e.on("message:error",m),e.on("toolCall:received",d),e.sendMessage(o,l).catch(()=>{a=!0,r?.()});try{for(;!a||n.length>0;)n.length>0?yield n.shift():(await new Promise(s=>{r=s}),r=null)}finally{e.off("message:start",f),e.off("message:chunk",t),e.off("message:complete",u),e.off("message:error",m),e.off("toolCall:received",d)}}function w(e){let o,l,n,r,a,c;if(typeof window<"u"&&window.AGO){const t=window.AGO;o=t.basepath,l=t.widgetId,n=t.agent||t.defaultAgent,r=t.permission,a=t.email,c=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"),n=n||t("ago-agent")||t("ago-agent-id"),r=r||t("ago-permission"),a=a||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,n=n||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,r=r||u.getAttribute("data-ago-permission")||void 0,a=a||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,n=e?.agent||e?.defaultAgentId||n,r=e?.permission||r,a=e?.userEmail||a,c=e?.userJwt||c;const f=e?.debug;return o?{baseUrl:o,widgetId:l,agent:n,permission:r,userEmail:a,userJwt:c,debug:f}:null}function q(e){const o=w(e);if(!o)throw new Error('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.');return new i.AgoClient(o)}function F(e,o){return{...e,handler:o}}exports.AgoApiError=i.AgoApiError;exports.AgoClient=i.AgoClient;exports.AgoError=i.AgoError;exports.AgoFunctionError=i.AgoFunctionError;exports.AgoNetworkError=i.AgoNetworkError;exports.AgoStreamError=i.AgoStreamError;exports.ClientContextRegistry=i.ClientContextRegistry;exports.EventEmitter=i.EventEmitter;exports.FunctionRegistry=i.FunctionRegistry;exports.SSEHandler=i.SSEHandler;exports.autoDetectConfig=w;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=q;exports.createConversationSession=A.createConversationSession;exports.createFormCollector=p.createFormCollector;exports.createMessageStream=k;exports.createMockClient=C.createMockClient;exports.createStore=p.createStore;exports.defineFunction=h;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=i.isStreamNetworkError;exports.logger=i.logger;exports.onFunctionInvoke=M;exports.onMessage=E;exports.onMessageChunk=S;exports.onMessageError=b;exports.onMessageStart=y;exports.onToolCall=v;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.withHandler=F;
package/dist/index.d.cts CHANGED
@@ -42,6 +42,12 @@ export declare class AgoClient {
42
42
  * Get a specific conversation with messages
43
43
  */
44
44
  getConversation(conversationId: string): Promise<Conversation>;
45
+ /**
46
+ * Map the backend's snake_case `tool_call_data` entries onto the camelCase
47
+ * {@link ToolCallData} shape used everywhere else in the SDK. Mirrors
48
+ * `SSEHandler.parseToolCall` so persisted and streamed tool calls match.
49
+ */
50
+ private static mapPersistedToolCalls;
45
51
  /**
46
52
  * Get messages for a conversation
47
53
  */
@@ -152,6 +158,13 @@ export declare class AgoClient {
152
158
  * Remove a dynamic context provider.
153
159
  */
154
160
  removeDynamicContext(key: string): boolean;
161
+ /**
162
+ * Broadcast that the client-side context changed by emitting `context:changed`
163
+ * with the fresh snapshot. The context-mutating methods call this automatically;
164
+ * stateful helpers whose context lives in a store (e.g. `createFormCollector`)
165
+ * call it when their store updates so observers like the dev panel stay live.
166
+ */
167
+ notifyContextChanged(): void;
155
168
  /**
156
169
  * Enable automatic capture of the current browser page (URL + title).
157
170
  * Injected as a dynamic context entry named `browser-page`.
@@ -197,6 +210,14 @@ export declare class AgoClient {
197
210
  * SDK Events
198
211
  */
199
212
  export declare interface AgoClientEvents {
213
+ /**
214
+ * The client-side context changed: a context entry or dynamic provider was
215
+ * added/removed, or a stateful helper (e.g. `createFormCollector`) updated its
216
+ * store. Carries the fresh snapshot so observers — notably the dev panel — can
217
+ * repaint without waiting for the next message. Fires for the form collector's
218
+ * initial install too, so its missing fields show from the start of a conversation.
219
+ */
220
+ "context:changed": ContextSnapshot | null;
200
221
  "message:start": {
201
222
  conversationId: string;
202
223
  messageId: string;
@@ -212,6 +233,12 @@ export declare interface AgoClientEvents {
212
233
  conversationId?: string;
213
234
  messageId?: string;
214
235
  };
236
+ /**
237
+ * A full conversation was loaded from the server (e.g. after a page reload).
238
+ * Carries the messages and their persisted tool calls so stateful helpers —
239
+ * notably `createFormCollector` — can replay them to restore their state.
240
+ */
241
+ "conversation:loaded": Conversation;
215
242
  "toolCall:received": ToolCallData;
216
243
  "toolCall:form": ToolCallData;
217
244
  "function:invoke": ClientFunctionInvocation;
@@ -498,6 +525,60 @@ export declare interface Conversation {
498
525
  messages?: AgoMessage[];
499
526
  }
500
527
 
528
+ export declare interface ConversationSession {
529
+ /**
530
+ * The stable widget id identifying this visitor. Generated once and persisted
531
+ * forever, so a returning visitor keeps the same id (and therefore the same
532
+ * server-side conversation history) across reloads.
533
+ */
534
+ readonly widgetId: string;
535
+ /**
536
+ * The last active thread id, decided **entirely on the front** so a reload costs
537
+ * no backend round-trip. Returns `null` when there is no cached thread, when its
538
+ * last message time is unknown, or when it has been idle longer than `ttlMs`.
539
+ */
540
+ getLastActiveThread(): string | null;
541
+ /**
542
+ * Record (and refresh) the active thread together with the time of its last
543
+ * message — call it once per turn. The `lastMessageAt` drives the sliding TTL;
544
+ * omit it and the thread won't be resumed (no time → not displayed).
545
+ */
546
+ setActiveThread(conversationId: string, lastMessageAt?: Date | number): void;
547
+ /** Forget the cached thread — e.g. on "new chat". */
548
+ clear(): void;
549
+ /** The resolved storage key holding the widget id — handy for debugging. */
550
+ readonly key: string;
551
+ }
552
+
553
+ export declare interface ConversationSessionOptions {
554
+ /**
555
+ * Storage backend. Defaults to `localStorage`, degrading to an in-memory store
556
+ * when storage is unavailable (SSR / disabled). Pass `sessionStorage` for a
557
+ * tab-scoped session, or any `{ getItem, setItem }` for a custom backend.
558
+ */
559
+ storage?: StorageLike;
560
+ /**
561
+ * Storage key for the widget id. Default `"ago_widget_id"` — the same key the
562
+ * HTTP client reads, so the visitor's id is shared across the SDK.
563
+ */
564
+ key?: string;
565
+ /**
566
+ * Explicit widget id to adopt (and persist) instead of reading or generating
567
+ * one — e.g. when the host app already has a stable visitor identifier.
568
+ */
569
+ widgetId?: string;
570
+ /** Storage key for the cached last active thread. Default `"ago_last_thread"`. */
571
+ threadKey?: string;
572
+ /**
573
+ * Maximum idle age of a thread to still resume it, in milliseconds, compared
574
+ * against the recorded time of its last message. Checked entirely on the front
575
+ * (no backend call): a thread idle longer than this — or one with no recorded
576
+ * last-message time — is not resumed (`getLastActiveThread` returns `null`).
577
+ * Default 2h. Pass `Infinity` to never expire.
578
+ */
579
+ ttlMs?: number;
580
+ }
581
+
501
582
  /**
502
583
  * Copy text to clipboard.
503
584
  */
@@ -529,6 +610,33 @@ export declare const copyToClipboard: ClientFunctionDefinition;
529
610
  */
530
611
  export declare function createAgo(overrides?: Partial<AgoConfig>): AgoClient;
531
612
 
613
+ /**
614
+ * Identify a returning visitor with a single, stable widget id — the same model as
615
+ * the frontend's `getOrGenerateWidgetId` — and resume their last active thread.
616
+ *
617
+ * There is no per-agent conversation id: the widget id is the identity, and the last
618
+ * active thread (its id + the time of its last message) is cached locally so resuming
619
+ * is a pure front-side decision — **no backend call** just to know whether the thread
620
+ * is still fresh. A thread idle longer than `ttlMs` (default 2h, sliding — refreshed
621
+ * by `setActiveThread`), or one with no recorded last-message time, is not resumed.
622
+ *
623
+ * ```ts
624
+ * const session = createConversationSession();
625
+ *
626
+ * // resume on load (front-only — no request):
627
+ * const conversationId = session.getLastActiveThread() ?? undefined;
628
+ *
629
+ * // record the thread once a turn completes:
630
+ * session.setActiveThread(reply.conversationId, reply.createdAt);
631
+ *
632
+ * session.clear(); // forget it — e.g. a "new chat" button
633
+ * ```
634
+ *
635
+ * Persistence is opt-in by storage backend: it defaults to `localStorage`, but pass
636
+ * `sessionStorage` for a tab-scoped session or omit storage in environments without it.
637
+ */
638
+ export declare function createConversationSession(options?: ConversationSessionOptions): ConversationSession;
639
+
532
640
  /**
533
641
  * Wire one schema into a conversational form: an observable store, an
534
642
  * `update_<name>` client function the agent calls to fill fields, a dynamic-context
@@ -675,6 +783,14 @@ export declare interface FormCollector<V = Record<string, unknown>> {
675
783
  contextProvider: () => ContextEntry;
676
784
  /** Register the functions + dynamic context on a client. Returns an uninstall fn. */
677
785
  install: (client: AgoClient) => () => void;
786
+ /**
787
+ * Rebuild the state by replaying the persisted `update_<name>` / `submit_<name>`
788
+ * tool-call arguments of a loaded conversation — restoring what the agent had
789
+ * collected after a page reload. Replays from the initial values, so it is
790
+ * idempotent. `install` wires this to the client's `conversation:loaded` event,
791
+ * so a custom front rarely needs to call it directly.
792
+ */
793
+ hydrate: (toolCalls: readonly ToolCallData[]) => void;
678
794
  /** Submit the form now (e.g. from a UI button). Blocks until required fields are filled. */
679
795
  submit: () => Promise<FormSubmitResult>;
680
796
  getValues: () => Partial<V>;
@@ -1054,7 +1170,7 @@ declare interface SSEHandlerCallbacks {
1054
1170
  }
1055
1171
 
1056
1172
  /** The slice of the Web Storage API that {@link createStore} relies on. */
1057
- declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1173
+ export declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1058
1174
 
1059
1175
  /**
1060
1176
  * A minimal observable store: one value, synchronous subscriptions, and
package/dist/index.d.ts CHANGED
@@ -42,6 +42,12 @@ export declare class AgoClient {
42
42
  * Get a specific conversation with messages
43
43
  */
44
44
  getConversation(conversationId: string): Promise<Conversation>;
45
+ /**
46
+ * Map the backend's snake_case `tool_call_data` entries onto the camelCase
47
+ * {@link ToolCallData} shape used everywhere else in the SDK. Mirrors
48
+ * `SSEHandler.parseToolCall` so persisted and streamed tool calls match.
49
+ */
50
+ private static mapPersistedToolCalls;
45
51
  /**
46
52
  * Get messages for a conversation
47
53
  */
@@ -152,6 +158,13 @@ export declare class AgoClient {
152
158
  * Remove a dynamic context provider.
153
159
  */
154
160
  removeDynamicContext(key: string): boolean;
161
+ /**
162
+ * Broadcast that the client-side context changed by emitting `context:changed`
163
+ * with the fresh snapshot. The context-mutating methods call this automatically;
164
+ * stateful helpers whose context lives in a store (e.g. `createFormCollector`)
165
+ * call it when their store updates so observers like the dev panel stay live.
166
+ */
167
+ notifyContextChanged(): void;
155
168
  /**
156
169
  * Enable automatic capture of the current browser page (URL + title).
157
170
  * Injected as a dynamic context entry named `browser-page`.
@@ -197,6 +210,14 @@ export declare class AgoClient {
197
210
  * SDK Events
198
211
  */
199
212
  export declare interface AgoClientEvents {
213
+ /**
214
+ * The client-side context changed: a context entry or dynamic provider was
215
+ * added/removed, or a stateful helper (e.g. `createFormCollector`) updated its
216
+ * store. Carries the fresh snapshot so observers — notably the dev panel — can
217
+ * repaint without waiting for the next message. Fires for the form collector's
218
+ * initial install too, so its missing fields show from the start of a conversation.
219
+ */
220
+ "context:changed": ContextSnapshot | null;
200
221
  "message:start": {
201
222
  conversationId: string;
202
223
  messageId: string;
@@ -212,6 +233,12 @@ export declare interface AgoClientEvents {
212
233
  conversationId?: string;
213
234
  messageId?: string;
214
235
  };
236
+ /**
237
+ * A full conversation was loaded from the server (e.g. after a page reload).
238
+ * Carries the messages and their persisted tool calls so stateful helpers —
239
+ * notably `createFormCollector` — can replay them to restore their state.
240
+ */
241
+ "conversation:loaded": Conversation;
215
242
  "toolCall:received": ToolCallData;
216
243
  "toolCall:form": ToolCallData;
217
244
  "function:invoke": ClientFunctionInvocation;
@@ -498,6 +525,60 @@ export declare interface Conversation {
498
525
  messages?: AgoMessage[];
499
526
  }
500
527
 
528
+ export declare interface ConversationSession {
529
+ /**
530
+ * The stable widget id identifying this visitor. Generated once and persisted
531
+ * forever, so a returning visitor keeps the same id (and therefore the same
532
+ * server-side conversation history) across reloads.
533
+ */
534
+ readonly widgetId: string;
535
+ /**
536
+ * The last active thread id, decided **entirely on the front** so a reload costs
537
+ * no backend round-trip. Returns `null` when there is no cached thread, when its
538
+ * last message time is unknown, or when it has been idle longer than `ttlMs`.
539
+ */
540
+ getLastActiveThread(): string | null;
541
+ /**
542
+ * Record (and refresh) the active thread together with the time of its last
543
+ * message — call it once per turn. The `lastMessageAt` drives the sliding TTL;
544
+ * omit it and the thread won't be resumed (no time → not displayed).
545
+ */
546
+ setActiveThread(conversationId: string, lastMessageAt?: Date | number): void;
547
+ /** Forget the cached thread — e.g. on "new chat". */
548
+ clear(): void;
549
+ /** The resolved storage key holding the widget id — handy for debugging. */
550
+ readonly key: string;
551
+ }
552
+
553
+ export declare interface ConversationSessionOptions {
554
+ /**
555
+ * Storage backend. Defaults to `localStorage`, degrading to an in-memory store
556
+ * when storage is unavailable (SSR / disabled). Pass `sessionStorage` for a
557
+ * tab-scoped session, or any `{ getItem, setItem }` for a custom backend.
558
+ */
559
+ storage?: StorageLike;
560
+ /**
561
+ * Storage key for the widget id. Default `"ago_widget_id"` — the same key the
562
+ * HTTP client reads, so the visitor's id is shared across the SDK.
563
+ */
564
+ key?: string;
565
+ /**
566
+ * Explicit widget id to adopt (and persist) instead of reading or generating
567
+ * one — e.g. when the host app already has a stable visitor identifier.
568
+ */
569
+ widgetId?: string;
570
+ /** Storage key for the cached last active thread. Default `"ago_last_thread"`. */
571
+ threadKey?: string;
572
+ /**
573
+ * Maximum idle age of a thread to still resume it, in milliseconds, compared
574
+ * against the recorded time of its last message. Checked entirely on the front
575
+ * (no backend call): a thread idle longer than this — or one with no recorded
576
+ * last-message time — is not resumed (`getLastActiveThread` returns `null`).
577
+ * Default 2h. Pass `Infinity` to never expire.
578
+ */
579
+ ttlMs?: number;
580
+ }
581
+
501
582
  /**
502
583
  * Copy text to clipboard.
503
584
  */
@@ -529,6 +610,33 @@ export declare const copyToClipboard: ClientFunctionDefinition;
529
610
  */
530
611
  export declare function createAgo(overrides?: Partial<AgoConfig>): AgoClient;
531
612
 
613
+ /**
614
+ * Identify a returning visitor with a single, stable widget id — the same model as
615
+ * the frontend's `getOrGenerateWidgetId` — and resume their last active thread.
616
+ *
617
+ * There is no per-agent conversation id: the widget id is the identity, and the last
618
+ * active thread (its id + the time of its last message) is cached locally so resuming
619
+ * is a pure front-side decision — **no backend call** just to know whether the thread
620
+ * is still fresh. A thread idle longer than `ttlMs` (default 2h, sliding — refreshed
621
+ * by `setActiveThread`), or one with no recorded last-message time, is not resumed.
622
+ *
623
+ * ```ts
624
+ * const session = createConversationSession();
625
+ *
626
+ * // resume on load (front-only — no request):
627
+ * const conversationId = session.getLastActiveThread() ?? undefined;
628
+ *
629
+ * // record the thread once a turn completes:
630
+ * session.setActiveThread(reply.conversationId, reply.createdAt);
631
+ *
632
+ * session.clear(); // forget it — e.g. a "new chat" button
633
+ * ```
634
+ *
635
+ * Persistence is opt-in by storage backend: it defaults to `localStorage`, but pass
636
+ * `sessionStorage` for a tab-scoped session or omit storage in environments without it.
637
+ */
638
+ export declare function createConversationSession(options?: ConversationSessionOptions): ConversationSession;
639
+
532
640
  /**
533
641
  * Wire one schema into a conversational form: an observable store, an
534
642
  * `update_<name>` client function the agent calls to fill fields, a dynamic-context
@@ -675,6 +783,14 @@ export declare interface FormCollector<V = Record<string, unknown>> {
675
783
  contextProvider: () => ContextEntry;
676
784
  /** Register the functions + dynamic context on a client. Returns an uninstall fn. */
677
785
  install: (client: AgoClient) => () => void;
786
+ /**
787
+ * Rebuild the state by replaying the persisted `update_<name>` / `submit_<name>`
788
+ * tool-call arguments of a loaded conversation — restoring what the agent had
789
+ * collected after a page reload. Replays from the initial values, so it is
790
+ * idempotent. `install` wires this to the client's `conversation:loaded` event,
791
+ * so a custom front rarely needs to call it directly.
792
+ */
793
+ hydrate: (toolCalls: readonly ToolCallData[]) => void;
678
794
  /** Submit the form now (e.g. from a UI button). Blocks until required fields are filled. */
679
795
  submit: () => Promise<FormSubmitResult>;
680
796
  getValues: () => Partial<V>;
@@ -1054,7 +1170,7 @@ declare interface SSEHandlerCallbacks {
1054
1170
  }
1055
1171
 
1056
1172
  /** The slice of the Web Storage API that {@link createStore} relies on. */
1057
- declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1173
+ export declare type StorageLike = Pick<Storage, "getItem" | "setItem">;
1058
1174
 
1059
1175
  /**
1060
1176
  * A minimal observable store: one value, synchronous subscriptions, and