@cloudflare/think 0.7.3 → 0.8.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.
@@ -0,0 +1,342 @@
1
+ import { FileInfo, Workspace } from "@cloudflare/shell";
2
+
3
+ //#region src/tools/workspace.d.ts
4
+ type WorkspaceLike = Pick<
5
+ Workspace,
6
+ | "readFile"
7
+ | "readFileBytes"
8
+ | "writeFile"
9
+ | "readDir"
10
+ | "rm"
11
+ | "glob"
12
+ | "mkdir"
13
+ | "stat"
14
+ >;
15
+ interface ReadOperations {
16
+ readFile(path: string): Promise<string | null>;
17
+ readFileBytes(path: string): Promise<Uint8Array | null>;
18
+ stat(path: string): Promise<FileInfo | null> | FileInfo | null;
19
+ }
20
+ interface WriteOperations {
21
+ writeFile(path: string, content: string): Promise<void>;
22
+ mkdir(
23
+ path: string,
24
+ opts?: {
25
+ recursive?: boolean;
26
+ }
27
+ ): Promise<void> | void;
28
+ }
29
+ interface EditOperations {
30
+ readFile(path: string): Promise<string | null>;
31
+ writeFile(path: string, content: string): Promise<void>;
32
+ }
33
+ interface ListOperations {
34
+ readDir(
35
+ dir: string,
36
+ opts?: {
37
+ limit?: number;
38
+ offset?: number;
39
+ }
40
+ ): Promise<FileInfo[]> | FileInfo[];
41
+ }
42
+ interface FindOperations {
43
+ glob(pattern: string): Promise<FileInfo[]> | FileInfo[];
44
+ }
45
+ interface DeleteOperations {
46
+ rm(
47
+ path: string,
48
+ opts?: {
49
+ recursive?: boolean;
50
+ force?: boolean;
51
+ }
52
+ ): Promise<void>;
53
+ }
54
+ interface GrepOperations {
55
+ glob(pattern: string): Promise<FileInfo[]> | FileInfo[];
56
+ readFile(path: string): Promise<string | null>;
57
+ }
58
+ interface BashOperations {
59
+ readDir(
60
+ dir: string,
61
+ opts?: {
62
+ limit?: number;
63
+ offset?: number;
64
+ }
65
+ ): Promise<FileInfo[]> | FileInfo[];
66
+ readFileBytes(path: string): Promise<Uint8Array | null>;
67
+ writeFile(path: string, content: string): Promise<void>;
68
+ writeFileBytes?: (path: string, content: Uint8Array) => Promise<void>;
69
+ mkdir(
70
+ path: string,
71
+ opts?: {
72
+ recursive?: boolean;
73
+ }
74
+ ): Promise<void> | void;
75
+ rm(
76
+ path: string,
77
+ opts?: {
78
+ recursive?: boolean;
79
+ force?: boolean;
80
+ }
81
+ ): Promise<void>;
82
+ }
83
+ interface WorkspaceToolsOptions {
84
+ /**
85
+ * Include the default workspace Bash tool. Enabled by default; pass `false`
86
+ * to omit it, or an options object to tune execution limits.
87
+ */
88
+ bash?: boolean | Omit<BashToolOptions, "ops">;
89
+ }
90
+ type WorkspaceTools = {
91
+ read: ReturnType<typeof createReadTool>;
92
+ write: ReturnType<typeof createWriteTool>;
93
+ edit: ReturnType<typeof createEditTool>;
94
+ list: ReturnType<typeof createListTool>;
95
+ find: ReturnType<typeof createFindTool>;
96
+ grep: ReturnType<typeof createGrepTool>;
97
+ delete: ReturnType<typeof createDeleteTool>;
98
+ bash?: ReturnType<typeof createBashTool>;
99
+ };
100
+ /**
101
+ * Create a complete set of AI SDK tools backed by a workspace.
102
+ *
103
+ * Accepts either a concrete `Workspace` from `@cloudflare/shell` or any
104
+ * `WorkspaceLike` implementation — e.g. a proxy that forwards calls to a
105
+ * shared workspace owned by a parent DO.
106
+ *
107
+ * ```ts
108
+ * import { Workspace } from "@cloudflare/shell";
109
+ * import { createWorkspaceTools } from "@cloudflare/think";
110
+ *
111
+ * class MyAgent extends Agent<Env> {
112
+ * workspace = new Workspace({ sql: this.ctx.storage.sql, name: () => this.name });
113
+ *
114
+ * async onChatMessage() {
115
+ * const tools = createWorkspaceTools(this.workspace);
116
+ * const result = streamText({ model, tools, messages });
117
+ * return result.toUIMessageStreamResponse();
118
+ * }
119
+ * }
120
+ * ```
121
+ */
122
+ declare function createWorkspaceTools(
123
+ workspace: WorkspaceLike,
124
+ options?: WorkspaceToolsOptions
125
+ ): WorkspaceTools;
126
+ type TextReadToolOutput = {
127
+ path: string;
128
+ content: string;
129
+ totalLines: number;
130
+ fromLine?: number;
131
+ toLine?: number;
132
+ };
133
+ type ImageReadToolOutput = {
134
+ kind: "image";
135
+ path: string;
136
+ name: string;
137
+ mediaType: string;
138
+ sizeBytes: number;
139
+ };
140
+ type FileReadToolOutput = {
141
+ kind: "file";
142
+ path: string;
143
+ name: string;
144
+ mediaType: string;
145
+ sizeBytes: number;
146
+ };
147
+ type BinaryReadToolOutput = {
148
+ kind: "binary";
149
+ path: string;
150
+ name: string;
151
+ mediaType: string;
152
+ sizeBytes: number;
153
+ unsupported: true;
154
+ };
155
+ type ReadToolError = {
156
+ error: string;
157
+ };
158
+ type ReadToolOutput =
159
+ | TextReadToolOutput
160
+ | ImageReadToolOutput
161
+ | FileReadToolOutput
162
+ | BinaryReadToolOutput
163
+ | ReadToolError;
164
+ interface ReadToolOptions {
165
+ ops: ReadOperations;
166
+ }
167
+ declare function createReadTool(options: ReadToolOptions): import("ai").Tool<
168
+ {
169
+ path: string;
170
+ offset?: number | undefined;
171
+ limit?: number | undefined;
172
+ },
173
+ ReadToolOutput
174
+ >;
175
+ interface WriteToolOptions {
176
+ ops: WriteOperations;
177
+ }
178
+ declare function createWriteTool(options: WriteToolOptions): import("ai").Tool<
179
+ {
180
+ path: string;
181
+ content: string;
182
+ },
183
+ {
184
+ path: string;
185
+ bytesWritten: number;
186
+ lines: number;
187
+ }
188
+ >;
189
+ interface EditToolOptions {
190
+ ops: EditOperations;
191
+ }
192
+ declare function createEditTool(options: EditToolOptions): import("ai").Tool<
193
+ {
194
+ path: string;
195
+ old_string: string;
196
+ new_string: string;
197
+ },
198
+ | {
199
+ error: string;
200
+ path?: undefined;
201
+ created?: undefined;
202
+ lines?: undefined;
203
+ replaced?: undefined;
204
+ fuzzyMatch?: undefined;
205
+ }
206
+ | {
207
+ path: string;
208
+ created: boolean;
209
+ lines: number;
210
+ error?: undefined;
211
+ replaced?: undefined;
212
+ fuzzyMatch?: undefined;
213
+ }
214
+ | {
215
+ path: string;
216
+ replaced: boolean;
217
+ fuzzyMatch: boolean;
218
+ lines: number;
219
+ error?: undefined;
220
+ created?: undefined;
221
+ }
222
+ | {
223
+ path: string;
224
+ replaced: boolean;
225
+ lines: number;
226
+ error?: undefined;
227
+ created?: undefined;
228
+ fuzzyMatch?: undefined;
229
+ }
230
+ >;
231
+ interface ListToolOptions {
232
+ ops: ListOperations;
233
+ }
234
+ declare function createListTool(options: ListToolOptions): import("ai").Tool<
235
+ {
236
+ path: string;
237
+ limit?: number | undefined;
238
+ offset?: number | undefined;
239
+ },
240
+ {
241
+ path: string;
242
+ count: number;
243
+ entries: string[];
244
+ }
245
+ >;
246
+ interface FindToolOptions {
247
+ ops: FindOperations;
248
+ }
249
+ declare function createFindTool(options: FindToolOptions): import("ai").Tool<
250
+ {
251
+ pattern: string;
252
+ },
253
+ Record<string, unknown>
254
+ >;
255
+ interface GrepToolOptions {
256
+ ops: GrepOperations;
257
+ }
258
+ declare function createGrepTool(options: GrepToolOptions): import("ai").Tool<
259
+ {
260
+ query: string;
261
+ include?: string | undefined;
262
+ fixedString?: boolean | undefined;
263
+ caseSensitive?: boolean | undefined;
264
+ contextLines?: number | undefined;
265
+ },
266
+ Record<string, unknown>
267
+ >;
268
+ type BashChangedFiles = {
269
+ created: string[];
270
+ updated: string[];
271
+ deleted: string[];
272
+ directoriesCreated: string[];
273
+ directoriesDeleted: string[];
274
+ };
275
+ interface BashToolOptions {
276
+ ops: BashOperations;
277
+ timeout?: number;
278
+ network?: boolean;
279
+ maxWorkspaceFiles?: number;
280
+ maxWorkspaceFileBytes?: number;
281
+ maxOutputBytes?: number;
282
+ }
283
+ declare function createBashTool(options: BashToolOptions): import("ai").Tool<
284
+ {
285
+ script: string;
286
+ cwd?: string | undefined;
287
+ },
288
+ {
289
+ errors?: string[] | undefined;
290
+ skippedFiles?: string[] | undefined;
291
+ stdout: string;
292
+ stderr: string;
293
+ exitCode: number;
294
+ changedFiles: BashChangedFiles;
295
+ }
296
+ >;
297
+ interface DeleteToolOptions {
298
+ ops: DeleteOperations;
299
+ }
300
+ declare function createDeleteTool(
301
+ options: DeleteToolOptions
302
+ ): import("ai").Tool<
303
+ {
304
+ path: string;
305
+ recursive?: boolean | undefined;
306
+ },
307
+ {
308
+ deleted: string;
309
+ }
310
+ >;
311
+ //#endregion
312
+ export {
313
+ createFindTool as C,
314
+ createWorkspaceTools as D,
315
+ createReadTool as E,
316
+ createWriteTool as O,
317
+ createEditTool as S,
318
+ createListTool as T,
319
+ WorkspaceToolsOptions as _,
320
+ EditOperations as a,
321
+ createBashTool as b,
322
+ FindToolOptions as c,
323
+ ListOperations as d,
324
+ ListToolOptions as f,
325
+ WorkspaceTools as g,
326
+ WorkspaceLike as h,
327
+ DeleteToolOptions as i,
328
+ GrepOperations as l,
329
+ ReadToolOptions as m,
330
+ BashToolOptions as n,
331
+ EditToolOptions as o,
332
+ ReadOperations as p,
333
+ DeleteOperations as r,
334
+ FindOperations as s,
335
+ BashOperations as t,
336
+ GrepToolOptions as u,
337
+ WriteOperations as v,
338
+ createGrepTool as w,
339
+ createDeleteTool as x,
340
+ WriteToolOptions as y
341
+ };
342
+ //# sourceMappingURL=workspace-Bri0ANBX.d.ts.map
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "tools"
10
10
  ],
