anyclaude-sdk 0.4.1 → 0.4.3
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 +22 -0
- package/dist/agent.js +3 -3
- package/dist/skills/define.d.ts +24 -0
- package/dist/skills/define.js +29 -0
- package/dist/skills/index.d.ts +1 -0
- package/dist/skills/index.js +1 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -277,6 +277,28 @@ await fs.writeFile('/app/index.ts', 'export const x = 1')
|
|
|
277
277
|
const workspace = composeWorkspace(fs, new NoopCommandExecutor())
|
|
278
278
|
```
|
|
279
279
|
|
|
280
|
+
## Skills (programmatic)
|
|
281
|
+
|
|
282
|
+
Declare reusable prompt-skills inline — each becomes a `/name` slash command and is invokable by the agent through the `skill` tool. `$ARGUMENTS` is substituted at call time:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
import { query, defineSkill } from 'anyclaude-sdk'
|
|
286
|
+
|
|
287
|
+
query({
|
|
288
|
+
prompt, workspace, llm,
|
|
289
|
+
skills: [
|
|
290
|
+
defineSkill({
|
|
291
|
+
name: 'changelog',
|
|
292
|
+
description: 'Summarize git changes into a changelog entry',
|
|
293
|
+
instructions: 'Write a concise changelog entry for: $ARGUMENTS',
|
|
294
|
+
argumentHint: '<since>',
|
|
295
|
+
}),
|
|
296
|
+
],
|
|
297
|
+
})
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
You can also pass plain `Skill` objects, or `skills: true` to load `.claude/skills/*.md` from the workspace.
|
|
301
|
+
|
|
280
302
|
## Serverless & the "survivor"
|
|
281
303
|
|
|
282
304
|
Run `query()` in a serverless function and stream `SDKMessage`s to the browser. For runs longer than the platform's time cap, checkpoint at a turn boundary and continue transparently in a fresh invocation:
|
package/dist/agent.js
CHANGED
|
@@ -12,7 +12,7 @@ import { ALL_CLAUDE_CODE_TOOLS, toolByName, toolDefs } from './tools/index.js';
|
|
|
12
12
|
import { task as taskTool } from './tools/task.js';
|
|
13
13
|
import { askUserQuestion } from './tools/ask_user.js';
|
|
14
14
|
import { loadMcpServers } from './mcp/index.js';
|
|
15
|
-
import { runSlashCommand } from './commands/index.js';
|
|
15
|
+
import { runSlashCommand, BUILTIN_COMMANDS } from './commands/index.js';
|
|
16
16
|
import { BackgroundTaskManager, BACKGROUND_TOOLS } from './background/index.js';
|
|
17
17
|
import { Mailbox, TaskBoard, TEAM_TOOLS, TEAM_DISPATCH_TOOLS, coordinatorPrompt } from './team/index.js';
|
|
18
18
|
import { MEMORY_TOOLS } from './memory/index.js';
|
|
@@ -395,9 +395,9 @@ export async function* runAgent(options) {
|
|
|
395
395
|
mcp_servers: mcpStatuses,
|
|
396
396
|
model: model ?? 'unknown',
|
|
397
397
|
permissionMode,
|
|
398
|
-
slash_commands: [],
|
|
398
|
+
slash_commands: [...new Set([...BUILTIN_COMMANDS, ...allCommands].map((c) => c.name.replace(/^\//, '')))],
|
|
399
399
|
output_style: 'default',
|
|
400
|
-
skills:
|
|
400
|
+
skills: skills.map((s) => s.name),
|
|
401
401
|
agents: agents ? Object.keys(agents) : undefined,
|
|
402
402
|
uuid: uuid(),
|
|
403
403
|
session_id: sessionId,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Skill } from './types.js';
|
|
2
|
+
export interface DefineSkillSpec {
|
|
3
|
+
/** Skill name — used as the slash-command name and the `skill` tool lookup key. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** One-line description of what the skill does (shown to the model + in /help). */
|
|
6
|
+
description: string;
|
|
7
|
+
/** The skill's instructions / prompt template. `$ARGUMENTS` is substituted at call time. */
|
|
8
|
+
instructions: string;
|
|
9
|
+
/** Optional argument hint, e.g. "<file>" or "<topic>". */
|
|
10
|
+
argumentHint?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Define a skill programmatically:
|
|
14
|
+
*
|
|
15
|
+
* query({ skills: [defineSkill({
|
|
16
|
+
* name: 'changelog',
|
|
17
|
+
* description: 'Summarize git changes into a changelog entry',
|
|
18
|
+
* instructions: 'Write a concise changelog entry for: $ARGUMENTS',
|
|
19
|
+
* })] })
|
|
20
|
+
*
|
|
21
|
+
* It is registered as a `/changelog` slash command and is invokable by the agent
|
|
22
|
+
* through the `skill` tool. (You can also pass plain `Skill` objects directly.)
|
|
23
|
+
*/
|
|
24
|
+
export declare function defineSkill(spec: DefineSkillSpec): Skill;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define a skill programmatically:
|
|
3
|
+
*
|
|
4
|
+
* query({ skills: [defineSkill({
|
|
5
|
+
* name: 'changelog',
|
|
6
|
+
* description: 'Summarize git changes into a changelog entry',
|
|
7
|
+
* instructions: 'Write a concise changelog entry for: $ARGUMENTS',
|
|
8
|
+
* })] })
|
|
9
|
+
*
|
|
10
|
+
* It is registered as a `/changelog` slash command and is invokable by the agent
|
|
11
|
+
* through the `skill` tool. (You can also pass plain `Skill` objects directly.)
|
|
12
|
+
*/
|
|
13
|
+
export function defineSkill(spec) {
|
|
14
|
+
const name = String(spec.name ?? '').trim();
|
|
15
|
+
if (!name)
|
|
16
|
+
throw new Error('defineSkill: `name` is required.');
|
|
17
|
+
if (!/^[A-Za-z0-9][\w:-]*$/.test(name)) {
|
|
18
|
+
throw new Error(`defineSkill: invalid name "${name}" (use letters, digits, _ - :).`);
|
|
19
|
+
}
|
|
20
|
+
const instructions = String(spec.instructions ?? '');
|
|
21
|
+
if (!instructions.trim())
|
|
22
|
+
throw new Error(`defineSkill("${name}"): \`instructions\` is required.`);
|
|
23
|
+
return {
|
|
24
|
+
name,
|
|
25
|
+
description: String(spec.description ?? '').trim(),
|
|
26
|
+
body: instructions,
|
|
27
|
+
...(spec.argumentHint ? { argumentHint: String(spec.argumentHint) } : {}),
|
|
28
|
+
};
|
|
29
|
+
}
|
package/dist/skills/index.d.ts
CHANGED
package/dist/skills/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anyclaude-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Standalone, browser-compatible SDK providing Claude Code agent capabilities (tools, tool loop, multi-turn, MCP, sub-agents, sessions) against any OpenAI/Anthropic-compatible LLM endpoint. Runs in the browser (WebContainer), Node, and Bun — no backend required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"./fs": { "types": "./dist/fs/index.d.ts", "import": "./dist/fs/index.js" },
|
|
15
15
|
"./llm": { "types": "./dist/llm/index.d.ts", "import": "./dist/llm/index.js" },
|
|
16
16
|
"./tools": { "types": "./dist/tools/index.d.ts", "import": "./dist/tools/index.js" },
|
|
17
|
+
"./session": { "types": "./dist/session/index.d.ts", "import": "./dist/session/index.js" },
|
|
18
|
+
"./memory": { "types": "./dist/memory/index.d.ts", "import": "./dist/memory/index.js" },
|
|
17
19
|
"./package.json": "./package.json"
|
|
18
20
|
},
|
|
19
21
|
"sideEffects": false,
|