@agen-ai/agent-runtime 0.3.1 → 0.4.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 +288 -29
- package/dist/adapterValidation.d.ts +1 -1
- package/dist/adapterValidation.js +199 -92
- package/dist/artifacts.js +0 -1
- package/dist/contractErrors.d.ts +16 -3
- package/dist/contractErrors.js +42 -6
- package/dist/hostBindings/index.d.ts +4 -0
- package/dist/hostBindings/index.js +9 -0
- package/dist/hostBindings/lifetime.d.ts +25 -0
- package/dist/hostBindings/lifetime.js +147 -0
- package/dist/hostBindings/opening.d.ts +14 -0
- package/dist/hostBindings/opening.js +82 -0
- package/dist/hostBindings/schema.d.ts +9 -0
- package/dist/hostBindings/schema.js +169 -0
- package/dist/hostBindings/types.d.ts +71 -0
- package/dist/hostBindings/types.js +0 -0
- package/dist/hostBindings/validation.d.ts +14 -0
- package/dist/hostBindings/validation.js +107 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/internal/objectShape.d.ts +2 -0
- package/dist/internal/objectShape.js +7 -0
- package/dist/outputValidation.js +3 -2
- package/dist/providerDriver.js +0 -1
- package/dist/providerInstanceRegistry.js +2 -1
- package/dist/sessionCleanup.d.ts +9 -0
- package/dist/sessionCleanup.js +17 -0
- package/dist/sessionInteractions/index.d.ts +2 -0
- package/dist/sessionInteractions/index.js +1 -0
- package/dist/sessionInteractions/lifetime.d.ts +52 -0
- package/dist/sessionInteractions/lifetime.js +251 -0
- package/dist/sessionInteractions/request.d.ts +42 -0
- package/dist/sessionInteractions/request.js +308 -0
- package/dist/sessionInteractions/types.d.ts +54 -0
- package/dist/sessionInteractions/types.js +10 -0
- package/dist/sessionInteractions/validation.d.ts +21 -0
- package/dist/sessionInteractions/validation.js +119 -0
- package/dist/sessionValidation.d.ts +15 -2
- package/dist/sessionValidation.js +155 -318
- package/dist/sessions.d.ts +31 -4
- package/dist/testing/conformance.d.ts +3 -3
- package/dist/testing/conformance.js +24 -31
- package/dist/testing/fakeProvider.js +59 -49
- package/dist/turnExecution/execution.d.ts +26 -0
- package/dist/turnExecution/execution.js +214 -0
- package/dist/turnExecution/receipts.d.ts +6 -0
- package/dist/turnExecution/receipts.js +39 -0
- package/dist/turnExecution/requests.d.ts +19 -0
- package/dist/turnExecution/requests.js +56 -0
- package/package.json +2 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { parseAgentError } from "@agen-ai/agent-protocol";
|
|
2
|
+
import { throwAgentProviderContractError } from "../contractErrors.js";
|
|
3
|
+
import { hasExactOwnKeys } from "../internal/objectShape.js";
|
|
4
|
+
import { validateAgentProviderOperationResult } from "../outputValidation.js";
|
|
5
|
+
function validateAgentProviderTurnInterruptionResult(candidate, context) {
|
|
6
|
+
if (candidate === null || typeof candidate !== "object" || !hasExactOwnKeys(candidate, candidate.status === "failed" ? ["status", "error"] : ["status"])) {
|
|
7
|
+
return throwAgentProviderContractError(
|
|
8
|
+
context.providerKey,
|
|
9
|
+
"invalid_operation_result",
|
|
10
|
+
"Provider interruption must return an output-free operation receipt."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const result = validateAgentProviderOperationResult(candidate, context);
|
|
14
|
+
return Object.freeze({ status: result.status, ...result.error === void 0 ? {} : { error: result.error } });
|
|
15
|
+
}
|
|
16
|
+
function validateAgentRequestResolutionResult(candidate, providerKey) {
|
|
17
|
+
const invalid = () => throwAgentProviderContractError(
|
|
18
|
+
providerKey,
|
|
19
|
+
"invalid_operation_result",
|
|
20
|
+
"Provider returned an invalid request delivery receipt."
|
|
21
|
+
);
|
|
22
|
+
if (candidate === null || typeof candidate !== "object" || !("status" in candidate)) return invalid();
|
|
23
|
+
if (candidate.status === "delivered" && hasExactOwnKeys(candidate, ["status"])) {
|
|
24
|
+
return Object.freeze({ status: "delivered" });
|
|
25
|
+
}
|
|
26
|
+
if (!("error" in candidate)) return invalid();
|
|
27
|
+
const error = parseAgentError(candidate.error);
|
|
28
|
+
if (candidate.status === "delivery_uncertain" && hasExactOwnKeys(candidate, ["status", "error"])) {
|
|
29
|
+
return Object.freeze({ status: "delivery_uncertain", error });
|
|
30
|
+
}
|
|
31
|
+
if (candidate.status === "rejected" && hasExactOwnKeys(candidate, ["status", "requestState", "error"]) && "requestState" in candidate && (candidate.requestState === "pending" || candidate.requestState === "unavailable")) {
|
|
32
|
+
return Object.freeze({ status: "rejected", requestState: candidate.requestState, error });
|
|
33
|
+
}
|
|
34
|
+
return invalid();
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
validateAgentProviderTurnInterruptionResult,
|
|
38
|
+
validateAgentRequestResolutionResult
|
|
39
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AgentRequest, AgentTurnId } from "@agen-ai/agent-protocol";
|
|
2
|
+
export interface PendingAgentRequest {
|
|
3
|
+
readonly request: AgentRequest;
|
|
4
|
+
readonly turnId: AgentTurnId;
|
|
5
|
+
}
|
|
6
|
+
export interface SuspendedAgentTurnRequests {
|
|
7
|
+
readonly restore: () => void;
|
|
8
|
+
readonly withdraw: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function createAgentTurnRequestAdmission(input: Readonly<{
|
|
11
|
+
pendingRequests: Map<string, PendingAgentRequest>;
|
|
12
|
+
canRestore: () => boolean;
|
|
13
|
+
}>): {
|
|
14
|
+
claim: (requestId: string, pending: PendingAgentRequest) => (() => void);
|
|
15
|
+
suspend: () => SuspendedAgentTurnRequests;
|
|
16
|
+
withdraw: () => void;
|
|
17
|
+
observeRequest(): void;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=requests.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function createRequestAdmissionGeneration() {
|
|
2
|
+
return { suspensions: /* @__PURE__ */ new Set(), withheldRequests: /* @__PURE__ */ new Map() };
|
|
3
|
+
}
|
|
4
|
+
function createAgentTurnRequestAdmission(input) {
|
|
5
|
+
let generation = createRequestAdmissionGeneration();
|
|
6
|
+
const withdraw = () => {
|
|
7
|
+
generation = createRequestAdmissionGeneration();
|
|
8
|
+
input.pendingRequests.clear();
|
|
9
|
+
};
|
|
10
|
+
const restoreReadyRequests = (requestGeneration) => {
|
|
11
|
+
if (requestGeneration !== generation || !input.canRestore() || requestGeneration.suspensions.size > 0 || input.pendingRequests.size > 0) return;
|
|
12
|
+
for (const [requestId, pending] of requestGeneration.withheldRequests) {
|
|
13
|
+
input.pendingRequests.set(requestId, pending);
|
|
14
|
+
}
|
|
15
|
+
requestGeneration.withheldRequests.clear();
|
|
16
|
+
};
|
|
17
|
+
const claim = (requestId, pending) => {
|
|
18
|
+
const claimedGeneration = generation;
|
|
19
|
+
input.pendingRequests.delete(requestId);
|
|
20
|
+
return () => {
|
|
21
|
+
if (claimedGeneration !== generation || !input.canRestore()) return;
|
|
22
|
+
claimedGeneration.withheldRequests.set(requestId, pending);
|
|
23
|
+
restoreReadyRequests(claimedGeneration);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const suspend = () => {
|
|
27
|
+
const suspendedGeneration = generation;
|
|
28
|
+
const suspension = Symbol("interruption");
|
|
29
|
+
suspendedGeneration.suspensions.add(suspension);
|
|
30
|
+
for (const [requestId, pending] of input.pendingRequests) {
|
|
31
|
+
suspendedGeneration.withheldRequests.set(requestId, pending);
|
|
32
|
+
}
|
|
33
|
+
input.pendingRequests.clear();
|
|
34
|
+
return {
|
|
35
|
+
restore() {
|
|
36
|
+
if (!suspendedGeneration.suspensions.delete(suspension)) return;
|
|
37
|
+
restoreReadyRequests(suspendedGeneration);
|
|
38
|
+
},
|
|
39
|
+
withdraw() {
|
|
40
|
+
if (!suspendedGeneration.suspensions.delete(suspension)) return;
|
|
41
|
+
if (suspendedGeneration === generation) withdraw();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
claim,
|
|
47
|
+
suspend,
|
|
48
|
+
withdraw,
|
|
49
|
+
observeRequest() {
|
|
50
|
+
generation = createRequestAdmissionGeneration();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
createAgentTurnRequestAdmission
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agen-ai/agent-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Provider-neutral driver, instance, adapter, session, output, and conformance contracts for coding-agent runtimes.",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@agen-ai/agent-protocol": "^0.
|
|
34
|
+
"@agen-ai/agent-protocol": "^0.4.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"tsup": "^8.5.0"
|