anyclaude-sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +295 -0
- package/dist/agent.d.ts +110 -0
- package/dist/agent.js +897 -0
- package/dist/background/index.d.ts +3 -0
- package/dist/background/index.js +9 -0
- package/dist/background/manager.d.ts +32 -0
- package/dist/background/manager.js +108 -0
- package/dist/background/tools.d.ts +5 -0
- package/dist/background/tools.js +98 -0
- package/dist/background/worker.d.ts +19 -0
- package/dist/background/worker.js +30 -0
- package/dist/commands/builtins.d.ts +2 -0
- package/dist/commands/builtins.js +306 -0
- package/dist/commands/index.d.ts +21 -0
- package/dist/commands/index.js +56 -0
- package/dist/commands/types.d.ts +110 -0
- package/dist/commands/types.js +5 -0
- package/dist/compact.d.ts +22 -0
- package/dist/compact.js +67 -0
- package/dist/fs/dexie.d.ts +57 -0
- package/dist/fs/dexie.js +243 -0
- package/dist/fs/index.d.ts +4 -0
- package/dist/fs/index.js +13 -0
- package/dist/fs/linuxTree.d.ts +11 -0
- package/dist/fs/linuxTree.js +43 -0
- package/dist/fs/opfs.d.ts +23 -0
- package/dist/fs/opfs.js +112 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +29 -0
- package/dist/llm/anthropic.d.ts +24 -0
- package/dist/llm/anthropic.js +280 -0
- package/dist/llm/index.d.ts +3 -0
- package/dist/llm/index.js +3 -0
- package/dist/llm/inlineTools.d.ts +11 -0
- package/dist/llm/inlineTools.js +72 -0
- package/dist/llm/openai.d.ts +29 -0
- package/dist/llm/openai.js +224 -0
- package/dist/llm/responses.d.ts +18 -0
- package/dist/llm/responses.js +256 -0
- package/dist/mcp/client.d.ts +20 -0
- package/dist/mcp/client.js +156 -0
- package/dist/mcp/index.d.ts +24 -0
- package/dist/mcp/index.js +157 -0
- package/dist/mcp/proxy.d.ts +3 -0
- package/dist/mcp/proxy.js +25 -0
- package/dist/mcp/sdkServer.d.ts +21 -0
- package/dist/mcp/sdkServer.js +28 -0
- package/dist/mcp/types.d.ts +92 -0
- package/dist/mcp/types.js +5 -0
- package/dist/memory/index.d.ts +4 -0
- package/dist/memory/index.js +5 -0
- package/dist/memory/render.d.ts +7 -0
- package/dist/memory/render.js +46 -0
- package/dist/memory/store.d.ts +20 -0
- package/dist/memory/store.js +79 -0
- package/dist/memory/tools.d.ts +5 -0
- package/dist/memory/tools.js +95 -0
- package/dist/memory/types.d.ts +15 -0
- package/dist/memory/types.js +4 -0
- package/dist/permissions/dangerous.d.ts +4 -0
- package/dist/permissions/dangerous.js +24 -0
- package/dist/permissions/gate.d.ts +21 -0
- package/dist/permissions/gate.js +66 -0
- package/dist/permissions/index.d.ts +5 -0
- package/dist/permissions/index.js +6 -0
- package/dist/permissions/match.d.ts +19 -0
- package/dist/permissions/match.js +104 -0
- package/dist/permissions/planMode.d.ts +3 -0
- package/dist/permissions/planMode.js +33 -0
- package/dist/permissions/types.d.ts +19 -0
- package/dist/permissions/types.js +2 -0
- package/dist/persist.d.ts +15 -0
- package/dist/persist.js +58 -0
- package/dist/prompt.d.ts +6 -0
- package/dist/prompt.js +34 -0
- package/dist/query.d.ts +105 -0
- package/dist/query.js +115 -0
- package/dist/queue.d.ts +23 -0
- package/dist/queue.js +43 -0
- package/dist/sandbox/cloudflare.d.ts +48 -0
- package/dist/sandbox/cloudflare.js +124 -0
- package/dist/sandbox/daytona.d.ts +48 -0
- package/dist/sandbox/daytona.js +79 -0
- package/dist/sandbox/e2b.d.ts +54 -0
- package/dist/sandbox/e2b.js +87 -0
- package/dist/sandbox/index.d.ts +8 -0
- package/dist/sandbox/index.js +19 -0
- package/dist/sandbox/local.d.ts +51 -0
- package/dist/sandbox/local.js +155 -0
- package/dist/sandbox/types.d.ts +18 -0
- package/dist/sandbox/types.js +27 -0
- package/dist/sandbox/util.d.ts +15 -0
- package/dist/sandbox/util.js +100 -0
- package/dist/sandbox/vercel.d.ts +48 -0
- package/dist/sandbox/vercel.js +130 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.js +6 -0
- package/dist/session/store.d.ts +28 -0
- package/dist/session/store.js +122 -0
- package/dist/session/types.d.ts +22 -0
- package/dist/session/types.js +2 -0
- package/dist/settings/index.d.ts +3 -0
- package/dist/settings/index.js +3 -0
- package/dist/settings/load.d.ts +20 -0
- package/dist/settings/load.js +36 -0
- package/dist/settings/merge.d.ts +13 -0
- package/dist/settings/merge.js +65 -0
- package/dist/settings/types.d.ts +17 -0
- package/dist/settings/types.js +3 -0
- package/dist/skills/index.d.ts +4 -0
- package/dist/skills/index.js +5 -0
- package/dist/skills/load.d.ts +23 -0
- package/dist/skills/load.js +54 -0
- package/dist/skills/parse.d.ts +7 -0
- package/dist/skills/parse.js +40 -0
- package/dist/skills/tool.d.ts +2 -0
- package/dist/skills/tool.js +39 -0
- package/dist/skills/types.d.ts +10 -0
- package/dist/skills/types.js +4 -0
- package/dist/team/dispatch.d.ts +2 -0
- package/dist/team/dispatch.js +41 -0
- package/dist/team/index.d.ts +9 -0
- package/dist/team/index.js +11 -0
- package/dist/team/mailbox.d.ts +24 -0
- package/dist/team/mailbox.js +33 -0
- package/dist/team/prompt.d.ts +1 -0
- package/dist/team/prompt.js +12 -0
- package/dist/team/runner.d.ts +20 -0
- package/dist/team/runner.js +45 -0
- package/dist/team/taskBoard.d.ts +41 -0
- package/dist/team/taskBoard.js +73 -0
- package/dist/team/tools.d.ts +7 -0
- package/dist/team/tools.js +190 -0
- package/dist/tools/bash.d.ts +2 -0
- package/dist/tools/bash.js +45 -0
- package/dist/tools/config.d.ts +2 -0
- package/dist/tools/config.js +44 -0
- package/dist/tools/define.d.ts +18 -0
- package/dist/tools/define.js +21 -0
- package/dist/tools/delete_file.d.ts +2 -0
- package/dist/tools/delete_file.js +33 -0
- package/dist/tools/edit_file.d.ts +2 -0
- package/dist/tools/edit_file.js +93 -0
- package/dist/tools/fileTypes.d.ts +32 -0
- package/dist/tools/fileTypes.js +166 -0
- package/dist/tools/glob.d.ts +2 -0
- package/dist/tools/glob.js +53 -0
- package/dist/tools/grep.d.ts +2 -0
- package/dist/tools/grep.js +110 -0
- package/dist/tools/imageProcessor.d.ts +15 -0
- package/dist/tools/imageProcessor.js +83 -0
- package/dist/tools/index.d.ts +28 -0
- package/dist/tools/index.js +45 -0
- package/dist/tools/list_files.d.ts +2 -0
- package/dist/tools/list_files.js +42 -0
- package/dist/tools/multi_edit.d.ts +2 -0
- package/dist/tools/multi_edit.js +112 -0
- package/dist/tools/notebook_edit.d.ts +2 -0
- package/dist/tools/notebook_edit.js +118 -0
- package/dist/tools/plan_mode.d.ts +4 -0
- package/dist/tools/plan_mode.js +44 -0
- package/dist/tools/read_file.d.ts +2 -0
- package/dist/tools/read_file.js +193 -0
- package/dist/tools/task.d.ts +2 -0
- package/dist/tools/task.js +77 -0
- package/dist/tools/todo_write.d.ts +2 -0
- package/dist/tools/todo_write.js +104 -0
- package/dist/tools/tool_search.d.ts +2 -0
- package/dist/tools/tool_search.js +49 -0
- package/dist/tools/types.d.ts +82 -0
- package/dist/tools/types.js +1 -0
- package/dist/tools/walk.d.ts +29 -0
- package/dist/tools/walk.js +82 -0
- package/dist/tools/web_fetch.d.ts +2 -0
- package/dist/tools/web_fetch.js +76 -0
- package/dist/tools/web_search.d.ts +22 -0
- package/dist/tools/web_search.js +195 -0
- package/dist/tools/write_file.d.ts +2 -0
- package/dist/tools/write_file.js +39 -0
- package/dist/types/index.d.ts +363 -0
- package/dist/types/index.js +9 -0
- package/dist/util/ids.d.ts +3 -0
- package/dist/util/ids.js +22 -0
- package/dist/util/paths.d.ts +16 -0
- package/dist/util/paths.js +72 -0
- package/dist/util/pricing.d.ts +15 -0
- package/dist/util/pricing.js +81 -0
- package/dist/workspace/index.d.ts +2 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/memory.d.ts +28 -0
- package/dist/workspace/memory.js +97 -0
- package/dist/workspace/webcontainer.d.ts +65 -0
- package/dist/workspace/webcontainer.js +156 -0
- package/package.json +78 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const encoder = new TextEncoder();
|
|
2
|
+
const decoder = new TextDecoder();
|
|
3
|
+
/**
|
|
4
|
+
* A pure in-memory FileSystem. Useful for tests and environments without a
|
|
5
|
+
* WebContainer. Does not implement CommandExecutor — pair it with a custom
|
|
6
|
+
* executor or `NoopCommandExecutor` if bash is not needed.
|
|
7
|
+
*/
|
|
8
|
+
export class MemoryFileSystem {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.files = new Map();
|
|
11
|
+
this.dirs = new Set(['/']);
|
|
12
|
+
}
|
|
13
|
+
norm(path) {
|
|
14
|
+
const isAbs = path.startsWith('/');
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const seg of path.split('/')) {
|
|
17
|
+
if (seg === '' || seg === '.')
|
|
18
|
+
continue;
|
|
19
|
+
if (seg === '..')
|
|
20
|
+
out.pop();
|
|
21
|
+
else
|
|
22
|
+
out.push(seg);
|
|
23
|
+
}
|
|
24
|
+
return (isAbs ? '/' : '') + out.join('/');
|
|
25
|
+
}
|
|
26
|
+
async readFile(path) {
|
|
27
|
+
const data = this.files.get(this.norm(path));
|
|
28
|
+
return data ? decoder.decode(data) : null;
|
|
29
|
+
}
|
|
30
|
+
async readBinary(path) {
|
|
31
|
+
return this.files.get(this.norm(path)) ?? null;
|
|
32
|
+
}
|
|
33
|
+
async writeFile(path, contents) {
|
|
34
|
+
await this.writeBinary(path, encoder.encode(contents));
|
|
35
|
+
}
|
|
36
|
+
async writeBinary(path, data) {
|
|
37
|
+
const p = this.norm(path);
|
|
38
|
+
this.files.set(p, data);
|
|
39
|
+
let dir = p.slice(0, p.lastIndexOf('/')) || '/';
|
|
40
|
+
while (dir && !this.dirs.has(dir)) {
|
|
41
|
+
this.dirs.add(dir);
|
|
42
|
+
dir = dir.slice(0, dir.lastIndexOf('/')) || '/';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async deleteFile(path) {
|
|
46
|
+
const p = this.norm(path);
|
|
47
|
+
this.files.delete(p);
|
|
48
|
+
for (const f of [...this.files.keys()]) {
|
|
49
|
+
if (f.startsWith(p + '/'))
|
|
50
|
+
this.files.delete(f);
|
|
51
|
+
}
|
|
52
|
+
this.dirs.delete(p);
|
|
53
|
+
}
|
|
54
|
+
async readdir(path) {
|
|
55
|
+
const p = this.norm(path);
|
|
56
|
+
if (!this.dirs.has(p) && p !== '/') {
|
|
57
|
+
// allow listing a dir that only exists implicitly via files
|
|
58
|
+
const hasChildren = [...this.files.keys(), ...this.dirs].some((k) => k.startsWith(p + '/'));
|
|
59
|
+
if (!hasChildren)
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const prefix = p === '/' ? '/' : p + '/';
|
|
63
|
+
const names = new Map();
|
|
64
|
+
for (const f of this.files.keys()) {
|
|
65
|
+
if (f.startsWith(prefix)) {
|
|
66
|
+
const rest = f.slice(prefix.length);
|
|
67
|
+
const slash = rest.indexOf('/');
|
|
68
|
+
if (slash === -1)
|
|
69
|
+
names.set(rest, false);
|
|
70
|
+
else
|
|
71
|
+
names.set(rest.slice(0, slash), true);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const d of this.dirs) {
|
|
75
|
+
if (d.startsWith(prefix) && d !== p) {
|
|
76
|
+
const rest = d.slice(prefix.length);
|
|
77
|
+
const name = rest.split('/')[0];
|
|
78
|
+
if (name)
|
|
79
|
+
names.set(name, true);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return [...names].map(([name, isDir]) => ({ name, isDir }));
|
|
83
|
+
}
|
|
84
|
+
async mkdir(path) {
|
|
85
|
+
let dir = this.norm(path);
|
|
86
|
+
while (dir && !this.dirs.has(dir)) {
|
|
87
|
+
this.dirs.add(dir);
|
|
88
|
+
dir = dir.slice(0, dir.lastIndexOf('/')) || '/';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** A CommandExecutor that refuses to run anything — for FS-only workspaces. */
|
|
93
|
+
export class NoopCommandExecutor {
|
|
94
|
+
async exec() {
|
|
95
|
+
return { output: 'bash is not available in this workspace', exitCode: 127 };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { CommandExecutor, FileSystem } from '../types/index.js';
|
|
2
|
+
export interface WebContainerLike {
|
|
3
|
+
fs: {
|
|
4
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
5
|
+
readFile(path: string, encoding: 'utf-8'): Promise<string>;
|
|
6
|
+
writeFile(path: string, data: string | Uint8Array): Promise<void>;
|
|
7
|
+
readdir(path: string, options?: {
|
|
8
|
+
withFileTypes?: boolean;
|
|
9
|
+
}): Promise<string[] | Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
isDirectory(): boolean;
|
|
12
|
+
}>>;
|
|
13
|
+
mkdir(path: string, options?: {
|
|
14
|
+
recursive?: boolean;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
rm(path: string, options?: {
|
|
17
|
+
recursive?: boolean;
|
|
18
|
+
force?: boolean;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
spawn(command: string, args?: string[], options?: {
|
|
22
|
+
env?: Record<string, string>;
|
|
23
|
+
cwd?: string;
|
|
24
|
+
}): Promise<WebContainerProcess>;
|
|
25
|
+
workdir?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface WebContainerProcess {
|
|
28
|
+
output: ReadableStream<string>;
|
|
29
|
+
exit: Promise<number>;
|
|
30
|
+
kill(): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Wraps a booted WebContainer instance, exposing the `FileSystem` and
|
|
34
|
+
* `CommandExecutor` interfaces the agent loop and tools depend on.
|
|
35
|
+
*
|
|
36
|
+
* All paths are resolved relative to `cwd` (default: the container workdir or
|
|
37
|
+
* "/home/projects" — the standard WebContainer mount point) when not absolute.
|
|
38
|
+
*/
|
|
39
|
+
export declare class WebContainerWorkspace implements FileSystem, CommandExecutor {
|
|
40
|
+
readonly wc: WebContainerLike;
|
|
41
|
+
readonly cwd: string;
|
|
42
|
+
constructor(wc: WebContainerLike, cwd?: string);
|
|
43
|
+
/** Resolve a possibly-relative path against the workspace cwd. */
|
|
44
|
+
resolve(path: string): string;
|
|
45
|
+
readFile(path: string): Promise<string | null>;
|
|
46
|
+
readBinary(path: string): Promise<Uint8Array | null>;
|
|
47
|
+
writeFile(path: string, contents: string): Promise<void>;
|
|
48
|
+
writeBinary(path: string, data: Uint8Array): Promise<void>;
|
|
49
|
+
deleteFile(path: string): Promise<void>;
|
|
50
|
+
readdir(path: string): Promise<Array<{
|
|
51
|
+
name: string;
|
|
52
|
+
isDir: boolean;
|
|
53
|
+
}> | null>;
|
|
54
|
+
mkdir(path: string): Promise<void>;
|
|
55
|
+
private ensureParent;
|
|
56
|
+
exec(command: string, timeoutMs?: number, env?: Record<string, string>): Promise<{
|
|
57
|
+
output: string;
|
|
58
|
+
exitCode: number;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* jsh is a constrained shell. Strip constructs it doesn't support so commands
|
|
63
|
+
* authored for a real bash shell still run (mirrors the spec's bash notes).
|
|
64
|
+
*/
|
|
65
|
+
export declare function sanitizeCommand(command: string): string;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
const textDecoder = new TextDecoder();
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a booted WebContainer instance, exposing the `FileSystem` and
|
|
4
|
+
* `CommandExecutor` interfaces the agent loop and tools depend on.
|
|
5
|
+
*
|
|
6
|
+
* All paths are resolved relative to `cwd` (default: the container workdir or
|
|
7
|
+
* "/home/projects" — the standard WebContainer mount point) when not absolute.
|
|
8
|
+
*/
|
|
9
|
+
export class WebContainerWorkspace {
|
|
10
|
+
constructor(wc, cwd) {
|
|
11
|
+
this.wc = wc;
|
|
12
|
+
this.cwd = cwd ?? wc.workdir ?? '/home/projects';
|
|
13
|
+
}
|
|
14
|
+
/** Resolve a possibly-relative path against the workspace cwd. */
|
|
15
|
+
resolve(path) {
|
|
16
|
+
if (path.startsWith('/'))
|
|
17
|
+
return normalize(path);
|
|
18
|
+
const base = this.cwd.endsWith('/') ? this.cwd.slice(0, -1) : this.cwd;
|
|
19
|
+
return normalize(`${base}/${path}`);
|
|
20
|
+
}
|
|
21
|
+
// ---- FileSystem ----
|
|
22
|
+
async readFile(path) {
|
|
23
|
+
try {
|
|
24
|
+
return await this.wc.fs.readFile(this.resolve(path), 'utf-8');
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async readBinary(path) {
|
|
31
|
+
try {
|
|
32
|
+
return await this.wc.fs.readFile(this.resolve(path));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async writeFile(path, contents) {
|
|
39
|
+
const resolved = this.resolve(path);
|
|
40
|
+
await this.ensureParent(resolved);
|
|
41
|
+
await this.wc.fs.writeFile(resolved, contents);
|
|
42
|
+
}
|
|
43
|
+
async writeBinary(path, data) {
|
|
44
|
+
const resolved = this.resolve(path);
|
|
45
|
+
await this.ensureParent(resolved);
|
|
46
|
+
await this.wc.fs.writeFile(resolved, data);
|
|
47
|
+
}
|
|
48
|
+
async deleteFile(path) {
|
|
49
|
+
await this.wc.fs.rm(this.resolve(path), { recursive: true, force: true });
|
|
50
|
+
}
|
|
51
|
+
async readdir(path) {
|
|
52
|
+
try {
|
|
53
|
+
const entries = await this.wc.fs.readdir(this.resolve(path), {
|
|
54
|
+
withFileTypes: true,
|
|
55
|
+
});
|
|
56
|
+
return entries.map((e) => ({
|
|
57
|
+
name: e.name,
|
|
58
|
+
isDir: e.isDirectory(),
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async mkdir(path) {
|
|
66
|
+
await this.wc.fs.mkdir(this.resolve(path), { recursive: true });
|
|
67
|
+
}
|
|
68
|
+
async ensureParent(resolvedPath) {
|
|
69
|
+
const idx = resolvedPath.lastIndexOf('/');
|
|
70
|
+
if (idx <= 0)
|
|
71
|
+
return;
|
|
72
|
+
const parent = resolvedPath.slice(0, idx);
|
|
73
|
+
try {
|
|
74
|
+
await this.wc.fs.mkdir(parent, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// best-effort; writeFile will surface a real error if it matters
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// ---- CommandExecutor ----
|
|
81
|
+
async exec(command, timeoutMs = 120_000, env) {
|
|
82
|
+
const sanitized = sanitizeCommand(command);
|
|
83
|
+
const proc = await this.wc.spawn('jsh', ['-c', sanitized], {
|
|
84
|
+
env,
|
|
85
|
+
cwd: this.cwd,
|
|
86
|
+
});
|
|
87
|
+
let output = '';
|
|
88
|
+
const reader = proc.output.getReader();
|
|
89
|
+
const collect = (async () => {
|
|
90
|
+
for (;;) {
|
|
91
|
+
const { value, done } = await reader.read();
|
|
92
|
+
if (done)
|
|
93
|
+
break;
|
|
94
|
+
output += typeof value === 'string' ? value : textDecoder.decode(value);
|
|
95
|
+
}
|
|
96
|
+
})();
|
|
97
|
+
let timedOut = false;
|
|
98
|
+
let timer;
|
|
99
|
+
const timeout = new Promise((res) => {
|
|
100
|
+
timer = setTimeout(() => {
|
|
101
|
+
timedOut = true;
|
|
102
|
+
try {
|
|
103
|
+
proc.kill();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
/* ignore */
|
|
107
|
+
}
|
|
108
|
+
res(124);
|
|
109
|
+
}, timeoutMs);
|
|
110
|
+
});
|
|
111
|
+
const exitCode = await Promise.race([proc.exit, timeout]);
|
|
112
|
+
if (timer)
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
try {
|
|
115
|
+
await collect;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
/* stream may close on kill */
|
|
119
|
+
}
|
|
120
|
+
reader.releaseLock?.();
|
|
121
|
+
if (timedOut) {
|
|
122
|
+
output += `\n[command timed out after ${timeoutMs}ms]`;
|
|
123
|
+
}
|
|
124
|
+
return { output: output.trimEnd(), exitCode };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* jsh is a constrained shell. Strip constructs it doesn't support so commands
|
|
129
|
+
* authored for a real bash shell still run (mirrors the spec's bash notes).
|
|
130
|
+
*/
|
|
131
|
+
export function sanitizeCommand(command) {
|
|
132
|
+
return command
|
|
133
|
+
.replace(/\s*2>&1/g, '')
|
|
134
|
+
.replace(/\s*>\s*\/dev\/null(\s+2>&1)?/g, '')
|
|
135
|
+
.replace(/\s*2>\s*\/dev\/null/g, '')
|
|
136
|
+
.trim();
|
|
137
|
+
}
|
|
138
|
+
/** Collapse `.`/`..` segments and duplicate slashes in an absolute path. */
|
|
139
|
+
function normalize(path) {
|
|
140
|
+
const isAbs = path.startsWith('/');
|
|
141
|
+
const out = [];
|
|
142
|
+
for (const seg of path.split('/')) {
|
|
143
|
+
if (seg === '' || seg === '.')
|
|
144
|
+
continue;
|
|
145
|
+
if (seg === '..') {
|
|
146
|
+
if (out.length && out[out.length - 1] !== '..')
|
|
147
|
+
out.pop();
|
|
148
|
+
else if (!isAbs)
|
|
149
|
+
out.push('..');
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
out.push(seg);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return (isAbs ? '/' : '') + out.join('/');
|
|
156
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "anyclaude-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
|
|
11
|
+
"./query": { "types": "./dist/query.d.ts", "import": "./dist/query.js" },
|
|
12
|
+
"./workspace": { "types": "./dist/workspace/index.d.ts", "import": "./dist/workspace/index.js" },
|
|
13
|
+
"./sandbox": { "types": "./dist/sandbox/index.d.ts", "import": "./dist/sandbox/index.js" },
|
|
14
|
+
"./fs": { "types": "./dist/fs/index.d.ts", "import": "./dist/fs/index.js" },
|
|
15
|
+
"./llm": { "types": "./dist/llm/index.d.ts", "import": "./dist/llm/index.js" },
|
|
16
|
+
"./tools": { "types": "./dist/tools/index.d.ts", "import": "./dist/tools/index.js" },
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.json",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
29
|
+
"prepublishOnly": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"claude",
|
|
33
|
+
"claude-code",
|
|
34
|
+
"agent",
|
|
35
|
+
"agent-sdk",
|
|
36
|
+
"ai-agent",
|
|
37
|
+
"tool-use",
|
|
38
|
+
"webcontainer",
|
|
39
|
+
"browser",
|
|
40
|
+
"bun",
|
|
41
|
+
"llm",
|
|
42
|
+
"openai",
|
|
43
|
+
"anthropic",
|
|
44
|
+
"mcp"
|
|
45
|
+
],
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"author": "Hans Ade <anye.happiness@swisslinkedu.com>",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/pipilot-dev/anyclaude-sdk.git"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/pipilot-dev/anyclaude-sdk#readme",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/pipilot-dev/anyclaude-sdk/issues"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@cloudflare/sandbox": "*",
|
|
58
|
+
"@daytonaio/sdk": "*",
|
|
59
|
+
"@vercel/sandbox": "*",
|
|
60
|
+
"@webcontainer/api": ">=1.1.0",
|
|
61
|
+
"dexie": ">=3.2.0",
|
|
62
|
+
"e2b": "*"
|
|
63
|
+
},
|
|
64
|
+
"peerDependenciesMeta": {
|
|
65
|
+
"@webcontainer/api": { "optional": true },
|
|
66
|
+
"dexie": { "optional": true },
|
|
67
|
+
"e2b": { "optional": true },
|
|
68
|
+
"@vercel/sandbox": { "optional": true },
|
|
69
|
+
"@daytonaio/sdk": { "optional": true },
|
|
70
|
+
"@cloudflare/sandbox": { "optional": true }
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@types/node": "^26.0.0",
|
|
74
|
+
"comlink": "^4.4.2",
|
|
75
|
+
"dexie": "^4.4.4",
|
|
76
|
+
"typescript": "^5.4.0"
|
|
77
|
+
}
|
|
78
|
+
}
|