@qvac/core 0.3.4 → 0.4.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.
Files changed (166) hide show
  1. package/README.md +19 -17
  2. package/dist-lib/lib/api/agents.d.ts +3 -3
  3. package/dist-lib/lib/api/agents.js +31 -20
  4. package/dist-lib/lib/api/approval-rules.d.ts +2 -2
  5. package/dist-lib/lib/api/approval-rules.js +2 -2
  6. package/dist-lib/lib/api/attachments.d.ts +2 -2
  7. package/dist-lib/lib/api/attachments.js +14 -25
  8. package/dist-lib/lib/api/chat-groups.d.ts +2 -2
  9. package/dist-lib/lib/api/chat-groups.js +9 -9
  10. package/dist-lib/lib/api/chat.d.ts +4 -2
  11. package/dist-lib/lib/api/chat.js +18 -18
  12. package/dist-lib/lib/api/chunks.d.ts +2 -2
  13. package/dist-lib/lib/api/chunks.js +27 -36
  14. package/dist-lib/lib/api/current-mesh.d.ts +7 -15
  15. package/dist-lib/lib/api/current-mesh.js +7 -22
  16. package/dist-lib/lib/api/devices.d.ts +4 -3
  17. package/dist-lib/lib/api/devices.js +18 -18
  18. package/dist-lib/lib/api/execution.d.ts +2 -2
  19. package/dist-lib/lib/api/execution.js +6 -6
  20. package/dist-lib/lib/api/files.d.ts +2 -2
  21. package/dist-lib/lib/api/files.js +4 -4
  22. package/dist-lib/lib/api/index.d.ts +12 -11
  23. package/dist-lib/lib/api/index.js +15 -13
  24. package/dist-lib/lib/api/inference-calls.d.ts +1 -1
  25. package/dist-lib/lib/api/inference-calls.js +2 -2
  26. package/dist-lib/lib/api/knowledge.d.ts +2 -2
  27. package/dist-lib/lib/api/knowledge.js +22 -11
  28. package/dist-lib/lib/api/local-files.d.ts +3 -0
  29. package/dist-lib/lib/api/local-files.js +23 -0
  30. package/dist-lib/lib/api/members.d.ts +6 -2
  31. package/dist-lib/lib/api/members.js +24 -17
  32. package/dist-lib/lib/api/mesh.d.ts +4 -5
  33. package/dist-lib/lib/api/mesh.js +7 -9
  34. package/dist-lib/lib/api/notifications.d.ts +2 -13
  35. package/dist-lib/lib/api/notifications.js +20 -52
  36. package/dist-lib/lib/api/rag.d.ts +2 -2
  37. package/dist-lib/lib/api/rag.js +4 -4
  38. package/dist-lib/lib/api/range.d.ts +11 -0
  39. package/dist-lib/lib/api/range.js +10 -0
  40. package/dist-lib/lib/api/sync.d.ts +2 -2
  41. package/dist-lib/lib/api/sync.js +3 -3
  42. package/dist-lib/lib/api/tool-activity.d.ts +2 -2
  43. package/dist-lib/lib/api/tool-activity.js +11 -10
  44. package/dist-lib/lib/api/tool-configs.d.ts +2 -2
  45. package/dist-lib/lib/api/tool-configs.js +6 -7
  46. package/dist-lib/lib/api/upload-frames.d.ts +9 -0
  47. package/dist-lib/lib/api/upload-frames.js +17 -0
  48. package/dist-lib/lib/api/watchable.d.ts +1 -6
  49. package/dist-lib/lib/api/watchable.js +4 -13
  50. package/dist-lib/lib/assistant/history.d.ts +3 -3
  51. package/dist-lib/lib/assistant-client.js +3 -2
  52. package/dist-lib/lib/assistant-tree.js +1 -1
  53. package/dist-lib/lib/assistant.d.ts +16 -14
  54. package/dist-lib/lib/assistant.js +166 -137
  55. package/dist-lib/lib/collabora/convert.js +1 -1
  56. package/dist-lib/lib/core/agent.d.ts +5 -7
  57. package/dist-lib/lib/core/agent.js +26 -6
  58. package/dist-lib/lib/core/archived-mesh.js +1 -0
  59. package/dist-lib/lib/core/chat-order.d.ts +20 -0
  60. package/dist-lib/lib/core/chat-order.js +96 -0
  61. package/dist-lib/lib/core/chat.d.ts +0 -5
  62. package/dist-lib/lib/core/chat.js +1 -3
  63. package/dist-lib/lib/core/chunk.d.ts +7 -14
  64. package/dist-lib/lib/core/chunk.js +17 -35
  65. package/dist-lib/lib/core/contract/agents.js +8 -0
  66. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  67. package/dist-lib/lib/core/contract/compute.js +1 -0
  68. package/dist-lib/lib/core/contract/joined-meshes.js +4 -3
  69. package/dist-lib/lib/core/contract/members.js +4 -3
  70. package/dist-lib/lib/core/contract/writers.js +5 -4
  71. package/dist-lib/lib/core/departures.js +5 -4
  72. package/dist-lib/lib/core/device-invites.js +2 -1
  73. package/dist-lib/lib/core/files/attachments.d.ts +8 -1
  74. package/dist-lib/lib/core/files/index.d.ts +4 -4
  75. package/dist-lib/lib/core/files/index.js +18 -8
  76. package/dist-lib/lib/core/files/local-index.d.ts +16 -0
  77. package/dist-lib/lib/core/files/local-index.js +38 -0
  78. package/dist-lib/lib/core/files/processing/document.js +2 -1
  79. package/dist-lib/lib/core/files/processing/ownership.js +6 -3
  80. package/dist-lib/lib/core/files/records/chunks.js +1 -0
  81. package/dist-lib/lib/core/files/records/reclaim.js +1 -0
  82. package/dist-lib/lib/core/files/records/routing.js +2 -1
  83. package/dist-lib/lib/core/files/store/blob.d.ts +1 -1
  84. package/dist-lib/lib/core/files/store/blob.js +6 -3
  85. package/dist-lib/lib/core/files/store/index.d.ts +1 -1
  86. package/dist-lib/lib/core/files/store/reference.js +4 -3
  87. package/dist-lib/lib/core/files/store/server.d.ts +8 -4
  88. package/dist-lib/lib/core/files/store/server.js +16 -12
  89. package/dist-lib/lib/core/files/store/sweep.js +2 -1
  90. package/dist-lib/lib/core/files/upload.d.ts +1 -1
  91. package/dist-lib/lib/core/hosted-agents.js +1 -1
  92. package/dist-lib/lib/core/image/cache-sweep.d.ts +1 -0
  93. package/dist-lib/lib/core/image/cache-sweep.js +7 -3
  94. package/dist-lib/lib/core/local/files.d.ts +24 -0
  95. package/dist-lib/lib/core/local/files.js +154 -0
  96. package/dist-lib/lib/core/local/index.d.ts +21 -5
  97. package/dist-lib/lib/core/local/index.js +75 -45
  98. package/dist-lib/lib/core/membership.d.ts +4 -1
  99. package/dist-lib/lib/core/membership.js +17 -2
  100. package/dist-lib/lib/core/mesh.d.ts +5 -0
  101. package/dist-lib/lib/core/mesh.js +11 -5
  102. package/dist-lib/lib/core/migrations/agent-indexes.d.ts +2 -0
  103. package/dist-lib/lib/core/migrations/agent-indexes.js +30 -0
  104. package/dist-lib/lib/core/migrations/file-index.d.ts +2 -0
  105. package/dist-lib/lib/core/migrations/file-index.js +27 -0
  106. package/dist-lib/lib/core/migrations/index.js +3 -1
  107. package/dist-lib/lib/core/notification.js +5 -5
  108. package/dist-lib/lib/core/range.d.ts +18 -0
  109. package/dist-lib/lib/core/range.js +17 -0
  110. package/dist-lib/lib/core/sync/index.js +39 -32
  111. package/dist-lib/lib/core/sync-status.js +3 -2
  112. package/dist-lib/lib/core/tool-activity.d.ts +2 -5
  113. package/dist-lib/lib/core/tool-activity.js +4 -7
  114. package/dist-lib/lib/core.d.ts +48 -29
  115. package/dist-lib/lib/core.js +465 -359
  116. package/dist-lib/lib/knowledge-search.d.ts +2 -2
  117. package/dist-lib/lib/kv-cache.js +1 -1
  118. package/dist-lib/lib/log.js +2 -3
  119. package/dist-lib/lib/mesh-scoped-engine.d.ts +8 -1
  120. package/dist-lib/lib/mesh-scoped-engine.js +62 -15
  121. package/dist-lib/lib/model-download.d.ts +14 -5
  122. package/dist-lib/lib/model-download.js +25 -17
  123. package/dist-lib/lib/run-transcript.d.ts +2 -2
  124. package/dist-lib/lib/run-transcript.js +3 -2
  125. package/dist-lib/lib/task.d.ts +1 -0
  126. package/dist-lib/lib/task.js +3 -2
  127. package/dist-lib/schema/build.js +4 -10
  128. package/dist-lib/schema/engine.js +261 -91
  129. package/dist-lib/schema/helpers.d.ts +4 -0
  130. package/dist-lib/schema/helpers.js +20 -0
  131. package/dist-lib/schema/local.d.ts +1 -1
  132. package/dist-lib/schema/local.js +70 -2
  133. package/dist-lib/schema/qvac.js +30 -0
  134. package/dist-lib/spec/bind.js +20 -3
  135. package/dist-lib/spec/calls.js +19 -15
  136. package/dist-lib/spec/capabilities.d.ts +42 -34
  137. package/dist-lib/spec/hrpc/hrpc.json +82 -30
  138. package/dist-lib/spec/hrpc/index.js +106 -57
  139. package/dist-lib/spec/hrpc/messages.js +5420 -5019
  140. package/dist-lib/spec/hyperschema/index.js +5424 -5023
  141. package/dist-lib/spec/hyperschema/schema.json +3202 -2666
  142. package/dist-lib/spec/hyperschema/types.d.ts +455 -319
  143. package/dist-lib/spec/local/hyperdb/db.json +119 -1
  144. package/dist-lib/spec/local/hyperdb/index.js +414 -2
  145. package/dist-lib/spec/local/hyperdb/messages.js +505 -124
  146. package/dist-lib/spec/local/hyperschema/index.js +203 -5
  147. package/dist-lib/spec/local/hyperschema/schema.json +136 -1
  148. package/dist-lib/spec/local/hyperschema/types.d.ts +32 -1
  149. package/dist-lib/spec/mesh/hyperdb/db.json +55 -3
  150. package/dist-lib/spec/mesh/hyperdb/index.js +119 -3
  151. package/dist-lib/spec/mesh/hyperdb/messages.js +244 -172
  152. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
  153. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  154. package/dist-lib/spec/mesh/hyperdispatch/messages.js +74 -2
  155. package/dist-lib/spec/mesh/hyperschema/index.js +74 -2
  156. package/dist-lib/spec/mesh/hyperschema/schema.json +27 -1
  157. package/dist-lib/spec/mesh/hyperschema/types.d.ts +9 -1
  158. package/package.json +6 -6
  159. package/tui/app.mjs +376 -151
  160. package/tui/boot.mjs +2 -1
  161. package/tui/lib/busy-words.mjs +2 -1
  162. package/tui/lib/knowledge-command.mjs +11 -10
  163. package/tui/lib/knowledge-import.mjs +7 -5
  164. package/tui/lib/render.mjs +4 -3
  165. package/tui/lib/usage.mjs +2 -1
  166. package/tui/main.mjs +2 -1
