@tangle-network/agent-provider-cli-bridge 1.0.3 → 1.1.1
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 +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/retained-control.d.ts +3 -1
- package/dist/retained-control.js +62 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -107,6 +107,11 @@ When `dispatch()` receives no `sessionId`, it creates one from that turn's stabl
|
|
|
107
107
|
Replay and result reads fail loudly after cli-bridge's configured replay retention expires.
|
|
108
108
|
Stopping a `session.events()` reader detaches only that replay observer.
|
|
109
109
|
Stopping a direct `environment.stream()` reader or destroying the environment cancels its active bridge runs and waits for terminal confirmation.
|
|
110
|
+
Destroying an environment does not close a native Bridge session that has reached a terminal result.
|
|
111
|
+
For a one-shot Pi session, call `closeExactCliBridgeSession(options, controlRef)` after reading the result.
|
|
112
|
+
The provider verifies the exact run and session before it closes the session.
|
|
113
|
+
Repeat cleanup of the same closed session succeeds without sending another close request.
|
|
114
|
+
Keep the `controlRef` from durable admission so a process restart can perform the same cleanup.
|
|
110
115
|
|
|
111
116
|
Pi retained sessions also expose typed permission interactions and native continuation.
|
|
112
117
|
The provider stores the selected harness, exact model route, and canonical create digest inside its opaque environment identifier.
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type { CliBridgeProviderOptions } from "./provider-options.js";
|
|
|
6
6
|
export type { CliBridgeExecution } from "./provider-options.js";
|
|
7
7
|
export type { CliBridgeRunLookupInput } from "./retained-control.js";
|
|
8
8
|
export { safeEndpointFromBaseUrl } from "./observation.js";
|
|
9
|
+
export { closeExactCliBridgeSession } from "./retained-control.js";
|
|
9
10
|
export interface CliBridgeProvider extends AgentEnvironmentProvider {
|
|
10
11
|
/** Recover the server-issued digest for one pre-dispatch retained admission. */
|
|
11
12
|
lookupRun(input: CliBridgeRunLookupInput): Promise<AgentExactRunControlRef | null>;
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { narrowedCliBridgeObservation } from "./observation.js";
|
|
|
10
10
|
import { cliBridgeEnvironmentId, optionalCliBridgeEnvironmentRoute, } from "./environment-identity.js";
|
|
11
11
|
import { resolveBridgeModel } from "./wire.js";
|
|
12
12
|
export { safeEndpointFromBaseUrl } from "./observation.js";
|
|
13
|
+
export { closeExactCliBridgeSession } from "./retained-control.js";
|
|
13
14
|
export function createCliBridgeProvider(options) {
|
|
14
15
|
assertCliBridgeProviderOptions(options);
|
|
15
16
|
const name = options.name ?? "cli-bridge";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type AgentExactRunControlRef, type AgentRunCancellationAcknowledgement, type AgentRunCancellationRequest } from "@tangle-network/agent-interface";
|
|
2
2
|
import type { AgentSessionStatus } from "@tangle-network/agent-interface/environment-provider";
|
|
3
3
|
import { type CliBridgeProviderOptions } from "./provider-options.js";
|
|
4
|
-
import type
|
|
4
|
+
import { type CliBridgeRun, type CliBridgeRunSnapshot } from "./retained-run-state.js";
|
|
5
5
|
import type { CliBridgeResponse, CliBridgeTransport } from "./transport.js";
|
|
6
|
+
/** Release one terminal native session using the exact retained run it last owned. */
|
|
7
|
+
export declare function closeExactCliBridgeSession(options: CliBridgeProviderOptions, controlRef: AgentExactRunControlRef, signal?: AbortSignal): Promise<void>;
|
|
6
8
|
export declare function cliBridgeCancellationSignal(options: CliBridgeProviderOptions): AbortSignal;
|
|
7
9
|
export declare function captureCliBridgeRunIdentity(response: CliBridgeResponse, run: CliBridgeRun, required: boolean): void;
|
|
8
10
|
export declare function detachCliBridgeReader(body: AsyncIterable<Uint8Array>): Promise<void>;
|
package/dist/retained-control.js
CHANGED
|
@@ -1,8 +1,69 @@
|
|
|
1
1
|
import { AgentExactRunControlRefSchema, AgentRunCancellationAcknowledgementSchema, AgentRunCancellationRequestSchema, agentRunCancellationRequestDigest, agentRunCancellationAcknowledgementMatchesRequest, sameAgentRunControlRef, } from "@tangle-network/agent-interface";
|
|
2
2
|
import { assertCliBridgeProviderOptions, } from "./provider-options.js";
|
|
3
|
+
import { runFromControlRef } from "./retained-run-state.js";
|
|
3
4
|
import { createCliBridgeTransport, MAX_CLI_BRIDGE_CONTROL_RESPONSE_BYTES, readBoundedCliBridgeResponse, requestHeaders, trimSlash, } from "./transport.js";
|
|
4
|
-
import { assertCliBridgeRunId, runSnapshot } from "./wire.js";
|
|
5
|
+
import { assertCliBridgeRunId, runSnapshot, safeJson } from "./wire.js";
|
|
5
6
|
const DEFAULT_CANCELLATION_WAIT_MS = 30_000;
|
|
7
|
+
/** Release one terminal native session using the exact retained run it last owned. */
|
|
8
|
+
export async function closeExactCliBridgeSession(options, controlRef, signal) {
|
|
9
|
+
assertCliBridgeProviderOptions(options);
|
|
10
|
+
const exact = AgentExactRunControlRefSchema.parse(controlRef);
|
|
11
|
+
if (exact.provider !== (options.name ?? "cli-bridge")) {
|
|
12
|
+
throw new Error("cli-bridge session close targets another provider");
|
|
13
|
+
}
|
|
14
|
+
const timeoutSignal = AbortSignal.timeout(options.cancelWaitMs ?? DEFAULT_CANCELLATION_WAIT_MS);
|
|
15
|
+
const operationSignal = signal === undefined ? timeoutSignal : AbortSignal.any([signal, timeoutSignal]);
|
|
16
|
+
const transport = createCliBridgeTransport(options);
|
|
17
|
+
try {
|
|
18
|
+
const run = await getCliBridgeRun(options, transport, runFromControlRef(exact), undefined, operationSignal);
|
|
19
|
+
if (!run?.terminal) {
|
|
20
|
+
throw new Error("cli-bridge cannot close a session before its exact run is terminal");
|
|
21
|
+
}
|
|
22
|
+
const endpoint = `${trimSlash(options.baseUrl)}/v1/sessions/${encodeURIComponent(exact.sessionId)}`;
|
|
23
|
+
const currentResponse = await transport.fetch(endpoint, {
|
|
24
|
+
method: "GET",
|
|
25
|
+
headers: requestHeaders(options),
|
|
26
|
+
signal: operationSignal,
|
|
27
|
+
});
|
|
28
|
+
const currentText = await readBoundedCliBridgeResponse(currentResponse, MAX_CLI_BRIDGE_CONTROL_RESPONSE_BYTES, operationSignal);
|
|
29
|
+
if (!currentResponse.ok) {
|
|
30
|
+
throw new Error(`cli-bridge session status returned HTTP ${currentResponse.status}`);
|
|
31
|
+
}
|
|
32
|
+
const current = safeJson(currentText);
|
|
33
|
+
if (current?.id !== exact.sessionId || current.run_id !== exact.runId) {
|
|
34
|
+
throw new Error("cli-bridge session close targets another retained run");
|
|
35
|
+
}
|
|
36
|
+
if (current.status === "closed")
|
|
37
|
+
return;
|
|
38
|
+
if (current.status === "running") {
|
|
39
|
+
throw new Error("cli-bridge cannot close an active retained session");
|
|
40
|
+
}
|
|
41
|
+
const response = await transport.fetch(`${endpoint}/close`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: requestHeaders(options),
|
|
44
|
+
signal: operationSignal,
|
|
45
|
+
});
|
|
46
|
+
const responseText = await readBoundedCliBridgeResponse(response, MAX_CLI_BRIDGE_CONTROL_RESPONSE_BYTES, operationSignal);
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
throw new Error(`cli-bridge session close returned HTTP ${response.status}`);
|
|
49
|
+
}
|
|
50
|
+
const confirmation = safeJson(responseText);
|
|
51
|
+
const closed = confirmation?.session;
|
|
52
|
+
if (typeof closed !== "object" || closed === null || Array.isArray(closed)) {
|
|
53
|
+
throw new Error("cli-bridge session close did not confirm the exact closed session");
|
|
54
|
+
}
|
|
55
|
+
const session = closed;
|
|
56
|
+
if (confirmation?.closed !== true ||
|
|
57
|
+
session.id !== exact.sessionId ||
|
|
58
|
+
session.run_id !== exact.runId ||
|
|
59
|
+
session.status !== "closed") {
|
|
60
|
+
throw new Error("cli-bridge session close did not confirm the exact closed session");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
await transport.close();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
6
67
|
export function cliBridgeCancellationSignal(options) {
|
|
7
68
|
assertCliBridgeProviderOptions(options);
|
|
8
69
|
return AbortSignal.timeout(options.cancelWaitMs ?? DEFAULT_CANCELLATION_WAIT_MS);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangle-network/agent-provider-cli-bridge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "AgentEnvironmentProvider adapter for cli-bridge retained sessions and one-shot turns",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"LICENSE"
|
|
65
65
|
],
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@tangle-network/agent-interface": "^2.
|
|
68
|
-
"undici": "8.
|
|
67
|
+
"@tangle-network/agent-interface": "^2.13.1",
|
|
68
|
+
"undici": "8.11.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@types/node": "26.
|
|
71
|
+
"@types/node": "26.6.3",
|
|
72
72
|
"typescript": "7.0.2",
|
|
73
|
-
"vitest": "
|
|
73
|
+
"vitest": "5.0.2"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"build": "pnpm run clean && tsc -p tsconfig.build.json",
|