@zeke-02/docx-editor-agents 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 (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +126 -0
  3. package/dist/agent-types-C8RvQB7n.d.mts +36 -0
  4. package/dist/agent-types-C8RvQB7n.d.ts +36 -0
  5. package/dist/ai-sdk/react.d.mts +57 -0
  6. package/dist/ai-sdk/react.d.ts +57 -0
  7. package/dist/ai-sdk/react.js +1 -0
  8. package/dist/ai-sdk/react.mjs +1 -0
  9. package/dist/ai-sdk/server.d.mts +80 -0
  10. package/dist/ai-sdk/server.d.ts +80 -0
  11. package/dist/ai-sdk/server.js +1 -0
  12. package/dist/ai-sdk/server.mjs +1 -0
  13. package/dist/ai-sdk/vue.d.ts +32 -0
  14. package/dist/ai-sdk/vue.js +1 -0
  15. package/dist/ai-sdk/vue.mjs +28 -0
  16. package/dist/bridge.d.mts +19 -0
  17. package/dist/bridge.d.ts +19 -0
  18. package/dist/bridge.js +1 -0
  19. package/dist/bridge.mjs +1 -0
  20. package/dist/chunk-24MVJKCP.mjs +8 -0
  21. package/dist/chunk-2RGRAPLW.js +5 -0
  22. package/dist/chunk-53PAUP4S.js +2 -0
  23. package/dist/chunk-AU3KR5IN.mjs +5 -0
  24. package/dist/chunk-KMEZXSKR.mjs +2 -0
  25. package/dist/chunk-RI5S75JY.js +8 -0
  26. package/dist/chunk-UNUH3LRU.mjs +1 -0
  27. package/dist/chunk-VXAJD6QK.js +1 -0
  28. package/dist/docx-editor-agents.css +2 -0
  29. package/dist/index.d.mts +178 -0
  30. package/dist/index.d.ts +178 -0
  31. package/dist/index.js +1 -0
  32. package/dist/index.mjs +1 -0
  33. package/dist/mcp.d.mts +200 -0
  34. package/dist/mcp.d.ts +200 -0
  35. package/dist/mcp.js +4 -0
  36. package/dist/mcp.mjs +4 -0
  37. package/dist/react.d.mts +251 -0
  38. package/dist/react.d.ts +251 -0
  39. package/dist/react.js +9 -0
  40. package/dist/react.mjs +9 -0
  41. package/dist/server-uWvnaIh-.d.mts +620 -0
  42. package/dist/server-uWvnaIh-.d.ts +620 -0
  43. package/dist/server.d.mts +35 -0
  44. package/dist/server.d.ts +35 -0
  45. package/dist/server.js +1 -0
  46. package/dist/server.mjs +1 -0
  47. package/dist/vue/components/AIContextMenu.d.ts +33 -0
  48. package/dist/vue/components/AIResponsePreview.d.ts +40 -0
  49. package/dist/vue/components/AgentChatLog.d.ts +37 -0
  50. package/dist/vue/components/AgentComposer.d.ts +30 -0
  51. package/dist/vue/components/AgentPanel.d.ts +49 -0
  52. package/dist/vue/components/AgentSuggestionChip.d.ts +10 -0
  53. package/dist/vue/components/AgentTimeline.d.ts +19 -0
  54. package/dist/vue/composables/useAgentBridge.d.ts +19 -0
  55. package/dist/vue/types.d.ts +5 -0
  56. package/dist/vue.d.ts +72 -0
  57. package/dist/vue.js +20 -0
  58. package/dist/vue.mjs +2026 -0
  59. package/package.json +157 -0
@@ -0,0 +1,251 @@
1
+ /**
2
+ * @zeke-02/docx-editor-agents/react
3
+ *
4
+ * React entry. Hooks, components, and types that need React as a peer
5
+ * dependency. Pair with `/server` (or `/ai-sdk/server`) for the API route
6
+ * that drives the LLM.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { useDocxAgentTools } from '@zeke-02/docx-editor-agents/react';
11
+ *
12
+ * const { tools, executeToolCall, getContext } = useDocxAgentTools({
13
+ * editorRef,
14
+ * author: 'Assistant',
15
+ * });
16
+ * ```
17
+ *
18
+ * @packageDocumentation
19
+ * @public
20
+ */
21
+ import { r as EditorRefLike, k as AgentToolResult, q as getToolSchemas, j as AgentToolDefinition, s as AgentContextSnapshot } from './server-uWvnaIh-.mjs';
22
+ export { t as getToolDisplayName } from './server-uWvnaIh-.mjs';
23
+ import * as react_jsx_runtime from 'react/jsx-runtime';
24
+ import { ReactNode, CSSProperties } from 'react';
25
+ import { A as AgentMessage, a as AgentToolCall } from './agent-types-C8RvQB7n.mjs';
26
+ import '@zeke-02/docx-editor-core/headless';
27
+
28
+ /**
29
+ * useAgentChat — React hook that wires agent tools to a live DocxEditor.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * import { useAgentChat } from '@zeke-02/docx-editor-agents/react';
34
+ *
35
+ * const { executeToolCall, toolSchemas } = useAgentChat({ editorRef, author: 'Assistant' });
36
+ *
37
+ * // Pass toolSchemas to your AI provider, execute tool calls on the client
38
+ * const result = executeToolCall('add_comment', { paragraphIndex: 3, text: 'Fix this.' });
39
+ * ```
40
+ */
41
+
42
+ interface UseAgentChatOptions {
43
+ /** Reference to the DocxEditor (must match EditorRefLike interface). */
44
+ editorRef: React.RefObject<EditorRefLike | null>;
45
+ /** Default author name for comments and changes. Default: 'AI' */
46
+ author?: string;
47
+ }
48
+ interface UseAgentChatReturn {
49
+ /** Execute a tool call through the bridge. */
50
+ executeToolCall: (toolName: string, input: Record<string, unknown>) => AgentToolResult;
51
+ /** Tool schemas in OpenAI function calling format. Pass to your AI provider. */
52
+ toolSchemas: ReturnType<typeof getToolSchemas>;
53
+ }
54
+ /**
55
+ * Hook that creates an EditorBridge and provides tool execution.
56
+ */
57
+ declare function useAgentChat(options: UseAgentChatOptions): UseAgentChatReturn;
58
+
59
+ /**
60
+ * useDocxAgentTools — wires the toolkit to a live DocxEditor for BYO chat
61
+ * frameworks.
62
+ *
63
+ * Returns three things consumers need to plug an agent into the editor:
64
+ *
65
+ * - `tools` — schemas in OpenAI function-calling format. Pass to `streamText({ tools })`,
66
+ * OpenAI's `tools` field, Anthropic's `tools`, or any provider that accepts
67
+ * that shape.
68
+ * - `executeToolCall` — the executor. Hand to AI SDK's `onToolCall`, or call
69
+ * yourself when you wire up tool calls manually.
70
+ * - `getContext` — snapshot of `{selection, currentPage, paragraphCount}` for
71
+ * system-prompt injection. Pass through `prepareRequestBody` (AI SDK) or
72
+ * inline into your own request body so the agent always knows what the
73
+ * user is looking at without an extra tool round-trip.
74
+ *
75
+ * Custom tools merge with the built-ins via the `tools` option. Names collide
76
+ * → consumer wins (your override replaces the built-in by name).
77
+ *
78
+ * @example
79
+ * ```tsx
80
+ * const { tools, executeToolCall, getContext } = useDocxAgentTools({
81
+ * editorRef,
82
+ * author: 'Assistant',
83
+ * tools: {
84
+ * fetch_clause: {
85
+ * name: 'fetch_clause',
86
+ * description: 'Fetch a clause template by name.',
87
+ * inputSchema: { type: 'object', properties: { name: { type: 'string' } } },
88
+ * handler: async (input) => ({ success: true, data: await fetchTemplate(input.name) }),
89
+ * },
90
+ * },
91
+ * });
92
+ * ```
93
+ */
94
+
95
+ interface UseDocxAgentToolsOptions {
96
+ /** Reference to the DocxEditor (must match EditorRefLike). */
97
+ editorRef: React.RefObject<EditorRefLike | null>;
98
+ /** Default author name for comments / tracked changes. Default: 'AI'. */
99
+ author?: string;
100
+ /**
101
+ * Optional consumer-defined tools to merge with the built-ins. Keyed by
102
+ * tool name. A tool with the same name as a built-in **replaces** it.
103
+ * Pass a stable reference (memoized or module-level) to avoid rebuilding
104
+ * the tool list on every render.
105
+ */
106
+ tools?: Record<string, AgentToolDefinition<any>>;
107
+ /**
108
+ * Allow-list of built-in tool names to expose. When provided, only the
109
+ * named tools are returned (custom tools from `tools` always pass).
110
+ * Useful for read-only or scope-restricted agents:
111
+ *
112
+ * @example include: ['read_document', 'find_text', 'add_comment']
113
+ */
114
+ include?: readonly string[];
115
+ /**
116
+ * Block-list of built-in tool names to hide. Applied after `include`.
117
+ * Use for agents that should not write tracked changes:
118
+ *
119
+ * @example exclude: ['suggest_change', 'apply_formatting', 'set_paragraph_style']
120
+ */
121
+ exclude?: readonly string[];
122
+ }
123
+ interface UseDocxAgentToolsReturn {
124
+ /** Tool schemas in OpenAI function calling format — pass to your AI provider. */
125
+ tools: ReturnType<typeof getToolSchemas>;
126
+ /** Execute a tool call by name. Pass to AI SDK's `onToolCall`. */
127
+ executeToolCall: (name: string, args: Record<string, unknown>) => AgentToolResult;
128
+ /** Snapshot of the user's current view for system-prompt injection. */
129
+ getContext: () => AgentContextSnapshot;
130
+ }
131
+ declare function useDocxAgentTools(options: UseDocxAgentToolsOptions): UseDocxAgentToolsReturn;
132
+
133
+ interface AgentPanelProps {
134
+ /** Header title. Defaults to `'Assistant'`. Pass a localised string for i18n. */
135
+ title?: string;
136
+ /** Header icon node. Defaults to a sparkle SVG. */
137
+ icon?: ReactNode;
138
+ /** Close button aria-label. Defaults to `'Close panel'`. */
139
+ closeLabel?: string;
140
+ /** Resize handle aria-label. Defaults to `'Resize agent panel'`. */
141
+ resizeHandleLabel?: string;
142
+ /** Controlled width in pixels. Omit for uncontrolled (internal state + localStorage). */
143
+ width?: number;
144
+ /** Default width when uncontrolled. */
145
+ defaultWidth?: number;
146
+ /** Min drag width. */
147
+ minWidth?: number;
148
+ /** Max drag width. */
149
+ maxWidth?: number;
150
+ /** Width change callback (drag end and intermediate). */
151
+ onWidthChange?: (w: number) => void;
152
+ /** Header close button click. Omit to hide the close button. */
153
+ onClose?: () => void;
154
+ /** Panel content. Render whatever you want — a chat, tabs, settings, anything. */
155
+ children: ReactNode;
156
+ /** Optional class on the outer wrapper. */
157
+ className?: string;
158
+ /**
159
+ * When `true`, the panel collapses to zero width with an ease-out
160
+ * transition (the children are still mounted so chat state survives
161
+ * close/reopen). The DocxEditor wrapper passes this when the user
162
+ * toggles the panel — kept off by default for standalone usage.
163
+ */
164
+ closed?: boolean;
165
+ }
166
+ declare function AgentPanel({ title, icon, closeLabel, resizeHandleLabel, width: controlledWidth, defaultWidth, minWidth, maxWidth, onWidthChange, onClose, children, className, closed, }: AgentPanelProps): react_jsx_runtime.JSX.Element;
167
+
168
+ interface AgentChatLogProps {
169
+ messages: AgentMessage[];
170
+ /** Render thinking dots at the bottom of the list. */
171
+ loading?: boolean;
172
+ /** Render an error bubble after the last message. */
173
+ error?: string | null;
174
+ /** Shown when there are no messages and not loading. */
175
+ emptyState?: ReactNode;
176
+ /** "Assistant is thinking" aria-label. Default English. */
177
+ thinkingLabel?: string;
178
+ /** "Working… N steps" — pass for i18n. Default English. */
179
+ workingLabel?: (count: number) => string;
180
+ /** "N steps" — pass for i18n. Default English. */
181
+ summaryLabel?: (count: number) => string;
182
+ /** "+ N earlier steps" — pass for i18n. Default English. */
183
+ earlierLabel?: (count: number) => string;
184
+ /** Auto-scroll to bottom on new messages / loading toggles. Default: true. */
185
+ autoScroll?: boolean;
186
+ /**
187
+ * Map a tool name to a friendly label for the per-message timeline.
188
+ * Pass `getToolDisplayName` from `@zeke-02/docx-editor-agents/react` to
189
+ * use the toolkit's registry-aware labels (e.g. "Adding comment").
190
+ */
191
+ humanizeToolName?: (name: string) => string;
192
+ /** Cap the tool-call timeline to this many recent rows. Default 3. */
193
+ maxVisibleCalls?: number;
194
+ className?: string;
195
+ style?: CSSProperties;
196
+ }
197
+ interface AgentTimelineProps {
198
+ /** Tool calls in chronological order. */
199
+ toolCalls: AgentToolCall[];
200
+ /**
201
+ * Whether the parent assistant turn is still streaming. While true, the
202
+ * timeline is forced expanded and shows a spinner; on false it
203
+ * auto-collapses to an "N steps" summary unless the user expanded it.
204
+ */
205
+ streaming?: boolean;
206
+ /**
207
+ * Cap the number of rendered call rows — older entries collapse into a
208
+ * "+N earlier steps" header. Default 3.
209
+ */
210
+ maxVisibleCalls?: number;
211
+ /**
212
+ * Map a tool name to a friendly label. Defaults to a sentence-case
213
+ * conversion of the snake_case name. Pass `getToolDisplayName` from
214
+ * `@zeke-02/docx-editor-agents/react` to use the toolkit's registry.
215
+ */
216
+ humanizeName?: (name: string) => string;
217
+ /** "Working… N steps" — pass for i18n. Default English. */
218
+ workingLabel?: (count: number) => string;
219
+ /** "N steps" — pass for i18n. Default English. */
220
+ summaryLabel?: (count: number) => string;
221
+ /** "+ N earlier steps" — pass for i18n. Default English. */
222
+ earlierLabel?: (count: number) => string;
223
+ }
224
+ /**
225
+ * Collapsible timeline of an assistant turn's tool calls. Lives above the
226
+ * assistant text bubble. Auto-collapses when the turn finishes; click the
227
+ * summary row to re-expand.
228
+ */
229
+ declare function AgentTimeline({ toolCalls, streaming, maxVisibleCalls, humanizeName, workingLabel, summaryLabel, earlierLabel, }: AgentTimelineProps): react_jsx_runtime.JSX.Element | null;
230
+ declare function AgentChatLog({ messages, loading, error, emptyState, autoScroll, humanizeToolName, maxVisibleCalls, className, style, thinkingLabel, workingLabel, summaryLabel, earlierLabel, }: AgentChatLogProps): react_jsx_runtime.JSX.Element;
231
+ interface AgentComposerProps {
232
+ value: string;
233
+ onChange: (next: string) => void;
234
+ onSubmit: () => void;
235
+ disabled?: boolean;
236
+ placeholder?: string;
237
+ /** Send-button aria-label. Default `'Send'`. */
238
+ sendLabel?: string;
239
+ /** Small text under the input — typically a scope reminder. */
240
+ footnote?: ReactNode;
241
+ className?: string;
242
+ }
243
+ declare function AgentComposer({ value, onChange, onSubmit, disabled, placeholder, sendLabel, footnote, className, }: AgentComposerProps): react_jsx_runtime.JSX.Element;
244
+ interface AgentSuggestionChipProps {
245
+ label: string;
246
+ onClick: () => void;
247
+ disabled?: boolean;
248
+ }
249
+ declare function AgentSuggestionChip({ label, onClick, disabled }: AgentSuggestionChipProps): react_jsx_runtime.JSX.Element;
250
+
251
+ export { AgentChatLog, type AgentChatLogProps, AgentComposer, type AgentComposerProps, AgentContextSnapshot, AgentMessage, AgentPanel, type AgentPanelProps, AgentSuggestionChip, type AgentSuggestionChipProps, AgentTimeline, type AgentTimelineProps, AgentToolCall, AgentToolDefinition, AgentToolResult, EditorRefLike, type UseAgentChatOptions, type UseAgentChatReturn, type UseDocxAgentToolsOptions, type UseDocxAgentToolsReturn, useAgentChat, useDocxAgentTools };
@@ -0,0 +1,251 @@
1
+ /**
2
+ * @zeke-02/docx-editor-agents/react
3
+ *
4
+ * React entry. Hooks, components, and types that need React as a peer
5
+ * dependency. Pair with `/server` (or `/ai-sdk/server`) for the API route
6
+ * that drives the LLM.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { useDocxAgentTools } from '@zeke-02/docx-editor-agents/react';
11
+ *
12
+ * const { tools, executeToolCall, getContext } = useDocxAgentTools({
13
+ * editorRef,
14
+ * author: 'Assistant',
15
+ * });
16
+ * ```
17
+ *
18
+ * @packageDocumentation
19
+ * @public
20
+ */
21
+ import { r as EditorRefLike, k as AgentToolResult, q as getToolSchemas, j as AgentToolDefinition, s as AgentContextSnapshot } from './server-uWvnaIh-.js';
22
+ export { t as getToolDisplayName } from './server-uWvnaIh-.js';
23
+ import * as react_jsx_runtime from 'react/jsx-runtime';
24
+ import { ReactNode, CSSProperties } from 'react';
25
+ import { A as AgentMessage, a as AgentToolCall } from './agent-types-C8RvQB7n.js';
26
+ import '@zeke-02/docx-editor-core/headless';
27
+
28
+ /**
29
+ * useAgentChat — React hook that wires agent tools to a live DocxEditor.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * import { useAgentChat } from '@zeke-02/docx-editor-agents/react';
34
+ *
35
+ * const { executeToolCall, toolSchemas } = useAgentChat({ editorRef, author: 'Assistant' });
36
+ *
37
+ * // Pass toolSchemas to your AI provider, execute tool calls on the client
38
+ * const result = executeToolCall('add_comment', { paragraphIndex: 3, text: 'Fix this.' });
39
+ * ```
40
+ */
41
+
42
+ interface UseAgentChatOptions {
43
+ /** Reference to the DocxEditor (must match EditorRefLike interface). */
44
+ editorRef: React.RefObject<EditorRefLike | null>;
45
+ /** Default author name for comments and changes. Default: 'AI' */
46
+ author?: string;
47
+ }
48
+ interface UseAgentChatReturn {
49
+ /** Execute a tool call through the bridge. */
50
+ executeToolCall: (toolName: string, input: Record<string, unknown>) => AgentToolResult;
51
+ /** Tool schemas in OpenAI function calling format. Pass to your AI provider. */
52
+ toolSchemas: ReturnType<typeof getToolSchemas>;
53
+ }
54
+ /**
55
+ * Hook that creates an EditorBridge and provides tool execution.
56
+ */
57
+ declare function useAgentChat(options: UseAgentChatOptions): UseAgentChatReturn;
58
+
59
+ /**
60
+ * useDocxAgentTools — wires the toolkit to a live DocxEditor for BYO chat
61
+ * frameworks.
62
+ *
63
+ * Returns three things consumers need to plug an agent into the editor:
64
+ *
65
+ * - `tools` — schemas in OpenAI function-calling format. Pass to `streamText({ tools })`,
66
+ * OpenAI's `tools` field, Anthropic's `tools`, or any provider that accepts
67
+ * that shape.
68
+ * - `executeToolCall` — the executor. Hand to AI SDK's `onToolCall`, or call
69
+ * yourself when you wire up tool calls manually.
70
+ * - `getContext` — snapshot of `{selection, currentPage, paragraphCount}` for
71
+ * system-prompt injection. Pass through `prepareRequestBody` (AI SDK) or
72
+ * inline into your own request body so the agent always knows what the
73
+ * user is looking at without an extra tool round-trip.
74
+ *
75
+ * Custom tools merge with the built-ins via the `tools` option. Names collide
76
+ * → consumer wins (your override replaces the built-in by name).
77
+ *
78
+ * @example
79
+ * ```tsx
80
+ * const { tools, executeToolCall, getContext } = useDocxAgentTools({
81
+ * editorRef,
82
+ * author: 'Assistant',
83
+ * tools: {
84
+ * fetch_clause: {
85
+ * name: 'fetch_clause',
86
+ * description: 'Fetch a clause template by name.',
87
+ * inputSchema: { type: 'object', properties: { name: { type: 'string' } } },
88
+ * handler: async (input) => ({ success: true, data: await fetchTemplate(input.name) }),
89
+ * },
90
+ * },
91
+ * });
92
+ * ```
93
+ */
94
+
95
+ interface UseDocxAgentToolsOptions {
96
+ /** Reference to the DocxEditor (must match EditorRefLike). */
97
+ editorRef: React.RefObject<EditorRefLike | null>;
98
+ /** Default author name for comments / tracked changes. Default: 'AI'. */
99
+ author?: string;
100
+ /**
101
+ * Optional consumer-defined tools to merge with the built-ins. Keyed by
102
+ * tool name. A tool with the same name as a built-in **replaces** it.
103
+ * Pass a stable reference (memoized or module-level) to avoid rebuilding
104
+ * the tool list on every render.
105
+ */
106
+ tools?: Record<string, AgentToolDefinition<any>>;
107
+ /**
108
+ * Allow-list of built-in tool names to expose. When provided, only the
109
+ * named tools are returned (custom tools from `tools` always pass).
110
+ * Useful for read-only or scope-restricted agents:
111
+ *
112
+ * @example include: ['read_document', 'find_text', 'add_comment']
113
+ */
114
+ include?: readonly string[];
115
+ /**
116
+ * Block-list of built-in tool names to hide. Applied after `include`.
117
+ * Use for agents that should not write tracked changes:
118
+ *
119
+ * @example exclude: ['suggest_change', 'apply_formatting', 'set_paragraph_style']
120
+ */
121
+ exclude?: readonly string[];
122
+ }
123
+ interface UseDocxAgentToolsReturn {
124
+ /** Tool schemas in OpenAI function calling format — pass to your AI provider. */
125
+ tools: ReturnType<typeof getToolSchemas>;
126
+ /** Execute a tool call by name. Pass to AI SDK's `onToolCall`. */
127
+ executeToolCall: (name: string, args: Record<string, unknown>) => AgentToolResult;
128
+ /** Snapshot of the user's current view for system-prompt injection. */
129
+ getContext: () => AgentContextSnapshot;
130
+ }
131
+ declare function useDocxAgentTools(options: UseDocxAgentToolsOptions): UseDocxAgentToolsReturn;
132
+
133
+ interface AgentPanelProps {
134
+ /** Header title. Defaults to `'Assistant'`. Pass a localised string for i18n. */
135
+ title?: string;
136
+ /** Header icon node. Defaults to a sparkle SVG. */
137
+ icon?: ReactNode;
138
+ /** Close button aria-label. Defaults to `'Close panel'`. */
139
+ closeLabel?: string;
140
+ /** Resize handle aria-label. Defaults to `'Resize agent panel'`. */
141
+ resizeHandleLabel?: string;
142
+ /** Controlled width in pixels. Omit for uncontrolled (internal state + localStorage). */
143
+ width?: number;
144
+ /** Default width when uncontrolled. */
145
+ defaultWidth?: number;
146
+ /** Min drag width. */
147
+ minWidth?: number;
148
+ /** Max drag width. */
149
+ maxWidth?: number;
150
+ /** Width change callback (drag end and intermediate). */
151
+ onWidthChange?: (w: number) => void;
152
+ /** Header close button click. Omit to hide the close button. */
153
+ onClose?: () => void;
154
+ /** Panel content. Render whatever you want — a chat, tabs, settings, anything. */
155
+ children: ReactNode;
156
+ /** Optional class on the outer wrapper. */
157
+ className?: string;
158
+ /**
159
+ * When `true`, the panel collapses to zero width with an ease-out
160
+ * transition (the children are still mounted so chat state survives
161
+ * close/reopen). The DocxEditor wrapper passes this when the user
162
+ * toggles the panel — kept off by default for standalone usage.
163
+ */
164
+ closed?: boolean;
165
+ }
166
+ declare function AgentPanel({ title, icon, closeLabel, resizeHandleLabel, width: controlledWidth, defaultWidth, minWidth, maxWidth, onWidthChange, onClose, children, className, closed, }: AgentPanelProps): react_jsx_runtime.JSX.Element;
167
+
168
+ interface AgentChatLogProps {
169
+ messages: AgentMessage[];
170
+ /** Render thinking dots at the bottom of the list. */
171
+ loading?: boolean;
172
+ /** Render an error bubble after the last message. */
173
+ error?: string | null;
174
+ /** Shown when there are no messages and not loading. */
175
+ emptyState?: ReactNode;
176
+ /** "Assistant is thinking" aria-label. Default English. */
177
+ thinkingLabel?: string;
178
+ /** "Working… N steps" — pass for i18n. Default English. */
179
+ workingLabel?: (count: number) => string;
180
+ /** "N steps" — pass for i18n. Default English. */
181
+ summaryLabel?: (count: number) => string;
182
+ /** "+ N earlier steps" — pass for i18n. Default English. */
183
+ earlierLabel?: (count: number) => string;
184
+ /** Auto-scroll to bottom on new messages / loading toggles. Default: true. */
185
+ autoScroll?: boolean;
186
+ /**
187
+ * Map a tool name to a friendly label for the per-message timeline.
188
+ * Pass `getToolDisplayName` from `@zeke-02/docx-editor-agents/react` to
189
+ * use the toolkit's registry-aware labels (e.g. "Adding comment").
190
+ */
191
+ humanizeToolName?: (name: string) => string;
192
+ /** Cap the tool-call timeline to this many recent rows. Default 3. */
193
+ maxVisibleCalls?: number;
194
+ className?: string;
195
+ style?: CSSProperties;
196
+ }
197
+ interface AgentTimelineProps {
198
+ /** Tool calls in chronological order. */
199
+ toolCalls: AgentToolCall[];
200
+ /**
201
+ * Whether the parent assistant turn is still streaming. While true, the
202
+ * timeline is forced expanded and shows a spinner; on false it
203
+ * auto-collapses to an "N steps" summary unless the user expanded it.
204
+ */
205
+ streaming?: boolean;
206
+ /**
207
+ * Cap the number of rendered call rows — older entries collapse into a
208
+ * "+N earlier steps" header. Default 3.
209
+ */
210
+ maxVisibleCalls?: number;
211
+ /**
212
+ * Map a tool name to a friendly label. Defaults to a sentence-case
213
+ * conversion of the snake_case name. Pass `getToolDisplayName` from
214
+ * `@zeke-02/docx-editor-agents/react` to use the toolkit's registry.
215
+ */
216
+ humanizeName?: (name: string) => string;
217
+ /** "Working… N steps" — pass for i18n. Default English. */
218
+ workingLabel?: (count: number) => string;
219
+ /** "N steps" — pass for i18n. Default English. */
220
+ summaryLabel?: (count: number) => string;
221
+ /** "+ N earlier steps" — pass for i18n. Default English. */
222
+ earlierLabel?: (count: number) => string;
223
+ }
224
+ /**
225
+ * Collapsible timeline of an assistant turn's tool calls. Lives above the
226
+ * assistant text bubble. Auto-collapses when the turn finishes; click the
227
+ * summary row to re-expand.
228
+ */
229
+ declare function AgentTimeline({ toolCalls, streaming, maxVisibleCalls, humanizeName, workingLabel, summaryLabel, earlierLabel, }: AgentTimelineProps): react_jsx_runtime.JSX.Element | null;
230
+ declare function AgentChatLog({ messages, loading, error, emptyState, autoScroll, humanizeToolName, maxVisibleCalls, className, style, thinkingLabel, workingLabel, summaryLabel, earlierLabel, }: AgentChatLogProps): react_jsx_runtime.JSX.Element;
231
+ interface AgentComposerProps {
232
+ value: string;
233
+ onChange: (next: string) => void;
234
+ onSubmit: () => void;
235
+ disabled?: boolean;
236
+ placeholder?: string;
237
+ /** Send-button aria-label. Default `'Send'`. */
238
+ sendLabel?: string;
239
+ /** Small text under the input — typically a scope reminder. */
240
+ footnote?: ReactNode;
241
+ className?: string;
242
+ }
243
+ declare function AgentComposer({ value, onChange, onSubmit, disabled, placeholder, sendLabel, footnote, className, }: AgentComposerProps): react_jsx_runtime.JSX.Element;
244
+ interface AgentSuggestionChipProps {
245
+ label: string;
246
+ onClick: () => void;
247
+ disabled?: boolean;
248
+ }
249
+ declare function AgentSuggestionChip({ label, onClick, disabled }: AgentSuggestionChipProps): react_jsx_runtime.JSX.Element;
250
+
251
+ export { AgentChatLog, type AgentChatLogProps, AgentComposer, type AgentComposerProps, AgentContextSnapshot, AgentMessage, AgentPanel, type AgentPanelProps, AgentSuggestionChip, type AgentSuggestionChipProps, AgentTimeline, type AgentTimelineProps, AgentToolCall, AgentToolDefinition, AgentToolResult, EditorRefLike, type UseAgentChatOptions, type UseAgentChatReturn, type UseDocxAgentToolsOptions, type UseDocxAgentToolsReturn, useAgentChat, useDocxAgentTools };
package/dist/react.js ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';var chunk53PAUP4S_js=require('./chunk-53PAUP4S.js'),chunkRI5S75JY_js=require('./chunk-RI5S75JY.js'),react=require('react'),jsxRuntime=require('react/jsx-runtime');var te=chunkRI5S75JY_js.d();function ne(e){let{editorRef:t,author:l="AI"}=e,c=react.useMemo(()=>({get:()=>t.current?chunk53PAUP4S_js.a(t.current,l):null}),[t,l]);return {executeToolCall:react.useCallback((d,p)=>{let r=c.get();return r?chunkRI5S75JY_js.b(d,p,r):{success:false,error:"Editor not ready"}},[c]),toolSchemas:te}}function re(e){let{editorRef:t,author:l="AI",tools:c,include:u,exclude:d}=e,p=!!c&&Object.keys(c).length>0,r=react.useCallback(i=>!(u&&!u.includes(i)||d&&d.includes(i)),[u,d]),f=react.useMemo(()=>{let i=u||d?chunkRI5S75JY_js.a.filter(n=>r(n.name)):chunkRI5S75JY_js.a;if(!p)return i.map(n=>({type:"function",function:{name:n.name,description:n.description,parameters:n.inputSchema}}));let o=new Map(i.map(n=>[n.name,n]));for(let[n,C]of Object.entries(c))o.set(n,C);return Array.from(o.values()).map(n=>({type:"function",function:{name:n.name,description:n.description,parameters:n.inputSchema}}))},[c,p,u,d,r]),g=react.useCallback((i,o)=>{let n=t.current;if(!n)return {success:false,error:"Editor not ready."};let C=chunk53PAUP4S_js.a(n,l),k=c?.[i];if(k)try{return k.handler(o,C)}catch(T){return {success:false,error:T instanceof Error?T.message:String(T)}}return r(i)?chunkRI5S75JY_js.b(i,o,C):{success:false,error:`Tool '${i}' is not enabled.`}},[t,l,c,r]),x=react.useCallback(()=>{let i=t.current;if(!i)return {selection:null,currentPage:0,totalPages:0};let o=chunk53PAUP4S_js.a(i,l);return {selection:o.getSelection(),currentPage:o.getCurrentPage(),totalPages:o.getTotalPages()}},[t,l]);return {tools:f,executeToolCall:g,getContext:x}}var y={agentPanel:{defaultTitle:"Assistant",close:"Close panel",resizeHandle:"Resize agent panel",thinking:"Assistant is thinking",composerPlaceholder:"Ask the assistant\u2026",send:"Send",timeline:{working:"Working\u2026 {count, plural, one {# step} other {# steps}}",summary:"{count, plural, one {# step} other {# steps}}",earlier:"+ {count, plural, one {# earlier step} other {# earlier steps}}"}}};var _="eigenpal:docx-editor:agentPanelWidth";function ae({size:e=22}){return jsxRuntime.jsx("svg",{viewBox:"0 -960 960 960",width:e,height:e,fill:"currentColor","aria-hidden":"true",children:jsxRuntime.jsx("path",{d:"m760-600-50-110-110-50 110-50 50-110 50 110 110 50-110 50-50 110Zm0 560-50-110-110-50 110-50 50-110 50 110 110 50-110 50-50 110ZM360-160 260-380 40-480l220-100 100-220 100 220 220 100-220 100-100 220Zm0-194 40-86 86-40-86-40-40-86-40 86-86 40 86 40 40 86Zm0-126Z"})})}function le({size:e=18}){return jsxRuntime.jsx("svg",{viewBox:"0 -960 960 960",width:e,height:e,fill:"currentColor","aria-hidden":"true",children:jsxRuntime.jsx("path",{d:"m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"})})}var ce=360,ue=280,de=600;function pe({title:e=y.agentPanel.defaultTitle,icon:t,closeLabel:l=y.agentPanel.close,resizeHandleLabel:c=y.agentPanel.resizeHandle,width:u,defaultWidth:d=ce,minWidth:p=ue,maxWidth:r=de,onWidthChange:f,onClose:g,children:x,className:i,closed:o=false}){let n=u!==void 0,[C,k]=react.useState(false),T=react.useRef(o);react.useEffect(()=>{if(T.current!==o){T.current=o,k(true);let m=window.setTimeout(()=>k(false),260);return ()=>window.clearTimeout(m)}},[o]);let[L,h]=react.useState(()=>{if(n)return u;if(typeof window>"u")return d;try{let m=window.localStorage.getItem(_);if(m){let S=Number(m);if(Number.isFinite(S)&&S>=p&&S<=r)return S}}catch{}return d}),E=n?u:L,v=react.useRef(null),B=react.useRef({minWidth:p,maxWidth:r,isControlled:n,onWidthChange:f});B.current={minWidth:p,maxWidth:r,isControlled:n,onWidthChange:f};let w=react.useRef(null);if(!w.current){let m=P=>{let D=v.current;if(!D)return;let I=B.current,q=D.startX-P.clientX,N=Math.min(I.maxWidth,Math.max(I.minWidth,D.startWidth+q));D.lastWidth=N,I.isControlled||h(N),I.onWidthChange?.(N);},S=()=>{let P=v.current;if(P&&(v.current=null,document.removeEventListener("pointermove",m),document.removeEventListener("pointerup",S),!B.current.isControlled))try{window.localStorage.setItem(_,String(P.lastWidth));}catch{}};w.current={move:m,up:S};}let Y=react.useCallback(m=>{m.preventDefault();let S=n?u:L;v.current={startX:m.clientX,startWidth:S,lastWidth:S},document.addEventListener("pointermove",w.current.move),document.addEventListener("pointerup",w.current.up);},[]);return react.useEffect(()=>()=>{let m=w.current;m&&(document.removeEventListener("pointermove",m.move),document.removeEventListener("pointerup",m.up));},[]),jsxRuntime.jsxs("div",{className:`ep-agent-panel${i?` ${i}`:""}`,style:{width:o?0:E,flex:o?"0 0 0px":`0 0 ${E}px`,height:"calc(100% - 16px)",margin:o?"8px 0 8px 0":"8px 8px 8px 12px",display:"flex",flexDirection:"column",background:"#ffffff",border:o?"1px solid transparent":"1px solid #e3e3e3",borderRadius:16,boxShadow:o?"none":"0 1px 2px rgba(60,64,67,0.05), 0 4px 12px rgba(60,64,67,0.08)",opacity:o?0:1,pointerEvents:o?"none":"auto",position:"relative",boxSizing:"border-box",minWidth:o?0:p,overflow:"hidden",fontFamily:"'Google Sans', 'Google Sans Text', system-ui, -apple-system, sans-serif",transition:C?"flex-basis 220ms cubic-bezier(0.4, 0, 0.2, 1), width 220ms cubic-bezier(0.4, 0, 0.2, 1), margin 220ms cubic-bezier(0.4, 0, 0.2, 1), opacity 180ms ease, box-shadow 220ms ease, border-color 220ms ease":"opacity 180ms ease, box-shadow 220ms ease, border-color 220ms ease"},"aria-hidden":o,"data-testid":"agent-panel","data-state":o?"closed":"open",role:"complementary","aria-label":e,children:[jsxRuntime.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":c,onPointerDown:Y,style:{position:"absolute",left:-3,top:0,bottom:0,width:6,cursor:"col-resize",touchAction:"none",zIndex:1},"data-testid":"agent-panel-resize-handle"}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 16px 10px",flex:"0 0 auto",background:"#ffffff"},children:[jsxRuntime.jsx("span",{style:{display:"inline-flex",alignItems:"center",color:"#0b57d0"},children:t??jsxRuntime.jsx(ae,{size:22})}),jsxRuntime.jsx("span",{style:{flex:1,fontSize:15,fontWeight:500,color:"#1f1f1f",letterSpacing:.1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e}),g&&jsxRuntime.jsx("button",{type:"button",onClick:g,"aria-label":l,title:l,"data-testid":"agent-panel-close",style:{border:"none",background:"transparent",padding:6,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#444746",borderRadius:999,transition:"background 0.15s"},onMouseEnter:m=>{m.currentTarget.style.background="#f1f3f4";},onMouseLeave:m=>{m.currentTarget.style.background="transparent";},children:jsxRuntime.jsx(le,{size:18})})]}),jsxRuntime.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:x})]})}function ge(e){let t={},l=/(=\d+|\w+)\s*\{([^}]*)\}/g,c;for(;(c=l.exec(e))!==null;)t[c[1]]=c[2];return t}function F(e,t,l="en"){return t?e.replace(/\{(\w+),\s*plural,\s*((?:[^{}]|\{[^{}]*\})*)\}/g,(u,d,p)=>{let r=Number(t[d]);if(isNaN(r))return u;let f=ge(p),g=f[`=${r}`];if(g!==void 0)return g.replace(/#/g,String(r));let x;try{x=new Intl.PluralRules(l).select(r);}catch{x=r===1?"one":"other";}return (f[x]??f.other??"").replace(/#/g,String(r))}).replace(/\{(\w+)\}/g,(u,d)=>{let p=t[d];return p!==void 0?String(p):`{${d}}`}):e}function V(e){let t=e.replace(/_/g," ");return t.charAt(0).toUpperCase()+t.slice(1)}var xe=y.agentPanel.thinking,he=y.agentPanel.composerPlaceholder,be=y.agentPanel.send,ye=e=>F(y.agentPanel.timeline.working,{count:e}),Ae=e=>F(y.agentPanel.timeline.summary,{count:e}),Se=e=>F(y.agentPanel.timeline.earlier,{count:e}),j="ep-agent-chat-keyframes",Ce=`
2
+ @keyframes epAgentDot {
3
+ 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
4
+ 40% { transform: scale(1); opacity: 1; }
5
+ }
6
+ @keyframes epAgentSpin {
7
+ to { transform: rotate(360deg); }
8
+ }
9
+ `;function Te(){react.useEffect(()=>{if(typeof document>"u"||document.getElementById(j))return;let e=document.createElement("style");e.id=j,e.textContent=Ce,document.head.appendChild(e);},[]);}var ke=3;function K({toolCalls:e,streaming:t,maxVisibleCalls:l=ke,humanizeName:c=V,workingLabel:u=ye,summaryLabel:d=Ae,earlierLabel:p=Se}){let[r,f]=react.useState(null),g=r??!!t;if(e.length===0)return null;let x=t?u(e.length):d(e.length),i=e.slice(-l),o=Math.max(0,e.length-i.length);return jsxRuntime.jsxs("div",{style:s.timelineWrap,"data-testid":"agent-timeline",children:[jsxRuntime.jsxs("button",{type:"button",onClick:()=>f(!g),"aria-expanded":g,style:s.timelineHeader,"data-testid":"agent-timeline-toggle",children:[jsxRuntime.jsxs("span",{style:s.timelineSummary,children:[t?jsxRuntime.jsx(X,{}):jsxRuntime.jsx(ve,{}),x]}),jsxRuntime.jsx("span",{style:{...s.timelineChevron,transform:g?"rotate(180deg)":"rotate(0deg)"},"aria-hidden":"true",children:"\u25BE"})]}),g&&jsxRuntime.jsxs("ol",{style:s.timelineList,children:[o>0&&jsxRuntime.jsx("li",{style:s.timelineMore,"data-testid":"agent-timeline-earlier",children:p(o)}),i.map(n=>jsxRuntime.jsxs("li",{style:s.timelineItem,children:[n.status==="running"?jsxRuntime.jsx(X,{size:10,compact:true}):jsxRuntime.jsx("span",{style:{...s.timelineDot,background:n.status==="error"?"#d93025":"#1e8e3e"},"aria-hidden":"true"}),jsxRuntime.jsxs("span",{style:s.timelineCall,children:[jsxRuntime.jsx("span",{style:s.timelineCallName,children:c(n.name)}),n.error&&jsxRuntime.jsx("span",{style:s.timelineError,children:n.error})]})]},n.id))]})]})}function X({size:e=12,compact:t=false}={}){return jsxRuntime.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",style:{marginRight:t?0:6,animation:"epAgentSpin 0.8s linear infinite",flexShrink:0},"aria-hidden":"true",children:[jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"9",stroke:"#dadce0",strokeWidth:"3",fill:"none"}),jsxRuntime.jsx("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"#0b57d0",strokeWidth:"3",strokeLinecap:"round"})]})}function ve(){return jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{marginRight:6},children:jsxRuntime.jsx("path",{d:"M5 13l4 4L19 7",stroke:"#1e8e3e",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function we({messages:e,loading:t,error:l,emptyState:c,autoScroll:u=true,humanizeToolName:d,maxVisibleCalls:p,className:r,style:f,thinkingLabel:g=xe,workingLabel:x,summaryLabel:i,earlierLabel:o}){Te();let n=react.useRef(null),C=e[e.length-1],k=C?.toolCalls?.length??0,T=C?.status==="streaming";react.useEffect(()=>{u&&n.current?.scrollIntoView({behavior:T||t?"auto":"smooth",block:"end"});},[e.length,k,t,T,u]);let L=e.length===0&&!t&&!l;return jsxRuntime.jsxs("div",{className:`ep-agent-chat-log${r?` ${r}`:""}`,style:{flex:1,overflow:"auto",padding:"16px 14px 8px",display:"flex",flexDirection:"column",gap:10,...f},children:[L&&c,e.map(h=>{let E=h.role==="assistant"&&h.toolCalls&&h.toolCalls.length>0,v=h.text.length>0;return jsxRuntime.jsxs("div",{style:s.messageGroup,"data-role":h.role,children:[E&&jsxRuntime.jsx(K,{toolCalls:h.toolCalls,streaming:h.status==="streaming",humanizeName:d,maxVisibleCalls:p,workingLabel:x,summaryLabel:i,earlierLabel:o}),v&&jsxRuntime.jsx("div",{style:h.role==="user"?s.userBubble:s.assistantBubble,children:h.text})]},h.id)}),t&&jsxRuntime.jsxs("div",{style:s.thinkingBubble,"aria-label":g,children:[jsxRuntime.jsx("span",{style:{...s.dot,animationDelay:"0s"}}),jsxRuntime.jsx("span",{style:{...s.dot,animationDelay:"0.15s"}}),jsxRuntime.jsx("span",{style:{...s.dot,animationDelay:"0.3s"}})]}),l&&jsxRuntime.jsx("div",{style:s.errorBubble,role:"alert",children:l}),jsxRuntime.jsx("div",{ref:n})]})}function Re({value:e,onChange:t,onSubmit:l,disabled:c,placeholder:u=he,sendLabel:d=be,footnote:p,className:r}){let f=u,g=e.trim().length>0&&!c;return jsxRuntime.jsxs("form",{onSubmit:i=>{i.preventDefault(),g&&l();},className:`ep-agent-composer${r?` ${r}`:""}`,style:s.composerWrap,children:[jsxRuntime.jsxs("div",{style:s.composerShell,children:[jsxRuntime.jsx("input",{style:s.composerInput,value:e,onChange:i=>t(i.target.value),placeholder:f,disabled:c}),jsxRuntime.jsx("button",{type:"submit","aria-label":d,disabled:!g,style:{...s.sendBtn,opacity:g?1:.35,cursor:g?"pointer":"not-allowed"},children:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:jsxRuntime.jsx("path",{d:"M12 19V5M5 12l7-7 7 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),p&&jsxRuntime.jsx("div",{style:s.footnote,children:p})]})}function Le({label:e,onClick:t,disabled:l}){return jsxRuntime.jsx("button",{type:"button",style:s.chip,onClick:t,disabled:l,children:e})}var s={messageGroup:{display:"flex",flexDirection:"column",gap:6,width:"100%"},userBubble:{background:"#0b57d0",color:"#fff",padding:"10px 14px",borderRadius:"20px 20px 4px 20px",fontSize:13.5,lineHeight:1.5,alignSelf:"flex-end",maxWidth:"88%",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"'Google Sans', 'Google Sans Text', system-ui, -apple-system, sans-serif"},assistantBubble:{background:"#f0f4f9",color:"#1f1f1f",padding:"12px 16px",borderRadius:"20px 20px 20px 4px",fontSize:13.5,lineHeight:1.55,alignSelf:"flex-start",maxWidth:"92%",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"'Google Sans', 'Google Sans Text', system-ui, -apple-system, sans-serif"},thinkingBubble:{background:"#f0f4f9",padding:"12px 16px",borderRadius:"20px 20px 20px 4px",alignSelf:"flex-start",display:"flex",gap:4,alignItems:"center"},dot:{width:6,height:6,borderRadius:"50%",background:"#5f6368",display:"inline-block",animation:"epAgentDot 1.4s infinite ease-in-out"},errorBubble:{background:"#fce8e6",color:"#b3261e",padding:"10px 14px",borderRadius:16,fontSize:12.5,alignSelf:"flex-start",maxWidth:"92%",whiteSpace:"pre-wrap",fontFamily:"'Google Sans Text', system-ui, sans-serif"},composerWrap:{padding:"8px 12px 14px",background:"#fff",flex:"0 0 auto"},composerShell:{display:"flex",alignItems:"center",gap:4,padding:"6px 6px 6px 18px",background:"#fff",border:"1px solid #c4c7c5",borderRadius:28,boxShadow:"0 1px 2px rgba(60,64,67,0.04)",transition:"border-color 0.15s, box-shadow 0.15s",fontFamily:"'Google Sans Text', system-ui, sans-serif"},composerInput:{flex:1,padding:"8px 0",fontSize:14,border:"none",outline:"none",background:"transparent",fontFamily:"inherit",color:"#1f1f1f"},sendBtn:{width:36,height:36,borderRadius:"50%",border:"none",background:"#0b57d0",color:"#fff",flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",transition:"background 0.15s, opacity 0.15s, transform 0.15s"},footnote:{fontSize:11,color:"#5f6368",textAlign:"center",marginTop:10,fontFamily:"'Google Sans Text', system-ui, sans-serif"},chip:{textAlign:"left",background:"#fff",border:"1px solid #dadce0",borderRadius:18,padding:"10px 14px",fontSize:13,color:"#1f1f1f",cursor:"pointer",fontFamily:"'Google Sans Text', system-ui, sans-serif",lineHeight:1.4,transition:"background 0.15s, border-color 0.15s, box-shadow 0.15s",width:"100%"},timelineWrap:{alignSelf:"flex-start",maxWidth:"92%",background:"#fff",border:"1px solid #e1e3e6",borderRadius:12,overflow:"hidden",fontFamily:"'Google Sans Text', system-ui, sans-serif"},timelineHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"8px 12px",background:"transparent",border:"none",cursor:"pointer",fontSize:12.5,color:"#1f1f1f",fontFamily:"inherit"},timelineSummary:{display:"inline-flex",alignItems:"center",fontWeight:500},timelineChevron:{fontSize:12,color:"#5f6368",transition:"transform 0.15s ease",marginLeft:8},timelineList:{listStyle:"none",margin:0,padding:"4px 12px 10px 12px",display:"flex",flexDirection:"column",gap:6,borderTop:"1px solid #ececf0"},timelineItem:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"#444746"},timelineDot:{width:6,height:6,borderRadius:"50%",flexShrink:0},timelineCall:{display:"inline-flex",flexDirection:"column",minWidth:0},timelineCallName:{color:"#1f1f1f"},timelineError:{color:"#d93025",fontSize:11},timelineMore:{fontSize:11,color:"#5f6368",fontStyle:"italic",paddingLeft:14}};Object.defineProperty(exports,"getToolDisplayName",{enumerable:true,get:function(){return chunkRI5S75JY_js.c}});exports.AgentChatLog=we;exports.AgentComposer=Re;exports.AgentPanel=pe;exports.AgentSuggestionChip=Le;exports.AgentTimeline=K;exports.useAgentChat=ne;exports.useDocxAgentTools=re;
package/dist/react.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import {a}from'./chunk-KMEZXSKR.mjs';import {d,b,a as a$1}from'./chunk-24MVJKCP.mjs';export{c as getToolDisplayName}from'./chunk-24MVJKCP.mjs';import {useMemo,useCallback,useState,useRef,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';var te=d();function ne(e){let{editorRef:t,author:l="AI"}=e,c=useMemo(()=>({get:()=>t.current?a(t.current,l):null}),[t,l]);return {executeToolCall:useCallback((d,p)=>{let r=c.get();return r?b(d,p,r):{success:false,error:"Editor not ready"}},[c]),toolSchemas:te}}function re(e){let{editorRef:t,author:l="AI",tools:c,include:u,exclude:d}=e,p=!!c&&Object.keys(c).length>0,r=useCallback(i=>!(u&&!u.includes(i)||d&&d.includes(i)),[u,d]),f=useMemo(()=>{let i=u||d?a$1.filter(n=>r(n.name)):a$1;if(!p)return i.map(n=>({type:"function",function:{name:n.name,description:n.description,parameters:n.inputSchema}}));let o=new Map(i.map(n=>[n.name,n]));for(let[n,C]of Object.entries(c))o.set(n,C);return Array.from(o.values()).map(n=>({type:"function",function:{name:n.name,description:n.description,parameters:n.inputSchema}}))},[c,p,u,d,r]),g=useCallback((i,o)=>{let n=t.current;if(!n)return {success:false,error:"Editor not ready."};let C=a(n,l),k=c?.[i];if(k)try{return k.handler(o,C)}catch(T){return {success:false,error:T instanceof Error?T.message:String(T)}}return r(i)?b(i,o,C):{success:false,error:`Tool '${i}' is not enabled.`}},[t,l,c,r]),x=useCallback(()=>{let i=t.current;if(!i)return {selection:null,currentPage:0,totalPages:0};let o=a(i,l);return {selection:o.getSelection(),currentPage:o.getCurrentPage(),totalPages:o.getTotalPages()}},[t,l]);return {tools:f,executeToolCall:g,getContext:x}}var y={agentPanel:{defaultTitle:"Assistant",close:"Close panel",resizeHandle:"Resize agent panel",thinking:"Assistant is thinking",composerPlaceholder:"Ask the assistant\u2026",send:"Send",timeline:{working:"Working\u2026 {count, plural, one {# step} other {# steps}}",summary:"{count, plural, one {# step} other {# steps}}",earlier:"+ {count, plural, one {# earlier step} other {# earlier steps}}"}}};var _="eigenpal:docx-editor:agentPanelWidth";function ae({size:e=22}){return jsx("svg",{viewBox:"0 -960 960 960",width:e,height:e,fill:"currentColor","aria-hidden":"true",children:jsx("path",{d:"m760-600-50-110-110-50 110-50 50-110 50 110 110 50-110 50-50 110Zm0 560-50-110-110-50 110-50 50-110 50 110 110 50-110 50-50 110ZM360-160 260-380 40-480l220-100 100-220 100 220 220 100-220 100-100 220Zm0-194 40-86 86-40-86-40-40-86-40 86-86 40 86 40 40 86Zm0-126Z"})})}function le({size:e=18}){return jsx("svg",{viewBox:"0 -960 960 960",width:e,height:e,fill:"currentColor","aria-hidden":"true",children:jsx("path",{d:"m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z"})})}var ce=360,ue=280,de=600;function pe({title:e=y.agentPanel.defaultTitle,icon:t,closeLabel:l=y.agentPanel.close,resizeHandleLabel:c=y.agentPanel.resizeHandle,width:u,defaultWidth:d=ce,minWidth:p=ue,maxWidth:r=de,onWidthChange:f,onClose:g,children:x,className:i,closed:o=false}){let n=u!==void 0,[C,k]=useState(false),T=useRef(o);useEffect(()=>{if(T.current!==o){T.current=o,k(true);let m=window.setTimeout(()=>k(false),260);return ()=>window.clearTimeout(m)}},[o]);let[L,h]=useState(()=>{if(n)return u;if(typeof window>"u")return d;try{let m=window.localStorage.getItem(_);if(m){let S=Number(m);if(Number.isFinite(S)&&S>=p&&S<=r)return S}}catch{}return d}),E=n?u:L,v=useRef(null),B=useRef({minWidth:p,maxWidth:r,isControlled:n,onWidthChange:f});B.current={minWidth:p,maxWidth:r,isControlled:n,onWidthChange:f};let w=useRef(null);if(!w.current){let m=P=>{let D=v.current;if(!D)return;let I=B.current,q=D.startX-P.clientX,N=Math.min(I.maxWidth,Math.max(I.minWidth,D.startWidth+q));D.lastWidth=N,I.isControlled||h(N),I.onWidthChange?.(N);},S=()=>{let P=v.current;if(P&&(v.current=null,document.removeEventListener("pointermove",m),document.removeEventListener("pointerup",S),!B.current.isControlled))try{window.localStorage.setItem(_,String(P.lastWidth));}catch{}};w.current={move:m,up:S};}let Y=useCallback(m=>{m.preventDefault();let S=n?u:L;v.current={startX:m.clientX,startWidth:S,lastWidth:S},document.addEventListener("pointermove",w.current.move),document.addEventListener("pointerup",w.current.up);},[]);return useEffect(()=>()=>{let m=w.current;m&&(document.removeEventListener("pointermove",m.move),document.removeEventListener("pointerup",m.up));},[]),jsxs("div",{className:`ep-agent-panel${i?` ${i}`:""}`,style:{width:o?0:E,flex:o?"0 0 0px":`0 0 ${E}px`,height:"calc(100% - 16px)",margin:o?"8px 0 8px 0":"8px 8px 8px 12px",display:"flex",flexDirection:"column",background:"#ffffff",border:o?"1px solid transparent":"1px solid #e3e3e3",borderRadius:16,boxShadow:o?"none":"0 1px 2px rgba(60,64,67,0.05), 0 4px 12px rgba(60,64,67,0.08)",opacity:o?0:1,pointerEvents:o?"none":"auto",position:"relative",boxSizing:"border-box",minWidth:o?0:p,overflow:"hidden",fontFamily:"'Google Sans', 'Google Sans Text', system-ui, -apple-system, sans-serif",transition:C?"flex-basis 220ms cubic-bezier(0.4, 0, 0.2, 1), width 220ms cubic-bezier(0.4, 0, 0.2, 1), margin 220ms cubic-bezier(0.4, 0, 0.2, 1), opacity 180ms ease, box-shadow 220ms ease, border-color 220ms ease":"opacity 180ms ease, box-shadow 220ms ease, border-color 220ms ease"},"aria-hidden":o,"data-testid":"agent-panel","data-state":o?"closed":"open",role:"complementary","aria-label":e,children:[jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":c,onPointerDown:Y,style:{position:"absolute",left:-3,top:0,bottom:0,width:6,cursor:"col-resize",touchAction:"none",zIndex:1},"data-testid":"agent-panel-resize-handle"}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 16px 10px",flex:"0 0 auto",background:"#ffffff"},children:[jsx("span",{style:{display:"inline-flex",alignItems:"center",color:"#0b57d0"},children:t??jsx(ae,{size:22})}),jsx("span",{style:{flex:1,fontSize:15,fontWeight:500,color:"#1f1f1f",letterSpacing:.1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e}),g&&jsx("button",{type:"button",onClick:g,"aria-label":l,title:l,"data-testid":"agent-panel-close",style:{border:"none",background:"transparent",padding:6,cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",color:"#444746",borderRadius:999,transition:"background 0.15s"},onMouseEnter:m=>{m.currentTarget.style.background="#f1f3f4";},onMouseLeave:m=>{m.currentTarget.style.background="transparent";},children:jsx(le,{size:18})})]}),jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:x})]})}function ge(e){let t={},l=/(=\d+|\w+)\s*\{([^}]*)\}/g,c;for(;(c=l.exec(e))!==null;)t[c[1]]=c[2];return t}function F(e,t,l="en"){return t?e.replace(/\{(\w+),\s*plural,\s*((?:[^{}]|\{[^{}]*\})*)\}/g,(u,d,p)=>{let r=Number(t[d]);if(isNaN(r))return u;let f=ge(p),g=f[`=${r}`];if(g!==void 0)return g.replace(/#/g,String(r));let x;try{x=new Intl.PluralRules(l).select(r);}catch{x=r===1?"one":"other";}return (f[x]??f.other??"").replace(/#/g,String(r))}).replace(/\{(\w+)\}/g,(u,d)=>{let p=t[d];return p!==void 0?String(p):`{${d}}`}):e}function V(e){let t=e.replace(/_/g," ");return t.charAt(0).toUpperCase()+t.slice(1)}var xe=y.agentPanel.thinking,he=y.agentPanel.composerPlaceholder,be=y.agentPanel.send,ye=e=>F(y.agentPanel.timeline.working,{count:e}),Ae=e=>F(y.agentPanel.timeline.summary,{count:e}),Se=e=>F(y.agentPanel.timeline.earlier,{count:e}),j="ep-agent-chat-keyframes",Ce=`
2
+ @keyframes epAgentDot {
3
+ 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
4
+ 40% { transform: scale(1); opacity: 1; }
5
+ }
6
+ @keyframes epAgentSpin {
7
+ to { transform: rotate(360deg); }
8
+ }
9
+ `;function Te(){useEffect(()=>{if(typeof document>"u"||document.getElementById(j))return;let e=document.createElement("style");e.id=j,e.textContent=Ce,document.head.appendChild(e);},[]);}var ke=3;function K({toolCalls:e,streaming:t,maxVisibleCalls:l=ke,humanizeName:c=V,workingLabel:u=ye,summaryLabel:d=Ae,earlierLabel:p=Se}){let[r,f]=useState(null),g=r??!!t;if(e.length===0)return null;let x=t?u(e.length):d(e.length),i=e.slice(-l),o=Math.max(0,e.length-i.length);return jsxs("div",{style:s.timelineWrap,"data-testid":"agent-timeline",children:[jsxs("button",{type:"button",onClick:()=>f(!g),"aria-expanded":g,style:s.timelineHeader,"data-testid":"agent-timeline-toggle",children:[jsxs("span",{style:s.timelineSummary,children:[t?jsx(X,{}):jsx(ve,{}),x]}),jsx("span",{style:{...s.timelineChevron,transform:g?"rotate(180deg)":"rotate(0deg)"},"aria-hidden":"true",children:"\u25BE"})]}),g&&jsxs("ol",{style:s.timelineList,children:[o>0&&jsx("li",{style:s.timelineMore,"data-testid":"agent-timeline-earlier",children:p(o)}),i.map(n=>jsxs("li",{style:s.timelineItem,children:[n.status==="running"?jsx(X,{size:10,compact:true}):jsx("span",{style:{...s.timelineDot,background:n.status==="error"?"#d93025":"#1e8e3e"},"aria-hidden":"true"}),jsxs("span",{style:s.timelineCall,children:[jsx("span",{style:s.timelineCallName,children:c(n.name)}),n.error&&jsx("span",{style:s.timelineError,children:n.error})]})]},n.id))]})]})}function X({size:e=12,compact:t=false}={}){return jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",style:{marginRight:t?0:6,animation:"epAgentSpin 0.8s linear infinite",flexShrink:0},"aria-hidden":"true",children:[jsx("circle",{cx:"12",cy:"12",r:"9",stroke:"#dadce0",strokeWidth:"3",fill:"none"}),jsx("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"#0b57d0",strokeWidth:"3",strokeLinecap:"round"})]})}function ve(){return jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",style:{marginRight:6},children:jsx("path",{d:"M5 13l4 4L19 7",stroke:"#1e8e3e",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function we({messages:e,loading:t,error:l,emptyState:c,autoScroll:u=true,humanizeToolName:d,maxVisibleCalls:p,className:r,style:f,thinkingLabel:g=xe,workingLabel:x,summaryLabel:i,earlierLabel:o}){Te();let n=useRef(null),C=e[e.length-1],k=C?.toolCalls?.length??0,T=C?.status==="streaming";useEffect(()=>{u&&n.current?.scrollIntoView({behavior:T||t?"auto":"smooth",block:"end"});},[e.length,k,t,T,u]);let L=e.length===0&&!t&&!l;return jsxs("div",{className:`ep-agent-chat-log${r?` ${r}`:""}`,style:{flex:1,overflow:"auto",padding:"16px 14px 8px",display:"flex",flexDirection:"column",gap:10,...f},children:[L&&c,e.map(h=>{let E=h.role==="assistant"&&h.toolCalls&&h.toolCalls.length>0,v=h.text.length>0;return jsxs("div",{style:s.messageGroup,"data-role":h.role,children:[E&&jsx(K,{toolCalls:h.toolCalls,streaming:h.status==="streaming",humanizeName:d,maxVisibleCalls:p,workingLabel:x,summaryLabel:i,earlierLabel:o}),v&&jsx("div",{style:h.role==="user"?s.userBubble:s.assistantBubble,children:h.text})]},h.id)}),t&&jsxs("div",{style:s.thinkingBubble,"aria-label":g,children:[jsx("span",{style:{...s.dot,animationDelay:"0s"}}),jsx("span",{style:{...s.dot,animationDelay:"0.15s"}}),jsx("span",{style:{...s.dot,animationDelay:"0.3s"}})]}),l&&jsx("div",{style:s.errorBubble,role:"alert",children:l}),jsx("div",{ref:n})]})}function Re({value:e,onChange:t,onSubmit:l,disabled:c,placeholder:u=he,sendLabel:d=be,footnote:p,className:r}){let f=u,g=e.trim().length>0&&!c;return jsxs("form",{onSubmit:i=>{i.preventDefault(),g&&l();},className:`ep-agent-composer${r?` ${r}`:""}`,style:s.composerWrap,children:[jsxs("div",{style:s.composerShell,children:[jsx("input",{style:s.composerInput,value:e,onChange:i=>t(i.target.value),placeholder:f,disabled:c}),jsx("button",{type:"submit","aria-label":d,disabled:!g,style:{...s.sendBtn,opacity:g?1:.35,cursor:g?"pointer":"not-allowed"},children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:jsx("path",{d:"M12 19V5M5 12l7-7 7 7",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),p&&jsx("div",{style:s.footnote,children:p})]})}function Le({label:e,onClick:t,disabled:l}){return jsx("button",{type:"button",style:s.chip,onClick:t,disabled:l,children:e})}var s={messageGroup:{display:"flex",flexDirection:"column",gap:6,width:"100%"},userBubble:{background:"#0b57d0",color:"#fff",padding:"10px 14px",borderRadius:"20px 20px 4px 20px",fontSize:13.5,lineHeight:1.5,alignSelf:"flex-end",maxWidth:"88%",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"'Google Sans', 'Google Sans Text', system-ui, -apple-system, sans-serif"},assistantBubble:{background:"#f0f4f9",color:"#1f1f1f",padding:"12px 16px",borderRadius:"20px 20px 20px 4px",fontSize:13.5,lineHeight:1.55,alignSelf:"flex-start",maxWidth:"92%",whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"'Google Sans', 'Google Sans Text', system-ui, -apple-system, sans-serif"},thinkingBubble:{background:"#f0f4f9",padding:"12px 16px",borderRadius:"20px 20px 20px 4px",alignSelf:"flex-start",display:"flex",gap:4,alignItems:"center"},dot:{width:6,height:6,borderRadius:"50%",background:"#5f6368",display:"inline-block",animation:"epAgentDot 1.4s infinite ease-in-out"},errorBubble:{background:"#fce8e6",color:"#b3261e",padding:"10px 14px",borderRadius:16,fontSize:12.5,alignSelf:"flex-start",maxWidth:"92%",whiteSpace:"pre-wrap",fontFamily:"'Google Sans Text', system-ui, sans-serif"},composerWrap:{padding:"8px 12px 14px",background:"#fff",flex:"0 0 auto"},composerShell:{display:"flex",alignItems:"center",gap:4,padding:"6px 6px 6px 18px",background:"#fff",border:"1px solid #c4c7c5",borderRadius:28,boxShadow:"0 1px 2px rgba(60,64,67,0.04)",transition:"border-color 0.15s, box-shadow 0.15s",fontFamily:"'Google Sans Text', system-ui, sans-serif"},composerInput:{flex:1,padding:"8px 0",fontSize:14,border:"none",outline:"none",background:"transparent",fontFamily:"inherit",color:"#1f1f1f"},sendBtn:{width:36,height:36,borderRadius:"50%",border:"none",background:"#0b57d0",color:"#fff",flexShrink:0,display:"inline-flex",alignItems:"center",justifyContent:"center",transition:"background 0.15s, opacity 0.15s, transform 0.15s"},footnote:{fontSize:11,color:"#5f6368",textAlign:"center",marginTop:10,fontFamily:"'Google Sans Text', system-ui, sans-serif"},chip:{textAlign:"left",background:"#fff",border:"1px solid #dadce0",borderRadius:18,padding:"10px 14px",fontSize:13,color:"#1f1f1f",cursor:"pointer",fontFamily:"'Google Sans Text', system-ui, sans-serif",lineHeight:1.4,transition:"background 0.15s, border-color 0.15s, box-shadow 0.15s",width:"100%"},timelineWrap:{alignSelf:"flex-start",maxWidth:"92%",background:"#fff",border:"1px solid #e1e3e6",borderRadius:12,overflow:"hidden",fontFamily:"'Google Sans Text', system-ui, sans-serif"},timelineHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"8px 12px",background:"transparent",border:"none",cursor:"pointer",fontSize:12.5,color:"#1f1f1f",fontFamily:"inherit"},timelineSummary:{display:"inline-flex",alignItems:"center",fontWeight:500},timelineChevron:{fontSize:12,color:"#5f6368",transition:"transform 0.15s ease",marginLeft:8},timelineList:{listStyle:"none",margin:0,padding:"4px 12px 10px 12px",display:"flex",flexDirection:"column",gap:6,borderTop:"1px solid #ececf0"},timelineItem:{display:"flex",alignItems:"center",gap:8,fontSize:12,color:"#444746"},timelineDot:{width:6,height:6,borderRadius:"50%",flexShrink:0},timelineCall:{display:"inline-flex",flexDirection:"column",minWidth:0},timelineCallName:{color:"#1f1f1f"},timelineError:{color:"#d93025",fontSize:11},timelineMore:{fontSize:11,color:"#5f6368",fontStyle:"italic",paddingLeft:14}};export{we as AgentChatLog,Re as AgentComposer,pe as AgentPanel,Le as AgentSuggestionChip,K as AgentTimeline,ne as useAgentChat,re as useDocxAgentTools};