@sourcegraph/amp-sdk 0.1.0-20251014160341-g7c5de51 → 0.1.0-20251021152627-g8658f12
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.
- package/README.md +32 -0
- package/dist/index.d.ts +9 -10
- package/dist/index.js +4301 -269
- package/dist/types.d.ts +100 -8
- package/package.json +4 -4
- package/dist/types.js +0 -64
package/dist/types.d.ts
CHANGED
|
@@ -91,7 +91,9 @@ export interface ErrorResultMessage extends BaseResultMessage {
|
|
|
91
91
|
is_error: true;
|
|
92
92
|
error: string;
|
|
93
93
|
}
|
|
94
|
+
/** Union of all possible stream messages */
|
|
94
95
|
export type StreamMessage = SystemMessage | AssistantMessage | UserMessage | ResultMessage | ErrorResultMessage;
|
|
96
|
+
/** User input message schema */
|
|
95
97
|
export declare const UserInputMessageSchema: z.ZodObject<{
|
|
96
98
|
type: z.ZodLiteral<"user">;
|
|
97
99
|
message: z.ZodObject<{
|
|
@@ -138,6 +140,51 @@ export declare const UserInputMessageSchema: z.ZodObject<{
|
|
|
138
140
|
};
|
|
139
141
|
type: "user";
|
|
140
142
|
}>;
|
|
143
|
+
/** User input message for streaming conversations */
|
|
144
|
+
export type UserInputMessage = z.infer<typeof UserInputMessageSchema>;
|
|
145
|
+
/** Recursive type for permission match conditions */
|
|
146
|
+
export type PermissionMatchCondition = string | PermissionMatchCondition[] | {
|
|
147
|
+
[key in string]: PermissionMatchCondition;
|
|
148
|
+
} | boolean | number | null | undefined;
|
|
149
|
+
/** Permission match condition for tool arguments schema */
|
|
150
|
+
export declare const PermissionMatchConditionSchema: z.ZodType<PermissionMatchCondition>;
|
|
151
|
+
/** Individual permission schema */
|
|
152
|
+
export declare const PermissionSchema: z.ZodEffects<z.ZodObject<{
|
|
153
|
+
tool: z.ZodString;
|
|
154
|
+
matches: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<PermissionMatchCondition, z.ZodTypeDef, PermissionMatchCondition>>>;
|
|
155
|
+
action: z.ZodEnum<["allow", "reject", "ask", "delegate"]>;
|
|
156
|
+
context: z.ZodOptional<z.ZodEnum<["thread", "subagent"]>>;
|
|
157
|
+
to: z.ZodOptional<z.ZodString>;
|
|
158
|
+
}, "strip", z.ZodTypeAny, {
|
|
159
|
+
tool: string;
|
|
160
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
161
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
162
|
+
context?: "thread" | "subagent" | undefined;
|
|
163
|
+
to?: string | undefined;
|
|
164
|
+
}, {
|
|
165
|
+
tool: string;
|
|
166
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
167
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
168
|
+
context?: "thread" | "subagent" | undefined;
|
|
169
|
+
to?: string | undefined;
|
|
170
|
+
}>, {
|
|
171
|
+
tool: string;
|
|
172
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
173
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
174
|
+
context?: "thread" | "subagent" | undefined;
|
|
175
|
+
to?: string | undefined;
|
|
176
|
+
}, {
|
|
177
|
+
tool: string;
|
|
178
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
179
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
180
|
+
context?: "thread" | "subagent" | undefined;
|
|
181
|
+
to?: string | undefined;
|
|
182
|
+
}>;
|
|
183
|
+
/** Permission */
|
|
184
|
+
export type Permission = z.infer<typeof PermissionSchema>;
|
|
185
|
+
/** Permissions list */
|
|
186
|
+
export type PermissionsList = Permission[];
|
|
187
|
+
/** MCP server configuration schema */
|
|
141
188
|
export declare const MCPServerSchema: z.ZodObject<{
|
|
142
189
|
command: z.ZodString;
|
|
143
190
|
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -151,6 +198,7 @@ export declare const MCPServerSchema: z.ZodObject<{
|
|
|
151
198
|
args?: string[] | undefined;
|
|
152
199
|
env?: Record<string, string> | undefined;
|
|
153
200
|
}>;
|
|
201
|
+
/** MCP configuration schema */
|
|
154
202
|
export declare const MCPConfigSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
155
203
|
command: z.ZodString;
|
|
156
204
|
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -164,6 +212,11 @@ export declare const MCPConfigSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
|
164
212
|
args?: string[] | undefined;
|
|
165
213
|
env?: Record<string, string> | undefined;
|
|
166
214
|
}>>;
|
|
215
|
+
/** MCP server configuration */
|
|
216
|
+
export type MCPServer = z.infer<typeof MCPServerSchema>;
|
|
217
|
+
/** MCP configuration object */
|
|
218
|
+
export type MCPConfig = z.infer<typeof MCPConfigSchema>;
|
|
219
|
+
/** Configuration options for Amp execution schema */
|
|
167
220
|
export declare const AmpOptionsSchema: z.ZodObject<{
|
|
168
221
|
cwd: z.ZodOptional<z.ZodString>;
|
|
169
222
|
dangerouslyAllowAll: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -187,6 +240,37 @@ export declare const AmpOptionsSchema: z.ZodObject<{
|
|
|
187
240
|
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
188
241
|
continue: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodString]>>;
|
|
189
242
|
toolbox: z.ZodOptional<z.ZodString>;
|
|
243
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
244
|
+
tool: z.ZodString;
|
|
245
|
+
matches: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<PermissionMatchCondition, z.ZodTypeDef, PermissionMatchCondition>>>;
|
|
246
|
+
action: z.ZodEnum<["allow", "reject", "ask", "delegate"]>;
|
|
247
|
+
context: z.ZodOptional<z.ZodEnum<["thread", "subagent"]>>;
|
|
248
|
+
to: z.ZodOptional<z.ZodString>;
|
|
249
|
+
}, "strip", z.ZodTypeAny, {
|
|
250
|
+
tool: string;
|
|
251
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
252
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
253
|
+
context?: "thread" | "subagent" | undefined;
|
|
254
|
+
to?: string | undefined;
|
|
255
|
+
}, {
|
|
256
|
+
tool: string;
|
|
257
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
258
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
259
|
+
context?: "thread" | "subagent" | undefined;
|
|
260
|
+
to?: string | undefined;
|
|
261
|
+
}>, {
|
|
262
|
+
tool: string;
|
|
263
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
264
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
265
|
+
context?: "thread" | "subagent" | undefined;
|
|
266
|
+
to?: string | undefined;
|
|
267
|
+
}, {
|
|
268
|
+
tool: string;
|
|
269
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
270
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
271
|
+
context?: "thread" | "subagent" | undefined;
|
|
272
|
+
to?: string | undefined;
|
|
273
|
+
}>, "many">>;
|
|
190
274
|
}, "strict", z.ZodTypeAny, {
|
|
191
275
|
env?: Record<string, string> | undefined;
|
|
192
276
|
cwd?: string | undefined;
|
|
@@ -202,6 +286,13 @@ export declare const AmpOptionsSchema: z.ZodObject<{
|
|
|
202
286
|
}> | undefined;
|
|
203
287
|
continue?: string | boolean | undefined;
|
|
204
288
|
toolbox?: string | undefined;
|
|
289
|
+
permissions?: {
|
|
290
|
+
tool: string;
|
|
291
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
292
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
293
|
+
context?: "thread" | "subagent" | undefined;
|
|
294
|
+
to?: string | undefined;
|
|
295
|
+
}[] | undefined;
|
|
205
296
|
}, {
|
|
206
297
|
env?: Record<string, string> | undefined;
|
|
207
298
|
cwd?: string | undefined;
|
|
@@ -217,18 +308,19 @@ export declare const AmpOptionsSchema: z.ZodObject<{
|
|
|
217
308
|
}> | undefined;
|
|
218
309
|
continue?: string | boolean | undefined;
|
|
219
310
|
toolbox?: string | undefined;
|
|
311
|
+
permissions?: {
|
|
312
|
+
tool: string;
|
|
313
|
+
action: "allow" | "reject" | "ask" | "delegate";
|
|
314
|
+
matches?: Record<string, PermissionMatchCondition> | undefined;
|
|
315
|
+
context?: "thread" | "subagent" | undefined;
|
|
316
|
+
to?: string | undefined;
|
|
317
|
+
}[] | undefined;
|
|
220
318
|
}>;
|
|
221
|
-
/**
|
|
222
|
-
export type UserInputMessage = z.infer<typeof UserInputMessageSchema>;
|
|
223
|
-
/** MCP server configuration */
|
|
224
|
-
export type MCPServer = z.infer<typeof MCPServerSchema>;
|
|
225
|
-
/** MCP configuration object */
|
|
226
|
-
export type MCPConfig = z.infer<typeof MCPConfigSchema>;
|
|
227
|
-
/** Configuration options for Amp CLI execution */
|
|
319
|
+
/** Configuration options for Amp execution */
|
|
228
320
|
export type AmpOptions = z.infer<typeof AmpOptionsSchema>;
|
|
229
321
|
/** Input type for prompts - either a string or streaming user messages */
|
|
230
322
|
type PromptInput = string | AsyncIterable<UserInputMessage>;
|
|
231
|
-
/** Options for executing Amp
|
|
323
|
+
/** Options for executing Amp commands */
|
|
232
324
|
export interface ExecuteOptions {
|
|
233
325
|
prompt: PromptInput;
|
|
234
326
|
options?: AmpOptions;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"email": "amp-devs@sourcegraph.com"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@sourcegraph/amp": "
|
|
7
|
+
"@sourcegraph/amp": "latest",
|
|
8
8
|
"zod": "^3.23.8"
|
|
9
9
|
},
|
|
10
10
|
"description": "TypeScript SDK for Amp CLI - Build custom AI agents with Amp's capabilities",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
},
|
|
45
45
|
"type": "module",
|
|
46
46
|
"types": "dist/index.d.ts",
|
|
47
|
-
"version": "0.1.0-
|
|
47
|
+
"version": "0.1.0-20251021152627-g8658f12",
|
|
48
48
|
"scripts": {
|
|
49
|
-
"build": "
|
|
49
|
+
"build": "bun run scripts/build.ts",
|
|
50
50
|
"dev": "pnpm exec tsc -b --watch",
|
|
51
51
|
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
52
|
-
"examples:basic": "pnpm run build && bun run examples/basic
|
|
52
|
+
"examples:basic": "pnpm run build && bun run examples/basic.ts",
|
|
53
53
|
"test": "vitest run",
|
|
54
54
|
"test:watch": "vitest",
|
|
55
55
|
"pin-cli-version": "bun run scripts/pin-cli-version.ts"
|
package/dist/types.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TypeScript SDK types for Amp CLI
|
|
3
|
-
*
|
|
4
|
-
* These types are compatible with the Amp CLI --stream-json output.
|
|
5
|
-
*/
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
// ============================================================================
|
|
8
|
-
// Validation Schemas (defined to derive interfaces from)
|
|
9
|
-
// ============================================================================
|
|
10
|
-
export const UserInputMessageSchema = z.object({
|
|
11
|
-
type: z.literal('user'),
|
|
12
|
-
message: z.object({
|
|
13
|
-
role: z.literal('user'),
|
|
14
|
-
content: z.array(z.object({
|
|
15
|
-
type: z.literal('text'),
|
|
16
|
-
text: z.string(),
|
|
17
|
-
})),
|
|
18
|
-
}),
|
|
19
|
-
});
|
|
20
|
-
export const MCPServerSchema = z.object({
|
|
21
|
-
command: z.string().describe('Command to run the MCP server'),
|
|
22
|
-
args: z.array(z.string()).describe('Arguments for the MCP server command').optional(),
|
|
23
|
-
env: z
|
|
24
|
-
.record(z.string(), z.string())
|
|
25
|
-
.describe('Environment variables for the server')
|
|
26
|
-
.optional(),
|
|
27
|
-
});
|
|
28
|
-
export const MCPConfigSchema = z
|
|
29
|
-
.record(z.string(), MCPServerSchema)
|
|
30
|
-
.describe('MCP server configurations keyed by server name');
|
|
31
|
-
export const AmpOptionsSchema = z
|
|
32
|
-
.object({
|
|
33
|
-
cwd: z.string().describe('Current working directory').optional(),
|
|
34
|
-
dangerouslyAllowAll: z
|
|
35
|
-
.boolean()
|
|
36
|
-
.describe('Allow all tool usage without asking for permission')
|
|
37
|
-
.optional(),
|
|
38
|
-
visibility: z
|
|
39
|
-
.enum(['private', 'public', 'workspace', 'group'])
|
|
40
|
-
.describe('Visibility level for new threads')
|
|
41
|
-
.default('workspace')
|
|
42
|
-
.optional(),
|
|
43
|
-
settingsFile: z.string().describe('Settings file path').optional(),
|
|
44
|
-
logLevel: z
|
|
45
|
-
.enum(['debug', 'info', 'warn', 'error', 'audit'])
|
|
46
|
-
.describe('Log level')
|
|
47
|
-
.optional(),
|
|
48
|
-
logFile: z.string().describe('Log file path').optional(),
|
|
49
|
-
mcpConfig: z
|
|
50
|
-
.union([z.string(), MCPConfigSchema])
|
|
51
|
-
.describe('MCP server configuration as JSON string, path to JSON file, or config object')
|
|
52
|
-
.optional(),
|
|
53
|
-
env: z
|
|
54
|
-
.record(z.string(), z.string())
|
|
55
|
-
.describe('Additional environment variables')
|
|
56
|
-
.optional(),
|
|
57
|
-
continue: z
|
|
58
|
-
.union([z.boolean(), z.string()])
|
|
59
|
-
.describe('Continue the most recent thread (true) or a specific thread by ID (string)')
|
|
60
|
-
.optional(),
|
|
61
|
-
toolbox: z.string().describe('Folder path with toolbox scripts').optional(),
|
|
62
|
-
})
|
|
63
|
-
.strict();
|
|
64
|
-
//# sourceMappingURL=types.js.map
|