@qvac/core 0.3.0 → 0.3.2

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 (191) hide show
  1. package/dist-lib/lib/api/chat.d.ts +3 -1
  2. package/dist-lib/lib/api/chat.js +6 -2
  3. package/dist-lib/lib/api/index.d.ts +2 -0
  4. package/dist-lib/lib/api/index.js +3 -1
  5. package/dist-lib/lib/api/inference-calls.d.ts +18 -0
  6. package/dist-lib/lib/api/inference-calls.js +15 -0
  7. package/dist-lib/lib/api/rag.js +10 -2
  8. package/dist-lib/lib/assistant/harness.d.ts +1 -0
  9. package/dist-lib/lib/assistant/history.d.ts +10 -1
  10. package/dist-lib/lib/assistant/history.js +36 -1
  11. package/dist-lib/lib/assistant/message.d.ts +2 -0
  12. package/dist-lib/lib/assistant/message.js +11 -0
  13. package/dist-lib/lib/assistant/skill-encode.js +27 -1
  14. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  15. package/dist-lib/lib/assistant-tree.js +11 -2
  16. package/dist-lib/lib/assistant.d.ts +19 -3
  17. package/dist-lib/lib/assistant.js +148 -23
  18. package/dist-lib/lib/core/chunk.js +5 -0
  19. package/dist-lib/lib/core/files/rag/build.d.ts +1 -2
  20. package/dist-lib/lib/core/files/rag/build.js +1 -2
  21. package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +1 -1
  22. package/dist-lib/lib/core/files/rag/index.d.ts +4 -24
  23. package/dist-lib/lib/core/files/rag/index.js +3 -17
  24. package/dist-lib/lib/core/files/rag/load.d.ts +1 -2
  25. package/dist-lib/lib/core/files/rag/load.js +1 -2
  26. package/dist-lib/lib/core/files/rag/produce.d.ts +1 -1
  27. package/dist-lib/lib/core/files/rag/produce.js +1 -3
  28. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -1
  29. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +1 -4
  30. package/dist-lib/lib/core/files/rag/similarity.d.ts +5 -0
  31. package/dist-lib/lib/core/files/rag/similarity.js +6 -0
  32. package/dist-lib/lib/core/files/upload.d.ts +1 -1
  33. package/dist-lib/lib/core/inference-calls-handoff.d.ts +20 -0
  34. package/dist-lib/lib/core/inference-calls-handoff.js +37 -0
  35. package/dist-lib/lib/core/inference-calls-receiver.d.ts +14 -0
  36. package/dist-lib/lib/core/inference-calls-receiver.js +39 -0
  37. package/dist-lib/lib/core/notification.js +5 -4
  38. package/dist-lib/lib/core/skill-secrets.js +3 -6
  39. package/dist-lib/lib/core.d.ts +9 -1
  40. package/dist-lib/lib/core.js +129 -13
  41. package/dist-lib/lib/credential-pusher.d.ts +2 -3
  42. package/dist-lib/lib/credential-pusher.js +67 -39
  43. package/dist-lib/lib/inference-calls.d.ts +40 -0
  44. package/dist-lib/lib/inference-calls.js +266 -0
  45. package/dist-lib/lib/integrations/index.d.ts +1 -2
  46. package/dist-lib/lib/integrations/index.js +0 -1
  47. package/dist-lib/lib/integrations/setup-routes.js +0 -15
  48. package/dist-lib/lib/oauth/flow-core.js +1 -1
  49. package/dist-lib/lib/oauth/flow.d.ts +4 -2
  50. package/dist-lib/lib/oauth/flow.js +3 -4
  51. package/dist-lib/lib/oauth/host.d.ts +3 -1
  52. package/dist-lib/lib/oauth/host.js +3 -1
  53. package/dist-lib/lib/oauth/keys.d.ts +21 -20
  54. package/dist-lib/lib/oauth/keys.js +59 -85
  55. package/dist-lib/lib/oauth/loopback.d.ts +2 -2
  56. package/dist-lib/lib/oauth/loopback.js +32 -19
  57. package/dist-lib/lib/oauth/loopback.stub.d.ts +2 -2
  58. package/dist-lib/lib/oauth/loopback.stub.js +2 -2
  59. package/dist-lib/lib/oauth/providers.d.ts +3 -5
  60. package/dist-lib/lib/oauth/providers.js +20 -67
  61. package/dist-lib/lib/oauth/redirect-types.d.ts +1 -0
  62. package/dist-lib/lib/oauth/registry.d.ts +10 -0
  63. package/dist-lib/lib/oauth/registry.js +25 -0
  64. package/dist-lib/lib/oauth/resolve.js +1 -1
  65. package/dist-lib/lib/oauth/token-exchange-core.js +2 -1
  66. package/dist-lib/lib/oauth/types.d.ts +1 -1
  67. package/dist-lib/lib/oauth.client.d.ts +3 -1
  68. package/dist-lib/lib/oauth.client.js +3 -1
  69. package/dist-lib/lib/oauth.d.ts +4 -7
  70. package/dist-lib/lib/oauth.js +4 -7
  71. package/dist-lib/lib/skill-types.d.ts +12 -0
  72. package/dist-lib/schema/content.js +5 -1
  73. package/dist-lib/schema/engine.js +63 -2
  74. package/dist-lib/schema/qvac.js +4 -2
  75. package/dist-lib/spec/bind.js +3 -0
  76. package/dist-lib/spec/calls.js +1 -0
  77. package/dist-lib/spec/capabilities.d.ts +2 -0
  78. package/dist-lib/spec/hrpc/hrpc.json +13 -0
  79. package/dist-lib/spec/hrpc/index.js +15 -3
  80. package/dist-lib/spec/hrpc/messages.js +284 -52
  81. package/dist-lib/spec/hyperschema/index.js +284 -52
  82. package/dist-lib/spec/hyperschema/schema.json +210 -1
  83. package/dist-lib/spec/hyperschema/types.d.ts +51 -1
  84. package/dist-lib/spec/local/hyperdb/messages.js +64 -128
  85. package/dist-lib/spec/local/hyperschema/index.js +32 -64
  86. package/dist-lib/spec/local/hyperschema/schema.json +16 -0
  87. package/dist-lib/spec/mesh/hyperdb/messages.js +176 -311
  88. package/dist-lib/spec/mesh/hyperdispatch/messages.js +132 -236
  89. package/dist-lib/spec/mesh/hyperschema/index.js +132 -236
  90. package/dist-lib/spec/mesh/hyperschema/schema.json +70 -1
  91. package/dist-lib/spec/mesh/hyperschema/types.d.ts +3 -1
  92. package/package.json +15 -18
  93. package/tui/app.mjs +98 -155
  94. package/tui/lib/knowledge-import.mjs +1 -1
  95. package/tui/lib/save-file.mjs +1 -1
  96. package/.claude/skills/asana/SKILL.md +0 -86
  97. package/.claude/skills/compaction/SKILL.md +0 -136
  98. package/.claude/skills/device-mesh-debug/SKILL.md +0 -328
  99. package/.claude/skills/gh-stack/SKILL.md +0 -181
  100. package/.claude/skills/gh-stack/references/commands.md +0 -177
  101. package/.claude/skills/gh-stack/references/stack-design.md +0 -97
  102. package/.claude/skills/gh-stack/references/troubleshooting.md +0 -159
  103. package/.claude/skills/js-house-style/SKILL.md +0 -671
  104. package/.claude/skills/pr-create/SKILL.md +0 -243
  105. package/.claude/skills/pr-review/SKILL.md +0 -428
  106. package/.claude/skills/release/SKILL.md +0 -122
  107. package/CLAUDE.md +0 -48
  108. package/dist-lib/lib/core/files/rag/artifact/codec.d.ts +0 -3
  109. package/dist-lib/lib/core/files/rag/artifact/codec.js +0 -172
  110. package/dist-lib/lib/core/files/rag/artifact/id.d.ts +0 -10
  111. package/dist-lib/lib/core/files/rag/artifact/id.js +0 -39
  112. package/dist-lib/lib/core/files/rag/artifact/types.d.ts +0 -24
  113. package/dist-lib/lib/core/files/rag/artifact/types.js +0 -41
  114. package/dist-lib/lib/core/files/rag/chunk/chunking.d.ts +0 -12
  115. package/dist-lib/lib/core/files/rag/chunk/chunking.js +0 -117
  116. package/dist-lib/lib/core/files/rag/chunk/metadata.d.ts +0 -30
  117. package/dist-lib/lib/core/files/rag/chunk/metadata.js +0 -89
  118. package/dist-lib/lib/core/files/rag/chunk/tokenizer.d.ts +0 -7
  119. package/dist-lib/lib/core/files/rag/chunk/tokenizer.js +0 -18
  120. package/dist-lib/lib/core/files/rag/extract/csv-text.d.ts +0 -1
  121. package/dist-lib/lib/core/files/rag/extract/csv-text.js +0 -117
  122. package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +0 -22
  123. package/dist-lib/lib/core/files/rag/extract/document-types.js +0 -152
  124. package/dist-lib/lib/core/files/rag/extract/extract.d.ts +0 -17
  125. package/dist-lib/lib/core/files/rag/extract/extract.js +0 -81
  126. package/dist-lib/lib/core/files/rag/extract/html-table-text.d.ts +0 -1
  127. package/dist-lib/lib/core/files/rag/extract/html-table-text.js +0 -125
  128. package/dist-lib/lib/core/files/rag/extract/html-text.d.ts +0 -1
  129. package/dist-lib/lib/core/files/rag/extract/html-text.js +0 -132
  130. package/dist-lib/lib/core/files/rag/extract/pdf-platform.d.ts +0 -17
  131. package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +0 -141
  132. package/dist-lib/lib/core/files/rag/extract/pdf-text.d.ts +0 -12
  133. package/dist-lib/lib/core/files/rag/extract/pdf-text.js +0 -43
  134. package/dist-lib/lib/core/files/rag/extract/rtf-text.d.ts +0 -1
  135. package/dist-lib/lib/core/files/rag/extract/rtf-text.js +0 -15
  136. package/dist-lib/lib/core/files/rag/extract/text-decoding.d.ts +0 -1
  137. package/dist-lib/lib/core/files/rag/extract/text-decoding.js +0 -91
  138. package/dist-lib/lib/core/files/rag/extract/types.d.ts +0 -36
  139. package/dist-lib/lib/core/files/rag/extract/types.js +0 -12
  140. package/dist-lib/lib/core/files/rag/extract/utf.d.ts +0 -2
  141. package/dist-lib/lib/core/files/rag/extract/utf.js +0 -18
  142. package/dist-lib/lib/core/files/rag/retrieval/citation-match.d.ts +0 -2
  143. package/dist-lib/lib/core/files/rag/retrieval/citation-match.js +0 -16
  144. package/dist-lib/lib/core/files/rag/retrieval/coverage.d.ts +0 -4
  145. package/dist-lib/lib/core/files/rag/retrieval/coverage.js +0 -48
  146. package/dist-lib/lib/core/files/rag/retrieval/diversity.d.ts +0 -10
  147. package/dist-lib/lib/core/files/rag/retrieval/diversity.js +0 -37
  148. package/dist-lib/lib/core/files/rag/retrieval/floor.d.ts +0 -5
  149. package/dist-lib/lib/core/files/rag/retrieval/floor.js +0 -21
  150. package/dist-lib/lib/core/files/rag/retrieval/format.d.ts +0 -6
  151. package/dist-lib/lib/core/files/rag/retrieval/format.js +0 -21
  152. package/dist-lib/lib/core/files/rag/retrieval/knowledge.d.ts +0 -2
  153. package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +0 -54
  154. package/dist-lib/lib/core/files/rag/retrieval/notices.d.ts +0 -16
  155. package/dist-lib/lib/core/files/rag/retrieval/notices.js +0 -27
  156. package/dist-lib/lib/core/files/rag/retrieval/scoring.d.ts +0 -8
  157. package/dist-lib/lib/core/files/rag/retrieval/scoring.js +0 -82
  158. package/dist-lib/lib/core/files/rag/retrieval/search.d.ts +0 -3
  159. package/dist-lib/lib/core/files/rag/retrieval/search.js +0 -49
  160. package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +0 -11
  161. package/dist-lib/lib/core/files/rag/retrieval/selection.js +0 -93
  162. package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.d.ts +0 -6
  163. package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.js +0 -79
  164. package/dist-lib/lib/core/files/rag/retrieval/sources.d.ts +0 -13
  165. package/dist-lib/lib/core/files/rag/retrieval/sources.js +0 -20
  166. package/dist-lib/lib/core/files/rag/retrieval/target.d.ts +0 -13
  167. package/dist-lib/lib/core/files/rag/retrieval/target.js +0 -89
  168. package/dist-lib/lib/core/files/rag/retrieval/terms.d.ts +0 -8
  169. package/dist-lib/lib/core/files/rag/retrieval/terms.js +0 -70
  170. package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +0 -29
  171. package/dist-lib/lib/core/files/rag/retrieval/types.js +0 -1
  172. package/dist-lib/lib/core/files/rag/retrieval/web-sources.d.ts +0 -8
  173. package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +0 -41
  174. package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.d.ts +0 -1
  175. package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.js +0 -96
  176. package/dist-lib/lib/core/files/rag/vector/memory.d.ts +0 -15
  177. package/dist-lib/lib/core/files/rag/vector/memory.js +0 -135
  178. package/dist-lib/lib/core/files/rag/vector/types.d.ts +0 -28
  179. package/dist-lib/lib/core/files/rag/vector/types.js +0 -1
  180. package/dist-lib/lib/integrations/oauth-providers.d.ts +0 -14
  181. package/dist-lib/lib/integrations/oauth-providers.js +0 -116
  182. package/dist-lib/lib/oauth/asana.d.ts +0 -35
  183. package/dist-lib/lib/oauth/asana.js +0 -71
  184. package/dist-lib/lib/oauth/google.d.ts +0 -37
  185. package/dist-lib/lib/oauth/google.js +0 -77
  186. package/dist-lib/lib/oauth/notion.d.ts +0 -34
  187. package/dist-lib/lib/oauth/notion.js +0 -82
  188. package/dist-lib/lib/oauth/spotify.d.ts +0 -32
  189. package/dist-lib/lib/oauth/spotify.js +0 -74
  190. package/dist-lib/lib/oauth/verify.d.ts +0 -8
  191. package/dist-lib/lib/oauth/verify.js +0 -58
