@useago/sdk 1.0.0 → 1.0.1

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.
package/dist/index.d.cts CHANGED
@@ -64,6 +64,13 @@ export declare class AgoClient {
64
64
  * Reject a tool call
65
65
  */
66
66
  rejectToolCall(toolCallId: string): Promise<void>;
67
+ /**
68
+ * Fetch a backend-stored form collector definition by name (the single source
69
+ * of truth for the form's description, schema, and submit target). Used by
70
+ * `loadFormCollector` / the name-only form of `useFormCollector` so the schema
71
+ * lives in the backend instead of being hardcoded in client code.
72
+ */
73
+ getFormCollector(name: string): Promise<FormCollectorDefinition>;
67
74
  /**
68
75
  * Relay a completed form collector's values to a server-configured destination.
69
76
  *
@@ -814,6 +821,22 @@ export declare interface FormCollector<V = Record<string, unknown>> {
814
821
  getValues: () => Partial<V>;
815
822
  setValues: (patch: Partial<V>) => void;
816
823
  reset: () => void;
824
+ /** Completeness status (`missing`/`complete`) derived from the current values + schema. */
825
+ getStatus: () => FormCollectorStatus;
826
+ }
827
+
828
+ /**
829
+ * The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
830
+ * {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
831
+ * {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
832
+ * `handler` variant (a function can't be stored server-side).
833
+ */
834
+ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
835
+ name: string;
836
+ description: string;
837
+ schema: FormCollectorSchema;
838
+ /** Server-stored submit target, if any. Absent means collect-only. */
839
+ submit?: SubmitConfig<V>;
817
840
  }
818
841
 
819
842
  /**
@@ -988,6 +1011,30 @@ export declare const highlightElement: ClientFunctionDefinition;
988
1011
  */
989
1012
  export declare function isStreamNetworkError(error: Error): boolean;
990
1013
 
1014
+ /**
1015
+ * Async sibling of {@link createFormCollector} that pulls the form's definition
1016
+ * (description + schema + submit target) from the backend by name — the single
1017
+ * source of truth — instead of hardcoding it in client code. Any field passed in
1018
+ * `options` overrides the fetched one (e.g. a client-only `submit` handler or
1019
+ * `initialValues`).
1020
+ *
1021
+ * ```ts
1022
+ * const order = await loadFormCollector(client, { name: "order" });
1023
+ * order.install(client);
1024
+ * ```
1025
+ */
1026
+ export declare function loadFormCollector<V = Record<string, unknown>>(client: Pick<AgoClient, "getFormCollector">, options: LoadFormCollectorOptions<V>): Promise<FormCollector<V>>;
1027
+
1028
+ /**
1029
+ * Options for {@link loadFormCollector} / the name-only form of `useFormCollector`:
1030
+ * the `name` is required and the definition is fetched from the backend, while any
1031
+ * field here overrides the fetched one — notably a client-only `submit` handler,
1032
+ * which can't be stored server-side.
1033
+ */
1034
+ export declare interface LoadFormCollectorOptions<V = Record<string, unknown>> extends Partial<Omit<CreateFormCollectorOptions<V>, "name">> {
1035
+ name: string;
1036
+ }
1037
+
991
1038
  /**
992
1039
  * Debug logger for SDK
993
1040
  */
package/dist/index.d.ts CHANGED
@@ -64,6 +64,13 @@ export declare class AgoClient {
64
64
  * Reject a tool call
65
65
  */
66
66
  rejectToolCall(toolCallId: string): Promise<void>;
67
+ /**
68
+ * Fetch a backend-stored form collector definition by name (the single source
69
+ * of truth for the form's description, schema, and submit target). Used by
70
+ * `loadFormCollector` / the name-only form of `useFormCollector` so the schema
71
+ * lives in the backend instead of being hardcoded in client code.
72
+ */
73
+ getFormCollector(name: string): Promise<FormCollectorDefinition>;
67
74
  /**
68
75
  * Relay a completed form collector's values to a server-configured destination.
69
76
  *
@@ -814,6 +821,22 @@ export declare interface FormCollector<V = Record<string, unknown>> {
814
821
  getValues: () => Partial<V>;
815
822
  setValues: (patch: Partial<V>) => void;
816
823
  reset: () => void;
824
+ /** Completeness status (`missing`/`complete`) derived from the current values + schema. */
825
+ getStatus: () => FormCollectorStatus;
826
+ }
827
+
828
+ /**
829
+ * The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
830
+ * {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
831
+ * {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
832
+ * `handler` variant (a function can't be stored server-side).
833
+ */
834
+ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
835
+ name: string;
836
+ description: string;
837
+ schema: FormCollectorSchema;
838
+ /** Server-stored submit target, if any. Absent means collect-only. */
839
+ submit?: SubmitConfig<V>;
817
840
  }
