@agen-ai/agent-orchestration 0.0.0-stage → 0.4.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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +413 -2
  3. package/dist/catalog/parse.d.ts +3 -0
  4. package/dist/catalog/parse.js +13 -0
  5. package/dist/catalog/schemas.d.ts +8 -0
  6. package/dist/catalog/schemas.js +78 -0
  7. package/dist/catalog/types.d.ts +53 -0
  8. package/dist/catalog/types.js +0 -0
  9. package/dist/coordinator/admission.d.ts +7 -0
  10. package/dist/coordinator/admission.js +189 -0
  11. package/dist/coordinator/cancel.d.ts +7 -0
  12. package/dist/coordinator/cancel.js +111 -0
  13. package/dist/coordinator/create.d.ts +3 -0
  14. package/dist/coordinator/create.js +87 -0
  15. package/dist/coordinator/parse.d.ts +10 -0
  16. package/dist/coordinator/parse.js +60 -0
  17. package/dist/coordinator/read.d.ts +4 -0
  18. package/dist/coordinator/read.js +267 -0
  19. package/dist/coordinator/recovery.d.ts +4 -0
  20. package/dist/coordinator/recovery.js +24 -0
  21. package/dist/coordinator/shutdown.d.ts +7 -0
  22. package/dist/coordinator/shutdown.js +66 -0
  23. package/dist/coordinator/types.d.ts +154 -0
  24. package/dist/coordinator/types.js +0 -0
  25. package/dist/delivery/calls.d.ts +4 -0
  26. package/dist/delivery/calls.js +34 -0
  27. package/dist/delivery/journal.d.ts +7 -0
  28. package/dist/delivery/journal.js +57 -0
  29. package/dist/delivery/parse.d.ts +4 -0
  30. package/dist/delivery/parse.js +31 -0
  31. package/dist/delivery/recovery.d.ts +3 -0
  32. package/dist/delivery/recovery.js +18 -0
  33. package/dist/delivery/scheduler.d.ts +3 -0
  34. package/dist/delivery/scheduler.js +123 -0
  35. package/dist/delivery/setup.d.ts +7 -0
  36. package/dist/delivery/setup.js +37 -0
  37. package/dist/delivery/types.d.ts +36 -0
  38. package/dist/delivery/types.js +0 -0
  39. package/dist/execution/authority.d.ts +16 -0
  40. package/dist/execution/authority.js +86 -0
  41. package/dist/execution/cleanup.d.ts +3 -0
  42. package/dist/execution/cleanup.js +75 -0
  43. package/dist/execution/control.d.ts +6 -0
  44. package/dist/execution/control.js +231 -0
  45. package/dist/execution/finish.d.ts +6 -0
  46. package/dist/execution/finish.js +49 -0
  47. package/dist/execution/journal.d.ts +19 -0
  48. package/dist/execution/journal.js +28 -0
  49. package/dist/execution/prepare.d.ts +3 -0
  50. package/dist/execution/prepare.js +153 -0
  51. package/dist/execution/scheduler.d.ts +4 -0
  52. package/dist/execution/scheduler.js +136 -0
  53. package/dist/execution/state.d.ts +107 -0
  54. package/dist/execution/state.js +120 -0
  55. package/dist/execution/stream.d.ts +9 -0
  56. package/dist/execution/stream.js +108 -0
  57. package/dist/host/types.d.ts +95 -0
  58. package/dist/host/types.js +0 -0
  59. package/dist/index.d.ts +20 -0
  60. package/dist/index.js +58 -0
  61. package/dist/mcp/bridge.d.ts +4 -0
  62. package/dist/mcp/bridge.js +222 -0
  63. package/dist/mcp/http.d.ts +11 -0
  64. package/dist/mcp/http.js +74 -0
  65. package/dist/mcp/index.d.ts +3 -0
  66. package/dist/mcp/index.js +4 -0
  67. package/dist/mcp/limits.d.ts +10 -0
  68. package/dist/mcp/limits.js +30 -0
  69. package/dist/mcp/protocol.d.ts +50 -0
  70. package/dist/mcp/protocol.js +81 -0
  71. package/dist/mcp/types.d.ts +22 -0
  72. package/dist/mcp/types.js +0 -0
  73. package/dist/policy/matching.d.ts +4 -0
  74. package/dist/policy/matching.js +18 -0
  75. package/dist/policy/parse.d.ts +3 -0
  76. package/dist/policy/parse.js +13 -0
  77. package/dist/policy/resolve.d.ts +7 -0
  78. package/dist/policy/resolve.js +67 -0
  79. package/dist/policy/schemas.d.ts +5 -0
  80. package/dist/policy/schemas.js +59 -0
  81. package/dist/policy/types.d.ts +60 -0
  82. package/dist/policy/types.js +0 -0
  83. package/dist/shared/bounds.d.ts +6 -0
  84. package/dist/shared/bounds.js +88 -0
  85. package/dist/shared/errors.d.ts +9 -0
  86. package/dist/shared/errors.js +27 -0
  87. package/dist/shared/identity.d.ts +6 -0
  88. package/dist/shared/identity.js +32 -0
  89. package/dist/shared/immutable.d.ts +2 -0
  90. package/dist/shared/immutable.js +10 -0
  91. package/dist/shared/limits.d.ts +32 -0
  92. package/dist/shared/limits.js +69 -0
  93. package/dist/shared/operational-errors.d.ts +7 -0
  94. package/dist/shared/operational-errors.js +15 -0
  95. package/dist/shared/schemas.d.ts +11 -0
  96. package/dist/shared/schemas.js +23 -0
  97. package/dist/shared/text.d.ts +2 -0
  98. package/dist/shared/text.js +15 -0
  99. package/dist/store/memory.d.ts +7 -0
  100. package/dist/store/memory.js +215 -0
  101. package/dist/store/pages.d.ts +16 -0
  102. package/dist/store/pages.js +46 -0
  103. package/dist/store/parse.d.ts +5 -0
  104. package/dist/store/parse.js +137 -0
  105. package/dist/store/types.d.ts +219 -0
  106. package/dist/store/types.js +0 -0
  107. package/dist/store-adapter/admission.d.ts +6 -0
  108. package/dist/store-adapter/admission.js +90 -0
  109. package/dist/store-adapter/context.d.ts +20 -0
  110. package/dist/store-adapter/context.js +107 -0
  111. package/dist/store-adapter/delivery.d.ts +15 -0
  112. package/dist/store-adapter/delivery.js +81 -0
  113. package/dist/store-adapter/execution.d.ts +12 -0
  114. package/dist/store-adapter/execution.js +151 -0
  115. package/dist/store-adapter/index.d.ts +7 -0
  116. package/dist/store-adapter/index.js +27 -0
  117. package/dist/store-adapter/lifecycle.d.ts +15 -0
  118. package/dist/store-adapter/lifecycle.js +80 -0
  119. package/dist/store-adapter/plan.d.ts +7 -0
  120. package/dist/store-adapter/plan.js +168 -0
  121. package/dist/store-adapter/types.d.ts +45 -0
  122. package/dist/store-adapter/types.js +0 -0
  123. package/dist/tasks/failure.d.ts +4 -0
  124. package/dist/tasks/failure.js +24 -0
  125. package/dist/tasks/parse.d.ts +18 -0
  126. package/dist/tasks/parse.js +66 -0
  127. package/dist/tasks/schemas.d.ts +47 -0
  128. package/dist/tasks/schemas.js +215 -0
  129. package/dist/tasks/types.d.ts +192 -0
  130. package/dist/tasks/types.js +0 -0
  131. package/dist/tools/create.d.ts +4 -0
  132. package/dist/tools/create.js +69 -0
  133. package/dist/tools/errors.d.ts +4 -0
  134. package/dist/tools/errors.js +35 -0
  135. package/dist/tools/guidance.d.ts +4 -0
  136. package/dist/tools/guidance.js +28 -0
  137. package/dist/tools/handlers.d.ts +4 -0
  138. package/dist/tools/handlers.js +84 -0
  139. package/dist/tools/projection.d.ts +13 -0
  140. package/dist/tools/projection.js +72 -0
  141. package/dist/tools/schemas.d.ts +6 -0
  142. package/dist/tools/schemas.js +93 -0
  143. package/dist/tools/types.d.ts +28 -0
  144. package/dist/tools/types.js +0 -0
  145. package/package.json +64 -3
