@qvac/core 0.6.3 → 0.6.5

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.
Files changed (102) hide show
  1. package/CHANGELOG.md +78 -1
  2. package/README.md +24 -16
  3. package/dist-lib/lib/api/chat-move.d.ts +3 -0
  4. package/dist-lib/lib/api/chat-move.js +7 -0
  5. package/dist-lib/lib/api/chat.d.ts +1 -1
  6. package/dist-lib/lib/api/chat.js +2 -1
  7. package/dist-lib/lib/api/chunk-delta.d.ts +7 -0
  8. package/dist-lib/lib/api/chunk-delta.js +33 -0
  9. package/dist-lib/lib/api/chunks.d.ts +1 -1
  10. package/dist-lib/lib/api/chunks.js +6 -3
  11. package/dist-lib/lib/api/index.d.ts +2 -0
  12. package/dist-lib/lib/api/index.js +2 -0
  13. package/dist-lib/lib/api/mesh.d.ts +2 -1
  14. package/dist-lib/lib/api/mesh.js +4 -0
  15. package/dist-lib/lib/assistant/harness.d.ts +8 -10
  16. package/dist-lib/lib/assistant.js +1 -1
  17. package/dist-lib/lib/constants.d.ts +1 -0
  18. package/dist-lib/lib/constants.js +1 -0
  19. package/dist-lib/lib/core/archived-mesh.js +3 -42
  20. package/dist-lib/lib/core/chat-activity.js +23 -10
  21. package/dist-lib/lib/core/chat-copy.d.ts +24 -0
  22. package/dist-lib/lib/core/chat-copy.js +115 -0
  23. package/dist-lib/lib/core/chat-move.d.ts +65 -0
  24. package/dist-lib/lib/core/chat-move.js +525 -0
  25. package/dist-lib/lib/core/chat.d.ts +6 -0
  26. package/dist-lib/lib/core/chat.js +11 -3
  27. package/dist-lib/lib/core/collections.d.ts +2 -0
  28. package/dist-lib/lib/core/collections.js +2 -0
  29. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  30. package/dist-lib/lib/core/contract/compute.js +2 -1
  31. package/dist-lib/lib/core/contract/index.js +2 -0
  32. package/dist-lib/lib/core/contract/invites.d.ts +1 -0
  33. package/dist-lib/lib/core/contract/invites.js +1 -1
  34. package/dist-lib/lib/core/contract/mesh-name.d.ts +3 -0
  35. package/dist-lib/lib/core/contract/mesh-name.js +26 -0
  36. package/dist-lib/lib/core/contract/writers.js +10 -3
  37. package/dist-lib/lib/core/files/index.d.ts +1 -1
  38. package/dist-lib/lib/core/files/index.js +1 -1
  39. package/dist-lib/lib/core/files/preview/index.js +4 -1
  40. package/dist-lib/lib/core/files/processing/source.js +4 -1
  41. package/dist-lib/lib/core/files/rag/limits.d.ts +0 -1
  42. package/dist-lib/lib/core/files/rag/limits.js +0 -1
  43. package/dist-lib/lib/core/files/store/index.d.ts +2 -1
  44. package/dist-lib/lib/core/files/store/index.js +2 -1
  45. package/dist-lib/lib/core/files/store/reference.d.ts +3 -0
  46. package/dist-lib/lib/core/files/store/reference.js +8 -0
  47. package/dist-lib/lib/core/files/store/sweep.js +3 -1
  48. package/dist-lib/lib/core/local/index.d.ts +4 -1
  49. package/dist-lib/lib/core/local/index.js +14 -1
  50. package/dist-lib/lib/core/mesh-seed-handoff.d.ts +3 -1
  51. package/dist-lib/lib/core/mesh-seed-handoff.js +1 -0
  52. package/dist-lib/lib/core/mesh.d.ts +5 -1
  53. package/dist-lib/lib/core/mesh.js +16 -1
  54. package/dist-lib/lib/core/sync/index.js +9 -1
  55. package/dist-lib/lib/core.d.ts +9 -0
  56. package/dist-lib/lib/core.js +156 -32
  57. package/dist-lib/lib/custom-model-pusher.js +9 -5
  58. package/dist-lib/lib/mesh-scoped-engine.js +5 -0
  59. package/dist-lib/schema/config.d.ts +1 -1
  60. package/dist-lib/schema/config.js +1 -1
  61. package/dist-lib/schema/engine.js +80 -1
  62. package/dist-lib/schema/local.js +17 -0
  63. package/dist-lib/schema/qvac.d.ts +2 -0
  64. package/dist-lib/schema/qvac.js +16 -0
  65. package/dist-lib/spec/bind.js +25 -0
  66. package/dist-lib/spec/calls.js +5 -0
  67. package/dist-lib/spec/capabilities.d.ts +10 -0
  68. package/dist-lib/spec/config/hyperconf/index.js +1 -1
  69. package/dist-lib/spec/hrpc/hrpc.json +65 -0
  70. package/dist-lib/spec/hrpc/index.js +66 -4
  71. package/dist-lib/spec/hrpc/messages.js +1398 -1154
  72. package/dist-lib/spec/hyperschema/index.js +1398 -1154
  73. package/dist-lib/spec/hyperschema/schema.json +204 -0
  74. package/dist-lib/spec/hyperschema/types.d.ts +47 -0
  75. package/dist-lib/spec/local/hyperdb/db.json +17 -1
  76. package/dist-lib/spec/local/hyperdb/index.js +83 -2
  77. package/dist-lib/spec/local/hyperdb/messages.js +340 -136
  78. package/dist-lib/spec/local/hyperschema/index.js +107 -2
  79. package/dist-lib/spec/local/hyperschema/schema.json +78 -1
  80. package/dist-lib/spec/local/hyperschema/types.d.ts +18 -1
  81. package/dist-lib/spec/mesh/hyperdb/db.json +16 -1
  82. package/dist-lib/spec/mesh/hyperdb/index.js +71 -2
  83. package/dist-lib/spec/mesh/hyperdb/messages.js +454 -228
  84. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
  85. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  86. package/dist-lib/spec/mesh/hyperdispatch/messages.js +150 -2
  87. package/dist-lib/spec/mesh/hyperschema/index.js +150 -2
  88. package/dist-lib/spec/mesh/hyperschema/schema.json +76 -1
  89. package/dist-lib/spec/mesh/hyperschema/types.d.ts +21 -1
  90. package/package.json +5 -8
  91. package/tui/app.mjs +89 -3
  92. package/tui/lib/move-command.mjs +17 -0
  93. package/dist-lib/lib/collabora/convert.d.ts +0 -9
  94. package/dist-lib/lib/collabora/convert.js +0 -65
  95. package/dist-lib/lib/collabora/entry.d.ts +0 -1
  96. package/dist-lib/lib/collabora/entry.js +0 -42
  97. package/dist-lib/lib/collabora/protocol.d.ts +0 -15
  98. package/dist-lib/lib/collabora/protocol.js +0 -31
  99. package/dist-lib/lib/collabora/worker.d.ts +0 -5
  100. package/dist-lib/lib/collabora/worker.js +0 -177
  101. package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +0 -2
  102. package/dist-lib/lib/core/files/rag/extract/office-collabora.js +0 -8
