@qvac/core 0.10.1 → 0.10.3

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 (40) hide show
  1. package/CHANGELOG.md +63 -1
  2. package/dist-lib/lib/api/agent-folders.d.ts +22 -0
  3. package/dist-lib/lib/api/agent-folders.js +115 -0
  4. package/dist-lib/lib/api/agents.d.ts +3 -1
  5. package/dist-lib/lib/api/agents.js +5 -3
  6. package/dist-lib/lib/api/execution.js +2 -0
  7. package/dist-lib/lib/api/index.d.ts +1 -0
  8. package/dist-lib/lib/api/index.js +4 -0
  9. package/dist-lib/lib/assistant-tree.js +2 -1
  10. package/dist-lib/lib/assistant.js +7 -4
  11. package/dist-lib/lib/core/agent.d.ts +5 -1
  12. package/dist-lib/lib/core/agent.js +8 -3
  13. package/dist-lib/lib/core/chat.d.ts +4 -1
  14. package/dist-lib/lib/core/chat.js +12 -4
  15. package/dist-lib/lib/core/local/index.d.ts +2 -1
  16. package/dist-lib/lib/core/local/index.js +9 -1
  17. package/dist-lib/lib/core/send.js +2 -0
  18. package/dist-lib/lib/core.d.ts +1 -0
  19. package/dist-lib/lib/core.js +41 -13
  20. package/dist-lib/lib/errors.d.ts +20 -0
  21. package/dist-lib/lib/errors.js +20 -0
  22. package/dist-lib/lib/lent-harness.d.ts +2 -0
  23. package/dist-lib/lib/lent-harness.js +51 -0
  24. package/dist-lib/lib/mesh-scoped-engine.js +3 -0
  25. package/dist-lib/schema/engine.js +58 -1
  26. package/dist-lib/spec/bind.js +9 -0
  27. package/dist-lib/spec/calls.js +3 -0
  28. package/dist-lib/spec/capabilities.d.ts +8 -2
  29. package/dist-lib/spec/hrpc/hrpc.json +40 -1
  30. package/dist-lib/spec/hrpc/index.js +40 -4
  31. package/dist-lib/spec/hrpc/messages.js +190 -0
  32. package/dist-lib/spec/hyperschema/index.js +190 -0
  33. package/dist-lib/spec/hyperschema/schema.json +141 -0
  34. package/dist-lib/spec/hyperschema/types.d.ts +40 -0
  35. package/package.json +2 -1
  36. package/tui/README.md +16 -0
  37. package/tui/app.mjs +80 -13
  38. package/tui/lib/folders-command.mjs +92 -0
  39. package/tui/lib/knowledge-import.mjs +3 -21
  40. package/tui/lib/local-path.mjs +21 -0
