@useago/sdk 0.4.7 → 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/CHANGELOG.md +98 -0
- package/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.md +107 -70
- package/dist/{AgoClient-CPqPT5s6.cjs → AgoClient-0x2Du_62.cjs} +1 -1
- package/dist/{AgoClient-BrYhSO5M.js → AgoClient-CZYNL25R.js} +29 -20
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +89 -0
- package/dist/angular.d.ts +89 -0
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-CGRO0bs2.cjs → createConversationSession-BLZvXMmM.cjs} +1 -1
- package/dist/{createConversationSession-Dmqd80DX.js → createConversationSession-Bmqj2rSS.js} +1 -1
- package/dist/createFormCollector-Bk0DRhUf.js +257 -0
- package/dist/createFormCollector-Ca8wRrxc.cjs +1 -0
- package/dist/devtools.d.cts +89 -0
- package/dist/devtools.d.ts +89 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +70 -68
- package/dist/react.cjs +23 -23
- package/dist/react.d.cts +74 -23
- package/dist/react.d.ts +74 -23
- package/dist/react.js +2154 -2075
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +571 -0
- package/dist/testing.d.ts +571 -0
- package/dist/testing.js +4 -0
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +89 -0
- package/dist/vue.d.ts +89 -0
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +74 -5
- package/dist/widget.d.ts +74 -5
- package/dist/widget.js +410 -317
- package/package.json +30 -9
- package/dist/createFormCollector-CPS2phYq.js +0 -245
- package/dist/createFormCollector-DaWZsBsI.cjs +0 -1
package/dist/react.d.cts
CHANGED
|
@@ -55,6 +55,13 @@ declare class AgoClient {
|
|
|
55
55
|
* Reject a tool call
|
|
56
56
|
*/
|
|
57
57
|
rejectToolCall(toolCallId: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Fetch a backend-stored form collector definition by name (the single source
|
|
60
|
+
* of truth for the form's description, schema, and submit target). Used by
|
|
61
|
+
* `loadFormCollector` / the name-only form of `useFormCollector` so the schema
|
|
62
|
+
* lives in the backend instead of being hardcoded in client code.
|
|
63
|
+
*/
|
|
64
|
+
getFormCollector(name: string): Promise<FormCollectorDefinition>;
|
|
58
65
|
/**
|
|
59
66
|
* Relay a completed form collector's values to a server-configured destination.
|
|
60
67
|
*
|
|
@@ -395,10 +402,13 @@ export declare interface ChatWidgetProps {
|
|
|
395
402
|
showAgentName?: boolean;
|
|
396
403
|
/**
|
|
397
404
|
* Conversational forms the agent can fill and submit during the chat. Each
|
|
398
|
-
*
|
|
405
|
+
* entry is installed as a {@link createFormCollector} (its `update_<name>` /
|
|
399
406
|
* `submit_<name>` functions + dynamic context) for the lifetime of the widget.
|
|
407
|
+
*
|
|
408
|
+
* Pass a full config (with `schema`) to define it inline, or just `{ name }` to
|
|
409
|
+
* fetch the definition from the backend ({@link loadFormCollector}).
|
|
400
410
|
*/
|
|
401
|
-
forms?: CreateFormCollectorOptions
|
|
411
|
+
forms?: Array<CreateFormCollectorOptions | LoadFormCollectorOptions>;
|
|
402
412
|
/**
|
|
403
413
|
* How clicking a suggested follow-up reply behaves. Defaults to sending the
|
|
404
414
|
* reply as a new user message. Pass a handler to override, or `false` to
|
|
@@ -592,6 +602,22 @@ export declare interface FormCollector<V = Record<string, unknown>> {
|
|
|
592
602
|
getValues: () => Partial<V>;
|
|
593
603
|
setValues: (patch: Partial<V>) => void;
|
|
594
604
|
reset: () => void;
|
|
605
|
+
/** Completeness status (`missing`/`complete`) derived from the current values + schema. */
|
|
606
|
+
getStatus: () => FormCollectorStatus;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
|
|
611
|
+
* {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
|
|
612
|
+
* {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
|
|
613
|
+
* `handler` variant (a function can't be stored server-side).
|
|
614
|
+
*/
|
|
615
|
+
export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
616
|
+
name: string;
|
|
617
|
+
description: string;
|
|
618
|
+
schema: FormCollectorSchema;
|
|
619
|
+
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
620
|
+
submit?: SubmitConfig<V>;
|
|
595
621
|
}
|
|
596
622
|
|
|
597
623
|
/**
|
|
@@ -682,6 +708,30 @@ export declare interface FormSubmitResult {
|
|
|
682
708
|
error?: string;
|
|
683
709
|
}
|
|
684
710
|
|
|
711
|
+
/**
|
|
712
|
+
* Async sibling of {@link createFormCollector} that pulls the form's definition
|
|
713
|
+
* (description + schema + submit target) from the backend by name — the single
|
|
714
|
+
* source of truth — instead of hardcoding it in client code. Any field passed in
|
|
715
|
+
* `options` overrides the fetched one (e.g. a client-only `submit` handler or
|
|
716
|
+
* `initialValues`).
|
|
717
|
+
*
|
|
718
|
+
* ```ts
|
|
719
|
+
* const order = await loadFormCollector(client, { name: "order" });
|
|
720
|
+
* order.install(client);
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
export declare function loadFormCollector<V = Record<string, unknown>>(client: Pick<AgoClient, "getFormCollector">, options: LoadFormCollectorOptions<V>): Promise<FormCollector<V>>;
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Options for {@link loadFormCollector} / the name-only form of `useFormCollector`:
|
|
727
|
+
* the `name` is required and the definition is fetched from the backend, while any
|
|
728
|
+
* field here overrides the fetched one — notably a client-only `submit` handler,
|
|
729
|
+
* which can't be stored server-side.
|
|
730
|
+
*/
|
|
731
|
+
export declare interface LoadFormCollectorOptions<V = Record<string, unknown>> extends Partial<Omit<CreateFormCollectorOptions<V>, "name">> {
|
|
732
|
+
name: string;
|
|
733
|
+
}
|
|
734
|
+
|
|
685
735
|
/**
|
|
686
736
|
* Renders markdown content with GitHub-flavored markdown support
|
|
687
737
|
* (tables, task lists, strikethrough, autolinks) and inline-styled
|
|
@@ -1039,32 +1089,26 @@ export declare interface UseConversationResult {
|
|
|
1039
1089
|
* functions + dynamic context on mount, removes them on unmount, and returns the
|
|
1040
1090
|
* live store state.
|
|
1041
1091
|
*
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1092
|
+
* Two modes, by whether you pass a `schema`:
|
|
1093
|
+
*
|
|
1094
|
+
* - **Inline** — pass `{ name, description, schema, submit? }` and the collector is
|
|
1095
|
+
* built synchronously (recreated only when `name`, the schema, or the submit
|
|
1096
|
+
* target changes; keep them stable). `loading` is always `false`.
|
|
1097
|
+
* - **Backend** — pass `{ name }` (no `schema`) and the definition is fetched from
|
|
1098
|
+
* the backend ({@link loadFormCollector}) so the schema lives server-side, not in
|
|
1099
|
+
* client code. `loading` is `true` until it resolves; any field you do pass
|
|
1100
|
+
* overrides the fetched one (e.g. a client-only `submit` handler).
|
|
1045
1101
|
*
|
|
1046
1102
|
* ```tsx
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
* description: "The order the user wants to place",
|
|
1050
|
-
* schema: {
|
|
1051
|
-
* type: "object",
|
|
1052
|
-
* properties: { product: { type: "string" }, quantity: { type: "number" } },
|
|
1053
|
-
* required: ["product", "quantity"],
|
|
1054
|
-
* },
|
|
1055
|
-
* submit: { via: "backend", destination: "order_webhook" },
|
|
1056
|
-
* });
|
|
1103
|
+
* // Backend-defined form — schema lives in the backend:
|
|
1104
|
+
* const order = useFormCollector({ name: "order" });
|
|
1057
1105
|
*
|
|
1058
|
-
* return
|
|
1059
|
-
* <
|
|
1060
|
-
*
|
|
1061
|
-
* ? `Still need: ${order.state.missing.join(", ")}`
|
|
1062
|
-
* : "Ready to submit"}
|
|
1063
|
-
* </div>
|
|
1064
|
-
* );
|
|
1106
|
+
* return order.loading
|
|
1107
|
+
* ? <p>Loading…</p>
|
|
1108
|
+
* : <p>{order.state.missing.length ? `Still need: ${order.state.missing.join(", ")}` : "Ready"}</p>;
|
|
1065
1109
|
* ```
|
|
1066
1110
|
*/
|
|
1067
|
-
export declare function useFormCollector<V = Record<string, unknown>>(options: CreateFormCollectorOptions<V>): UseFormCollectorResult<V>;
|
|
1111
|
+
export declare function useFormCollector<V = Record<string, unknown>>(options: CreateFormCollectorOptions<V> | LoadFormCollectorOptions<V>): UseFormCollectorResult<V>;
|
|
1068
1112
|
|
|
1069
1113
|
export declare interface UseFormCollectorResult<V = Record<string, unknown>> extends FormCollector<V> {
|
|
1070
1114
|
/**
|
|
@@ -1072,6 +1116,13 @@ export declare interface UseFormCollectorResult<V = Record<string, unknown>> ext
|
|
|
1072
1116
|
* status (`missing`, `complete`) derived on read — re-renders on every change.
|
|
1073
1117
|
*/
|
|
1074
1118
|
state: FormCollectorState<V> & FormCollectorStatus;
|
|
1119
|
+
/**
|
|
1120
|
+
* True while the backend definition is being fetched (name-only usage). Always
|
|
1121
|
+
* `false` when an inline `schema` is provided.
|
|
1122
|
+
*/
|
|
1123
|
+
loading: boolean;
|
|
1124
|
+
/** Set if fetching the backend definition failed. */
|
|
1125
|
+
error: Error | null;
|
|
1075
1126
|
}
|
|
1076
1127
|
|
|
1077
1128
|
/**
|
package/dist/react.d.ts
CHANGED
|
@@ -55,6 +55,13 @@ declare class AgoClient {
|
|
|
55
55
|
* Reject a tool call
|
|
56
56
|
*/
|
|
57
57
|
rejectToolCall(toolCallId: string): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Fetch a backend-stored form collector definition by name (the single source
|
|
60
|
+
* of truth for the form's description, schema, and submit target). Used by
|
|
61
|
+
* `loadFormCollector` / the name-only form of `useFormCollector` so the schema
|
|
62
|
+
* lives in the backend instead of being hardcoded in client code.
|
|
63
|
+
*/
|
|
64
|
+
getFormCollector(name: string): Promise<FormCollectorDefinition>;
|
|
58
65
|
/**
|
|
59
66
|
* Relay a completed form collector's values to a server-configured destination.
|
|
60
67
|
*
|
|
@@ -395,10 +402,13 @@ export declare interface ChatWidgetProps {
|
|
|
395
402
|
showAgentName?: boolean;
|
|
396
403
|
/**
|
|
397
404
|
* Conversational forms the agent can fill and submit during the chat. Each
|
|
398
|
-
*
|
|
405
|
+
* entry is installed as a {@link createFormCollector} (its `update_<name>` /
|
|
399
406
|
* `submit_<name>` functions + dynamic context) for the lifetime of the widget.
|
|
407
|
+
*
|
|
408
|
+
* Pass a full config (with `schema`) to define it inline, or just `{ name }` to
|
|
409
|
+
* fetch the definition from the backend ({@link loadFormCollector}).
|
|
400
410
|
*/
|
|
401
|
-
forms?: CreateFormCollectorOptions
|
|
411
|
+
forms?: Array<CreateFormCollectorOptions | LoadFormCollectorOptions>;
|
|
402
412
|
/**
|
|
403
413
|
* How clicking a suggested follow-up reply behaves. Defaults to sending the
|
|
404
414
|
* reply as a new user message. Pass a handler to override, or `false` to
|
|
@@ -592,6 +602,22 @@ export declare interface FormCollector<V = Record<string, unknown>> {
|
|
|
592
602
|
getValues: () => Partial<V>;
|
|
593
603
|
setValues: (patch: Partial<V>) => void;
|
|
594
604
|
reset: () => void;
|
|
605
|
+
/** Completeness status (`missing`/`complete`) derived from the current values + schema. */
|
|
606
|
+
getStatus: () => FormCollectorStatus;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
|
|
611
|
+
* {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
|
|
612
|
+
* {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
|
|
613
|
+
* `handler` variant (a function can't be stored server-side).
|
|
614
|
+
*/
|
|
615
|
+
export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
616
|
+
name: string;
|
|
617
|
+
description: string;
|
|
618
|
+
schema: FormCollectorSchema;
|
|
619
|
+
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
620
|
+
submit?: SubmitConfig<V>;
|
|
595
621
|
}
|
|
596
622
|
|
|
597
623
|
/**
|
|
@@ -682,6 +708,30 @@ export declare interface FormSubmitResult {
|
|
|
682
708
|
error?: string;
|
|
683
709
|
}
|
|
684
710
|
|
|
711
|
+
/**
|
|
712
|
+
* Async sibling of {@link createFormCollector} that pulls the form's definition
|
|
713
|
+
* (description + schema + submit target) from the backend by name — the single
|
|
714
|
+
* source of truth — instead of hardcoding it in client code. Any field passed in
|
|
715
|
+
* `options` overrides the fetched one (e.g. a client-only `submit` handler or
|
|
716
|
+
* `initialValues`).
|
|
717
|
+
*
|
|
718
|
+
* ```ts
|
|
719
|
+
* const order = await loadFormCollector(client, { name: "order" });
|
|
720
|
+
* order.install(client);
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
export declare function loadFormCollector<V = Record<string, unknown>>(client: Pick<AgoClient, "getFormCollector">, options: LoadFormCollectorOptions<V>): Promise<FormCollector<V>>;
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Options for {@link loadFormCollector} / the name-only form of `useFormCollector`:
|
|
727
|
+
* the `name` is required and the definition is fetched from the backend, while any
|
|
728
|
+
* field here overrides the fetched one — notably a client-only `submit` handler,
|
|
729
|
+
* which can't be stored server-side.
|
|
730
|
+
*/
|
|
731
|
+
export declare interface LoadFormCollectorOptions<V = Record<string, unknown>> extends Partial<Omit<CreateFormCollectorOptions<V>, "name">> {
|
|
732
|
+
name: string;
|
|
733
|
+
}
|
|
734
|
+
|
|
685
735
|
/**
|
|
686
736
|
* Renders markdown content with GitHub-flavored markdown support
|
|
687
737
|
* (tables, task lists, strikethrough, autolinks) and inline-styled
|
|
@@ -1039,32 +1089,26 @@ export declare interface UseConversationResult {
|
|
|
1039
1089
|
* functions + dynamic context on mount, removes them on unmount, and returns the
|
|
1040
1090
|
* live store state.
|
|
1041
1091
|
*
|
|
1042
|
-
*
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1092
|
+
* Two modes, by whether you pass a `schema`:
|
|
1093
|
+
*
|
|
1094
|
+
* - **Inline** — pass `{ name, description, schema, submit? }` and the collector is
|
|
1095
|
+
* built synchronously (recreated only when `name`, the schema, or the submit
|
|
1096
|
+
* target changes; keep them stable). `loading` is always `false`.
|
|
1097
|
+
* - **Backend** — pass `{ name }` (no `schema`) and the definition is fetched from
|
|
1098
|
+
* the backend ({@link loadFormCollector}) so the schema lives server-side, not in
|
|
1099
|
+
* client code. `loading` is `true` until it resolves; any field you do pass
|
|
1100
|
+
* overrides the fetched one (e.g. a client-only `submit` handler).
|
|
1045
1101
|
*
|
|
1046
1102
|
* ```tsx
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
* description: "The order the user wants to place",
|
|
1050
|
-
* schema: {
|
|
1051
|
-
* type: "object",
|
|
1052
|
-
* properties: { product: { type: "string" }, quantity: { type: "number" } },
|
|
1053
|
-
* required: ["product", "quantity"],
|
|
1054
|
-
* },
|
|
1055
|
-
* submit: { via: "backend", destination: "order_webhook" },
|
|
1056
|
-
* });
|
|
1103
|
+
* // Backend-defined form — schema lives in the backend:
|
|
1104
|
+
* const order = useFormCollector({ name: "order" });
|
|
1057
1105
|
*
|
|
1058
|
-
* return
|
|
1059
|
-
* <
|
|
1060
|
-
*
|
|
1061
|
-
* ? `Still need: ${order.state.missing.join(", ")}`
|
|
1062
|
-
* : "Ready to submit"}
|
|
1063
|
-
* </div>
|
|
1064
|
-
* );
|
|
1106
|
+
* return order.loading
|
|
1107
|
+
* ? <p>Loading…</p>
|
|
1108
|
+
* : <p>{order.state.missing.length ? `Still need: ${order.state.missing.join(", ")}` : "Ready"}</p>;
|
|
1065
1109
|
* ```
|
|
1066
1110
|
*/
|
|
1067
|
-
export declare function useFormCollector<V = Record<string, unknown>>(options: CreateFormCollectorOptions<V>): UseFormCollectorResult<V>;
|
|
1111
|
+
export declare function useFormCollector<V = Record<string, unknown>>(options: CreateFormCollectorOptions<V> | LoadFormCollectorOptions<V>): UseFormCollectorResult<V>;
|
|
1068
1112
|
|
|
1069
1113
|
export declare interface UseFormCollectorResult<V = Record<string, unknown>> extends FormCollector<V> {
|
|
1070
1114
|
/**
|
|
@@ -1072,6 +1116,13 @@ export declare interface UseFormCollectorResult<V = Record<string, unknown>> ext
|
|
|
1072
1116
|
* status (`missing`, `complete`) derived on read — re-renders on every change.
|
|
1073
1117
|
*/
|
|
1074
1118
|
state: FormCollectorState<V> & FormCollectorStatus;
|
|
1119
|
+
/**
|
|
1120
|
+
* True while the backend definition is being fetched (name-only usage). Always
|
|
1121
|
+
* `false` when an inline `schema` is provided.
|
|
1122
|
+
*/
|
|
1123
|
+
loading: boolean;
|
|
1124
|
+
/** Set if fetching the backend definition failed. */
|
|
1125
|
+
error: Error | null;
|
|
1075
1126
|
}
|
|
1076
1127
|
|
|
1077
1128
|
/**
|