@qvac/core 1.0.0-rc.6 → 1.0.0-rc.8

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 (67) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist-lib/lib/api/agents.js +5 -2
  3. package/dist-lib/lib/api/approval-rules.js +8 -5
  4. package/dist-lib/lib/api/chat.d.ts +1 -2
  5. package/dist-lib/lib/api/chat.js +4 -18
  6. package/dist-lib/lib/api/device-routes.d.ts +6 -1
  7. package/dist-lib/lib/api/device-routes.js +20 -1
  8. package/dist-lib/lib/api/index.d.ts +0 -1
  9. package/dist-lib/lib/api/index.js +1 -2
  10. package/dist-lib/lib/api/mesh.d.ts +1 -1
  11. package/dist-lib/lib/api/mesh.js +1 -1
  12. package/dist-lib/lib/api/rag.js +2 -5
  13. package/dist-lib/lib/api/sync.js +12 -2
  14. package/dist-lib/lib/assistant/model-round.d.ts +7 -1
  15. package/dist-lib/lib/assistant/model-round.js +33 -11
  16. package/dist-lib/lib/assistant-tree.js +7 -0
  17. package/dist-lib/lib/assistant.d.ts +3 -2
  18. package/dist-lib/lib/assistant.js +20 -19
  19. package/dist-lib/lib/core/archived-mesh.d.ts +1 -0
  20. package/dist-lib/lib/core/archived-mesh.js +11 -14
  21. package/dist-lib/lib/core/chat-copy.d.ts +0 -1
  22. package/dist-lib/lib/core/chat-copy.js +1 -2
  23. package/dist-lib/lib/core/chat-move.d.ts +3 -1
  24. package/dist-lib/lib/core/chat-move.js +5 -2
  25. package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
  26. package/dist-lib/lib/core/local/index.d.ts +2 -1
  27. package/dist-lib/lib/core/local/index.js +3 -2
  28. package/dist-lib/lib/core/public-mesh.d.ts +6 -8
  29. package/dist-lib/lib/core/public-mesh.js +19 -29
  30. package/dist-lib/lib/core/sync/index.js +1 -1
  31. package/dist-lib/lib/core.d.ts +21 -8
  32. package/dist-lib/lib/core.js +233 -204
  33. package/dist-lib/lib/errors.d.ts +8 -12
  34. package/dist-lib/lib/errors.js +8 -12
  35. package/dist-lib/lib/model-download.d.ts +6 -1
  36. package/dist-lib/lib/model-download.js +16 -3
  37. package/dist-lib/lib/oauth/resolve.js +29 -8
  38. package/dist-lib/lib/oauth/token-exchange-core.js +11 -0
  39. package/dist-lib/schema/engine.js +10 -3
  40. package/dist-lib/schema/local.js +4 -2
  41. package/dist-lib/schema/qvac.js +2 -1
  42. package/dist-lib/spec/capabilities.d.ts +2 -2
  43. package/dist-lib/spec/hrpc/hrpc.json +1 -1
  44. package/dist-lib/spec/hrpc/index.js +1 -1
  45. package/dist-lib/spec/hrpc/messages.js +273 -250
  46. package/dist-lib/spec/hyperschema/index.js +273 -250
  47. package/dist-lib/spec/hyperschema/schema.json +27 -6
  48. package/dist-lib/spec/hyperschema/types.d.ts +7 -1
  49. package/dist-lib/spec/local/hyperdb/messages.js +26 -12
  50. package/dist-lib/spec/local/hyperschema/index.js +13 -6
  51. package/dist-lib/spec/local/hyperschema/schema.json +10 -0
  52. package/dist-lib/spec/local/hyperschema/types.d.ts +2 -0
  53. package/dist-lib/spec/mesh/hyperdb/messages.js +30 -6
  54. package/dist-lib/spec/mesh/hyperdispatch/messages.js +15 -3
  55. package/dist-lib/spec/mesh/hyperschema/index.js +15 -3
  56. package/dist-lib/spec/mesh/hyperschema/schema.json +5 -0
  57. package/dist-lib/spec/mesh/hyperschema/types.d.ts +1 -0
  58. package/package.json +10 -4
  59. package/tui/README.md +51 -0
  60. package/tui/app.mjs +88 -17
  61. package/tui/boot.mjs +23 -6
  62. package/tui/cli.mjs +93 -0
  63. package/tui/index.mjs +2 -87
  64. package/tui/lib/updater.mjs +86 -0
  65. package/tui/main.mjs +26 -15
  66. package/dist-lib/lib/core/chat-project.d.ts +0 -2
  67. package/dist-lib/lib/core/chat-project.js +0 -15