package/tui/app.mjs CHANGED
@@ -31,6 +31,7 @@ import { paintSelection, selectionText } from './lib/select.mjs'
31
31
  import { center, splash } from './lib/splash.mjs'
32
32
  import { wrapBlock, wrapLine } from './lib/wrap.mjs'
33
33
  import { knowledgeCommand } from './lib/knowledge-command.mjs'
34
+ import { describeMove } from './lib/move-command.mjs'
34
35
  import { saveUniqueFile } from './lib/save-file.mjs'
35
36
  import { usageReport } from './lib/usage.mjs'
36
37
  import { compactionTriggerRatio } from '../dist-lib/lib/compaction.js'
@@ -235,12 +236,14 @@ const COMMANDS = [
235
236
  // before `meshes`, so a bare /mesh offers the verb first and the list second
236
237
  {
237
238
  name: 'mesh',
238
- desc: 'switch which mesh is the active one, open another, or name one',
239
+ desc: 'switch which mesh is the active one, open another, name one, or move a chat into one',
239
240
  palette: true,
240
241
  sub: [
241
242
  { name: 'use', desc: '<n|id> — make one of your meshes the active one' },
242
243
  { name: 'new', desc: '[compute] — open another shared mesh, or lend this device’s model' },
243
- { name: 'label', desc: '<n|id> <name> — name a mesh, privately to you' }
244
+ { name: 'label', desc: '<n|id> <name> — name a mesh, privately to you' },
245
+ { name: 'move', desc: '<n|id> [chat] — move this chat, or a named one, into another mesh' },
246
+ { name: 'moved', desc: '[chat] — how the last move from this window is going' }
244
247
  ]
245
248
  },
246
249
  { name: 'meshes', desc: 'list the meshes this device belongs to', palette: true },
@@ -1639,6 +1642,8 @@ export class ChatApp {
1639
1642
  this._skills = skills || null
1640
1643
  this.agent = agent
1641
1644
  this.chatId = chatId
1645
+ // the chat /mesh moved reports on when named none: its source row is purged once it lands
1646
+ this._lastMove = null
1642
1647
  // applied only if this device is the agent's provider; null on a joiner
1643
1648
  this._modelName = modelName || null
1644
1649
  // run as init()'s first command so the connection happens inside the TUI, not before render
@@ -2260,6 +2265,7 @@ export class ChatApp {
2260
2265
  ' /members — list mesh members with their devices grouped',
2261
2266
  ' /meshes - list the meshes this device belongs to, numbered, marking account / shared / active / open / writable',
2262
2267
  ' /mesh use <n|id> - make one of them active; its agent, chat and roster replace the ones on screen',
2268
+ ' /mesh move <n|id> [chat] - move this chat (or the named one) into another mesh, its files and running turn with it · /mesh moved [chat] - how that move is going',
2263
2269
  ' /my-device — dump this device\u2019s CPU/GPU inventory (manufacturer, cores, drivers, …)'
2264
2270
  ].join('\n')
2265
2271
 
@@ -3420,7 +3426,17 @@ export class ChatApp {
3420
3426
  })
3421
3427
  }