@@ -0,0 +1,37 @@
1
+ import { getStruct } from '../../spec/hyperschema/index.js';
2
+ import { ACK_TIMEOUT_MS, HandoffChannel, HOST_SILENT, HOST_UNREACHABLE } from './handoff-channel.js';
3
+ const PROTOCOL = 'qvac/inference-calls-handoff';
4
+ export { ACK_TIMEOUT_MS, HOST_SILENT, HOST_UNREACHABLE };
5
+ const handoff = getStruct('@assistant/inference-calls-handoff');
6
+ const handoffAck = getStruct('@assistant/inference-calls-handoff-ack');
7
+ export class InferenceCallsHandoff {
8
+ _channel;
9
+ constructor(opts) {
10
+ this._channel = new HandoffChannel({
11
+ protocol: PROTOCOL,
12
+ requestEncoding: handoff,
13
+ ackEncoding: handoffAck,
14
+ onrequest: opts.onrequest,
15
+ buildAck: (id, error, result) => ({
16
+ id,
17
+ error,
18
+ calls: result ? [...result.calls] : undefined,
19
+ truncated: result?.truncated
20
+ }),
21
+ readAck: (ack) => ({
22
+ error: ack.error ?? '',
23
+ result: { calls: ack.calls ?? [], truncated: ack.truncated ?? false }
24
+ }),
25
+ ackTimeoutMs: opts.ackTimeoutMs
26
+ });
27
+ }
28
+ addStream(stream) {
29
+ this._channel.addStream(stream);
30
+ }
31
+ send(hostDeviceId, request) {
32
+ return this._channel.send(hostDeviceId, request);
33
+ }
34
+ destroy() {
35
+ this._channel.destroy();
36
+ }
37
+ }
@@ -0,0 +1,14 @@
1
+ import type { Mesh } from './mesh.ts';
2
+ import type { InferenceCallsHandler } from './inference-calls-handoff.ts';
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
+ export interface InferenceCallsReceiverOptions {
7
+ readonly mesh: Mesh;
8
+ readonly deviceId: Uint8Array;
9
+ readonly listLocal: (chatId: string) => {
10
+ calls: ReadonlyArray<AssistantInferenceCallEntry>;
11
+ truncated: boolean;
12
+ };
13
+ }
14
+ export declare function createInferenceCallsReceiver(opts: InferenceCallsReceiverOptions): InferenceCallsHandler;
@@ -0,0 +1,39 @@
1
+ import b4a from 'b4a';
2
+ import { getAgent } from './agent.js';
3
+ import { getChat } from './chat.js';
4
+ import { NO_SUCH_AGENT, NOT_THE_HOST, SENDER_REVOKED } from './skill-secrets.js';
5
+ const DEVICES = '@qvac/devices';
6
+ export const NO_SUCH_CHAT = 'no such chat on the device hosting this agent';
7
+ export const NO_RECORD_STORE = 'the device hosting this agent is not recording prompts right now';
8
+ const MAX_ANSWER_BYTES = 2 * 1024 * 1024;
9
+ export function createInferenceCallsReceiver(opts) {
10
+ return async (request, fromDeviceId) => {
11
+ const sender = await opts.mesh.view.get(DEVICES, { id: fromDeviceId });
12
+ if (!sender || sender.revoked)
13
+ throw new Error(SENDER_REVOKED);
14
+ const chat = await getChat(opts.mesh, request.chatId);
15
+ if (!chat)
16
+ throw new Error(NO_SUCH_CHAT);
17
+ const agent = await getAgent(opts.mesh, chat.agentId);
18
+ if (!agent)
19
+ throw new Error(NO_SUCH_AGENT);
20
+ if (!agent.providerDeviceId || !b4a.equals(agent.providerDeviceId, opts.deviceId)) {
21
+ throw new Error(NOT_THE_HOST);
22
+ }
23
+ const own = opts.listLocal(request.chatId);
24
+ const answer = capped(own.calls);
25
+ return { ...answer, truncated: answer.truncated || own.truncated };
26
+ };
27
+ }
28
+ function capped(calls) {
29
+ const kept = [];
30
+ let bytes = 0;
31
+ for (const entry of [...calls].reverse()) {
32
+ bytes += b4a.byteLength(JSON.stringify(entry.call));
33
+ if (bytes > MAX_ANSWER_BYTES && kept.length > 0) {
34
+ return { calls: kept.reverse(), truncated: true };
35
+ }
36
+ kept.push(entry);
37
+ }
38
+ return { calls: kept.reverse(), truncated: false };
39
+ }
@@ -35,10 +35,11 @@ export async function deriveNotifications(mesh, local, requestedLimit, deviceId)
35
35
  if (isDiagramRepairPrompt(text))
