@markprompt/core
Advanced tools
Comparing version 0.26.0 to 0.26.1
@@ -52,2 +52,10 @@ import defaults from 'defaults'; | ||
}; | ||
function checkAbortSignal(signal) { | ||
if (signal?.aborted) { | ||
if (signal.reason instanceof Error) { | ||
throw signal.reason; | ||
} | ||
throw new Error(signal.reason); | ||
} | ||
} | ||
export async function* submitChat(messages, projectKey, options = {}) { | ||
@@ -85,2 +93,3 @@ if (!projectKey) { | ||
const data = parseEncodedJSONHeader(res, 'x-markprompt-data'); | ||
checkAbortSignal(options.signal); | ||
if (res.headers.get('Content-Type')?.includes('application/json')) { | ||
@@ -114,5 +123,3 @@ const json = await res.json(); | ||
if (!res.ok || !res.body) { | ||
if (options.signal?.aborted) { | ||
throw new Error(options.signal.reason); | ||
} | ||
checkAbortSignal(options.signal); | ||
const text = await res.text(); | ||
@@ -130,5 +137,3 @@ try { | ||
} | ||
if (options.signal?.aborted) { | ||
throw new Error(options.signal.reason); | ||
} | ||
checkAbortSignal(options.signal); | ||
// eslint-disable-next-line prefer-const | ||
@@ -158,2 +163,3 @@ let completion = {}; | ||
mergeWith(completion, json.choices[0]?.delta, concatStrings); | ||
checkAbortSignal(options.signal); | ||
/** | ||
@@ -166,2 +172,3 @@ * If we do not yield a structuredClone here, the completion object will | ||
} | ||
checkAbortSignal(options.signal); | ||
if (isChatCompletionMessage(completion) && isMarkpromptMetadata(data)) { | ||
@@ -168,0 +175,0 @@ return { ...completion, ...data }; |
{ | ||
"name": "@markprompt/core", | ||
"version": "0.26.0", | ||
"version": "0.26.1", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
59821
819