@qvac/sdk 0.2.0-dev.1760804157.f3c48d2 ā 0.2.1-dev.1760824861.f79d2c5
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.
|
@@ -45,8 +45,44 @@ export async function* stream(request) {
|
|
|
45
45
|
}
|
|
46
46
|
yield* streamWithProgress();
|
|
47
47
|
}
|
|
48
|
+
else if (request.type === "downloadAsset" &&
|
|
49
|
+
"withProgress" in request &&
|
|
50
|
+
request.withProgress) {
|
|
51
|
+
async function* streamWithProgress() {
|
|
52
|
+
const queue = [];
|
|
53
|
+
let done = false;
|
|
54
|
+
const downloadAssetHandler = handler;
|
|
55
|
+
downloadAssetHandler(request, (update) => queue.push(update))
|
|
56
|
+
.then((final) => {
|
|
57
|
+
queue.push(final);
|
|
58
|
+
done = true;
|
|
59
|
+
})
|
|
60
|
+
.catch((error) => {
|
|
61
|
+
done = true;
|
|
62
|
+
throw error;
|
|
63
|
+
});
|
|
64
|
+
while (!done || queue.length > 0) {
|
|
65
|
+
if (queue.length > 0) {
|
|
66
|
+
yield queue.shift();
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
yield* streamWithProgress();
|
|
74
|
+
}
|
|
48
75
|
else {
|
|
49
|
-
|
|
76
|
+
const result = handler(request);
|
|
77
|
+
// Check if the handler returns a Promise or AsyncGenerator
|
|
78
|
+
if (Symbol.asyncIterator in result) {
|
|
79
|
+
// It's an AsyncGenerator
|
|
80
|
+
yield* result;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// It's a Promise, await and yield the single result
|
|
84
|
+
yield await result;
|
|
85
|
+
}
|
|
50
86
|
}
|
|
51
87
|
}
|
|
52
88
|
const createMockRPCRequest = () => {
|
|
@@ -12,9 +12,9 @@ try {
|
|
|
12
12
|
const totalMB = (progress.total / 1024 / 1024).toFixed(2);
|
|
13
13
|
const percentage = progress.percentage.toFixed(1);
|
|
14
14
|
console.log(`š Progress: ${percentage}% (${downloadedMB}MB / ${totalMB}MB)`);
|
|
15
|
-
// Example: Stops at
|
|
16
|
-
if (parseFloat(percentage) >=
|
|
17
|
-
console.log("\nš« Auto-cancelling at
|
|
15
|
+
// Example: Stops at 10% (or use Ctrl+C for manual stop)
|
|
16
|
+
if (parseFloat(percentage) >= 10 && !cancelled) {
|
|
17
|
+
console.log("\nš« Auto-cancelling at 10% for demo purposes...,");
|
|
18
18
|
console.log(`š Progress: ${percentage}% (${downloadedMB}MB / ${totalMB}MB)`);
|
|
19
19
|
console.log(progress);
|
|
20
20
|
cancelled = true;
|
|
@@ -8,6 +8,7 @@ import { provideHandler } from "./provideHandler";
|
|
|
8
8
|
import { handleTranslate } from "./translate";
|
|
9
9
|
import { handleLoggingStream } from "./logging-stream";
|
|
10
10
|
import { handleRag } from "./rag";
|
|
11
|
+
import { cancelHandler } from "./cancelHandler";
|
|
11
12
|
export declare const handlers: {
|
|
12
13
|
completionStream: typeof handleCompletionStream;
|
|
13
14
|
downloadAsset: typeof handleDownloadAsset;
|
|
@@ -19,5 +20,6 @@ export declare const handlers: {
|
|
|
19
20
|
translate: typeof handleTranslate;
|
|
20
21
|
loggingStream: typeof handleLoggingStream;
|
|
21
22
|
rag: typeof handleRag;
|
|
23
|
+
cancel: typeof cancelHandler;
|
|
22
24
|
};
|
|
23
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -8,6 +8,7 @@ import { provideHandler } from "./provideHandler.js";
|
|
|
8
8
|
import { handleTranslate } from "./translate.js";
|
|
9
9
|
import { handleLoggingStream } from "./logging-stream.js";
|
|
10
10
|
import { handleRag } from "./rag.js";
|
|
11
|
+
import { cancelHandler } from "./cancelHandler.js";
|
|
11
12
|
export const handlers = {
|
|
12
13
|
completionStream: handleCompletionStream,
|
|
13
14
|
downloadAsset: handleDownloadAsset,
|
|
@@ -19,4 +20,5 @@ export const handlers = {
|
|
|
19
20
|
translate: handleTranslate,
|
|
20
21
|
loggingStream: handleLoggingStream,
|
|
21
22
|
rag: handleRag,
|
|
23
|
+
cancel: cancelHandler,
|
|
22
24
|
};
|