@anuma/sdk 1.0.0-next.20260224164627

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.
@@ -0,0 +1,427 @@
1
+ /**
2
+ * Google Calendar tool definition for the chat system.
3
+ * This tool allows the LLM to list events from the user's Google Calendar.
4
+ */
5
+ /**
6
+ * Tool configuration type that extends the SDK's tool type with executor support.
7
+ * The SDK runtime supports these properties even though the base types don't include them.
8
+ *
9
+ * Note: Client tools use "arguments" internally. The SDK converts this to "parameters"
10
+ * when sending to the API (see serverTools.ts mergeTools function).
11
+ */
12
+ interface ToolConfig {
13
+ type: "function";
14
+ function: {
15
+ name: string;
16
+ description: string;
17
+ arguments: Record<string, unknown>;
18
+ };
19
+ executor?: (args: Record<string, unknown>) => Promise<unknown> | unknown;
20
+ autoExecute?: boolean;
21
+ skipContinuation?: boolean;
22
+ }
23
+ interface ListEventsArgs {
24
+ timeMin?: string;
25
+ timeMax?: string;
26
+ maxResults?: number;
27
+ }
28
+ interface CreateEventArgs {
29
+ summary: string;
30
+ start: string;
31
+ end: string;
32
+ description?: string;
33
+ location?: string;
34
+ attendees?: string[];
35
+ }
36
+ interface UpdateEventArgs {
37
+ eventId: string;
38
+ summary?: string;
39
+ start?: string;
40
+ end?: string;
41
+ description?: string;
42
+ location?: string;
43
+ attendees?: string[];
44
+ }
45
+ interface CalendarEvent {
46
+ id: string;
47
+ summary: string;
48
+ start: string;
49
+ end: string;
50
+ description?: string;
51
+ location?: string;
52
+ }
53
+ /**
54
+ * Creates the Google Calendar list events tool with access to the token getter.
55
+ * The token getter is captured in a closure so the executor can access it.
56
+ */
57
+ declare function createGoogleCalendarTool(getAccessToken: () => string | null, requestCalendarAccess: () => Promise<string>): ToolConfig;
58
+ /**
59
+ * Creates the Google Calendar create event tool with access to the token getter.
60
+ * The token getter is captured in a closure so the executor can access it.
61
+ */
62
+ declare function createGoogleCalendarCreateEventTool(getAccessToken: () => string | null, requestCalendarAccess: () => Promise<string>): ToolConfig;
63
+ /**
64
+ * Creates the Google Calendar update event tool with access to the token getter.
65
+ * The token getter is captured in a closure so the executor can access it.
66
+ */
67
+ declare function createGoogleCalendarUpdateEventTool(getAccessToken: () => string | null, requestCalendarAccess: () => Promise<string>): ToolConfig;
68
+ /**
69
+ * Creates all chat tools with the provided token context.
70
+ * This factory function allows tools to access authentication tokens via closures.
71
+ */
72
+ declare function createChatTools(getAccessToken: () => string | null, requestCalendarAccess: () => Promise<string>): ToolConfig[];
73
+
74
+ /**
75
+ * Generic factories for creating client-side UI interaction tools.
76
+ *
77
+ * These factories handle the boilerplate of wiring tool executors to the
78
+ * UIInteractionProvider lifecycle (ID generation, context injection,
79
+ * promise resolution). Apps provide the tool schema and any custom logic.
80
+ */
81
+
82
+ /**
83
+ * Minimal context interface required by tool factories.
84
+ * Matches the methods provided by UIInteractionProvider.
85
+ */
86
+ type UIInteractionContext = {
87
+ createInteraction: (id: string, type: string, data: any) => Promise<any>;
88
+ createDisplayInteraction: (id: string, displayType: string, data: any, result: any, toolVersion?: number) => void;
89
+ };
90
+ /**
91
+ * Options for context injection, following the same getter pattern
92
+ * as createGoogleCalendarTool and createDriveTools.
93
+ */
94
+ type CreateUIToolsOptions = {
95
+ /** Returns the current UIInteractionContext (or null if unavailable) */
96
+ getContext: () => UIInteractionContext | null;
97
+ /** Returns the ID of the last message in the conversation (used for anchoring) */
98
+ getLastMessageId?: () => string | undefined;
99
+ };
100
+ /**
101
+ * Configuration for an interactive tool that waits for user input.
102
+ */
103
+ type InteractiveToolConfig = {
104
+ /** Tool name as called by the LLM (e.g. "prompt_user_choice") */
105
+ name: string;
106
+ /** Tool description shown to the LLM */
107
+ description: string;
108
+ /** JSON Schema for tool parameters */
109
+ parameters: Record<string, unknown>;
110
+ /** Interaction type string used by the provider (e.g. "choice", "form") */
111
+ interactionType: string;
112
+ /** Optional validation of LLM-provided args. Return false to cancel. */
113
+ validate?: (args: any) => boolean;
114
+ /** Transform args before storing as interaction data */
115
+ mapArgs?: (args: any) => any;
116
+ /** Transform the user's result before returning to the LLM */
117
+ mapResult?: (result: any, args: any) => any;
118
+ };
119
+ /**
120
+ * Migration map for a display tool.
121
+ * Keys are "fromVersion->toVersion" strings (e.g. "1->2").
122
+ * Each function receives the stored result at fromVersion and returns the
123
+ * result upgraded to toVersion.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * migrations: {
128
+ * "1->2": (old) => ({ ...old, newField: old.legacyField ?? defaultValue }),
129
+ * }
130
+ * ```
131
+ */
132
+ type DisplayToolMigrations = {
133
+ [key: `${number}->${number}`]: (data: any) => any;
134
+ };
135
+ /**
136
+ * Configuration for a display-only tool that renders data without blocking.
137
+ */
138
+ type DisplayToolConfig<TArgs = any, TResult = any> = {
139
+ /** Tool name as called by the LLM (e.g. "display_weather") */
140
+ name: string;
141
+ /** Tool description shown to the LLM */
142
+ description: string;
143
+ /** JSON Schema for tool parameters */
144
+ parameters: Record<string, unknown>;
145
+ /** Display type string used to dispatch rendering (e.g. "weather") */
146
+ displayType: string;
147
+ /** Execute function that fetches/computes the display data */
148
+ execute: (args: TArgs) => Promise<TResult>;
149
+ /**
150
+ * Schema version for the result format. Increment when the result shape
151
+ * changes in a backward-incompatible way. Default: 1.
152
+ */
153
+ version?: number;
154
+ /**
155
+ * Migration functions keyed by "fromVersion->toVersion".
156
+ * Used to upgrade stored results to the current version on restore.
157
+ */
158
+ migrations?: DisplayToolMigrations;
159
+ };
160
+ /**
161
+ * Migrate a stored display result from an older version to the current version.
162
+ *
163
+ * Runs the migration chain step-by-step: fromVersion → fromVersion+1 → … → toVersion.
164
+ * Steps with no registered migration function are skipped (result passes through unchanged).
165
+ * Returns the original result unchanged if fromVersion >= toVersion.
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const migrated = migrateDisplayResult(storedResult, 1, 3, {
170
+ * "1->2": (v1) => ({ ...v1, added: v1.old ?? 0 }),
171
+ * "2->3": (v2) => ({ ...v2, renamed: v2.added }),
172
+ * });
173
+ * ```
174
+ */
175
+ declare function migrateDisplayResult(result: any, fromVersion: number, toVersion: number, migrations: DisplayToolMigrations): any;
176
+ /**
177
+ * Create an interactive tool that waits for user input.
178
+ *
179
+ * When the LLM calls this tool, it creates a pending interaction in
180
+ * the UIInteractionProvider and returns a Promise that resolves when
181
+ * the user responds via the UI.
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const choiceTool = createInteractiveTool(
186
+ * { getContext: () => uiInteraction, getLastMessageId: () => lastMsgId },
187
+ * {
188
+ * name: "prompt_user_choice",
189
+ * description: "Present choices to the user",
190
+ * parameters: { type: "object", properties: { ... } },
191
+ * interactionType: "choice",
192
+ * validate: (args) => args.title && args.options?.length >= 2,
193
+ * }
194
+ * );
195
+ * ```
196
+ */
197
+ declare function createInteractiveTool(options: CreateUIToolsOptions, config: InteractiveToolConfig): ToolConfig;
198
+ /**
199
+ * Create a display-only tool that renders data without blocking.
200
+ *
201
+ * When the LLM calls this tool, it executes the provided function,
202
+ * stores the result as a resolved display interaction for rendering,
203
+ * and immediately returns the data to the LLM.
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const weatherTool = createDisplayTool(
208
+ * { getContext: () => uiInteraction, getLastMessageId: () => lastMsgId },
209
+ * {
210
+ * name: "display_weather",
211
+ * description: "Show weather for a location",
212
+ * parameters: { type: "object", properties: { location: { type: "string" } } },
213
+ * displayType: "weather",
214
+ * execute: async (args) => fetchWeatherData(args.location),
215
+ * }
216
+ * );
217
+ * ```
218
+ */
219
+ declare function createDisplayTool<TArgs = any, TResult = any>(options: CreateUIToolsOptions, config: DisplayToolConfig<TArgs, TResult>): ToolConfig;
220
+
221
+ /**
222
+ * Chart display tool factory.
223
+ *
224
+ * Creates a client-side tool that renders bar, line, area, and pie charts
225
+ * inline in the chat. The tool validates the LLM-provided data and passes
226
+ * it through for rendering by the ChartCard component.
227
+ */
228
+
229
+ type ChartDataPoint = Record<string, string | number>;
230
+ type DisplayChartResult = {
231
+ chartType: "bar" | "line" | "area" | "pie";
232
+ title?: string;
233
+ data: ChartDataPoint[];
234
+ dataKeys: string[];
235
+ xAxisKey?: string;
236
+ colors?: Record<string, string>;
237
+ } | {
238
+ error: string;
239
+ };
240
+ /**
241
+ * Create a display_chart tool that renders charts inline in the chat.
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * import { createChartTool } from "@anuma/sdk/tools";
246
+ *
247
+ * const chartTool = createChartTool({
248
+ * getContext: () => uiInteraction,
249
+ * getLastMessageId: () => lastMsgId,
250
+ * });
251
+ * ```
252
+ */
253
+ declare function createChartTool(options: CreateUIToolsOptions): ToolConfig;
254
+
255
+ /**
256
+ * Google Drive tool definition for the chat system.
257
+ * This tool allows the LLM to search files in the user's Google Drive.
258
+ */
259
+
260
+ interface SearchFilesArgs {
261
+ query: string;
262
+ maxResults?: number;
263
+ mimeType?: string;
264
+ }
265
+ interface DriveFile {
266
+ id: string;
267
+ name: string;
268
+ mimeType: string;
269
+ webViewLink?: string;
270
+ modifiedTime?: string;
271
+ size?: string;
272
+ owners?: {
273
+ displayName: string;
274
+ emailAddress: string;
275
+ }[];
276
+ }
277
+ /**
278
+ * Creates the Google Drive search tool with access to the token getter.
279
+ * The token getter is captured in a closure so the executor can access it.
280
+ */
281
+ declare function createGoogleDriveSearchTool(getAccessToken: () => string | null, requestDriveAccess: () => Promise<string>): ToolConfig;
282
+ interface ListRecentFilesArgs {
283
+ maxResults?: number;
284
+ mimeType?: string;
285
+ }
286
+ /**
287
+ * Creates the Google Drive list recent files tool with access to the token getter.
288
+ */
289
+ declare function createGoogleDriveListRecentTool(getAccessToken: () => string | null, requestDriveAccess: () => Promise<string>): ToolConfig;
290
+ interface GetFileContentArgs {
291
+ fileId?: string;
292
+ fileName?: string;
293
+ }
294
+ /**
295
+ * Creates the Google Drive get file content tool
296
+ */
297
+ declare function createGoogleDriveGetContentTool(getAccessToken: () => string | null, requestDriveAccess: () => Promise<string>): ToolConfig;
298
+ /**
299
+ * Creates all Google Drive tools with the provided token context.
300
+ */
301
+ declare function createDriveTools(getAccessToken: () => string | null, requestDriveAccess: () => Promise<string>): ToolConfig[];
302
+
303
+ /**
304
+ * Notion MCP tool definitions for the chat system.
305
+ *
306
+ * These tools communicate with Notion's hosted MCP server using the
307
+ * Model Context Protocol (JSON-RPC 2.0). The MCP server handles all
308
+ * Notion API interactions - we just forward tool calls to it.
309
+ *
310
+ * MCP Server: https://mcp.notion.com/mcp (Streamable HTTP)
311
+ * Fallback: https://mcp.notion.com/sse (Server-Sent Events)
312
+ *
313
+ * @see https://developers.notion.com/guides/mcp/build-mcp-client
314
+ * @see https://modelcontextprotocol.io
315
+ */
316
+
317
+ interface NotionSearchArgs {
318
+ query: string;
319
+ query_type?: "internal" | "user";
320
+ filters?: Record<string, unknown>;
321
+ }
322
+ interface NotionFetchArgs {
323
+ id: string;
324
+ include_transcript?: boolean;
325
+ include_discussions?: boolean;
326
+ }
327
+ interface NotionCreatePagesArgs {
328
+ pages: Array<{
329
+ properties: Record<string, unknown>;
330
+ content: string;
331
+ }>;
332
+ parent?: Record<string, unknown>;
333
+ }
334
+ interface NotionUpdatePageArgs {
335
+ data: {
336
+ page_id: string;
337
+ command: string;
338
+ properties?: Record<string, unknown>;
339
+ new_str?: string;
340
+ selection_with_ellipsis?: string;
341
+ allow_deleting_content?: boolean;
342
+ };
343
+ }
344
+ interface NotionMovePagesArgs {
345
+ page_or_database_ids: string[];
346
+ new_parent: Record<string, unknown>;
347
+ }
348
+ /**
349
+ * MCP Tool: notion-search
350
+ * Semantic search over Notion workspace and connected sources, or user search
351
+ */
352
+ declare function createNotionSearchTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
353
+ /**
354
+ * MCP Tool: notion-fetch
355
+ * Retrieves details about a Notion entity (page or database) by URL or ID
356
+ */
357
+ declare function createNotionFetchTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
358
+ /**
359
+ * MCP Tool: notion-create-pages
360
+ * Creates one or more Notion pages with properties and content
361
+ */
362
+ declare function createNotionCreatePagesTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
363
+ /**
364
+ * MCP Tool: notion-update-page
365
+ * Update a page's properties or content using command-based operations
366
+ */
367
+ declare function createNotionUpdatePageTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
368
+ /**
369
+ * MCP Tool: notion-move-pages
370
+ * Move one or more pages/databases to a new parent
371
+ */
372
+ declare function createNotionMovePagesTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
373
+ /**
374
+ * MCP Tool: notion-duplicate-page
375
+ * Duplicate a Notion page (completes asynchronously)
376
+ */
377
+ declare function createNotionDuplicatePageTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
378
+ /**
379
+ * MCP Tool: notion-create-database
380
+ * Create a new Notion database with a properties schema
381
+ */
382
+ declare function createNotionCreateDatabaseTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
383
+ /**
384
+ * MCP Tool: notion-update-data-source
385
+ * Update a data source's properties, name, or other attributes
386
+ */
387
+ declare function createNotionUpdateDataSourceTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
388
+ /**
389
+ * MCP Tool: notion-create-comment
390
+ * Add a comment to a page, specific content, or reply to a discussion
391
+ */
392
+ declare function createNotionCreateCommentTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
393
+ /**
394
+ * MCP Tool: notion-get-comments
395
+ * Get comments and discussions from a Notion page
396
+ */
397
+ declare function createNotionGetCommentsTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
398
+ /**
399
+ * MCP Tool: notion-get-users
400
+ * List users in the workspace, get a specific user, or get self
401
+ */
402
+ declare function createNotionGetUsersTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
403
+ /**
404
+ * MCP Tool: notion-get-teams
405
+ * Retrieve teams (teamspaces) in the workspace
406
+ */
407
+ declare function createNotionGetTeamsTool(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig;
408
+ /**
409
+ * Create all Notion MCP tools
410
+ *
411
+ * Returns tools that communicate with Notion's hosted MCP server.
412
+ * The MCP server handles all Notion API interactions.
413
+ */
414
+ declare function createNotionTools(getAccessToken: () => string | null, requestNotionAccess: () => Promise<string>): ToolConfig[];
415
+ /**
416
+ * Get the MCP endpoints for direct access
417
+ */
418
+ declare function getMCPEndpoints(): {
419
+ http: string;
420
+ sse: string;
421
+ };
422
+ /**
423
+ * Call any MCP tool directly (for advanced use cases)
424
+ */
425
+ declare function callNotionMCPTool<T>(accessToken: string, toolName: string, args: Record<string, unknown>): Promise<T>;
426
+
427
+ export { type CalendarEvent, type ChartDataPoint, type CreateEventArgs, type CreateUIToolsOptions, type DisplayChartResult, type DisplayToolConfig, type DisplayToolMigrations, type DriveFile, type GetFileContentArgs, type InteractiveToolConfig, type ListEventsArgs, type ListRecentFilesArgs, type NotionCreatePagesArgs, type NotionFetchArgs, type NotionMovePagesArgs, type NotionSearchArgs, type NotionUpdatePageArgs, type SearchFilesArgs, type ToolConfig, type UIInteractionContext, type UpdateEventArgs, callNotionMCPTool, createChartTool, createChatTools, createDisplayTool, createDriveTools, createGoogleCalendarCreateEventTool, createGoogleCalendarTool, createGoogleCalendarUpdateEventTool, createGoogleDriveGetContentTool, createGoogleDriveListRecentTool, createGoogleDriveSearchTool, createInteractiveTool, createNotionCreateCommentTool, createNotionCreateDatabaseTool, createNotionCreatePagesTool, createNotionDuplicatePageTool, createNotionFetchTool, createNotionGetCommentsTool, createNotionGetTeamsTool, createNotionGetUsersTool, createNotionMovePagesTool, createNotionSearchTool, createNotionTools, createNotionUpdateDataSourceTool, createNotionUpdatePageTool, getMCPEndpoints, migrateDisplayResult };