@qvac/core 0.6.4 → 1.0.0-rc.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.
Files changed (51) hide show
  1. package/dist-lib/lib/api/host-run-log.d.ts +43 -0
  2. package/dist-lib/lib/api/host-run-log.js +97 -0
  3. package/dist-lib/lib/api/index.d.ts +3 -0
  4. package/dist-lib/lib/api/index.js +9 -0
  5. package/dist-lib/lib/api/instrument.js +33 -2
  6. package/dist-lib/lib/assistant/harness.d.ts +4 -1
  7. package/dist-lib/lib/assistant/history.d.ts +7 -2
  8. package/dist-lib/lib/assistant/history.js +34 -3
  9. package/dist-lib/lib/assistant/host-run-log.d.ts +3 -0
  10. package/dist-lib/lib/assistant/host-run-log.js +48 -0
  11. package/dist-lib/lib/assistant.d.ts +2 -0
  12. package/dist-lib/lib/assistant.js +817 -412
  13. package/dist-lib/lib/core/async-iterable.js +1 -1
  14. package/dist-lib/lib/core/chat-activity.d.ts +1 -1
  15. package/dist-lib/lib/core/chat-activity.js +16 -1
  16. package/dist-lib/lib/core/chat-search.js +11 -4
  17. package/dist-lib/lib/core/chunk.d.ts +3 -3
  18. package/dist-lib/lib/core/chunk.js +6 -2
  19. package/dist-lib/lib/core/harness-loan.js +4 -0
  20. package/dist-lib/lib/core/host-run-log-store.d.ts +114 -0
  21. package/dist-lib/lib/core/host-run-log-store.js +976 -0
  22. package/dist-lib/lib/core/prompt-history.js +3 -1
  23. package/dist-lib/lib/core/transcript-visibility.d.ts +19 -0
  24. package/dist-lib/lib/core/transcript-visibility.js +47 -0
  25. package/dist-lib/lib/core.d.ts +2 -0
  26. package/dist-lib/lib/core.js +36 -0
  27. package/dist-lib/lib/custom-model-pusher.js +9 -5
  28. package/dist-lib/lib/mesh-scoped-engine.js +5 -0
  29. package/dist-lib/lib/run-transcript.d.ts +10 -3
  30. package/dist-lib/lib/run-transcript.js +23 -5
  31. package/dist-lib/lib/task.js +6 -1
  32. package/dist-lib/schema/content.d.ts +1 -0
  33. package/dist-lib/schema/content.js +15 -3
  34. package/dist-lib/schema/engine.js +90 -3
  35. package/dist-lib/schema/indexes.js +10 -1
  36. package/dist-lib/schema/qvac.js +10 -2
  37. package/dist-lib/spec/bind.js +15 -0
  38. package/dist-lib/spec/calls.js +5 -0
  39. package/dist-lib/spec/capabilities.d.ts +10 -0
  40. package/dist-lib/spec/hrpc/hrpc.json +164 -99
  41. package/dist-lib/spec/hrpc/index.js +260 -200
  42. package/dist-lib/spec/hrpc/messages.js +1202 -898
  43. package/dist-lib/spec/hyperschema/index.js +1202 -898
  44. package/dist-lib/spec/hyperschema/schema.json +265 -0
  45. package/dist-lib/spec/hyperschema/types.d.ts +65 -3
  46. package/dist-lib/spec/mesh/hyperdb/messages.js +385 -241
  47. package/dist-lib/spec/mesh/hyperdispatch/messages.js +138 -12
  48. package/dist-lib/spec/mesh/hyperschema/index.js +138 -12
  49. package/dist-lib/spec/mesh/hyperschema/schema.json +79 -1
  50. package/dist-lib/spec/mesh/hyperschema/types.d.ts +19 -3
  51. package/package.json +3 -2
