@r-cli/sdk 1.0.112 → 1.0.114

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 (2) hide show
  1. package/package.json +7 -3
  2. package/sdk.d.ts +206 -0
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "@r-cli/sdk",
3
- "version": "1.0.112",
3
+ "version": "1.0.114",
4
4
  "description": "SDK for Claude Tools with tool, query, and createSdkMcpServer exports",
5
5
  "type": "module",
6
6
  "main": "./sdk.mjs",
7
+ "types": "./sdk.d.ts",
7
8
  "exports": {
8
- ".": "./sdk.mjs"
9
+ ".": {
10
+ "import": "./sdk.mjs",
11
+ "types": "./sdk.d.ts"
12
+ }
9
13
  },
10
14
  "files": [
11
15
  "sdk.mjs",
16
+ "sdk.d.ts",
12
17
  "README.md"
13
18
  ],
14
19
  "keywords": [
@@ -31,4 +36,3 @@
31
36
  "access": "public"
32
37
  }
33
38
  }
34
-
package/sdk.d.ts ADDED
@@ -0,0 +1,206 @@
1
+ /**
2
+ * JSON Schema type for tool input/output schemas
3
+ */
4
+ export interface JsonSchema {
5
+ type: "object";
6
+ properties?: Record<string, unknown>;
7
+ required?: string[];
8
+ [key: string]: unknown;
9
+ }
10
+
11
+ /**
12
+ * Tool definition
13
+ */
14
+ export interface ToolDefinition {
15
+ name: string;
16
+ description: string;
17
+ inputSchema: JsonSchema;
18
+ handler: (args: Record<string, unknown>) => Promise<unknown> | unknown;
19
+ }
20
+
21
+ /**
22
+ * MCP Server instance returned by createSdkMcpServer
23
+ */
24
+ export interface McpServerInstance {
25
+ type: "sdk";
26
+ name: string;
27
+ instance: unknown; // McpServer instance
28
+ }
29
+
30
+ /**
31
+ * Options for createSdkMcpServer
32
+ */
33
+ export interface CreateSdkMcpServerOptions {
34
+ name: string;
35
+ version?: string;
36
+ tools?: ToolDefinition[];
37
+ }
38
+
39
+ /**
40
+ * Options for canUseTool callback
41
+ */
42
+ export interface CanUseToolOptions {
43
+ signal: AbortSignal;
44
+ suggestions?: string[];
45
+ }
46
+
47
+ /**
48
+ * Hook callback function
49
+ */
50
+ export type HookCallback = (
51
+ input: unknown,
52
+ toolUseID: string,
53
+ options: { signal: AbortSignal }
54
+ ) => Promise<unknown> | unknown;
55
+
56
+ /**
57
+ * Hook matcher configuration
58
+ */
59
+ export interface HookMatcher {
60
+ matcher: unknown;
61
+ hooks: HookCallback[];
62
+ }
63
+
64
+ /**
65
+ * Hooks configuration - maps event names to arrays of matchers
66
+ */
67
+ export type HooksConfig = Record<string, HookMatcher[]>;
68
+
69
+ /**
70
+ * Query options
71
+ */
72
+ export interface QueryOptions {
73
+ abortController?: AbortController;
74
+ additionalDirectories?: string[];
75
+ allowedTools?: string[];
76
+ appendSystemPrompt?: string;
77
+ canUseTool?: (
78
+ toolName: string,
79
+ input: Record<string, unknown>,
80
+ options: CanUseToolOptions
81
+ ) => Promise<boolean> | boolean;
82
+ continue?: boolean;
83
+ customSystemPrompt?: string;
84
+ cwd?: string;
85
+ disallowedTools?: string[];
86
+ env?: Record<string, string>;
87
+ executable?: string;
88
+ executableArgs?: string[];
89
+ extraArgs?: Record<string, unknown>;
90
+ fallbackModel?: string;
91
+ hooks?: HooksConfig;
92
+ includePartialMessages?: boolean;
93
+ maxTurns?: number;
94
+ mcpServers?: Record<string, McpServerInstance | unknown>;
95
+ model?: string;
96
+ pathToClaudeCodeExecutable?: string;
97
+ permissionMode?: string;
98
+ permissionPromptToolName?: string;
99
+ resume?: unknown;
100
+ stderr?: NodeJS.WriteStream;
101
+ strictMcpConfig?: boolean;
102
+ }
103
+
104
+ /**
105
+ * Query function parameters
106
+ */
107
+ export interface QueryParams {
108
+ prompt: string | AsyncIterable<string>;
109
+ options?: QueryOptions;
110
+ }
111
+
112
+ /**
113
+ * SDK message type (simplified - actual implementation may have more specific types)
114
+ */
115
+ export type SdkMessage = unknown;
116
+
117
+ /**
118
+ * Query instance returned by query function
119
+ *
120
+ * The Query instance is an async iterable, so you can use it in for-await-of loops:
121
+ * ```typescript
122
+ * for await (const message of query({ prompt: "..." })) {
123
+ * // process message
124
+ * }
125
+ * ```
126
+ */
127
+ export interface QueryInstance extends AsyncIterable<SdkMessage> {
128
+ /**
129
+ * Stream input messages to the query
130
+ * @param stream - Async iterable of messages to stream
131
+ */
132
+ streamInput(stream: AsyncIterable<string>): Promise<void>;
133
+
134
+ /**
135
+ * Interrupt the current query operation
136
+ */
137
+ interrupt(): Promise<void>;
138
+
139
+ /**
140
+ * Set the permission mode
141
+ * @param mode - Permission mode string
142
+ */
143
+ setPermissionMode(mode: string): Promise<void>;
144
+
145
+ /**
146
+ * Set the model to use
147
+ * @param model - Model name/identifier
148
+ */
149
+ setModel(model: string): Promise<void>;
150
+
151
+ /**
152
+ * Get supported commands (only available in streaming mode)
153
+ * @returns Array of supported command names
154
+ */
155
+ supportedCommands(): Promise<string[]>;
156
+
157
+ /**
158
+ * Get supported models (only available in streaming mode)
159
+ * @returns Array of supported model names
160
+ */
161
+ supportedModels(): Promise<string[]>;
162
+
163
+ /**
164
+ * Async iterator methods
165
+ */
166
+ next(value?: unknown): Promise<IteratorResult<SdkMessage>>;
167
+ return(value?: unknown): Promise<IteratorResult<SdkMessage>>;
168
+ throw(e?: unknown): Promise<IteratorResult<SdkMessage>>;
169
+
170
+ /**
171
+ * Async iterator symbol
172
+ */
173
+ [Symbol.asyncIterator](): AsyncIterator<SdkMessage>;
174
+ }
175
+
176
+ /**
177
+ * Creates a tool definition
178
+ * @param name - Tool name
179
+ * @param description - Tool description
180
+ * @param inputSchema - JSON schema for tool input
181
+ * @param handler - Handler function that processes tool calls
182
+ * @returns Tool definition object
183
+ */
184
+ export function tool(
185
+ name: string,
186
+ description: string,
187
+ inputSchema: JsonSchema,
188
+ handler: (args: Record<string, unknown>) => Promise<unknown> | unknown
189
+ ): ToolDefinition;
190
+
191
+ /**
192
+ * Creates an SDK MCP server
193
+ * @param options - Server configuration options
194
+ * @returns MCP server instance
195
+ */
196
+ export function createSdkMcpServer(
197
+ options: CreateSdkMcpServerOptions
198
+ ): McpServerInstance;
199
+
200
+ /**
201
+ * Creates a query instance for tool operations
202
+ * @param params - Query parameters including prompt and options
203
+ * @returns Query instance
204
+ */
205
+ export function query(params: QueryParams): QueryInstance;
206
+