@agen-ai/agent-runtime 0.1.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/LICENSE +21 -0
- package/README.md +139 -0
- package/dist/adapterValidation.d.ts +4 -0
- package/dist/adapterValidation.js +242 -0
- package/dist/artifacts.d.ts +28 -0
- package/dist/artifacts.js +87 -0
- package/dist/configurationValidation.d.ts +3 -0
- package/dist/configurationValidation.js +35 -0
- package/dist/contractErrors.d.ts +17 -0
- package/dist/contractErrors.js +59 -0
- package/dist/evidence.d.ts +50 -0
- package/dist/evidence.js +368 -0
- package/dist/foundation.d.ts +8 -0
- package/dist/foundation.js +37 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/internal/controlCharacters.d.ts +2 -0
- package/dist/internal/controlCharacters.js +7 -0
- package/dist/internal/serializedJsonBytes.d.ts +3 -0
- package/dist/internal/serializedJsonBytes.js +57 -0
- package/dist/outputValidation.d.ts +13 -0
- package/dist/outputValidation.js +174 -0
- package/dist/outputs.d.ts +81 -0
- package/dist/outputs.js +217 -0
- package/dist/providerCatalog.d.ts +13 -0
- package/dist/providerCatalog.js +33 -0
- package/dist/providerDriver.d.ts +41 -0
- package/dist/providerDriver.js +52 -0
- package/dist/providerInstanceRegistry.d.ts +40 -0
- package/dist/providerInstanceRegistry.js +322 -0
- package/dist/readiness.d.ts +22 -0
- package/dist/readiness.js +58 -0
- package/dist/sessionValidation.d.ts +19 -0
- package/dist/sessionValidation.js +767 -0
- package/dist/sessions.d.ts +133 -0
- package/dist/sessions.js +0 -0
- package/dist/steeringValidation.d.ts +4 -0
- package/dist/steeringValidation.js +36 -0
- package/dist/testing/conformance.d.ts +30 -0
- package/dist/testing/conformance.js +379 -0
- package/dist/testing/fakeProvider.d.ts +35 -0
- package/dist/testing/fakeProvider.js +367 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.js +2 -0
- package/dist/text.d.ts +2 -0
- package/dist/text.js +16 -0
- package/package.json +62 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseAgentError
|
|
3
|
+
} from "@agen-ai/agent-protocol";
|
|
4
|
+
import { throwAgentProviderContractError } from "./contractErrors.js";
|
|
5
|
+
import {
|
|
6
|
+
validateAgentProviderOutput
|
|
7
|
+
} from "./outputs.js";
|
|
8
|
+
function unsupportedCapabilitySemantic(value) {
|
|
9
|
+
throw new TypeError(
|
|
10
|
+
`Unsupported Agent Protocol capability semantic: ${String(value)}.`
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
function isItemKindCapabilitySupported(capabilities, itemKind) {
|
|
14
|
+
switch (itemKind) {
|
|
15
|
+
case "plan":
|
|
16
|
+
return capabilities.output.plans;
|
|
17
|
+
case "file_change":
|
|
18
|
+
return capabilities.output.fileChanges === "structured";
|
|
19
|
+
case "mcp_tool_call":
|
|
20
|
+
return capabilities.interactionExtensions.mcp;
|
|
21
|
+
case "collaboration_tool_call":
|
|
22
|
+
return capabilities.interactionExtensions.subagents;
|
|
23
|
+
case "user_message":
|
|
24
|
+
case "assistant_message":
|
|
25
|
+
case "reasoning":
|
|
26
|
+
case "command_execution":
|
|
27
|
+
case "dynamic_tool_call":
|
|
28
|
+
case "web_search":
|
|
29
|
+
case "browser_action":
|
|
30
|
+
case "computer_action":
|
|
31
|
+
case "image_view":
|
|
32
|
+
case "review":
|
|
33
|
+
case "context_compaction":
|
|
34
|
+
case "unknown":
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return unsupportedCapabilitySemantic(itemKind);
|
|
38
|
+
}
|
|
39
|
+
function isContentStreamCapabilitySupported(capabilities, streamKind) {
|
|
40
|
+
switch (streamKind) {
|
|
41
|
+
case "plan_text":
|
|
42
|
+
return capabilities.output.plans;
|
|
43
|
+
case "file_change_output":
|
|
44
|
+
return capabilities.output.fileChanges === "structured";
|
|
45
|
+
case "assistant_text":
|
|
46
|
+
case "reasoning_text":
|
|
47
|
+
case "reasoning_summary":
|
|
48
|
+
case "command_output":
|
|
49
|
+
case "unknown":
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return unsupportedCapabilitySemantic(streamKind);
|
|
53
|
+
}
|
|
54
|
+
function isEventCapabilitySupported(capabilities, event) {
|
|
55
|
+
switch (event.type) {
|
|
56
|
+
case "item.started":
|
|
57
|
+
case "item.updated":
|
|
58
|
+
case "item.completed":
|
|
59
|
+
return isItemKindCapabilitySupported(capabilities, event.payload.itemKind);
|
|
60
|
+
case "content.delta":
|
|
61
|
+
return capabilities.output.streaming && isContentStreamCapabilitySupported(
|
|
62
|
+
capabilities,
|
|
63
|
+
event.payload.streamKind
|
|
64
|
+
);
|
|
65
|
+
case "turn.plan.updated":
|
|
66
|
+
case "turn.plan.proposed":
|
|
67
|
+
return capabilities.output.plans;
|
|
68
|
+
case "turn.diff.updated":
|
|
69
|
+
return capabilities.output.fileChanges !== "none";
|
|
70
|
+
case "artifact.referenced":
|
|
71
|
+
return capabilities.output.artifactKinds.includes(
|
|
72
|
+
event.payload.artifact.kind
|
|
73
|
+
);
|
|
74
|
+
case "request.opened":
|
|
75
|
+
return event.payload.request.requestKind === "approval" ? capabilities.requests.approval : capabilities.requests.elicitation.kind === "structured" || capabilities.requests.elicitation.kind === "text" && event.payload.request.fields.every(
|
|
76
|
+
(field) => field.kind === "text"
|
|
77
|
+
);
|
|
78
|
+
case "turn.started":
|
|
79
|
+
case "turn.state_changed":
|
|
80
|
+
case "turn.completed":
|
|
81
|
+
case "progress.updated":
|
|
82
|
+
case "runtime.warning":
|
|
83
|
+
case "runtime.error":
|
|
84
|
+
case "provider.diagnostic":
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return unsupportedCapabilitySemantic(event);
|
|
88
|
+
}
|
|
89
|
+
function assertOutputCapability(context, output) {
|
|
90
|
+
if (output.kind === "artifact") {
|
|
91
|
+
if (context.capabilities.output.artifactKinds.includes(
|
|
92
|
+
output.candidate.descriptor.kind
|
|
93
|
+
)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
throwAgentProviderContractError(
|
|
97
|
+
context.providerKey,
|
|
98
|
+
"output_capability_mismatch",
|
|
99
|
+
`Provider ${context.providerKey} emitted an artifact without advertising its kind.`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
if (output.kind === "event" && !isEventCapabilitySupported(context.capabilities, output.event)) {
|
|
103
|
+
throwAgentProviderContractError(
|
|
104
|
+
context.providerKey,
|
|
105
|
+
"output_capability_mismatch",
|
|
106
|
+
`Provider ${context.providerKey} emitted ${output.event.type} without advertising support.`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function validateAgentProviderOutputForContext(candidate, context) {
|
|
111
|
+
const output = validateAgentProviderOutput(candidate);
|
|
112
|
+
if (output.kind === "event" && context.sessionId !== void 0) {
|
|
113
|
+
if (output.event.sessionId !== context.sessionId) {
|
|
114
|
+
throwAgentProviderContractError(
|
|
115
|
+
context.providerKey,
|
|
116
|
+
"output_session_mismatch",
|
|
117
|
+
`Provider ${context.providerKey} emitted an event for another session.`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
if (context.turnId !== void 0 && output.event.turnId !== void 0 && output.event.turnId !== context.turnId) {
|
|
121
|
+
throwAgentProviderContractError(
|
|
122
|
+
context.providerKey,
|
|
123
|
+
"output_turn_mismatch",
|
|
124
|
+
`Provider ${context.providerKey} emitted an event for another turn.`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (output.kind === "authentication" && output.progress.attemptId !== context.authenticationAttemptId) {
|
|
129
|
+
throwAgentProviderContractError(
|
|
130
|
+
context.providerKey,
|
|
131
|
+
"output_authentication_attempt_mismatch",
|
|
132
|
+
`Provider ${context.providerKey} emitted authentication progress for another attempt.`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
assertOutputCapability(context, output);
|
|
136
|
+
return output;
|
|
137
|
+
}
|
|
138
|
+
function validateAgentProviderOperationResult(candidate, context) {
|
|
139
|
+
if (candidate === null || typeof candidate !== "object" || ![
|
|
140
|
+
"accepted",
|
|
141
|
+
"completed",
|
|
142
|
+
"failed",
|
|
143
|
+
"canceled",
|
|
144
|
+
"waiting_for_request"
|
|
145
|
+
].includes(candidate.status) || candidate.outputs !== void 0 && !Array.isArray(candidate.outputs)) {
|
|
146
|
+
throwAgentProviderContractError(
|
|
147
|
+
context.providerKey,
|
|
148
|
+
"invalid_operation_result",
|
|
149
|
+
`Provider ${context.providerKey} returned an invalid operation result.`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (candidate.status === "failed" !== (candidate.error !== void 0)) {
|
|
153
|
+
throwAgentProviderContractError(
|
|
154
|
+
context.providerKey,
|
|
155
|
+
"invalid_operation_result",
|
|
156
|
+
"Only failed provider operation results must include an error."
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
return Object.freeze({
|
|
160
|
+
status: candidate.status,
|
|
161
|
+
...candidate.outputs === void 0 ? {} : {
|
|
162
|
+
outputs: Object.freeze(
|
|
163
|
+
candidate.outputs.map(
|
|
164
|
+
(output) => validateAgentProviderOutputForContext(output, context)
|
|
165
|
+
)
|
|
166
|
+
)
|
|
167
|
+
},
|
|
168
|
+
...candidate.error === void 0 ? {} : { error: parseAgentError(candidate.error) }
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
validateAgentProviderOperationResult,
|
|
173
|
+
validateAgentProviderOutputForContext
|
|
174
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type AgentError, type AgentEvent, type AgentIsoDateTime } from "@agen-ai/agent-protocol";
|
|
2
|
+
import { type AgentArtifactCandidate, type CreateAgentArtifactCandidateInput } from "./artifacts.js";
|
|
3
|
+
import { type AgentProviderEvidence, type AgentProviderRequestContext, type CreateAgentProviderEvidenceInput } from "./evidence.js";
|
|
4
|
+
export declare const AGENT_PROCESS_LIFECYCLE_TYPES: readonly ["process.started", "process.ready", "process.exited", "process.timeout", "process.interrupted", "process.error"];
|
|
5
|
+
export type AgentProcessLifecycleType = (typeof AGENT_PROCESS_LIFECYCLE_TYPES)[number];
|
|
6
|
+
export interface AgentProcessLifecycle {
|
|
7
|
+
readonly type: AgentProcessLifecycleType;
|
|
8
|
+
readonly occurredAt: AgentIsoDateTime;
|
|
9
|
+
readonly message?: string;
|
|
10
|
+
readonly exitCode?: number;
|
|
11
|
+
readonly error?: AgentError;
|
|
12
|
+
}
|
|
13
|
+
export declare const AGENT_AUTHENTICATION_STATUSES: readonly ["awaiting_user", "completed", "failed", "canceled", "expired"];
|
|
14
|
+
export type AgentAuthenticationStatus = (typeof AGENT_AUTHENTICATION_STATUSES)[number];
|
|
15
|
+
export interface AgentAuthenticationProgress {
|
|
16
|
+
readonly attemptId: string;
|
|
17
|
+
readonly status: AgentAuthenticationStatus;
|
|
18
|
+
readonly occurredAt: AgentIsoDateTime;
|
|
19
|
+
readonly providerLoginId?: string;
|
|
20
|
+
readonly verificationUrl?: string;
|
|
21
|
+
readonly userCode?: string;
|
|
22
|
+
readonly expiresAt?: AgentIsoDateTime;
|
|
23
|
+
readonly accountLabel?: string;
|
|
24
|
+
readonly error?: AgentError;
|
|
25
|
+
}
|
|
26
|
+
export interface AgentProviderEventOutput {
|
|
27
|
+
readonly kind: "event";
|
|
28
|
+
readonly event: AgentEvent;
|
|
29
|
+
readonly evidence?: AgentProviderObservationEvidence;
|
|
30
|
+
readonly requestContext?: AgentProviderRequestContext;
|
|
31
|
+
}
|
|
32
|
+
export interface AgentProviderLifecycleOutput {
|
|
33
|
+
readonly kind: "lifecycle";
|
|
34
|
+
readonly lifecycle: AgentProcessLifecycle;
|
|
35
|
+
}
|
|
36
|
+
export interface AgentProviderAuthenticationOutput {
|
|
37
|
+
readonly kind: "authentication";
|
|
38
|
+
readonly progress: AgentAuthenticationProgress;
|
|
39
|
+
}
|
|
40
|
+
export interface AgentProviderArtifactOutput {
|
|
41
|
+
readonly kind: "artifact";
|
|
42
|
+
readonly candidate: AgentArtifactCandidate;
|
|
43
|
+
}
|
|
44
|
+
export interface AgentProviderEvidenceOutput {
|
|
45
|
+
readonly kind: "evidence";
|
|
46
|
+
readonly evidence: AgentProviderDiagnosticEvidence;
|
|
47
|
+
}
|
|
48
|
+
export type AgentProviderObservationEvidence = AgentProviderEvidence & Readonly<{
|
|
49
|
+
category: "provider_event" | "provider_request";
|
|
50
|
+
}>;
|
|
51
|
+
export type AgentProviderDiagnosticEvidence = AgentProviderEvidence & Readonly<{
|
|
52
|
+
category: "diagnostic";
|
|
53
|
+
}>;
|
|
54
|
+
export type AgentProviderOutput = AgentProviderEventOutput | AgentProviderLifecycleOutput | AgentProviderAuthenticationOutput | AgentProviderArtifactOutput | AgentProviderEvidenceOutput;
|
|
55
|
+
export interface CreateAgentEventOutputOptions {
|
|
56
|
+
readonly evidence?: AgentProviderObservationEvidence;
|
|
57
|
+
readonly requestContext?: AgentProviderRequestContext;
|
|
58
|
+
}
|
|
59
|
+
export declare function createAgentEventOutput(input: unknown, options?: CreateAgentEventOutputOptions): AgentProviderEventOutput;
|
|
60
|
+
export declare function createAgentLifecycleOutput(input: {
|
|
61
|
+
readonly type: AgentProcessLifecycleType;
|
|
62
|
+
readonly occurredAt: string;
|
|
63
|
+
readonly message?: string;
|
|
64
|
+
readonly exitCode?: number;
|
|
65
|
+
readonly error?: AgentError;
|
|
66
|
+
}): AgentProviderLifecycleOutput;
|
|
67
|
+
export declare function createAgentAuthenticationOutput(input: {
|
|
68
|
+
readonly attemptId: string;
|
|
69
|
+
readonly status: AgentAuthenticationStatus;
|
|
70
|
+
readonly occurredAt: string;
|
|
71
|
+
readonly providerLoginId?: string;
|
|
72
|
+
readonly verificationUrl?: string;
|
|
73
|
+
readonly userCode?: string;
|
|
74
|
+
readonly expiresAt?: string;
|
|
75
|
+
readonly accountLabel?: string;
|
|
76
|
+
readonly error?: AgentError;
|
|
77
|
+
}): AgentProviderAuthenticationOutput;
|
|
78
|
+
export declare function createAgentArtifactOutput(input: CreateAgentArtifactCandidateInput): AgentProviderArtifactOutput;
|
|
79
|
+
export declare function createAgentEvidenceOutput(input: CreateAgentProviderEvidenceInput<"diagnostic">): AgentProviderEvidenceOutput;
|
|
80
|
+
export declare function validateAgentProviderOutput(input: unknown): AgentProviderOutput;
|
|
81
|
+
//# sourceMappingURL=outputs.d.ts.map
|
package/dist/outputs.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseAgentError,
|
|
3
|
+
parseAgentEvent,
|
|
4
|
+
parseAgentIsoDateTime
|
|
5
|
+
} from "@agen-ai/agent-protocol";
|
|
6
|
+
import {
|
|
7
|
+
createAgentArtifactCandidate
|
|
8
|
+
} from "./artifacts.js";
|
|
9
|
+
import {
|
|
10
|
+
createAgentProviderEvidence,
|
|
11
|
+
validateAgentProviderRequestContext,
|
|
12
|
+
validateAgentProviderEvidence
|
|
13
|
+
} from "./evidence.js";
|
|
14
|
+
import {
|
|
15
|
+
parseAgentBoundedText,
|
|
16
|
+
parseAgentProviderTechnicalId
|
|
17
|
+
} from "./foundation.js";
|
|
18
|
+
import { containsAgentControlCharacter } from "./internal/controlCharacters.js";
|
|
19
|
+
const AGENT_PROCESS_LIFECYCLE_TYPES = [
|
|
20
|
+
"process.started",
|
|
21
|
+
"process.ready",
|
|
22
|
+
"process.exited",
|
|
23
|
+
"process.timeout",
|
|
24
|
+
"process.interrupted",
|
|
25
|
+
"process.error"
|
|
26
|
+
];
|
|
27
|
+
const AGENT_AUTHENTICATION_STATUSES = [
|
|
28
|
+
"awaiting_user",
|
|
29
|
+
"completed",
|
|
30
|
+
"failed",
|
|
31
|
+
"canceled",
|
|
32
|
+
"expired"
|
|
33
|
+
];
|
|
34
|
+
const AGENT_AUTHENTICATION_VERIFICATION_URL_MAX_LENGTH = 2048;
|
|
35
|
+
const AGENT_AUTHENTICATION_USER_CODE_MAX_LENGTH = 80;
|
|
36
|
+
const AGENT_AUTHENTICATION_ACCOUNT_LABEL_MAX_LENGTH = 4e3;
|
|
37
|
+
const AGENT_AUTHENTICATION_VERIFICATION_URL_PATTERN = /^[Hh][Tt][Tt][Pp][Ss]:\/\/(?![^/?#]*@)/u;
|
|
38
|
+
function authenticationVerificationUrl(value) {
|
|
39
|
+
if (value.length > AGENT_AUTHENTICATION_VERIFICATION_URL_MAX_LENGTH || !AGENT_AUTHENTICATION_VERIFICATION_URL_PATTERN.test(value)) {
|
|
40
|
+
throw new TypeError(
|
|
41
|
+
"Authentication verificationUrl must use HTTPS without user information and contain at most 2,048 characters."
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
new URL(value);
|
|
46
|
+
} catch {
|
|
47
|
+
throw new TypeError("Authentication verificationUrl must be a valid URL.");
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
function authenticationText(value, field, maxLength) {
|
|
52
|
+
const text = parseAgentBoundedText(value, field, maxLength);
|
|
53
|
+
if (text !== text.trim() || containsAgentControlCharacter(text)) {
|
|
54
|
+
throw new TypeError(
|
|
55
|
+
`${field} must be canonical text without surrounding whitespace or control characters.`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return text;
|
|
59
|
+
}
|
|
60
|
+
function boundedText(value, field) {
|
|
61
|
+
if (value === void 0) return void 0;
|
|
62
|
+
return parseAgentBoundedText(value, field, 4e3);
|
|
63
|
+
}
|
|
64
|
+
function validatedObservationEvidence(input) {
|
|
65
|
+
const evidence = validateAgentProviderEvidence(input);
|
|
66
|
+
if (evidence.category === "diagnostic") {
|
|
67
|
+
throw new TypeError(
|
|
68
|
+
"Agent event evidence must describe a provider event or request."
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return evidence;
|
|
72
|
+
}
|
|
73
|
+
function validatedDiagnosticEvidence(input) {
|
|
74
|
+
const evidence = validateAgentProviderEvidence(input);
|
|
75
|
+
if (evidence.category !== "diagnostic") {
|
|
76
|
+
throw new TypeError(
|
|
77
|
+
"Standalone agent evidence must be diagnostic."
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return evidence;
|
|
81
|
+
}
|
|
82
|
+
function createAgentEventOutput(input, options = {}) {
|
|
83
|
+
const event = parseAgentEvent(input);
|
|
84
|
+
if (options.requestContext !== void 0 && event.type !== "request.opened") {
|
|
85
|
+
throw new TypeError(
|
|
86
|
+
"Provider request context may be attached only to request.opened events."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (options.evidence !== void 0 && options.evidence.category === "provider_request" !== (event.type === "request.opened")) {
|
|
90
|
+
throw new TypeError(
|
|
91
|
+
"Provider request evidence must be attached exactly to request.opened events."
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return Object.freeze({
|
|
95
|
+
kind: "event",
|
|
96
|
+
event,
|
|
97
|
+
...options.evidence === void 0 ? {} : { evidence: validatedObservationEvidence(options.evidence) },
|
|
98
|
+
...options.requestContext === void 0 ? {} : {
|
|
99
|
+
requestContext: validateAgentProviderRequestContext(
|
|
100
|
+
options.requestContext
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function createAgentLifecycleOutput(input) {
|
|
106
|
+
if (!AGENT_PROCESS_LIFECYCLE_TYPES.includes(input.type)) {
|
|
107
|
+
throw new TypeError("Agent process lifecycle type is unsupported.");
|
|
108
|
+
}
|
|
109
|
+
if (input.exitCode !== void 0 && (!Number.isSafeInteger(input.exitCode) || input.exitCode < -1)) {
|
|
110
|
+
throw new TypeError(
|
|
111
|
+
"Agent process exitCode must be a safe integer of at least -1."
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
return Object.freeze({
|
|
115
|
+
kind: "lifecycle",
|
|
116
|
+
lifecycle: Object.freeze({
|
|
117
|
+
type: input.type,
|
|
118
|
+
occurredAt: parseAgentIsoDateTime(input.occurredAt),
|
|
119
|
+
...input.message === void 0 ? {} : { message: boundedText(input.message, "lifecycle message") },
|
|
120
|
+
...input.exitCode === void 0 ? {} : { exitCode: input.exitCode },
|
|
121
|
+
...input.error === void 0 ? {} : { error: parseAgentError(input.error) }
|
|
122
|
+
})
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function createAgentAuthenticationOutput(input) {
|
|
126
|
+
if (!AGENT_AUTHENTICATION_STATUSES.includes(input.status)) {
|
|
127
|
+
throw new TypeError("Agent authentication status is unsupported.");
|
|
128
|
+
}
|
|
129
|
+
if (input.status === "failed" !== (input.error !== void 0)) {
|
|
130
|
+
throw new TypeError(
|
|
131
|
+
"Only failed agent authentication progress must include an error."
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return Object.freeze({
|
|
135
|
+
kind: "authentication",
|
|
136
|
+
progress: Object.freeze({
|
|
137
|
+
attemptId: parseAgentProviderTechnicalId(input.attemptId, "attemptId"),
|
|
138
|
+
status: input.status,
|
|
139
|
+
occurredAt: parseAgentIsoDateTime(input.occurredAt),
|
|
140
|
+
...input.providerLoginId === void 0 ? {} : {
|
|
141
|
+
providerLoginId: parseAgentProviderTechnicalId(
|
|
142
|
+
input.providerLoginId,
|
|
143
|
+
"providerLoginId"
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
...input.verificationUrl === void 0 ? {} : {
|
|
147
|
+
verificationUrl: authenticationVerificationUrl(
|
|
148
|
+
input.verificationUrl
|
|
149
|
+
)
|
|
150
|
+
},
|
|
151
|
+
...input.userCode === void 0 ? {} : {
|
|
152
|
+
userCode: authenticationText(
|
|
153
|
+
input.userCode,
|
|
154
|
+
"userCode",
|
|
155
|
+
AGENT_AUTHENTICATION_USER_CODE_MAX_LENGTH
|
|
156
|
+
)
|
|
157
|
+
},
|
|
158
|
+
...input.expiresAt === void 0 ? {} : { expiresAt: parseAgentIsoDateTime(input.expiresAt) },
|
|
159
|
+
...input.accountLabel === void 0 ? {} : {
|
|
160
|
+
accountLabel: authenticationText(
|
|
161
|
+
input.accountLabel,
|
|
162
|
+
"accountLabel",
|
|
163
|
+
AGENT_AUTHENTICATION_ACCOUNT_LABEL_MAX_LENGTH
|
|
164
|
+
)
|
|
165
|
+
},
|
|
166
|
+
...input.error === void 0 ? {} : { error: parseAgentError(input.error) }
|
|
167
|
+
})
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function createAgentArtifactOutput(input) {
|
|
171
|
+
return Object.freeze({
|
|
172
|
+
kind: "artifact",
|
|
173
|
+
candidate: createAgentArtifactCandidate(input)
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function createAgentEvidenceOutput(input) {
|
|
177
|
+
return Object.freeze({
|
|
178
|
+
kind: "evidence",
|
|
179
|
+
evidence: validatedDiagnosticEvidence(createAgentProviderEvidence(input))
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
function validateAgentProviderOutput(input) {
|
|
183
|
+
if (input === null || typeof input !== "object" || !("kind" in input)) {
|
|
184
|
+
throw new TypeError("Agent provider output is invalid.");
|
|
185
|
+
}
|
|
186
|
+
const candidate = input;
|
|
187
|
+
switch (candidate.kind) {
|
|
188
|
+
case "event":
|
|
189
|
+
return createAgentEventOutput(candidate.event, {
|
|
190
|
+
...candidate.evidence === void 0 ? {} : { evidence: candidate.evidence },
|
|
191
|
+
...candidate.requestContext === void 0 ? {} : { requestContext: candidate.requestContext }
|
|
192
|
+
});
|
|
193
|
+
case "lifecycle":
|
|
194
|
+
return createAgentLifecycleOutput(candidate.lifecycle);
|
|
195
|
+
case "authentication":
|
|
196
|
+
return createAgentAuthenticationOutput(candidate.progress);
|
|
197
|
+
case "artifact":
|
|
198
|
+
return createAgentArtifactOutput(candidate.candidate);
|
|
199
|
+
case "evidence":
|
|
200
|
+
return Object.freeze({
|
|
201
|
+
kind: "evidence",
|
|
202
|
+
evidence: validatedDiagnosticEvidence(candidate.evidence)
|
|
203
|
+
});
|
|
204
|
+
default:
|
|
205
|
+
throw new TypeError("Agent provider output kind is unsupported.");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
export {
|
|
209
|
+
AGENT_AUTHENTICATION_STATUSES,
|
|
210
|
+
AGENT_PROCESS_LIFECYCLE_TYPES,
|
|
211
|
+
createAgentArtifactOutput,
|
|
212
|
+
createAgentAuthenticationOutput,
|
|
213
|
+
createAgentEventOutput,
|
|
214
|
+
createAgentEvidenceOutput,
|
|
215
|
+
createAgentLifecycleOutput,
|
|
216
|
+
validateAgentProviderOutput
|
|
217
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type AgentCapabilities, type AgentInstanceId, type AgentProviderKey } from "@agen-ai/agent-protocol";
|
|
2
|
+
import type { AgentProviderDriver, MaterializedAgentProviderInstance } from "./providerDriver.js";
|
|
3
|
+
export interface AgentProviderCatalogEntry {
|
|
4
|
+
readonly providerKey: AgentProviderKey;
|
|
5
|
+
readonly supportsMultipleInstances: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface AgentProviderInstanceCatalogEntry {
|
|
8
|
+
readonly instanceId: AgentInstanceId;
|
|
9
|
+
readonly capabilities: AgentCapabilities;
|
|
10
|
+
}
|
|
11
|
+
export declare function createAgentProviderCatalogEntries(drivers: Iterable<AgentProviderDriver>): readonly AgentProviderCatalogEntry[];
|
|
12
|
+
export declare function createAgentProviderInstanceCatalogEntries(instances: readonly MaterializedAgentProviderInstance[]): readonly AgentProviderInstanceCatalogEntry[];
|
|
13
|
+
//# sourceMappingURL=providerCatalog.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseAgentCapabilities
|
|
3
|
+
} from "@agen-ai/agent-protocol";
|
|
4
|
+
function compareStrings(left, right) {
|
|
5
|
+
if (left === right) return 0;
|
|
6
|
+
return left < right ? -1 : 1;
|
|
7
|
+
}
|
|
8
|
+
function createAgentProviderCatalogEntries(drivers) {
|
|
9
|
+
return Object.freeze(
|
|
10
|
+
[...drivers].map(
|
|
11
|
+
(driver) => Object.freeze({
|
|
12
|
+
providerKey: driver.providerKey,
|
|
13
|
+
supportsMultipleInstances: driver.supportsMultipleInstances
|
|
14
|
+
})
|
|
15
|
+
).sort(
|
|
16
|
+
(left, right) => compareStrings(left.providerKey, right.providerKey)
|
|
17
|
+
)
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function createAgentProviderInstanceCatalogEntries(instances) {
|
|
21
|
+
return Object.freeze(
|
|
22
|
+
instances.map(
|
|
23
|
+
(instance) => Object.freeze({
|
|
24
|
+
instanceId: instance.instanceId,
|
|
25
|
+
capabilities: parseAgentCapabilities(instance.capabilities)
|
|
26
|
+
})
|
|
27
|
+
).sort((left, right) => compareStrings(left.instanceId, right.instanceId))
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
createAgentProviderCatalogEntries,
|
|
32
|
+
createAgentProviderInstanceCatalogEntries
|
|
33
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type AgentCapabilities, type AgentInstanceId, type AgentProviderKey } from "@agen-ai/agent-protocol";
|
|
2
|
+
import type { MaybePromise } from "./foundation.js";
|
|
3
|
+
import type { AgentProviderReadiness } from "./readiness.js";
|
|
4
|
+
import type { AgentProviderAdapter } from "./sessions.js";
|
|
5
|
+
export interface AgentProviderInstanceDefinition {
|
|
6
|
+
readonly providerKey: AgentProviderKey;
|
|
7
|
+
readonly instanceId: AgentInstanceId;
|
|
8
|
+
readonly driverConfiguration: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentProviderReadinessCheckInput {
|
|
11
|
+
readonly signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
export interface MaterializedAgentProviderInstance {
|
|
14
|
+
readonly instanceId: AgentInstanceId;
|
|
15
|
+
readonly capabilities: AgentCapabilities;
|
|
16
|
+
readonly adapter: AgentProviderAdapter;
|
|
17
|
+
readonly checkReadiness: (input?: AgentProviderReadinessCheckInput) => MaybePromise<AgentProviderReadiness>;
|
|
18
|
+
readonly dispose: () => MaybePromise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface AgentProviderDriverCreateInput<Configuration> {
|
|
21
|
+
readonly instanceId: AgentInstanceId;
|
|
22
|
+
readonly configuration: Configuration;
|
|
23
|
+
}
|
|
24
|
+
export interface AgentProviderDriverDefinition<Configuration> {
|
|
25
|
+
readonly providerKey: AgentProviderKey;
|
|
26
|
+
readonly supportsMultipleInstances: boolean;
|
|
27
|
+
readonly parseConfiguration: (input: unknown) => Configuration;
|
|
28
|
+
readonly validateConfiguration?: (input: AgentProviderDriverCreateInput<Configuration>) => void;
|
|
29
|
+
readonly createInstance: (input: AgentProviderDriverCreateInput<Configuration>) => MaybePromise<MaterializedAgentProviderInstance>;
|
|
30
|
+
}
|
|
31
|
+
export interface AgentProviderDriver {
|
|
32
|
+
readonly providerKey: AgentProviderKey;
|
|
33
|
+
readonly supportsMultipleInstances: boolean;
|
|
34
|
+
readonly materialize: (definition: AgentProviderInstanceDefinition) => MaybePromise<MaterializedAgentProviderInstance>;
|
|
35
|
+
}
|
|
36
|
+
export declare class AgentProviderConfigurationError extends Error {
|
|
37
|
+
readonly providerKey: AgentProviderKey;
|
|
38
|
+
constructor(providerKey: AgentProviderKey, options?: ErrorOptions);
|
|
39
|
+
}
|
|
40
|
+
export declare function defineAgentProviderDriver<Configuration>(definition: AgentProviderDriverDefinition<Configuration>): AgentProviderDriver;
|
|
41
|
+
//# sourceMappingURL=providerDriver.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseAgentInstanceId,
|
|
3
|
+
parseAgentProviderKey
|
|
4
|
+
} from "@agen-ai/agent-protocol";
|
|
5
|
+
class AgentProviderConfigurationError extends Error {
|
|
6
|
+
constructor(providerKey, options) {
|
|
7
|
+
super(
|
|
8
|
+
`Agent provider configuration is invalid for ${providerKey}.`,
|
|
9
|
+
options
|
|
10
|
+
);
|
|
11
|
+
this.providerKey = providerKey;
|
|
12
|
+
this.name = "AgentProviderConfigurationError";
|
|
13
|
+
}
|
|
14
|
+
providerKey;
|
|
15
|
+
}
|
|
16
|
+
function defineAgentProviderDriver(definition) {
|
|
17
|
+
const providerKey = parseAgentProviderKey(definition.providerKey);
|
|
18
|
+
return Object.freeze({
|
|
19
|
+
providerKey,
|
|
20
|
+
supportsMultipleInstances: definition.supportsMultipleInstances,
|
|
21
|
+
materialize(instanceDefinition) {
|
|
22
|
+
let requestedProviderKey;
|
|
23
|
+
try {
|
|
24
|
+
requestedProviderKey = parseAgentProviderKey(
|
|
25
|
+
instanceDefinition.providerKey
|
|
26
|
+
);
|
|
27
|
+
} catch (cause) {
|
|
28
|
+
throw new AgentProviderConfigurationError(providerKey, { cause });
|
|
29
|
+
}
|
|
30
|
+
if (requestedProviderKey !== providerKey) {
|
|
31
|
+
throw new AgentProviderConfigurationError(providerKey);
|
|
32
|
+
}
|
|
33
|
+
let createInput;
|
|
34
|
+
try {
|
|
35
|
+
createInput = {
|
|
36
|
+
instanceId: parseAgentInstanceId(instanceDefinition.instanceId),
|
|
37
|
+
configuration: definition.parseConfiguration(
|
|
38
|
+
instanceDefinition.driverConfiguration
|
|
39
|
+
)
|
|
40
|
+
};
|
|
41
|
+
definition.validateConfiguration?.(createInput);
|
|
42
|
+
} catch (cause) {
|
|
43
|
+
throw new AgentProviderConfigurationError(providerKey, { cause });
|
|
44
|
+
}
|
|
45
|
+
return definition.createInstance(createInput);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
AgentProviderConfigurationError,
|
|
51
|
+
defineAgentProviderDriver
|
|
52
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type AgentInstanceId, type AgentProviderKey } from "@agen-ai/agent-protocol";
|
|
2
|
+
import { type AgentProviderCatalogEntry, type AgentProviderInstanceCatalogEntry } from "./providerCatalog.js";
|
|
3
|
+
import { type AgentProviderDriver, type AgentProviderInstanceDefinition, type MaterializedAgentProviderInstance } from "./providerDriver.js";
|
|
4
|
+
import { type AgentProviderReadiness } from "./readiness.js";
|
|
5
|
+
export declare const AGENT_PROVIDER_REGISTRY_ERROR_CODES: readonly ["invalid_driver", "duplicate_provider", "duplicate_instance", "provider_not_registered", "multiple_instances_unsupported", "invalid_instance_configuration", "instance_materialization_failed", "instance_contract_mismatch", "instance_not_found", "instance_disposed", "instance_cleanup_failed", "registry_disposed"];
|
|
6
|
+
export type AgentProviderRegistryErrorCode = (typeof AGENT_PROVIDER_REGISTRY_ERROR_CODES)[number];
|
|
7
|
+
interface AgentProviderRegistryErrorInput {
|
|
8
|
+
readonly code: AgentProviderRegistryErrorCode;
|
|
9
|
+
readonly message: string;
|
|
10
|
+
readonly providerKey?: AgentProviderKey;
|
|
11
|
+
readonly instanceId?: AgentInstanceId;
|
|
12
|
+
readonly cleanupFailureInstanceIds?: readonly AgentInstanceId[];
|
|
13
|
+
readonly cause?: unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare class AgentProviderRegistryError extends Error {
|
|
16
|
+
readonly code: AgentProviderRegistryErrorCode;
|
|
17
|
+
readonly providerKey?: AgentProviderKey;
|
|
18
|
+
readonly instanceId?: AgentInstanceId;
|
|
19
|
+
readonly cleanupFailureInstanceIds: readonly AgentInstanceId[];
|
|
20
|
+
constructor(input: AgentProviderRegistryErrorInput);
|
|
21
|
+
}
|
|
22
|
+
export interface AgentProviderRegistry {
|
|
23
|
+
readonly listProviderCatalogEntries: () => readonly AgentProviderCatalogEntry[];
|
|
24
|
+
readonly listInstanceCatalogEntries: () => readonly AgentProviderInstanceCatalogEntry[];
|
|
25
|
+
readonly listInstances: () => readonly MaterializedAgentProviderInstance[];
|
|
26
|
+
readonly getInstance: (instanceId: AgentInstanceId) => MaterializedAgentProviderInstance | null;
|
|
27
|
+
readonly hasInstance: (instanceId: AgentInstanceId) => boolean;
|
|
28
|
+
readonly requireInstance: (instanceId: AgentInstanceId) => MaterializedAgentProviderInstance;
|
|
29
|
+
readonly checkReadiness: (instanceId: AgentInstanceId, input?: Readonly<{
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}>) => Promise<AgentProviderReadiness>;
|
|
32
|
+
readonly dispose: () => Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
export interface CreateAgentProviderRegistryInput {
|
|
35
|
+
readonly drivers: readonly AgentProviderDriver[];
|
|
36
|
+
readonly definitions: readonly AgentProviderInstanceDefinition[];
|
|
37
|
+
}
|
|
38
|
+
export declare function createAgentProviderRegistry(input: CreateAgentProviderRegistryInput): Promise<AgentProviderRegistry>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=providerInstanceRegistry.d.ts.map
|