@a5c-ai/babysitter-sdk 0.0.169 → 0.0.170-staging.00aac85c
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/dist/cli/commands/configure.d.ts +124 -0
- package/dist/cli/commands/configure.d.ts.map +1 -0
- package/dist/cli/commands/configure.js +514 -0
- package/dist/cli/commands/health.d.ts +89 -0
- package/dist/cli/commands/health.d.ts.map +1 -0
- package/dist/cli/commands/health.js +579 -0
- package/dist/cli/commands/hookLog.d.ts +15 -0
- package/dist/cli/commands/hookLog.d.ts.map +1 -0
- package/dist/cli/commands/hookLog.js +286 -0
- package/dist/cli/commands/hookRun.d.ts +20 -0
- package/dist/cli/commands/hookRun.d.ts.map +1 -0
- package/dist/cli/commands/hookRun.js +544 -0
- package/dist/cli/commands/runExecuteTasks.d.ts +42 -0
- package/dist/cli/commands/runExecuteTasks.d.ts.map +1 -0
- package/dist/cli/commands/runExecuteTasks.js +377 -0
- package/dist/cli/commands/runIterate.d.ts +5 -1
- package/dist/cli/commands/runIterate.d.ts.map +1 -1
- package/dist/cli/commands/runIterate.js +75 -6
- package/dist/cli/commands/session.d.ts +97 -0
- package/dist/cli/commands/session.d.ts.map +1 -0
- package/dist/cli/commands/session.js +922 -0
- package/dist/cli/commands/skill.d.ts +87 -0
- package/dist/cli/commands/skill.d.ts.map +1 -0
- package/dist/cli/commands/skill.js +869 -0
- package/dist/cli/completionProof.d.ts +4 -0
- package/dist/cli/completionProof.d.ts.map +1 -0
- package/dist/cli/{completionSecret.js → completionProof.js} +7 -7
- package/dist/cli/main.d.ts +14 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +649 -16
- package/dist/config/defaults.d.ts +165 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +281 -0
- package/dist/config/index.d.ts +25 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +35 -0
- package/dist/hooks/dispatcher.d.ts.map +1 -1
- package/dist/hooks/dispatcher.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/runtime/constants.d.ts +1 -1
- package/dist/runtime/constants.d.ts.map +1 -1
- package/dist/runtime/createRun.d.ts.map +1 -1
- package/dist/runtime/createRun.js +7 -3
- package/dist/runtime/exceptions.d.ts +186 -3
- package/dist/runtime/exceptions.d.ts.map +1 -1
- package/dist/runtime/exceptions.js +416 -15
- package/dist/runtime/types.d.ts +1 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/session/index.d.ts +9 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +30 -0
- package/dist/session/parse.d.ts +45 -0
- package/dist/session/parse.d.ts.map +1 -0
- package/dist/session/parse.js +159 -0
- package/dist/session/types.d.ts +194 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +45 -0
- package/dist/session/write.d.ts +50 -0
- package/dist/session/write.d.ts.map +1 -0
- package/dist/session/write.js +196 -0
- package/dist/storage/createRunDir.d.ts.map +1 -1
- package/dist/storage/createRunDir.js +1 -0
- package/dist/storage/paths.d.ts +5 -1
- package/dist/storage/paths.d.ts.map +1 -1
- package/dist/storage/paths.js +6 -1
- package/dist/storage/types.d.ts +3 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/tasks/kinds/index.d.ts.map +1 -1
- package/dist/tasks/kinds/index.js +6 -1
- package/dist/testing/runHarness.d.ts.map +1 -1
- package/dist/testing/runHarness.js +5 -1
- package/package.json +1 -2
- package/dist/cli/completionSecret.d.ts +0 -4
- package/dist/cli/completionSecret.d.ts.map +0 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Configuration Defaults for Babysitter SDK
|
|
3
|
+
*
|
|
4
|
+
* This module serves as the single source of truth for all default configuration
|
|
5
|
+
* values used throughout the babysitter SDK. Import from here instead of using
|
|
6
|
+
* scattered magic numbers and strings.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Log level type for SDK logging configuration
|
|
10
|
+
*/
|
|
11
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
|
|
12
|
+
/**
|
|
13
|
+
* Complete configuration interface for the Babysitter SDK
|
|
14
|
+
*/
|
|
15
|
+
export interface BabysitterConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Directory where run state is stored, relative to the working directory.
|
|
18
|
+
* Contains journals, task definitions, blobs, and state snapshots.
|
|
19
|
+
*/
|
|
20
|
+
runsDir: string;
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of iterations allowed before the run harness terminates.
|
|
23
|
+
* Prevents infinite loops in process orchestration.
|
|
24
|
+
*/
|
|
25
|
+
maxIterations: number;
|
|
26
|
+
/**
|
|
27
|
+
* Quality threshold percentage (0-100) for task completion validation.
|
|
28
|
+
* Tasks below this threshold may be flagged for review.
|
|
29
|
+
*/
|
|
30
|
+
qualityThreshold: number;
|
|
31
|
+
/**
|
|
32
|
+
* Default timeout in milliseconds for task execution.
|
|
33
|
+
* Individual tasks may override this value.
|
|
34
|
+
*/
|
|
35
|
+
timeout: number;
|
|
36
|
+
/**
|
|
37
|
+
* Minimum log level for SDK logging output.
|
|
38
|
+
* Messages below this level will be suppressed.
|
|
39
|
+
*/
|
|
40
|
+
logLevel: LogLevel;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to allow logging of potentially sensitive values.
|
|
43
|
+
* When false, secrets and sensitive data are redacted from logs.
|
|
44
|
+
*/
|
|
45
|
+
allowSecretLogs: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Default timeout in milliseconds for hook execution.
|
|
48
|
+
* Hooks that exceed this duration will be terminated.
|
|
49
|
+
*/
|
|
50
|
+
hookTimeout: number;
|
|
51
|
+
/**
|
|
52
|
+
* Default timeout in milliseconds for node task execution.
|
|
53
|
+
* Node.js child processes are terminated if they exceed this limit.
|
|
54
|
+
*/
|
|
55
|
+
nodeTaskTimeout: number;
|
|
56
|
+
/**
|
|
57
|
+
* Default step interval in milliseconds for deterministic clock simulation.
|
|
58
|
+
* Used in testing to advance simulated time predictably.
|
|
59
|
+
*/
|
|
60
|
+
clockStepMs: number;
|
|
61
|
+
/**
|
|
62
|
+
* Default epoch timestamp (ms) for deterministic clock starting point.
|
|
63
|
+
* Used in testing for reproducible timing behavior.
|
|
64
|
+
*/
|
|
65
|
+
clockStartMs: number;
|
|
66
|
+
/**
|
|
67
|
+
* Storage layout version identifier.
|
|
68
|
+
* Used to ensure compatibility between SDK versions and stored data.
|
|
69
|
+
*/
|
|
70
|
+
layoutVersion: string;
|
|
71
|
+
/**
|
|
72
|
+
* Maximum size in bytes for inline result preview in CLI output.
|
|
73
|
+
* Results larger than this are written to files instead.
|
|
74
|
+
*/
|
|
75
|
+
largeResultPreviewLimit: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Validation result for configuration checks
|
|
79
|
+
*/
|
|
80
|
+
export interface ConfigValidationResult {
|
|
81
|
+
/**
|
|
82
|
+
* Whether the configuration passed all validation checks
|
|
83
|
+
*/
|
|
84
|
+
valid: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Array of validation error messages, empty if valid
|
|
87
|
+
*/
|
|
88
|
+
errors: string[];
|
|
89
|
+
/**
|
|
90
|
+
* Array of validation warning messages (non-fatal issues)
|
|
91
|
+
*/
|
|
92
|
+
warnings: string[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Environment variable names for configuration overrides
|
|
96
|
+
*/
|
|
97
|
+
export declare const CONFIG_ENV_VARS: {
|
|
98
|
+
readonly RUNS_DIR: "BABYSITTER_RUNS_DIR";
|
|
99
|
+
readonly MAX_ITERATIONS: "BABYSITTER_MAX_ITERATIONS";
|
|
100
|
+
readonly QUALITY_THRESHOLD: "BABYSITTER_QUALITY_THRESHOLD";
|
|
101
|
+
readonly TIMEOUT: "BABYSITTER_TIMEOUT";
|
|
102
|
+
readonly LOG_LEVEL: "BABYSITTER_LOG_LEVEL";
|
|
103
|
+
readonly ALLOW_SECRET_LOGS: "BABYSITTER_ALLOW_SECRET_LOGS";
|
|
104
|
+
readonly HOOK_TIMEOUT: "BABYSITTER_HOOK_TIMEOUT";
|
|
105
|
+
readonly NODE_TASK_TIMEOUT: "BABYSITTER_NODE_TASK_TIMEOUT";
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Default configuration values for the Babysitter SDK.
|
|
109
|
+
*
|
|
110
|
+
* These defaults are used when no explicit configuration is provided.
|
|
111
|
+
* They can be overridden via environment variables or explicit config.
|
|
112
|
+
*/
|
|
113
|
+
export declare const DEFAULTS: Readonly<BabysitterConfig>;
|
|
114
|
+
/**
|
|
115
|
+
* Retrieves configuration with environment variable overrides merged in.
|
|
116
|
+
*
|
|
117
|
+
* Environment variables take precedence over defaults. This allows runtime
|
|
118
|
+
* configuration without code changes.
|
|
119
|
+
*
|
|
120
|
+
* @param overrides - Optional explicit overrides that take highest precedence
|
|
121
|
+
* @returns Complete configuration with all values resolved
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* // Get config with defaults and env var overrides
|
|
126
|
+
* const config = getConfig();
|
|
127
|
+
*
|
|
128
|
+
* // Get config with explicit overrides
|
|
129
|
+
* const customConfig = getConfig({ maxIterations: 500 });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function getConfig(overrides?: Partial<BabysitterConfig>): BabysitterConfig;
|
|
133
|
+
/**
|
|
134
|
+
* Validates a configuration object for correctness.
|
|
135
|
+
*
|
|
136
|
+
* Checks that all values are within acceptable ranges and of correct types.
|
|
137
|
+
* Returns detailed error and warning messages for any issues found.
|
|
138
|
+
*
|
|
139
|
+
* @param config - The configuration to validate
|
|
140
|
+
* @returns Validation result with errors and warnings
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const config = getConfig();
|
|
145
|
+
* const result = validateConfig(config);
|
|
146
|
+
* if (!result.valid) {
|
|
147
|
+
* console.error("Config errors:", result.errors);
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function validateConfig(config: BabysitterConfig): ConfigValidationResult;
|
|
152
|
+
/**
|
|
153
|
+
* Creates a frozen copy of the defaults for safe external use.
|
|
154
|
+
*
|
|
155
|
+
* @returns A read-only copy of the default configuration
|
|
156
|
+
*/
|
|
157
|
+
export declare function getDefaults(): Readonly<BabysitterConfig>;
|
|
158
|
+
/**
|
|
159
|
+
* Checks if a value is a valid log level.
|
|
160
|
+
*
|
|
161
|
+
* @param value - The value to check
|
|
162
|
+
* @returns true if the value is a valid LogLevel
|
|
163
|
+
*/
|
|
164
|
+
export declare function isValidLogLevel(value: unknown): value is LogLevel;
|
|
165
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;;OAGG;IACH,eAAe,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;CASlB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAwEtC,CAAC;AAiDX;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAqCjF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,gBAAgB,GAAG,sBAAsB,CA2E/E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAAC,gBAAgB,CAAC,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAEjE"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Centralized Configuration Defaults for Babysitter SDK
|
|
4
|
+
*
|
|
5
|
+
* This module serves as the single source of truth for all default configuration
|
|
6
|
+
* values used throughout the babysitter SDK. Import from here instead of using
|
|
7
|
+
* scattered magic numbers and strings.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DEFAULTS = exports.CONFIG_ENV_VARS = void 0;
|
|
11
|
+
exports.getConfig = getConfig;
|
|
12
|
+
exports.validateConfig = validateConfig;
|
|
13
|
+
exports.getDefaults = getDefaults;
|
|
14
|
+
exports.isValidLogLevel = isValidLogLevel;
|
|
15
|
+
/**
|
|
16
|
+
* Environment variable names for configuration overrides
|
|
17
|
+
*/
|
|
18
|
+
exports.CONFIG_ENV_VARS = {
|
|
19
|
+
RUNS_DIR: "BABYSITTER_RUNS_DIR",
|
|
20
|
+
MAX_ITERATIONS: "BABYSITTER_MAX_ITERATIONS",
|
|
21
|
+
QUALITY_THRESHOLD: "BABYSITTER_QUALITY_THRESHOLD",
|
|
22
|
+
TIMEOUT: "BABYSITTER_TIMEOUT",
|
|
23
|
+
LOG_LEVEL: "BABYSITTER_LOG_LEVEL",
|
|
24
|
+
ALLOW_SECRET_LOGS: "BABYSITTER_ALLOW_SECRET_LOGS",
|
|
25
|
+
HOOK_TIMEOUT: "BABYSITTER_HOOK_TIMEOUT",
|
|
26
|
+
NODE_TASK_TIMEOUT: "BABYSITTER_NODE_TASK_TIMEOUT",
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Default configuration values for the Babysitter SDK.
|
|
30
|
+
*
|
|
31
|
+
* These defaults are used when no explicit configuration is provided.
|
|
32
|
+
* They can be overridden via environment variables or explicit config.
|
|
33
|
+
*/
|
|
34
|
+
exports.DEFAULTS = {
|
|
35
|
+
/**
|
|
36
|
+
* Default runs directory: .a5c/runs
|
|
37
|
+
* Stores all run-related state including journals, tasks, and blobs.
|
|
38
|
+
*/
|
|
39
|
+
runsDir: ".a5c/runs",
|
|
40
|
+
/**
|
|
41
|
+
* Maximum iterations: 256
|
|
42
|
+
* Reasonable upper bound for most workflows while preventing runaway loops.
|
|
43
|
+
*/
|
|
44
|
+
maxIterations: 256,
|
|
45
|
+
/**
|
|
46
|
+
* Quality threshold: 80%
|
|
47
|
+
* Standard quality bar for task completion verification.
|
|
48
|
+
*/
|
|
49
|
+
qualityThreshold: 80,
|
|
50
|
+
/**
|
|
51
|
+
* Default timeout: 120000ms (2 minutes)
|
|
52
|
+
* Balanced timeout for general task execution.
|
|
53
|
+
*/
|
|
54
|
+
timeout: 120000,
|
|
55
|
+
/**
|
|
56
|
+
* Log level: info
|
|
57
|
+
* Shows informational messages, warnings, and errors by default.
|
|
58
|
+
*/
|
|
59
|
+
logLevel: "info",
|
|
60
|
+
/**
|
|
61
|
+
* Allow secret logs: false
|
|
62
|
+
* Security-first default - sensitive data is redacted.
|
|
63
|
+
*/
|
|
64
|
+
allowSecretLogs: false,
|
|
65
|
+
/**
|
|
66
|
+
* Hook timeout: 30000ms (30 seconds)
|
|
67
|
+
* Hooks should complete quickly as they run synchronously.
|
|
68
|
+
*/
|
|
69
|
+
hookTimeout: 30000,
|
|
70
|
+
/**
|
|
71
|
+
* Node task timeout: 900000ms (15 minutes)
|
|
72
|
+
* Extended timeout for potentially long-running Node.js tasks.
|
|
73
|
+
*/
|
|
74
|
+
nodeTaskTimeout: 15 * 60 * 1000, // 900000
|
|
75
|
+
/**
|
|
76
|
+
* Clock step: 1000ms (1 second)
|
|
77
|
+
* Standard time increment for deterministic testing.
|
|
78
|
+
*/
|
|
79
|
+
clockStepMs: 1000,
|
|
80
|
+
/**
|
|
81
|
+
* Clock start: January 1, 2025 UTC
|
|
82
|
+
* Fixed epoch for reproducible test timing.
|
|
83
|
+
*/
|
|
84
|
+
clockStartMs: Date.UTC(2025, 0, 1, 0, 0, 0, 0),
|
|
85
|
+
/**
|
|
86
|
+
* Layout version: 2026.01-storage-preview
|
|
87
|
+
* Current storage format version identifier.
|
|
88
|
+
*/
|
|
89
|
+
layoutVersion: "2026.01-storage-preview",
|
|
90
|
+
/**
|
|
91
|
+
* Large result preview limit: 1MB
|
|
92
|
+
* Results exceeding this size are stored externally.
|
|
93
|
+
*/
|
|
94
|
+
largeResultPreviewLimit: 1024 * 1024,
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Valid log levels for validation
|
|
98
|
+
*/
|
|
99
|
+
const VALID_LOG_LEVELS = ["debug", "info", "warn", "error", "silent"];
|
|
100
|
+
/**
|
|
101
|
+
* Parses an environment variable as a boolean.
|
|
102
|
+
*
|
|
103
|
+
* @param value - The environment variable value
|
|
104
|
+
* @returns true for "1" or "true" (case-insensitive), false otherwise
|
|
105
|
+
*/
|
|
106
|
+
function parseEnvBoolean(value) {
|
|
107
|
+
if (!value)
|
|
108
|
+
return false;
|
|
109
|
+
const normalized = value.trim().toLowerCase();
|
|
110
|
+
return normalized === "1" || normalized === "true";
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parses an environment variable as a positive integer.
|
|
114
|
+
*
|
|
115
|
+
* @param value - The environment variable value
|
|
116
|
+
* @param fallback - Value to return if parsing fails
|
|
117
|
+
* @returns The parsed integer or fallback
|
|
118
|
+
*/
|
|
119
|
+
function parseEnvPositiveInt(value, fallback) {
|
|
120
|
+
if (!value)
|
|
121
|
+
return fallback;
|
|
122
|
+
const parsed = parseInt(value.trim(), 10);
|
|
123
|
+
if (!Number.isFinite(parsed) || parsed <= 0)
|
|
124
|
+
return fallback;
|
|
125
|
+
return parsed;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Parses an environment variable as a log level.
|
|
129
|
+
*
|
|
130
|
+
* @param value - The environment variable value
|
|
131
|
+
* @param fallback - Value to return if parsing fails
|
|
132
|
+
* @returns The parsed log level or fallback
|
|
133
|
+
*/
|
|
134
|
+
function parseEnvLogLevel(value, fallback) {
|
|
135
|
+
if (!value)
|
|
136
|
+
return fallback;
|
|
137
|
+
const normalized = value.trim().toLowerCase();
|
|
138
|
+
if (VALID_LOG_LEVELS.includes(normalized)) {
|
|
139
|
+
return normalized;
|
|
140
|
+
}
|
|
141
|
+
return fallback;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Retrieves configuration with environment variable overrides merged in.
|
|
145
|
+
*
|
|
146
|
+
* Environment variables take precedence over defaults. This allows runtime
|
|
147
|
+
* configuration without code changes.
|
|
148
|
+
*
|
|
149
|
+
* @param overrides - Optional explicit overrides that take highest precedence
|
|
150
|
+
* @returns Complete configuration with all values resolved
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* // Get config with defaults and env var overrides
|
|
155
|
+
* const config = getConfig();
|
|
156
|
+
*
|
|
157
|
+
* // Get config with explicit overrides
|
|
158
|
+
* const customConfig = getConfig({ maxIterations: 500 });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
function getConfig(overrides) {
|
|
162
|
+
const env = typeof process !== "undefined" ? process.env : {};
|
|
163
|
+
return {
|
|
164
|
+
runsDir: overrides?.runsDir ?? env[exports.CONFIG_ENV_VARS.RUNS_DIR] ?? exports.DEFAULTS.runsDir,
|
|
165
|
+
maxIterations: overrides?.maxIterations ??
|
|
166
|
+
parseEnvPositiveInt(env[exports.CONFIG_ENV_VARS.MAX_ITERATIONS], exports.DEFAULTS.maxIterations),
|
|
167
|
+
qualityThreshold: overrides?.qualityThreshold ??
|
|
168
|
+
parseEnvPositiveInt(env[exports.CONFIG_ENV_VARS.QUALITY_THRESHOLD], exports.DEFAULTS.qualityThreshold),
|
|
169
|
+
timeout: overrides?.timeout ?? parseEnvPositiveInt(env[exports.CONFIG_ENV_VARS.TIMEOUT], exports.DEFAULTS.timeout),
|
|
170
|
+
logLevel: overrides?.logLevel ?? parseEnvLogLevel(env[exports.CONFIG_ENV_VARS.LOG_LEVEL], exports.DEFAULTS.logLevel),
|
|
171
|
+
allowSecretLogs: overrides?.allowSecretLogs ?? parseEnvBoolean(env[exports.CONFIG_ENV_VARS.ALLOW_SECRET_LOGS]),
|
|
172
|
+
hookTimeout: overrides?.hookTimeout ?? parseEnvPositiveInt(env[exports.CONFIG_ENV_VARS.HOOK_TIMEOUT], exports.DEFAULTS.hookTimeout),
|
|
173
|
+
nodeTaskTimeout: overrides?.nodeTaskTimeout ??
|
|
174
|
+
parseEnvPositiveInt(env[exports.CONFIG_ENV_VARS.NODE_TASK_TIMEOUT], exports.DEFAULTS.nodeTaskTimeout),
|
|
175
|
+
clockStepMs: overrides?.clockStepMs ?? exports.DEFAULTS.clockStepMs,
|
|
176
|
+
clockStartMs: overrides?.clockStartMs ?? exports.DEFAULTS.clockStartMs,
|
|
177
|
+
layoutVersion: overrides?.layoutVersion ?? exports.DEFAULTS.layoutVersion,
|
|
178
|
+
largeResultPreviewLimit: overrides?.largeResultPreviewLimit ?? exports.DEFAULTS.largeResultPreviewLimit,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Validates a configuration object for correctness.
|
|
183
|
+
*
|
|
184
|
+
* Checks that all values are within acceptable ranges and of correct types.
|
|
185
|
+
* Returns detailed error and warning messages for any issues found.
|
|
186
|
+
*
|
|
187
|
+
* @param config - The configuration to validate
|
|
188
|
+
* @returns Validation result with errors and warnings
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* const config = getConfig();
|
|
193
|
+
* const result = validateConfig(config);
|
|
194
|
+
* if (!result.valid) {
|
|
195
|
+
* console.error("Config errors:", result.errors);
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
function validateConfig(config) {
|
|
200
|
+
const errors = [];
|
|
201
|
+
const warnings = [];
|
|
202
|
+
// Validate runsDir
|
|
203
|
+
if (!config.runsDir || typeof config.runsDir !== "string") {
|
|
204
|
+
errors.push("runsDir must be a non-empty string");
|
|
205
|
+
}
|
|
206
|
+
// Validate maxIterations
|
|
207
|
+
if (!Number.isFinite(config.maxIterations) || config.maxIterations <= 0) {
|
|
208
|
+
errors.push("maxIterations must be a positive finite number");
|
|
209
|
+
}
|
|
210
|
+
else if (config.maxIterations > 10000) {
|
|
211
|
+
warnings.push("maxIterations is unusually high (>10000), this may cause performance issues");
|
|
212
|
+
}
|
|
213
|
+
// Validate qualityThreshold
|
|
214
|
+
if (!Number.isFinite(config.qualityThreshold) || config.qualityThreshold < 0 || config.qualityThreshold > 100) {
|
|
215
|
+
errors.push("qualityThreshold must be a number between 0 and 100");
|
|
216
|
+
}
|
|
217
|
+
// Validate timeout
|
|
218
|
+
if (!Number.isFinite(config.timeout) || config.timeout <= 0) {
|
|
219
|
+
errors.push("timeout must be a positive finite number");
|
|
220
|
+
}
|
|
221
|
+
else if (config.timeout < 1000) {
|
|
222
|
+
warnings.push("timeout is very short (<1s), tasks may fail prematurely");
|
|
223
|
+
}
|
|
224
|
+
// Validate logLevel
|
|
225
|
+
if (!VALID_LOG_LEVELS.includes(config.logLevel)) {
|
|
226
|
+
errors.push(`logLevel must be one of: ${VALID_LOG_LEVELS.join(", ")}`);
|
|
227
|
+
}
|
|
228
|
+
// Validate allowSecretLogs
|
|
229
|
+
if (typeof config.allowSecretLogs !== "boolean") {
|
|
230
|
+
errors.push("allowSecretLogs must be a boolean");
|
|
231
|
+
}
|
|
232
|
+
else if (config.allowSecretLogs) {
|
|
233
|
+
warnings.push("allowSecretLogs is enabled - sensitive data may be exposed in logs");
|
|
234
|
+
}
|
|
235
|
+
// Validate hookTimeout
|
|
236
|
+
if (!Number.isFinite(config.hookTimeout) || config.hookTimeout <= 0) {
|
|
237
|
+
errors.push("hookTimeout must be a positive finite number");
|
|
238
|
+
}
|
|
239
|
+
// Validate nodeTaskTimeout
|
|
240
|
+
if (!Number.isFinite(config.nodeTaskTimeout) || config.nodeTaskTimeout <= 0) {
|
|
241
|
+
errors.push("nodeTaskTimeout must be a positive finite number");
|
|
242
|
+
}
|
|
243
|
+
// Validate clockStepMs
|
|
244
|
+
if (!Number.isFinite(config.clockStepMs) || config.clockStepMs <= 0) {
|
|
245
|
+
errors.push("clockStepMs must be a positive finite number");
|
|
246
|
+
}
|
|
247
|
+
// Validate clockStartMs
|
|
248
|
+
if (!Number.isFinite(config.clockStartMs) || config.clockStartMs < 0) {
|
|
249
|
+
errors.push("clockStartMs must be a non-negative finite number");
|
|
250
|
+
}
|
|
251
|
+
// Validate layoutVersion
|
|
252
|
+
if (!config.layoutVersion || typeof config.layoutVersion !== "string") {
|
|
253
|
+
errors.push("layoutVersion must be a non-empty string");
|
|
254
|
+
}
|
|
255
|
+
// Validate largeResultPreviewLimit
|
|
256
|
+
if (!Number.isFinite(config.largeResultPreviewLimit) || config.largeResultPreviewLimit <= 0) {
|
|
257
|
+
errors.push("largeResultPreviewLimit must be a positive finite number");
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
valid: errors.length === 0,
|
|
261
|
+
errors,
|
|
262
|
+
warnings,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Creates a frozen copy of the defaults for safe external use.
|
|
267
|
+
*
|
|
268
|
+
* @returns A read-only copy of the default configuration
|
|
269
|
+
*/
|
|
270
|
+
function getDefaults() {
|
|
271
|
+
return { ...exports.DEFAULTS };
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Checks if a value is a valid log level.
|
|
275
|
+
*
|
|
276
|
+
* @param value - The value to check
|
|
277
|
+
* @returns true if the value is a valid LogLevel
|
|
278
|
+
*/
|
|
279
|
+
function isValidLogLevel(value) {
|
|
280
|
+
return typeof value === "string" && VALID_LOG_LEVELS.includes(value);
|
|
281
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Babysitter SDK Configuration Module
|
|
3
|
+
*
|
|
4
|
+
* This module provides centralized configuration management for the SDK.
|
|
5
|
+
* Import from this module to access defaults, configuration helpers, and types.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { DEFAULTS, getConfig, validateConfig } from "@a5c/babysitter-sdk/config";
|
|
10
|
+
*
|
|
11
|
+
* // Use defaults directly
|
|
12
|
+
* console.log(DEFAULTS.runsDir); // ".a5c/runs"
|
|
13
|
+
*
|
|
14
|
+
* // Get merged config with env overrides
|
|
15
|
+
* const config = getConfig({ maxIterations: 500 });
|
|
16
|
+
*
|
|
17
|
+
* // Validate configuration
|
|
18
|
+
* const result = validateConfig(config);
|
|
19
|
+
* if (!result.valid) {
|
|
20
|
+
* throw new Error(result.errors.join(", "));
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export { type LogLevel, type BabysitterConfig, type ConfigValidationResult, DEFAULTS, CONFIG_ENV_VARS, getConfig, validateConfig, getDefaults, isValidLogLevel, } from "./defaults";
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAG3B,QAAQ,EACR,eAAe,EAGf,SAAS,EACT,cAAc,EACd,WAAW,EACX,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Babysitter SDK Configuration Module
|
|
4
|
+
*
|
|
5
|
+
* This module provides centralized configuration management for the SDK.
|
|
6
|
+
* Import from this module to access defaults, configuration helpers, and types.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { DEFAULTS, getConfig, validateConfig } from "@a5c/babysitter-sdk/config";
|
|
11
|
+
*
|
|
12
|
+
* // Use defaults directly
|
|
13
|
+
* console.log(DEFAULTS.runsDir); // ".a5c/runs"
|
|
14
|
+
*
|
|
15
|
+
* // Get merged config with env overrides
|
|
16
|
+
* const config = getConfig({ maxIterations: 500 });
|
|
17
|
+
*
|
|
18
|
+
* // Validate configuration
|
|
19
|
+
* const result = validateConfig(config);
|
|
20
|
+
* if (!result.valid) {
|
|
21
|
+
* throw new Error(result.errors.join(", "));
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.isValidLogLevel = exports.getDefaults = exports.validateConfig = exports.getConfig = exports.CONFIG_ENV_VARS = exports.DEFAULTS = void 0;
|
|
27
|
+
var defaults_1 = require("./defaults");
|
|
28
|
+
// Constants
|
|
29
|
+
Object.defineProperty(exports, "DEFAULTS", { enumerable: true, get: function () { return defaults_1.DEFAULTS; } });
|
|
30
|
+
Object.defineProperty(exports, "CONFIG_ENV_VARS", { enumerable: true, get: function () { return defaults_1.CONFIG_ENV_VARS; } });
|
|
31
|
+
// Functions
|
|
32
|
+
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return defaults_1.getConfig; } });
|
|
33
|
+
Object.defineProperty(exports, "validateConfig", { enumerable: true, get: function () { return defaults_1.validateConfig; } });
|
|
34
|
+
Object.defineProperty(exports, "getDefaults", { enumerable: true, get: function () { return defaults_1.getDefaults; } });
|
|
35
|
+
Object.defineProperty(exports, "isValidLogLevel", { enumerable: true, get: function () { return defaults_1.isValidLogLevel; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/hooks/dispatcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACV,qBAAqB,EACrB,UAAU,EAEX,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/hooks/dispatcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACV,qBAAqB,EACrB,UAAU,EAEX,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiBtE;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,UAAU,CAAC,CAoHrB"}
|
package/dist/hooks/dispatcher.js
CHANGED
|
@@ -42,6 +42,7 @@ exports.callHook = callHook;
|
|
|
42
42
|
const node_child_process_1 = require("node:child_process");
|
|
43
43
|
const node_fs_1 = require("node:fs");
|
|
44
44
|
const path = __importStar(require("node:path"));
|
|
45
|
+
const defaults_1 = require("../config/defaults");
|
|
45
46
|
/**
|
|
46
47
|
* Find `plugins/babysitter/hooks/hook-dispatcher.sh` by walking up from cwd.
|
|
47
48
|
* This allows running from nested projects/fixtures inside a mono-repo.
|
|
@@ -72,7 +73,7 @@ function findHookDispatcherPath(startCwd) {
|
|
|
72
73
|
* Call a hook by dispatching to the shell hook-dispatcher.sh
|
|
73
74
|
*/
|
|
74
75
|
async function callHook(options) {
|
|
75
|
-
const { hookType, payload, cwd = process.cwd(), timeout =
|
|
76
|
+
const { hookType, payload, cwd = process.cwd(), timeout = defaults_1.DEFAULTS.hookTimeout, throwOnFailure = false, } = options;
|
|
76
77
|
const dispatcherPath = findHookDispatcherPath(cwd);
|
|
77
78
|
if (!dispatcherPath) {
|
|
78
79
|
return {
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const replaySchemaVersion
|
|
1
|
+
export declare const replaySchemaVersion: string;
|
|
2
2
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/runtime/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/runtime/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,QAAyB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRun.d.ts","sourceRoot":"","sources":["../../src/runtime/createRun.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGjE,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"createRun.d.ts","sourceRoot":"","sources":["../../src/runtime/createRun.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGjE,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAoFnF"}
|
|
@@ -18,11 +18,11 @@ async function createRun(options) {
|
|
|
18
18
|
const runDir = (0, paths_1.getRunDir)(options.runsDir, runId);
|
|
19
19
|
const normalizedEntrypoint = normalizeEntrypoint(runDir, options.process.importPath, options.process.exportName);
|
|
20
20
|
const requestId = options.request ?? options.process.processId ?? runId;
|
|
21
|
-
const
|
|
22
|
-
const
|
|
21
|
+
const providedProof = typeof options.metadata?.completionProof === "string" ? options.metadata.completionProof : undefined;
|
|
22
|
+
const completionProof = providedProof ?? crypto_1.default.randomBytes(16).toString("hex");
|
|
23
23
|
const extraMetadata = {
|
|
24
24
|
...options.metadata,
|
|
25
|
-
|
|
25
|
+
completionProof,
|
|
26
26
|
};
|
|
27
27
|
const { metadata } = await (0, createRunDir_1.createRunDir)({
|
|
28
28
|
runsRoot: options.runsDir,
|
|
@@ -35,6 +35,7 @@ async function createRun(options) {
|
|
|
35
35
|
entrypoint: normalizedEntrypoint,
|
|
36
36
|
processPath: normalizedEntrypoint.importPath,
|
|
37
37
|
extraMetadata,
|
|
38
|
+
prompt: options.prompt,
|
|
38
39
|
});
|
|
39
40
|
let lockAcquired = false;
|
|
40
41
|
try {
|
|
@@ -51,6 +52,9 @@ async function createRun(options) {
|
|
|
51
52
|
if (options.inputs !== undefined) {
|
|
52
53
|
eventPayload.inputsRef = paths_1.INPUTS_FILE;
|
|
53
54
|
}
|
|
55
|
+
if (options.prompt !== undefined) {
|
|
56
|
+
eventPayload.prompt = options.prompt;
|
|
57
|
+
}
|
|
54
58
|
await (0, journal_1.appendEvent)({
|
|
55
59
|
runDir,
|
|
56
60
|
eventType: "RUN_CREATED",
|