818
841
 
819
842
  /**
@@ -988,6 +1011,30 @@ export declare const highlightElement: ClientFunctionDefinition;
988
1011
  */
989
1012
  export declare function isStreamNetworkError(error: Error): boolean;
990
1013
 
1014
+ /**
1015
+ * Async sibling of {@link createFormCollector} that pulls the form's definition
1016
+ * (description + schema + submit target) from the backend by name — the single
1017
+ * source of truth — instead of hardcoding it in client code. Any field passed in
1018
+ * `options` overrides the fetched one (e.g. a client-only `submit` handler or
1019
+ * `initialValues`).
1020
+ *
1021
+ * ```ts
1022
+ * const order = await loadFormCollector(client, { name: "order" });
1023
+ * order.install(client);
1024
+ * ```
1025
+ */
1026
+ export declare function loadFormCollector<V = Record<string, unknown>>(client: Pick<AgoClient, "getFormCollector">, options: LoadFormCollectorOptions<V>): Promise<FormCollector<V>>;
1027
+
1028
+ /**
1029
+ * Options for {@link loadFormCollector} / the name-only form of `useFormCollector`:
1030
+ * the `name` is required and the definition is fetched from the backend, while any
1031
+ * field here overrides the fetched one — notably a client-only `submit` handler,
1032
+ * which can't be stored server-side.
1033
+ */
1034
+ export declare interface LoadFormCollectorOptions<V = Record<string, unknown>> extends Partial<Omit<CreateFormCollectorOptions<V>, "name">> {
1035
+ name: string;
1036
+ }
1037
+
991
1038
  /**
992
1039
  * Debug logger for SDK
993
1040
  */
package/dist/index.js CHANGED
@@ -1,31 +1,31 @@
1
- import { a as w, c as h, d as A, f as y, i as C, l as E, n as S, o as b, r as v, s as k, t as d, u as M } from "./AgoClient-BrYhSO5M.js";
2
- import { n as T, r as I, t as U } from "./createFormCollector-CPS2phYq.js";
3
- import { t as O } from "./createConversationSession-Dmqd80DX.js";
4
- import { t as x } from "./createMockClient-DwdxNwEn.js";
1
+ import { a as w, c as h, d as A, f as y, i as C, l as E, n as S, o as b, r as v, s as k, t as d, u as F } from "./AgoClient-CZYNL25R.js";
2
+ import { i as T, n as I, r as U, t as G } from "./createFormCollector-Bk0DRhUf.js";
3
+ import { t as q } from "./createConversationSession-Bmqj2rSS.js";
4
+ import { t as L } from "./createMockClient-DwdxNwEn.js";
5
5
  import "./testing.js";
