@qvac/harness 1.0.0-rc.10 → 1.0.0-rc.12
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 +78 -0
- package/dist-lib/index.d.ts +2 -12
- package/dist-lib/index.js +8 -2
- package/dist-lib/lib/agent/resolve.js +9 -2
- package/dist-lib/lib/agent/tools.d.ts +1 -0
- package/dist-lib/lib/agent/tools.js +1 -1
- package/dist-lib/lib/capabilities/agent-ports.d.ts +1 -1
- package/dist-lib/lib/capabilities/agent-ports.js +7 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +4 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +3 -1
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +12 -5
- package/dist-lib/lib/capabilities/completion-engine/actors/run-prepare.js +36 -22
- package/dist-lib/lib/capabilities/completion-engine/actors/skill-step.js +24 -5
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +3 -2
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +18 -3
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +1 -0
- package/dist-lib/lib/capabilities/completion-engine/driver.js +3 -2
- package/dist-lib/lib/capabilities/completion-engine/loop.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/model-round.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/prepare-step.d.ts +2 -1
- package/dist-lib/lib/capabilities/completion-engine/round.d.ts +9 -0
- package/dist-lib/lib/capabilities/completion-engine/round.js +12 -8
- package/dist-lib/lib/capabilities/completion-engine/tool-execution.js +15 -1
- package/dist-lib/lib/capabilities/completion-engine/turns.js +5 -2
- package/dist-lib/lib/capabilities/skill-entry.d.ts +4 -0
- package/dist-lib/lib/capabilities/skill-entry.js +28 -1
- package/dist-lib/lib/capabilities/tool-failed-note.d.ts +1 -0
- package/dist-lib/lib/capabilities/tool-failed-note.js +1 -0
- package/dist-lib/lib/capabilities/tool-turns.d.ts +5 -1
- package/dist-lib/lib/capabilities/tool-turns.js +21 -2
- package/dist-lib/lib/context-window.d.ts +1 -0
- package/dist-lib/lib/context-window.js +6 -0
- package/dist-lib/lib/contract/agent.d.ts +4 -0
- package/dist-lib/lib/contract/completion.d.ts +2 -0
- package/dist-lib/lib/contract/models.d.ts +3 -1
- package/dist-lib/lib/contract/run.d.ts +1 -0
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +3 -1
- package/dist-lib/lib/machine/completion/actions/completion.js +43 -7
- package/dist-lib/lib/machine/completion/actions/tools.js +4 -5
- package/dist-lib/lib/machine/completion/context.js +1 -0
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +2 -1
- package/dist-lib/lib/machine/completion/guards/retry.js +4 -3
- package/dist-lib/lib/machine/completion/implementations.d.ts +2 -0
- package/dist-lib/lib/machine/completion/implementations.js +7 -3
- package/dist-lib/lib/machine/completion/machine.d.ts +6 -0
- package/dist-lib/lib/machine/completion/machine.js +12 -1
- package/dist-lib/lib/machine/completion/rules.d.ts +1 -0
- package/dist-lib/lib/machine/completion/rules.js +3 -0
- package/dist-lib/lib/machine/completion/types.d.ts +5 -0
- package/dist-lib/lib/machine/index.d.ts +6 -0
- package/dist-lib/lib/models/custom-model-cache.d.ts +1 -0
- package/dist-lib/lib/models/custom-model-cache.js +3 -0
- package/dist-lib/lib/models/gguf-header.d.ts +6 -0
- package/dist-lib/lib/models/gguf-header.js +38 -1
- package/dist-lib/lib/models/kv-cache.d.ts +2 -0
- package/dist-lib/lib/models/kv-cache.js +8 -0
- package/dist-lib/lib/models/load-requests.d.ts +9 -0
- package/dist-lib/lib/models/load-requests.js +42 -0
- package/dist-lib/lib/models/model-handle.d.ts +1 -0
- package/dist-lib/lib/models/model-pool.d.ts +2 -1
- package/dist-lib/lib/models/model-pool.js +17 -7
- package/dist-lib/lib/no-redirect-fetch-impl.d.ts +1 -0
- package/dist-lib/lib/no-redirect-fetch-impl.js +32 -1
- package/dist-lib/lib/prompt.d.ts +4 -2
- package/dist-lib/lib/prompt.js +16 -5
- package/dist-lib/lib/residency/completion-runtime.d.ts +6 -5
- package/dist-lib/lib/residency/completion-runtime.js +3 -7
- package/dist-lib/lib/residency/index.d.ts +9 -1
- package/dist-lib/lib/residency/index.js +38 -8
- package/dist-lib/lib/skills-host/index.d.ts +1 -0
- package/dist-lib/lib/skills-host/index.js +3 -0
- package/dist-lib/lib/tools/attachments/staging.d.ts +1 -0
- package/dist-lib/lib/tools/attachments/staging.js +11 -0
- package/dist-lib/lib/tools/http-request/request.d.ts +3 -1
- package/dist-lib/lib/tools/http-request/request.js +2 -1
- package/dist-lib/lib/tools/http-request/truncate-response.d.ts +16 -1
- package/dist-lib/lib/tools/http-request/truncate-response.js +45 -9
- package/dist-lib/lib/tools/http-request.js +12 -6
- package/dist-lib/lib/tools/office/ops.d.ts +1 -0
- package/dist-lib/lib/tools/office/ops.js +5 -1
- package/dist-lib/lib/tools/office.d.ts +1 -0
- package/dist-lib/lib/tools/office.js +151 -21
- package/dist-lib/lib/tools/operations/compile.js +4 -4
- package/dist-lib/lib/tools/skills/credential-check.d.ts +1 -0
- package/dist-lib/lib/tools/skills/credential-check.js +3 -0
- package/dist-lib/lib/tools/skills/manifest-parse.js +27 -3
- package/dist-lib/lib/tools/skills/manifest.d.ts +1 -0
- package/dist-lib/plugins/image/edit-image.js +4 -3
- package/dist-lib/plugins/image/generate-image.d.ts +3 -2
- package/dist-lib/plugins/image/generate-image.js +87 -64
- package/dist-lib/plugins/image/index.js +1 -0
- package/dist-lib/plugins/music/generate-music.d.ts +3 -2
- package/dist-lib/plugins/music/generate-music.js +68 -47
- package/dist-lib/plugins/music/index.js +1 -0
- package/dist-lib/plugins/run-report/story.js +4 -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/package.json +5 -1
|
@@ -31,6 +31,7 @@ export interface ModelLease {
|
|
|
31
31
|
modelId: string;
|
|
32
32
|
ctxSize?: number | undefined;
|
|
33
33
|
slots?: number | undefined;
|
|
34
|
+
canThink?: boolean | undefined;
|
|
34
35
|
release(): void;
|
|
35
36
|
}
|
|
36
37
|
export interface ModelLeaseOptions {
|
|
@@ -60,6 +61,7 @@ export interface ResidencyOptions {
|
|
|
60
61
|
llmLoad?: LlamaLoadKnobs | undefined;
|
|
61
62
|
slots?: number | undefined;
|
|
62
63
|
completionModelCap?: number | undefined;
|
|
64
|
+
modelsDir?: string | undefined;
|
|
63
65
|
sdk: Pick<SdkLoader, 'load'>;
|
|
64
66
|
loads: LoadTracker;
|
|
65
67
|
gate: ResidencyGate;
|
|
@@ -74,11 +76,13 @@ export interface ResidencyOptions {
|
|
|
74
76
|
unloadIdlePlugins(): Promise<Array<PromiseSettledResult<unknown>>>;
|
|
75
77
|
tools(): readonly ToolDefinition[];
|
|
76
78
|
skills(agentId: string | null, model: string): Promise<CompletionSkillEntry[]>;
|
|
79
|
+
platform?(): string;
|
|
77
80
|
}
|
|
78
81
|
export declare class Residency {
|
|
79
82
|
readonly gate: ResidencyGate;
|
|
80
83
|
readonly sdk: Pick<SdkLoader, 'load'>;
|
|
81
84
|
readonly fit: ModelFit;
|
|
85
|
+
readonly requests: import("../models/load-requests.ts").LoadRequests;
|
|
82
86
|
private readonly _loads;
|
|
83
87
|
private readonly _emit;
|
|
84
88
|
private readonly _projectionFor;
|
|
@@ -89,6 +93,7 @@ export declare class Residency {
|
|
|
89
93
|
private readonly _unloadIdlePlugins;
|
|
90
94
|
private readonly _tools;
|
|
91
95
|
private readonly _skills;
|
|
96
|
+
private readonly _platform;
|
|
92
97
|
private readonly _pinned;
|
|
93
98
|
private readonly _borrowed;
|
|
94
99
|
private readonly _replying;
|
|
@@ -100,6 +105,7 @@ export declare class Residency {
|
|
|
100
105
|
private readonly _kvCacheV?;
|
|
101
106
|
private readonly _llmLoad?;
|
|
102
107
|
private readonly _slots?;
|
|
108
|
+
private readonly _modelsDir?;
|
|
103
109
|
private readonly _completionModelCap;
|
|
104
110
|
private readonly _modelFaults;
|
|
105
111
|
private readonly _idle;
|
|
@@ -117,6 +123,7 @@ export declare class Residency {
|
|
|
117
123
|
get status(): ModelStatusCache;
|
|
118
124
|
tools(): readonly ToolDefinition[];
|
|
119
125
|
skills(agentId: string | null, model: string): Promise<CompletionSkillEntry[]>;
|
|
126
|
+
platform(): string | undefined;
|
|
120
127
|
recreate(): void;
|
|
121
128
|
destroy(): Promise<void> | undefined;
|
|
122
129
|
setIdleTimeout(ms: number): void;
|
|
@@ -180,10 +187,11 @@ export declare class Residency {
|
|
|
180
187
|
loadOptions(model: string, agent?: LoadOptionKnobs): ModelLoadOptions;
|
|
181
188
|
acquireLease({ pool, key, open, signal, prepare, onLoad }: ModelLeaseOptions): Promise<ModelLease | null>;
|
|
182
189
|
completionRuntime(request: CompletionRuntimeRequest): Promise<import("./completion-runtime.ts").PreparedRuntime>;
|
|
183
|
-
servedRound(model: string): {
|
|
190
|
+
servedRound(model: string, load?: LoadOptionKnobs): {
|
|
184
191
|
key: string;
|
|
185
192
|
acquireRound: (invocationSignal?: BareAbortSignal) => Promise<import("../contract/completion.ts").RoundModelLease>;
|
|
186
193
|
};
|
|
194
|
+
roomForCompletion(model: string, { loadOpts, signal }: Pick<RoomOptions, 'loadOpts' | 'signal'>): Promise<void>;
|
|
187
195
|
makeRoomForCompletion(model: string, { loadOpts, signal, deadlineMs }: RoomOptions): Promise<boolean>;
|
|
188
196
|
evictWedged(model: string, key: string): Promise<WedgedEviction>;
|
|
189
197
|
private _evictAfterLeases;
|
|
@@ -7,6 +7,7 @@ import { ContextChoice as ContextClimb } from '../models/context-choice.js';
|
|
|
7
7
|
import { parseGgufHeader, readGgufHeaderBytes } from '../models/gguf-header.js';
|
|
8
8
|
import { resolveMainGpu } from '../models/gpu-selection.js';
|
|
9
9
|
import { createIdleReaper } from '../models/idle-unload.js';
|
|
10
|
+
import { createLoadRequests } from '../models/load-requests.js';
|
|
10
11
|
import { memoryCapBytes, nextVictim, VictimRank } from '../models/memory-cap.js';
|
|
11
12
|
import { assetBytes, curatedListables, curatedModelAsset, customContextLength, customModelSrc, modelAddonOf } from '../models/model-catalog.js';
|
|
12
13
|
import { ModelFit } from '../models/model-fit.js';
|
|
@@ -43,6 +44,7 @@ export class Residency {
|
|
|
43
44
|
gate;
|
|
44
45
|
sdk;
|
|
45
46
|
fit = new ModelFit(async (input) => (await this.sdk.load()).assessModelFit(input));
|
|
47
|
+
requests = createLoadRequests((state) => this.notify(state));
|
|
46
48
|
_loads;
|
|
47
49
|
_emit;
|
|
48
50
|
_projectionFor;
|
|
@@ -53,6 +55,7 @@ export class Residency {
|
|
|
53
55
|
_unloadIdlePlugins;
|
|
54
56
|
_tools;
|
|
55
57
|
_skills;
|
|
58
|
+
_platform;
|
|
56
59
|
_pinned = new Set();
|
|
57
60
|
_borrowed = new Set();
|
|
58
61
|
_replying = [];
|
|
@@ -64,6 +67,7 @@ export class Residency {
|
|
|
64
67
|
_kvCacheV;
|
|
65
68
|
_llmLoad;
|
|
66
69
|
_slots;
|
|
70
|
+
_modelsDir;
|
|
67
71
|
_completionModelCap;
|
|
68
72
|
_modelFaults = new Map();
|
|
69
73
|
_idle;
|
|
@@ -91,6 +95,7 @@ export class Residency {
|
|
|
91
95
|
this._unloadIdlePlugins = opts.unloadIdlePlugins;
|
|
92
96
|
this._tools = opts.tools;
|
|
93
97
|
this._skills = opts.skills;
|
|
98
|
+
this._platform = opts.platform;
|
|
94
99
|
this._llmDevice = opts.llmDevice;
|
|
95
100
|
this._llmGpuLayers = opts.llmGpuLayers;
|
|
96
101
|
this._contextSize = opts.contextSize;
|
|
@@ -98,6 +103,7 @@ export class Residency {
|
|
|
98
103
|
this._kvCacheV = opts.kvCacheV;
|
|
99
104
|
this._llmLoad = opts.llmLoad;
|
|
100
105
|
this._slots = opts.slots;
|
|
106
|
+
this._modelsDir = opts.modelsDir;
|
|
101
107
|
this._completionModelCap = opts.completionModelCap ?? DEFAULT_COMPLETION_MODEL_CAP;
|
|
102
108
|
this._models = this._createPool();
|
|
103
109
|
this._idle = createIdleReaper({
|
|
@@ -118,6 +124,9 @@ export class Residency {
|
|
|
118
124
|
skills(agentId, model) {
|
|
119
125
|
return this._skills(agentId, model);
|
|
120
126
|
}
|
|
127
|
+
platform() {
|
|
128
|
+
return this._platform?.();
|
|
129
|
+
}
|
|
121
130
|
recreate() {
|
|
122
131
|
this.fit.clearRows();
|
|
123
132
|
this._reserved.clear();
|
|
@@ -199,9 +208,7 @@ export class Residency {
|
|
|
199
208
|
const loadOpts = resolveLoadOptions({}, this.deviceConfig());
|
|
200
209
|
const key = modelKey(model, loadOpts);
|
|
201
210
|
const pool = this._models;
|
|
202
|
-
|
|
203
|
-
await this.makeRoomForCompletion(model, { loadOpts, signal });
|
|
204
|
-
}
|
|
211
|
+
await this.roomForCompletion(model, { loadOpts, signal });
|
|
205
212
|
try {
|
|
206
213
|
const { modelId } = await raceAbort(pool.open(key, model, loadOpts).load(), signal);
|
|
207
214
|
return { modelId, release: () => releaseModel(pool, key) };
|
|
@@ -230,7 +237,10 @@ export class Residency {
|
|
|
230
237
|
return this._pools().flatMap((pool) => loadedModels(pool));
|
|
231
238
|
}
|
|
232
239
|
loading() {
|
|
233
|
-
return new Set(
|
|
240
|
+
return new Set([
|
|
241
|
+
...this._pools().flatMap((pool) => loadingModels(pool)),
|
|
242
|
+
...this.requests.models()
|
|
243
|
+
]);
|
|
234
244
|
}
|
|
235
245
|
settled() {
|
|
236
246
|
return new Set(this._pools().flatMap((pool) => settledModels(pool)));
|
|
@@ -261,7 +271,8 @@ export class Residency {
|
|
|
261
271
|
onUnloadFailure: (modelId, error) => this.gate.recordModelUnloadFailure(modelId, error),
|
|
262
272
|
beforeLoad: (load) => this.beforeLoad(load),
|
|
263
273
|
chooseContext: (load, tier) => this._chooseContext(load, tier),
|
|
264
|
-
hold: this._hold
|
|
274
|
+
hold: this._hold,
|
|
275
|
+
modelsDir: this._modelsDir
|
|
265
276
|
});
|
|
266
277
|
}
|
|
267
278
|
loadLifecycleSdk() {
|
|
@@ -801,7 +812,13 @@ export class Residency {
|
|
|
801
812
|
pendingLoad = loading;
|
|
802
813
|
onLoad?.(loading);
|
|
803
814
|
const loaded = await raceAbort(loading, signal);
|
|
804
|
-
return {
|
|
815
|
+
return {
|
|
816
|
+
modelId: loaded.modelId,
|
|
817
|
+
ctxSize: loaded.ctxSize,
|
|
818
|
+
slots: loaded.slots,
|
|
819
|
+
canThink: loaded.canThink,
|
|
820
|
+
release
|
|
821
|
+
};
|
|
805
822
|
}
|
|
806
823
|
catch (error) {
|
|
807
824
|
if (pendingLoad) {
|
|
@@ -822,11 +839,24 @@ export class Residency {
|
|
|
822
839
|
releaseWork();
|
|
823
840
|
}
|
|
824
841
|
}
|
|
825
|
-
servedRound(model) {
|
|
826
|
-
const loadOpts = this.loadOptions(model);
|
|
842
|
+
servedRound(model, load) {
|
|
843
|
+
const loadOpts = this.loadOptions(model, load);
|
|
827
844
|
const key = modelKey(model, loadOpts);
|
|
828
845
|
return { key, acquireRound: roundAcquirer(this, { model, key, loadOpts }) };
|
|
829
846
|
}
|
|
847
|
+
async roomForCompletion(model, { loadOpts, signal }) {
|
|
848
|
+
const key = modelKey(model, loadOpts);
|
|
849
|
+
if (isResident(this._models, key)) {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
await this.requests.around(model, async () => {
|
|
853
|
+
await this.makeRoomForCompletion(model, { loadOpts, signal });
|
|
854
|
+
await this.unloadIdleGenerators();
|
|
855
|
+
});
|
|
856
|
+
if (isResident(this._models, key)) {
|
|
857
|
+
this.notify({ status: 'ready', model, catalogChanged: true });
|
|
858
|
+
}
|
|
859
|
+
}
|
|
830
860
|
async makeRoomForCompletion(model, { loadOpts, signal, deadlineMs = MODEL_ROOM_WAIT_MS }) {
|
|
831
861
|
if (this._capBytes !== null) {
|
|
832
862
|
await evictIdleWhere(this._models, this._replacedBy(model));
|
|
@@ -48,6 +48,7 @@ export declare class SkillsHost {
|
|
|
48
48
|
resolveCredential(key: string, ctx?: ToolExecuteContext): Promise<CredentialStoreValue> | CredentialStoreValue;
|
|
49
49
|
statuses(agentId?: string | null, modelName?: string | null, options?: HarnessSkillsOptions): Promise<ResolvedSkillCatalogEntry[]>;
|
|
50
50
|
completionSkills(agentId: string | null, model: string): Promise<CompletionSkillEntry[]>;
|
|
51
|
+
get platform(): string;
|
|
51
52
|
private _currentPlatform;
|
|
52
53
|
private _installedTools;
|
|
53
54
|
private _baseDir;
|
|
@@ -19,6 +19,7 @@ export interface StageInputsOptions {
|
|
|
19
19
|
export interface StagedInputs {
|
|
20
20
|
files: readonly StagedInput[];
|
|
21
21
|
}
|
|
22
|
+
export declare function uploadsAvailable(fetchAttachment: FetchAttachmentFn, { turnImages, signal }?: StageInputsOptions): Promise<number | null>;
|
|
22
23
|
export declare function stageInputs(fetchAttachment: FetchAttachmentFn, inputs: readonly ExecInput[], opts?: StageInputsOptions): Promise<StagedInputs | ExecError>;
|
|
23
24
|
export interface AttachOutputsOptions {
|
|
24
25
|
readonly declared: readonly string[];
|
|
@@ -67,6 +67,17 @@ async function probeAttachment(fetchAttachment, id, { signal, deadline }) {
|
|
|
67
67
|
}
|
|
68
68
|
return { size: byteLengthOf(head), bytes: hasBytes(head) ? head.bytes : null };
|
|
69
69
|
}
|
|
70
|
+
export async function uploadsAvailable(fetchAttachment, { turnImages = [], signal } = {}) {
|
|
71
|
+
if (turnImages.length) {
|
|
72
|
+
return turnImages.length;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return (await bounded(fetchAttachment({ meta: true, signal }), STAGE_TIMEOUT_MS)) ? 1 : 0;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
70
81
|
export async function stageInputs(fetchAttachment, inputs, opts = {}) {
|
|
71
82
|
const { turnImages = [], signal } = opts;
|
|
72
83
|
const files = inputs.map(() => null);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AbortSignal as BareAbortSignal } from 'bare-abort-controller';
|
|
2
2
|
export declare const MAX_RESPONSE_CHARS = 8192;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const IDLE_TIMEOUT_MS = 10000;
|
|
4
|
+
export declare const TIMEOUT_MS = 30000;
|
|
4
5
|
export interface FetchInit {
|
|
5
6
|
method: string;
|
|
6
7
|
headers: Record<string, string>;
|
|
@@ -10,6 +11,7 @@ export interface FetchInit {
|
|
|
10
11
|
validatedAddresses?: readonly string[] | undefined;
|
|
11
12
|
maxBytes?: number;
|
|
12
13
|
truncate?: boolean;
|
|
14
|
+
idleTimeoutMs?: number;
|
|
13
15
|
}
|
|
14
16
|
export declare function isRedirectStatus(status: number): boolean;
|
|
15
17
|
export type ParseResult<T> = {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
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
|
-
export const
|
|
4
|
+
export const IDLE_TIMEOUT_MS = 10_000;
|
|
5
|
+
export const TIMEOUT_MS = 30_000;
|
|
5
6
|
export function isRedirectStatus(status) {
|
|
6
7
|
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
|
7
8
|
}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ToolExecuteContext } from '../../contract/index.ts';
|
|
2
|
+
type BudgetContext = Pick<ToolExecuteContext, 'ctxSize' | 'runBudget'> | undefined;
|
|
3
|
+
export declare function responseBudgetChars(ctx: BudgetContext): number;
|
|
4
|
+
export declare function capResponseBody(body: string, ctx: BudgetContext): CappedBody;
|
|
5
|
+
export interface ResponseCoverage {
|
|
6
|
+
readonly keptChars: number;
|
|
7
|
+
readonly totalChars: number;
|
|
8
|
+
readonly percent: number;
|
|
9
|
+
readonly note: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CappedBody {
|
|
12
|
+
readonly body: string;
|
|
13
|
+
readonly truncated?: ResponseCoverage;
|
|
14
|
+
}
|
|
15
|
+
export declare function truncateResponseBody(body: string, budget: number): CappedBody;
|
|
2
16
|
export declare const ELISION = "\u2026 [truncated]";
|
|
17
|
+
export {};
|
|
@@ -1,19 +1,55 @@
|
|
|
1
1
|
import { MAX_RESPONSE_CHARS } from './request.js';
|
|
2
2
|
import { isRecord } from '../../guards.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const RESPONSE_FLOOR_CHARS = 2048;
|
|
4
|
+
export function responseBudgetChars(ctx) {
|
|
5
|
+
const room = ctx?.runBudget?.responseRoomChars;
|
|
6
|
+
if (room !== undefined) {
|
|
7
|
+
return Math.max(RESPONSE_FLOOR_CHARS, room);
|
|
8
|
+
}
|
|
9
|
+
const ctxSize = ctx?.ctxSize;
|
|
10
|
+
return ctxSize ? Math.max(MAX_RESPONSE_CHARS, Math.floor(ctxSize / 4)) : MAX_RESPONSE_CHARS;
|
|
11
|
+
}
|
|
12
|
+
export function capResponseBody(body, ctx) {
|
|
13
|
+
const capped = truncateResponseBody(body, responseBudgetChars(ctx));
|
|
14
|
+
const budget = ctx?.runBudget;
|
|
15
|
+
if (budget?.responseRoomChars !== undefined) {
|
|
16
|
+
budget.responseRoomChars = Math.max(0, budget.responseRoomChars - capped.body.length);
|
|
17
|
+
}
|
|
18
|
+
return capped;
|
|
19
|
+
}
|
|
20
|
+
const NOT_JSON = Symbol('not-json');
|
|
21
|
+
export function truncateResponseBody(body, budget) {
|
|
22
|
+
if (body.length <= budget) {
|
|
23
|
+
return { body };
|
|
24
|
+
}
|
|
25
|
+
const parsed = parseJson(body);
|
|
26
|
+
if (parsed !== NOT_JSON) {
|
|
27
|
+
const compact = JSON.stringify(parsed);
|
|
28
|
+
if (compact.length <= budget) {
|
|
29
|
+
return { body: compact };
|
|
30
|
+
}
|
|
31
|
+
const kept = JSON.stringify(fit(parsed, budget));
|
|
32
|
+
return { body: kept, truncated: coverageOf(Math.min(kept.length, budget), compact.length) };
|
|
33
|
+
}
|
|
34
|
+
const kept = `${body.slice(0, budget)}${ELISION}`;
|
|
35
|
+
return { body: kept, truncated: coverageOf(budget, body.length) };
|
|
36
|
+
}
|
|
37
|
+
function coverageOf(keptChars, totalChars) {
|
|
38
|
+
const percent = Math.max(1, Math.floor((keptChars / totalChars) * 100));
|
|
39
|
+
return {
|
|
40
|
+
keptChars,
|
|
41
|
+
totalChars,
|
|
42
|
+
percent,
|
|
43
|
+
note: `Only the first ${percent}% of this response was read, to fit the context window. Tell the user that your answer covers that part only.`
|
|
44
|
+
};
|
|
7
45
|
}
|
|
8
|
-
function
|
|
9
|
-
let parsed;
|
|
46
|
+
function parseJson(body) {
|
|
10
47
|
try {
|
|
11
|
-
|
|
48
|
+
return JSON.parse(body);
|
|
12
49
|
}
|
|
13
50
|
catch {
|
|
14
|
-
return
|
|
51
|
+
return NOT_JSON;
|
|
15
52
|
}
|
|
16
|
-
return JSON.stringify(fit(parsed, MAX_RESPONSE_CHARS));
|
|
17
53
|
}
|
|
18
54
|
const MARKER_CHARS = 64;
|
|
19
55
|
function shrinkable(value) {
|
|
@@ -3,9 +3,9 @@ import { AbortController } from 'bare-abort-controller';
|
|
|
3
3
|
import { lookupHost } from '../dns-lookup.js';
|
|
4
4
|
import { READ_METHODS } from './http-methods.js';
|
|
5
5
|
import { encodeDeclaredFields } from './http-request/encode-fields.js';
|
|
6
|
-
import {
|
|
6
|
+
import { capResponseBody } from './http-request/truncate-response.js';
|
|
7
7
|
import { AbortedError } from '../helpers/race-abort.js';
|
|
8
|
-
import { applyQuery, buildHeaders, contentTypeOf, encodeBody, isRedirectStatus, parseJsonBody, parseObjectArg, TIMEOUT_MS } from './http-request/request.js';
|
|
8
|
+
import { applyQuery, buildHeaders, contentTypeOf, encodeBody, isRedirectStatus, parseJsonBody, IDLE_TIMEOUT_MS, parseObjectArg, TIMEOUT_MS } from './http-request/request.js';
|
|
9
9
|
import { parseAuth, resolveBearerHeader, resolveRedirectBearerHeader } from './skills/auth-resolver.js';
|
|
10
10
|
import { recordCredentialHealth } from './skills/credential-health.js';
|
|
11
11
|
import { Policy } from '../policy/index.js';
|
|
@@ -17,7 +17,7 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
17
17
|
policyVersion,
|
|
18
18
|
toolset: 'http-request',
|
|
19
19
|
defer: true,
|
|
20
|
-
description: 'Make an outbound HTTP or HTTPS request and return the response status and body
|
|
20
|
+
description: 'Make an outbound HTTP or HTTPS request and return the response status and body as text. A body too large for the context window is cut, and `truncated` then says what share of it was read. Authorization/Cookie headers are stripped before sending. Stored skill credentials are attached automatically for their allow-listed hosts; `auth` is only needed to force a specific credential key. For APIs and text responses only: a URL that serves a file — PDF, .docx, .xlsx, an image, any binary — comes back as truncated garbage here. Use web_fetch for those; it downloads and attaches the file.',
|
|
21
21
|
parameters: {
|
|
22
22
|
type: 'object',
|
|
23
23
|
properties: {
|
|
@@ -142,7 +142,8 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
142
142
|
body,
|
|
143
143
|
signal: controller.signal,
|
|
144
144
|
redirect: 'manual',
|
|
145
|
-
validatedAddresses
|
|
145
|
+
validatedAddresses,
|
|
146
|
+
idleTimeoutMs: IDLE_TIMEOUT_MS
|
|
146
147
|
});
|
|
147
148
|
if (credentialKey) {
|
|
148
149
|
recordCredentialHealth(credentialKey, response.status, ctx?.agentId);
|
|
@@ -187,14 +188,19 @@ export function createHttpRequestTool({ policyVersion, fetch: fetchImpl, credent
|
|
|
187
188
|
credentialKey = next.credentialKey;
|
|
188
189
|
}
|
|
189
190
|
const text = await response.text();
|
|
191
|
+
if (ctx?.uncappedResponse) {
|
|
192
|
+
return { status: response.status, body: text };
|
|
193
|
+
}
|
|
190
194
|
return {
|
|
191
195
|
status: response.status,
|
|
192
|
-
|
|
196
|
+
...capResponseBody(text, ctx)
|
|
193
197
|
};
|
|
194
198
|
}
|
|
195
199
|
catch (err) {
|
|
196
200
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
197
|
-
const timedOut = error.name === 'AbortError' ||
|
|
201
|
+
const timedOut = error.name === 'AbortError' ||
|
|
202
|
+
error.name === 'TimeoutError' ||
|
|
203
|
+
error instanceof AbortedError;
|
|
198
204
|
return {
|
|
199
205
|
error: timedOut ? 'request timed out' : `request failed: ${error.message}`,
|
|
200
206
|
code: timedOut ? 'timeout' : 'transport'
|
|
@@ -4,6 +4,7 @@ export interface OpSpec {
|
|
|
4
4
|
readonly inches?: boolean;
|
|
5
5
|
readonly query?: boolean;
|
|
6
6
|
readonly aliases?: Readonly<Record<string, string>>;
|
|
7
|
+
readonly skipsLooks?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare const PPTX_OPS: Readonly<Record<string, OpSpec>>;
|
|
9
10
|
export declare const DOCX_OPS: Readonly<Record<string, OpSpec>>;
|
|
@@ -7,7 +7,11 @@ export const PPTX_OPS = {
|
|
|
7
7
|
setText: { slots: [['slide', 'shape'], 'text'] },
|
|
8
8
|
setCellText: { slots: [['slide', 'shape', 'row', 'column'], 'text'] },
|
|
9
9
|
setStyle: { slots: [['slide', 'shape'], 'style', ['paragraph']] },
|
|
10
|
-
addSlide: {
|
|
10
|
+
addSlide: {
|
|
11
|
+
slots: [['like', 'layout', 'at', 'title', 'body', 'image']],
|
|
12
|
+
aliases: { subtitle: 'body' },
|
|
13
|
+
skipsLooks: true
|
|
14
|
+
},
|
|
11
15
|
addPicture: { slots: ['slide', 'image', [...BOX, 'name', 'description']], inches: true },
|
|
12
16
|
addTextBox: { slots: ['slide', [...BOX, 'text', 'style', 'fill', 'name']], inches: true },
|
|
13
17
|
addTable: { slots: ['slide', [...BOX, 'rows', 'header', 'name']], inches: true },
|
|
@@ -4,6 +4,7 @@ type Deck = ReturnType<typeof pptx.open>;
|
|
|
4
4
|
type Workbook = ReturnType<typeof xlsx.open>;
|
|
5
5
|
type FormatName = 'pptx' | 'docx' | 'xlsx';
|
|
6
6
|
type Args = Record<string, unknown>;
|
|
7
|
+
export declare function bodyLines(op: Args): Args;
|
|
7
8
|
export declare function shapeFor(deck: Deck, op: Args): Args;
|
|
8
9
|
export declare function sheetFor(book: Workbook, op: Args, created: boolean): Args;
|
|
9
10
|
export declare function normalizeArgs(args: Args): Args;
|