@useago/sdk 1.3.2 → 1.4.0
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-B2BU8tfB.cjs +8 -0
- package/dist/{AgoClient-Cwx_eYSu.js → AgoClient-BrhKkDWt.js} +129 -88
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +87 -1
- package/dist/angular.d.ts +87 -1
- package/dist/angular.js +13 -7
- package/dist/{createConversationSession-B3h567tt.js → createConversationSession-ByePKfus.js} +1 -1
- package/dist/{createConversationSession-DV0Xp_3O.cjs → createConversationSession-Cin8dVNq.cjs} +1 -1
- package/dist/{createFormCollector-CyWisAkI.js → createFormCollector-BYKe5Uxm.js} +1 -1
- package/dist/{createFormCollector-BB3Uscuo.cjs → createFormCollector-CpYX_5PT.cjs} +1 -1
- package/dist/devtools.d.cts +83 -1
- package/dist/devtools.d.ts +83 -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 +83 -1
- package/dist/index.d.ts +83 -1
- package/dist/index.js +3 -3
- package/dist/react.cjs +3 -3
- package/dist/react.d.cts +148 -2
- package/dist/react.d.ts +148 -2
- package/dist/react.js +468 -390
- package/dist/testing.d.cts +83 -1
- package/dist/testing.d.ts +83 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +115 -1
- package/dist/vue.d.ts +115 -1
- package/dist/vue.js +66 -57
- package/dist/widget.cjs +1 -1
- package/dist/widget.d.cts +83 -1
- package/dist/widget.d.ts +83 -1
- package/dist/widget.js +3 -3
- package/package.json +1 -1
- package/dist/AgoClient-CzSmJQxl.cjs +0 -6
package/dist/index.d.cts
CHANGED
|
@@ -165,6 +165,37 @@ export declare class AgoClient {
|
|
|
165
165
|
path: string;
|
|
166
166
|
description: string;
|
|
167
167
|
}>): void;
|
|
168
|
+
/**
|
|
169
|
+
* Register a "page state" function that lets AGO change the current page's
|
|
170
|
+
* state (filters, sort, view mode, selection…) and reads the current state
|
|
171
|
+
* back as dynamic context. This is the state-mutation mirror of
|
|
172
|
+
* {@link registerNavigationFunction}.
|
|
173
|
+
*
|
|
174
|
+
* It does two things:
|
|
175
|
+
* - Synthesizes ONE client function (default name `setPageState`) whose
|
|
176
|
+
* properties are the controls — all optional, so the agent sets only the
|
|
177
|
+
* ones the user asked for.
|
|
178
|
+
* - Registers a dynamic context provider (keyed `page-state:<fnName>`) that
|
|
179
|
+
* reports each control's current `get()` value on every message.
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* client.registerPageStateFunction([
|
|
183
|
+
* {
|
|
184
|
+
* name: "statusFilter",
|
|
185
|
+
* description: "Filter the list by review status",
|
|
186
|
+
* schema: { type: "string", enum: ["all", "pending", "approved"] },
|
|
187
|
+
* get: () => filters.status,
|
|
188
|
+
* set: (v) => setFilters({ ...filters, status: v }),
|
|
189
|
+
* },
|
|
190
|
+
* ]);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
|
|
194
|
+
/**
|
|
195
|
+
* Unregister a page state function and its dynamic context provider.
|
|
196
|
+
* Mirror of unregistering `navigateToPage`.
|
|
197
|
+
*/
|
|
198
|
+
unregisterPageStateFunction(functionName?: string): void;
|
|
168
199
|
/**
|
|
169
200
|
* Register or update a piece of client-side context.
|
|
170
201
|
* This context is sent with every message so the AI understands the user's situation.
|
|
@@ -421,6 +452,12 @@ export declare interface AgoMessage {
|
|
|
421
452
|
followUpReplies?: string[];
|
|
422
453
|
/** Uploaded files on this message (usually the user's). */
|
|
423
454
|
attachments?: AgoAttachment[];
|
|
455
|
+
/**
|
|
456
|
+
* True when the backend flagged this message as hidden (e.g. an
|
|
457
|
+
* auto-continuation nudge). Kept in the model's context but not displayed;
|
|
458
|
+
* UI helpers like `useMessages`/`ChatWidget` filter these out.
|
|
459
|
+
*/
|
|
460
|
+
hidden?: boolean;
|
|
424
461
|
createdAt: Date;
|
|
425
462
|
}
|
|
426
463
|
|
|
@@ -432,6 +469,14 @@ export declare class AgoNetworkError extends AgoError {
|
|
|
432
469
|
constructor(message: string, originalError?: Error | undefined);
|
|
433
470
|
}
|
|
434
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Options for {@link AgoClient.registerPageStateFunction}.
|
|
474
|
+
*/
|
|
475
|
+
export declare interface AgoPageStateOptions {
|
|
476
|
+
/** Name of the synthesized client function. Defaults to "setPageState". */
|
|
477
|
+
functionName?: string;
|
|
478
|
+
}
|
|
479
|
+
|
|
435
480
|
/**
|
|
436
481
|
* Knowledge source citation
|
|
437
482
|
*/
|
|
@@ -441,6 +486,32 @@ export declare interface AgoSource {
|
|
|
441
486
|
url?: string;
|
|
442
487
|
}
|
|
443
488
|
|
|
489
|
+
/**
|
|
490
|
+
* A single editable control on the current page (a filter, a sort, a view mode,
|
|
491
|
+
* a selection…). It becomes one optional property of the synthesized
|
|
492
|
+
* `setPageState` function, and its current value is surfaced back to the agent
|
|
493
|
+
* as dynamic context. This is the state-mutation mirror of a navigation route.
|
|
494
|
+
*/
|
|
495
|
+
export declare interface AgoStateControl<T = unknown> {
|
|
496
|
+
/** Machine name of the control, e.g. "statusFilter". Becomes a property of the tool. */
|
|
497
|
+
name: string;
|
|
498
|
+
/** Description for the LLM, e.g. "Filter the list by review status". */
|
|
499
|
+
description: string;
|
|
500
|
+
/** JSON schema for a SINGLE field (like one property of navigateToPage). */
|
|
501
|
+
schema: {
|
|
502
|
+
type: "string" | "number" | "boolean" | "array";
|
|
503
|
+
enum?: (string | number)[];
|
|
504
|
+
items?: {
|
|
505
|
+
type: string;
|
|
506
|
+
enum?: (string | number)[];
|
|
507
|
+
};
|
|
508
|
+
};
|
|
509
|
+
/** Current value → pushed as dynamic context so the agent knows what to change. */
|
|
510
|
+
get?: () => T;
|
|
511
|
+
/** Apply the state change on the page. May be async. */
|
|
512
|
+
set: (value: T) => void | Promise<void>;
|
|
513
|
+
}
|
|
514
|
+
|
|
444
515
|
/**
|
|
445
516
|
* SSE stream error
|
|
446
517
|
*
|
|
@@ -602,7 +673,11 @@ export declare interface ClientFunctionSchema {
|
|
|
602
673
|
properties: Record<string, {
|
|
603
674
|
type: string;
|
|
604
675
|
description?: string;
|
|
605
|
-
enum?: string[];
|
|
676
|
+
enum?: (string | number)[];
|
|
677
|
+
items?: {
|
|
678
|
+
type: string;
|
|
679
|
+
enum?: (string | number)[];
|
|
680
|
+
};
|
|
606
681
|
default?: unknown;
|
|
607
682
|
}>;
|
|
608
683
|
required?: string[];
|
|
@@ -1325,6 +1400,13 @@ export declare interface SendMessageOptions {
|
|
|
1325
1400
|
agentId?: string;
|
|
1326
1401
|
/** File attachments */
|
|
1327
1402
|
files?: File[];
|
|
1403
|
+
/**
|
|
1404
|
+
* Mark this message as hidden. The backend keeps it in the model's context but
|
|
1405
|
+
* flags it so the UI never displays it. Used by auto-continuation to nudge the
|
|
1406
|
+
* agent after a navigation without polluting the visible transcript.
|
|
1407
|
+
* Requires backend support for the `hidden` flag; older backends ignore it.
|
|
1408
|
+
*/
|
|
1409
|
+
hidden?: boolean;
|
|
1328
1410
|
}
|
|
1329
1411
|
|
|
1330
1412
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -165,6 +165,37 @@ export declare class AgoClient {
|
|
|
165
165
|
path: string;
|
|
166
166
|
description: string;
|
|
167
167
|
}>): void;
|
|
168
|
+
/**
|
|
169
|
+
* Register a "page state" function that lets AGO change the current page's
|
|
170
|
+
* state (filters, sort, view mode, selection…) and reads the current state
|
|
171
|
+
* back as dynamic context. This is the state-mutation mirror of
|
|
172
|
+
* {@link registerNavigationFunction}.
|
|
173
|
+
*
|
|
174
|
+
* It does two things:
|
|
175
|
+
* - Synthesizes ONE client function (default name `setPageState`) whose
|
|
176
|
+
* properties are the controls — all optional, so the agent sets only the
|
|
177
|
+
* ones the user asked for.
|
|
178
|
+
* - Registers a dynamic context provider (keyed `page-state:<fnName>`) that
|
|
179
|
+
* reports each control's current `get()` value on every message.
|
|
180
|
+
*
|
|
181
|
+
* ```ts
|
|
182
|
+
* client.registerPageStateFunction([
|
|
183
|
+
* {
|
|
184
|
+
* name: "statusFilter",
|
|
185
|
+
* description: "Filter the list by review status",
|
|
186
|
+
* schema: { type: "string", enum: ["all", "pending", "approved"] },
|
|
187
|
+
* get: () => filters.status,
|
|
188
|
+
* set: (v) => setFilters({ ...filters, status: v }),
|
|
189
|
+
* },
|
|
190
|
+
* ]);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
|
|
194
|
+
/**
|
|
195
|
+
* Unregister a page state function and its dynamic context provider.
|
|
196
|
+
* Mirror of unregistering `navigateToPage`.
|
|
197
|
+
*/
|
|
198
|
+
unregisterPageStateFunction(functionName?: string): void;
|
|
168
199
|
/**
|
|
169
200
|
* Register or update a piece of client-side context.
|
|
170
201
|
* This context is sent with every message so the AI understands the user's situation.
|
|
@@ -421,6 +452,12 @@ export declare interface AgoMessage {
|
|
|
421
452
|
followUpReplies?: string[];
|
|
422
453
|
/** Uploaded files on this message (usually the user's). */
|
|
423
454
|
attachments?: AgoAttachment[];
|
|
455
|
+
/**
|
|
456
|
+
* True when the backend flagged this message as hidden (e.g. an
|
|
457
|
+
* auto-continuation nudge). Kept in the model's context but not displayed;
|
|
458
|
+
* UI helpers like `useMessages`/`ChatWidget` filter these out.
|
|
459
|
+
*/
|
|
460
|
+
hidden?: boolean;
|
|
424
461
|
createdAt: Date;
|
|
425
462
|
}
|
|
426
463
|
|
|
@@ -432,6 +469,14 @@ export declare class AgoNetworkError extends AgoError {
|
|
|
432
469
|
constructor(message: string, originalError?: Error | undefined);
|
|
433
470
|
}
|
|
434
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Options for {@link AgoClient.registerPageStateFunction}.
|
|
474
|
+
*/
|
|
475
|
+
export declare interface AgoPageStateOptions {
|
|
476
|
+
/** Name of the synthesized client function. Defaults to "setPageState". */
|
|
477
|
+
functionName?: string;
|
|
478
|
+
}
|
|
479
|
+
|
|
435
480
|
/**
|
|
436
481
|
* Knowledge source citation
|
|
437
482
|
*/
|
|
@@ -441,6 +486,32 @@ export declare interface AgoSource {
|
|
|
441
486
|
url?: string;
|
|
442
487
|
}
|
|
443
488
|
|
|
489
|
+
/**
|
|
490
|
+
* A single editable control on the current page (a filter, a sort, a view mode,
|
|
491
|
+
* a selection…). It becomes one optional property of the synthesized
|
|
492
|
+
* `setPageState` function, and its current value is surfaced back to the agent
|
|
493
|
+
* as dynamic context. This is the state-mutation mirror of a navigation route.
|
|
494
|
+
*/
|
|
495
|
+
export declare interface AgoStateControl<T = unknown> {
|
|
496
|
+
/** Machine name of the control, e.g. "statusFilter". Becomes a property of the tool. */
|
|
497
|
+
name: string;
|
|
498
|
+
/** Description for the LLM, e.g. "Filter the list by review status". */
|
|
499
|
+
description: string;
|
|
500
|
+
/** JSON schema for a SINGLE field (like one property of navigateToPage). */
|
|
501
|
+
schema: {
|
|
502
|
+
type: "string" | "number" | "boolean" | "array";
|
|
503
|
+
enum?: (string | number)[];
|
|
504
|
+
items?: {
|
|
505
|
+
type: string;
|
|
506
|
+
enum?: (string | number)[];
|
|
507
|
+
};
|
|
508
|
+
};
|
|
509
|
+
/** Current value → pushed as dynamic context so the agent knows what to change. */
|
|
510
|
+
get?: () => T;
|
|
511
|
+
/** Apply the state change on the page. May be async. */
|
|
512
|
+
set: (value: T) => void | Promise<void>;
|
|
513
|
+
}
|
|
514
|
+
|
|
444
515
|
/**
|
|
445
516
|
* SSE stream error
|
|
446
517
|
*
|
|
@@ -602,7 +673,11 @@ export declare interface ClientFunctionSchema {
|
|
|
602
673
|
properties: Record<string, {
|
|
603
674
|
type: string;
|
|
604
675
|
description?: string;
|
|
605
|
-
enum?: string[];
|
|
676
|
+
enum?: (string | number)[];
|
|
677
|
+
items?: {
|
|
678
|
+
type: string;
|
|
679
|
+
enum?: (string | number)[];
|
|
680
|
+
};
|
|
606
681
|
default?: unknown;
|
|
607
682
|
}>;
|
|
608
683
|
required?: string[];
|
|
@@ -1325,6 +1400,13 @@ export declare interface SendMessageOptions {
|
|
|
1325
1400
|
agentId?: string;
|
|
1326
1401
|
/** File attachments */
|
|
1327
1402
|
files?: File[];
|
|
1403
|
+
/**
|
|
1404
|
+
* Mark this message as hidden. The backend keeps it in the model's context but
|
|
1405
|
+
* flags it so the UI never displays it. Used by auto-continuation to nudge the
|
|
1406
|
+
* agent after a navigation without polluting the visible transcript.
|
|
1407
|
+
* Requires backend support for the `hidden` flag; older backends ignore it.
|
|
1408
|
+
*/
|
|
1409
|
+
hidden?: boolean;
|
|
1328
1410
|
}
|
|
1329
1411
|
|
|
1330
1412
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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-
|
|
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-BrhKkDWt.js";
|
|
3
|
+
import { i as $, n as K, r as Q, t as V } from "./createFormCollector-BYKe5Uxm.js";
|
|
4
|
+
import { t as X } from "./createConversationSession-ByePKfus.js";
|
|
5
5
|
import { t as Z } from "./createMockClient-DwdxNwEn.js";
|
|
6
6
|
import "./testing.js";
|
|
7
7
|
function oe(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-B2BU8tfB.cjs"),M=require("./createFormCollector-CpYX_5PT.cjs"),G=require("./createMockClient-zHQ0cjUH.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.unregisterFunction("navigateToPage")}),[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;
|
package/dist/react.d.cts
CHANGED
|
@@ -30,6 +30,23 @@ declare interface AgoAttachment {
|
|
|
30
30
|
isSafeImage: boolean;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export declare interface AgoAutoContinueOptions {
|
|
34
|
+
/** Function names whose invocation counts as "navigated". Default `["navigateToPage"]`. */
|
|
35
|
+
navigationFunctions?: string[];
|
|
36
|
+
/** Registered function that signals the destination has editable state. Default `"setPageState"`. */
|
|
37
|
+
pageStateFunctionName?: string;
|
|
38
|
+
/** The hidden continuation prompt. Override for i18n / tone. */
|
|
39
|
+
continuationPrompt?: string;
|
|
40
|
+
/** Max continuations per user gesture (guards navigate→continue→navigate loops). Default `1`. */
|
|
41
|
+
maxDepth?: number;
|
|
42
|
+
/** How long to wait for the destination page to register page-state before giving up. Default `4000`ms. */
|
|
43
|
+
readinessTimeoutMs?: number;
|
|
44
|
+
/** Extra settle delay after page-state appears, to let sibling state mount. Default `150`ms. */
|
|
45
|
+
settleMs?: number;
|
|
46
|
+
/** Opt-out escape hatch. Default `true`. */
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
33
50
|
/**
|
|
34
51
|
* Main SDK client for AGO Chat integration
|
|
35
52
|
*/
|
|
@@ -156,6 +173,37 @@ declare class AgoClient {
|
|
|
156
173
|
path: string;
|
|
157
174
|
description: string;
|
|
158
175
|
}>): void;
|
|
176
|
+
/**
|
|
177
|
+
* Register a "page state" function that lets AGO change the current page's
|
|
178
|
+
* state (filters, sort, view mode, selection…) and reads the current state
|
|
179
|
+
* back as dynamic context. This is the state-mutation mirror of
|
|
180
|
+
* {@link registerNavigationFunction}.
|
|
181
|
+
*
|
|
182
|
+
* It does two things:
|
|
183
|
+
* - Synthesizes ONE client function (default name `setPageState`) whose
|
|
184
|
+
* properties are the controls — all optional, so the agent sets only the
|
|
185
|
+
* ones the user asked for.
|
|
186
|
+
* - Registers a dynamic context provider (keyed `page-state:<fnName>`) that
|
|
187
|
+
* reports each control's current `get()` value on every message.
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* client.registerPageStateFunction([
|
|
191
|
+
* {
|
|
192
|
+
* name: "statusFilter",
|
|
193
|
+
* description: "Filter the list by review status",
|
|
194
|
+
* schema: { type: "string", enum: ["all", "pending", "approved"] },
|
|
195
|
+
* get: () => filters.status,
|
|
196
|
+
* set: (v) => setFilters({ ...filters, status: v }),
|
|
197
|
+
* },
|
|
198
|
+
* ]);
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
registerPageStateFunction(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
|
|
202
|
+
/**
|
|
203
|
+
* Unregister a page state function and its dynamic context provider.
|
|
204
|
+
* Mirror of unregistering `navigateToPage`.
|
|
205
|
+
*/
|
|
206
|
+
unregisterPageStateFunction(functionName?: string): void;
|
|
159
207
|
/**
|
|
160
208
|
* Register or update a piece of client-side context.
|
|
161
209
|
* This context is sent with every message so the AI understands the user's situation.
|
|
@@ -401,9 +449,23 @@ export declare interface AgoMessage {
|
|
|
401
449
|
followUpReplies?: string[];
|
|
402
450
|
/** Uploaded files on this message (usually the user's). */
|
|
403
451
|
attachments?: AgoAttachment[];
|
|
452
|
+
/**
|
|
453
|
+
* True when the backend flagged this message as hidden (e.g. an
|
|
454
|
+
* auto-continuation nudge). Kept in the model's context but not displayed;
|
|
455
|
+
* UI helpers like `useMessages`/`ChatWidget` filter these out.
|
|
456
|
+
*/
|
|
457
|
+
hidden?: boolean;
|
|
404
458
|
createdAt: Date;
|
|
405
459
|
}
|
|
406
460
|
|
|
461
|
+
/**
|
|
462
|
+
* Options for {@link AgoClient.registerPageStateFunction}.
|
|
463
|
+
*/
|
|
464
|
+
export declare interface AgoPageStateOptions {
|
|
465
|
+
/** Name of the synthesized client function. Defaults to "setPageState". */
|
|
466
|
+
functionName?: string;
|
|
467
|
+
}
|
|
468
|
+
|
|
407
469
|
/**
|
|
408
470
|
* Provides an AgoClient to all descendant components via React context.
|
|
409
471
|
*
|
|
@@ -457,6 +519,32 @@ export declare interface AgoSource {
|
|
|
457
519
|
url?: string;
|
|
458
520
|
}
|
|
459
521
|
|
|
522
|
+
/**
|
|
523
|
+
* A single editable control on the current page (a filter, a sort, a view mode,
|
|
524
|
+
* a selection…). It becomes one optional property of the synthesized
|
|
525
|
+
* `setPageState` function, and its current value is surfaced back to the agent
|
|
526
|
+
* as dynamic context. This is the state-mutation mirror of a navigation route.
|
|
527
|
+
*/
|
|
528
|
+
export declare interface AgoStateControl<T = unknown> {
|
|
529
|
+
/** Machine name of the control, e.g. "statusFilter". Becomes a property of the tool. */
|
|
530
|
+
name: string;
|
|
531
|
+
/** Description for the LLM, e.g. "Filter the list by review status". */
|
|
532
|
+
description: string;
|
|
533
|
+
/** JSON schema for a SINGLE field (like one property of navigateToPage). */
|
|
534
|
+
schema: {
|
|
535
|
+
type: "string" | "number" | "boolean" | "array";
|
|
536
|
+
enum?: (string | number)[];
|
|
537
|
+
items?: {
|
|
538
|
+
type: string;
|
|
539
|
+
enum?: (string | number)[];
|
|
540
|
+
};
|
|
541
|
+
};
|
|
542
|
+
/** Current value → pushed as dynamic context so the agent knows what to change. */
|
|
543
|
+
get?: () => T;
|
|
544
|
+
/** Apply the state change on the page. May be async. */
|
|
545
|
+
set: (value: T) => void | Promise<void>;
|
|
546
|
+
}
|
|
547
|
+
|
|
460
548
|
/**
|
|
461
549
|
* Chat input component with send button
|
|
462
550
|
*/
|
|
@@ -566,7 +654,11 @@ declare interface ClientFunctionSchema {
|
|
|
566
654
|
properties: Record<string, {
|
|
567
655
|
type: string;
|
|
568
656
|
description?: string;
|
|
569
|
-
enum?: string[];
|
|
657
|
+
enum?: (string | number)[];
|
|
658
|
+
items?: {
|
|
659
|
+
type: string;
|
|
660
|
+
enum?: (string | number)[];
|
|
661
|
+
};
|
|
570
662
|
default?: unknown;
|
|
571
663
|
}>;
|
|
572
664
|
required?: string[];
|
|
@@ -935,6 +1027,13 @@ declare interface SendMessageOptions {
|
|
|
935
1027
|
agentId?: string;
|
|
936
1028
|
/** File attachments */
|
|
937
1029
|
files?: File[];
|
|
1030
|
+
/**
|
|
1031
|
+
* Mark this message as hidden. The backend keeps it in the model's context but
|
|
1032
|
+
* flags it so the UI never displays it. Used by auto-continuation to nudge the
|
|
1033
|
+
* agent after a navigation without polluting the visible transcript.
|
|
1034
|
+
* Requires backend support for the `hidden` flag; older backends ignore it.
|
|
1035
|
+
*/
|
|
1036
|
+
hidden?: boolean;
|
|
938
1037
|
}
|
|
939
1038
|
|
|
940
1039
|
/**
|
|
@@ -1053,6 +1152,27 @@ export declare function useAgo(config: UseAgoOptions | null): {
|
|
|
1053
1152
|
isReady: boolean;
|
|
1054
1153
|
};
|
|
1055
1154
|
|
|
1155
|
+
/**
|
|
1156
|
+
* Auto-continue the agent after it navigates, so a "go to page B and change X"
|
|
1157
|
+
* request completes in one user gesture. Mount this once inside `AgoProvider`.
|
|
1158
|
+
*
|
|
1159
|
+
* How it works: when the agent calls the navigation function and that turn ends,
|
|
1160
|
+
* this waits for the destination page's `useAgoPageState` to register (so the
|
|
1161
|
+
* SDK will ship its `setPageState` + current state on the next send), then sends
|
|
1162
|
+
* a hidden continuation message. The agent then applies the state in a second
|
|
1163
|
+
* turn. The continuation is `hidden`, so it never shows in the transcript
|
|
1164
|
+
* (requires backend support for the `hidden` flag).
|
|
1165
|
+
*
|
|
1166
|
+
* ```tsx
|
|
1167
|
+
* function AppShell() {
|
|
1168
|
+
* useAgoNavigation(navigate, routes);
|
|
1169
|
+
* useAgoAutoContinueAfterNavigation();
|
|
1170
|
+
* return <Outlet />;
|
|
1171
|
+
* }
|
|
1172
|
+
* ```
|
|
1173
|
+
*/
|
|
1174
|
+
export declare function useAgoAutoContinueAfterNavigation(options?: AgoAutoContinueOptions): void;
|
|
1175
|
+
|
|
1056
1176
|
/**
|
|
1057
1177
|
* Returns the AgoClient from the nearest AgoProvider.
|
|
1058
1178
|
* Throws if used outside of an AgoProvider.
|
|
@@ -1134,7 +1254,11 @@ export declare interface UseAgoFunctionOptions {
|
|
|
1134
1254
|
properties: Record<string, {
|
|
1135
1255
|
type: string;
|
|
1136
1256
|
description?: string;
|
|
1137
|
-
enum?: string[];
|
|
1257
|
+
enum?: (string | number)[];
|
|
1258
|
+
items?: {
|
|
1259
|
+
type: string;
|
|
1260
|
+
enum?: (string | number)[];
|
|
1261
|
+
};
|
|
1138
1262
|
default?: unknown;
|
|
1139
1263
|
}>;
|
|
1140
1264
|
required?: string[];
|
|
@@ -1158,6 +1282,28 @@ export declare function useAgoNavigation(navigate: (path: string) => void, route
|
|
|
1158
1282
|
|
|
1159
1283
|
export declare type UseAgoOptions = AgoConfig;
|
|
1160
1284
|
|
|
1285
|
+
/**
|
|
1286
|
+
* Declaratively register editable page-state controls with the AGO agent.
|
|
1287
|
+
* The state-mutation mirror of `useAgoNavigation`: it wraps
|
|
1288
|
+
* `registerPageStateFunction` with React lifecycle management, so the agent can
|
|
1289
|
+
* change the current page's state (filters, sort, view mode…) and read the
|
|
1290
|
+
* current state back.
|
|
1291
|
+
*
|
|
1292
|
+
* ```tsx
|
|
1293
|
+
* const [status, setStatus] = useState("all");
|
|
1294
|
+
* useAgoPageState([
|
|
1295
|
+
* {
|
|
1296
|
+
* name: "statusFilter",
|
|
1297
|
+
* description: "Filter the list by review status",
|
|
1298
|
+
* schema: { type: "string", enum: ["all", "pending", "approved"] },
|
|
1299
|
+
* get: () => status,
|
|
1300
|
+
* set: setStatus,
|
|
1301
|
+
* },
|
|
1302
|
+
* ]);
|
|
1303
|
+
* ```
|
|
1304
|
+
*/
|
|
1305
|
+
export declare function useAgoPageState(controls: AgoStateControl[], opts?: AgoPageStateOptions): void;
|
|
1306
|
+
|
|
1161
1307
|
export declare interface UseAgoResult {
|
|
1162
1308
|
/** The AGO client instance */
|
|
1163
1309
|
client: AgoClient;
|