@nexum-hub/agent 0.0.0-stage → 0.0.2
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/README.md +133 -2
- package/contracts/v2/common.schema.json +262 -0
- package/contracts/v2/fixtures/inputs.json +244 -0
- package/contracts/v2/fixtures/wire.json +6493 -0
- package/contracts/v2/model/agent.close.input.schema.json +14 -0
- package/contracts/v2/model/agent.close.output.schema.json +101 -0
- package/contracts/v2/model/agent.list.input.schema.json +57 -0
- package/contracts/v2/model/agent.list.output.schema.json +220 -0
- package/contracts/v2/model/agent.open.input.schema.json +35 -0
- package/contracts/v2/model/agent.open.output.schema.json +41 -0
- package/contracts/v2/model/agent.run.cancel.input.schema.json +18 -0
- package/contracts/v2/model/agent.run.cancel.output.schema.json +100 -0
- package/contracts/v2/model/agent.run.get.input.schema.json +41 -0
- package/contracts/v2/model/agent.run.get.output.schema.json +100 -0
- package/contracts/v2/model/agent.run.input.input.schema.json +30 -0
- package/contracts/v2/model/agent.run.input.output.schema.json +100 -0
- package/contracts/v2/model/agent.run.list.input.schema.json +47 -0
- package/contracts/v2/model/agent.run.list.output.schema.json +41 -0
- package/contracts/v2/model/agent.run.start.input.schema.json +73 -0
- package/contracts/v2/model/agent.run.start.output.schema.json +100 -0
- package/contracts/v2/wire/bodies.schema.json +383 -0
- package/contracts/v2/wire/envelope.schema.json +2280 -0
- package/contracts/v2/wire/events.schema.json +242 -0
- package/contracts/v2/wire/maintenance.schema.json +308 -0
- package/contracts/v2/wire/operations.schema.json +1791 -0
- package/contracts/v2/wire/stream.schema.json +74 -0
- package/contracts/v2/wire/types.schema.json +2616 -0
- package/dist/adapters/mcp-http.d.ts +22 -0
- package/dist/adapters/mcp-http.js +472 -0
- package/dist/adapters/mcp-http.js.map +1 -0
- package/dist/adapters/mcp-oauth.d.ts +29 -0
- package/dist/adapters/mcp-oauth.js +653 -0
- package/dist/adapters/mcp-oauth.js.map +1 -0
- package/dist/adapters/mcp-wire.d.ts +21 -0
- package/dist/adapters/mcp-wire.js +307 -0
- package/dist/adapters/mcp-wire.js.map +1 -0
- package/dist/adapters/mcp.d.ts +56 -0
- package/dist/adapters/mcp.js +1989 -0
- package/dist/adapters/mcp.js.map +1 -0
- package/dist/adapters/openapi-http.d.ts +29 -0
- package/dist/adapters/openapi-http.js +504 -0
- package/dist/adapters/openapi-http.js.map +1 -0
- package/dist/adapters/openapi-request.d.ts +26 -0
- package/dist/adapters/openapi-request.js +597 -0
- package/dist/adapters/openapi-request.js.map +1 -0
- package/dist/adapters/openapi-schema.d.ts +22 -0
- package/dist/adapters/openapi-schema.js +471 -0
- package/dist/adapters/openapi-schema.js.map +1 -0
- package/dist/adapters/openapi-typegen.d.ts +11 -0
- package/dist/adapters/openapi-typegen.js +185 -0
- package/dist/adapters/openapi-typegen.js.map +1 -0
- package/dist/adapters/openapi-types.d.ts +99 -0
- package/dist/adapters/openapi-types.js +2 -0
- package/dist/adapters/openapi-types.js.map +1 -0
- package/dist/adapters/openapi.d.ts +7 -0
- package/dist/adapters/openapi.js +768 -0
- package/dist/adapters/openapi.js.map +1 -0
- package/dist/application/activation.d.ts +28 -0
- package/dist/application/activation.js +289 -0
- package/dist/application/activation.js.map +1 -0
- package/dist/application/attachments.d.ts +24 -0
- package/dist/application/attachments.js +87 -0
- package/dist/application/attachments.js.map +1 -0
- package/dist/application/authority.d.ts +32 -0
- package/dist/application/authority.js +213 -0
- package/dist/application/authority.js.map +1 -0
- package/dist/application/catalog.d.ts +11 -0
- package/dist/application/catalog.js +177 -0
- package/dist/application/catalog.js.map +1 -0
- package/dist/application/config.d.ts +24 -0
- package/dist/application/config.js +140 -0
- package/dist/application/config.js.map +1 -0
- package/dist/application/connection.d.ts +35 -0
- package/dist/application/connection.js +465 -0
- package/dist/application/connection.js.map +1 -0
- package/dist/application/data-plane.d.ts +35 -0
- package/dist/application/data-plane.js +437 -0
- package/dist/application/data-plane.js.map +1 -0
- package/dist/application/diagnostics.d.ts +4 -0
- package/dist/application/diagnostics.js +65 -0
- package/dist/application/diagnostics.js.map +1 -0
- package/dist/application/dispatcher.d.ts +4 -0
- package/dist/application/dispatcher.js +16 -0
- package/dist/application/dispatcher.js.map +1 -0
- package/dist/application/main.d.ts +12 -0
- package/dist/application/main.js +167 -0
- package/dist/application/main.js.map +1 -0
- package/dist/application/maintenance.d.ts +27 -0
- package/dist/application/maintenance.js +244 -0
- package/dist/application/maintenance.js.map +1 -0
- package/dist/application/packages.d.ts +25 -0
- package/dist/application/packages.js +208 -0
- package/dist/application/packages.js.map +1 -0
- package/dist/application/processes.d.ts +49 -0
- package/dist/application/processes.js +180 -0
- package/dist/application/processes.js.map +1 -0
- package/dist/application/run-view.d.ts +17 -0
- package/dist/application/run-view.js +286 -0
- package/dist/application/run-view.js.map +1 -0
- package/dist/application/runtime.d.ts +78 -0
- package/dist/application/runtime.js +1747 -0
- package/dist/application/runtime.js.map +1 -0
- package/dist/application/tasks.d.ts +38 -0
- package/dist/application/tasks.js +23 -0
- package/dist/application/tasks.js.map +1 -0
- package/dist/application/user-state.d.ts +20 -0
- package/dist/application/user-state.js +52 -0
- package/dist/application/user-state.js.map +1 -0
- package/dist/application/work-git.d.ts +14 -0
- package/dist/application/work-git.js +67 -0
- package/dist/application/work-git.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +40 -0
- package/dist/cli.js.map +1 -0
- package/dist/contracts/caller.d.ts +51 -0
- package/dist/contracts/caller.js +95 -0
- package/dist/contracts/caller.js.map +1 -0
- package/dist/contracts/error-data.d.ts +6 -0
- package/dist/contracts/error-data.js +51 -0
- package/dist/contracts/error-data.js.map +1 -0
- package/dist/contracts/errors.d.ts +10 -0
- package/dist/contracts/errors.js +28 -0
- package/dist/contracts/errors.js.map +1 -0
- package/dist/contracts/json.d.ts +9 -0
- package/dist/contracts/json.js +104 -0
- package/dist/contracts/json.js.map +1 -0
- package/dist/contracts/types.d.ts +122 -0
- package/dist/contracts/types.js +19 -0
- package/dist/contracts/types.js.map +1 -0
- package/dist/contracts/validation.d.ts +4 -0
- package/dist/contracts/validation.js +157 -0
- package/dist/contracts/validation.js.map +1 -0
- package/dist/contracts/wire-validation.d.ts +9 -0
- package/dist/contracts/wire-validation.js +399 -0
- package/dist/contracts/wire-validation.js.map +1 -0
- package/dist/contracts/wire.d.ts +1083 -0
- package/dist/contracts/wire.js +62 -0
- package/dist/contracts/wire.js.map +1 -0
- package/dist/extension-api.d.ts +12 -0
- package/dist/extension-api.js +2 -0
- package/dist/extension-api.js.map +1 -0
- package/dist/extensions/api.d.ts +72 -0
- package/dist/extensions/api.js +2 -0
- package/dist/extensions/api.js.map +1 -0
- package/dist/extensions/host-requests.d.ts +23 -0
- package/dist/extensions/host-requests.js +60 -0
- package/dist/extensions/host-requests.js.map +1 -0
- package/dist/extensions/materials.d.ts +37 -0
- package/dist/extensions/materials.js +691 -0
- package/dist/extensions/materials.js.map +1 -0
- package/dist/extensions/package-loader.d.ts +28 -0
- package/dist/extensions/package-loader.js +177 -0
- package/dist/extensions/package-loader.js.map +1 -0
- package/dist/extensions/packages.d.ts +73 -0
- package/dist/extensions/packages.js +441 -0
- package/dist/extensions/packages.js.map +1 -0
- package/dist/extensions/registry.d.ts +92 -0
- package/dist/extensions/registry.js +1540 -0
- package/dist/extensions/registry.js.map +1 -0
- package/dist/extensions/resources.d.ts +105 -0
- package/dist/extensions/resources.js +595 -0
- package/dist/extensions/resources.js.map +1 -0
- package/dist/extensions/state.d.ts +25 -0
- package/dist/extensions/state.js +10 -0
- package/dist/extensions/state.js.map +1 -0
- package/dist/extensions/transfer.d.ts +81 -0
- package/dist/extensions/transfer.js +16 -0
- package/dist/extensions/transfer.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/maintenance/configuration.d.ts +79 -0
- package/dist/maintenance/configuration.js +1503 -0
- package/dist/maintenance/configuration.js.map +1 -0
- package/dist/maintenance/credentials.d.ts +23 -0
- package/dist/maintenance/credentials.js +177 -0
- package/dist/maintenance/credentials.js.map +1 -0
- package/dist/maintenance/files.d.ts +2 -0
- package/dist/maintenance/files.js +40 -0
- package/dist/maintenance/files.js.map +1 -0
- package/dist/maintenance/npm.d.ts +71 -0
- package/dist/maintenance/npm.js +1013 -0
- package/dist/maintenance/npm.js.map +1 -0
- package/dist/maintenance/oauth.d.ts +45 -0
- package/dist/maintenance/oauth.js +686 -0
- package/dist/maintenance/oauth.js.map +1 -0
- package/dist/maintenance/requests.d.ts +347 -0
- package/dist/maintenance/requests.js +959 -0
- package/dist/maintenance/requests.js.map +1 -0
- package/dist/maintenance/work-git.d.ts +29 -0
- package/dist/maintenance/work-git.js +776 -0
- package/dist/maintenance/work-git.js.map +1 -0
- package/dist/process/backend.d.ts +54 -0
- package/dist/process/backend.js +39 -0
- package/dist/process/backend.js.map +1 -0
- package/dist/process/environment-windows.d.ts +15 -0
- package/dist/process/environment-windows.js +151 -0
- package/dist/process/environment-windows.js.map +1 -0
- package/dist/process/environment.d.ts +28 -0
- package/dist/process/environment.js +410 -0
- package/dist/process/environment.js.map +1 -0
- package/dist/process/launch.d.ts +31 -0
- package/dist/process/launch.js +281 -0
- package/dist/process/launch.js.map +1 -0
- package/dist/process/managed.d.ts +36 -0
- package/dist/process/managed.js +459 -0
- package/dist/process/managed.js.map +1 -0
- package/dist/process/output-log.d.ts +50 -0
- package/dist/process/output-log.js +552 -0
- package/dist/process/output-log.js.map +1 -0
- package/dist/process/pipes.d.ts +16 -0
- package/dist/process/pipes.js +588 -0
- package/dist/process/pipes.js.map +1 -0
- package/dist/process/pty.d.ts +22 -0
- package/dist/process/pty.js +512 -0
- package/dist/process/pty.js.map +1 -0
- package/dist/process/windows-conout-worker.d.ts +1 -0
- package/dist/process/windows-conout-worker.js +90 -0
- package/dist/process/windows-conout-worker.js.map +1 -0
- package/dist/process/windows-conout.d.ts +46 -0
- package/dist/process/windows-conout.js +140 -0
- package/dist/process/windows-conout.js.map +1 -0
- package/dist/process/windows-helper.d.ts +43 -0
- package/dist/process/windows-helper.js +255 -0
- package/dist/process/windows-helper.js.map +1 -0
- package/dist/process/windows-job.d.ts +39 -0
- package/dist/process/windows-job.js +224 -0
- package/dist/process/windows-job.js.map +1 -0
- package/dist/process/windows-pipes.d.ts +16 -0
- package/dist/process/windows-pipes.js +475 -0
- package/dist/process/windows-pipes.js.map +1 -0
- package/dist/results/artifacts.d.ts +118 -0
- package/dist/results/artifacts.js +873 -0
- package/dist/results/artifacts.js.map +1 -0
- package/dist/results/encoder.d.ts +57 -0
- package/dist/results/encoder.js +1179 -0
- package/dist/results/encoder.js.map +1 -0
- package/dist/results/mcp.d.ts +95 -0
- package/dist/results/mcp.js +656 -0
- package/dist/results/mcp.js.map +1 -0
- package/dist/results/media.d.ts +19 -0
- package/dist/results/media.js +301 -0
- package/dist/results/media.js.map +1 -0
- package/dist/results/normalize.d.ts +29 -0
- package/dist/results/normalize.js +464 -0
- package/dist/results/normalize.js.map +1 -0
- package/dist/runtime/control-scripts.d.ts +23 -0
- package/dist/runtime/control-scripts.js +242 -0
- package/dist/runtime/control-scripts.js.map +1 -0
- package/dist/runtime/engine.d.ts +177 -0
- package/dist/runtime/engine.js +1159 -0
- package/dist/runtime/engine.js.map +1 -0
- package/dist/runtime/globals.d.ts +1 -0
- package/dist/runtime/globals.js +31 -0
- package/dist/runtime/globals.js.map +1 -0
- package/dist/runtime/material-retention.d.ts +34 -0
- package/dist/runtime/material-retention.js +671 -0
- package/dist/runtime/material-retention.js.map +1 -0
- package/dist/runtime/modules.d.ts +50 -0
- package/dist/runtime/modules.js +320 -0
- package/dist/runtime/modules.js.map +1 -0
- package/dist/runtime/names.d.ts +2 -0
- package/dist/runtime/names.js +22 -0
- package/dist/runtime/names.js.map +1 -0
- package/dist/runtime/operations.d.ts +20 -0
- package/dist/runtime/operations.js +137 -0
- package/dist/runtime/operations.js.map +1 -0
- package/dist/runtime/paths.d.ts +3 -0
- package/dist/runtime/paths.js +38 -0
- package/dist/runtime/paths.js.map +1 -0
- package/dist/runtime/promises.d.ts +9 -0
- package/dist/runtime/promises.js +78 -0
- package/dist/runtime/promises.js.map +1 -0
- package/dist/runtime/retention.d.ts +88 -0
- package/dist/runtime/retention.js +735 -0
- package/dist/runtime/retention.js.map +1 -0
- package/dist/runtime/run-log.d.ts +30 -0
- package/dist/runtime/run-log.js +207 -0
- package/dist/runtime/run-log.js.map +1 -0
- package/dist/runtime/scripts.d.ts +84 -0
- package/dist/runtime/scripts.js +387 -0
- package/dist/runtime/scripts.js.map +1 -0
- package/dist/runtime/tasks.d.ts +54 -0
- package/dist/runtime/tasks.js +290 -0
- package/dist/runtime/tasks.js.map +1 -0
- package/dist/sdk/maintenance.d.ts +3 -0
- package/dist/sdk/maintenance.js +80 -0
- package/dist/sdk/maintenance.js.map +1 -0
- package/dist/sdk/output-extension.d.ts +3 -0
- package/dist/sdk/output-extension.js +44 -0
- package/dist/sdk/output-extension.js.map +1 -0
- package/dist/sdk/output.d.ts +52 -0
- package/dist/sdk/output.js +350 -0
- package/dist/sdk/output.js.map +1 -0
- package/dist/sdk/runtime.d.ts +3 -0
- package/dist/sdk/runtime.js +26 -0
- package/dist/sdk/runtime.js.map +1 -0
- package/dist/sdk/sh.d.ts +3 -0
- package/dist/sdk/sh.js +384 -0
- package/dist/sdk/sh.js.map +1 -0
- package/dist/sdk/state.d.ts +2 -0
- package/dist/sdk/state.js +69 -0
- package/dist/sdk/state.js.map +1 -0
- package/dist/sdk/transfer.d.ts +3 -0
- package/dist/sdk/transfer.js +141 -0
- package/dist/sdk/transfer.js.map +1 -0
- package/dist/services/extensions.d.ts +19 -0
- package/dist/services/extensions.js +183 -0
- package/dist/services/extensions.js.map +1 -0
- package/dist/services/state.d.ts +37 -0
- package/dist/services/state.js +125 -0
- package/dist/services/state.js.map +1 -0
- package/dist/services/transfer.d.ts +86 -0
- package/dist/services/transfer.js +948 -0
- package/dist/services/transfer.js.map +1 -0
- package/dist/storage/schema.d.ts +8 -0
- package/dist/storage/schema.js +241 -0
- package/dist/storage/schema.js.map +1 -0
- package/dist/storage/sqlite.d.ts +241 -0
- package/dist/storage/sqlite.js +1855 -0
- package/dist/storage/sqlite.js.map +1 -0
- package/dist/storage/transfers.d.ts +90 -0
- package/dist/storage/transfers.js +2 -0
- package/dist/storage/transfers.js.map +1 -0
- package/dist/transfer/io.d.ts +74 -0
- package/dist/transfer/io.js +425 -0
- package/dist/transfer/io.js.map +1 -0
- package/dist/transfer/offers.d.ts +72 -0
- package/dist/transfer/offers.js +380 -0
- package/dist/transfer/offers.js.map +1 -0
- package/dist/transfer/stream-slots.d.ts +12 -0
- package/dist/transfer/stream-slots.js +28 -0
- package/dist/transfer/stream-slots.js.map +1 -0
- package/dist/work/catalog.d.ts +43 -0
- package/dist/work/catalog.js +198 -0
- package/dist/work/catalog.js.map +1 -0
- package/dist/work/discovery.d.ts +70 -0
- package/dist/work/discovery.js +465 -0
- package/dist/work/discovery.js.map +1 -0
- package/dist/work/service.d.ts +83 -0
- package/dist/work/service.js +703 -0
- package/dist/work/service.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1,948 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { performance } from "node:perf_hooks";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { MIMEType, types } from "node:util";
|
|
5
|
+
import { AgentError, requireCondition } from "../contracts/errors.js";
|
|
6
|
+
import { authorizeCall, callerKey, fixedCaller, } from "../contracts/caller.js";
|
|
7
|
+
import { canonicalJson, isPlainRecord } from "../contracts/json.js";
|
|
8
|
+
import { prepareUpload, receiveUpload, sendDownload, TransferIoError, } from "../transfer/io.js";
|
|
9
|
+
import { TransferStreamSlots, } from "../transfer/stream-slots.js";
|
|
10
|
+
const terminal = new Set([
|
|
11
|
+
"succeeded",
|
|
12
|
+
"failed",
|
|
13
|
+
"cancelled",
|
|
14
|
+
"expired",
|
|
15
|
+
"interrupted",
|
|
16
|
+
]);
|
|
17
|
+
const statuses = new Set([
|
|
18
|
+
"preparing",
|
|
19
|
+
"pending",
|
|
20
|
+
"transferring",
|
|
21
|
+
"cancelling",
|
|
22
|
+
...terminal,
|
|
23
|
+
]);
|
|
24
|
+
const denials = new Set([
|
|
25
|
+
"forbidden",
|
|
26
|
+
"permission_denied",
|
|
27
|
+
"access_denied",
|
|
28
|
+
"resource_forbidden",
|
|
29
|
+
"path_not_allowed",
|
|
30
|
+
"unauthorized",
|
|
31
|
+
]);
|
|
32
|
+
const iso = (value) => value == null ? null : new Date(value).toISOString();
|
|
33
|
+
function data(value, max = 16384) {
|
|
34
|
+
return JSON.parse(canonicalJson(value, max));
|
|
35
|
+
}
|
|
36
|
+
function keys(value, allowed) {
|
|
37
|
+
requireCondition(isPlainRecord(value) &&
|
|
38
|
+
Object.keys(value).every((key) => allowed.includes(key)), "invalid_arguments", "Only the documented transfer parameters are accepted.");
|
|
39
|
+
}
|
|
40
|
+
function text(value, maximum = 4096) {
|
|
41
|
+
requireCondition(typeof value === "string" &&
|
|
42
|
+
value.length > 0 &&
|
|
43
|
+
Buffer.byteLength(value) <= maximum &&
|
|
44
|
+
!/[\0\r\n]/.test(value), "invalid_arguments", "A transfer parameter must be bounded nonempty text.");
|
|
45
|
+
}
|
|
46
|
+
function mime(value) {
|
|
47
|
+
text(value, 256);
|
|
48
|
+
try {
|
|
49
|
+
return new MIMEType(value).toString();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new AgentError("invalid_arguments", "The transfer MIME type is invalid.");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function safeError(cause, fallback = "transfer_failed") {
|
|
56
|
+
// Causes and transport messages can contain credential-bearing URLs. Persist only known codes.
|
|
57
|
+
const code = cause instanceof AgentError && /^[a-z][a-z0-9_]{0,95}$/.test(cause.code)
|
|
58
|
+
? cause.code
|
|
59
|
+
: fallback;
|
|
60
|
+
return {
|
|
61
|
+
code,
|
|
62
|
+
message: "The transfer did not complete; inspect its retained state and closure diagnostics.",
|
|
63
|
+
...(cause instanceof TransferIoError
|
|
64
|
+
? {
|
|
65
|
+
details: {
|
|
66
|
+
fileCommitted: cause.fileCommitted,
|
|
67
|
+
cleanupConfirmed: cause.cleanupConfirmed,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
: {}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** Agent/profile Core coordinator. Extension factories receive only bind()'s public service. */
|
|
74
|
+
export class TransferServices extends EventEmitter {
|
|
75
|
+
store;
|
|
76
|
+
resources;
|
|
77
|
+
artifacts;
|
|
78
|
+
offers;
|
|
79
|
+
channels;
|
|
80
|
+
streams;
|
|
81
|
+
#instance;
|
|
82
|
+
#instanceController = new AbortController();
|
|
83
|
+
#entries = new Map();
|
|
84
|
+
#reservations = new WeakMap();
|
|
85
|
+
#maxBytes;
|
|
86
|
+
#claimMs;
|
|
87
|
+
#activeMs;
|
|
88
|
+
#reservationMs;
|
|
89
|
+
#now;
|
|
90
|
+
#origin;
|
|
91
|
+
constructor(store, resources, artifacts, offers, channels, options) {
|
|
92
|
+
super();
|
|
93
|
+
this.store = store;
|
|
94
|
+
this.resources = resources;
|
|
95
|
+
this.artifacts = artifacts;
|
|
96
|
+
this.offers = offers;
|
|
97
|
+
this.channels = channels;
|
|
98
|
+
this.setMaxListeners(0);
|
|
99
|
+
this.#origin = data(options.origin);
|
|
100
|
+
requireCondition(this.#origin.type === "platform" &&
|
|
101
|
+
this.#origin.namespace === "transfer" &&
|
|
102
|
+
this.#origin.owner &&
|
|
103
|
+
this.#origin.version &&
|
|
104
|
+
this.#origin.revision, "invalid_transfer_options", "Transfer resources need their actual Core platform source.");
|
|
105
|
+
requireCondition(resources.store === store, "invalid_transfer_options", "Transfers and managed resources must share one profile authority.");
|
|
106
|
+
requireCondition(artifacts.root === store.root &&
|
|
107
|
+
artifacts.agentId === store.binding.agentId &&
|
|
108
|
+
offers.profileRoot === store.root &&
|
|
109
|
+
offers.agentId === store.binding.agentId, "invalid_transfer_options", "Transfers, artifacts and offers must share the actual Agent/profile.");
|
|
110
|
+
this.#maxBytes = options.maxBytes ?? 256 * 1024 ** 2;
|
|
111
|
+
this.#claimMs = options.claimTimeoutMs ?? 10 * 60_000;
|
|
112
|
+
this.#activeMs = options.activeTimeoutMs ?? 30 * 60_000;
|
|
113
|
+
this.#reservationMs = options.reservationTimeoutMs ?? 5000;
|
|
114
|
+
for (const [value, maximum] of [
|
|
115
|
+
[this.#maxBytes, 20 * 1024 ** 3],
|
|
116
|
+
[this.#claimMs, 600_000],
|
|
117
|
+
[this.#activeMs, 1_800_000],
|
|
118
|
+
[this.#reservationMs, 30_000],
|
|
119
|
+
])
|
|
120
|
+
requireCondition(Number.isSafeInteger(value) && value > 0 && value <= maximum, "invalid_transfer_options", "Transfer budgets and deadlines must be bounded trusted Agent configuration.");
|
|
121
|
+
const wallNow = options.now ?? Date.now;
|
|
122
|
+
let monotonicAt = performance.now();
|
|
123
|
+
let logicalAt = wallNow();
|
|
124
|
+
this.#now = () => {
|
|
125
|
+
const monotonicNow = performance.now();
|
|
126
|
+
// Like RunEngine, elapsed monotonic time is a lower bound when the
|
|
127
|
+
// wall clock moves backwards. Retain fractions internally so frequent
|
|
128
|
+
// progress/checks cannot discard elapsed time, and retain observed
|
|
129
|
+
// forward jumps when the wall clock subsequently returns.
|
|
130
|
+
logicalAt = Math.max(wallNow(), logicalAt + monotonicNow - monotonicAt);
|
|
131
|
+
monotonicAt = monotonicNow;
|
|
132
|
+
return Math.floor(logicalAt);
|
|
133
|
+
};
|
|
134
|
+
this.streams = options.streams ?? new TransferStreamSlots();
|
|
135
|
+
this.#instance = resources.instance(this.#origin, {
|
|
136
|
+
signal: this.#instanceController.signal,
|
|
137
|
+
assertActive: () => this.#instanceController.signal.throwIfAborted(),
|
|
138
|
+
authorize() { },
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
#owner(caller) {
|
|
142
|
+
return {
|
|
143
|
+
callerKey: callerKey(caller),
|
|
144
|
+
owner: {
|
|
145
|
+
type: this.#origin.type,
|
|
146
|
+
owner: this.#origin.owner,
|
|
147
|
+
namespace: this.#origin.namespace,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
#current(scope, access, value) {
|
|
152
|
+
scope.signal.throwIfAborted();
|
|
153
|
+
authorizeCall(() => scope.assertCurrent());
|
|
154
|
+
authorizeCall(() => scope.authorize({ type: "transfer", value, access }));
|
|
155
|
+
}
|
|
156
|
+
#authority(scope) {
|
|
157
|
+
const caller = scope.context.caller;
|
|
158
|
+
requireCondition(isPlainRecord(caller) &&
|
|
159
|
+
typeof caller.principalId === "string" &&
|
|
160
|
+
caller.principalId.length > 0 &&
|
|
161
|
+
typeof caller.clientId === "string" &&
|
|
162
|
+
caller.clientId.length > 0 &&
|
|
163
|
+
(caller.grantId === undefined || typeof caller.grantId === "string"), "invalid_transfer_context", "Transfers require the verified current caller.");
|
|
164
|
+
requireCondition(scope.context.agentId === this.store.binding.agentId &&
|
|
165
|
+
typeof scope.context.pwd === "string", "invalid_transfer_context", "Transfers require the actual Agent and working directory.");
|
|
166
|
+
const runId = scope.runId ?? scope.context.runId;
|
|
167
|
+
text(runId, 128);
|
|
168
|
+
const fixed = fixedCaller(caller), owner = this.#owner(fixed), run = this.store.getRun(runId);
|
|
169
|
+
requireCondition(run.bootId === this.store.bootId &&
|
|
170
|
+
run.callerKey === owner.callerKey &&
|
|
171
|
+
run.endedAt === null &&
|
|
172
|
+
!run.stop, "invalid_transfer_context", "The verified invocation must belong to a live run on this Agent boot.");
|
|
173
|
+
requireCondition(path.isAbsolute(scope.context.pwd), "invalid_transfer_context", "The transfer working directory must be the trusted absolute invocation directory.");
|
|
174
|
+
return { caller: fixed, owner, runId, pwd: scope.context.pwd };
|
|
175
|
+
}
|
|
176
|
+
#target(scope, row) {
|
|
177
|
+
const target = row.metadata.target;
|
|
178
|
+
if (target.path)
|
|
179
|
+
authorizeCall(() => scope.authorize({
|
|
180
|
+
type: "path",
|
|
181
|
+
value: target.path,
|
|
182
|
+
access: row.direction === "upload" ? "write" : "read",
|
|
183
|
+
}));
|
|
184
|
+
if (target.resourceUri)
|
|
185
|
+
authorizeCall(() => scope.authorize({
|
|
186
|
+
type: "resource",
|
|
187
|
+
value: target.resourceUri,
|
|
188
|
+
access: "read",
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
#snapshot(row) {
|
|
192
|
+
const target = row.metadata.target;
|
|
193
|
+
const live = this.#entries.get(row.transferId);
|
|
194
|
+
const file = row.metadata.file ?? (live?.fileCommitted ? live.file : undefined);
|
|
195
|
+
return data({
|
|
196
|
+
transferId: row.transferId,
|
|
197
|
+
direction: row.direction,
|
|
198
|
+
status: row.status,
|
|
199
|
+
runId: row.originRunId,
|
|
200
|
+
contextId: row.metadata.origin?.contextId ?? null,
|
|
201
|
+
projectId: row.metadata.origin?.projectId ?? null,
|
|
202
|
+
...(row.direction === "upload" && target.path
|
|
203
|
+
? { path: target.path }
|
|
204
|
+
: {}),
|
|
205
|
+
...(row.direction === "download" && target.resourceUri
|
|
206
|
+
? {
|
|
207
|
+
resource: {
|
|
208
|
+
uri: target.resourceUri,
|
|
209
|
+
name: target.name,
|
|
210
|
+
mimeType: target.mimeType,
|
|
211
|
+
size: target.size,
|
|
212
|
+
},
|
|
213
|
+
}
|
|
214
|
+
: {}),
|
|
215
|
+
maxBytes: row.metadata.maxBytes ?? null,
|
|
216
|
+
progress: {
|
|
217
|
+
bytesTransferred: row.bytesTransferred,
|
|
218
|
+
totalBytes: row.direction === "download"
|
|
219
|
+
? (target.size ?? null)
|
|
220
|
+
: (target.expectedSize ?? row.metadata.file?.size ?? null),
|
|
221
|
+
},
|
|
222
|
+
createdAt: iso(row.createdAt),
|
|
223
|
+
expiresAt: iso(row.claimDeadlineAt),
|
|
224
|
+
startedAt: iso(row.metadata.startedAt),
|
|
225
|
+
deadlineAt: iso(row.transferDeadlineAt),
|
|
226
|
+
finishedAt: iso(row.endedAt),
|
|
227
|
+
...(file ? { file: { ...file } } : {}),
|
|
228
|
+
error: row.metadata.error ??
|
|
229
|
+
(live?.fault
|
|
230
|
+
? safeError(undefined, "transfer_persistence_failed")
|
|
231
|
+
: (live?.failure ??
|
|
232
|
+
(row.status === "interrupted"
|
|
233
|
+
? {
|
|
234
|
+
code: "transfer_interrupted",
|
|
235
|
+
message: "The previous Agent boot ended; no live stream controller was restored.",
|
|
236
|
+
}
|
|
237
|
+
: null))),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
#changed(entry) {
|
|
241
|
+
this.emit("change", entry.record.transferId);
|
|
242
|
+
}
|
|
243
|
+
#refresh(entry) {
|
|
244
|
+
return (entry.record = this.store.getTransfer(entry.record.transferId, entry.authority.owner));
|
|
245
|
+
}
|
|
246
|
+
#fault(entry, cause) {
|
|
247
|
+
entry.fault ??= cause;
|
|
248
|
+
this.emit("fault", {
|
|
249
|
+
transferId: entry.record.transferId,
|
|
250
|
+
error: safeError(cause, "transfer_persistence_failed"),
|
|
251
|
+
});
|
|
252
|
+
this.#changed(entry);
|
|
253
|
+
}
|
|
254
|
+
#ioScope(entry, current, authorize, signal) {
|
|
255
|
+
return {
|
|
256
|
+
pwd: entry.authority.pwd,
|
|
257
|
+
signal,
|
|
258
|
+
assertCurrent: current,
|
|
259
|
+
authorize: (target) => authorizeCall(() => authorize({
|
|
260
|
+
type: target.uri ? "resource" : "path",
|
|
261
|
+
value: target.uri ?? target.path,
|
|
262
|
+
access: target.access,
|
|
263
|
+
})),
|
|
264
|
+
onProgress: (bytes) => {
|
|
265
|
+
const row = this.#refresh(entry);
|
|
266
|
+
entry.record = this.store.progressTransfer(row.transferId, entry.authority.owner, { revision: row.revision, bytesTransferred: bytes }, this.#now());
|
|
267
|
+
entry.ref.report({
|
|
268
|
+
state: entry.record.status,
|
|
269
|
+
bytesTransferred: bytes,
|
|
270
|
+
});
|
|
271
|
+
this.#changed(entry);
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
#artifactScope(entry, current, authorize, signal) {
|
|
276
|
+
return {
|
|
277
|
+
pwd: entry.authority.pwd,
|
|
278
|
+
ownerKey: entry.authority.owner.callerKey,
|
|
279
|
+
runId: entry.authority.runId,
|
|
280
|
+
signal,
|
|
281
|
+
assertCurrent: current,
|
|
282
|
+
authorize: (target) => {
|
|
283
|
+
if (target.path)
|
|
284
|
+
authorizeCall(() => authorize({ type: "path", value: target.path, access: "read" }));
|
|
285
|
+
if (target.uri)
|
|
286
|
+
authorizeCall(() => authorize({ type: "resource", value: target.uri, access: "read" }));
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
#timer(callback, at, replace) {
|
|
291
|
+
const timer = setTimeout(() => {
|
|
292
|
+
// A native timer can wake slightly early. Wait only the remaining
|
|
293
|
+
// duration and keep the owner's clearTimeout handle current.
|
|
294
|
+
if (this.#now() < at) {
|
|
295
|
+
replace(this.#timer(callback, at, replace));
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
callback();
|
|
299
|
+
}, Math.max(1, at - this.#now()));
|
|
300
|
+
timer.unref();
|
|
301
|
+
return timer;
|
|
302
|
+
}
|
|
303
|
+
#release(reservation) {
|
|
304
|
+
if (reservation.released)
|
|
305
|
+
return;
|
|
306
|
+
reservation.released = true;
|
|
307
|
+
clearTimeout(reservation.timer);
|
|
308
|
+
reservation.permit.release();
|
|
309
|
+
if (reservation.entry.reservation === reservation)
|
|
310
|
+
reservation.entry.reservation = undefined;
|
|
311
|
+
}
|
|
312
|
+
#requestStop(entry, reason) {
|
|
313
|
+
if (terminal.has(entry.record.status))
|
|
314
|
+
return false;
|
|
315
|
+
if (entry.stop) {
|
|
316
|
+
// The first stop remains authoritative; an explicit control/cleanup call
|
|
317
|
+
// can retry only its still-unconfirmed settlement.
|
|
318
|
+
void this.#settle(entry).catch((cause) => this.#fault(entry, cause));
|
|
319
|
+
return entry.stop.kind === reason.kind;
|
|
320
|
+
}
|
|
321
|
+
let accepted = false;
|
|
322
|
+
try {
|
|
323
|
+
const row = this.#refresh(entry);
|
|
324
|
+
const requested = this.store.requestTransferCancel(row.transferId, entry.authority.owner, { revision: row.revision, reason }, this.#now());
|
|
325
|
+
entry.record = requested.transfer;
|
|
326
|
+
if (!requested.accepted)
|
|
327
|
+
return false;
|
|
328
|
+
accepted = true;
|
|
329
|
+
entry.stop = entry.record.metadata.stop ?? reason;
|
|
330
|
+
}
|
|
331
|
+
catch (cause) {
|
|
332
|
+
this.#fault(entry, cause);
|
|
333
|
+
entry.stop = reason;
|
|
334
|
+
}
|
|
335
|
+
entry.stopped.abort(new AgentError(entry.stop.code, "The independent transfer is stopping."));
|
|
336
|
+
clearTimeout(entry.claimTimer);
|
|
337
|
+
clearTimeout(entry.activeTimer);
|
|
338
|
+
if (entry.reservation && !entry.reservation.consumed)
|
|
339
|
+
this.#release(entry.reservation);
|
|
340
|
+
this.offers.forget(entry.record.transferId, reason.kind === "expired" ? "expired" : "unavailable");
|
|
341
|
+
this.#changed(entry);
|
|
342
|
+
void this.#settle(entry).catch((cause) => this.#fault(entry, cause));
|
|
343
|
+
return accepted;
|
|
344
|
+
}
|
|
345
|
+
async #settle(entry) {
|
|
346
|
+
if (entry.settling)
|
|
347
|
+
return entry.settling;
|
|
348
|
+
const settle = async () => {
|
|
349
|
+
// Cancellation can arrive while a channel is still being prepared. Wait
|
|
350
|
+
// until its real binding is known before revoking, never abandon it late.
|
|
351
|
+
await entry.preparing.catch(() => { });
|
|
352
|
+
const closing = entry.channel && !entry.channelClosed
|
|
353
|
+
? Promise.resolve().then(() => this.channels.revoke(entry.channel, entry.stop ?? { kind: "failure", code: "transfer_completed" }))
|
|
354
|
+
: Promise.resolve();
|
|
355
|
+
const outcomes = await Promise.allSettled([
|
|
356
|
+
closing,
|
|
357
|
+
entry.active ?? Promise.resolve(),
|
|
358
|
+
]);
|
|
359
|
+
entry.channelClosed = outcomes[0].status === "fulfilled";
|
|
360
|
+
if (outcomes[1].status === "rejected")
|
|
361
|
+
entry.ioCleanupConfirmed = false;
|
|
362
|
+
const failedClosure = outcomes.find((item) => item.status === "rejected");
|
|
363
|
+
if (failedClosure?.status === "rejected")
|
|
364
|
+
entry.failure ??= safeError(failedClosure.reason, "transfer_cleanup_unconfirmed");
|
|
365
|
+
if (!entry.ioCleanupConfirmed || !entry.channelClosed) {
|
|
366
|
+
// A lost revoke observation is retryable control uncertainty, not proof
|
|
367
|
+
// that local I/O failed or that the SQLite authority failed.
|
|
368
|
+
this.emit("fault", {
|
|
369
|
+
transferId: entry.record.transferId,
|
|
370
|
+
error: safeError(undefined, "transfer_cleanup_unconfirmed"),
|
|
371
|
+
});
|
|
372
|
+
this.#changed(entry);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
entry.closure.resolve();
|
|
376
|
+
await entry.closure.promise; // Manager's already-registered close observer runs first.
|
|
377
|
+
requireCondition(this.store.getResource(entry.ref.id).closedAt !== null, "transfer_cleanup_unconfirmed", "The resource authority did not confirm physical closure.");
|
|
378
|
+
if (entry.reservation)
|
|
379
|
+
this.#release(entry.reservation);
|
|
380
|
+
if (entry.fault)
|
|
381
|
+
throw new AgentError("transfer_persistence_failed", "The original transfer persistence failure remains unresolved.", { transferId: entry.record.transferId });
|
|
382
|
+
const row = this.#refresh(entry);
|
|
383
|
+
const status = entry.stop?.kind === "cancel"
|
|
384
|
+
? "cancelled"
|
|
385
|
+
: entry.stop?.kind === "expired"
|
|
386
|
+
? "expired"
|
|
387
|
+
: entry.stop || entry.failure
|
|
388
|
+
? "failed"
|
|
389
|
+
: "succeeded";
|
|
390
|
+
entry.record = this.store.finishTransfer(row.transferId, entry.authority.owner, {
|
|
391
|
+
revision: row.revision,
|
|
392
|
+
status,
|
|
393
|
+
cleanupConfirmed: true,
|
|
394
|
+
...(entry.fileCommitted
|
|
395
|
+
? { fileCommitted: true, file: entry.file }
|
|
396
|
+
: {}),
|
|
397
|
+
...(entry.failure
|
|
398
|
+
? { error: entry.failure }
|
|
399
|
+
: entry.stop
|
|
400
|
+
? {
|
|
401
|
+
error: {
|
|
402
|
+
code: entry.stop.code,
|
|
403
|
+
message: "The independent transfer stopped before successful completion.",
|
|
404
|
+
},
|
|
405
|
+
}
|
|
406
|
+
: {}),
|
|
407
|
+
}, this.#now());
|
|
408
|
+
if (entry.record.endedAt === null)
|
|
409
|
+
throw new AgentError("transfer_cleanup_unconfirmed", "The resource authority did not confirm physical closure.");
|
|
410
|
+
clearTimeout(entry.claimTimer);
|
|
411
|
+
clearTimeout(entry.activeTimer);
|
|
412
|
+
this.offers.forget(row.transferId, "terminal");
|
|
413
|
+
this.#entries.delete(row.transferId);
|
|
414
|
+
this.#changed(entry);
|
|
415
|
+
};
|
|
416
|
+
const attempt = settle();
|
|
417
|
+
entry.settling = attempt;
|
|
418
|
+
try {
|
|
419
|
+
await attempt;
|
|
420
|
+
}
|
|
421
|
+
finally {
|
|
422
|
+
if (entry.settling === attempt)
|
|
423
|
+
entry.settling = undefined;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
async #prepare(entry, input, scope) {
|
|
427
|
+
const check = () => {
|
|
428
|
+
this.#current(scope, entry.record.direction === "upload" ? "createUpload" : "createDownload", "new");
|
|
429
|
+
entry.ref.signal.throwIfAborted();
|
|
430
|
+
entry.stopped.signal.throwIfAborted();
|
|
431
|
+
};
|
|
432
|
+
const signal = AbortSignal.any([
|
|
433
|
+
scope.signal,
|
|
434
|
+
entry.ref.signal,
|
|
435
|
+
entry.stopped.signal,
|
|
436
|
+
]);
|
|
437
|
+
const authorization = (target) => authorizeCall(() => scope.authorize(target));
|
|
438
|
+
let target;
|
|
439
|
+
if (entry.record.direction === "upload") {
|
|
440
|
+
entry.prepared = await prepareUpload(input, this.#ioScope(entry, check, authorization, signal), { maxBytes: this.#maxBytes });
|
|
441
|
+
target = {
|
|
442
|
+
path: entry.prepared.path,
|
|
443
|
+
mimeType: entry.prepared.mimeType,
|
|
444
|
+
...(entry.prepared.expectedSize === undefined
|
|
445
|
+
? {}
|
|
446
|
+
: { expectedSize: entry.prepared.expectedSize }),
|
|
447
|
+
...(entry.prepared.expectedSha256 === undefined
|
|
448
|
+
? {}
|
|
449
|
+
: { expectedSha256: entry.prepared.expectedSha256 }),
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
const artifactScope = this.#artifactScope(entry, check, authorization, signal);
|
|
454
|
+
if (input.path) {
|
|
455
|
+
const permit = this.streams.tryAcquire();
|
|
456
|
+
requireCondition(permit, "transfer_busy", "All four actual file streams are occupied; no work was queued.");
|
|
457
|
+
try {
|
|
458
|
+
entry.artifact = await this.artifacts.register({
|
|
459
|
+
path: input.path,
|
|
460
|
+
...(input.name ? { name: input.name } : {}),
|
|
461
|
+
...(input.mimeType ? { mimeType: input.mimeType } : {}),
|
|
462
|
+
}, artifactScope, undefined, { maxBytes: this.#maxBytes });
|
|
463
|
+
}
|
|
464
|
+
finally {
|
|
465
|
+
permit.release();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
else
|
|
469
|
+
entry.artifact = await this.artifacts.metadata(input.uri, artifactScope);
|
|
470
|
+
requireCondition(entry.artifact.size <= this.#maxBytes, "resource_exhausted", "The fixed artifact exceeds the accepted transfer budget.");
|
|
471
|
+
if (input.mimeType)
|
|
472
|
+
requireCondition(mime(input.mimeType) === entry.artifact.mimeType, "invalid_arguments", "A download hint cannot replace the registered resource MIME type.");
|
|
473
|
+
target = {
|
|
474
|
+
resourceUri: entry.artifact.uri,
|
|
475
|
+
name: input.name ?? entry.artifact.name,
|
|
476
|
+
mimeType: entry.artifact.mimeType,
|
|
477
|
+
size: entry.artifact.size,
|
|
478
|
+
sha256: entry.artifact.sha256,
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
check();
|
|
482
|
+
const claimDeadlineAt = Math.min(this.#now() + this.#claimMs, entry.artifact ? Date.parse(entry.artifact.expiresAt) : Infinity);
|
|
483
|
+
requireCondition(claimDeadlineAt > this.#now(), "resource_expired", "The fixed artifact expired before channel preparation.");
|
|
484
|
+
const channel = Object.freeze({
|
|
485
|
+
binding: Object.freeze({
|
|
486
|
+
...this.store.binding,
|
|
487
|
+
bootId: this.store.bootId,
|
|
488
|
+
}),
|
|
489
|
+
transferId: entry.record.transferId,
|
|
490
|
+
resourceId: entry.ref.id,
|
|
491
|
+
caller: entry.authority.caller,
|
|
492
|
+
direction: entry.record.direction,
|
|
493
|
+
claimDeadlineAt,
|
|
494
|
+
maxBytes: this.#maxBytes,
|
|
495
|
+
target: Object.freeze(target),
|
|
496
|
+
});
|
|
497
|
+
// Set before awaiting: even a prepare rejection can have created a real
|
|
498
|
+
// remote channel whose cleanup must be attempted and confirmed.
|
|
499
|
+
entry.channel = channel;
|
|
500
|
+
entry.request = await this.channels.prepare(channel, signal);
|
|
501
|
+
check();
|
|
502
|
+
requireCondition(entry.request.method ===
|
|
503
|
+
(entry.record.direction === "upload" ? "PUT" : "GET") &&
|
|
504
|
+
Date.parse(entry.request.expiresAt) === claimDeadlineAt, "invalid_transfer_channel", "The actual channel must use the fixed direction and claim deadline.");
|
|
505
|
+
this.resources.commitHandoff(entry.ref, (checked) => {
|
|
506
|
+
check();
|
|
507
|
+
const published = this.store.publishTransferPending(entry.record.transferId, entry.authority.owner, {
|
|
508
|
+
revision: entry.record.revision,
|
|
509
|
+
resourceRevision: checked.revision,
|
|
510
|
+
claimDeadlineAt,
|
|
511
|
+
metadata: { target },
|
|
512
|
+
}, this.#now());
|
|
513
|
+
entry.record = published.transfer;
|
|
514
|
+
entry.published = true;
|
|
515
|
+
return published.resource;
|
|
516
|
+
});
|
|
517
|
+
entry.claimTimer = this.#timer(() => this.#requestStop(entry, { kind: "expired", code: "transfer_expired" }), claimDeadlineAt, (timer) => {
|
|
518
|
+
entry.claimTimer = timer;
|
|
519
|
+
});
|
|
520
|
+
this.#changed(entry);
|
|
521
|
+
}
|
|
522
|
+
async #create(scope, authority, direction, raw) {
|
|
523
|
+
const access = direction === "upload" ? "createUpload" : "createDownload";
|
|
524
|
+
this.#current(scope, access, "new");
|
|
525
|
+
requireCondition(authority.caller.grantId && authority.caller.grantId.length > 0, "transfer_grant_required", "Creating a transfer channel requires the verified Cloud Grant.");
|
|
526
|
+
const input = data(raw);
|
|
527
|
+
keys(input, direction === "upload"
|
|
528
|
+
? ["path", "expectedSize", "expectedSha256", "mimeType"]
|
|
529
|
+
: ["path", "uri", "name", "mimeType"]);
|
|
530
|
+
if (direction === "upload" || input.path !== undefined)
|
|
531
|
+
text(input.path);
|
|
532
|
+
if (direction === "download") {
|
|
533
|
+
requireCondition((input.path === undefined) !== (input.uri === undefined), "invalid_arguments", "A download uses exactly one path or registered resource URI.");
|
|
534
|
+
if (input.uri !== undefined)
|
|
535
|
+
text(input.uri);
|
|
536
|
+
if (input.name !== undefined) {
|
|
537
|
+
text(input.name, 512);
|
|
538
|
+
requireCondition(path.basename(input.name) === input.name &&
|
|
539
|
+
!input.name.includes("\\") &&
|
|
540
|
+
![".", ".."].includes(input.name), "invalid_arguments", "A download name must be a single file name.");
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (input.mimeType !== undefined)
|
|
544
|
+
input.mimeType = mime(input.mimeType);
|
|
545
|
+
if (input.expectedSize !== undefined)
|
|
546
|
+
requireCondition(typeof input.expectedSize === "number" &&
|
|
547
|
+
Number.isSafeInteger(input.expectedSize) &&
|
|
548
|
+
input.expectedSize >= 0 &&
|
|
549
|
+
input.expectedSize <= this.#maxBytes, "resource_exhausted", "The declared upload size exceeds the accepted Agent budget.");
|
|
550
|
+
if (input.expectedSha256 !== undefined)
|
|
551
|
+
requireCondition(typeof input.expectedSha256 === "string" &&
|
|
552
|
+
/^[0-9a-f]{64}$/.test(input.expectedSha256), "invalid_arguments", "An expected SHA-256 must be lowercase hexadecimal.");
|
|
553
|
+
const closure = Promise.withResolvers(), stopped = new AbortController();
|
|
554
|
+
let entry;
|
|
555
|
+
const value = {
|
|
556
|
+
closed: closure.promise,
|
|
557
|
+
dispose: async () => {
|
|
558
|
+
stopped.abort(new AgentError("transfer_cancelled", "The owning resource requested cancellation."));
|
|
559
|
+
if (entry) {
|
|
560
|
+
this.#requestStop(entry, {
|
|
561
|
+
kind: "cancel",
|
|
562
|
+
code: "transfer_cancelled",
|
|
563
|
+
});
|
|
564
|
+
await this.#settle(entry);
|
|
565
|
+
requireCondition(entry.ioCleanupConfirmed && entry.channelClosed, "transfer_cleanup_unconfirmed", "Transfer cleanup is still unconfirmed.");
|
|
566
|
+
}
|
|
567
|
+
else
|
|
568
|
+
closure.resolve();
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
const service = this.#instance.bind({
|
|
572
|
+
runId: authority.runId,
|
|
573
|
+
signal: scope.signal,
|
|
574
|
+
assertActive: () => this.#current(scope, access, "new"),
|
|
575
|
+
authorize: () => this.#current(scope, access, "new"),
|
|
576
|
+
});
|
|
577
|
+
const ref = await service.register({ kind: "transfer", value });
|
|
578
|
+
try {
|
|
579
|
+
const record = this.store.createTransfer(authority.owner, {
|
|
580
|
+
resourceId: ref.id,
|
|
581
|
+
runId: authority.runId,
|
|
582
|
+
direction,
|
|
583
|
+
maxBytes: this.#maxBytes,
|
|
584
|
+
metadata: { target: {} },
|
|
585
|
+
}, this.#now());
|
|
586
|
+
entry = {
|
|
587
|
+
authority,
|
|
588
|
+
ref,
|
|
589
|
+
stopped,
|
|
590
|
+
closure,
|
|
591
|
+
record,
|
|
592
|
+
preparing: Promise.resolve(),
|
|
593
|
+
published: false,
|
|
594
|
+
fileCommitted: false,
|
|
595
|
+
ioCleanupConfirmed: true,
|
|
596
|
+
channelClosed: false,
|
|
597
|
+
};
|
|
598
|
+
this.#entries.set(record.transferId, entry);
|
|
599
|
+
ref.signal.addEventListener("abort", () => {
|
|
600
|
+
if (!entry.settling && !terminal.has(entry.record.status))
|
|
601
|
+
this.#requestStop(entry, {
|
|
602
|
+
kind: "cancel",
|
|
603
|
+
code: "transfer_cancelled",
|
|
604
|
+
});
|
|
605
|
+
}, { once: true });
|
|
606
|
+
entry.preparing = this.#prepare(entry, input, scope);
|
|
607
|
+
await entry.preparing;
|
|
608
|
+
}
|
|
609
|
+
catch (cause) {
|
|
610
|
+
if (entry && !entry.published) {
|
|
611
|
+
entry.failure ??= safeError(cause);
|
|
612
|
+
this.#requestStop(entry, {
|
|
613
|
+
kind: "failure",
|
|
614
|
+
code: String(entry.failure.code),
|
|
615
|
+
});
|
|
616
|
+
await this.#settle(entry).catch((error) => this.#fault(entry, error));
|
|
617
|
+
}
|
|
618
|
+
else if (!entry)
|
|
619
|
+
closure.resolve();
|
|
620
|
+
throw cause;
|
|
621
|
+
}
|
|
622
|
+
// Handoff is committed. A later delivery failure cannot roll back the
|
|
623
|
+
// independent resource, revoke a valid channel, or replay file preparation.
|
|
624
|
+
const deliveryScope = {
|
|
625
|
+
ownerKey: authority.owner.callerKey,
|
|
626
|
+
grantId: authority.caller.grantId,
|
|
627
|
+
signal: scope.signal,
|
|
628
|
+
assertCurrent: () => this.#current(scope, access, "new"),
|
|
629
|
+
authorizeTarget: scope.authorize.bind(scope),
|
|
630
|
+
};
|
|
631
|
+
try {
|
|
632
|
+
return this.offers.issue(this.#snapshot(entry.record), entry.request, deliveryScope);
|
|
633
|
+
}
|
|
634
|
+
catch (cause) {
|
|
635
|
+
throw new AgentError("transfer_delivery_failed", "The independently managed channel exists, but its short-lived Offer could not be delivered. Query or cancel the retained identity.", { transferId: entry.record.transferId, status: entry.record.status }, { cause });
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
bind(scope) {
|
|
639
|
+
const authority = this.#authority(scope);
|
|
640
|
+
const read = (id, access) => {
|
|
641
|
+
this.#current(scope, access, id);
|
|
642
|
+
const row = this.store.getTransfer(id, authority.owner);
|
|
643
|
+
this.#target(scope, row);
|
|
644
|
+
return row;
|
|
645
|
+
};
|
|
646
|
+
return Object.freeze({
|
|
647
|
+
createUpload: async (input) => (await this.#create(scope, authority, "upload", input)),
|
|
648
|
+
createDownload: async (input) => (await this.#create(scope, authority, "download", input)),
|
|
649
|
+
get: async (id, options = {}) => {
|
|
650
|
+
keys(options, ["waitMs"]);
|
|
651
|
+
const wait = options.waitMs ?? 0;
|
|
652
|
+
requireCondition(Number.isSafeInteger(wait) && wait >= 0 && wait <= 30000, "invalid_arguments", "Transfer observation is bounded to thirty seconds.");
|
|
653
|
+
let row = read(id, "get");
|
|
654
|
+
if (wait && !terminal.has(row.status)) {
|
|
655
|
+
await new Promise((resolve, reject) => {
|
|
656
|
+
const finish = (cause) => {
|
|
657
|
+
clearTimeout(timer);
|
|
658
|
+
this.off("change", changed);
|
|
659
|
+
scope.signal.removeEventListener("abort", aborted);
|
|
660
|
+
cause ? reject(cause) : resolve();
|
|
661
|
+
};
|
|
662
|
+
const changed = (value) => {
|
|
663
|
+
if (value === id)
|
|
664
|
+
finish();
|
|
665
|
+
};
|
|
666
|
+
const aborted = () => finish(scope.signal.reason);
|
|
667
|
+
const timer = setTimeout(() => finish(), wait);
|
|
668
|
+
this.on("change", changed);
|
|
669
|
+
scope.signal.addEventListener("abort", aborted, { once: true });
|
|
670
|
+
if (scope.signal.aborted)
|
|
671
|
+
aborted();
|
|
672
|
+
});
|
|
673
|
+
row = read(id, "get");
|
|
674
|
+
}
|
|
675
|
+
return this.#snapshot(row);
|
|
676
|
+
},
|
|
677
|
+
list: async (raw = {}) => {
|
|
678
|
+
this.#current(scope, "list", "new");
|
|
679
|
+
const query = data(raw);
|
|
680
|
+
keys(query, ["direction", "status", "runId", "limit", "cursor"]);
|
|
681
|
+
requireCondition(query.direction === undefined ||
|
|
682
|
+
query.direction === "upload" ||
|
|
683
|
+
query.direction === "download", "invalid_arguments", "Transfer direction is upload or download.");
|
|
684
|
+
requireCondition(query.status === undefined ||
|
|
685
|
+
(typeof query.status === "string" && statuses.has(query.status)), "invalid_arguments", "The transfer status filter is invalid.");
|
|
686
|
+
if (query.runId !== undefined)
|
|
687
|
+
text(query.runId, 128);
|
|
688
|
+
if (query.cursor !== undefined)
|
|
689
|
+
text(query.cursor, 4096);
|
|
690
|
+
const limit = query.limit ?? 20;
|
|
691
|
+
requireCondition(typeof limit === "number" &&
|
|
692
|
+
Number.isSafeInteger(limit) &&
|
|
693
|
+
limit > 0 &&
|
|
694
|
+
limit <= 100, "invalid_arguments", "Transfer page sizes are between one and one hundred.");
|
|
695
|
+
const filter = {
|
|
696
|
+
...(query.direction === undefined
|
|
697
|
+
? {}
|
|
698
|
+
: { direction: query.direction }),
|
|
699
|
+
...(query.status === undefined ? {} : { status: query.status }),
|
|
700
|
+
...(query.runId === undefined ? {} : { runId: query.runId }),
|
|
701
|
+
};
|
|
702
|
+
let cursor = query.cursor, scanned = 0, bytes = 0;
|
|
703
|
+
const transfers = [];
|
|
704
|
+
while (scanned < 1000) {
|
|
705
|
+
this.#current(scope, "list", "new");
|
|
706
|
+
const page = this.store.scanTransfers(authority.owner, filter, Math.min(100, 1000 - scanned), cursor);
|
|
707
|
+
for (let index = 0; index < page.items.length; index++) {
|
|
708
|
+
const item = page.items[index], previous = cursor;
|
|
709
|
+
cursor = item.cursor;
|
|
710
|
+
scanned++;
|
|
711
|
+
try {
|
|
712
|
+
read(item.record.transferId, "list");
|
|
713
|
+
}
|
|
714
|
+
catch (cause) {
|
|
715
|
+
if (cause instanceof AgentError && denials.has(cause.code))
|
|
716
|
+
continue;
|
|
717
|
+
throw cause;
|
|
718
|
+
}
|
|
719
|
+
const snapshot = this.#snapshot(item.record), size = Buffer.byteLength(canonicalJson(snapshot));
|
|
720
|
+
if (bytes + size > 60 * 1024)
|
|
721
|
+
return { transfers, nextCursor: previous ?? null };
|
|
722
|
+
bytes += size;
|
|
723
|
+
transfers.push(snapshot);
|
|
724
|
+
if (transfers.length === limit)
|
|
725
|
+
return {
|
|
726
|
+
transfers,
|
|
727
|
+
nextCursor: index < page.items.length - 1 || page.more ? cursor : null,
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
if (!page.more)
|
|
731
|
+
return { transfers, nextCursor: null };
|
|
732
|
+
}
|
|
733
|
+
return { transfers, nextCursor: cursor ?? null };
|
|
734
|
+
},
|
|
735
|
+
cancel: async (id) => {
|
|
736
|
+
const row = read(id, "cancel");
|
|
737
|
+
if (terminal.has(row.status))
|
|
738
|
+
return { accepted: false, transfer: this.#snapshot(row) };
|
|
739
|
+
const entry = this.#entries.get(id);
|
|
740
|
+
requireCondition(entry, "transfer_control_unavailable", "No live controller exists for this retained transfer; no task was reconstructed.");
|
|
741
|
+
const accepted = this.#requestStop(entry, {
|
|
742
|
+
kind: "cancel",
|
|
743
|
+
code: "transfer_cancelled",
|
|
744
|
+
});
|
|
745
|
+
if (entry.fault)
|
|
746
|
+
throw new AgentError("transfer_persistence_failed", "The cancellation could not be confirmed by the transfer authority.", { transferId: id });
|
|
747
|
+
return { accepted, transfer: this.#snapshot(this.#refresh(entry)) };
|
|
748
|
+
},
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
/** Used only by the Core delivery authority; a snapshot alone grants no access. */
|
|
752
|
+
authorizeDelivery(scope, snapshot) {
|
|
753
|
+
scope.signal?.throwIfAborted();
|
|
754
|
+
authorizeCall(() => scope.assertCurrent());
|
|
755
|
+
const entry = this.#entries.get(snapshot.transferId);
|
|
756
|
+
requireCondition(entry &&
|
|
757
|
+
entry.published &&
|
|
758
|
+
entry.authority.owner.callerKey === scope.ownerKey &&
|
|
759
|
+
entry.authority.caller.grantId === scope.grantId &&
|
|
760
|
+
entry.record.status === "pending" &&
|
|
761
|
+
!entry.stop &&
|
|
762
|
+
!entry.fault &&
|
|
763
|
+
entry.channel &&
|
|
764
|
+
entry.channel.claimDeadlineAt > this.#now(), "transfer_delivery_unavailable", "The current owner/Grant has no live unconsumed transfer channel.");
|
|
765
|
+
const row = this.#refresh(entry);
|
|
766
|
+
requireCondition(row.status === "pending" &&
|
|
767
|
+
row.claimDeadlineAt > this.#now() &&
|
|
768
|
+
this.store.getResource(row.resourceId).closedAt === null, "transfer_delivery_unavailable", "The transfer is no longer live and pending.");
|
|
769
|
+
requireCondition(scope.authorizeTarget, "transfer_delivery_authorization_unavailable", "Delivery requires the current transfer and target authority, not a retained creator closure.");
|
|
770
|
+
authorizeCall(() => scope.authorizeTarget({
|
|
771
|
+
type: "transfer",
|
|
772
|
+
value: row.transferId,
|
|
773
|
+
access: row.direction === "upload" ? "createUpload" : "createDownload",
|
|
774
|
+
}));
|
|
775
|
+
this.#target({ authorize: scope.authorizeTarget }, row);
|
|
776
|
+
}
|
|
777
|
+
#claimCurrent(entry, scope) {
|
|
778
|
+
scope.signal.throwIfAborted();
|
|
779
|
+
entry.stopped.signal.throwIfAborted();
|
|
780
|
+
entry.ref.signal.throwIfAborted();
|
|
781
|
+
requireCondition(scope.binding.agentId === this.store.binding.agentId &&
|
|
782
|
+
scope.binding.profile === this.store.binding.profile &&
|
|
783
|
+
scope.binding.cloudEnvironment ===
|
|
784
|
+
this.store.binding.cloudEnvironment &&
|
|
785
|
+
scope.binding.bootId === this.store.bootId &&
|
|
786
|
+
callerKey(scope.caller) === entry.authority.owner.callerKey &&
|
|
787
|
+
scope.caller.grantId === entry.authority.caller.grantId, "transfer_claim_forbidden", "The fresh claimant must match the actual Agent/profile/boot and original owner/Grant.");
|
|
788
|
+
this.#current(scope, entry.record.direction === "upload" ? "createUpload" : "createDownload", entry.record.transferId);
|
|
789
|
+
this.#target(scope, this.#refresh(entry));
|
|
790
|
+
requireCondition(!entry.fault, "transfer_persistence_failed", "The transfer authority has an unresolved persistence failure.");
|
|
791
|
+
}
|
|
792
|
+
reserveClaim(id, scope) {
|
|
793
|
+
const entry = this.#entries.get(id);
|
|
794
|
+
requireCondition(entry, "transfer_control_unavailable", "No live transfer controller exists on this Agent boot.");
|
|
795
|
+
this.#claimCurrent(entry, scope);
|
|
796
|
+
requireCondition(entry.record.status === "pending" &&
|
|
797
|
+
!entry.reservation &&
|
|
798
|
+
entry.record.claimDeadlineAt > this.#now(), "transfer_not_claimable", "The offer is expired, already reserved, or no longer pending.");
|
|
799
|
+
const permit = this.streams.tryAcquire();
|
|
800
|
+
requireCondition(permit, "transfer_busy", "All four actual streams are occupied; the channel must remain unconsumed.");
|
|
801
|
+
const identity = Object.freeze({ transferId: id });
|
|
802
|
+
const reservation = {
|
|
803
|
+
identity,
|
|
804
|
+
entry,
|
|
805
|
+
scope,
|
|
806
|
+
permit,
|
|
807
|
+
consumed: false,
|
|
808
|
+
released: false,
|
|
809
|
+
timer: undefined,
|
|
810
|
+
};
|
|
811
|
+
Object.assign(reservation, {
|
|
812
|
+
timer: this.#timer(() => {
|
|
813
|
+
if (!reservation.consumed)
|
|
814
|
+
this.#release(reservation);
|
|
815
|
+
}, Math.min(entry.record.claimDeadlineAt, this.#now() + this.#reservationMs), (timer) => {
|
|
816
|
+
reservation.timer = timer;
|
|
817
|
+
}),
|
|
818
|
+
});
|
|
819
|
+
this.#reservations.set(identity, reservation);
|
|
820
|
+
entry.reservation = reservation;
|
|
821
|
+
return identity;
|
|
822
|
+
}
|
|
823
|
+
releaseReservation(identity) {
|
|
824
|
+
const reservation = this.#reservations.get(identity);
|
|
825
|
+
requireCondition(reservation && !reservation.consumed, "invalid_transfer_reservation", "Only an actual unstarted Core reservation can be released.");
|
|
826
|
+
this.#release(reservation);
|
|
827
|
+
}
|
|
828
|
+
async commitClaim(identity, io) {
|
|
829
|
+
const reservation = this.#reservations.get(identity);
|
|
830
|
+
requireCondition(reservation && !reservation.released && !reservation.consumed, "invalid_transfer_reservation", "The actual unstarted Core reservation is required.");
|
|
831
|
+
const { entry, scope } = reservation;
|
|
832
|
+
try {
|
|
833
|
+
this.#claimCurrent(entry, scope);
|
|
834
|
+
requireCondition((entry.record.direction === "upload"
|
|
835
|
+
? "upload" in io
|
|
836
|
+
: "download" in io) && types.isPromise(io.closed), "invalid_transfer_channel", "The actual binary endpoint must match the channel direction.");
|
|
837
|
+
const row = this.#refresh(entry);
|
|
838
|
+
const claimedAt = this.#now();
|
|
839
|
+
entry.record = this.store.claimTransfer(row.transferId, entry.authority.owner, {
|
|
840
|
+
revision: row.revision,
|
|
841
|
+
transferDeadlineAt: claimedAt + this.#activeMs,
|
|
842
|
+
}, claimedAt);
|
|
843
|
+
}
|
|
844
|
+
catch (cause) {
|
|
845
|
+
this.#release(reservation);
|
|
846
|
+
throw cause;
|
|
847
|
+
}
|
|
848
|
+
reservation.consumed = true;
|
|
849
|
+
// The native transport can reject before file processing reaches its close
|
|
850
|
+
// await. Observe now without replacing or losing that later outcome.
|
|
851
|
+
void Promise.prototype.then.call(io.closed, undefined, () => { });
|
|
852
|
+
clearTimeout(reservation.timer);
|
|
853
|
+
clearTimeout(entry.claimTimer);
|
|
854
|
+
this.offers.forget(entry.record.transferId, "consumed");
|
|
855
|
+
entry.activeTimer = this.#timer(() => this.#requestStop(entry, { kind: "timeout", code: "transfer_timeout" }), entry.record.transferDeadlineAt, (timer) => {
|
|
856
|
+
entry.activeTimer = timer;
|
|
857
|
+
});
|
|
858
|
+
const signal = AbortSignal.any([
|
|
859
|
+
scope.signal,
|
|
860
|
+
entry.ref.signal,
|
|
861
|
+
entry.stopped.signal,
|
|
862
|
+
]);
|
|
863
|
+
const check = () => this.#claimCurrent(entry, scope);
|
|
864
|
+
entry.active = (async () => {
|
|
865
|
+
try {
|
|
866
|
+
const actual = this.#ioScope(entry, check, scope.authorize.bind(scope), signal);
|
|
867
|
+
if ("upload" in io) {
|
|
868
|
+
const file = await receiveUpload(io.upload, entry.prepared, actual, {
|
|
869
|
+
maxBytes: entry.record.metadata.maxBytes,
|
|
870
|
+
...(io.contentLength === undefined
|
|
871
|
+
? {}
|
|
872
|
+
: { contentLength: io.contentLength }),
|
|
873
|
+
});
|
|
874
|
+
entry.fileCommitted = true;
|
|
875
|
+
entry.file = file;
|
|
876
|
+
const row = this.#refresh(entry);
|
|
877
|
+
entry.record = this.store.progressTransfer(row.transferId, entry.authority.owner, {
|
|
878
|
+
revision: row.revision,
|
|
879
|
+
bytesTransferred: file.size,
|
|
880
|
+
fileCommitted: true,
|
|
881
|
+
file,
|
|
882
|
+
}, this.#now());
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
const source = await this.artifacts.open(entry.artifact.uri, this.#artifactScope(entry, check, scope.authorize.bind(scope), signal));
|
|
886
|
+
await sendDownload(source, io.download, actual, {
|
|
887
|
+
maxBytes: entry.record.metadata.maxBytes,
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
await io.closed;
|
|
891
|
+
check();
|
|
892
|
+
}
|
|
893
|
+
catch (cause) {
|
|
894
|
+
if (cause instanceof TransferIoError) {
|
|
895
|
+
entry.fileCommitted ||= cause.fileCommitted;
|
|
896
|
+
entry.file ??= cause.file;
|
|
897
|
+
entry.ioCleanupConfirmed &&= cause.cleanupConfirmed;
|
|
898
|
+
if (entry.fileCommitted) {
|
|
899
|
+
try {
|
|
900
|
+
const row = this.#refresh(entry);
|
|
901
|
+
entry.record = this.store.progressTransfer(row.transferId, entry.authority.owner, {
|
|
902
|
+
revision: row.revision,
|
|
903
|
+
bytesTransferred: entry.file?.size ?? row.bytesTransferred,
|
|
904
|
+
fileCommitted: true,
|
|
905
|
+
...(entry.file ? { file: entry.file } : {}),
|
|
906
|
+
}, this.#now());
|
|
907
|
+
}
|
|
908
|
+
catch (error) {
|
|
909
|
+
this.#fault(entry, error);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (!(cause instanceof TransferIoError) &&
|
|
914
|
+
cause instanceof AgentError &&
|
|
915
|
+
cause.code === "transfer_cleanup_unconfirmed")
|
|
916
|
+
entry.ioCleanupConfirmed = false;
|
|
917
|
+
entry.failure ??= safeError(cause);
|
|
918
|
+
this.#requestStop(entry, {
|
|
919
|
+
kind: "failure",
|
|
920
|
+
code: String(entry.failure.code),
|
|
921
|
+
});
|
|
922
|
+
// The port must close the transport on failure/cancellation. A rejected
|
|
923
|
+
// closure cannot be turned into a confirmed successful cleanup.
|
|
924
|
+
try {
|
|
925
|
+
await io.closed;
|
|
926
|
+
}
|
|
927
|
+
catch (cause) {
|
|
928
|
+
if (!(cause instanceof TransferIoError && cause.cleanupConfirmed === true))
|
|
929
|
+
entry.ioCleanupConfirmed = false;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
finally {
|
|
933
|
+
clearTimeout(entry.activeTimer);
|
|
934
|
+
this.#changed(entry);
|
|
935
|
+
}
|
|
936
|
+
})();
|
|
937
|
+
try {
|
|
938
|
+
await entry.active;
|
|
939
|
+
await this.#settle(entry);
|
|
940
|
+
}
|
|
941
|
+
catch (cause) {
|
|
942
|
+
this.#fault(entry, cause);
|
|
943
|
+
throw cause;
|
|
944
|
+
}
|
|
945
|
+
return this.#snapshot(this.#refresh(entry));
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
//# sourceMappingURL=transfer.js.map
|