@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/dist/widget.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 @@ 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 @@ declare interface AgoClientEvents {
252
293
  declare interface AgoConfig {
253
294
  /** API base URL (e.g., https://YOUR-DOMAIN.useago.com) */
254
295
  baseUrl: string;
255
- /** Widget ID (X-Widget-Id header). Auto-generated if not provided. */
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 @@ 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;
@@ -345,6 +393,13 @@ export declare interface ChatWidgetHandle {
345
393
  element: HTMLElement;
346
394
  /** Programmatically send a message (same path as the input). */
347
395
  sendMessage: (content: string, files?: File[]) => Promise<void>;
396
+ /**
397
+ * Open / close / toggle the side panel. Present only for
398
+ * `placement: "left" | "right"` (an inline panel is always visible).
399
+ */
400
+ open?: () => void;
401
+ close?: () => void;
402
+ toggle?: () => void;
348
403
  /**
349
404
  * The conversation-persistence session, present only when `persistConversation`
350
405
  * is set — exposes the stable `widgetId` and `session.clear()` to start a new thread.
@@ -520,6 +575,20 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
520
575
  */
521
576
  declare type DynamicContextProvider = () => ContextEntry | null | undefined;
522
577
 
578
+ /**
579
+ * The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
580
+ * {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
581
+ * {@link CreateFormCollectorOptions}: the `submit` here is never the client-only
582
+ * `handler` variant (a function can't be stored server-side).
583
+ */
584
+ declare interface FormCollectorDefinition<V = Record<string, unknown>> {
585
+ name: string;
586
+ description: string;
587
+ schema: FormCollectorSchema;
588
+ /** Server-stored submit target, if any. Absent means collect-only. */
589
+ submit?: SubmitConfig<V>;
590
+ }
591
+
523
592
  /**
524
593
  * Shape of a form's fields. Mirrors a client function's `parameters` (so the same
525
594
  * 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.
@@ -584,6 +653,16 @@ declare interface FormSchema {
584
653
  required?: string[];
585
654
  }
586
655
 
656
+ /**
657
+ * Options for {@link loadFormCollector} / the name-only form of `useFormCollector`:
658
+ * the `name` is required and the definition is fetched from the backend, while any
659
+ * field here overrides the fetched one — notably a client-only `submit` handler,
660
+ * which can't be stored server-side.
661
+ */
662
+ declare interface LoadFormCollectorOptions<V = Record<string, unknown>> extends Partial<Omit<CreateFormCollectorOptions<V>, "name">> {
663
+ name: string;
664
+ }
665
+
587
666
  declare type MessageStatus = "IN_PROGRESS" | "DONE" | "ERROR" | "TODO" | "CANCELED";
588
667
 
589
668
  /**
@@ -646,9 +725,37 @@ export declare interface MountChatWidgetOptions {
646
725
  placeholder?: string;
647
726
  /** Enable file attachments. */
648
727
  allowFiles?: boolean;
649
- /** Widget height (number → px). */
728
+ /** Widget height (number → px). Ignored when `placement` is `"left"`/`"right"`
729
+ * (a side panel is always full-height). */
650
730
  height?: string | number;
651
- /** URL of a logo shown in the header. */
731
+ /**
732
+ * Where the panel renders. `"inline"` (default) mounts it directly into the
733
+ * target element, filling it. `"left"` / `"right"` instead pin a **fixed,
734
+ * full-height side panel** to that edge of the viewport that slides open and
735
+ * closed; the target is only used as the DOM parent (pass `document.body` for
736
+ * a true page overlay). In side mode `height` is ignored and the width comes
737
+ * from {@link MountChatWidgetOptions.width}.
738
+ */
739
+ placement?: "inline" | "left" | "right";
740
+ /**
741
+ * Width of the side panel for `placement: "left" | "right"` (number → px).
742
+ * Capped at the viewport width so it never overflows on mobile. Ignored when
743
+ * `placement` is `"inline"`. Defaults to `400`.
744
+ */
745
+ width?: string | number;
746
+ /**
747
+ * For side placements, render the built-in floating launcher button that opens
748
+ * the panel (plus a close "×" in the header). Set `false` to drive open/close
749
+ * yourself via the handle's `open()`/`close()`/`toggle()`. Ignored when
750
+ * `placement` is `"inline"`. Defaults to `true`.
751
+ */
752
+ launcher?: boolean;
753
+ /**
754
+ * For side placements, whether the panel starts open. Ignored when `placement`
755
+ * is `"inline"` (an inline panel is always visible). Defaults to `false`.
756
+ */
757
+ defaultOpen?: boolean;
758
+ /** URL of a logo shown in the header (and on the launcher button, if shown). */
652
759
  logoUrl?: string;
653
760
  /** Show the agent name above assistant messages. Defaults to `false`. */
654
761
  showAgentName?: boolean;
@@ -665,10 +772,13 @@ export declare interface MountChatWidgetOptions {
665
772
  loadThreads?: boolean;
666
773
  /**
667
774
  * Conversational forms the agent can fill and submit during the chat. Each
668
- * config is installed as a {@link createFormCollector} for the lifetime of the
775
+ * entry is installed as a {@link createFormCollector} for the lifetime of the
669
776
  * widget (removed on `destroy()`).
777
+ *
778
+ * Pass a full config (with `schema`) to define it inline, or just `{ name }` to
779
+ * fetch the definition from the backend ({@link loadFormCollector}).
670
780
  */
671
- forms?: CreateFormCollectorOptions[];
781
+ forms?: Array<CreateFormCollectorOptions | LoadFormCollectorOptions>;
672
782
  /**
673
783
  * How clicking a suggested follow-up reply behaves. Defaults to sending the
674
784
  * reply as a new user message. Pass a handler to override, or `false` to