@qvac/harness 1.0.0-rc.16 → 1.0.0-rc.18
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 +139 -2
- package/dist-lib/index.d.ts +6 -2
- package/dist-lib/index.js +17 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +28 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +13 -8
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +6 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +1 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +2 -2
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/durable.js +7 -1
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/operations.js +28 -9
- package/dist-lib/lib/capabilities/completion-engine/ports.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +3 -1
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/session.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +2 -1
- package/dist-lib/lib/capabilities/completion-engine/turns.js +5 -2
- package/dist-lib/lib/capabilities/enhance.js +3 -3
- package/dist-lib/lib/capabilities/sdk-tool.d.ts +1 -1
- package/dist-lib/lib/capabilities/sdk-tool.js +3 -2
- package/dist-lib/lib/capabilities/skill-entry.d.ts +9 -1
- package/dist-lib/lib/capabilities/skill-entry.js +11 -7
- package/dist-lib/lib/capabilities/tool-turns.d.ts +5 -0
- package/dist-lib/lib/capabilities/tool-turns.js +24 -27
- package/dist-lib/lib/client/index.js +3 -2
- package/dist-lib/lib/connect.d.ts +2 -0
- package/dist-lib/lib/connect.js +33 -3
- package/dist-lib/lib/contract/completion.d.ts +14 -0
- package/dist-lib/lib/contract/exec.d.ts +1 -0
- package/dist-lib/lib/contract/ocr.d.ts +4 -0
- package/dist-lib/lib/contract/run.d.ts +8 -0
- package/dist-lib/lib/contract-types.d.ts +4 -1
- package/dist-lib/lib/errors.d.ts +4 -0
- package/dist-lib/lib/errors.js +5 -1
- package/dist-lib/lib/guards.d.ts +2 -0
- package/dist-lib/lib/guards.js +7 -0
- package/dist-lib/lib/hardware/capability-probe.js +10 -7
- package/dist-lib/lib/hardware/gpu-probe-addon.js +26 -11
- package/dist-lib/lib/hardware/gpu-stats.native.cjs +17 -1
- package/dist-lib/lib/helpers/completion-params.d.ts +2 -1
- package/dist-lib/lib/helpers/completion-params.js +16 -1
- package/dist-lib/lib/helpers/control-tokens.d.ts +3 -0
- package/dist-lib/lib/helpers/control-tokens.js +25 -0
- package/dist-lib/lib/machine/completion/actions/completion.js +34 -5
- package/dist-lib/lib/machine/completion/actions/tools.js +4 -1
- package/dist-lib/lib/machine/completion/rules.d.ts +2 -0
- package/dist-lib/lib/machine/completion/rules.js +7 -0
- package/dist-lib/lib/machine/completion/types.d.ts +6 -0
- package/dist-lib/lib/machine/index.d.ts +2 -1
- package/dist-lib/lib/machine/index.js +2 -1
- package/dist-lib/lib/no-redirect-fetch-impl.d.ts +1 -1
- package/dist-lib/lib/no-redirect-fetch-impl.js +13 -7
- package/dist-lib/lib/office/engine/xlsx/sheet.js +10 -4
- package/dist-lib/lib/plugins/registry.d.ts +3 -0
- package/dist-lib/lib/plugins/registry.js +15 -1
- package/dist-lib/lib/plugins/require-bare.d.ts +1 -0
- package/dist-lib/lib/plugins/require-bare.js +13 -0
- package/dist-lib/lib/run-log/request-codec.js +2 -2
- package/dist-lib/lib/serve.js +38 -1
- package/dist-lib/lib/sidecar/index.d.ts +1 -1
- package/dist-lib/lib/sidecar/index.js +5 -6
- package/dist-lib/lib/skills-host/index.js +13 -8
- package/dist-lib/lib/spawn.d.ts +2 -0
- package/dist-lib/lib/spawn.js +5 -3
- package/dist-lib/lib/tools/ask-user.d.ts +2 -0
- package/dist-lib/lib/tools/ask-user.js +137 -0
- package/dist-lib/lib/tools/attachments/delivered.d.ts +5 -0
- package/dist-lib/lib/tools/attachments/delivered.js +16 -0
- package/dist-lib/lib/tools/attachments/fetched-file.d.ts +32 -0
- package/dist-lib/lib/tools/attachments/fetched-file.js +134 -0
- package/dist-lib/lib/tools/exec.js +2 -1
- package/dist-lib/lib/tools/fs/document-text.js +3 -26
- package/dist-lib/lib/tools/http-request/request.d.ts +2 -2
- package/dist-lib/lib/tools/http-request/request.js +1 -1
- package/dist-lib/lib/tools/http-request.d.ts +1 -0
- package/dist-lib/lib/tools/http-request.js +54 -3
- package/dist-lib/lib/tools/index.d.ts +3 -1
- package/dist-lib/lib/tools/index.js +6 -2
- package/dist-lib/lib/tools/office.js +20 -12
- package/dist-lib/lib/tools/pdf/pages.d.ts +12 -0
- package/dist-lib/lib/tools/pdf/pages.js +28 -0
- package/dist-lib/lib/tools/pdf.js +24 -9
- package/dist-lib/lib/tools/skills/bundled-dir.d.ts +5 -1
- package/dist-lib/lib/tools/skills/bundled-dir.js +23 -20
- package/dist-lib/lib/tools/skills/catalog.d.ts +1 -1
- package/dist-lib/lib/tools/skills/catalog.js +1 -1
- package/dist-lib/lib/tools/skills/overlay-crud.d.ts +3 -3
- package/dist-lib/lib/tools/skills/overlay-crud.js +4 -4
- package/dist-lib/lib/tools/skills/scope-key.d.ts +1 -0
- package/dist-lib/lib/tools/skills/scope-key.js +4 -0
- package/dist-lib/lib/tools/web-fetch.js +41 -130
- package/dist-lib/plugins/knowledge/index.js +3 -3
- package/dist-lib/plugins/mcp/call.js +5 -1
- package/dist-lib/plugins/mcp/protocol.d.ts +6 -1
- package/dist-lib/plugins/mcp/protocol.js +2 -2
- package/dist-lib/plugins/ocr/reading-order.js +151 -4
- package/dist-lib/plugins/python/bare-floor.d.ts +1 -0
- package/dist-lib/plugins/python/bare-floor.js +2 -0
- package/dist-lib/plugins/python/index.d.ts +1 -0
- package/dist-lib/plugins/python/index.js +1 -0
- package/dist-lib/plugins/python/language.js +9 -8
- package/dist-lib/plugins/python/python-adapter.d.ts +4 -0
- package/dist-lib/plugins/python/python-adapter.js +26 -0
- package/dist-lib/plugins/python/worker/client.js +1 -1
- package/dist-lib/plugins/python/worker/entry.js +2 -8
- package/dist-lib/plugins/python/worker/preload.d.ts +1 -0
- package/dist-lib/plugins/python/worker/preload.js +2 -0
- package/dist-lib/plugins/python/worker/spawn.js +1 -1
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-arm64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/sandbox-windows/prebuilds/win32-x64/qvac-sandbox.exe +0 -0
- package/dist-lib/plugins/weather/lookup.js +1 -0
- package/dist-lib/schema/harness.js +17 -0
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +32 -0
- package/dist-lib/spec/hyperschema/index.js +32 -0
- package/dist-lib/spec/hyperschema/schema.json +40 -0
- package/dist-lib/spec/hyperschema/types.d.ts +12 -0
- package/package.json +18 -9
|
@@ -60,21 +60,20 @@ export class HarnessSidecar {
|
|
|
60
60
|
HarnessLog.setSink((line, level) => log[level](SCOPE, line));
|
|
61
61
|
captureConsole(log);
|
|
62
62
|
await alignSdkConsoleWithHost(hostWantsLogs);
|
|
63
|
-
const skillsDir = argv[2] ||
|
|
63
|
+
const skillsDir = argv[2] || undefined;
|
|
64
64
|
if (argv[11]) {
|
|
65
65
|
process.env.QVAC_PYTHON_WHEELS_DIR = argv[11];
|
|
66
66
|
}
|
|
67
67
|
configureSdkStorage(sdkStorage);
|
|
68
68
|
process.env.QVAC_PYODIDE_CACHE_DIR = `${sdkStorage.home}/pyodide-cache`;
|
|
69
|
-
const skillCatalog =
|
|
70
|
-
const credentialStore =
|
|
71
|
-
? (key, ctx) => harness?.resolveCredential(key, ctx) ?? null
|
|
72
|
-
: undefined;
|
|
69
|
+
const skillCatalog = await loadSkillCatalog(skillsDir ?? null);
|
|
70
|
+
const credentialStore = (key, ctx) => harness?.resolveCredential(key, ctx) ?? null;
|
|
73
71
|
const tools = Tools.product({
|
|
74
72
|
sdkHome: sdkStorage.home,
|
|
75
73
|
skillsDir,
|
|
76
74
|
skillCatalog,
|
|
77
|
-
credentialStore
|
|
75
|
+
credentialStore,
|
|
76
|
+
ask: argv[15] === '1'
|
|
78
77
|
});
|
|
79
78
|
const plugins = this._plugins(pluginContext(argv, { sdkStorage, skillsDir, skillCatalog, credentialStore }));
|
|
80
79
|
harness = new Harness({
|
|
@@ -4,13 +4,12 @@ import { errorMessage } from '../guards.js';
|
|
|
4
4
|
import { HarnessLog } from '../log.js';
|
|
5
5
|
import { modelNameToCapabilityProfile } from '../models/model-catalog.js';
|
|
6
6
|
import { probeBinVersions } from '../tools/skills/bin-check.js';
|
|
7
|
-
import { ensureBundledSkillsDir } from '../tools/skills/bundled-dir.js';
|
|
8
7
|
import { availableSkills, detectPlatform, loadSkillCatalog, resolveSkillStatuses, skillSupportsPlatform, versionProbeSkills } from '../tools/skills/catalog.js';
|
|
9
8
|
import { resetCredentialHealth } from '../tools/skills/credential-health.js';
|
|
10
9
|
import { ensureSkillsOverlayDir } from '../tools/skills/overlay-dir.js';
|
|
11
10
|
import { copyBaseForEdit, deleteOverlaySkill, listManagedSkills, readSkillFile, writeSkillFile } from '../tools/skills/overlay-crud.js';
|
|
12
11
|
import { watchSkillsOverlay } from '../tools/skills/overlay-watch.js';
|
|
13
|
-
import { deviceSharedKeys, scopeKey } from '../tools/skills/scope-key.js';
|
|
12
|
+
import { deviceSharedKeys, parseScopeKey, scopeKey } from '../tools/skills/scope-key.js';
|
|
14
13
|
import { settingsScopeKey } from '../tools/skills/skill-settings.js';
|
|
15
14
|
import { bareRuntime } from '../tools/exec/bare-runtime.js';
|
|
16
15
|
import { runCommand } from '../tools/exec/runner.js';
|
|
@@ -68,6 +67,12 @@ export class SkillsHost {
|
|
|
68
67
|
}
|
|
69
68
|
next.set(storeKey, record);
|
|
70
69
|
}
|
|
70
|
+
for (const storeKey of previous.keys()) {
|
|
71
|
+
if (!next.has(storeKey)) {
|
|
72
|
+
const { key, agentId, skill } = parseScopeKey(storeKey);
|
|
73
|
+
resetCredentialHealth(key, agentId, skill);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
71
76
|
this._credentials = next;
|
|
72
77
|
}
|
|
73
78
|
setSkillSettings(entries) {
|
|
@@ -92,10 +97,10 @@ export class SkillsHost {
|
|
|
92
97
|
return this._allSkills.find((entry) => entry.name === skill)?.env;
|
|
93
98
|
}
|
|
94
99
|
async listManagedSkills() {
|
|
95
|
-
return listManagedSkills(
|
|
100
|
+
return listManagedSkills(this._baseDir(), await ensureSkillsOverlayDir());
|
|
96
101
|
}
|
|
97
102
|
async readSkillFile(name) {
|
|
98
|
-
return readSkillFile(
|
|
103
|
+
return readSkillFile(this._baseDir(), await ensureSkillsOverlayDir(), name);
|
|
99
104
|
}
|
|
100
105
|
async writeSkillFile(name, content) {
|
|
101
106
|
const overlay = await this._overlayDir();
|
|
@@ -105,7 +110,7 @@ export class SkillsHost {
|
|
|
105
110
|
}
|
|
106
111
|
async copyBaseForEdit(name) {
|
|
107
112
|
const overlay = await this._overlayDir();
|
|
108
|
-
const result = await copyBaseForEdit(
|
|
113
|
+
const result = await copyBaseForEdit(this._baseDir(), overlay, name);
|
|
109
114
|
if (result.copied) {
|
|
110
115
|
await this._reload();
|
|
111
116
|
}
|
|
@@ -180,8 +185,8 @@ export class SkillsHost {
|
|
|
180
185
|
_installedTools() {
|
|
181
186
|
return new Set(this._tools().map((tool) => tool.name));
|
|
182
187
|
}
|
|
183
|
-
|
|
184
|
-
return this._skillsDir ??
|
|
188
|
+
_baseDir() {
|
|
189
|
+
return this._skillsDir ?? null;
|
|
185
190
|
}
|
|
186
191
|
async _overlayDir() {
|
|
187
192
|
const overlay = await ensureSkillsOverlayDir();
|
|
@@ -191,7 +196,7 @@ export class SkillsHost {
|
|
|
191
196
|
return overlay;
|
|
192
197
|
}
|
|
193
198
|
async _reload() {
|
|
194
|
-
this._allSkills = await loadSkillCatalog(
|
|
199
|
+
this._allSkills = await loadSkillCatalog(this._baseDir(), { platform: null });
|
|
195
200
|
this._filter();
|
|
196
201
|
}
|
|
197
202
|
_filter() {
|
package/dist-lib/lib/spawn.d.ts
CHANGED
|
@@ -68,6 +68,7 @@ export interface HarnessChildOptions {
|
|
|
68
68
|
llm?: HarnessLlmConfig;
|
|
69
69
|
knowledge?: HarnessKnowledgeConfig;
|
|
70
70
|
pluginOptions?: HarnessPluginOptions;
|
|
71
|
+
ask?: boolean;
|
|
71
72
|
onIpc?: (ipc: StowIpc) => void;
|
|
72
73
|
logger?: Logger | null;
|
|
73
74
|
deps?: string[];
|
|
@@ -94,6 +95,7 @@ export interface SpawnHarnessOptions {
|
|
|
94
95
|
llm?: HarnessLlmConfig;
|
|
95
96
|
knowledge?: HarnessKnowledgeConfig;
|
|
96
97
|
pluginOptions?: HarnessPluginOptions;
|
|
98
|
+
ask?: boolean;
|
|
97
99
|
logger?: Logger | null;
|
|
98
100
|
}
|
|
99
101
|
export declare function spawnHarness(opts: SpawnHarnessOptions): RemoteHarness;
|
package/dist-lib/lib/spawn.js
CHANGED
|
@@ -7,7 +7,7 @@ export function harnessChild(entry, opts) {
|
|
|
7
7
|
if (opts.logger) {
|
|
8
8
|
HarnessLog.toHost(opts.logger);
|
|
9
9
|
}
|
|
10
|
-
const { runner, skillsDir, gpuStats, wheelsDir, sdkStorage, embedDevice, embedGpuLayers, embedBatchSize, imageModel, imageClamps, musicModel, musicClamps, llm, knowledge, pluginOptions, onIpc, logger = null, ...spec } = opts;
|
|
10
|
+
const { runner, skillsDir, gpuStats, wheelsDir, sdkStorage, embedDevice, embedGpuLayers, embedBatchSize, imageModel, imageClamps, musicModel, musicClamps, llm, knowledge, pluginOptions, ask, onIpc, logger = null, ...spec } = opts;
|
|
11
11
|
const embedConfig = createEmbedConfig({
|
|
12
12
|
device: embedDevice,
|
|
13
13
|
gpuLayers: embedGpuLayers,
|
|
@@ -29,7 +29,8 @@ export function harnessChild(entry, opts) {
|
|
|
29
29
|
wheelsDir ?? '',
|
|
30
30
|
gpuStats === undefined ? '' : JSON.stringify(gpuStats),
|
|
31
31
|
knowledge ? JSON.stringify(knowledge) : '',
|
|
32
|
-
pluginOptions ? JSON.stringify(pluginOptions) : ''
|
|
32
|
+
pluginOptions ? JSON.stringify(pluginOptions) : '',
|
|
33
|
+
ask ? '1' : ''
|
|
33
34
|
],
|
|
34
35
|
logger,
|
|
35
36
|
create: (ipc) => {
|
|
@@ -63,7 +64,8 @@ export function spawnHarness(opts) {
|
|
|
63
64
|
opts.wheelsDir ?? '',
|
|
64
65
|
opts.gpuStats === undefined ? '' : JSON.stringify(opts.gpuStats),
|
|
65
66
|
opts.knowledge ? JSON.stringify(opts.knowledge) : '',
|
|
66
|
-
opts.pluginOptions ? JSON.stringify(opts.pluginOptions) : ''
|
|
67
|
+
opts.pluginOptions ? JSON.stringify(opts.pluginOptions) : '',
|
|
68
|
+
opts.ask ? '1' : ''
|
|
67
69
|
], logger);
|
|
68
70
|
const died = exit.then((code) => new HarnessError('HARNESS_EXITED_BEFORE_READY', [code]));
|
|
69
71
|
const failure = await Promise.race([ipc.ready.then(() => null), died]);
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { isRecord } from '../guards.js';
|
|
2
|
+
const FIELD_TYPES = [
|
|
3
|
+
'single',
|
|
4
|
+
'multiple',
|
|
5
|
+
'date',
|
|
6
|
+
'text',
|
|
7
|
+
'note',
|
|
8
|
+
'number'
|
|
9
|
+
];
|
|
10
|
+
const CHOICE_TYPES = ['single', 'multiple'];
|
|
11
|
+
function fieldType(value) {
|
|
12
|
+
return FIELD_TYPES.find((type) => type === value) ?? null;
|
|
13
|
+
}
|
|
14
|
+
function fieldError(field, seen) {
|
|
15
|
+
if (!isRecord(field) || typeof field.id !== 'string' || !field.id) {
|
|
16
|
+
return 'every field needs an id';
|
|
17
|
+
}
|
|
18
|
+
if (seen.has(field.id)) {
|
|
19
|
+
return `field id ${field.id} is used twice`;
|
|
20
|
+
}
|
|
21
|
+
seen.add(field.id);
|
|
22
|
+
if (typeof field.label !== 'string' || !field.label) {
|
|
23
|
+
return `field ${field.id} needs a label`;
|
|
24
|
+
}
|
|
25
|
+
const type = fieldType(field.type);
|
|
26
|
+
if (!type) {
|
|
27
|
+
return `field ${field.id} has type ${String(field.type)}; use one of ${FIELD_TYPES.join(', ')}`;
|
|
28
|
+
}
|
|
29
|
+
const options = field.options;
|
|
30
|
+
if (CHOICE_TYPES.includes(type) &&
|
|
31
|
+
!(Array.isArray(options) && options.length > 0 && options.every((o) => typeof o === 'string'))) {
|
|
32
|
+
return `field ${field.id} is a ${type} choice and needs options`;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function formError(args) {
|
|
37
|
+
if (typeof args.question !== 'string' || !args.question) {
|
|
38
|
+
return 'question is required';
|
|
39
|
+
}
|
|
40
|
+
if (!Array.isArray(args.fields) || args.fields.length === 0) {
|
|
41
|
+
return 'fields needs at least one field';
|
|
42
|
+
}
|
|
43
|
+
const seen = new Set();
|
|
44
|
+
for (const field of args.fields) {
|
|
45
|
+
const error = fieldError(field, seen);
|
|
46
|
+
if (error) {
|
|
47
|
+
return error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
function formFields(fields) {
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const field of Array.isArray(fields) ? fields : []) {
|
|
55
|
+
const type = isRecord(field) ? fieldType(field.type) : null;
|
|
56
|
+
if (!isRecord(field) || !type) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
out.push({
|
|
60
|
+
id: String(field.id),
|
|
61
|
+
label: String(field.label),
|
|
62
|
+
type,
|
|
63
|
+
options: CHOICE_TYPES.includes(type) && Array.isArray(field.options)
|
|
64
|
+
? field.options.map(String)
|
|
65
|
+
: undefined,
|
|
66
|
+
required: field.required === true
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
function answerOf(answer) {
|
|
72
|
+
try {
|
|
73
|
+
const values = JSON.parse(answer);
|
|
74
|
+
if (isRecord(values) && !Array.isArray(values)) {
|
|
75
|
+
return { answers: values };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch { }
|
|
79
|
+
return { reply: answer };
|
|
80
|
+
}
|
|
81
|
+
const PARAMETERS = {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
question: { type: 'string', description: 'One line on what you need and why' },
|
|
85
|
+
fields: {
|
|
86
|
+
type: 'array',
|
|
87
|
+
items: {
|
|
88
|
+
type: 'object',
|
|
89
|
+
properties: {
|
|
90
|
+
id: { type: 'string', description: 'Key of this answer in the result' },
|
|
91
|
+
label: { type: 'string', description: 'The question the user reads' },
|
|
92
|
+
type: {
|
|
93
|
+
type: 'string',
|
|
94
|
+
enum: [...FIELD_TYPES],
|
|
95
|
+
description: 'single: pick one option; multiple: pick any options; date; text: a short answer; ' +
|
|
96
|
+
'note: a longer optional comment; number'
|
|
97
|
+
},
|
|
98
|
+
options: {
|
|
99
|
+
type: 'array',
|
|
100
|
+
items: { type: 'string' },
|
|
101
|
+
description: 'The choices, for single and multiple'
|
|
102
|
+
},
|
|
103
|
+
required: { type: 'boolean' }
|
|
104
|
+
},
|
|
105
|
+
required: ['id', 'label', 'type']
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
required: ['question', 'fields']
|
|
110
|
+
};
|
|
111
|
+
export function createAskUserTool() {
|
|
112
|
+
return {
|
|
113
|
+
name: 'ask_user',
|
|
114
|
+
toolset: null,
|
|
115
|
+
description: 'Ask the user for details you need before you act, as a short form in the chat. ' +
|
|
116
|
+
'The run waits for the answers. Ask only what you cannot guess well, all in one form. ' +
|
|
117
|
+
'The result is the answers by field id, a reply in the user’s own words, or skipped: ' +
|
|
118
|
+
'then go on with your best guess and say what you assumed.',
|
|
119
|
+
parameters: PARAMETERS,
|
|
120
|
+
effect: () => 'read',
|
|
121
|
+
autoApprove: true,
|
|
122
|
+
validate: formError,
|
|
123
|
+
async execute(args, ctx) {
|
|
124
|
+
if (!ctx?.askUser) {
|
|
125
|
+
return { error: 'This chat cannot show a form; ask in your reply instead.' };
|
|
126
|
+
}
|
|
127
|
+
const answer = await ctx.askUser({
|
|
128
|
+
question: String(args.question),
|
|
129
|
+
form: formFields(args.fields)
|
|
130
|
+
});
|
|
131
|
+
if (answer === null) {
|
|
132
|
+
return { skipped: true, note: 'The user skipped the form; go on with your best guess.' };
|
|
133
|
+
}
|
|
134
|
+
return answerOf(answer);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DeliveredFile, RunBudget } from '../../contract/run.ts';
|
|
2
|
+
export declare function sha256(bytes: Uint8Array): string;
|
|
3
|
+
export declare function deliveredFile(budget: RunBudget | undefined, name: string): DeliveredFile | undefined;
|
|
4
|
+
export declare function recordDelivered(budget: RunBudget | undefined, file: DeliveredFile): void;
|
|
5
|
+
export declare function attachmentOf({ attachmentId, fileName, byteLength }: DeliveredFile): Pick<DeliveredFile, 'attachmentId' | 'fileName' | 'byteLength'>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
export function sha256(bytes) {
|
|
3
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
4
|
+
}
|
|
5
|
+
export function deliveredFile(budget, name) {
|
|
6
|
+
const key = name.toLowerCase();
|
|
7
|
+
return budget?.delivered?.find((file) => file.name === key);
|
|
8
|
+
}
|
|
9
|
+
export function recordDelivered(budget, file) {
|
|
10
|
+
if (budget) {
|
|
11
|
+
budget.delivered = [...(budget.delivered ?? []), file];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function attachmentOf({ attachmentId, fileName, byteLength }) {
|
|
15
|
+
return { attachmentId, fileName, byteLength };
|
|
16
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AttachFn, AttachmentRecord } from '../../contract/index.ts';
|
|
2
|
+
export declare const MAX_FILE_BYTES = 100000000;
|
|
3
|
+
export declare function isFileMime(mimeType: string): boolean;
|
|
4
|
+
export declare function bareMime(contentType: string | null | undefined): string;
|
|
5
|
+
export declare function fetchedFileName(url: URL, mimeType: string): string;
|
|
6
|
+
export declare function dispositionFileName(header: string | null | undefined): string | null;
|
|
7
|
+
export interface AttachFetchedFileOptions {
|
|
8
|
+
readonly url: URL;
|
|
9
|
+
readonly mimeType: string;
|
|
10
|
+
readonly attach: AttachFn | undefined;
|
|
11
|
+
readonly maxBytes: number;
|
|
12
|
+
readonly fileName?: string | null | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface AttachedFile {
|
|
15
|
+
readonly attachmentId: string;
|
|
16
|
+
readonly fileName: string;
|
|
17
|
+
readonly mimeType: string;
|
|
18
|
+
readonly byteLength: number;
|
|
19
|
+
readonly content: string;
|
|
20
|
+
}
|
|
21
|
+
export interface FileRefused {
|
|
22
|
+
readonly error: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function attachFetchedFile(bytes: Uint8Array | undefined, { url, mimeType, attach, maxBytes, fileName }: AttachFetchedFileOptions): Promise<AttachedFile | FileRefused>;
|
|
25
|
+
export interface AttachTextFileOptions {
|
|
26
|
+
readonly url: URL;
|
|
27
|
+
readonly mimeType: string;
|
|
28
|
+
readonly attach: AttachFn | undefined;
|
|
29
|
+
readonly maxBytes: number;
|
|
30
|
+
readonly fileName?: string | null | undefined;
|
|
31
|
+
}
|
|
32
|
+
export declare function attachTextFile(bytes: Uint8Array | undefined, { url, mimeType, attach, maxBytes, fileName }: AttachTextFileOptions): Promise<AttachmentRecord | null>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { checkFileName } from './output-policy.js';
|
|
3
|
+
export const MAX_FILE_BYTES = 100_000_000;
|
|
4
|
+
const BINARY_MIME_PREFIXES = ['image/', 'audio/', 'video/', 'font/', 'model/'];
|
|
5
|
+
const TEXT_EXTENSIONS = {
|
|
6
|
+
'text/plain': 'txt',
|
|
7
|
+
'text/markdown': 'md'
|
|
8
|
+
};
|
|
9
|
+
const MIME_EXTENSIONS = {
|
|
10
|
+
'application/pdf': 'pdf',
|
|
11
|
+
'application/msword': 'doc',
|
|
12
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
|
|
13
|
+
'application/vnd.ms-excel': 'xls',
|
|
14
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
|
|
15
|
+
'application/vnd.ms-powerpoint': 'ppt',
|
|
16
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'pptx',
|
|
17
|
+
'application/vnd.oasis.opendocument.text': 'odt',
|
|
18
|
+
'application/vnd.oasis.opendocument.spreadsheet': 'ods',
|
|
19
|
+
'application/epub+zip': 'epub',
|
|
20
|
+
'application/zip': 'zip',
|
|
21
|
+
'application/gzip': 'gz',
|
|
22
|
+
'image/svg+xml': 'svg',
|
|
23
|
+
'image/jpeg': 'jpg',
|
|
24
|
+
'audio/mpeg': 'mp3',
|
|
25
|
+
'video/quicktime': 'mov',
|
|
26
|
+
'application/octet-stream': 'bin'
|
|
27
|
+
};
|
|
28
|
+
export function isFileMime(mimeType) {
|
|
29
|
+
if (mimeType in MIME_EXTENSIONS)
|
|
30
|
+
return true;
|
|
31
|
+
return BINARY_MIME_PREFIXES.some((prefix) => mimeType.startsWith(prefix));
|
|
32
|
+
}
|
|
33
|
+
export function bareMime(contentType) {
|
|
34
|
+
return contentType?.split(';')[0]?.trim().toLowerCase() ?? '';
|
|
35
|
+
}
|
|
36
|
+
export function fetchedFileName(url, mimeType) {
|
|
37
|
+
const last = url.pathname.split('/').filter(Boolean).pop() ?? '';
|
|
38
|
+
let decoded = last;
|
|
39
|
+
try {
|
|
40
|
+
decoded = decodeURIComponent(last);
|
|
41
|
+
}
|
|
42
|
+
catch { }
|
|
43
|
+
const base = decoded.split(/[/\\]/).filter(Boolean).pop() ?? '';
|
|
44
|
+
return base ? withExtension(base, mimeType) : `${url.hostname}.${extensionFor(mimeType)}`;
|
|
45
|
+
}
|
|
46
|
+
export function dispositionFileName(header) {
|
|
47
|
+
if (!header)
|
|
48
|
+
return null;
|
|
49
|
+
const extended = /filename\*\s*=\s*(?:UTF-8|utf-8)''([^;]+)/.exec(header)?.[1];
|
|
50
|
+
if (extended) {
|
|
51
|
+
try {
|
|
52
|
+
return decodeURIComponent(extended.trim());
|
|
53
|
+
}
|
|
54
|
+
catch { }
|
|
55
|
+
}
|
|
56
|
+
return (/filename\s*=\s*"([^"]*)"/.exec(header)?.[1] ??
|
|
57
|
+
/filename\s*=\s*([^;\s]+)/.exec(header)?.[1] ??
|
|
58
|
+
null);
|
|
59
|
+
}
|
|
60
|
+
export async function attachFetchedFile(bytes, { url, mimeType, attach, maxBytes, fileName }) {
|
|
61
|
+
if (!attach || !bytes || bytes.byteLength === 0) {
|
|
62
|
+
return { error: 'This URL serves a file, not a readable page, and it could not be attached.' };
|
|
63
|
+
}
|
|
64
|
+
if (bytes.byteLength >= maxBytes) {
|
|
65
|
+
return { error: `This file is larger than ${maxBytes / 1_000_000}MB and was not attached.` };
|
|
66
|
+
}
|
|
67
|
+
const mime = isPdf(bytes) ? 'application/pdf' : mimeType || 'application/octet-stream';
|
|
68
|
+
const named = fileName && checkFileName(fileName) === null ? withExtension(fileName, mime) : null;
|
|
69
|
+
const record = await attach({
|
|
70
|
+
fileName: named ?? fetchedFileName(url, mime),
|
|
71
|
+
mimeType: mime,
|
|
72
|
+
bytes,
|
|
73
|
+
raw: !mime.startsWith('image/')
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
attachmentId: record.id,
|
|
77
|
+
fileName: record.fileName,
|
|
78
|
+
mimeType: mime,
|
|
79
|
+
byteLength: record.byteLength,
|
|
80
|
+
content: `Attached the file "${record.fileName}" (${Math.round(record.byteLength / 1024)}KB, ${mime}) from ${url.toString()} — ` +
|
|
81
|
+
'the user can open or save it. Its contents were NOT read, so do not describe what is inside ' +
|
|
82
|
+
'yet. To read it, use the skill for its type (pdf for a PDF), or stage it with exec as ' +
|
|
83
|
+
`inputs [{ "attachmentId": "${record.id}", "path": "${record.fileName}" }] — never ask the ` +
|
|
84
|
+
'user to attach a file this call already attached.'
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function isPdf(bytes) {
|
|
88
|
+
return b4a.toString(bytes.subarray(0, 5), 'latin1') === '%PDF-';
|
|
89
|
+
}
|
|
90
|
+
export async function attachTextFile(bytes, { url, mimeType, attach, maxBytes, fileName }) {
|
|
91
|
+
if (!attach || !bytes || bytes.byteLength === 0 || bytes.byteLength >= maxBytes) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const mime = mimeType || 'text/plain';
|
|
95
|
+
const named = fileName && checkFileName(fileName) === null ? withExtension(fileName, mime) : null;
|
|
96
|
+
try {
|
|
97
|
+
return await attach({
|
|
98
|
+
fileName: named ?? fetchedFileName(url, mime),
|
|
99
|
+
mimeType: mime,
|
|
100
|
+
bytes,
|
|
101
|
+
raw: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function withExtension(base, mimeType) {
|
|
109
|
+
const extension = /\.([\w-]{1,8})$/.exec(base)?.[1]?.toLowerCase() ?? '';
|
|
110
|
+
if (extension && acceptableExtensions(mimeType).has(extension)) {
|
|
111
|
+
return base;
|
|
112
|
+
}
|
|
113
|
+
const trustsName = mimeType === 'application/octet-stream' || !isFileMime(mimeType);
|
|
114
|
+
if (trustsName && /^[a-z][\w-]*$/.test(extension)) {
|
|
115
|
+
return base;
|
|
116
|
+
}
|
|
117
|
+
return `${base}.${extensionFor(mimeType)}`;
|
|
118
|
+
}
|
|
119
|
+
function acceptableExtensions(mimeType) {
|
|
120
|
+
const accepted = new Set([extensionFor(mimeType)]);
|
|
121
|
+
const subtype = mimeType.split('/')[1] ?? '';
|
|
122
|
+
if (/^[a-z0-9]{1,8}$/.test(subtype)) {
|
|
123
|
+
accepted.add(subtype);
|
|
124
|
+
}
|
|
125
|
+
return accepted;
|
|
126
|
+
}
|
|
127
|
+
function extensionFor(mimeType) {
|
|
128
|
+
const known = MIME_EXTENSIONS[mimeType] ?? TEXT_EXTENSIONS[mimeType];
|
|
129
|
+
if (known) {
|
|
130
|
+
return known;
|
|
131
|
+
}
|
|
132
|
+
const subtype = mimeType.split('/')[1] ?? '';
|
|
133
|
+
return /^[a-z0-9]{1,5}$/.test(subtype) ? subtype : 'bin';
|
|
134
|
+
}
|
|
@@ -319,7 +319,8 @@ export function createExecTool({ policyVersion, spawn, killProcess, shell: compo
|
|
|
319
319
|
return language.validate(rawArgs, {
|
|
320
320
|
sandbox,
|
|
321
321
|
trusted: run.trusted,
|
|
322
|
-
toolNames: ctx?.toolNames
|
|
322
|
+
toolNames: ctx?.toolNames,
|
|
323
|
+
offeredTools: ctx?.offeredTools
|
|
323
324
|
});
|
|
324
325
|
}
|
|
325
326
|
return firstAnswer(languages, (each) => each.strays(rawArgs)) ?? shellStray(rawArgs);
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { HarnessError } from '../../errors.js';
|
|
2
1
|
import { docx, pptx } from '../../office/engine/index.js';
|
|
3
|
-
import {
|
|
4
|
-
let pdfium = null;
|
|
5
|
-
function loadPdfium() {
|
|
6
|
-
pdfium ??= import('bare-pdfium').then((loaded) => loaded, () => null);
|
|
7
|
-
return pdfium;
|
|
8
|
-
}
|
|
2
|
+
import { pdfPages } from '../pdf/pages.js';
|
|
9
3
|
export function isDocument(key) {
|
|
10
4
|
return /\.(pdf|docx|pptx)$/i.test(key);
|
|
11
5
|
}
|
|
@@ -14,25 +8,8 @@ export async function documentText(key, bytes, { ocr, signal } = {}) {
|
|
|
14
8
|
const read = /\.docx$/i.test(key) ? docx.open(bytes).read() : pptx.open(bytes).read();
|
|
15
9
|
return collectText(read).join('\n');
|
|
16
10
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
throw new HarnessError('PDF_TEXT_UNAVAILABLE');
|
|
20
|
-
}
|
|
21
|
-
const doc = lib.open(bytes);
|
|
22
|
-
try {
|
|
23
|
-
const recognized = ocr
|
|
24
|
-
? (await recognizePages({ doc, bytes }, { ocr, signal })).pages
|
|
25
|
-
: undefined;
|
|
26
|
-
return [...doc.textPages()]
|
|
27
|
-
.map(({ page, text }) => {
|
|
28
|
-
const read = recognized?.get(page) ?? text;
|
|
29
|
-
return `--- page ${page + 1} ---\n${read.replace(/\r\n?/g, '\n').trim()}`;
|
|
30
|
-
})
|
|
31
|
-
.join('\n');
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
doc.close();
|
|
35
|
-
}
|
|
11
|
+
const pages = await pdfPages(bytes, { ocr, signal });
|
|
12
|
+
return pages.map(({ page, text }) => `--- page ${page} ---\n${text}`).join('\n');
|
|
36
13
|
}
|
|
37
14
|
function collectText(value) {
|
|
38
15
|
if (Array.isArray(value)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
2
|
export declare const MAX_RESPONSE_CHARS = 8192;
|
|
3
3
|
export declare const IDLE_TIMEOUT_MS = 10000;
|
|
4
|
-
export declare const TIMEOUT_MS =
|
|
4
|
+
export declare const TIMEOUT_MS = 120000;
|
|
5
5
|
export interface FetchInit {
|
|
6
6
|
method: string;
|
|
7
7
|
headers: Record<string, string>;
|
|
@@ -9,7 +9,7 @@ export interface FetchInit {
|
|
|
9
9
|
signal: BareAbortSignal;
|
|
10
10
|
redirect?: 'manual';
|
|
11
11
|
validatedAddresses?: readonly string[] | undefined;
|
|
12
|
-
maxBytes?: number;
|
|
12
|
+
maxBytes?: number | ((contentType: string) => number);
|
|
13
13
|
truncate?: boolean;
|
|
14
14
|
idleTimeoutMs?: number;
|
|
15
15
|
}
|
|
@@ -2,7 +2,7 @@ import { isRecord } from '../../guards.js';
|
|
|
2
2
|
const BLOCKED_HEADERS = new Set(['authorization', 'cookie', 'proxy-authorization']);
|
|
3
3
|
export const MAX_RESPONSE_CHARS = 8192;
|
|
4
4
|
export const IDLE_TIMEOUT_MS = 10_000;
|
|
5
|
-
export const TIMEOUT_MS =
|
|
5
|
+
export const TIMEOUT_MS = 120_000;
|
|
6
6
|
export function isRedirectStatus(status) {
|
|
7
7
|
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
|
8
8
|
}
|