@@ -131,18 +131,14 @@ declare const DEFINITIONS: {
131
131
  readonly code: 100127;
132
132
  readonly message: (max: number) => string;
133
133
  };
134
- readonly OWN_WORKSPACE_INVITE_REFUSED: {
135
- readonly code: 100128;
136
- readonly message: () => string;
137
- };
138
- readonly OWN_WORKSPACE_LEAVE_REFUSED: {
139
- readonly code: 100129;
140
- readonly message: () => string;
141
- };
142
134
  readonly COMPUTE_MESH_RETIRED: {
143
135
  readonly code: 100130;
144
136
  readonly message: () => string;
145
137
  };
138
+ readonly ROUTE_NEEDS_WORKSPACE: {
139
+ readonly code: 100131;
140
+ readonly message: (route: string) => string;
141
+ };
146
142
  readonly INVITE_INVALID: {
147
143
  readonly code: 100201;
148
144
  readonly message: () => string;
@@ -487,10 +483,6 @@ declare const DEFINITIONS: {
487
483
  readonly code: 100726;
488
484
  readonly message: (chunkId: string) => string;
489
485
  };
490
- readonly CHAT_PROJECT_OTHER_WORKSPACE: {
491
- readonly code: 100727;
492
- readonly message: () => string;
493
- };
494
486
  readonly CHAT_AGENT_SWITCH_NO_DEVICE: {
495
487
  readonly code: 100728;
496
488
  readonly message: () => string;
@@ -743,6 +735,10 @@ declare const DEFINITIONS: {
743
735
  readonly code: 101220;
744
736
  readonly message: () => string;
745
737
  };
738
+ readonly OAUTH_GRANT_REVOKED: {
739
+ readonly code: 101221;
740
+ readonly message: () => string;
741
+ };
746
742
  readonly SIDECAR_ENTRY_MISSING: {
747
743
  readonly code: 101301;
748
744
  readonly message: () => string;
@@ -105,18 +105,14 @@ const DEFINITIONS = {
105
105
  code: 100127,
106
106
  message: (max) => `A project order holds at most ${max} projects`
107
107
  },
108
- OWN_WORKSPACE_INVITE_REFUSED: {
109
- code: 100128,
110
- message: () => 'Your own workspace is yours alone: invite people into another workspace'
111
- },
112
- OWN_WORKSPACE_LEAVE_REFUSED: {
113
- code: 100129,
114
- message: () => 'Your own workspace cannot be left'
115
- },
116
108
  COMPUTE_MESH_RETIRED: {
117
109
  code: 100130,
118
110
  message: () => 'Compute meshes are retired: a model runs on the device that asks'
119
111
  },
112
+ ROUTE_NEEDS_WORKSPACE: {
113
+ code: 100131,
114
+ message: (route) => `${route} reads and writes a workspace: name a workspace's meshId, not the account's`
115
+ },
120
116
  INVITE_INVALID: { code: 100201, message: () => 'Invalid mesh invite' },
121
117
  MESH_JOIN_CANCELED: { code: 100202, message: () => 'Mesh join canceled' },
122
118
  JOIN_NOT_PERMITTED: {
@@ -401,10 +397,6 @@ const DEFINITIONS = {
401
397
  code: 100726,
402
398
  message: (chunkId) => `model-request ${chunkId} has already ended`
403
399
  },
404
- CHAT_PROJECT_OTHER_WORKSPACE: {
405
- code: 100727,
406
- message: () => "a chat links only projects of its own workspace: start one in the project's"
407
- },
408
400
  CHAT_AGENT_SWITCH_NO_DEVICE: {
409
401
  code: 100728,
410
402
  message: () => "this device has no identity yet, so it cannot switch a chat's agent"
@@ -658,6 +650,10 @@ const DEFINITIONS = {
658
650
  code: 101220,
659
651
  message: () => 'OAuth client registration timed out'
660
652
  },
653
+ OAUTH_GRANT_REVOKED: {
654
+ code: 101221,
655
+ message: () => 'OAuth grant was revoked or expired (invalid_grant); sign in again'
656
+ },
661
657
  SIDECAR_ENTRY_MISSING: {
662
658
  code: 101301,
663
659
  message: () => 'sidecar mode needs a stowed bundle entry'
@@ -25,6 +25,9 @@ export interface CacheWaitOptions {
25
25
  readonly onProgress?: (percentage: number) => void;
26
26
  readonly onStall?: () => void;
27
27
  }
28
+ export interface RetryOptions {
29
+ readonly sibling?: boolean;
30
+ }
28
31
  interface DownloadHarness {
29
32
  list?(options?: {
30
33
  cachedOnly?: boolean;
@@ -138,6 +141,7 @@ export declare class ModelDownloadReconciler {
138
141
  private readonly _observedProgress;
139
142
  private readonly _observedSpeed;
140
143
  private readonly _requestedModels;
144
+ private readonly _siblingRequests;
141
145
  private readonly _heldLoads;
142
146
  private readonly _releasing;
143
147
  private readonly _targetTotals;
@@ -174,7 +178,8 @@ export declare class ModelDownloadReconciler {
174
178
  private _transfer;
175
179
  private _completeTransfer;
176
180
  waitUntilCached(model: string, signal: AbortSignal, { onHold, onProgress, onStall }?: CacheWaitOptions): Promise<void>;
177
- retry(name: string): Promise<void>;
181
+ retry(name: string, { sibling }?: RetryOptions): Promise<void>;
182
+ siblingResumed(name: string): void;
178
183
  release<T>(name: string, removeFiles: () => Promise<T>): Promise<T>;
179
184
  close(): Promise<void>;
180
185
  private _watchConfig;
@@ -34,6 +34,7 @@ export class ModelDownloadReconciler {
34
34
  _observedProgress = new Map();
35
35
  _observedSpeed = new Map();
36
36
  _requestedModels = new Set();
37
+ _siblingRequests = new Set();
37
38
  _heldLoads = new Set();
38
39
  _releasing = new Set();
39
40
  _targetTotals = new Map();
@@ -227,10 +228,15 @@ export class ModelDownloadReconciler {
227
228
  this._kick();
228
229
  });
229
230
  }
230
- async retry(name) {
231
+ async retry(name, { sibling = false } = {}) {
231
232
  if (this._closed)
232
233
  throw new CoreError('MODEL_DOWNLOAD_CLOSED');
233
- this._requestedModels.add(name);
234
+ if (!sibling) {
235
+ this._requestedModels.add(name);
236
+ }
237
+ else if (!this._requestedModels.has(name)) {
238
+ this._siblingRequests.add(name);
239
+ }
234
240
  this._attemptGenerations.set(name, this._attemptGeneration(name) + 1);
235
241
  const demand = this._demands.get(name);
236
242
  if (demand) {
@@ -243,11 +249,17 @@ export class ModelDownloadReconciler {
243
249
  }
244
250
  this._kick();
245
251
  }
252
+ siblingResumed(name) {
253
+ if (this._config?.pausedModels?.includes(name) && this._requestedModels.delete(name)) {
254
+ this._siblingRequests.add(name);
255
+ }
256
+ }
246
257
  async release(name, removeFiles) {
247
258
  if (this._closed)
248
259
  throw new CoreError('MODEL_DOWNLOAD_CLOSED');
249
260
  this._releasing.add(name);
250
261
  this._requestedModels.delete(name);
262
+ this._siblingRequests.delete(name);
251
263
  this._handled.delete(name);
252
264
  try {
253
265
  if (this._active?.model === name) {
@@ -616,7 +628,7 @@ export class ModelDownloadReconciler {
616
628
  }
617
629
  }
618
630
  }
619
- for (const name of this._requestedModels) {
631
+ for (const name of [...this._requestedModels, ...this._siblingRequests]) {
620
632
  if (wanted.has(name))
621
633
  continue;
622
634
  const addon = availability.addons.get(name);
@@ -647,6 +659,7 @@ export class ModelDownloadReconciler {
647
659
  for (const model of wanted.values()) {
648
660
  if (availability.cached.has(model.name)) {
649
661
  this._requestedModels.delete(model.name);
662
+ this._siblingRequests.delete(model.name);
650
663
  this._resolveDemand(model.name);
651
664
  await this._status.clear(model.name);
652
665
  continue;
@@ -1,4 +1,5 @@
1
1
  import { scopedKey } from './keys.js';
2
+ import { isCoreError } from '../errors.js';
2
3
  export const REFRESH_SKEW_MS = 60_000;
3
4
  const inFlightRefresh = new WeakMap();
4
5
  export async function resolveOAuthCredential(opts) {
@@ -41,12 +42,16 @@ export async function resolveOAuthCredential(opts) {
41
42
  let pending = engineRefreshes.get(refreshKey);
42
43
  if (!pending) {
43
44
  pending = (async () => {
44
- const refreshed = await refresh({
45
- clientId,
46
- clientSecret,
47
- refreshToken,
48
- fetch: opts.fetch
49
- });
45
+ let refreshed;
46
+ try {
47
+ refreshed = await refresh({ clientId, clientSecret, refreshToken, fetch: opts.fetch });
48
+ }
49
+ catch (err) {
50
+ if (isCoreError(err, 'OAUTH_GRANT_REVOKED')) {
51
+ await forgetGrant(opts, refreshToken);
52
+ }
53
+ throw err;
54
+ }
50
55
  await engine.configSet({
51
56
  key: scopedKey(agentId, credentialKey),
52
57
  value: refreshed.accessToken
@@ -65,7 +70,23 @@ export async function resolveOAuthCredential(opts) {
65
70
  }
66
71
  return await pending;
67
72
  }
68
- catch {
69
- return token;
73
+ catch (err) {
74
+ return isCoreError(err, 'OAUTH_GRANT_REVOKED') ? null : token;
75
+ }
76
+ }
77
+ async function forgetGrant({ engine, agentId, credentialKey, stateKey }, deadRefreshToken) {
78
+ const { value: raw } = await engine.configGet({ key: scopedKey(agentId, stateKey) });
79
+ let current = {};
80
+ try {
81
+ current = (typeof raw === 'string' && JSON.parse(raw)) || {};
82
+ }
83
+ catch { }
84
+ if (current.refreshToken !== deadRefreshToken) {
85
+ return;
70
86
  }
87
+ await engine.configSet({ key: scopedKey(agentId, credentialKey), value: '' });
88
+ await engine.configSet({
89
+ key: scopedKey(agentId, stateKey),
90
+ value: JSON.stringify({ ...current, refreshToken: undefined, expiresAt: undefined })
91
+ });
71
92
  }
@@ -86,12 +86,23 @@ export async function refreshOAuthTokensWithFetch(config, refreshToken, fetchImp
86
86
  read: async (response) => {
87
87
  if (!response.ok) {
88
88
  const text = await response.text().catch(() => '');
89
+ if (isInvalidGrant(text)) {
90
+ throw new CoreError('OAUTH_GRANT_REVOKED');
91
+ }
89
92
  throw new CoreError('OAUTH_TOKEN_REFRESH_FAILED', [response.status, text]);
90
93
  }
91
94
  return toTokens(parseTokenResponse(await response.json()), refreshToken);
92
95
  }
93
96
  });
94
97
  }
98
+ function isInvalidGrant(text) {
99
+ try {
100
+ return TokenErrorSchema.safeParse(JSON.parse(text)).data?.error === 'invalid_grant';
101
+ }
102
+ catch {
103
+ return false;
104
+ }
105
+ }
95
106
  export function isTokenExpired(record, bufferMs = 60_000) {
96
107
  return typeof record.expiresAt === 'number' && Date.now() + bufferMs >= record.expiresAt;
97
108
  }
@@ -2015,8 +2015,7 @@ export function registerEngineTypes(ns) {
2015
2015
  fields: [
2016
2016
  { name: 'meshId', type: 'string' },
2017
2017
  { name: 'writable', type: 'bool', required: true },
2018
- { name: 'displayName', type: 'string' },
2019
- { name: 'ownWorkspace', type: 'string' }
2018
+ { name: 'displayName', type: 'string' }
2020
2019
  ]
2021
2020
  });
2022
2021
  ns.register({
@@ -2100,10 +2099,18 @@ export function registerEngineTypes(ns) {
2100
2099
  { name: 'knowledge', type: 'uint', required: true }
2101
2100
  ]
2102
2101
  });
2102
+ ns.register({
2103
+ name: 'migrate-archived-mesh-request',
2104
+ fields: [
2105
+ { name: 'meshId', type: 'string', required: true },
2106
+ { name: 'workspaceId', type: 'string', required: true }
2107
+ ]
2108
+ });
2103
2109
  ns.register({
2104
2110
  name: 'archived-mesh-migration',
2105
2111
  fields: [
2106
2112
  { name: 'meshId', type: 'string', required: true },
2113
+ { name: 'workspaceId', type: 'string', required: true },
2107
2114
  { name: 'migrated', type: 'bool', required: true },
2108
2115
  { name: 'migratedAt', type: 'uint', required: true },
2109
2116
  { name: 'chats', type: 'uint', required: true },
@@ -3226,7 +3233,7 @@ export function registerEngineApi(api) {
3226
3233
  });
3227
3234
  api.register({
3228
3235
  name: 'migrate-archived-mesh',
3229
- request: { name: '@assistant/mesh-target', stream: false },
3236
+ request: { name: '@assistant/migrate-archived-mesh-request', stream: false },
3230
3237
  response: { name: '@assistant/archived-mesh-migration', stream: false }
3231
3238
  });
3232
3239
  api.register({
@@ -126,7 +126,8 @@ export function registerLocalTypes(ns) {
126
126
  { name: 'workspaceKey', type: 'fixed32' },
127
127
  { name: 'joinedAt', type: 'uint' },
128
128
  { name: 'kicked', type: 'bool' },
129
- { name: 'retiredUnder', type: 'fixed32' }
129
+ { name: 'retiredUnder', type: 'fixed32' },
130
+ { name: 'initial', type: 'bool' }
130
131
  ]);
131
132
  versioned('member-proof', [
132
133
  { name: 'meshKey', type: 'fixed32', required: true },
@@ -169,7 +170,8 @@ export function registerLocalTypes(ns) {
169
170
  { name: 'restartRunId', type: 'string' },
170
171
  { name: 'startedAt', type: 'uint', required: true },
171
172
  { name: 'completedAt', type: 'uint' },
172
- { name: 'failure', type: 'string' }
173
+ { name: 'failure', type: 'string' },
174
+ { name: 'targetMeshId', type: 'string' }
173
175
  ]);
174
176
  ns.register({ name: 'capability-profile', enum: CAPABILITY_PROFILES, strings: true });
175
177
  versioned('mesh-update', [
@@ -556,7 +556,8 @@ export function registerQvacTypes(ns) {
556
556
  { name: 'shared', type: 'bool' },
557
557
  { name: 'sharedAt', type: 'uint' },
558
558
  { name: 'workspace', type: 'bool' },
559
- { name: 'kicked', type: 'bool' }
559
+ { name: 'kicked', type: 'bool' },
560
+ { name: 'initial', type: 'bool' }
560
561
  ]);
561
562
  versioned('put-joined-mesh-operation', [
562
563
  { name: 'room', type: '@qvac/joined-mesh', required: true }
@@ -160,7 +160,7 @@ export interface Capabilities {
160
160
  updateMember(input: T.AssistantUpdateMemberRequest): Promise<T.AssistantMember>
161
161
  removeMember(input: T.AssistantRemoveMemberRequest): Promise<T.AssistantOkResponse>
162
162
  archivedMeshContents(input: T.AssistantMeshTarget): Promise<T.AssistantArchivedMeshContents>
163
- migrateArchivedMesh(input: T.AssistantMeshTarget): Promise<T.AssistantArchivedMeshMigration>
163
+ migrateArchivedMesh(input: T.AssistantMigrateArchivedMeshRequest): Promise<T.AssistantArchivedMeshMigration>
164
164
  listArchivedMeshes(input?: T.AssistantEmpty): Promise<T.AssistantArchivedMeshList>
165
165
  accountRecoverable(input?: T.AssistantEmpty): Promise<T.AssistantAccountRecoveryState>
166
166
  recoveryPublish(input: T.AssistantIdentityPhrase): Promise<T.AssistantAccountRecoveryState>
@@ -366,7 +366,7 @@ export interface CapabilityHandlers {
366
366
  updateMember(input: T.AssistantUpdateMemberRequest): T.AssistantMember | Promise<T.AssistantMember>
367
367
  removeMember(input: T.AssistantRemoveMemberRequest): T.AssistantOkResponse | Promise<T.AssistantOkResponse>
368
368
  archivedMeshContents(input: T.AssistantMeshTarget): T.AssistantArchivedMeshContents | Promise<T.AssistantArchivedMeshContents>
369
- migrateArchivedMesh(input: T.AssistantMeshTarget): T.AssistantArchivedMeshMigration | Promise<T.AssistantArchivedMeshMigration>
369
+ migrateArchivedMesh(input: T.AssistantMigrateArchivedMeshRequest): T.AssistantArchivedMeshMigration | Promise<T.AssistantArchivedMeshMigration>
370
370
  listArchivedMeshes(input?: T.AssistantEmpty): T.AssistantArchivedMeshList | Promise<T.AssistantArchivedMeshList>
371
371
  accountRecoverable(input?: T.AssistantEmpty): T.AssistantAccountRecoveryState | Promise<T.AssistantAccountRecoveryState>
372
372
  recoveryPublish(input: T.AssistantIdentityPhrase): T.AssistantAccountRecoveryState | Promise<T.AssistantAccountRecoveryState>
@@ -1721,7 +1721,7 @@
1721
1721
  "id": 132,
1722
1722
  "name": "@assistant/migrate-archived-mesh",
1723
1723
  "request": {
1724
- "name": "@assistant/mesh-target",
1724
+ "name": "@assistant/migrate-archived-mesh-request",
1725
1725
  "stream": false
1726
1726
  },
1727
1727
  "response": {
@@ -551,7 +551,7 @@ class HRPC {
551
551
  ['@assistant/update-member', getEncoding('@assistant/update-member-request')],
552
552
  ['@assistant/remove-member', getEncoding('@assistant/remove-member-request')],
553
553
  ['@assistant/archived-mesh-contents', getEncoding('@assistant/mesh-target')],
554
- ['@assistant/migrate-archived-mesh', getEncoding('@assistant/mesh-target')],
554
+ ['@assistant/migrate-archived-mesh', getEncoding('@assistant/migrate-archived-mesh-request')],
555
555
  ['@assistant/list-archived-meshes', getEncoding('@assistant/empty')],
556
556
  ['@assistant/account-recoverable', getEncoding('@assistant/empty')],
557
557
  ['@assistant/recovery-publish', getEncoding('@assistant/identity-phrase')],