@cloudflare/think 0.5.0 → 0.5.1

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
@@ -67,6 +67,8 @@ drill-in, and cleanup patterns.
67
67
 
68
68
  Every Think agent gets `this.workspace` — a virtual filesystem backed by the DO's SQLite storage. Workspace tools (`read`, `write`, `edit`, `list`, `find`, `grep`, `delete`) are automatically available to the model.
69
69
 
70
+ The `read` tool returns line-numbered text for text files. For images and PDFs, it keeps the persisted tool result compact and passes file bytes to multimodal-capable models using AI SDK content parts.
71
+
70
72
  ```ts
71
73
  export class MyAgent extends Think<Env> {
72
74
  getModel() { ... }
package/dist/think.js CHANGED
@@ -437,7 +437,7 @@ var Think = class Think extends Agent {
437
437
  };
438
438
  const system = await this.session.freezeSystemPrompt() || this.getSystemPrompt();
439
439
  const messages = pruneMessages({
440
- messages: await convertToModelMessages(truncateOlderMessages(this.session.getHistory())),
440
+ messages: await convertToModelMessages(truncateOlderMessages(this.session.getHistory()), { tools }),
441
441
  toolCalls: "before-last-2-messages"
442
442
  });
443
443
  if (messages.length === 0) throw new Error("No messages to send to the model. This usually means the chat request arrived before any messages were persisted.");
@@ -1187,6 +1187,7 @@ var Think = class Think extends Agent {
1187
1187
  _setupProtocolHandlers() {
1188
1188
  const _onConnect = this.onConnect.bind(this);
1189
1189
  this.onConnect = async (connection, ctx) => {
1190
+ if (this._cf_requestTargetsSubAgent(ctx.request)) return _onConnect(connection, ctx);
1190
1191
  if (this._resumableStream.hasActiveStream()) this._notifyStreamResuming(connection);
1191
1192
  else connection.send(JSON.stringify({
1192
1193
  type: MSG_CHAT_MESSAGES,
@@ -1204,6 +1205,7 @@ var Think = class Think extends Agent {
1204
1205
  };
1205
1206
  const _onMessage = this.onMessage.bind(this);
1206
1207
  this.onMessage = async (connection, message) => {
1208
+ if (this._cf_connectionTargetsSubAgent(connection)) return _onMessage(connection, message);
1207
1209
  if (typeof message === "string") {
1208
1210
  const event = parseProtocolMessage(message);
1209
1211
  if (event) {
@@ -1279,7 +1281,13 @@ var Think = class Think extends Agent {
1279
1281
  if (this._resumableStream.hasActiveStream() && this._resumableStream.activeRequestId === requestId) {
1280
1282
  const orphanedStreamId = this._resumableStream.replayChunks(connection, this._resumableStream.activeRequestId);
1281
1283
  if (orphanedStreamId) this._persistOrphanedStream(orphanedStreamId);
1282
- }
1284
+ } else if (this._resumableStream.hasActiveStream()) {} else if (!this._resumableStream.replayCompletedChunksByRequestId(connection, requestId)) connection.send(JSON.stringify({
1285
+ body: "",
1286
+ done: true,
1287
+ id: requestId,
1288
+ type: MSG_CHAT_RESPONSE,
1289
+ replay: true
1290
+ }));
1283
1291
  }
1284
1292
  async _handleChatRequest(connection, event) {
1285
1293
  if (!event.init?.body) return;