3422
3428
 
3423
- return notice('usage: /mesh use <n|id> · /mesh new [compute] · /mesh label <n|id> <name>')
3429
+ if (action === 'move' && target) {
3430
+ return run(() => this._moveChat(target, labelParts.join(' ')))
3431
+ }
3432
+
3433
+ if (action === 'moved') {
3434
+ return run(() => this._movedChat(target))
3435
+ }
3436
+
3437
+ return notice(
3438
+ 'usage: /mesh use <n|id> · /mesh new [compute] · /mesh label <n|id> <name> · /mesh move <n|id> [chat] · /mesh moved [chat]'
3439
+ )
3424
3440
  }
3425
3441
 
3426
3442
  // the same interactive pickers as the menu's Switch rows, rather than a list to /…use by id
@@ -6523,6 +6539,76 @@ export class ChatApp {
6523
6539
  ]
6524
6540
  }
6525
6541
 
6542
+ // the target's first agent answers it there; a mesh with none leaves the chat waiting for one
6543
+ async _moveChat(selector, chatNeedle) {
6544
+ const named = await this._resolveMesh(selector)
6545
+ if (named.error) {
6546
+ return named.error
6547
+ }
6548
+
6549
+ const chat = await this._chatToMove(chatNeedle)
6550
+ if (chat.miss) {
6551
+ return chat.miss
6552
+ }
6553
+
6554
+ const { agents } = await this.engine.listAgents({ meshId: named.meshId })
6555
+ const move = await this.engine.moveChatToMesh({
6556
+ meshId: this.meshId,
6557
+ chatId: chat.id,
6558
+ targetMeshId: named.meshId,
6559
+ agentId: agents?.[0]?.id
6560
+ })
6561
+ this._lastMove = { id: chat.id, title: chat.title }
6562
+
6563
+ return this._describeMove(move, chat.title)
6564
+ }
6565
+
6566
+ async _movedChat(chatNeedle) {
6567
+ const chat = chatNeedle ? await this._chatToMove(chatNeedle) : this._lastMove
6568
+ if (!chat || chat.miss) {
6569
+ return chat?.miss ?? 'no move from this window yet - /mesh move <n|id> [chat]'
6570
+ }
6571
+
6572
+ const frames = this.engine.chatMoveWatch({ meshId: this.meshId, chatId: chat.id })
6573
+ try {
6574
+ for await (const move of frames) {
6575
+ return this._describeMove(move, chat.title)
6576
+ }
6577
+ } finally {
6578
+ frames.destroy()
6579
+ }
6580
+
6581
+ return 'the move watch ended'
6582
+ }
6583
+
6584
+ async _describeMove(move, title) {
6585
+ const { meshes } = await this.engine.listMeshes({}).catch(() => ({ meshes: [] }))
6586
+ const index = (meshes ?? []).findIndex((mesh) => mesh.meshId === move.targetMeshId)
6587
+ const where = index < 0 ? '/meshes lists it' : `/mesh use ${index + 1} to open it`
6588
+
6589
+ return describeMove(move, { title, where })
6590
+ }
6591
+
6592
+ async _chatToMove(needle) {
6593
+ if (!needle) {
6594
+ if (!this.chatId) {
6595
+ return { miss: 'no chat is open' }
6596
+ }
6597
+
6598
+ const { chats } = await this.engine.listChats({ meshId: this.meshId })
6599
+ const open = (chats ?? []).find((c) => c.id === this.chatId)
6600
+
6601
+ return { id: this.chatId, title: open?.title || 'this chat' }
6602
+ }
6603
+
6604
+ const { chat, ambiguous } = await this._resolveChat(needle)
6605
+ if (ambiguous) {
6606
+ return { miss: `"${needle}" matches ${ambiguous} chats — be specific` }
6607
+ }
6608
+
6609
+ return chat ? { id: chat.id, title: chat.title } : { miss: `no chat matching "${needle}"` }
6610
+ }
6611
+
6526
6612
  // The same selector /mesh use takes, so a mesh is named by its list number as well as its id
6527
6613
  async _resolveMesh(selector) {
6528
6614
  const { meshes } = await this.engine.listMeshes({})
@@ -0,0 +1,17 @@
1
+ // what one chatMoveWatch frame tells the person who typed /mesh move
2
+ export function describeMove(move, { title, where }) {
3
+ const short = move.targetMeshId.slice(0, 8)
4
+ if (move.state === 'failed') {
5
+ return `move of "${title}" failed: ${move.failure}`
6
+ }
7
+
8
+ if (move.state === 'carrying') {
9
+ const files = move.waiting?.length ? move.waiting.join(', ') : `${move.files - move.carried}`
10
+ return `"${title}" is in ${short} - waiting on ${files}; the source stays until they arrive, /mesh moved shows progress`
11
+ }
12
+
13
+ const retried = move.restarted ? ' - its running turn is answered again there' : ''
14
+ const settled = move.state === 'complete' ? 'moved' : 'moving'
15
+
16
+ return `${settled} "${title}" to ${short}${retried} - ${where}`
17
+ }
@@ -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,2 +0,0 @@
1
- import type { RagFileExtractor } from 'rag-extract';
2
- export declare const extractOfficeText: RagFileExtractor;
@@ -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
- };