package/tui/boot.mjs CHANGED
@@ -39,7 +39,8 @@ async function startSidecar({ entry, config, logger }) {
39
39
  return {
40
40
  engine,
41
41
  close: () => engine.close(),
42
- skills: async (agentId, modelName) => (await engine.skills({ agentId, modelName })).skills ?? []
42
+ skills: async (agentId, modelName, meshId) =>
43
+ (await engine.skills({ agentId, modelName, meshId })).skills ?? []
43
44
  }
44
45
  }
45
46
 
@@ -1,3 +1,4 @@
1
+ import b4a from 'b4a'
1
2
  // What the busy line says while a run is in flight, in place of `thinking…`.
2
3
  // Every word has to read as a mind at work first and a duck second — so the
3
4
  // real words here already mean thinking or grinding (Pondering, Brooding,
@@ -75,7 +76,7 @@ export const SLIP_DELETE_MS = 45 // per character backspaced
75
76
  export const SLIP_TYPE_MS = 65 // per character of the correction typed
76
77
 
77
78
  function hashOf(runId) {
78
- const key = typeof runId === 'string' ? runId : runId.toString('hex')
79
+ const key = typeof runId === 'string' ? runId : b4a.toHex(runId)
79
80
  let hash = 0
80
81
  for (let i = 0; i < key.length; i++) hash = (hash * 31 + key.charCodeAt(i)) >>> 0
81
82
  return hash
@@ -5,48 +5,49 @@ import { saveUniqueStream } from './save-file.mjs'
5
5
  const USAGE =
6
6
  'usage: /knowledge [list] · /knowledge add <file> · /knowledge add-dir <directory> · /knowledge download <n|id> · /knowledge remove <n|id>'
7
7
 
8
- export async function knowledgeCommand(engine, { chatId, saveDir }, input) {
8
+ export async function knowledgeCommand(engine, { chatId, meshId, saveDir }, input) {
9
9
  try {
10
- return { type: 'notice', text: await execute(engine, chatId, saveDir, input) }
10
+ return { type: 'notice', text: await execute(engine, { chatId, meshId }, saveDir, input) }
11
11
  } catch (error) {
12
12
  return { type: 'run.error', error }
13
13
  }
14
14
  }
15
15
 
16
- async function execute(engine, chatId, saveDir, input) {
16
+ async function execute(engine, scope, saveDir, input) {
17
+ const { chatId, meshId } = scope
17
18
  const { action, argument } = parseInput(input)
18
19
  if ((!action || action === 'list') && !argument) {
19
20
  const [{ knowledge }, { statuses }] = await Promise.all([
20
- engine.listKnowledge({ chatId }),
21
- engine.listIndexing({ chatId })
21
+ engine.listKnowledge({ chatId, meshId }),
22
+ engine.listIndexing({ chatId, meshId })
22
23
  ])
23
24
  return formatKnowledge(sortKnowledge(knowledge ?? []), statuses ?? [])
24
25
  }
25
26
  if (action === 'add' || action === 'add-dir') {
26
27
  if (!argument) return USAGE
27
28
  if (action === 'add') {
28
- const added = await importKnowledgeFile(engine, chatId, argument)
29
+ const added = await importKnowledgeFile(engine, scope, argument)
29
30
  return `uploaded ${singleLine(added.fileName)} (${added.byteLength}B) · run /knowledge to track indexing`
30
31
  }
31
- return formatDirectoryImport(await importKnowledgeDirectory(engine, chatId, argument))
32
+ return formatDirectoryImport(await importKnowledgeDirectory(engine, scope, argument))
32
33
  }
33
34
 
34
35
  const [selector, ...extra] = argument.split(/\s+/)
35
36
  if ((action !== 'download' && action !== 'remove') || !selector || extra.length) return USAGE
36
37
 
37
- const { knowledge } = await engine.listKnowledge({ chatId })
38
+ const { knowledge } = await engine.listKnowledge({ chatId, meshId })
38
39
  const selected = resolveKnowledge(sortKnowledge(knowledge ?? []), selector)
39
40
  if (selected.error) return selected.error
40
41
  const row = selected.knowledge
41
42
  if (action === 'remove') {
42
- await engine.removeKnowledge({ knowledgeId: row.id, at: Date.now() })
43
+ await engine.removeKnowledge({ knowledgeId: row.id, at: Date.now(), meshId })
43
44
  return `removed ${singleLine(row.fileName)} (${row.id.slice(0, 8)})`
44
45
  }
45
46
 
46
47
  const saved = await saveUniqueStream(
47
48
  saveDir,
48
49
  row.fileName,
49
- frameData(engine.downloadKnowledge({ blobId: row.blobId }))
50
+ frameData(engine.downloadKnowledge({ blobId: row.blobId, meshId }))
50
51
  )
51
52
  if (saved) return `saved ${singleLine(row.fileName)} (${saved.bytesWritten}B) to ${saved.file}`
52
53
  return `not saved: 100 files named ${singleLine(row.fileName)} already exist in ${saveDir}`
@@ -28,15 +28,15 @@ const MIME_TYPES = new Map([
28
28
  ['.odt', 'application/vnd.oasis.opendocument.text']
29
29
  ])
30
30
 
31
- export async function importKnowledgeFile(engine, chatId, inputPath) {
31
+ export async function importKnowledgeFile(engine, scope, inputPath) {
32
32
  const file = resolvePath(inputPath)
33
33
  const stat = await fs.promises.stat(file)
34
34
  if (!stat.isFile()) throw new Error(`not a file: ${file}`)
35
35
  if (!supported(file)) throw new Error(`unsupported knowledge file: ${path.basename(file)}`)
36
- return upload(engine, chatId, file, stat.size)
36
+ return upload(engine, scope, file, stat.size)
37
37
  }
38
38
 
39
- export async function importKnowledgeDirectory(engine, chatId, inputPath) {
39
+ export async function importKnowledgeDirectory(engine, scope, inputPath) {
40
40
  const directory = resolvePath(inputPath)
41
41
  const stat = await fs.promises.stat(directory)
42
42
  if (!stat.isDirectory()) throw new Error(`not a directory: ${directory}`)
@@ -59,7 +59,7 @@ export async function importKnowledgeDirectory(engine, chatId, inputPath) {
59
59
  continue
60
60
  }
61
61
  try {
62
- added.push(await upload(engine, chatId, file, fileStat.size))
62
+ added.push(await upload(engine, scope, file, fileStat.size))
63
63
  } catch (error) {
64
64
  failed.push({ fileName: name, error: errorMessage(error) })
65
65
  }
@@ -79,7 +79,7 @@ function supported(file) {
79
79
  return ACCEPTED.has(path.extname(file).toLowerCase())
80
80
  }
81
81
 
82
- async function upload(engine, chatId, file, byteLength) {
82
+ async function upload(engine, { chatId, meshId }, file, byteLength) {
83
83
  const fileName = path.basename(file)
84
84
  const extension = path.extname(file).toLowerCase()
85
85
  const stream = engine.uploadKnowledge()
@@ -92,7 +92,9 @@ async function upload(engine, chatId, file, byteLength) {
92
92
  const source = fs.createReadStream(file, { highWaterMark: UPLOAD_FRAME_BYTES })
93
93
 
94
94
  try {
95
+ // the first frame names the mesh; the rest carry bytes
95
96
  const metadataWritten = await writeFrame(stream, {
97
+ meshId,
96
98
  chatId,
97
99
  fileName,
98
100
  mimeType: MIME_TYPES.get(extension) ?? 'application/octet-stream',
@@ -1,4 +1,5 @@
1
1
  import { busyWord } from './busy-words.mjs'
2
+ import b4a from 'b4a'
2
3
 
3
4
  const PAYLOAD_FIELDS = {
4
5
  content: 'content',
@@ -33,7 +34,7 @@ export function turnsFromChunks(chunks) {
33
34
  if (chunk.type === 'user-message') {
34
35
  turns.push({
35
36
  from: 'user',
36
- deviceId: chunk.originDeviceId?.toString('hex'),
37
+ deviceId: chunk.originDeviceId && b4a.toHex(chunk.originDeviceId),
37
38
  segments: [{ type: 'user-message', text: chunk.userMessage.text }]
38
39
  })
39
40
  continue
@@ -44,7 +45,7 @@ export function turnsFromChunks(chunks) {
44
45
  if (chunk.type === 'attachment' && !chunk.runId) {
45
46
  turns.push({
46
47
  from: 'user',
47
- deviceId: chunk.originDeviceId?.toString('hex'),
48
+ deviceId: chunk.originDeviceId && b4a.toHex(chunk.originDeviceId),
48
49
  segments: [{ type: 'attachment', detail: chunk.attachment }]
49
50
  })
50
51
  continue
@@ -71,7 +72,7 @@ export function turnsFromChunks(chunks) {
71
72
  turn.statusDetail = chunk.runStatus
72
73
  // Status chunks are stamped by the device doing the work (the
73
74
  // provider), so progress can be labelled with WHERE it's happening.
74
- turn.statusDeviceId = chunk.originDeviceId?.toString('hex')
75
+ turn.statusDeviceId = chunk.originDeviceId && b4a.toHex(chunk.originDeviceId)
75
76
  continue
76
77
  }
77
78
  // An approval-request chunk IS the approval state (see runAgent's
package/tui/lib/usage.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import b4a from 'b4a'
1
2
  // What the run itself reported, and nothing counted here: `ctxSize` is the window the device
2
3
  // that ran the turn had loaded, `cacheTokens` the SDK's occupancy reading, `usage` the
3
4
  // harness's attribution of the prompt it sent (docs/decisions in @qvac/harness).
@@ -29,7 +30,7 @@ export function usageReport(statuses, folds = []) {
29
30
  occupied: metrics.cacheTokens ?? null,
30
31
  rows: promptRows(metrics.usage, metrics.cacheTokens),
31
32
  last: {
32
- deviceId: last.originDeviceId?.toString('hex') ?? null,
33
+ deviceId: last.originDeviceId ? b4a.toHex(last.originDeviceId) : null,
33
34
  totalTokens: metrics.totalTokens ?? null,
34
35
  tokensPerSecond: metrics.tokensPerSecond ?? null,
35
36
  timeToFirstToken: metrics.timeToFirstToken ?? null,
package/tui/main.mjs CHANGED
@@ -9,6 +9,7 @@ import { spawn } from 'child_process'
9
9
  import path from 'path'
10
10
  import { readBootTiming } from './lib/boot-timing.mjs'
11
11
  import { ChatApp } from './app.mjs'
12
+ import b4a from 'b4a'
12
13
 
13
14
  const { Program } = tui
14
15
 
@@ -245,7 +246,7 @@ async function run(args) {
245
246
  const { deviceId, meshInvite } = await connect()
246
247
  console.log(`storage ${booted.storagePath}`)
247
248
  console.log(`log ${booted.logFile}`)
248
- console.log(`device ${booted.deviceName} ${deviceId.toString('hex')}`)
249
+ console.log(`device ${booted.deviceName} ${b4a.toHex(deviceId)}`)
249
250
  console.log(`invite ${meshInvite ?? '(none — mesh not writable)'}`)
250
251
  printBootTiming(booted)
251
252
  return