@agen-ai/agent-runtime 0.4.1 → 0.4.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.
Files changed (37) hide show
  1. package/README.md +154 -71
  2. package/dist/adapterValidation.d.ts +4 -2
  3. package/dist/adapterValidation.js +108 -59
  4. package/dist/contractErrors.d.ts +1 -1
  5. package/dist/contractErrors.js +7 -1
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/nativeContinuations/admission.d.ts +17 -0
  9. package/dist/nativeContinuations/admission.js +250 -0
  10. package/dist/nativeContinuations/index.d.ts +2 -0
  11. package/dist/nativeContinuations/index.js +1 -0
  12. package/dist/nativeContinuations/types.d.ts +52 -0
  13. package/dist/nativeContinuations/types.js +0 -0
  14. package/dist/outputValidation.js +1 -0
  15. package/dist/providerCatalog.d.ts +1 -1
  16. package/dist/providerDriver.d.ts +4 -1
  17. package/dist/providerInstanceRegistry.d.ts +4 -4
  18. package/dist/sessionAdmission.d.ts +12 -0
  19. package/dist/sessionAdmission.js +54 -0
  20. package/dist/sessionInteractions/lifetime.d.ts +32 -3
  21. package/dist/sessionInteractions/lifetime.js +145 -13
  22. package/dist/sessionInteractions/request.d.ts +3 -2
  23. package/dist/sessionInteractions/request.js +98 -25
  24. package/dist/sessionInteractions/types.d.ts +68 -12
  25. package/dist/sessionInteractions/validation.d.ts +13 -9
  26. package/dist/sessionInteractions/validation.js +121 -60
  27. package/dist/sessionValidation.d.ts +78 -2
  28. package/dist/sessionValidation.js +213 -162
  29. package/dist/sessions.d.ts +33 -2
  30. package/dist/testing/conformance.d.ts +3 -1
  31. package/dist/testing/conformance.js +180 -85
  32. package/dist/testing/fakeProvider.js +2 -2
  33. package/dist/turnExecution/execution.d.ts +23 -6
  34. package/dist/turnExecution/execution.js +136 -32
  35. package/dist/turnExecution/requests.d.ts +15 -3
  36. package/dist/turnExecution/requests.js +93 -28
  37. package/package.json +2 -2
@@ -1,21 +1,25 @@
1
1
  import { type AgentCapabilities, type AgentProviderKey, type AgentSessionId } from "@agen-ai/agent-protocol";
2
2
  import { AgentProviderContractError } from "../contractErrors.js";
3
3
  import type { AgentProviderAdapter } from "../sessions.js";
4
- import { type AgentSessionInteraction, type AgentSessionInteractionContext, type AgentSessionInteractionLimits, type AgentSessionInteractionSupport, type AgentSessionInteractionTerminal } from "./types.js";
4
+ import type { AgentNativeContinuationSupport, AgentNativeContinuationContext } from "../nativeContinuations/types.js";
5
+ import { type AgentSessionInteractionContext, type AgentSessionInteractionLimits, type AgentSessionInteractionSupport, type AgentSessionInteractionTerminal, type AgentSessionHumanWaitKind, type AgentProviderSessionInteraction, type AgentSessionInteractionDeadline } from "./types.js";
6
+ export declare function interactionRecord(input: unknown): Record<string, unknown>;
5
7
  export declare function interactionContractError(providerKey: AgentProviderKey, message: string): AgentProviderContractError;
6
8
  export declare function validateSessionInteractionSupport(capabilities: AgentCapabilities, adapter: AgentProviderAdapter): AgentSessionInteractionSupport;
9
+ export declare function validateNativeContinuationSupport(capabilities: AgentCapabilities, adapter: AgentProviderAdapter, interactions: AgentSessionInteractionSupport): AgentNativeContinuationSupport;
7
10
  export interface ValidatedSessionInteractionContext {
8
11
  readonly onRequest: AgentSessionInteractionContext["onRequest"];
12
+ readonly humanWait: AgentSessionHumanWaitKind;
9
13
  readonly limits: Readonly<AgentSessionInteractionLimits>;
10
14
  }
