@artooi/ag-ui-web-component 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +21 -0
  3. package/README.md +471 -0
  4. package/dist/ag-ui-web-component.bundle.js +319 -0
  5. package/dist/ag-ui-web-component.bundle.js.map +7 -0
  6. package/dist/ag_ui_chat.d.ts +85 -0
  7. package/dist/ag_ui_chat.d.ts.map +1 -0
  8. package/dist/agui_client.d.ts +99 -0
  9. package/dist/agui_client.d.ts.map +1 -0
  10. package/dist/animations.d.ts +33 -0
  11. package/dist/animations.d.ts.map +1 -0
  12. package/dist/client_tool_registry.d.ts +32 -0
  13. package/dist/client_tool_registry.d.ts.map +1 -0
  14. package/dist/confirmation_modal.d.ts +14 -0
  15. package/dist/confirmation_modal.d.ts.map +1 -0
  16. package/dist/constants.d.ts +40 -0
  17. package/dist/constants.d.ts.map +1 -0
  18. package/dist/conversation_store.d.ts +54 -0
  19. package/dist/conversation_store.d.ts.map +1 -0
  20. package/dist/create_http_agent.d.ts +22 -0
  21. package/dist/create_http_agent.d.ts.map +1 -0
  22. package/dist/define_ag_ui_chat.d.ts +9 -0
  23. package/dist/define_ag_ui_chat.d.ts.map +1 -0
  24. package/dist/dom_driver.d.ts +24 -0
  25. package/dist/dom_driver.d.ts.map +1 -0
  26. package/dist/index.d.ts +18 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +1159 -0
  29. package/dist/index.js.map +7 -0
  30. package/dist/is_destructive.d.ts +8 -0
  31. package/dist/is_destructive.d.ts.map +1 -0
  32. package/dist/is_navigates.d.ts +9 -0
  33. package/dist/is_navigates.d.ts.map +1 -0
  34. package/dist/page_map.d.ts +16 -0
  35. package/dist/page_map.d.ts.map +1 -0
  36. package/dist/route_map.d.ts +27 -0
  37. package/dist/route_map.d.ts.map +1 -0
  38. package/dist/state_hook.d.ts +23 -0
  39. package/dist/state_hook.d.ts.map +1 -0
  40. package/dist/styles.d.ts +2 -0
  41. package/dist/styles.d.ts.map +1 -0
  42. package/dist/tool_call_card.d.ts +29 -0
  43. package/dist/tool_call_card.d.ts.map +1 -0
  44. package/dist/version.d.ts +2 -0
  45. package/dist/version.d.ts.map +1 -0
  46. package/package.json +79 -0
  47. package/src/ag_ui_chat.ts +411 -0
  48. package/src/agui_client.ts +212 -0
  49. package/src/animations.ts +86 -0
  50. package/src/client_tool_registry.ts +56 -0
  51. package/src/confirmation_modal.ts +69 -0
  52. package/src/constants.ts +48 -0
  53. package/src/conversation_store.ts +103 -0
  54. package/src/create_http_agent.ts +40 -0
  55. package/src/define_ag_ui_chat.ts +15 -0
  56. package/src/dom_driver.ts +60 -0
  57. package/src/index.ts +60 -0
  58. package/src/is_destructive.ts +11 -0
  59. package/src/is_navigates.ts +12 -0
  60. package/src/page_map.ts +25 -0
  61. package/src/route_map.ts +83 -0
  62. package/src/state_hook.ts +44 -0
  63. package/src/styles.ts +296 -0
  64. package/src/tool_call_card.ts +95 -0
  65. package/src/version.ts +1 -0
