@herdctl/core 0.0.1 → 0.0.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.
- package/dist/config/__tests__/agent.test.js +31 -13
- package/dist/config/__tests__/agent.test.js.map +1 -1
- package/dist/config/__tests__/merge.test.js +9 -2
- package/dist/config/__tests__/merge.test.js.map +1 -1
- package/dist/config/__tests__/schema.test.js +350 -1
- package/dist/config/__tests__/schema.test.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +3 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/schema.d.ts +828 -24
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +118 -6
- package/dist/config/schema.js.map +1 -1
- package/dist/fleet-manager/__tests__/coverage.test.js +11 -332
- package/dist/fleet-manager/__tests__/coverage.test.js.map +1 -1
- package/dist/fleet-manager/__tests__/errors.test.js +1 -49
- package/dist/fleet-manager/__tests__/errors.test.js.map +1 -1
- package/dist/fleet-manager/__tests__/integration.test.js +109 -0
- package/dist/fleet-manager/__tests__/integration.test.js.map +1 -1
- package/dist/fleet-manager/__tests__/reload.test.js +1 -1
- package/dist/fleet-manager/__tests__/reload.test.js.map +1 -1
- package/dist/fleet-manager/config-reload.d.ts +164 -0
- package/dist/fleet-manager/config-reload.d.ts.map +1 -0
- package/dist/fleet-manager/config-reload.js +445 -0
- package/dist/fleet-manager/config-reload.js.map +1 -0
- package/dist/fleet-manager/context.d.ts +76 -0
- package/dist/fleet-manager/context.d.ts.map +1 -0
- package/dist/fleet-manager/context.js +11 -0
- package/dist/fleet-manager/context.js.map +1 -0
- package/dist/fleet-manager/errors.d.ts +0 -25
- package/dist/fleet-manager/errors.d.ts.map +1 -1
- package/dist/fleet-manager/errors.js +0 -38
- package/dist/fleet-manager/errors.js.map +1 -1
- package/dist/fleet-manager/event-emitters.d.ts +123 -0
- package/dist/fleet-manager/event-emitters.d.ts.map +1 -0
- package/dist/fleet-manager/event-emitters.js +136 -0
- package/dist/fleet-manager/event-emitters.js.map +1 -0
- package/dist/fleet-manager/event-types.d.ts +0 -15
- package/dist/fleet-manager/event-types.d.ts.map +1 -1
- package/dist/fleet-manager/fleet-manager.d.ts +40 -653
- package/dist/fleet-manager/fleet-manager.d.ts.map +1 -1
- package/dist/fleet-manager/fleet-manager.js +95 -1720
- package/dist/fleet-manager/fleet-manager.js.map +1 -1
- package/dist/fleet-manager/index.d.ts +13 -2
- package/dist/fleet-manager/index.d.ts.map +1 -1
- package/dist/fleet-manager/index.js +19 -6
- package/dist/fleet-manager/index.js.map +1 -1
- package/dist/fleet-manager/job-control.d.ts +64 -0
- package/dist/fleet-manager/job-control.d.ts.map +1 -0
- package/dist/fleet-manager/job-control.js +296 -0
- package/dist/fleet-manager/job-control.js.map +1 -0
- package/dist/fleet-manager/log-streaming.d.ts +171 -0
- package/dist/fleet-manager/log-streaming.d.ts.map +1 -0
- package/dist/fleet-manager/log-streaming.js +503 -0
- package/dist/fleet-manager/log-streaming.js.map +1 -0
- package/dist/fleet-manager/schedule-executor.d.ts +63 -0
- package/dist/fleet-manager/schedule-executor.d.ts.map +1 -0
- package/dist/fleet-manager/schedule-executor.js +209 -0
- package/dist/fleet-manager/schedule-executor.js.map +1 -0
- package/dist/fleet-manager/schedule-management.d.ts +71 -0
- package/dist/fleet-manager/schedule-management.d.ts.map +1 -0
- package/dist/fleet-manager/schedule-management.js +171 -0
- package/dist/fleet-manager/schedule-management.js.map +1 -0
- package/dist/fleet-manager/status-queries.d.ts +105 -0
- package/dist/fleet-manager/status-queries.d.ts.map +1 -0
- package/dist/fleet-manager/status-queries.js +247 -0
- package/dist/fleet-manager/status-queries.js.map +1 -0
- package/dist/fleet-manager/types.d.ts +0 -39
- package/dist/fleet-manager/types.d.ts.map +1 -1
- package/dist/runner/__tests__/job-executor.test.js +206 -1
- package/dist/runner/__tests__/job-executor.test.js.map +1 -1
- package/dist/runner/job-executor.d.ts +9 -0
- package/dist/runner/job-executor.d.ts.map +1 -1
- package/dist/runner/job-executor.js +78 -4
- package/dist/runner/job-executor.js.map +1 -1
- package/dist/runner/types.d.ts +2 -0
- package/dist/runner/types.d.ts.map +1 -1
- package/dist/scheduler/__tests__/cron.test.d.ts +2 -0
- package/dist/scheduler/__tests__/cron.test.d.ts.map +1 -0
- package/dist/scheduler/__tests__/cron.test.js +867 -0
- package/dist/scheduler/__tests__/cron.test.js.map +1 -0
- package/dist/scheduler/__tests__/scheduler.test.js +164 -5
- package/dist/scheduler/__tests__/scheduler.test.js.map +1 -1
- package/dist/scheduler/cron.d.ts +126 -0
- package/dist/scheduler/cron.d.ts.map +1 -0
- package/dist/scheduler/cron.js +390 -0
- package/dist/scheduler/cron.js.map +1 -0
- package/dist/scheduler/errors.d.ts +81 -1
- package/dist/scheduler/errors.d.ts.map +1 -1
- package/dist/scheduler/errors.js +81 -6
- package/dist/scheduler/errors.js.map +1 -1
- package/dist/scheduler/index.d.ts +1 -0
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/index.js.map +1 -1
- package/dist/scheduler/schedule-runner.d.ts +2 -2
- package/dist/scheduler/schedule-runner.d.ts.map +1 -1
- package/dist/scheduler/schedule-runner.js +20 -8
- package/dist/scheduler/schedule-runner.js.map +1 -1
- package/dist/scheduler/scheduler.d.ts +4 -4
- package/dist/scheduler/scheduler.d.ts.map +1 -1
- package/dist/scheduler/scheduler.js +86 -20
- package/dist/scheduler/scheduler.js.map +1 -1
- package/dist/scheduler/types.d.ts +1 -1
- package/dist/scheduler/types.d.ts.map +1 -1
- package/dist/state/schemas/job-metadata.d.ts +2 -2
- package/package.json +33 -8
- package/.turbo/turbo-build.log +0 -4
- package/.turbo/turbo-test.log +0 -219
- package/.turbo/turbo-typecheck.log +0 -4
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/coverage-final.json +0 -51
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -251
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/coverage/src/config/index.html +0 -191
- package/coverage/src/config/index.ts.html +0 -442
- package/coverage/src/config/interpolate.ts.html +0 -652
- package/coverage/src/config/loader.ts.html +0 -1501
- package/coverage/src/config/merge.ts.html +0 -823
- package/coverage/src/config/parser.ts.html +0 -1213
- package/coverage/src/config/schema.ts.html +0 -1123
- package/coverage/src/fleet-manager/errors.ts.html +0 -2326
- package/coverage/src/fleet-manager/event-types.ts.html +0 -1219
- package/coverage/src/fleet-manager/fleet-manager.ts.html +0 -7030
- package/coverage/src/fleet-manager/index.html +0 -206
- package/coverage/src/fleet-manager/index.ts.html +0 -469
- package/coverage/src/fleet-manager/job-manager.ts.html +0 -2074
- package/coverage/src/fleet-manager/job-queue.ts.html +0 -2479
- package/coverage/src/fleet-manager/types.ts.html +0 -2602
- package/coverage/src/index.html +0 -116
- package/coverage/src/index.ts.html +0 -181
- package/coverage/src/runner/errors.ts.html +0 -1006
- package/coverage/src/runner/index.html +0 -191
- package/coverage/src/runner/index.ts.html +0 -256
- package/coverage/src/runner/job-executor.ts.html +0 -1429
- package/coverage/src/runner/message-processor.ts.html +0 -1150
- package/coverage/src/runner/sdk-adapter.ts.html +0 -658
- package/coverage/src/runner/types.ts.html +0 -559
- package/coverage/src/scheduler/errors.ts.html +0 -388
- package/coverage/src/scheduler/index.html +0 -206
- package/coverage/src/scheduler/index.ts.html +0 -244
- package/coverage/src/scheduler/interval.ts.html +0 -652
- package/coverage/src/scheduler/schedule-runner.ts.html +0 -1411
- package/coverage/src/scheduler/schedule-state.ts.html +0 -718
- package/coverage/src/scheduler/scheduler.ts.html +0 -1795
- package/coverage/src/scheduler/types.ts.html +0 -733
- package/coverage/src/state/directory.ts.html +0 -736
- package/coverage/src/state/errors.ts.html +0 -376
- package/coverage/src/state/fleet-state.ts.html +0 -937
- package/coverage/src/state/index.html +0 -221
- package/coverage/src/state/index.ts.html +0 -322
- package/coverage/src/state/job-metadata.ts.html +0 -1420
- package/coverage/src/state/job-output.ts.html +0 -1033
- package/coverage/src/state/schemas/fleet-state.ts.html +0 -445
- package/coverage/src/state/schemas/index.html +0 -176
- package/coverage/src/state/schemas/index.ts.html +0 -286
- package/coverage/src/state/schemas/job-metadata.ts.html +0 -628
- package/coverage/src/state/schemas/job-output.ts.html +0 -616
- package/coverage/src/state/schemas/session-info.ts.html +0 -361
- package/coverage/src/state/session.ts.html +0 -844
- package/coverage/src/state/types.ts.html +0 -262
- package/coverage/src/state/utils/atomic.ts.html +0 -748
- package/coverage/src/state/utils/index.html +0 -146
- package/coverage/src/state/utils/index.ts.html +0 -103
- package/coverage/src/state/utils/reads.ts.html +0 -1621
- package/coverage/src/work-sources/adapters/github.ts.html +0 -3583
- package/coverage/src/work-sources/adapters/index.html +0 -131
- package/coverage/src/work-sources/adapters/index.ts.html +0 -277
- package/coverage/src/work-sources/errors.ts.html +0 -298
- package/coverage/src/work-sources/index.html +0 -176
- package/coverage/src/work-sources/index.ts.html +0 -529
- package/coverage/src/work-sources/manager.ts.html +0 -1324
- package/coverage/src/work-sources/registry.ts.html +0 -619
- package/coverage/src/work-sources/types.ts.html +0 -568
- package/dist/fleet-manager/__tests__/event-helpers.test.d.ts +0 -7
- package/dist/fleet-manager/__tests__/event-helpers.test.d.ts.map +0 -1
- package/dist/fleet-manager/__tests__/event-helpers.test.js +0 -368
- package/dist/fleet-manager/__tests__/event-helpers.test.js.map +0 -1
- package/src/config/__tests__/agent.test.ts +0 -864
- package/src/config/__tests__/interpolate.test.ts +0 -644
- package/src/config/__tests__/loader.test.ts +0 -784
- package/src/config/__tests__/merge.test.ts +0 -751
- package/src/config/__tests__/parser.test.ts +0 -533
- package/src/config/__tests__/schema.test.ts +0 -873
- package/src/config/index.ts +0 -119
- package/src/config/interpolate.ts +0 -189
- package/src/config/loader.ts +0 -472
- package/src/config/merge.ts +0 -246
- package/src/config/parser.ts +0 -376
- package/src/config/schema.ts +0 -346
- package/src/fleet-manager/__tests__/coverage.test.ts +0 -2869
- package/src/fleet-manager/__tests__/errors.test.ts +0 -660
- package/src/fleet-manager/__tests__/event-helpers.test.ts +0 -448
- package/src/fleet-manager/__tests__/integration.test.ts +0 -1209
- package/src/fleet-manager/__tests__/job-control.test.ts +0 -283
- package/src/fleet-manager/__tests__/job-manager.test.ts +0 -869
- package/src/fleet-manager/__tests__/job-queue.test.ts +0 -401
- package/src/fleet-manager/__tests__/reload.test.ts +0 -751
- package/src/fleet-manager/__tests__/status-queries.test.ts +0 -595
- package/src/fleet-manager/__tests__/trigger.test.ts +0 -601
- package/src/fleet-manager/errors.ts +0 -747
- package/src/fleet-manager/event-types.ts +0 -378
- package/src/fleet-manager/fleet-manager.ts +0 -2315
- package/src/fleet-manager/index.ts +0 -128
- package/src/fleet-manager/job-manager.ts +0 -663
- package/src/fleet-manager/job-queue.ts +0 -798
- package/src/fleet-manager/types.ts +0 -839
- package/src/index.ts +0 -32
- package/src/runner/__tests__/errors.test.ts +0 -382
- package/src/runner/__tests__/job-executor.test.ts +0 -1708
- package/src/runner/__tests__/message-processor.test.ts +0 -960
- package/src/runner/__tests__/sdk-adapter.test.ts +0 -626
- package/src/runner/errors.ts +0 -307
- package/src/runner/index.ts +0 -57
- package/src/runner/job-executor.ts +0 -448
- package/src/runner/message-processor.ts +0 -355
- package/src/runner/sdk-adapter.ts +0 -191
- package/src/runner/types.ts +0 -158
- package/src/scheduler/__tests__/errors.test.ts +0 -159
- package/src/scheduler/__tests__/interval.test.ts +0 -515
- package/src/scheduler/__tests__/schedule-runner.test.ts +0 -798
- package/src/scheduler/__tests__/schedule-state.test.ts +0 -671
- package/src/scheduler/__tests__/scheduler.test.ts +0 -1280
- package/src/scheduler/errors.ts +0 -101
- package/src/scheduler/index.ts +0 -53
- package/src/scheduler/interval.ts +0 -189
- package/src/scheduler/schedule-runner.ts +0 -442
- package/src/scheduler/schedule-state.ts +0 -211
- package/src/scheduler/scheduler.ts +0 -570
- package/src/scheduler/types.ts +0 -216
- package/src/state/__tests__/directory.test.ts +0 -595
- package/src/state/__tests__/fleet-state.test.ts +0 -868
- package/src/state/__tests__/job-metadata-schema.test.ts +0 -414
- package/src/state/__tests__/job-metadata.test.ts +0 -831
- package/src/state/__tests__/job-output.test.ts +0 -856
- package/src/state/__tests__/session-schema.test.ts +0 -378
- package/src/state/__tests__/session.test.ts +0 -604
- package/src/state/directory.ts +0 -217
- package/src/state/errors.ts +0 -97
- package/src/state/fleet-state.ts +0 -284
- package/src/state/index.ts +0 -79
- package/src/state/job-metadata.ts +0 -445
- package/src/state/job-output.ts +0 -316
- package/src/state/schemas/__tests__/job-output.test.ts +0 -338
- package/src/state/schemas/fleet-state.ts +0 -120
- package/src/state/schemas/index.ts +0 -67
- package/src/state/schemas/job-metadata.ts +0 -181
- package/src/state/schemas/job-output.ts +0 -177
- package/src/state/schemas/session-info.ts +0 -92
- package/src/state/session.ts +0 -253
- package/src/state/types.ts +0 -59
- package/src/state/utils/__tests__/atomic.test.ts +0 -723
- package/src/state/utils/__tests__/reads.test.ts +0 -1071
- package/src/state/utils/atomic.ts +0 -221
- package/src/state/utils/index.ts +0 -6
- package/src/state/utils/reads.ts +0 -512
- package/src/work-sources/__tests__/github.test.ts +0 -1800
- package/src/work-sources/__tests__/manager.test.ts +0 -529
- package/src/work-sources/__tests__/registry.test.ts +0 -477
- package/src/work-sources/__tests__/types.test.ts +0 -479
- package/src/work-sources/adapters/github.ts +0 -1166
- package/src/work-sources/adapters/index.ts +0 -64
- package/src/work-sources/errors.ts +0 -71
- package/src/work-sources/index.ts +0 -148
- package/src/work-sources/manager.ts +0 -413
- package/src/work-sources/registry.ts +0 -178
- package/src/work-sources/types.ts +0 -161
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -19
package/src/state/job-output.ts
DELETED
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Job output logging operations
|
|
3
|
-
*
|
|
4
|
-
* Provides functions for streaming job output to JSONL files.
|
|
5
|
-
* Supports real-time monitoring with immediate writes (no buffering).
|
|
6
|
-
*
|
|
7
|
-
* Output files are stored at: .herdctl/jobs/job-<id>.jsonl
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { join } from "node:path";
|
|
11
|
-
import { createReadStream } from "node:fs";
|
|
12
|
-
import { stat } from "node:fs/promises";
|
|
13
|
-
import { createInterface } from "node:readline";
|
|
14
|
-
import { appendJsonl } from "./utils/atomic.js";
|
|
15
|
-
import { StateFileError } from "./errors.js";
|
|
16
|
-
import {
|
|
17
|
-
type JobOutputMessage,
|
|
18
|
-
type JobOutputInput,
|
|
19
|
-
isValidJobOutputInput,
|
|
20
|
-
JobOutputMessageSchema,
|
|
21
|
-
} from "./schemas/job-output.js";
|
|
22
|
-
|
|
23
|
-
// =============================================================================
|
|
24
|
-
// Types
|
|
25
|
-
// =============================================================================
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Logger interface for job output operations
|
|
29
|
-
*/
|
|
30
|
-
export interface JobOutputLogger {
|
|
31
|
-
warn: (message: string) => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Options for job output operations
|
|
36
|
-
*/
|
|
37
|
-
export interface JobOutputOptions {
|
|
38
|
-
/** Logger for warnings and errors */
|
|
39
|
-
logger?: JobOutputLogger;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Options for reading job output
|
|
44
|
-
*/
|
|
45
|
-
export interface ReadJobOutputOptions extends JobOutputOptions {
|
|
46
|
-
/** Whether to skip invalid lines instead of failing */
|
|
47
|
-
skipInvalidLines?: boolean;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// =============================================================================
|
|
51
|
-
// Path Utilities
|
|
52
|
-
// =============================================================================
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get the path to a job's output file
|
|
56
|
-
*
|
|
57
|
-
* @param jobsDir - Path to the jobs directory (.herdctl/jobs)
|
|
58
|
-
* @param jobId - Job ID (e.g., job-2024-01-15-abc123)
|
|
59
|
-
* @returns Path to the JSONL output file
|
|
60
|
-
*/
|
|
61
|
-
export function getJobOutputPath(jobsDir: string, jobId: string): string {
|
|
62
|
-
return join(jobsDir, `${jobId}.jsonl`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// =============================================================================
|
|
66
|
-
// Write Operations
|
|
67
|
-
// =============================================================================
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Append a single message to a job's output log
|
|
71
|
-
*
|
|
72
|
-
* Writes immediately to disk for real-time monitoring (no buffering).
|
|
73
|
-
* Uses append mode which is safe for concurrent appends.
|
|
74
|
-
*
|
|
75
|
-
* @param jobsDir - Path to the jobs directory
|
|
76
|
-
* @param jobId - Job ID
|
|
77
|
-
* @param message - Message to append (timestamp added automatically)
|
|
78
|
-
* @throws StateFileError if write fails or message is invalid
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* await appendJobOutput(jobsDir, jobId, {
|
|
83
|
-
* type: "assistant",
|
|
84
|
-
* content: "Hello, world!"
|
|
85
|
-
* });
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
export async function appendJobOutput(
|
|
89
|
-
jobsDir: string,
|
|
90
|
-
jobId: string,
|
|
91
|
-
message: JobOutputInput
|
|
92
|
-
): Promise<void> {
|
|
93
|
-
// Validate message structure
|
|
94
|
-
if (!isValidJobOutputInput(message)) {
|
|
95
|
-
throw new StateFileError(
|
|
96
|
-
`Invalid job output message: must have a valid 'type' field`,
|
|
97
|
-
getJobOutputPath(jobsDir, jobId),
|
|
98
|
-
"write"
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const outputPath = getJobOutputPath(jobsDir, jobId);
|
|
103
|
-
|
|
104
|
-
// Add timestamp to message
|
|
105
|
-
const messageWithTimestamp: JobOutputMessage = {
|
|
106
|
-
...message,
|
|
107
|
-
timestamp: new Date().toISOString(),
|
|
108
|
-
} as JobOutputMessage;
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
await appendJsonl(outputPath, messageWithTimestamp);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
throw new StateFileError(
|
|
114
|
-
`Failed to append to job output: ${(error as Error).message}`,
|
|
115
|
-
outputPath,
|
|
116
|
-
"write",
|
|
117
|
-
error as Error
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Append multiple messages to a job's output log
|
|
124
|
-
*
|
|
125
|
-
* Writes all messages immediately in sequence.
|
|
126
|
-
* Each message is validated before writing begins.
|
|
127
|
-
*
|
|
128
|
-
* @param jobsDir - Path to the jobs directory
|
|
129
|
-
* @param jobId - Job ID
|
|
130
|
-
* @param messages - Messages to append (timestamps added automatically)
|
|
131
|
-
* @throws StateFileError if write fails or any message is invalid
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```typescript
|
|
135
|
-
* await appendJobOutputBatch(jobsDir, jobId, [
|
|
136
|
-
* { type: "tool_use", tool_name: "read_file", input: { path: "/etc/hosts" } },
|
|
137
|
-
* { type: "tool_result", result: "127.0.0.1 localhost", success: true }
|
|
138
|
-
* ]);
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
export async function appendJobOutputBatch(
|
|
142
|
-
jobsDir: string,
|
|
143
|
-
jobId: string,
|
|
144
|
-
messages: JobOutputInput[]
|
|
145
|
-
): Promise<void> {
|
|
146
|
-
const outputPath = getJobOutputPath(jobsDir, jobId);
|
|
147
|
-
|
|
148
|
-
// Validate all messages first
|
|
149
|
-
for (let i = 0; i < messages.length; i++) {
|
|
150
|
-
if (!isValidJobOutputInput(messages[i])) {
|
|
151
|
-
throw new StateFileError(
|
|
152
|
-
`Invalid job output message at index ${i}: must have a valid 'type' field`,
|
|
153
|
-
outputPath,
|
|
154
|
-
"write"
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Write all messages
|
|
160
|
-
const timestamp = new Date().toISOString();
|
|
161
|
-
for (const message of messages) {
|
|
162
|
-
const messageWithTimestamp: JobOutputMessage = {
|
|
163
|
-
...message,
|
|
164
|
-
timestamp,
|
|
165
|
-
} as JobOutputMessage;
|
|
166
|
-
|
|
167
|
-
try {
|
|
168
|
-
await appendJsonl(outputPath, messageWithTimestamp);
|
|
169
|
-
} catch (error) {
|
|
170
|
-
throw new StateFileError(
|
|
171
|
-
`Failed to append to job output: ${(error as Error).message}`,
|
|
172
|
-
outputPath,
|
|
173
|
-
"write",
|
|
174
|
-
error as Error
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// =============================================================================
|
|
181
|
-
// Read Operations
|
|
182
|
-
// =============================================================================
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Read job output as an async generator for streaming reads
|
|
186
|
-
*
|
|
187
|
-
* Yields messages one at a time, allowing for memory-efficient
|
|
188
|
-
* processing of large output files.
|
|
189
|
-
*
|
|
190
|
-
* @param jobsDir - Path to the jobs directory
|
|
191
|
-
* @param jobId - Job ID
|
|
192
|
-
* @param options - Read options
|
|
193
|
-
* @yields JobOutputMessage objects
|
|
194
|
-
* @throws StateFileError if file cannot be read (except ENOENT which yields nothing)
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```typescript
|
|
198
|
-
* for await (const message of readJobOutput(jobsDir, jobId)) {
|
|
199
|
-
* console.log(`[${message.type}] ${message.timestamp}`);
|
|
200
|
-
* }
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
export async function* readJobOutput(
|
|
204
|
-
jobsDir: string,
|
|
205
|
-
jobId: string,
|
|
206
|
-
options: ReadJobOutputOptions = {}
|
|
207
|
-
): AsyncGenerator<JobOutputMessage, void, undefined> {
|
|
208
|
-
const { skipInvalidLines = false, logger = console } = options;
|
|
209
|
-
const outputPath = getJobOutputPath(jobsDir, jobId);
|
|
210
|
-
|
|
211
|
-
// Check if file exists
|
|
212
|
-
try {
|
|
213
|
-
await stat(outputPath);
|
|
214
|
-
} catch (error) {
|
|
215
|
-
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
216
|
-
// File doesn't exist - yield nothing
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
throw new StateFileError(
|
|
220
|
-
`Failed to read job output: ${(error as Error).message}`,
|
|
221
|
-
outputPath,
|
|
222
|
-
"read",
|
|
223
|
-
error as Error
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Create readline interface for streaming
|
|
228
|
-
const fileStream = createReadStream(outputPath, { encoding: "utf-8" });
|
|
229
|
-
const rl = createInterface({
|
|
230
|
-
input: fileStream,
|
|
231
|
-
crlfDelay: Infinity,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
let lineNumber = 0;
|
|
235
|
-
|
|
236
|
-
try {
|
|
237
|
-
for await (const line of rl) {
|
|
238
|
-
lineNumber++;
|
|
239
|
-
|
|
240
|
-
// Skip empty lines
|
|
241
|
-
const trimmedLine = line.trim();
|
|
242
|
-
if (trimmedLine === "") {
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
const parsed = JSON.parse(trimmedLine);
|
|
248
|
-
const validated = JobOutputMessageSchema.safeParse(parsed);
|
|
249
|
-
|
|
250
|
-
if (validated.success) {
|
|
251
|
-
yield validated.data;
|
|
252
|
-
} else if (skipInvalidLines) {
|
|
253
|
-
logger.warn(
|
|
254
|
-
`[herdctl] Skipping invalid message at line ${lineNumber} in ${outputPath}: ${validated.error.message}`
|
|
255
|
-
);
|
|
256
|
-
} else {
|
|
257
|
-
throw new StateFileError(
|
|
258
|
-
`Invalid job output message at line ${lineNumber}: ${validated.error.message}`,
|
|
259
|
-
outputPath,
|
|
260
|
-
"read"
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
} catch (error) {
|
|
264
|
-
if (error instanceof StateFileError) {
|
|
265
|
-
throw error;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (skipInvalidLines) {
|
|
269
|
-
logger.warn(
|
|
270
|
-
`[herdctl] Skipping malformed JSON at line ${lineNumber} in ${outputPath}: ${(error as Error).message}`
|
|
271
|
-
);
|
|
272
|
-
} else {
|
|
273
|
-
throw new StateFileError(
|
|
274
|
-
`Failed to parse job output at line ${lineNumber}: ${(error as Error).message}`,
|
|
275
|
-
outputPath,
|
|
276
|
-
"read",
|
|
277
|
-
error as Error
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
} finally {
|
|
283
|
-
// Ensure resources are cleaned up
|
|
284
|
-
rl.close();
|
|
285
|
-
fileStream.destroy();
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Read all job output messages into an array
|
|
291
|
-
*
|
|
292
|
-
* Convenience function that collects all messages from readJobOutput.
|
|
293
|
-
* For large files, prefer using readJobOutput directly as a generator.
|
|
294
|
-
*
|
|
295
|
-
* @param jobsDir - Path to the jobs directory
|
|
296
|
-
* @param jobId - Job ID
|
|
297
|
-
* @param options - Read options
|
|
298
|
-
* @returns Array of all job output messages
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* ```typescript
|
|
302
|
-
* const messages = await readJobOutputAll(jobsDir, jobId);
|
|
303
|
-
* console.log(`Total messages: ${messages.length}`);
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
export async function readJobOutputAll(
|
|
307
|
-
jobsDir: string,
|
|
308
|
-
jobId: string,
|
|
309
|
-
options: ReadJobOutputOptions = {}
|
|
310
|
-
): Promise<JobOutputMessage[]> {
|
|
311
|
-
const messages: JobOutputMessage[] = [];
|
|
312
|
-
for await (const message of readJobOutput(jobsDir, jobId, options)) {
|
|
313
|
-
messages.push(message);
|
|
314
|
-
}
|
|
315
|
-
return messages;
|
|
316
|
-
}
|
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
JobOutputTypeSchema,
|
|
4
|
-
JobOutputMessageSchema,
|
|
5
|
-
SystemMessageSchema,
|
|
6
|
-
AssistantMessageSchema,
|
|
7
|
-
ToolUseMessageSchema,
|
|
8
|
-
ToolResultMessageSchema,
|
|
9
|
-
ErrorMessageSchema,
|
|
10
|
-
validateJobOutputMessage,
|
|
11
|
-
isValidJobOutputInput,
|
|
12
|
-
type JobOutputMessage,
|
|
13
|
-
type JobOutputInput,
|
|
14
|
-
} from "../job-output.js";
|
|
15
|
-
|
|
16
|
-
describe("JobOutputTypeSchema", () => {
|
|
17
|
-
it("accepts valid types", () => {
|
|
18
|
-
expect(JobOutputTypeSchema.parse("system")).toBe("system");
|
|
19
|
-
expect(JobOutputTypeSchema.parse("assistant")).toBe("assistant");
|
|
20
|
-
expect(JobOutputTypeSchema.parse("tool_use")).toBe("tool_use");
|
|
21
|
-
expect(JobOutputTypeSchema.parse("tool_result")).toBe("tool_result");
|
|
22
|
-
expect(JobOutputTypeSchema.parse("error")).toBe("error");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("rejects invalid types", () => {
|
|
26
|
-
expect(() => JobOutputTypeSchema.parse("invalid")).toThrow();
|
|
27
|
-
expect(() => JobOutputTypeSchema.parse("")).toThrow();
|
|
28
|
-
expect(() => JobOutputTypeSchema.parse(null)).toThrow();
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe("SystemMessageSchema", () => {
|
|
33
|
-
it("accepts valid system message", () => {
|
|
34
|
-
const message = {
|
|
35
|
-
type: "system" as const,
|
|
36
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
37
|
-
content: "System initialized",
|
|
38
|
-
};
|
|
39
|
-
expect(SystemMessageSchema.parse(message)).toEqual(message);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("accepts system message with subtype", () => {
|
|
43
|
-
const message = {
|
|
44
|
-
type: "system" as const,
|
|
45
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
46
|
-
subtype: "session_start",
|
|
47
|
-
};
|
|
48
|
-
expect(SystemMessageSchema.parse(message).subtype).toBe("session_start");
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it("accepts minimal system message", () => {
|
|
52
|
-
const message = {
|
|
53
|
-
type: "system" as const,
|
|
54
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
55
|
-
};
|
|
56
|
-
expect(SystemMessageSchema.parse(message)).toEqual(message);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe("AssistantMessageSchema", () => {
|
|
61
|
-
it("accepts valid assistant message", () => {
|
|
62
|
-
const message = {
|
|
63
|
-
type: "assistant" as const,
|
|
64
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
65
|
-
content: "Hello, world!",
|
|
66
|
-
};
|
|
67
|
-
expect(AssistantMessageSchema.parse(message)).toEqual(message);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("accepts assistant message with partial flag", () => {
|
|
71
|
-
const message = {
|
|
72
|
-
type: "assistant" as const,
|
|
73
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
74
|
-
content: "Partial...",
|
|
75
|
-
partial: true,
|
|
76
|
-
};
|
|
77
|
-
expect(AssistantMessageSchema.parse(message).partial).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("accepts assistant message with usage info", () => {
|
|
81
|
-
const message = {
|
|
82
|
-
type: "assistant" as const,
|
|
83
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
84
|
-
content: "Response",
|
|
85
|
-
usage: {
|
|
86
|
-
input_tokens: 100,
|
|
87
|
-
output_tokens: 50,
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
expect(AssistantMessageSchema.parse(message).usage).toEqual({
|
|
91
|
-
input_tokens: 100,
|
|
92
|
-
output_tokens: 50,
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe("ToolUseMessageSchema", () => {
|
|
98
|
-
it("accepts valid tool_use message", () => {
|
|
99
|
-
const message = {
|
|
100
|
-
type: "tool_use" as const,
|
|
101
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
102
|
-
tool_name: "read_file",
|
|
103
|
-
};
|
|
104
|
-
expect(ToolUseMessageSchema.parse(message)).toEqual(message);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("accepts tool_use with full details", () => {
|
|
108
|
-
const message = {
|
|
109
|
-
type: "tool_use" as const,
|
|
110
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
111
|
-
tool_name: "bash",
|
|
112
|
-
tool_use_id: "tool-123",
|
|
113
|
-
input: { command: "ls -la" },
|
|
114
|
-
};
|
|
115
|
-
const parsed = ToolUseMessageSchema.parse(message);
|
|
116
|
-
expect(parsed.tool_name).toBe("bash");
|
|
117
|
-
expect(parsed.tool_use_id).toBe("tool-123");
|
|
118
|
-
expect(parsed.input).toEqual({ command: "ls -la" });
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("rejects tool_use without tool_name", () => {
|
|
122
|
-
const message = {
|
|
123
|
-
type: "tool_use" as const,
|
|
124
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
125
|
-
};
|
|
126
|
-
expect(() => ToolUseMessageSchema.parse(message)).toThrow();
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe("ToolResultMessageSchema", () => {
|
|
131
|
-
it("accepts valid tool_result message", () => {
|
|
132
|
-
const message = {
|
|
133
|
-
type: "tool_result" as const,
|
|
134
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
135
|
-
result: "file contents",
|
|
136
|
-
success: true,
|
|
137
|
-
};
|
|
138
|
-
expect(ToolResultMessageSchema.parse(message).success).toBe(true);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("accepts tool_result with error", () => {
|
|
142
|
-
const message = {
|
|
143
|
-
type: "tool_result" as const,
|
|
144
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
145
|
-
success: false,
|
|
146
|
-
error: "Command failed with exit code 1",
|
|
147
|
-
};
|
|
148
|
-
const parsed = ToolResultMessageSchema.parse(message);
|
|
149
|
-
expect(parsed.success).toBe(false);
|
|
150
|
-
expect(parsed.error).toBe("Command failed with exit code 1");
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("accepts minimal tool_result", () => {
|
|
154
|
-
const message = {
|
|
155
|
-
type: "tool_result" as const,
|
|
156
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
157
|
-
};
|
|
158
|
-
expect(ToolResultMessageSchema.parse(message)).toEqual(message);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
describe("ErrorMessageSchema", () => {
|
|
163
|
-
it("accepts valid error message", () => {
|
|
164
|
-
const message = {
|
|
165
|
-
type: "error" as const,
|
|
166
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
167
|
-
message: "Something went wrong",
|
|
168
|
-
};
|
|
169
|
-
expect(ErrorMessageSchema.parse(message).message).toBe(
|
|
170
|
-
"Something went wrong"
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("accepts error with code and stack", () => {
|
|
175
|
-
const message = {
|
|
176
|
-
type: "error" as const,
|
|
177
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
178
|
-
message: "Timeout",
|
|
179
|
-
code: "ERR_TIMEOUT",
|
|
180
|
-
stack: "Error: Timeout\n at foo.ts:10",
|
|
181
|
-
};
|
|
182
|
-
const parsed = ErrorMessageSchema.parse(message);
|
|
183
|
-
expect(parsed.code).toBe("ERR_TIMEOUT");
|
|
184
|
-
expect(parsed.stack).toContain("foo.ts:10");
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("rejects error without message", () => {
|
|
188
|
-
const message = {
|
|
189
|
-
type: "error" as const,
|
|
190
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
191
|
-
};
|
|
192
|
-
expect(() => ErrorMessageSchema.parse(message)).toThrow();
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe("JobOutputMessageSchema (discriminated union)", () => {
|
|
197
|
-
it("parses system message", () => {
|
|
198
|
-
const msg: JobOutputMessage = JobOutputMessageSchema.parse({
|
|
199
|
-
type: "system",
|
|
200
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
201
|
-
content: "Init",
|
|
202
|
-
});
|
|
203
|
-
expect(msg.type).toBe("system");
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("parses assistant message", () => {
|
|
207
|
-
const msg: JobOutputMessage = JobOutputMessageSchema.parse({
|
|
208
|
-
type: "assistant",
|
|
209
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
210
|
-
content: "Hello",
|
|
211
|
-
});
|
|
212
|
-
expect(msg.type).toBe("assistant");
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("parses tool_use message", () => {
|
|
216
|
-
const msg: JobOutputMessage = JobOutputMessageSchema.parse({
|
|
217
|
-
type: "tool_use",
|
|
218
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
219
|
-
tool_name: "test",
|
|
220
|
-
});
|
|
221
|
-
expect(msg.type).toBe("tool_use");
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("parses tool_result message", () => {
|
|
225
|
-
const msg: JobOutputMessage = JobOutputMessageSchema.parse({
|
|
226
|
-
type: "tool_result",
|
|
227
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
228
|
-
});
|
|
229
|
-
expect(msg.type).toBe("tool_result");
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("parses error message", () => {
|
|
233
|
-
const msg: JobOutputMessage = JobOutputMessageSchema.parse({
|
|
234
|
-
type: "error",
|
|
235
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
236
|
-
message: "Oops",
|
|
237
|
-
});
|
|
238
|
-
expect(msg.type).toBe("error");
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it("rejects invalid type", () => {
|
|
242
|
-
expect(() =>
|
|
243
|
-
JobOutputMessageSchema.parse({
|
|
244
|
-
type: "invalid",
|
|
245
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
246
|
-
})
|
|
247
|
-
).toThrow();
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it("rejects missing type", () => {
|
|
251
|
-
expect(() =>
|
|
252
|
-
JobOutputMessageSchema.parse({
|
|
253
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
254
|
-
})
|
|
255
|
-
).toThrow();
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
describe("validateJobOutputMessage", () => {
|
|
260
|
-
it("returns parsed message for valid input", () => {
|
|
261
|
-
const input = {
|
|
262
|
-
type: "assistant",
|
|
263
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
264
|
-
content: "Hello",
|
|
265
|
-
};
|
|
266
|
-
const result = validateJobOutputMessage(input);
|
|
267
|
-
expect(result).not.toBeNull();
|
|
268
|
-
expect(result?.type).toBe("assistant");
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it("returns null for invalid input", () => {
|
|
272
|
-
expect(validateJobOutputMessage({ type: "invalid" })).toBeNull();
|
|
273
|
-
expect(validateJobOutputMessage(null)).toBeNull();
|
|
274
|
-
expect(validateJobOutputMessage("string")).toBeNull();
|
|
275
|
-
expect(validateJobOutputMessage(123)).toBeNull();
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it("returns null for missing required fields", () => {
|
|
279
|
-
expect(
|
|
280
|
-
validateJobOutputMessage({
|
|
281
|
-
type: "error",
|
|
282
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
283
|
-
// missing message
|
|
284
|
-
})
|
|
285
|
-
).toBeNull();
|
|
286
|
-
|
|
287
|
-
expect(
|
|
288
|
-
validateJobOutputMessage({
|
|
289
|
-
type: "tool_use",
|
|
290
|
-
timestamp: "2024-01-15T10:00:00Z",
|
|
291
|
-
// missing tool_name
|
|
292
|
-
})
|
|
293
|
-
).toBeNull();
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
describe("isValidJobOutputInput", () => {
|
|
298
|
-
it("returns true for valid input objects", () => {
|
|
299
|
-
expect(isValidJobOutputInput({ type: "system" })).toBe(true);
|
|
300
|
-
expect(isValidJobOutputInput({ type: "assistant", content: "Hi" })).toBe(
|
|
301
|
-
true
|
|
302
|
-
);
|
|
303
|
-
expect(isValidJobOutputInput({ type: "tool_use", tool_name: "test" })).toBe(
|
|
304
|
-
true
|
|
305
|
-
);
|
|
306
|
-
expect(isValidJobOutputInput({ type: "tool_result" })).toBe(true);
|
|
307
|
-
expect(isValidJobOutputInput({ type: "error", message: "Err" })).toBe(true);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it("returns false for invalid type", () => {
|
|
311
|
-
expect(isValidJobOutputInput({ type: "invalid" })).toBe(false);
|
|
312
|
-
expect(isValidJobOutputInput({ type: "" })).toBe(false);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it("returns false for non-objects", () => {
|
|
316
|
-
expect(isValidJobOutputInput(null)).toBe(false);
|
|
317
|
-
expect(isValidJobOutputInput(undefined)).toBe(false);
|
|
318
|
-
expect(isValidJobOutputInput("string")).toBe(false);
|
|
319
|
-
expect(isValidJobOutputInput(123)).toBe(false);
|
|
320
|
-
expect(isValidJobOutputInput([])).toBe(false);
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
it("returns false for objects without type", () => {
|
|
324
|
-
expect(isValidJobOutputInput({})).toBe(false);
|
|
325
|
-
expect(isValidJobOutputInput({ content: "Hi" })).toBe(false);
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
it("returns false for objects with non-string type", () => {
|
|
329
|
-
expect(isValidJobOutputInput({ type: 123 })).toBe(false);
|
|
330
|
-
expect(isValidJobOutputInput({ type: null })).toBe(false);
|
|
331
|
-
expect(isValidJobOutputInput({ type: {} })).toBe(false);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it("allows objects without timestamp (timestamp added later)", () => {
|
|
335
|
-
const input: JobOutputInput = { type: "assistant", content: "Hi" };
|
|
336
|
-
expect(isValidJobOutputInput(input)).toBe(true);
|
|
337
|
-
});
|
|
338
|
-
});
|