@cloudflare/ai-chat 0.6.0 → 0.6.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/dist/index.js CHANGED
@@ -113,6 +113,7 @@ var AIChatAgent = class AIChatAgent extends Agent {
113
113
  this._abortRegistry = new AbortRegistry();
114
114
  const _onConnect = this.onConnect.bind(this);
115
115
  this.onConnect = async (connection, ctx) => {
116
+ if (this._cf_requestTargetsSubAgent(ctx.request)) return _onConnect(connection, ctx);
116
117
  if (this._resumableStream.hasActiveStream()) this._notifyStreamResuming(connection);
117
118
  return _onConnect(connection, ctx);
118
119
  };
@@ -126,6 +127,7 @@ var AIChatAgent = class AIChatAgent extends Agent {
126
127
  };
127
128
  const _onMessage = this.onMessage.bind(this);
128
129
  this.onMessage = async (connection, message) => {
130
+ if (this._cf_connectionTargetsSubAgent(connection)) return _onMessage(connection, message);
129
131
  if (typeof message === "string") {
130
132
  let data;
131
133
  try {
@@ -281,7 +283,13 @@ var AIChatAgent = class AIChatAgent extends Agent {
281
283
  if (this._resumableStream.hasActiveStream() && this._resumableStream.activeRequestId === data.id) {
282
284
  const orphanedStreamId = this._resumableStream.replayChunks(connection, this._resumableStream.activeRequestId);
283
285
  if (orphanedStreamId) this._persistOrphanedStream(orphanedStreamId);
284
- }
286
+ } else if (this._resumableStream.hasActiveStream()) {} else if (!this._resumableStream.replayCompletedChunksByRequestId(connection, data.id)) connection.send(JSON.stringify({
287
+ body: "",
288
+ done: true,
289
+ id: data.id,
290
+ type: "cf_agent_use_chat_response",
291
+ replay: true
292
+ }));
285
293
  return;
286
294
  }
287
295
  if (data.type === "cf_agent_tool_result") {