11
11
  "type": "module",
12
- "version": "0.7.3",
12
+ "version": "0.8.0",
13
13
  "license": "MIT",
14
14
  "repository": {
15
15
  "directory": "packages/think",
@@ -20,20 +20,25 @@
20
20
  "bugs": {
21
21
  "url": "https://github.com/cloudflare/agents/issues"
22
22
  },
23
- "devDependencies": {
23
+ "dependencies": {
24
+ "@cloudflare/codemode": "^0.3.8",
24
25
  "@cloudflare/shell": "^0.3.8",
26
+ "chat": "^4.29.0",
27
+ "just-bash": "^3.0.1"
28
+ },
29
+ "devDependencies": {
30
+ "@chat-adapter/telegram": "^4.29.0",
25
31
  "ai": "^6.0.185",
26
32
  "zod": "^4.4.3"
27
33
  },
28
34
  "peerDependencies": {
29
- "@cloudflare/codemode": ">=0.3.4 <1.0.0",
30
- "@cloudflare/shell": ">=0.3.4 <1.0.0",
31
- "agents": ">=0.12.4 <1.0.0",
32
- "ai": "^6.0.0",
35
+ "@chat-adapter/telegram": "^4.29.0",
36
+ "agents": ">=0.14.0 <1.0.0",
37
+ "ai": "^6.0.182",
33
38
  "zod": "^4.0.0"
34
39
  },
35
40
  "peerDependenciesMeta": {
36
- "@cloudflare/codemode": {
41
+ "@chat-adapter/telegram": {
37
42
  "optional": true
38
43
  }
39
44
  },
@@ -46,6 +51,18 @@
46
51
  "types": "./dist/extensions/index.d.ts",
47
52
  "import": "./dist/extensions/index.js"
48
53
  },
54
+ "./workflows": {
55
+ "types": "./dist/workflows.d.ts",
56
+ "import": "./dist/workflows.js"
57
+ },
58
+ "./messengers": {
59
+ "types": "./dist/messengers/index.d.ts",
60
+ "import": "./dist/messengers/index.js"
61
+ },
62
+ "./messengers/telegram": {
63
+ "types": "./dist/messengers/telegram.d.ts",
64
+ "import": "./dist/messengers/telegram.js"
65
+ },
49
66
  "./tools/workspace": {
50
67
  "types": "./dist/tools/workspace.d.ts",
51
68
  "import": "./dist/tools/workspace.js"