@@ -39,7 +39,7 @@ export function toAsyncIterable(streamOrIterable) {
39
39
  [Symbol.asyncIterator]() {
40
40
  return iterator;
41
41
  },
42
- async return() {
42
+ async ['return']() {
43
43
  onEnd();
44
44
  queue.length = 0;
45
45
  stream.off?.('data', onData);
@@ -1,5 +1,5 @@
1
1
  import type { Mesh } from './mesh.ts';
2
- export type ChatActivityState = 'queued' | 'running' | 'generating-image' | 'generating-audio' | 'transcribing-audio' | 'awaiting-approval';
2
+ export type ChatActivityState = 'queued' | 'running' | 'generating-image' | 'generating-audio' | 'transcribing-audio' | 'awaiting-approval' | 'paused' | 'recovery-required';
3
3
  export interface ChatActivityRow {
4
4
  readonly id: string;
5
5
  readonly activityState: ChatActivityState;
@@ -139,7 +139,14 @@ function activityState(runs) {
139
139
  if (started.length === 0) {
140
140
  return 'queued';
141
141
  }
142
- return mediaState(latestRun(started)) ?? 'running';
142
+ const active = latestRun(started);
143
+ if (active.status === 'recovery-required') {
144
+ return 'recovery-required';
145
+ }
146
+ if (active.status === 'paused') {
147
+ return 'paused';
148
+ }
149
+ return mediaState(active) ?? 'running';
143
150
  }
144
151
  function mediaState(run) {
145
152
  if (run.progress === 'generating') {
@@ -183,9 +190,16 @@ function applyChunk(activity, chunk) {
183
190
  }
184
191
  else if (state === 'executing' && chunk.seq > run.attemptSeq) {
185
192
  run.attemptSeq = chunk.seq;
193
+ run.status = 'running';
186
194
  run.progress = status?.progress?.phase ?? null;
187
195
  run.tools.length = 0;
188
196
  }
197
+ else if (state === 'paused' || state === 'recovery-required') {
198
+ run.status = state;
199
+ run.attemptSeq = Math.max(run.attemptSeq, chunk.seq);
200
+ run.progress = null;
201
+ run.tools.length = 0;
202
+ }
189
203
  return;
190
204
  }
191
205
  if (chunk.type === 'approval-request') {
@@ -210,6 +224,7 @@ function createRun(request) {
210
224
  requestSeq: request.seq,
211
225
  attemptSeq: request.seq,
212
226
  started: false,
227
+ status: 'queued',
213
228
  progress: null,
214
229
  tools: [],
215
230
  pendingApprovals: new Set(),
@@ -1,5 +1,6 @@
1
1
  import { diagramRepairAccepted, diagramRepairLinks, isDiagramRepairPrompt } from '@qvac/harness/lib/diagram-repair.ts';
2
2
  import { chunkTypeOrdinal } from '../../schema/indexes.js';
3
+ import { visibleTranscriptTextChunks } from './transcript-visibility.js';
3
4
  import { enrichAll, lastActivity, liveGroupIds } from './chat.js';
4
5
  import { foldSearchText } from './search-fold.js';
5
6
  import { ACTIVE_CHATS, CHUNKS_BY_TYPE } from './collections.js';
@@ -57,18 +58,20 @@ function titleHit(chat) {
57
58
  async function contentHits(snap, chat, { needle, cap }) {
58
59
  if (cap <= 0)
59
60
  return [];
60
- const [users, content, attachments, requests, statuses] = await Promise.all([
61
+ const [users, content, attachments, requests, statuses, resets] = await Promise.all([
61
62
  chunksOfType(snap, chat.id, 'user-message'),
62
63
  chunksOfType(snap, chat.id, 'content'),
63
64
  chunksOfType(snap, chat.id, 'attachment'),
64
65
  chunksOfType(snap, chat.id, 'run-request'),
65
- chunksOfType(snap, chat.id, 'run-status')
66
+ chunksOfType(snap, chat.id, 'run-status'),
67
+ chunksOfType(snap, chat.id, 'round-reset')
66
68
  ]);
69
+ const visibleContent = visibleTranscriptTextChunks([...content, ...statuses, ...resets]).filter((chunk) => chunk.type === 'content');
67
70
  const repairs = diagramRepairLinks([...users, ...requests], (chunk) => {
68
71
  return chunk.userMessage?.text ?? null;
69
72
  });
70
73
  const hiddenPromptIds = new Set(users.filter((user) => isDiagramRepairPrompt(user.userMessage?.text ?? '')).map((u) => u.id));
71
- const repairText = (target) => content
74
+ const repairText = (target) => visibleContent
72
75
  .filter((chunk) => chunk.runId === target)
73
76
  .map((chunk) => chunk.content?.text ?? '')
74
77
  .join('');
@@ -93,7 +96,11 @@ async function contentHits(snap, chat, { needle, cap }) {
93
96
  }
94
97
  const matches = [
95
98
  ...matchUserMessages(users, needle, { cap, hiddenIds: hiddenPromptIds }),
96
- ...matchJoinedContent(content, needle, { cap, hidden: hiddenRunIds, redacted: redactedRunIds }),
99
+ ...matchJoinedContent(visibleContent, needle, {
100
+ cap,
101
+ hidden: hiddenRunIds,
102
+ redacted: redactedRunIds
103
+ }),
97
104
  ...matchAttachments(attachments, needle, cap)
98
105
  ];
99
106
  return matches
@@ -2,8 +2,8 @@ import type HyperDB from 'hyperdb';
2
2
  import type { QvacChunk, QvacUpdateChunkOperation } from '../../spec/mesh/hyperschema/types.d.ts';
3
3
  import type { Mesh, MeshDispatcher } from './mesh.ts';
4
4
  import { type Bounds } from './range.ts';
5
- type ChunkPayload = Pick<QvacChunk, 'userMessage' | 'content' | 'thinking' | 'toolCall' | 'toolResult' | 'attachment' | 'approvalRequest' | 'runStatus' | 'runRequest' | 'sources' | 'compaction'>;
6
- type AppendChunkInput = Pick<QvacChunk, 'chatId' | 'runId' | 'type' | 'originDeviceId' | 'parentId' | 'effect' | 'intent' | 'display' | 'rawCall' | 'capability' | 'capabilityArgs' | 'enhance'> & ChunkPayload & {
5
+ type ChunkPayload = Pick<QvacChunk, 'userMessage' | 'content' | 'thinking' | 'toolCall' | 'toolResult' | 'attachment' | 'approvalRequest' | 'runStatus' | 'runRequest' | 'sources' | 'compaction' | 'roundReset'>;
6
+ type AppendChunkInput = Pick<QvacChunk, 'chatId' | 'runId' | 'type' | 'originDeviceId' | 'parentId' | 'effect' | 'intent' | 'display' | 'rawCall' | 'capability' | 'capabilityArgs' | 'enhance' | 'round' | 'callId' | 'resumed'> & ChunkPayload & {
7
7
  id?: string;
8
8
  };
9
9
  type UpdateChunkInput = Pick<QvacChunk, 'id' | 'runStatus' | 'attachment'>;
@@ -36,7 +36,7 @@ export declare function getChunk(store: Mesh, id: string): Promise<QvacChunk | n
36
36
  export interface AppendedChunk {
37
37
  readonly id: string;
38
38
  }
39
- export declare function appendChunk(store: Mesh, { id, chatId, runId, type, originDeviceId, parentId, effect, intent, display, rawCall, capability, capabilityArgs, enhance, ...payload }: AppendChunkInput, into?: MeshDispatcher): Promise<AppendedChunk>;
39
+ export declare function appendChunk(store: Mesh, { id, chatId, runId, type, originDeviceId, parentId, effect, intent, display, rawCall, capability, capabilityArgs, enhance, round, callId, resumed, ...payload }: AppendChunkInput, into?: MeshDispatcher): Promise<AppendedChunk>;
40
40
  export declare function updateChunk(store: Mesh, { id, runStatus, attachment }: UpdateChunkInput): Promise<QvacChunk>;
41
41
  export declare function updateOp(chunk: QvacChunk, { id, runStatus, attachment }: UpdateChunkInput): QvacUpdateChunkOperation;
42
42
  export interface ResolveApprovalInput {
@@ -12,7 +12,8 @@ export const HISTORY_CHUNK_TYPES = [
12
12
  'run-request',
13
13
  'content',
14
14
  'attachment',
15
- 'compaction'
15
+ 'compaction',
16
+ 'round-reset'
16
17
  ];
17
18
  function linkChunks(store, chunks) {
18
19
  const mint = store.attachmentUrl;
@@ -117,7 +118,7 @@ function assertPayloadMatchesType(type, payload) {
117
118
  throw new Error(`chunk payload invalid: ${type} carries ${field} and nothing else`);
118
119
  }
119
120
  }
120
- export async function appendChunk(store, { id = randomId(), chatId, runId, type, originDeviceId, parentId, effect, intent, display, rawCall, capability, capabilityArgs, enhance, ...payload }, into = store) {
121
+ export async function appendChunk(store, { id = randomId(), chatId, runId, type, originDeviceId, parentId, effect, intent, display, rawCall, capability, capabilityArgs, enhance, round, callId, resumed, ...payload }, into = store) {
121
122
  assertPayloadMatchesType(type, payload);
122
123
  if (type === 'sources' && !runId) {
123
124
  throw new Error('chunk payload invalid: a sources chunk requires runId');
@@ -151,6 +152,9 @@ export async function appendChunk(store, { id = randomId(), chatId, runId, type,
151
152
  capability,
152
153
  capabilityArgs,
153
154
  enhance,
155
+ round,
156
+ callId,
157
+ resumed,
154
158
  createdAt: Date.now(),
155
159
  senderMemberId: type === 'user-message' && store.ourDeviceId && b4a.equals(store.ourDeviceId, originDeviceId)
156
160
  ? store.ourMemberId || undefined
@@ -12,6 +12,10 @@ export function loanFailureNotice(error) {
12
12
  if (message.includes(LOAN_UNREACHABLE)) {
13
13
  return LOAN_UNREACHABLE;
14
14
  }
15
+ if (message.includes('does not support a host-owned run log') ||
16
+ message.includes('rpc stream destroyed')) {
17
+ return LOAN_REFUSED;
18
+ }
15
19
  if (message.includes('CHANNEL_CLOSED')) {
16
20
  return LOAN_REFUSED;
17
21
  }
@@ -0,0 +1,114 @@
1
+ import Corestore from 'corestore';
2
+ import { type EngineBoot, type EngineStep, type RunRecord } from '@qvac/harness/run-log';
3
+ export interface HostRunLogLease {
4
+ generation: string;
5
+ boot?: EngineBoot;
6
+ digestKey: Uint8Array;
7
+ }
8
+ export interface HostRunLogScope {
9
+ meshId: string;
10
+ runId: string;
11
+ }
12
+ export interface HostRunLogExport {
13
+ meshId: string;
14
+ runId: string;
15
+ publicKey: Uint8Array;
16
+ discoveryKey: Uint8Array;
17
+ encryptionKey: Uint8Array;
18
+ physicalLength: number;
19
+ logicalLength: number;
20
+ nextSeq: number;
21
+ }
22
+ export interface HostRunLogIndexExport {
23
+ publicKey: Uint8Array;
24
+ discoveryKey: Uint8Array;
25
+ physicalLength: number;
26
+ }
27
+ export interface HostRunLogReleaseArgs extends HostRunLogScope {
28
+ generation: string;
29
+ }
30
+ export interface HostRunLogAppendArgs extends HostRunLogReleaseArgs {
31
+ step: EngineStep;
32
+ }
33
+ export interface HostRunLogListOptions {
34
+ meshId?: string;
35
+ includeExpired?: boolean;
36
+ }
37
+ export interface RunLogSnapshotDescriptor extends Pick<HostRunLogExport, 'meshId' | 'runId' | 'publicKey' | 'encryptionKey' | 'physicalLength'> {
38
+ timeoutMs?: number;
39
+ }
40
+ export interface HostRunLogStoreOptions {
41
+ retentionMs?: number;
42
+ now?: () => number;
43
+ }
44
+ export interface HostRunLogSummary extends HostRunLogScope {
45
+ publicKey: string;
46
+ discoveryKey: string;
47
+ createdAt: number;
48
+ updatedAt: number;
49
+ logicalLength: number;
50
+ nextSeq: number;
51
+ active: boolean;
52
+ expired?: true;
53
+ }
54
+ export interface RunLogSnapshot {
55
+ readonly meshId: string;
56
+ readonly runId: string;
57
+ readonly physicalLength: number;
58
+ readonly logicalLength: number;
59
+ readonly nextSeq: number;
60
+ readonly boot: EngineBoot;
61
+ records(): AsyncIterable<RunLogSnapshotRecord>;
62
+ close(): Promise<void>;
63
+ }
64
+ export interface RunLogSnapshotRecord {
65
+ recordIndex: number;
66
+ stepSeq: number;
67
+ physicalLength: number;
68
+ record: RunRecord;
69
+ }
70
+ export declare class HostRunLogStore {
71
+ private readonly _ownerRoot;
72
+ private readonly _ownerNamespace;
73
+ private readonly _cores;
74
+ private readonly _retentionMs;
75
+ private readonly _now;
76
+ private readonly _locks;
77
+ private readonly _indexLock;
78
+ private readonly _sessions;
79
+ private _indexBee;
80
+ private _ready;
81
+ private _closePromise;
82
+ private _closed;
83
+ opened: boolean;
84
+ constructor(store: Corestore, options?: HostRunLogStoreOptions);
85
+ ready(): Promise<void>;
86
+ private _open;
87
+ private _fenceLease;
88
+ begin({ meshId, runId }: HostRunLogScope): Promise<HostRunLogLease>;
89
+ append(args: HostRunLogAppendArgs): Promise<void>;
90
+ release({ meshId, runId, generation }: HostRunLogReleaseArgs): Promise<void>;
91
+ exportRun({ meshId, runId }: HostRunLogScope): Promise<HostRunLogExport>;
92
+ exportIndex(): Promise<HostRunLogIndexExport>;
93
+ list({ meshId, includeExpired }?: HostRunLogListOptions): Promise<HostRunLogSummary[]>;
94
+ expired({ meshId, runId }: HostRunLogScope): Promise<boolean>;
95
+ close(): Promise<void>;
96
+ private _close;
97
+ private _expireOldRuns;
98
+ private _expireRun;
99
+ private _session;
100
+ private _openRun;
101
+ private _writeCursor;
102
+ private _index;
103
+ private _getIndex;
104
+ private _putIndex;
105
+ private _entries;
106
+ private _keys;
107
+ private _keysById;
108
+ private _summaryEntry;
109
+ private _lock;
110
+ private _assertOpen;
111
+ private _assertLease;
112
+ private _closeRun;
113
+ }
114
+ export declare function openRunLogSnapshot(store: Corestore, descriptor: RunLogSnapshotDescriptor): Promise<RunLogSnapshot>;