@cloudflare/ai-chat 0.9.4 → 0.10.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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ Tools with an `execute` function run on the server automatically:
|
|
|
102
102
|
|
|
103
103
|
```typescript
|
|
104
104
|
import { createWorkersAI } from "workers-ai-provider";
|
|
105
|
-
import { streamText, convertToModelMessages,
|
|
105
|
+
import { streamText, convertToModelMessages, isStepCount, tool } from "ai";
|
|
106
106
|
import { z } from "zod";
|
|
107
107
|
|
|
108
108
|
export class ChatAgent extends AIChatAgent {
|
|
@@ -122,7 +122,7 @@ export class ChatAgent extends AIChatAgent {
|
|
|
122
122
|
}
|
|
123
123
|
})
|
|
124
124
|
},
|
|
125
|
-
stopWhen:
|
|
125
|
+
stopWhen: isStepCount(5)
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
return result.toUIMessageStreamResponse();
|
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
SaveMessagesResult as SaveMessagesResult$1,
|
|
34
34
|
createToolsFromClientSchemas
|
|
35
35
|
} from "agents/chat";
|
|
36
|
-
import {
|
|
36
|
+
import { GenerateTextOnFinishCallback, ToolSet, UIMessage } from "ai";
|
|
37
37
|
|
|
38
38
|
//#region src/index.d.ts
|
|
39
39
|
type ChatRecoveryRetryData = {
|
|
@@ -826,7 +826,7 @@ declare class AIChatAgent<
|
|
|
826
826
|
* @returns Response to send to the client or undefined
|
|
827
827
|
*/
|
|
828
828
|
onChatMessage(
|
|
829
|
-
_onFinish:
|
|
829
|
+
_onFinish: GenerateTextOnFinishCallback<ToolSet>,
|
|
830
830
|
_options?: OnChatMessageOptions
|
|
831
831
|
): Promise<Response | undefined>;
|
|
832
832
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MessageType } from "./types.js";
|
|
2
2
|
import { autoTransformMessages } from "./ai-chat-v5-migration.js";
|
|
3
|
-
import { Agent, __DO_NOT_USE_WILL_BREAK__agentContext, isDurableObjectMemoryLimitReset } from "agents";
|
|
3
|
+
import { Agent, __DO_NOT_USE_WILL_BREAK__agentContext, __DO_NOT_USE_WILL_BREAK__withInvocationScope, isDurableObjectMemoryLimitReset } from "agents";
|
|
4
4
|
import { AbortRegistry, AgentToolProgressEmitter, AgentToolStreamProgressThrottle, AutoContinuationController, ChatRecoveryEngine, ChatStreamStalledError, ContinuationState, MAX_BOUND_PARAMS, PreStreamTurns, ResumableStream, ResumeHandshake, STREAM_CLEANUP_DELAY_SECONDS, StreamProgressCreditThrottle, SubmitConcurrencyController, TIMED_OUT, TurnQueue, aiSdkRecoveryCodec, applyChunkToParts, awaitWithDeadline, buildChatRecoveringFrame, buildInClauseStrings, bumpChatRecoveryProgress, chatRecoverySchedulePolicy, classifyAgentToolChildRecovery, cleanupStreamBuffers, clearChatTerminal, clientResolvableToolNames, createChatFiberSnapshot, createToolsFromClientSchemas, drainInteractionApplies, enforceRowSizeLimit, hasIncompleteToolBatch, interceptAgentToolBroadcast, isReplayChunk, iterateWithStallWatchdog, listActiveChatRecoveryIncidents, parseProtocolMessage, partAwaitsClientInteraction, pendingChatTerminal, persistReconstructedOrphan, readChatRecoveryProgress, reconcileMessages, reconcileOrphanPartial, recordChatTerminal, repairInterruptedToolParts, resolveChatRecoveryConfig, resolveToolMergeId, runChatRecoveryExhaustion, sanitizeMessage, sendIfOpen, setChatRecovering, shouldCreditStreamProgress, sweepStaleChatRecoveryIncidents, toolApprovalUpdate, unwrapChatFiberSnapshot, wrapChatFiberSnapshot } from "agents/chat";
|
|
5
5
|
import { nanoid } from "nanoid";
|
|
6
6
|
//#region src/index.ts
|
|
@@ -1223,12 +1223,12 @@ var AIChatAgent = class AIChatAgent extends Agent {
|
|
|
1223
1223
|
const generation = options?.epoch;
|
|
1224
1224
|
let result;
|
|
1225
1225
|
try {
|
|
1226
|
-
result = await this._turnQueue.enqueue(requestId, () => withAgentSpan(this, "chat_turn", "turn", {
|
|
1226
|
+
result = await this._turnQueue.enqueue(requestId, () => __DO_NOT_USE_WILL_BREAK__withInvocationScope(() => withAgentSpan(this, "chat_turn", "turn", {
|
|
1227
1227
|
"cloudflare.agents.component": "ai_chat",
|
|
1228
1228
|
"cloudflare.agents.turn.request_id": requestId,
|
|
1229
1229
|
"cloudflare.agents.turn.admission": "queue",
|
|
1230
1230
|
"cloudflare.agents.turn.generation": generation
|
|
1231
|
-
}, fn), { generation });
|
|
1231
|
+
}, fn), { detached: true }), { generation });
|
|
1232
1232
|
} finally {
|
|
1233
1233
|
const gen = generation ?? this._turnQueue.generation;
|
|
1234
1234
|
if (this._turnQueue.queuedCount(gen) === 0) this._mergeQueuedUserStartIndexByEpoch.delete(gen);
|