@@ -0,0 +1,92 @@
1
+ import { resolveLocalPath } from './local-path.mjs'
2
+
3
+ const USAGE = 'usage: /folders [list] · /folders add <path> [ro|rw] · /folders remove <path>'
4
+ const ACCESS = new Map([
5
+ ['ro', 'read'],
6
+ ['rw', 'write']
7
+ ])
8
+ const LABEL = { read: 'ro', write: 'rw' }
9
+
10
+ // host: the agent runs elsewhere; lender: it borrows a model, and a lent run gets no folder
11
+ export async function foldersCommand(engine, { agent, host = null, lender = null }, input) {
12
+ if (host) {
13
+ return {
14
+ type: 'notice',
15
+ text: `${agent.name} runs on ${host}, so its folders are shared there · run /folders on that device`
16
+ }
17
+ }
18
+
19
+ try {
20
+ return { type: 'notice', text: await execute(engine, { agent, lender }, input) }
21
+ } catch (error) {
22
+ return { type: 'run.error', error }
23
+ }
24
+ }
25
+
26
+ async function execute(engine, { agent, lender }, input) {
27
+ const agentId = agent.id
28
+ const { action, argument } = parseInput(input)
29
+ const borrowed = lender ? [borrowedNote(agent, lender)] : []
30
+ if (!action || action === 'list') {
31
+ const { folders } = await engine.listAgentFolders({ agentId })
32
+
33
+ return folders?.length ? [formatFolders(agent, folders), ...borrowed].join('\n') : empty(agent)
34
+ }
35
+
36
+ if (action === 'add' && argument) {
37
+ // the access is the last word, so a path with spaces needs no quotes
38
+ const [, given, flag = 'ro'] = argument.match(/^(.*?)(?:\s+(ro|rw))?$/)
39
+ const access = ACCESS.get(flag)
40
+ const path = resolveLocalPath(unquote(given))
41
+ const { folders } = await engine.addAgentFolder({ agentId, path, access })
42
+ const can = access === 'write' ? 'read and edit' : 'read'
43
+ const shared = lender
44
+ ? `shared ${path} with ${agent.name}`
45
+ : `${agent.name} can ${can} ${path} from its next message`
46
+
47
+ return [shared, ...borrowed, ...rows(folders)].join('\n')
48
+ }
49
+
50
+ if (action === 'remove' && argument) {
51
+ const path = resolveLocalPath(unquote(argument))
52
+ await engine.removeAgentFolder({ agentId, path })
53
+
54
+ return `stopped sharing ${path} with ${agent.name}`
55
+ }
56
+
57
+ return USAGE
58
+ }
59
+
60
+ function empty(agent) {
61
+ return `no folders shared with ${agent.name} on this device · /folders add <path> [ro|rw]`
62
+ }
63
+
64
+ function borrowedNote(agent, lender) {
65
+ return `${agent.name} borrows its model from ${lender}, and a borrowed run gets no folders · /agent borrow none to run it here`
66
+ }
67
+
68
+ function formatFolders(agent, folders) {
69
+ return [
70
+ `folders ${agent.name} can use on this device (relative paths start in the first):`,
71
+ ...rows(folders)
72
+ ].join('\n')
73
+ }
74
+
75
+ function rows(folders) {
76
+ return folders.map((folder) => ` ${LABEL[folder.access]} ${folder.path}`)
77
+ }
78
+
79
+ function parseInput(input) {
80
+ const value = input.trim()
81
+ const separator = value.search(/\s/)
82
+ if (separator === -1) {
83
+ return { action: value, argument: '' }
84
+ }
85
+
86
+ return { action: value.slice(0, separator), argument: value.slice(separator).trim() }
87
+ }
88
+
89
+ function unquote(value) {
90
+ const match = value.match(/^(["'])(.*)\1$/)
91
+ return match ? match[2] : value
92
+ }
@@ -1,8 +1,7 @@
1
1
  import fs from 'fs'
2
- import os from 'os'
3
2
  import path from 'path'
4
- import { fileURLToPath } from 'url'
5
3
  import { RAG_ACCEPT_EXTENSIONS } from 'rag-extract'
4
+ import { resolveLocalPath } from './local-path.mjs'
6
5
  import { UPLOAD_FRAME_BYTES, writeFrame } from './upload-frames.mjs'
7
6
  import { errorMessage } from '../../dist-lib/lib/guards.js'
8
7
  const ACCEPTED = new Set(RAG_ACCEPT_EXTENSIONS)
@@ -30,7 +29,7 @@ const MIME_TYPES = new Map([
30
29
  ])
31
30
 
32
31
  export async function importKnowledgeFile(engine, scope, inputPath) {
33
- const file = resolvePath(inputPath)
32
+ const file = resolveLocalPath(inputPath)
34
33
  const stat = await fs.promises.stat(file)
35
34
  if (!stat.isFile()) {
36
35
  throw new Error(`not a file: ${file}`)
@@ -44,7 +43,7 @@ export async function importKnowledgeFile(engine, scope, inputPath) {
44
43
  }
45
44
 
46
45
  export async function importKnowledgeDirectory(engine, scope, inputPath) {
47
- const directory = resolvePath(inputPath)
46
+ const directory = resolveLocalPath(inputPath)
48
47
  const stat = await fs.promises.stat(directory)
49
48
  if (!stat.isDirectory()) {
50
49
  throw new Error(`not a directory: ${directory}`)
@@ -79,23 +78,6 @@ export async function importKnowledgeDirectory(engine, scope, inputPath) {
79
78
  return { directory, added, failed, skipped }
80
79
  }
81
80
 
82
- function resolvePath(input) {
83
- const value = input.trim()
84
- if (value.startsWith('file://')) {
85
- return fileURLToPath(value)
86
- }
87
-
88
- if (value === '~') {
89
- return os.homedir()
90
- }
91
-
92
- if (value.startsWith('~/')) {
93
- return path.join(os.homedir(), value.slice(2))
94
- }
95
-
96
- return path.resolve(value)
97
- }
98
-
99
81
  function supported(file) {
100
82
  return ACCEPTED.has(path.extname(file).toLowerCase())
101
83
  }
@@ -0,0 +1,21 @@
1
+ import os from 'os'
2
+ import path from 'path'
3
+ import { fileURLToPath } from 'url'
4
+
5
+ // a path as a person types it: a file:// url, ~ for home, or relative to where duck started
6
+ export function resolveLocalPath(input) {
7
+ const value = input.trim()
8
+ if (value.startsWith('file://')) {
9
+ return fileURLToPath(value)
10
+ }
11
+
12
+ if (value === '~') {
13
+ return os.homedir()
14
+ }
15
+
16
+ if (value.startsWith('~/')) {
17
+ return path.join(os.homedir(), value.slice(2))
18
+ }
19
+
20
+ return path.resolve(value)
21
+ }