Skip to content

Commit 05cd90a

Browse files
authored
Add @cloudflare/workspace/tools entrypoint (#23)
* workspace: Add AI SDK tools entrypoint Add @cloudflare/workspace/tools as a separate package subpath for AI SDK tool wrappers. The entrypoint exposes createAITools() plus the underlying read, write, edit, ls, exec, and share helpers, while keeping ai and zod as optional peers so the main Workspace entrypoint stays independent of the AI SDK. Cover the tool set with focused tests for read-only mode, file operations, byte caps, backend routing, UTF-8-safe exec truncation, and asset sharing. * examples/think: Use workspace AI tools Replace the example's local workspace tool wrappers with createAITools() from @cloudflare/workspace/tools. The example keeps its report_update tool, passes the same backend guidance to the shared exec tool, and relies on Workspace assets for optional sharing. Remove the now-unused diff dependencies and update the example README so the documented tool sources match the migrated wiring. * docs: Document workspace tool interface Update the tool interface guide for the shipped @cloudflare/workspace/tools entrypoint. The docs now cover createAITools(), fixed tool names, read-only mode, opt-in exec, asset sharing, FileStore ranges, and the validation commands for the change. * workspace: Use a function type for remote add Represent RemoteAddFn as a function type instead of an interface with only a call signature. This keeps the artifacts CLI type shape the same while satisfying the workspace lint rule. * workspace, examples/think, docs: Rename publish tool Expose the assets-backed AI tool as publish instead of share while keeping the underlying Workspace assets client unchanged. Update the package exports, tests, Think documentation, and tool interface docs so the model-facing name is consistent. * workspace, examples/think, docs: Add Think compatibility option Add a useThink constructor option that attaches Think's WorkspaceLike filesystem methods to the Workspace instance. This lets Think consumers assign the Workspace directly while keeping the primary API on workspace.fs. Update the Think example to use the option, remove its local compatibility adapter, and document the new constructor option. * workspace, examples/think, docs: Address tools review feedback Restore model-facing exec fallback guidance, return structured exec errors, omit the publish prefix when no session id is configured, and cancel file read streams when byte-range reads stop before EOF. Keep diff bundled as an implementation detail by removing its optional peer declaration, and fix the assets README wording and Think tools table alignment.
1 parent e9e01d8 commit 05cd90a

29 files changed

Lines changed: 1479 additions & 729 deletions

docs/01_vfs.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ new Workspace({
3333
Workspace where `fs` works against the local SQLite store but
3434
`shell` throws.
3535

36-
`WorkspaceOptions` is `{ storage, backends, now? }`. There is no
37-
`root`, `sandbox`, or `sessionId` field on the host facade — sandbox
38-
wiring lives behind a `WorkspaceBackend`.
36+
`WorkspaceOptions` includes the storage handle, optional backends,
37+
clock, session id, mounts, observer, git identity, assets, artifacts,
38+
and `useThink`. There is no `root` or `sandbox` field on the host
39+
facade — sandbox wiring lives behind a `WorkspaceBackend`.
40+
41+
Set `useThink: true` when assigning the Workspace to
42+
`Think.workspace`. This adds Think's string-oriented filesystem
43+
compatibility methods (`readFile`, `readFileBytes`, `writeFile`,
44+
`readDir`, `rm`, `glob`, `mkdir`, and `stat`) directly to that
45+
Workspace instance while leaving the primary API on `workspace.fs`.
3946

4047
Illustrative layout (nothing below `/` is auto-created beyond
4148
`ROOT_INODE` itself):

0 commit comments

Comments
 (0)