@qvac/core 1.0.0-rc.7 → 1.0.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 +241 -3
- package/README.md +1 -0
- package/dist-lib/lib/api/attachments.d.ts +1 -1
- package/dist-lib/lib/api/attachments.js +11 -0
- package/dist-lib/lib/api/chunks.d.ts +4 -2
- package/dist-lib/lib/api/chunks.js +6 -3
- package/dist-lib/lib/api/device-routes.d.ts +6 -1
- package/dist-lib/lib/api/device-routes.js +20 -1
- package/dist-lib/lib/api/devices.js +6 -18
- package/dist-lib/lib/api/execution.d.ts +6 -2
- package/dist-lib/lib/api/execution.js +29 -3
- package/dist-lib/lib/api/host-run-log.d.ts +7 -1
- package/dist-lib/lib/api/host-run-log.js +3 -1
- package/dist-lib/lib/api/index.d.ts +3 -1
- package/dist-lib/lib/api/index.js +17 -6
- package/dist-lib/lib/api/members.js +13 -29
- package/dist-lib/lib/api/mesh.d.ts +2 -1
- package/dist-lib/lib/api/projects.d.ts +1 -1
- package/dist-lib/lib/api/projects.js +9 -5
- package/dist-lib/lib/api/rag-label.d.ts +4 -0
- package/dist-lib/lib/api/rag-label.js +21 -0
- package/dist-lib/lib/api/rag-lexical.d.ts +22 -0
- package/dist-lib/lib/api/rag-lexical.js +1058 -0
- package/dist-lib/lib/api/rag-manifest.d.ts +13 -0
- package/dist-lib/lib/api/rag-manifest.js +46 -0
- package/dist-lib/lib/api/rag-outline.d.ts +36 -0
- package/dist-lib/lib/api/rag-outline.js +426 -0
- package/dist-lib/lib/api/rag-plugin.d.ts +20 -0
- package/dist-lib/lib/api/rag-plugin.js +70 -0
- package/dist-lib/lib/api/rag-synthesis.d.ts +7 -0
- package/dist-lib/lib/api/rag-synthesis.js +102 -0
- package/dist-lib/lib/api/rag-targets.d.ts +23 -0
- package/dist-lib/lib/api/rag-targets.js +215 -0
- package/dist-lib/lib/api/rag-window.d.ts +5 -0
- package/dist-lib/lib/api/rag-window.js +46 -0
- package/dist-lib/lib/api/rag.d.ts +3 -2
- package/dist-lib/lib/api/rag.js +421 -184
- package/dist-lib/lib/api/served.js +8 -14
- package/dist-lib/lib/api/workspace.d.ts +8 -1
- package/dist-lib/lib/api/workspace.js +27 -13
- package/dist-lib/lib/assistant/harness.d.ts +9 -1
- package/dist-lib/lib/assistant/history.d.ts +11 -2
- package/dist-lib/lib/assistant/history.js +74 -4
- package/dist-lib/lib/assistant/media-round.d.ts +61 -0
- package/dist-lib/lib/assistant/media-round.js +111 -0
- package/dist-lib/lib/assistant/message.d.ts +7 -0
- package/dist-lib/lib/assistant/model-round.d.ts +19 -1
- package/dist-lib/lib/assistant/model-round.js +163 -28
- package/dist-lib/lib/assistant/pdf-pages.d.ts +16 -1
- package/dist-lib/lib/assistant/pdf-pages.js +67 -3
- package/dist-lib/lib/assistant/round-host.d.ts +22 -0
- package/dist-lib/lib/assistant/round-host.js +142 -8
- package/dist-lib/lib/assistant/upload.d.ts +12 -0
- package/dist-lib/lib/assistant/upload.js +36 -0
- package/dist-lib/lib/assistant-client.d.ts +1 -0
- package/dist-lib/lib/assistant-client.js +40 -19
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +48 -1
- package/dist-lib/lib/assistant.d.ts +18 -1
- package/dist-lib/lib/assistant.js +484 -95
- package/dist-lib/lib/client.d.ts +1 -0
- package/dist-lib/lib/client.js +4 -1
- package/dist-lib/lib/compaction.js +2 -2
- package/dist-lib/lib/core/agent.js +12 -45
- package/dist-lib/lib/core/approval-rules.js +1 -8
- package/dist-lib/lib/core/archived-mesh.d.ts +2 -1
- package/dist-lib/lib/core/archived-mesh.js +12 -8
- package/dist-lib/lib/core/chat-copy.d.ts +18 -3
- package/dist-lib/lib/core/chat-copy.js +74 -25
- package/dist-lib/lib/core/chat-fork.js +15 -6
- package/dist-lib/lib/core/chat-group.js +16 -24
- package/dist-lib/lib/core/chat-move.d.ts +9 -0
- package/dist-lib/lib/core/chat-move.js +94 -3
- package/dist-lib/lib/core/chat-order.js +12 -18
- package/dist-lib/lib/core/chat.js +38 -31
- package/dist-lib/lib/core/chunk.d.ts +2 -2
- package/dist-lib/lib/core/chunk.js +18 -25
- package/dist-lib/lib/core/collections.d.ts +2 -0
- package/dist-lib/lib/core/collections.js +2 -0
- package/dist-lib/lib/core/contract/activity.d.ts +4 -0
- package/dist-lib/lib/core/contract/activity.js +34 -4
- package/dist-lib/lib/core/contract/chat-group.d.ts +1 -0
- package/dist-lib/lib/core/contract/chat-group.js +21 -1
- package/dist-lib/lib/core/contract/chat.d.ts +9 -0
- package/dist-lib/lib/core/contract/chat.js +127 -5
- package/dist-lib/lib/core/contract/chunks.d.ts +1 -0
- package/dist-lib/lib/core/contract/chunks.js +37 -6
- package/dist-lib/lib/core/contract/features.d.ts +21 -0
- package/dist-lib/lib/core/contract/features.js +22 -0
- package/dist-lib/lib/core/contract/index.js +2 -0
- package/dist-lib/lib/core/contract/indexing.js +4 -2
- package/dist-lib/lib/core/contract/knowledge.js +5 -4
- package/dist-lib/lib/core/contract/members.js +16 -10
- package/dist-lib/lib/core/contract/mesh-kind.d.ts +1 -0
- package/dist-lib/lib/core/contract/mesh-kind.js +3 -1
- package/dist-lib/lib/core/contract/projects.d.ts +5 -0
- package/dist-lib/lib/core/contract/projects.js +13 -5
- package/dist-lib/lib/core/contract/roles.js +32 -4
- package/dist-lib/lib/core/contract/run-requests.d.ts +1 -0
- package/dist-lib/lib/core/contract/run-requests.js +35 -2
- package/dist-lib/lib/core/contract/seed-defaults.js +2 -2
- package/dist-lib/lib/core/contract/tool-configs.js +3 -2
- package/dist-lib/lib/core/contract/workspace.d.ts +2 -0
- package/dist-lib/lib/core/contract/workspace.js +40 -7
- package/dist-lib/lib/core/contract/writers.js +2 -2
- package/dist-lib/lib/core/departures.d.ts +3 -1
- package/dist-lib/lib/core/departures.js +3 -0
- package/dist-lib/lib/core/devices.js +1 -8
- package/dist-lib/lib/core/files/attachments.d.ts +2 -0
- package/dist-lib/lib/core/files/attachments.js +19 -1
- package/dist-lib/lib/core/files/index.d.ts +20 -4
- package/dist-lib/lib/core/files/index.js +132 -21
- package/dist-lib/lib/core/files/processing/document.d.ts +4 -0
- package/dist-lib/lib/core/files/processing/document.js +7 -0
- package/dist-lib/lib/core/files/processing/index.d.ts +13 -0
- package/dist-lib/lib/core/files/processing/index.js +144 -12
- package/dist-lib/lib/core/files/processing/protocol.js +13 -34
- package/dist-lib/lib/core/files/processing/state.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +19 -2
- package/dist-lib/lib/core/files/rag/build.js +123 -19
- package/dist-lib/lib/core/files/rag/failure.js +2 -1
- package/dist-lib/lib/core/files/rag/index.d.ts +11 -3
- package/dist-lib/lib/core/files/rag/index.js +13 -1
- package/dist-lib/lib/core/files/rag/load.d.ts +6 -3
- package/dist-lib/lib/core/files/rag/load.js +27 -6
- package/dist-lib/lib/core/files/rag/plugin-index.d.ts +32 -0
- package/dist-lib/lib/core/files/rag/plugin-index.js +127 -0
- package/dist-lib/lib/core/files/rag/produce.d.ts +5 -3
- package/dist-lib/lib/core/files/rag/produce.js +104 -16
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +3 -1
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +62 -13
- package/dist-lib/lib/core/files/rag/text-cache.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/text-cache.js +141 -0
- package/dist-lib/lib/core/files/records/knowledge.d.ts +1 -3
- package/dist-lib/lib/core/files/records/knowledge.js +7 -40
- package/dist-lib/lib/core/files/records/reclaim.js +5 -10
- package/dist-lib/lib/core/files/upload.js +68 -41
- package/dist-lib/lib/core/fs-drives.js +14 -26
- package/dist-lib/lib/core/invite.d.ts +1 -0
- package/dist-lib/lib/core/invite.js +4 -2
- package/dist-lib/lib/core/local/files.d.ts +1 -1
- package/dist-lib/lib/core/local/files.js +5 -5
- package/dist-lib/lib/core/local/index.d.ts +13 -6
- package/dist-lib/lib/core/local/index.js +103 -69
- package/dist-lib/lib/core/local/run-logs.d.ts +1 -1
- package/dist-lib/lib/core/local/run-logs.js +5 -5
- package/dist-lib/lib/core/mesh-processor.d.ts +19 -0
- package/dist-lib/lib/core/mesh-processor.js +87 -0
- package/dist-lib/lib/core/mesh.d.ts +48 -5
- package/dist-lib/lib/core/mesh.js +318 -129
- package/dist-lib/lib/core/migrations/agent-catalog.js +2 -8
- package/dist-lib/lib/core/migrations/agent-tools-scope.js +5 -11
- package/dist-lib/lib/core/migrations/workspace-from-0-21/index.d.ts +88 -0
- package/dist-lib/lib/core/migrations/workspace-from-0-21/index.js +731 -0
- package/dist-lib/lib/core/migrations/writer-links.d.ts +2 -0
- package/dist-lib/lib/core/migrations/writer-links.js +32 -0
- package/dist-lib/lib/core/project-keys.d.ts +6 -0
- package/dist-lib/lib/core/project-keys.js +11 -0
- package/dist-lib/lib/core/public-mesh.d.ts +3 -0
- package/dist-lib/lib/core/public-mesh.js +10 -8
- package/dist-lib/lib/core/run-requests.d.ts +3 -0
- package/dist-lib/lib/core/run-requests.js +21 -1
- package/dist-lib/lib/core/skill-availability.d.ts +33 -0
- package/dist-lib/lib/core/skill-availability.js +67 -0
- package/dist-lib/lib/core/sync/background.d.ts +0 -1
- package/dist-lib/lib/core/sync/background.js +2 -1
- package/dist-lib/lib/core/sync/changed.d.ts +4 -2
- package/dist-lib/lib/core/sync/changed.js +1 -1
- package/dist-lib/lib/core/sync/index.js +52 -10
- package/dist-lib/lib/core/sync/view-updates.d.ts +18 -12
- package/dist-lib/lib/core/sync/view-updates.js +82 -91
- package/dist-lib/lib/core/sync-status.js +97 -41
- package/dist-lib/lib/core/tool-activity.js +6 -12
- package/dist-lib/lib/core/tool-configs.js +17 -29
- package/dist-lib/lib/core/upgrade-summary.d.ts +19 -0
- package/dist-lib/lib/core/upgrade-summary.js +67 -0
- package/dist-lib/lib/core/view-read.d.ts +4 -0
- package/dist-lib/lib/core/view-read.js +23 -0
- package/dist-lib/lib/core/workspace-upgrade.d.ts +7 -0
- package/dist-lib/lib/core/workspace-upgrade.js +27 -16
- package/dist-lib/lib/core.d.ts +45 -42
- package/dist-lib/lib/core.js +675 -640
- package/dist-lib/lib/errors.d.ts +24 -0
- package/dist-lib/lib/errors.js +24 -0
- package/dist-lib/lib/llm-model-names.d.ts +1 -1
- package/dist-lib/lib/llm-model-names.js +1 -1
- package/dist-lib/lib/mesh-scoped-engine.js +4 -0
- package/dist-lib/lib/model-context.js +1 -2
- package/dist-lib/lib/model-download.d.ts +6 -1
- package/dist-lib/lib/model-download.js +16 -3
- package/dist-lib/lib/oauth/resolve.js +29 -8
- package/dist-lib/lib/oauth/token-exchange-core.js +11 -0
- package/dist-lib/lib/probe-rounds.d.ts +7 -2
- package/dist-lib/lib/probe-rounds.js +6 -1
- package/dist-lib/lib/run-transcript.d.ts +4 -1
- package/dist-lib/lib/run-transcript.js +15 -6
- package/dist-lib/schema/engine.js +83 -6
- package/dist-lib/schema/indexes.d.ts +3 -0
- package/dist-lib/schema/indexes.js +5 -0
- package/dist-lib/schema/local.js +11 -2
- package/dist-lib/schema/qvac.js +49 -5
- package/dist-lib/spec/bind.js +34 -0
- package/dist-lib/spec/calls.js +5 -0
- package/dist-lib/spec/capabilities.d.ts +17 -0
- package/dist-lib/spec/hrpc/hrpc.json +65 -0
- package/dist-lib/spec/hrpc/index.js +68 -5
- package/dist-lib/spec/hrpc/messages.js +260 -23
- package/dist-lib/spec/hyperschema/index.js +260 -23
- package/dist-lib/spec/hyperschema/schema.json +181 -0
- package/dist-lib/spec/hyperschema/types.d.ts +48 -0
- package/dist-lib/spec/local/hyperdb/messages.js +270 -224
- package/dist-lib/spec/local/hyperschema/index.js +73 -38
- package/dist-lib/spec/local/hyperschema/schema.json +31 -0
- package/dist-lib/spec/local/hyperschema/types.d.ts +8 -0
- package/dist-lib/spec/mesh/hyperdb/db.json +39 -2
- package/dist-lib/spec/mesh/hyperdb/index.js +120 -3
- package/dist-lib/spec/mesh/hyperdb/messages.js +1328 -838
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +30 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.js +86 -1
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +682 -287
- package/dist-lib/spec/mesh/hyperschema/index.js +682 -287
- package/dist-lib/spec/mesh/hyperschema/schema.json +201 -0
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +52 -0
- package/package.json +82 -71
- package/tui/README.md +52 -0
- package/tui/app.mjs +69 -12
- package/tui/boot.mjs +27 -6
- package/tui/cli.mjs +93 -0
- package/tui/index.mjs +2 -87
- package/tui/lib/attachment-files.mjs +82 -0
- package/tui/lib/reopen-meshes.mjs +15 -0
- package/tui/lib/updater.mjs +86 -0
- package/tui/main.mjs +29 -57
- package/worker/assistant-sidecar.mjs +10 -3
- package/worker/stow-entry.mjs +3 -52
- package/dist-lib/lib/core/chat-project.d.ts +0 -2
- package/dist-lib/lib/core/chat-project.js +0 -15
|
@@ -54,18 +54,12 @@ export function createServedApi({ pool, local, foreign, status, list, deviceId,
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
async function servedListing(mesh, deviceId) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
lastActivityAt: activity.get(id) || createdAt
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
finally {
|
|
69
|
-
await snap.close();
|
|
70
|
-
}
|
|
57
|
+
const activity = await lastActivity(mesh.view);
|
|
58
|
+
return (await servedChats(mesh, deviceId)).map(({ id, agentId, title, createdAt }) => ({
|
|
59
|
+
id,
|
|
60
|
+
agentId,
|
|
61
|
+
title,
|
|
62
|
+
createdAt,
|
|
63
|
+
lastActivityAt: activity.get(id) || createdAt
|
|
64
|
+
}));
|
|
71
65
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { LoggerInterface } from '@qvac/logging';
|
|
2
2
|
import { type MeshPool } from './current-mesh.ts';
|
|
3
3
|
import type { MeshStatusSource } from './mesh.ts';
|
|
4
|
+
import type { NameOf } from './projects.ts';
|
|
4
5
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
5
|
-
|
|
6
|
+
type Status = Pick<MeshStatusSource, 'createWorkspace' | 'name' | 'leaveWorkspace' | 'upgradeSummary' | 'watch' | 'unwatch'>;
|
|
7
|
+
interface WorkspaceOptions {
|
|
8
|
+
readonly nameOf: NameOf;
|
|
9
|
+
readonly log: LoggerInterface | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function createWorkspaceApi(pool: MeshPool, status: Status, { nameOf, log }: WorkspaceOptions): Pick<CapabilityHandlers, 'createWorkspace' | 'getWorkspace' | 'workspaceWatch' | 'updateWorkspace' | 'leaveWorkspace' | 'workspaceUpgradeSummary'>;
|
|
12
|
+
export {};
|
|
@@ -1,30 +1,45 @@
|
|
|
1
|
-
import { MESH_NAMES } from '../core/collections.js';
|
|
2
|
-
import { MESH_NAME_ROW } from '../core/contract/mesh-name.js';
|
|
3
1
|
import { WORKSPACE_ROW, readWorkspace } from '../core/contract/workspace.js';
|
|
2
|
+
import { readView } from '../core/view-read.js';
|
|
3
|
+
import { isCoreError } from '../errors.js';
|
|
4
4
|
import { meshWatchable, requireMesh } from './current-mesh.js';
|
|
5
5
|
import { requireOurAdmin, requireWorkspace } from './members.js';
|
|
6
|
-
async function
|
|
6
|
+
async function heldWorkspace(mesh) {
|
|
7
|
+
try {
|
|
8
|
+
return await readView(mesh, readWorkspace);
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
if (isCoreError(err, 'MESH_VIEW_UNAVAILABLE')) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function read(mesh, meshId, nameOf) {
|
|
7
18
|
requireWorkspace(mesh, meshId);
|
|
8
|
-
const row = await
|
|
9
|
-
|
|
10
|
-
return { meshId, name: named?.name ?? '', icon: row?.icon || undefined };
|
|
19
|
+
const row = await heldWorkspace(mesh);
|
|
20
|
+
return { meshId, name: nameOf(mesh.key)?.name ?? '', icon: row?.icon || undefined };
|
|
11
21
|
}
|
|
12
|
-
export function createWorkspaceApi(pool, status, log) {
|
|
22
|
+
export function createWorkspaceApi(pool, status, { nameOf, log }) {
|
|
13
23
|
return {
|
|
14
24
|
createWorkspace: async (request) => {
|
|
15
25
|
const meshId = await status.createWorkspace({
|
|
16
26
|
name: request?.config?.name ?? undefined,
|
|
17
27
|
icon: request?.config?.icon ?? undefined
|
|
18
28
|
});
|
|
19
|
-
return read(await requireMesh(pool, meshId), meshId);
|
|
29
|
+
return read(await requireMesh(pool, meshId), meshId, nameOf);
|
|
30
|
+
},
|
|
31
|
+
getWorkspace: async ({ meshId }) => read(await requireMesh(pool, meshId), meshId, nameOf),
|
|
32
|
+
workspaceWatch: meshWatchable(pool, ({ meshId }, mesh) => read(mesh, meshId, nameOf), { name: 'workspaceWatch', log, changes: status }),
|
|
33
|
+
updateWorkspace: async (request) => {
|
|
34
|
+
const mesh = await requireMesh(pool, request.meshId);
|
|
35
|
+
await update(mesh, request, status);
|
|
36
|
+
return read(mesh, request.meshId, nameOf);
|
|
20
37
|
},
|
|
21
|
-
getWorkspace: async ({ meshId }) => read(await requireMesh(pool, meshId), meshId),
|
|
22
|
-
workspaceWatch: meshWatchable(pool, ({ meshId }, mesh) => read(mesh, meshId), { name: 'workspaceWatch', log }),
|
|
23
|
-
updateWorkspace: async (request) => update(await requireMesh(pool, request.meshId), request, status),
|
|
24
38
|
leaveWorkspace: async ({ meshId }) => {
|
|
25
39
|
await status.leaveWorkspace(meshId);
|
|
26
40
|
return { ok: true };
|
|
27
|
-
}
|
|
41
|
+
},
|
|
42
|
+
workspaceUpgradeSummary: () => status.upgradeSummary()
|
|
28
43
|
};
|
|
29
44
|
}
|
|
30
45
|
async function update(mesh, { meshId, config }, status) {
|
|
@@ -43,5 +58,4 @@ async function update(mesh, { meshId, config }, status) {
|
|
|
43
58
|
}
|
|
44
59
|
});
|
|
45
60
|
}
|
|
46
|
-
return read(mesh, meshId);
|
|
47
61
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AbortSignal } from 'bare-abort-controller';
|
|
2
|
-
import type { ApprovalCall, CompletionEvent, DeleteModelSummary, DriveOpFn, GrantedDrive, HostRunLog, ManagedSkill, MemoryBudget, ModelRoundIo, ModelRoundPort, ModelRoundRequest, ModelRoundResult, ModelSourcePreview, PreviewModelSourceContext, SkillFileContent } from '@qvac/harness';
|
|
2
|
+
import type { ApprovalCall, CompletionEvent, DeleteModelSummary, DriveOpFn, GrantedDrive, HostRunLog, KnowledgeArtifact, KnowledgeHit, KnowledgeQuery, KnowledgeRemoved, KnowledgeStatus, KnowledgeUpsertResult, ManagedSkill, MemoryBudget, ModelRoundIo, ModelRoundPort, ModelRoundRequest, ModelRoundResult, ModelSourcePreview, OcrPage, OcrReadContext, PreviewModelSourceContext, SkillFileContent } from '@qvac/harness';
|
|
3
|
+
import type { MediaRoundIo, MediaRoundPort, MediaRoundRequest, MediaRoundResult } from '@qvac/harness/lib/contract/index.ts';
|
|
3
4
|
import type { SkillCatalogOptions, SkillManagementHooks } from '../core.ts';
|
|
4
5
|
import type { AssistantAgent, AssistantCapabilityProfile, AssistantChunkContentAttachment, AssistantCustomModelPreview, AssistantCustomModelReportEntry, AssistantDeleteModelRequest, AssistantDetectLanguageRequest, AssistantDetectLanguageResponse, AssistantDeleteModelResponse, AssistantEnhanceMode, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantModelInfoList, AssistantPreviewCustomModelRequest, AssistantSkillCatalogResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantToolReportEntry, AssistantTranscribeRequest, AssistantTranscribeResponse } from '../../spec/hyperschema/types.d.ts';
|
|
5
6
|
import type { HarnessDiagnostics } from '../diagnostics.ts';
|
|
@@ -95,6 +96,7 @@ export interface Harness {
|
|
|
95
96
|
replaysContext?: boolean;
|
|
96
97
|
deferTools?: boolean;
|
|
97
98
|
modelRound?: ModelRoundPort;
|
|
99
|
+
mediaRound?: MediaRoundPort;
|
|
98
100
|
session?: string;
|
|
99
101
|
thinkingDefault?: string;
|
|
100
102
|
toolConfigs?: Record<string, Record<string, unknown>>;
|
|
@@ -136,6 +138,7 @@ export interface Harness {
|
|
|
136
138
|
signal?: AbortSignal;
|
|
137
139
|
}): AsyncIterable<HarnessEvent>;
|
|
138
140
|
serveModelRound?(request: ModelRoundRequest, io: ModelRoundIo): Promise<ModelRoundResult>;
|
|
141
|
+
serveMediaRound?(request: MediaRoundRequest, io: MediaRoundIo): Promise<MediaRoundResult>;
|
|
139
142
|
invoke?(context: {
|
|
140
143
|
capability: string;
|
|
141
144
|
args: Record<string, unknown>;
|
|
@@ -184,6 +187,11 @@ export interface Harness {
|
|
|
184
187
|
audio: Buffer;
|
|
185
188
|
signal?: AbortSignal;
|
|
186
189
|
}): Promise<string>;
|
|
190
|
+
knowledgeUpsert?(artifact: KnowledgeArtifact): Promise<KnowledgeUpsertResult>;
|
|
191
|
+
knowledgeRemove?(artifactId: string): Promise<KnowledgeRemoved>;
|
|
192
|
+
knowledgeSearch?(query: KnowledgeQuery): Promise<KnowledgeHit[]>;
|
|
193
|
+
knowledgeStatus?(): Promise<KnowledgeStatus>;
|
|
194
|
+
ocrRead?(context: OcrReadContext): Promise<OcrPage>;
|
|
187
195
|
detectLanguage?(context: {
|
|
188
196
|
text: string;
|
|
189
197
|
topK?: number;
|
|
@@ -3,7 +3,7 @@ import type { AssistantChunk } from '../../spec/hyperschema/types.d.ts';
|
|
|
3
3
|
import type { ScopedCapabilities } from '../mesh-scoped-engine.ts';
|
|
4
4
|
import type { OwnerRounds } from './model-round.ts';
|
|
5
5
|
import type { DiagramRepairLink } from '@qvac/harness/lib/diagram-repair.ts';
|
|
6
|
-
import type { ChatMessage } from './message.ts';
|
|
6
|
+
import type { ChatMessage, PdfShotRef } from './message.ts';
|
|
7
7
|
export declare function senderOf(chunk: AssistantChunk): string | undefined;
|
|
8
8
|
export declare const TERMINAL_STATES: Set<string>;
|
|
9
9
|
export declare const HISTORY_TYPES: AssistantChunk['type'][];
|
|
@@ -36,8 +36,9 @@ export interface HistoryReplay {
|
|
|
36
36
|
readonly sentRuns?: ReadonlyMap<string, ReadonlyArray<ChatMessage>>;
|
|
37
37
|
readonly askedRuns?: ReadonlyMap<string, string>;
|
|
38
38
|
readonly readRuns?: ReadonlyMap<string, string>;
|
|
39
|
+
readonly shownRuns?: ReadonlyMap<string, PdfShotRef[]>;
|
|
39
40
|
}
|
|
40
|
-
export declare function historyFromChunks(chunks: ReadonlyArray<AssistantChunk>, stale?: Partial<StaleToolRuns>, { sentRuns, askedRuns, readRuns }?: HistoryReplay): ChatMessage[];
|
|
41
|
+
export declare function historyFromChunks(chunks: ReadonlyArray<AssistantChunk>, stale?: Partial<StaleToolRuns>, { sentRuns, askedRuns, readRuns, shownRuns }?: HistoryReplay): ChatMessage[];
|
|
41
42
|
export interface RunPromptView {
|
|
42
43
|
readonly history: AssistantChunk[];
|
|
43
44
|
readonly stale: StaleToolRuns;
|
|
@@ -48,8 +49,16 @@ export declare function runPromptView(all: ReadonlyArray<AssistantChunk>, approv
|
|
|
48
49
|
export interface RoundReplay {
|
|
49
50
|
readonly sentRuns: Map<string, ChatMessage[]>;
|
|
50
51
|
readonly readRuns: Map<string, string>;
|
|
52
|
+
readonly shownRuns: Map<string, PdfShotRef[]>;
|
|
51
53
|
}
|
|
52
54
|
export declare function replayFromChunks(rounds: ReadonlyArray<AssistantChunk>): RoundReplay;
|
|
55
|
+
export interface CarriedRun {
|
|
56
|
+
readonly asked: string;
|
|
57
|
+
readonly toolTurns: ChatMessage[];
|
|
58
|
+
readonly firstRound: number;
|
|
59
|
+
}
|
|
60
|
+
export declare function carriedRun(rounds: ReadonlyArray<AssistantChunk>, runId: string): CarriedRun | null;
|
|
61
|
+
export declare function carriedInput(input: ChatMessage[], { asked, toolTurns }: CarriedRun): ChatMessage[];
|
|
53
62
|
export declare function sentTurn(chunk: AssistantChunk): string | undefined;
|
|
54
63
|
export declare function runView(chunks: ReadonlyArray<AssistantChunk>, { request, runId }: RunAt): AssistantChunk[];
|
|
55
64
|
export declare function foldableView(chunks: ReadonlyArray<AssistantChunk>, run?: RunAt): AssistantChunk[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { attachmentTurn, skillLoadedTurn } from '@qvac/harness/lib/capabilities/tool-turns.ts';
|
|
1
|
+
import { answeredToolTurns, attachmentTurn, isAnswer, skillLoadedTurn } from '@qvac/harness/lib/capabilities/tool-turns.ts';
|
|
2
2
|
import { HISTORY_CHUNK_TYPES } from '../core/chunk.js';
|
|
3
3
|
import { isAudioAttachment } from '../core/audio-attachment.js';
|
|
4
4
|
import { isDocumentAttachment, isPdfAttachment } from '../core/document-attachment.js';
|
|
@@ -8,7 +8,9 @@ import { isVideoAttachment } from '../core/video/attachment.js';
|
|
|
8
8
|
import { compactionTurn, foldCompactedChunks, foldPosition } from '../compaction.js';
|
|
9
9
|
import { attemptStarts, hiddenTranscriptText } from '../core/transcript-visibility.js';
|
|
10
10
|
import { acceptedRepairCount, historyBranches, isPromptChunk } from '../core/prompt-history.js';
|
|
11
|
+
import * as z from 'zod';
|
|
11
12
|
import { isChatMessage } from '../run-replay.js';
|
|
13
|
+
import { PdfBoundsSchema } from './pdf-pages.js';
|
|
12
14
|
import { isRecord } from '../guards.js';
|
|
13
15
|
import { STEERED } from '../run-input.js';
|
|
14
16
|
export function senderOf(chunk) {
|
|
@@ -23,12 +25,20 @@ export async function listHistoryChunks(engine, chatId) {
|
|
|
23
25
|
engine.listChunks({ chatId, type: 'tool-result' }),
|
|
24
26
|
engine.listChunks({ chatId, type: 'run-status' })
|
|
25
27
|
]);
|
|
28
|
+
const answered = new Set((toolResults.chunks ?? []).flatMap((chunk) => isAnswer(chunk.toolResult?.result) ? [callKey(chunk)] : []));
|
|
29
|
+
const calls = answered.size
|
|
30
|
+
? ((await engine.listChunks({ chatId, type: 'tool-call' })).chunks ?? [])
|
|
31
|
+
: [];
|
|
26
32
|
return [
|
|
27
33
|
...(history.chunks ?? []),
|
|
28
34
|
...(toolResults.chunks ?? []),
|
|
29
|
-
...(runStatuses.chunks ?? [])
|
|
35
|
+
...(runStatuses.chunks ?? []),
|
|
36
|
+
...calls.filter((chunk) => answered.has(callKey(chunk)))
|
|
30
37
|
].sort((a, b) => a.seq - b.seq);
|
|
31
38
|
}
|
|
39
|
+
function callKey(chunk) {
|
|
40
|
+
return `${chunk.runId ?? ''}:${chunk.callId ?? ''}`;
|
|
41
|
+
}
|
|
32
42
|
export function latestAttemptStarts(chunks) {
|
|
33
43
|
return attemptStarts(chunks);
|
|
34
44
|
}
|
|
@@ -59,7 +69,7 @@ function derivedAttachments(chunks) {
|
|
|
59
69
|
}
|
|
60
70
|
return derived;
|
|
61
71
|
}
|
|
62
|
-
export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), askedRuns = new Map(), readRuns = new Map() } = {}) {
|
|
72
|
+
export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), askedRuns = new Map(), readRuns = new Map(), shownRuns = new Map() } = {}) {
|
|
63
73
|
const attemptStarts = latestAttemptStarts(chunks);
|
|
64
74
|
const hiddenText = hiddenTranscriptText(chunks);
|
|
65
75
|
const staleRunIds = stale.runIds ?? new Set();
|
|
@@ -88,6 +98,7 @@ export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), as
|
|
|
88
98
|
const history = [];
|
|
89
99
|
const replayedSkills = new Set();
|
|
90
100
|
const answeredCalls = new Set();
|
|
101
|
+
const calls = new Map();
|
|
91
102
|
if (folded.summary) {
|
|
92
103
|
history.push({ role: 'user', content: compactionTurn(folded.summary) });
|
|
93
104
|
}
|
|
@@ -108,6 +119,10 @@ export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), as
|
|
|
108
119
|
if (asking && read !== undefined) {
|
|
109
120
|
asking.readContent = read;
|
|
110
121
|
}
|
|
122
|
+
const shown = live ? shownRuns.get(live) : undefined;
|
|
123
|
+
if (asking && shown) {
|
|
124
|
+
asking.pdfShots = shown;
|
|
125
|
+
}
|
|
111
126
|
const sent = live ? sentRuns.get(live) : undefined;
|
|
112
127
|
if (sent) {
|
|
113
128
|
const replayed = sent.map((message) => shownAgain(message, byId));
|
|
@@ -175,7 +190,26 @@ export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), as
|
|
|
175
190
|
anchor(chunk.runId);
|
|
176
191
|
continue;
|
|
177
192
|
}
|
|
193
|
+
if (chunk.toolCall) {
|
|
194
|
+
calls.set(callKey(chunk), chunk);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
178
197
|
if (chunk.toolResult && chunk.runId && sentRuns.has(chunk.runId)) {
|
|
198
|
+
const call = calls.get(callKey(chunk))?.toolCall;
|
|
199
|
+
const live = !staleRunIds.has(chunk.runId) && !beforeLatestAttempt(chunk, attemptStarts);
|
|
200
|
+
if (call &&
|
|
201
|
+
chunk.callId &&
|
|
202
|
+
isAnswer(chunk.toolResult.result) &&
|
|
203
|
+
live &&
|
|
204
|
+
!repeatedCall(chunk, answeredCalls)) {
|
|
205
|
+
const turns = answeredToolTurns({
|
|
206
|
+
name: call.name,
|
|
207
|
+
id: chunk.callId,
|
|
208
|
+
arguments: isRecord(call.arguments) ? call.arguments : {}
|
|
209
|
+
});
|
|
210
|
+
history.splice(history.indexOf(anchor(chunk.runId)), 0, ...turns);
|
|
211
|
+
turns.forEach((turn) => kept.add(turn));
|
|
212
|
+
}
|
|
179
213
|
continue;
|
|
180
214
|
}
|
|
181
215
|
if (chunk.toolResult?.name === SKILL_TOOL) {
|
|
@@ -263,6 +297,7 @@ export function runPromptView(all, approvals, run) {
|
|
|
263
297
|
export function replayFromChunks(rounds) {
|
|
264
298
|
const sentRuns = new Map();
|
|
265
299
|
const readRuns = new Map();
|
|
300
|
+
const shownRuns = new Map();
|
|
266
301
|
for (const chunk of rounds) {
|
|
267
302
|
if (!chunk.runId)
|
|
268
303
|
continue;
|
|
@@ -270,6 +305,10 @@ export function replayFromChunks(rounds) {
|
|
|
270
305
|
if (sent !== undefined) {
|
|
271
306
|
readRuns.set(chunk.runId, sent);
|
|
272
307
|
}
|
|
308
|
+
const shots = sentShots(chunk);
|
|
309
|
+
if (shots) {
|
|
310
|
+
shownRuns.set(chunk.runId, shots);
|
|
311
|
+
}
|
|
273
312
|
const turns = chunk.modelRequest?.state === 'done' ? chunk.modelRequest.toolTurns : undefined;
|
|
274
313
|
if (Array.isArray(turns)) {
|
|
275
314
|
sentRuns.set(chunk.runId, turns
|
|
@@ -277,12 +316,43 @@ export function replayFromChunks(rounds) {
|
|
|
277
316
|
.map(({ role, content, imageIds }) => imageIds ? { role, content, imageIds } : { role, content }));
|
|
278
317
|
}
|
|
279
318
|
}
|
|
280
|
-
return { sentRuns, readRuns };
|
|
319
|
+
return { sentRuns, readRuns, shownRuns };
|
|
320
|
+
}
|
|
321
|
+
export function carriedRun(rounds, runId) {
|
|
322
|
+
const own = rounds.filter((chunk) => chunk.runId === runId);
|
|
323
|
+
const read = own.findLast((chunk) => sentTurn(chunk) !== undefined);
|
|
324
|
+
const asked = read && sentTurn(read);
|
|
325
|
+
const turns = own.findLast((chunk) => chunk.modelRequest)?.modelRequest?.toolTurns;
|
|
326
|
+
const toolTurns = Array.isArray(turns) ? turns.filter(isChatMessage) : [];
|
|
327
|
+
if (asked === undefined || toolTurns.length === 0) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
const numbers = own.flatMap((chunk) => chunk.modelRequest?.round ?? []);
|
|
331
|
+
return {
|
|
332
|
+
asked,
|
|
333
|
+
toolTurns: toolTurns.map(({ role, content }) => ({ role, content })),
|
|
334
|
+
firstRound: Math.max(...numbers) + 1
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
export function carriedInput(input, { asked, toolTurns }) {
|
|
338
|
+
const at = input.findLastIndex((turn) => turn.role === 'user');
|
|
339
|
+
const turns = input.map((turn, index) => index === at ? { role: 'user', content: asked } : turn);
|
|
340
|
+
return [...turns, ...toolTurns];
|
|
281
341
|
}
|
|
282
342
|
export function sentTurn(chunk) {
|
|
283
343
|
const turn = chunk.context?.turn;
|
|
284
344
|
return isRecord(turn) && typeof turn.sent === 'string' ? turn.sent : undefined;
|
|
285
345
|
}
|
|
346
|
+
const SentShots = z.array(z.object({
|
|
347
|
+
id: z.string(),
|
|
348
|
+
page: z.number().int().nonnegative(),
|
|
349
|
+
clip: PdfBoundsSchema.optional()
|
|
350
|
+
}));
|
|
351
|
+
function sentShots(chunk) {
|
|
352
|
+
const turn = chunk.context?.turn;
|
|
353
|
+
const shots = isRecord(turn) ? SentShots.safeParse(turn.shots) : null;
|
|
354
|
+
return shots?.success ? shots.data : undefined;
|
|
355
|
+
}
|
|
286
356
|
export function runView(chunks, { request, runId }) {
|
|
287
357
|
const fixed = !!request.requesterMemberId;
|
|
288
358
|
const seqs = new Map();
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { MediaRoundOutput, MediaRoundResult } from '@qvac/harness/lib/contract/index.ts';
|
|
2
|
+
import type { AbortSignal } from 'bare-abort-controller';
|
|
3
|
+
import * as z from 'zod';
|
|
4
|
+
import type { ScopedCapabilities } from '../mesh-scoped-engine.ts';
|
|
5
|
+
import { type MediaKind } from '../probe-rounds.ts';
|
|
6
|
+
export declare const MODEL_MISSING = "model-missing";
|
|
7
|
+
export declare const mediaOptions: z.ZodObject<{
|
|
8
|
+
modelChoice: z.ZodOptional<z.ZodString>;
|
|
9
|
+
params: z.ZodCustom<Record<string, unknown>, Record<string, unknown>>;
|
|
10
|
+
sources: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
11
|
+
refs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
12
|
+
attachmentId: z.ZodString;
|
|
13
|
+
width: z.ZodNumber;
|
|
14
|
+
height: z.ZodNumber;
|
|
15
|
+
}, z.core.$strip>>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export type MediaOptions = z.infer<typeof mediaOptions>;
|
|
18
|
+
declare const settled: z.ZodUnion<readonly [z.ZodObject<{
|
|
19
|
+
error: z.ZodString;
|
|
20
|
+
code: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
22
|
+
kind: z.ZodLiteral<"image">;
|
|
23
|
+
blobId: z.ZodString;
|
|
24
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
25
|
+
kind: z.ZodLiteral<"music">;
|
|
26
|
+
blobId: z.ZodString;
|
|
27
|
+
format: z.ZodObject<{
|
|
28
|
+
sampleRate: z.ZodNumber;
|
|
29
|
+
channels: z.ZodNumber;
|
|
30
|
+
bitsPerSample: z.ZodNumber;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
gpuRequested: z.ZodBoolean;
|
|
33
|
+
stats: z.ZodOptional<z.ZodObject<{
|
|
34
|
+
audioDurationMs: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
totalTimeMs: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
realTimeFactor: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
backendDevice: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
backendId: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
}, z.core.$strip>>;
|
|
40
|
+
}, z.core.$strip>]>;
|
|
41
|
+
export type MediaSettled = z.infer<typeof settled>;
|
|
42
|
+
export declare function mediaKindOf(options: unknown): MediaKind | undefined;
|
|
43
|
+
export declare function isModelMissing(err: unknown): boolean;
|
|
44
|
+
export declare function putBlob(engine: ScopedCapabilities, meshId: string, bytes: Uint8Array): Promise<string>;
|
|
45
|
+
interface ChatAttachment {
|
|
46
|
+
readonly chatId: string;
|
|
47
|
+
readonly attachmentId: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function readBlob(engine: ScopedCapabilities, blobId: string, signal: AbortSignal): Promise<Uint8Array>;
|
|
50
|
+
export declare function readAttachment(engine: ScopedCapabilities, { chatId, attachmentId }: ChatAttachment, signal: AbortSignal): Promise<Uint8Array>;
|
|
51
|
+
export interface Generated {
|
|
52
|
+
readonly bytes: Uint8Array;
|
|
53
|
+
readonly blobId: string;
|
|
54
|
+
}
|
|
55
|
+
export interface MediaOutput {
|
|
56
|
+
readonly result: MediaRoundResult;
|
|
57
|
+
readonly generated?: Generated;
|
|
58
|
+
}
|
|
59
|
+
export declare function mediaOutputFrom(engine: ScopedCapabilities, result: unknown, signal: AbortSignal): Promise<MediaOutput>;
|
|
60
|
+
export declare function storedBytes(output: MediaRoundOutput): Uint8Array;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { pcmToWav } from '@qvac/harness/plugins/music';
|
|
3
|
+
import { AbortedError } from '@qvac/harness/race-abort';
|
|
4
|
+
import * as z from 'zod';
|
|
5
|
+
import { isRecord } from '../guards.js';
|
|
6
|
+
import { MEDIA_KINDS } from '../probe-rounds.js';
|
|
7
|
+
const MODEL_MISSING_CODE = 102108;
|
|
8
|
+
export const MODEL_MISSING = 'model-missing';
|
|
9
|
+
const UPLOAD_FRAME_BYTES = 64 * 1024;
|
|
10
|
+
const WAV_HEADER_BYTES = 44;
|
|
11
|
+
export const mediaOptions = z.object({
|
|
12
|
+
modelChoice: z.string().optional(),
|
|
13
|
+
params: z.custom((value) => isRecord(value)),
|
|
14
|
+
sources: z.array(z.string()).optional(),
|
|
15
|
+
refs: z
|
|
16
|
+
.array(z.object({ attachmentId: z.string(), width: z.number(), height: z.number() }))
|
|
17
|
+
.optional()
|
|
18
|
+
});
|
|
19
|
+
const format = z.object({
|
|
20
|
+
sampleRate: z.number().positive(),
|
|
21
|
+
channels: z.number().positive(),
|
|
22
|
+
bitsPerSample: z.number().positive()
|
|
23
|
+
});
|
|
24
|
+
const stats = z.object({
|
|
25
|
+
audioDurationMs: z.number().optional(),
|
|
26
|
+
totalTimeMs: z.number().optional(),
|
|
27
|
+
realTimeFactor: z.number().optional(),
|
|
28
|
+
backendDevice: z.number().optional(),
|
|
29
|
+
backendId: z.number().optional()
|
|
30
|
+
});
|
|
31
|
+
const settled = z.union([
|
|
32
|
+
z.object({ error: z.string(), code: z.string().optional() }),
|
|
33
|
+
z.object({ kind: z.literal('image'), blobId: z.string() }),
|
|
34
|
+
z.object({
|
|
35
|
+
kind: z.literal('music'),
|
|
36
|
+
blobId: z.string(),
|
|
37
|
+
format,
|
|
38
|
+
gpuRequested: z.boolean(),
|
|
39
|
+
stats: stats.optional()
|
|
40
|
+
})
|
|
41
|
+
]);
|
|
42
|
+
export function mediaKindOf(options) {
|
|
43
|
+
const kind = isRecord(options) ? options.kind : undefined;
|
|
44
|
+
return MEDIA_KINDS.find((known) => known === kind);
|
|
45
|
+
}
|
|
46
|
+
export function isModelMissing(err) {
|
|
47
|
+
return isRecord(err) && err.code === MODEL_MISSING_CODE;
|
|
48
|
+
}
|
|
49
|
+
export async function putBlob(engine, meshId, bytes) {
|
|
50
|
+
const duplex = engine.putBlob();
|
|
51
|
+
const buf = b4a.toBuffer(bytes);
|
|
52
|
+
duplex.write({ meshId });
|
|
53
|
+
for (let at = 0; at < buf.length; at += UPLOAD_FRAME_BYTES) {
|
|
54
|
+
duplex.write({ data: buf.subarray(at, at + UPLOAD_FRAME_BYTES) });
|
|
55
|
+
}
|
|
56
|
+
duplex.end();
|
|
57
|
+
let blobId = null;
|
|
58
|
+
for await (const frame of duplex) {
|
|
59
|
+
blobId = frame.blobId || blobId;
|
|
60
|
+
}
|
|
61
|
+
if (!blobId) {
|
|
62
|
+
throw new Error('blob write ended without a reference');
|
|
63
|
+
}
|
|
64
|
+
return blobId;
|
|
65
|
+
}
|
|
66
|
+
export function readBlob(engine, blobId, signal) {
|
|
67
|
+
return collect(engine.downloadAttachment({ blobId }), signal);
|
|
68
|
+
}
|
|
69
|
+
async function collect(stream, signal) {
|
|
70
|
+
const abort = () => stream.destroy();
|
|
71
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
72
|
+
const pieces = [];
|
|
73
|
+
try {
|
|
74
|
+
for await (const frame of stream) {
|
|
75
|
+
if (frame.data) {
|
|
76
|
+
pieces.push(frame.data);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
signal.removeEventListener('abort', abort);
|
|
82
|
+
stream.destroy();
|
|
83
|
+
}
|
|
84
|
+
if (signal.aborted) {
|
|
85
|
+
throw new AbortedError();
|
|
86
|
+
}
|
|
87
|
+
return b4a.concat(pieces);
|
|
88
|
+
}
|
|
89
|
+
export function readAttachment(engine, { chatId, attachmentId }, signal) {
|
|
90
|
+
return collect(engine.fileRead({ chatId, fileId: attachmentId }), signal);
|
|
91
|
+
}
|
|
92
|
+
export async function mediaOutputFrom(engine, result, signal) {
|
|
93
|
+
const parsed = settled.parse(result);
|
|
94
|
+
if ('error' in parsed) {
|
|
95
|
+
return { result: parsed };
|
|
96
|
+
}
|
|
97
|
+
const bytes = await readBlob(engine, parsed.blobId, signal);
|
|
98
|
+
const generated = { bytes, blobId: parsed.blobId };
|
|
99
|
+
if (parsed.kind === 'image') {
|
|
100
|
+
return { result: { kind: 'image', bytes }, generated };
|
|
101
|
+
}
|
|
102
|
+
const { format: audio, gpuRequested, stats: report } = parsed;
|
|
103
|
+
const pcm = bytes.subarray(WAV_HEADER_BYTES);
|
|
104
|
+
return {
|
|
105
|
+
result: { kind: 'music', bytes: pcm, format: audio, gpuRequested, stats: report },
|
|
106
|
+
generated
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function storedBytes(output) {
|
|
110
|
+
return output.kind === 'image' ? output.bytes : pcmToWav({ pcm: output.bytes, ...output.format });
|
|
111
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DocumentAttachment } from '../core/document-attachment.ts';
|
|
2
|
+
import type { PdfBounds } from '../core/pdf/figure.ts';
|
|
2
3
|
export interface ChatMessage {
|
|
3
4
|
role: 'user' | 'assistant' | 'tool';
|
|
4
5
|
content: string;
|
|
@@ -15,6 +16,12 @@ export interface ChatMessage {
|
|
|
15
16
|
videos?: VideoRef[];
|
|
16
17
|
documents?: DocumentAttachment[];
|
|
17
18
|
pdfs?: PdfRef[];
|
|
19
|
+
pdfShots?: PdfShotRef[];
|
|
20
|
+
}
|
|
21
|
+
export interface PdfShotRef {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly page: number;
|
|
24
|
+
readonly clip?: PdfBounds;
|
|
18
25
|
}
|
|
19
26
|
export declare function earlierImages(messages: ReadonlyArray<ChatMessage>): Set<string>;
|
|
20
27
|
export declare function claimNewImages(messages: unknown, sent: Set<string>): boolean;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ModelRoundIo, type ModelRoundPort, type ModelRoundRequest } from '@qvac/harness';
|
|
2
|
+
import type { MediaRoundPort } from '@qvac/harness/lib/contract/index.ts';
|
|
2
3
|
import type { AbortSignal } from 'bare-abort-controller';
|
|
4
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
3
5
|
import type { AssistantChunk, AssistantChunkContentModelRequest, AssistantChunkDelta } from '../../spec/hyperschema/types.d.ts';
|
|
4
6
|
import type { ScopedCapabilities } from '../mesh-scoped-engine.ts';
|
|
5
7
|
import { type AttachmentRef } from './message.ts';
|
|
@@ -28,6 +30,9 @@ export interface OwnerRoundsOptions {
|
|
|
28
30
|
readonly from: number;
|
|
29
31
|
readonly media?: ((file: string) => MediaRef | undefined) | undefined;
|
|
30
32
|
readonly inspect?: ((call: Record<string, unknown>) => void) | undefined;
|
|
33
|
+
readonly meshId?: string | undefined;
|
|
34
|
+
readonly local?: MediaRoundPort | undefined;
|
|
35
|
+
readonly log?: LoggerInterface | null | undefined;
|
|
31
36
|
}
|
|
32
37
|
interface Echo {
|
|
33
38
|
readonly type: 'content' | 'thinking';
|
|
@@ -44,9 +49,16 @@ export interface OutputHooks {
|
|
|
44
49
|
forwarded(echo: Echo): void;
|
|
45
50
|
retook(): void;
|
|
46
51
|
}
|
|
52
|
+
export declare class Echoes {
|
|
53
|
+
private readonly _pending;
|
|
54
|
+
forwarded({ type, text }: Echo): void;
|
|
55
|
+
own(type: Echo['type'], text: string): string;
|
|
56
|
+
}
|
|
47
57
|
export declare class OwnerRounds {
|
|
48
58
|
readonly port: ModelRoundPort;
|
|
59
|
+
readonly media: MediaRoundPort;
|
|
49
60
|
inputLength: number;
|
|
61
|
+
roundBase: number;
|
|
50
62
|
share: ((agentId: string) => Promise<void>) | null;
|
|
51
63
|
private readonly _opts;
|
|
52
64
|
private readonly _echoes;
|
|
@@ -55,14 +67,18 @@ export declare class OwnerRounds {
|
|
|
55
67
|
private _rounds;
|
|
56
68
|
private _retakes;
|
|
57
69
|
private readonly _takers;
|
|
70
|
+
private readonly _generated;
|
|
58
71
|
constructor(opts: OwnerRoundsOptions);
|
|
59
72
|
get rounds(): number;
|
|
60
73
|
ranHere(round: number | undefined): boolean;
|
|
61
74
|
retook(): boolean;
|
|
62
|
-
|
|
75
|
+
unechoed(type: Echo['type'], text: string): string;
|
|
63
76
|
retire(): Promise<void>;
|
|
64
77
|
private _round;
|
|
65
78
|
probe({ kind, prompt, modelId, responseFormat, signal }: Probe): Promise<string>;
|
|
79
|
+
private _generate;
|
|
80
|
+
generated(bytes: Uint8Array): string | undefined;
|
|
81
|
+
private _named;
|
|
66
82
|
private _probed;
|
|
67
83
|
private _dropOnHostLoss;
|
|
68
84
|
private _ask;
|
|
@@ -70,6 +86,7 @@ export declare class OwnerRounds {
|
|
|
70
86
|
private _switchedTo;
|
|
71
87
|
private _sendContext;
|
|
72
88
|
private _options;
|
|
89
|
+
private _pdfShots;
|
|
73
90
|
private _namedImages;
|
|
74
91
|
private _media;
|
|
75
92
|
private _knownSets;
|
|
@@ -90,6 +107,7 @@ export declare class RoundOutput {
|
|
|
90
107
|
private _resetAt;
|
|
91
108
|
constructor(id: string, io: ModelRoundIo, hooks: OutputHooks);
|
|
92
109
|
apply(frame: AssistantChunkDelta): AssistantChunkContentModelRequest | undefined;
|
|
110
|
+
hold(): void;
|
|
93
111
|
reask(id: string, emit: ModelRoundIo['emit']): void;
|
|
94
112
|
round(): AssistantChunkContentModelRequest | undefined;
|
|
95
113
|
switchedTo(from: number): string | undefined;
|