@boostecom/provider 0.0.1

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 (70) hide show
  1. package/README.md +90 -0
  2. package/dist/index.cjs +2522 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +848 -0
  5. package/dist/index.d.ts +848 -0
  6. package/dist/index.js +2484 -0
  7. package/dist/index.js.map +1 -0
  8. package/docs/content/README.md +337 -0
  9. package/docs/content/agent-teams.mdx +324 -0
  10. package/docs/content/api.mdx +757 -0
  11. package/docs/content/best-practices.mdx +624 -0
  12. package/docs/content/examples.mdx +675 -0
  13. package/docs/content/guide.mdx +516 -0
  14. package/docs/content/index.mdx +99 -0
  15. package/docs/content/installation.mdx +246 -0
  16. package/docs/content/skills.mdx +548 -0
  17. package/docs/content/troubleshooting.mdx +588 -0
  18. package/docs/examples/README.md +499 -0
  19. package/docs/examples/abort-signal.ts +125 -0
  20. package/docs/examples/agent-teams.ts +122 -0
  21. package/docs/examples/basic-usage.ts +73 -0
  22. package/docs/examples/check-cli.ts +51 -0
  23. package/docs/examples/conversation-history.ts +69 -0
  24. package/docs/examples/custom-config.ts +90 -0
  25. package/docs/examples/generate-object-constraints.ts +209 -0
  26. package/docs/examples/generate-object.ts +211 -0
  27. package/docs/examples/hooks-callbacks.ts +63 -0
  28. package/docs/examples/images.ts +76 -0
  29. package/docs/examples/integration-test.ts +241 -0
  30. package/docs/examples/limitations.ts +150 -0
  31. package/docs/examples/logging-custom-logger.ts +99 -0
  32. package/docs/examples/logging-default.ts +55 -0
  33. package/docs/examples/logging-disabled.ts +74 -0
  34. package/docs/examples/logging-verbose.ts +64 -0
  35. package/docs/examples/long-running-tasks.ts +179 -0
  36. package/docs/examples/message-injection.ts +210 -0
  37. package/docs/examples/mid-stream-injection.ts +126 -0
  38. package/docs/examples/run-all-examples.sh +48 -0
  39. package/docs/examples/sdk-tools-callbacks.ts +49 -0
  40. package/docs/examples/skills-discovery.ts +144 -0
  41. package/docs/examples/skills-management.ts +140 -0
  42. package/docs/examples/stream-object.ts +80 -0
  43. package/docs/examples/streaming.ts +52 -0
  44. package/docs/examples/structured-output-repro.ts +227 -0
  45. package/docs/examples/tool-management.ts +215 -0
  46. package/docs/examples/tool-streaming.ts +132 -0
  47. package/docs/examples/zod4-compatibility-test.ts +290 -0
  48. package/docs/src/claude-code-language-model.test.ts +3883 -0
  49. package/docs/src/claude-code-language-model.ts +2586 -0
  50. package/docs/src/claude-code-provider.test.ts +97 -0
  51. package/docs/src/claude-code-provider.ts +179 -0
  52. package/docs/src/convert-to-claude-code-messages.images.test.ts +104 -0
  53. package/docs/src/convert-to-claude-code-messages.test.ts +193 -0
  54. package/docs/src/convert-to-claude-code-messages.ts +419 -0
  55. package/docs/src/errors.test.ts +213 -0
  56. package/docs/src/errors.ts +216 -0
  57. package/docs/src/index.test.ts +49 -0
  58. package/docs/src/index.ts +98 -0
  59. package/docs/src/logger.integration.test.ts +164 -0
  60. package/docs/src/logger.test.ts +184 -0
  61. package/docs/src/logger.ts +65 -0
  62. package/docs/src/map-claude-code-finish-reason.test.ts +120 -0
  63. package/docs/src/map-claude-code-finish-reason.ts +60 -0
  64. package/docs/src/mcp-helpers.test.ts +71 -0
  65. package/docs/src/mcp-helpers.ts +123 -0
  66. package/docs/src/message-injection.test.ts +460 -0
  67. package/docs/src/types.ts +447 -0
  68. package/docs/src/validation.test.ts +558 -0
  69. package/docs/src/validation.ts +360 -0
  70. package/package.json +124 -0
