@cntyclub/agent-react 0.1.1 → 0.2.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 (3) hide show
  1. package/README.md +26 -0
  2. package/dist/index.d.ts +365 -31
  3. package/package.json +4 -2
package/README.md CHANGED
@@ -84,6 +84,32 @@ export function DashboardAgent() {
84
84
  `pages` + `navigate` power **page-follow**: in popup mode, when the agent uses a tool
85
85
  that maps to a page, the host app navigates there while the chat shows the same data.
86
86
 
87
+ ## API schema (OpenAPI)
88
+
89
+ The backend publishes a dedicated, scoped OpenAPI document for Agent Mode:
90
+
91
+ - **Schema**: `GET {API_BASE}/agent-mode/schema/` (YAML)
92
+ - **Swagger UI**: `{API_BASE}/agent-mode/docs/`
93
+
94
+ This repo vendors that document at [`api-spec/agent-mode-api.yaml`](api-spec/agent-mode-api.yaml)
95
+ and generates TypeScript types from it into `src/api/schema.ts` (committed). All wire
96
+ types in `src/types.ts` derive from the generated schema, so the client cannot drift
97
+ from the backend contract silently.
98
+
99
+ **Update workflow** when the backend API changes:
100
+
101
+ ```bash
102
+ curl https://api.country.club/agent-mode/schema/ -o api-spec/agent-mode-api.yaml
103
+ pnpm gen:api # regenerates src/api/schema.ts
104
+ pnpm typecheck # surfaces any breaking contract changes immediately
105
+ ```
106
+
107
+ Consumers can also import the full typed surface for their own tooling:
108
+
109
+ ```ts
110
+ import type { AgentModePaths, AgentModeComponents, AgentModeOperations } from "@cntyclub/agent-react";
111
+ ```
112
+
87
113
  ## Exports
88
114
 
89
115
  - `AgentWidget` — the complete widget (launcher + popup + fullscreen Agent Mode).
package/dist/index.d.ts CHANGED
@@ -1,5 +1,357 @@
1
1
  import * as React from 'react';
2
2
 
3
+ /**
4
+ * This file was auto-generated by openapi-typescript.
5
+ * Do not make direct changes to the file.
6
+ */
7
+ interface paths {
8
+ "/agent-mode/approvals/{call_id}/resolve/": {
9
+ parameters: {
10
+ query?: never;
11
+ header?: never;
12
+ path?: never;
13
+ cookie?: never;
14
+ };
15
+ get?: never;
16
+ put?: never;
17
+ /**
18
+ * Resolve a pending agent action
19
+ * @description Approve or decline a pending write-tool call.
20
+ */
21
+ post: operations["agent_approval_resolve"];
22
+ delete?: never;
23
+ options?: never;
24
+ head?: never;
25
+ patch?: never;
26
+ trace?: never;
27
+ };
28
+ "/agent-mode/chat/": {
29
+ parameters: {
30
+ query?: never;
31
+ header?: never;
32
+ path?: never;
33
+ cookie?: never;
34
+ };
35
+ get?: never;
36
+ put?: never;
37
+ /**
38
+ * Chat with an agent
39
+ * @description Sends a user message to the agent identified by client_id. Read-only MCP tools run automatically; write tools come back as pending approvals the user must resolve.
40
+ */
41
+ post: operations["agent_chat_send"];
42
+ delete?: never;
43
+ options?: never;
44
+ head?: never;
45
+ patch?: never;
46
+ trace?: never;
47
+ };
48
+ "/agent-mode/config/": {
49
+ parameters: {
50
+ query?: never;
51
+ header?: never;
52
+ path?: never;
53
+ cookie?: never;
54
+ };
55
+ /**
56
+ * Get agent widget config
57
+ * @description Widget bootstrap: safe agent display config for the resolved client_id.
58
+ */
59
+ get: operations["agent_config_get"];
60
+ put?: never;
61
+ post?: never;
62
+ delete?: never;
63
+ options?: never;
64
+ head?: never;
65
+ patch?: never;
66
+ trace?: never;
67
+ };
68
+ "/agent-mode/conversations/": {
69
+ parameters: {
70
+ query?: never;
71
+ header?: never;
72
+ path?: never;
73
+ cookie?: never;
74
+ };
75
+ /**
76
+ * List my conversations
77
+ * @description List the calling user's conversations with an agent.
78
+ */
79
+ get: operations["agent_conversations_list"];
80
+ put?: never;
81
+ post?: never;
82
+ delete?: never;
83
+ options?: never;
84
+ head?: never;
85
+ patch?: never;
86
+ trace?: never;
87
+ };
88
+ "/agent-mode/conversations/{conversation_id}/": {
89
+ parameters: {
90
+ query?: never;
91
+ header?: never;
92
+ path?: never;
93
+ cookie?: never;
94
+ };
95
+ /**
96
+ * Get conversation messages
97
+ * @description Fetch or delete one of the calling user's conversations.
98
+ */
99
+ get: operations["agent_conversation_get"];
100
+ put?: never;
101
+ post?: never;
102
+ /**
103
+ * Delete a conversation
104
+ * @description Fetch or delete one of the calling user's conversations.
105
+ */
106
+ delete: operations["agent_conversation_delete"];
107
+ options?: never;
108
+ head?: never;
109
+ patch?: never;
110
+ trace?: never;
111
+ };
112
+ }
113
+ interface components {
114
+ schemas: {
115
+ /** @description One chat message as returned by Agent Mode endpoints (wire format). */
116
+ AgentChatMessage: {
117
+ /** Format: uuid */
118
+ id: string;
119
+ /**
120
+ * @description * `user` - user
121
+ * * `assistant` - assistant
122
+ * * `tool` - tool
123
+ * @enum {string}
124
+ */
125
+ role: "user" | "assistant" | "tool";
126
+ content: string;
127
+ /** Format: date-time */
128
+ created_at: string;
129
+ /** @description Structured UI blocks. Table blocks: {type:'table', tool_name, columns[], rows[], row_count, truncated?, pagination?}. */
130
+ blocks?: {
131
+ [key: string]: unknown;
132
+ }[];
133
+ /** @description Assistant messages only: tools the assistant requested ({id, name, arguments}). */
134
+ tool_calls?: {
135
+ [key: string]: unknown;
136
+ }[];
137
+ tool_name?: string;
138
+ tool_call_id?: string;
139
+ };
140
+ /** @description Response of the chat and approval-resolve endpoints. */
141
+ AgentChatResponse: {
142
+ /**
143
+ * @description * `success` - success
144
+ * * `error` - error
145
+ * @enum {string}
146
+ */
147
+ status: "success" | "error";
148
+ /** @description Human-readable error detail when status=error. */
149
+ message?: string;
150
+ /** Format: uuid */
151
+ conversation_id?: string;
152
+ /** @description New messages created by this call, in order. */
153
+ messages?: components["schemas"]["AgentChatMessage"][];
154
+ pending_approvals?: components["schemas"]["PendingApproval"][];
155
+ };
156
+ /** @description Response of GET /agent-mode/conversations/<id>/. */
157
+ AgentConversationDetailResponse: {
158
+ conversation: components["schemas"]["ConversationList"];
159
+ messages: components["schemas"]["AgentChatMessage"][];
160
+ pending_approvals: components["schemas"]["PendingApproval"][];
161
+ };
162
+ /** @description Response of GET /agent-mode/conversations/. */
163
+ AgentConversationsResponse: {
164
+ conversations: components["schemas"]["ConversationList"][];
165
+ };
166
+ /** @description Widget bootstrap config — safe, non-sensitive fields only. */
167
+ AgentPublicConfig: {
168
+ name: string;
169
+ description: string;
170
+ has_mcp: boolean;
171
+ is_public: boolean;
172
+ };
173
+ /** @description Input for POST /agent-mode/approvals/<id>/resolve/. */
174
+ ApprovalRequestRequest: {
175
+ client_id: string;
176
+ approve: boolean;
177
+ };
178
+ /** @description Input for POST /agent-mode/chat/. */
179
+ ChatRequestRequest: {
180
+ client_id: string;
181
+ message: string;
182
+ /** Format: uuid */
183
+ conversation_id?: string | null;
184
+ };
185
+ ConversationList: {
186
+ /** Format: uuid */
187
+ readonly id?: string;
188
+ /** @description Derived from the first user message. */
189
+ title?: string;
190
+ /** Format: date-time */
191
+ readonly created_at?: string;
192
+ /** Format: date-time */
193
+ readonly updated_at?: string;
194
+ };
195
+ /** @description A write-tool call waiting for the user's explicit approval. */
196
+ PendingApproval: {
197
+ /** Format: uuid */
198
+ id: string;
199
+ tool_name: string;
200
+ /** @description Stored arguments that will be executed verbatim on approval. */
201
+ arguments: {
202
+ [key: string]: unknown;
203
+ };
204
+ /** Format: date-time */
205
+ created_at: string;
206
+ };
207
+ };
208
+ responses: never;
209
+ parameters: never;
210
+ requestBodies: never;
211
+ headers: never;
212
+ pathItems: never;
213
+ }
214
+ interface operations {
215
+ agent_approval_resolve: {
216
+ parameters: {
217
+ query?: never;
218
+ header?: never;
219
+ path: {
220
+ call_id: string;
221
+ };
222
+ cookie?: never;
223
+ };
224
+ requestBody: {
225
+ content: {
226
+ "application/json": components["schemas"]["ApprovalRequestRequest"];
227
+ "application/x-www-form-urlencoded": components["schemas"]["ApprovalRequestRequest"];
228
+ "multipart/form-data": components["schemas"]["ApprovalRequestRequest"];
229
+ };
230
+ };
231
+ responses: {
232
+ 200: {
233
+ headers: {
234
+ [name: string]: unknown;
235
+ };
236
+ content: {
237
+ "application/json": components["schemas"]["AgentChatResponse"];
238
+ };
239
+ };
240
+ };
241
+ };
242
+ agent_chat_send: {
243
+ parameters: {
244
+ query?: never;
245
+ header?: never;
246
+ path?: never;
247
+ cookie?: never;
248
+ };
249
+ requestBody: {
250
+ content: {
251
+ "application/json": components["schemas"]["ChatRequestRequest"];
252
+ "application/x-www-form-urlencoded": components["schemas"]["ChatRequestRequest"];
253
+ "multipart/form-data": components["schemas"]["ChatRequestRequest"];
254
+ };
255
+ };
256
+ responses: {
257
+ 200: {
258
+ headers: {
259
+ [name: string]: unknown;
260
+ };
261
+ content: {
262
+ "application/json": components["schemas"]["AgentChatResponse"];
263
+ };
264
+ };
265
+ };
266
+ };
267
+ agent_config_get: {
268
+ parameters: {
269
+ query?: never;
270
+ header?: never;
271
+ path?: never;
272
+ cookie?: never;
273
+ };
274
+ requestBody?: never;
275
+ responses: {
276
+ 200: {
277
+ headers: {
278
+ [name: string]: unknown;
279
+ };
280
+ content: {
281
+ "application/json": components["schemas"]["AgentPublicConfig"];
282
+ };
283
+ };
284
+ };
285
+ };
286
+ agent_conversations_list: {
287
+ parameters: {
288
+ query?: never;
289
+ header?: never;
290
+ path?: never;
291
+ cookie?: never;
292
+ };
293
+ requestBody?: never;
294
+ responses: {
295
+ 200: {
296
+ headers: {
297
+ [name: string]: unknown;
298
+ };
299
+ content: {
300
+ "application/json": components["schemas"]["AgentConversationsResponse"];
301
+ };
302
+ };
303
+ };
304
+ };
305
+ agent_conversation_get: {
306
+ parameters: {
307
+ query?: never;
308
+ header?: never;
309
+ path: {
310
+ conversation_id: string;
311
+ };
312
+ cookie?: never;
313
+ };
314
+ requestBody?: never;
315
+ responses: {
316
+ 200: {
317
+ headers: {
318
+ [name: string]: unknown;
319
+ };
320
+ content: {
321
+ "application/json": components["schemas"]["AgentConversationDetailResponse"];
322
+ };
323
+ };
324
+ };
325
+ };
326
+ agent_conversation_delete: {
327
+ parameters: {
328
+ query?: never;
329
+ header?: never;
330
+ path: {
331
+ conversation_id: string;
332
+ };
333
+ cookie?: never;
334
+ };
335
+ requestBody?: never;
336
+ responses: {
337
+ /** @description No response body */
338
+ 204: {
339
+ headers: {
340
+ [name: string]: unknown;
341
+ };
342
+ content?: never;
343
+ };
344
+ };
345
+ };
346
+ }
347
+
348
+ /**
349
+ * All wire types derive from the generated OpenAPI schema (src/api/schema.ts,
350
+ * generated from api-spec/agent-mode-api.yaml — the backend's
351
+ * /agent-mode/schema/ document). Regenerate with `pnpm gen:api` after updating
352
+ * the spec; see the README for the full update workflow.
353
+ */
354
+ type AgentModeSchemas = components["schemas"];
3
355
  /** A structured UI block attached to a message (currently: result tables). */
4
356
  interface TableBlock {
5
357
  type: "table";
@@ -16,41 +368,23 @@ interface ToolCallInfo {
16
368
  name?: string;
17
369
  arguments?: Record<string, unknown>;
18
370
  }
19
- interface AgentMessage {
20
- id: string;
21
- role: "user" | "assistant" | "tool";
22
- content: string;
23
- created_at: string;
371
+ /**
372
+ * One chat message. Wire shape from the schema; `blocks`/`tool_calls` are
373
+ * JSON fields on the wire, narrowed here to their documented structures.
374
+ */
375
+ interface AgentMessage extends Omit<AgentModeSchemas["AgentChatMessage"], "blocks" | "tool_calls"> {
24
376
  blocks?: MessageBlock[];
25
377
  tool_calls?: ToolCallInfo[];
26
- tool_name?: string;
27
- tool_call_id?: string;
28
378
  }
29
- interface PendingApproval {
30
- id: string;
31
- tool_name: string;
32
- arguments: Record<string, unknown>;
33
- created_at: string;
34
- }
35
- interface ConversationSummary {
36
- id: string;
37
- title: string;
38
- created_at: string;
39
- updated_at: string;
40
- }
41
- interface AgentPublicConfig {
42
- name: string;
43
- description: string;
44
- has_mcp: boolean;
45
- is_public: boolean;
46
- }
47
- interface ChatResponse {
48
- status: "success" | "error";
49
- message?: string;
50
- conversation_id?: string;
379
+ type PendingApproval = AgentModeSchemas["PendingApproval"];
380
+ type ConversationSummary = Required<AgentModeSchemas["ConversationList"]>;
381
+ type AgentPublicConfig = AgentModeSchemas["AgentPublicConfig"];
382
+ /** Response of the chat and approval-resolve endpoints. */
383
+ interface ChatResponse extends Omit<AgentModeSchemas["AgentChatResponse"], "messages"> {
51
384
  messages?: AgentMessage[];
52
- pending_approvals?: PendingApproval[];
53
385
  }
386
+ type ChatRequest = AgentModeSchemas["ChatRequestRequest"];
387
+ type ApprovalRequest = AgentModeSchemas["ApprovalRequestRequest"];
54
388
  /** Maps MCP tools to a page in the host app so the agent can navigate alongside chat. */
55
389
  interface AgentPageMapping {
56
390
  /** MCP tool names whose execution relates to this page. */
@@ -210,4 +544,4 @@ declare function ToolApprovalCard({ approval, onResolve, resolving }: ToolApprov
210
544
  */
211
545
  declare function defineAgentConfig(config: AgentConfig): AgentConfig;
212
546
 
213
- export { AgentApiClient, AgentApiError, type AgentChatActions, type AgentChatState, type AgentConfig, type AgentMessage, type AgentPageMapping, AgentPanel, type AgentPanelProps, type AgentPublicConfig, AgentWidget, type AgentWidgetProps, type ChatResponse, type ConversationSummary, type MessageBlock, MessageItem, type PendingApproval, type TableBlock, ToolApprovalCard, type ToolApprovalCardProps, type ToolCallInfo, defineAgentConfig, useAgentChat };
547
+ export { AgentApiClient, AgentApiError, type AgentChatActions, type AgentChatState, type AgentConfig, type AgentMessage, type components as AgentModeComponents, type operations as AgentModeOperations, type paths as AgentModePaths, type AgentModeSchemas, type AgentPageMapping, AgentPanel, type AgentPanelProps, type AgentPublicConfig, AgentWidget, type AgentWidgetProps, type ApprovalRequest, type ChatRequest, type ChatResponse, type ConversationSummary, type MessageBlock, MessageItem, type PendingApproval, type TableBlock, ToolApprovalCard, type ToolApprovalCardProps, type ToolCallInfo, defineAgentConfig, useAgentChat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntyclub/agent-react",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Embeddable AI agent chat widget for Country Club dashboards — floating button, popup panel, fullscreen Agent Mode, MCP tool approvals, and paginated result tables. Built exclusively on @cntyclub/ui-react.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -32,6 +32,7 @@
32
32
  "@cntyclub/ui-react": "link:../DashboardsCountryClub-UIKit/packages/ui-react",
33
33
  "@types/react": "^19.2.13",
34
34
  "@types/react-dom": "^19.2.3",
35
+ "openapi-typescript": "^7.13.0",
35
36
  "react": "^19.2.5",
36
37
  "react-dom": "^19.2.5",
37
38
  "tsup": "^8.5.1",
@@ -49,6 +50,7 @@
49
50
  "build": "tsup",
50
51
  "dev": "tsup --watch",
51
52
  "typecheck": "tsc --noEmit",
52
- "clean": "rm -rf dist"
53
+ "clean": "rm -rf dist",
54
+ "gen:api": "openapi-typescript api-spec/agent-mode-api.yaml -o src/api/schema.ts"
53
55
  }
54
56
  }