| null =>
@@ -232,7 +233,7 @@ export const streamDirectCompanion = async (
abortSignal: options.signal,
});
for await (const part of result.fullStream) {
- options.signal?.throwIfAborted();
+ throwIfAborted(options.signal);
if (part.type === "error") throw part.error;
if (part.type !== "text-delta") continue;
const delta = typeof part.text === "string" ? part.text : "";
diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts
index e261d8f8..e2694572 100644
--- a/packages/client/src/index.ts
+++ b/packages/client/src/index.ts
@@ -2,6 +2,7 @@ import {
parsePreparedAiGeneration,
streamDirectAiGeneration,
} from "./ai-direct-stream";
+import { throwIfAborted } from "./abort-signal";
import { createPluginCapabilities } from './plugin-capabilities';
import type {
@@ -690,7 +691,7 @@ export const createEdgeEverClient = (options: EdgeEverClientOptions = {}) => {
payload: unknown,
streamOptions: { signal?: AbortSignal; onEvent: (event: CompanionEvent) => void },
) => {
- streamOptions.signal?.throwIfAborted();
+ throwIfAborted(streamOptions.signal);
const { context, response } = await send(preparePath, {
method: "POST", body: JSON.stringify(payload), signal: streamOptions.signal,
});
@@ -707,10 +708,10 @@ export const createEdgeEverClient = (options: EdgeEverClientOptions = {}) => {
prepare: () => Promise;
run: (prepared: P) => Promise;
}): Promise => {
- args.signal?.throwIfAborted();
+ throwIfAborted(args.signal);
const prepared = await args.prepare();
if (prepared == null) throw directAiUnavailable();
- args.signal?.throwIfAborted();
+ throwIfAborted(args.signal);
return args.run(prepared);
};
@@ -1077,7 +1078,7 @@ export const createEdgeEverClient = (options: EdgeEverClientOptions = {}) => {
},
streamAiGeneration: async (payload: AiGenerateInput, streamOptions: { signal?: AbortSignal; onEvent: (event: AiStreamEvent) => void }) => {
- streamOptions.signal?.throwIfAborted();
+ throwIfAborted(streamOptions.signal);
const { context, response } = await send("/api/v1/ai/generate/prepare", {
method: "POST", body: JSON.stringify(payload), signal: streamOptions.signal,
});
diff --git a/packages/client/src/infographic-direct.ts b/packages/client/src/infographic-direct.ts
index c3b988c4..ba586fbe 100644
--- a/packages/client/src/infographic-direct.ts
+++ b/packages/client/src/infographic-direct.ts
@@ -1,6 +1,7 @@
import { isStepCount, tool, ToolLoopAgent, type LanguageModel } from "ai";
import { z } from "zod";
import { infographicRequestsTimeline, type InfographicAgentEvent, type InfographicAgentRequest } from "@edgeever/shared";
+import { throwIfAborted } from "./abort-signal";
export const runInfographicAgent = async (args: {
input: InfographicAgentRequest;
@@ -64,7 +65,7 @@ export const runInfographicAgent = async (args: {
];
const result = await agent.stream({ messages, abortSignal: args.signal });
for await (const part of result.fullStream) {
- args.signal.throwIfAborted();
+ throwIfAborted(args.signal);
if (part.type === "error") throw part.error;
if (part.type !== "text-delta" || !part.text || !proposed || asked) continue;
response += part.text;