@@ -0,0 +1,447 @@
1
+ // Import types from the SDK
2
+ import type {
3
+ PermissionMode,
4
+ McpServerConfig,
5
+ CanUseTool,
6
+ SdkBeta,
7
+ SandboxSettings,
8
+ SdkPluginConfig,
9
+ Options,
10
+ SpawnedProcess,
11
+ SpawnOptions,
12
+ AgentMcpServerSpec,
13
+ Query,
14
+ } from '@anthropic-ai/claude-agent-sdk';
15
+
16
+ export type StreamingInputMode = 'auto' | 'always' | 'off';
17
+
18
+ /**
19
+ * Logger interface for custom logging.
20
+ * Allows consumers to provide their own logging implementation
21
+ * or disable logging entirely.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const customLogger: Logger = {
26
+ * debug: (message) => myLoggingService.debug(message),
27
+ * info: (message) => myLoggingService.info(message),
28
+ * warn: (message) => myLoggingService.warn(message),
29
+ * error: (message) => myLoggingService.error(message),
30
+ * };
31
+ * ```
32
+ */
33
+ export interface Logger {
34
+ /**
35
+ * Log a debug message. Only logged when verbose mode is enabled.
36
+ * Used for detailed execution tracing and troubleshooting.
37
+ */
38
+ debug: (message: string) => void;
39
+
40
+ /**
41
+ * Log an informational message. Only logged when verbose mode is enabled.
42
+ * Used for general execution flow information.
43
+ */
44
+ info: (message: string) => void;
45
+
46
+ /**
47
+ * Log a warning message.
48
+ */
49
+ warn: (message: string) => void;
50
+
51
+ /**
52
+ * Log an error message.
53
+ */
54
+ error: (message: string) => void;
55
+ }
56
+
57
+ /**
58
+ * Configuration settings for Claude Code SDK behavior.
59
+ * These settings control how the CLI executes, what permissions it has,
60
+ * and which tools are available during conversations.
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const settings: ClaudeCodeSettings = {
65
+ * maxTurns: 10,
66
+ * permissionMode: 'auto',
67
+ * cwd: '/path/to/project',
68
+ * allowedTools: ['Read', 'LS'],
69
+ * disallowedTools: ['Bash(rm:*)']
70
+ * };
71
+ * ```
72
+ */
73
+ export interface ClaudeCodeSettings {
74
+ /**
75
+ * Custom path to Claude Code SDK executable
76
+ * @default 'claude' (uses system PATH)
77
+ */
78
+ pathToClaudeCodeExecutable?: string;
79
+
80
+ /**
81
+ * Custom system prompt to use
82
+ */
83
+ customSystemPrompt?: string;
84
+
85
+ /**
86
+ * Append additional content to the system prompt
87
+ */
88
+ appendSystemPrompt?: string;
89
+
90
+ /**
91
+ * Agent SDK system prompt configuration. Preferred over legacy fields.
92
+ * - string: custom system prompt
93
+ * - preset object: Claude Code preset, with optional append
94
+ */
95
+ systemPrompt?: string | { type: 'preset'; preset: 'claude_code'; append?: string };
96
+
97
+ /**
98
+ * Maximum number of turns for the conversation
99
+ */
100
+ maxTurns?: number;
101
+
102
+ /**
103
+ * Maximum thinking tokens for the model
104
+ */
105
+ maxThinkingTokens?: number;
106
+
107
+ /**
108
+ * Working directory for CLI operations
109
+ */
110
+ cwd?: string;
111
+
112
+ /**
113
+ * JavaScript runtime to use
114
+ * @default 'node' (or 'bun' if Bun is detected)
115
+ */
116
+ executable?: 'bun' | 'deno' | 'node';
117
+
118
+ /**
119
+ * Additional arguments for the JavaScript runtime
120
+ */
121
+ executableArgs?: string[];
122
+
123
+ /**
124
+ * Permission mode for tool usage
125
+ * @default 'default'
126
+ */
127
+ permissionMode?: PermissionMode;
128
+
129
+ /**
130
+ * Custom tool name for permission prompts
131
+ */
132
+ permissionPromptToolName?: string;
133
+
134
+ /**
135
+ * Continue the most recent conversation
136
+ */
137
+ continue?: boolean;
138
+
139
+ /**
140
+ * Resume a specific session by ID
141
+ */
142
+ resume?: string;
143
+
144
+ /**
145
+ * Use a specific session ID for this query.
146
+ * Allows deterministic session identifiers for tracking and correlation.
147
+ */
148
+ sessionId?: string;
149
+
150
+ /**
151
+ * Tools to explicitly allow during execution
152
+ * Examples: ['Read', 'LS', 'Bash(git log:*)']
153
+ */
154
+ allowedTools?: string[];
155
+
156
+ /**
157
+ * Tools to disallow during execution
158
+ * Examples: ['Write', 'Edit', 'Bash(rm:*)']
159
+ */
160
+ disallowedTools?: string[];
161
+
162
+ /**
163
+ * Enable Agent SDK beta features.
164
+ */
165
+ betas?: SdkBeta[];
166
+
167
+ /**
168
+ * Allow bypassing permissions when using permissionMode: 'bypassPermissions'.
169
+ */
170
+ allowDangerouslySkipPermissions?: boolean;
171
+
172
+ /**
173
+ * Enable file checkpointing for rewind support.
174
+ */
175
+ enableFileCheckpointing?: boolean;
176
+
177
+ /**
178
+ * Maximum budget in USD for the query.
179
+ */
180
+ maxBudgetUsd?: number;
181
+
182
+ /**
183
+ * Load custom plugins from local paths.
184
+ */
185
+ plugins?: SdkPluginConfig[];
186
+
187
+ /**
188
+ * Resume session at a specific message UUID.
189
+ */
190
+ resumeSessionAt?: string;
191
+
192
+ /**
193
+ * Configure sandbox behavior programmatically.
194
+ */
195
+ sandbox?: SandboxSettings;
196
+
197
+ /**
198
+ * Tool configuration (array of tool names or Claude Code preset).
199
+ */
200
+ tools?: Options['tools'];
201
+
202
+ /**
203
+ * MCP server configuration
204
+ */
205
+ mcpServers?: Record<string, McpServerConfig>;
206
+
207
+ /**
208
+ * Filesystem settings sources to load (CLAUDE.md, settings.json, etc.)
209
+ * When omitted, the Agent SDK loads no filesystem settings.
210
+ *
211
+ * Required for Skills support - skills are loaded from these sources.
212
+ * @example ['user', 'project']
213
+ */
214
+ settingSources?: Array<'user' | 'project' | 'local'>;
215
+
216
+ /**
217
+ * Hook callbacks for lifecycle events (e.g., PreToolUse, PostToolUse).
218
+ * Note: typed loosely to support multiple SDK versions.
219
+ */
220
+ hooks?: Partial<
221
+ Record<
222
+ string,
223
+ Array<{ matcher?: string; hooks: Array<(...args: unknown[]) => Promise<unknown>> }>
224
+ >
225
+ >;
226
+
227
+ /**
228
+ * Dynamic permission callback invoked before a tool is executed.
229
+ * Allows runtime approval/denial and optional input mutation.
230
+ */
231
+ canUseTool?: CanUseTool;
232
+
233
+ /**
234
+ * Controls whether to send streaming input to the SDK (enables canUseTool).
235
+ * - 'auto' (default): stream when canUseTool is provided
236
+ * - 'always': always stream
237
+ * - 'off': never stream (legacy behavior)
238
+ */
239
+ streamingInput?: StreamingInputMode;
240
+
241
+ /**
242
+ * Enable verbose logging for debugging
243
+ */
244
+ verbose?: boolean;
245
+
246
+ /**
247
+ * Enable programmatic debug logging from the SDK.
248
+ */
249
+ debug?: boolean;
250
+
251
+ /**
252
+ * Path to a file for SDK debug log output.
253
+ */
254
+ debugFile?: string;
255
+
256
+ /**
257
+ * Custom logger for handling warnings and errors.
258
+ * - Set to `false` to disable all logging
259
+ * - Provide a Logger object to use custom logging
260
+ * - Leave undefined to use console (default)
261
+ *
262
+ * @default console
263
+ * @example
264
+ * ```typescript
265
+ * // Disable logging
266
+ * const settings = { logger: false };
267
+ *
268
+ * // Custom logger
269
+ * const settings = {
270
+ * logger: {
271
+ * warn: (msg) => myLogger.warn(msg),
272
+ * error: (msg) => myLogger.error(msg),
273
+ * }
274
+ * };
275
+ * ```
276
+ */
277
+ logger?: Logger | false;
278
+
279
+ /**
280
+ * Environment variables to set
281
+ */
282
+ env?: Record<string, string | undefined>;
283
+
284
+ /**
285
+ * Additional directories Claude can access.
286
+ */
287
+ additionalDirectories?: string[];
288
+
289
+ /**
290
+ * Programmatically defined subagents.
291
+ */
292
+ agents?: Record<
293
+ string,
294
+ {
295
+ /** Natural language description of when to use this agent */
296
+ description: string;
297
+ /** Array of allowed tool names. If omitted, inherits all tools from parent */
298
+ tools?: string[];
299
+ /** Array of tool names to explicitly disallow for this agent */
300
+ disallowedTools?: string[];
301
+ /** The agent's system prompt */
302
+ prompt: string;
303
+ /** Model to use for this agent. If omitted or 'inherit', uses the main model */
304
+ model?: 'sonnet' | 'opus' | 'haiku' | 'inherit';
305
+ /** MCP servers available to this agent (server names or inline configs) */
306
+ mcpServers?: AgentMcpServerSpec[];
307
+ /** Experimental: Critical reminder added to system prompt */
308
+ criticalSystemReminder_EXPERIMENTAL?: string;
309
+ }
310
+ >;
311
+
312
+ /**
313
+ * Include partial message events from the SDK stream.
314
+ */
315
+ includePartialMessages?: boolean;
316
+
317
+ /**
318
+ * Model to use if primary fails.
319
+ */
320
+ fallbackModel?: string;
321
+
322
+ /**
323
+ * When resuming, fork to a new session ID instead of continuing the original.
324
+ */
325
+ forkSession?: boolean;
326
+
327
+ /**
328
+ * Callback for stderr output from the underlying process.
329
+ */
330
+ stderr?: (data: string) => void;
331
+
332
+ /**
333
+ * Enforce strict MCP validation.
334
+ */
335
+ strictMcpConfig?: boolean;
336
+
337
+ /**
338
+ * Additional CLI arguments.
339
+ */
340
+ extraArgs?: Record<string, string | null>;
341
+
342
+ /**
343
+ * When false, disables session persistence to disk.
344
+ * Sessions will not be saved to ~/.claude/projects/ and cannot be resumed later.
345
+ * Useful for ephemeral or automated workflows where session history is not needed.
346
+ * @default true
347
+ */
348
+ persistSession?: boolean;
349
+
350
+ /**
351
+ * Custom function to spawn the Claude Code process.
352
+ * Use this to run Claude Code in VMs, containers, or remote environments.
353
+ */
354
+ spawnClaudeCodeProcess?: (options: SpawnOptions) => SpawnedProcess;
355
+
356
+ /**
357
+ * Escape hatch for Agent SDK options. Overrides explicit settings.
358
+ * Provider-managed fields (e.g. model, abortController, prompt, outputFormat)
359
+ * are ignored if supplied here.
360
+ */
361
+ sdkOptions?: Partial<Options>;
362
+
363
+ /**
364
+ * Maximum size (in characters) for tool results sent to the client stream.
365
+ * The interior Claude Code process retains full data; this only affects client stream.
366
+ * Tool results exceeding this size will be truncated with a `...[truncated N chars]` suffix.
367
+ * @default 10000
368
+ */
369
+ maxToolResultSize?: number;
370
+
371
+ /**
372
+ * Callback invoked when the Query object is created.
373
+ * Use this to access the Query for advanced features like mid-stream
374
+ * message injection via `query.streamInput()`.
375
+ *
376
+ * @example
377
+ * ```typescript
378
+ * const model = claudeCode('sonnet', {
379
+ * onQueryCreated: (query) => {
380
+ * // Store query for later injection
381
+ * myQueryStore.set(sessionId, query);
382
+ * }
383
+ * });
384
+ * ```
385
+ */
386
+ onQueryCreated?: (query: Query) => void;
387
+
388
+ /**
389
+ * Callback invoked when streaming input mode starts.
390
+ * Provides a MessageInjector that can be used to inject messages mid-session.
391
+ *
392
+ * This enables supervisor patterns where you can redirect or interrupt
393
+ * the agent during execution.
394
+ *
395
+ * @example
396
+ * ```typescript
397
+ * const model = claudeCode("haiku", {
398
+ * streamingInput: "always",
399
+ * onStreamStart: (injector) => {
400
+ * // Store the injector for later use
401
+ * supervisorInjector = injector;
402
+ * }
403
+ * });
404
+ *
405
+ * // Later, inject a message mid-session:
406
+ * supervisorInjector.inject("STOP! Change of plans...");
407
+ * ```
408
+ */
409
+ onStreamStart?: (injector: MessageInjector) => void;
410
+ }
411
+
412
+ /**
413
+ * Controller for injecting messages into an active Claude Code session.
414
+ * Obtained via the onStreamStart callback.
415
+ */
416
+ export interface MessageInjector {
417
+ /**
418
+ * Inject a user message into the current session.
419
+ * The message will be queued and sent to the agent mid-turn.
420
+ *
421
+ * @param content - The message content to inject
422
+ * @param onResult - Optional callback invoked when delivery status is known:
423
+ * - `delivered: true` if the message was sent to the agent
424
+ * - `delivered: false` if the session ended before the message could be delivered
425
+ *
426
+ * @example
427
+ * ```typescript
428
+ * // Fire-and-forget
429
+ * injector.inject("STOP! Cancel the current task.");
430
+ *
431
+ * // With delivery tracking
432
+ * injector.inject("Change of plans!", (delivered) => {
433
+ * if (!delivered) {
434
+ * console.log("Message not delivered - session ended first");
435
+ * // Handle retry via session resume, etc.
436
+ * }
437
+ * });
438
+ * ```
439
+ */
440
+ inject(content: string, onResult?: (delivered: boolean) => void): void;
441
+
442
+ /**
443
+ * Signal that no more messages will be injected.
444
+ * Call this when the session should be allowed to complete normally.
445
+ */
446
+ close(): void;
447
+ }