@qvac/core 0.7.3 → 0.7.4
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 +83 -1
- package/README.md +4 -3
- package/dist-lib/lib/api/device-routes.d.ts +11 -0
- package/dist-lib/lib/api/device-routes.js +124 -0
- package/dist-lib/lib/assistant.js +8 -2
- package/dist-lib/lib/core/agent.js +6 -2
- package/dist-lib/lib/core/device-control.d.ts +23 -0
- package/dist-lib/lib/core/device-control.js +92 -0
- package/dist-lib/lib/core/mesh.d.ts +14 -0
- package/dist-lib/lib/core/mesh.js +100 -4
- package/dist-lib/lib/core/peer-duplex.d.ts +2 -0
- package/dist-lib/lib/core/peer-duplex.js +11 -2
- package/dist-lib/lib/core/tool-configs.js +1 -1
- package/dist-lib/lib/core.d.ts +3 -0
- package/dist-lib/lib/core.js +41 -1
- package/dist-lib/lib/log.js +4 -1
- package/dist-lib/schema/build.js +1 -0
- package/dist-lib/schema/engine.js +45 -15
- package/dist-lib/spec/capabilities.d.ts +6 -6
- package/dist-lib/spec/hrpc/hrpc.json +3 -3
- package/dist-lib/spec/hrpc/index.js +3 -3
- package/dist-lib/spec/hrpc/messages.js +105 -20
- package/dist-lib/spec/hyperschema/index.js +105 -20
- package/dist-lib/spec/hyperschema/schema.json +81 -8
- package/dist-lib/spec/hyperschema/types.d.ts +17 -0
- package/package.json +2 -1
- package/tui/README.md +8 -4
- package/tui/app.mjs +273 -66
- package/tui/boot.mjs +46 -3
- package/tui/index.mjs +5 -1
- package/tui/lib/device-target.mjs +64 -0
package/tui/boot.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import process from 'bare-process'
|
|
|
5
5
|
import { fileURLToPath } from 'bare-url'
|
|
6
6
|
import path from 'path'
|
|
7
7
|
import { Client } from '../dist-lib/lib/client.js'
|
|
8
|
+
import { decodeMeshInvite } from '../dist-lib/lib/core/invite.js'
|
|
8
9
|
import { Logger, toLoggerOptions } from '../dist-lib/lib/log.js'
|
|
9
10
|
import { configureSdkStorage } from '@qvac/harness/sdk-storage'
|
|
10
11
|
import { MODEL_CACHE_PATH_ENV, releaseChannel, resolveStorage } from '@qvac/harness/storage'
|
|
@@ -40,8 +41,49 @@ async function startSidecar({ entry, config, logger }) {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
// --join
|
|
44
|
+
// --join adds a mesh as a new member, --device-join pairs this device into the inviter's account
|
|
45
|
+
function bootInvite({ join, deviceJoin }) {
|
|
46
|
+
if (join && deviceJoin) {
|
|
47
|
+
throw new Error('pass --join or --device-join, not both')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const raw = join || deviceJoin
|
|
51
|
+
if (!raw) {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const invite = decodeMeshInvite(raw)
|
|
56
|
+
if (!invite) {
|
|
57
|
+
throw new Error('not a mesh invite: expected qvac://mesh/…')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (join && !invite.memberInvite) {
|
|
61
|
+
throw new Error('that is a device invite: use --device-join, or ask for /invite member')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (deviceJoin && invite.memberInvite) {
|
|
65
|
+
throw new Error('that is a member invite: use --join')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return raw
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// joinMesh returns with the handshake under way, and the invite asked for next needs it done
|
|
72
|
+
async function joined(engine) {
|
|
73
|
+
for await (const { state, error } of engine.meshStatusWatch({})) {
|
|
74
|
+
if (state === 'joined') {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (state === 'error' || state === 'kicked') {
|
|
79
|
+
throw new Error(error || `the join ended ${state}`)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// --join and --device-join are the headless way in, /join the interactive one
|
|
44
85
|
export async function boot(args) {
|
|
86
|
+
const joining = bootInvite(args)
|
|
45
87
|
const connectStart = Date.now()
|
|
46
88
|
// only an explicit QVAC_MODEL overrides, or resuming a shared mesh rewrites the desktop's agent
|
|
47
89
|
const modelOverride = process.env.QVAC_MODEL || null
|
|
@@ -95,8 +137,9 @@ export async function boot(args) {
|
|
|
95
137
|
})
|
|
96
138
|
// the device id is its public key: the raw 32-byte buffer end to end, never a hex string
|
|
97
139
|
const deviceId = (await engine.deviceInfo({})).id
|
|
98
|
-
if (
|
|
99
|
-
await engine.joinMesh({ invite:
|
|
140
|
+
if (joining) {
|
|
141
|
+
await engine.joinMesh({ invite: joining })
|
|
142
|
+
await joined(engine)
|
|
100
143
|
}
|
|
101
144
|
|
|
102
145
|
const meshInvite = (await engine.meshInvite({})).invite ?? null
|
package/tui/index.mjs
CHANGED
|
@@ -13,7 +13,11 @@ const cmd = command(
|
|
|
13
13
|
flag('--storage|-s [dir]', 'a self-contained root, its own corestore and SDK home'),
|
|
14
14
|
flag('--temp', 'the same, in a throwaway dir'),
|
|
15
15
|
flag('--headless', 'no TUI: print the device invite and stream logs until ctrl+C'),
|
|
16
|
-
flag('--join|-j <invite>', 'join
|
|
16
|
+
flag('--join|-j <invite>', 'join a mesh as a new member at boot (a member invite)'),
|
|
17
|
+
flag(
|
|
18
|
+
'--device-join <invite>',
|
|
19
|
+
'pair this device into the inviter’s account at boot (a device invite)'
|
|
20
|
+
),
|
|
17
21
|
flag('--fake-models', 'adds the quack model: a deterministic fake LLM for testing without AI'),
|
|
18
22
|
flag('--version|-v', 'versions of core, harness and the SDK')
|
|
19
23
|
)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import b4a from 'b4a'
|
|
2
|
+
import { DEVICE_ROUTES } from '../../dist-lib/lib/api/device-routes.js'
|
|
3
|
+
|
|
4
|
+
// the routes /device points at another device of this account; every other route stays here
|
|
5
|
+
const ON_DEVICE = new Set(DEVICE_ROUTES)
|
|
6
|
+
|
|
7
|
+
export function onDevice(engine, deviceId) {
|
|
8
|
+
if (!deviceId) {
|
|
9
|
+
return engine
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return new Proxy(engine, {
|
|
13
|
+
get(target, prop) {
|
|
14
|
+
const value = Reflect.get(target, prop)
|
|
15
|
+
if (typeof value !== 'function') {
|
|
16
|
+
return value
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!ON_DEVICE.has(prop)) {
|
|
20
|
+
return value.bind(target)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (input = {}) => value.call(target, { ...input, deviceId })
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// by its number in /device list, its name, or a prefix of its id
|
|
29
|
+
export function pickDevice(devices, asked) {
|
|
30
|
+
const wanted = asked.trim().toLowerCase()
|
|
31
|
+
if (!wanted) {
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const index = Number(wanted)
|
|
36
|
+
if (Number.isInteger(index) && index >= 1 && index <= devices.length) {
|
|
37
|
+
return devices[index - 1]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const named = devices.filter((device) => device.name?.toLowerCase() === wanted)
|
|
41
|
+
if (named.length === 1) {
|
|
42
|
+
return named[0]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const prefixed = devices.filter((device) => b4a.toHex(device.id).startsWith(wanted))
|
|
46
|
+
|
|
47
|
+
return prefixed.length === 1 ? prefixed[0] : null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function deviceLines(devices, { own, target, connected }) {
|
|
51
|
+
return devices.map((device, i) => {
|
|
52
|
+
const mark = target && b4a.equals(device.id, target) ? '*' : ' '
|
|
53
|
+
const facts = []
|
|
54
|
+
if (own && b4a.equals(device.id, own)) {
|
|
55
|
+
facts.push('this device')
|
|
56
|
+
} else {
|
|
57
|
+
facts.push(connected.has(b4a.toHex(device.id)) ? 'connected' : 'not connected')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
facts.push(`${device.cachedModelNames?.length ?? 0} models downloaded`)
|
|
61
|
+
|
|
62
|
+
return `${mark}${i + 1}. ${device.name} (${b4a.toHex(device.id).slice(0, 8)}) — ${facts.join(' · ')}`
|
|
63
|
+
})
|
|
64
|
+
}
|