@qvac/core 0.8.0 → 0.10.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 +114 -1
- package/README.md +5 -5
- package/dist-lib/index.d.ts +0 -1
- package/dist-lib/index.js +0 -1
- package/dist-lib/lib/api/agents.d.ts +7 -1
- package/dist-lib/lib/api/agents.js +2 -2
- package/dist-lib/lib/api/app-config.d.ts +2 -1
- package/dist-lib/lib/api/app-config.js +2 -2
- package/dist-lib/lib/api/attachments.js +3 -2
- package/dist-lib/lib/api/chat-move.d.ts +2 -1
- package/dist-lib/lib/api/chat-move.js +2 -2
- package/dist-lib/lib/api/chat.d.ts +3 -1
- package/dist-lib/lib/api/chat.js +5 -5
- package/dist-lib/lib/api/chunks.d.ts +2 -1
- package/dist-lib/lib/api/chunks.js +3 -3
- package/dist-lib/lib/api/config.d.ts +2 -1
- package/dist-lib/lib/api/config.js +2 -2
- package/dist-lib/lib/api/current-mesh.d.ts +1 -3
- package/dist-lib/lib/api/current-mesh.js +4 -10
- package/dist-lib/lib/api/custom-models.d.ts +7 -1
- package/dist-lib/lib/api/custom-models.js +10 -8
- package/dist-lib/lib/api/device-routes.d.ts +0 -2
- package/dist-lib/lib/api/device-routes.js +4 -5
- package/dist-lib/lib/api/devices.d.ts +3 -1
- package/dist-lib/lib/api/devices.js +9 -8
- package/dist-lib/lib/api/diagnostics.d.ts +2 -1
- package/dist-lib/lib/api/diagnostics.js +2 -2
- package/dist-lib/lib/api/index.d.ts +2 -0
- package/dist-lib/lib/api/index.js +39 -21
- package/dist-lib/lib/api/instrument.d.ts +2 -2
- package/dist-lib/lib/api/instrument.js +10 -11
- package/dist-lib/lib/api/knowledge.d.ts +3 -1
- package/dist-lib/lib/api/knowledge.js +9 -7
- package/dist-lib/lib/api/logs.js +3 -3
- package/dist-lib/lib/api/members.d.ts +6 -1
- package/dist-lib/lib/api/members.js +11 -10
- package/dist-lib/lib/api/mesh.d.ts +2 -2
- package/dist-lib/lib/api/mesh.js +6 -6
- package/dist-lib/lib/api/model-download.d.ts +2 -1
- package/dist-lib/lib/api/model-download.js +2 -2
- package/dist-lib/lib/api/network.d.ts +3 -2
- package/dist-lib/lib/api/network.js +4 -4
- package/dist-lib/lib/api/notifications.d.ts +3 -1
- package/dist-lib/lib/api/notifications.js +5 -4
- package/dist-lib/lib/api/rag.d.ts +0 -1
- package/dist-lib/lib/api/rag.js +3 -4
- package/dist-lib/lib/api/sync.d.ts +2 -1
- package/dist-lib/lib/api/sync.js +2 -2
- package/dist-lib/lib/api/tool-activity.d.ts +2 -1
- package/dist-lib/lib/api/tool-activity.js +4 -3
- package/dist-lib/lib/api/tool-configs.d.ts +2 -1
- package/dist-lib/lib/api/tool-configs.js +4 -3
- package/dist-lib/lib/api/upload-frames.d.ts +0 -1
- package/dist-lib/lib/api/upload-frames.js +0 -1
- package/dist-lib/lib/api/watchable.d.ts +3 -2
- package/dist-lib/lib/api/watchable.js +2 -3
- package/dist-lib/lib/assistant/fake-models.d.ts +2 -4
- package/dist-lib/lib/assistant/harness.js +8 -6
- package/dist-lib/lib/assistant-client.d.ts +2 -0
- package/dist-lib/lib/assistant-client.js +4 -3
- package/dist-lib/lib/assistant-tree.d.ts +3 -3
- package/dist-lib/lib/assistant.d.ts +2 -2
- package/dist-lib/lib/assistant.js +11 -11
- package/dist-lib/lib/client.d.ts +2 -2
- package/dist-lib/lib/core/agent.js +5 -4
- package/dist-lib/lib/core/archived-mesh.d.ts +2 -3
- package/dist-lib/lib/core/archived-mesh.js +3 -3
- package/dist-lib/lib/core/chat-activity.js +5 -3
- package/dist-lib/lib/core/chat-copy.d.ts +0 -1
- package/dist-lib/lib/core/chat-copy.js +2 -2
- package/dist-lib/lib/core/chat-fork.d.ts +0 -6
- package/dist-lib/lib/core/chat-fork.js +11 -17
- package/dist-lib/lib/core/chat-group.js +8 -7
- package/dist-lib/lib/core/chat-move.d.ts +4 -6
- package/dist-lib/lib/core/chat-move.js +14 -15
- package/dist-lib/lib/core/chat-order.d.ts +2 -1
- package/dist-lib/lib/core/chat-order.js +15 -2
- package/dist-lib/lib/core/chat.js +8 -7
- package/dist-lib/lib/core/chunk.js +13 -8
- package/dist-lib/lib/core/collections.d.ts +1 -0
- package/dist-lib/lib/core/collections.js +1 -0
- package/dist-lib/lib/core/contract/compute.d.ts +0 -4
- package/dist-lib/lib/core/contract/compute.js +2 -9
- package/dist-lib/lib/core/contract/types.d.ts +2 -2
- package/dist-lib/lib/core/departures.d.ts +2 -2
- package/dist-lib/lib/core/device-control.d.ts +0 -2
- package/dist-lib/lib/core/device-control.js +5 -6
- package/dist-lib/lib/core/files/attachments.js +5 -4
- package/dist-lib/lib/core/files/index.d.ts +2 -1
- package/dist-lib/lib/core/files/index.js +20 -8
- package/dist-lib/lib/core/files/processing/claims.js +3 -3
- package/dist-lib/lib/core/files/processing/document.d.ts +2 -0
- package/dist-lib/lib/core/files/processing/document.js +3 -0
- package/dist-lib/lib/core/files/processing/index.js +4 -2
- package/dist-lib/lib/core/files/processing/source.d.ts +3 -0
- package/dist-lib/lib/core/files/processing/source.js +5 -3
- package/dist-lib/lib/core/files/processing/state.js +1 -0
- package/dist-lib/lib/core/files/rag/index.d.ts +3 -0
- package/dist-lib/lib/core/files/rag/index.js +3 -1
- package/dist-lib/lib/core/files/rag/load.js +6 -3
- package/dist-lib/lib/core/files/rag/produce.js +3 -3
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +1 -1
- package/dist-lib/lib/core/files/rag/similarity.d.ts +2 -2
- package/dist-lib/lib/core/files/rag/similarity.js +2 -3
- package/dist-lib/lib/core/files/records/chunks.js +1 -1
- package/dist-lib/lib/core/files/records/knowledge.js +2 -1
- package/dist-lib/lib/core/files/records/purge.js +9 -5
- package/dist-lib/lib/core/files/records/reclaim.js +20 -48
- package/dist-lib/lib/core/files/records/sweep.d.ts +3 -0
- package/dist-lib/lib/core/files/records/sweep.js +9 -3
- package/dist-lib/lib/core/files/store/blob.d.ts +2 -0
- package/dist-lib/lib/core/files/store/blob.js +2 -2
- package/dist-lib/lib/core/files/store/index.d.ts +1 -0
- package/dist-lib/lib/core/files/store/index.js +2 -0
- package/dist-lib/lib/core/files/store/reference.js +4 -2
- package/dist-lib/lib/core/files/upload.d.ts +1 -1
- package/dist-lib/lib/core/files/upload.js +10 -9
- package/dist-lib/lib/core/handoff-channel.d.ts +6 -4
- package/dist-lib/lib/core/handoff-channel.js +8 -9
- package/dist-lib/lib/core/harness-loan.d.ts +0 -2
- package/dist-lib/lib/core/harness-loan.js +3 -4
- package/dist-lib/lib/core/hosted-agents.d.ts +2 -2
- package/dist-lib/lib/core/inference-calls-handoff.d.ts +2 -2
- package/dist-lib/lib/core/inference-calls-handoff.js +6 -5
- package/dist-lib/lib/core/inference-calls-receiver.d.ts +0 -2
- package/dist-lib/lib/core/inference-calls-receiver.js +5 -7
- package/dist-lib/lib/core/invite.js +9 -4
- package/dist-lib/lib/core/local/index.d.ts +4 -1
- package/dist-lib/lib/core/local/index.js +23 -2
- package/dist-lib/lib/core/membership.d.ts +2 -2
- package/dist-lib/lib/core/mesh.d.ts +13 -7
- package/dist-lib/lib/core/mesh.js +55 -47
- package/dist-lib/lib/core/migrations/file-index.js +2 -4
- package/dist-lib/lib/core/next-frame.js +2 -1
- package/dist-lib/lib/core/pdf/rasterize.d.ts +2 -1
- package/dist-lib/lib/core/pdf/rasterize.js +5 -5
- package/dist-lib/lib/core/peer-duplex.d.ts +3 -3
- package/dist-lib/lib/core/peer-duplex.js +4 -4
- package/dist-lib/lib/core/secret-handoff.d.ts +2 -2
- package/dist-lib/lib/core/secret-handoff.js +7 -4
- package/dist-lib/lib/core/send.js +3 -2
- package/dist-lib/lib/core/skill-overlay-handoff.d.ts +2 -2
- package/dist-lib/lib/core/skill-overlay-handoff.js +6 -5
- package/dist-lib/lib/core/skill-overlay-receiver.js +5 -5
- package/dist-lib/lib/core/skill-secrets.d.ts +0 -5
- package/dist-lib/lib/core/skill-secrets.js +5 -9
- package/dist-lib/lib/core/sync/changed.d.ts +20 -0
- package/dist-lib/lib/core/sync/changed.js +7 -0
- package/dist-lib/lib/core/sync/devices.js +1 -1
- package/dist-lib/lib/core/sync/files.d.ts +1 -0
- package/dist-lib/lib/core/sync/files.js +50 -72
- package/dist-lib/lib/core/sync/index.d.ts +1 -2
- package/dist-lib/lib/core/sync/index.js +40 -62
- package/dist-lib/lib/core/sync/view-updates.d.ts +33 -0
- package/dist-lib/lib/core/sync/view-updates.js +133 -0
- package/dist-lib/lib/core/system-info.d.ts +2 -2
- package/dist-lib/lib/core/system-info.js +10 -11
- package/dist-lib/lib/core/tool-configs.js +6 -6
- package/dist-lib/lib/core.d.ts +1 -7
- package/dist-lib/lib/core.js +147 -131
- package/dist-lib/lib/custom-model-pusher.d.ts +2 -4
- package/dist-lib/lib/custom-model-task.d.ts +2 -1
- package/dist-lib/lib/custom-model-task.js +2 -2
- package/dist-lib/lib/downloads-allowed-pusher.d.ts +2 -4
- package/dist-lib/lib/errors.d.ts +603 -0
- package/dist-lib/lib/errors.js +552 -0
- package/dist-lib/lib/log.d.ts +7 -6
- package/dist-lib/lib/log.js +10 -6
- package/dist-lib/lib/logger-type.d.ts +2 -5
- package/dist-lib/lib/model-download-status.d.ts +2 -2
- package/dist-lib/lib/model-download.d.ts +2 -2
- package/dist-lib/lib/model-download.js +3 -2
- package/dist-lib/lib/model-idle-pusher.d.ts +2 -4
- package/dist-lib/lib/model-memory-cap.d.ts +2 -4
- package/dist-lib/lib/oauth/browser-connect.js +3 -2
- package/dist-lib/lib/oauth/flow-core.js +3 -3
- package/dist-lib/lib/oauth/loopback.js +10 -9
- package/dist-lib/lib/oauth/providers.js +4 -2
- package/dist-lib/lib/oauth/register.js +3 -2
- package/dist-lib/lib/oauth/token-exchange-core.js +5 -4
- package/dist-lib/lib/run-transcript.d.ts +2 -2
- package/dist-lib/lib/task.js +2 -1
- package/dist-lib/schema/engine.js +6 -3
- package/dist-lib/schema/field-order.js +1 -3
- package/dist-lib/schema/local.js +11 -0
- package/dist-lib/spec/hrpc/messages.js +20 -9
- package/dist-lib/spec/hyperschema/index.js +20 -9
- package/dist-lib/spec/hyperschema/schema.json +15 -0
- package/dist-lib/spec/hyperschema/types.d.ts +3 -0
- package/dist-lib/spec/local/hyperdb/db.json +16 -1
- package/dist-lib/spec/local/hyperdb/index.js +71 -2
- package/dist-lib/spec/local/hyperdb/messages.js +300 -143
- package/dist-lib/spec/local/hyperschema/index.js +82 -2
- package/dist-lib/spec/local/hyperschema/schema.json +43 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +12 -1
- package/package.json +9 -2
- package/tui/README.md +2 -2
- package/tui/app.mjs +11 -5
- package/tui/boot.mjs +1 -1
- package/worker/assistant-sidecar.mjs +7 -0
- package/dist-lib/lib/log-levels.d.ts +0 -7
- package/dist-lib/lib/log-levels.js +0 -1
- package/dist-lib/lib/logger.d.ts +0 -5
- package/dist-lib/lib/logger.js +0 -18
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Codec } from 'compact-encoding';
|
|
2
|
-
export declare const HOST_UNREACHABLE = "the device hosting this agent is not connected";
|
|
3
|
-
export declare const HOST_SILENT = "the device hosting this agent did not answer";
|
|
4
2
|
export declare const ACK_TIMEOUT_MS = 60000;
|
|
3
|
+
export interface HandoffError {
|
|
4
|
+
readonly message: string;
|
|
5
|
+
readonly code: number;
|
|
6
|
+
}
|
|
5
7
|
export interface HandoffStream {
|
|
6
8
|
readonly remotePublicKey: Uint8Array;
|
|
7
9
|
readonly noiseStream: {
|
|
@@ -16,9 +18,9 @@ export interface HandoffChannelOptions<Req, Res, Ack extends {
|
|
|
16
18
|
readonly extraRequestEncodings?: ReadonlyArray<Codec<RequestMessage<Req>>>;
|
|
17
19
|
readonly ackEncoding: Codec<Ack>;
|
|
18
20
|
readonly onrequest: (request: Req, from: Uint8Array) => Promise<Res>;
|
|
19
|
-
readonly buildAck: (id: number, error:
|
|
21
|
+
readonly buildAck: (id: number, error: HandoffError, result: Res | null) => Ack;
|
|
20
22
|
readonly readAck: (ack: Ack) => {
|
|
21
|
-
readonly error:
|
|
23
|
+
readonly error: HandoffError;
|
|
22
24
|
readonly result: Res;
|
|
23
25
|
};
|
|
24
26
|
readonly ackTimeoutMs?: number;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { errorMessage } from '../guards.js';
|
|
3
3
|
import { createProtocolPairing } from './protocol-pairing.js';
|
|
4
|
-
|
|
5
|
-
export const HOST_SILENT = 'the device hosting this agent did not answer';
|
|
4
|
+
import { CoreError, coreErrorCodeOf, coreErrorFrom } from '../errors.js';
|
|
6
5
|
export const ACK_TIMEOUT_MS = 60_000;
|
|
7
6
|
export class HandoffChannel {
|
|
8
7
|
_opts;
|
|
@@ -59,11 +58,11 @@ export class HandoffChannel {
|
|
|
59
58
|
const deviceId = b4a.toHex(hostDeviceId);
|
|
60
59
|
const peer = this._peers.get(deviceId);
|
|
61
60
|
if (!peer) {
|
|
62
|
-
return Promise.reject(new
|
|
61
|
+
return Promise.reject(new CoreError('AGENT_HOST_UNREACHABLE'));
|
|
63
62
|
}
|
|
64
63
|
const id = this._nextId++;
|
|
65
64
|
const { promise, resolve, reject } = Promise.withResolvers();
|
|
66
|
-
const timer = setTimeout(() => this._fail((w) => w === this._waiters.get(id), new
|
|
65
|
+
const timer = setTimeout(() => this._fail((w) => w === this._waiters.get(id), new CoreError('AGENT_HOST_SILENT')), this._ackTimeoutMs);
|
|
67
66
|
this._waiters.set(id, { deviceId, timer, resolve, reject });
|
|
68
67
|
const target = kind === 0 ? peer.requests : peer.extraRequests[kind - 1];
|
|
69
68
|
if (!target) {
|
|
@@ -85,13 +84,13 @@ export class HandoffChannel {
|
|
|
85
84
|
if (!peer) {
|
|
86
85
|
return;
|
|
87
86
|
}
|
|
88
|
-
let error = '';
|
|
87
|
+
let error = { message: '', code: 0 };
|
|
89
88
|
let result = null;
|
|
90
89
|
try {
|
|
91
90
|
result = await this._opts.onrequest(m.request, peer.remoteKey);
|
|
92
91
|
}
|
|
93
92
|
catch (err) {
|
|
94
|
-
error = errorMessage(err);
|
|
93
|
+
error = { message: errorMessage(err), code: coreErrorCodeOf(err) };
|
|
95
94
|
}
|
|
96
95
|
peer.responses.send(this._opts.buildAck(m.id, error, result));
|
|
97
96
|
}
|
|
@@ -103,8 +102,8 @@ export class HandoffChannel {
|
|
|
103
102
|
this._waiters.delete(ack.id);
|
|
104
103
|
clearTimeout(waiter.timer);
|
|
105
104
|
const { error, result } = this._opts.readAck(ack);
|
|
106
|
-
if (error) {
|
|
107
|
-
waiter.reject(
|
|
105
|
+
if (error.message) {
|
|
106
|
+
waiter.reject(coreErrorFrom(error.code, error.message));
|
|
108
107
|
}
|
|
109
108
|
else {
|
|
110
109
|
waiter.resolve(result);
|
|
@@ -114,7 +113,7 @@ export class HandoffChannel {
|
|
|
114
113
|
if (this._peers.get(deviceId)?.channel !== channel)
|
|
115
114
|
return;
|
|
116
115
|
this._peers.delete(deviceId);
|
|
117
|
-
this._fail((waiter) => waiter.deviceId === deviceId, new
|
|
116
|
+
this._fail((waiter) => waiter.deviceId === deviceId, new CoreError('AGENT_HOST_UNREACHABLE'));
|
|
118
117
|
}
|
|
119
118
|
_fail(match, err) {
|
|
120
119
|
for (const [id, waiter] of this._waiters) {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Duplex } from 'streamx';
|
|
2
2
|
import { PeerDuplexChannel, type PeerStream } from './peer-duplex.ts';
|
|
3
|
-
export declare const LOAN_UNREACHABLE = "the device lending its model is not connected";
|
|
4
3
|
export declare const LOAN_REFUSED = "the device would not lend its model";
|
|
5
|
-
export declare const LOAN_REVOKED = "the device stopped lending its model";
|
|
6
4
|
export declare function loanFailureNotice(error: unknown): string | null;
|
|
7
5
|
export type LoanStream = PeerStream;
|
|
8
6
|
export interface HarnessLoanOptions {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { PeerDuplexChannel } from './peer-duplex.js';
|
|
2
|
+
import { CoreError, LOAN_UNREACHABLE } from '../errors.js';
|
|
2
3
|
const PROTOCOL = 'qvac/harness-loan';
|
|
3
|
-
export const LOAN_UNREACHABLE = 'the device lending its model is not connected';
|
|
4
4
|
export const LOAN_REFUSED = 'the device would not lend its model';
|
|
5
|
-
export const LOAN_REVOKED = 'the device stopped lending its model';
|
|
6
5
|
export function loanFailureNotice(error) {
|
|
7
6
|
const message = messageOf(error);
|
|
8
7
|
if (message.includes(LOAN_UNREACHABLE)) {
|
|
@@ -23,8 +22,8 @@ export class HarnessLoan extends PeerDuplexChannel {
|
|
|
23
22
|
super({
|
|
24
23
|
protocol: PROTOCOL,
|
|
25
24
|
onaccept: opts.onborrow,
|
|
26
|
-
unreachable: LOAN_UNREACHABLE,
|
|
27
|
-
revoked: LOAN_REVOKED
|
|
25
|
+
unreachable: () => new CoreError('LOAN_UNREACHABLE'),
|
|
26
|
+
revoked: () => new CoreError('LOAN_REVOKED')
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
29
|
borrow(deviceId) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
2
2
|
import type { AssistantSkill } from '../../spec/hyperschema/types.d.ts';
|
|
3
3
|
import type { openLocalStore } from './local/index.ts';
|
|
4
4
|
import type { Mesh } from './mesh.ts';
|
|
@@ -12,7 +12,7 @@ export interface HostedAgentsOptions {
|
|
|
12
12
|
readonly catalog: () => Promise<ReadonlyArray<AssistantSkill>>;
|
|
13
13
|
readonly send: (hostDeviceId: Uint8Array, request: SecretRequest) => Promise<void>;
|
|
14
14
|
readonly onmoved: () => Promise<unknown>;
|
|
15
|
-
readonly log?:
|
|
15
|
+
readonly log?: LoggerInterface | null;
|
|
16
16
|
}
|
|
17
17
|
export declare class HostedAgents {
|
|
18
18
|
private readonly _mesh;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ACK_TIMEOUT_MS,
|
|
1
|
+
import { ACK_TIMEOUT_MS, type HandoffStream } from './handoff-channel.ts';
|
|
2
2
|
import type { AssistantInferenceCallEntry, AssistantInferenceCallsRequest } from '../../spec/hyperschema/types.d.ts';
|
|
3
|
-
export { ACK_TIMEOUT_MS,
|
|
3
|
+
export { ACK_TIMEOUT_MS, type HandoffStream };
|
|
4
4
|
export type InferenceCallsRequest = AssistantInferenceCallsRequest;
|
|
5
5
|
export interface InferenceCallsAnswer {
|
|
6
6
|
readonly calls: ReadonlyArray<AssistantInferenceCallEntry>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getStruct } from '../../spec/hyperschema/index.js';
|
|
2
|
-
import { ACK_TIMEOUT_MS, HandoffChannel
|
|
2
|
+
import { ACK_TIMEOUT_MS, HandoffChannel } from './handoff-channel.js';
|
|
3
3
|
const PROTOCOL = 'qvac/inference-calls-handoff';
|
|
4
|
-
export { ACK_TIMEOUT_MS
|
|
4
|
+
export { ACK_TIMEOUT_MS };
|
|
5
5
|
const handoff = getStruct('@assistant/inference-calls-handoff');
|
|
6
6
|
const handoffAck = getStruct('@assistant/inference-calls-handoff-ack');
|
|
7
7
|
export class InferenceCallsHandoff {
|
|
@@ -12,14 +12,15 @@ export class InferenceCallsHandoff {
|
|
|
12
12
|
requestEncoding: handoff,
|
|
13
13
|
ackEncoding: handoffAck,
|
|
14
14
|
onrequest: opts.onrequest,
|
|
15
|
-
buildAck: (id,
|
|
15
|
+
buildAck: (id, { message, code }, result) => ({
|
|
16
16
|
id,
|
|
17
|
-
error,
|
|
17
|
+
error: message,
|
|
18
|
+
code,
|
|
18
19
|
calls: result ? [...result.calls] : undefined,
|
|
19
20
|
truncated: result?.truncated
|
|
20
21
|
}),
|
|
21
22
|
readAck: (ack) => ({
|
|
22
|
-
error: ack.error ?? '',
|
|
23
|
+
error: { message: ack.error ?? '', code: ack.code ?? 0 },
|
|
23
24
|
result: { calls: ack.calls ?? [], truncated: ack.truncated ?? false }
|
|
24
25
|
}),
|
|
25
26
|
ackTimeoutMs: opts.ackTimeoutMs
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Mesh } from './mesh.ts';
|
|
2
2
|
import type { InferenceCallsHandler } from './inference-calls-handoff.ts';
|
|
3
3
|
import type { AssistantInferenceCallEntry } from '../../spec/hyperschema/types.d.ts';
|
|
4
|
-
export declare const NO_SUCH_CHAT = "no such chat on the device hosting this agent";
|
|
5
|
-
export declare const NO_RECORD_STORE = "the device hosting this agent is not recording prompts right now";
|
|
6
4
|
export interface InferenceCallsReceiverOptions {
|
|
7
5
|
readonly mesh: Mesh;
|
|
8
6
|
readonly deviceId: Uint8Array;
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { getAgent } from './agent.js';
|
|
3
3
|
import { getChat } from './chat.js';
|
|
4
|
-
import { NO_SUCH_AGENT, NOT_THE_HOST, SENDER_REVOKED } from './skill-secrets.js';
|
|
5
4
|
import { DEVICES } from './collections.js';
|
|
6
|
-
|
|
7
|
-
export const NO_RECORD_STORE = 'the device hosting this agent is not recording prompts right now';
|
|
5
|
+
import { CoreError } from '../errors.js';
|
|
8
6
|
const MAX_ANSWER_BYTES = 2 * 1024 * 1024;
|
|
9
7
|
export function createInferenceCallsReceiver(opts) {
|
|
10
8
|
return async (request, fromDeviceId) => {
|
|
11
9
|
const sender = await opts.mesh.view.get(DEVICES, { id: fromDeviceId });
|
|
12
10
|
if (!sender || sender.revoked) {
|
|
13
|
-
throw new
|
|
11
|
+
throw new CoreError('PEER_SENDER_REVOKED');
|
|
14
12
|
}
|
|
15
13
|
const chat = await getChat(opts.mesh, request.chatId);
|
|
16
14
|
if (!chat) {
|
|
17
|
-
throw new
|
|
15
|
+
throw new CoreError('INFERENCE_CHAT_NOT_FOUND');
|
|
18
16
|
}
|
|
19
17
|
const agent = await getAgent(opts.mesh, chat.agentId);
|
|
20
18
|
if (!agent) {
|
|
21
|
-
throw new
|
|
19
|
+
throw new CoreError('AGENT_HOST_AGENT_UNKNOWN');
|
|
22
20
|
}
|
|
23
21
|
if (!agent.providerDeviceId || !b4a.equals(agent.providerDeviceId, opts.deviceId)) {
|
|
24
|
-
throw new
|
|
22
|
+
throw new CoreError('AGENT_NOT_HOSTED_HERE');
|
|
25
23
|
}
|
|
26
24
|
const own = opts.listLocal(request.chatId);
|
|
27
25
|
const answer = capped(own.calls);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as z32 from 'z32';
|
|
2
2
|
import { decode as decodeStruct, encode as encodeStruct } from '../../spec/mesh/hyperschema/index.js';
|
|
3
3
|
const INVITE_STRUCT = '@qvac/mesh-invite';
|
|
4
|
-
const
|
|
4
|
+
const MEMBER_INVITE_PREFIX = 'qvac://workspace/';
|
|
5
|
+
const DEVICE_INVITE_PREFIX = 'qvac://device/';
|
|
6
|
+
const LEGACY_INVITE_PREFIX = 'qvac://mesh/';
|
|
7
|
+
const INVITE_PREFIXES = [MEMBER_INVITE_PREFIX, DEVICE_INVITE_PREFIX, LEGACY_INVITE_PREFIX];
|
|
5
8
|
export function encodeMeshInvite(invite) {
|
|
6
9
|
const payload = {
|
|
7
10
|
meshKey: invite.baseKey,
|
|
@@ -17,16 +20,18 @@ export function encodeMeshInvite(invite) {
|
|
|
17
20
|
deviceSeed: invite.deviceSeed ?? null,
|
|
18
21
|
deviceProof: invite.deviceProof ?? null
|
|
19
22
|
};
|
|
20
|
-
|
|
23
|
+
const prefix = invite.memberInvite ? MEMBER_INVITE_PREFIX : DEVICE_INVITE_PREFIX;
|
|
24
|
+
return prefix + z32.encode(encodeStruct(INVITE_STRUCT, payload));
|
|
21
25
|
}
|
|
22
26
|
export function decodeMeshInvite(raw) {
|
|
23
27
|
const value = raw.trim().toLowerCase();
|
|
24
|
-
|
|
28
|
+
const prefix = INVITE_PREFIXES.find((p) => value.startsWith(p));
|
|
29
|
+
if (!prefix) {
|
|
25
30
|
return null;
|
|
26
31
|
}
|
|
27
32
|
let payload;
|
|
28
33
|
try {
|
|
29
|
-
payload = decodeStruct(INVITE_STRUCT, z32.decode(value.slice(
|
|
34
|
+
payload = decodeStruct(INVITE_STRUCT, z32.decode(value.slice(prefix.length)));
|
|
30
35
|
}
|
|
31
36
|
catch {
|
|
32
37
|
return null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import CorestoreStorage from 'hypercore-storage';
|
|
2
2
|
import HyperDB from 'hyperdb';
|
|
3
|
-
import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatMove, LocalChatNotify, LocalChatOrder, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
|
|
3
|
+
import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatMove, LocalMeshUpdate, LocalChatNotify, LocalChatOrder, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
|
|
4
4
|
import type { DeviceMetadata } from '../mesh.ts';
|
|
5
5
|
import { LocalFiles } from './files.ts';
|
|
6
6
|
export interface ResolvedSession {
|
|
@@ -106,6 +106,9 @@ declare class LocalStore {
|
|
|
106
106
|
readAccountRecovery(meshKey: Buffer): Promise<LocalAccountRecovery | null>;
|
|
107
107
|
readChatMove(meshKey: Buffer, chatId: string): Promise<LocalChatMove | null>;
|
|
108
108
|
listChatMoves(): Promise<LocalChatMove[]>;
|
|
109
|
+
readMeshUpdate(meshKey: Buffer): Promise<LocalMeshUpdate | null>;
|
|
110
|
+
writeMeshUpdate(row: LocalMeshUpdate): Promise<void>;
|
|
111
|
+
clearMeshUpdate(meshKey: Buffer): Promise<void>;
|
|
109
112
|
recordChatMove(row: LocalChatMove): Promise<void>;
|
|
110
113
|
recordAccountRecovery(row: LocalAccountRecovery): Promise<void>;
|
|
111
114
|
replaceIdentity(identity: Omit<LocalIdentity, 'id'>): Promise<void>;
|
|
@@ -4,10 +4,11 @@ import crypto from 'hypercore-crypto';
|
|
|
4
4
|
import ScopeLock from 'scope-lock';
|
|
5
5
|
import { MAX_DEVICE_NAME_CHARS, deviceNameWithinBounds } from '../../../schema/qvac.js';
|
|
6
6
|
import { generateMnemonic, mintIdentity } from '../identity.js';
|
|
7
|
+
import { CoreError } from '../../errors.js';
|
|
7
8
|
import LocalDatabaseSpec from '../../../spec/local/hyperdb/index.js';
|
|
8
9
|
import b4a from 'b4a';
|
|
9
10
|
import { dropMeshFiles, LocalFiles } from './files.js';
|
|
10
|
-
import { LOCAL_ACCOUNT_RECOVERY, LOCAL_ACTIVE_MESH, LOCAL_APP_CONFIG, LOCAL_CHAT_MOVES, LOCAL_CHAT_NOTIFY, LOCAL_CHAT_ORDER, LOCAL_CHAT_ORDER_BY_KEY, LOCAL_CONFIG, LOCAL_CUSTOM_MODEL, LOCAL_DEVICE, LOCAL_IDENTITY, LOCAL_MEMBERSHIP, LOCAL_MEMBER_PROOF, LOCAL_MESH_DEPARTURE, LOCAL_MESH_HISTORY, LOCAL_MESH_MEMBERSHIP, LOCAL_MESH_SESSION, LOCAL_MODEL_DOWNLOAD, LOCAL_MODEL_NOTIFY } from '../collections.js';
|
|
11
|
+
import { LOCAL_ACCOUNT_RECOVERY, LOCAL_ACTIVE_MESH, LOCAL_APP_CONFIG, LOCAL_CHAT_MOVES, LOCAL_MESH_UPDATES, LOCAL_CHAT_NOTIFY, LOCAL_CHAT_ORDER, LOCAL_CHAT_ORDER_BY_KEY, LOCAL_CONFIG, LOCAL_CUSTOM_MODEL, LOCAL_DEVICE, LOCAL_IDENTITY, LOCAL_MEMBERSHIP, LOCAL_MEMBER_PROOF, LOCAL_MESH_DEPARTURE, LOCAL_MESH_HISTORY, LOCAL_MESH_MEMBERSHIP, LOCAL_MESH_SESSION, LOCAL_MODEL_DOWNLOAD, LOCAL_MODEL_NOTIFY } from '../collections.js';
|
|
11
12
|
const IDENTITY_ID = 'identity';
|
|
12
13
|
const MEMBERSHIP_ID = 'membership';
|
|
13
14
|
const APP_CONFIG_ID = 'default';
|
|
@@ -275,7 +276,7 @@ class LocalStore {
|
|
|
275
276
|
}
|
|
276
277
|
const name = seed.name.trim();
|
|
277
278
|
if (!deviceNameWithinBounds(name)) {
|
|
278
|
-
throw new
|
|
279
|
+
throw new CoreError('DEVICE_NAME_TOO_LONG', [MAX_DEVICE_NAME_CHARS]);
|
|
279
280
|
}
|
|
280
281
|
seed = { ...seed, name };
|
|
281
282
|
const tx = this._db.transaction();
|
|
@@ -353,6 +354,23 @@ class LocalStore {
|
|
|
353
354
|
listChatMoves() {
|
|
354
355
|
return this._db.find(LOCAL_CHAT_MOVES).toArray();
|
|
355
356
|
}
|
|
357
|
+
readMeshUpdate(meshKey) {
|
|
358
|
+
return this._db.get(LOCAL_MESH_UPDATES, { meshKey });
|
|
359
|
+
}
|
|
360
|
+
writeMeshUpdate(row) {
|
|
361
|
+
return this._locked(async () => {
|
|
362
|
+
const tx = this._db.transaction();
|
|
363
|
+
await tx.insert(LOCAL_MESH_UPDATES, row);
|
|
364
|
+
await tx.flush();
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
clearMeshUpdate(meshKey) {
|
|
368
|
+
return this._locked(async () => {
|
|
369
|
+
const tx = this._db.transaction();
|
|
370
|
+
await tx.delete(LOCAL_MESH_UPDATES, { meshKey });
|
|
371
|
+
await tx.flush();
|
|
372
|
+
});
|
|
373
|
+
}
|
|
356
374
|
recordChatMove(row) {
|
|
357
375
|
return this._locked(async () => {
|
|
358
376
|
const tx = this._db.transaction();
|
|
@@ -555,6 +573,7 @@ class LocalStore {
|
|
|
555
573
|
}
|
|
556
574
|
await this._dropChatOrder(tx, key);
|
|
557
575
|
await dropMeshFiles(tx, key);
|
|
576
|
+
await tx.delete(LOCAL_MESH_UPDATES, { meshKey: key });
|
|
558
577
|
await tx.flush();
|
|
559
578
|
});
|
|
560
579
|
}
|
|
@@ -563,6 +582,7 @@ class LocalStore {
|
|
|
563
582
|
const tx = this._db.transaction();
|
|
564
583
|
await this._dropChatOrder(tx, key);
|
|
565
584
|
await dropMeshFiles(tx, key);
|
|
585
|
+
await tx.delete(LOCAL_MESH_UPDATES, { meshKey: key });
|
|
566
586
|
await tx.flush();
|
|
567
587
|
});
|
|
568
588
|
}
|
|
@@ -610,6 +630,7 @@ class LocalStore {
|
|
|
610
630
|
await tx.insert(LOCAL_MESH_MEMBERSHIP, { ...row, leftAt, wasHome });
|
|
611
631
|
await this._dropChatOrder(tx, row.key);
|
|
612
632
|
await dropMeshFiles(tx, row.key);
|
|
633
|
+
await tx.delete(LOCAL_MESH_UPDATES, { meshKey: row.key });
|
|
613
634
|
}
|
|
614
635
|
await tx.insert(LOCAL_ACTIVE_MESH, { deviceId, homeMeshKey: key });
|
|
615
636
|
await tx.flush();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { KeyPair } from 'hyperswarm';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
3
3
|
import type { LocalIdentity } from '../../spec/local/hyperschema/types.d.ts';
|
|
4
4
|
import type { QvacDevice } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
5
5
|
import type { Mesh } from './mesh.ts';
|
|
@@ -10,7 +10,7 @@ export interface MembershipView {
|
|
|
10
10
|
}
|
|
11
11
|
export interface MembershipContext {
|
|
12
12
|
readonly deviceKeyPair: KeyPair;
|
|
13
|
-
readonly log:
|
|
13
|
+
readonly log: LoggerInterface | null;
|
|
14
14
|
}
|
|
15
15
|
export declare function membershipView(mesh: Mesh, deviceId: Buffer): Promise<MembershipView>;
|
|
16
16
|
export interface KnownMember {
|
|
@@ -7,9 +7,10 @@ import type { KeyPair } from 'hypercore-crypto';
|
|
|
7
7
|
import type Wakeup from 'protomux-wakeup';
|
|
8
8
|
import ReadyResource from 'ready-resource';
|
|
9
9
|
import { Files } from './files/index.ts';
|
|
10
|
-
import type {
|
|
10
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
11
11
|
import { Router } from '../../spec/mesh/hyperdispatch/index.js';
|
|
12
12
|
import type { QvacCapabilityProfile, QvacDevice, QvacMember, QvacMeshName } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
13
|
+
import { type PendingUpdates } from './sync/view-updates.ts';
|
|
13
14
|
import type { AttachmentUrl } from './attachment-link.ts';
|
|
14
15
|
import type { MeshFileIndex } from './files/local-index.ts';
|
|
15
16
|
import { type DeviceAttestation } from './device-attestation.ts';
|
|
@@ -33,17 +34,17 @@ export interface MeshOptions {
|
|
|
33
34
|
key?: Buffer | null;
|
|
34
35
|
writerSeed?: string;
|
|
35
36
|
deviceId?: Buffer;
|
|
36
|
-
logger?:
|
|
37
|
+
logger?: LoggerInterface | null;
|
|
37
38
|
blindPeerKeys?: ReadonlyArray<Buffer>;
|
|
38
39
|
bootFrom?: AutobeeOplogRef | null;
|
|
39
40
|
trustedDevice?: (deviceId: Buffer) => Promise<boolean>;
|
|
40
41
|
wakeup?: Wakeup;
|
|
41
42
|
attachmentUrl?: AttachmentUrl | null;
|
|
42
43
|
fileIndex?: MeshFileIndex | null;
|
|
44
|
+
pendingUpdates?: PendingUpdates | null;
|
|
43
45
|
slowWriteMs?: number;
|
|
44
46
|
slowDrainMs?: number;
|
|
45
47
|
}
|
|
46
|
-
export declare const MESH_JOINING = "This mesh is still joining: it accepts writes once it is joined";
|
|
47
48
|
export declare function meshPublicKeyFromSeed(seed: Buffer): Buffer;
|
|
48
49
|
export declare function isOurTrustedWriter(snap: HyperDB, writerKey: Buffer, ourMemberId: Buffer | null): Promise<boolean>;
|
|
49
50
|
export type BirthRow = {
|
|
@@ -103,6 +104,8 @@ export declare class Mesh extends ReadyResource {
|
|
|
103
104
|
private readonly _deviceKeyPair;
|
|
104
105
|
private readonly _encryptionKey;
|
|
105
106
|
private _blindPeering;
|
|
107
|
+
openedEmpty: boolean;
|
|
108
|
+
private readonly _updates;
|
|
106
109
|
private _openedAt;
|
|
107
110
|
private readonly _trustedDevice;
|
|
108
111
|
private _joined;
|
|
@@ -126,6 +129,7 @@ export declare class Mesh extends ReadyResource {
|
|
|
126
129
|
get blobs(): Hyperblobs;
|
|
127
130
|
get syncActivity(): SyncActivity;
|
|
128
131
|
get publicKey(): Buffer;
|
|
132
|
+
get log(): LoggerInterface | null;
|
|
129
133
|
get devicePublicKey(): Buffer;
|
|
130
134
|
get key(): Buffer;
|
|
131
135
|
get compute(): boolean;
|
|
@@ -137,8 +141,9 @@ export declare class Mesh extends ReadyResource {
|
|
|
137
141
|
get ourMemberId(): Buffer | null;
|
|
138
142
|
get ourDeviceId(): Buffer | null;
|
|
139
143
|
get membership(): MembershipStats;
|
|
144
|
+
tallyMembership(): void;
|
|
140
145
|
refreshMembership(): Promise<void>;
|
|
141
|
-
refreshOurMember(): Promise<
|
|
146
|
+
refreshOurMember(): Promise<QvacDevice | null>;
|
|
142
147
|
get name(): QvacMeshName | null;
|
|
143
148
|
refreshName(): Promise<void>;
|
|
144
149
|
setName(name: string): Promise<void>;
|
|
@@ -182,7 +187,7 @@ export declare class Mesh extends ReadyResource {
|
|
|
182
187
|
pendingUploads(): number;
|
|
183
188
|
suspend(): Promise<void>;
|
|
184
189
|
resume(): void;
|
|
185
|
-
syncChatOrder: ((chatIds: Set<string>
|
|
190
|
+
syncChatOrder: ((chatIds: Set<string>) => Promise<void>) | null;
|
|
186
191
|
chatOrderBuilt: Promise<void>;
|
|
187
192
|
watch(listener: () => void): void;
|
|
188
193
|
unwatch(listener: () => void): void;
|
|
@@ -194,10 +199,11 @@ export declare class Mesh extends ReadyResource {
|
|
|
194
199
|
_autobeeApply(nodes: ReadonlyArray<AutobeeNode>, view: MeshView, host: AutobeeHost): Promise<void>;
|
|
195
200
|
private _applyNode;
|
|
196
201
|
private _halt;
|
|
197
|
-
_autobeeUpdate(
|
|
202
|
+
_autobeeUpdate(_view: MeshView, changes: AutobeeChanges): Promise<void>;
|
|
203
|
+
synced(): Promise<void>;
|
|
204
|
+
private _syncUpdate;
|
|
198
205
|
private _arrive;
|
|
199
206
|
private _readLanding;
|
|
200
|
-
private _prefetchView;
|
|
201
207
|
checkOwnAdmission(): Promise<void>;
|
|
202
208
|
checkResumedRevocation(): Promise<'kicked' | 'left' | null>;
|
|
203
209
|
ownWriterRefused(): Promise<boolean>;
|