@aexhq/sdk 0.13.6

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 (112) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +160 -0
  3. package/dist/_contracts/connection-ticket.d.ts +21 -0
  4. package/dist/_contracts/connection-ticket.js +49 -0
  5. package/dist/_contracts/event-envelope.d.ts +276 -0
  6. package/dist/_contracts/event-envelope.js +324 -0
  7. package/dist/_contracts/event-stream-client.d.ts +47 -0
  8. package/dist/_contracts/event-stream-client.js +141 -0
  9. package/dist/_contracts/http.d.ts +35 -0
  10. package/dist/_contracts/http.js +114 -0
  11. package/dist/_contracts/index.d.ts +28 -0
  12. package/dist/_contracts/index.js +29 -0
  13. package/dist/_contracts/managed-key.d.ts +74 -0
  14. package/dist/_contracts/managed-key.js +110 -0
  15. package/dist/_contracts/operations.d.ts +237 -0
  16. package/dist/_contracts/operations.js +632 -0
  17. package/dist/_contracts/provider-support.d.ts +220 -0
  18. package/dist/_contracts/provider-support.js +90 -0
  19. package/dist/_contracts/proxy-protocol.d.ts +257 -0
  20. package/dist/_contracts/proxy-protocol.js +234 -0
  21. package/dist/_contracts/proxy-validation.d.ts +19 -0
  22. package/dist/_contracts/proxy-validation.js +51 -0
  23. package/dist/_contracts/run-artifacts.d.ts +47 -0
  24. package/dist/_contracts/run-artifacts.js +101 -0
  25. package/dist/_contracts/run-config.d.ts +304 -0
  26. package/dist/_contracts/run-config.js +659 -0
  27. package/dist/_contracts/run-cost.d.ts +125 -0
  28. package/dist/_contracts/run-cost.js +616 -0
  29. package/dist/_contracts/run-custody.d.ts +226 -0
  30. package/dist/_contracts/run-custody.js +465 -0
  31. package/dist/_contracts/run-record.d.ts +127 -0
  32. package/dist/_contracts/run-record.js +177 -0
  33. package/dist/_contracts/run-retention.d.ts +213 -0
  34. package/dist/_contracts/run-retention.js +484 -0
  35. package/dist/_contracts/run-unit.d.ts +194 -0
  36. package/dist/_contracts/run-unit.js +215 -0
  37. package/dist/_contracts/runner-event.d.ts +114 -0
  38. package/dist/_contracts/runner-event.js +187 -0
  39. package/dist/_contracts/runtime-manifest.d.ts +106 -0
  40. package/dist/_contracts/runtime-manifest.js +98 -0
  41. package/dist/_contracts/runtime-security-profile.d.ts +27 -0
  42. package/dist/_contracts/runtime-security-profile.js +82 -0
  43. package/dist/_contracts/runtime-sizes.d.ts +144 -0
  44. package/dist/_contracts/runtime-sizes.js +136 -0
  45. package/dist/_contracts/runtime-types.d.ts +212 -0
  46. package/dist/_contracts/runtime-types.js +2 -0
  47. package/dist/_contracts/sdk-errors.d.ts +34 -0
  48. package/dist/_contracts/sdk-errors.js +52 -0
  49. package/dist/_contracts/sdk-secrets.d.ts +31 -0
  50. package/dist/_contracts/sdk-secrets.js +220 -0
  51. package/dist/_contracts/side-effect-audit.d.ts +129 -0
  52. package/dist/_contracts/side-effect-audit.js +494 -0
  53. package/dist/_contracts/sse.d.ts +74 -0
  54. package/dist/_contracts/sse.js +0 -0
  55. package/dist/_contracts/stable.d.ts +26 -0
  56. package/dist/_contracts/stable.js +44 -0
  57. package/dist/_contracts/status.d.ts +19 -0
  58. package/dist/_contracts/status.js +61 -0
  59. package/dist/_contracts/submission.d.ts +383 -0
  60. package/dist/_contracts/submission.js +1380 -0
  61. package/dist/agents-md.d.ts +46 -0
  62. package/dist/agents-md.js +83 -0
  63. package/dist/agents-md.js.map +1 -0
  64. package/dist/asset-upload.d.ts +66 -0
  65. package/dist/asset-upload.js +168 -0
  66. package/dist/asset-upload.js.map +1 -0
  67. package/dist/bundle.d.ts +33 -0
  68. package/dist/bundle.js +89 -0
  69. package/dist/bundle.js.map +1 -0
  70. package/dist/cli.mjs +4140 -0
  71. package/dist/cli.mjs.sha256 +1 -0
  72. package/dist/client.d.ts +460 -0
  73. package/dist/client.js +857 -0
  74. package/dist/client.js.map +1 -0
  75. package/dist/fetch-archive.d.ts +16 -0
  76. package/dist/fetch-archive.js +170 -0
  77. package/dist/fetch-archive.js.map +1 -0
  78. package/dist/file.d.ts +57 -0
  79. package/dist/file.js +153 -0
  80. package/dist/file.js.map +1 -0
  81. package/dist/index.d.ts +30 -0
  82. package/dist/index.js +34 -0
  83. package/dist/index.js.map +1 -0
  84. package/dist/mcp-server.d.ts +84 -0
  85. package/dist/mcp-server.js +114 -0
  86. package/dist/mcp-server.js.map +1 -0
  87. package/dist/node-fs.d.ts +12 -0
  88. package/dist/node-fs.js +44 -0
  89. package/dist/node-fs.js.map +1 -0
  90. package/dist/proxy-endpoint.d.ts +131 -0
  91. package/dist/proxy-endpoint.js +147 -0
  92. package/dist/proxy-endpoint.js.map +1 -0
  93. package/dist/skill.d.ts +117 -0
  94. package/dist/skill.js +169 -0
  95. package/dist/skill.js.map +1 -0
  96. package/dist/version.d.ts +9 -0
  97. package/dist/version.js +10 -0
  98. package/dist/version.js.map +1 -0
  99. package/docs/cleanup.md +38 -0
  100. package/docs/credentials.md +153 -0
  101. package/docs/events.md +76 -0
  102. package/docs/mcp.md +47 -0
  103. package/docs/outputs.md +157 -0
  104. package/docs/product-boundaries.md +57 -0
  105. package/docs/provider-runtime-capabilities.md +103 -0
  106. package/docs/quickstart.md +110 -0
  107. package/docs/release.md +99 -0
  108. package/docs/run-config.md +53 -0
  109. package/docs/run-record.md +39 -0
  110. package/docs/skills.md +139 -0
  111. package/docs/testing.md +29 -0
  112. package/package.json +47 -0
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Runtime manifest: the per-run, per-provider description of where
3
+ * aex places things inside the agent container, plus the merged
4
+ * env-var bag delivered via `RUNTIME.env` / `RUNTIME.json`.
5
+ *
6
+ * The hosted API computes a manifest at submitRun-response time
7
+ * (from the validated submission + the chosen provider) via
8
+ * {@link buildRuntimeManifest} and echoes it on the wire as
9
+ * `Run.runtimeManifest`, so caller code (anyone rendering catalog markdown
10
+ * pre-submission, or resolving aex's in-container path strings) doesn't
11
+ * have to guess.
12
+ * The managed runtime materialises the actual `RUNTIME.env` / `RUNTIME.json`
13
+ * files in-container from the same provider + envVars inputs, so the
14
+ * SDK-side view and the in-container view describe the same layout.
15
+ *
16
+ * Manifest values are derived, never persisted separately — the source
17
+ * of truth for the customer half remains `submission.environment.envVars`
18
+ * on the run row; the aex half is constant for a given
19
+ * provider+SDK-version pair.
20
+ */
21
+ /**
22
+ * Managed-runner container paths. Kept here so the BFF, worker, and
23
+ * in-container bridge render identical values; runtime bootstrap constants are
24
+ * validated against these by a regression test
25
+ * (`packages/contracts/test/runtime-manifest.test.ts`).
26
+ */
27
+ const ANTHROPIC_PATHS = Object.freeze({
28
+ skillsRoot: "/workspace/skills",
29
+ filesRoot: "/mnt/session/uploads/aex/files",
30
+ assetsRoot: "/mnt/session/uploads/aex/assets",
31
+ aexCli: "/mnt/session/uploads/aex/aex",
32
+ indexJson: "/mnt/session/uploads/aex/index.json",
33
+ readme: "/mnt/session/uploads/aex/SKILLS.md",
34
+ runtimeJson: "/mnt/session/uploads/aex/RUNTIME.json",
35
+ runtimeEnv: "/mnt/session/uploads/aex/RUNTIME.env"
36
+ });
37
+ /**
38
+ * Container paths exposed for a given provider. Today only
39
+ * `"anthropic"` is recognised; calling with anything else throws so
40
+ * forward-compat surfaces the missing provider entry instead of
41
+ * silently emitting Anthropic paths.
42
+ */
43
+ export function runtimePathsFor(provider) {
44
+ if (provider === "anthropic") {
45
+ return ANTHROPIC_PATHS;
46
+ }
47
+ throw new Error(`Unknown runtime provider: ${provider}`);
48
+ }
49
+ /**
50
+ * Reserved env-var prefix for aex-set runtime keys. Mirrors the
51
+ * constant in `submission.ts`; duplicated here so this module is
52
+ * self-contained and can be tree-shaken by SDK consumers that don't
53
+ * need the submission parser.
54
+ */
55
+ const AEX_PREFIX = "AEX_";
56
+ /**
57
+ * Build the runtime manifest for a single submission. Pure function:
58
+ * same input → same output → safe to call from the BFF response path
59
+ * and from the worker bootstrap path with identical results.
60
+ */
61
+ export function buildRuntimeManifest(input) {
62
+ const paths = runtimePathsFor(input.provider);
63
+ const aexEnvVars = {
64
+ AEX_PROVIDER: input.provider,
65
+ AEX_CLI: paths.aexCli,
66
+ AEX_SKILLS_ROOT: paths.skillsRoot,
67
+ AEX_FILES_ROOT: paths.filesRoot,
68
+ AEX_ASSETS_ROOT: paths.assetsRoot,
69
+ AEX_INDEX_JSON: paths.indexJson,
70
+ AEX_README: paths.readme,
71
+ AEX_RUNTIME_JSON: paths.runtimeJson,
72
+ AEX_RUNTIME_ENV: paths.runtimeEnv
73
+ };
74
+ const customerEnvVars = {};
75
+ for (const [key, value] of Object.entries(input.customerEnvVars ?? {})) {
76
+ if (key.startsWith(AEX_PREFIX)) {
77
+ // Defensive filter; the strict parser rejects this at submit
78
+ // time. If a stored snapshot somehow carries a reserved key
79
+ // we drop it rather than letting it shadow our value.
80
+ continue;
81
+ }
82
+ customerEnvVars[key] = value;
83
+ }
84
+ const envVars = Object.freeze({ ...aexEnvVars, ...customerEnvVars });
85
+ return Object.freeze({
86
+ provider: input.provider,
87
+ skillsRoot: paths.skillsRoot,
88
+ filesRoot: paths.filesRoot,
89
+ assetsRoot: paths.assetsRoot,
90
+ aexCli: paths.aexCli,
91
+ indexJson: paths.indexJson,
92
+ readme: paths.readme,
93
+ runtimeJson: paths.runtimeJson,
94
+ runtimeEnv: paths.runtimeEnv,
95
+ envVars
96
+ });
97
+ }
98
+ //# sourceMappingURL=runtime-manifest.js.map
@@ -0,0 +1,27 @@
1
+ export declare const RUNTIME_SECURITY_PROFILES: readonly ["strict", "standard", "developer"];
2
+ export type RuntimeSecurityProfileName = (typeof RUNTIME_SECURITY_PROFILES)[number];
3
+ export interface RuntimeSecurityProfile {
4
+ readonly name: RuntimeSecurityProfileName;
5
+ readonly defaultNetworkingMode: "limited" | "open";
6
+ readonly allowOpenNetworking: boolean;
7
+ readonly allowRuntimePackages: boolean;
8
+ readonly allowCustomerEnvVars: boolean;
9
+ readonly allowProxyEndpoints: boolean;
10
+ readonly allowMcpServers: boolean;
11
+ }
12
+ export interface RuntimeSecurityProfileEvaluationInput {
13
+ readonly networkingMode?: "limited" | "open";
14
+ readonly packageCount?: number;
15
+ readonly customerEnvVarCount?: number;
16
+ readonly proxyEndpointCount?: number;
17
+ readonly mcpServerCount?: number;
18
+ }
19
+ export interface RuntimeSecurityProfileViolation {
20
+ readonly field: string;
21
+ readonly reason: string;
22
+ }
23
+ export declare const RUNTIME_SECURITY_PROFILE_CONFIG: Readonly<Record<RuntimeSecurityProfileName, RuntimeSecurityProfile>>;
24
+ export declare function parseRuntimeSecurityProfile(input: unknown): RuntimeSecurityProfileName | undefined;
25
+ export declare function resolveRuntimeSecurityProfile(input: RuntimeSecurityProfileName | undefined): RuntimeSecurityProfile;
26
+ export declare function serializeRuntimeSecurityProfile(profile: RuntimeSecurityProfileName): string;
27
+ export declare function evaluateRuntimeSecurityProfile(profileName: RuntimeSecurityProfileName | undefined, input: RuntimeSecurityProfileEvaluationInput): readonly RuntimeSecurityProfileViolation[];
@@ -0,0 +1,82 @@
1
+ export const RUNTIME_SECURITY_PROFILES = ["strict", "standard", "developer"];
2
+ export const RUNTIME_SECURITY_PROFILE_CONFIG = Object.freeze({
3
+ strict: Object.freeze({
4
+ name: "strict",
5
+ defaultNetworkingMode: "limited",
6
+ allowOpenNetworking: false,
7
+ allowRuntimePackages: false,
8
+ allowCustomerEnvVars: true,
9
+ allowProxyEndpoints: true,
10
+ allowMcpServers: true
11
+ }),
12
+ standard: Object.freeze({
13
+ name: "standard",
14
+ defaultNetworkingMode: "limited",
15
+ allowOpenNetworking: true,
16
+ allowRuntimePackages: true,
17
+ allowCustomerEnvVars: true,
18
+ allowProxyEndpoints: true,
19
+ allowMcpServers: true
20
+ }),
21
+ developer: Object.freeze({
22
+ name: "developer",
23
+ defaultNetworkingMode: "open",
24
+ allowOpenNetworking: true,
25
+ allowRuntimePackages: true,
26
+ allowCustomerEnvVars: true,
27
+ allowProxyEndpoints: true,
28
+ allowMcpServers: true
29
+ })
30
+ });
31
+ export function parseRuntimeSecurityProfile(input) {
32
+ if (input === undefined || input === null) {
33
+ return undefined;
34
+ }
35
+ if (typeof input !== "string" || !RUNTIME_SECURITY_PROFILES.includes(input)) {
36
+ throw new Error(`securityProfile must be one of: ${RUNTIME_SECURITY_PROFILES.join(", ")} (got ${JSON.stringify(input)})`);
37
+ }
38
+ return input;
39
+ }
40
+ export function resolveRuntimeSecurityProfile(input) {
41
+ return RUNTIME_SECURITY_PROFILE_CONFIG[input ?? "standard"];
42
+ }
43
+ export function serializeRuntimeSecurityProfile(profile) {
44
+ parseRuntimeSecurityProfile(profile);
45
+ return profile;
46
+ }
47
+ export function evaluateRuntimeSecurityProfile(profileName, input) {
48
+ const profile = resolveRuntimeSecurityProfile(profileName);
49
+ const violations = [];
50
+ if (input.networkingMode === "open" && !profile.allowOpenNetworking) {
51
+ violations.push({
52
+ field: "environment.networking.mode",
53
+ reason: `${profile.name} requires limited networking`
54
+ });
55
+ }
56
+ if ((input.packageCount ?? 0) > 0 && !profile.allowRuntimePackages) {
57
+ violations.push({
58
+ field: "environment.packages",
59
+ reason: `${profile.name} does not allow runtime package installs`
60
+ });
61
+ }
62
+ if ((input.customerEnvVarCount ?? 0) > 0 && !profile.allowCustomerEnvVars) {
63
+ violations.push({
64
+ field: "environment.envVars",
65
+ reason: `${profile.name} does not allow customer runtime env vars`
66
+ });
67
+ }
68
+ if ((input.proxyEndpointCount ?? 0) > 0 && !profile.allowProxyEndpoints) {
69
+ violations.push({
70
+ field: "proxyEndpoints",
71
+ reason: `${profile.name} does not allow HTTP proxy endpoints`
72
+ });
73
+ }
74
+ if ((input.mcpServerCount ?? 0) > 0 && !profile.allowMcpServers) {
75
+ violations.push({
76
+ field: "submission.mcpServers",
77
+ reason: `${profile.name} does not allow MCP servers`
78
+ });
79
+ }
80
+ return Object.freeze(violations);
81
+ }
82
+ //# sourceMappingURL=runtime-security-profile.js.map
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Managed runtime sizing presets.
3
+ *
4
+ * The public contract exposes product-level runtime size tokens, not host
5
+ * implementation details. The closed token set keeps invalid resource pairings
6
+ * out of the wire contract while leaving the concrete host mapping private.
7
+ */
8
+ export interface RuntimeResources {
9
+ readonly cpus: number;
10
+ readonly memoryMb: number;
11
+ }
12
+ /**
13
+ * The single source of truth: every offered preset, keyed by its wire token.
14
+ * Tokens intentionally remain stable product presets.
15
+ */
16
+ export declare const RUNTIME_SIZE_PRESETS: {
17
+ readonly "shared-1x-256mb": {
18
+ readonly cpus: 1;
19
+ readonly memoryMb: 256;
20
+ };
21
+ readonly "shared-1x-512mb": {
22
+ readonly cpus: 1;
23
+ readonly memoryMb: 512;
24
+ };
25
+ readonly "shared-1x-1gb": {
26
+ readonly cpus: 1;
27
+ readonly memoryMb: 1024;
28
+ };
29
+ readonly "shared-1x-2gb": {
30
+ readonly cpus: 1;
31
+ readonly memoryMb: 2048;
32
+ };
33
+ readonly "shared-2x-512mb": {
34
+ readonly cpus: 2;
35
+ readonly memoryMb: 512;
36
+ };
37
+ readonly "shared-2x-1gb": {
38
+ readonly cpus: 2;
39
+ readonly memoryMb: 1024;
40
+ };
41
+ readonly "shared-2x-2gb": {
42
+ readonly cpus: 2;
43
+ readonly memoryMb: 2048;
44
+ };
45
+ readonly "shared-2x-4gb": {
46
+ readonly cpus: 2;
47
+ readonly memoryMb: 4096;
48
+ };
49
+ readonly "shared-4x-1gb": {
50
+ readonly cpus: 4;
51
+ readonly memoryMb: 1024;
52
+ };
53
+ readonly "shared-4x-2gb": {
54
+ readonly cpus: 4;
55
+ readonly memoryMb: 2048;
56
+ };
57
+ readonly "shared-4x-4gb": {
58
+ readonly cpus: 4;
59
+ readonly memoryMb: 4096;
60
+ };
61
+ readonly "shared-4x-8gb": {
62
+ readonly cpus: 4;
63
+ readonly memoryMb: 8192;
64
+ };
65
+ readonly "shared-8x-2gb": {
66
+ readonly cpus: 8;
67
+ readonly memoryMb: 2048;
68
+ };
69
+ readonly "shared-8x-4gb": {
70
+ readonly cpus: 8;
71
+ readonly memoryMb: 4096;
72
+ };
73
+ readonly "shared-8x-8gb": {
74
+ readonly cpus: 8;
75
+ readonly memoryMb: 8192;
76
+ };
77
+ readonly "shared-8x-16gb": {
78
+ readonly cpus: 8;
79
+ readonly memoryMb: 16384;
80
+ };
81
+ };
82
+ /** The accepted runtime-size values (the wire/CLI tokens). */
83
+ export type RuntimeSize = keyof typeof RUNTIME_SIZE_PRESETS;
84
+ /** All preset tokens, ordered as declared. Handy for CLI help + validation. */
85
+ export declare const RUNTIME_SIZES: readonly RuntimeSize[];
86
+ /** Default when `runtimeSize` is omitted. */
87
+ export declare const DEFAULT_RUNTIME_SIZE: RuntimeSize;
88
+ /**
89
+ * Symbol-style accessors for TS callers. `RuntimeSizes.SHARED_2X_2GB`
90
+ * resolves to the wire token `"shared-2x-2gb"`.
91
+ */
92
+ export declare const RuntimeSizes: {
93
+ readonly SHARED_1X_256MB: "shared-1x-256mb";
94
+ readonly SHARED_1X_512MB: "shared-1x-512mb";
95
+ readonly SHARED_1X_1GB: "shared-1x-1gb";
96
+ readonly SHARED_1X_2GB: "shared-1x-2gb";
97
+ readonly SHARED_2X_512MB: "shared-2x-512mb";
98
+ readonly SHARED_2X_1GB: "shared-2x-1gb";
99
+ readonly SHARED_2X_2GB: "shared-2x-2gb";
100
+ readonly SHARED_2X_4GB: "shared-2x-4gb";
101
+ readonly SHARED_4X_1GB: "shared-4x-1gb";
102
+ readonly SHARED_4X_2GB: "shared-4x-2gb";
103
+ readonly SHARED_4X_4GB: "shared-4x-4gb";
104
+ readonly SHARED_4X_8GB: "shared-4x-8gb";
105
+ readonly SHARED_8X_2GB: "shared-8x-2gb";
106
+ readonly SHARED_8X_4GB: "shared-8x-4gb";
107
+ readonly SHARED_8X_8GB: "shared-8x-8gb";
108
+ readonly SHARED_8X_16GB: "shared-8x-16gb";
109
+ };
110
+ /** Resolve a preset token to its product-level resource descriptor. */
111
+ export declare function runtimeResources(size: RuntimeSize): RuntimeResources;
112
+ /**
113
+ * Validate the wire `runtimeSize` field. `undefined` (omitted) is allowed and
114
+ * consumers apply {@link DEFAULT_RUNTIME_SIZE}.
115
+ */
116
+ export declare function parseRuntimeSize(input: unknown): RuntimeSize | undefined;
117
+ /** Default run deadline when `timeout` is omitted (1 hour). */
118
+ export declare const DEFAULT_RUN_TIMEOUT_MS: number;
119
+ /** Hard ceiling on a run deadline (6 hours). */
120
+ export declare const MAX_RUN_TIMEOUT_MS: number;
121
+ /** Floor on a run deadline (1 minute). */
122
+ export declare const MIN_RUN_TIMEOUT_MS: number;
123
+ /**
124
+ * Parse a human duration string (`"1h"`, `"90m"`, `"3600s"`, `"500ms"`, or a
125
+ * bare-ms integer) into milliseconds. Throws on malformed input.
126
+ */
127
+ export declare function parseDurationToMs(input: string): number;
128
+ /**
129
+ * Validate the wire `timeout` field (a duration string) into a bounded ms
130
+ * value. `undefined` (omitted) returns `undefined`; the consumer applies
131
+ * {@link DEFAULT_RUN_TIMEOUT_MS}.
132
+ */
133
+ export declare function parseRunTimeout(input: unknown): number | undefined;
134
+ /** Apply the default when a parsed `timeoutMs` is absent. */
135
+ export declare function resolveRunTimeoutMs(timeoutMs: number | undefined): number;
136
+ /** Format a millisecond deadline as a second-granularity duration string. */
137
+ export declare function orchestrationTimeoutString(ms: number): string;
138
+ /** Runtime process: time to wait after graceful interrupt before hard kill. */
139
+ export declare const RUN_PROCESS_KILL_GRACE_MS: number;
140
+ /**
141
+ * Orchestrator: extra window past `timeoutMs` to wait for terminal callback
142
+ * before host-level cleanup.
143
+ */
144
+ export declare const RUN_TERMINAL_GRACE_MS: number;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Managed runtime sizing presets.
3
+ *
4
+ * The public contract exposes product-level runtime size tokens, not host
5
+ * implementation details. The closed token set keeps invalid resource pairings
6
+ * out of the wire contract while leaving the concrete host mapping private.
7
+ */
8
+ /**
9
+ * The single source of truth: every offered preset, keyed by its wire token.
10
+ * Tokens intentionally remain stable product presets.
11
+ */
12
+ export const RUNTIME_SIZE_PRESETS = {
13
+ "shared-1x-256mb": { cpus: 1, memoryMb: 256 },
14
+ "shared-1x-512mb": { cpus: 1, memoryMb: 512 },
15
+ "shared-1x-1gb": { cpus: 1, memoryMb: 1024 },
16
+ "shared-1x-2gb": { cpus: 1, memoryMb: 2048 },
17
+ "shared-2x-512mb": { cpus: 2, memoryMb: 512 },
18
+ "shared-2x-1gb": { cpus: 2, memoryMb: 1024 },
19
+ "shared-2x-2gb": { cpus: 2, memoryMb: 2048 },
20
+ "shared-2x-4gb": { cpus: 2, memoryMb: 4096 },
21
+ "shared-4x-1gb": { cpus: 4, memoryMb: 1024 },
22
+ "shared-4x-2gb": { cpus: 4, memoryMb: 2048 },
23
+ "shared-4x-4gb": { cpus: 4, memoryMb: 4096 },
24
+ "shared-4x-8gb": { cpus: 4, memoryMb: 8192 },
25
+ "shared-8x-2gb": { cpus: 8, memoryMb: 2048 },
26
+ "shared-8x-4gb": { cpus: 8, memoryMb: 4096 },
27
+ "shared-8x-8gb": { cpus: 8, memoryMb: 8192 },
28
+ "shared-8x-16gb": { cpus: 8, memoryMb: 16384 }
29
+ };
30
+ /** All preset tokens, ordered as declared. Handy for CLI help + validation. */
31
+ export const RUNTIME_SIZES = Object.keys(RUNTIME_SIZE_PRESETS);
32
+ /** Default when `runtimeSize` is omitted. */
33
+ export const DEFAULT_RUNTIME_SIZE = "shared-1x-512mb";
34
+ /**
35
+ * Symbol-style accessors for TS callers. `RuntimeSizes.SHARED_2X_2GB`
36
+ * resolves to the wire token `"shared-2x-2gb"`.
37
+ */
38
+ export const RuntimeSizes = {
39
+ SHARED_1X_256MB: "shared-1x-256mb",
40
+ SHARED_1X_512MB: "shared-1x-512mb",
41
+ SHARED_1X_1GB: "shared-1x-1gb",
42
+ SHARED_1X_2GB: "shared-1x-2gb",
43
+ SHARED_2X_512MB: "shared-2x-512mb",
44
+ SHARED_2X_1GB: "shared-2x-1gb",
45
+ SHARED_2X_2GB: "shared-2x-2gb",
46
+ SHARED_2X_4GB: "shared-2x-4gb",
47
+ SHARED_4X_1GB: "shared-4x-1gb",
48
+ SHARED_4X_2GB: "shared-4x-2gb",
49
+ SHARED_4X_4GB: "shared-4x-4gb",
50
+ SHARED_4X_8GB: "shared-4x-8gb",
51
+ SHARED_8X_2GB: "shared-8x-2gb",
52
+ SHARED_8X_4GB: "shared-8x-4gb",
53
+ SHARED_8X_8GB: "shared-8x-8gb",
54
+ SHARED_8X_16GB: "shared-8x-16gb"
55
+ };
56
+ /** Resolve a preset token to its product-level resource descriptor. */
57
+ export function runtimeResources(size) {
58
+ return RUNTIME_SIZE_PRESETS[size];
59
+ }
60
+ /**
61
+ * Validate the wire `runtimeSize` field. `undefined` (omitted) is allowed and
62
+ * consumers apply {@link DEFAULT_RUNTIME_SIZE}.
63
+ */
64
+ export function parseRuntimeSize(input) {
65
+ if (input === undefined) {
66
+ return undefined;
67
+ }
68
+ if (typeof input !== "string" || !RUNTIME_SIZES.includes(input)) {
69
+ throw new Error(`runtimeSize must be one of: ${RUNTIME_SIZES.join(", ")} (got ${JSON.stringify(input)})`);
70
+ }
71
+ return input;
72
+ }
73
+ // ===========================================================================
74
+ // Run timeout
75
+ // ===========================================================================
76
+ /** Default run deadline when `timeout` is omitted (1 hour). */
77
+ export const DEFAULT_RUN_TIMEOUT_MS = 60 * 60 * 1000;
78
+ /** Hard ceiling on a run deadline (6 hours). */
79
+ export const MAX_RUN_TIMEOUT_MS = 6 * 60 * 60 * 1000;
80
+ /** Floor on a run deadline (1 minute). */
81
+ export const MIN_RUN_TIMEOUT_MS = 60 * 1000;
82
+ const DURATION_PATTERN = /^(\d+(?:\.\d+)?)(ms|s|m|h)?$/;
83
+ /**
84
+ * Parse a human duration string (`"1h"`, `"90m"`, `"3600s"`, `"500ms"`, or a
85
+ * bare-ms integer) into milliseconds. Throws on malformed input.
86
+ */
87
+ export function parseDurationToMs(input) {
88
+ const match = DURATION_PATTERN.exec(input.trim());
89
+ if (!match) {
90
+ throw new Error(`invalid duration ${JSON.stringify(input)} (expected e.g. "1h", "90m", "30s", "500ms", or a bare ms integer)`);
91
+ }
92
+ const value = Number(match[1]);
93
+ if (!Number.isFinite(value) || value < 0) {
94
+ throw new Error(`invalid duration ${JSON.stringify(input)} (must be a non-negative number)`);
95
+ }
96
+ const unit = match[2] ?? "ms";
97
+ const factor = unit === "h" ? 3_600_000 : unit === "m" ? 60_000 : unit === "s" ? 1_000 : 1;
98
+ return Math.round(value * factor);
99
+ }
100
+ /**
101
+ * Validate the wire `timeout` field (a duration string) into a bounded ms
102
+ * value. `undefined` (omitted) returns `undefined`; the consumer applies
103
+ * {@link DEFAULT_RUN_TIMEOUT_MS}.
104
+ */
105
+ export function parseRunTimeout(input) {
106
+ if (input === undefined) {
107
+ return undefined;
108
+ }
109
+ if (typeof input !== "string") {
110
+ throw new Error(`timeout must be a duration string (e.g. "1h", "30m"); got ${JSON.stringify(input)}`);
111
+ }
112
+ const ms = parseDurationToMs(input);
113
+ if (ms < MIN_RUN_TIMEOUT_MS) {
114
+ throw new Error(`timeout must be at least ${MIN_RUN_TIMEOUT_MS}ms (1m); got ${ms}ms`);
115
+ }
116
+ if (ms > MAX_RUN_TIMEOUT_MS) {
117
+ throw new Error(`timeout must be at most ${MAX_RUN_TIMEOUT_MS}ms (6h); got ${ms}ms`);
118
+ }
119
+ return ms;
120
+ }
121
+ /** Apply the default when a parsed `timeoutMs` is absent. */
122
+ export function resolveRunTimeoutMs(timeoutMs) {
123
+ return timeoutMs ?? DEFAULT_RUN_TIMEOUT_MS;
124
+ }
125
+ /** Format a millisecond deadline as a second-granularity duration string. */
126
+ export function orchestrationTimeoutString(ms) {
127
+ return `${Math.max(1, Math.ceil(ms / 1000))}s`;
128
+ }
129
+ /** Runtime process: time to wait after graceful interrupt before hard kill. */
130
+ export const RUN_PROCESS_KILL_GRACE_MS = 60 * 1000;
131
+ /**
132
+ * Orchestrator: extra window past `timeoutMs` to wait for terminal callback
133
+ * before host-level cleanup.
134
+ */
135
+ export const RUN_TERMINAL_GRACE_MS = 90 * 1000;
136
+ //# sourceMappingURL=runtime-sizes.js.map