@framers/agentos 0.13.3 → 0.13.5
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/dist/api/AgentOS.d.ts +3 -0
- package/dist/api/AgentOS.d.ts.map +1 -1
- package/dist/api/AgentOS.js +52 -1
- package/dist/api/AgentOS.js.map +1 -1
- package/dist/api/generateObject.d.ts.map +1 -1
- package/dist/api/generateObject.js +1 -150
- package/dist/api/generateObject.js.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +2 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/runtime/AgentOSOrchestrator.d.ts.map +1 -1
- package/dist/api/runtime/AgentOSOrchestrator.js +1 -0
- package/dist/api/runtime/AgentOSOrchestrator.js.map +1 -1
- package/dist/api/runtime/ExternalToolResultHandler.d.ts.map +1 -1
- package/dist/api/runtime/ExternalToolResultHandler.js +1 -0
- package/dist/api/runtime/ExternalToolResultHandler.js.map +1 -1
- package/dist/api/runtime/StreamChunkEmitter.d.ts.map +1 -1
- package/dist/api/runtime/StreamChunkEmitter.js +1 -0
- package/dist/api/runtime/StreamChunkEmitter.js.map +1 -1
- package/dist/api/runtime/structuredReply.d.ts +138 -0
- package/dist/api/runtime/structuredReply.d.ts.map +1 -0
- package/dist/api/runtime/structuredReply.js +284 -0
- package/dist/api/runtime/structuredReply.js.map +1 -0
- package/dist/api/types/AgentOSInput.d.ts +6 -0
- package/dist/api/types/AgentOSInput.d.ts.map +1 -1
- package/dist/api/types/AgentOSResponse.d.ts +2 -0
- package/dist/api/types/AgentOSResponse.d.ts.map +1 -1
- package/dist/api/types/AgentOSResponse.js.map +1 -1
- package/dist/cognition/emergent/EffectsStore.d.ts +6 -1
- package/dist/cognition/emergent/EffectsStore.d.ts.map +1 -1
- package/dist/cognition/emergent/EffectsStore.js.map +1 -1
- package/dist/cognition/emergent/EmergentCapabilityEngine.d.ts +8 -0
- package/dist/cognition/emergent/EmergentCapabilityEngine.d.ts.map +1 -1
- package/dist/cognition/emergent/EmergentCapabilityEngine.js +84 -9
- package/dist/cognition/emergent/EmergentCapabilityEngine.js.map +1 -1
- package/dist/cognition/emergent/EmergentJudge.d.ts.map +1 -1
- package/dist/cognition/emergent/EmergentJudge.js +8 -1
- package/dist/cognition/emergent/EmergentJudge.js.map +1 -1
- package/dist/cognition/emergent/ForgeToolMetaTool.d.ts +2 -1
- package/dist/cognition/emergent/ForgeToolMetaTool.d.ts.map +1 -1
- package/dist/cognition/emergent/ForgeToolMetaTool.js +27 -4
- package/dist/cognition/emergent/ForgeToolMetaTool.js.map +1 -1
- package/dist/cognition/emergent/SandboxedToolForge.d.ts +7 -3
- package/dist/cognition/emergent/SandboxedToolForge.d.ts.map +1 -1
- package/dist/cognition/emergent/SandboxedToolForge.js +21 -8
- package/dist/cognition/emergent/SandboxedToolForge.js.map +1 -1
- package/dist/cognition/emergent/broker/CapabilityBroker.d.ts +56 -18
- package/dist/cognition/emergent/broker/CapabilityBroker.d.ts.map +1 -1
- package/dist/cognition/emergent/broker/CapabilityBroker.js +309 -47
- package/dist/cognition/emergent/broker/CapabilityBroker.js.map +1 -1
- package/dist/cognition/emergent/broker/dry-run.d.ts +39 -0
- package/dist/cognition/emergent/broker/dry-run.d.ts.map +1 -0
- package/dist/cognition/emergent/broker/dry-run.js +88 -0
- package/dist/cognition/emergent/broker/dry-run.js.map +1 -0
- package/dist/cognition/emergent/broker/fetch.d.ts +30 -7
- package/dist/cognition/emergent/broker/fetch.d.ts.map +1 -1
- package/dist/cognition/emergent/broker/fetch.js +69 -9
- package/dist/cognition/emergent/broker/fetch.js.map +1 -1
- package/dist/cognition/emergent/broker/fs-write.d.ts +73 -0
- package/dist/cognition/emergent/broker/fs-write.d.ts.map +1 -0
- package/dist/cognition/emergent/broker/fs-write.js +268 -0
- package/dist/cognition/emergent/broker/fs-write.js.map +1 -0
- package/dist/cognition/emergent/broker/protected.d.ts +19 -0
- package/dist/cognition/emergent/broker/protected.d.ts.map +1 -0
- package/dist/cognition/emergent/broker/protected.js +89 -0
- package/dist/cognition/emergent/broker/protected.js.map +1 -0
- package/dist/cognition/emergent/capabilities.d.ts +2 -0
- package/dist/cognition/emergent/capabilities.d.ts.map +1 -1
- package/dist/cognition/emergent/capabilities.js +12 -2
- package/dist/cognition/emergent/capabilities.js.map +1 -1
- package/dist/cognition/emergent/ceiling.d.ts +38 -3
- package/dist/cognition/emergent/ceiling.d.ts.map +1 -1
- package/dist/cognition/emergent/ceiling.js +119 -2
- package/dist/cognition/emergent/ceiling.js.map +1 -1
- package/dist/cognition/emergent/executor/QuickJSExecutor.d.ts +1 -1
- package/dist/cognition/emergent/executor/QuickJSExecutor.d.ts.map +1 -1
- package/dist/cognition/emergent/executor/QuickJSExecutor.js +45 -15
- package/dist/cognition/emergent/executor/QuickJSExecutor.js.map +1 -1
- package/dist/cognition/emergent/executor/guest-prelude.d.ts.map +1 -1
- package/dist/cognition/emergent/executor/guest-prelude.js +48 -17
- package/dist/cognition/emergent/executor/guest-prelude.js.map +1 -1
- package/dist/cognition/emergent/executor/guest-surface.d.ts.map +1 -1
- package/dist/cognition/emergent/executor/guest-surface.js +18 -5
- package/dist/cognition/emergent/executor/guest-surface.js.map +1 -1
- package/dist/cognition/emergent/persisted-source.d.ts.map +1 -1
- package/dist/cognition/emergent/persisted-source.js +7 -1
- package/dist/cognition/emergent/persisted-source.js.map +1 -1
- package/dist/cognition/emergent/types.d.ts +117 -6
- package/dist/cognition/emergent/types.d.ts.map +1 -1
- package/dist/cognition/emergent/types.js.map +1 -1
- package/dist/cognition/substrate/GMI.d.ts.map +1 -1
- package/dist/cognition/substrate/GMI.js +58 -4
- package/dist/cognition/substrate/GMI.js.map +1 -1
- package/dist/cognition/substrate/IGMI.d.ts +2 -0
- package/dist/cognition/substrate/IGMI.d.ts.map +1 -1
- package/dist/cognition/substrate/IGMI.js.map +1 -1
- package/dist/core/tools/ITool.d.ts +12 -2
- package/dist/core/tools/ITool.d.ts.map +1 -1
- package/dist/core/utils/errors.d.ts +2 -0
- package/dist/core/utils/errors.d.ts.map +1 -1
- package/dist/core/utils/errors.js +3 -0
- package/dist/core/utils/errors.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/io/hearing/LiveKitTranscriptionOutput.d.ts +95 -0
- package/dist/io/hearing/LiveKitTranscriptionOutput.d.ts.map +1 -0
- package/dist/io/hearing/LiveKitTranscriptionOutput.js +108 -0
- package/dist/io/hearing/LiveKitTranscriptionOutput.js.map +1 -0
- package/dist/io/hearing/livekit.d.ts +15 -0
- package/dist/io/hearing/livekit.d.ts.map +1 -0
- package/dist/io/hearing/livekit.js +15 -0
- package/dist/io/hearing/livekit.js.map +1 -0
- package/dist/io/voice-pipeline/browser.d.ts +19 -0
- package/dist/io/voice-pipeline/browser.d.ts.map +1 -0
- package/dist/io/voice-pipeline/browser.js +20 -0
- package/dist/io/voice-pipeline/browser.js.map +1 -0
- package/dist/io/voice-pipeline/index.d.ts +1 -0
- package/dist/io/voice-pipeline/index.d.ts.map +1 -1
- package/dist/io/voice-pipeline/index.js +1 -0
- package/dist/io/voice-pipeline/index.js.map +1 -1
- package/dist/io/voice-pipeline/transcriptLedger.d.ts +139 -0
- package/dist/io/voice-pipeline/transcriptLedger.d.ts.map +1 -0
- package/dist/io/voice-pipeline/transcriptLedger.js +192 -0
- package/dist/io/voice-pipeline/transcriptLedger.js.map +1 -0
- package/dist/io/voice-pipeline/types.d.ts +27 -0
- package/dist/io/voice-pipeline/types.d.ts.map +1 -1
- package/package.json +11 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview A forge test's view of the files it touched. In a dry run
|
|
3
|
+
* every check is made as in a real call, but a write lands in a temporary
|
|
4
|
+
* directory made for the run, a delete marks its target gone for the run,
|
|
5
|
+
* and every check that asks whether a path exists, or what it is, asks this
|
|
6
|
+
* overlay first and the real tree second. A state-changing request is never
|
|
7
|
+
* sent: it takes the first unused answer the test case gave for its method
|
|
8
|
+
* and URL, or a `204` saying it was not sent.
|
|
9
|
+
* @module @framers/agentos/emergent/broker/dry-run
|
|
10
|
+
*/
|
|
11
|
+
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
/** The answers one forge test case may give its state-changing requests. */
|
|
15
|
+
export const MAX_TEST_RESPONSES = 16;
|
|
16
|
+
/** The header a state-changing request answered by a dry run carries when the test case gave no answer for it. */
|
|
17
|
+
export const NOT_SENT_HEADER = 'x-agentos-forge-test';
|
|
18
|
+
export class DryRunOverlay {
|
|
19
|
+
constructor(responses) {
|
|
20
|
+
this.responses = responses;
|
|
21
|
+
this.written = new Map();
|
|
22
|
+
this.deleted = new Set();
|
|
23
|
+
this.used = new Set();
|
|
24
|
+
this.counter = 0;
|
|
25
|
+
}
|
|
26
|
+
/** What the run did to `target` (a real path), if anything. */
|
|
27
|
+
look(target) {
|
|
28
|
+
if (this.written.has(target)) {
|
|
29
|
+
return 'file';
|
|
30
|
+
}
|
|
31
|
+
return this.deleted.has(target) ? 'absent' : undefined;
|
|
32
|
+
}
|
|
33
|
+
/** A write: the data goes to the run's own directory; the target reads as that file for the rest of the run. */
|
|
34
|
+
async write(target, data) {
|
|
35
|
+
this.dir ?? (this.dir = mkdtemp(path.join(tmpdir(), 'agentos-dry-run-')));
|
|
36
|
+
const dir = await this.dir;
|
|
37
|
+
this.counter += 1;
|
|
38
|
+
const file = path.join(dir, String(this.counter));
|
|
39
|
+
await writeFile(file, data, { flag: 'wx' });
|
|
40
|
+
this.written.set(target, file);
|
|
41
|
+
this.deleted.delete(target);
|
|
42
|
+
}
|
|
43
|
+
/** A delete: the target reads as absent for the rest of the run. */
|
|
44
|
+
remove(target) {
|
|
45
|
+
this.written.delete(target);
|
|
46
|
+
this.deleted.add(target);
|
|
47
|
+
}
|
|
48
|
+
/** The bytes the run wrote at `target`, or undefined when it wrote none there. */
|
|
49
|
+
async read(target) {
|
|
50
|
+
const file = this.written.get(target);
|
|
51
|
+
return file === undefined ? undefined : readFile(file);
|
|
52
|
+
}
|
|
53
|
+
/** The answer for a state-changing request, which is not sent. */
|
|
54
|
+
answer(method, url) {
|
|
55
|
+
for (let index = 0; index < this.responses.length; index += 1) {
|
|
56
|
+
const candidate = this.responses[index];
|
|
57
|
+
if (this.used.has(index) || candidate.method !== method) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
let candidateUrl;
|
|
61
|
+
try {
|
|
62
|
+
candidateUrl = new URL(candidate.url).href;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (candidateUrl === url.href) {
|
|
68
|
+
this.used.add(index);
|
|
69
|
+
// These statuses carry no body; the forge refuses an answer outside 200 to 599.
|
|
70
|
+
const noBody = candidate.status === 204 || candidate.status === 205 || candidate.status === 304;
|
|
71
|
+
return new Response(noBody ? null : (candidate.body ?? null), {
|
|
72
|
+
status: candidate.status,
|
|
73
|
+
headers: candidate.headers ?? {},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return new Response(null, { status: 204, headers: { [NOT_SENT_HEADER]: 'not-sent' } });
|
|
78
|
+
}
|
|
79
|
+
/** Removes the run's directory. */
|
|
80
|
+
async dispose() {
|
|
81
|
+
const dir = this.dir;
|
|
82
|
+
this.dir = undefined;
|
|
83
|
+
if (dir) {
|
|
84
|
+
await rm(await dir, { recursive: true, force: true }).catch(() => undefined);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=dry-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dry-run.js","sourceRoot":"","sources":["../../../../src/cognition/emergent/broker/dry-run.ts"],"names":[],"mappings":"AA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,IAAI,YAAY,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;gBAC9B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACrB,gFAAgF;gBAChF,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,MAAM,KAAK,GAAG,CAAC;gBAChG,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE;oBAC5D,MAAM,EAAE,SAAS,CAAC,MAAM;oBACxB,OAAO,EAAE,SAAS,CAAC,OAAO,IAAI,EAAE;iBACjC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;IACzF,CAAC;IAED,mCAAmC;IACnC,KAAK,CAAC,OAAO;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;QACrB,IAAI,GAAG,EAAE,CAAC;YACR,MAAM,EAAE,CAAC,MAAM,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;CACF"}
|
|
@@ -7,19 +7,39 @@
|
|
|
7
7
|
* body as a stream that is refused past its limit.
|
|
8
8
|
* @module @framers/agentos/emergent/broker/fetch
|
|
9
9
|
*/
|
|
10
|
+
import type { HttpMethod } from '../types.js';
|
|
11
|
+
import { CapabilityRefusal } from './refusal.js';
|
|
10
12
|
/** The scope a ceiling grants `fetch` under, with its defaults applied. */
|
|
11
13
|
export interface FetchScope {
|
|
12
14
|
domains: string[] | '*';
|
|
13
|
-
methods:
|
|
15
|
+
methods: HttpMethod[];
|
|
14
16
|
maxResponseBytes: number;
|
|
15
17
|
maxRedirects: number;
|
|
16
18
|
timeoutMs: number;
|
|
19
|
+
/** Set when `methods` holds a state-changing method. */
|
|
20
|
+
maxRequestBytes?: number;
|
|
17
21
|
}
|
|
18
22
|
/** A request that passed every check made before anything is sent. */
|
|
19
23
|
export interface PreparedFetch {
|
|
20
24
|
url: URL;
|
|
21
|
-
method:
|
|
25
|
+
method: HttpMethod;
|
|
22
26
|
headers: Headers;
|
|
27
|
+
/** A state-changing request's body; GET and HEAD carry none. */
|
|
28
|
+
body?: string | Uint8Array;
|
|
29
|
+
/** The body's size in bytes. */
|
|
30
|
+
bodyBytes?: number;
|
|
31
|
+
}
|
|
32
|
+
/** The methods that change state: sent with a bounded body, never redirected, recorded with their method. */
|
|
33
|
+
export declare const STATE_CHANGING: ReadonlySet<HttpMethod>;
|
|
34
|
+
/**
|
|
35
|
+
* A state-changing request cut (by the call's end or its time bound) after
|
|
36
|
+
* `fetch()` was called. Node's fetch does not say how far the request got,
|
|
37
|
+
* so the broker cannot tell whether the server acted on it: the record keeps
|
|
38
|
+
* no outcome (the store's unknown) and the code `cut_in_flight`.
|
|
39
|
+
*/
|
|
40
|
+
export declare class InFlightCut extends CapabilityRefusal {
|
|
41
|
+
readonly how: 'aborted' | 'timed_out';
|
|
42
|
+
constructor(how: 'aborted' | 'timed_out', host: string);
|
|
23
43
|
}
|
|
24
44
|
/**
|
|
25
45
|
* The URL a forged tool's first argument names: a string, a URL, or an object
|
|
@@ -29,15 +49,18 @@ export interface PreparedFetch {
|
|
|
29
49
|
export declare function fetchTarget(input: unknown): string | undefined;
|
|
30
50
|
/**
|
|
31
51
|
* The checks made before anything is sent. The caller's options are read for
|
|
32
|
-
* `method
|
|
33
|
-
* signal of the caller's are never passed
|
|
52
|
+
* `method`, `headers` and, for a state-changing method, `body` only: a
|
|
53
|
+
* redirect mode, credentials or a signal of the caller's are never passed
|
|
54
|
+
* on, and a body on GET or HEAD is dropped, as stage 1 dropped it.
|
|
34
55
|
*/
|
|
35
56
|
export declare function prepareFetch(input: unknown, init: unknown, scope: FetchScope): PreparedFetch;
|
|
36
57
|
/**
|
|
37
58
|
* Sends a prepared request. `signal` is the call's; the scope's `timeoutMs`
|
|
38
|
-
* bounds the whole request, redirects and body included.
|
|
39
|
-
* followed here, its host checked like the first
|
|
40
|
-
* method through every redirect status.
|
|
59
|
+
* bounds the whole request, redirects and body included. For GET and HEAD
|
|
60
|
+
* every redirect is followed here, its host checked like the first, and the
|
|
61
|
+
* method kept through every redirect status. A state-changing request is
|
|
62
|
+
* never redirected: its redirect answer is returned as it came, and a cut
|
|
63
|
+
* after it was sent is an {@link InFlightCut}.
|
|
41
64
|
*/
|
|
42
65
|
export declare function sendFetch(prepared: PreparedFetch, scope: FetchScope, signal: AbortSignal): Promise<{
|
|
43
66
|
response: Response;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/cognition/emergent/broker/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/cognition/emergent/broker/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACxB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,eA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abilityRefusal } from './refusal.js';
|
|
11
|
+
/** The methods that change state: sent with a bounded body, never redirected, recorded with their method. */
|
|
12
|
+
export const STATE_CHANGING = new Set(['POST', 'PUT', 'PATCH', 'DELETE']);
|
|
13
|
+
/**
|
|
14
|
+
* A state-changing request cut (by the call's end or its time bound) after
|
|
15
|
+
* `fetch()` was called. Node's fetch does not say how far the request got,
|
|
16
|
+
* so the broker cannot tell whether the server acted on it: the record keeps
|
|
17
|
+
* no outcome (the store's unknown) and the code `cut_in_flight`.
|
|
18
|
+
*/
|
|
19
|
+
export class InFlightCut extends CapabilityRefusal {
|
|
20
|
+
constructor(how, host) {
|
|
21
|
+
super('cut_in_flight', `${host}: the request was sent, and whether the server acted on it is unknown`);
|
|
22
|
+
this.how = how;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
11
25
|
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
12
26
|
const NULL_BODY_STATUSES = new Set([204, 205, 304]);
|
|
13
27
|
/** Dropped when a redirect changes the origin, as fetch itself does. */
|
|
@@ -67,10 +81,35 @@ function headersFrom(given) {
|
|
|
67
81
|
}
|
|
68
82
|
return headers;
|
|
69
83
|
}
|
|
84
|
+
/** A state-changing request's body: a string or bytes within the scope's bound, read once. */
|
|
85
|
+
function requestBody(given, limit) {
|
|
86
|
+
if (given === undefined || given === null) {
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
let body;
|
|
90
|
+
if (typeof given === 'string') {
|
|
91
|
+
body = given;
|
|
92
|
+
}
|
|
93
|
+
else if (given instanceof Uint8Array) {
|
|
94
|
+
body = given;
|
|
95
|
+
}
|
|
96
|
+
else if (given instanceof ArrayBuffer) {
|
|
97
|
+
body = new Uint8Array(given);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw new CapabilityRefusal('unsupported_body', 'a request body is a string or bytes');
|
|
101
|
+
}
|
|
102
|
+
const bodyBytes = typeof body === 'string' ? Buffer.byteLength(body, 'utf8') : body.byteLength;
|
|
103
|
+
if (bodyBytes > limit) {
|
|
104
|
+
throw new CapabilityRefusal('request_too_large', `${bodyBytes} bytes, more than ${limit}`);
|
|
105
|
+
}
|
|
106
|
+
return { body, bodyBytes };
|
|
107
|
+
}
|
|
70
108
|
/**
|
|
71
109
|
* The checks made before anything is sent. The caller's options are read for
|
|
72
|
-
* `method
|
|
73
|
-
* signal of the caller's are never passed
|
|
110
|
+
* `method`, `headers` and, for a state-changing method, `body` only: a
|
|
111
|
+
* redirect mode, credentials or a signal of the caller's are never passed
|
|
112
|
+
* on, and a body on GET or HEAD is dropped, as stage 1 dropped it.
|
|
74
113
|
*/
|
|
75
114
|
export function prepareFetch(input, init, scope) {
|
|
76
115
|
const raw = fetchTarget(input);
|
|
@@ -91,7 +130,11 @@ export function prepareFetch(input, init, scope) {
|
|
|
91
130
|
throw new CapabilityRefusal('method_not_allowed', method);
|
|
92
131
|
}
|
|
93
132
|
checkHost(url, scope);
|
|
94
|
-
|
|
133
|
+
const headers = headersFrom(options.headers);
|
|
134
|
+
if (!STATE_CHANGING.has(method)) {
|
|
135
|
+
return { url, method: method, headers };
|
|
136
|
+
}
|
|
137
|
+
return { url, method: method, headers, ...requestBody(options.body, scope.maxRequestBytes ?? 0) };
|
|
95
138
|
}
|
|
96
139
|
async function cappedBody(response, limit) {
|
|
97
140
|
if (!response.body) {
|
|
@@ -122,19 +165,36 @@ async function cappedBody(response, limit) {
|
|
|
122
165
|
}
|
|
123
166
|
/**
|
|
124
167
|
* Sends a prepared request. `signal` is the call's; the scope's `timeoutMs`
|
|
125
|
-
* bounds the whole request, redirects and body included.
|
|
126
|
-
* followed here, its host checked like the first
|
|
127
|
-
* method through every redirect status.
|
|
168
|
+
* bounds the whole request, redirects and body included. For GET and HEAD
|
|
169
|
+
* every redirect is followed here, its host checked like the first, and the
|
|
170
|
+
* method kept through every redirect status. A state-changing request is
|
|
171
|
+
* never redirected: its redirect answer is returned as it came, and a cut
|
|
172
|
+
* after it was sent is an {@link InFlightCut}.
|
|
128
173
|
*/
|
|
129
174
|
export async function sendFetch(prepared, scope, signal) {
|
|
130
175
|
const bounded = AbortSignal.any([signal, AbortSignal.timeout(scope.timeoutMs)]);
|
|
131
|
-
const
|
|
176
|
+
const changesState = STATE_CHANGING.has(prepared.method);
|
|
177
|
+
const ended = (host) => changesState
|
|
178
|
+
? new InFlightCut(signal.aborted ? 'aborted' : 'timed_out', host)
|
|
179
|
+
: new CapabilityRefusal(signal.aborted ? 'aborted' : 'timed_out', host);
|
|
180
|
+
// A typed array is not a BodyInit under TypeScript 5.7 and later; its own copy is.
|
|
181
|
+
const sentBody = prepared.body === undefined
|
|
182
|
+
? undefined
|
|
183
|
+
: typeof prepared.body === 'string'
|
|
184
|
+
? prepared.body
|
|
185
|
+
: prepared.body.slice().buffer;
|
|
132
186
|
const headers = new Headers(prepared.headers);
|
|
133
187
|
let url = prepared.url;
|
|
134
188
|
for (let redirects = 0;; redirects += 1) {
|
|
135
189
|
let response;
|
|
136
190
|
try {
|
|
137
|
-
response = await fetch(url, {
|
|
191
|
+
response = await fetch(url, {
|
|
192
|
+
method: prepared.method,
|
|
193
|
+
headers,
|
|
194
|
+
redirect: 'manual',
|
|
195
|
+
signal: bounded,
|
|
196
|
+
...(sentBody !== undefined ? { body: sentBody } : {}),
|
|
197
|
+
});
|
|
138
198
|
}
|
|
139
199
|
catch (error) {
|
|
140
200
|
if (bounded.aborted) {
|
|
@@ -143,7 +203,7 @@ export async function sendFetch(prepared, scope, signal) {
|
|
|
143
203
|
throw error;
|
|
144
204
|
}
|
|
145
205
|
const location = response.headers.get('location');
|
|
146
|
-
if (REDIRECT_STATUSES.has(response.status) && location !== null) {
|
|
206
|
+
if (!changesState && REDIRECT_STATUSES.has(response.status) && location !== null) {
|
|
147
207
|
await response.body?.cancel().catch(() => undefined);
|
|
148
208
|
if (redirects >= scope.maxRedirects) {
|
|
149
209
|
throw new CapabilityRefusal('too_many_redirects', `more than ${scope.maxRedirects}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../../src/cognition/emergent/broker/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../../src/cognition/emergent/broker/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAwBjD,6GAA6G;AAC7G,MAAM,CAAC,MAAM,cAAc,GAA4B,IAAI,GAAG,CAAa,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE/G;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,iBAAiB;IAChD,YACW,GAA4B,EACrC,IAAY;QAEZ,KAAK,CAAC,eAAe,EAAE,GAAG,IAAI,uEAAuE,CAAC,CAAC;QAH9F,QAAG,GAAH,GAAG,CAAyB;IAIvC,CAAC;CACF;AAED,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC7D,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACpD,wEAAwE;AACxE,MAAM,oBAAoB,GAAG,CAAC,eAAe,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAExF;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,YAAY,GAAG,EAAE,CAAC;QACzB,OAAO,KAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IACD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAA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D,OAAO;YACL,qEAAqE;YACrE,0DAA0D;YAC1D,QAAQ,EAAE,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAE,IAAI,CAAC,MAAsB,EAAE;gBAC1E,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;aAC1B,CAAC;YACF,KAAK,EAAE,IAAI,EAAE,UAAU,IAAI,CAAC;SAC7B,CAAC;IACJ,CAAC;AACH,CAAC;AAED,4EAA4E;AAC5E,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAAc,EACd,IAAa,EACb,KAAiB,EACjB,MAAmB;IAEnB,OAAO,CAAC,MAAM,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The broker's `fs.writeFile` and `fs.unlink` for code-forged
|
|
3
|
+
* tools under a ceiling: the path checks against the roots (lexical, then
|
|
4
|
+
* the parent's real path, then the last component), and the operations. A
|
|
5
|
+
* write opens its file with an exclusive create and no signal, so the broker
|
|
6
|
+
* always knows whether it made the file, and writes through the handle in
|
|
7
|
+
* chunks, checking the call's signal and its own time bound between them: a
|
|
8
|
+
* cut write closes the handle and removes what it made. A removal or a
|
|
9
|
+
* rename, once started, runs to its end. Node has no `openat`, so a process
|
|
10
|
+
* that swaps a parent directory for a link between the check and the open is
|
|
11
|
+
* outside what these checks stop; and an exclusive create on a network file
|
|
12
|
+
* system that does not honour it is too. The documentation says both.
|
|
13
|
+
* @module @framers/agentos/emergent/broker/fs-write
|
|
14
|
+
*/
|
|
15
|
+
import type { DryRunOverlay } from './dry-run.js';
|
|
16
|
+
import { CapabilityRefusal } from './refusal.js';
|
|
17
|
+
/**
|
|
18
|
+
* An effect cut by the call's end or by its own time bound before it was
|
|
19
|
+
* done. `fileLeft` is set when the broker could not remove a file it made.
|
|
20
|
+
*/
|
|
21
|
+
export declare class EffectCut extends CapabilityRefusal {
|
|
22
|
+
readonly outcome: 'aborted' | 'timed_out';
|
|
23
|
+
readonly fileLeft: boolean;
|
|
24
|
+
constructor(outcome: 'aborted' | 'timed_out', detail: string, fileLeft?: boolean);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Write or delete roots, each root's real path resolved lazily and pinned,
|
|
28
|
+
* as the broker's read roots are. A root whose real path is protected (see
|
|
29
|
+
* protected.ts) is set apart when it resolves: a target under it is refused
|
|
30
|
+
* with `protected_path`, whether the root existed at construction or not.
|
|
31
|
+
*/
|
|
32
|
+
export declare class EffectRoots {
|
|
33
|
+
readonly roots: readonly string[];
|
|
34
|
+
private readonly protectedReal;
|
|
35
|
+
private readonly cache;
|
|
36
|
+
private readonly guarded;
|
|
37
|
+
constructor(roots: readonly string[], protectedReal: readonly string[]);
|
|
38
|
+
/** The roots' real paths, the protected ones set apart. */
|
|
39
|
+
real(): Promise<{
|
|
40
|
+
allowed: string[];
|
|
41
|
+
guarded: string[];
|
|
42
|
+
}>;
|
|
43
|
+
private realOf;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A write's scope: the path checks, then the last component, which may
|
|
47
|
+
* exist only as a regular file, and under `create-only` not at all.
|
|
48
|
+
*/
|
|
49
|
+
export declare function checkWrite(filePath: unknown, roots: EffectRoots, mode: 'create-only' | 'create-or-replace', overlay?: DryRunOverlay): Promise<string>;
|
|
50
|
+
/** A delete's scope: the path checks, then the last component, which must be a regular file. */
|
|
51
|
+
export declare function checkDelete(filePath: unknown, roots: EffectRoots, overlay?: DryRunOverlay): Promise<string>;
|
|
52
|
+
/** The data a write carries, as bytes: a string is written as UTF-8. */
|
|
53
|
+
export declare function writeBytes(data: unknown): Uint8Array;
|
|
54
|
+
/**
|
|
55
|
+
* Writes `data` at `target` (already checked). Under `create-only` the
|
|
56
|
+
* target itself is created exclusively; under `create-or-replace` a
|
|
57
|
+
* temporary file beside it, named for the call, is created exclusively and
|
|
58
|
+
* then renamed over the target. A cut (the call's `signal`, or the effect's
|
|
59
|
+
* `timer`, started when the effect was admitted) that arrives while the open
|
|
60
|
+
* runs takes effect once the open settles.
|
|
61
|
+
*/
|
|
62
|
+
export declare function writeAt(target: string, data: Uint8Array, mode: 'create-only' | 'create-or-replace', callId: string, signal: AbortSignal, timer: AbortSignal): Promise<{
|
|
63
|
+
bytes: number;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Removes `target` (already checked): one directory entry, a regular file.
|
|
67
|
+
* The removal is one system call: the call's `signal` and the effect's
|
|
68
|
+
* `timer` can stop it from starting, and once started it runs to its end.
|
|
69
|
+
*/
|
|
70
|
+
export declare function removeAt(target: string, signal: AbortSignal, timer: AbortSignal): Promise<{
|
|
71
|
+
bytes: number;
|
|
72
|
+
}>;
|
|
73
|
+
//# sourceMappingURL=fs-write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-write.d.ts","sourceRoot":"","sources":["../../../../src/cognition/emergent/broker/fs-write.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAKjD;;;GAGG;AACH,qBAAa,SAAU,SAAQ,iBAAiB;IAE5C,QAAQ,CAAC,OAAO,EAAE,SAAS,GAAG,WAAW;IAEzC,QAAQ,CAAC,QAAQ,EAAE,OAAO;gBAFjB,OAAO,EAAE,SAAS,GAAG,WAAW,EACzC,MAAM,EAAE,MAAM,EACL,QAAQ,GAAE,OAAe;CAIrC;AAED;;;;;GAKG;AACH,qBAAa,WAAW;IAKpB,QAAQ,CAAC,KAAK,EAA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