@useago/sdk 1.3.2 → 1.4.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/README.md +41 -0
- package/dist/{AgoClient-Cwx_eYSu.js → AgoClient-BdtuHX7k.js} +150 -85
- package/dist/AgoClient-CRAnT4qE.cjs +8 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +99 -1
- package/dist/angular.d.ts +99 -1
- package/dist/angular.js +16 -7
- package/dist/{createConversationSession-DV0Xp_3O.cjs → createConversationSession-B8zfTL78.cjs} +1 -1
- package/dist/{createConversationSession-B3h567tt.js → createConversationSession-CWpf4u6I.js} +1 -1
- package/dist/{createFormCollector-CyWisAkI.js → createFormCollector-B4n0_diV.js} +1 -1
- package/dist/{createFormCollector-BB3Uscuo.cjs → createFormCollector-BB_l0Sia.cjs} +1 -1
- package/dist/{createMockClient-DwdxNwEn.js → createMockClient-d-arlmCq.js} +19 -17
- package/dist/createMockClient-ucPENDzz.cjs +1 -0
- package/dist/devtools.d.cts +93 -1
- package/dist/devtools.d.ts +93 -1
- package/dist/helpers.d.cts +5 -1
- package/dist/helpers.d.ts +5 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +93 -1
- package/dist/index.d.ts +93 -1
- package/dist/index.js +4 -4
- package/dist/react.cjs +3 -3
- package/dist/react.d.cts +158 -2
- package/dist/react.d.ts +158 -2
- package/dist/react.js +469 -391
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +93 -1
- package/dist/testing.d.ts +93 -1
- package/dist/testing.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +125 -1
- package/dist/vue.d.ts +125 -1
- package/dist/vue.js +73 -64
- package/dist/widget.cjs +1 -1
- package/dist/widget.d.cts +93 -1
- package/dist/widget.d.ts +93 -1
- package/dist/widget.js +3 -3
- package/package.json +1 -1
- package/dist/AgoClient-CzSmJQxl.cjs +0 -6
- package/dist/createMockClient-zHQ0cjUH.cjs +0 -1
package/dist/devtools.d.ts
CHANGED
|
@@ -146,6 +146,12 @@ declare class AgoClient {
|
|
|
146
146
|
getRegisteredFunctions(): ClientFunctionSchema[];
|
|
147
147
|
/**
|
|
148
148
|
* Register a navigation function that lets AGO navigate users to different pages.
|
|
149
|
+
*
|
|
150
|
+
* Also registers a dynamic context entry (`current-page`) that reports the page
|
|
151
|
+
* the user is currently on, by route name, on every message. This is what lets
|
|
152
|
+
* the agent know *where* it is after it navigates (e.g. so auto-continuation
|
|
153
|
+
* can apply page state on the destination), not just how to navigate away.
|
|
154
|
+
*
|
|
149
155
|
* @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
|
|
150
156
|
* @param routes - Map of route names to paths, with descriptions for the LLM
|
|
151
157
|
*/
|
|
@@ -154,6 +160,41 @@ declare class AgoClient {
|
|
|
154
160
|
path: string;
|
|
155
161
|
description: string;
|
|
156
162
|
}>): void;
|
|
163
|
+
/**
|
|
164
|
+
* Unregister the navigation function and its `current-page` context provider.
|
|
165
|
+
*/
|
|
166
|
+
unregisterNavigationFunction(): void;
|
|
167
|
+
/**
|
|
168
|
+
* Register a "page state" function that lets AGO change the current page's
|
|
169
|
+
* state (filters, sort, view mode, selection…) and reads the current state
|
|
170
|
+
* back as dynamic context. This is the state-mutation mirror of
|
|
171
|
+
* {@link registerNavigationFunction}.
|
|
172
|
+
*
|
|
173
|
+
* It does two things:
|
|
174
|
+
* - Synthesizes ONE client function (default name `setPageState`) whose
|
|
175
|
+
* properties are the controls — all optional, so the agent sets only the
|
|
176
|
+
* ones the user asked for.
|
|
177
|
+
* - Registers a dynamic context provider (keyed `page-state:<fnName>`) that
|
|
178
|
+
* reports each control's current `get()` value on every message.
|
|
179
|
+
*
|
|
180
|
+
* ```ts
|
|
181
|
+
* client.registerPageStateFunction([
|
|
182
|
+
* {
|
|
183
|
+
* name: "statusFilter",
|
|
184
|
+
* description: "Filter the list by review status",
|
|
185
|
+
* schema: { type: "string", enum: ["all", "pending", "approved"] },
|
|
186
|
+
* get: () => filters.status,
|
|
187
|
+
* set: (v) => setFilters({ ...filters, status: v }),
|
|
188
|
+
* },
|
|
189
|
+
* ]);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
|
|
193
|
+
/**
|
|
194
|
+
* Unregister a page state function and its dynamic context provider.
|
|
195
|
+
* Mirror of unregistering `navigateToPage`.
|
|
196
|
+
*/
|
|
197
|
+
unregisterPageStateFunction(functionName?: string): void;
|
|
157
198
|
/**
|
|
158
199
|
* Register or update a piece of client-side context.
|
|
159
200
|
* This context is sent with every message so the AI understands the user's situation.
|
|
@@ -386,9 +427,23 @@ declare interface AgoMessage {
|
|
|
386
427
|
followUpReplies?: string[];
|
|
387
428
|
/** Uploaded files on this message (usually the user's). */
|
|
388
429
|
attachments?: AgoAttachment[];
|
|
430
|
+
/**
|
|
431
|
+
* True when the backend flagged this message as hidden (e.g. an
|
|
432
|
+
* auto-continuation nudge). Kept in the model's context but not displayed;
|
|
433
|
+
* UI helpers like `useMessages`/`ChatWidget` filter these out.
|
|
434
|
+
*/
|
|
435
|
+
hidden?: boolean;
|
|
389
436
|
createdAt: Date;
|
|
390
437
|
}
|
|
391
438
|
|
|
439
|
+
/**
|
|
440
|
+
* Options for {@link AgoClient.registerPageStateFunction}.
|
|
441
|
+
*/
|
|
442
|
+
declare interface AgoPageStateOptions {
|
|
443
|
+
/** Name of the synthesized client function. Defaults to "setPageState". */
|
|
444
|
+
functionName?: string;
|
|
445
|
+
}
|
|
446
|
+
|
|
392
447
|
/**
|
|
393
448
|
* Knowledge source citation
|
|
394
449
|
*/
|
|
@@ -398,6 +453,32 @@ declare interface AgoSource {
|
|
|
398
453
|
url?: string;
|
|
399
454
|
}
|
|
400
455
|
|
|
456
|
+
/**
|
|
457
|
+
* A single editable control on the current page (a filter, a sort, a view mode,
|
|
458
|
+
* a selection…). It becomes one optional property of the synthesized
|
|
459
|
+
* `setPageState` function, and its current value is surfaced back to the agent
|
|
460
|
+
* as dynamic context. This is the state-mutation mirror of a navigation route.
|
|
461
|
+
*/
|
|
462
|
+
declare interface AgoStateControl<T = unknown> {
|
|
463
|
+
/** Machine name of the control, e.g. "statusFilter". Becomes a property of the tool. */
|
|
464
|
+
name: string;
|
|
465
|
+
/** Description for the LLM, e.g. "Filter the list by review status". */
|
|
466
|
+
description: string;
|
|
467
|
+
/** JSON schema for a SINGLE field (like one property of navigateToPage). */
|
|
468
|
+
schema: {
|
|
469
|
+
type: "string" | "number" | "boolean" | "array";
|
|
470
|
+
enum?: (string | number)[];
|
|
471
|
+
items?: {
|
|
472
|
+
type: string;
|
|
473
|
+
enum?: (string | number)[];
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
/** Current value → pushed as dynamic context so the agent knows what to change. */
|
|
477
|
+
get?: () => T;
|
|
478
|
+
/** Apply the state change on the page. May be async. */
|
|
479
|
+
set: (value: T) => void | Promise<void>;
|
|
480
|
+
}
|
|
481
|
+
|
|
401
482
|
/**
|
|
402
483
|
* Single-object function definition — combines name, schema, and handler.
|
|
403
484
|
*
|
|
@@ -444,7 +525,11 @@ declare interface ClientFunctionSchema {
|
|
|
444
525
|
properties: Record<string, {
|
|
445
526
|
type: string;
|
|
446
527
|
description?: string;
|
|
447
|
-
enum?: string[];
|
|
528
|
+
enum?: (string | number)[];
|
|
529
|
+
items?: {
|
|
530
|
+
type: string;
|
|
531
|
+
enum?: (string | number)[];
|
|
532
|
+
};
|
|
448
533
|
default?: unknown;
|
|
449
534
|
}>;
|
|
450
535
|
required?: string[];
|
|
@@ -621,6 +706,13 @@ declare interface SendMessageOptions {
|
|
|
621
706
|
agentId?: string;
|
|
622
707
|
/** File attachments */
|
|
623
708
|
files?: File[];
|
|
709
|
+
/**
|
|
710
|
+
* Mark this message as hidden. The backend keeps it in the model's context but
|
|
711
|
+
* flags it so the UI never displays it. Used by auto-continuation to nudge the
|
|
712
|
+
* agent after a navigation without polluting the visible transcript.
|
|
713
|
+
* Requires backend support for the `hidden` flag; older backends ignore it.
|
|
714
|
+
*/
|
|
715
|
+
hidden?: boolean;
|
|
624
716
|
}
|
|
625
717
|
|
|
626
718
|
/**
|
package/dist/helpers.d.cts
CHANGED
|
@@ -37,7 +37,11 @@ declare interface ClientFunctionSchema {
|
|
|
37
37
|
properties: Record<string, {
|
|
38
38
|
type: string;
|
|
39
39
|
description?: string;
|
|
40
|
-
enum?: string[];
|
|
40
|
+
enum?: (string | number)[];
|
|
41
|
+
items?: {
|
|
42
|
+
type: string;
|
|
43
|
+
enum?: (string | number)[];
|
|
44
|
+
};
|
|
41
45
|
default?: unknown;
|
|
42
46
|
}>;
|
|
43
47
|
required?: string[];
|
package/dist/helpers.d.ts
CHANGED
|
@@ -37,7 +37,11 @@ declare interface ClientFunctionSchema {
|
|
|
37
37
|
properties: Record<string, {
|
|
38
38
|
type: string;
|
|
39
39
|
description?: string;
|
|
40
|
-
enum?: string[];
|
|
40
|
+
enum?: (string | number)[];
|
|
41
|
+
items?: {
|
|
42
|
+
type: string;
|
|
43
|
+
enum?: (string | number)[];
|
|
44
|
+
};
|
|
41
45
|
default?: unknown;
|
|
42
46
|
}>;
|
|
43
47
|
required?: string[];
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./AgoClient-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./AgoClient-CRAnT4qE.cjs"),f=require("./createFormCollector-BB_l0Sia.cjs"),h=require("./createConversationSession-B8zfTL78.cjs"),p=require("./createMockClient-ucPENDzz.cjs");require("./testing.cjs");const g=require("./functions-Djnq-JAo.cjs");function w(e){return e}function S(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 F(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 v(e,o){return e.on("form:submitted",o),()=>e.off("form:submitted",o)}function M(e,o){return e.on("form:error",o),()=>e.off("form:error",o)}function q(e,o){return e.on("function:invoke",o),()=>e.off("function:invoke",o)}async function*k(e,o,l){const a=[];let n=null,i=!1;const m=s=>{a.push(s),n?.()},c=s=>m({type:"start",data:s}),t=s=>m({type:"chunk",data:s}),u=s=>{m({type:"complete",data:s}),i=!0,n?.()},d=s=>{m({type:"error",data:s}),i=!0,n?.()},C=s=>m({type:"toolCall",data:s});e.on("message:start",c),e.on("message:chunk",t),e.on("message:complete",u),e.on("message:error",d),e.on("toolCall:received",C),e.sendMessage(o,l).catch(()=>{i=!0,n?.()});try{for(;!i||a.length>0;)a.length>0?yield a.shift():(await new Promise(s=>{n=s}),n=null)}finally{e.off("message:start",c),e.off("message:chunk",t),e.off("message:complete",u),e.off("message:error",d),e.off("toolCall:received",C)}}function A(e){let o,l,a,n,i,m;if(typeof window<"u"&&window.AGO){const t=window.AGO;o=t.basepath,l=t.widgetId,a=t.agent||t.defaultAgent,n=t.permission,i=t.email,m=t.jwt}if(typeof document<"u"){const t=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||t("ago-base-url"),l=l||t("ago-widget-id"),a=a||t("ago-agent")||t("ago-agent-id"),n=n||t("ago-permission"),i=i||t("ago-user-email")}if(typeof document<"u"){const t=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of t)u&&(o=o||u.getAttribute("data-ago-base-url")||void 0,l=l||u.getAttribute("data-ago-widget-id")||void 0,a=a||u.getAttribute("data-ago-agent")||u.getAttribute("data-ago-agent-id")||void 0,n=n||u.getAttribute("data-ago-permission")||void 0,i=i||u.getAttribute("data-ago-user-email")||void 0)}o=e?.baseUrl||o,l=e?.widgetId||l,a=e?.agent||e?.defaultAgentId||a,n=e?.permission||n,i=e?.userEmail||i,m=e?.userJwt||m;const c=e?.debug;return o?{baseUrl:o,widgetId:l,agent:a,permission:n,userEmail:i,userJwt:m,debug:c}:null}function T(e){const o=A(e);if(!o)throw new r.AgoError('createAgo(): could not detect AGO configuration. Set window.AGO, add <meta name="ago-base-url">, or pass { baseUrl } explicitly.',"config_missing_base_url");return new r.AgoClient(o)}function I(e,o){return{...e,handler:o}}exports.AgoApiError=r.AgoApiError;exports.AgoClient=r.AgoClient;exports.AgoError=r.AgoError;exports.AgoFunctionError=r.AgoFunctionError;exports.AgoNetworkError=r.AgoNetworkError;exports.AgoStreamError=r.AgoStreamError;exports.ClientContextRegistry=r.ClientContextRegistry;exports.EventEmitter=r.EventEmitter;exports.FunctionRegistry=r.FunctionRegistry;exports.SSEHandler=r.SSEHandler;exports.autoDetectConfig=A;exports.canInlineImage=r.canInlineImage;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=T;exports.createConversationSession=h.createConversationSession;exports.createFormCollector=f.createFormCollector;exports.createMessageStream=k;exports.createMockClient=p.createMockClient;exports.createStore=f.createStore;exports.defineFunction=w;exports.deriveFormStatus=f.deriveFormStatus;exports.formatFileSize=r.formatFileSize;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=r.isStreamNetworkError;exports.loadFormCollector=f.loadFormCollector;exports.logger=r.logger;exports.onFormError=M;exports.onFormSubmitted=v;exports.onFunctionInvoke=q;exports.onMessage=S;exports.onMessageChunk=E;exports.onMessageError=F;exports.onMessageStart=y;exports.onToolCall=b;exports.openUrl=g.openUrl;exports.safeAttachmentUrl=r.safeAttachmentUrl;exports.scrollToElement=g.scrollToElement;exports.setLocalStorage=g.setLocalStorage;exports.setTheme=g.setTheme;exports.showConfirmDialog=g.showConfirmDialog;exports.showNotification=g.showNotification;exports.showToast=g.showToast;exports.submitForm=g.submitForm;exports.trackEvent=g.trackEvent;exports.validateConfig=r.validateConfig;exports.withHandler=I;
|
package/dist/index.d.cts
CHANGED
|
@@ -157,6 +157,12 @@ export declare class AgoClient {
|
|
|
157
157
|
getRegisteredFunctions(): ClientFunctionSchema[];
|
|
158
158
|
/**
|
|
159
159
|
* Register a navigation function that lets AGO navigate users to different pages.
|
|
160
|
+
*
|
|
161
|
+
* Also registers a dynamic context entry (`current-page`) that reports the page
|
|
162
|
+
* the user is currently on, by route name, on every message. This is what lets
|
|
163
|
+
* the agent know *where* it is after it navigates (e.g. so auto-continuation
|
|
164
|
+
* can apply page state on the destination), not just how to navigate away.
|
|
165
|
+
*
|
|
160
166
|
* @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
|
|
161
167
|
* @param routes - Map of route names to paths, with descriptions for the LLM
|
|
162
168
|
*/
|
|
@@ -165,6 +171,41 @@ export declare class AgoClient {
|
|
|
165
171
|
path: string;
|
|
166
172
|
description: string;
|
|
167
173
|
}>): void;
|
|
174
|
+
/**
|
|
175
|
+
* Unregister the navigation function and its `current-page` context provider.
|
|
176
|
+
*/
|
|
177
|
+
unregisterNavigationFunction(): void;
|
|
178
|
+
/**
|
|
179
|
+
* Register a "page state" function that lets AGO change the current page's
|
|
180
|
+
* state (filters, sort, view mode, selection…) and reads the current state
|
|
181
|
+
* back as dynamic context. This is the state-mutation mirror of
|
|
182
|
+
* {@link registerNavigationFunction}.
|
|
183
|
+
*
|
|
184
|
+
* It does two things:
|
|
185
|
+
* - Synthesizes ONE client function (default name `setPageState`) whose
|
|
186
|
+
* properties are the controls — all optional, so the agent sets only the
|
|
187
|
+
* ones the user asked for.
|
|
188
|
+
* - Registers a dynamic context provider (keyed `page-state:<fnName>`) that
|
|
189
|
+
* reports each control's current `get()` value on every message.
|
|
190
|
+
*
|
|
191
|
+
* ```ts
|
|
192
|
+
* client.registerPageStateFunction([
|
|
193
|
+
* {
|
|
194
|
+
* name: "statusFilter",
|
|
195
|
+
* description: "Filter the list by review status",
|
|
196
|
+
* schema: { type: "string", enum: ["all", "pending", "approved"] },
|
|
197
|
+
* get: () => filters.status,
|
|
198
|
+
* set: (v) => setFilters({ ...filters, status: v }),
|
|
199
|
+
* },
|
|
200
|
+
* ]);
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
|
|
204
|
+
/**
|
|
205
|
+
* Unregister a page state function and its dynamic context provider.
|
|
206
|
+
* Mirror of unregistering `navigateToPage`.
|
|
207
|
+
*/
|
|
208
|
+
unregisterPageStateFunction(functionName?: string): void;
|
|
168
209
|
/**
|
|
169
210
|
* Register or update a piece of client-side context.
|
|
170
211
|
* This context is sent with every message so the AI understands the user's situation.
|
|
@@ -421,6 +462,12 @@ export declare interface AgoMessage {
|
|
|
421
462
|
followUpReplies?: string[];
|
|
422
463
|
/** Uploaded files on this message (usually the user's). */
|
|
423
464
|
attachments?: AgoAttachment[];
|
|
465
|
+
/**
|
|
466
|
+
* True when the backend flagged this message as hidden (e.g. an
|
|
467
|
+
* auto-continuation nudge). Kept in the model's context but not displayed;
|
|
468
|
+
* UI helpers like `useMessages`/`ChatWidget` filter these out.
|
|
469
|
+
*/
|
|
470
|
+
hidden?: boolean;
|
|
424
471
|
createdAt: Date;
|
|
425
472
|
}
|
|
426
473
|
|
|
@@ -432,6 +479,14 @@ export declare class AgoNetworkError extends AgoError {
|
|
|
432
479
|
constructor(message: string, originalError?: Error | undefined);
|
|
433
480
|
}
|
|
434
481
|
|
|
482
|
+
/**
|
|
483
|
+
* Options for {@link AgoClient.registerPageStateFunction}.
|
|
484
|
+
*/
|
|
485
|
+
export declare interface AgoPageStateOptions {
|
|
486
|
+
/** Name of the synthesized client function. Defaults to "setPageState". */
|
|
487
|
+
functionName?: string;
|
|
488
|
+
}
|
|
489
|
+
|
|
435
490
|
/**
|
|
436
491
|
* Knowledge source citation
|
|
437
492
|
*/
|
|
@@ -441,6 +496,32 @@ export declare interface AgoSource {
|
|
|
441
496
|
url?: string;
|
|
442
497
|
}
|
|
443
498
|
|
|
499
|
+
/**
|
|
500
|
+
* A single editable control on the current page (a filter, a sort, a view mode,
|
|
501
|
+
* a selection…). It becomes one optional property of the synthesized
|
|
502
|
+
* `setPageState` function, and its current value is surfaced back to the agent
|
|
503
|
+
* as dynamic context. This is the state-mutation mirror of a navigation route.
|
|
504
|
+
*/
|
|
505
|
+
export declare interface AgoStateControl<T = unknown> {
|
|
506
|
+
/** Machine name of the control, e.g. "statusFilter". Becomes a property of the tool. */
|
|
507
|
+
name: string;
|
|
508
|
+
/** Description for the LLM, e.g. "Filter the list by review status". */
|
|
509
|
+
description: string;
|
|
510
|
+
/** JSON schema for a SINGLE field (like one property of navigateToPage). */
|
|
511
|
+
schema: {
|
|
512
|
+
type: "string" | "number" | "boolean" | "array";
|
|
513
|
+
enum?: (string | number)[];
|
|
514
|
+
items?: {
|
|
515
|
+
type: string;
|
|
516
|
+
enum?: (string | number)[];
|
|
517
|
+
};
|
|
518
|
+
};
|
|
519
|
+
/** Current value → pushed as dynamic context so the agent knows what to change. */
|
|
520
|
+
get?: () => T;
|
|
521
|
+
/** Apply the state change on the page. May be async. */
|
|
522
|
+
set: (value: T) => void | Promise<void>;
|
|
523
|
+
}
|
|
524
|
+
|
|
444
525
|
/**
|
|
445
526
|
* SSE stream error
|
|
446
527
|
*
|
|
@@ -602,7 +683,11 @@ export declare interface ClientFunctionSchema {
|
|
|
602
683
|
properties: Record<string, {
|
|
603
684
|
type: string;
|
|
604
685
|
description?: string;
|
|
605
|
-
enum?: string[];
|
|
686
|
+
enum?: (string | number)[];
|
|
687
|
+
items?: {
|
|
688
|
+
type: string;
|
|
689
|
+
enum?: (string | number)[];
|
|
690
|
+
};
|
|
606
691
|
default?: unknown;
|
|
607
692
|
}>;
|
|
608
693
|
required?: string[];
|
|
@@ -1325,6 +1410,13 @@ export declare interface SendMessageOptions {
|
|
|
1325
1410
|
agentId?: string;
|
|
1326
1411
|
/** File attachments */
|
|
1327
1412
|
files?: File[];
|
|
1413
|
+
/**
|
|
1414
|
+
* Mark this message as hidden. The backend keeps it in the model's context but
|
|
1415
|
+
* flags it so the UI never displays it. Used by auto-continuation to nudge the
|
|
1416
|
+
* agent after a navigation without polluting the visible transcript.
|
|
1417
|
+
* Requires backend support for the `hidden` flag; older backends ignore it.
|
|
1418
|
+
*/
|
|
1419
|
+
hidden?: boolean;
|
|
1328
1420
|
}
|
|
1329
1421
|
|
|
1330
1422
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -157,6 +157,12 @@ export declare class AgoClient {
|
|
|
157
157
|
getRegisteredFunctions(): ClientFunctionSchema[];
|
|
158
158
|
/**
|
|
159
159
|
* Register a navigation function that lets AGO navigate users to different pages.
|
|
160
|
+
*
|
|
161
|
+
* Also registers a dynamic context entry (`current-page`) that reports the page
|
|
162
|
+
* the user is currently on, by route name, on every message. This is what lets
|
|
163
|
+
* the agent know *where* it is after it navigates (e.g. so auto-continuation
|
|
164
|
+
* can apply page state on the destination), not just how to navigate away.
|
|
165
|
+
*
|
|
160
166
|
* @param navigate - A callback that performs the navigation (e.g. react-router's navigate)
|
|
161
167
|
* @param routes - Map of route names to paths, with descriptions for the LLM
|
|
162
168
|
*/
|
|
@@ -165,6 +171,41 @@ export declare class AgoClient {
|
|
|
165
171
|
path: string;
|
|
166
172
|
description: string;
|
|
167
173
|
}>): void;
|
|
174
|
+
/**
|
|
175
|
+
* Unregister the navigation function and its `current-page` context provider.
|
|
176
|
+
*/
|
|
177
|
+
unregisterNavigationFunction(): void;
|
|
178
|
+
/**
|
|
179
|
+
* Register a "page state" function that lets AGO change the current page's
|
|
180
|
+
* state (filters, sort, view mode, selection…) and reads the current state
|
|
181
|
+
* back as dynamic context. This is the state-mutation mirror of
|
|
182
|
+
* {@link registerNavigationFunction}.
|
|
183
|
+
*
|
|
184
|
+
* It does two things:
|
|
185
|
+
* - Synthesizes ONE client function (default name `setPageState`) whose
|
|
186
|
+
* properties are the controls — all optional, so the agent sets only the
|
|
187
|
+
* ones the user asked for.
|
|
188
|
+
* - Registers a dynamic context provider (keyed `page-state:<fnName>`) that
|
|
189
|
+
* reports each control's current `get()` value on every message.
|
|
190
|
+
*
|
|
191
|
+
* ```ts
|
|
192
|
+
* client.registerPageStateFunction([
|
|
193
|
+
* {
|
|
194
|
+
* name: "statusFilter",
|
|
195
|
+
* description: "Filter the list by review status",
|
|
196
|
+
* schema: { type: "string", enum: ["all", "pending", "approved"] },
|
|
197
|
+
* get: () => filters.status,
|
|
198
|
+
* set: (v) => setFilters({ ...filters, status: v }),
|
|
199
|
+
* },
|
|
200
|
+
* ]);
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
|
|
204
|
+
/**
|
|
205
|
+
* Unregister a page state function and its dynamic context provider.
|
|
206
|
+
* Mirror of unregistering `navigateToPage`.
|
|
207
|
+
*/
|
|
208
|
+
unregisterPageStateFunction(functionName?: string): void;
|
|
168
209
|
/**
|
|
169
210
|
* Register or update a piece of client-side context.
|
|
170
211
|
* This context is sent with every message so the AI understands the user's situation.
|
|
@@ -421,6 +462,12 @@ export declare interface AgoMessage {
|
|
|
421
462
|
followUpReplies?: string[];
|
|
422
463
|
/** Uploaded files on this message (usually the user's). */
|
|
423
464
|
attachments?: AgoAttachment[];
|
|
465
|
+
/**
|
|
466
|
+
* True when the backend flagged this message as hidden (e.g. an
|
|
467
|
+
* auto-continuation nudge). Kept in the model's context but not displayed;
|
|
468
|
+
* UI helpers like `useMessages`/`ChatWidget` filter these out.
|
|
469
|
+
*/
|
|
470
|
+
hidden?: boolean;
|
|
424
471
|
createdAt: Date;
|
|
425
472
|
}
|
|
426
473
|
|
|
@@ -432,6 +479,14 @@ export declare class AgoNetworkError extends AgoError {
|
|
|
432
479
|
constructor(message: string, originalError?: Error | undefined);
|
|
433
480
|
}
|
|
434
481
|
|
|
482
|
+
/**
|
|
483
|
+
* Options for {@link AgoClient.registerPageStateFunction}.
|
|
484
|
+
*/
|
|
485
|
+
export declare interface AgoPageStateOptions {
|
|
486
|
+
/** Name of the synthesized client function. Defaults to "setPageState". */
|
|
487
|
+
functionName?: string;
|
|
488
|
+
}
|
|
489
|
+
|
|
435
490
|
/**
|
|
436
491
|
* Knowledge source citation
|
|
437
492
|
*/
|
|
@@ -441,6 +496,32 @@ export declare interface AgoSource {
|
|
|
441
496
|
url?: string;
|
|
442
497
|
}
|
|
443
498
|
|
|
499
|
+
/**
|
|
500
|
+
* A single editable control on the current page (a filter, a sort, a view mode,
|
|
501
|
+
* a selection…). It becomes one optional property of the synthesized
|
|
502
|
+
* `setPageState` function, and its current value is surfaced back to the agent
|
|
503
|
+
* as dynamic context. This is the state-mutation mirror of a navigation route.
|
|
504
|
+
*/
|
|
505
|
+
export declare interface AgoStateControl<T = unknown> {
|
|
506
|
+
/** Machine name of the control, e.g. "statusFilter". Becomes a property of the tool. */
|
|
507
|
+
name: string;
|
|
508
|
+
/** Description for the LLM, e.g. "Filter the list by review status". */
|
|
509
|
+
description: string;
|
|
510
|
+
/** JSON schema for a SINGLE field (like one property of navigateToPage). */
|
|
511
|
+
schema: {
|
|
512
|
+
type: "string" | "number" | "boolean" | "array";
|
|
513
|
+
enum?: (string | number)[];
|
|
514
|
+
items?: {
|
|
515
|
+
type: string;
|
|
516
|
+
enum?: (string | number)[];
|
|
517
|
+
};
|
|
518
|
+
};
|
|
519
|
+
/** Current value → pushed as dynamic context so the agent knows what to change. */
|
|
520
|
+
get?: () => T;
|
|
521
|
+
/** Apply the state change on the page. May be async. */
|
|
522
|
+
set: (value: T) => void | Promise<void>;
|
|
523
|
+
}
|
|
524
|
+
|
|
444
525
|
/**
|
|
445
526
|
* SSE stream error
|
|
446
527
|
*
|
|
@@ -602,7 +683,11 @@ export declare interface ClientFunctionSchema {
|
|
|
602
683
|
properties: Record<string, {
|
|
603
684
|
type: string;
|
|
604
685
|
description?: string;
|
|
605
|
-
enum?: string[];
|
|
686
|
+
enum?: (string | number)[];
|
|
687
|
+
items?: {
|
|
688
|
+
type: string;
|
|
689
|
+
enum?: (string | number)[];
|
|
690
|
+
};
|
|
606
691
|
default?: unknown;
|
|
607
692
|
}>;
|
|
608
693
|
required?: string[];
|
|
@@ -1325,6 +1410,13 @@ export declare interface SendMessageOptions {
|
|
|
1325
1410
|
agentId?: string;
|
|
1326
1411
|
/** File attachments */
|
|
1327
1412
|
files?: File[];
|
|
1413
|
+
/**
|
|
1414
|
+
* Mark this message as hidden. The backend keeps it in the model's context but
|
|
1415
|
+
* flags it so the UI never displays it. Used by auto-continuation to nudge the
|
|
1416
|
+
* agent after a navigation without polluting the visible transcript.
|
|
1417
|
+
* Requires backend support for the `hidden` flag; older backends ignore it.
|
|
1418
|
+
*/
|
|
1419
|
+
hidden?: boolean;
|
|
1328
1420
|
}
|
|
1329
1421
|
|
|
1330
1422
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as h, c as A, d as y, f as C, i as E, l as S, m as b, o as v, p as F, r as M, s as I, t as k, u as T } from "./functions-CApuQZ2b.js";
|
|
2
|
-
import { _ as G, a as O, c as _, d as q, f as x, g as L, h as N, l as D, m as d, n as H, o as J, p as R, r as j, s as z, t as c, u as B } from "./AgoClient-
|
|
3
|
-
import { i as $, n as K, r as Q, t as V } from "./createFormCollector-
|
|
4
|
-
import { t as X } from "./createConversationSession-
|
|
5
|
-
import { t as Z } from "./createMockClient-
|
|
2
|
+
import { _ as G, a as O, c as _, d as q, f as x, g as L, h as N, l as D, m as d, n as H, o as J, p as R, r as j, s as z, t as c, u as B } from "./AgoClient-BdtuHX7k.js";
|
|
3
|
+
import { i as $, n as K, r as Q, t as V } from "./createFormCollector-B4n0_diV.js";
|
|
4
|
+
import { t as X } from "./createConversationSession-CWpf4u6I.js";
|
|
5
|
+
import { t as Z } from "./createMockClient-d-arlmCq.js";
|
|
6
6
|
import "./testing.js";
|
|
7
7
|
function oe(e) {
|
|
8
8
|
return e;
|
package/dist/react.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`)?(0,
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("./rolldown-runtime-16Nf8qvH.cjs"),F=require("./AgoClient-CRAnT4qE.cjs"),M=require("./createFormCollector-BB_l0Sia.cjs"),G=require("./createMockClient-ucPENDzz.cjs");let s=require("react");s=T.__toESM(s,1);let o=require("react/jsx-runtime"),_=require("react-markdown");_=T.__toESM(_,1);let N=require("remark-gfm");N=T.__toESM(N,1);function H(e){const[t,r]=(0,s.useState)(!1),n=(0,s.useRef)(null),a=(0,s.useMemo)(()=>{if(n.current&&(n.current.destroy(),n.current=null),!e)return null;const l=new F.AgoClient(e);return n.current=l,l},[e?.baseUrl,e?.widgetId]);return(0,s.useEffect)(()=>(r(!0),()=>{n.current?.destroy(),n.current=null}),[a]),(0,s.useEffect)(()=>{n.current&&e&&n.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 D=(0,s.createContext)(null),Y=({children:e,client:t,tools:r,helpers:n,pageContext:a,...l})=>{const{client:d}=H(t?null:l),c=t||d;return(0,s.useEffect)(()=>{if(!(!r||r.length===0)){for(const p of r)c.register(p);return()=>{for(const p of r)c.unregisterFunction(p.name)}}},[c,r]),(0,s.useEffect)(()=>{if(!n)return;const p=[];return Promise.resolve().then(()=>require("./functions-Djnq-JAo.cjs")).then(u=>u.functions_exports).then(u=>{for(const[b,x]of Object.entries(n)){const y=u[b];if(!y){console.warn(`[AGO] Unknown helper: "${b}"`);continue}const h=x===!0?y:{...y,handler:x};c.register(h),p.push(h.name)}}),()=>{for(const u of p)c.unregisterFunction(u)}},[c,n]),(0,s.useEffect)(()=>{a==="auto"&&c.enableAutoPageContext()},[c,a]),(0,o.jsx)(D.Provider,{value:c,children:e})};function E(){const e=(0,s.useContext)(D);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,s.useContext)(D)}function z({client:e,conversationId:t}={}){const r=R(),n=e||r;if(!n)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(t),[p,u]=(0,s.useState)(!1),[b,x]=(0,s.useState)(null);(0,s.useEffect)(()=>{t&&t!==d&&(c(t),y(t))},[t]);const y=async h=>{try{l((await n.getMessages(h)).filter(m=>!m.hidden))}catch(m){x(m instanceof Error?m:new Error("Failed to load messages"))}};return(0,s.useEffect)(()=>{const h=g=>{d||c(g.conversationId)},m=g=>{l(f=>{const w=f[f.length-1];return w&&w.id===g.messageId?[...f.slice(0,-1),{...w,content:w.content+g.content}]:f})},C=g=>{l(f=>{let w=-1;for(let k=f.length-1;k>=0;k--)if(f[k].role==="assistant"&&f[k].status==="IN_PROGRESS"){w=k;break}return w<0?f:[...f.slice(0,w),{...f[w],...g},...f.slice(w+1)]})},v=g=>{l(f=>{const w=f.findIndex(k=>k.id===g.id);return w>=0?[...f.slice(0,w),g,...f.slice(w+1)]:[...f,g]}),u(!1)},i=g=>{x(new Error(g.error)),u(!1)};return n.on("message:start",h),n.on("message:chunk",m),n.on("message:answer-complete",C),n.on("message:complete",v),n.on("message:error",i),()=>{n.off("message:start",h),n.off("message:chunk",m),n.off("message:answer-complete",C),n.off("message:complete",v),n.off("message:error",i)}},[n,d]),{messages:a,isLoading:p,error:b,sendMessage:(0,s.useCallback)(async(h,m)=>{u(!0),x(null);const C={id:`temp-${Date.now()}`,conversationId:d||"",content:h,role:"user",status:"DONE",attachments:m&&m.length>0?F.attachmentsFromFiles(m):void 0,createdAt:new Date},v={id:`temp-assistant-${Date.now()}`,conversationId:d||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};l(i=>[...i,C,v]);try{const i=await n.sendMessage(h,{conversationId:d,files:m});return i.conversationId&&!d&&c(i.conversationId),l(g=>{const f=g.filter(k=>!k.id.startsWith("temp-")),w={...C,id:C.id.replace("temp-","user-"),conversationId:i.conversationId};return f.some(k=>k.id===i.id)?[...f,w].sort((k,P)=>new Date(k.createdAt).getTime()-new Date(P.createdAt).getTime()):[...f,w,i]}),i}catch(i){return x(i instanceof Error?i:new Error("Failed to send message")),u(!1),l(g=>g.filter(f=>!f.id.startsWith("temp-"))),null}},[n,d]),clearMessages:(0,s.useCallback)(()=>{l([]),c(void 0),x(null)},[]),conversationId:d}}var O=({onSend:e,disabled:t=!1,placeholder:r="Type a message...",allowFiles:n=!1,className:a=""})=>{const[l,d]=(0,s.useState)(""),[c,p]=(0,s.useState)([]),u=(0,s.useRef)(null),b=(0,s.useRef)(null),x=(0,s.useCallback)(()=>{const i=b.current;if(!i)return;const g=110;i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight+2,g)}px`,i.style.overflowY=i.scrollHeight+2>g?"auto":"hidden"},[]),y=(0,s.useCallback)(i=>{i.preventDefault(),(l.trim()||c.length>0)&&(e(l.trim(),c.length>0?c:void 0),d(""),p([]),requestAnimationFrame(x))},[l,c,e,x]),h=(0,s.useCallback)(i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),y(i))},[y]),m=(0,s.useCallback)(i=>{const g=Array.from(i.target.files||[]);p(f=>[...f,...g])},[]),C=(0,s.useCallback)(i=>{p(g=>g.filter((f,w)=>w!==i))},[]),v=l.trim()||c.length>0;return(0,o.jsxs)("form",{onSubmit:y,className:`ago-chat-input ${a}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[c.length>0&&(0,o.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:c.map((i,g)=>(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:i.name}),(0,o.jsx)("button",{type:"button",onClick:()=>C(g),"aria-label":`Remove ${i.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},g))}),(0,o.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[n&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("button",{type:"button",onClick:()=>u.current?.click(),disabled:t,"aria-label":"Attach file",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:u,type:"file",multiple:!0,onChange:m,style:{display:"none"}})]}),(0,o.jsx)("textarea",{ref:b,value:l,onChange:i=>{d(i.target.value),x()},onKeyDown:h,placeholder:r,"aria-label":r,disabled:t,rows:1,style:{flex:1,padding:"10px 14px",border:"1px solid #dee3e8",borderRadius:"20px",resize:"none",outline:"none",boxSizing:"border-box",maxHeight:"110px",overflowY:"hidden",fontFamily:"inherit",fontSize:"16px",lineHeight:1.4,color:"#30373e",backgroundColor:"#f8f8f8",transition:"border-color 0.15s"},onFocus:i=>{i.currentTarget.style.borderColor="#1b5fc4"},onBlur:i=>{i.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,...r})=>(0,o.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...r,children:t}),Q=({children:e,...t})=>(0,o.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...t,children:e}),A=(e,t)=>{const r=({children:n,...a})=>s.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:t,fontWeight:600,lineHeight:"1.3"},...a},n);return r.displayName=`MarkdownHeading${e}`,r},Z=({children:e,...t})=>(0,o.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...t,children:e}),ee=({children:e,...t})=>(0,o.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...t,children:e}),te=({children:e,...t})=>(0,o.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...t,children:e}),ne=({className:e,children:t,...r})=>e!==void 0||String(t).includes(`
|
|
2
|
+
`)?(0,o.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}):(0,o.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...r,children:t}),re=({children:e,...t})=>(0,o.jsx)("pre",{style:{margin:"0 0 8px 0"},...t,children:e}),oe=({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}),se=({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})}),ae=({children:e,...t})=>(0,o.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...t,children:e}),ie=({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}),ce=e=>(0,o.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),de={a:X,p:Q,h1:A(1,"20px"),h2:A(2,"18px"),h3:A(3,"16px"),h4:A(4,"15px"),h5:A(5,"14px"),h6:A(6,"13px"),ul:Z,ol:ee,li:te,code:ne,pre:re,blockquote:oe,table:se,th:ae,td:ie,img:le,hr:ce},ue=[N.default],q=({content:e})=>(0,o.jsx)(_.default,{remarkPlugins:ue,components:de,children:e}),fe=({attachment:e,isUser:t})=>{const r=F.safeAttachmentUrl(e.url);if(F.canInlineImage(e))return(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,o.jsx)("img",{src:r,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const n=F.formatFileSize(e.fileSize),a=(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,o.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,o.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),n&&(0,o.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:n})]})]}),l={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:t?"rgba(255,255,255,0.12)":"#fff",color:t?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return r?(0,o.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",style:l,children:a}):(0,o.jsx)("div",{style:l,children:a})},ge=({source:e,index:t})=>{const r=(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})]}),n={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:n,onMouseEnter:a=>{a.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:a=>{a.currentTarget.style.borderColor="#dee3e8"},children:r}):(0,o.jsx)("div",{style:n,children:r})},pe=()=>(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); }
|
|
5
5
|
40% { opacity: 1; transform: scale(1); }
|
|
6
6
|
}
|
|
7
|
-
`})]}),O=({message:e,className:t="",showAgentName:o=!1,isLast:n=!1,onFollowUpClick:a})=>{const i=e.role==="user",f=e.status==="IN_PROGRESS";return(0,r.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&o&&e.agent&&(0,r.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!i&&e.sources&&e.sources.length>0&&(0,r.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((c,g)=>(0,r.jsx)(fe,{source:c,index:g},c.id))}),e.attachments&&e.attachments.length>0&&(0,r.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:i?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(c=>(0,r.jsx)(ue,{attachment:c,isUser:i},c.id))}),(e.content||f)&&(0,r.jsx)("div",{className:"ago-message__content",style:{maxWidth:i?"75%":"100%",padding:i?"10px 14px":"2px 8px",borderRadius:i?"16px":"0",backgroundColor:i?"#03182f":"transparent",color:i?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,r.jsx)(q,{content:e.content}):f&&(0,r.jsx)(pe,{})}),n&&e.followUpReplies&&e.followUpReplies.length>0&&(0,r.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,g)=>(0,r.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(c):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:u=>{u.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:u=>{u.currentTarget.style.borderColor="#dee3e8"},children:c},g))})]})},ge=({client:e,conversationId:t,title:o="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:i=!1,height:f=500,logoUrl:c,showAgentName:g=!1,forms:u,onFollowUpClick:v,className:m="",onMessageSent:S,onMessageReceived:x})=>{const h=(0,s.useRef)(null),C=_(),w=e??C,{messages:l,isLoading:p,error:d,sendMessage:y}=W({client:e,conversationId:t});(0,s.useEffect)(()=>{if(!w||!u||u.length===0)return;let b=!1;const E=[];return Promise.all(u.map(M=>M.schema!=null?Promise.resolve(j.createFormCollector(M)):j.loadFormCollector(w,M))).then(M=>{if(!b)for(const J of M)E.push(J.install(w))}).catch(()=>{}),()=>{b=!0,E.forEach(M=>M())}},[w,u?JSON.stringify(u.map(b=>[b.name,b.schema??null,b.submit??!1,b.description??null])):""]),(0,s.useEffect)(()=>{h.current?.scrollIntoView({behavior:"smooth"})},[l]),(0,s.useEffect)(()=>{const b=l[l.length-1];b&&b.role==="assistant"&&b.status==="DONE"&&x&&x({id:b.id,content:b.content})},[l,x]);const k=async(b,E)=>{S?.(b),await y(b,E)},F=l[l.length-1],K=p&&F?.role==="assistant"&&F.status==="IN_PROGRESS",U=v===!1?void 0:v??(b=>k(b));return(0,r.jsxs)("div",{className:`ago-chat-widget ${m}`,style:{display:"flex",flexDirection:"column",height:typeof f=="number"?`${f}px`:f,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,r.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[c&&(0,r.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,r.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:o})]}),(0,r.jsxs)("div",{className:"ago-chat-widget__messages",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[l.length===0?(0,r.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:n}):l.map((b,E)=>(0,r.jsx)(O,{message:b,showAgentName:g,isLast:E===l.length-1,onFollowUpClick:U},b.id)),d&&(0,r.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:d.message}),(0,r.jsx)("div",{ref:h})]}),(0,r.jsx)(L,{onSend:k,disabled:K,placeholder:a,allowFiles:i})]})};function $({client:e,autoLoad:t=!0}={}){const o=_(),n=e||o;if(!n)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,i]=(0,s.useState)([]),[f,c]=(0,s.useState)(null),[g,u]=(0,s.useState)(!1),[v,m]=(0,s.useState)(null),S=(0,s.useCallback)(async()=>{u(!0),m(null);try{i(await n.getConversations())}catch(C){m(C instanceof Error?C:new Error("Failed to load conversations"))}finally{u(!1)}},[n]),x=(0,s.useCallback)(async C=>{u(!0),m(null);try{c(await n.getConversation(C))}catch(w){m(w instanceof Error?w:new Error("Failed to load conversation"))}finally{u(!1)}},[n]),h=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{t&&S()},[t,S]),{conversations:a,currentConversation:f,isLoading:g,error:v,selectConversation:x,startNewConversation:h,refreshConversations:S}}function xe(e={}){const t=_(),o=e.client||t;if(!o)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const n=W({client:o,conversationId:e.conversationId}),a=$({client:o,autoLoad:e.autoLoad});return{messages:n.messages,isLoading:n.isLoading,error:n.error||a.error,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function me(e,t){const o=A(),{name:n,description:a,parameters:i,handler:f}=typeof e=="string"?{name:e,...t}:e,c=(0,s.useRef)(f);c.current=f,(0,s.useEffect)(()=>{const g=u=>c.current(u);return o.registerFunction(n,g,{description:a,parameters:i}),()=>{o.unregisterFunction(n)}},[o,n,a,i])}function he(e,t){const o=A(),n=(0,s.useRef)(e);n.current=e,(0,s.useEffect)(()=>(o.registerNavigationFunction(a=>n.current(a),t),()=>{o.unregisterFunction("navigateToPage")}),[o,t])}function ye(e,t){const o=A(),n=(0,s.useId)(),a=t??n,i=(0,s.useRef)(e);i.current=e;const f=typeof e=="function";(0,s.useEffect)(()=>{if(typeof i.current=="function"){const c=()=>i.current();return o.addDynamicContext(a,c),()=>{o.removeDynamicContext(a)}}return o.setContext(a,i.current),()=>{o.removeContext(a)}},[o,a,f,f?"":JSON.stringify(e)])}function B(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var D={missing:[],complete:!1};function be(e){const t=A(),o=e.schema!=null,n=JSON.stringify(e.schema??null),a=e.submit,i=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",f=JSON.stringify(e.initialValues??null),c=(0,s.useMemo)(()=>o?j.createFormCollector(e):null,[o,e.name,n,i,f,e.autoSubmit]),[g,u]=(0,s.useState)({collector:null,loading:!o,error:null});(0,s.useEffect)(()=>{if(o)return;let p=!1;return u({collector:null,loading:!0,error:null}),j.loadFormCollector(t,e).then(d=>{p||u({collector:d,loading:!1,error:null})}).catch(d=>{p||u({collector:null,loading:!1,error:d instanceof Error?d:new Error(String(d))})}),()=>{p=!0}},[t,o,e.name,i,f,e.autoSubmit]);const v=o?c:g.collector,m=o?!1:g.loading,S=o?null:g.error;(0,s.useEffect)(()=>{if(v)return v.install(t)},[t,v]);const x=(0,s.useMemo)(()=>j.createStore({values:e.initialValues??{},submitted:!1}),[f]),h=B(v?.store??x),C=(0,s.useMemo)(()=>v?.getStatus()??D,[h,v]),w=(0,s.useMemo)(()=>({...h,...C}),[h,C]),l=(0,s.useMemo)(()=>({name:e.name,store:x,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>x.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>D}),[e.name,x]);return{...v??l,state:w,loading:m,error:S}}exports.AgoProvider=G;exports.ChatInput=L;exports.ChatWidget=ge;exports.Markdown=q;exports.Message=O;exports.createFormCollector=j.createFormCollector;exports.createMockClient=V.createMockClient;exports.deriveFormStatus=j.deriveFormStatus;exports.loadFormCollector=j.loadFormCollector;exports.useAgo=H;exports.useAgoClient=A;exports.useAgoContext=ye;exports.useAgoFunction=me;exports.useAgoNavigation=he;exports.useAgoStore=B;exports.useChat=xe;exports.useConversation=$;exports.useFormCollector=be;exports.useMessages=W;exports.useOptionalAgoClient=_;
|
|
7
|
+
`})]}),$=({message:e,className:t="",showAgentName:r=!1,isLast:n=!1,onFollowUpClick:a})=>{const l=e.role==="user",d=e.status==="IN_PROGRESS";return(0,o.jsxs)("div",{className:`ago-message ago-message--${e.role} ${t}`,style:{display:"flex",flexDirection:"column",alignItems:l?"flex-end":"flex-start",marginBottom:"16px"},children:[!l&&r&&e.agent&&(0,o.jsx)("div",{className:"ago-message__agent",style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"13px",fontWeight:500,color:"#30373e",marginBottom:"6px",padding:"0 4px"},children:e.agent.displayName||e.agent.name}),!l&&e.sources&&e.sources.length>0&&(0,o.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((c,p)=>(0,o.jsx)(ge,{source:c,index:p},c.id))}),e.attachments&&e.attachments.length>0&&(0,o.jsx)("div",{className:"ago-message__attachments",style:{display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:l?"flex-end":"flex-start",maxWidth:"75%"},children:e.attachments.map(c=>(0,o.jsx)(fe,{attachment:c,isUser:l},c.id))}),(e.content||d)&&(0,o.jsx)("div",{className:"ago-message__content",style:{maxWidth:l?"75%":"100%",padding:l?"10px 14px":"2px 8px",borderRadius:l?"16px":"0",backgroundColor:l?"#03182f":"transparent",color:l?"#fff":"#30373e",wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"},children:e.content?(0,o.jsx)(q,{content:e.content}):d&&(0,o.jsx)(pe,{})}),n&&e.followUpReplies&&e.followUpReplies.length>0&&(0,o.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((c,p)=>(0,o.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!a,onClick:a?()=>a(c):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:a?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:u=>{u.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:u=>{u.currentTarget.style.borderColor="#dee3e8"},children:c},p))})]})},xe=({client:e,conversationId:t,title:r="Chat",welcomeMessage:n="Hello! How can I help you today?",placeholder:a="Type a message...",allowFiles:l=!1,height:d=500,logoUrl:c,showAgentName:p=!1,forms:u,onFollowUpClick:b,className:x="",onMessageSent:y,onMessageReceived:h})=>{const m=(0,s.useRef)(null),C=R(),v=e??C,{messages:i,isLoading:g,error:f,sendMessage:w}=z({client:e,conversationId:t});(0,s.useEffect)(()=>{if(!v||!u||u.length===0)return;let S=!1;const I=[];return Promise.all(u.map(j=>j.schema!=null?Promise.resolve(M.createFormCollector(j)):M.loadFormCollector(v,j))).then(j=>{if(!S)for(const V of j)I.push(V.install(v))}).catch(()=>{}),()=>{S=!0,I.forEach(j=>j())}},[v,u?JSON.stringify(u.map(S=>[S.name,S.schema??null,S.submit??!1,S.description??null])):""]),(0,s.useEffect)(()=>{m.current?.scrollIntoView({behavior:"smooth"})},[i]),(0,s.useEffect)(()=>{const S=i[i.length-1];S&&S.role==="assistant"&&S.status==="DONE"&&h&&h({id:S.id,content:S.content})},[i,h]);const k=async(S,I)=>{y?.(S),await w(S,I)},P=i[i.length-1],K=g&&P?.role==="assistant"&&P.status==="IN_PROGRESS",J=b===!1?void 0:b??(S=>k(S));return(0,o.jsxs)("div",{className:`ago-chat-widget ${x}`,style:{display:"flex",flexDirection:"column",height:typeof d=="number"?`${d}px`:d,border:"1px solid #dee3e8",borderRadius:"16px",overflow:"hidden",backgroundColor:"#fff",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"},children:[(0,o.jsxs)("div",{className:"ago-chat-widget__header",style:{padding:"14px 16px",borderBottom:"1px solid #dee3e8",backgroundColor:"#03182f",color:"#e8f0fe",display:"flex",alignItems:"center",gap:"10px"},children:[c&&(0,o.jsx)("img",{src:c,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,o.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:r})]}),(0,o.jsxs)("div",{className:"ago-chat-widget__messages",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":!1,style:{flex:1,overflow:"auto",padding:"16px",backgroundColor:"#fbfbfb"},children:[i.length===0?(0,o.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:n}):i.map((S,I)=>(0,o.jsx)($,{message:S,showAgentName:p,isLast:I===i.length-1,onFollowUpClick:J},S.id)),f&&(0,o.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:f.message}),(0,o.jsx)("div",{ref:m})]}),(0,o.jsx)(O,{onSend:k,disabled:K,placeholder:a,allowFiles:l})]})};function B({client:e,autoLoad:t=!0}={}){const r=R(),n=e||r;if(!n)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[a,l]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[p,u]=(0,s.useState)(!1),[b,x]=(0,s.useState)(null),y=(0,s.useCallback)(async()=>{u(!0),x(null);try{l(await n.getConversations())}catch(C){x(C instanceof Error?C:new Error("Failed to load conversations"))}finally{u(!1)}},[n]),h=(0,s.useCallback)(async C=>{u(!0),x(null);try{c(await n.getConversation(C))}catch(v){x(v instanceof Error?v:new Error("Failed to load conversation"))}finally{u(!1)}},[n]),m=(0,s.useCallback)(()=>{c(null)},[]);return(0,s.useEffect)(()=>{t&&y()},[t,y]),{conversations:a,currentConversation:d,isLoading:p,error:b,selectConversation:h,startNewConversation:m,refreshConversations:y}}function me(e={}){const t=R(),r=e.client||t;if(!r)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const n=z({client:r,conversationId:e.conversationId}),a=B({client:r,autoLoad:e.autoLoad});return{messages:n.messages,isLoading:n.isLoading,error:n.error||a.error,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:a.conversations,currentConversation:a.currentConversation,isConversationsLoading:a.isLoading,selectConversation:a.selectConversation,startNewConversation:a.startNewConversation,refreshConversations:a.refreshConversations}}function he(e,t){const r=E(),{name:n,description:a,parameters:l,handler:d}=typeof e=="string"?{name:e,...t}:e,c=(0,s.useRef)(d);c.current=d,(0,s.useEffect)(()=>{const p=u=>c.current(u);return r.registerFunction(n,p,{description:a,parameters:l}),()=>{r.unregisterFunction(n)}},[r,n,a,l])}function ye(e,t){const r=E(),n=(0,s.useRef)(e);n.current=e,(0,s.useEffect)(()=>(r.registerNavigationFunction(a=>n.current(a),t),()=>{r.unregisterNavigationFunction()}),[r,t])}function be(e,t){const r=E(),n=t?.functionName??"setPageState",a=(0,s.useRef)(e);a.current=e,(0,s.useEffect)(()=>{const l=a.current.map(d=>{const c=()=>a.current.find(p=>p.name===d.name)??d;return{name:d.name,description:d.description,schema:d.schema,get:d.get?()=>c().get?.():void 0,set:p=>c().set(p)}});return r.registerPageStateFunction(l,{functionName:n}),()=>{r.unregisterPageStateFunction(n)}},[r,n])}var ve="You have navigated the user to a new page. That page now exposes its editable state through the available setPageState function, and its current values in the page context. If the user's latest request also asked to change something on this page, call setPageState now to apply exactly those changes and nothing else. Otherwise, reply with a short confirmation only.";function W(e){return{navigationFunctions:e?.navigationFunctions??["navigateToPage"],pageStateFunctionName:e?.pageStateFunctionName??"setPageState",continuationPrompt:e?.continuationPrompt??ve,maxDepth:e?.maxDepth??1,readinessTimeoutMs:e?.readinessTimeoutMs??4e3,settleMs:e?.settleMs??150,enabled:e?.enabled??!0}}function Ce(e){const t=E(),r=(0,s.useRef)(W(e));r.current=W(e),(0,s.useEffect)(()=>{const n={navigated:!1,depth:0,runId:0,ourSendPending:!1},a=()=>t.getRegisteredFunctions().some(x=>x.name===r.current.pageStateFunctionName),l=x=>new Promise(y=>{let h=!1;const m=g=>{h||(h=!0,clearTimeout(i),t.off("context:changed",v),y(g))},C=()=>setTimeout(()=>m(x===n.runId&&a()),r.current.settleMs),v=()=>{if(x!==n.runId)return m(!1);a()&&(t.off("context:changed",v),C())},i=setTimeout(()=>m(!1),r.current.readinessTimeoutMs);a()?C():t.on("context:changed",v)}),d=async x=>{const y=++n.runId;if(!(!await l(y)||y!==n.runId)){n.depth+=1,n.ourSendPending=!0;try{await t.sendMessage(r.current.continuationPrompt,{conversationId:x,hidden:!0})}catch{n.ourSendPending=!1}}},c=x=>{r.current.navigationFunctions.includes(x.functionName)&&(n.navigated=!0)},p=()=>{n.ourSendPending||(n.depth=0,n.runId+=1)},u=x=>{n.ourSendPending=!1;const y=n.navigated;n.navigated=!1,r.current.enabled&&y&&(n.depth>=r.current.maxDepth||d(x.conversationId))},b=()=>{n.ourSendPending=!1};return t.on("function:invoke",c),t.on("message:start",p),t.on("message:complete",u),t.on("message:error",b),()=>{n.runId+=1,t.off("function:invoke",c),t.off("message:start",p),t.off("message:complete",u),t.off("message:error",b)}},[t])}function we(e,t){const r=E(),n=(0,s.useId)(),a=t??n,l=(0,s.useRef)(e);l.current=e;const d=typeof e=="function";(0,s.useEffect)(()=>{if(typeof l.current=="function"){const c=()=>l.current();return r.addDynamicContext(a,c),()=>{r.removeDynamicContext(a)}}return r.setContext(a,l.current),()=>{r.removeContext(a)}},[r,a,d,d?"":JSON.stringify(e)])}function U(e){return(0,s.useSyncExternalStore)(e.subscribe,e.get,e.get)}var L={missing:[],complete:!1};function Se(e){const t=E(),r=e.schema!=null,n=JSON.stringify(e.schema??null),a=e.submit,l=a?typeof a=="string"?`client:${a}`:a.via==="backend"?"backend":"handler"in a?"client:handler":`client:${a.url}`:"none",d=JSON.stringify(e.initialValues??null),c=(0,s.useMemo)(()=>r?M.createFormCollector(e):null,[r,e.name,n,l,d,e.autoSubmit]),[p,u]=(0,s.useState)({collector:null,loading:!r,error:null});(0,s.useEffect)(()=>{if(r)return;let g=!1;return u({collector:null,loading:!0,error:null}),M.loadFormCollector(t,e).then(f=>{g||u({collector:f,loading:!1,error:null})}).catch(f=>{g||u({collector:null,loading:!1,error:f instanceof Error?f:new Error(String(f))})}),()=>{g=!0}},[t,r,e.name,l,d,e.autoSubmit]);const b=r?c:p.collector,x=r?!1:p.loading,y=r?null:p.error;(0,s.useEffect)(()=>{if(b)return b.install(t)},[t,b]);const h=(0,s.useMemo)(()=>M.createStore({values:e.initialValues??{},submitted:!1}),[d]),m=U(b?.store??h),C=(0,s.useMemo)(()=>b?.getStatus()??L,[m,b]),v=(0,s.useMemo)(()=>({...m,...C}),[m,C]),i=(0,s.useMemo)(()=>({name:e.name,store:h,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>h.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>L}),[e.name,h]);return{...b??i,state:v,loading:x,error:y}}exports.AgoProvider=Y;exports.ChatInput=O;exports.ChatWidget=xe;exports.Markdown=q;exports.Message=$;exports.createFormCollector=M.createFormCollector;exports.createMockClient=G.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=H;exports.useAgoAutoContinueAfterNavigation=Ce;exports.useAgoClient=E;exports.useAgoContext=we;exports.useAgoFunction=he;exports.useAgoNavigation=ye;exports.useAgoPageState=be;exports.useAgoStore=U;exports.useChat=me;exports.useConversation=B;exports.useFormCollector=Se;exports.useMessages=z;exports.useOptionalAgoClient=R;
|