11
15
  export declare function validateSessionInteractionContext(input: AgentSessionInteractionContext): ValidatedSessionInteractionContext;
12
- export interface CapturedSessionInteractionCandidate {
13
- readonly request: unknown;
14
- readonly signal: AbortSignal;
15
- readonly terminal: Promise<unknown>;
16
- readonly respond: AgentSessionInteraction["respond"];
17
- }
18
- export declare function captureSessionInteractionCandidate(input: AgentSessionInteraction, observe: (terminal: Promise<unknown>) => void): CapturedSessionInteractionCandidate;
19
- export declare function validateSessionInteractionCandidate(input: CapturedSessionInteractionCandidate, sessionId: AgentSessionId, requestTimeoutMs: number): CapturedSessionInteractionCandidate & Pick<AgentSessionInteraction, "request">;
16
+ export declare function validateNativeContinuationContext(input: AgentNativeContinuationContext | undefined): AgentNativeContinuationContext | undefined;
17
+ export type CapturedSessionInteractionCandidate = AgentProviderSessionInteraction;
18
+ export declare function captureSessionInteractionCandidate(input: AgentProviderSessionInteraction, observe: (terminal: Promise<unknown>) => void): CapturedSessionInteractionCandidate;
19
+ export type ValidatedSessionInteractionCandidate = CapturedSessionInteractionCandidate & Readonly<{
20
+ deadline: AgentSessionInteractionDeadline;
21
+ deadlineAt?: number;
22
+ }>;
23
+ export declare function validateSessionInteractionCandidate(input: CapturedSessionInteractionCandidate, sessionId: AgentSessionId, context: ValidatedSessionInteractionContext): ValidatedSessionInteractionCandidate;
20
24
  export declare function validateSessionInteractionTerminal(input: unknown): AgentSessionInteractionTerminal;
21
25
  //# sourceMappingURL=validation.d.ts.map
@@ -1,50 +1,98 @@
1
1
  import path from "node:path";
2
2
  import {
3
3
  parseAgentError,
4
- parseAgentSessionDecisionChoiceId,
5
- parseAgentSessionDecisionRequest
4
+ parseAgentIsoDateTime,
5
+ parseAgentSessionRequest,
6
+ parseAgentSessionResponse,
7
+ parseAgentSessionFormChoiceId,
8
+ parseAgentSessionPlanReviewChoiceId,
9
+ parseAgentSessionPlanId,
10
+ parseAgentSessionPlanRevision
6
11
  } from "@agen-ai/agent-protocol";
7
12
  import { AgentProviderContractError } from "../contractErrors.js";
8
13
  import { hasExactOwnKeys } from "../internal/objectShape.js";
9
14
  import {
10
15
  DEFAULT_AGENT_SESSION_INTERACTION_LIMITS
11
16
  } from "./types.js";
