@useago/sdk 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -176,6 +176,7 @@ declare class AgoClient {
176
176
  * call it when their store updates so observers like the dev panel stay live.
177
177
  */
178
178
  notifyContextChanged(): void;
179
+ /* Excluded from this release type: emitFormEvent */
179
180
  /**
180
181
  * Enable automatic capture of the current browser page (URL + title).
181
182
  * Injected as a dynamic context entry named `browser-page`.
@@ -290,6 +291,27 @@ declare interface AgoClientEvents {
290
291
  result: unknown;
291
292
  error?: string;
292
293
  };
294
+ /**
295
+ * A form collector submitted successfully. `result` is the raw submit response
296
+ * (POST body / handler return value / backend relay result) — the third-party
297
+ * API's answer. `values` is the submitted field set, `name` the collector name.
298
+ */
299
+ "form:submitted": {
300
+ name: string;
301
+ values: Record<string, unknown>;
302
+ result: unknown;
303
+ };
304
+ /**
305
+ * A form collector submit was attempted and failed at the network/server level
306
+ * (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
307
+ * pre-checks (missing required fields, no submit target) are NOT errors and do
308
+ * not fire this — they are returned to the caller as `{ ok: false }`.
309
+ */
310
+ "form:error": {
311
+ name: string;
312
+ values: Record<string, unknown>;
313
+ error: string;
314
+ };
293
315
  "connection:status": {
294
316
  connected: boolean;
295
317
  };
@@ -474,7 +496,7 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
474
496
 
475
497
  /**
476
498
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
477
- * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
499
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes from the LLM tool's `parameters` (the full schema still reaches the agent via dynamic context).
478
500
  */
479
501
  declare interface FormCollectorSchema {
480
502
  type: "object";
@@ -491,17 +513,32 @@ declare interface FormField {
491
513
  }
492
514
 
493
515
  /**
494
- * A field's conditional-requiredness rule. The field becomes required exactly
495
- * when the controlling `property` matches `value` against the answers collected
496
- * so far:
516
+ * A field's conditional-requiredness rule: either a single {@link FormFieldLeafCondition}
517
+ * or a boolean combination of rules. `anyOf` is OR (true when any nested rule
518
+ * holds); `allOf` is AND (true when every nested rule holds). Both nest
519
+ * arbitrarily, so you can mix them, e.g.
520
+ * `{ anyOf: [{ property: "a", op: ">=", value: 1 }, { property: "b", value: "1" }] }`.
521
+ * An empty `anyOf` is never required; an empty `allOf` is always required.
522
+ *
523
+ * Stripped from the LLM tool's `parameters` (see {@link toWireParameters}), but the
524
+ * full schema, `requiredWhen` included, still reaches the agent via the dynamic
525
+ * context so it knows when each field becomes required.
526
+ */
527
+ declare type FormFieldCondition = FormFieldLeafCondition | {
528
+ anyOf: FormFieldCondition[];
529
+ } | {
530
+ allOf: FormFieldCondition[];
531
+ };
532
+
533
+ /**
534
+ * A single leaf comparison. The field it guards becomes required exactly when the
535
+ * controlling `property` matches `value` against the answers collected so far:
497
536
  * - a single `value`, no `op` — equality (compared as strings);
498
537
  * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
499
538
  * - an array `value`, no `op` — "one of": matches when the property equals any
500
539
  * listed value.
501
- *
502
- * SDK-only — it is stripped from the schema before it reaches the LLM tool
503
540
  */
504
- declare interface FormFieldCondition {
541
+ declare interface FormFieldLeafCondition {
505
542
  /** The controlling field whose value the rule tests. */
506
543
  property: string;
507
544
  /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
@@ -522,7 +559,8 @@ declare interface FormFieldSchema {
522
559
  default?: unknown;
523
560
  /**
524
561
  * Makes the field required only while this condition holds. Drives the dynamic
525
- * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
562
+ * `missing` list; stripped from the LLM tool's `parameters` (still sent to the
563
+ * agent via dynamic context). See {@link toWireParameters}.
526
564
  */
527
565
  requiredWhen?: FormFieldCondition;
528
566
  }
package/dist/testing.d.ts CHANGED
@@ -176,6 +176,7 @@ declare class AgoClient {
176
176
  * call it when their store updates so observers like the dev panel stay live.
177
177
  */
178
178
  notifyContextChanged(): void;
179
+ /* Excluded from this release type: emitFormEvent */
179
180
  /**
180
181
  * Enable automatic capture of the current browser page (URL + title).
181
182
  * Injected as a dynamic context entry named `browser-page`.
@@ -290,6 +291,27 @@ declare interface AgoClientEvents {
290
291
  result: unknown;
291
292
  error?: string;
292
293
  };
294
+ /**
295
+ * A form collector submitted successfully. `result` is the raw submit response
296
+ * (POST body / handler return value / backend relay result) — the third-party
297
+ * API's answer. `values` is the submitted field set, `name` the collector name.
298
+ */
299
+ "form:submitted": {
300
+ name: string;
301
+ values: Record<string, unknown>;
302
+ result: unknown;
303
+ };
304
+ /**
305
+ * A form collector submit was attempted and failed at the network/server level
306
+ * (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
307
+ * pre-checks (missing required fields, no submit target) are NOT errors and do
308
+ * not fire this — they are returned to the caller as `{ ok: false }`.
309
+ */
310
+ "form:error": {
311
+ name: string;
312
+ values: Record<string, unknown>;
313
+ error: string;
314
+ };
293
315
  "connection:status": {
294
316
  connected: boolean;
295
317
  };
@@ -474,7 +496,7 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
474
496
 
475
497
  /**
476
498
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
477
- * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
499
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes from the LLM tool's `parameters` (the full schema still reaches the agent via dynamic context).
478
500
  */
479
501
  declare interface FormCollectorSchema {
480
502
  type: "object";
@@ -491,17 +513,32 @@ declare interface FormField {
491
513
  }
492
514
 
493
515
  /**
494
- * A field's conditional-requiredness rule. The field becomes required exactly
495
- * when the controlling `property` matches `value` against the answers collected
496
- * so far:
516
+ * A field's conditional-requiredness rule: either a single {@link FormFieldLeafCondition}
517
+ * or a boolean combination of rules. `anyOf` is OR (true when any nested rule
518
+ * holds); `allOf` is AND (true when every nested rule holds). Both nest
519
+ * arbitrarily, so you can mix them, e.g.
520
+ * `{ anyOf: [{ property: "a", op: ">=", value: 1 }, { property: "b", value: "1" }] }`.
521
+ * An empty `anyOf` is never required; an empty `allOf` is always required.
522
+ *
523
+ * Stripped from the LLM tool's `parameters` (see {@link toWireParameters}), but the
524
+ * full schema, `requiredWhen` included, still reaches the agent via the dynamic
525
+ * context so it knows when each field becomes required.
526
+ */
527
+ declare type FormFieldCondition = FormFieldLeafCondition | {
528
+ anyOf: FormFieldCondition[];
529
+ } | {
530
+ allOf: FormFieldCondition[];
531
+ };
532
+
533
+ /**
534
+ * A single leaf comparison. The field it guards becomes required exactly when the
535
+ * controlling `property` matches `value` against the answers collected so far:
497
536
  * - a single `value`, no `op` — equality (compared as strings);
498
537
  * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
499
538
  * - an array `value`, no `op` — "one of": matches when the property equals any
500
539
  * listed value.
501
- *
502
- * SDK-only — it is stripped from the schema before it reaches the LLM tool
503
540
  */
504
- declare interface FormFieldCondition {
541
+ declare interface FormFieldLeafCondition {
505
542
  /** The controlling field whose value the rule tests. */
506
543
  property: string;
507
544
  /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
@@ -522,7 +559,8 @@ declare interface FormFieldSchema {
522
559
  default?: unknown;
523
560
  /**
524
561
  * Makes the field required only while this condition holds. Drives the dynamic
525
- * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
562
+ * `missing` list; stripped from the LLM tool's `parameters` (still sent to the
563
+ * agent via dynamic context). See {@link toWireParameters}.
526
564
  */
527
565
  requiredWhen?: FormFieldCondition;
528
566
  }
package/dist/vue.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),p=require("./AgoClient--y10UXUV.cjs");let t=require("vue");var I=Symbol("ago-client"),y={install(o,n){const e=new p.AgoClient(n);o.provide(I,e)}};function g(o){if(o)return new p.AgoClient(o);const n=(0,t.inject)(I);if(!n)throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");return n}function E(o={}){const n=o.client??g(),e=(0,t.ref)([]),s=(0,t.ref)(o.conversationId),i=(0,t.ref)(!1),r=(0,t.ref)(null),c=a=>{s.value||(s.value=a.conversationId)},f=a=>{const u=e.value.findIndex(v=>v.id===a.messageId);u>=0&&(e.value[u]={...e.value[u],content:e.value[u].content+a.content})},m=a=>{const u=e.value.findIndex(v=>v.id===a.id);u>=0?e.value[u]=a:e.value.push(a),i.value=!1},C=a=>{r.value=new Error(a.error),i.value=!1};(0,t.onMounted)(()=>{n.on("message:start",c),n.on("message:chunk",f),n.on("message:complete",m),n.on("message:error",C)}),(0,t.onUnmounted)(()=>{n.off("message:start",c),n.off("message:chunk",f),n.off("message:complete",m),n.off("message:error",C)});async function d(a,u){i.value=!0,r.value=null;const v={id:`temp-${Date.now()}`,conversationId:s.value||"",content:a,role:"user",status:"DONE",createdAt:new Date},L={id:`temp-assistant-${Date.now()}`,conversationId:s.value||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};e.value.push(v,L);try{const l=await n.sendMessage(a,{conversationId:s.value,files:u});l.conversationId&&!s.value&&(s.value=l.conversationId),e.value=e.value.filter(w=>!w.id.startsWith("temp-"));const A={...v,id:v.id.replace("temp-","user-"),conversationId:l.conversationId};return e.value.some(w=>w.id===l.id)?e.value.push(A):e.value.push(A,l),l}catch(l){return r.value=l instanceof Error?l:new Error("Failed to send"),i.value=!1,e.value=e.value.filter(A=>!A.id.startsWith("temp-")),null}}function h(){e.value=[],s.value=void 0,r.value=null}return{messages:e,isLoading:i,error:r,conversationId:s,sendMessage:d,clearMessages:h}}function M(o={}){const n=o.client??g(),e=o.autoLoad??!0,s=(0,t.ref)([]),i=(0,t.ref)(null),r=(0,t.ref)(!1),c=(0,t.ref)(null);async function f(){r.value=!0,c.value=null;try{s.value=await n.getConversations()}catch(d){c.value=d instanceof Error?d:new Error("Failed to load conversations")}finally{r.value=!1}}async function m(d){r.value=!0,c.value=null;try{i.value=await n.getConversation(d)}catch(h){c.value=h instanceof Error?h:new Error("Failed to load conversation")}finally{r.value=!1}}function C(){i.value=null}return(0,t.onMounted)(()=>{e&&f()}),{conversations:s,currentConversation:i,isLoading:r,error:c,selectConversation:m,startNewConversation:C,refreshConversations:f}}function N(o={}){const n=E({client:o.client,conversationId:o.conversationId}),e=M({client:o.client,autoLoad:o.autoLoad}),s=(0,t.computed)(()=>n.error.value||e.error.value);return{messages:n.messages,isLoading:n.isLoading,error:s,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:e.conversations,currentConversation:e.currentConversation,isConversationsLoading:e.isLoading,selectConversation:e.selectConversation,startNewConversation:e.startNewConversation,refreshConversations:e.refreshConversations}}function F(o,n){const e=g();(0,t.onMounted)(()=>{e.registerFunction(o,n.handler,{description:n.description,parameters:n.parameters})}),(0,t.onUnmounted)(()=>{e.unregisterFunction(o)})}function S(o,n){const e=g();(0,t.onMounted)(()=>{e.registerNavigationFunction(o,n)}),(0,t.onUnmounted)(()=>{e.unregisterFunction("navigateToPage")})}function _(o,n){const e=g();(0,t.onMounted)(()=>{e.on(o,n)}),(0,t.onUnmounted)(()=>{e.off(o,n)})}function D(o){const n=(0,t.shallowRef)(o.get());return(0,t.onScopeDispose)(o.subscribe(e=>{n.value=e})),n}exports.AGO_CLIENT_KEY=I;exports.AgoPlugin=y;exports.useAgo=g;exports.useAgoEvents=_;exports.useAgoFunction=F;exports.useAgoNavigation=S;exports.useAgoStore=D;exports.useChat=N;exports.useConversation=M;exports.useMessages=E;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./rolldown-runtime-16Nf8qvH.cjs"),p=require("./AgoClient-B3-WGVne.cjs");let t=require("vue");var I=Symbol("ago-client"),y={install(o,n){const e=new p.AgoClient(n);o.provide(I,e)}};function g(o){if(o)return new p.AgoClient(o);const n=(0,t.inject)(I);if(!n)throw new Error("useAgo(): no AgoClient found. Either pass config or install AgoPlugin.");return n}function E(o={}){const n=o.client??g(),e=(0,t.ref)([]),s=(0,t.ref)(o.conversationId),i=(0,t.ref)(!1),r=(0,t.ref)(null),c=a=>{s.value||(s.value=a.conversationId)},f=a=>{const u=e.value.findIndex(v=>v.id===a.messageId);u>=0&&(e.value[u]={...e.value[u],content:e.value[u].content+a.content})},m=a=>{const u=e.value.findIndex(v=>v.id===a.id);u>=0?e.value[u]=a:e.value.push(a),i.value=!1},C=a=>{r.value=new Error(a.error),i.value=!1};(0,t.onMounted)(()=>{n.on("message:start",c),n.on("message:chunk",f),n.on("message:complete",m),n.on("message:error",C)}),(0,t.onUnmounted)(()=>{n.off("message:start",c),n.off("message:chunk",f),n.off("message:complete",m),n.off("message:error",C)});async function d(a,u){i.value=!0,r.value=null;const v={id:`temp-${Date.now()}`,conversationId:s.value||"",content:a,role:"user",status:"DONE",createdAt:new Date},L={id:`temp-assistant-${Date.now()}`,conversationId:s.value||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};e.value.push(v,L);try{const l=await n.sendMessage(a,{conversationId:s.value,files:u});l.conversationId&&!s.value&&(s.value=l.conversationId),e.value=e.value.filter(w=>!w.id.startsWith("temp-"));const A={...v,id:v.id.replace("temp-","user-"),conversationId:l.conversationId};return e.value.some(w=>w.id===l.id)?e.value.push(A):e.value.push(A,l),l}catch(l){return r.value=l instanceof Error?l:new Error("Failed to send"),i.value=!1,e.value=e.value.filter(A=>!A.id.startsWith("temp-")),null}}function h(){e.value=[],s.value=void 0,r.value=null}return{messages:e,isLoading:i,error:r,conversationId:s,sendMessage:d,clearMessages:h}}function M(o={}){const n=o.client??g(),e=o.autoLoad??!0,s=(0,t.ref)([]),i=(0,t.ref)(null),r=(0,t.ref)(!1),c=(0,t.ref)(null);async function f(){r.value=!0,c.value=null;try{s.value=await n.getConversations()}catch(d){c.value=d instanceof Error?d:new Error("Failed to load conversations")}finally{r.value=!1}}async function m(d){r.value=!0,c.value=null;try{i.value=await n.getConversation(d)}catch(h){c.value=h instanceof Error?h:new Error("Failed to load conversation")}finally{r.value=!1}}function C(){i.value=null}return(0,t.onMounted)(()=>{e&&f()}),{conversations:s,currentConversation:i,isLoading:r,error:c,selectConversation:m,startNewConversation:C,refreshConversations:f}}function N(o={}){const n=E({client:o.client,conversationId:o.conversationId}),e=M({client:o.client,autoLoad:o.autoLoad}),s=(0,t.computed)(()=>n.error.value||e.error.value);return{messages:n.messages,isLoading:n.isLoading,error:s,sendMessage:n.sendMessage,clearMessages:n.clearMessages,conversationId:n.conversationId,conversations:e.conversations,currentConversation:e.currentConversation,isConversationsLoading:e.isLoading,selectConversation:e.selectConversation,startNewConversation:e.startNewConversation,refreshConversations:e.refreshConversations}}function F(o,n){const e=g();(0,t.onMounted)(()=>{e.registerFunction(o,n.handler,{description:n.description,parameters:n.parameters})}),(0,t.onUnmounted)(()=>{e.unregisterFunction(o)})}function S(o,n){const e=g();(0,t.onMounted)(()=>{e.registerNavigationFunction(o,n)}),(0,t.onUnmounted)(()=>{e.unregisterFunction("navigateToPage")})}function _(o,n){const e=g();(0,t.onMounted)(()=>{e.on(o,n)}),(0,t.onUnmounted)(()=>{e.off(o,n)})}function D(o){const n=(0,t.shallowRef)(o.get());return(0,t.onScopeDispose)(o.subscribe(e=>{n.value=e})),n}exports.AGO_CLIENT_KEY=I;exports.AgoPlugin=y;exports.useAgo=g;exports.useAgoEvents=_;exports.useAgoFunction=F;exports.useAgoNavigation=S;exports.useAgoStore=D;exports.useChat=N;exports.useConversation=M;exports.useMessages=E;
package/dist/vue.d.cts CHANGED
@@ -184,6 +184,7 @@ declare class AgoClient {
184
184
  * call it when their store updates so observers like the dev panel stay live.
185
185
  */
186
186
  notifyContextChanged(): void;
187
+ /* Excluded from this release type: emitFormEvent */
187
188
  /**
188
189
  * Enable automatic capture of the current browser page (URL + title).
189
190
  * Injected as a dynamic context entry named `browser-page`.
@@ -298,6 +299,27 @@ declare interface AgoClientEvents {
298
299
  result: unknown;
299
300
  error?: string;
300
301
  };
302
+ /**
303
+ * A form collector submitted successfully. `result` is the raw submit response
304
+ * (POST body / handler return value / backend relay result) — the third-party
305
+ * API's answer. `values` is the submitted field set, `name` the collector name.
306
+ */
307
+ "form:submitted": {
308
+ name: string;
309
+ values: Record<string, unknown>;
310
+ result: unknown;
311
+ };
312
+ /**
313
+ * A form collector submit was attempted and failed at the network/server level
314
+ * (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
315
+ * pre-checks (missing required fields, no submit target) are NOT errors and do
316
+ * not fire this — they are returned to the caller as `{ ok: false }`.
317
+ */
318
+ "form:error": {
319
+ name: string;
320
+ values: Record<string, unknown>;
321
+ error: string;
322
+ };
301
323
  "connection:status": {
302
324
  connected: boolean;
303
325
  };
@@ -490,7 +512,7 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
490
512
 
491
513
  /**
492
514
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
493
- * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
515
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes from the LLM tool's `parameters` (the full schema still reaches the agent via dynamic context).
494
516
  */
495
517
  declare interface FormCollectorSchema {
496
518
  type: "object";
@@ -515,17 +537,32 @@ declare interface FormField_2 {
515
537
  }
516
538
 
517
539
  /**
518
- * A field's conditional-requiredness rule. The field becomes required exactly
519
- * when the controlling `property` matches `value` against the answers collected
520
- * so far:
540
+ * A field's conditional-requiredness rule: either a single {@link FormFieldLeafCondition}
541
+ * or a boolean combination of rules. `anyOf` is OR (true when any nested rule
542
+ * holds); `allOf` is AND (true when every nested rule holds). Both nest
543
+ * arbitrarily, so you can mix them, e.g.
544
+ * `{ anyOf: [{ property: "a", op: ">=", value: 1 }, { property: "b", value: "1" }] }`.
545
+ * An empty `anyOf` is never required; an empty `allOf` is always required.
546
+ *
547
+ * Stripped from the LLM tool's `parameters` (see {@link toWireParameters}), but the
548
+ * full schema, `requiredWhen` included, still reaches the agent via the dynamic
549
+ * context so it knows when each field becomes required.
550
+ */
551
+ declare type FormFieldCondition = FormFieldLeafCondition | {
552
+ anyOf: FormFieldCondition[];
553
+ } | {
554
+ allOf: FormFieldCondition[];
555
+ };
556
+
557
+ /**
558
+ * A single leaf comparison. The field it guards becomes required exactly when the
559
+ * controlling `property` matches `value` against the answers collected so far:
521
560
  * - a single `value`, no `op` — equality (compared as strings);
522
561
  * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
523
562
  * - an array `value`, no `op` — "one of": matches when the property equals any
524
563
  * listed value.
525
- *
526
- * SDK-only — it is stripped from the schema before it reaches the LLM tool
527
564
  */
528
- declare interface FormFieldCondition {
565
+ declare interface FormFieldLeafCondition {
529
566
  /** The controlling field whose value the rule tests. */
530
567
  property: string;
531
568
  /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
@@ -546,7 +583,8 @@ declare interface FormFieldSchema {
546
583
  default?: unknown;
547
584
  /**
548
585
  * Makes the field required only while this condition holds. Drives the dynamic
549
- * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
586
+ * `missing` list; stripped from the LLM tool's `parameters` (still sent to the
587
+ * agent via dynamic context). See {@link toWireParameters}.
550
588
  */
551
589
  requiredWhen?: FormFieldCondition;
552
590
  }
package/dist/vue.d.ts CHANGED
@@ -184,6 +184,7 @@ declare class AgoClient {
184
184
  * call it when their store updates so observers like the dev panel stay live.
185
185
  */
186
186
  notifyContextChanged(): void;
187
+ /* Excluded from this release type: emitFormEvent */
187
188
  /**
188
189
  * Enable automatic capture of the current browser page (URL + title).
189
190
  * Injected as a dynamic context entry named `browser-page`.
@@ -298,6 +299,27 @@ declare interface AgoClientEvents {
298
299
  result: unknown;
299
300
  error?: string;
300
301
  };
302
+ /**
303
+ * A form collector submitted successfully. `result` is the raw submit response
304
+ * (POST body / handler return value / backend relay result) — the third-party
305
+ * API's answer. `values` is the submitted field set, `name` the collector name.
306
+ */
307
+ "form:submitted": {
308
+ name: string;
309
+ values: Record<string, unknown>;
310
+ result: unknown;
311
+ };
312
+ /**
313
+ * A form collector submit was attempted and failed at the network/server level
314
+ * (HTTP non-2xx, or a thrown handler/fetch). `error` is the message. Validation
315
+ * pre-checks (missing required fields, no submit target) are NOT errors and do
316
+ * not fire this — they are returned to the caller as `{ ok: false }`.
317
+ */
318
+ "form:error": {
319
+ name: string;
320
+ values: Record<string, unknown>;
321
+ error: string;
322
+ };
301
323
  "connection:status": {
302
324
  connected: boolean;
303
325
  };
@@ -490,7 +512,7 @@ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
490
512
 
491
513
  /**
492
514
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
493
- * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes before the schema reaches the LLM.
515
+ * object feeds the store, the update function, and the dynamic context). Additionally allows the SDK-only per-field `requiredWhen`, which {@link toWireParameters} removes from the LLM tool's `parameters` (the full schema still reaches the agent via dynamic context).
494
516
  */
495
517
  declare interface FormCollectorSchema {
496
518
  type: "object";
@@ -515,17 +537,32 @@ declare interface FormField_2 {
515
537
  }
516
538
 
517
539
  /**
518
- * A field's conditional-requiredness rule. The field becomes required exactly
519
- * when the controlling `property` matches `value` against the answers collected
520
- * so far:
540
+ * A field's conditional-requiredness rule: either a single {@link FormFieldLeafCondition}
541
+ * or a boolean combination of rules. `anyOf` is OR (true when any nested rule
542
+ * holds); `allOf` is AND (true when every nested rule holds). Both nest
543
+ * arbitrarily, so you can mix them, e.g.
544
+ * `{ anyOf: [{ property: "a", op: ">=", value: 1 }, { property: "b", value: "1" }] }`.
545
+ * An empty `anyOf` is never required; an empty `allOf` is always required.
546
+ *
547
+ * Stripped from the LLM tool's `parameters` (see {@link toWireParameters}), but the
548
+ * full schema, `requiredWhen` included, still reaches the agent via the dynamic
549
+ * context so it knows when each field becomes required.
550
+ */
551
+ declare type FormFieldCondition = FormFieldLeafCondition | {
552
+ anyOf: FormFieldCondition[];
553
+ } | {
554
+ allOf: FormFieldCondition[];
555
+ };
556
+
557
+ /**
558
+ * A single leaf comparison. The field it guards becomes required exactly when the
559
+ * controlling `property` matches `value` against the answers collected so far:
521
560
  * - a single `value`, no `op` — equality (compared as strings);
522
561
  * - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
523
562
  * - an array `value`, no `op` — "one of": matches when the property equals any
524
563
  * listed value.
525
- *
526
- * SDK-only — it is stripped from the schema before it reaches the LLM tool
527
564
  */
528
- declare interface FormFieldCondition {
565
+ declare interface FormFieldLeafCondition {
529
566
  /** The controlling field whose value the rule tests. */
530
567
  property: string;
531
568
  /** Comparison operator; omitted means equality. Ignored when `value` is an array. */
@@ -546,7 +583,8 @@ declare interface FormFieldSchema {
546
583
  default?: unknown;
547
584
  /**
548
585
  * Makes the field required only while this condition holds. Drives the dynamic
549
- * `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
586
+ * `missing` list; stripped from the LLM tool's `parameters` (still sent to the
587
+ * agent via dynamic context). See {@link toWireParameters}.
550
588
  */
551
589
  requiredWhen?: FormFieldCondition;
552
590
  }
package/dist/vue.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as A } from "./AgoClient-DYdIe_R4.js";
1
+ import { t as A } from "./AgoClient-QcTtrN7u.js";
2
2
  import { computed as y, inject as F, onMounted as g, onScopeDispose as N, onUnmounted as I, ref as c, shallowRef as D } from "vue";
3
3
  var L = /* @__PURE__ */ Symbol("ago-client"), b = { install(t, n) {
4
4
  const e = new A(n);
package/dist/widget.cjs CHANGED
@@ -1,5 +1,5 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Te=require("./AgoClient--y10UXUV.cjs"),Ne=require("./createFormCollector-DWzGKDwO.cjs"),et=require("./createConversationSession-BuMXp0Ia.cjs");var tt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function U(o){return o.replace(/[&<>"']/g,n=>tt[n])}function Le(o){const n=o.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)?n:null}var Fe='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Q="";function B(o){const n=[],a=u=>(n.push(u),`${Q}${n.length-1}${Q}`);let t=o;return t=t.replace(/`([^`]+)`/g,(u,i)=>a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Fe}">${U(i)}</code>`)),t=t.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(u,i,f)=>{const l=Le(f);return l?a(`<img alt="${U(i)}" src="${U(l)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):u}),t=t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(u,i,f)=>{const l=Le(f);return l?a(`<a href="${U(l)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${B(i)}</a>`):u}),t=U(t),t=t.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),t=t.replace(new RegExp(`${Q}(\\d+)${Q}`,"g"),(u,i)=>n[Number(i)]),t}function R(o,n,a){const t=document.createElement(o);return Object.assign(t.style,n),a!==void 0&&(t.innerHTML=a),t}var ze=/^ {0,3}([-*_])( *\1){2,} *$/,He=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,Ue=/^ {0,3}(```+|~~~+)/,Z=/^ {0,3}>\s?/,W=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,nt=["20px","18px","16px","15px","14px","13px"],ge=o=>o.match(/^\s*/)?.[0].length??0;function ot(o){return o.trim()===""||ze.test(o)||He.test(o)||Ue.test(o)||Z.test(o)||W.test(o)}function We(o){const n=o[0].match(W),a=n[1].length,t=/\d/.test(n[2]),u=R(t?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:t?"decimal":"disc",listStylePosition:"outside"});let i=0;for(;i<o.length;){const f=o[i].match(W),l=[];for(i++;i<o.length&&ge(o[i])>a;)l.push(o[i]),i++;const p=R("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),c=f[3].match(/^\[([ xX])\]\s+(.*)$/);c?(p.style.listStyleType="none",p.style.marginLeft="-20px",p.innerHTML=`<span style="margin-right:6px">${c[1].toLowerCase()==="x"?"☑":"☐"}</span>${B(c[2])}`):p.innerHTML=B(f[3]),l.filter(g=>W.test(g)).length>0&&p.appendChild(We(l.filter(g=>g.trim()!==""))),u.appendChild(p)}return u}function rt(o){const n=l=>l.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(p=>p.trim()),a=R("div",{overflowX:"auto",margin:"0 0 8px 0"}),t=R("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),u=document.createElement("thead"),i=document.createElement("tr");for(const l of n(o[0]))i.appendChild(R("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},B(l)));u.appendChild(i),t.appendChild(u);const f=document.createElement("tbody");for(const l of o.slice(2)){const p=document.createElement("tr");for(const c of n(l))p.appendChild(R("td",{border:"1px solid #dee3e8",padding:"6px 10px"},B(c)));f.appendChild(p)}return t.appendChild(f),a.appendChild(t),a}var at=o=>!!o&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);function J(o){const n=document.createDocumentFragment(),a=o.replace(/\r\n?/g,`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Oe=require("./AgoClient-B3-WGVne.cjs"),De=require("./createFormCollector-BI3DXaew.cjs"),at=require("./createConversationSession-C0diFTUk.cjs");var it={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function U(r){return r.replace(/[&<>"']/g,o=>it[o])}function Be(r){const o=r.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var Ue='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Z="";function M(r){const o=[],a=u=>(o.push(u),`${Z}${o.length-1}${Z}`);let t=r;return t=t.replace(/`([^`]+)`/g,(u,s)=>a(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Ue}">${U(s)}</code>`)),t=t.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(u,s,f)=>{const l=Be(f);return l?a(`<img alt="${U(s)}" src="${U(l)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):u}),t=t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(u,s,f)=>{const l=Be(f);return l?a(`<a href="${U(l)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${M(s)}</a>`):u}),t=U(t),t=t.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),t=t.replace(new RegExp(`${Z}(\\d+)${Z}`,"g"),(u,s)=>o[Number(s)]),t}function R(r,o,a){const t=document.createElement(r);return Object.assign(t.style,o),a!==void 0&&(t.innerHTML=a),t}var We=/^ {0,3}([-*_])( *\1){2,} *$/,Pe=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,Ge=/^ {0,3}(```+|~~~+)/,ee=/^ {0,3}>\s?/,W=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,st=["20px","18px","16px","15px","14px","13px"],he=r=>r.match(/^\s*/)?.[0].length??0;function lt(r){return r.trim()===""||We.test(r)||Pe.test(r)||Ge.test(r)||ee.test(r)||W.test(r)}function je(r){const o=r[0].match(W),a=o[1].length,t=/\d/.test(o[2]),u=R(t?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:t?"decimal":"disc",listStylePosition:"outside"});let s=0;for(;s<r.length;){const f=r[s].match(W),l=[];for(s++;s<r.length&&he(r[s])>a;)l.push(r[s]),s++;const p=R("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),c=f[3].match(/^\[([ xX])\]\s+(.*)$/);c?(p.style.listStyleType="none",p.style.marginLeft="-20px",p.innerHTML=`<span style="margin-right:6px">${c[1].toLowerCase()==="x"?"☑":"☐"}</span>${M(c[2])}`):p.innerHTML=M(f[3]),l.filter(h=>W.test(h)).length>0&&p.appendChild(je(l.filter(h=>h.trim()!==""))),u.appendChild(p)}return u}function dt(r){const o=l=>l.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(p=>p.trim()),a=R("div",{overflowX:"auto",margin:"0 0 8px 0"}),t=R("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),u=document.createElement("thead"),s=document.createElement("tr");for(const l of o(r[0]))s.appendChild(R("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},M(l)));u.appendChild(s),t.appendChild(u);const f=document.createElement("tbody");for(const l of r.slice(2)){const p=document.createElement("tr");for(const c of o(l))p.appendChild(R("td",{border:"1px solid #dee3e8",padding:"6px 10px"},M(c)));f.appendChild(p)}return t.appendChild(f),a.appendChild(t),a}var ct=r=>!!r&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(r);function te(r){const o=document.createDocumentFragment(),a=r.replace(/\r\n?/g,`
2
2
  `).split(`
3
- `);let t=0;for(;t<a.length;){const i=a[t];if(i.trim()===""){t++;continue}const f=i.match(Ue);if(f){const c=f[1][0],g=[];for(t++;t<a.length&&!new RegExp(`^ {0,3}${c==="`"?"`{3,}":"~{3,}"}\\s*$`).test(a[t]);)g.push(a[t]),t++;t++;const N=R("pre",{margin:"0 0 8px 0"});N.appendChild(R("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:Fe,whiteSpace:"pre"},U(g.join(`
4
- `)))),n.appendChild(N);continue}if(ze.test(i)){n.appendChild(R("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),t++;continue}const l=i.match(He);if(l){const c=l[1].length;n.appendChild(R(`h${c}`,{margin:"16px 0 8px 0",fontSize:nt[c-1],fontWeight:"600",lineHeight:"1.3"},B(l[2]))),t++;continue}if(Z.test(i)){const c=[];for(;t<a.length&&Z.test(a[t]);)c.push(a[t].replace(Z,"")),t++;const g=R("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});g.appendChild(J(c.join(`
5
- `))),n.appendChild(g);continue}if(i.includes("|")&&at(a[t+1])){const c=[i,a[t+1]];for(t+=2;t<a.length&&a[t].includes("|")&&a[t].trim();)c.push(a[t]),t++;n.appendChild(rt(c));continue}if(W.test(i)){const c=[],g=ge(i);for(;t<a.length&&a[t].trim()!=="";)if(W.test(a[t])||ge(a[t])>g)c.push(a[t]),t++;else break;n.appendChild(We(c));continue}const p=[i];for(t++;t<a.length&&!ot(a[t]);)p.push(a[t]),t++;n.appendChild(R("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>B(c)).join("<br>")))}const u=n.lastElementChild;return u&&(u.style.marginBottom="0"),n}var me='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Oe={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color"},he="var(--ago-brand-color, #03182f)",xe="var(--ago-brand-text-color, #fff)",st="var(--ago-header-background, var(--ago-brand-color, #03182f))",De="var(--ago-header-text-color, #e8f0fe)",j="var(--ago-panel-background, #fff)",it="var(--ago-messages-background, #fbfbfb)",Y="var(--ago-text-color, #30373e)",lt="var(--ago-muted-text-color, #6b6d6f)",I="var(--ago-border-color, #dee3e8)",fe="var(--ago-accent-color, #1b5fc4)",dt="var(--ago-radius, 16px)",ue="var(--ago-message-radius, 16px)";function ct(o,n){if(n)for(const a of Object.keys(Oe)){const t=n[a];t!=null&&o.style.setProperty(Oe[a],t)}}function w(o,n){Object.assign(o.style,n)}function x(o={}){const n=document.createElement("div");return w(n,o),n}var Me="Form submitted.";function pt(o){if(typeof o=="string")return o||null;if(!o||typeof o!="object")return null;const n=o;if(typeof n.message=="string"&&n.message)return n.message;const a=n.result;if(typeof a=="string"&&a)return a;if(a&&typeof a=="object"){const t=a.message;if(typeof t=="string"&&t)return t}return null}var Be="ago-chat-widget-keyframes";function ft(){if(typeof document>"u"||document.getElementById(Be))return;const o=document.createElement("style");o.id=Be,o.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(o)}function ut(o){const n=typeof o=="string"?document.querySelector(o):o;if(!n)throw new Error(`mountChatWidget: target "${String(o)}" not found.`);return n}function gt(o,n){const{title:a="Chat",welcomeMessage:t="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:i=!1,height:f=500,placement:l="inline",width:p=400,defaultOpen:c=!1,logoUrl:g,showAgentName:N=!1,theme:m,loadThreads:_=!1,forms:q,formSubmittedMessage:L=Me,onFollowUpClick:$,onMessageSent:be,onMessageReceived:ee}=n;if(!n.client&&!n.config?.baseUrl)throw new Te.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const b=n.client??new Te.AgoClient(n.config),Ce=ut(o),F=l==="left"||l==="right",Pe=F&&(n.launcher??!0);let z=F?c:!0;const te=n.persistConversation,X=te?et.createConversationSession(te===!0?{}:te):void 0;let k=n.conversationId??X?.getLastActiveThread()??void 0,d=[],O=!1,P=null;const ye=[];function Ge(e){if(typeof L=="function"){const s=L(e);if(typeof s=="string"&&s)return s}const r=pt(e);return r||(typeof L=="string"?L:Me)}const K=[],H=x({display:"flex",flexDirection:"column",height:F?"100%":typeof f=="number"?`${f}px`:f,border:`1px solid ${I}`,borderRadius:dt,overflow:"hidden",backgroundColor:j,fontFamily:me,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});H.className="ago-chat-widget",ct(H,m);const G=x({padding:"14px 16px",borderBottom:`1px solid ${I}`,backgroundColor:st,color:De,display:"flex",alignItems:"center",gap:"10px"});if(G.className="ago-chat-widget__header",g){const e=document.createElement("img");e.src=g,e.alt="Logo",w(e,{height:"24px",width:"auto"}),G.appendChild(e)}const ne=document.createElement("h3");if(ne.textContent=a,w(ne,{margin:"0",fontSize:"15px",fontWeight:"600"}),G.appendChild(ne),F){const e=document.createElement("button");e.type="button",e.className="ago-chat-widget__close",e.setAttribute("aria-label","Close"),e.textContent="×",w(e,{marginLeft:"auto",background:"transparent",border:"none",color:De,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),e.addEventListener("click",()=>ce()),G.appendChild(e)}const T=x({flex:"1",overflow:"auto",padding:"16px",backgroundColor:it});T.className="ago-chat-widget__messages";const{inputRow:je,setDisabled:qe,focus:oe}=mt({placeholder:u,allowFiles:i,onSend:(e,r)=>{se(e,r)}});ft(),H.append(G,T,je);let V=H,D,S;const re=l==="left"?"left":"right";if(F&&(D=x({position:"fixed",top:"0",bottom:"0",[re]:"0",width:typeof p=="number"?`${p}px`:p,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),D.className="ago-chat-widget-panel",w(H,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[re==="left"?"borderRight":"borderLeft"]:`1px solid ${I}`}),D.appendChild(H),V=D),Pe){if(S=document.createElement("button"),S.type="button",S.className="ago-chat-widget-launcher",S.setAttribute("aria-label",`Open ${a}`),w(S,{position:"fixed",bottom:"20px",[re]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:he,color:xe,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:me}),g){const e=document.createElement("img");e.src=g,e.alt="",w(e,{width:"26px",height:"26px",objectFit:"contain"}),S.appendChild(e)}else S.appendChild(Ze());S.addEventListener("click",()=>de())}Ce.appendChild(V),S&&Ce.appendChild(S),le();const ve=$!==!1,we=$===!1?void 0:$??(e=>{se(e)});function Xe(e,r){const s=e.role==="user",h=x({display:"flex",flexDirection:"column",alignItems:s?"flex-end":"flex-start",marginBottom:"16px"});if(h.className=`ago-message ago-message--${e.role}`,!s&&N&&e.agent){const C=x({fontSize:"13px",fontWeight:"500",color:Y,marginBottom:"6px",padding:"0 4px"});C.className="ago-message__agent",C.textContent=e.agent.displayName||e.agent.name,h.appendChild(C)}if(!s&&e.sources&&e.sources.length>0){const C=x({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});C.className="ago-message__sources",e.sources.forEach((y,E)=>{const M=y.url?document.createElement("a"):document.createElement("div");y.url&&M instanceof HTMLAnchorElement&&(M.href=y.url,M.target="_blank",M.rel="noopener noreferrer"),w(M,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${I}`,borderRadius:"8px",backgroundColor:j,textDecoration:"none",color:Y,fontSize:"12px",overflow:"hidden"});const $e=x({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${fe}`,color:fe,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});$e.textContent=String(E+1);const pe=x({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});pe.textContent=y.title,pe.title=y.title,M.append($e,pe),C.appendChild(M)}),h.appendChild(C)}const v=x({maxWidth:s?"75%":"100%",padding:s?"10px 14px":"2px 8px",borderRadius:s?ue:"0",backgroundColor:s?he:"transparent",color:s?xe:Y,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if(v.className="ago-message__content",e.content?v.appendChild(J(e.content)):e.status==="IN_PROGRESS"&&v.appendChild(Je()),h.appendChild(v),r&&e.followUpReplies&&e.followUpReplies.length>0){const C=x({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});C.className="ago-message__followups";for(const y of e.followUpReplies){const E=document.createElement("button");E.type="button",E.className="ago-message__followup-btn",E.textContent=y,E.disabled=!ve,w(E,{padding:"6px 14px",fontSize:"14px",borderRadius:ue,border:`1px solid ${I}`,backgroundColor:j,color:Y,cursor:ve?"pointer":"default",transition:"border-color 0.15s"}),we&&E.addEventListener("click",()=>we(y)),E.addEventListener("mouseenter",()=>{E.style.borderColor=fe}),E.addEventListener("mouseleave",()=>{E.style.borderColor=I}),C.appendChild(E)}h.appendChild(C)}return h}function Ke(e){const r=x({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:ue,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});r.className="ago-form-notice",r.setAttribute("role","status");const s=document.createElement("span");s.textContent="✓",s.setAttribute("aria-hidden","true"),w(s,{fontWeight:"700"});const h=document.createElement("span");return h.textContent=e,r.append(s,h),r}function A(){if(T.replaceChildren(),d.length===0){const r=x({textAlign:"center",color:lt,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});r.appendChild(J(t)),T.appendChild(r)}else d.forEach((r,s)=>{T.appendChild(Xe(r,s===d.length-1))});for(const r of ye)T.appendChild(Ke(r));if(P){const r=x({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});r.textContent=P,T.appendChild(r)}T.scrollTop=T.scrollHeight;const e=d[d.length-1];qe(O&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function Ve(){for(let e=d.length-1;e>=0;e--){const r=d[e];if(r.role==="assistant"&&r.status==="IN_PROGRESS")return r}}const Ee=e=>{k||(k=e.conversationId)},Se=e=>{const r=Ve();r&&(r.content+=e.content,A())},Re=e=>{const r=d.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");r>=0?d[r]=e:d.push(e),A(),oe()},_e=e=>{const r=d.findIndex(s=>s.id===e.id||s.role==="assistant"&&s.status==="IN_PROGRESS");r>=0?d[r]=e:d.push(e),O=!1,A(),e.status==="DONE"&&ee?.({id:e.id,content:e.content})},ke=e=>{P=e.error,O=!1,d=d.filter(r=>!r.id.startsWith("temp-")),A()};b.on("message:start",Ee),b.on("message:chunk",Se),b.on("message:answer-complete",Re),b.on("message:complete",_e),b.on("message:error",ke);const ae=[];let Ae=!1;const Ie=e=>{if(Ae)return;ae.push(e.install(b));let r=e.store.get().submitted;const s=e.store.subscribe(h=>{h.submitted&&!r&&(ye.push(Ge(h.submitResult)),A()),r=h.submitted});ae.push(s)};for(const e of q??[])e.schema!=null?Ie(Ne.createFormCollector(e)):Ne.loadFormCollector(b,e).then(r=>Ie(r)).catch(()=>{});async function se(e,r){const s=e.trim();if(!s&&!r?.length||O)return;be?.(s),O=!0,P=null;const h=Date.now();d.push({id:`temp-user-${h}`,conversationId:k||"",content:s,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${h}`,conversationId:k||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),A();try{const v=await b.sendMessage(s,{conversationId:k,files:r});v.conversationId&&(k||(k=v.conversationId),X?.setActiveThread(v.conversationId,v.createdAt));const C=d.find(y=>y.id===`temp-user-${h}`);if(C&&(C.id=`user-${h}`,C.conversationId=v.conversationId),!d.some(y=>y.id===v.id)){const y=d.findIndex(E=>E.id===`temp-assistant-${h}`);y>=0?d[y]=v:d.push(v)}d=d.filter(y=>!y.id.startsWith("temp-")),O=!1,A(),_&&ie()}catch(v){P=v instanceof Error?v.message:"Failed to send message",O=!1,d=d.filter(C=>!C.id.startsWith("temp-")),A()}}async function ie(){try{const e=await b.getConversations();K.splice(0,K.length,...e)}catch{}return K}async function Qe(e){try{const r=(await b.getConversation(e))?.messages??[];r.length>0&&d.length===0&&(d=r,A())}catch{d.length===0&&(X?.clear(),k=void 0)}}return A(),oe(),k&&Qe(k),_&&ie(),{client:b,element:V,sendMessage:se,...F?{open:de,close:ce,toggle:Ye}:{},session:X,threads:K,refreshThreads:ie,destroy(){b.off("message:start",Ee),b.off("message:chunk",Se),b.off("message:answer-complete",Re),b.off("message:complete",_e),b.off("message:error",ke),Ae=!0,ae.forEach(e=>e()),V.remove(),S?.remove(),n.client||b.destroy()}};function le(){if(!D)return;const e=l==="left"?"translateX(-100%)":"translateX(100%)";D.style.transform=z?"translateX(0)":e,D.setAttribute("aria-hidden",z?"false":"true"),S&&(S.style.display=z?"none":"flex")}function de(){z=!0,le(),oe()}function ce(){z=!1,le()}function Ye(){z?ce():de()}function Ze(){const e="http://www.w3.org/2000/svg",r=document.createElementNS(e,"svg");r.setAttribute("width","26"),r.setAttribute("height","26"),r.setAttribute("viewBox","0 0 24 24"),r.setAttribute("fill","none");const s=document.createElementNS(e,"path");return s.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),s.setAttribute("stroke","currentColor"),s.setAttribute("stroke-width","2"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),r.appendChild(s),r}function Je(){const e=x({display:"flex",gap:"4px",padding:"4px 0"});for(let r=0;r<3;r++){const s=x({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${r*.2}s`});e.appendChild(s)}return e}}function mt(o){let n=[];const a=document.createElement("form");w(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${I}`,backgroundColor:j}),a.className="ago-chat-input";const t=x({display:"flex",flexWrap:"wrap",gap:"6px"}),u=x({display:"flex",gap:"8px",alignItems:"flex-end"}),i=document.createElement("textarea");i.placeholder=o.placeholder,i.rows=1,w(i,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${I}`,borderRadius:"12px",fontSize:"16px",fontFamily:me,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const f=document.createElement("button");f.type="submit",f.textContent="Send",w(f,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:he,color:xe,fontSize:"16px",fontWeight:"500",cursor:"pointer"});let l=null,p=null;o.allowFiles&&(l=document.createElement("input"),l.type="file",l.multiple=!0,w(l,{display:"none"}),p=document.createElement("button"),p.type="button",p.textContent="📎",w(p,{padding:"10px 12px",border:`1px solid ${I}`,borderRadius:"12px",backgroundColor:j,cursor:"pointer",fontSize:"14px"}),p.addEventListener("click",()=>l?.click()),l.addEventListener("change",()=>{n=[...n,...Array.from(l?.files??[])],c()}));function c(){t.replaceChildren(),n.forEach((m,_)=>{const q=x({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${I}`,borderRadius:"8px",fontSize:"12px"}),L=document.createElement("span");L.textContent=m.name;const $=document.createElement("button");$.type="button",$.textContent="×",w($,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),$.addEventListener("click",()=>{n=n.filter((be,ee)=>ee!==_),c()}),q.append(L,$),t.appendChild(q)})}const g=()=>{const m=i.value,_=n;return i.value="",n=[],c(),{content:m,files:_}},N=()=>{const{content:m,files:_}=g();(m.trim()||_.length>0)&&o.onSend(m.trim(),_.length>0?_:void 0)};return a.addEventListener("submit",m=>{m.preventDefault(),N()}),i.addEventListener("keydown",m=>{m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),N())}),p&&u.appendChild(p),u.append(i,f),l&&a.appendChild(l),a.append(t,u),{inputRow:a,getValueAndClear:g,setDisabled:m=>{i.disabled=m,f.disabled=m,f.style.opacity=m?"0.6":"1",f.style.cursor=m?"not-allowed":"pointer"},focus:()=>i.focus()}}exports.mountChatWidget=gt;exports.renderMarkdown=J;
3
+ `);let t=0;for(;t<a.length;){const s=a[t];if(s.trim()===""){t++;continue}const f=s.match(Ge);if(f){const c=f[1][0],h=[];for(t++;t<a.length&&!new RegExp(`^ {0,3}${c==="`"?"`{3,}":"~{3,}"}\\s*$`).test(a[t]);)h.push(a[t]),t++;t++;const N=R("pre",{margin:"0 0 8px 0"});N.appendChild(R("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:Ue,whiteSpace:"pre"},U(h.join(`
4
+ `)))),o.appendChild(N);continue}if(We.test(s)){o.appendChild(R("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),t++;continue}const l=s.match(Pe);if(l){const c=l[1].length;o.appendChild(R(`h${c}`,{margin:"16px 0 8px 0",fontSize:st[c-1],fontWeight:"600",lineHeight:"1.3"},M(l[2]))),t++;continue}if(ee.test(s)){const c=[];for(;t<a.length&&ee.test(a[t]);)c.push(a[t].replace(ee,"")),t++;const h=R("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});h.appendChild(te(c.join(`
5
+ `))),o.appendChild(h);continue}if(s.includes("|")&&ct(a[t+1])){const c=[s,a[t+1]];for(t+=2;t<a.length&&a[t].includes("|")&&a[t].trim();)c.push(a[t]),t++;o.appendChild(dt(c));continue}if(W.test(s)){const c=[],h=he(s);for(;t<a.length&&a[t].trim()!=="";)if(W.test(a[t])||he(a[t])>h)c.push(a[t]),t++;else break;o.appendChild(je(c));continue}const p=[s];for(t++;t<a.length&&!lt(a[t]);)p.push(a[t]),t++;o.appendChild(R("p",{margin:"0 0 8px 0",lineHeight:"1.6"},p.map(c=>M(c)).join("<br>")))}const u=o.lastElementChild;return u&&(u.style.marginBottom="0"),o}var xe='var(--ago-font, "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif)',Me={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color",agentBubbleBg:"--ago-agent-bubble-background"},be="var(--ago-brand-color, #03182f)",Ce="var(--ago-brand-text-color, #fff)",pt="var(--ago-header-background, var(--ago-brand-color, #03182f))",Fe="var(--ago-header-text-color, #e8f0fe)",X="var(--ago-panel-background, #fff)",ft="var(--ago-messages-background, #fbfbfb)",J="var(--ago-text-color, #30373e)",ut="var(--ago-muted-text-color, #6b6d6f)",A="var(--ago-border-color, #dee3e8)",ge="var(--ago-accent-color, #1b5fc4)",gt="var(--ago-agent-bubble-background, #f1f3f5)",mt="var(--ago-radius, 16px)",me="var(--ago-message-radius, 16px)";function ht(r,o){if(o)for(const a of Object.keys(Me)){const t=o[a];t!=null&&r.style.setProperty(Me[a],t)}}function E(r,o){Object.assign(r.style,o)}function b(r={}){const o=document.createElement("div");return E(o,r),o}var ze="Form submitted.";function xt(r){if(typeof r=="string")return r||null;if(!r||typeof r!="object")return null;const o=r;if(typeof o.message=="string"&&o.message)return o.message;const a=o.result;if(typeof a=="string"&&a)return a;if(a&&typeof a=="object"){const t=a.message;if(typeof t=="string"&&t)return t}return null}var He="ago-chat-widget-keyframes";function bt(){if(typeof document>"u"||document.getElementById(He))return;const r=document.createElement("style");r.id=He,r.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }",document.head.appendChild(r)}function Ct(r){const o=typeof r=="string"?document.querySelector(r):r;if(!o)throw new Error(`mountChatWidget: target "${String(r)}" not found.`);return o}function yt(r,o){const{title:a="Chat",welcomeMessage:t="Hello! How can I help you today?",placeholder:u="Type a message...",allowFiles:s=!1,height:f=500,placement:l="inline",width:p=400,defaultOpen:c=!1,logoUrl:h,showAgentName:N=!1,agentBubble:g=!1,showHeader:I=!0,theme:K,loadThreads:P=!1,forms:T,formSubmittedMessage:G=ze,onFollowUpClick:j,onMessageSent:qe,onMessageReceived:Xe,onFormSubmitted:ne,onFormError:oe}=o;if(!o.client&&!o.config?.baseUrl)throw new Oe.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const m=o.client??new Oe.AgoClient(o.config),ye=Ct(r),F=l==="left"||l==="right",Ke=F&&(o.launcher??!0);let z=F?c:!0;const re=o.persistConversation,V=re?at.createConversationSession(re===!0?{}:re):void 0;let _=o.conversationId??V?.getLastActiveThread()??void 0,d=[],L=!1,q=null;const ve=[];function Ve(e){if(typeof G=="function"){const i=G(e);if(typeof i=="string"&&i)return i}const n=xt(e);return n||(typeof G=="string"?G:ze)}const Q=[],H=b({display:"flex",flexDirection:"column",height:F?"100%":typeof f=="number"?`${f}px`:f,border:`1px solid ${A}`,borderRadius:mt,overflow:"hidden",backgroundColor:X,fontFamily:xe,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});H.className="ago-chat-widget",ht(H,K);let O;if(I){if(O=b({padding:"14px 16px",borderBottom:`1px solid ${A}`,backgroundColor:pt,color:Fe,display:"flex",alignItems:"center",gap:"10px"}),O.className="ago-chat-widget__header",h){const n=document.createElement("img");n.src=h,n.alt="Logo",E(n,{height:"24px",width:"auto"}),O.appendChild(n)}const e=document.createElement("h3");if(e.textContent=a,E(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),O.appendChild(e),F){const n=document.createElement("button");n.type="button",n.className="ago-chat-widget__close",n.setAttribute("aria-label","Close"),n.textContent="×",E(n,{marginLeft:"auto",background:"transparent",border:"none",color:Fe,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),n.addEventListener("click",()=>fe()),O.appendChild(n)}}const $=b({flex:"1",overflow:"auto",padding:"16px",backgroundColor:ft});$.className="ago-chat-widget__messages";const{inputRow:Qe,setDisabled:Ye,focus:ae}=vt({placeholder:u,allowFiles:s,onSend:(e,n)=>{le(e,n)}});bt(),H.append(...O?[O]:[],$,Qe);let Y=H,D,S;const ie=l==="left"?"left":"right";if(F&&(D=b({position:"fixed",top:"0",bottom:"0",[ie]:"0",width:typeof p=="number"?`${p}px`:p,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),D.className="ago-chat-widget-panel",E(H,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ie==="left"?"borderRight":"borderLeft"]:`1px solid ${A}`}),D.appendChild(H),Y=D),Ke){if(S=document.createElement("button"),S.type="button",S.className="ago-chat-widget-launcher",S.setAttribute("aria-label",`Open ${a}`),E(S,{position:"fixed",bottom:"20px",[ie]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:be,color:Ce,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:xe}),h){const e=document.createElement("img");e.src=h,e.alt="",E(e,{width:"26px",height:"26px",objectFit:"contain"}),S.appendChild(e)}else S.appendChild(ot());S.addEventListener("click",()=>pe())}ye.appendChild(Y),S&&ye.appendChild(S),ce();const Ee=j!==!1,we=j===!1?void 0:j??(e=>{le(e)});function Ze(e,n){const i=e.role==="user",x=b({display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start",marginBottom:"16px"});if(x.className=`ago-message ago-message--${e.role}`,!i&&N&&e.agent){const C=b({fontSize:"13px",fontWeight:"500",color:J,marginBottom:"6px",padding:"0 4px"});C.className="ago-message__agent",C.textContent=e.agent.displayName||e.agent.name,x.appendChild(C)}if(!i&&e.sources&&e.sources.length>0){const C=b({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});C.className="ago-message__sources",e.sources.forEach((y,w)=>{const B=y.url?document.createElement("a"):document.createElement("div");y.url&&B instanceof HTMLAnchorElement&&(B.href=y.url,B.target="_blank",B.rel="noopener noreferrer"),E(B,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${A}`,borderRadius:"8px",backgroundColor:X,textDecoration:"none",color:J,fontSize:"12px",overflow:"hidden"});const Le=b({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${ge}`,color:ge,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});Le.textContent=String(w+1);const ue=b({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});ue.textContent=y.title,ue.title=y.title,B.append(Le,ue),C.appendChild(B)}),x.appendChild(C)}const v=b({maxWidth:i?"75%":g?"85%":"100%",padding:i||g?"10px 14px":"2px 8px",borderRadius:i||g?me:"0",backgroundColor:i?be:g?gt:"transparent",color:i?Ce:J,wordBreak:"break-word",fontSize:"16px",lineHeight:"1.6"});if(v.className="ago-message__content",e.content?v.appendChild(te(e.content)):e.status==="IN_PROGRESS"&&v.appendChild(rt()),x.appendChild(v),n&&e.followUpReplies&&e.followUpReplies.length>0){const C=b({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});C.className="ago-message__followups";for(const y of e.followUpReplies){const w=document.createElement("button");w.type="button",w.className="ago-message__followup-btn",w.textContent=y,w.disabled=!Ee,E(w,{padding:"6px 14px",fontSize:"14px",borderRadius:me,border:`1px solid ${A}`,backgroundColor:X,color:J,cursor:Ee?"pointer":"default",transition:"border-color 0.15s"}),we&&w.addEventListener("click",()=>we(y)),w.addEventListener("mouseenter",()=>{w.style.borderColor=ge}),w.addEventListener("mouseleave",()=>{w.style.borderColor=A}),C.appendChild(w)}x.appendChild(C)}return x}function Je(e){const n=b({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:me,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});n.className="ago-form-notice",n.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),E(i,{fontWeight:"700"});const x=document.createElement("span");return x.textContent=e,n.append(i,x),n}function k(){if($.replaceChildren(),d.length===0){const n=b({textAlign:"center",color:ut,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});n.appendChild(te(t)),$.appendChild(n)}else d.forEach((n,i)=>{$.appendChild(Ze(n,i===d.length-1))});for(const n of ve)$.appendChild(Je(n));if(q){const n=b({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});n.textContent=q,$.appendChild(n)}$.scrollTop=$.scrollHeight;const e=d[d.length-1];Ye(L&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function et(){for(let e=d.length-1;e>=0;e--){const n=d[e];if(n.role==="assistant"&&n.status==="IN_PROGRESS")return n}}const Se=e=>{_||(_=e.conversationId)},Re=e=>{const n=et();n&&(n.content+=e.content,k())},_e=e=>{const n=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");n>=0?d[n]=e:d.push(e),k(),ae()},ke=e=>{const n=d.findIndex(i=>i.id===e.id||i.role==="assistant"&&i.status==="IN_PROGRESS");n>=0?d[n]=e:d.push(e),L=!1,k(),e.status==="DONE"&&Xe?.({id:e.id,content:e.content})},Ae=e=>{q=e.error,L=!1,d=d.filter(n=>!n.id.startsWith("temp-")),k()};m.on("message:start",Se),m.on("message:chunk",Re),m.on("message:answer-complete",_e),m.on("message:complete",ke),m.on("message:error",Ae);const Ie=e=>ne?.(e),$e=e=>oe?.(e);ne&&m.on("form:submitted",Ie),oe&&m.on("form:error",$e);const se=[];let Ne=!1;const Te=e=>{if(Ne)return;se.push(e.install(m));let n=e.store.get().submitted;const i=e.store.subscribe(x=>{x.submitted&&!n&&(ve.push(Ve(x.submitResult)),k()),n=x.submitted});se.push(i)};for(const e of T??[])e.schema!=null?Te(De.createFormCollector(e)):De.loadFormCollector(m,e).then(n=>Te(n)).catch(()=>{});async function le(e,n){const i=e.trim();if(!i&&!n?.length||L)return;qe?.(i),L=!0,q=null;const x=Date.now();d.push({id:`temp-user-${x}`,conversationId:_||"",content:i,role:"user",status:"DONE",createdAt:new Date}),d.push({id:`temp-assistant-${x}`,conversationId:_||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),k();try{const v=await m.sendMessage(i,{conversationId:_,files:n});v.conversationId&&(_||(_=v.conversationId),V?.setActiveThread(v.conversationId,v.createdAt));const C=d.find(y=>y.id===`temp-user-${x}`);if(C&&(C.id=`user-${x}`,C.conversationId=v.conversationId),!d.some(y=>y.id===v.id)){const y=d.findIndex(w=>w.id===`temp-assistant-${x}`);y>=0?d[y]=v:d.push(v)}d=d.filter(y=>!y.id.startsWith("temp-")),L=!1,k(),P&&de()}catch(v){q=v instanceof Error?v.message:"Failed to send message",L=!1,d=d.filter(C=>!C.id.startsWith("temp-")),k()}}async function de(){try{const e=await m.getConversations();Q.splice(0,Q.length,...e)}catch{}return Q}async function tt(e){try{const n=(await m.getConversation(e))?.messages??[];n.length>0&&d.length===0&&(d=n,k())}catch{d.length===0&&(V?.clear(),_=void 0)}}return k(),ae(),_&&tt(_),P&&de(),{client:m,element:Y,sendMessage:le,...F?{open:pe,close:fe,toggle:nt}:{},session:V,threads:Q,refreshThreads:de,destroy(){m.off("message:start",Se),m.off("message:chunk",Re),m.off("message:answer-complete",_e),m.off("message:complete",ke),m.off("message:error",Ae),ne&&m.off("form:submitted",Ie),oe&&m.off("form:error",$e),Ne=!0,se.forEach(e=>e()),Y.remove(),S?.remove(),o.client||m.destroy()}};function ce(){if(!D)return;const e=l==="left"?"translateX(-100%)":"translateX(100%)";D.style.transform=z?"translateX(0)":e,D.setAttribute("aria-hidden",z?"false":"true"),S&&(S.style.display=z?"none":"flex")}function pe(){z=!0,ce(),ae()}function fe(){z=!1,ce()}function nt(){z?fe():pe()}function ot(){const e="http://www.w3.org/2000/svg",n=document.createElementNS(e,"svg");n.setAttribute("width","26"),n.setAttribute("height","26"),n.setAttribute("viewBox","0 0 24 24"),n.setAttribute("fill","none");const i=document.createElementNS(e,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),n.appendChild(i),n}function rt(){const e=b({display:"flex",gap:"4px",padding:"4px 0"});for(let n=0;n<3;n++){const i=b({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${n*.2}s`});e.appendChild(i)}return e}}function vt(r){let o=[];const a=document.createElement("form");E(a,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${A}`,backgroundColor:X}),a.className="ago-chat-input";const t=b({display:"flex",flexWrap:"wrap",gap:"6px"}),u=b({display:"flex",gap:"8px",alignItems:"flex-end"}),s=document.createElement("textarea");s.placeholder=r.placeholder,s.rows=1,E(s,{flex:"1",resize:"none",padding:"10px 12px",border:`1px solid ${A}`,borderRadius:"12px",fontSize:"16px",fontFamily:xe,lineHeight:"1.4",maxHeight:"120px",outline:"none"});const f=document.createElement("button");f.type="submit",f.textContent="Send",E(f,{padding:"10px 16px",border:"none",borderRadius:"12px",backgroundColor:be,color:Ce,fontSize:"16px",fontWeight:"500",cursor:"pointer"});let l=null,p=null;r.allowFiles&&(l=document.createElement("input"),l.type="file",l.multiple=!0,E(l,{display:"none"}),p=document.createElement("button"),p.type="button",p.textContent="📎",E(p,{padding:"10px 12px",border:`1px solid ${A}`,borderRadius:"12px",backgroundColor:X,cursor:"pointer",fontSize:"14px"}),p.addEventListener("click",()=>l?.click()),l.addEventListener("change",()=>{o=[...o,...Array.from(l?.files??[])],c()}));function c(){t.replaceChildren(),o.forEach((g,I)=>{const K=b({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${A}`,borderRadius:"8px",fontSize:"12px"}),P=document.createElement("span");P.textContent=g.name;const T=document.createElement("button");T.type="button",T.textContent="×",E(T,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),T.addEventListener("click",()=>{o=o.filter((G,j)=>j!==I),c()}),K.append(P,T),t.appendChild(K)})}const h=()=>{const g=s.value,I=o;return s.value="",o=[],c(),{content:g,files:I}},N=()=>{const{content:g,files:I}=h();(g.trim()||I.length>0)&&r.onSend(g.trim(),I.length>0?I:void 0)};return a.addEventListener("submit",g=>{g.preventDefault(),N()}),s.addEventListener("keydown",g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),N())}),p&&u.appendChild(p),u.append(s,f),l&&a.appendChild(l),a.append(t,u),{inputRow:a,getValueAndClear:h,setDisabled:g=>{s.disabled=g,f.disabled=g,f.style.opacity=g?"0.6":"1",f.style.cursor=g?"not-allowed":"pointer"},focus:()=>s.focus()}}exports.mountChatWidget=yt;exports.renderMarkdown=te;