@@ -0,0 +1,59 @@
1
+ import { AgentProviderKeySchema } from "@agen-ai/agent-protocol/zod";
2
+ import { z } from "zod/v4";
3
+ import { TargetOptionSchema } from "../catalog/schemas.js";
4
+ import { DELEGATION_ENTRIES } from "../shared/bounds.js";
5
+ import { CanonicalIdSchema, ExecutionModeSchema, ReasoningSchema, RevisionSchema, requireUniqueValues } from "../shared/schemas.js";
6
+ function targetIdentityKey(identity2) {
7
+ return JSON.stringify([identity2.catalogId, identity2.targetId]);
8
+ }
9
+ const exclusion = z.strictObject({
10
+ exclusionId: CanonicalIdSchema,
11
+ providerKey: AgentProviderKeySchema.optional(),
12
+ modelId: CanonicalIdSchema.optional(),
13
+ targetId: CanonicalIdSchema.optional(),
14
+ catalogId: CanonicalIdSchema.optional(),
15
+ reasoning: ReasoningSchema.optional(),
16
+ executionMode: ExecutionModeSchema.optional(),
17
+ options: z.array(TargetOptionSchema).min(1).max(100).optional()
18
+ }).superRefine((value, context) => {
19
+ if ([value.providerKey, value.modelId, value.targetId, value.catalogId, value.reasoning, value.executionMode, value.options].every((criterion) => criterion === void 0)) {
20
+ context.addIssue({ code: "custom", path: [], message: "A developer exclusion requires at least one criterion." });
21
+ }
22
+ if ((value.modelId !== void 0 || value.options !== void 0) && value.providerKey === void 0) {
23
+ context.addIssue({ code: "custom", path: ["providerKey"], message: "Model and native option exclusions require a provider identity." });
24
+ }
25
+ if (value.targetId === void 0 !== (value.catalogId === void 0)) {
26
+ context.addIssue({ code: "custom", path: ["targetId"], message: "Exact target exclusions require both catalog and target identities." });
27
+ }
28
+ if (value.options) requireUniqueValues(value.options.map((option) => option.key), context, ["options"]);
29
+ });
30
+ const developer = z.strictObject({
31
+ enabled: z.boolean().default(true),
32
+ exclusions: z.array(exclusion).max(DELEGATION_ENTRIES).default([])
33
+ }).superRefine((value, context) => {
34
+ requireUniqueValues(value.exclusions.map((entry) => entry.exclusionId), context, ["exclusions"]);
35
+ });
36
+ const identity = z.strictObject({ catalogId: CanonicalIdSchema, targetId: CanonicalIdSchema });
37
+ const identities = z.array(identity).max(DELEGATION_ENTRIES).superRefine((value, context) => {
38
+ requireUniqueValues(value.map(targetIdentityKey), context, []);
39
+ });
40
+ const selection = z.discriminatedUnion("kind", [
41
+ z.strictObject({ kind: z.literal("all_available"), includeFast: z.boolean(), unknownModeTargets: identities }),
42
+ z.strictObject({ kind: z.literal("explicit"), targets: identities })
43
+ ]);
44
+ const user = z.discriminatedUnion("enabled", [
45
+ z.strictObject({ enabled: z.literal(false) }),
46
+ z.strictObject({
47
+ enabled: z.literal(true),
48
+ selection: selection.default({ kind: "all_available", includeFast: false, unknownModeTargets: [] })
49
+ })
50
+ ]);
51
+ const PolicySnapshotSchema = z.strictObject({
52
+ revision: RevisionSchema,
53
+ developer: developer.default({ enabled: true, exclusions: [] }),
54
+ user: user.default({ enabled: false })
55
+ });
56
+ export {
57
+ PolicySnapshotSchema,
58
+ targetIdentityKey
59
+ };
@@ -0,0 +1,60 @@
1
+ import type { AgentProviderKey } from "@agen-ai/agent-protocol";
2
+ import type { DelegationExecutionMode, DelegationReasoning, DelegationTarget, DelegationTargetOption, DelegationTargetReference } from "../catalog/types.js";
3
+ export interface DelegationExclusion {
4
+ readonly exclusionId: string;
5
+ readonly providerKey?: AgentProviderKey;
6
+ readonly modelId?: string;
7
+ readonly targetId?: string;
8
+ readonly catalogId?: string;
9
+ readonly reasoning?: DelegationReasoning;
10
+ readonly executionMode?: DelegationExecutionMode;
11
+ readonly options?: readonly DelegationTargetOption[];
12
+ }
13
+ export interface DelegationDeveloperPolicy {
14
+ readonly enabled: boolean;
15
+ readonly exclusions: readonly DelegationExclusion[];
16
+ }
17
+ export type DelegationTargetIdentity = Readonly<{
18
+ catalogId: string;
19
+ targetId: string;
20
+ }>;
21
+ export type DelegationUserSelection = Readonly<{
22
+ kind: "all_available";
23
+ includeFast: boolean;
24
+ unknownModeTargets: readonly DelegationTargetIdentity[];
25
+ }> | Readonly<{
26
+ kind: "explicit";
27
+ targets: readonly DelegationTargetIdentity[];
28
+ }>;
29
+ export type DelegationUserPolicy = Readonly<{
30
+ enabled: false;
31
+ }> | Readonly<{
32
+ enabled: true;
33
+ selection?: DelegationUserSelection;
34
+ }>;
35
+ export interface DelegationPolicySnapshot {
36
+ readonly revision: number;
37
+ readonly developer: DelegationDeveloperPolicy;
38
+ readonly user: DelegationUserPolicy;
39
+ }
40
+ export type DelegationPolicyOutcome = "allowed" | "denied" | "unverifiable";
41
+ export interface DelegationTargetDecision {
42
+ readonly reference: DelegationTargetReference;
43
+ readonly selected: boolean;
44
+ readonly outcome: DelegationPolicyOutcome;
45
+ readonly reasons: readonly Readonly<{
46
+ code: string;
47
+ exclusionId?: string;
48
+ message: string;
49
+ }>[];
50
+ }
51
+ export interface ResolvedDelegationPolicy {
52
+ readonly enabled: boolean;
53
+ readonly policyRevision: number;
54
+ readonly catalogId: string;
55
+ readonly catalogRevision: number;
56
+ readonly decisions: readonly DelegationTargetDecision[];
57
+ readonly allowedTargets: readonly DelegationTarget[];
58
+ readonly missingSelections: readonly DelegationTargetIdentity[];
59
+ }
60
+ //# sourceMappingURL=types.d.ts.map
File without changes
@@ -0,0 +1,6 @@
1
+ export declare const DELEGATION_DOCUMENT_BYTES = 1048576;
2
+ export declare const DELEGATION_TARGET_BYTES = 32768;
3
+ export declare const DELEGATION_ENTRIES = 1000;
4
+ export declare function captureDelegationRecord(input: unknown, path?: readonly (string | number)[]): Record<string, unknown>;
5
+ export declare function copyBoundedDelegationData(input: unknown): unknown;
6
+ //# sourceMappingURL=bounds.d.ts.map
@@ -0,0 +1,88 @@
1
+ import { invalidDelegationData } from "./errors.js";
2
+ const DELEGATION_DOCUMENT_BYTES = 1048576;
3
+ const DELEGATION_TARGET_BYTES = 32768;
4
+ const DELEGATION_ENTRIES = 1e3;
5
+ function captureDelegationRecord(input, path = []) {
6
+ if (input === null || typeof input !== "object" || Array.isArray(input) || ![Object.prototype, null].includes(Object.getPrototypeOf(input))) {
7
+ return invalidDelegationData("invalid_data", path, "Delegation objects must be plain data records.");
8
+ }
9
+ const result = {};
10
+ const keys = Reflect.ownKeys(input);
11
+ if (keys.length > DELEGATION_ENTRIES) invalidDelegationData("entry_limit", path, "Delegation object has too many properties.");
12
+ for (const key of keys) {
13
+ if (typeof key !== "string" || ["__proto__", "constructor", "prototype"].includes(key)) {
14
+ invalidDelegationData("invalid_data", path, "Delegation property names must be safe strings.");
15
+ }
16
+ const descriptor = Object.getOwnPropertyDescriptor(input, key);
17
+ if (!descriptor?.enumerable || !Object.hasOwn(descriptor, "value")) {
18
+ invalidDelegationData("invalid_data", [...path, key], "Delegation properties must be enumerable data properties.");
19
+ }
20
+ result[key] = descriptor.value;
21
+ }
22
+ return result;
23
+ }
24
+ function copyBoundedDelegationData(input) {
25
+ const ancestors = /* @__PURE__ */ new Set();
26
+ const encoder = new TextEncoder();
27
+ let bytes = 0;
28
+ const reserve = (count, path) => {
29
+ bytes += count;
30
+ if (bytes > DELEGATION_DOCUMENT_BYTES) invalidDelegationData("byte_limit", path, "Delegation data exceeds 1 MiB of serialized JSON.");
31
+ };
32
+ const visit = (value, path, depth) => {
33
+ if (depth > 16) invalidDelegationData("depth_limit", path, "Delegation data exceeds its nesting limit.");
34
+ if (typeof value === "string") {
35
+ if (value.length > DELEGATION_DOCUMENT_BYTES) invalidDelegationData("byte_limit", path, "Delegation string exceeds its byte limit.");
36
+ reserve(encoder.encode(JSON.stringify(value)).byteLength, path);
37
+ return value;
38
+ }
39
+ if (value === null || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) {
40
+ reserve(JSON.stringify(value).length, path);
41
+ return value;
42
+ }
43
+ if (typeof value !== "object") invalidDelegationData("invalid_data", path, "Delegation data must contain only finite JSON values.");
44
+ if (ancestors.has(value)) invalidDelegationData("invalid_data", path, "Delegation data cannot contain cycles.");
45
+ ancestors.add(value);
46
+ let result;
47
+ if (Array.isArray(value)) {
48
+ const keys = Reflect.ownKeys(value);
49
+ const length = Object.getOwnPropertyDescriptor(value, "length")?.value;
50
+ if (Object.getPrototypeOf(value) !== Array.prototype || length > DELEGATION_ENTRIES || keys.length !== length + 1) {
51
+ invalidDelegationData("invalid_data", path, "Delegation arrays must be dense, bounded and free of extra properties.");
52
+ }
53
+ const entries = new Array(length);
54
+ reserve(2 + Math.max(0, length - 1), path);
55
+ for (const key of keys) {
56
+ if (key === "length") continue;
57
+ if (typeof key !== "string" || !/^(?:0|[1-9][0-9]*)$/u.test(key) || Number(key) >= length) {
58
+ invalidDelegationData("invalid_data", path, "Delegation arrays cannot carry extra properties.");
59
+ }
60
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
61
+ if (!descriptor?.enumerable || !Object.hasOwn(descriptor, "value")) {
62
+ invalidDelegationData("invalid_data", [...path, Number(key)], "Delegation array entries must be data properties.");
63
+ }
64
+ entries[Number(key)] = visit(descriptor.value, [...path, Number(key)], depth + 1);
65
+ }
66
+ result = entries;
67
+ } else {
68
+ const record = captureDelegationRecord(value, path);
69
+ const entries = Object.entries(record);
70
+ reserve(2 + Math.max(0, entries.length - 1), path);
71
+ for (const [key, child] of entries) {
72
+ reserve(encoder.encode(JSON.stringify(key)).byteLength + 1, path);
73
+ record[key] = visit(child, [...path, key], depth + 1);
74
+ }
75
+ result = record;
76
+ }
77
+ ancestors.delete(value);
78
+ return result;
79
+ };
80
+ return visit(input, [], 0);
81
+ }
82
+ export {
83
+ DELEGATION_DOCUMENT_BYTES,
84
+ DELEGATION_ENTRIES,
85
+ DELEGATION_TARGET_BYTES,
86
+ captureDelegationRecord,
87
+ copyBoundedDelegationData
88
+ };
@@ -0,0 +1,9 @@
1
+ import { type ValidationErrorInput, type ValidationIssue } from "@agen-ai/validation";
2
+ export type DelegationValidationIssue = ValidationIssue;
3
+ export declare class DelegationValidationError extends Error {
4
+ readonly issues: readonly DelegationValidationIssue[];
5
+ constructor(issues: readonly DelegationValidationIssue[]);
6
+ }
7
+ export declare function invalidDelegationData(code: string, path: readonly (string | number)[], message: string): never;
8
+ export declare function delegationSchemaError(error: ValidationErrorInput, input: unknown): never;
9
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,27 @@
1
+ import {
2
+ normalizeValidationError
3
+ } from "@agen-ai/validation";
4
+ import { freezeDelegationData } from "./immutable.js";
5
+ class DelegationValidationError extends Error {
6
+ issues;
7
+ constructor(issues) {
8
+ super("Delegation data is invalid.");
9
+ this.name = "DelegationValidationError";
10
+ this.issues = freezeDelegationData(issues.slice(0, 100).map((issue) => ({
11
+ code: issue.code,
12
+ path: [...issue.path],
13
+ message: issue.message
14
+ })));
15
+ }
16
+ }
17
+ function invalidDelegationData(code, path, message) {
18
+ throw new DelegationValidationError([{ code, path, message }]);
19
+ }
20
+ function delegationSchemaError(error, input) {
21
+ throw new DelegationValidationError(normalizeValidationError(error, input));
22
+ }
23
+ export {
24
+ DelegationValidationError,
25
+ delegationSchemaError,
26
+ invalidDelegationData
27
+ };
@@ -0,0 +1,6 @@
1
+ export declare function delegationCanonicalJson(input: unknown): string;
2
+ export declare function delegationDataBytes(input: unknown): number;
3
+ export declare function delegationInputDigest(input: unknown): string;
4
+ export declare function createDelegationId(): string;
5
+ export declare function delegationSubordinateId(runId: string, kind: string): string;
6
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1,32 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { copyBoundedDelegationData } from "./bounds.js";
3
+ function delegationCanonicalJson(input) {
4
+ const canonicalize = (value) => {
5
+ if (Array.isArray(value)) return value.map(canonicalize);
6
+ if (value !== null && typeof value === "object") {
7
+ return Object.fromEntries(Object.entries(value).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, child]) => [key, canonicalize(child)]));
8
+ }
9
+ return value;
10
+ };
11
+ return JSON.stringify(canonicalize(copyBoundedDelegationData(input)));
12
+ }
13
+ function delegationDataBytes(input) {
14
+ return new TextEncoder().encode(delegationCanonicalJson(input)).byteLength;
15
+ }
16
+ function delegationInputDigest(input) {
17
+ return createHash("sha256").update(delegationCanonicalJson(input)).digest("hex");
18
+ }
19
+ function createDelegationId() {
20
+ return randomUUID();
21
+ }
22
+ function delegationSubordinateId(runId, kind) {
23
+ const hex = delegationInputDigest({ runId, kind });
24
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-a${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
25
+ }
26
+ export {
27
+ createDelegationId,
28
+ delegationCanonicalJson,
29
+ delegationDataBytes,
30
+ delegationInputDigest,
31
+ delegationSubordinateId
32
+ };
@@ -0,0 +1,2 @@
1
+ export declare function freezeDelegationData<Value>(value: Value): Value;
2
+ //# sourceMappingURL=immutable.d.ts.map
@@ -0,0 +1,10 @@
1
+ function freezeDelegationData(value) {
2
+ if (value !== null && typeof value === "object") {
3
+ for (const child of Object.values(value)) freezeDelegationData(child);
4
+ Object.freeze(value);
5
+ }
6
+ return value;
7
+ }
8
+ export {
9
+ freezeDelegationData
10
+ };
@@ -0,0 +1,32 @@
1
+ export declare const DELEGATION_FINAL_RESERVATION_BYTES = 32768;
2
+ export declare const DELEGATION_FAILURE_BYTES = 2048;
3
+ export declare const DELEGATION_CRITICAL_SLOT_BYTES = 2048;
4
+ export declare const DELEGATION_CRITICAL_SLOTS = 4;
5
+ export declare const DELEGATION_RUN_RESERVATION_BYTES = 40960;
6
+ export interface DelegationLimits {
7
+ readonly maxActiveRuns: number;
8
+ readonly maxQueuedRuns: number;
9
+ readonly maxDepth: number;
10
+ readonly maxTasks: number;
11
+ readonly maxRuns: number;
12
+ readonly maxRunsPerTask: number;
13
+ readonly maxInputBytes: number;
14
+ readonly maxInputTextCharacters: number;
15
+ readonly maxRetainedInputBytes: number;
16
+ readonly maxObservationBytes: number;
17
+ readonly maxRunObservationBytes: number;
18
+ readonly maxRunObservations: number;
19
+ readonly maxRetainedObservationBytes: number;
20
+ readonly maxOrdinaryOperationsPerRun: number;
21
+ readonly maxOrdinaryOperations: number;
22
+ readonly runTimeoutMs: number;
23
+ readonly queuedStartTimeoutMs: number;
24
+ readonly maxWaitMs: number;
25
+ readonly controlTimeoutMs: number;
26
+ readonly notificationTtlMs: number;
27
+ readonly maxPageRecords: number;
28
+ readonly maxPageBytes: number;
29
+ }
30
+ export declare const DEFAULT_DELEGATION_LIMITS: DelegationLimits;
31
+ export declare function parseDelegationLimits(input?: unknown): DelegationLimits;
32
+ //# sourceMappingURL=limits.d.ts.map
@@ -0,0 +1,69 @@
1
+ import { z } from "zod/v4";
2
+ import { copyBoundedDelegationData } from "./bounds.js";
3
+ import { delegationSchemaError } from "./errors.js";
4
+ import { freezeDelegationData } from "./immutable.js";
5
+ const DELEGATION_FINAL_RESERVATION_BYTES = 32768;
6
+ const DELEGATION_FAILURE_BYTES = 2048;
7
+ const DELEGATION_CRITICAL_SLOT_BYTES = 2048;
8
+ const DELEGATION_CRITICAL_SLOTS = 4;
9
+ const DELEGATION_RUN_RESERVATION_BYTES = 40960;
10
+ const DEFAULT_DELEGATION_LIMITS = Object.freeze({
11
+ maxActiveRuns: 4,
12
+ maxQueuedRuns: 32,
13
+ maxDepth: 2,
14
+ maxTasks: 256,
15
+ maxRuns: 1024,
16
+ maxRunsPerTask: 8,
17
+ maxInputBytes: 24576,
18
+ maxInputTextCharacters: 16e3,
19
+ maxRetainedInputBytes: 16777216,
20
+ maxObservationBytes: 8192,
21
+ maxRunObservationBytes: 1048576,
22
+ maxRunObservations: 2048,
23
+ maxRetainedObservationBytes: 33554432,
24
+ maxOrdinaryOperationsPerRun: 32,
25
+ maxOrdinaryOperations: 8192,
26
+ runTimeoutMs: 18e5,
27
+ queuedStartTimeoutMs: 3e5,
28
+ maxWaitMs: 3e4,
29
+ controlTimeoutMs: 1e4,
30
+ notificationTtlMs: 864e5,
31
+ maxPageRecords: 100,
32
+ maxPageBytes: 65536
33
+ });
34
+ const finite = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
35
+ const schema = z.strictObject(Object.fromEntries(Object.entries(DEFAULT_DELEGATION_LIMITS).map(([key, value]) => [key, finite.default(value)]))).superRefine((value, context) => {
36
+ for (const [smaller, larger] of [
37
+ ["maxActiveRuns", "maxRuns"],
38
+ ["maxQueuedRuns", "maxRuns"],
39
+ ["maxTasks", "maxRuns"],
40
+ ["maxRunsPerTask", "maxRuns"],
41
+ ["maxInputBytes", "maxRetainedInputBytes"]
42
+ ]) {
43
+ if (value[smaller] > value[larger]) context.addIssue({ code: "custom", path: [smaller], message: `${smaller} exceeds ${larger}.` });
44
+ }
45
+ if (value.maxPageRecords > 100 || value.maxPageBytes > 65536 || value.maxInputBytes > 24576 || value.maxInputTextCharacters > 16e3 || value.maxObservationBytes > 8192) {
46
+ context.addIssue({ code: "custom", path: [], message: "Limits exceed the initial bounded record and page format." });
47
+ }
48
+ if (value.maxRuns > Math.floor(Number.MAX_SAFE_INTEGER / DELEGATION_RUN_RESERVATION_BYTES) || value.maxOrdinaryOperations > Math.floor(Number.MAX_SAFE_INTEGER / DELEGATION_CRITICAL_SLOT_BYTES) || value.maxRunObservations > Math.floor(Number.MAX_SAFE_INTEGER / value.maxObservationBytes)) {
49
+ context.addIssue({ code: "custom", path: [], message: "Derived store reservations must remain safe integers." });
50
+ }
51
+ for (const key of ["runTimeoutMs", "queuedStartTimeoutMs", "maxWaitMs", "controlTimeoutMs", "notificationTtlMs"]) {
52
+ if (value[key] > 2147483647) context.addIssue({ code: "custom", path: [key], message: "Durations must fit a referenced Node timer." });
53
+ }
54
+ });
55
+ function parseDelegationLimits(input = {}) {
56
+ const captured = copyBoundedDelegationData(input);
57
+ const parsed = schema.safeParse(captured);
58
+ if (!parsed.success) return delegationSchemaError(parsed.error, captured);
59
+ return freezeDelegationData(parsed.data);
60
+ }
61
+ export {
62
+ DEFAULT_DELEGATION_LIMITS,
63
+ DELEGATION_CRITICAL_SLOTS,
64
+ DELEGATION_CRITICAL_SLOT_BYTES,
65
+ DELEGATION_FAILURE_BYTES,
66
+ DELEGATION_FINAL_RESERVATION_BYTES,
67
+ DELEGATION_RUN_RESERVATION_BYTES,
68
+ parseDelegationLimits
69
+ };
@@ -0,0 +1,7 @@
1
+ export type DelegationErrorCode = "delegation_disabled" | "policy_denied" | "target_unavailable" | "stale_target" | "unsupported_operation" | "capacity_exceeded" | "operation_conflict" | "stale_revision" | "owner_lost" | "request_unavailable" | "delivery_uncertain" | "recovery_required" | "store_failed";
2
+ export declare class DelegationOperationError extends Error {
3
+ readonly code: DelegationErrorCode;
4
+ constructor(code: DelegationErrorCode, message: string);
5
+ }
6
+ export declare function failDelegation(code: DelegationErrorCode, message: string): never;
7
+ //# sourceMappingURL=operational-errors.d.ts.map
@@ -0,0 +1,15 @@
1
+ class DelegationOperationError extends Error {
2
+ constructor(code, message) {
3
+ super(message);
4
+ this.code = code;
5
+ this.name = "DelegationOperationError";
6
+ }
7
+ code;
8
+ }
9
+ function failDelegation(code, message) {
10
+ throw new DelegationOperationError(code, message);
11
+ }
12
+ export {
13
+ DelegationOperationError,
14
+ failDelegation
15
+ };
@@ -0,0 +1,11 @@
1
+ import { z } from "zod/v4";
2
+ export declare const CanonicalIdSchema: z.ZodString;
3
+ export declare const ReasoningSchema: z.ZodString;
4
+ export declare const RevisionSchema: z.ZodNumber;
5
+ export declare const ExecutionModeSchema: z.ZodEnum<{
6
+ standard: "standard";
7
+ fast: "fast";
8
+ }>;
9
+ export declare const ReasonTextSchema: z.ZodString;
10
+ export declare function requireUniqueValues(values: readonly string[], context: z.RefinementCtx, path: readonly (string | number)[]): void;
11
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1,23 @@
1
+ import { z } from "zod/v4";
2
+ const canonicalPattern = /^(?![\s\S]*[\u0000-\u001F\u007F-\u009F])\S(?:[\s\S]*\S)?$/u;
3
+ const canonicalMessage = "Delegation text must be canonical and contain no control or surrounding whitespace.";
4
+ const CanonicalIdSchema = z.string().min(1).max(256).regex(canonicalPattern, canonicalMessage);
5
+ const ReasoningSchema = z.string().min(1).max(128).regex(canonicalPattern, canonicalMessage);
6
+ const RevisionSchema = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
7
+ const ExecutionModeSchema = z.enum(["standard", "fast"]);
8
+ const ReasonTextSchema = z.string().min(1).max(2e3).regex(canonicalPattern, canonicalMessage);
9
+ function requireUniqueValues(values, context, path) {
10
+ const seen = /* @__PURE__ */ new Set();
11
+ for (const [index, value] of values.entries()) {
12
+ if (seen.has(value)) context.addIssue({ code: "custom", path: [...path, index], message: "Delegation identities must be unique." });
13
+ seen.add(value);
14
+ }
15
+ }
16
+ export {
17
+ CanonicalIdSchema,
18
+ ExecutionModeSchema,
19
+ ReasonTextSchema,
20
+ ReasoningSchema,
21
+ RevisionSchema,
22
+ requireUniqueValues
23
+ };
@@ -0,0 +1,2 @@
1
+ export declare function fitDelegationText(text: string, fits: (value: string) => boolean): string;
2
+ //# sourceMappingURL=text.d.ts.map
@@ -0,0 +1,15 @@
1
+ function fitDelegationText(text, fits) {
2
+ if (fits(text)) return text;
3
+ const characters = Array.from(text);
4
+ let low = 0;
5
+ let high = characters.length;
6
+ while (low < high) {
7
+ const middle = Math.ceil((low + high) / 2);
8
+ if (fits(characters.slice(0, middle).join(""))) low = middle;
9
+ else high = middle - 1;
10
+ }
11
+ return characters.slice(0, low).join("");
12
+ }
13
+ export {
14
+ fitDelegationText
15
+ };
@@ -0,0 +1,7 @@
1
+ import { type DelegationLimits } from "../shared/limits.js";
2
+ import type { DelegationStore } from "./types.js";
3
+ export declare function createInMemoryDelegationStore(options?: {
4
+ readonly limits?: Partial<DelegationLimits>;
5
+ readonly storeId?: string;
6
+ }): DelegationStore;
7
+ //# sourceMappingURL=memory.d.ts.map