@qvac/core 0.10.3 → 0.11.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 +71 -1
- package/dist-lib/lib/assistant/history.d.ts +2 -1
- package/dist-lib/lib/assistant/history.js +32 -5
- package/dist-lib/lib/assistant/message.d.ts +20 -0
- package/dist-lib/lib/assistant/message.js +36 -0
- package/dist-lib/lib/assistant/pdf-budget.d.ts +3 -0
- package/dist-lib/lib/assistant/pdf-budget.js +13 -0
- package/dist-lib/lib/assistant/video-budget.d.ts +13 -0
- package/dist-lib/lib/assistant/video-budget.js +29 -0
- package/dist-lib/lib/assistant-tree.d.ts +1 -0
- package/dist-lib/lib/assistant-tree.js +9 -2
- package/dist-lib/lib/assistant.d.ts +26 -3
- package/dist-lib/lib/assistant.js +471 -47
- package/dist-lib/lib/core/chat-fork.js +1 -0
- package/dist-lib/lib/core/chat-search.js +1 -1
- package/dist-lib/lib/core/chunk.d.ts +2 -2
- package/dist-lib/lib/core/chunk.js +5 -1
- package/dist-lib/lib/core/departures.js +6 -0
- package/dist-lib/lib/core/document-attachment.d.ts +7 -0
- package/dist-lib/lib/core/document-attachment.js +9 -0
- package/dist-lib/lib/core/files/index.js +4 -4
- package/dist-lib/lib/core/files/records/chunks.js +21 -0
- package/dist-lib/lib/core/files/records/purge.js +4 -3
- package/dist-lib/lib/core/files/records/source.js +3 -5
- package/dist-lib/lib/core/files/upload.js +3 -2
- package/dist-lib/lib/core/identity.d.ts +2 -0
- package/dist-lib/lib/core/identity.js +19 -0
- package/dist-lib/lib/core/pdf/rasterize.d.ts +0 -1
- package/dist-lib/lib/core/pdf/rasterize.js +0 -1
- package/dist-lib/lib/core/video/attachment.d.ts +1 -0
- package/dist-lib/lib/core/video/attachment.js +7 -0
- package/dist-lib/lib/core/video/digest.d.ts +16 -0
- package/dist-lib/lib/core/video/digest.js +57 -0
- package/dist-lib/lib/core/video/frames.d.ts +32 -0
- package/dist-lib/lib/core/video/frames.js +224 -0
- package/dist-lib/lib/core.d.ts +1 -0
- package/dist-lib/lib/core.js +44 -7
- package/dist-lib/lib/credential-pusher.d.ts +6 -0
- package/dist-lib/lib/credential-pusher.js +76 -59
- package/dist-lib/lib/errors.d.ts +8 -0
- package/dist-lib/lib/errors.js +8 -0
- package/dist-lib/lib/oauth/flow-core.js +2 -0
- package/dist-lib/lib/oauth/loopback.d.ts +1 -0
- package/dist-lib/lib/oauth/loopback.js +31 -1
- package/dist-lib/lib/oauth/register.js +33 -18
- package/dist-lib/lib/oauth/request.d.ts +10 -0
- package/dist-lib/lib/oauth/request.js +22 -0
- package/dist-lib/lib/oauth/token-exchange-core.js +29 -32
- package/dist-lib/lib/oauth/types.d.ts +3 -0
- package/dist-lib/lib/oauth.d.ts +2 -1
- package/dist-lib/lib/oauth.js +1 -0
- package/dist-lib/lib/run-notices.d.ts +1 -0
- package/dist-lib/lib/run-notices.js +2 -1
- package/dist-lib/lib/run-replay.d.ts +8 -2
- package/dist-lib/lib/run-replay.js +29 -11
- package/dist-lib/lib/task.js +1 -1
- package/dist-lib/schema/engine.js +4 -2
- package/dist-lib/schema/indexes.js +2 -2
- package/dist-lib/schema/qvac.js +4 -2
- package/dist-lib/spec/hrpc/messages.js +16 -6
- package/dist-lib/spec/hyperschema/index.js +16 -6
- package/dist-lib/spec/hyperschema/schema.json +10 -0
- package/dist-lib/spec/hyperschema/types.d.ts +2 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +26 -11
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +18 -8
- package/dist-lib/spec/mesh/hyperschema/index.js +18 -8
- package/dist-lib/spec/mesh/hyperschema/schema.json +11 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +3 -1
- package/package.json +7 -4
- package/tui/app.mjs +34 -1
- package/tui/lib/render.mjs +5 -0
- package/tui/main.mjs +8 -0
|
@@ -166,6 +166,7 @@ async function forkedChunk(ctx, chunk) {
|
|
|
166
166
|
chatId: ctx.chatId,
|
|
167
167
|
runId: chunk.runId && forkedId(ctx, chunk.runId),
|
|
168
168
|
parentId: chunk.parentId && ctx.kept.has(chunk.parentId) ? forkedId(ctx, chunk.parentId) : null,
|
|
169
|
+
sourceId: chunk.sourceId && forkedId(ctx, chunk.sourceId),
|
|
169
170
|
compaction: chunk.compaction && {
|
|
170
171
|
...chunk.compaction,
|
|
171
172
|
throughId: forkedId(ctx, chunk.compaction.throughId)
|
|
@@ -177,7 +177,7 @@ function matchAttachments(chunks, needle, cap) {
|
|
|
177
177
|
if (matches.length >= cap)
|
|
178
178
|
break;
|
|
179
179
|
const attachment = chunk.attachment;
|
|
180
|
-
if (!attachment || (attachment.deletedAt ?? 0) > 0) {
|
|
180
|
+
if (!attachment || (attachment.deletedAt ?? 0) > 0 || chunk.sourceId) {
|
|
181
181
|
continue;
|
|
182
182
|
}
|
|
183
183
|
const found = locate(attachment.fileName, needle);
|
|
@@ -3,7 +3,7 @@ import type { QvacChunk, QvacUpdateChunkOperation } from '../../spec/mesh/hypers
|
|
|
3
3
|
import type { Mesh, MeshDispatcher } from './mesh.ts';
|
|
4
4
|
import { type Bounds } from './range.ts';
|
|
5
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 & {
|
|
6
|
+
type AppendChunkInput = Pick<QvacChunk, 'chatId' | 'runId' | 'type' | 'originDeviceId' | 'parentId' | 'effect' | 'intent' | 'display' | 'rawCall' | 'capability' | 'capabilityArgs' | 'enhance' | 'sourceId'> & ChunkPayload & {
|
|
7
7
|
id?: string;
|
|
8
8
|
};
|
|
9
9
|
type UpdateChunkInput = Pick<QvacChunk, 'id' | 'runStatus' | 'attachment'>;
|
|
@@ -40,7 +40,7 @@ export declare function getChunk(store: Mesh, id: string): Promise<QvacChunk | n
|
|
|
40
40
|
export interface AppendedChunk {
|
|
41
41
|
readonly id: string;
|
|
42
42
|
}
|
|
43
|
-
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>;
|
|
43
|
+
export declare function appendChunk(store: Mesh, { id, chatId, runId, type, originDeviceId, parentId, effect, intent, display, rawCall, capability, capabilityArgs, enhance, sourceId, ...payload }: AppendChunkInput, into?: MeshDispatcher): Promise<AppendedChunk>;
|
|
44
44
|
export declare function updateChunk(store: Mesh, { id, runStatus, attachment }: UpdateChunkInput): Promise<QvacChunk>;
|
|
45
45
|
export declare function updateOp(chunk: QvacChunk, { id, runStatus, attachment }: UpdateChunkInput): QvacUpdateChunkOperation;
|
|
46
46
|
export interface ResolveApprovalInput {
|
|
@@ -118,7 +118,7 @@ function assertPayloadMatchesType(type, payload) {
|
|
|
118
118
|
throw new CoreError('CHUNK_PAYLOAD_INVALID', [`${type} carries ${field} and nothing else`]);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
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, sourceId, ...payload }, into = store) {
|
|
122
122
|
assertPayloadMatchesType(type, payload);
|
|
123
123
|
if (type === 'sources' && !runId) {
|
|
124
124
|
throw new CoreError('CHUNK_PAYLOAD_INVALID', ['a sources chunk requires runId']);
|
|
@@ -129,6 +129,9 @@ export async function appendChunk(store, { id = randomId(), chatId, runId, type,
|
|
|
129
129
|
if (capability && type !== 'run-request') {
|
|
130
130
|
throw new CoreError('CHUNK_PAYLOAD_INVALID', ['only a run-request carries a capability']);
|
|
131
131
|
}
|
|
132
|
+
if (sourceId && type !== 'attachment') {
|
|
133
|
+
throw new CoreError('CHUNK_PAYLOAD_INVALID', ['only an attachment is derived from another']);
|
|
134
|
+
}
|
|
132
135
|
if (type === 'user-message' && !store.ourMemberId) {
|
|
133
136
|
await store.refreshOurMember();
|
|
134
137
|
}
|
|
@@ -154,6 +157,7 @@ export async function appendChunk(store, { id = randomId(), chatId, runId, type,
|
|
|
154
157
|
capability,
|
|
155
158
|
capabilityArgs,
|
|
156
159
|
enhance,
|
|
160
|
+
sourceId,
|
|
157
161
|
createdAt: Date.now(),
|
|
158
162
|
senderMemberId: type === 'user-message' && store.ourDeviceId && b4a.equals(store.ourDeviceId, originDeviceId)
|
|
159
163
|
? store.ourMemberId || undefined
|
|
@@ -163,6 +163,9 @@ async function admitted(mesh) {
|
|
|
163
163
|
return true;
|
|
164
164
|
if (await mesh.ownWriterRefused())
|
|
165
165
|
return false;
|
|
166
|
+
if (mesh.closing) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
166
169
|
return new Promise((resolve) => {
|
|
167
170
|
const settle = (ok) => {
|
|
168
171
|
mesh.autobee.off('writable', onWritable);
|
|
@@ -188,6 +191,9 @@ function waitForDelivery(mesh) {
|
|
|
188
191
|
if (delivered()) {
|
|
189
192
|
return Promise.resolve(true);
|
|
190
193
|
}
|
|
194
|
+
if (mesh.closing) {
|
|
195
|
+
return Promise.resolve(false);
|
|
196
|
+
}
|
|
191
197
|
return new Promise((resolve) => {
|
|
192
198
|
const settle = (ok) => {
|
|
193
199
|
local.off('upload', onUpload);
|
|
@@ -23,6 +23,13 @@ export interface DocumentReadState {
|
|
|
23
23
|
}
|
|
24
24
|
export declare function documentUnreadReason({ knowledgeOn, failedFiles, attachedCount }: DocumentReadState): DocumentUnreadReason;
|
|
25
25
|
export declare function documentUnreadNotice(reason: DocumentUnreadReason, plural: boolean): string;
|
|
26
|
+
export interface PdfPagesCutState {
|
|
27
|
+
readonly fileName: string;
|
|
28
|
+
readonly lastPage: number;
|
|
29
|
+
readonly pageCount: number;
|
|
30
|
+
}
|
|
31
|
+
export declare function pdfPagesCutNotice({ fileName, lastPage, pageCount }: PdfPagesCutState): string;
|
|
32
|
+
export declare function pdfPagesSkippedNotice(fileName: string): string;
|
|
26
33
|
export interface AnnotatedMessage {
|
|
27
34
|
content: string;
|
|
28
35
|
documents?: DocumentAttachment[];
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { isAudioAttachment } from './audio-attachment.js';
|
|
2
2
|
import { classifyRagDocument, RAG_DOCUMENT_KIND } from './files/rag/index.js';
|
|
3
3
|
import { IMAGE_MIMES } from './image/normalize.js';
|
|
4
|
+
import { isVideoAttachment } from './video/attachment.js';
|
|
4
5
|
export function isDocumentAttachment(ref) {
|
|
5
6
|
if (IMAGE_MIMES.has(ref.mimeType.toLowerCase()))
|
|
6
7
|
return false;
|
|
8
|
+
if (isVideoAttachment(ref.fileName, ref.mimeType))
|
|
9
|
+
return false;
|
|
7
10
|
return !isAudioAttachment(ref.fileName, ref.mimeType);
|
|
8
11
|
}
|
|
9
12
|
export function isPdfAttachment(ref) {
|
|
@@ -30,6 +33,12 @@ export function documentUnreadNotice(reason, plural) {
|
|
|
30
33
|
}[reason];
|
|
31
34
|
return `[The attached document${plural ? 's' : ''} could not be read for this reply: ${why}.]`;
|
|
32
35
|
}
|
|
36
|
+
export function pdfPagesCutNotice({ fileName, lastPage, pageCount }) {
|
|
37
|
+
return `[Only pages 1–${lastPage} of "${fileName}" (${pageCount} pages) were shown to you as images; pages ${lastPage + 1}–${pageCount} were not, and no tool can show them. If asked about a later page you have no excerpt for, tell the user only the first ${lastPage} pages could be read. Do not guess its content.]`;
|
|
38
|
+
}
|
|
39
|
+
export function pdfPagesSkippedNotice(fileName) {
|
|
40
|
+
return `[No page of "${fileName}" was shown to you as an image: the files before it in this message used up the page images, and no tool can show them. If asked about it and you have no excerpt, tell the user it could not be read. Do not guess its content.]`;
|
|
41
|
+
}
|
|
33
42
|
export function annotateDocumentAttachments(messages) {
|
|
34
43
|
for (const turn of messages.filter((message) => message.documents?.length)) {
|
|
35
44
|
const block = (turn.documents ?? []).map(documentAttachmentLine).join('\n');
|
|
@@ -4,7 +4,7 @@ import { attachmentFiles } from './attachments.js';
|
|
|
4
4
|
import { isKnowledgeRoutedAttachment, getKnowledge, listKnowledge, getKnowledgeArtifact, listKnowledgeArtifactsByKnowledge, addKnowledgeArtifact, hasLiveSource, syncAttachmentChunk, syncKnowledgeTombstone, syncArtifactArrival, sweepTombstonedBlobs, reclaimPurgedFiles, referencedBlobs, scopedFile, attachmentRecord, isProcessorOutput, isProcessorArtifactId } from './records/index.js';
|
|
5
5
|
import { knowledgeFiles } from './knowledge.js';
|
|
6
6
|
import { randomId } from '../id.js';
|
|
7
|
-
import { getChunk, listChunks } from '../chunk.js';
|
|
7
|
+
import { findChunksOfType, getChunk, listChunks } from '../chunk.js';
|
|
8
8
|
import { settleFiles, isClaimLive, listIndexingByChat, FileState, FileProcessing } from './processing/index.js';
|
|
9
9
|
import { DeadlineScheduler } from '../../deadline.js';
|
|
10
10
|
import { liveDeviceForWriter } from '../contract/activity.js';
|
|
@@ -14,7 +14,7 @@ import { RagProcessor } from './rag/index.js';
|
|
|
14
14
|
import { PreviewProcessor, PREVIEW_VERSION, previewId } from './preview/index.js';
|
|
15
15
|
import { CoreError } from '../../errors.js';
|
|
16
16
|
import { errorMessage } from '../../guards.js';
|
|
17
|
-
import { ACTIVE_KNOWLEDGE_BY_CHAT, AGENTS, CHATS,
|
|
17
|
+
import { ACTIVE_KNOWLEDGE_BY_CHAT, AGENTS, CHATS, INDEXING_STATUS_BY_CHAT, KNOWLEDGE, KNOWLEDGE_ARTIFACTS_BY_KNOWLEDGE } from '../collections.js';
|
|
18
18
|
export { fullTextBudgetChars, fullTextHits, retrieveRagKnowledge, searchRagChunks, referencesPendingFile } from './rag/index.js';
|
|
19
19
|
export { isKnowledgeRoutedAttachment } from './records/index.js';
|
|
20
20
|
export { assertRemovableAt } from './records/index.js';
|
|
@@ -457,13 +457,13 @@ export class Files extends EventEmitter {
|
|
|
457
457
|
}
|
|
458
458
|
const agent = await snap.get(AGENTS, { id: chat.agentId });
|
|
459
459
|
const knowledge = await snap.find(ACTIVE_KNOWLEDGE_BY_CHAT, range).toArray();
|
|
460
|
-
const chunks = await snap
|
|
460
|
+
const chunks = await findChunksOfType(snap, { chatId, type: 'attachment' });
|
|
461
461
|
const statuses = await snap.find(INDEXING_STATUS_BY_CHAT, range).toArray();
|
|
462
462
|
const sources = new Map(knowledge.map((row) => [row.id, row]));
|
|
463
463
|
const ragIds = new Set(sources.keys());
|
|
464
464
|
for (const chunk of chunks) {
|
|
465
465
|
const file = chunk.attachment;
|
|
466
|
-
if (!file || file.deletedAt || sources.has(file.id)) {
|
|
466
|
+
if (!file || file.deletedAt || chunk.sourceId || sources.has(file.id)) {
|
|
467
467
|
continue;
|
|
468
468
|
}
|
|
469
469
|
sources.set(file.id, { ...file, chatId, updatedAt: file.createdAt });
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { listChunks, updateOp } from '../../chunk.js';
|
|
1
3
|
import { hasLiveSource } from './routing.js';
|
|
2
4
|
export async function syncAttachmentChunk(mesh, chunk) {
|
|
3
5
|
if (chunk.type !== 'attachment')
|
|
@@ -6,6 +8,7 @@ export async function syncAttachmentChunk(mesh, chunk) {
|
|
|
6
8
|
if (!attachment?.deletedAt || typeof attachment.blobId !== 'string') {
|
|
7
9
|
return;
|
|
8
10
|
}
|
|
11
|
+
await tombstoneDerived(mesh, chunk, attachment.deletedAt);
|
|
9
12
|
if (await hasLiveSource(mesh, chunk.chatId, attachment.blobId)) {
|
|
10
13
|
return;
|
|
11
14
|
}
|
|
@@ -13,3 +16,21 @@ export async function syncAttachmentChunk(mesh, chunk) {
|
|
|
13
16
|
await mesh.files.clear(attachment.blobId, chunk.id);
|
|
14
17
|
await mesh.fileIndex?.markCleared(attachment.blobId);
|
|
15
18
|
}
|
|
19
|
+
async function tombstoneDerived(mesh, source, at) {
|
|
20
|
+
const ours = mesh.ourDeviceId;
|
|
21
|
+
if (!ours || !source.attachment) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const batch = mesh.batch();
|
|
25
|
+
for (const chunk of await listChunks(mesh, { chatId: source.chatId, type: 'attachment' })) {
|
|
26
|
+
const { attachment } = chunk;
|
|
27
|
+
if (chunk.sourceId !== source.attachment.id || !attachment || attachment.deletedAt) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (b4a.equals(chunk.originDeviceId, ours)) {
|
|
31
|
+
const tombstone = { ...attachment, deletedAt: at };
|
|
32
|
+
batch.dispatch('update-chunk', updateOp(chunk, { id: chunk.id, attachment: tombstone }));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
await batch.flush();
|
|
36
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { fileKeyOf } from '../local-index.js';
|
|
3
3
|
import { referencedBlobs } from './sweep.js';
|
|
4
|
-
import {
|
|
4
|
+
import { findChunksOfType } from '../../chunk.js';
|
|
5
|
+
import { KNOWLEDGE_ARTIFACTS_BY_KNOWLEDGE, KNOWLEDGE_BY_CHAT, PURGED_CHATS } from '../../collections.js';
|
|
5
6
|
export async function reclaimPurgedFiles(mesh) {
|
|
6
7
|
const index = mesh.fileIndex;
|
|
7
8
|
if (!index) {
|
|
@@ -42,8 +43,8 @@ export async function chatReferences(mesh, chatId) {
|
|
|
42
43
|
const inChat = { gte: { chatId }, lte: { chatId } };
|
|
43
44
|
const snap = mesh.view.snapshot();
|
|
44
45
|
try {
|
|
45
|
-
for
|
|
46
|
-
if (chunk.
|
|
46
|
+
for (const chunk of await findChunksOfType(snap, { chatId, type: 'attachment' })) {
|
|
47
|
+
if (chunk.attachment) {
|
|
47
48
|
references.push(chunk.attachment.blobId);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mediaKindOrdinal } from '../../../../schema/media-kind.js';
|
|
2
|
-
import { ATTACHMENTS_BY_MEDIA_KIND, CHATS, CHUNKS,
|
|
2
|
+
import { ATTACHMENTS_BY_MEDIA_KIND, CHATS, CHUNKS, KNOWLEDGE } from '../../collections.js';
|
|
3
|
+
import { findChunksOfType } from '../../chunk.js';
|
|
3
4
|
export function attachmentRecord(chunk) {
|
|
4
5
|
const file = chunk.attachment;
|
|
5
6
|
if (chunk.type !== 'attachment' || !file) {
|
|
@@ -64,10 +65,7 @@ export async function scopedFile(view, { chatId, fileId }) {
|
|
|
64
65
|
if (row) {
|
|
65
66
|
return row.chatId === chatId && !row.deletedAt ? row : null;
|
|
66
67
|
}
|
|
67
|
-
for
|
|
68
|
-
gte: { chatId },
|
|
69
|
-
lte: { chatId }
|
|
70
|
-
})) {
|
|
68
|
+
for (const chunk of await findChunksOfType(view, { chatId, type: 'attachment' })) {
|
|
71
69
|
if (chunk.attachment?.id === fileId) {
|
|
72
70
|
return chunk.attachment.deletedAt ? null : attachmentRecord(chunk);
|
|
73
71
|
}
|
|
@@ -23,7 +23,7 @@ export async function* uploadFile(mesh, frames, { kind, maxBytes, deviceId, inac
|
|
|
23
23
|
if (first.done) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const { chatId, runId, fileName, mimeType, raw } = first.value;
|
|
26
|
+
const { chatId, runId, fileName, mimeType, raw, sourceId } = first.value;
|
|
27
27
|
const originDeviceId = kind === 'knowledge' ? deviceId : first.value.originDeviceId;
|
|
28
28
|
if (typeof chatId !== 'string' ||
|
|
29
29
|
typeof fileName !== 'string' ||
|
|
@@ -89,7 +89,8 @@ export async function* uploadFile(mesh, frames, { kind, maxBytes, deviceId, inac
|
|
|
89
89
|
runId,
|
|
90
90
|
type: 'attachment',
|
|
91
91
|
attachment,
|
|
92
|
-
originDeviceId
|
|
92
|
+
originDeviceId,
|
|
93
|
+
sourceId
|
|
93
94
|
});
|
|
94
95
|
chunkId = appended.id;
|
|
95
96
|
}
|
|
@@ -18,6 +18,8 @@ export declare function generateMnemonic(): Promise<string>;
|
|
|
18
18
|
export declare function openIdentity(mnemonic: string): Promise<IdentityKey>;
|
|
19
19
|
export declare function mintIdentity(mnemonic: string, devicePublicKey: Buffer): Promise<MintedIdentity>;
|
|
20
20
|
export declare function attestDeviceProof(devicePublicKey: Buffer, parent: KeyPair, parentProof: Buffer): Promise<Buffer>;
|
|
21
|
+
export declare function pairingAnchorSeed(accountSeed: Buffer, memberId: Buffer): Buffer;
|
|
22
|
+
export declare function chainTo(proof: Buffer, publicKey: Buffer): Buffer | null;
|
|
21
23
|
export declare function delegationFits(proof: Buffer, delegate: KeyPair): Promise<boolean>;
|
|
22
24
|
export declare function verifyDeviceProof(proof: Buffer, expected: ExpectedDeviceProof): Promise<boolean>;
|
|
23
25
|
export declare function claimAttestation(meshPublicKey: Buffer, deviceId: Buffer, writerKey: Buffer): Buffer;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
1
2
|
import c from 'compact-encoding';
|
|
2
3
|
import crypto from 'hypercore-crypto';
|
|
3
4
|
import { ProofEncoding } from 'keet-identity-key/lib/encoding.js';
|
|
4
5
|
export const MAX_PROOF_BYTES = 1024;
|
|
5
6
|
const [CLAIM_NAMESPACE] = crypto.namespace('@qvac/core/member-claim', 1);
|
|
7
|
+
const [ANCHOR_NAMESPACE] = crypto.namespace('@qvac/core/pairing-anchor', 1);
|
|
6
8
|
let loaded = null;
|
|
7
9
|
async function identityKey() {
|
|
8
10
|
if (loaded === null) {
|
|
@@ -25,6 +27,23 @@ export async function attestDeviceProof(devicePublicKey, parent, parentProof) {
|
|
|
25
27
|
throw new Error('attestDeviceProof needs the parent proof');
|
|
26
28
|
return (await identityKey()).attestDevice(devicePublicKey, parent, parentProof);
|
|
27
29
|
}
|
|
30
|
+
export function pairingAnchorSeed(accountSeed, memberId) {
|
|
31
|
+
return crypto.hash([ANCHOR_NAMESPACE, accountSeed, memberId]);
|
|
32
|
+
}
|
|
33
|
+
export function chainTo(proof, publicKey) {
|
|
34
|
+
let decoded;
|
|
35
|
+
try {
|
|
36
|
+
decoded = c.decode(ProofEncoding, proof);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const at = decoded.chain.findIndex((link) => b4a.equals(link.publicKey, publicKey));
|
|
42
|
+
if (at === -1) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return c.encode(ProofEncoding, { ...decoded, chain: decoded.chain.slice(0, at + 1) });
|
|
46
|
+
}
|
|
28
47
|
export async function delegationFits(proof, delegate) {
|
|
29
48
|
const device = crypto.keyPair();
|
|
30
49
|
const extended = await attestDeviceProof(device.publicKey, delegate, proof);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isVideoAttachment(fileName: string, mimeType: string): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { mediaKindOf } from '../../../schema/media-kind.js';
|
|
2
|
+
const VIDEO_CONTAINERS = ['.mp4', '.m4v', '.mov'];
|
|
3
|
+
export function isVideoAttachment(fileName, mimeType) {
|
|
4
|
+
const name = fileName.toLowerCase();
|
|
5
|
+
return (mediaKindOf(mimeType, fileName) === 'video' ||
|
|
6
|
+
VIDEO_CONTAINERS.some((extension) => name.endsWith(extension)));
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const VIDEO_DIGEST_MIME = "application/vnd.qvac.video-frames";
|
|
2
|
+
export declare const VIDEO_AUDIO: readonly ['none', 'silent', 'speech', 'unheard'];
|
|
3
|
+
export type VideoAudio = (typeof VIDEO_AUDIO)[number];
|
|
4
|
+
export interface VideoDigestHeader {
|
|
5
|
+
readonly duration: number;
|
|
6
|
+
readonly times: ReadonlyArray<number>;
|
|
7
|
+
readonly audio: VideoAudio;
|
|
8
|
+
readonly transcript?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface VideoDigest extends VideoDigestHeader {
|
|
11
|
+
readonly frames: ReadonlyArray<Uint8Array>;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseVideoDigestHeader(json: string): VideoDigestHeader;
|
|
14
|
+
export declare function videoDigestFileName(videoFileName: string): string;
|
|
15
|
+
export declare function packVideoDigest(digest: VideoDigest): Uint8Array;
|
|
16
|
+
export declare function unpackVideoDigest(bytes: Uint8Array): VideoDigest;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
export const VIDEO_DIGEST_MIME = 'application/vnd.qvac.video-frames';
|
|
4
|
+
export const VIDEO_AUDIO = ['none', 'silent', 'speech', 'unheard'];
|
|
5
|
+
const HEADER_BYTES = 4;
|
|
6
|
+
const VideoDigestHeaderSchema = z.object({
|
|
7
|
+
duration: z.number().nonnegative(),
|
|
8
|
+
times: z.array(z.number().nonnegative()),
|
|
9
|
+
audio: z.enum(VIDEO_AUDIO),
|
|
10
|
+
transcript: z.string().optional()
|
|
11
|
+
});
|
|
12
|
+
const HeaderSchema = VideoDigestHeaderSchema.extend({
|
|
13
|
+
version: z.literal(1),
|
|
14
|
+
sizes: z.array(z.number().int().positive())
|
|
15
|
+
});
|
|
16
|
+
export function parseVideoDigestHeader(json) {
|
|
17
|
+
return VideoDigestHeaderSchema.parse(JSON.parse(json));
|
|
18
|
+
}
|
|
19
|
+
export function videoDigestFileName(videoFileName) {
|
|
20
|
+
return `${videoFileName}.frames`;
|
|
21
|
+
}
|
|
22
|
+
export function packVideoDigest(digest) {
|
|
23
|
+
const header = b4a.from(JSON.stringify({
|
|
24
|
+
version: 1,
|
|
25
|
+
duration: digest.duration,
|
|
26
|
+
times: digest.times,
|
|
27
|
+
sizes: digest.frames.map((frame) => frame.byteLength),
|
|
28
|
+
audio: digest.audio,
|
|
29
|
+
transcript: digest.transcript
|
|
30
|
+
}));
|
|
31
|
+
const length = b4a.alloc(HEADER_BYTES);
|
|
32
|
+
b4a.writeUInt32LE(length, header.byteLength, 0);
|
|
33
|
+
return b4a.concat([length, header, ...digest.frames]);
|
|
34
|
+
}
|
|
35
|
+
export function unpackVideoDigest(bytes) {
|
|
36
|
+
const length = b4a.readUInt32LE(bytes, 0);
|
|
37
|
+
const header = HeaderSchema.parse(JSON.parse(b4a.toString(bytes.subarray(HEADER_BYTES, HEADER_BYTES + length))));
|
|
38
|
+
if (header.sizes.length !== header.times.length) {
|
|
39
|
+
throw new Error('video digest: a frame time without its frame');
|
|
40
|
+
}
|
|
41
|
+
let offset = HEADER_BYTES + length;
|
|
42
|
+
const frames = header.sizes.map((size) => {
|
|
43
|
+
const frame = bytes.subarray(offset, offset + size);
|
|
44
|
+
offset += size;
|
|
45
|
+
return frame;
|
|
46
|
+
});
|
|
47
|
+
if (offset !== bytes.byteLength) {
|
|
48
|
+
throw new Error('video digest: frames do not fill the blob');
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
duration: header.duration,
|
|
52
|
+
times: header.times,
|
|
53
|
+
audio: header.audio,
|
|
54
|
+
transcript: header.transcript,
|
|
55
|
+
frames
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface Orientation {
|
|
2
|
+
readonly rotate: 0 | 90 | 180 | 270;
|
|
3
|
+
readonly flipH: boolean;
|
|
4
|
+
readonly flipV: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface VideoProbe extends Orientation {
|
|
7
|
+
readonly hasVideo: boolean;
|
|
8
|
+
readonly hasAudio: boolean;
|
|
9
|
+
readonly duration: number;
|
|
10
|
+
readonly width: number;
|
|
11
|
+
readonly height: number;
|
|
12
|
+
readonly aspect: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SampledFrame {
|
|
15
|
+
readonly time: number;
|
|
16
|
+
readonly width: number;
|
|
17
|
+
readonly height: number;
|
|
18
|
+
readonly jpeg: Uint8Array;
|
|
19
|
+
}
|
|
20
|
+
export interface SampleOptions {
|
|
21
|
+
readonly times: ReadonlyArray<number>;
|
|
22
|
+
readonly maxEdge: number;
|
|
23
|
+
readonly probe: VideoProbe;
|
|
24
|
+
}
|
|
25
|
+
export interface Size {
|
|
26
|
+
readonly width: number;
|
|
27
|
+
readonly height: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function probeVideo(file: string): Promise<VideoProbe>;
|
|
30
|
+
export declare function frameTimes(duration: number, count: number): number[];
|
|
31
|
+
export declare function frameSize(probe: VideoProbe, maxEdge: number): Size;
|
|
32
|
+
export declare function sampleFrames(file: string, opts: SampleOptions): Promise<SampledFrame[]>;
|