@@ -0,0 +1,85 @@
1
+ import type { Context, Tool } from "@ag-ui/core";
2
+ import { type ClientTool } from "./client_tool_registry.js";
3
+ import { MESSAGE_ROLE } from "./constants.js";
4
+ import { type ClientConversationStore, type NavigationCheckpoint } from "./conversation_store.js";
5
+ import { type AgentFactory } from "./create_http_agent.js";
6
+ import { type PageMap } from "./page_map.js";
7
+ import { type RouteMap } from "./route_map.js";
8
+ import { type StateHook } from "./state_hook.js";
9
+ /** The role a rendered chat message takes. */
10
+ export type MessageRole = (typeof MESSAGE_ROLE)[keyof typeof MESSAGE_ROLE];
11
+ /** `detail` shape of the {@link SUBMIT_EVENT} CustomEvent. */
12
+ export interface SubmitDetail {
13
+ readonly content: string;
14
+ }
15
+ /**
16
+ * `<ag-ui-chat>` — a framework-free chat sidebar Web Component over AG-UI.
17
+ *
18
+ * Owns the Shadow DOM shell (header, scrolling message list, input row),
19
+ * builds an {@link AgUiClient} on first send (via the overridable
20
+ * {@link agentFactory}), and renders streaming assistant text plus tool-call
21
+ * activity. Emits a {@link SUBMIT_EVENT} for host visibility.
22
+ *
23
+ * The per-run frontend tool catalog and context are supplied by
24
+ * {@link getTools} / {@link getContext}, which later phases (the tool
25
+ * registry, DOM driver) populate.
26
+ */
27
+ export declare class AgUiChat extends HTMLElement {
28
+ #private;
29
+ /** Agent factory; override to inject a custom or fake agent (tests). */
30
+ agentFactory: AgentFactory;
31
+ /** Extra HTTP headers for the AG-UI endpoint (e.g. CSRF). */
32
+ headers: Record<string, string>;
33
+ /** When true, destructive tools execute without a confirmation modal. */
34
+ autoConfirm: boolean;
35
+ /**
36
+ * Per-run frontend tool catalog provider. Defaults to the built-in
37
+ * `route.*` tools (when a {@link routeMap} is set) plus the tools registered
38
+ * via {@link registerTool} / {@link registerStateHook}; override to supply a
39
+ * fully custom catalog.
40
+ */
41
+ getTools: () => Tool[];
42
+ /**
43
+ * Per-run context provider. Defaults to the compact page map (when a
44
+ * {@link getPageMap} provider is set and {@link autoInjectPageMap} is on).
45
+ */
46
+ getContext: () => Context[];
47
+ /**
48
+ * Navigable routes the agent can jump to via the built-in `route.*` tools.
49
+ * A compact summary also rides in each run's context.
50
+ */
51
+ routeMap: RouteMap;
52
+ /**
53
+ * Optional client-side router. When set (an SPA), `navigate_to_route` routes
54
+ * in-page and the run loop continues; when unset (an MPA like the admin), it
55
+ * falls back to `window.location` and the resumable-loop machinery applies.
56
+ */
57
+ navigate: ((path: string) => void) | null;
58
+ /** Provider for the per-run page map; see {@link getContext}. */
59
+ getPageMap: (() => PageMap) | null;
60
+ /** Whether to auto-inject the page map into context each run. */
61
+ autoInjectPageMap: boolean;
62
+ /**
63
+ * Persistence for the conversation + navigation checkpoint. Defaults to
64
+ * per-tab `sessionStorage` so the chat survives full page reloads; inject a
65
+ * server-backed store for cross-tab/device durability.
66
+ */
67
+ conversationStore: ClientConversationStore;
68
+ /**
69
+ * Builds the tool result a navigating tool resumes with after the page
70
+ * reloads. Defaults to the landed URL; a host (e.g. the admin package) can
71
+ * override to include a page snapshot or post-reload validation errors.
72
+ */
73
+ navigationResult: (checkpoint: NavigationCheckpoint) => unknown;
74
+ constructor();
75
+ /** Declare a frontend tool the agent may call. */
76
+ registerTool(tool: ClientTool): void;
77
+ /** Bind a piece of host state to `read_<name>` / `set_<name>` tools. */
78
+ registerStateHook(hook: StateHook): void;
79
+ /** The AG-UI endpoint URL, read from the `endpoint` attribute. */
80
+ get endpoint(): string;
81
+ connectedCallback(): void;
82
+ /** Append a message bubble and return it. */
83
+ appendMessage(role: MessageRole, content: string): HTMLDivElement;
84
+ }
85
+ //# sourceMappingURL=ag_ui_chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ag_ui_chat.d.ts","sourceRoot":"","sources":["../src/ag_ui_chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,MAAM,aAAa,CAAC;AAO1D,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,2BAA2B,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAkC,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAE1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,YAAY,EAAmB,MAAM,wBAAwB,CAAC;AAG5E,OAAO,EAAwB,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIvE,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE3E,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,QAAS,SAAQ,WAAW;;IACvC,wEAAwE;IACxE,YAAY,EAAE,YAAY,CAAmB;IAE7C,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAErC,yEAAyE;IACzE,WAAW,UAAS;IAEpB;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,IAAI,EAAE,CAOpB;IAEF;;;OAGG;IACH,UAAU,EAAE,MAAM,OAAO,EAAE,CAAuE;IAElG;;;OAGG;IACH,QAAQ,EAAE,QAAQ,CAAM;IAExB;;;;OAIG;IACH,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAAI,CAAQ;IAEjD,iEAAiE;IACjE,UAAU,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG,IAAI,CAAQ;IAE1C,iEAAiE;IACjE,iBAAiB,UAAQ;IAEzB;;;;OAIG;IACH,iBAAiB,EAAE,uBAAuB,CAA6B;IAEvE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,UAAU,EAAE,oBAAoB,KAAK,OAAO,CAG5D;;IAyBH,kDAAkD;IAClD,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAIpC,wEAAwE;IACxE,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IA0BxC,kEAAkE;IAClE,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,iBAAiB,IAAI,IAAI;IA6CzB,6CAA6C;IAC7C,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc;CAiMlE"}
@@ -0,0 +1,99 @@
1
+ import { type AbstractAgent } from "@ag-ui/client";
2
+ import type { Context, Message, Tool } from "@ag-ui/core";
3
+ /** A tool call surfaced to the host by {@link AgUiClient}. */
4
+ export interface AgUiToolCall {
5
+ readonly id: string;
6
+ readonly name: string;
7
+ readonly args: Record<string, unknown>;
8
+ }
9
+ /** The result of executing a frontend tool, destined for a tool-result message. */
10
+ export interface ToolExecution {
11
+ /** String content for the AG-UI tool-result message. */
12
+ content: string;
13
+ /** Present when the handler failed; surfaced for logging. */
14
+ error?: string;
15
+ /**
16
+ * When `true`, a navigating tool triggered a page reload. The loop stops
17
+ * without appending a result — the result is supplied after the next mount
18
+ * (see the resume path). Mutually exclusive with a usable `content`.
19
+ */
20
+ halt?: boolean;
21
+ }
22
+ /**
23
+ * Executes a frontend tool call.
24
+ *
25
+ * Returns the {@link ToolExecution} to post back to the agent, or ``null`` when
26
+ * the call is not a frontend tool the host owns (a server-side tool the server
27
+ * already executed — the client must not re-run for it).
28
+ */
29
+ export type ExecuteTool = (call: AgUiToolCall) => Promise<ToolExecution | null>;
30
+ /**
31
+ * Callbacks the {@link AgUiClient} invokes as a run progresses. The host
32
+ * (the `<ag-ui-chat>` element) implements these to render streaming text and
33
+ * tool activity into the chat.
34
+ */
35
+ export interface AgUiClientHandlers {
36
+ onRunStart(): void;
37
+ /** Fired on every streamed token; ``buffer`` is the full text so far. */
38
+ onTextDelta(buffer: string): void;
39
+ /** Fired when the assistant message completes; ``buffer`` is the final text. */
40
+ onTextEnd(buffer: string): void;
41
+ /** Fired when the agent finishes calling a tool (server- or frontend-side). */
42
+ onToolCall(call: AgUiToolCall): void;
43
+ onRunEnd(): void;
44
+ onError(message: string): void;
45
+ }
46
+ /**
47
+ * Provider of the per-run frontend tool catalog and context. Both are read
48
+ * fresh on every {@link AgUiClient.send} so the catalog reflects the current
49
+ * page state.
50
+ */
51
+ export interface AgUiRunInputs {
52
+ getTools?: () => Tool[];
53
+ getContext?: () => Context[];
54
+ }
55
+ export interface AgUiClientConfig extends AgUiRunInputs {
56
+ /** The AG-UI agent to drive. Injected so it can be faked in tests. */
57
+ agent: AbstractAgent;
58
+ handlers: AgUiClientHandlers;
59
+ /** Executes frontend tool calls. Omit for server-only tool sets. */
60
+ executeTool?: ExecuteTool;
61
+ /**
62
+ * Invoked with the latest history whenever it changes, so the host can
63
+ * persist it for durability across page reloads. Omit to keep the
64
+ * conversation in-memory only.
65
+ */
66
+ onPersist?: (messages: readonly Message[]) => void;
67
+ }
68
+ /**
69
+ * Thin orchestration layer over an AG-UI {@link AbstractAgent}.
70
+ *
71
+ * Translates AG-UI's subscriber callbacks into the host's
72
+ * {@link AgUiClientHandlers}, and appends the user message + current frontend
73
+ * tool catalog + context to each run.
74
+ */
75
+ export declare class AgUiClient {
76
+ #private;
77
+ constructor(config: AgUiClientConfig);
78
+ /** Whether a run is currently in flight. */
79
+ get running(): boolean;
80
+ /** The current conversation history (for persistence / rehydration). */
81
+ get messages(): readonly Message[];
82
+ /**
83
+ * Append a user message and run the agent to completion.
84
+ *
85
+ * When the agent calls frontend tools, this executes them and re-runs the
86
+ * agent with the results, looping until the agent stops calling frontend
87
+ * tools (bounded by {@link MAX_TOOL_ROUNDS}).
88
+ */
89
+ send(content: string): Promise<void>;
90
+ /**
91
+ * Resume the run loop after a navigating tool's result was supplied
92
+ * post-reload (via {@link addToolResult}). Unlike {@link send}, adds no user
93
+ * message — it simply continues the conversation already in history.
94
+ */
95
+ resume(): Promise<void>;
96
+ /** Append a frontend tool result to history (used by the resume path). */
97
+ addToolResult(toolCallId: string, content: string): void;
98
+ }
99
+ //# sourceMappingURL=agui_client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agui_client.d.ts","sourceRoot":"","sources":["../src/agui_client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAoC,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAG1D,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAA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wEAAwE;IACxE,IAAI,QAAQ,IAAI,SAAS,OAAO,EAAE,CAEjC;IAED;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,0EAA0E;IAC1E,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;CA+EzD"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Visible-action animation primitives.
3
+ *
4
+ * These run against the **host page** DOM (not the element's shadow root) so a
5
+ * user watches the agent type, highlight, and click at human-readable speed.
6
+ * Each is configurable; pass small/zero durations in tests (or use fake timers).
7
+ */
8
+ /** An element whose `value` can be typed into. */
9
+ export type TextLikeElement = HTMLInputElement | HTMLTextAreaElement;
10
+ export interface TypeOptions {
11
+ /** Milliseconds between characters. Default 35. */
12
+ charDelayMs?: number;
13
+ }
14
+ /**
15
+ * Clear ``el`` and type ``value`` one character at a time, firing ``input``
16
+ * events as a real user would, then a final ``change`` event.
17
+ */
18
+ export declare function typeInto(el: TextLikeElement, value: string, options?: TypeOptions): Promise<void>;
19
+ export interface HighlightClickOptions {
20
+ /** Milliseconds to hold the highlight before clicking. Default 280. */
21
+ highlightMs?: number;
22
+ }
23
+ /** Outline ``el``, pause so the user sees it, then click and restore. */
24
+ export declare function highlightThenClick(el: HTMLElement, options?: HighlightClickOptions): Promise<void>;
25
+ /** Scroll ``el`` to the vertical centre of the viewport. */
26
+ export declare function scrollIntoCenterView(el: HTMLElement): void;
27
+ export interface FlashOptions {
28
+ /** Milliseconds to hold the focus flash. Default 200. */
29
+ flashMs?: number;
30
+ }
31
+ /** Focus ``el`` and briefly flash a ring around it. */
32
+ export declare function focusWithFlash(el: HTMLElement, options?: FlashOptions): Promise<void>;
33
+ //# sourceMappingURL=animations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animations.d.ts","sourceRoot":"","sources":["../src/animations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,kDAAkD;AAClD,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;AAErE,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAC5B,EAAE,EAAE,eAAe,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,IAAI,CAAC,CAYf;AAED,MAAM,WAAW,qBAAqB;IACpC,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,yEAAyE;AACzE,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,WAAW,EACf,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,4DAA4D;AAC5D,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,CAE1D;AAED,MAAM,WAAW,YAAY;IAC3B,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,uDAAuD;AACvD,wBAAsB,cAAc,CAAC,EAAE,EAAE,WAAW,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAO/F"}
@@ -0,0 +1,32 @@
1
+ import type { Tool } from "@ag-ui/core";
2
+ /**
3
+ * A tool the frontend declares and executes itself.
4
+ *
5
+ * `parameters` is a JSON Schema (and may carry the `x-destructive` extension).
6
+ * `handler` receives the parsed arguments and returns a result that is
7
+ * JSON-serialised into the AG-UI tool-result message sent back to the agent.
8
+ */
9
+ export interface ClientTool {
10
+ name: string;
11
+ description: string;
12
+ parameters: Record<string, unknown>;
13
+ handler: (args: Record<string, unknown>) => unknown | Promise<unknown>;
14
+ }
15
+ /**
16
+ * Holds the frontend tools a host has declared on an `<ag-ui-chat>` element.
17
+ *
18
+ * Produces AG-UI {@link Tool} definitions for `RunAgentInput.tools` and looks
19
+ * up handlers when the agent calls a tool. Pure (no DOM); the element owns one
20
+ * instance.
21
+ */
22
+ export declare class ClientToolRegistry {
23
+ #private;
24
+ /** Register a tool. Throws if the name is already taken. */
25
+ register(tool: ClientTool): void;
26
+ has(name: string): boolean;
27
+ /** Return a registered tool or throw. */
28
+ get(name: string): ClientTool;
29
+ /** AG-UI tool definitions for `RunAgentInput.tools`. */
30
+ tools(): Tool[];
31
+ }
32
+ //# sourceMappingURL=client_tool_registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client_tool_registry.d.ts","sourceRoot":"","sources":["../src/client_tool_registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxE;AAED;;;;;;GAMG;AACH,qBAAa,kBAAkB;;IAG7B,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAOhC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,yCAAyC;IACzC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAQ7B,wDAAwD;IACxD,KAAK,IAAI,IAAI,EAAE;CAOhB"}
@@ -0,0 +1,14 @@
1
+ /** What the confirmation modal displays. */
2
+ export interface ConfirmationRequest {
3
+ toolName: string;
4
+ args: Record<string, unknown>;
5
+ }
6
+ /**
7
+ * Render a confirmation modal into ``host`` and resolve when the user decides.
8
+ *
9
+ * Resolves ``true`` if the user confirms, ``false`` if they cancel or dismiss
10
+ * via the backdrop. The modal is appended to ``host`` (the chat container
11
+ * inside the element's shadow root) and removed once resolved.
12
+ */
13
+ export declare function requestConfirmation(host: Node & ParentNode, request: ConfirmationRequest): Promise<boolean>;
14
+ //# sourceMappingURL=confirmation_modal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmation_modal.d.ts","sourceRoot":"","sources":["../src/confirmation_modal.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,GAAG,UAAU,EACvB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,OAAO,CAAC,CAoDlB"}
@@ -0,0 +1,40 @@
1
+ /** The Custom Element tag name registered by {@link defineAgUiChat}. */
2
+ export declare const ELEMENT_TAG = "ag-ui-chat";
3
+ /**
4
+ * Event dispatched by `<ag-ui-chat>` when the user submits a message.
5
+ * `detail` carries `{ content: string }`. Later phases wire this to the
6
+ * AG-UI client; for now it is the public seam for host integration.
7
+ */
8
+ export declare const SUBMIT_EVENT = "ag-ui-submit";
9
+ /** Roles a chat message can take. */
10
+ export declare const MESSAGE_ROLE: {
11
+ readonly USER: "user";
12
+ readonly ASSISTANT: "assistant";
13
+ };
14
+ /**
15
+ * JSON-Schema extension key marking a tool as destructive. Mirrors the
16
+ * `django-ag-ui` server side. When a tool's `parameters` carries
17
+ * `{ "x-destructive": true }`, the element gates its execution behind the
18
+ * confirmation modal (unless `autoConfirm` is set).
19
+ */
20
+ export declare const X_DESTRUCTIVE_KEY = "x-destructive";
21
+ /**
22
+ * JSON-Schema extension key marking a tool as navigating — its handler triggers
23
+ * a full page reload (an MPA navigation). When a tool's `parameters` carries
24
+ * `{ "x-navigates": true }`, the element checkpoints the call before the reload
25
+ * and resumes the run loop once the next page mounts. Mirrors `x-destructive`.
26
+ */
27
+ export declare const X_NAVIGATES_KEY = "x-navigates";
28
+ /** Upper bound on frontend tool-call → re-run rounds within one send. */
29
+ export declare const MAX_TOOL_ROUNDS = 10;
30
+ /**
31
+ * Lifecycle status of a rendered tool-call card. A card opens as `PENDING`
32
+ * while the call runs, then settles to `DONE`, `ERROR`, or `DECLINED`.
33
+ */
34
+ export declare const TOOL_CALL_STATUS: {
35
+ readonly PENDING: "pending";
36
+ readonly DONE: "done";
37
+ readonly ERROR: "error";
38
+ readonly DECLINED: "declined";
39
+ };
40
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,wEAAwE;AACxE,eAAO,MAAM,WAAW,eAAe,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C,qCAAqC;AACrC,eAAO,MAAM,YAAY;;;CAGf,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C,yEAAyE;AACzE,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;CAKnB,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { Message } from "@ag-ui/core";
2
+ /**
3
+ * A checkpoint recorded just before a navigating tool reloads the page.
4
+ *
5
+ * The reload destroys the in-memory run loop, so the element persists this
6
+ * marker first; on the next mount it supplies the tool's result and resumes.
7
+ */
8
+ export interface NavigationCheckpoint {
9
+ /** The tool-call id whose result must be supplied after the reload. */
10
+ readonly toolCallId: string;
11
+ }
12
+ /**
13
+ * Client-side persistence seam for the conversation and a pending-navigation
14
+ * checkpoint, keyed by `thread_id`.
15
+ *
16
+ * The default {@link SessionStorageStore} keeps everything per-tab in
17
+ * `sessionStorage`, so the chat survives the full page reloads of a
18
+ * multi-page app. A host may inject a server-backed store instead (e.g. one
19
+ * that rehydrates from a history endpoint); `loadMessages` is therefore
20
+ * async-friendly. The checkpoint methods stay synchronous — the marker is a
21
+ * tiny local hint a server store can derive from history and no-op.
22
+ */
23
+ export interface ClientConversationStore {
24
+ /** A stable conversation id, generated and persisted on first read. */
25
+ threadId(): string;
26
+ /** Load the persisted message history, or `null` when none exists. */
27
+ loadMessages(threadId: string): Promise<readonly Message[] | null>;
28
+ /** Persist the message history. */
29
+ saveMessages(threadId: string, messages: readonly Message[]): void;
30
+ /** Load the pending-navigation checkpoint, or `null` when none is set. */
31
+ loadCheckpoint(threadId: string): NavigationCheckpoint | null;
32
+ /** Set the pending-navigation checkpoint, or clear it when given `null`. */
33
+ saveCheckpoint(threadId: string, checkpoint: NavigationCheckpoint | null): void;
34
+ /** Forget the conversation and checkpoint (e.g. a "new chat" action). */
35
+ clear(threadId: string): void;
36
+ }
37
+ /**
38
+ * Default {@link ClientConversationStore}: per-tab `sessionStorage`.
39
+ *
40
+ * Survives full page reloads and same-tab navigation, clears on tab close —
41
+ * the right scope for an embedded agent's conversation in a multi-page app.
42
+ * One thread id per tab; the message history and checkpoint are namespaced by
43
+ * it so two tabs hold independent conversations.
44
+ */
45
+ export declare class SessionStorageStore implements ClientConversationStore {
46
+ #private;
47
+ threadId(): string;
48
+ loadMessages(threadId: string): Promise<readonly Message[] | null>;
49
+ saveMessages(threadId: string, messages: readonly Message[]): void;
50
+ loadCheckpoint(threadId: string): NavigationCheckpoint | null;
51
+ saveCheckpoint(threadId: string, checkpoint: NavigationCheckpoint | null): void;
52
+ clear(threadId: string): void;
53
+ }
54
+ //# sourceMappingURL=conversation_store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation_store.d.ts","sourceRoot":"","sources":["../src/conversation_store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,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
2
+ import type { Message } from "@ag-ui/core";
3
+ /** Config for {@link createHttpAgent}. */
4
+ export interface HttpAgentOptions {
5
+ endpoint: string;
6
+ headers?: Record<string, string>;
7
+ /** Stable conversation id, so the agent's runs share a thread. */
8
+ threadId?: string;
9
+ /** Rehydrated history to seed the agent with (durable conversation). */
10
+ initialMessages?: readonly Message[];
11
+ }
12
+ /**
13
+ * Build an AG-UI {@link HttpAgent} pointed at ``endpoint``.
14
+ *
15
+ * This is the default agent factory used by ``<ag-ui-chat>``. Tests and
16
+ * advanced hosts override the element's ``agentFactory`` to inject a
17
+ * different {@link AbstractAgent} (e.g. a fake, or a middleware-wrapped one).
18
+ */
19
+ export declare function createHttpAgent(options: HttpAgentOptions): AbstractAgent;
20
+ /** Signature of the agent factory the element calls to build its agent. */
21
+ export type AgentFactory = (options: HttpAgentOptions) => AbstractAgent;
22
+ //# sourceMappingURL=create_http_agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_http_agent.d.ts","sourceRoot":"","sources":["../src/create_http_agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAa,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,eAAe,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CACtC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAgBxE;AAED,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,gBAAgB,KAAK,aAAa,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Register the `<ag-ui-chat>` Custom Element.
3
+ *
4
+ * Idempotent: calling it more than once (or after another module already
5
+ * registered the tag) is a no-op. Registration is an explicit step rather
6
+ * than an import side effect so the package is SSR-safe and tree-shakeable.
7
+ */
8
+ export declare function defineAgUiChat(): void;
9
+ //# sourceMappingURL=define_ag_ui_chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define_ag_ui_chat.d.ts","sourceRoot":"","sources":["../src/define_ag_ui_chat.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAIrC"}
@@ -0,0 +1,24 @@
1
+ import { type HighlightClickOptions, type TextLikeElement, type TypeOptions } from "./animations.js";
2
+ /**
3
+ * Generic, framework-free DOM-driving primitives.
4
+ *
5
+ * Each operates on an element the caller has already located. Host packages
6
+ * (e.g. `django-admin-agent`) wrap these with environment-aware lookups —
7
+ * `fill_field(name, value)` finds `#id_<name>` then calls {@link fillField}.
8
+ */
9
+ export interface FillFieldOptions extends TypeOptions, FlashOptionsLike {
10
+ }
11
+ interface FlashOptionsLike {
12
+ flashMs?: number;
13
+ }
14
+ /** Scroll to, focus (with a flash), and type ``value`` into a text field. */
15
+ export declare function fillField(el: TextLikeElement, value: string, options?: FillFieldOptions): Promise<void>;
16
+ /** Scroll to, highlight, and click an element. */
17
+ export declare function clickElement(el: HTMLElement, options?: HighlightClickOptions): Promise<void>;
18
+ /**
19
+ * Set a `<select>` or checkbox value without typing animation, dispatching the
20
+ * ``input`` and ``change`` events frameworks listen for.
21
+ */
22
+ export declare function setControlValue(el: HTMLInputElement | HTMLSelectElement, value: string | boolean): void;
23
+ export {};
24
+ //# sourceMappingURL=dom_driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom_driver.d.ts","sourceRoot":"","sources":["../src/dom_driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,qBAAqB,EAG1B,KAAK,eAAe,EACpB,KAAK,WAAW,EAEjB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;GAMG;AAEH,MAAM,WAAW,gBAAiB,SAAQ,WAAW,EAAE,gBAAgB;CAAG;AAE1E,UAAU,gBAAgB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,6EAA6E;AAC7E,wBAAsB,SAAS,CAC7B,EAAE,EAAE,eAAe,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,kDAAkD;AAClD,wBAAsB,YAAY,CAChC,EAAE,EAAE,WAAW,EACf,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAGf;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,gBAAgB,GAAG,iBAAiB,EACxC,KAAK,EAAE,MAAM,GAAG,OAAO,GACtB,IAAI,CAQN"}
@@ -0,0 +1,18 @@
1
+ export { AgUiChat, type MessageRole, type SubmitDetail } from "./ag_ui_chat.js";
2
+ export { AgUiClient, type AgUiClientConfig, type AgUiClientHandlers, type AgUiRunInputs, type AgUiToolCall, type ExecuteTool, type ToolExecution, } from "./agui_client.js";
3
+ export { type FlashOptions, focusWithFlash, type HighlightClickOptions, highlightThenClick, scrollIntoCenterView, type TextLikeElement, type TypeOptions, typeInto, } from "./animations.js";
4
+ export { type ClientTool, ClientToolRegistry } from "./client_tool_registry.js";
5
+ export { type ConfirmationRequest, requestConfirmation } from "./confirmation_modal.js";
6
+ export { ELEMENT_TAG, MAX_TOOL_ROUNDS, MESSAGE_ROLE, SUBMIT_EVENT, TOOL_CALL_STATUS, X_DESTRUCTIVE_KEY, X_NAVIGATES_KEY, } from "./constants.js";
7
+ export { type ClientConversationStore, type NavigationCheckpoint, SessionStorageStore, } from "./conversation_store.js";
8
+ export { type AgentFactory, createHttpAgent, type HttpAgentOptions, } from "./create_http_agent.js";
9
+ export { defineAgUiChat } from "./define_ag_ui_chat.js";
10
+ export { clickElement, type FillFieldOptions, fillField, setControlValue, } from "./dom_driver.js";
11
+ export { isDestructive } from "./is_destructive.js";
12
+ export { isNavigates } from "./is_navigates.js";
13
+ export { createPageMapContext, type PageMap } from "./page_map.js";
14
+ export { createRouteTools, type Route, type RouteMap } from "./route_map.js";
15
+ export { createStateHookTools, type StateHook } from "./state_hook.js";
16
+ export { type SettledStatus, ToolCallCard, type ToolCallStatus, } from "./tool_call_card.js";
17
+ export { VERSION } from "./version.js";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EACL,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,aAAa,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,YAAY,EACjB,cAAc,EACd,KAAK,qBAAqB,EAC1B,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,QAAQ,GACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,UAAU,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,KAAK,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACxF,OAAO,EACL,WAAW,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,YAAY,EACjB,eAAe,EACf,KA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