anyclaude-sdk 0.4.4 → 0.4.6

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:
package/dist/compact.d.ts CHANGED
@@ -19,4 +19,19 @@ export declare function summarizeHistory(history: ChatMsg[], llm: SummarizerLLM,
19
19
  signal?: AbortSignal;
20
20
  focus?: string;
21
21
  }): Promise<ChatMsg[] | null>;
22
+ /**
23
+ * Window-aware compaction: keep the most recent `keepRecent` messages VERBATIM
24
+ * and summarize only the older prefix into one summary message. Far less lossy
25
+ * than `summarizeHistory` (which collapses the entire transcript) — recent turns
26
+ * stay intact while old context is condensed. Returns a new history, or the
27
+ * original array unchanged if there isn't enough to compact.
28
+ *
29
+ * if (estimateTokens(history) > limit) history = await compactWithWindow(history, llm, { keepRecent: 8 })
30
+ */
31
+ export declare function compactWithWindow(history: ChatMsg[], llm: SummarizerLLM, opts?: {
32
+ keepRecent?: number;
33
+ model?: string;
34
+ signal?: AbortSignal;
35
+ focus?: string;
36
+ }): Promise<ChatMsg[]>;
22
37
  export {};
package/dist/compact.js CHANGED
@@ -65,3 +65,28 @@ export async function summarizeHistory(history, llm, opts = {}) {
65
65
  return null;
66
66
  return [history[0], { role: 'user', content: `Summary of the conversation so far:\n${summary}` }];
67
67
  }
68
+ /**
69
+ * Window-aware compaction: keep the most recent `keepRecent` messages VERBATIM
70
+ * and summarize only the older prefix into one summary message. Far less lossy
71
+ * than `summarizeHistory` (which collapses the entire transcript) — recent turns
72
+ * stay intact while old context is condensed. Returns a new history, or the
73
+ * original array unchanged if there isn't enough to compact.
74
+ *
75
+ * if (estimateTokens(history) > limit) history = await compactWithWindow(history, llm, { keepRecent: 8 })
76
+ */
77
+ export async function compactWithWindow(history, llm, opts = {}) {
78
+ const keepRecent = Math.max(2, opts.keepRecent ?? 8);
79
+ if (history.length <= keepRecent + 2)
80
+ return history;
81
+ // Cut boundary for the verbatim window; don't start it on an orphan tool
82
+ // result (pull its preceding assistant turn into the window).
83
+ let cut = history.length - keepRecent;
84
+ while (cut > 1 && history[cut]?.role === 'tool')
85
+ cut--;
86
+ const older = history.slice(0, cut); // includes the system message at [0]
87
+ const recent = history.slice(cut);
88
+ const summarized = await summarizeHistory(older, llm, opts);
89
+ if (!summarized)
90
+ return history;
91
+ return [summarized[0], summarized[1], ...recent];
92
+ }
package/dist/index.d.ts CHANGED
@@ -24,4 +24,4 @@ export { enterPlanMode, exitPlanMode, PLAN_MODE_TOOLS } from './tools/plan_mode.
24
24
  export { uuid } from './util/ids.js';
25
25
  export * as paths from './util/paths.js';
26
26
  export { priceFor, computeCostUSD, contextWindowFor, type Pricing } from './util/pricing.js';
27
- export { estimateTokens, summarizeHistory } from './compact.js';
27
+ export { estimateTokens, summarizeHistory, compactWithWindow } from './compact.js';
package/dist/index.js CHANGED
@@ -26,5 +26,5 @@ export { enterPlanMode, exitPlanMode, PLAN_MODE_TOOLS } from './tools/plan_mode.
26
26
  export { uuid } from './util/ids.js';
27
27
  export * as paths from './util/paths.js';
28
28
  export { priceFor, computeCostUSD, contextWindowFor } from './util/pricing.js';
29
- export { estimateTokens, summarizeHistory } from './compact.js';
29
+ export { estimateTokens, summarizeHistory, compactWithWindow } from './compact.js';
30
30
  // (createResponsesClient is exported via ./llm/index.js)
@@ -1,3 +1,4 @@
1
1
  export * from './openai.js';
2
2
  export * from './anthropic.js';
3
3
  export * from './responses.js';
4
+ export { hasInlineToolCalls, parseInlineToolCalls } from './inlineTools.js';
package/dist/llm/index.js CHANGED
@@ -1,3 +1,6 @@
1
1
  export * from './openai.js';
2
2
  export * from './anthropic.js';
3
3
  export * from './responses.js';
4
+ // Inline tool-call parsing — recover tool calls a model emitted as TEXT
5
+ // (e.g. weak models that narrate tool calls instead of using native function calls).
6
+ export { hasInlineToolCalls, parseInlineToolCalls } from './inlineTools.js';
package/package.json CHANGED
@@ -1,22 +1,69 @@
1
1
  {
2
2
  "name": "anyclaude-sdk",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
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
+ },
51
+ "./permissions": {
52
+ "types": "./dist/permissions/index.d.ts",
53
+ "import": "./dist/permissions/index.js"
54
+ },
55
+ "./skills": {
56
+ "types": "./dist/skills/index.d.ts",
57
+ "import": "./dist/skills/index.js"
58
+ },
59
+ "./queue": {
60
+ "types": "./dist/queue.d.ts",
61
+ "import": "./dist/queue.js"
62
+ },
63
+ "./prompt": {
64
+ "types": "./dist/prompt.d.ts",
65
+ "import": "./dist/prompt.js"
66
+ }
20
67
  },
21
68
  "sideEffects": false,
22
69
  "files": [
@@ -64,12 +111,24 @@
64
111
  "e2b": "*"
65
112
  },
66
113
  "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 }
114
+ "@webcontainer/api": {
115
+ "optional": true
116
+ },
117
+ "dexie": {
118
+ "optional": true
119
+ },
120
+ "e2b": {
121
+ "optional": true
122
+ },
123
+ "@vercel/sandbox": {
124
+ "optional": true
125
+ },
126
+ "@daytonaio/sdk": {
127
+ "optional": true
128
+ },
129
+ "@cloudflare/sandbox": {
130
+ "optional": true
131
+ }
73
132
  },
74
133
  "devDependencies": {
75
134
  "@types/node": "^26.0.0",