Skip to content

Add @cloudflare/workspace/tools entrypoint - #23

Merged
aron-cf merged 7 commits into
mainfrom
tools
Jul 29, 2026
Merged

Add @cloudflare/workspace/tools entrypoint#23
aron-cf merged 7 commits into
mainfrom
tools

Conversation

@aron-cf

@aron-cf aron-cf commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

This change adds a reusable @cloudflare/workspace/tools entrypoint for agents that want ready-made AI SDK tools backed by a Workspace. The Think example had its own local copies of these tools, which made it easy for behavior to drift from the package. Moving the tools into @cloudflare/workspace gives examples and package consumers the same file, shell, and publishing behavior.

The new entrypoint exposes createAITools() and lower-level helpers for the fixed tool names read, write, edit, ls, optional exec, and optional publish. The main @cloudflare/workspace entrypoint stays independent of the AI SDK because ai and zod are optional peers only for the tools subpath. exec is opt-in through shell backend configuration, readonly: true exposes only read and ls, and publish appears only when workspace.assets is configured unless callers disable it with assets: false.

Workspace now also accepts useThink: true. That option adds Think's string-oriented filesystem compatibility methods directly to the instance, so a Workspace can be assigned to Think.workspace without a local adapter. The compatibility methods are only added when the option is set; the primary file API remains workspace.fs.

The Think example now imports createAITools() from @cloudflare/workspace/tools, constructs its Workspace with useThink: true, and keeps only its example-specific report_update tool locally. It passes the same backend guidance to the shared exec tool, keeps workspaceBash disabled, uses the publish tool name for assets, and drops the local duplicate filesystem, shell, and asset tool implementations.

Manual verification is to build the workspace package, run the focused tests, and typecheck both the package and the Think example:

npm run build --workspace @cloudflare/workspace
cd packages/workspace && npx vitest run src/workspace.test.ts src/tools/ai.test.ts
npm run typecheck --workspace @cloudflare/workspace
npm run typecheck --workspace @cloudflare/example-think
npm run check

The Think local setup can also be checked with:

npm run seed:r2:local --workspace @cloudflare/example-think
cd examples/think && npm run dev

wrangler dev requires Cloudflare credentials because the example uses a remote Workers AI binding. With credentials and Docker available, the example should start with local durable objects, workflows, R2 buckets, Worker Loader, and the container definition.

The documentation now describes the shipped tools interface, documents useThink, lists the tools subpath in the docs index, and updates the package and Think READMEs to point at the shared implementation. Follow-up work can add provider-specific adapters beyond the AI SDK if another tool format needs first-class support.

aron-cf added 5 commits July 29, 2026 21:55
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.
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.
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.
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.
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.
@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/workspace/@cloudflare/workspace@23

commit: b94808c

aron-cf added 2 commits July 29, 2026 23:26
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.
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.
@aron-cf
aron-cf marked this pull request as ready for review July 29, 2026 23:43
@aron-cf
aron-cf merged commit 05cd90a into main Jul 29, 2026
11 checks passed
@aron-cf
aron-cf deleted the tools branch July 29, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant