@useago/sdk 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +103 -74
- package/dist/AgoClient-_fig8FoN.cjs +6 -0
- package/dist/{AgoClient-BrYhSO5M.js → AgoClient-bQozE6-A.js} +174 -134
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +131 -1
- package/dist/angular.d.ts +131 -1
- package/dist/angular.js +1 -1
- package/dist/{createConversationSession-Dmqd80DX.js → createConversationSession-BbK3ou1k.js} +1 -1
- package/dist/{createConversationSession-CGRO0bs2.cjs → createConversationSession-DJUFgOXy.cjs} +1 -1
- package/dist/createFormCollector-CdQjGAl_.cjs +1 -0
- package/dist/createFormCollector-D-TpSd9x.js +257 -0
- package/dist/devtools.d.cts +131 -1
- package/dist/devtools.d.ts +131 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +126 -4
- package/dist/index.d.ts +126 -4
- package/dist/index.js +94 -92
- package/dist/react.cjs +20 -20
- package/dist/react.d.cts +125 -30
- package/dist/react.d.ts +125 -30
- package/dist/react.js +2207 -2135
- package/dist/testing.d.cts +131 -1
- package/dist/testing.d.ts +131 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +131 -1
- package/dist/vue.d.ts +131 -1
- package/dist/vue.js +1 -1
- package/dist/widget.cjs +4 -4
- package/dist/widget.d.cts +115 -5
- package/dist/widget.d.ts +115 -5
- package/dist/widget.js +408 -322
- package/package.json +2 -2
- package/dist/AgoClient-CPqPT5s6.cjs +0 -6
- package/dist/createFormCollector-CPS2phYq.js +0 -245
- package/dist/createFormCollector-DaWZsBsI.cjs +0 -1
package/dist/angular.d.cts
CHANGED
|
@@ -16,12 +16,26 @@ declare class AgoClient {
|
|
|
16
16
|
private contextRegistry;
|
|
17
17
|
private eventEmitter;
|
|
18
18
|
private config;
|
|
19
|
+
/** Conversations already warned about an empty reply (one warning each). */
|
|
20
|
+
private warnedEmptyConversations;
|
|
19
21
|
constructor(config: AgoConfig);
|
|
20
22
|
/**
|
|
21
23
|
* Send a message and receive a streaming response
|
|
22
24
|
*/
|
|
23
25
|
sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
|
|
24
26
|
private processSSEResponse;
|
|
27
|
+
/**
|
|
28
|
+
* Detect a reply that completed as DONE with no content and no activity —
|
|
29
|
+
* today's backend answers an unknown `agent` slug with an empty 200, which
|
|
30
|
+
* otherwise fails silently. Emits `message:empty` (always) and warns on the
|
|
31
|
+
* console once per conversation (unless `warnOnEmptyReply: false`).
|
|
32
|
+
*
|
|
33
|
+
* Deferred with setTimeout(0) so both land AFTER `sendMessage` resolves:
|
|
34
|
+
* `await client.sendMessage(...)` followed by `client.waitFor("message:empty")`
|
|
35
|
+
* must not race. TEMPORARY heuristic: remove once the backend returns an
|
|
36
|
+
* explicit error for unknown agents (see TODOS.md, backend issue).
|
|
37
|
+
*/
|
|
38
|
+
private maybeFlagEmptyReply;
|
|
25
39
|
private handleClientFunctionInvocation;
|
|
26
40
|
/**
|
|
27
41
|
* Get list of conversations
|
|
@@ -53,6 +67,13 @@ declare class AgoClient {
|
|
|
53
67
|
* Reject a tool call
|
|
54
68
|
*/
|
|
55
69
|
rejectToolCall(toolCallId: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Fetch a backend-stored form collector definition by name (the single source
|
|
72
|
+
* of truth for the form's description, schema, and submit target). Used by
|
|
73
|
+
* `loadFormCollector` / the name-only form of `useFormCollector` so the schema
|
|
74
|
+
* lives in the backend instead of being hardcoded in client code.
|
|
75
|
+
*/
|
|
76
|
+
getFormCollector(name: string): Promise<FormCollectorDefinition>;
|
|
56
77
|
/**
|
|
57
78
|
* Relay a completed form collector's values to a server-configured destination.
|
|
58
79
|
*
|
|
@@ -187,6 +208,11 @@ declare class AgoClient {
|
|
|
187
208
|
}): Promise<AgoClientEvents[K]>;
|
|
188
209
|
/**
|
|
189
210
|
* Update client configuration
|
|
211
|
+
*
|
|
212
|
+
* Validates the MERGED config before committing: omitting a key (or passing
|
|
213
|
+
* it as `undefined`, common with spread-built partials) keeps the current
|
|
214
|
+
* value; an explicit empty/non-string `baseUrl` throws `config_missing_base_url`
|
|
215
|
+
* and leaves the client unchanged (no half-updated state).
|
|
190
216
|
*/
|
|
191
217
|
updateConfig(config: Partial<AgoConfig>): void;
|
|
192
218
|
/**
|
|
@@ -222,8 +248,23 @@ export declare interface AgoClientEvents {
|
|
|
222
248
|
*/
|
|
223
249
|
"message:answer-complete": AgoMessage;
|
|
224
250
|
"message:complete": AgoMessage;
|
|
251
|
+
/**
|
|
252
|
+
* A reply finished as `DONE` with empty content and no tool calls, client
|
|
253
|
+
* functions, or follow-up replies — usually an unknown `agent` slug (the
|
|
254
|
+
* backend currently answers those with an empty 200). Fires after
|
|
255
|
+
* `message:complete` AND after `sendMessage` resolves, so subscribing right
|
|
256
|
+
* after `await sendMessage(...)` still catches it. `messageId` and
|
|
257
|
+
* `conversationId` are empty strings when the stream completed without any
|
|
258
|
+
* message data at all (e.g. a proxy stripped the SSE stream).
|
|
259
|
+
*/
|
|
260
|
+
"message:empty": {
|
|
261
|
+
conversationId: string;
|
|
262
|
+
messageId: string;
|
|
263
|
+
};
|
|
225
264
|
"message:error": {
|
|
226
265
|
error: string;
|
|
266
|
+
/** Stable error code (see configuration.md#error-codes) when the failure was an AgoError. */
|
|
267
|
+
code?: string;
|
|
227
268
|
conversationId?: string;
|
|
228
269
|
messageId?: string;
|
|
229
270
|
};
|
|
@@ -252,7 +293,7 @@ export declare interface AgoClientEvents {
|
|
|
252
293
|
export declare interface AgoConfig {
|
|
253
294
|
/** API base URL (e.g., https://YOUR-DOMAIN.useago.com) */
|
|
254
295
|
baseUrl: string;
|
|
255
|
-
/**
|
|
296
|
+
/** Per-visitor anonymous ID (X-User-Anon-Id header). Auto-generated if not provided. */
|
|
256
297
|
widgetId?: string;
|
|
257
298
|
/** Default agent (id or slug) for new conversations. Shorthand for `defaultAgentId`. */
|
|
258
299
|
agent?: string;
|
|
@@ -266,6 +307,13 @@ export declare interface AgoConfig {
|
|
|
266
307
|
userJwt?: string;
|
|
267
308
|
/** Enable debug logging */
|
|
268
309
|
debug?: boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Warn on the console when a reply completes with empty content and no tool
|
|
312
|
+
* calls (the usual cause is an unknown `agent` slug, which the backend
|
|
313
|
+
* currently answers with an empty 200). Default `true`. The `message:empty`
|
|
314
|
+
* event fires regardless of this setting.
|
|
315
|
+
*/
|
|
316
|
+
warnOnEmptyReply?: boolean;
|
|
269
317
|
}
|
|
270
318
|
|
|
271
319
|
declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
|
|
@@ -477,6 +525,30 @@ export declare interface Conversation {
|
|
|
477
525
|
*/
|
|
478
526
|
declare type DynamicContextProvider = () => ContextEntry | null | undefined;
|
|
479
527
|
|
|
528
|
+
/**
|
|
529
|
+
* The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
|
|
530
|
+
* {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
|
|
531
|
+
* {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
|
|
532
|
+
* `handler` variant (a function can't be stored server-side).
|
|
533
|
+
*/
|
|
534
|
+
declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
535
|
+
name: string;
|
|
536
|
+
description: string;
|
|
537
|
+
schema: FormCollectorSchema;
|
|
538
|
+
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
539
|
+
submit?: SubmitConfig<V>;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Shape of a form's fields. Mirrors a client function's `parameters` (so the same
|
|
544
|
+
* 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.
|
|
545
|
+
*/
|
|
546
|
+
declare interface FormCollectorSchema {
|
|
547
|
+
type: "object";
|
|
548
|
+
properties: Record<string, FormFieldSchema>;
|
|
549
|
+
required?: string[];
|
|
550
|
+
}
|
|
551
|
+
|
|
480
552
|
declare interface FormField {
|
|
481
553
|
type: "string" | "number" | "boolean" | "array";
|
|
482
554
|
title?: string;
|
|
@@ -485,6 +557,43 @@ declare interface FormField {
|
|
|
485
557
|
default?: unknown;
|
|
486
558
|
}
|
|
487
559
|
|
|
560
|
+
/**
|
|
561
|
+
* A field's conditional-requiredness rule. The field becomes required exactly
|
|
562
|
+
* when the controlling `property` matches `value` against the answers collected
|
|
563
|
+
* so far:
|
|
564
|
+
* - a single `value`, no `op` — equality (compared as strings);
|
|
565
|
+
* - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
|
|
566
|
+
* - an array `value`, no `op` — "one of": matches when the property equals any
|
|
567
|
+
* listed value.
|
|
568
|
+
*
|
|
569
|
+
* SDK-only — it is stripped from the schema before it reaches the LLM tool
|
|
570
|
+
*/
|
|
571
|
+
declare interface FormFieldCondition {
|
|
572
|
+
/** The controlling field whose value the rule tests. */
|
|
573
|
+
property: string;
|
|
574
|
+
/** Comparison operator; omitted means equality. Ignored when `value` is an array. */
|
|
575
|
+
op?: ">=" | "<=" | ">" | "<";
|
|
576
|
+
/**
|
|
577
|
+
* The value(s) to test the controlling field against. A single value is an
|
|
578
|
+
* equality (or, with `op`, a numeric comparison); an array is an "is one of"
|
|
579
|
+
* membership test, e.g. `value: ["1", "2", "3"]`.
|
|
580
|
+
*/
|
|
581
|
+
value: string | number | Array<string | number>;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
|
|
585
|
+
declare interface FormFieldSchema {
|
|
586
|
+
type: string;
|
|
587
|
+
description?: string;
|
|
588
|
+
enum?: string[];
|
|
589
|
+
default?: unknown;
|
|
590
|
+
/**
|
|
591
|
+
* Makes the field required only while this condition holds. Drives the dynamic
|
|
592
|
+
* `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
|
|
593
|
+
*/
|
|
594
|
+
requiredWhen?: FormFieldCondition;
|
|
595
|
+
}
|
|
596
|
+
|
|
488
597
|
/**
|
|
489
598
|
* Form schema for tool calls requiring user input
|
|
490
599
|
*/
|
|
@@ -541,6 +650,27 @@ declare interface SendMessageOptions {
|
|
|
541
650
|
files?: File[];
|
|
542
651
|
}
|
|
543
652
|
|
|
653
|
+
/**
|
|
654
|
+
* Where a completed form is sent.
|
|
655
|
+
* - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
|
|
656
|
+
* POSTs the values to that URL.
|
|
657
|
+
* - `{ via: "client", url }` — same, written out.
|
|
658
|
+
* - `{ via: "client", handler }` — the browser runs your own submit logic.
|
|
659
|
+
* - `{ via: "backend", destination }` — the browser relays the values to the backend,
|
|
660
|
+
* which forwards them to the server-configured destination (URL + secret stay server-side).
|
|
661
|
+
* - `false` — collect only, no submit function.
|
|
662
|
+
*/
|
|
663
|
+
declare type SubmitConfig<V = Record<string, unknown>> = string | {
|
|
664
|
+
via: "client";
|
|
665
|
+
url: string;
|
|
666
|
+
} | {
|
|
667
|
+
via: "client";
|
|
668
|
+
handler: (values: V) => Promise<unknown> | unknown;
|
|
669
|
+
} | {
|
|
670
|
+
via: "backend";
|
|
671
|
+
destination: string;
|
|
672
|
+
} | false;
|
|
673
|
+
|
|
544
674
|
/**
|
|
545
675
|
* Tool call data from SSE stream
|
|
546
676
|
*/
|
package/dist/angular.d.ts
CHANGED
|
@@ -16,12 +16,26 @@ declare class AgoClient {
|
|
|
16
16
|
private contextRegistry;
|
|
17
17
|
private eventEmitter;
|
|
18
18
|
private config;
|
|
19
|
+
/** Conversations already warned about an empty reply (one warning each). */
|
|
20
|
+
private warnedEmptyConversations;
|
|
19
21
|
constructor(config: AgoConfig);
|
|
20
22
|
/**
|
|
21
23
|
* Send a message and receive a streaming response
|
|
22
24
|
*/
|
|
23
25
|
sendMessage(content: string, options?: SendMessageOptions): Promise<AgoMessage>;
|
|
24
26
|
private processSSEResponse;
|
|
27
|
+
/**
|
|
28
|
+
* Detect a reply that completed as DONE with no content and no activity —
|
|
29
|
+
* today's backend answers an unknown `agent` slug with an empty 200, which
|
|
30
|
+
* otherwise fails silently. Emits `message:empty` (always) and warns on the
|
|
31
|
+
* console once per conversation (unless `warnOnEmptyReply: false`).
|
|
32
|
+
*
|
|
33
|
+
* Deferred with setTimeout(0) so both land AFTER `sendMessage` resolves:
|
|
34
|
+
* `await client.sendMessage(...)` followed by `client.waitFor("message:empty")`
|
|
35
|
+
* must not race. TEMPORARY heuristic: remove once the backend returns an
|
|
36
|
+
* explicit error for unknown agents (see TODOS.md, backend issue).
|
|
37
|
+
*/
|
|
38
|
+
private maybeFlagEmptyReply;
|
|
25
39
|
private handleClientFunctionInvocation;
|
|
26
40
|
/**
|
|
27
41
|
* Get list of conversations
|
|
@@ -53,6 +67,13 @@ declare class AgoClient {
|
|
|
53
67
|
* Reject a tool call
|
|
54
68
|
*/
|
|
55
69
|
rejectToolCall(toolCallId: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Fetch a backend-stored form collector definition by name (the single source
|
|
72
|
+
* of truth for the form's description, schema, and submit target). Used by
|
|
73
|
+
* `loadFormCollector` / the name-only form of `useFormCollector` so the schema
|
|
74
|
+
* lives in the backend instead of being hardcoded in client code.
|
|
75
|
+
*/
|
|
76
|
+
getFormCollector(name: string): Promise<FormCollectorDefinition>;
|
|
56
77
|
/**
|
|
57
78
|
* Relay a completed form collector's values to a server-configured destination.
|
|
58
79
|
*
|
|
@@ -187,6 +208,11 @@ declare class AgoClient {
|
|
|
187
208
|
}): Promise<AgoClientEvents[K]>;
|
|
188
209
|
/**
|
|
189
210
|
* Update client configuration
|
|
211
|
+
*
|
|
212
|
+
* Validates the MERGED config before committing: omitting a key (or passing
|
|
213
|
+
* it as `undefined`, common with spread-built partials) keeps the current
|
|
214
|
+
* value; an explicit empty/non-string `baseUrl` throws `config_missing_base_url`
|
|
215
|
+
* and leaves the client unchanged (no half-updated state).
|
|
190
216
|
*/
|
|
191
217
|
updateConfig(config: Partial<AgoConfig>): void;
|
|
192
218
|
/**
|
|
@@ -222,8 +248,23 @@ export declare interface AgoClientEvents {
|
|
|
222
248
|
*/
|
|
223
249
|
"message:answer-complete": AgoMessage;
|
|
224
250
|
"message:complete": AgoMessage;
|
|
251
|
+
/**
|
|
252
|
+
* A reply finished as `DONE` with empty content and no tool calls, client
|
|
253
|
+
* functions, or follow-up replies — usually an unknown `agent` slug (the
|
|
254
|
+
* backend currently answers those with an empty 200). Fires after
|
|
255
|
+
* `message:complete` AND after `sendMessage` resolves, so subscribing right
|
|
256
|
+
* after `await sendMessage(...)` still catches it. `messageId` and
|
|
257
|
+
* `conversationId` are empty strings when the stream completed without any
|
|
258
|
+
* message data at all (e.g. a proxy stripped the SSE stream).
|
|
259
|
+
*/
|
|
260
|
+
"message:empty": {
|
|
261
|
+
conversationId: string;
|
|
262
|
+
messageId: string;
|
|
263
|
+
};
|
|
225
264
|
"message:error": {
|
|
226
265
|
error: string;
|
|
266
|
+
/** Stable error code (see configuration.md#error-codes) when the failure was an AgoError. */
|
|
267
|
+
code?: string;
|
|
227
268
|
conversationId?: string;
|
|
228
269
|
messageId?: string;
|
|
229
270
|
};
|
|
@@ -252,7 +293,7 @@ export declare interface AgoClientEvents {
|
|
|
252
293
|
export declare interface AgoConfig {
|
|
253
294
|
/** API base URL (e.g., https://YOUR-DOMAIN.useago.com) */
|
|
254
295
|
baseUrl: string;
|
|
255
|
-
/**
|
|
296
|
+
/** Per-visitor anonymous ID (X-User-Anon-Id header). Auto-generated if not provided. */
|
|
256
297
|
widgetId?: string;
|
|
257
298
|
/** Default agent (id or slug) for new conversations. Shorthand for `defaultAgentId`. */
|
|
258
299
|
agent?: string;
|
|
@@ -266,6 +307,13 @@ export declare interface AgoConfig {
|
|
|
266
307
|
userJwt?: string;
|
|
267
308
|
/** Enable debug logging */
|
|
268
309
|
debug?: boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Warn on the console when a reply completes with empty content and no tool
|
|
312
|
+
* calls (the usual cause is an unknown `agent` slug, which the backend
|
|
313
|
+
* currently answers with an empty 200). Default `true`. The `message:empty`
|
|
314
|
+
* event fires regardless of this setting.
|
|
315
|
+
*/
|
|
316
|
+
warnOnEmptyReply?: boolean;
|
|
269
317
|
}
|
|
270
318
|
|
|
271
319
|
declare type AgoEventHandler<K extends AgoEventName> = (data: AgoClientEvents[K]) => void;
|
|
@@ -477,6 +525,30 @@ export declare interface Conversation {
|
|
|
477
525
|
*/
|
|
478
526
|
declare type DynamicContextProvider = () => ContextEntry | null | undefined;
|
|
479
527
|
|
|
528
|
+
/**
|
|
529
|
+
* The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
|
|
530
|
+
* {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
|
|
531
|
+
* {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
|
|
532
|
+
* `handler` variant (a function can't be stored server-side).
|
|
533
|
+
*/
|
|
534
|
+
declare interface FormCollectorDefinition<V = Record<string, unknown>> {
|
|
535
|
+
name: string;
|
|
536
|
+
description: string;
|
|
537
|
+
schema: FormCollectorSchema;
|
|
538
|
+
/** Server-stored submit target, if any. Absent means collect-only. */
|
|
539
|
+
submit?: SubmitConfig<V>;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Shape of a form's fields. Mirrors a client function's `parameters` (so the same
|
|
544
|
+
* 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.
|
|
545
|
+
*/
|
|
546
|
+
declare interface FormCollectorSchema {
|
|
547
|
+
type: "object";
|
|
548
|
+
properties: Record<string, FormFieldSchema>;
|
|
549
|
+
required?: string[];
|
|
550
|
+
}
|
|
551
|
+
|
|
480
552
|
declare interface FormField {
|
|
481
553
|
type: "string" | "number" | "boolean" | "array";
|
|
482
554
|
title?: string;
|
|
@@ -485,6 +557,43 @@ declare interface FormField {
|
|
|
485
557
|
default?: unknown;
|
|
486
558
|
}
|
|
487
559
|
|
|
560
|
+
/**
|
|
561
|
+
* A field's conditional-requiredness rule. The field becomes required exactly
|
|
562
|
+
* when the controlling `property` matches `value` against the answers collected
|
|
563
|
+
* so far:
|
|
564
|
+
* - a single `value`, no `op` — equality (compared as strings);
|
|
565
|
+
* - a single `value` with `op` — numeric comparison (both sides coerced to numbers);
|
|
566
|
+
* - an array `value`, no `op` — "one of": matches when the property equals any
|
|
567
|
+
* listed value.
|
|
568
|
+
*
|
|
569
|
+
* SDK-only — it is stripped from the schema before it reaches the LLM tool
|
|
570
|
+
*/
|
|
571
|
+
declare interface FormFieldCondition {
|
|
572
|
+
/** The controlling field whose value the rule tests. */
|
|
573
|
+
property: string;
|
|
574
|
+
/** Comparison operator; omitted means equality. Ignored when `value` is an array. */
|
|
575
|
+
op?: ">=" | "<=" | ">" | "<";
|
|
576
|
+
/**
|
|
577
|
+
* The value(s) to test the controlling field against. A single value is an
|
|
578
|
+
* equality (or, with `op`, a numeric comparison); an array is an "is one of"
|
|
579
|
+
* membership test, e.g. `value: ["1", "2", "3"]`.
|
|
580
|
+
*/
|
|
581
|
+
value: string | number | Array<string | number>;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** A single field's schema: the wire-legal keys plus the SDK-only `requiredWhen`. */
|
|
585
|
+
declare interface FormFieldSchema {
|
|
586
|
+
type: string;
|
|
587
|
+
description?: string;
|
|
588
|
+
enum?: string[];
|
|
589
|
+
default?: unknown;
|
|
590
|
+
/**
|
|
591
|
+
* Makes the field required only while this condition holds. Drives the dynamic
|
|
592
|
+
* `missing` list; stripped before the LLM tool — see {@link toWireParameters}.
|
|
593
|
+
*/
|
|
594
|
+
requiredWhen?: FormFieldCondition;
|
|
595
|
+
}
|
|
596
|
+
|
|
488
597
|
/**
|
|
489
598
|
* Form schema for tool calls requiring user input
|
|
490
599
|
*/
|
|
@@ -541,6 +650,27 @@ declare interface SendMessageOptions {
|
|
|
541
650
|
files?: File[];
|
|
542
651
|
}
|
|
543
652
|
|
|
653
|
+
/**
|
|
654
|
+
* Where a completed form is sent.
|
|
655
|
+
* - `"https://..."` (a bare string) — shorthand for `{ via: "client", url }`: the browser
|
|
656
|
+
* POSTs the values to that URL.
|
|
657
|
+
* - `{ via: "client", url }` — same, written out.
|
|
658
|
+
* - `{ via: "client", handler }` — the browser runs your own submit logic.
|
|
659
|
+
* - `{ via: "backend", destination }` — the browser relays the values to the backend,
|
|
660
|
+
* which forwards them to the server-configured destination (URL + secret stay server-side).
|
|
661
|
+
* - `false` — collect only, no submit function.
|
|
662
|
+
*/
|
|
663
|
+
declare type SubmitConfig<V = Record<string, unknown>> = string | {
|
|
664
|
+
via: "client";
|
|
665
|
+
url: string;
|
|
666
|
+
} | {
|
|
667
|
+
via: "client";
|
|
668
|
+
handler: (values: V) => Promise<unknown> | unknown;
|
|
669
|
+
} | {
|
|
670
|
+
via: "backend";
|
|
671
|
+
destination: string;
|
|
672
|
+
} | false;
|
|
673
|
+
|
|
544
674
|
/**
|
|
545
675
|
* Tool call data from SSE stream
|
|
546
676
|
*/
|
package/dist/angular.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as o } from "./AgoClient-
|
|
1
|
+
import { t as o } from "./AgoClient-bQozE6-A.js";
|
|
2
2
|
var n = class {
|
|
3
3
|
constructor(t) {
|
|
4
4
|
this.client = new o(t), this.messages$ = this.fromEvent("message:complete"), this.chunks$ = this.fromEvent("message:chunk"), this.errors$ = this.fromEvent("message:error"), this.messageStart$ = this.fromEvent("message:start");
|
package/dist/{createConversationSession-Dmqd80DX.js → createConversationSession-BbK3ou1k.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as d } from "./createFormCollector-D-TpSd9x.js";
|
|
2
2
|
var f = "ago_widget_id", g = "ago_last_thread", y = 7200 * 1e3;
|
|
3
3
|
function v() {
|
|
4
4
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
|
package/dist/{createConversationSession-CGRO0bs2.cjs → createConversationSession-DJUFgOXy.cjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
const d=require("./createFormCollector-
|
|
1
|
+
const d=require("./createFormCollector-CdQjGAl_.cjs");var f="ago_widget_id",g="ago_last_thread",y=7200*1e3;function v(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const r=Math.floor(Math.random()*16);return(e==="x"?r:r&3|8).toString(16)})}function _(e={}){const r=e.key??f,i=e.threadKey??g,u=e.ttlMs??y,l=e.storage??(typeof localStorage<"u"?localStorage:void 0);let n=e.widgetId??"";if(!n&&l)try{n=l.getItem(r)??""}catch{}if(n||(n=v()),l)try{l.setItem(r,n)}catch{}const o=d.createStore({value:null,lastMessageAt:null},{key:i,storage:l}),c=o.get();c.value!==null&&s(c.lastMessageAt)&&o.set({value:null,lastMessageAt:null});function s(t){return t===null?!0:Number.isFinite(u)?Date.now()-t>u:!1}return{widgetId:n,key:r,getLastActiveThread(){const{value:t,lastMessageAt:a}=o.get();return t===null||s(a)?null:t},setActiveThread(t,a){const x=a==null?null:a instanceof Date?a.getTime():a;o.set({value:t,lastMessageAt:x})},clear(){o.set({value:null,lastMessageAt:null})}}}Object.defineProperty(exports,"createConversationSession",{enumerable:!0,get:function(){return _}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const O=require("./AgoClient-_fig8FoN.cjs");function _(o,e){const i=e?e.storage??(typeof localStorage<"u"?localStorage:void 0):void 0;let t=o;if(e&&i)try{const c=i.getItem(e.key);c!=null&&(t=JSON.parse(c))}catch{}const a=new Set,f=()=>a.forEach(c=>c(t));function d(){if(e&&i)try{i.setItem(e.key,JSON.stringify(t))}catch{}}return{get:()=>t,set:c=>{t=c,d(),f()},subscribe:c=>(a.add(c),()=>{a.delete(c)})}}var k=/^[a-zA-Z0-9_-]{1,40}$/,P=o=>o==null||o==="";function q(o,e){const i=e[o.property];if(P(i))return!1;if(Array.isArray(o.value))return o.value.some(f=>String(i)===String(f));if(!o.op)return String(i)===String(o.value);const t=Number(i),a=Number(o.value);if(Number.isNaN(t)||Number.isNaN(a))return!1;switch(o.op){case">=":return t>=a;case"<=":return t<=a;case">":return t>a;case"<":return t<a;default:return O.logger.warn(`Unknown requiredWhen op "${o.op}"; treating as not required.`),!1}}function p(o,e){const i=o.properties??{},t=new Set;for(const f of o.required??[]){const d=i[f]?.requiredWhen;(!d||q(d,e))&&t.add(f)}for(const[f,d]of Object.entries(i))d.requiredWhen&&q(d.requiredWhen,e)&&t.add(f);const a=[...t].filter(f=>P(e[f]));return{missing:a,complete:a.length===0}}function W(o){const e={};for(const[i,t]of Object.entries(o.properties??{}))e[i]={type:t.type,...t.description!=null&&{description:t.description},...t.enum&&{enum:t.enum},...t.default!==void 0&&{default:t.default}};return{type:"object",properties:e,required:[]}}function j(o){const{name:e,description:i,schema:t}=o;if(!k.test(e))throw new Error(`Invalid form collector name "${e}": must match ${k} (it becomes the update_/submit_ function names).`);const a=typeof o.submit=="string"?o.submit?{via:"client",url:o.submit}:!1:o.submit??!1,f=t.properties??{},d=r=>{const n={};for(const[u,s]of Object.entries(r)){const l=f[u];if(l)if(s==null)n[u]=s;else if(l.type==="number"||l.type==="integer"){const b=typeof s=="number"?s:Number(s);n[u]=Number.isNaN(b)?s:b}else l.type==="boolean"?n[u]=typeof s=="boolean"?s:s==="true"?!0:s==="false"?!1:!!s:n[u]=s}return n},c=o.initialValues??{},m=_({values:c,submitted:!1}),v=r=>{const n=m.get(),u={...n,values:{...n.values,...r}};return m.set(u),u};let h=null;const N=async()=>{const{values:r}=m.get(),{complete:n,missing:u}=p(t,r);if(!n)return{ok:!1,missing:u};if(!a)return{ok:!1,error:"No submit target configured for this form collector."};const s=r;try{let l;if(a.via==="client")if("handler"in a)l=await a.handler(s);else{const b=await fetch(a.url,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(s)});if(!b.ok)return{ok:!1,error:`Submit failed: HTTP ${b.status}`};l=await b.json().catch(()=>{})}else{if(!h)return{ok:!1,error:"Backend submit requires install(client) (or useFormCollector) first."};l=await h.submitFormCollector(a.destination,s)}return m.set({...m.get(),submitted:!0}),{ok:!0,result:l}}catch(l){const b=l instanceof Error?l.message:"Submit failed";return O.logger.error(`FormCollector "${e}" submit failed:`,l),{ok:!1,error:b}}},S={name:`update_${e}`,description:`Fill or update fields of the "${e}" form. ${i} Pass any subset of fields; call it repeatedly to fill the form as the user provides information. Returns the current values and which required fields are still missing.`,parameters:W(t),handler:r=>{const n=v(d(r)),{missing:u}=p(t,n.values);return{ok:!0,values:n.values,missing:u}}},g=[S];a&&g.push({name:`submit_${e}`,description:`Submit the completed "${e}" form. Only call this once every required field is collected and the user has confirmed. If fields are missing it returns them instead of submitting.`,parameters:{type:"object",properties:{}},handler:()=>N()});const T="client__",C=a?`submit_${e}`:null,E=r=>{const n=r.functionName??r.toolName;if(n)return n.startsWith(T)?n.slice(8):n},$=r=>{let n={...c},u=!1;for(const s of r){const l=E(s);l===S.name?s.arguments&&(n={...n,...d(s.arguments)}):C&&l===C&&s.status?.toLowerCase()==="done"&&(u=!0)}m.set({values:n,submitted:u})},y=`form:${e}`,w=()=>{const{values:r,submitted:n}=m.get(),{missing:u,complete:s}=p(t,r),l=a?` When nothing is missing and the user confirms, call submit_${e}.`:"",b=n?`The "${e}" form has been submitted.`:`You are currently collecting information from the user to fill the "${e}" form.`;return{name:`Form: ${e}`,description:`${b} ${i} There are conditionnals questions/values to collected, you can find this information with the requiredWhen field in the form. The form schema is the following: ${JSON.stringify(t)}. Data collected so far: ${JSON.stringify(r)}. Call update_${e} with any fields the user provides; ask only for what is still missing.${l}`,data:{values:r,missing:u,complete:s,submitted:n}}},F=r=>{$((r.messages??[]).flatMap(n=>n.toolCalls??[]))};return{name:e,store:m,functions:g,contextKey:y,contextProvider:w,install:r=>{h=r;for(const u of g)r.register(u);r.addDynamicContext(y,w);const n=m.subscribe(()=>r.notifyContextChanged());return r.on("conversation:loaded",F),()=>{n();for(const u of g)r.unregisterFunction(u.name);r.removeDynamicContext(y),r.off("conversation:loaded",F),h===r&&(h=null)}},hydrate:$,submit:N,getValues:()=>m.get().values,setValues:r=>{v(d(r))},reset:()=>{m.set({values:c,submitted:!1})},getStatus:()=>p(t,m.get().values)}}async function x(o,e){const i=await o.getFormCollector(e.name);return j({name:i.name,description:e.description??i.description,schema:e.schema??i.schema,submit:e.submit??i.submit,initialValues:e.initialValues})}Object.defineProperty(exports,"createFormCollector",{enumerable:!0,get:function(){return j}});Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return _}});Object.defineProperty(exports,"deriveFormStatus",{enumerable:!0,get:function(){return p}});Object.defineProperty(exports,"loadFormCollector",{enumerable:!0,get:function(){return x}});
|