anyclaude-react 0.2.2 → 0.3.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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/workspaceTools.d.ts +48 -0
- package/dist/workspaceTools.js +57 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createAgentClient, createEndpointClient } from './client.js';
|
|
2
|
+
export { createWorkspaceClientTools, createWebContainerClientTools, type WorkspaceLike, type WorkspaceClientToolsOptions, } from './workspaceTools.js';
|
|
2
3
|
export type { AgentClient, RunFn, RunOptions, EndpointClientOptions, ClientToolMap, ClientToolExecutor, ClientToolResult, } from './client.js';
|
|
3
4
|
export { useAgent } from './useAgent.js';
|
|
4
5
|
export type { UseAgentOptions, UseAgentResult, AgentStatus } from './useAgent.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// anyclaude-react — restylable React UI kit for anyclaude-sdk.
|
|
2
2
|
export { createAgentClient, createEndpointClient } from './client.js';
|
|
3
|
+
export { createWorkspaceClientTools, createWebContainerClientTools, } from './workspaceTools.js';
|
|
3
4
|
export { useAgent } from './useAgent.js';
|
|
4
5
|
export { renderMarkdown } from './markdown.js';
|
|
5
6
|
export { Message, MarkdownMessage } from './components/Message.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WebContainerWorkspace } from 'anyclaude-sdk/workspace';
|
|
2
|
+
import type { ClientToolMap } from './client.js';
|
|
3
|
+
/** Structural view of an SDK workspace: a FileSystem, optionally a shell.
|
|
4
|
+
* `DexieFileSystem`, `WebContainerWorkspace`, `OpfsFileSystem`,
|
|
5
|
+
* `MemoryFileSystem` all satisfy this. */
|
|
6
|
+
export interface WorkspaceLike {
|
|
7
|
+
readFile(path: string): Promise<string | null>;
|
|
8
|
+
writeFile(path: string, contents: string): Promise<void>;
|
|
9
|
+
readdir(path: string): Promise<Array<{
|
|
10
|
+
name: string;
|
|
11
|
+
isDir: boolean;
|
|
12
|
+
}> | null>;
|
|
13
|
+
deleteFile(path: string): Promise<void>;
|
|
14
|
+
mkdir?(path: string): Promise<void>;
|
|
15
|
+
readBinary?(path: string): Promise<Uint8Array | null>;
|
|
16
|
+
writeBinary?(path: string, data: Uint8Array): Promise<void>;
|
|
17
|
+
/** Present on shell-capable workspaces (e.g. WebContainerWorkspace). */
|
|
18
|
+
exec?(command: string, timeoutMs?: number): Promise<{
|
|
19
|
+
output: string;
|
|
20
|
+
exitCode: number;
|
|
21
|
+
}>;
|
|
22
|
+
cwd?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface WorkspaceClientToolsOptions {
|
|
25
|
+
/** Working directory for the tools (default: workspace.cwd ?? '/'). */
|
|
26
|
+
cwd?: string;
|
|
27
|
+
/** Restrict to these tool names (default: all supported by the workspace). */
|
|
28
|
+
only?: string[];
|
|
29
|
+
/** Extra or overriding executors, merged on top of the generated map. */
|
|
30
|
+
extra?: ClientToolMap;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build a `ClientToolMap` that executes the SDK's built-in workspace tools
|
|
34
|
+
* against any SDK workspace. `bash` is included only when the workspace has a
|
|
35
|
+
* shell (`exec`); filesystem-only workspaces (e.g. IndexedDB) omit it.
|
|
36
|
+
*
|
|
37
|
+
* useAgent({ endpoint: '/api/agent',
|
|
38
|
+
* clientTools: createWorkspaceClientTools(new DexieFileSystem('my-db')) })
|
|
39
|
+
*/
|
|
40
|
+
export declare function createWorkspaceClientTools(workspace: WorkspaceLike, opts?: WorkspaceClientToolsOptions): ClientToolMap;
|
|
41
|
+
/**
|
|
42
|
+
* Convenience: client tools backed by a booted WebContainer — real files + a
|
|
43
|
+
* real `jsh` shell, all in the browser tab.
|
|
44
|
+
*
|
|
45
|
+
* const wc = await WebContainer.boot()
|
|
46
|
+
* useAgent({ endpoint: '/api/agent', clientTools: createWebContainerClientTools(wc) })
|
|
47
|
+
*/
|
|
48
|
+
export declare function createWebContainerClientTools(wc: ConstructorParameters<typeof WebContainerWorkspace>[0], opts?: WorkspaceClientToolsOptions): ClientToolMap;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// createWorkspaceClientTools — run the SDK's built-in workspace tools
|
|
2
|
+
// (read/write/edit/multi_edit/delete/list/glob/grep, and bash when a shell is
|
|
3
|
+
// available) on the HOST instead of the server. Pair with the server-side
|
|
4
|
+
// `query({ clientTools: WORKSPACE_TOOL_NAMES })`: the agent emits a
|
|
5
|
+
// `client_tool_request`, this map executes it against the chosen workspace —
|
|
6
|
+
// a browser WebContainer, an IndexedDB `DexieFileSystem`, OPFS, or memory — and
|
|
7
|
+
// the result is streamed back. Reuses the real SDK tool implementations, so the
|
|
8
|
+
// behavior matches server-side exactly.
|
|
9
|
+
import { bash, readFile, writeFile, editFile, multiEdit, deleteFile, listFiles, glob, grep, } from 'anyclaude-sdk/tools';
|
|
10
|
+
import { WebContainerWorkspace } from 'anyclaude-sdk/workspace';
|
|
11
|
+
const WORKSPACE_TOOLS = [bash, writeFile, readFile, editFile, multiEdit, deleteFile, listFiles, glob, grep];
|
|
12
|
+
const NOOP_EXEC = {
|
|
13
|
+
async exec() {
|
|
14
|
+
return { output: 'No shell available in this workspace (filesystem-only).', exitCode: 127 };
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Build a `ClientToolMap` that executes the SDK's built-in workspace tools
|
|
19
|
+
* against any SDK workspace. `bash` is included only when the workspace has a
|
|
20
|
+
* shell (`exec`); filesystem-only workspaces (e.g. IndexedDB) omit it.
|
|
21
|
+
*
|
|
22
|
+
* useAgent({ endpoint: '/api/agent',
|
|
23
|
+
* clientTools: createWorkspaceClientTools(new DexieFileSystem('my-db')) })
|
|
24
|
+
*/
|
|
25
|
+
export function createWorkspaceClientTools(workspace, opts = {}) {
|
|
26
|
+
const hasExec = typeof workspace.exec === 'function';
|
|
27
|
+
const ctx = {
|
|
28
|
+
fs: workspace,
|
|
29
|
+
exec: hasExec ? workspace : NOOP_EXEC,
|
|
30
|
+
cwd: opts.cwd ?? workspace.cwd ?? '/',
|
|
31
|
+
readFiles: new Set(),
|
|
32
|
+
};
|
|
33
|
+
const map = {};
|
|
34
|
+
for (const t of WORKSPACE_TOOLS) {
|
|
35
|
+
const name = t.def.function.name;
|
|
36
|
+
if (opts.only && !opts.only.includes(name))
|
|
37
|
+
continue;
|
|
38
|
+
if (name === 'bash' && !hasExec)
|
|
39
|
+
continue;
|
|
40
|
+
map[name] = async (input) => {
|
|
41
|
+
const r = await t.run(input, ctx);
|
|
42
|
+
return { content: r.content, is_error: r.isError };
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return { ...map, ...(opts.extra ?? {}) };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Convenience: client tools backed by a booted WebContainer — real files + a
|
|
49
|
+
* real `jsh` shell, all in the browser tab.
|
|
50
|
+
*
|
|
51
|
+
* const wc = await WebContainer.boot()
|
|
52
|
+
* useAgent({ endpoint: '/api/agent', clientTools: createWebContainerClientTools(wc) })
|
|
53
|
+
*/
|
|
54
|
+
export function createWebContainerClientTools(wc, opts = {}) {
|
|
55
|
+
const ws = new WebContainerWorkspace(wc, opts.cwd);
|
|
56
|
+
return createWorkspaceClientTools(ws, opts);
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anyclaude-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React UI kit for anyclaude-sdk — restylable hooks + components (useAgent, Transcript, Composer, AgentChat, Terminal, FileExplorer, CodeEditor, ChatPanel, AskUser) with built-in serverless 'survivor' stream-stitching. Build chatbots, agents, research assistants, browser IDEs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@codemirror/view": ">=6.0.0",
|
|
55
55
|
"@xterm/addon-fit": ">=0.10.0",
|
|
56
56
|
"@xterm/xterm": ">=5.3.0",
|
|
57
|
-
"anyclaude-sdk": ">=0.
|
|
57
|
+
"anyclaude-sdk": ">=0.4.4",
|
|
58
58
|
"codemirror": ">=6.0.0",
|
|
59
59
|
"react": ">=18"
|
|
60
60
|
},
|