6
- import { a as D, c as H, d as J, f as R, i as j, l as B, m as P, o as $, p as z, r as K, s as Q, t as V, u as W } from "./functions-C1-5vadY.js";
7
- function X(e) {
6
+ import { a as H, c as J, d as R, f as j, i as B, l as P, m as $, o as z, p as K, r as Q, s as V, t as W, u as X } from "./functions-C1-5vadY.js";
7
+ function Y(e) {
8
8
  return e;
9
9
  }
10
- function Y(e, t) {
11
- return e.on("message:complete", t), () => e.off("message:complete", t);
10
+ function Z(e, o) {
11
+ return e.on("message:complete", o), () => e.off("message:complete", o);
12
12
  }
13
- function Z(e, t) {
14
- return e.on("message:chunk", t), () => e.off("message:chunk", t);
13
+ function _(e, o) {
14
+ return e.on("message:chunk", o), () => e.off("message:chunk", o);
15
15
  }
16
- function _(e, t) {
17
- return e.on("message:start", t), () => e.off("message:start", t);
16
+ function ee(e, o) {
17
+ return e.on("message:start", o), () => e.off("message:start", o);
18
18
  }
19
- function ee(e, t) {
20
- return e.on("message:error", t), () => e.off("message:error", t);
19
+ function oe(e, o) {
20
+ return e.on("message:error", o), () => e.off("message:error", o);
21
21
  }
22
- function te(e, t) {
23
- return e.on("toolCall:received", t), () => e.off("toolCall:received", t);
22
+ function te(e, o) {
23
+ return e.on("toolCall:received", o), () => e.off("toolCall:received", o);
24
24
  }
25
- function oe(e, t) {
26
- return e.on("function:invoke", t), () => e.off("function:invoke", t);
25
+ function re(e, o) {
26
+ return e.on("function:invoke", o), () => e.off("function:invoke", o);
27
27
  }
28
- async function* re(e, t, g) {
28
+ async function* ae(e, o, g) {
29
29
  const a = [];
30
30
  let r = null, n = !1;
31
31
  const u = (s) => {
@@ -33,7 +33,7 @@ async function* re(e, t, g) {
33
33
  }, f = (s) => u({
34
34
  type: "start",
35
35
  data: s
36
- }), o = (s) => u({
36
+ }), t = (s) => u({
37
37
  type: "chunk",
38
38
  data: s
39
39
  }), i = (s) => {
@@ -50,7 +50,7 @@ async function* re(e, t, g) {
50
50
  type: "toolCall",
51
51
  data: s
52
52
  });
53
- e.on("message:start", f), e.on("message:chunk", o), e.on("message:complete", i), e.on("message:error", m), e.on("toolCall:received", l), e.sendMessage(t, g).catch(() => {
53
+ e.on("message:start", f), e.on("message:chunk", t), e.on("message:complete", i), e.on("message:error", m), e.on("toolCall:received", l), e.sendMessage(o, g).catch(() => {
54
54
  n = !0, r?.();
55
55
  });
56
56
  try {
@@ -58,28 +58,28 @@ async function* re(e, t, g) {
58
58
  r = s;
59
59
  }), r = null);
60
60
  } finally {
61
- e.off("message:start", f), e.off("message:chunk", o), e.off("message:complete", i), e.off("message:error", m), e.off("toolCall:received", l);
61
+ e.off("message:start", f), e.off("message:chunk", t), e.off("message:complete", i), e.off("message:error", m), e.off("toolCall:received", l);
62
62
  }
63
63
  }
64
64
  function c(e) {
65
- let t, g, a, r, n, u;
65
+ let o, g, a, r, n, u;
66
66
  if (typeof window < "u" && window.AGO) {
67
- const o = window.AGO;
68
- t = o.basepath, g = o.widgetId, a = o.agent || o.defaultAgent, r = o.permission, n = o.email, u = o.jwt;
67
+ const t = window.AGO;
68
+ o = t.basepath, g = t.widgetId, a = t.agent || t.defaultAgent, r = t.permission, n = t.email, u = t.jwt;
69
69
  }
70
70
  if (typeof document < "u") {
71
- const o = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
72
- t = t || o("ago-base-url"), g = g || o("ago-widget-id"), a = a || o("ago-agent") || o("ago-agent-id"), r = r || o("ago-permission"), n = n || o("ago-user-email");
71
+ const t = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
72
+ o = o || t("ago-base-url"), g = g || t("ago-widget-id"), a = a || t("ago-agent") || t("ago-agent-id"), r = r || t("ago-permission"), n = n || t("ago-user-email");
73
73
  }
74
74
  if (typeof document < "u") {
75
- const o = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
76
- for (const i of o)
77
- i && (t = t || i.getAttribute("data-ago-base-url") || void 0, g = g || i.getAttribute("data-ago-widget-id") || void 0, a = a || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, r = r || i.getAttribute("data-ago-permission") || void 0, n = n || i.getAttribute("data-ago-user-email") || void 0);
75
+ const t = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
76
+ for (const i of t)
77
+ i && (o = o || i.getAttribute("data-ago-base-url") || void 0, g = g || i.getAttribute("data-ago-widget-id") || void 0, a = a || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, r = r || i.getAttribute("data-ago-permission") || void 0, n = n || i.getAttribute("data-ago-user-email") || void 0);
78
78
  }
79
- t = e?.baseUrl || t, g = e?.widgetId || g, a = e?.agent || e?.defaultAgentId || a, r = e?.permission || r, n = e?.userEmail || n, u = e?.userJwt || u;
79
+ o = e?.baseUrl || o, g = e?.widgetId || g, a = e?.agent || e?.defaultAgentId || a, r = e?.permission || r, n = e?.userEmail || n, u = e?.userJwt || u;
80
80
  const f = e?.debug;
81
- return t ? {
82
- baseUrl: t,
81
+ return o ? {
82
+ baseUrl: o,
83
83
  widgetId: g,
84
84
  agent: a,
85
85
  permission: r,
@@ -88,22 +88,22 @@ function c(e) {
88
88
  debug: f
89
89
  } : null;
90
90
  }
91
- function ae(e) {
92
- const t = c(e);
93
- if (!t) throw new Error('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.');
94
- return new d(t);
91
+ function ne(e) {
92
+ const o = c(e);
93
+ if (!o) throw new Error('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.');
94
+ return new d(o);
95
95
  }
96
- function ne(e, t) {
96
+ function se(e, o) {
97
97
  return {
98
98
  ...e,
99
- handler: t
99
+ handler: o
100
100
  };
101
101
  }
102
102
  export {
103
103
  h as AgoApiError,
104
104
  d as AgoClient,
105
105
  E as AgoError,
106
- M as AgoFunctionError,
106
+ F as AgoFunctionError,
107
107
  A as AgoNetworkError,
108
108
  y as AgoStreamError,
109
109
  w as ClientContextRegistry,
@@ -111,34 +111,35 @@ export {
111
111
  b as FunctionRegistry,
112
112
  v as SSEHandler,
113
113
  c as autoDetectConfig,
114
- V as copyToClipboard,
115
- ae as createAgo,
116
- O as createConversationSession,
117
- U as createFormCollector,
118
- re as createMessageStream,
119
- x as createMockClient,
120
- I as createStore,
121
- X as defineFunction,
122
- T as deriveFormStatus,
123
- K as getLocalStorage,
124
- j as getUserLocation,
125
- D as highlightElement,
114
+ W as copyToClipboard,
115
+ ne as createAgo,
116
+ q as createConversationSession,
117
+ G as createFormCollector,
118
+ ae as createMessageStream,
119
+ L as createMockClient,
120
+ T as createStore,
121
+ Y as defineFunction,
122
+ I as deriveFormStatus,
123
+ Q as getLocalStorage,
124
+ B as getUserLocation,
125
+ H as highlightElement,
126
126
  C as isStreamNetworkError,
127
+ U as loadFormCollector,
127
128
  k as logger,
128
- oe as onFunctionInvoke,
129
- Y as onMessage,
130
- Z as onMessageChunk,
131
- ee as onMessageError,
132
- _ as onMessageStart,
129
+ re as onFunctionInvoke,
130
+ Z as onMessage,
131
+ _ as onMessageChunk,
132
+ oe as onMessageError,
133
+ ee as onMessageStart,
133
134
  te as onToolCall,
134
- $ as openUrl,
135
- Q as scrollToElement,
136
- H as setLocalStorage,
137
- B as setTheme,
138
- W as showConfirmDialog,
139
- J as showNotification,
140
- R as showToast,
141
- z as submitForm,
142
- P as trackEvent,
143
- ne as withHandler
135
+ z as openUrl,
136
+ V as scrollToElement,
137
+ J as setLocalStorage,
138
+ P as setTheme,
139
+ X as showConfirmDialog,
140
+ R as showNotification,
141
+ j as showToast,
142
+ K as submitForm,
143
+ $ as trackEvent,
144
+ se as withHandler
144
145
  };