@qvac/core 0.6.3 → 1.0.0-rc.0
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/CHANGELOG.md +10 -1
- package/README.md +4 -12
- package/dist-lib/lib/api/host-run-log.d.ts +43 -0
- package/dist-lib/lib/api/host-run-log.js +97 -0
- package/dist-lib/lib/api/index.d.ts +3 -0
- package/dist-lib/lib/api/index.js +9 -0
- package/dist-lib/lib/api/instrument.js +33 -2
- package/dist-lib/lib/assistant/harness.d.ts +4 -1
- package/dist-lib/lib/assistant/history.d.ts +7 -2
- package/dist-lib/lib/assistant/history.js +34 -3
- package/dist-lib/lib/assistant/host-run-log.d.ts +3 -0
- package/dist-lib/lib/assistant/host-run-log.js +48 -0
- package/dist-lib/lib/assistant.d.ts +2 -0
- package/dist-lib/lib/assistant.js +817 -412
- package/dist-lib/lib/core/async-iterable.js +1 -1
- package/dist-lib/lib/core/chat-activity.d.ts +1 -1
- package/dist-lib/lib/core/chat-activity.js +16 -1
- package/dist-lib/lib/core/chat-search.js +11 -4
- package/dist-lib/lib/core/chunk.d.ts +3 -3
- package/dist-lib/lib/core/chunk.js +6 -2
- package/dist-lib/lib/core/files/rag/limits.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/limits.js +0 -1
- package/dist-lib/lib/core/harness-loan.js +4 -0
- package/dist-lib/lib/core/host-run-log-store.d.ts +114 -0
- package/dist-lib/lib/core/host-run-log-store.js +976 -0
- package/dist-lib/lib/core/prompt-history.js +3 -1
- package/dist-lib/lib/core/transcript-visibility.d.ts +19 -0
- package/dist-lib/lib/core/transcript-visibility.js +47 -0
- package/dist-lib/lib/core.d.ts +2 -0
- package/dist-lib/lib/core.js +36 -2
- package/dist-lib/lib/custom-model-pusher.js +9 -5
- package/dist-lib/lib/mesh-scoped-engine.js +5 -0
- package/dist-lib/lib/run-transcript.d.ts +10 -3
- package/dist-lib/lib/run-transcript.js +23 -5
- package/dist-lib/lib/task.js +6 -1
- package/dist-lib/schema/content.d.ts +1 -0
- package/dist-lib/schema/content.js +15 -3
- package/dist-lib/schema/engine.js +90 -3
- package/dist-lib/schema/indexes.js +10 -1
- package/dist-lib/schema/qvac.js +10 -2
- package/dist-lib/spec/bind.js +15 -0
- package/dist-lib/spec/calls.js +5 -0
- package/dist-lib/spec/capabilities.d.ts +10 -0
- package/dist-lib/spec/hrpc/hrpc.json +164 -99
- package/dist-lib/spec/hrpc/index.js +260 -200
- package/dist-lib/spec/hrpc/messages.js +1202 -898
- package/dist-lib/spec/hyperschema/index.js +1202 -898
- package/dist-lib/spec/hyperschema/schema.json +265 -0
- package/dist-lib/spec/hyperschema/types.d.ts +65 -3
- package/dist-lib/spec/mesh/hyperdb/messages.js +385 -241
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +138 -12
- package/dist-lib/spec/mesh/hyperschema/index.js +138 -12
- package/dist-lib/spec/mesh/hyperschema/schema.json +79 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +19 -3
- package/package.json +3 -7
- package/dist-lib/lib/collabora/convert.d.ts +0 -9
- package/dist-lib/lib/collabora/convert.js +0 -65
- package/dist-lib/lib/collabora/entry.d.ts +0 -1
- package/dist-lib/lib/collabora/entry.js +0 -42
- package/dist-lib/lib/collabora/protocol.d.ts +0 -15
- package/dist-lib/lib/collabora/protocol.js +0 -31
- package/dist-lib/lib/collabora/worker.d.ts +0 -5
- package/dist-lib/lib/collabora/worker.js +0 -177
- package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/extract/office-collabora.js +0 -8
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// This file is autogenerated by hyperschema-ts
|
|
2
|
-
// Schema version:
|
|
2
|
+
// Schema version: 13
|
|
3
3
|
// Do not edit manually.
|
|
4
4
|
|
|
5
|
-
export type QvacChunkType = "user-message" | "content" | "thinking" | "tool-call" | "tool-result" | "attachment" | "approval-request" | "run-status" | "run-request" | "sources" | "compaction"
|
|
5
|
+
export type QvacChunkType = "user-message" | "content" | "thinking" | "tool-call" | "tool-result" | "attachment" | "approval-request" | "run-status" | "run-request" | "sources" | "compaction" | "round-reset"
|
|
6
6
|
|
|
7
|
-
export type QvacRunState = "executing" | "completed" | "failed" | "canceled"
|
|
7
|
+
export type QvacRunState = "executing" | "completed" | "failed" | "canceled" | "paused" | "recovery-required"
|
|
8
8
|
|
|
9
9
|
export type QvacApprovalStatus = "pending" | "approved" | "denied"
|
|
10
10
|
|
|
@@ -140,6 +140,10 @@ export interface QvacChunkV1 {
|
|
|
140
140
|
capability?: string | null
|
|
141
141
|
capabilityArgs?: unknown | null
|
|
142
142
|
enhance?: QvacEnhanceMode | null
|
|
143
|
+
round?: number
|
|
144
|
+
callId?: string | null
|
|
145
|
+
resumed?: boolean
|
|
146
|
+
roundReset?: QvacChunkContentRoundReset | null
|
|
143
147
|
}
|
|
144
148
|
|
|
145
149
|
export type QvacChunk = (QvacChunkV1 & { version?: number })
|
|
@@ -179,6 +183,10 @@ export interface QvacAppendChunkOperationV1 {
|
|
|
179
183
|
capability?: string | null
|
|
180
184
|
capabilityArgs?: unknown | null
|
|
181
185
|
enhance?: QvacEnhanceMode | null
|
|
186
|
+
round?: number
|
|
187
|
+
callId?: string | null
|
|
188
|
+
resumed?: boolean
|
|
189
|
+
roundReset?: QvacChunkContentRoundReset | null
|
|
182
190
|
}
|
|
183
191
|
|
|
184
192
|
export type QvacAppendChunkOperation = (QvacAppendChunkOperationV1 & { version?: number })
|
|
@@ -808,6 +816,12 @@ export interface QvacPurgeChatOperationV1 {
|
|
|
808
816
|
|
|
809
817
|
export type QvacPurgeChatOperation = (QvacPurgeChatOperationV1 & { version?: number })
|
|
810
818
|
|
|
819
|
+
export interface QvacChunkContentRoundResetV1 {
|
|
820
|
+
replacedTypes?: QvacChunkType[] | null
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
export type QvacChunkContentRoundReset = (QvacChunkContentRoundResetV1 & { version?: number })
|
|
824
|
+
|
|
811
825
|
export interface SchemaTypes {
|
|
812
826
|
"@qvac/chunk-type": QvacChunkType
|
|
813
827
|
"@qvac/run-state": QvacRunState
|
|
@@ -979,4 +993,6 @@ export interface SchemaTypes {
|
|
|
979
993
|
"@qvac/purged-chat": QvacPurgedChat
|
|
980
994
|
"@qvac/purge-chat-operation-v1": QvacPurgeChatOperationV1
|
|
981
995
|
"@qvac/purge-chat-operation": QvacPurgeChatOperation
|
|
996
|
+
"@qvac/chunk-content-round-reset-v1": QvacChunkContentRoundResetV1
|
|
997
|
+
"@qvac/chunk-content-round-reset": QvacChunkContentRoundReset
|
|
982
998
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qvac/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-rc.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Peer-to-peer AI across your devices",
|
|
6
6
|
"engines": {
|
|
@@ -51,10 +51,6 @@
|
|
|
51
51
|
"types": "./dist-lib/lib/core/files/rag/models.d.ts",
|
|
52
52
|
"default": "./dist-lib/lib/core/files/rag/models.js"
|
|
53
53
|
},
|
|
54
|
-
"./rag/extract/office": {
|
|
55
|
-
"types": "./dist-lib/lib/core/files/rag/extract/office-collabora.d.ts",
|
|
56
|
-
"default": "./dist-lib/lib/core/files/rag/extract/office-collabora.js"
|
|
57
|
-
},
|
|
58
54
|
"./rag/limits": {
|
|
59
55
|
"types": "./dist-lib/lib/core/files/rag/limits.d.ts",
|
|
60
56
|
"default": "./dist-lib/lib/core/files/rag/limits.js"
|
|
@@ -223,7 +219,6 @@
|
|
|
223
219
|
"bare": "bare-fetch",
|
|
224
220
|
"default": "./dist-lib/lib/fetch-node.js"
|
|
225
221
|
},
|
|
226
|
-
"#collabora-worker-entry": "./dist-lib/lib/collabora/entry.js",
|
|
227
222
|
"worker_threads": {
|
|
228
223
|
"bare": "bare-worker",
|
|
229
224
|
"default": "worker_threads"
|
|
@@ -242,7 +237,7 @@
|
|
|
242
237
|
}
|
|
243
238
|
},
|
|
244
239
|
"dependencies": {
|
|
245
|
-
"@qvac/harness": "
|
|
240
|
+
"@qvac/harness": "1.0.0-rc.0",
|
|
246
241
|
"@qvac/skills": "^0.1.11",
|
|
247
242
|
"asenion": "^0.1.0",
|
|
248
243
|
"autobee": "^2.11.8",
|
|
@@ -279,6 +274,7 @@
|
|
|
279
274
|
"compact-encoding": "^3.4.0",
|
|
280
275
|
"corestore": "^7.12.6",
|
|
281
276
|
"hrpc": "^4.3.0",
|
|
277
|
+
"hyperbee2": "^2.18.0",
|
|
282
278
|
"hyperblobs": "^2.12.1",
|
|
283
279
|
"hyperconf": "^1.0.3",
|
|
284
280
|
"hypercore-blob-server": "^1.12.0",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AbortSignal } from 'bare-abort-controller';
|
|
2
|
-
export interface ConvertInput {
|
|
3
|
-
readonly bytes: Uint8Array;
|
|
4
|
-
readonly fileName: string;
|
|
5
|
-
readonly to: string;
|
|
6
|
-
readonly signal?: AbortSignal;
|
|
7
|
-
}
|
|
8
|
-
export declare function convert(input: ConvertInput): Promise<Uint8Array>;
|
|
9
|
-
export declare function convertToText(input: ConvertInput): Promise<string>;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
|
-
import { randomBytes } from 'crypto';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import os from 'os';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { convertInWorker } from './worker.js';
|
|
7
|
-
const ZIP_SIGNATURE = 0x04034b50;
|
|
8
|
-
const EOCD_SIGNATURE = 0x06054b50;
|
|
9
|
-
const EOCD_SIZE = 22;
|
|
10
|
-
const EOCD_SCAN = 65_535 + EOCD_SIZE;
|
|
11
|
-
export async function convert(input) {
|
|
12
|
-
assertIntactZip(input.bytes);
|
|
13
|
-
const base = path.join(os.tmpdir(), `qvac-collabora-${b4a.toHex(randomBytes(8))}`);
|
|
14
|
-
const src = `${base}${sourceExtension(input.fileName)}`;
|
|
15
|
-
const out = `${base}.${input.to}`;
|
|
16
|
-
try {
|
|
17
|
-
await fs.promises.writeFile(src, input.bytes);
|
|
18
|
-
await convertInWorker({ src, out, format: input.to }, input.signal);
|
|
19
|
-
return await fs.promises.readFile(out);
|
|
20
|
-
}
|
|
21
|
-
finally {
|
|
22
|
-
await unlinkQuiet(src);
|
|
23
|
-
await unlinkQuiet(out);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export async function convertToText(input) {
|
|
27
|
-
const bytes = await convert(input);
|
|
28
|
-
return stripBom(b4a.toString(bytes, 'utf8'));
|
|
29
|
-
}
|
|
30
|
-
function assertIntactZip(bytes) {
|
|
31
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
32
|
-
if (bytes.byteLength < EOCD_SIZE || view.getUint32(0, true) !== ZIP_SIGNATURE) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const eocd = findEocd(view);
|
|
36
|
-
if (eocd === -1) {
|
|
37
|
-
throw new Error('truncated document: the zip central directory is missing');
|
|
38
|
-
}
|
|
39
|
-
const directoryEnd = view.getUint32(eocd + 16, true) + view.getUint32(eocd + 12, true);
|
|
40
|
-
if (directoryEnd > eocd) {
|
|
41
|
-
throw new Error('truncated document: zip central directory is cut off');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function findEocd(view) {
|
|
45
|
-
const from = Math.max(0, view.byteLength - EOCD_SCAN);
|
|
46
|
-
for (let at = view.byteLength - EOCD_SIZE; at >= from; at--) {
|
|
47
|
-
if (view.getUint32(at, true) === EOCD_SIGNATURE)
|
|
48
|
-
return at;
|
|
49
|
-
}
|
|
50
|
-
return -1;
|
|
51
|
-
}
|
|
52
|
-
function sourceExtension(fileName) {
|
|
53
|
-
const ext = path.extname(fileName).toLowerCase();
|
|
54
|
-
return ext || '.doc';
|
|
55
|
-
}
|
|
56
|
-
function stripBom(text) {
|
|
57
|
-
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
58
|
-
}
|
|
59
|
-
async function unlinkQuiet(file) {
|
|
60
|
-
try {
|
|
61
|
-
await fs.promises.unlink(file);
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { parentPort } from 'worker_threads';
|
|
2
|
-
import { asHostJob } from './protocol.js';
|
|
3
|
-
import { errorMessage } from '../guards.js';
|
|
4
|
-
async function main() {
|
|
5
|
-
if (!parentPort) {
|
|
6
|
-
throw new Error('collabora entry loaded on the main thread');
|
|
7
|
-
}
|
|
8
|
-
const port = parentPort;
|
|
9
|
-
const convert = await load();
|
|
10
|
-
port.on('message', (message) => {
|
|
11
|
-
const job = asHostJob(message);
|
|
12
|
-
if (!job) {
|
|
13
|
-
port.close();
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (typeof convert === 'string') {
|
|
17
|
-
port.postMessage({ id: job.id, error: convert });
|
|
18
|
-
port.close();
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
port.postMessage(run(convert, job));
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
async function load() {
|
|
25
|
-
try {
|
|
26
|
-
const { Document } = await import('bare-collabora');
|
|
27
|
-
return (job) => void new Document(job.src).saveAs(job.out, job.format);
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
return `the document engine failed to load: ${errorMessage(error)}`;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function run(convert, job) {
|
|
34
|
-
try {
|
|
35
|
-
convert(job);
|
|
36
|
-
return { id: job.id, ok: true };
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
return { id: job.id, error: errorMessage(error) };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
await main();
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface HostJob {
|
|
2
|
-
readonly id: number;
|
|
3
|
-
readonly src: string;
|
|
4
|
-
readonly out: string;
|
|
5
|
-
readonly format: string;
|
|
6
|
-
}
|
|
7
|
-
export type WorkerReply = {
|
|
8
|
-
readonly id: number;
|
|
9
|
-
readonly ok: true;
|
|
10
|
-
} | {
|
|
11
|
-
readonly id: number;
|
|
12
|
-
readonly error: string;
|
|
13
|
-
};
|
|
14
|
-
export declare function asWorkerReply(value: unknown): WorkerReply | null;
|
|
15
|
-
export declare function asHostJob(value: unknown): HostJob | null;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export function asWorkerReply(value) {
|
|
2
|
-
if (typeof value !== 'object' || value === null || !('id' in value)) {
|
|
3
|
-
return null;
|
|
4
|
-
}
|
|
5
|
-
const id = value.id;
|
|
6
|
-
if (typeof id !== 'number') {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
if ('ok' in value && value.ok === true) {
|
|
10
|
-
return { id, ok: true };
|
|
11
|
-
}
|
|
12
|
-
if ('error' in value && typeof value.error === 'string') {
|
|
13
|
-
return { id, error: value.error };
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
export function asHostJob(value) {
|
|
18
|
-
if (typeof value !== 'object' || value === null)
|
|
19
|
-
return null;
|
|
20
|
-
if (!('id' in value && 'src' in value && 'out' in value && 'format' in value)) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
const { id, src, out, format } = value;
|
|
24
|
-
if (typeof id !== 'number') {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
if (typeof src !== 'string' || typeof out !== 'string' || typeof format !== 'string') {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
return { id, src, out, format };
|
|
31
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AbortSignal } from 'bare-abort-controller';
|
|
2
|
-
import { type HostJob } from './protocol.ts';
|
|
3
|
-
export type ConvertJob = Omit<HostJob, 'id'>;
|
|
4
|
-
export declare function convertInWorker(job: ConvertJob, signal?: AbortSignal): Promise<void>;
|
|
5
|
-
export declare function closeCollaboraWorker(): void;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import process from 'process';
|
|
2
|
-
import ScopeLock from 'scope-lock';
|
|
3
|
-
import safetyCatch from 'safety-catch';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
import { Worker as Thread } from 'worker_threads';
|
|
6
|
-
import { asWorkerReply } from './protocol.js';
|
|
7
|
-
import { errorMessage } from '../guards.js';
|
|
8
|
-
const DEADLINE_MS = 60_000;
|
|
9
|
-
const lock = new ScopeLock();
|
|
10
|
-
let active = null;
|
|
11
|
-
export async function convertInWorker(job, signal) {
|
|
12
|
-
await lock.lock();
|
|
13
|
-
try {
|
|
14
|
-
const worker = active ?? (active = spawn());
|
|
15
|
-
const id = worker.nextId++;
|
|
16
|
-
worker.link.ref();
|
|
17
|
-
try {
|
|
18
|
-
worker.link.write({ id, ...job });
|
|
19
|
-
await settle(worker, id, signal);
|
|
20
|
-
}
|
|
21
|
-
finally {
|
|
22
|
-
worker.link.unref();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
finally {
|
|
26
|
-
lock.unlock();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export function closeCollaboraWorker() {
|
|
30
|
-
if (!active)
|
|
31
|
-
return;
|
|
32
|
-
active.link.kill();
|
|
33
|
-
active = null;
|
|
34
|
-
}
|
|
35
|
-
async function settle(worker, id, signal) {
|
|
36
|
-
const deadline = timeout(deadlineMs());
|
|
37
|
-
const cancel = cancellation(signal);
|
|
38
|
-
try {
|
|
39
|
-
const landed = reply(worker, id).catch((error) => {
|
|
40
|
-
abandon(worker);
|
|
41
|
-
throw error;
|
|
42
|
-
});
|
|
43
|
-
const outcome = await Promise.race([landed, deadline.expired, cancel.cancelled]);
|
|
44
|
-
if (typeof outcome === 'string') {
|
|
45
|
-
abandon(worker);
|
|
46
|
-
throw new Error(outcome === 'deadline' ? 'the document engine stopped responding' : 'conversion cancelled');
|
|
47
|
-
}
|
|
48
|
-
if (outcome.error) {
|
|
49
|
-
throw new Error(outcome.error);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
finally {
|
|
53
|
-
deadline.clear();
|
|
54
|
-
cancel.clear();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async function reply(worker, id) {
|
|
58
|
-
const message = asWorkerReply(await worker.link.read());
|
|
59
|
-
if (!message) {
|
|
60
|
-
throw new Error('the document engine closed unexpectedly');
|
|
61
|
-
}
|
|
62
|
-
if (message.id !== id) {
|
|
63
|
-
throw new Error('the document engine answered a different conversion');
|
|
64
|
-
}
|
|
65
|
-
return 'error' in message ? { error: message.error } : {};
|
|
66
|
-
}
|
|
67
|
-
function abandon(worker) {
|
|
68
|
-
if (active === worker) {
|
|
69
|
-
active = null;
|
|
70
|
-
}
|
|
71
|
-
worker.link.kill();
|
|
72
|
-
}
|
|
73
|
-
function spawn() {
|
|
74
|
-
if (typeof Bare === 'undefined') {
|
|
75
|
-
throw new Error('the document engine needs the Bare runtime');
|
|
76
|
-
}
|
|
77
|
-
let thread;
|
|
78
|
-
try {
|
|
79
|
-
thread = new Thread(entry());
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
throw new Error(`the document engine failed to load: ${errorMessage(error)}`);
|
|
83
|
-
}
|
|
84
|
-
const inbox = new Inbox(thread);
|
|
85
|
-
thread.unref();
|
|
86
|
-
return {
|
|
87
|
-
nextId: 1,
|
|
88
|
-
link: {
|
|
89
|
-
read: () => inbox.read(),
|
|
90
|
-
write: (job) => thread.postMessage(job),
|
|
91
|
-
ref: () => thread.ref(),
|
|
92
|
-
unref: () => thread.unref(),
|
|
93
|
-
kill() {
|
|
94
|
-
thread.unref();
|
|
95
|
-
thread.terminate().catch(safetyCatch);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
class Inbox {
|
|
101
|
-
replies = [];
|
|
102
|
-
waiting = [];
|
|
103
|
-
ended = false;
|
|
104
|
-
failure = null;
|
|
105
|
-
constructor(thread) {
|
|
106
|
-
thread.on('message', (reply) => this.push(reply));
|
|
107
|
-
thread.on('error', (error) => this.end(error));
|
|
108
|
-
thread.on('exit', () => this.end());
|
|
109
|
-
}
|
|
110
|
-
read() {
|
|
111
|
-
if (this.replies.length > 0) {
|
|
112
|
-
return Promise.resolve(this.replies.shift());
|
|
113
|
-
}
|
|
114
|
-
if (this.failure) {
|
|
115
|
-
return Promise.reject(this.failure);
|
|
116
|
-
}
|
|
117
|
-
if (this.ended) {
|
|
118
|
-
return Promise.resolve(null);
|
|
119
|
-
}
|
|
120
|
-
return new Promise((resolve, reject) => this.waiting.push({ resolve, reject }));
|
|
121
|
-
}
|
|
122
|
-
push(reply) {
|
|
123
|
-
const next = this.waiting.shift();
|
|
124
|
-
if (next) {
|
|
125
|
-
next.resolve(reply);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
this.replies.push(reply);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
end(error) {
|
|
132
|
-
if (this.ended) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
this.ended = true;
|
|
136
|
-
if (error !== undefined) {
|
|
137
|
-
this.failure = new Error(`the document engine closed unexpectedly: ${errorMessage(error)}`);
|
|
138
|
-
}
|
|
139
|
-
for (const next of this.waiting.splice(0)) {
|
|
140
|
-
if (this.failure) {
|
|
141
|
-
next.reject(this.failure);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
next.resolve(null);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function entry() {
|
|
150
|
-
return (process.env.QVAC_COLLABORA_WORKER_ENTRY ||
|
|
151
|
-
fileURLToPath(import.meta.resolve('#collabora-worker-entry')));
|
|
152
|
-
}
|
|
153
|
-
function deadlineMs() {
|
|
154
|
-
const ms = Number(process.env.QVAC_COLLABORA_TIMEOUT_MS);
|
|
155
|
-
return ms > 0 ? ms : DEADLINE_MS;
|
|
156
|
-
}
|
|
157
|
-
function timeout(ms) {
|
|
158
|
-
let timer;
|
|
159
|
-
const expired = new Promise((resolve) => {
|
|
160
|
-
timer = setTimeout(() => resolve('deadline'), ms);
|
|
161
|
-
});
|
|
162
|
-
return { expired, clear: () => clearTimeout(timer) };
|
|
163
|
-
}
|
|
164
|
-
function cancellation(signal) {
|
|
165
|
-
if (!signal) {
|
|
166
|
-
return { cancelled: new Promise(() => { }), clear: () => { } };
|
|
167
|
-
}
|
|
168
|
-
if (signal.aborted) {
|
|
169
|
-
return { cancelled: Promise.resolve('aborted'), clear: () => { } };
|
|
170
|
-
}
|
|
171
|
-
let onAbort = () => { };
|
|
172
|
-
const cancelled = new Promise((resolve) => {
|
|
173
|
-
onAbort = () => resolve('aborted');
|
|
174
|
-
signal.addEventListener('abort', onAbort);
|
|
175
|
-
});
|
|
176
|
-
return { cancelled, clear: () => signal.removeEventListener('abort', onAbort) };
|
|
177
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { convertToText } from '../../../../collabora/convert.js';
|
|
2
|
-
import { MAX_OFFICE_BYTES } from '../limits.js';
|
|
3
|
-
export const extractOfficeText = (bytes, fileName, opts) => {
|
|
4
|
-
if (bytes.byteLength > MAX_OFFICE_BYTES) {
|
|
5
|
-
throw new Error(`document is too large to convert: ${bytes.byteLength} bytes, limit ${MAX_OFFICE_BYTES}`);
|
|
6
|
-
}
|
|
7
|
-
return convertToText({ bytes, fileName, to: 'md', signal: opts?.signal });
|
|
8
|
-
};
|