36
36
  continue;
37
37
  const sender = await snap.get('@qvac/devices', { id: chunk.originDeviceId });
38
- if (own?.memberId && sender?.memberId?.equals(own.memberId))
38
+ const senderMemberId = chunk.senderMemberId ?? sender?.memberId;
39
+ if (own?.memberId && senderMemberId?.equals(own.memberId))
39
40
  continue;
40
- const member = sender?.memberId
41
- ? await snap.get('@qvac/members', { id: sender.memberId })
41
+ const member = senderMemberId
42
+ ? await snap.get('@qvac/members', { id: senderMemberId })
42
43
  : null;
43
44
  candidates.push({
44
45
  chatId: chat.id,
@@ -48,7 +49,7 @@ export async function deriveNotifications(mesh, local, requestedLimit, deviceId)
48
49
  seq: chunk.seq,
49
50
  createdAt: chunk.createdAt,
50
51
  senderDeviceId: chunk.originDeviceId,
51
- senderMemberId: sender?.memberId,
52
+ senderMemberId,
52
53
  senderName: member?.name ?? sender?.name,
53
54
  chatTitle: chat.title,
54
55
  preview: Array.from(text).slice(0, PREVIEW_LIMIT).join('') || undefined
@@ -1,7 +1,7 @@
1
1
  import b4a from 'b4a';
2
2
  import { credentialSlots } from '@qvac/harness/lib/tools/skills/credential-slots.ts';
3
3
  import { isDeviceSharedCredentialKey } from '@qvac/harness/lib/tools/skills/scope-key.ts';
4
- import { oauthStateKey, settingConfigKey } from '../credential-pusher.js';
4
+ import { settingConfigKey } from '../credential-pusher.js';
5
5
  import { scopedKey } from '../oauth/common.js';
6
6
  import { getAgent } from './agent.js';
7
7
  const DEVICES = '@qvac/devices';
@@ -65,15 +65,12 @@ function credentialKeys(skill) {
65
65
  for (const route of skill.setup?.routes ?? []) {
66
66
  if (route.credentialKey)
67
67
  keys.add(route.credentialKey);
68
+ if (route.oauth?.stateKey)
69
+ keys.add(route.oauth.stateKey);
68
70
  for (const field of route.fields ?? []) {
69
71
  if (field.secret === true)
70
72
  keys.add(field.key);
71
73
  }
72
74
  }
73
- for (const key of [...keys]) {
74
- const state = oauthStateKey(key);
75
- if (state)
76
- keys.add(state);
77
- }
78
75
  return [...keys];
79
76
  }
@@ -5,6 +5,7 @@ import ReadyGuard from 'ready-guard';
5
5
  import ReadyResource from 'ready-resource';
6
6
  import type { Logger } from '../index.ts';
7
7
  import type { AssistantArchivedMeshList, AssistantCompactChatResponse, AssistantCopySkillResponse, AssistantDeleteModelRequest, AssistantDeleteModelResponse, AssistantDeleteSkillResponse, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantManagedSkillsResponse, AssistantMeshList, AssistantModelCatalogRevision, AssistantModelInfoList, AssistantOkResponse, AssistantSkillCatalogResponse, AssistantSkillFileResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantTranscribeRequest, AssistantTranscribeResponse } from '../spec/index.d.ts';
8
+ import type { InferenceCallSource } from './api/inference-calls.ts';
8
9
  import { type BlindPeeringOpts } from './core/blind-peers.ts';
9
10
  import { type IndexingEmbedder, type RagExtractors, type VectorIndex } from './core/files/index.ts';
10
11
  import { type DriveHost } from './core/fs-drives.ts';
@@ -165,6 +166,7 @@ export declare class Core extends ReadyResource {
165
166
  private readonly _following;
166
167
  private readonly _secretHandoff;
167
168
  private readonly _skillOverlayHandoff;
169
+ private readonly _inferenceCallsHandoff;
168
170
  private _minting;
169
171
  private _leaving;
170
172
  private _kicked;
@@ -172,6 +174,7 @@ export declare class Core extends ReadyResource {
172
174
  private readonly _peers;
173
175
  private readonly _statusListeners;
174
176
  private readonly _diagnosticsProviders;
177
+ private _inferenceCalls;
175
178
  private _systemInfo;
176
179
  private _statusError;
177
180
  private _upgradeRequired;
@@ -186,6 +189,7 @@ export declare class Core extends ReadyResource {
186
189
  _open(): Promise<void>;
187
190
  private _runBootOffline;
188
191
  private _openBootMesh;
192
+ private _openAccountBeside;
189
193
  private _runBootOnline;
190
194
  private _reopenMesh;
191
195
  get otaConfigCore(): {
@@ -351,7 +355,10 @@ export declare class Core extends ReadyResource {
351
355
  private _isJoinedRoomKey;
352
356
  private _isOwnMemberDevice;
353
357
  private _skillOverlayOp;
354
- private _resolveSkillOverlayHost;
358
+ private _resolveAgentHost;
359
+ private _listInferenceCalls;
360
+ private _toInferenceEntry;
361
+ private _serveInferenceCalls;
355
362
  private _serveSkillOverlayOp;
356
363
  private _runLocalSkillOverlayOp;
357
364
  private _setupFields;
@@ -367,6 +374,7 @@ export declare class Core extends ReadyResource {
367
374
  private _logSource;
368
375
  compact(force?: boolean): Promise<void>;
369
376
  registerDiagnostics(provider: () => object): () => void;
377
+ registerInferenceCalls(source: InferenceCallSource): () => void;
370
378
  registerListModels(hook: (options: AssistantListModelsRequest) => Promise<AssistantModelInfoList>): () => void;
371
379
  registerDeleteModel(hook: (options: AssistantDeleteModelRequest) => Promise<AssistantDeleteModelResponse>): () => void;
372
380
  registerClearKvCache(hook: () => Promise<AssistantKvCacheDeletionResponse>): () => void;
@@ -14,7 +14,7 @@ import { createApi } from './api/index.js';
14
14
  import { NO_SUCH_MESH } from './api/current-mesh.js';
15
15
  import { BLIND_PEER_KEYS, BLIND_RELAY_KEYS } from './core/blind-peers.js';
16
16
  import { CoreBlobServer, parseBlobReferenceCoreKey, MemoryVectorIndex } from './core/files/index.js';
17
- import { removeChatAttachments, removeChatKnowledge } from './core/chat.js';
17
+ import { getChat, removeChatAttachments, removeChatKnowledge } from './core/chat.js';
18
18
  import { createFsDriveHost } from './core/fs-drives.js';
19
19
  import { sweepDriveStaging } from './fs-drive-bridge.js';
20
20
  import { closeCollaboraWorker } from './collabora/worker.js';
@@ -27,6 +27,8 @@ import { HarnessLoan } from './core/harness-loan.js';
27
27
  import { duplexPair } from '@qvac/harness/transport';
28
28
  import { MeshSeedHandoff } from './core/mesh-seed-handoff.js';
29
29
  import { SecretHandoff } from './core/secret-handoff.js';
30
+ import { InferenceCallsHandoff } from './core/inference-calls-handoff.js';
31
+ import { createInferenceCallsReceiver, NO_RECORD_STORE } from './core/inference-calls-receiver.js';
30
32
  import { SkillOverlayHandoff } from './core/skill-overlay-handoff.js';
31
33
  import { createSkillOverlayReceiver } from './core/skill-overlay-receiver.js';
32
34
  import { createSkillSecretReceiver, HOST_REVOKED, NO_SUCH_AGENT, NOT_THE_HOST } from './core/skill-secrets.js';
@@ -43,7 +45,6 @@ import { buildDefaultSeed } from './core/helpers/index.js';
43
45
  import { Mesh } from './core/mesh.js';
44
46
  import { raceResource } from './race-resource.js';
45
47
  import { createSystemInfoSampler } from './core/system-info.js';
46
- import { oauthStateKeyFor } from './credential-pusher.js';
47
48
  import { setLogger } from './logger.js';
48
49
  import { settleOnClose } from '@qvac/harness/rpc';
49
50
  import { openLocalSpec } from './spec-loader.js';
@@ -156,6 +157,7 @@ export class Core extends ReadyResource {
156
157
  _following = new Set();
157
158
  _secretHandoff;
158
159
  _skillOverlayHandoff;
160
+ _inferenceCallsHandoff;
159
161
  _minting;
160
162
  _leaving;
161
163
  _kicked;
@@ -163,6 +165,7 @@ export class Core extends ReadyResource {
163
165
  _peers;
164
166
  _statusListeners;
165
167
  _diagnosticsProviders;
168
+ _inferenceCalls = null;
166
169
  _systemInfo;
167
170
  _statusError;
168
171
  _upgradeRequired;
@@ -261,6 +264,9 @@ export class Core extends ReadyResource {
261
264
  onrequest: (request, from) => this._serveMeshSeed(request, from)
262
265
  });
263
266
  this._harnessLoan = new HarnessLoan({ onborrow: (from) => this._lendHarness(from) });
267
+ this._inferenceCallsHandoff = new InferenceCallsHandoff({
268
+ onrequest: (request, from) => this._serveInferenceCalls(request, from)
269
+ });
264
270
  this._minting = false;
265
271
  this._leaving = false;
266
272
  this._kicked = false;
@@ -336,6 +342,10 @@ export class Core extends ReadyResource {
336
342
  meshStatus,
337
343
  network: this._networkStatusSource(),
338
344
  diagnostics: this._diagnosticsSource(),
345
+ inferenceCalls: {
346
+ list: (chatId) => this._listInferenceCalls(chatId),
347
+ forget: async (chatId) => void (await this._inferenceCalls?.forget(chatId))
348
+ },
339
349
  logs: this._logSource(),
340
350
  deviceId: this.devicePublicKey,
341
351
  lifecycle: this._apiLifecycle,
@@ -480,7 +490,12 @@ export class Core extends ReadyResource {
480
490
  if (this._blockedByMinVersion() || this._currentMesh() || this._minting)
481
491
  return;
482
492
  try {
483
- await this._switchToMesh({ seed: this._meshSeed, baseKey: this._meshKey, account: true });
493
+ const mesh = await this._switchToMesh({
494
+ seed: this._meshSeed,
495
+ baseKey: this._meshKey,
496
+ account: true
497
+ });
498
+ void this._openAccountBeside(mesh).catch(noop);
484
499
  }
485
500
  catch (err) {
486
501
  if (this.closing)
@@ -492,6 +507,23 @@ export class Core extends ReadyResource {
492
507
  this._log?.error(['p2p', 'mesh'], 'mesh open failed', err);
493
508
  }
494
509
  }
510
+ async _openAccountBeside(active) {
511
+ const home = await this._homeMeshKey();
512
+ if (!home || home.equals(active.key))
513
+ return;
514
+ await this._meshTransitionLock.lock();
515
+ try {
516
+ if (this.closing || this._blockedByMinVersion())
517
+ return;
518
+ const mesh = await this._openPooledMesh(home.toString('hex')).catch(() => null);
519
+ if (mesh && !mesh.ourMemberId)
520
+ await mesh.refreshOurMember();
521
+ }
522
+ finally {
523
+ this._meshTransitionLock.unlock();
524
+ }
525
+ this._notifyStatus();
526
+ }
495
527
  async _runBootOnline() {
496
528
  void this.onlineBoot.ready().catch(noop);
497
529
  try {
@@ -519,7 +551,12 @@ export class Core extends ReadyResource {
519
551
  try {
520
552
  if (this.closing || this._currentMesh() || this._minting)
521
553
  return;
522
- await this._startMesh({ seed: this._meshSeed, baseKey: this._meshKey, account: true });
554
+ const mesh = await this._startMesh({
555
+ seed: this._meshSeed,
556
+ baseKey: this._meshKey,
557
+ account: true
558
+ });
559
+ void this._openAccountBeside(mesh).catch(noop);
523
560
  }
524
561
  catch (err) {
525
562
  if (this.closing)
@@ -1071,8 +1108,9 @@ export class Core extends ReadyResource {
1071
1108
  const attestation = claimAttestation(mesh.publicKey, deviceId, mesh.localWriterKey);
1072
1109
  const known = await this._knownMember(mesh);
1073
1110
  if (known) {
1111
+ const displayName = (await this.local.readIdentity())?.displayName;
1074
1112
  return {
1075
- member: { id: known.id, name: known.name, joinedAt: now, updatedAt: now },
1113
+ member: { id: known.id, name: displayName ?? known.name, joinedAt: now, updatedAt: now },
1076
1114
  proof: await attestMemberClaim(attestation, this._deviceKeyPair, known.proof)
1077
1115
  };
1078
1116
  }
@@ -1964,6 +2002,9 @@ export class Core extends ReadyResource {
1964
2002
  .catch((error) => this._log?.warn(['p2p', 'mesh'], 'chat-tombstone notification reclaim failed', error));
1965
2003
  void removeChatAttachments(mesh, deviceId, chatId, deletedAt).catch((error) => this._log?.warn(['p2p', 'mesh'], 'chat-tombstone attachment reclaim failed', error));
1966
2004
  void removeChatKnowledge(mesh, chatId, deletedAt).catch((error) => this._log?.warn(['p2p', 'mesh'], 'chat-tombstone knowledge reclaim failed', error));
2005
+ void this._inferenceCalls
2006
+ ?.forget(chatId)
2007
+ .catch((error) => this._log?.warn(['p2p', 'mesh'], 'chat-tombstone inspector reclaim failed', error));
1967
2008
  });
1968
2009
  const sweepLock = new ScopeLock({ debounce: true });
1969
2010
  const sweep = async () => {
@@ -2355,7 +2396,7 @@ export class Core extends ReadyResource {
2355
2396
  try {
2356
2397
  if (meshId === this._activeMeshKey)
2357
2398
  throw new Error('The active mesh cannot be closed');
2358
- const mesh = this._currentMesh(meshId);
2399
+ const mesh = this._currentMesh(meshId) ?? (await this._opening.get(meshId)?.catch(noop));
2359
2400
  if (!mesh)
2360
2401
  return;
2361
2402
  await this._retirePooledMesh(mesh);
@@ -2569,6 +2610,7 @@ export class Core extends ReadyResource {
2569
2610
  this._harnessLoan.destroy();
2570
2611
  this._secretHandoff.destroy();
2571
2612
  this._skillOverlayHandoff.destroy();
2613
+ this._inferenceCallsHandoff.destroy();
2572
2614
  if (!this._swarm)
2573
2615
  return;
2574
2616
  const swarm = this._swarm;
@@ -2796,12 +2838,12 @@ export class Core extends ReadyResource {
2796
2838
  return ourDevice;
2797
2839
  }
2798
2840
  async _skillOverlayOp(agentId, op) {
2799
- const host = await this._resolveSkillOverlayHost(agentId);
2841
+ const host = await this._resolveAgentHost(agentId);
2800
2842
  if (!host)
2801
2843
  return this._runLocalSkillOverlayOp(op);
2802
2844
  return this._skillOverlayHandoff.send(host, { ...op, agentId });
2803
2845
  }
2804
- async _resolveSkillOverlayHost(agentId) {
2846
+ async _resolveAgentHost(agentId) {
2805
2847
  if (!agentId)
2806
2848
  return null;
2807
2849
  if (!this.opened)
@@ -2822,6 +2864,56 @@ export class Core extends ReadyResource {
2822
2864
  throw new Error(HOST_REVOKED);
2823
2865
  return agent.providerDeviceId;
2824
2866
  }
2867
+ async _listInferenceCalls(chatId) {
2868
+ const mesh = await this._awaitMesh();
2869
+ const store = this._inferenceCalls;
2870
+ const own = store?.list(chatId) ?? { calls: [], truncated: false };
2871
+ const local = own.calls;
2872
+ const chat = mesh ? await getChat(mesh, chatId) : null;
2873
+ if (!chat)
2874
+ return own;
2875
+ const host = await this._resolveAgentHost(chat.agentId).catch((err) => {
2876
+ if (local.length === 0)
2877
+ throw err;
2878
+ this._log?.warn(['api'], 'inspector host unresolved, showing this device only', {
2879
+ chatId,
2880
+ err
2881
+ });
2882
+ return null;
2883
+ });
2884
+ if (!host) {
2885
+ if (!store)
2886
+ throw new Error(NO_RECORD_STORE);
2887
+ return own;
2888
+ }
2889
+ const answer = await this._inferenceCallsHandoff.send(host, { chatId });
2890
+ const calls = [
2891
+ ...local,
2892
+ ...answer.calls.flatMap((entry) => this._toInferenceEntry(entry))
2893
+ ].sort((a, b) => a.at - b.at);
2894
+ return { calls, truncated: own.truncated || answer.truncated };
2895
+ }
2896
+ _toInferenceEntry(entry) {
2897
+ const call = entry.call;
2898
+ if (typeof call !== 'object' || call === null)
2899
+ return [];
2900
+ return [{ runId: entry.runId, at: entry.at, call: call }];
2901
+ }
2902
+ async _serveInferenceCalls(request, fromDeviceId) {
2903
+ const mesh = this._currentMesh();
2904
+ const deviceId = this.devicePublicKey;
2905
+ if (!mesh || !deviceId)
2906
+ throw new Error(NOT_THE_HOST);
2907
+ const store = this._inferenceCalls;
2908
+ if (!store)
2909
+ throw new Error(NO_RECORD_STORE);
2910
+ const receive = createInferenceCallsReceiver({
2911
+ mesh,
2912
+ deviceId,
2913
+ listLocal: (chatId) => store.list(chatId)
2914
+ });
2915
+ return receive(request, fromDeviceId);
2916
+ }
2825
2917
  async _serveSkillOverlayOp(op, fromDeviceId) {
2826
2918
  const mesh = this._currentMesh();
2827
2919
  const deviceId = this.devicePublicKey;
@@ -2868,16 +2960,16 @@ export class Core extends ReadyResource {
2868
2960
  return new Map();
2869
2961
  const fields = new Map();
2870
2962
  for (const slot of skill.credentials ?? []) {
2871
- for (const key of slot.split('|')) {
2963
+ for (const key of slot.split('|'))
2872
2964
  fields.set(key, true);
2873
- const stateKey = oauthStateKeyFor(key);
2874
- if (stateKey)
2875
- fields.set(stateKey, true);
2876
- }
2877
2965
  }
2966
+ const foreign = credentialKeysOwnedElsewhere(skills, skillName);
2878
2967
  for (const route of skill.setup?.routes ?? []) {
2879
2968
  if (route.credentialKey)
2880
2969
  fields.set(route.credentialKey, true);
2970
+ const stateKey = route.oauth?.stateKey;
2971
+ if (stateKey && !foreign.has(stateKey))
2972
+ fields.set(stateKey, true);
2881
2973
  for (const field of route.fields ?? [])
2882
2974
  fields.set(field.key, field.secret === true);
2883
2975
  }
@@ -2913,6 +3005,7 @@ export class Core extends ReadyResource {
2913
3005
  this._skillOverlayHandoff.addStream(conn);
2914
3006
  this._meshSeedHandoff.addStream(conn);
2915
3007
  this._harnessLoan.addStream(conn);
3008
+ this._inferenceCallsHandoff.addStream(conn);
2916
3009
  for (const entry of this._meshes.values()) {
2917
3010
  entry.hostedAgents?.kick();
2918
3011
  if (entry.mesh.ourMemberId)
@@ -3054,6 +3147,13 @@ export class Core extends ReadyResource {
3054
3147
  this._diagnosticsProviders.add(provider);
3055
3148
  return () => void this._diagnosticsProviders.delete(provider);
3056
3149
  }
3150
+ registerInferenceCalls(source) {
3151
+ this._inferenceCalls = source;
3152
+ return () => {
3153
+ if (this._inferenceCalls === source)
3154
+ this._inferenceCalls = null;
3155
+ };
3156
+ }
3057
3157
  registerListModels(hook) {
3058
3158
  this._listModels = hook;
3059
3159
  return () => {
@@ -3411,3 +3511,19 @@ function statusErrorMessage(context, err) {
3411
3511
  const detail = err instanceof Error ? err.message : err ? String(err) : '';
3412
3512
  return detail ? `${context}: ${detail}` : context;
3413
3513
  }
3514
+ function credentialKeysOwnedElsewhere(skills, skillName) {
3515
+ const keys = new Set();
3516
+ for (const entry of skills) {
3517
+ if (entry.name === skillName)
3518
+ continue;
3519
+ for (const slot of entry.credentials ?? []) {
3520
+ for (const key of slot.split('|'))
3521
+ keys.add(key);
3522
+ }
3523
+ for (const route of entry.setup?.routes ?? []) {
3524
+ if (route.credentialKey)
3525
+ keys.add(route.credentialKey);
3526
+ }
3527
+ }
3528
+ return keys;
3529
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Harness } from './assistant.ts';
2
2
  import { type ConfigEngine } from './oauth.ts';
3
+ import type { OAuthRouteLike } from './oauth/keys.ts';
3
4
  export type CredentialEntry = {
4
5
  key: string;
5
6
  token?: string | null;
@@ -20,7 +21,7 @@ export type PusherSkill = {
20
21
  credentials?: readonly string[];
21
22
  };
22
23
  setup?: {
23
- routes?: ReadonlyArray<{
24
+ routes?: ReadonlyArray<OAuthRouteLike & {
24
25
  fields?: ReadonlyArray<{
25
26
  key: string;
26
27
  secret?: boolean;
@@ -53,7 +54,6 @@ export type CredentialPusherLogger = {
53
54
  export type CredentialPusherHandle = (() => Promise<void>) & {
54
55
  sync(): Promise<void>;
55
56
  };
56
- export declare function oauthStateKeyFor(credentialKey: string): string | null;
57
57
  export declare function nextRefreshDelay(entries: ReadonlyArray<{
58
58
  expiresAt?: number | null;
59
59
  }>, now?: number): number;
@@ -63,5 +63,4 @@ export declare function settingFields(catalog: ReadonlyArray<PusherSkill>): Read
63
63
  key: string;
64
64
  }>;
65
65
  export declare function settingConfigKey(agentId: string | undefined, skill: string, key: string): string;
66
- export declare function oauthStateKey(credentialKey: string): string | undefined;
67
66
  export declare function startCredentialPusher(harness: CredentialTarget, engine: CredentialEngine, logger?: CredentialPusherLogger | null): CredentialPusherHandle;