@useago/sdk 1.5.4 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/{AgoClient-BW0YZsis.js → AgoClient-BI5esqbd.js} +25 -12
- package/dist/{AgoClient-Ba3ICq4K.cjs → AgoClient-CQh8YovA.cjs} +4 -4
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +29 -3
- package/dist/angular.d.ts +29 -3
- package/dist/angular.js +2 -2
- package/dist/{createConversationSession-okoz3teC.cjs → createConversationSession-0zVkMdYj.cjs} +1 -1
- package/dist/{createConversationSession-BjsgjL-v.js → createConversationSession-BlYTpxwz.js} +1 -1
- package/dist/{createFormCollector-Bay2UpRv.js → createFormCollector-Bgs94NyR.js} +1 -1
- package/dist/{createFormCollector-BWIh1pMl.cjs → createFormCollector-DiCe_8ik.cjs} +1 -1
- package/dist/devtools.d.cts +28 -2
- package/dist/devtools.d.ts +28 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +36 -2
- package/dist/index.d.ts +36 -2
- package/dist/index.js +3 -3
- package/dist/react.cjs +2 -2
- package/dist/react.d.cts +28 -2
- package/dist/react.d.ts +28 -2
- package/dist/react.js +107 -106
- package/dist/testing.d.cts +28 -2
- package/dist/testing.d.ts +28 -2
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +28 -2
- package/dist/vue.d.ts +28 -2
- package/dist/vue.js +2 -2
- package/dist/widget.cjs +2 -2
- package/dist/widget.d.cts +28 -2
- package/dist/widget.d.ts +28 -2
- package/dist/widget.js +4 -4
- package/package.json +1 -1
package/dist/devtools.d.cts
CHANGED
|
@@ -140,9 +140,14 @@ declare class AgoClient {
|
|
|
140
140
|
*/
|
|
141
141
|
rejectFunction(invocationId: string): Promise<void>;
|
|
142
142
|
/**
|
|
143
|
-
* Get
|
|
143
|
+
* Get a page of conversations, newest-first. `pageSize` is capped at 100 by
|
|
144
|
+
* the backend (default 50). Returns the `{ data, has_more, total }` envelope
|
|
145
|
+
* so callers can page; `total` counts across all pages.
|
|
144
146
|
*/
|
|
145
|
-
getConversations(
|
|
147
|
+
getConversations(options?: {
|
|
148
|
+
page?: number;
|
|
149
|
+
pageSize?: number;
|
|
150
|
+
}): Promise<PaginatedResult<Conversation>>;
|
|
146
151
|
/**
|
|
147
152
|
* Get a specific conversation with messages
|
|
148
153
|
*/
|
|
@@ -488,6 +493,15 @@ declare interface AgoClientEvents {
|
|
|
488
493
|
* notably `createFormCollector` — can replay them to restore their state.
|
|
489
494
|
*/
|
|
490
495
|
"conversation:loaded": Conversation;
|
|
496
|
+
/**
|
|
497
|
+
* The conversation's title was generated and streamed during a live turn
|
|
498
|
+
* (the backend emits it once, at the end of the first turn). Lets the UI
|
|
499
|
+
* update a header without a refetch.
|
|
500
|
+
*/
|
|
501
|
+
"conversation:title": {
|
|
502
|
+
conversationId: string;
|
|
503
|
+
title: string;
|
|
504
|
+
};
|
|
491
505
|
"toolCall:received": ToolCallData;
|
|
492
506
|
"toolCall:form": ToolCallData;
|
|
493
507
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -1028,6 +1042,16 @@ declare type NudgeAction = {
|
|
|
1028
1042
|
setPageState: Record<string, unknown>;
|
|
1029
1043
|
};
|
|
1030
1044
|
|
|
1045
|
+
/**
|
|
1046
|
+
* A page of list results, mirroring the API's `{ data, has_more, total }`
|
|
1047
|
+
* envelope. `total` is the count across all pages, not just this page.
|
|
1048
|
+
*/
|
|
1049
|
+
declare interface PaginatedResult<T> {
|
|
1050
|
+
data: T[];
|
|
1051
|
+
hasMore: boolean;
|
|
1052
|
+
total: number;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1031
1055
|
/**
|
|
1032
1056
|
* Controller returned by {@link createAgoProactive} (also available as
|
|
1033
1057
|
* `client.proactive`).
|
|
@@ -1280,6 +1304,8 @@ declare interface SSEChunkData {
|
|
|
1280
1304
|
thread?: {
|
|
1281
1305
|
id: string;
|
|
1282
1306
|
};
|
|
1307
|
+
/** Generated conversation title, streamed once at the end of the first turn. */
|
|
1308
|
+
title?: string;
|
|
1283
1309
|
agent?: {
|
|
1284
1310
|
id: string;
|
|
1285
1311
|
name: string;
|
package/dist/devtools.d.ts
CHANGED
|
@@ -140,9 +140,14 @@ declare class AgoClient {
|
|
|
140
140
|
*/
|
|
141
141
|
rejectFunction(invocationId: string): Promise<void>;
|
|
142
142
|
/**
|
|
143
|
-
* Get
|
|
143
|
+
* Get a page of conversations, newest-first. `pageSize` is capped at 100 by
|
|
144
|
+
* the backend (default 50). Returns the `{ data, has_more, total }` envelope
|
|
145
|
+
* so callers can page; `total` counts across all pages.
|
|
144
146
|
*/
|
|
145
|
-
getConversations(
|
|
147
|
+
getConversations(options?: {
|
|
148
|
+
page?: number;
|
|
149
|
+
pageSize?: number;
|
|
150
|
+
}): Promise<PaginatedResult<Conversation>>;
|
|
146
151
|
/**
|
|
147
152
|
* Get a specific conversation with messages
|
|
148
153
|
*/
|
|
@@ -488,6 +493,15 @@ declare interface AgoClientEvents {
|
|
|
488
493
|
* notably `createFormCollector` — can replay them to restore their state.
|
|
489
494
|
*/
|
|
490
495
|
"conversation:loaded": Conversation;
|
|
496
|
+
/**
|
|
497
|
+
* The conversation's title was generated and streamed during a live turn
|
|
498
|
+
* (the backend emits it once, at the end of the first turn). Lets the UI
|
|
499
|
+
* update a header without a refetch.
|
|
500
|
+
*/
|
|
501
|
+
"conversation:title": {
|
|
502
|
+
conversationId: string;
|
|
503
|
+
title: string;
|
|
504
|
+
};
|
|
491
505
|
"toolCall:received": ToolCallData;
|
|
492
506
|
"toolCall:form": ToolCallData;
|
|
493
507
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -1028,6 +1042,16 @@ declare type NudgeAction = {
|
|
|
1028
1042
|
setPageState: Record<string, unknown>;
|
|
1029
1043
|
};
|
|
1030
1044
|
|
|
1045
|
+
/**
|
|
1046
|
+
* A page of list results, mirroring the API's `{ data, has_more, total }`
|
|
1047
|
+
* envelope. `total` is the count across all pages, not just this page.
|
|
1048
|
+
*/
|
|
1049
|
+
declare interface PaginatedResult<T> {
|
|
1050
|
+
data: T[];
|
|
1051
|
+
hasMore: boolean;
|
|
1052
|
+
total: number;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1031
1055
|
/**
|
|
1032
1056
|
* Controller returned by {@link createAgoProactive} (also available as
|
|
1033
1057
|
* `client.proactive`).
|
|
@@ -1280,6 +1304,8 @@ declare interface SSEChunkData {
|
|
|
1280
1304
|
thread?: {
|
|
1281
1305
|
id: string;
|
|
1282
1306
|
};
|
|
1307
|
+
/** Generated conversation title, streamed once at the end of the first turn. */
|
|
1308
|
+
title?: string;
|
|
1283
1309
|
agent?: {
|
|
1284
1310
|
id: string;
|
|
1285
1311
|
name: string;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./AgoClient-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./AgoClient-CQh8YovA.cjs"),C=require("./autoContinue-CP9pJR-V.cjs"),p=require("./createConversationSession-0zVkMdYj.cjs"),f=require("./createFormCollector-DiCe_8ik.cjs"),E=require("./createMockClient-Dw-cyISN.cjs");require("./testing.cjs");const g=require("./functions-CPs7omgM.cjs");function S(e){return e}function w(e,o){return e.on("message:complete",o),()=>e.off("message:complete",o)}function y(e,o){return e.on("message:chunk",o),()=>e.off("message:chunk",o)}function v(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 M(e,o){return e.on("form:submitted",o),()=>e.off("form:submitted",o)}function T(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*I(e,o,l){const a=[];let n=null,i=!1;const c=s=>{a.push(s),n?.()},m=s=>c({type:"start",data:s}),r=s=>c({type:"chunk",data:s}),u=s=>{c({type:"complete",data:s}),i=!0,n?.()},d=s=>{c({type:"error",data:s}),i=!0,n?.()},A=s=>c({type:"toolCall",data:s});e.on("message:start",m),e.on("message:chunk",r),e.on("message:complete",u),e.on("message:error",d),e.on("toolCall:received",A),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",m),e.off("message:chunk",r),e.off("message:complete",u),e.off("message:error",d),e.off("toolCall:received",A)}}function h(e){let o,l,a,n,i,c;if(typeof window<"u"&&window.AGO){const r=window.AGO;o=r.basepath,l=r.widgetId,a=r.agent||r.defaultAgent,n=r.permission,i=r.email,c=r.jwt}if(typeof document<"u"){const r=u=>document.querySelector(`meta[name="${u}"]`)?.getAttribute("content")||void 0;o=o||r("ago-base-url"),l=l||r("ago-widget-id"),a=a||r("ago-agent")||r("ago-agent-id"),n=n||r("ago-permission"),i=i||r("ago-user-email")}if(typeof document<"u"){const r=[document.body,...Array.from(document.querySelectorAll("script[data-ago-base-url]"))].filter(Boolean);for(const u of r)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,c=e?.userJwt||c;const m=e?.debug;return o?{baseUrl:o,widgetId:l,agent:a,permission:n,userEmail:i,userJwt:c,debug:m}:null}function _(e){const o=h(e);if(!o)throw new t.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 t.AgoClient(o)}function k(e,o){return{...e,handler:o}}exports.ActivityLedger=t.ActivityLedger;exports.AgoApiError=t.AgoApiError;exports.AgoClient=t.AgoClient;exports.AgoError=t.AgoError;exports.AgoFunctionError=t.AgoFunctionError;exports.AgoNetworkError=t.AgoNetworkError;exports.AgoStreamError=t.AgoStreamError;exports.ClientContextRegistry=t.ClientContextRegistry;exports.DEFAULT_MAX_ACTIVITY_ENTRIES=t.DEFAULT_MAX_ACTIVITY_ENTRIES;exports.EventEmitter=t.EventEmitter;exports.FunctionRegistry=t.FunctionRegistry;exports.SSEHandler=t.SSEHandler;exports.SignalCollector=t.SignalCollector;exports.attachAutoContinueAfterNavigation=C.attachAutoContinueAfterNavigation;exports.autoDetectConfig=h;exports.canInlineImage=t.canInlineImage;exports.copyToClipboard=g.copyToClipboard;exports.createAgo=_;exports.createAgoProactive=t.createAgoProactive;exports.createConversationSession=p.createConversationSession;exports.createFormCollector=f.createFormCollector;exports.createMessageStream=I;exports.createMockClient=E.createMockClient;exports.createStore=t.createStore;exports.defineFunction=S;exports.deriveFormStatus=f.deriveFormStatus;exports.formatFileSize=t.formatFileSize;exports.getLocalStorage=g.getLocalStorage;exports.getUserLocation=g.getUserLocation;exports.highlightElement=g.highlightElement;exports.isStreamNetworkError=t.isStreamNetworkError;exports.loadFormCollector=f.loadFormCollector;exports.logger=t.logger;exports.matchesRoutePattern=t.matchesRoutePattern;exports.matchesWhen=t.matchesWhen;exports.onFormError=T;exports.onFormSubmitted=M;exports.onFunctionInvoke=q;exports.onMessage=w;exports.onMessageChunk=y;exports.onMessageError=F;exports.onMessageStart=v;exports.onToolCall=b;exports.openUrl=g.openUrl;exports.partialDeepMatch=t.partialDeepMatch;exports.safeAttachmentUrl=t.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=t.validateConfig;exports.withHandler=k;
|
package/dist/index.d.cts
CHANGED
|
@@ -179,9 +179,14 @@ export declare class AgoClient {
|
|
|
179
179
|
*/
|
|
180
180
|
rejectFunction(invocationId: string): Promise<void>;
|
|
181
181
|
/**
|
|
182
|
-
* Get
|
|
182
|
+
* Get a page of conversations, newest-first. `pageSize` is capped at 100 by
|
|
183
|
+
* the backend (default 50). Returns the `{ data, has_more, total }` envelope
|
|
184
|
+
* so callers can page; `total` counts across all pages.
|
|
183
185
|
*/
|
|
184
|
-
getConversations(
|
|
186
|
+
getConversations(options?: {
|
|
187
|
+
page?: number;
|
|
188
|
+
pageSize?: number;
|
|
189
|
+
}): Promise<PaginatedResult<Conversation>>;
|
|
185
190
|
/**
|
|
186
191
|
* Get a specific conversation with messages
|
|
187
192
|
*/
|
|
@@ -527,6 +532,15 @@ export declare interface AgoClientEvents {
|
|
|
527
532
|
* notably `createFormCollector` — can replay them to restore their state.
|
|
528
533
|
*/
|
|
529
534
|
"conversation:loaded": Conversation;
|
|
535
|
+
/**
|
|
536
|
+
* The conversation's title was generated and streamed during a live turn
|
|
537
|
+
* (the backend emits it once, at the end of the first turn). Lets the UI
|
|
538
|
+
* update a header without a refetch.
|
|
539
|
+
*/
|
|
540
|
+
"conversation:title": {
|
|
541
|
+
conversationId: string;
|
|
542
|
+
title: string;
|
|
543
|
+
};
|
|
530
544
|
"toolCall:received": ToolCallData;
|
|
531
545
|
"toolCall:form": ToolCallData;
|
|
532
546
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -1846,6 +1860,16 @@ export declare function onToolCall(client: AgoClient, callback: (toolCall: ToolC
|
|
|
1846
1860
|
*/
|
|
1847
1861
|
export declare const openUrl: ClientFunctionDefinition;
|
|
1848
1862
|
|
|
1863
|
+
/**
|
|
1864
|
+
* A page of list results, mirroring the API's `{ data, has_more, total }`
|
|
1865
|
+
* envelope. `total` is the count across all pages, not just this page.
|
|
1866
|
+
*/
|
|
1867
|
+
export declare interface PaginatedResult<T> {
|
|
1868
|
+
data: T[];
|
|
1869
|
+
hasMore: boolean;
|
|
1870
|
+
total: number;
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1849
1873
|
/**
|
|
1850
1874
|
* Partial deep match: every key/value present in `expected` must match the
|
|
1851
1875
|
* corresponding value in `actual`. Nested objects recurse (partially); arrays
|
|
@@ -2314,6 +2338,8 @@ export declare interface SSEChunkData {
|
|
|
2314
2338
|
thread?: {
|
|
2315
2339
|
id: string;
|
|
2316
2340
|
};
|
|
2341
|
+
/** Generated conversation title, streamed once at the end of the first turn. */
|
|
2342
|
+
title?: string;
|
|
2317
2343
|
agent?: {
|
|
2318
2344
|
id: string;
|
|
2319
2345
|
name: string;
|
|
@@ -2395,6 +2421,14 @@ declare interface SSEHandlerCallbacks {
|
|
|
2395
2421
|
arguments: Record<string, unknown>;
|
|
2396
2422
|
conversationId: string;
|
|
2397
2423
|
}) => void;
|
|
2424
|
+
/**
|
|
2425
|
+
* The conversation's title was generated and streamed (the backend emits it
|
|
2426
|
+
* once, near the end of the first turn).
|
|
2427
|
+
*/
|
|
2428
|
+
onTitle?: (data: {
|
|
2429
|
+
conversationId: string;
|
|
2430
|
+
title: string;
|
|
2431
|
+
}) => void;
|
|
2398
2432
|
/**
|
|
2399
2433
|
* The main answer text is finished (the backend emitted `status: "DONE"`) but
|
|
2400
2434
|
* follow-up replies may still be streaming. Fires once, before {@link onComplete},
|
package/dist/index.d.ts
CHANGED
|
@@ -179,9 +179,14 @@ export declare class AgoClient {
|
|
|
179
179
|
*/
|
|
180
180
|
rejectFunction(invocationId: string): Promise<void>;
|
|
181
181
|
/**
|
|
182
|
-
* Get
|
|
182
|
+
* Get a page of conversations, newest-first. `pageSize` is capped at 100 by
|
|
183
|
+
* the backend (default 50). Returns the `{ data, has_more, total }` envelope
|
|
184
|
+
* so callers can page; `total` counts across all pages.
|
|
183
185
|
*/
|
|
184
|
-
getConversations(
|
|
186
|
+
getConversations(options?: {
|
|
187
|
+
page?: number;
|
|
188
|
+
pageSize?: number;
|
|
189
|
+
}): Promise<PaginatedResult<Conversation>>;
|
|
185
190
|
/**
|
|
186
191
|
* Get a specific conversation with messages
|
|
187
192
|
*/
|
|
@@ -527,6 +532,15 @@ export declare interface AgoClientEvents {
|
|
|
527
532
|
* notably `createFormCollector` — can replay them to restore their state.
|
|
528
533
|
*/
|
|
529
534
|
"conversation:loaded": Conversation;
|
|
535
|
+
/**
|
|
536
|
+
* The conversation's title was generated and streamed during a live turn
|
|
537
|
+
* (the backend emits it once, at the end of the first turn). Lets the UI
|
|
538
|
+
* update a header without a refetch.
|
|
539
|
+
*/
|
|
540
|
+
"conversation:title": {
|
|
541
|
+
conversationId: string;
|
|
542
|
+
title: string;
|
|
543
|
+
};
|
|
530
544
|
"toolCall:received": ToolCallData;
|
|
531
545
|
"toolCall:form": ToolCallData;
|
|
532
546
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -1846,6 +1860,16 @@ export declare function onToolCall(client: AgoClient, callback: (toolCall: ToolC
|
|
|
1846
1860
|
*/
|
|
1847
1861
|
export declare const openUrl: ClientFunctionDefinition;
|
|
1848
1862
|
|
|
1863
|
+
/**
|
|
1864
|
+
* A page of list results, mirroring the API's `{ data, has_more, total }`
|
|
1865
|
+
* envelope. `total` is the count across all pages, not just this page.
|
|
1866
|
+
*/
|
|
1867
|
+
export declare interface PaginatedResult<T> {
|
|
1868
|
+
data: T[];
|
|
1869
|
+
hasMore: boolean;
|
|
1870
|
+
total: number;
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1849
1873
|
/**
|
|
1850
1874
|
* Partial deep match: every key/value present in `expected` must match the
|
|
1851
1875
|
* corresponding value in `actual`. Nested objects recurse (partially); arrays
|
|
@@ -2314,6 +2338,8 @@ export declare interface SSEChunkData {
|
|
|
2314
2338
|
thread?: {
|
|
2315
2339
|
id: string;
|
|
2316
2340
|
};
|
|
2341
|
+
/** Generated conversation title, streamed once at the end of the first turn. */
|
|
2342
|
+
title?: string;
|
|
2317
2343
|
agent?: {
|
|
2318
2344
|
id: string;
|
|
2319
2345
|
name: string;
|
|
@@ -2395,6 +2421,14 @@ declare interface SSEHandlerCallbacks {
|
|
|
2395
2421
|
arguments: Record<string, unknown>;
|
|
2396
2422
|
conversationId: string;
|
|
2397
2423
|
}) => void;
|
|
2424
|
+
/**
|
|
2425
|
+
* The conversation's title was generated and streamed (the backend emits it
|
|
2426
|
+
* once, near the end of the first turn).
|
|
2427
|
+
*/
|
|
2428
|
+
onTitle?: (data: {
|
|
2429
|
+
conversationId: string;
|
|
2430
|
+
title: string;
|
|
2431
|
+
}) => void;
|
|
2398
2432
|
/**
|
|
2399
2433
|
* The main answer text is finished (the backend emitted `status: "DONE"`) but
|
|
2400
2434
|
* follow-up replies may still be streaming. Fires once, before {@link onComplete},
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as h, c as w, d as C, f as y, i as E, l as S, m as b, o as v, p as F, r as T, s as I, t as M, u as U } from "./functions-tzyOZNp6.js";
|
|
2
|
-
import { C as k, S as L, T as N, _ as x, a as D, b as d, c as G, d as O, f as R, g as q, h as P, l as H, m as J, n as j, o as z, p as B, r as V, s as W, t as c, u as X, v as Y, w as $, x as K, y as Q } from "./AgoClient-
|
|
2
|
+
import { C as k, S as L, T as N, _ as x, a as D, b as d, c as G, d as O, f as R, g as q, h as P, l as H, m as J, n as j, o as z, p as B, r as V, s as W, t as c, u as X, v as Y, w as $, x as K, y as Q } from "./AgoClient-BI5esqbd.js";
|
|
3
3
|
import { t as ee } from "./autoContinue-CC8K9mBU.js";
|
|
4
|
-
import { t as oe } from "./createConversationSession-
|
|
5
|
-
import { n as ae, r as ne, t as se } from "./createFormCollector-
|
|
4
|
+
import { t as oe } from "./createConversationSession-BlYTpxwz.js";
|
|
5
|
+
import { n as ae, r as ne, t as se } from "./createFormCollector-Bgs94NyR.js";
|
|
6
6
|
import { t as ue } from "./createMockClient-DcuNlufr.js";
|
|
7
7
|
import "./testing.js";
|
|
8
8
|
function fe(e) {
|
package/dist/react.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Q=Object.create,T=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=Object.getOwnPropertyNames,ne=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty,oe=(e,n)=>{let t={};for(var o in e)T(t,o,{get:e[o],enumerable:!0});return n||T(t,Symbol.toStringTag,{value:"Module"}),t},se=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(var r=te(n),i=0,u=r.length,s;i<u;i++)s=r[i],!re.call(e,s)&&s!==t&&T(e,s,{get:(f=>n[f]).bind(null,s),enumerable:!(o=ee(n,s))||o.enumerable});return e},O=(e,n,t)=>(t=e!=null?Q(ne(e)):{},se(n||!e||!e.__esModule?T(t,"default",{value:e,enumerable:!0}):t,e));const _=require("./AgoClient-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Q=Object.create,T=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=Object.getOwnPropertyNames,ne=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty,oe=(e,n)=>{let t={};for(var o in e)T(t,o,{get:e[o],enumerable:!0});return n||T(t,Symbol.toStringTag,{value:"Module"}),t},se=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(var r=te(n),i=0,u=r.length,s;i<u;i++)s=r[i],!re.call(e,s)&&s!==t&&T(e,s,{get:(f=>n[f]).bind(null,s),enumerable:!(o=ee(n,s))||o.enumerable});return e},O=(e,n,t)=>(t=e!=null?Q(ne(e)):{},se(n||!e||!e.__esModule?T(t,"default",{value:e,enumerable:!0}):t,e));const _=require("./AgoClient-CQh8YovA.cjs"),ae=require("./autoContinue-CP9pJR-V.cjs"),M=require("./createFormCollector-DiCe_8ik.cjs"),ie=require("./createMockClient-Dw-cyISN.cjs");let a=require("react");a=O(a,1);let l=require("react/jsx-runtime"),D=require("react-markdown");D=O(D,1);let W=require("remark-gfm");W=O(W,1);function B(e){const[n,t]=(0,a.useState)(!1),o=(0,a.useRef)(null),r=(0,a.useMemo)(()=>{if(o.current&&(o.current.destroy(),o.current=null),!e)return null;const i=new _.AgoClient(e);return o.current=i,i},[e?.baseUrl,e?.widgetId]);return(0,a.useEffect)(()=>(r&&o.current===null&&(o.current=r,r.reviveAfterDestroy()),t(!0),()=>{o.current?.destroy(),o.current=null}),[r]),(0,a.useEffect)(()=>{o.current&&e&&o.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:r,isReady:n}}var q=(0,a.createContext)(null),le=({children:e,client:n,tools:t,helpers:o,pageContext:r,...i})=>{const{client:u}=B(n?null:i),s=n||u;return(0,a.useEffect)(()=>{if(!(!t||t.length===0)){for(const f of t)s.register(f);return()=>{for(const f of t)s.unregisterFunction(f.name)}}},[s,t]),(0,a.useEffect)(()=>{if(!o)return;const f=[];return Promise.resolve().then(()=>require("./functions-CPs7omgM.cjs")).then(d=>d.functions_exports).then(d=>{for(const[m,S]of Object.entries(o)){const I=d[m];if(!I){console.warn(`[AGO] Unknown helper: "${m}"`);continue}const A=S===!0?I:{...I,handler:S};s.register(A),f.push(A.name)}}),()=>{for(const d of f)s.unregisterFunction(d)}},[s,o]),(0,a.useEffect)(()=>{r==="auto"&&s.enableAutoPageContext()},[s,r]),(0,l.jsx)(q.Provider,{value:s,children:e})};function F(){const e=(0,a.useContext)(q);if(!e)throw new Error('useAgoClient must be used within an <AgoProvider>. Wrap your component tree with <AgoProvider baseUrl="...">.');return e}function E(){return(0,a.useContext)(q)}function z({client:e,conversationId:n}={}){const t=E(),o=e||t;if(!o)throw new Error("useMessages requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,i]=(0,a.useState)([]),[u,s]=(0,a.useState)(n),[f,d]=(0,a.useState)(!1),[m,S]=(0,a.useState)(null);(0,a.useEffect)(()=>{n&&n!==u&&(s(n),I(n))},[n]);const I=async A=>{try{i((await o.getMessages(A)).filter(k=>!k.hidden))}catch(k){S(k instanceof Error?k:new Error("Failed to load messages"))}};return(0,a.useEffect)(()=>{const A=p=>p==="IN_PROGRESS"||p==="WAITING_CLIENT",k=p=>{u||s(p.conversationId),d(!0),i(y=>{const w=y.findIndex(C=>C.id===p.messageId);return w>=0?y.map((C,R)=>R===w?{...C,status:"IN_PROGRESS"}:C):y.some(C=>C.role==="assistant"&&A(C.status))?y:[...y,{id:p.messageId,conversationId:p.conversationId,content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}]})},g=p=>{i(y=>{const w=y.findIndex(C=>C.id===p.messageId);return w<0?y:y.map((C,R)=>R===w?{...C,content:C.content+p.content}:C)})},h=p=>{i(y=>{let w=-1;for(let C=y.length-1;C>=0;C--)if(y[C].role==="assistant"&&A(y[C].status)){w=C;break}return w<0?y:[...y.slice(0,w),{...y[w],...p},...y.slice(w+1)]})},c=p=>{i(y=>{const w=y.findIndex(C=>C.id===p.id);return w>=0?[...y.slice(0,w),p,...y.slice(w+1)]:[...y,p]}),d(!1)},b=p=>{S(new Error(p.error)),d(!1)};return o.on("message:start",k),o.on("message:chunk",g),o.on("message:answer-complete",h),o.on("message:complete",c),o.on("message:error",b),()=>{o.off("message:start",k),o.off("message:chunk",g),o.off("message:answer-complete",h),o.off("message:complete",c),o.off("message:error",b)}},[o,u]),{messages:r,isLoading:f,error:m,sendMessage:(0,a.useCallback)(async(A,k)=>{d(!0),S(null);const g={id:`temp-${Date.now()}`,conversationId:u||"",content:A,role:"user",status:"DONE",attachments:k&&k.length>0?_.attachmentsFromFiles(k):void 0,createdAt:new Date},h={id:`temp-assistant-${Date.now()}`,conversationId:u||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};i(c=>[...c,g,h]);try{const c=await o.sendMessage(A,{conversationId:u,files:k});return c.conversationId&&!u&&s(c.conversationId),i(b=>{const p=b.filter(w=>!w.id.startsWith("temp-")),y={...g,id:g.id.replace("temp-","user-"),conversationId:c.conversationId};return p.some(w=>w.id===c.id)?[...p,y].sort((w,C)=>new Date(w.createdAt).getTime()-new Date(C.createdAt).getTime()):[...p,y,c]}),c}catch(c){return S(c instanceof Error?c:new Error("Failed to send message")),d(!1),i(b=>b.filter(p=>!p.id.startsWith("temp-"))),null}},[o,u]),clearMessages:(0,a.useCallback)(()=>{i([]),s(void 0),S(null)},[]),conversationId:u}}var U=({onSend:e,disabled:n=!1,placeholder:t="Type a message...",allowFiles:o=!1,className:r=""})=>{const[i,u]=(0,a.useState)(""),[s,f]=(0,a.useState)([]),d=(0,a.useRef)(null),m=(0,a.useRef)(null),S=(0,a.useCallback)(()=>{const c=m.current;if(!c)return;const b=110;c.style.height="auto",c.style.height=`${Math.min(c.scrollHeight+2,b)}px`,c.style.overflowY=c.scrollHeight+2>b?"auto":"hidden"},[]),I=(0,a.useCallback)(c=>{c.preventDefault(),(i.trim()||s.length>0)&&(e(i.trim(),s.length>0?s:void 0),u(""),f([]),requestAnimationFrame(S))},[i,s,e,S]),A=(0,a.useCallback)(c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),I(c))},[I]),k=(0,a.useCallback)(c=>{const b=Array.from(c.target.files||[]);f(p=>[...p,...b])},[]),g=(0,a.useCallback)(c=>{f(b=>b.filter((p,y)=>y!==c))},[]),h=i.trim()||s.length>0;return(0,l.jsxs)("form",{onSubmit:I,className:`ago-chat-input ${r}`,style:{display:"flex",flexDirection:"column",gap:"8px",padding:"12px 16px",borderTop:"1px solid #dee3e8",backgroundColor:"#fff"},children:[s.length>0&&(0,l.jsx)("div",{className:"ago-chat-input__files",style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:s.map((c,b)=>(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"6px",padding:"4px 10px",backgroundColor:"#f0f2f5",borderRadius:"6px",fontSize:"12px",color:"#30373e"},children:[(0,l.jsx)("span",{style:{maxWidth:"120px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.name}),(0,l.jsx)("button",{type:"button",onClick:()=>g(b),"aria-label":`Remove ${c.name}`,style:{border:"none",background:"none",cursor:"pointer",padding:"0",color:"#6b6d6f",fontSize:"14px",lineHeight:1},children:"×"})]},b))}),(0,l.jsxs)("div",{style:{display:"flex",gap:"8px",alignItems:"flex-end"},children:[o&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("button",{type:"button",onClick:()=>d.current?.click(),disabled:n,"aria-label":"Attach file",style:{padding:"8px",border:"1px solid #dee3e8",borderRadius:"8px",backgroundColor:"#fff",cursor:n?"not-allowed":"pointer",color:"#6b6d6f",fontSize:"16px",lineHeight:1},children:"+"}),(0,l.jsx)("input",{ref:d,type:"file",multiple:!0,onChange:k,style:{display:"none"}})]}),(0,l.jsx)("textarea",{ref:m,value:i,onChange:c=>{u(c.target.value),S()},onKeyDown:A,placeholder:t,"aria-label":t,disabled:n,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:c=>{c.currentTarget.style.borderColor="#1b5fc4"},onBlur:c=>{c.currentTarget.style.borderColor="#dee3e8"}}),(0,l.jsx)("button",{type:"submit",disabled:n||!h,style:{padding:"10px 18px",border:"none",borderRadius:"20px",backgroundColor:n||!h?"#b5bfc8":"#03182f",color:"#fff",cursor:n||!h?"not-allowed":"pointer",fontWeight:500,fontSize:"16px",transition:"background-color 0.15s"},children:"Send"})]})]})},ce=({href:e,children:n,...t})=>(0,l.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"#1b5fc4",textDecoration:"underline"},...t,children:n}),ue=({children:e,...n})=>(0,l.jsx)("p",{style:{margin:"0 0 8px 0",lineHeight:"1.6"},...n,children:e}),P=(e,n)=>{const t=({children:o,...r})=>a.default.createElement(`h${e}`,{style:{margin:"16px 0 8px 0",fontSize:n,fontWeight:600,lineHeight:"1.3"},...r},o);return t.displayName=`MarkdownHeading${e}`,t},de=({children:e,...n})=>(0,l.jsx)("ul",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"disc",listStylePosition:"outside"},...n,children:e}),fe=({children:e,...n})=>(0,l.jsx)("ol",{style:{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:"decimal",listStylePosition:"outside"},...n,children:e}),ge=({children:e,...n})=>(0,l.jsx)("li",{style:{display:"list-item",margin:"2px 0",lineHeight:"1.6"},...n,children:e}),pe=({className:e,children:n,...t})=>e!==void 0||String(n).includes(`
|
|
2
2
|
`)?(0,l.jsx)("code",{style:{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}):(0,l.jsx)("code",{style:{background:"#f0f2f5",padding:"2px 5px",borderRadius:"4px",fontSize:"13px",fontFamily:'"IBM Plex Mono", monospace'},...t,children:n}),me=({children:e,...n})=>(0,l.jsx)("pre",{style:{margin:"0 0 8px 0"},...n,children:e}),xe=({children:e,...n})=>(0,l.jsx)("blockquote",{style:{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"},...n,children:e}),he=({children:e,...n})=>(0,l.jsx)("div",{style:{overflowX:"auto",margin:"0 0 8px 0"},children:(0,l.jsx)("table",{style:{borderCollapse:"collapse",width:"100%",fontSize:"13px"},...n,children:e})}),ye=({children:e,...n})=>(0,l.jsx)("th",{style:{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:600},...n,children:e}),ve=({children:e,...n})=>(0,l.jsx)("td",{style:{border:"1px solid #dee3e8",padding:"6px 10px"},...n,children:e}),be=({alt:e,...n})=>(0,l.jsx)("img",{alt:e??"",style:{maxWidth:"100%",borderRadius:"8px",margin:"4px 0"},...n}),Ce=e=>(0,l.jsx)("hr",{style:{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"},...e}),we={a:ce,p:ue,h1:P(1,"20px"),h2:P(2,"18px"),h3:P(3,"16px"),h4:P(4,"15px"),h5:P(5,"14px"),h6:P(6,"13px"),ul:de,ol:fe,li:ge,code:pe,pre:me,blockquote:xe,table:he,th:ye,td:ve,img:be,hr:Ce},Se=[W.default],G=({content:e})=>(0,l.jsx)(D.default,{remarkPlugins:Se,components:we,children:e}),Ae=({attachment:e,isUser:n})=>{const t=_.safeAttachmentUrl(e.url);if(_.canInlineImage(e))return(0,l.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:{display:"inline-block",textDecoration:"none"},children:(0,l.jsx)("img",{src:t,alt:e.name,loading:"lazy",style:{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:"1px solid #dee3e8",display:"block"}})});const o=_.formatFileSize(e.fileSize),r=(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("span",{style:{fontSize:"16px",lineHeight:1,flexShrink:0},"aria-hidden":!0,children:"📄"}),(0,l.jsxs)("span",{style:{display:"flex",flexDirection:"column",minWidth:0},children:[(0,l.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"},title:e.name,children:e.name}),o&&(0,l.jsx)("span",{style:{fontSize:"11px",color:"#6b6d6f"},children:o})]})]}),i={display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:"1px solid #dee3e8",backgroundColor:n?"rgba(255,255,255,0.12)":"#fff",color:n?"#fff":"#30373e",fontSize:"13px",textDecoration:"none",maxWidth:"220px"};return t?(0,l.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:i,children:r}):(0,l.jsx)("div",{style:i,children:r})},ke=({source:e,index:n})=>{const t=(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:0},children:[(0,l.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:n+1}),(0,l.jsx)("div",{style:{fontSize:"12px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"#30373e"},title:e.title,children:e.title})]}),o={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,l.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",style:o,onMouseEnter:r=>{r.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:r=>{r.currentTarget.style.borderColor="#dee3e8"},children:t}):(0,l.jsx)("div",{style:o,children:t})},je=()=>(0,l.jsxs)("div",{style:{display:"flex",gap:"4px",padding:"4px 0"},children:[[0,1,2].map(e=>(0,l.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,l.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
|
-
`})]}),K=({message:e,className:n="",showAgentName:t=!1,isLast:o=!1,onFollowUpClick:r})=>{const i=e.role==="user",u=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,l.jsxs)("div",{className:`ago-message ago-message--${e.role} ${n}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&t&&e.agent&&(0,l.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,l.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((s,f)=>(0,l.jsx)(ke,{source:s,index:f},s.id))}),e.attachments&&e.attachments.length>0&&(0,l.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(s=>(0,l.jsx)(Ae,{attachment:s,isUser:i},s.id))}),(e.content||u)&&(0,l.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,l.jsx)(G,{content:e.content}):u&&(0,l.jsx)(je,{})}),o&&e.followUpReplies&&e.followUpReplies.length>0&&(0,l.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((s,f)=>(0,l.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!r,onClick:r?()=>r(s):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:r?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:d=>{d.currentTarget.style.borderColor="#dee3e8"},children:s},f))})]})},Ie=({client:e,conversationId:n,title:t="Chat",welcomeMessage:o="Hello! How can I help you today?",placeholder:r="Type a message...",allowFiles:i=!1,height:u=500,logoUrl:s,showAgentName:f=!1,forms:d,onFollowUpClick:m,className:S="",onMessageSent:I,onMessageReceived:A})=>{const k=(0,a.useRef)(null),p=E(),h=e??p,{messages:c,isLoading:b,error:g,sendMessage:y}=z({client:e,conversationId:n});(0,a.useEffect)(()=>{if(!h||!d||d.length===0)return;let x=!1;const j=[];return Promise.all(d.map(N=>N.schema!=null?Promise.resolve(M.createFormCollector(N)):M.loadFormCollector(h,N))).then(N=>{if(!x)for(const Z of N)j.push(Z.install(h))}).catch(()=>{}),()=>{x=!0,j.forEach(N=>N())}},[h,d?JSON.stringify(d.map(x=>[x.name,x.schema??null,x.submit??!1,x.description??null])):""]),(0,a.useEffect)(()=>{k.current?.scrollIntoView({behavior:"smooth"})},[c]),(0,a.useEffect)(()=>{const x=c[c.length-1];x&&x.role==="assistant"&&x.status==="DONE"&&A&&A({id:x.id,content:x.content})},[c,A]);const w=async(x,j)=>{I?.(x),await y(x,j)},C=c[c.length-1],R=b&&C?.role==="assistant"&&(C.status==="IN_PROGRESS"||C.status==="WAITING_CLIENT"),v=m===!1?void 0:m??(x=>w(x));return(0,l.jsxs)("div",{className:`ago-chat-widget ${S}`,style:{display:"flex",flexDirection:"column",height:typeof u=="number"?`${u}px`:u,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,l.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:[s&&(0,l.jsx)("img",{src:s,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,l.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:t})]}),(0,l.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:[c.length===0?(0,l.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:o}):c.map((x,j)=>(0,l.jsx)(K,{message:x,showAgentName:f,isLast:j===c.length-1,onFollowUpClick:v},x.id)),g&&(0,l.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:g.message}),(0,l.jsx)("div",{ref:k})]}),(0,l.jsx)(U,{onSend:w,disabled:R,placeholder:r,allowFiles:i})]})};function J(e={}){const n=E(),t=e.client??n;if(!t)throw new _.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[o,r]=(0,a.useState)(null),i=(0,a.useRef)(o);i.current=o;const u=(0,a.useRef)(e.onExpand);return u.current=e.onExpand,(0,a.useEffect)(()=>{const s=d=>{r(d),t.proactive?.shown(d)},f=({nudge:d})=>{r(m=>m?.id===d.id?null:m)};return t.on("nudge:ready",s),t.on("nudge:accepted",f),t.on("nudge:dismissed",f),()=>{t.off("nudge:ready",s),t.off("nudge:accepted",f),t.off("nudge:dismissed",f)}},[t]),{nudge:o,accept:(0,a.useCallback)(async()=>{const s=i.current;s&&(r(null),await t.proactive?.accept(s),(s.source==="agent"||s.goal)&&u.current?.(s))},[t]),dismiss:(0,a.useCallback)(()=>{const s=i.current;s&&(r(null),t.proactive?.dismiss(s))},[t])}}var Ne=({client:e,onExpand:n,autoHideMs:t,position:o="bottom-right",openChatLabel:r="Open chat",className:i=""})=>{const{nudge:u,accept:s,dismiss:f}=J({client:e,onExpand:n});if((0,a.useEffect)(()=>{if(!u||!t)return;const m=setTimeout(()=>f(),t);return()=>clearTimeout(m)},[u,t,f]),!u)return null;const d=u.source==="agent"||!!u.goal;return(0,l.jsxs)("div",{className:`ago-nudge ${i}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...o==="bottom-left"?{left:"20px"}:{right:"20px"},zIndex:2147483e3,maxWidth:"320px",padding:"14px 16px",backgroundColor:"#fff",color:"#03182f",border:"1px solid #dee3e8",borderRadius:"16px",boxShadow:"rgba(15, 15, 15, 0.12) 0px 4px 20px 0px",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",lineHeight:1.5,textAlign:"left"},children:[(0,l.jsx)("button",{type:"button",className:"ago-nudge__close","aria-label":"Dismiss",onClick:f,style:{position:"absolute",top:"6px",right:"8px",border:"none",background:"transparent",color:"#6b6d6f",fontSize:"16px",lineHeight:1,cursor:"pointer",padding:"4px"},children:"×"}),(0,l.jsx)("div",{className:"ago-nudge__message",style:{paddingRight:"16px"},children:u.message}),(u.action||d)&&(0,l.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[u.action&&(0,l.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{s()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:u.action.label}),d&&(0,l.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{s()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:r})]})]})};function V({client:e,autoLoad:n=!0}={}){const t=E(),o=e||t;if(!o)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,i]=(0,a.useState)([]),[u,s]=(0,a.useState)(null),[f,d]=(0,a.useState)(!1),[m,S]=(0,a.useState)(null),I=(0,a.useCallback)(async()=>{d(!0),S(null);try{i(await o.getConversations())}catch(p){S(p instanceof Error?p:new Error("Failed to load conversations"))}finally{d(!1)}},[o]),A=(0,a.useCallback)(async p=>{d(!0),S(null);try{s(await o.getConversation(p))}catch(h){S(h instanceof Error?h:new Error("Failed to load conversation"))}finally{d(!1)}},[o]),k=(0,a.useCallback)(()=>{s(null)},[]);return(0,a.useEffect)(()=>{n&&I()},[n,I]),{conversations:r,currentConversation:u,isLoading:f,error:m,selectConversation:A,startNewConversation:k,refreshConversations:I}}function _e(e={}){const n=E(),t=e.client||n;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const o=z({client:t,conversationId:e.conversationId}),r=V({client:t,autoLoad:e.autoLoad});return{messages:o.messages,isLoading:o.isLoading,error:o.error||r.error,sendMessage:o.sendMessage,clearMessages:o.clearMessages,conversationId:o.conversationId,conversations:r.conversations,currentConversation:r.currentConversation,isConversationsLoading:r.isLoading,selectConversation:r.selectConversation,startNewConversation:r.startNewConversation,refreshConversations:r.refreshConversations}}function Re(e,n){const t=F(),{name:o,description:r,parameters:i,handler:u,maxResultBytes:s,requiresApproval:f}=typeof e=="string"?{name:e,...n}:e,d=(0,a.useRef)(u);d.current=u,(0,a.useEffect)(()=>{const m=S=>d.current(S);return t.registerFunction(o,m,{description:r,parameters:i,maxResultBytes:s,requiresApproval:f}),()=>{t.unregisterFunction(o)}},[t,o,r,i,s,f])}function Ee(e,n){const t=F(),o=(0,a.useRef)(e);o.current=e,(0,a.useEffect)(()=>(t.registerNavigationFunction(r=>o.current(r),n),()=>{t.unregisterNavigationFunction()}),[t,n])}function Me(e,n){const t=F(),o=n?.functionName??"setPageState",r=n?.requiresApproval,i=(0,a.useRef)(e);i.current=e,(0,a.useEffect)(()=>{const u=i.current.map(s=>{const f=()=>i.current.find(d=>d.name===s.name)??s;return{name:s.name,description:s.description,schema:s.schema,get:s.get?()=>f().get?.():void 0,set:d=>f().set(d)}});return t.registerPageStateFunction(u,{functionName:o,requiresApproval:r}),()=>{t.unregisterPageStateFunction(o)}},[t,o,r])}function Fe(e){const n=F(),t=(0,a.useRef)(e);t.current=e,(0,a.useEffect)(()=>ae.attachAutoContinueAfterNavigation(n,()=>t.current),[n])}var Pe=new Set(["awaiting-approval"]);function Y(e){switch(e){case"progress_indicator":return"progress";case"reasoning":return"reasoning";case"confirmation_input":return"confirmation";case"form":return"form";default:return"status"}}function Te(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":Y(e.type)}function L(e,n){const t=(e??"").toLowerCase();return t.includes("reject")?"rejected":t.includes("error")||t.includes("fail")?"error":t.includes("done")||t.includes("complet")?"done":(t.includes("waiting")||t.includes("pending"))&&(n==="confirmation"||n==="form")?"awaiting-approval":"running"}function $(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase()).trim()}function De(e){switch(e.kind){case"navigation":return`Navigating to ${$(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||$(e.functionName)||"Working";case"progress":return e.message||"Working";case"reasoning":return e.message||"Thinking";case"confirmation":return e.message||"Waiting for your confirmation";case"form":return e.message||e.toolDisplayName||"Please fill in the form";default:return e.message||e.toolDisplayName||e.toolName||"Working"}}function We(e={}){const{includeReasoning:n=!1,labelFor:t}=e,o=E(),r=e.client||o;if(!r)throw new _.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[i,u]=(0,a.useState)([]),s=(0,a.useRef)(new Set),f=(0,a.useRef)(void 0),d=(0,a.useRef)(t);d.current=t;const m=(0,a.useCallback)((p,h)=>{u(c=>{const b=c.findIndex(y=>y.id===p),g={...b>=0?c[b]:{id:p,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...h};return g.label=d.current?.(g)??De(g),b>=0?[...c.slice(0,b),g,...c.slice(b+1)]:[...c,g]})},[]);(0,a.useEffect)(()=>{const p=v=>{f.current=v.messageId},h=v=>{const x=Y(v.type);x==="reasoning"&&!n||m(v.id,{kind:x,status:L(v.status,x),messageId:f.current,toolName:v.toolName,toolDisplayName:v.toolDisplayName,message:v.message,data:v.data,formSchema:v.formSchema,requiresApproval:x==="confirmation"||x==="form"})},c=v=>{v.invocationId&&m(v.invocationId,{kind:v.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:f.current,functionName:v.functionName,arguments:v.arguments})},b=v=>{v.invocationId&&m(v.invocationId,{kind:v.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:f.current,functionName:v.functionName,arguments:v.arguments,requiresApproval:!0})},g=v=>{if(!v.invocationId)return;const x=v.result,j=typeof v.result=="object"&&x!==null&&x.approved===!1&&x.reason==="user_rejected";m(v.invocationId,{status:v.error?"error":j?"rejected":"done",requiresApproval:!1})},y=v=>{for(const x of v.messages??[])if(x.role==="assistant")for(const j of x.toolCalls??[]){const N=Te(j);N==="reasoning"&&!n||/waiting/i.test(j.status??"")||m(j.id,{kind:N,status:L(j.status,N),messageId:x.id,toolName:j.toolName,toolDisplayName:j.toolDisplayName,functionName:j.functionName,arguments:j.arguments,message:j.message,data:j.data,formSchema:j.formSchema,requiresApproval:N==="confirmation"||N==="form"})}},w=v=>{u(x=>x.map(j=>j.status==="running"||j.status==="awaiting-approval"?{...j,status:v}:j))},C=()=>w("done"),R=()=>w("error");return r.on("message:start",p),r.on("toolCall:received",h),r.on("function:invoke",c),r.on("function:awaiting-approval",b),r.on("function:result",g),r.on("conversation:loaded",y),r.on("message:complete",C),r.on("message:error",R),()=>{r.off("message:start",p),r.off("toolCall:received",h),r.off("function:invoke",c),r.off("function:awaiting-approval",b),r.off("function:result",g),r.off("conversation:loaded",y),r.off("message:complete",C),r.off("message:error",R)}},[r,n,m]);const S=(0,a.useCallback)(async p=>{const h=i.find(c=>c.id===p);!h||h.status!=="awaiting-approval"||s.current.has(p)||h.kind!=="form"&&(s.current.add(p),m(p,{status:"running",requiresApproval:!1}),h.functionName?await r.approveFunction(p):await r.confirmToolCall(p))},[r,i,m]),I=(0,a.useCallback)(async p=>{const h=i.find(c=>c.id===p);!h||h.status!=="awaiting-approval"||s.current.has(p)||(s.current.add(p),m(p,{status:"rejected",requiresApproval:!1}),h.functionName?await r.rejectFunction(p):await r.rejectToolCall(p))},[r,i,m]),A=(0,a.useCallback)(async(p,h)=>{m(p,{status:"running",requiresApproval:!1}),await r.submitToolCallForm(p,h),m(p,{status:"done"})},[r,m]),k=(0,a.useCallback)(()=>{s.current.clear(),u([])},[]);return{items:i,latest:i.length>0?i[i.length-1]:void 0,isAwaitingApproval:i.some(p=>Pe.has(p.status)),approve:S,reject:I,submitForm:A,clear:k}}function Oe(e={}){const n=E(),t=e.client||n;if(!t)throw new _.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[o,r]=(0,a.useState)(()=>t.getRecentActivity());(0,a.useEffect)(()=>{r(t.getRecentActivity());const s=()=>r(t.getRecentActivity());return t.on("activity:recorded",s),()=>t.off("activity:recorded",s)},[t]);const i=(0,a.useCallback)(s=>t.recordActivity(s),[t]),u=(0,a.useCallback)(()=>{t.clearActivity(),r([])},[t]);return{entries:o,latest:o.length>0?o[o.length-1]:void 0,record:i,clear:u}}function qe(e,n){const t=F(),o=(0,a.useId)(),r=n??o,i=(0,a.useRef)(e);i.current=e;const u=typeof e=="function";(0,a.useEffect)(()=>{if(typeof i.current=="function"){const s=()=>i.current();return t.addDynamicContext(r,s),()=>{t.removeDynamicContext(r)}}return t.setContext(r,i.current),()=>{t.removeContext(r)}},[t,r,u,u?"":JSON.stringify(e)])}function X(e){return(0,a.useSyncExternalStore)(e.subscribe,e.get,e.get)}var H={missing:[],complete:!1};function ze(e){const n=F(),t=e.schema!=null,o=JSON.stringify(e.schema??null),r=e.submit,i=r?typeof r=="string"?`client:${r}`:r.via==="backend"?"backend":"handler"in r?"client:handler":`client:${r.url}`:"none",u=JSON.stringify(e.initialValues??null),s=(0,a.useMemo)(()=>t?M.createFormCollector(e):null,[t,e.name,o,i,u,e.autoSubmit]),[f,d]=(0,a.useState)({collector:null,loading:!t,error:null});(0,a.useEffect)(()=>{if(t)return;let b=!1;return d({collector:null,loading:!0,error:null}),M.loadFormCollector(n,e).then(g=>{b||d({collector:g,loading:!1,error:null})}).catch(g=>{b||d({collector:null,loading:!1,error:g instanceof Error?g:new Error(String(g))})}),()=>{b=!0}},[n,t,e.name,i,u,e.autoSubmit]);const m=t?s:f.collector,S=t?!1:f.loading,I=t?null:f.error;(0,a.useEffect)(()=>{if(m)return m.install(n)},[n,m]);const A=(0,a.useMemo)(()=>_.createStore({values:e.initialValues??{},submitted:!1}),[u]),k=X(m?.store??A),p=(0,a.useMemo)(()=>m?.getStatus()??H,[k,m]),h=(0,a.useMemo)(()=>({...k,...p}),[k,p]),c=(0,a.useMemo)(()=>({name:e.name,store:A,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),definitionContextKey:`form:${e.name}:definition`,definitionContextProvider:()=>({name:`Form definition: ${e.name}`,description:"",stable:!0}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>A.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>H}),[e.name,A]);return{...m??c,state:h,loading:S,error:I}}exports.AgoNudge=Ne;exports.AgoProvider=le;exports.ChatInput=U;exports.ChatWidget=Ie;exports.Markdown=G;exports.Message=K;exports.__exportAll=oe;exports.createFormCollector=M.createFormCollector;exports.createMockClient=ie.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=B;exports.useAgoActivity=We;exports.useAgoActivityLog=Oe;exports.useAgoAutoContinueAfterNavigation=Fe;exports.useAgoClient=F;exports.useAgoContext=qe;exports.useAgoFunction=Re;exports.useAgoNavigation=Ee;exports.useAgoPageState=Me;exports.useAgoStore=X;exports.useChat=_e;exports.useConversation=V;exports.useFormCollector=ze;exports.useMessages=z;exports.useOptionalAgoClient=E;exports.useProactiveNudge=J;
|
|
7
|
+
`})]}),K=({message:e,className:n="",showAgentName:t=!1,isLast:o=!1,onFollowUpClick:r})=>{const i=e.role==="user",u=e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT";return(0,l.jsxs)("div",{className:`ago-message ago-message--${e.role} ${n}`,style:{display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"},children:[!i&&t&&e.agent&&(0,l.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,l.jsx)("div",{className:"ago-message__sources",style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"},children:e.sources.map((s,f)=>(0,l.jsx)(ke,{source:s,index:f},s.id))}),e.attachments&&e.attachments.length>0&&(0,l.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(s=>(0,l.jsx)(Ae,{attachment:s,isUser:i},s.id))}),(e.content||u)&&(0,l.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,l.jsx)(G,{content:e.content}):u&&(0,l.jsx)(je,{})}),o&&e.followUpReplies&&e.followUpReplies.length>0&&(0,l.jsx)("div",{className:"ago-message__followups",style:{display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"},children:e.followUpReplies.map((s,f)=>(0,l.jsx)("button",{type:"button",className:"ago-message__followup-btn",disabled:!r,onClick:r?()=>r(s):void 0,style:{minHeight:"36px",padding:"6px 14px",fontSize:"13px",borderRadius:"16px",border:"1px solid #dee3e8",backgroundColor:"#fff",color:"#30373e",cursor:r?"pointer":"default",transition:"border-color 0.15s"},onMouseEnter:d=>{d.currentTarget.style.borderColor="#1b5fc4"},onMouseLeave:d=>{d.currentTarget.style.borderColor="#dee3e8"},children:s},f))})]})},Ie=({client:e,conversationId:n,title:t="Chat",welcomeMessage:o="Hello! How can I help you today?",placeholder:r="Type a message...",allowFiles:i=!1,height:u=500,logoUrl:s,showAgentName:f=!1,forms:d,onFollowUpClick:m,className:S="",onMessageSent:I,onMessageReceived:A})=>{const k=(0,a.useRef)(null),g=E(),h=e??g,{messages:c,isLoading:b,error:p,sendMessage:y}=z({client:e,conversationId:n});(0,a.useEffect)(()=>{if(!h||!d||d.length===0)return;let x=!1;const j=[];return Promise.all(d.map(N=>N.schema!=null?Promise.resolve(M.createFormCollector(N)):M.loadFormCollector(h,N))).then(N=>{if(!x)for(const Z of N)j.push(Z.install(h))}).catch(()=>{}),()=>{x=!0,j.forEach(N=>N())}},[h,d?JSON.stringify(d.map(x=>[x.name,x.schema??null,x.submit??!1,x.description??null])):""]),(0,a.useEffect)(()=>{k.current?.scrollIntoView({behavior:"smooth"})},[c]),(0,a.useEffect)(()=>{const x=c[c.length-1];x&&x.role==="assistant"&&x.status==="DONE"&&A&&A({id:x.id,content:x.content})},[c,A]);const w=async(x,j)=>{I?.(x),await y(x,j)},C=c[c.length-1],R=b&&C?.role==="assistant"&&(C.status==="IN_PROGRESS"||C.status==="WAITING_CLIENT"),v=m===!1?void 0:m??(x=>w(x));return(0,l.jsxs)("div",{className:`ago-chat-widget ${S}`,style:{display:"flex",flexDirection:"column",height:typeof u=="number"?`${u}px`:u,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,l.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:[s&&(0,l.jsx)("img",{src:s,alt:"Logo",style:{height:"24px",width:"auto"}}),(0,l.jsx)("h3",{style:{margin:0,fontSize:"15px",fontWeight:600},children:t})]}),(0,l.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:[c.length===0?(0,l.jsx)("div",{style:{textAlign:"center",color:"#6b6d6f",padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"},children:o}):c.map((x,j)=>(0,l.jsx)(K,{message:x,showAgentName:f,isLast:j===c.length-1,onFollowUpClick:v},x.id)),p&&(0,l.jsx)("div",{role:"alert",style:{padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"},children:p.message}),(0,l.jsx)("div",{ref:k})]}),(0,l.jsx)(U,{onSend:w,disabled:R,placeholder:r,allowFiles:i})]})};function J(e={}){const n=E(),t=e.client??n;if(!t)throw new _.AgoError("useProactiveNudge: no AgoClient. Pass one via options.client or wrap your tree with <AgoProvider>.","proactive_missing_client");const[o,r]=(0,a.useState)(null),i=(0,a.useRef)(o);i.current=o;const u=(0,a.useRef)(e.onExpand);return u.current=e.onExpand,(0,a.useEffect)(()=>{const s=d=>{r(d),t.proactive?.shown(d)},f=({nudge:d})=>{r(m=>m?.id===d.id?null:m)};return t.on("nudge:ready",s),t.on("nudge:accepted",f),t.on("nudge:dismissed",f),()=>{t.off("nudge:ready",s),t.off("nudge:accepted",f),t.off("nudge:dismissed",f)}},[t]),{nudge:o,accept:(0,a.useCallback)(async()=>{const s=i.current;s&&(r(null),await t.proactive?.accept(s),(s.source==="agent"||s.goal)&&u.current?.(s))},[t]),dismiss:(0,a.useCallback)(()=>{const s=i.current;s&&(r(null),t.proactive?.dismiss(s))},[t])}}var Ne=({client:e,onExpand:n,autoHideMs:t,position:o="bottom-right",openChatLabel:r="Open chat",className:i=""})=>{const{nudge:u,accept:s,dismiss:f}=J({client:e,onExpand:n});if((0,a.useEffect)(()=>{if(!u||!t)return;const m=setTimeout(()=>f(),t);return()=>clearTimeout(m)},[u,t,f]),!u)return null;const d=u.source==="agent"||!!u.goal;return(0,l.jsxs)("div",{className:`ago-nudge ${i}`,role:"status","aria-live":"polite",style:{position:"fixed",bottom:"90px",...o==="bottom-left"?{left:"20px"}:{right:"20px"},zIndex:2147483e3,maxWidth:"320px",padding:"14px 16px",backgroundColor:"#fff",color:"#03182f",border:"1px solid #dee3e8",borderRadius:"16px",boxShadow:"rgba(15, 15, 15, 0.12) 0px 4px 20px 0px",fontFamily:'"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:"14px",lineHeight:1.5,textAlign:"left"},children:[(0,l.jsx)("button",{type:"button",className:"ago-nudge__close","aria-label":"Dismiss",onClick:f,style:{position:"absolute",top:"6px",right:"8px",border:"none",background:"transparent",color:"#6b6d6f",fontSize:"16px",lineHeight:1,cursor:"pointer",padding:"4px"},children:"×"}),(0,l.jsx)("div",{className:"ago-nudge__message",style:{paddingRight:"16px"},children:u.message}),(u.action||d)&&(0,l.jsxs)("div",{className:"ago-nudge__actions",style:{display:"flex",gap:"8px",marginTop:"10px",flexWrap:"wrap"},children:[u.action&&(0,l.jsx)("button",{type:"button",className:"ago-nudge__action",onClick:()=>{s()},style:{border:"none",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#03182f",color:"#e8f0fe",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:u.action.label}),d&&(0,l.jsx)("button",{type:"button",className:"ago-nudge__expand",onClick:()=>{s()},style:{border:"1px solid #dee3e8",borderRadius:"10px",padding:"6px 12px",backgroundColor:"#fff",color:"#03182f",fontSize:"13px",fontWeight:600,cursor:"pointer"},children:r})]})]})};function V({client:e,autoLoad:n=!0}={}){const t=E(),o=e||t;if(!o)throw new Error("useConversation requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const[r,i]=(0,a.useState)([]),[u,s]=(0,a.useState)(null),[f,d]=(0,a.useState)(!1),[m,S]=(0,a.useState)(null),I=(0,a.useCallback)(async()=>{d(!0),S(null);try{const{data:g}=await o.getConversations();i(g)}catch(g){S(g instanceof Error?g:new Error("Failed to load conversations"))}finally{d(!1)}},[o]),A=(0,a.useCallback)(async g=>{d(!0),S(null);try{s(await o.getConversation(g))}catch(h){S(h instanceof Error?h:new Error("Failed to load conversation"))}finally{d(!1)}},[o]),k=(0,a.useCallback)(()=>{s(null)},[]);return(0,a.useEffect)(()=>{n&&I()},[n,I]),{conversations:r,currentConversation:u,isLoading:f,error:m,selectConversation:A,startNewConversation:k,refreshConversations:I}}function _e(e={}){const n=E(),t=e.client||n;if(!t)throw new Error("useChat requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.");const o=z({client:t,conversationId:e.conversationId}),r=V({client:t,autoLoad:e.autoLoad});return{messages:o.messages,isLoading:o.isLoading,error:o.error||r.error,sendMessage:o.sendMessage,clearMessages:o.clearMessages,conversationId:o.conversationId,conversations:r.conversations,currentConversation:r.currentConversation,isConversationsLoading:r.isLoading,selectConversation:r.selectConversation,startNewConversation:r.startNewConversation,refreshConversations:r.refreshConversations}}function Re(e,n){const t=F(),{name:o,description:r,parameters:i,handler:u,maxResultBytes:s,requiresApproval:f}=typeof e=="string"?{name:e,...n}:e,d=(0,a.useRef)(u);d.current=u,(0,a.useEffect)(()=>{const m=S=>d.current(S);return t.registerFunction(o,m,{description:r,parameters:i,maxResultBytes:s,requiresApproval:f}),()=>{t.unregisterFunction(o)}},[t,o,r,i,s,f])}function Ee(e,n){const t=F(),o=(0,a.useRef)(e);o.current=e,(0,a.useEffect)(()=>(t.registerNavigationFunction(r=>o.current(r),n),()=>{t.unregisterNavigationFunction()}),[t,n])}function Me(e,n){const t=F(),o=n?.functionName??"setPageState",r=n?.requiresApproval,i=(0,a.useRef)(e);i.current=e,(0,a.useEffect)(()=>{const u=i.current.map(s=>{const f=()=>i.current.find(d=>d.name===s.name)??s;return{name:s.name,description:s.description,schema:s.schema,get:s.get?()=>f().get?.():void 0,set:d=>f().set(d)}});return t.registerPageStateFunction(u,{functionName:o,requiresApproval:r}),()=>{t.unregisterPageStateFunction(o)}},[t,o,r])}function Fe(e){const n=F(),t=(0,a.useRef)(e);t.current=e,(0,a.useEffect)(()=>ae.attachAutoContinueAfterNavigation(n,()=>t.current),[n])}var Pe=new Set(["awaiting-approval"]);function Y(e){switch(e){case"progress_indicator":return"progress";case"reasoning":return"reasoning";case"confirmation_input":return"confirmation";case"form":return"form";default:return"status"}}function Te(e){return e.type==="client_function"?e.functionName==="navigateToPage"?"navigation":"action":Y(e.type)}function L(e,n){const t=(e??"").toLowerCase();return t.includes("reject")?"rejected":t.includes("error")||t.includes("fail")?"error":t.includes("done")||t.includes("complet")?"done":(t.includes("waiting")||t.includes("pending"))&&(n==="confirmation"||n==="form")?"awaiting-approval":"running"}function $(e){return typeof e!="string"||!e?"page":e.replace(/[-_]+/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/\b\w/g,n=>n.toUpperCase()).trim()}function De(e){switch(e.kind){case"navigation":return`Navigating to ${$(e.arguments?.page)}`;case"action":return e.functionName==="setPageState"?"Updating the page":e.functionName==="openFilteredConversations"?"Opening conversations":e.toolDisplayName||e.message||$(e.functionName)||"Working";case"progress":return e.message||"Working";case"reasoning":return e.message||"Thinking";case"confirmation":return e.message||"Waiting for your confirmation";case"form":return e.message||e.toolDisplayName||"Please fill in the form";default:return e.message||e.toolDisplayName||e.toolName||"Working"}}function We(e={}){const{includeReasoning:n=!1,labelFor:t}=e,o=E(),r=e.client||o;if(!r)throw new _.AgoError("useAgoActivity requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[i,u]=(0,a.useState)([]),s=(0,a.useRef)(new Set),f=(0,a.useRef)(void 0),d=(0,a.useRef)(t);d.current=t;const m=(0,a.useCallback)((g,h)=>{u(c=>{const b=c.findIndex(y=>y.id===g),p={...b>=0?c[b]:{id:g,kind:"status",label:"",status:"running",requiresApproval:!1,createdAt:new Date},...h};return p.label=d.current?.(p)??De(p),b>=0?[...c.slice(0,b),p,...c.slice(b+1)]:[...c,p]})},[]);(0,a.useEffect)(()=>{const g=v=>{f.current=v.messageId},h=v=>{const x=Y(v.type);x==="reasoning"&&!n||m(v.id,{kind:x,status:L(v.status,x),messageId:f.current,toolName:v.toolName,toolDisplayName:v.toolDisplayName,message:v.message,data:v.data,formSchema:v.formSchema,requiresApproval:x==="confirmation"||x==="form"})},c=v=>{v.invocationId&&m(v.invocationId,{kind:v.functionName==="navigateToPage"?"navigation":"action",status:"running",messageId:f.current,functionName:v.functionName,arguments:v.arguments})},b=v=>{v.invocationId&&m(v.invocationId,{kind:v.functionName==="navigateToPage"?"navigation":"action",status:"awaiting-approval",messageId:f.current,functionName:v.functionName,arguments:v.arguments,requiresApproval:!0})},p=v=>{if(!v.invocationId)return;const x=v.result,j=typeof v.result=="object"&&x!==null&&x.approved===!1&&x.reason==="user_rejected";m(v.invocationId,{status:v.error?"error":j?"rejected":"done",requiresApproval:!1})},y=v=>{for(const x of v.messages??[])if(x.role==="assistant")for(const j of x.toolCalls??[]){const N=Te(j);N==="reasoning"&&!n||/waiting/i.test(j.status??"")||m(j.id,{kind:N,status:L(j.status,N),messageId:x.id,toolName:j.toolName,toolDisplayName:j.toolDisplayName,functionName:j.functionName,arguments:j.arguments,message:j.message,data:j.data,formSchema:j.formSchema,requiresApproval:N==="confirmation"||N==="form"})}},w=v=>{u(x=>x.map(j=>j.status==="running"||j.status==="awaiting-approval"?{...j,status:v}:j))},C=()=>w("done"),R=()=>w("error");return r.on("message:start",g),r.on("toolCall:received",h),r.on("function:invoke",c),r.on("function:awaiting-approval",b),r.on("function:result",p),r.on("conversation:loaded",y),r.on("message:complete",C),r.on("message:error",R),()=>{r.off("message:start",g),r.off("toolCall:received",h),r.off("function:invoke",c),r.off("function:awaiting-approval",b),r.off("function:result",p),r.off("conversation:loaded",y),r.off("message:complete",C),r.off("message:error",R)}},[r,n,m]);const S=(0,a.useCallback)(async g=>{const h=i.find(c=>c.id===g);!h||h.status!=="awaiting-approval"||s.current.has(g)||h.kind!=="form"&&(s.current.add(g),m(g,{status:"running",requiresApproval:!1}),h.functionName?await r.approveFunction(g):await r.confirmToolCall(g))},[r,i,m]),I=(0,a.useCallback)(async g=>{const h=i.find(c=>c.id===g);!h||h.status!=="awaiting-approval"||s.current.has(g)||(s.current.add(g),m(g,{status:"rejected",requiresApproval:!1}),h.functionName?await r.rejectFunction(g):await r.rejectToolCall(g))},[r,i,m]),A=(0,a.useCallback)(async(g,h)=>{m(g,{status:"running",requiresApproval:!1}),await r.submitToolCallForm(g,h),m(g,{status:"done"})},[r,m]),k=(0,a.useCallback)(()=>{s.current.clear(),u([])},[]);return{items:i,latest:i.length>0?i[i.length-1]:void 0,isAwaitingApproval:i.some(g=>Pe.has(g.status)),approve:S,reject:I,submitForm:A,clear:k}}function Oe(e={}){const n=E(),t=e.client||n;if(!t)throw new _.AgoError("useAgoActivityLog requires an AgoClient. Either pass it as options.client or wrap your app in <AgoProvider>.","provider_missing_client");const[o,r]=(0,a.useState)(()=>t.getRecentActivity());(0,a.useEffect)(()=>{r(t.getRecentActivity());const s=()=>r(t.getRecentActivity());return t.on("activity:recorded",s),()=>t.off("activity:recorded",s)},[t]);const i=(0,a.useCallback)(s=>t.recordActivity(s),[t]),u=(0,a.useCallback)(()=>{t.clearActivity(),r([])},[t]);return{entries:o,latest:o.length>0?o[o.length-1]:void 0,record:i,clear:u}}function qe(e,n){const t=F(),o=(0,a.useId)(),r=n??o,i=(0,a.useRef)(e);i.current=e;const u=typeof e=="function";(0,a.useEffect)(()=>{if(typeof i.current=="function"){const s=()=>i.current();return t.addDynamicContext(r,s),()=>{t.removeDynamicContext(r)}}return t.setContext(r,i.current),()=>{t.removeContext(r)}},[t,r,u,u?"":JSON.stringify(e)])}function X(e){return(0,a.useSyncExternalStore)(e.subscribe,e.get,e.get)}var H={missing:[],complete:!1};function ze(e){const n=F(),t=e.schema!=null,o=JSON.stringify(e.schema??null),r=e.submit,i=r?typeof r=="string"?`client:${r}`:r.via==="backend"?"backend":"handler"in r?"client:handler":`client:${r.url}`:"none",u=JSON.stringify(e.initialValues??null),s=(0,a.useMemo)(()=>t?M.createFormCollector(e):null,[t,e.name,o,i,u,e.autoSubmit]),[f,d]=(0,a.useState)({collector:null,loading:!t,error:null});(0,a.useEffect)(()=>{if(t)return;let b=!1;return d({collector:null,loading:!0,error:null}),M.loadFormCollector(n,e).then(p=>{b||d({collector:p,loading:!1,error:null})}).catch(p=>{b||d({collector:null,loading:!1,error:p instanceof Error?p:new Error(String(p))})}),()=>{b=!0}},[n,t,e.name,i,u,e.autoSubmit]);const m=t?s:f.collector,S=t?!1:f.loading,I=t?null:f.error;(0,a.useEffect)(()=>{if(m)return m.install(n)},[n,m]);const A=(0,a.useMemo)(()=>_.createStore({values:e.initialValues??{},submitted:!1}),[u]),k=X(m?.store??A),g=(0,a.useMemo)(()=>m?.getStatus()??H,[k,m]),h=(0,a.useMemo)(()=>({...k,...g}),[k,g]),c=(0,a.useMemo)(()=>({name:e.name,store:A,functions:[],contextKey:`form:${e.name}`,contextProvider:()=>({name:`Form: ${e.name}`,description:""}),definitionContextKey:`form:${e.name}:definition`,definitionContextProvider:()=>({name:`Form definition: ${e.name}`,description:"",stable:!0}),install:()=>()=>{},hydrate:()=>{},submit:async()=>({ok:!1,error:"Form definition not loaded yet."}),getValues:()=>A.get().values,setValues:()=>{},reset:()=>{},getStatus:()=>H}),[e.name,A]);return{...m??c,state:h,loading:S,error:I}}exports.AgoNudge=Ne;exports.AgoProvider=le;exports.ChatInput=U;exports.ChatWidget=Ie;exports.Markdown=G;exports.Message=K;exports.__exportAll=oe;exports.createFormCollector=M.createFormCollector;exports.createMockClient=ie.createMockClient;exports.deriveFormStatus=M.deriveFormStatus;exports.loadFormCollector=M.loadFormCollector;exports.useAgo=B;exports.useAgoActivity=We;exports.useAgoActivityLog=Oe;exports.useAgoAutoContinueAfterNavigation=Fe;exports.useAgoClient=F;exports.useAgoContext=qe;exports.useAgoFunction=Re;exports.useAgoNavigation=Ee;exports.useAgoPageState=Me;exports.useAgoStore=X;exports.useChat=_e;exports.useConversation=V;exports.useFormCollector=ze;exports.useMessages=z;exports.useOptionalAgoClient=E;exports.useProactiveNudge=J;
|
package/dist/react.d.cts
CHANGED
|
@@ -195,9 +195,14 @@ declare class AgoClient {
|
|
|
195
195
|
*/
|
|
196
196
|
rejectFunction(invocationId: string): Promise<void>;
|
|
197
197
|
/**
|
|
198
|
-
* Get
|
|
198
|
+
* Get a page of conversations, newest-first. `pageSize` is capped at 100 by
|
|
199
|
+
* the backend (default 50). Returns the `{ data, has_more, total }` envelope
|
|
200
|
+
* so callers can page; `total` counts across all pages.
|
|
199
201
|
*/
|
|
200
|
-
getConversations(
|
|
202
|
+
getConversations(options?: {
|
|
203
|
+
page?: number;
|
|
204
|
+
pageSize?: number;
|
|
205
|
+
}): Promise<PaginatedResult<Conversation>>;
|
|
201
206
|
/**
|
|
202
207
|
* Get a specific conversation with messages
|
|
203
208
|
*/
|
|
@@ -543,6 +548,15 @@ declare interface AgoClientEvents {
|
|
|
543
548
|
* notably `createFormCollector` — can replay them to restore their state.
|
|
544
549
|
*/
|
|
545
550
|
"conversation:loaded": Conversation;
|
|
551
|
+
/**
|
|
552
|
+
* The conversation's title was generated and streamed during a live turn
|
|
553
|
+
* (the backend emits it once, at the end of the first turn). Lets the UI
|
|
554
|
+
* update a header without a refetch.
|
|
555
|
+
*/
|
|
556
|
+
"conversation:title": {
|
|
557
|
+
conversationId: string;
|
|
558
|
+
title: string;
|
|
559
|
+
};
|
|
546
560
|
"toolCall:received": ToolCallData;
|
|
547
561
|
"toolCall:form": ToolCallData;
|
|
548
562
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -1434,6 +1448,16 @@ export declare type NudgeAction = {
|
|
|
1434
1448
|
setPageState: Record<string, unknown>;
|
|
1435
1449
|
};
|
|
1436
1450
|
|
|
1451
|
+
/**
|
|
1452
|
+
* A page of list results, mirroring the API's `{ data, has_more, total }`
|
|
1453
|
+
* envelope. `total` is the count across all pages, not just this page.
|
|
1454
|
+
*/
|
|
1455
|
+
export declare interface PaginatedResult<T> {
|
|
1456
|
+
data: T[];
|
|
1457
|
+
hasMore: boolean;
|
|
1458
|
+
total: number;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1437
1461
|
/**
|
|
1438
1462
|
* Controller returned by {@link createAgoProactive} (also available as
|
|
1439
1463
|
* `client.proactive`).
|
|
@@ -1686,6 +1710,8 @@ declare interface SSEChunkData {
|
|
|
1686
1710
|
thread?: {
|
|
1687
1711
|
id: string;
|
|
1688
1712
|
};
|
|
1713
|
+
/** Generated conversation title, streamed once at the end of the first turn. */
|
|
1714
|
+
title?: string;
|
|
1689
1715
|
agent?: {
|
|
1690
1716
|
id: string;
|
|
1691
1717
|
name: string;
|
package/dist/react.d.ts
CHANGED
|
@@ -195,9 +195,14 @@ declare class AgoClient {
|
|
|
195
195
|
*/
|
|
196
196
|
rejectFunction(invocationId: string): Promise<void>;
|
|
197
197
|
/**
|
|
198
|
-
* Get
|
|
198
|
+
* Get a page of conversations, newest-first. `pageSize` is capped at 100 by
|
|
199
|
+
* the backend (default 50). Returns the `{ data, has_more, total }` envelope
|
|
200
|
+
* so callers can page; `total` counts across all pages.
|
|
199
201
|
*/
|
|
200
|
-
getConversations(
|
|
202
|
+
getConversations(options?: {
|
|
203
|
+
page?: number;
|
|
204
|
+
pageSize?: number;
|
|
205
|
+
}): Promise<PaginatedResult<Conversation>>;
|
|
201
206
|
/**
|
|
202
207
|
* Get a specific conversation with messages
|
|
203
208
|
*/
|
|
@@ -543,6 +548,15 @@ declare interface AgoClientEvents {
|
|
|
543
548
|
* notably `createFormCollector` — can replay them to restore their state.
|
|
544
549
|
*/
|
|
545
550
|
"conversation:loaded": Conversation;
|
|
551
|
+
/**
|
|
552
|
+
* The conversation's title was generated and streamed during a live turn
|
|
553
|
+
* (the backend emits it once, at the end of the first turn). Lets the UI
|
|
554
|
+
* update a header without a refetch.
|
|
555
|
+
*/
|
|
556
|
+
"conversation:title": {
|
|
557
|
+
conversationId: string;
|
|
558
|
+
title: string;
|
|
559
|
+
};
|
|
546
560
|
"toolCall:received": ToolCallData;
|
|
547
561
|
"toolCall:form": ToolCallData;
|
|
548
562
|
"function:invoke": ClientFunctionInvocation;
|
|
@@ -1434,6 +1448,16 @@ export declare type NudgeAction = {
|
|
|
1434
1448
|
setPageState: Record<string, unknown>;
|
|
1435
1449
|
};
|
|
1436
1450
|
|
|
1451
|
+
/**
|
|
1452
|
+
* A page of list results, mirroring the API's `{ data, has_more, total }`
|
|
1453
|
+
* envelope. `total` is the count across all pages, not just this page.
|
|
1454
|
+
*/
|
|
1455
|
+
export declare interface PaginatedResult<T> {
|
|
1456
|
+
data: T[];
|
|
1457
|
+
hasMore: boolean;
|
|
1458
|
+
total: number;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1437
1461
|
/**
|
|
1438
1462
|
* Controller returned by {@link createAgoProactive} (also available as
|
|
1439
1463
|
* `client.proactive`).
|
|
@@ -1686,6 +1710,8 @@ declare interface SSEChunkData {
|
|
|
1686
1710
|
thread?: {
|
|
1687
1711
|
id: string;
|
|
1688
1712
|
};
|
|
1713
|
+
/** Generated conversation title, streamed once at the end of the first turn. */
|
|
1714
|
+
title?: string;
|
|
1689
1715
|
agent?: {
|
|
1690
1716
|
id: string;
|
|
1691
1717
|
name: string;
|