@useago/sdk 1.0.7 → 1.0.9
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/README.md +14 -3
- package/dist/{AgoClient--y10UXUV.cjs → AgoClient-B3-WGVne.cjs} +3 -3
- package/dist/{AgoClient-DYdIe_R4.js → AgoClient-QcTtrN7u.js} +3 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +46 -8
- package/dist/angular.d.ts +46 -8
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-BuMXp0Ia.cjs → createConversationSession-C0diFTUk.cjs} +1 -1
- package/dist/{createConversationSession-CCT1hCf8.js → createConversationSession-CR-71aLR.js} +1 -1
- package/dist/createFormCollector-BI3DXaew.cjs +1 -0
- package/dist/createFormCollector-CFt1_QSL.js +299 -0
- package/dist/devtools.d.cts +46 -8
- package/dist/devtools.d.ts +46 -8
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +64 -9
- package/dist/index.d.ts +64 -9
- package/dist/index.js +53 -45
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +47 -9
- package/dist/react.d.ts +47 -9
- package/dist/react.js +2 -2
- package/dist/testing.d.cts +46 -8
- package/dist/testing.d.ts +46 -8
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +46 -8
- package/dist/vue.d.ts +46 -8
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +77 -8
- package/dist/widget.d.ts +77 -8
- package/dist/widget.js +371 -366
- package/package.json +1 -1
- package/dist/createFormCollector-BwM7qTrp.js +0 -276
- package/dist/createFormCollector-DWzGKDwO.cjs +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -187,6 +187,7 @@ export declare class AgoClient {
|
|
|
187
187
|
* call it when their store updates so observers like the dev panel stay live.
|
|
188
188
|
*/
|
|
189
189
|
notifyContextChanged(): void;
|
|
190
|
+
/* Excluded from this release type: emitFormEvent */
|
|
190
191
|
/**
|
|
191
192
|
* Enable automatic capture of the current browser page (URL + title).
|
|
192
193
|
* Injected as a dynamic context entry named `browser-page`.
|
|
@@ -301,6 +302,27 @@ export declare interface AgoClientEvents {
|
|
|
301
302
|
result: unknown;
|
|
302
303
|
error?: string;
|
|
303
304
|
};
|
|
305
|
+
/**
|
|
306
|
+
* A form collector submitted successfully. `result` is the raw submit response
|
|
307
|
+
* (POST body / handler return value / backend relay result) — the third-party
|
|
308
|
+
* API's answer. `values` is the submitted field set, `name` the collector name.
|
|
309
|
+
*/
|
|
310
|
+
"form:submitted": {
|
|
311
|
+
name: string;
|
|
312
|
+
values: Record<string, unknown>;
|
|
313
|
+
result: unknown;
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* A form collector submit was attempted and failed at the network/server level
|
|
317
|
+
* (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
|
|
318
|
+
* pre-checks (missing required fields, no submit target) are NOT errors and do
|
|
319
|
+
* not fire this — they are returned to the caller as `{ ok: false }`.
|
|
320
|
+
*/
|
|
321
|
+
"form:error": {
|
|
322
|
+
name: string;
|
|
323
|
+
values: Record<string, unknown>;
|
|
324
|
+
error: string;
|
|
325
|
+
};
|
|
304
326
|
"connection:status": {
|
|
305
327
|
connected: boolean;
|
|
306
328
|
};
|
|
@@ -913,7 +935,7 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
913
935
|
|
|
914
936
|
/**
|
|
915
937
|
* Shape of a form's fields. Mirrors a client function's `parameters` (so the same
|
|
916
|
-
* object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes
|
|
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).
|
|
917
939
|
*/
|
|
918
940
|
export declare interface FormCollectorSchema {
|
|
919
941
|
type: "object";
|
|
@@ -953,17 +975,32 @@ export declare interface FormField {
|
|
|
953
975
|
}
|
|
954
976
|
|
|
955
977
|
/**
|
|
956
|
-
* A field's conditional-requiredness rule
|
|
957
|
-
*
|
|
958
|
-
*
|
|
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:
|
|
959
998
|
* - a single `value`, no `op` — equality (compared as strings);
|
|
960
999
|
* - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
|
|
961
1000
|
* - an array `value`, no `op` — "one of": matches when the property equals any
|
|
962
1001
|
* listed value.
|
|
963
|
-
*
|
|
964
|
-
* SDK-only — it is stripped from the schema before it reaches the LLM tool
|
|
965
1002
|
*/
|
|
966
|
-
declare interface
|
|
1003
|
+
export declare interface FormFieldLeafCondition {
|
|
967
1004
|
/** The controlling field whose value the rule tests. */
|
|
968
1005
|
property: string;
|
|
969
1006
|
/** Comparison operator; omitted means equality. Ignored when `value` is an array. */
|
|
@@ -977,14 +1014,15 @@ declare interface FormFieldCondition {
|
|
|
977
1014
|
}
|
|
978
1015
|
|
|
979
1016
|
/** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
|
|
980
|
-
declare interface FormFieldSchema {
|
|
1017
|
+
export declare interface FormFieldSchema {
|
|
981
1018
|
type: string;
|
|
982
1019
|
description?: string;
|
|
983
1020
|
enum?: string[];
|
|
984
1021
|
default?: unknown;
|
|
985
1022
|
/**
|
|
986
1023
|
* Makes the field required only while this condition holds. Drives the dynamic
|
|
987
|
-
* `missing` list; stripped
|
|
1024
|
+
* `missing` list; stripped from the LLM tool's `parameters` (still sent to the
|
|
1025
|
+
* agent via dynamic context). See {@link toWireParameters}.
|
|
988
1026
|
*/
|
|
989
1027
|
requiredWhen?: FormFieldCondition;
|
|
990
1028
|
}
|
|
@@ -1162,6 +1200,23 @@ export declare interface MockAgoClientOptions {
|
|
|
1162
1200
|
|
|
1163
1201
|
declare type MockFn = (...args: any[]) => any;
|
|
1164
1202
|
|
|
1203
|
+
/**
|
|
1204
|
+
* Subscribe to failed form collector submissions (network/server failures).
|
|
1205
|
+
*/
|
|
1206
|
+
export declare function onFormError(client: AgoClient, callback: (data: AgoClientEvents["form:error"]) => void): () => void;
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Subscribe to successful form collector submissions. `result` is the submit
|
|
1210
|
+
* response (the third-party API's answer). Returns an unsubscribe function.
|
|
1211
|
+
*
|
|
1212
|
+
* ```ts
|
|
1213
|
+
* const unsub = onFormSubmitted(client, ({ name, result }) => {
|
|
1214
|
+
* console.log(name, "submitted", result);
|
|
1215
|
+
* });
|
|
1216
|
+
* ```
|
|
1217
|
+
*/
|
|
1218
|
+
export declare function onFormSubmitted(client: AgoClient, callback: (data: AgoClientEvents["form:submitted"]) => void): () => void;
|
|
1219
|
+
|
|
1165
1220
|
/**
|
|
1166
1221
|
* Subscribe to client function invocations.
|
|
1167
1222
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
|
|
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-
|
|
3
|
-
import { i as B, n as P, r as $, t as z } from "./createFormCollector-
|
|
4
|
-
import { t as Q } from "./createConversationSession-
|
|
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
|
+
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-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) {
|
|
@@ -19,81 +19,87 @@ function oe(e, o) {
|
|
|
19
19
|
function te(e, o) {
|
|
20
20
|
return e.on("message:error", o), () => e.off("message:error", o);
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function re(e, o) {
|
|
23
23
|
return e.on("toolCall:received", o), () => e.off("toolCall:received", o);
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function ne(e, o) {
|
|
26
|
+
return e.on("form:submitted", o), () => e.off("form:submitted", o);
|
|
27
|
+
}
|
|
28
|
+
function ae(e, o) {
|
|
29
|
+
return e.on("form:error", o), () => e.off("form:error", o);
|
|
30
|
+
}
|
|
31
|
+
function se(e, o) {
|
|
26
32
|
return e.on("function:invoke", o), () => e.off("function:invoke", o);
|
|
27
33
|
}
|
|
28
|
-
async function*
|
|
29
|
-
const
|
|
30
|
-
let
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
}, f = (s) =>
|
|
34
|
+
async function* ie(e, o, u) {
|
|
35
|
+
const n = [];
|
|
36
|
+
let r = null, a = !1;
|
|
37
|
+
const g = (s) => {
|
|
38
|
+
n.push(s), r?.();
|
|
39
|
+
}, f = (s) => g({
|
|
34
40
|
type: "start",
|
|
35
41
|
data: s
|
|
36
|
-
}), t = (s) =>
|
|
42
|
+
}), t = (s) => g({
|
|
37
43
|
type: "chunk",
|
|
38
44
|
data: s
|
|
39
45
|
}), i = (s) => {
|
|
40
|
-
|
|
46
|
+
g({
|
|
41
47
|
type: "complete",
|
|
42
48
|
data: s
|
|
43
|
-
}),
|
|
44
|
-
},
|
|
45
|
-
|
|
49
|
+
}), a = !0, r?.();
|
|
50
|
+
}, m = (s) => {
|
|
51
|
+
g({
|
|
46
52
|
type: "error",
|
|
47
53
|
data: s
|
|
48
|
-
}),
|
|
49
|
-
},
|
|
54
|
+
}), a = !0, r?.();
|
|
55
|
+
}, l = (s) => g({
|
|
50
56
|
type: "toolCall",
|
|
51
57
|
data: s
|
|
52
58
|
});
|
|
53
|
-
e.on("message:start", f), e.on("message:chunk", t), e.on("message:complete", i), e.on("message:error",
|
|
54
|
-
|
|
59
|
+
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, u).catch(() => {
|
|
60
|
+
a = !0, r?.();
|
|
55
61
|
});
|
|
56
62
|
try {
|
|
57
|
-
for (; !
|
|
58
|
-
|
|
59
|
-
}),
|
|
63
|
+
for (; !a || n.length > 0; ) n.length > 0 ? yield n.shift() : (await new Promise((s) => {
|
|
64
|
+
r = s;
|
|
65
|
+
}), r = null);
|
|
60
66
|
} finally {
|
|
61
|
-
e.off("message:start", f), e.off("message:chunk", t), e.off("message:complete", i), e.off("message:error",
|
|
67
|
+
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
68
|
}
|
|
63
69
|
}
|
|
64
70
|
function p(e) {
|
|
65
|
-
let o,
|
|
71
|
+
let o, u, n, r, a, g;
|
|
66
72
|
if (typeof window < "u" && window.AGO) {
|
|
67
73
|
const t = window.AGO;
|
|
68
|
-
o = t.basepath,
|
|
74
|
+
o = t.basepath, u = t.widgetId, n = t.agent || t.defaultAgent, r = t.permission, a = t.email, g = t.jwt;
|
|
69
75
|
}
|
|
70
76
|
if (typeof document < "u") {
|
|
71
77
|
const t = (i) => document.querySelector(`meta[name="${i}"]`)?.getAttribute("content") || void 0;
|
|
72
|
-
o = o || t("ago-base-url"),
|
|
78
|
+
o = o || t("ago-base-url"), u = u || t("ago-widget-id"), n = n || t("ago-agent") || t("ago-agent-id"), r = r || t("ago-permission"), a = a || t("ago-user-email");
|
|
73
79
|
}
|
|
74
80
|
if (typeof document < "u") {
|
|
75
81
|
const t = [document.body, ...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);
|
|
76
82
|
for (const i of t)
|
|
77
|
-
i && (o = o || i.getAttribute("data-ago-base-url") || void 0,
|
|
83
|
+
i && (o = o || i.getAttribute("data-ago-base-url") || void 0, u = u || i.getAttribute("data-ago-widget-id") || void 0, n = n || i.getAttribute("data-ago-agent") || i.getAttribute("data-ago-agent-id") || void 0, r = r || i.getAttribute("data-ago-permission") || void 0, a = a || i.getAttribute("data-ago-user-email") || void 0);
|
|
78
84
|
}
|
|
79
|
-
o = e?.baseUrl || o,
|
|
85
|
+
o = e?.baseUrl || o, u = e?.widgetId || u, n = e?.agent || e?.defaultAgentId || n, r = e?.permission || r, a = e?.userEmail || a, g = e?.userJwt || g;
|
|
80
86
|
const f = e?.debug;
|
|
81
87
|
return o ? {
|
|
82
88
|
baseUrl: o,
|
|
83
|
-
widgetId:
|
|
84
|
-
agent:
|
|
85
|
-
permission:
|
|
86
|
-
userEmail:
|
|
87
|
-
userJwt:
|
|
89
|
+
widgetId: u,
|
|
90
|
+
agent: n,
|
|
91
|
+
permission: r,
|
|
92
|
+
userEmail: a,
|
|
93
|
+
userJwt: g,
|
|
88
94
|
debug: f
|
|
89
95
|
} : null;
|
|
90
96
|
}
|
|
91
|
-
function
|
|
97
|
+
function ue(e) {
|
|
92
98
|
const o = p(e);
|
|
93
99
|
if (!o) throw new c('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.', "config_missing_base_url");
|
|
94
100
|
return new d(o);
|
|
95
101
|
}
|
|
96
|
-
function
|
|
102
|
+
function ge(e, o) {
|
|
97
103
|
return {
|
|
98
104
|
...e,
|
|
99
105
|
handler: o
|
|
@@ -112,35 +118,37 @@ export {
|
|
|
112
118
|
L as SSEHandler,
|
|
113
119
|
p as autoDetectConfig,
|
|
114
120
|
T as copyToClipboard,
|
|
115
|
-
|
|
121
|
+
ue as createAgo,
|
|
116
122
|
Q as createConversationSession,
|
|
117
123
|
z as createFormCollector,
|
|
118
|
-
|
|
124
|
+
ie as createMessageStream,
|
|
119
125
|
W as createMockClient,
|
|
120
126
|
B as createStore,
|
|
121
127
|
Y as defineFunction,
|
|
122
128
|
P as deriveFormStatus,
|
|
123
|
-
|
|
129
|
+
M as getLocalStorage,
|
|
124
130
|
E as getUserLocation,
|
|
125
131
|
h as highlightElement,
|
|
126
132
|
G as isStreamNetworkError,
|
|
127
133
|
$ as loadFormCollector,
|
|
128
134
|
O as logger,
|
|
129
|
-
|
|
135
|
+
ae as onFormError,
|
|
136
|
+
ne as onFormSubmitted,
|
|
137
|
+
se as onFunctionInvoke,
|
|
130
138
|
Z as onMessage,
|
|
131
139
|
ee as onMessageChunk,
|
|
132
140
|
te as onMessageError,
|
|
133
141
|
oe as onMessageStart,
|
|
134
|
-
|
|
142
|
+
re as onToolCall,
|
|
135
143
|
v as openUrl,
|
|
136
|
-
|
|
144
|
+
k as scrollToElement,
|
|
137
145
|
A as setLocalStorage,
|
|
138
146
|
b as setTheme,
|
|
139
147
|
I as showConfirmDialog,
|
|
140
148
|
y as showNotification,
|
|
141
149
|
C as showToast,
|
|
142
|
-
|
|
150
|
+
F as submitForm,
|
|
143
151
|
S as trackEvent,
|
|
144
152
|
_ as validateConfig,
|
|
145
|
-
|
|
153
|
+
ge as withHandler
|
|
146
154
|
};
|
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
|
|
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
|
@@ -178,6 +178,7 @@ declare class AgoClient {
|
|
|
178
178
|
* call it when their store updates so observers like the dev panel stay live.
|
|
179
179
|
*/
|
|
180
180
|
notifyContextChanged(): void;
|
|
181
|
+
/* Excluded from this release type: emitFormEvent */
|
|
181
182
|
/**
|
|
182
183
|
* Enable automatic capture of the current browser page (URL + title).
|
|
183
184
|
* Injected as a dynamic context entry named `browser-page`.
|
|
@@ -292,6 +293,27 @@ declare interface AgoClientEvents {
|
|
|
292
293
|
result: unknown;
|
|
293
294
|
error?: string;
|
|
294
295
|
};
|
|
296
|
+
/**
|
|
297
|
+
* A form collector submitted successfully. `result` is the raw submit response
|
|
298
|
+
* (POST body / handler return value / backend relay result) — the third-party
|
|
299
|
+
* API's answer. `values` is the submitted field set, `name` the collector name.
|
|
300
|
+
*/
|
|
301
|
+
"form:submitted": {
|
|
302
|
+
name: string;
|
|
303
|
+
values: Record<string, unknown>;
|
|
304
|
+
result: unknown;
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* A form collector submit was attempted and failed at the network/server level
|
|
308
|
+
* (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
|
|
309
|
+
* pre-checks (missing required fields, no submit target) are NOT errors and do
|
|
310
|
+
* not fire this — they are returned to the caller as `{ ok: false }`.
|
|
311
|
+
*/
|
|
312
|
+
"form:error": {
|
|
313
|
+
name: string;
|
|
314
|
+
values: Record<string, unknown>;
|
|
315
|
+
error: string;
|
|
316
|
+
};
|
|
295
317
|
"connection:status": {
|
|
296
318
|
connected: boolean;
|
|
297
319
|
};
|
|
@@ -683,7 +705,7 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
683
705
|
|
|
684
706
|
/**
|
|
685
707
|
* Shape of a form's fields. Mirrors a client function's `parameters` (so the same
|
|
686
|
-
* object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes
|
|
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).
|
|
687
709
|
*/
|
|
688
710
|
export declare interface FormCollectorSchema {
|
|
689
711
|
type: "object";
|
|
@@ -723,17 +745,32 @@ declare interface FormField {
|
|
|
723
745
|
}
|
|
724
746
|
|
|
725
747
|
/**
|
|
726
|
-
* A field's conditional-requiredness rule
|
|
727
|
-
*
|
|
728
|
-
*
|
|
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:
|
|
729
768
|
* - a single `value`, no `op` — equality (compared as strings);
|
|
730
769
|
* - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
|
|
731
770
|
* - an array `value`, no `op` — "one of": matches when the property equals any
|
|
732
771
|
* listed value.
|
|
733
|
-
*
|
|
734
|
-
* SDK-only — it is stripped from the schema before it reaches the LLM tool
|
|
735
772
|
*/
|
|
736
|
-
declare interface
|
|
773
|
+
export declare interface FormFieldLeafCondition {
|
|
737
774
|
/** The controlling field whose value the rule tests. */
|
|
738
775
|
property: string;
|
|
739
776
|
/** Comparison operator; omitted means equality. Ignored when `value` is an array. */
|
|
@@ -747,14 +784,15 @@ declare interface FormFieldCondition {
|
|
|
747
784
|
}
|
|
748
785
|
|
|
749
786
|
/** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
|
|
750
|
-
declare interface FormFieldSchema {
|
|
787
|
+
export declare interface FormFieldSchema {
|
|
751
788
|
type: string;
|
|
752
789
|
description?: string;
|
|
753
790
|
enum?: string[];
|
|
754
791
|
default?: unknown;
|
|
755
792
|
/**
|
|
756
793
|
* Makes the field required only while this condition holds. Drives the dynamic
|
|
757
|
-
* `missing` list; stripped
|
|
794
|
+
* `missing` list; stripped from the LLM tool's `parameters` (still sent to the
|
|
795
|
+
* agent via dynamic context). See {@link toWireParameters}.
|
|
758
796
|
*/
|
|
759
797
|
requiredWhen?: FormFieldCondition;
|
|
760
798
|
}
|
package/dist/react.d.ts
CHANGED
|
@@ -178,6 +178,7 @@ declare class AgoClient {
|
|
|
178
178
|
* call it when their store updates so observers like the dev panel stay live.
|
|
179
179
|
*/
|
|
180
180
|
notifyContextChanged(): void;
|
|
181
|
+
/* Excluded from this release type: emitFormEvent */
|
|
181
182
|
/**
|
|
182
183
|
* Enable automatic capture of the current browser page (URL + title).
|
|
183
184
|
* Injected as a dynamic context entry named `browser-page`.
|
|
@@ -292,6 +293,27 @@ declare interface AgoClientEvents {
|
|
|
292
293
|
result: unknown;
|
|
293
294
|
error?: string;
|
|
294
295
|
};
|
|
296
|
+
/**
|
|
297
|
+
* A form collector submitted successfully. `result` is the raw submit response
|
|
298
|
+
* (POST body / handler return value / backend relay result) — the third-party
|
|
299
|
+
* API's answer. `values` is the submitted field set, `name` the collector name.
|
|
300
|
+
*/
|
|
301
|
+
"form:submitted": {
|
|
302
|
+
name: string;
|
|
303
|
+
values: Record<string, unknown>;
|
|
304
|
+
result: unknown;
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* A form collector submit was attempted and failed at the network/server level
|
|
308
|
+
* (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
|
|
309
|
+
* pre-checks (missing required fields, no submit target) are NOT errors and do
|
|
310
|
+
* not fire this — they are returned to the caller as `{ ok: false }`.
|
|
311
|
+
*/
|
|
312
|
+
"form:error": {
|
|
313
|
+
name: string;
|
|
314
|
+
values: Record<string, unknown>;
|
|
315
|
+
error: string;
|
|
316
|
+
};
|
|
295
317
|
"connection:status": {
|
|
296
318
|
connected: boolean;
|
|
297
319
|
};
|
|
@@ -683,7 +705,7 @@ export declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
|
683
705
|
|
|
684
706
|
/**
|
|
685
707
|
* Shape of a form's fields. Mirrors a client function's `parameters` (so the same
|
|
686
|
-
* object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes
|
|
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).
|
|
687
709
|
*/
|
|
688
710
|
export declare interface FormCollectorSchema {
|
|
689
711
|
type: "object";
|
|
@@ -723,17 +745,32 @@ declare interface FormField {
|
|
|
723
745
|
}
|
|
724
746
|
|
|
725
747
|
/**
|
|
726
|
-
* A field's conditional-requiredness rule
|
|
727
|
-
*
|
|
728
|
-
*
|
|
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:
|
|
729
768
|
* - a single `value`, no `op` — equality (compared as strings);
|
|
730
769
|
* - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
|
|
731
770
|
* - an array `value`, no `op` — "one of": matches when the property equals any
|
|
732
771
|
* listed value.
|
|
733
|
-
*
|
|
734
|
-
* SDK-only — it is stripped from the schema before it reaches the LLM tool
|
|
735
772
|
*/
|
|
736
|
-
declare interface
|
|
773
|
+
export declare interface FormFieldLeafCondition {
|
|
737
774
|
/** The controlling field whose value the rule tests. */
|
|
738
775
|
property: string;
|
|
739
776
|
/** Comparison operator; omitted means equality. Ignored when `value` is an array. */
|
|
@@ -747,14 +784,15 @@ declare interface FormFieldCondition {
|
|
|
747
784
|
}
|
|
748
785
|
|
|
749
786
|
/** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
|
|
750
|
-
declare interface FormFieldSchema {
|
|
787
|
+
export declare interface FormFieldSchema {
|
|
751
788
|
type: string;
|
|
752
789
|
description?: string;
|
|
753
790
|
enum?: string[];
|
|
754
791
|
default?: unknown;
|
|
755
792
|
/**
|
|
756
793
|
* Makes the field required only while this condition holds. Drives the dynamic
|
|
757
|
-
* `missing` list; stripped
|
|
794
|
+
* `missing` list; stripped from the LLM tool's `parameters` (still sent to the
|
|
795
|
+
* agent via dynamic context). See {@link toWireParameters}.
|
|
758
796
|
*/
|
|
759
797
|
requiredWhen?: FormFieldCondition;
|
|
760
798
|
}
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as J } from "./AgoClient-
|
|
2
|
-
import { i as q, n as Me, r as z, t as H } from "./createFormCollector-
|
|
1
|
+
import { t as J } from "./AgoClient-QcTtrN7u.js";
|
|
2
|
+
import { i as q, n as Me, r as z, t as H } from "./createFormCollector-CFt1_QSL.js";
|
|
3
3
|
import { t as Ee } from "./createMockClient-DwdxNwEn.js";
|
|
4
4
|
import G, { createContext as V, useCallback as E, useContext as O, useEffect as S, useId as j, useMemo as F, useRef as T, useState as M, useSyncExternalStore as X } from "react";
|
|
5
5
|
import { Fragment as Y, jsx as s, jsxs as I } from "react/jsx-runtime";
|