paseo-agy-acp 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +296 -0
- package/LICENSE +201 -0
- package/README.md +571 -0
- package/README.zh-CN.md +540 -0
- package/assets/official-kernel-compat/rc01/paseo_model_compat.py +172 -0
- package/dist/ACP Connector/acp/session/paseo-context.d.ts +6 -0
- package/dist/ACP Connector/acp/session/paseo-context.js +83 -0
- package/dist/ACP Connector/acp/session/paseo-context.js.map +1 -0
- package/dist/ACP Connector/acp/session/turn-scheduler.d.ts +90 -0
- package/dist/ACP Connector/acp/session/turn-scheduler.js +247 -0
- package/dist/ACP Connector/acp/session/turn-scheduler.js.map +1 -0
- package/dist/ACP Connector/admission/dispatch-boundary.d.ts +19 -0
- package/dist/ACP Connector/admission/dispatch-boundary.js +16 -0
- package/dist/ACP Connector/admission/dispatch-boundary.js.map +1 -0
- package/dist/ACP Connector/admission/errors.d.ts +18 -0
- package/dist/ACP Connector/admission/errors.js +46 -0
- package/dist/ACP Connector/admission/errors.js.map +1 -0
- package/dist/ACP Connector/admission/owner-instance.d.ts +31 -0
- package/dist/ACP Connector/admission/owner-instance.js +105 -0
- package/dist/ACP Connector/admission/owner-instance.js.map +1 -0
- package/dist/ACP Connector/admission/runtime.d.ts +20 -0
- package/dist/ACP Connector/admission/runtime.js +157 -0
- package/dist/ACP Connector/admission/runtime.js.map +1 -0
- package/dist/ACP Connector/admission/startup-recovery.d.ts +22 -0
- package/dist/ACP Connector/admission/startup-recovery.js +129 -0
- package/dist/ACP Connector/admission/startup-recovery.js.map +1 -0
- package/dist/ACP Connector/admission/turn-coordinator.d.ts +57 -0
- package/dist/ACP Connector/admission/turn-coordinator.js +369 -0
- package/dist/ACP Connector/admission/turn-coordinator.js.map +1 -0
- package/dist/ACP Connector/agent.d.ts +4 -0
- package/dist/ACP Connector/agent.js +6 -0
- package/dist/ACP Connector/agent.js.map +1 -0
- package/dist/ACP Connector/main.d.ts +2 -0
- package/dist/ACP Connector/main.js +31 -0
- package/dist/ACP Connector/main.js.map +1 -0
- package/dist/ACP Connector/official-kernel/admission-fence.d.ts +10 -0
- package/dist/ACP Connector/official-kernel/admission-fence.js +52 -0
- package/dist/ACP Connector/official-kernel/admission-fence.js.map +1 -0
- package/dist/ACP Connector/official-kernel/context.d.ts +3 -0
- package/dist/ACP Connector/official-kernel/context.js +52 -0
- package/dist/ACP Connector/official-kernel/context.js.map +1 -0
- package/dist/ACP Connector/official-kernel/errors.d.ts +5 -0
- package/dist/ACP Connector/official-kernel/errors.js +39 -0
- package/dist/ACP Connector/official-kernel/errors.js.map +1 -0
- package/dist/ACP Connector/official-kernel/identity.d.ts +3 -0
- package/dist/ACP Connector/official-kernel/identity.js +17 -0
- package/dist/ACP Connector/official-kernel/identity.js.map +1 -0
- package/dist/ACP Connector/official-kernel/json-rpc.d.ts +34 -0
- package/dist/ACP Connector/official-kernel/json-rpc.js +26 -0
- package/dist/ACP Connector/official-kernel/json-rpc.js.map +1 -0
- package/dist/ACP Connector/official-kernel/kernel-compat-lifecycle.d.ts +115 -0
- package/dist/ACP Connector/official-kernel/kernel-compat-lifecycle.js +1904 -0
- package/dist/ACP Connector/official-kernel/kernel-compat-lifecycle.js.map +1 -0
- package/dist/ACP Connector/official-kernel/kernel-compat-pins.d.ts +14 -0
- package/dist/ACP Connector/official-kernel/kernel-compat-pins.js +29 -0
- package/dist/ACP Connector/official-kernel/kernel-compat-pins.js.map +1 -0
- package/dist/ACP Connector/official-kernel/kernel-compat-rc01-recipe.d.ts +2 -0
- package/dist/ACP Connector/official-kernel/kernel-compat-rc01-recipe.js +32 -0
- package/dist/ACP Connector/official-kernel/kernel-compat-rc01-recipe.js.map +1 -0
- package/dist/ACP Connector/official-kernel/kernel.d.ts +3 -0
- package/dist/ACP Connector/official-kernel/kernel.js +12 -0
- package/dist/ACP Connector/official-kernel/kernel.js.map +1 -0
- package/dist/ACP Connector/official-kernel/login.d.ts +1 -0
- package/dist/ACP Connector/official-kernel/login.js +73 -0
- package/dist/ACP Connector/official-kernel/login.js.map +1 -0
- package/dist/ACP Connector/official-kernel/mcp-rewrite.d.ts +1 -0
- package/dist/ACP Connector/official-kernel/mcp-rewrite.js +39 -0
- package/dist/ACP Connector/official-kernel/mcp-rewrite.js.map +1 -0
- package/dist/ACP Connector/official-kernel/mode-map.d.ts +5 -0
- package/dist/ACP Connector/official-kernel/mode-map.js +35 -0
- package/dist/ACP Connector/official-kernel/mode-map.js.map +1 -0
- package/dist/ACP Connector/official-kernel/ndjson.d.ts +3 -0
- package/dist/ACP Connector/official-kernel/ndjson.js +29 -0
- package/dist/ACP Connector/official-kernel/ndjson.js.map +1 -0
- package/dist/ACP Connector/official-kernel/proxy.d.ts +14 -0
- package/dist/ACP Connector/official-kernel/proxy.js +197 -0
- package/dist/ACP Connector/official-kernel/proxy.js.map +1 -0
- package/dist/ACP Connector/official-kernel/run.d.ts +8 -0
- package/dist/ACP Connector/official-kernel/run.js +22 -0
- package/dist/ACP Connector/official-kernel/run.js.map +1 -0
- package/dist/ACP Connector/official-kernel/spawn.d.ts +5 -0
- package/dist/ACP Connector/official-kernel/spawn.js +33 -0
- package/dist/ACP Connector/official-kernel/spawn.js.map +1 -0
- package/dist/Admission Controller/controller.d.ts +338 -0
- package/dist/Admission Controller/controller.js +2089 -0
- package/dist/Admission Controller/controller.js.map +1 -0
- package/dist/Admission Controller/key-derivation.d.ts +24 -0
- package/dist/Admission Controller/key-derivation.js +141 -0
- package/dist/Admission Controller/key-derivation.js.map +1 -0
- package/dist/Admission Controller/key-store.d.ts +8 -0
- package/dist/Admission Controller/key-store.js +280 -0
- package/dist/Admission Controller/key-store.js.map +1 -0
- package/dist/Admission Controller/policy-limits.d.ts +6 -0
- package/dist/Admission Controller/policy-limits.js +11 -0
- package/dist/Admission Controller/policy-limits.js.map +1 -0
- package/dist/Admission Controller/process-evidence.d.ts +111 -0
- package/dist/Admission Controller/process-evidence.js +549 -0
- package/dist/Admission Controller/process-evidence.js.map +1 -0
- package/dist/Admission Controller/runtime-config.d.ts +23 -0
- package/dist/Admission Controller/runtime-config.js +86 -0
- package/dist/Admission Controller/runtime-config.js.map +1 -0
- package/dist/Admission Controller/schema.d.ts +12 -0
- package/dist/Admission Controller/schema.js +422 -0
- package/dist/Admission Controller/schema.js.map +1 -0
- package/package.json +72 -0
- package/scripts/prepare-admission-state-dir.mjs +62 -0
- package/scripts/prepare-official-kernel-compat.mjs +387 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { TurnClaim } from "../acp/session/turn-scheduler.js";
|
|
2
|
+
import { createOfficialAdmission, issueAdmittedOfficialPromptWrite } from "./admission-fence.js";
|
|
3
|
+
import { extractPromptText, extractSessionId, injectPaseoContext } from "./context.js";
|
|
4
|
+
import { blankTurnError, sessionUpdateShowsVisibleOutput, shouldRejectBlankTurn } from "./errors.js";
|
|
5
|
+
import { overlayProductIdentity } from "./identity.js";
|
|
6
|
+
import { isJsonRpcFailure, isJsonRpcNotification, isJsonRpcRequest, isJsonRpcSuccess, jsonRpcError } from "./json-rpc.js";
|
|
7
|
+
import { rewriteMcpServers } from "./mcp-rewrite.js";
|
|
8
|
+
import { rewriteModeFields } from "./mode-map.js";
|
|
9
|
+
import { createNdjsonParser, encodeNdjson } from "./ndjson.js";
|
|
10
|
+
const INITIALIZE_METHOD = "initialize";
|
|
11
|
+
const SESSION_NEW_METHOD = "session/new";
|
|
12
|
+
const SESSION_PROMPT_METHOD = "session/prompt";
|
|
13
|
+
const SESSION_SET_MODE_METHOD = "session/set_mode";
|
|
14
|
+
const SESSION_SET_CONFIG_METHOD = "session/set_config_option";
|
|
15
|
+
const SESSION_CANCEL_METHOD = "session/cancel";
|
|
16
|
+
const SESSION_UPDATE_METHOD = "session/update";
|
|
17
|
+
export class OfficialKernelProxy {
|
|
18
|
+
#child;
|
|
19
|
+
#stdin;
|
|
20
|
+
#stdout;
|
|
21
|
+
#version;
|
|
22
|
+
#pending = new Map();
|
|
23
|
+
#claims = new Map();
|
|
24
|
+
#env;
|
|
25
|
+
#admission;
|
|
26
|
+
#closed = false;
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.#child = options.child;
|
|
29
|
+
this.#stdin = options.stdin;
|
|
30
|
+
this.#stdout = options.stdout;
|
|
31
|
+
this.#version = options.version;
|
|
32
|
+
this.#env = options.env ?? process.env;
|
|
33
|
+
this.#admission = createOfficialAdmission(this.#env);
|
|
34
|
+
}
|
|
35
|
+
start() {
|
|
36
|
+
const parseClient = createNdjsonParser((message) => {
|
|
37
|
+
void this.#onClientMessage(message);
|
|
38
|
+
});
|
|
39
|
+
const parseChild = createNdjsonParser((message) => {
|
|
40
|
+
this.#onChildMessage(message);
|
|
41
|
+
});
|
|
42
|
+
this.#stdin.on("data", parseClient);
|
|
43
|
+
this.#child.stdout.on("data", parseChild);
|
|
44
|
+
this.#stdin.on("end", () => this.#child.stdin.end());
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
const finish = () => {
|
|
47
|
+
if (this.#closed)
|
|
48
|
+
return;
|
|
49
|
+
this.#closed = true;
|
|
50
|
+
this.#admission?.coordinator.close();
|
|
51
|
+
this.#admission?.runtime.close();
|
|
52
|
+
resolve();
|
|
53
|
+
};
|
|
54
|
+
this.#child.once("error", reject);
|
|
55
|
+
this.#child.once("exit", finish);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
#writeClient(message) {
|
|
59
|
+
this.#stdout.write(encodeNdjson(message));
|
|
60
|
+
}
|
|
61
|
+
#writeChild(message) {
|
|
62
|
+
this.#child.stdin.write(encodeNdjson(message));
|
|
63
|
+
}
|
|
64
|
+
async #onClientMessage(message) {
|
|
65
|
+
try {
|
|
66
|
+
if (isJsonRpcNotification(message)) {
|
|
67
|
+
this.#onClientNotification(message);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!isJsonRpcRequest(message)) {
|
|
71
|
+
this.#writeChild(message);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await this.#onClientRequest(message);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (isJsonRpcRequest(message)) {
|
|
78
|
+
this.#writeClient(jsonRpcError(message.id, error instanceof Error ? error.message : "official kernel proxy failed"));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
#onClientNotification(message) {
|
|
83
|
+
if (message.method === SESSION_CANCEL_METHOD) {
|
|
84
|
+
const sessionId = extractSessionId("params" in message ? message.params : undefined);
|
|
85
|
+
if (sessionId)
|
|
86
|
+
this.#claims.get(sessionId)?.abort();
|
|
87
|
+
}
|
|
88
|
+
this.#writeChild(message);
|
|
89
|
+
}
|
|
90
|
+
async #onClientRequest(request) {
|
|
91
|
+
let params = request.params;
|
|
92
|
+
if (request.method === SESSION_NEW_METHOD) {
|
|
93
|
+
params = rewriteMcpServers(rewriteModeFields(params));
|
|
94
|
+
}
|
|
95
|
+
else if (request.method === SESSION_SET_MODE_METHOD || request.method === SESSION_SET_CONFIG_METHOD) {
|
|
96
|
+
params = rewriteModeFields(params);
|
|
97
|
+
}
|
|
98
|
+
else if (request.method === SESSION_PROMPT_METHOD) {
|
|
99
|
+
params = rewriteModeFields(await injectPaseoContext(params, this.#env));
|
|
100
|
+
await this.#handlePrompt(request, params);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.#track(request.id, request.method, params);
|
|
104
|
+
this.#writeChild({ ...request, jsonrpc: "2.0", params });
|
|
105
|
+
}
|
|
106
|
+
async #handlePrompt(request, params) {
|
|
107
|
+
const sessionId = extractSessionId(params);
|
|
108
|
+
const promptText = extractPromptText(params) || "prompt";
|
|
109
|
+
const rewritten = { ...request, jsonrpc: "2.0", params };
|
|
110
|
+
const coordinator = this.#admission?.coordinator;
|
|
111
|
+
const processId = this.#child.pid;
|
|
112
|
+
if (coordinator === undefined || processId === undefined) {
|
|
113
|
+
this.#track(rewritten.id, rewritten.method, params);
|
|
114
|
+
this.#writeChild(rewritten);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const claim = new TurnClaim("foreground");
|
|
118
|
+
if (sessionId)
|
|
119
|
+
this.#claims.set(sessionId, claim);
|
|
120
|
+
let wrote = false;
|
|
121
|
+
try {
|
|
122
|
+
const stopReason = await coordinator.admit({
|
|
123
|
+
sessionId: sessionId ?? "session",
|
|
124
|
+
model: "official",
|
|
125
|
+
promptText,
|
|
126
|
+
claim,
|
|
127
|
+
execute: async (boundary) => {
|
|
128
|
+
const response = this.#track(rewritten.id, rewritten.method, params);
|
|
129
|
+
issueAdmittedOfficialPromptWrite(boundary, processId, () => {
|
|
130
|
+
wrote = true;
|
|
131
|
+
this.#writeChild(rewritten);
|
|
132
|
+
});
|
|
133
|
+
await response;
|
|
134
|
+
return { stopReason: claim.aborted ? "cancelled" : "end_turn" };
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
if (!wrote) {
|
|
138
|
+
this.#writeClient({
|
|
139
|
+
jsonrpc: "2.0",
|
|
140
|
+
id: request.id,
|
|
141
|
+
result: { stopReason: stopReason === "cancelled" ? "cancelled" : "end_turn" }
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
if (sessionId)
|
|
147
|
+
this.#claims.delete(sessionId);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
#track(id, method, params) {
|
|
151
|
+
return new Promise((resolve) => {
|
|
152
|
+
this.#pending.set(id, {
|
|
153
|
+
method,
|
|
154
|
+
sessionId: extractSessionId(params),
|
|
155
|
+
sawVisibleOutput: false,
|
|
156
|
+
resolve
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
#onChildMessage(message) {
|
|
161
|
+
if (isJsonRpcNotification(message) && message.method === SESSION_UPDATE_METHOD) {
|
|
162
|
+
const sessionId = extractSessionId(message.params);
|
|
163
|
+
if (sessionUpdateShowsVisibleOutput(message.params)) {
|
|
164
|
+
for (const pending of this.#pending.values()) {
|
|
165
|
+
if (pending.method === SESSION_PROMPT_METHOD &&
|
|
166
|
+
(pending.sessionId === undefined || pending.sessionId === sessionId)) {
|
|
167
|
+
pending.sawVisibleOutput = true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this.#writeClient(message);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (isJsonRpcSuccess(message) || isJsonRpcFailure(message)) {
|
|
175
|
+
const pending = this.#pending.get(message.id);
|
|
176
|
+
if (pending === undefined) {
|
|
177
|
+
this.#writeClient(message);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
this.#pending.delete(message.id);
|
|
181
|
+
let outbound = message;
|
|
182
|
+
if (pending.method === INITIALIZE_METHOD && isJsonRpcSuccess(message)) {
|
|
183
|
+
outbound = { ...message, result: overlayProductIdentity(message.result, this.#version) };
|
|
184
|
+
}
|
|
185
|
+
else if (pending.method === SESSION_PROMPT_METHOD &&
|
|
186
|
+
isJsonRpcSuccess(message) &&
|
|
187
|
+
shouldRejectBlankTurn(message.result, pending.sawVisibleOutput)) {
|
|
188
|
+
outbound = blankTurnError(message.id);
|
|
189
|
+
}
|
|
190
|
+
this.#writeClient(outbound);
|
|
191
|
+
pending.resolve(outbound);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
this.#writeClient(message);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../ACP Connector/official-kernel/proxy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,gCAAgC,EAAE,MAAM,sBAAsB,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CA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|
6
|
+
version: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function runOfficialKernel(options: RunOfficialKernelOptions): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { OfficialKernelProxy } from "./proxy.js";
|
|
2
|
+
import { spawnOfficialKernel } from "./spawn.js";
|
|
3
|
+
export async function runOfficialKernel(options) {
|
|
4
|
+
const env = options.env ?? process.env;
|
|
5
|
+
const child = spawnOfficialKernel(env);
|
|
6
|
+
const proxy = new OfficialKernelProxy({
|
|
7
|
+
child,
|
|
8
|
+
stdin: (options.stdin ?? process.stdin),
|
|
9
|
+
stdout: (options.stdout ?? process.stdout),
|
|
10
|
+
env,
|
|
11
|
+
version: options.version
|
|
12
|
+
});
|
|
13
|
+
try {
|
|
14
|
+
await proxy.start();
|
|
15
|
+
}
|
|
16
|
+
finally {
|
|
17
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
18
|
+
child.kill("SIGTERM");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../ACP Connector/official-kernel/run.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AASjD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAiC;IACvE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,KAAK,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,IAAI,mBAAmB,CAAC;QACpC,KAAK;QACL,KAAK,EAAE,CAAC,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAa;QACnD,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAa;QACtD,GAAG;QACH,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;YAAS,CAAC;QACT,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YACzD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
|
+
export declare const DEFAULT_OFFICIAL_BIN: string;
|
|
3
|
+
export declare function resolveOfficialBinary(environment?: NodeJS.ProcessEnv): string;
|
|
4
|
+
export declare function officialSpawnArgs(binary: string): string[];
|
|
5
|
+
export declare function spawnOfficialKernel(environment?: NodeJS.ProcessEnv): ChildProcessWithoutNullStreams;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
export const DEFAULT_OFFICIAL_BIN = path.join(homedir(), ".local/opt/agy-acp-server-agy_acp_server_20260818_01_RC01/agy-acp-server-canary");
|
|
6
|
+
export function resolveOfficialBinary(environment = process.env) {
|
|
7
|
+
const configured = environment.PASEO_AGY_ACP_OFFICIAL_BIN?.trim();
|
|
8
|
+
return configured && configured.length > 0 ? configured : DEFAULT_OFFICIAL_BIN;
|
|
9
|
+
}
|
|
10
|
+
export function officialSpawnArgs(binary) {
|
|
11
|
+
const base = path.basename(binary);
|
|
12
|
+
if (base.endsWith(".par") || base === "agy_acp_server.par")
|
|
13
|
+
return ["--uid="];
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
export function spawnOfficialKernel(environment = process.env) {
|
|
17
|
+
const binary = resolveOfficialBinary(environment);
|
|
18
|
+
if (!existsSync(binary)) {
|
|
19
|
+
throw new Error(`official Antigravity ACP kernel is missing at ${binary}; set PASEO_AGY_ACP_OFFICIAL_BIN`);
|
|
20
|
+
}
|
|
21
|
+
const child = spawn(binary, officialSpawnArgs(binary), {
|
|
22
|
+
cwd: path.dirname(binary),
|
|
23
|
+
env: environment,
|
|
24
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
25
|
+
});
|
|
26
|
+
if (child.stdin === null || child.stdout === null || child.stderr === null) {
|
|
27
|
+
child.kill("SIGKILL");
|
|
28
|
+
throw new Error("official kernel stdio pipes are unavailable");
|
|
29
|
+
}
|
|
30
|
+
child.stderr.pipe(process.stderr);
|
|
31
|
+
return child;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=spawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../../ACP Connector/official-kernel/spawn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAuC,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAC3C,OAAO,EAAE,EACT,iFAAiF,CAClF,CAAC;AAEF,MAAM,UAAU,qBAAqB,CAAC,WAAW,GAAsB,OAAO,CAAC,GAAG;IAChF,MAAM,UAAU,GAAG,WAAW,CAAC,0BAA0B,EAAE,IAAI,EAAE,CAAC;IAClE,OAAO,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,KAAK,oBAAoB;QAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9E,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,WAAW,GAAsB,OAAO,CAAC,GAAG;IAE5C,MAAM,MAAM,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;IAClD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,iDAAiD,MAAM,kCAAkC,CAC1F,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAAE;QACrD,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACzB,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;KAChC,CAAC,CAAC;IACH,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC3E,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { type LinuxProcessEvidenceReaders } from "./process-evidence.js";
|
|
2
|
+
export { isAllowedAdmissionActiveTurns, isAllowedAdmissionConcurrentStarts } from "./policy-limits.js";
|
|
3
|
+
export interface AdmissionPolicy {
|
|
4
|
+
maxActiveTurns: number;
|
|
5
|
+
maxConcurrentStarts: number;
|
|
6
|
+
minStartIntervalMs: number;
|
|
7
|
+
queueTimeoutMs: number;
|
|
8
|
+
capacityCooldownMs: number;
|
|
9
|
+
}
|
|
10
|
+
export interface AdmissionControllerOptions {
|
|
11
|
+
databasePath: string;
|
|
12
|
+
policy: AdmissionPolicy;
|
|
13
|
+
encryptionKey?: Buffer;
|
|
14
|
+
contentFingerprintKey?: Buffer;
|
|
15
|
+
/** Test-only synchronous hook for proving rollback at the atomic dispatch boundary. */
|
|
16
|
+
faultInjection?: AdmissionControllerFaultInjection;
|
|
17
|
+
}
|
|
18
|
+
/** Test-only synchronous hooks for proving rollback at durable transaction midpoints. */
|
|
19
|
+
export interface AdmissionControllerFaultInjection {
|
|
20
|
+
afterProcessIdentityPersisted?(): void;
|
|
21
|
+
}
|
|
22
|
+
interface EnqueueRequestBase {
|
|
23
|
+
requestId: string;
|
|
24
|
+
sessionId: string;
|
|
25
|
+
fingerprint: string;
|
|
26
|
+
provider: string;
|
|
27
|
+
model: string;
|
|
28
|
+
now: number;
|
|
29
|
+
ownerIdentity?: VerifiedLinuxConnectorIdentity;
|
|
30
|
+
}
|
|
31
|
+
export type EnqueueRequest = EnqueueRequestBase & {
|
|
32
|
+
agentId?: string;
|
|
33
|
+
parentId?: string;
|
|
34
|
+
};
|
|
35
|
+
export type ConfirmedProviderOutcome = "completed" | "failed" | "cancelled";
|
|
36
|
+
export type RequestState = "queued" | "admitted" | "starting" | "dispatch_intent" | "dispatch_ambiguous" | "active" | "provider_terminal" | "completed" | "failed" | "cancelled" | "queue_timeout" | "recovery_required";
|
|
37
|
+
export type PolicyEventState = "policy_steady" | "policy_soft_draining_to_1";
|
|
38
|
+
export type SanitizedEventState = RequestState | PolicyEventState | "absent";
|
|
39
|
+
export type SanitizedEventKind = "request_enqueued" | "request_cancelled" | "request_abandoned" | "request_queue_timed_out" | "request_admitted" | "request_starting" | "request_dispatch_intent" | "request_active" | "request_dispatch_ambiguous" | "request_provider_terminal" | "request_released" | "request_recovery_required" | "request_recovery_seat_released" | "queued_owner_dead" | "policy_drain_completed";
|
|
40
|
+
/** Exact, identifier-free pagination input for the sanitized audit journal. */
|
|
41
|
+
export interface SanitizedEventPageRequest {
|
|
42
|
+
afterEventSeq: number;
|
|
43
|
+
limit: number;
|
|
44
|
+
}
|
|
45
|
+
/** Audit-only state transition. It cannot be used to recover request payloads or identities. */
|
|
46
|
+
export interface SanitizedAdmissionEvent {
|
|
47
|
+
readonly eventSeq: number;
|
|
48
|
+
readonly kind: SanitizedEventKind;
|
|
49
|
+
readonly fromState: SanitizedEventState;
|
|
50
|
+
readonly toState: SanitizedEventState;
|
|
51
|
+
readonly occurredAt: number;
|
|
52
|
+
readonly correlationHmac: string;
|
|
53
|
+
}
|
|
54
|
+
export interface StoredRequest {
|
|
55
|
+
requestId: string;
|
|
56
|
+
sessionId: string;
|
|
57
|
+
agentId: string;
|
|
58
|
+
fingerprint: string;
|
|
59
|
+
provider: string;
|
|
60
|
+
model: string;
|
|
61
|
+
state: RequestState;
|
|
62
|
+
enqueuedAt: number;
|
|
63
|
+
}
|
|
64
|
+
/** Terminal fact for the existing online ACP output path. */
|
|
65
|
+
export interface LiveTurnCompletion {
|
|
66
|
+
readonly outcome: ConfirmedProviderOutcome;
|
|
67
|
+
readonly failure?: Readonly<{
|
|
68
|
+
readonly category: "provider_capacity" | "quota" | "auth" | "permission" | "timeout" | "transport" | "unknown";
|
|
69
|
+
readonly httpStatus?: number;
|
|
70
|
+
readonly code?: string;
|
|
71
|
+
readonly reason?: string;
|
|
72
|
+
}>;
|
|
73
|
+
}
|
|
74
|
+
/** Durable queue observation. It grants no admission or recovery authority. */
|
|
75
|
+
export interface AdmissionQueueSnapshot {
|
|
76
|
+
readonly requestId: string;
|
|
77
|
+
readonly position: number;
|
|
78
|
+
readonly eligiblePosition: number | null;
|
|
79
|
+
readonly enqueuedAt: number;
|
|
80
|
+
readonly waitedMs: number;
|
|
81
|
+
readonly cooldownUntil: number | null;
|
|
82
|
+
}
|
|
83
|
+
export interface AdmissionLease {
|
|
84
|
+
leaseId: string;
|
|
85
|
+
requestId: string;
|
|
86
|
+
generation: number;
|
|
87
|
+
ownerInstanceId: string;
|
|
88
|
+
}
|
|
89
|
+
export type LeaseFence = Pick<AdmissionLease, "leaseId" | "generation" | "ownerInstanceId">;
|
|
90
|
+
/** Nonterminal controller phases which need a startup recovery decision. */
|
|
91
|
+
export type RecoverableDispatchPhase = "admitted" | "starting" | "dispatch_intent" | "dispatch_ambiguous" | "active" | "recovery_required";
|
|
92
|
+
/** Immutable evidence for one Linux process instance. */
|
|
93
|
+
export interface VerifiedLinuxProcessIdentity {
|
|
94
|
+
bootId: string;
|
|
95
|
+
pid: number;
|
|
96
|
+
startTimeTicks: string;
|
|
97
|
+
pidNamespaceInode: number;
|
|
98
|
+
ppid: number;
|
|
99
|
+
pgrp: number;
|
|
100
|
+
session: number;
|
|
101
|
+
}
|
|
102
|
+
/** Connector owner evidence paired with the connector's stable instance ID. */
|
|
103
|
+
export interface VerifiedLinuxConnectorIdentity extends VerifiedLinuxProcessIdentity {
|
|
104
|
+
ownerInstanceId: string;
|
|
105
|
+
createdAt: string;
|
|
106
|
+
}
|
|
107
|
+
/** The only process record accepted at the irreversible dispatch boundary. */
|
|
108
|
+
export interface VerifiedLinuxProcessRecord {
|
|
109
|
+
requestId: string;
|
|
110
|
+
leaseId: string;
|
|
111
|
+
generation: number;
|
|
112
|
+
ownerInstanceId: string;
|
|
113
|
+
processIdentity: {
|
|
114
|
+
connector: VerifiedLinuxConnectorIdentity;
|
|
115
|
+
child: VerifiedLinuxProcessIdentity;
|
|
116
|
+
};
|
|
117
|
+
promptChannel: "stdin" | "pty";
|
|
118
|
+
}
|
|
119
|
+
/** Durable process evidence available to startup recovery, never request content. */
|
|
120
|
+
export interface RecoverableDispatchProcessIdentity {
|
|
121
|
+
readonly promptChannel: "stdin" | "pty";
|
|
122
|
+
readonly connector: VerifiedLinuxConnectorIdentity;
|
|
123
|
+
readonly child: VerifiedLinuxProcessIdentity;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* One nonterminal dispatch candidate after connector startup. A null process
|
|
127
|
+
* identity is intentionally explicit: the caller must fail closed into
|
|
128
|
+
* recovery and must not resume or replay the dispatch from this inventory.
|
|
129
|
+
*/
|
|
130
|
+
export interface RecoverableDispatch {
|
|
131
|
+
readonly requestId: string;
|
|
132
|
+
readonly sessionId: string;
|
|
133
|
+
readonly provider: string;
|
|
134
|
+
readonly model: string;
|
|
135
|
+
readonly fence: LeaseFence;
|
|
136
|
+
readonly phase: RecoverableDispatchPhase;
|
|
137
|
+
readonly heartbeatAt: number;
|
|
138
|
+
readonly processIdentity: RecoverableDispatchProcessIdentity | null;
|
|
139
|
+
}
|
|
140
|
+
/** Durable queued-owner evidence for a request that has not dispatched. */
|
|
141
|
+
export interface RecoverableQueuedOwner {
|
|
142
|
+
readonly requestId: string;
|
|
143
|
+
readonly owner: VerifiedLinuxConnectorIdentity;
|
|
144
|
+
}
|
|
145
|
+
export type LeaseSuspectReason = "heartbeat_expired" | "identity_unverifiable";
|
|
146
|
+
export interface AdmissionRuntimeReaperReaders extends LinuxProcessEvidenceReaders {
|
|
147
|
+
listProcessIds(): readonly number[];
|
|
148
|
+
}
|
|
149
|
+
export interface AdmissionRuntimeReaperSummary {
|
|
150
|
+
readonly inspected: number;
|
|
151
|
+
readonly released: number;
|
|
152
|
+
readonly retained: number;
|
|
153
|
+
readonly markedRecoveryRequired: number;
|
|
154
|
+
readonly suspected: number;
|
|
155
|
+
readonly queuedSettled: number;
|
|
156
|
+
}
|
|
157
|
+
export type DispatchIntentFailureReason = "invalid_process_identity" | "stale_lease" | "conflicting_intent" | "transaction_fault";
|
|
158
|
+
/** Result for the dispatcher identity callback. Success means dispatch_intent is already durable too. */
|
|
159
|
+
export type ProcessIdentityRecordResult = {
|
|
160
|
+
status: "recorded";
|
|
161
|
+
idempotent: boolean;
|
|
162
|
+
} | {
|
|
163
|
+
status: "not_recorded";
|
|
164
|
+
reason: DispatchIntentFailureReason;
|
|
165
|
+
};
|
|
166
|
+
/** Result for the dispatch boundary's following commit callback; only an exact durable replay succeeds. */
|
|
167
|
+
export type DispatchIntentCommitResult = {
|
|
168
|
+
status: "committed";
|
|
169
|
+
idempotent: boolean;
|
|
170
|
+
} | {
|
|
171
|
+
status: "not_committed";
|
|
172
|
+
reason: DispatchIntentFailureReason;
|
|
173
|
+
};
|
|
174
|
+
export declare class AdmissionConflictError extends Error {
|
|
175
|
+
constructor(_requestId: string);
|
|
176
|
+
}
|
|
177
|
+
export declare class PayloadExpiredError extends Error {
|
|
178
|
+
constructor(_requestId: string);
|
|
179
|
+
}
|
|
180
|
+
export declare class PayloadConflictError extends Error {
|
|
181
|
+
constructor(_requestId: string);
|
|
182
|
+
}
|
|
183
|
+
export declare class LeaseFenceError extends Error {
|
|
184
|
+
constructor(_leaseId: string);
|
|
185
|
+
}
|
|
186
|
+
/** Raised when durable recovery inventory data cannot be trusted. */
|
|
187
|
+
export declare class RecoverableDispatchInventoryError extends Error {
|
|
188
|
+
constructor();
|
|
189
|
+
}
|
|
190
|
+
export declare class AdmissionMigrationError extends Error {
|
|
191
|
+
constructor(detail: string);
|
|
192
|
+
}
|
|
193
|
+
export declare class AdmissionRuntimeError extends Error {
|
|
194
|
+
constructor(message: string);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* A local, cross-process admission plane. It deliberately refuses to infer
|
|
198
|
+
* that a dispatched turn is safe to replay after a crash.
|
|
199
|
+
*/
|
|
200
|
+
export declare class AdmissionController {
|
|
201
|
+
#private;
|
|
202
|
+
readonly databasePath: string;
|
|
203
|
+
readonly policy: AdmissionPolicy;
|
|
204
|
+
constructor(options: AdmissionControllerOptions);
|
|
205
|
+
close(): void;
|
|
206
|
+
get schemaVersion(): number;
|
|
207
|
+
enqueue(input: EnqueueRequest): {
|
|
208
|
+
requestId: string;
|
|
209
|
+
existed: boolean;
|
|
210
|
+
};
|
|
211
|
+
enqueueWithPayload(input: EnqueueRequest, plaintext: string, expiresAt: number): {
|
|
212
|
+
requestId: string;
|
|
213
|
+
existed: boolean;
|
|
214
|
+
};
|
|
215
|
+
persistPayload(requestId: string, plaintext: string, now: number, expiresAt: number): void;
|
|
216
|
+
readPayload(requestId: string, now: number): string;
|
|
217
|
+
/** Cancelling after admission needs process and provider-terminal evidence. */
|
|
218
|
+
cancelQueued(requestId: string, now: number): void;
|
|
219
|
+
admitNext(now: number, ownerInstanceId: string): AdmissionLease | null;
|
|
220
|
+
/**
|
|
221
|
+
* Atomically admit this request only when the global selector chose it.
|
|
222
|
+
* Callers may wait on their own request, but cannot bypass the controller's
|
|
223
|
+
* oldest-eligible and agent-fair ordering.
|
|
224
|
+
*/
|
|
225
|
+
admitRequest(requestId: string, now: number, ownerInstanceId: string): AdmissionLease | null;
|
|
226
|
+
getQueueSnapshot(requestId: string, now: number): AdmissionQueueSnapshot | null;
|
|
227
|
+
markStarting(fence: LeaseFence, now: number): void;
|
|
228
|
+
/**
|
|
229
|
+
* Persist a verified Linux process record and dispatch_intent in one SQLite
|
|
230
|
+
* transaction. The following dispatch-boundary commit callback is an exact replay
|
|
231
|
+
* check, so no crash window exists between those two callbacks.
|
|
232
|
+
*/
|
|
233
|
+
recordProcessIdentity(input: unknown): ProcessIdentityRecordResult;
|
|
234
|
+
/**
|
|
235
|
+
* Confirm the atomic identity-and-intent persistence. A fresh call performs
|
|
236
|
+
* the same transaction; a matching dispatch_intent record is idempotent.
|
|
237
|
+
*/
|
|
238
|
+
commitDispatchIntent(input: unknown): DispatchIntentCommitResult;
|
|
239
|
+
markDispatchIntent(fence: LeaseFence, now: number): void;
|
|
240
|
+
markActive(fence: LeaseFence, now: number): void;
|
|
241
|
+
markDispatchAmbiguous(fence: LeaseFence, now: number): void;
|
|
242
|
+
/**
|
|
243
|
+
* End a reserved turn only when the Connector still has direct proof that no
|
|
244
|
+
* business prompt write occurred. This is terminal, never a requeue.
|
|
245
|
+
*/
|
|
246
|
+
abandonBeforePrompt(fence: LeaseFence, now: number, outcome: Extract<ConfirmedProviderOutcome, "failed" | "cancelled">): void;
|
|
247
|
+
/** Retain an uncertain dispatch as visible capacity debt; never requeue it. */
|
|
248
|
+
markExecutionRecoveryRequired(fence: LeaseFence, now: number): void;
|
|
249
|
+
/**
|
|
250
|
+
* Release only the local seat after the Connector has independently proved
|
|
251
|
+
* that the persisted connector, child, and process group are all gone. The
|
|
252
|
+
* request deliberately remains recovery_required and cannot be replayed.
|
|
253
|
+
*/
|
|
254
|
+
releaseExitedRecoverySeat(fence: LeaseFence, now: number): void;
|
|
255
|
+
/**
|
|
256
|
+
* Persist the terminal state and release the seat used by the existing live
|
|
257
|
+
* ACP update path. No delivery replay record is created.
|
|
258
|
+
*/
|
|
259
|
+
completeLiveTurn(fence: LeaseFence, now: number, completion: LiveTurnCompletion): void;
|
|
260
|
+
heartbeat(fence: LeaseFence, now: number): void;
|
|
261
|
+
/**
|
|
262
|
+
* Runtime recovery is evidence-only: a stale heartbeat can mark suspicion,
|
|
263
|
+
* but only connector/child/process-group proof can release local capacity.
|
|
264
|
+
*/
|
|
265
|
+
reapSuspects(now: number, readers: AdmissionRuntimeReaperReaders): AdmissionRuntimeReaperSummary;
|
|
266
|
+
setCapacityCooldown(provider: string, model: string, notBefore: number, now: number): void;
|
|
267
|
+
/**
|
|
268
|
+
* Read an identifier-free page of the append-only audit journal. The exact
|
|
269
|
+
* input shape deliberately provides no request/session/provider lookup seam.
|
|
270
|
+
*/
|
|
271
|
+
readSanitizedEvents(input: unknown): readonly SanitizedAdmissionEvent[];
|
|
272
|
+
getRequest(requestId: string): StoredRequest | null;
|
|
273
|
+
/**
|
|
274
|
+
* Enumerate durable, nonterminal dispatches for connector startup recovery.
|
|
275
|
+
* This deliberately reads no prompt or outbox table, never decrypts data,
|
|
276
|
+
* and returns a null identity instead of implying that a dispatch is safe to
|
|
277
|
+
* resume when immutable process evidence is absent.
|
|
278
|
+
*/
|
|
279
|
+
listRecoverableDispatches(): readonly RecoverableDispatch[];
|
|
280
|
+
/**
|
|
281
|
+
* Enumerate queued requests whose owning connector was durably recorded at
|
|
282
|
+
* enqueue time. This returns no payload and grants no replay authority.
|
|
283
|
+
*/
|
|
284
|
+
listRecoverableQueuedOwners(): readonly RecoverableQueuedOwner[];
|
|
285
|
+
settleQueuedOwnerDeath(requestId: string, ownerInstanceId: string, now: number): boolean;
|
|
286
|
+
claimDurablePolicy(policy: AdmissionPolicy, ownerInstanceId: string, now: number): void;
|
|
287
|
+
assertDurablePolicyMatch(policy: AdmissionPolicy, ownerInstanceId: string, now: number): void;
|
|
288
|
+
beginSoftDrainTo1(ownerInstanceId: string, now: number): void;
|
|
289
|
+
private migrate;
|
|
290
|
+
private assertRenameColumnAvailable;
|
|
291
|
+
private createInitialV1Schema;
|
|
292
|
+
private migrateV1ToV2;
|
|
293
|
+
private migrateV2ToV3;
|
|
294
|
+
private transaction;
|
|
295
|
+
private runInjectedTransactionFault;
|
|
296
|
+
private persistProcessIdentityAndDispatchIntent;
|
|
297
|
+
/** A failed writer may inspect only a committed, exact winner; it never retries a write. */
|
|
298
|
+
private recheckDispatchIdentityAfterContention;
|
|
299
|
+
/** Reads the lease and identity under one snapshot so no partial winner can be inferred. */
|
|
300
|
+
private inspectDispatchIdentityContentionWinner;
|
|
301
|
+
private persistProcessIdentityAndDispatchIntentInTransaction;
|
|
302
|
+
private findLeaseProcessIdentity;
|
|
303
|
+
private insertLeaseProcessIdentity;
|
|
304
|
+
private persistQueuedOwnerReference;
|
|
305
|
+
private findQueuedOwnerIdentity;
|
|
306
|
+
private insertQueuedOwnerIdentity;
|
|
307
|
+
private expireQueued;
|
|
308
|
+
private activeLeaseCount;
|
|
309
|
+
private hasSeatCapacity;
|
|
310
|
+
private markSuspect;
|
|
311
|
+
private completeSoftDrainTo1IfSettled;
|
|
312
|
+
private hasDispatchCapacity;
|
|
313
|
+
private reserveAdmission;
|
|
314
|
+
private orderedQueuedRequests;
|
|
315
|
+
private selectEligibleRequest;
|
|
316
|
+
private isCooldownActive;
|
|
317
|
+
private cooldownUntil;
|
|
318
|
+
private requireLease;
|
|
319
|
+
private requireLeaseById;
|
|
320
|
+
private requireRequest;
|
|
321
|
+
private requireRequestState;
|
|
322
|
+
private requireEncryptionKey;
|
|
323
|
+
private requireContentFingerprintKey;
|
|
324
|
+
private journalTransition;
|
|
325
|
+
private encrypt;
|
|
326
|
+
private decrypt;
|
|
327
|
+
private enqueueRequest;
|
|
328
|
+
private insertPayload;
|
|
329
|
+
private contentFingerprint;
|
|
330
|
+
private payloadAad;
|
|
331
|
+
private policyFingerprint;
|
|
332
|
+
private assertDurablePolicyMatchInTransaction;
|
|
333
|
+
private readPolicyStateInTransaction;
|
|
334
|
+
private requirePolicyStateInTransaction;
|
|
335
|
+
private validatePayloadExpiry;
|
|
336
|
+
private transition;
|
|
337
|
+
private setLeasePhase;
|
|
338
|
+
}
|