12
- function record(input) {
17
+ function interactionRecord(input) {
13
18
  if (input === null || typeof input !== "object" || Array.isArray(input)) throw new TypeError("Expected an interaction object.");
14
19
  return input;
15
20
  }
16
21
  function interactionContractError(providerKey, message) {
17
22
  return new AgentProviderContractError(providerKey, "invalid_session_interaction", message);
18
23
  }
24
+ const operations = ["create", "resume", "branch"];
25
+ const kinds = ["decision", "form", "plan_review"];
26
+ const timings = ["after_open_return", "before_open_return", "before_binding"];
27
+ const waits = ["bounded", "until_withdrawn_or_closed"];
28
+ function ordered(input, values) {
29
+ if (!Array.isArray(input) || input.length === 0 || input.length > values.length) throw new TypeError("Expected a bounded nonempty support list.");
30
+ let last = -1;
31
+ const result = [];
32
+ for (const value of input) {
33
+ const index = values.indexOf(value);
34
+ if (index <= last) throw new TypeError("Support must be unique and canonical-sorted.");
35
+ last = index;
36
+ result.push(values[index]);
37
+ }
38
+ const [first, ...rest] = result;
39
+ if (first === void 0) throw new TypeError();
40
+ return Object.freeze([first, ...rest]);
41
+ }
42
+ function mapping(input, capabilities, adapter) {
43
+ const value = interactionRecord(input);
44
+ const operation = operations.find((entry) => entry === value.openingOperation);
45
+ const requestKind = kinds.find((entry) => entry === value.requestKind);
46
+ if (!operation || !requestKind || operation === "resume" && (!capabilities.sessions.resume || adapter.resumption.kind !== "supported") || operation === "branch" && (capabilities.sessions.branch.kind !== "through_turn" || adapter.branching.kind !== "through_turn")) throw new TypeError();
47
+ return Object.freeze({ openingOperation: operation, requestKind });
48
+ }
19
49
  function validateSessionInteractionSupport(capabilities, adapter) {
20
- const input = adapter.sessionInteractions;
21
- if (input === void 0) return Object.freeze({ kind: "unsupported" });
50
+ if (adapter.sessionInteractions === void 0) return Object.freeze({ kind: "unsupported" });
22
51
  try {
23
- const value = record(input);
52
+ const value = interactionRecord(adapter.sessionInteractions);
24
53
  if (value.kind === "unsupported" && hasExactOwnKeys(value, ["kind"])) return Object.freeze({ kind: "unsupported" });
25
- if (!hasExactOwnKeys(value, ["kind", "openingOperations", "requestKinds", "producerOwnership"]) || value.kind !== "supported" || value.producerOwnership !== "exclusive" || !Array.isArray(value.openingOperations) || value.openingOperations.length === 0 || !Array.isArray(value.requestKinds) || value.requestKinds.length !== 1 || value.requestKinds[0] !== "decision") throw new TypeError();
26
- const operations = [];
27
- for (const operation of value.openingOperations) {
28
- if (operation !== "create" && operation !== "resume" && operation !== "branch") throw new TypeError();
29
- if (operations.includes(operation)) throw new TypeError();
30
- if (operation === "resume" && (!capabilities.sessions.resume || adapter.resumption.kind !== "supported")) throw new TypeError();
31
- if (operation === "branch" && (capabilities.sessions.branch.kind !== "through_turn" || adapter.branching.kind !== "through_turn")) throw new TypeError();
32
- operations.push(operation);
33
- }
34
- const order = ["create", "resume", "branch"];
35
- if (operations.some((operation, index) => index > 0 && order.indexOf(operation) < order.indexOf(operations[index - 1]))) throw new TypeError();
36
- const [first, ...rest] = operations;
37
- if (first === void 0) throw new TypeError();
38
- return Object.freeze({
39
- kind: "supported",
40
- producerOwnership: "exclusive",
41
- openingOperations: Object.freeze([first, ...rest]),
42
- requestKinds: Object.freeze(["decision"])
54
+ if (!hasExactOwnKeys(value, ["kind", "mappings", "producerOwnership", "humanWait"]) || value.kind !== "supported" || value.producerOwnership !== "exclusive" || !Array.isArray(value.mappings) || value.mappings.length < 1 || value.mappings.length > 9) throw new TypeError();
55
+ let previous = -1;
56
+ const parsed = value.mappings.map((entry) => {
57
+ if (!hasExactOwnKeys(interactionRecord(entry), ["openingOperation", "requestKind"])) throw new TypeError();
58
+ const parsed2 = mapping(entry, capabilities, adapter);
59
+ const index = operations.indexOf(parsed2.openingOperation) * 3 + kinds.indexOf(parsed2.requestKind);
60
+ if (index <= previous) throw new TypeError();
61
+ previous = index;
62
+ return parsed2;
43
63
  });
64
+ const [first, ...rest] = parsed;
65
+ if (!first) throw new TypeError();
66
+ return Object.freeze({ kind: "supported", producerOwnership: "exclusive", mappings: Object.freeze([first, ...rest]), humanWait: ordered(value.humanWait, waits) });
44
67
  } catch {
45
68
  throw interactionContractError(capabilities.providerKey, "Provider declared invalid session interaction support.");
46
69
  }
47
70
  }
71
+ function validateNativeContinuationSupport(capabilities, adapter, interactions) {
72
+ if (adapter.nativeContinuations === void 0) return Object.freeze({ kind: "unsupported" });
73
+ try {
74
+ const value = interactionRecord(adapter.nativeContinuations);
75
+ if (value.kind === "unsupported" && hasExactOwnKeys(value, ["kind"])) return Object.freeze({ kind: "unsupported" });
76
+ if (!hasExactOwnKeys(value, ["kind", "mappings", "producerOwnership"]) || value.kind !== "supported" || value.producerOwnership !== "exclusive" || !Array.isArray(value.mappings) || value.mappings.length < 1 || value.mappings.length > 18 || interactions.kind !== "supported") throw new TypeError();
77
+ let previous = -1;
78
+ const parsed = value.mappings.map((entry) => {
79
+ const record = interactionRecord(entry);
80
+ if (!hasExactOwnKeys(record, ["openingOperation", "requestKind", "timing"])) throw new TypeError();
81
+ const parsed2 = mapping(record, capabilities, adapter);
82
+ const timing = timings.find((entry2) => entry2 === record.timing);
83
+ if (parsed2.requestKind === "decision" || !timing || !interactions.mappings.some((entry2) => entry2.openingOperation === parsed2.openingOperation && entry2.requestKind === parsed2.requestKind)) throw new TypeError();
84
+ const index = operations.indexOf(parsed2.openingOperation) * 6 + (parsed2.requestKind === "form" ? 0 : 3) + timings.indexOf(timing);
85
+ if (index <= previous) throw new TypeError();
86
+ previous = index;
87
+ return Object.freeze({ openingOperation: parsed2.openingOperation, requestKind: parsed2.requestKind, timing });
88
+ });
89
+ const [first, ...rest] = parsed;
90
+ if (!first) throw new TypeError();
91
+ return Object.freeze({ kind: "supported", producerOwnership: "exclusive", mappings: Object.freeze([first, ...rest]) });
92
+ } catch {
93
+ throw new AgentProviderContractError(capabilities.providerKey, "capability_port_mismatch", "Provider declared invalid native continuation support.");
94
+ }
95
+ }
48
96
  const limitRanges = {
49
97
  maxRetainedRequests: [1, 32],
50
98
  maxRetainedBytes: [65536, 2097152],
@@ -53,65 +101,78 @@ const limitRanges = {
53
101
  cleanupTimeoutMs: [1e3, 12e4]
54
102
  };
55
103
  function validateSessionInteractionContext(input) {
56
- const value = record(input);
57
- const onRequest = value.onRequest;
58
- if (!hasExactOwnKeys(value, Object.hasOwn(value, "limits") ? ["onRequest", "limits"] : ["onRequest"]) || typeof onRequest !== "function") throw new TypeError("Session interactions require a callable handler and known fields.");
59
- const supplied = value.limits === void 0 ? {} : record(value.limits);
60
- if (Reflect.ownKeys(supplied).some((key) => typeof key !== "string" || !Object.hasOwn(limitRanges, key))) {
61
- throw new TypeError("Session interaction limits contain an unknown field.");
62
- }
104
+ const value = interactionRecord(input);
105
+ if (Reflect.ownKeys(value).some((key) => !["onRequest", "limits", "humanWait"].includes(String(key))) || typeof value.onRequest !== "function") throw new TypeError("Session interactions require a callable handler and known fields.");
106
+ const human = value.humanWait === void 0 ? { kind: "bounded" } : interactionRecord(value.humanWait);
107
+ if (!hasExactOwnKeys(human, ["kind"]) || human.kind !== "bounded" && human.kind !== "until_withdrawn_or_closed") throw new TypeError("Invalid human wait policy.");
108
+ const supplied = value.limits === void 0 ? {} : interactionRecord(value.limits);
109
+ if (Reflect.ownKeys(supplied).some((key) => typeof key !== "string" || !Object.hasOwn(limitRanges, key)) || human.kind === "until_withdrawn_or_closed" && Object.hasOwn(supplied, "requestTimeoutMs")) throw new TypeError("Conflicting or unknown session interaction limits.");
63
110
  const limits = { ...DEFAULT_AGENT_SESSION_INTERACTION_LIMITS };
64
111
  for (const key of Object.keys(limitRanges)) {
65
112
  const number = supplied[key];
66
113
  if (number === void 0) continue;
67
114
  const [minimum, maximum] = limitRanges[key];
68
- if (typeof number !== "number" || !Number.isSafeInteger(number) || number < minimum || number > maximum) {
69
- throw new RangeError(`Session interaction ${key} must be an integer between ${minimum} and ${maximum}.`);
70
- }
115
+ if (typeof number !== "number" || !Number.isSafeInteger(number) || number < minimum || number > maximum) throw new RangeError(`Invalid session interaction ${key}.`);
71
116
  limits[key] = number;
72
117
  }
73
- return Object.freeze({ onRequest: onRequest.bind(input), limits: Object.freeze(limits) });
118
+ return Object.freeze({ onRequest: input.onRequest.bind(input), humanWait: human.kind, limits: Object.freeze(limits) });
119
+ }
120
+ function validateNativeContinuationContext(input) {
121
+ if (input === void 0) return void 0;
122
+ const value = interactionRecord(input);
123
+ if (!hasExactOwnKeys(value, ["onExecution"]) || typeof value.onExecution !== "function") throw new TypeError("Native continuations require one callable handler.");
124
+ return Object.freeze({ onExecution: input.onExecution.bind(input) });
74
125
  }
75
126
  function captureSessionInteractionCandidate(input, observe) {
76
- const value = record(input);
127
+ const value = interactionRecord(input);
77
128
  const terminal = value.terminal;
78
129
  const observation = Promise.resolve(terminal);
79
130
  void observation.catch(() => {
80
131
  });
81
132
  observe(observation);
82
- const request = value.request;
83
- const signal = value.signal;
84
- const respond = value.respond;
85
- if (!hasExactOwnKeys(value, ["request", "signal", "terminal", "respond"]) || !(signal instanceof AbortSignal) || typeof respond !== "function" || !terminal || typeof record(terminal).then !== "function") throw new TypeError("Provider offered an invalid session interaction handle.");
86
- return Object.freeze({
87
- request,
88
- signal,
89
- terminal: observation,
90
- respond: respond.bind(input)
91
- });
92
- }
93
- function validateSessionInteractionCandidate(input, sessionId, requestTimeoutMs) {
94
- const parsed = parseAgentSessionDecisionRequest(input.request);
95
- if (parsed.sessionId !== sessionId || !path.isAbsolute(parsed.target.path) || path.normalize(parsed.target.path) !== parsed.target.path) {
96
- throw new TypeError("Session interaction does not match its session or canonical workspace target.");
133
+ if (!(value.signal instanceof AbortSignal) || !terminal || typeof interactionRecord(terminal).then !== "function") throw new TypeError("Invalid interaction lifecycle.");
134
+ if (value.kind === "direct" && hasExactOwnKeys(value, ["kind", "request", "signal", "terminal", "respond"]) && typeof value.respond === "function") {
135
+ return Object.freeze({ kind: "direct", request: input.request, signal: value.signal, terminal: observation, respond: value.respond.bind(input) });
97
136
  }
98
- const expiry = Math.min(Date.parse(parsed.expiresAt), Date.now() + requestTimeoutMs);
99
- if (expiry <= Date.now()) throw new TypeError("Provider offered an expired session interaction.");
100
- const request = parseAgentSessionDecisionRequest({ ...parsed, expiresAt: new Date(expiry).toISOString() });
101
- return Object.freeze({ ...input, request });
137
+ if (value.kind === "prepared" && hasExactOwnKeys(value, ["kind", "request", "signal", "terminal", "prepareResponse"]) && typeof value.prepareResponse === "function") {
138
+ const request = parseAgentSessionRequest(value.request);
139
+ if (request.kind === "decision") throw new TypeError("Decisions cannot prepare native execution.");
140
+ return Object.freeze({ kind: "prepared", request, signal: value.signal, terminal: observation, prepareResponse: value.prepareResponse.bind(input) });
141
+ }
142
+ throw new TypeError("Provider offered an invalid session interaction handle.");
143
+ }
144
+ function validateSessionInteractionCandidate(input, sessionId, context) {
145
+ const request = parseAgentSessionRequest(input.request);
146
+ if (request.sessionId !== sessionId || request.kind === "decision" && (!path.isAbsolute(request.target.path) || path.normalize(request.target.path) !== request.target.path)) throw new TypeError("Interaction does not match its exact session or canonical workspace target.");
147
+ const provider = request.expiresAt === void 0 ? void 0 : Date.parse(request.expiresAt);
148
+ const host = context.humanWait === "bounded" ? Date.now() + context.limits.requestTimeoutMs : void 0;
149
+ const source = provider !== void 0 && (host === void 0 || provider <= host) ? "provider" : "host_policy";
150
+ const deadlineAt = source === "provider" ? provider : host;
151
+ const deadline = deadlineAt === void 0 ? Object.freeze({ kind: "no_deadline" }) : Object.freeze({ kind: "deadline", expiresAt: source === "provider" ? request.expiresAt : parseAgentIsoDateTime(new Date(deadlineAt).toISOString()), source });
152
+ if (input.kind === "prepared" && request.kind === "decision") throw new TypeError();
153
+ return Object.freeze({ ...input, request, deadline, ...deadlineAt === void 0 ? {} : { deadlineAt } });
154
+ }
155
+ function acceptedResponse(input) {
156
+ const value = interactionRecord(input);
157
+ if (value.kind === "decision") return parseAgentSessionResponse(value);
158
+ if (value.kind === "form" && hasExactOwnKeys(value, ["kind", "action", "choiceId"]) && (value.action === "submit" || value.action === "cancel")) return Object.freeze({ kind: "form", action: value.action, choiceId: parseAgentSessionFormChoiceId(value.choiceId) });
159
+ if (value.kind === "plan_review" && hasExactOwnKeys(value, ["kind", "action", "choiceId", "planId", "revision"]) && (value.action === "approve" || value.action === "revise" || value.action === "abandon")) return Object.freeze({ kind: "plan_review", action: value.action, choiceId: parseAgentSessionPlanReviewChoiceId(value.choiceId), planId: parseAgentSessionPlanId(value.planId), revision: parseAgentSessionPlanRevision(value.revision) });
160
+ throw new TypeError("Invalid accepted response.");
102
161
  }
103
162
  function validateSessionInteractionTerminal(input) {
104
- const value = record(input);
105
- if (value.kind === "answered" && hasExactOwnKeys(value, ["kind", "choiceId"])) {
106
- return Object.freeze({ kind: "answered", choiceId: parseAgentSessionDecisionChoiceId(value.choiceId) });
107
- }
163
+ const value = interactionRecord(input);
164
+ if (value.kind === "answered" && hasExactOwnKeys(value, ["kind", "response"])) return Object.freeze({ kind: "answered", response: acceptedResponse(value.response) });
108
165
  if ((value.kind === "failed" || value.kind === "rejected" || value.kind === "delivery_uncertain") && hasExactOwnKeys(value, ["kind", "error"])) return Object.freeze({ kind: value.kind, error: parseAgentError(value.error) });
109
- if ((value.kind === "withdrawn" || value.kind === "expired" || value.kind === "session_closed") && hasExactOwnKeys(value, ["kind"])) return Object.freeze({ kind: value.kind });
166
+ if (value.kind === "expired" && hasExactOwnKeys(value, ["kind", "source"]) && (value.source === "provider" || value.source === "host_policy")) return Object.freeze({ kind: "expired", source: value.source });
167
+ if ((value.kind === "withdrawn" || value.kind === "session_closed") && hasExactOwnKeys(value, ["kind"])) return Object.freeze({ kind: value.kind });
110
168
  throw new TypeError("Provider returned an invalid session interaction terminal.");
111
169
  }
112
170
  export {
113
171
  captureSessionInteractionCandidate,
114
172
  interactionContractError,
173
+ interactionRecord,
174
+ validateNativeContinuationContext,
175
+ validateNativeContinuationSupport,
115
176
  validateSessionInteractionCandidate,
116
177
  validateSessionInteractionContext,
117
178
  validateSessionInteractionSupport,
@@ -1,8 +1,81 @@
1
- import { type AgentCapabilities, type AgentProviderKey, type AgentSessionBinding, type AgentSessionId } from "@agen-ai/agent-protocol";
1
+ import { type AgentCapabilities, type AgentCollaborationNode, type AgentContextCumulativeUsage, type AgentContextMeasurementScope, type AgentContextUsage, type AgentGeneratedResourceDescriptor, type AgentItemKind, type AgentItemStatus, type AgentOperationInvocation, type AgentOperationResult, type AgentProviderKey, type AgentSessionBinding, type AgentSessionId, type AgentTurnId } from "@agen-ai/agent-protocol";
2
2
  import { type AgentHostBindingLease } from "./hostBindings/lifetime.js";
3
3
  import { type MaybePromise } from "./foundation.js";
4
- import type { AgentProviderSession, AgentSessionBindingCreatedObserver } from "./sessions.js";
4
+ import { type AgentProviderOutputValidationContext } from "./outputValidation.js";
5
+ import type { AgentProviderStartTurnInput, AgentProviderSession, AgentSessionBindingCreatedObserver, AgentProviderTurnExecution } from "./sessions.js";
6
+ import { type ValidatedAgentTurnExecution, type AdoptedAgentTurnExecution } from "./turnExecution/execution.js";
7
+ import { type PendingAgentRequest } from "./turnExecution/requests.js";
5
8
  import type { SessionInteractionOwner } from "./sessionInteractions/lifetime.js";
9
+ interface ObservedAgentItem {
10
+ readonly itemKind: AgentItemKind;
11
+ readonly status: AgentItemStatus;
12
+ readonly inProgressObserved: boolean;
13
+ readonly terminal: boolean;
14
+ }
15
+ interface AgentTurnSequenceState {
16
+ readonly fileChangeMode: AgentCapabilities["output"]["fileChanges"];
17
+ readonly observedItems: Map<string, ObservedAgentItem>;
18
+ readonly proposedPlans: Map<string, string>;
19
+ readonly generatedResourceIds: Set<string>;
20
+ started: boolean;
21
+ terminal: boolean;
22
+ finalDiffObserved: boolean;
23
+ }
24
+ interface AgentContextUsageSequenceState {
25
+ readonly latestByScope: Map<AgentContextMeasurementScope, AgentContextUsage>;
26
+ readonly cumulativeByScope: Map<AgentContextMeasurementScope, AgentContextCumulativeUsage>;
27
+ readonly compactionReadyScopes: Set<AgentContextMeasurementScope>;
28
+ }
29
+ interface TrackedAgentOperationInvocation {
30
+ readonly invocation: AgentOperationInvocation;
31
+ result?: AgentOperationResult;
32
+ }
33
+ interface AgentInteractionSequenceState {
34
+ readonly operationResults: Map<string, AgentOperationResult>;
35
+ readonly operationInvocations: Map<string, TrackedAgentOperationInvocation>;
36
+ readonly collaborationNodes: Map<string, AgentCollaborationNode>;
37
+ readonly collaborationSpawnReservations: Map<string, AgentCollaborationSpawnReservation>;
38
+ readonly generatedResources: Map<string, AgentGeneratedResourceDescriptor>;
39
+ }
40
+ interface AgentCollaborationSpawnReservation {
41
+ readonly parentCollaborationId?: string;
42
+ }
43
+ interface ActiveAgentTurn {
44
+ readonly turnId: AgentTurnId;
45
+ readonly pendingRequests: Map<string, PendingAgentRequest>;
46
+ readonly state: AgentTurnSequenceState;
47
+ readonly inFlightOperations: Set<Promise<void>>;
48
+ readonly owner: ValidatedAgentTurnExecution;
49
+ }
50
+ export declare function createAgentSessionValidationOwner(capabilities: AgentCapabilities, sessionId: AgentSessionId): {
51
+ sessionAdmission: {
52
+ reserveExecution(): object;
53
+ installExecution(token: object, execution: ActiveAgentTurn): void;
54
+ releaseExecution(token: object): void;
55
+ readonly execution: ActiveAgentTurn | null;
56
+ ownsExecution(token: object): boolean;
57
+ stop(): void;
58
+ claimRequest(requestId: import("@agen-ai/agent-protocol").AgentRequestId, duplicateCode: "invalid_turn_sequence" | "invalid_session_interaction"): void;
59
+ };
60
+ sessionLifetime: AbortController;
61
+ contextUsageState: AgentContextUsageSequenceState;
62
+ interactionState: AgentInteractionSequenceState;
63
+ outputContext: (turnId?: AgentTurnId) => AgentProviderOutputValidationContext;
64
+ requireUsable: () => void;
65
+ readonly activeTurn: ActiveAgentTurn | null;
66
+ readonly closed: boolean;
67
+ readonly unusable: boolean;
68
+ fence(): void;
69
+ stop(): void;
70
+ completeClose(): void;
71
+ installClose(close: () => Promise<void>): void;
72
+ reserveExecution: () => object;
73
+ ownsExecution: (token: object) => boolean;
74
+ releaseExecution: (token: object) => void;
75
+ installNativeExecution(token: object, turnId: AgentTurnId, createCandidate: (signal: AbortSignal) => AgentProviderTurnExecution): AdoptedAgentTurnExecution;
76
+ installCallerExecution(token: object, turnInput: AgentProviderStartTurnInput, start: (input: AgentProviderStartTurnInput) => AgentProviderTurnExecution): ValidatedAgentTurnExecution;
77
+ };
78
+ export type AgentSessionValidationOwner = ReturnType<typeof createAgentSessionValidationOwner>;
6
79
  export declare function validateAgentProviderSession(input: {
7
80
  readonly capabilities: AgentCapabilities;
8
81
  readonly sessionId: AgentSessionId;
@@ -11,6 +84,7 @@ export declare function validateAgentProviderSession(input: {
11
84
  readonly sourceBinding?: AgentSessionBinding;
12
85
  readonly hostBindingLease?: AgentHostBindingLease;
13
86
  readonly sessionInteractionOwner?: SessionInteractionOwner;
87
+ readonly validationOwner?: AgentSessionValidationOwner;
14
88
  }): AgentProviderSession;
15
89
  export declare function closeRejectedAgentProviderSession(session: AgentProviderSession | null, error: unknown, hostBinding?: Readonly<{
16
90
  providerKey: AgentProviderKey;
@@ -27,6 +101,8 @@ export declare function openIdentityCreatingAgentProviderSession(input: {
27
101
  readonly hostBindingLease?: AgentHostBindingLease;
28
102
  readonly openingInput?: object;
29
103
  readonly sessionInteractionOwner?: SessionInteractionOwner;
104
+ readonly validationOwner?: AgentSessionValidationOwner;
30
105
  readonly open: (observer: AgentSessionBindingCreatedObserver) => MaybePromise<AgentProviderSession>;
31
106
  }): Promise<AgentProviderSession>;
107
+ export {};
32
108
  //# sourceMappingURL=sessionValidation.d.ts.map