anyclaude-sdk 0.4.3 → 0.4.5

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 CHANGED
@@ -317,10 +317,19 @@ Pluggable `SessionStore` adapters (all implement `SessionStoreLike`): `SessionSt
317
317
  Declare tools the **host** executes — e.g. run `bash` in the user's browser WebContainer while the agent loop runs on your server. The run pauses with a `client_tool_request`; the client executes it and you resume with the result:
318
318
 
319
319
  ```ts
320
- query({ prompt, llm, workspace, sessionId, clientTools: ['bash'] }) // → emits client_tool_request + pauses
320
+ import { WORKSPACE_TOOL_NAMES } from 'anyclaude-sdk'
321
+ query({ prompt, llm, workspace, sessionId, clientTools: WORKSPACE_TOOL_NAMES }) // → emits client_tool_request + pauses
321
322
  query({ llm, workspace, sessionId, resume: true, continueRun: true, clientToolResults }) // → continues
322
323
  ```
323
324
 
325
+ On the browser side, `anyclaude-react` turns those into a ready executor map backed by **any** workspace — a WebContainer (real shell + files), the user's **IndexedDB** (`DexieFileSystem`), OPFS, or memory:
326
+
327
+ ```tsx
328
+ import { createWebContainerClientTools, createWorkspaceClientTools } from 'anyclaude-react'
329
+ useAgent({ endpoint: '/api/agent', clientTools: createWebContainerClientTools(wc) }) // files + bash
330
+ useAgent({ endpoint: '/api/agent', clientTools: createWorkspaceClientTools(new DexieFileSystem('my-db')) }) // IndexedDB
331
+ ```
332
+
324
333
  ## Interactive — `ask_user_question`
325
334
 
326
335
  Provide `onAskUser` and the agent gains an `ask_user_question` tool to put a multiple-choice decision to the user:
@@ -22,11 +22,16 @@ export interface DexieFileSystemOptions {
22
22
  cwd?: string;
23
23
  /** Wipe all nodes on first open (fresh filesystem). */
24
24
  resetOnInit?: boolean;
25
+ /** Use an existing Dexie instance instead of opening one by name — lets the
26
+ * filesystem share a database your app already owns. It must declare a
27
+ * `nodes` table keyed by `path` (or be a fresh Dexie this FS can version). */
28
+ db?: unknown;
25
29
  }
26
30
  export declare class DexieFileSystem implements FileSystem {
27
31
  readonly cwd: string;
28
32
  private readonly dbName;
29
33
  private readonly resetOnInit;
34
+ private readonly injectedDb;
30
35
  private db;
31
36
  private opening;
32
37
  constructor(dbName?: string, options?: DexieFileSystemOptions);
package/dist/fs/dexie.js CHANGED
@@ -20,6 +20,7 @@ export class DexieFileSystem {
20
20
  this.dbName = dbName;
21
21
  this.cwd = options.cwd ?? '/';
22
22
  this.resetOnInit = options.resetOnInit ?? false;
23
+ this.injectedDb = options.db ?? null;
23
24
  }
24
25
  // ---- lifecycle ----
25
26
  async open() {
@@ -28,14 +29,25 @@ export class DexieFileSystem {
28
29
  if (this.opening)
29
30
  return this.opening;
30
31
  this.opening = (async () => {
31
- // @ts-ignore optional peer dependency, resolved at runtime
32
- const mod = await import('dexie');
33
- const Dexie = mod.default ?? mod;
34
- const db = new Dexie(this.dbName);
35
- db.version(1).stores({
36
- // primary key `path`, secondary index `parent`
37
- nodes: 'path, parent',
38
- });
32
+ let db;
33
+ if (this.injectedDb) {
34
+ // Use the caller's Dexie instance. Declare our schema if it isn't open
35
+ // yet; an already-open db is assumed to carry a compatible `nodes` table.
36
+ db = this.injectedDb;
37
+ if (!db.isOpen?.()) {
38
+ db.version(1).stores({ nodes: 'path, parent' });
39
+ }
40
+ }
41
+ else {
42
+ // @ts-ignore optional peer dependency, resolved at runtime
43
+ const mod = await import('dexie');
44
+ const Dexie = mod.default ?? mod;
45
+ db = new Dexie(this.dbName);
46
+ db.version(1).stores({
47
+ // primary key `path`, secondary index `parent`
48
+ nodes: 'path, parent',
49
+ });
50
+ }
39
51
  this.db = db;
40
52
  if (this.resetOnInit)
41
53
  await db.nodes.clear();
@@ -23,6 +23,11 @@ export { defineTool, type DefineToolSpec } from './define.js';
23
23
  export { askUserQuestion } from './ask_user.js';
24
24
  /** Every built-in Claude Code tool, ready to pass to `query()`. */
25
25
  export declare const ALL_CLAUDE_CODE_TOOLS: Tool[];
26
+ /** Built-in tools that operate on the workspace (filesystem + shell). Pass as
27
+ * `query({ clientTools: WORKSPACE_TOOL_NAMES })` to execute them on the HOST
28
+ * (e.g. a browser WebContainer or IndexedDB FS) instead of server-side. Pair
29
+ * with anyclaude-react's `createWorkspaceClientTools(workspace)`. */
30
+ export declare const WORKSPACE_TOOL_NAMES: readonly ["bash", "write_file", "read_file", "edit_file", "multi_edit", "delete_file", "list_files", "glob", "grep"];
26
31
  /** Extract the OpenAI-shape definitions to send to the LLM. */
27
32
  export declare function toolDefs(tools: Tool[]): ToolDef[];
28
33
  /** Build a name→tool lookup for dispatching tool calls. */
@@ -36,6 +36,21 @@ export const ALL_CLAUDE_CODE_TOOLS = [
36
36
  toolSearch,
37
37
  config,
38
38
  ];
39
+ /** Built-in tools that operate on the workspace (filesystem + shell). Pass as
40
+ * `query({ clientTools: WORKSPACE_TOOL_NAMES })` to execute them on the HOST
41
+ * (e.g. a browser WebContainer or IndexedDB FS) instead of server-side. Pair
42
+ * with anyclaude-react's `createWorkspaceClientTools(workspace)`. */
43
+ export const WORKSPACE_TOOL_NAMES = [
44
+ 'bash',
45
+ 'write_file',
46
+ 'read_file',
47
+ 'edit_file',
48
+ 'multi_edit',
49
+ 'delete_file',
50
+ 'list_files',
51
+ 'glob',
52
+ 'grep',
53
+ ];
39
54
  /** Extract the OpenAI-shape definitions to send to the LLM. */
40
55
  export function toolDefs(tools) {
41
56
  return tools.map((t) => t.def);
package/package.json CHANGED
@@ -1,22 +1,53 @@
1
1
  {
2
2
  "name": "anyclaude-sdk",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
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",
7
7
  "module": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
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
- "./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" },
19
- "./package.json": "./package.json"
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./query": {
15
+ "types": "./dist/query.d.ts",
16
+ "import": "./dist/query.js"
17
+ },
18
+ "./workspace": {
19
+ "types": "./dist/workspace/index.d.ts",
20
+ "import": "./dist/workspace/index.js"
21
+ },
22
+ "./sandbox": {
23
+ "types": "./dist/sandbox/index.d.ts",
24
+ "import": "./dist/sandbox/index.js"
25
+ },
26
+ "./fs": {
27
+ "types": "./dist/fs/index.d.ts",
28
+ "import": "./dist/fs/index.js"
29
+ },
30
+ "./llm": {
31
+ "types": "./dist/llm/index.d.ts",
32
+ "import": "./dist/llm/index.js"
33
+ },
34
+ "./tools": {
35
+ "types": "./dist/tools/index.d.ts",
36
+ "import": "./dist/tools/index.js"
37
+ },
38
+ "./session": {
39
+ "types": "./dist/session/index.d.ts",
40
+ "import": "./dist/session/index.js"
41
+ },
42
+ "./memory": {
43
+ "types": "./dist/memory/index.d.ts",
44
+ "import": "./dist/memory/index.js"
45
+ },
46
+ "./package.json": "./package.json",
47
+ "./compact": {
48
+ "types": "./dist/compact.d.ts",
49
+ "import": "./dist/compact.js"
50
+ }
20
51
  },
21
52
  "sideEffects": false,
22
53
  "files": [
@@ -64,12 +95,24 @@
64
95
  "e2b": "*"
65
96
  },
66
97
  "peerDependenciesMeta": {
67
- "@webcontainer/api": { "optional": true },
68
- "dexie": { "optional": true },
69
- "e2b": { "optional": true },
70
- "@vercel/sandbox": { "optional": true },
71
- "@daytonaio/sdk": { "optional": true },
72
- "@cloudflare/sandbox": { "optional": true }
98
+ "@webcontainer/api": {
99
+ "optional": true
100
+ },
101
+ "dexie": {
102
+ "optional": true
103
+ },
104
+ "e2b": {
105
+ "optional": true
106
+ },
107
+ "@vercel/sandbox": {
108
+ "optional": true
109
+ },
110
+ "@daytonaio/sdk": {
111
+ "optional": true
112
+ },
113
+ "@cloudflare/sandbox": {
114
+ "optional": true
115
+ }
73
116
  },
74
117
  "devDependencies": {
75
118
  "@types/node": "^26.0.0",