@granular-software/sdk 0.4.18 → 0.4.20
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/README.md +10 -0
- package/dist/agent-evals.d.mts +320 -0
- package/dist/agent-evals.d.ts +320 -0
- package/dist/agent-evals.js +15518 -0
- package/dist/agent-evals.js.map +1 -0
- package/dist/agent-evals.mjs +15484 -0
- package/dist/agent-evals.mjs.map +1 -0
- package/dist/agent-harness.d.mts +121 -0
- package/dist/agent-harness.d.ts +121 -0
- package/dist/agent-harness.js +986 -0
- package/dist/agent-harness.js.map +1 -0
- package/dist/agent-harness.mjs +966 -0
- package/dist/agent-harness.mjs.map +1 -0
- package/dist/cli/index.js +200 -27
- package/dist/client-DWYdWpS-.d.mts +2051 -0
- package/dist/client-DWYdWpS-.d.ts +2051 -0
- package/dist/index.d.mts +34 -1992
- package/dist/index.d.ts +34 -1992
- package/dist/index.js +1392 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1367 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -4
package/README.md
CHANGED
|
@@ -456,6 +456,16 @@ Defines domain ontology: classes (with typed properties), and relationships (wit
|
|
|
456
456
|
### `environment.recordObject(options)`
|
|
457
457
|
Creates or updates a class instance with fields and relationships. Returns `{ path, id, created }`.
|
|
458
458
|
|
|
459
|
+
### `environment.recordObjects(records, options?)`
|
|
460
|
+
Batch upsert for many instances. The SDK sends **chunks** (default **100** rows per HTTP `POST` to `/records/batch`) with **retries** on transient failures, so large arrays do not time out as a single oversized request.
|
|
461
|
+
|
|
462
|
+
Optional **`options`**:
|
|
463
|
+
- **`batchSize`** — max rows per request (default 100).
|
|
464
|
+
- **`concurrency`** — how many chunk requests may run in parallel (default 1, max 16); can reduce wall time when the server can overlap work.
|
|
465
|
+
- **`onChunkComplete`** — async-friendly hook after each chunk for progress UIs; the returned array is always ordered like `records`.
|
|
466
|
+
|
|
467
|
+
**Sync batch vs queued import:** use **`recordObjects`** when you need **synchronous** commits and/or per-chunk feedback. Use **`enqueueRecordImport`** + **`getRecordImport` / `getRecordImportSummary`** for **background** ingestion with aggregate counters when admission latency matters more than immediate row-by-row completion.
|
|
468
|
+
|
|
459
469
|
### `environment.getRelationships(modelPath)`
|
|
460
470
|
Returns relationship definitions for a given class.
|
|
461
471
|
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { P as Prompt, c as Environment, b as SessionHeapSnapshot, a$ as ManifestContent, ax as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, y as CreateEnvironmentData, i as GranularOptions } from './client-DWYdWpS-.mjs';
|
|
2
|
+
import { GeneratedJobCodeIssue, HarnessControllerBudgets } from './agent-harness.mjs';
|
|
3
|
+
import '@automerge/automerge';
|
|
4
|
+
import '@automerge/automerge/slim';
|
|
5
|
+
|
|
6
|
+
type EvalMatcher = string | RegExp;
|
|
7
|
+
interface AgentEvalPromptInteraction {
|
|
8
|
+
promptId: string;
|
|
9
|
+
type: string;
|
|
10
|
+
title: string;
|
|
11
|
+
message: string;
|
|
12
|
+
answer: unknown;
|
|
13
|
+
}
|
|
14
|
+
interface AgentEvalGenerationInput {
|
|
15
|
+
systemPrompt: string;
|
|
16
|
+
history: Array<{
|
|
17
|
+
role: "user" | "assistant";
|
|
18
|
+
content: string;
|
|
19
|
+
}>;
|
|
20
|
+
request: string;
|
|
21
|
+
attempt: number;
|
|
22
|
+
repairIssues?: GeneratedJobCodeIssue[];
|
|
23
|
+
}
|
|
24
|
+
interface AgentEvalGenerationOutput {
|
|
25
|
+
reply?: string;
|
|
26
|
+
code?: string;
|
|
27
|
+
raw?: unknown;
|
|
28
|
+
}
|
|
29
|
+
type AgentEvalTurnGenerator = (input: AgentEvalGenerationInput) => Promise<AgentEvalGenerationOutput>;
|
|
30
|
+
interface ScriptedPromptRule {
|
|
31
|
+
type?: Prompt["type"];
|
|
32
|
+
when?: EvalMatcher | EvalMatcher[];
|
|
33
|
+
answer: unknown | ((input: {
|
|
34
|
+
prompt: Prompt;
|
|
35
|
+
history: AgentEvalPromptInteraction[];
|
|
36
|
+
}) => unknown | Promise<unknown>);
|
|
37
|
+
}
|
|
38
|
+
type AgentEvalPromptResponder = (input: {
|
|
39
|
+
prompt: Prompt;
|
|
40
|
+
history: AgentEvalPromptInteraction[];
|
|
41
|
+
}) => Promise<unknown>;
|
|
42
|
+
interface AgentEvalExpectations {
|
|
43
|
+
replyIncludes?: EvalMatcher[];
|
|
44
|
+
replyExcludes?: EvalMatcher[];
|
|
45
|
+
actionIncludes?: EvalMatcher[];
|
|
46
|
+
actionExcludes?: EvalMatcher[];
|
|
47
|
+
codeIncludes?: EvalMatcher[];
|
|
48
|
+
codeExcludes?: EvalMatcher[];
|
|
49
|
+
}
|
|
50
|
+
interface AgentEvalCheckContext {
|
|
51
|
+
conversation: AgentEvalConversation;
|
|
52
|
+
environment: Environment;
|
|
53
|
+
turnDir: string;
|
|
54
|
+
request: string;
|
|
55
|
+
responseText: string;
|
|
56
|
+
terminalKind: "reply" | "closure";
|
|
57
|
+
finalCode?: string;
|
|
58
|
+
actionSummary: string[];
|
|
59
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
60
|
+
result: unknown;
|
|
61
|
+
heap: SessionHeapSnapshot;
|
|
62
|
+
openPrompts: Prompt[];
|
|
63
|
+
liveDoc: Record<string, unknown>;
|
|
64
|
+
inspect: (code: string) => Promise<unknown>;
|
|
65
|
+
assertMatches: (label: string, text: string, includes?: EvalMatcher[], excludes?: EvalMatcher[]) => void;
|
|
66
|
+
}
|
|
67
|
+
type AgentEvalCheck = (context: AgentEvalCheckContext) => Promise<void> | void;
|
|
68
|
+
interface AgentEvalInspection {
|
|
69
|
+
code: string;
|
|
70
|
+
includes?: EvalMatcher[];
|
|
71
|
+
excludes?: EvalMatcher[];
|
|
72
|
+
check?: AgentEvalCheck;
|
|
73
|
+
}
|
|
74
|
+
interface AgentEvalSetupContext {
|
|
75
|
+
conversation: AgentEvalConversation;
|
|
76
|
+
environment: Environment;
|
|
77
|
+
turnDir: string;
|
|
78
|
+
}
|
|
79
|
+
interface AgentEvalSetup {
|
|
80
|
+
manifest?: ManifestContent;
|
|
81
|
+
records?: RecordObjectOptions[];
|
|
82
|
+
effects?: ToolWithHandler[];
|
|
83
|
+
run?: (input: AgentEvalSetupContext) => Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
interface AgentEvalPrepareContext {
|
|
86
|
+
conversation: AgentEvalConversation;
|
|
87
|
+
environment: Environment;
|
|
88
|
+
turnDir: string;
|
|
89
|
+
}
|
|
90
|
+
interface AgentEvalStep {
|
|
91
|
+
id?: string;
|
|
92
|
+
title?: string;
|
|
93
|
+
request: string;
|
|
94
|
+
setup?: AgentEvalSetup;
|
|
95
|
+
human?: AgentEvalPromptResponder;
|
|
96
|
+
expect?: AgentEvalExpectations;
|
|
97
|
+
inspect?: AgentEvalInspection | AgentEvalInspection[];
|
|
98
|
+
check?: AgentEvalCheck | AgentEvalCheck[];
|
|
99
|
+
maxIterations?: number;
|
|
100
|
+
autoAnswerPrompts?: boolean;
|
|
101
|
+
}
|
|
102
|
+
interface AgentEvalScenario {
|
|
103
|
+
id: string;
|
|
104
|
+
request?: string;
|
|
105
|
+
steps?: AgentEvalStep[];
|
|
106
|
+
setup?: AgentEvalSetup;
|
|
107
|
+
prepareRecords?: RecordObjectOptions[];
|
|
108
|
+
prepareTools?: ToolWithHandler[];
|
|
109
|
+
prepare?: (input: AgentEvalPrepareContext) => Promise<void>;
|
|
110
|
+
human?: AgentEvalPromptResponder;
|
|
111
|
+
expect?: AgentEvalExpectations;
|
|
112
|
+
verify?: AgentEvalInspection;
|
|
113
|
+
inspect?: AgentEvalInspection | AgentEvalInspection[];
|
|
114
|
+
check?: AgentEvalCheck | AgentEvalCheck[];
|
|
115
|
+
maxIterations?: number;
|
|
116
|
+
}
|
|
117
|
+
interface AgentEvalStepResult {
|
|
118
|
+
id: string;
|
|
119
|
+
request: string;
|
|
120
|
+
responseText: string;
|
|
121
|
+
terminalKind: "reply" | "closure";
|
|
122
|
+
finalCode?: string;
|
|
123
|
+
actionSummary: string[];
|
|
124
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
125
|
+
inspectionResults: unknown[];
|
|
126
|
+
turnDir: string;
|
|
127
|
+
}
|
|
128
|
+
interface AgentEvalResult {
|
|
129
|
+
scenario: AgentEvalScenario;
|
|
130
|
+
status: "passed" | "failed";
|
|
131
|
+
responseText: string;
|
|
132
|
+
terminalKind: "reply" | "closure";
|
|
133
|
+
finalCode?: string;
|
|
134
|
+
actionSummary: string[];
|
|
135
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
136
|
+
verification: unknown | null;
|
|
137
|
+
steps?: AgentEvalStepResult[];
|
|
138
|
+
turnDir: string;
|
|
139
|
+
error?: string;
|
|
140
|
+
}
|
|
141
|
+
interface AgentEvalSuiteResult {
|
|
142
|
+
artifactDir: string;
|
|
143
|
+
results: AgentEvalResult[];
|
|
144
|
+
}
|
|
145
|
+
interface AgentEvalHarnessOptions {
|
|
146
|
+
granular: Granular;
|
|
147
|
+
environmentId?: string;
|
|
148
|
+
openEnvironment?: (input: {
|
|
149
|
+
label: string;
|
|
150
|
+
clientId: string;
|
|
151
|
+
}) => Promise<Environment>;
|
|
152
|
+
generator: AgentEvalTurnGenerator;
|
|
153
|
+
artifactBaseDir?: string;
|
|
154
|
+
suiteName?: string;
|
|
155
|
+
controllerBudgets?: HarnessControllerBudgets;
|
|
156
|
+
chatTimeoutMs?: number;
|
|
157
|
+
jobTimeoutMs?: number;
|
|
158
|
+
pollIntervalMs?: number;
|
|
159
|
+
}
|
|
160
|
+
interface AgentEvalConversation {
|
|
161
|
+
label: string;
|
|
162
|
+
environment: Environment;
|
|
163
|
+
history: AgentEvalHistoryEntry[];
|
|
164
|
+
promptEvents: PendingPromptEvent[];
|
|
165
|
+
artifactDir: string;
|
|
166
|
+
turnCount: number;
|
|
167
|
+
}
|
|
168
|
+
interface AgentEvalPendingTurn {
|
|
169
|
+
conversation: AgentEvalConversation;
|
|
170
|
+
request: string;
|
|
171
|
+
turnDir: string;
|
|
172
|
+
boundaryTimestamp: number;
|
|
173
|
+
finalCode: string;
|
|
174
|
+
finalReply: string;
|
|
175
|
+
stdout: string[];
|
|
176
|
+
stderr: string[];
|
|
177
|
+
prompts: Prompt[];
|
|
178
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
179
|
+
job: {
|
|
180
|
+
id: string;
|
|
181
|
+
result: Promise<unknown>;
|
|
182
|
+
on: (event: string, handler: (data: unknown) => void) => void;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
interface AgentEvalCompletedTurn {
|
|
186
|
+
conversation: AgentEvalConversation;
|
|
187
|
+
request: string;
|
|
188
|
+
turnDir: string;
|
|
189
|
+
responseText: string;
|
|
190
|
+
terminalKind: "reply" | "closure";
|
|
191
|
+
finalCode?: string;
|
|
192
|
+
actionSummary: string[];
|
|
193
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
194
|
+
verification: unknown | null;
|
|
195
|
+
result: unknown;
|
|
196
|
+
}
|
|
197
|
+
interface AgentEvalHistoryEntry {
|
|
198
|
+
role: "user" | "assistant";
|
|
199
|
+
content: string;
|
|
200
|
+
code?: string;
|
|
201
|
+
jobStatus?: string;
|
|
202
|
+
jobResultPreview?: string;
|
|
203
|
+
error?: string;
|
|
204
|
+
}
|
|
205
|
+
interface PendingPromptEvent {
|
|
206
|
+
prompt: Prompt;
|
|
207
|
+
receivedAt: number;
|
|
208
|
+
}
|
|
209
|
+
declare function createTimestampedArtifactDirectory(options?: {
|
|
210
|
+
baseDir?: string;
|
|
211
|
+
suiteName?: string;
|
|
212
|
+
}): string;
|
|
213
|
+
declare function createScriptedPromptResponder(rules: ScriptedPromptRule[], fallback?: AgentEvalPromptResponder): AgentEvalPromptResponder;
|
|
214
|
+
declare function createOpenAIChatTurnGenerator(options: {
|
|
215
|
+
apiKey: string;
|
|
216
|
+
model?: string;
|
|
217
|
+
baseUrl?: string;
|
|
218
|
+
temperature?: number;
|
|
219
|
+
headers?: Record<string, string>;
|
|
220
|
+
}): AgentEvalTurnGenerator;
|
|
221
|
+
declare function runAgentEvalSuite(options: {
|
|
222
|
+
harness: ReturnType<typeof createAgentEvalHarness>;
|
|
223
|
+
scenarios: AgentEvalScenario[];
|
|
224
|
+
}): Promise<AgentEvalSuiteResult>;
|
|
225
|
+
declare function createAgentEvalHarness(options: AgentEvalHarnessOptions): {
|
|
226
|
+
artifactDir: string;
|
|
227
|
+
openConversation: (label: string) => Promise<AgentEvalConversation>;
|
|
228
|
+
closeConversation: (conversation: AgentEvalConversation) => Promise<void>;
|
|
229
|
+
runTurn: (input: {
|
|
230
|
+
conversation: AgentEvalConversation;
|
|
231
|
+
request: string;
|
|
232
|
+
prepareRecords?: RecordObjectOptions[];
|
|
233
|
+
prepareTools?: ToolWithHandler[];
|
|
234
|
+
prepare?: (ctx: AgentEvalPrepareContext) => Promise<void>;
|
|
235
|
+
human?: AgentEvalPromptResponder;
|
|
236
|
+
verification?: AgentEvalInspection;
|
|
237
|
+
maxIterations?: number;
|
|
238
|
+
autoAnswerPrompts?: boolean;
|
|
239
|
+
}) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
240
|
+
resumePendingTurn: (pending: AgentEvalPendingTurn, responder: AgentEvalPromptResponder) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
241
|
+
};
|
|
242
|
+
type AgentTestTarget = {
|
|
243
|
+
environmentId: string;
|
|
244
|
+
} | {
|
|
245
|
+
connect: ConnectOptions;
|
|
246
|
+
} | {
|
|
247
|
+
createEnvironment: {
|
|
248
|
+
sandboxId: string;
|
|
249
|
+
data: CreateEnvironmentData;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
interface AgentTesterOptions {
|
|
253
|
+
granular?: Granular;
|
|
254
|
+
client?: Granular;
|
|
255
|
+
apiKey?: string;
|
|
256
|
+
token?: string;
|
|
257
|
+
apiUrl?: string;
|
|
258
|
+
local?: boolean;
|
|
259
|
+
granularOptions?: Omit<GranularOptions, "apiKey" | "token" | "apiUrl" | "endpointMode">;
|
|
260
|
+
generator?: AgentEvalTurnGenerator;
|
|
261
|
+
openai?: {
|
|
262
|
+
apiKey: string;
|
|
263
|
+
model?: string;
|
|
264
|
+
baseUrl?: string;
|
|
265
|
+
temperature?: number;
|
|
266
|
+
headers?: Record<string, string>;
|
|
267
|
+
};
|
|
268
|
+
model?: string;
|
|
269
|
+
target: AgentTestTarget;
|
|
270
|
+
artifactBaseDir?: string;
|
|
271
|
+
suiteName?: string;
|
|
272
|
+
controllerBudgets?: HarnessControllerBudgets;
|
|
273
|
+
chatTimeoutMs?: number;
|
|
274
|
+
jobTimeoutMs?: number;
|
|
275
|
+
pollIntervalMs?: number;
|
|
276
|
+
}
|
|
277
|
+
declare function createAgentTester(options: AgentTesterOptions): {
|
|
278
|
+
granular: Granular;
|
|
279
|
+
generator: AgentEvalTurnGenerator;
|
|
280
|
+
environmentId: string | null;
|
|
281
|
+
openThread: (label: string) => Promise<AgentEvalConversation>;
|
|
282
|
+
closeThread: (conversation: AgentEvalConversation) => Promise<void>;
|
|
283
|
+
runStep: (input: {
|
|
284
|
+
conversation: AgentEvalConversation;
|
|
285
|
+
request: string;
|
|
286
|
+
prepareRecords?: RecordObjectOptions[];
|
|
287
|
+
prepareTools?: ToolWithHandler[];
|
|
288
|
+
prepare?: (ctx: AgentEvalPrepareContext) => Promise<void>;
|
|
289
|
+
human?: AgentEvalPromptResponder;
|
|
290
|
+
verification?: AgentEvalInspection;
|
|
291
|
+
maxIterations?: number;
|
|
292
|
+
autoAnswerPrompts?: boolean;
|
|
293
|
+
}) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
294
|
+
continueStep: (pending: AgentEvalPendingTurn, responder: AgentEvalPromptResponder) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
295
|
+
runSuite: (scenarios: AgentEvalScenario[]) => Promise<AgentEvalSuiteResult>;
|
|
296
|
+
artifactDir: string;
|
|
297
|
+
openConversation: (label: string) => Promise<AgentEvalConversation>;
|
|
298
|
+
closeConversation: (conversation: AgentEvalConversation) => Promise<void>;
|
|
299
|
+
runTurn: (input: {
|
|
300
|
+
conversation: AgentEvalConversation;
|
|
301
|
+
request: string;
|
|
302
|
+
prepareRecords?: RecordObjectOptions[];
|
|
303
|
+
prepareTools?: ToolWithHandler[];
|
|
304
|
+
prepare?: (ctx: AgentEvalPrepareContext) => Promise<void>;
|
|
305
|
+
human?: AgentEvalPromptResponder;
|
|
306
|
+
verification?: AgentEvalInspection;
|
|
307
|
+
maxIterations?: number;
|
|
308
|
+
autoAnswerPrompts?: boolean;
|
|
309
|
+
}) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
310
|
+
resumePendingTurn: (pending: AgentEvalPendingTurn, responder: AgentEvalPromptResponder) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
311
|
+
};
|
|
312
|
+
declare function runAgentTests(options: {
|
|
313
|
+
tester: ReturnType<typeof createAgentTester> | ReturnType<typeof createAgentEvalHarness>;
|
|
314
|
+
scenarios: AgentEvalScenario[];
|
|
315
|
+
}): Promise<AgentEvalSuiteResult>;
|
|
316
|
+
declare const createHumanResponder: typeof createScriptedPromptResponder;
|
|
317
|
+
declare const createOpenAIGenerator: typeof createOpenAIChatTurnGenerator;
|
|
318
|
+
declare const createTestArtifactsDirectory: typeof createTimestampedArtifactDirectory;
|
|
319
|
+
|
|
320
|
+
export { type AgentEvalCheck, type AgentEvalCheckContext, type AgentEvalCompletedTurn, type AgentEvalConversation, type AgentEvalExpectations, type AgentEvalGenerationInput, type AgentEvalGenerationOutput, type AgentEvalHarnessOptions, type AgentEvalInspection, type AgentEvalPendingTurn, type AgentEvalPrepareContext, type AgentEvalPromptInteraction, type AgentEvalPromptResponder, type AgentEvalResult, type AgentEvalScenario, type AgentEvalSetup, type AgentEvalSetupContext, type AgentEvalStep, type AgentEvalStepResult, type AgentEvalSuiteResult, type AgentEvalTurnGenerator, type AgentTestTarget, type AgentTesterOptions, type EvalMatcher, type ScriptedPromptRule, createAgentEvalHarness, createAgentTester, createHumanResponder, createOpenAIChatTurnGenerator, createOpenAIGenerator, createScriptedPromptResponder, createTestArtifactsDirectory, createTimestampedArtifactDirectory, runAgentEvalSuite, runAgentTests };
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { P as Prompt, c as Environment, b as SessionHeapSnapshot, a$ as ManifestContent, ax as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, y as CreateEnvironmentData, i as GranularOptions } from './client-DWYdWpS-.js';
|
|
2
|
+
import { GeneratedJobCodeIssue, HarnessControllerBudgets } from './agent-harness.js';
|
|
3
|
+
import '@automerge/automerge';
|
|
4
|
+
import '@automerge/automerge/slim';
|
|
5
|
+
|
|
6
|
+
type EvalMatcher = string | RegExp;
|
|
7
|
+
interface AgentEvalPromptInteraction {
|
|
8
|
+
promptId: string;
|
|
9
|
+
type: string;
|
|
10
|
+
title: string;
|
|
11
|
+
message: string;
|
|
12
|
+
answer: unknown;
|
|
13
|
+
}
|
|
14
|
+
interface AgentEvalGenerationInput {
|
|
15
|
+
systemPrompt: string;
|
|
16
|
+
history: Array<{
|
|
17
|
+
role: "user" | "assistant";
|
|
18
|
+
content: string;
|
|
19
|
+
}>;
|
|
20
|
+
request: string;
|
|
21
|
+
attempt: number;
|
|
22
|
+
repairIssues?: GeneratedJobCodeIssue[];
|
|
23
|
+
}
|
|
24
|
+
interface AgentEvalGenerationOutput {
|
|
25
|
+
reply?: string;
|
|
26
|
+
code?: string;
|
|
27
|
+
raw?: unknown;
|
|
28
|
+
}
|
|
29
|
+
type AgentEvalTurnGenerator = (input: AgentEvalGenerationInput) => Promise<AgentEvalGenerationOutput>;
|
|
30
|
+
interface ScriptedPromptRule {
|
|
31
|
+
type?: Prompt["type"];
|
|
32
|
+
when?: EvalMatcher | EvalMatcher[];
|
|
33
|
+
answer: unknown | ((input: {
|
|
34
|
+
prompt: Prompt;
|
|
35
|
+
history: AgentEvalPromptInteraction[];
|
|
36
|
+
}) => unknown | Promise<unknown>);
|
|
37
|
+
}
|
|
38
|
+
type AgentEvalPromptResponder = (input: {
|
|
39
|
+
prompt: Prompt;
|
|
40
|
+
history: AgentEvalPromptInteraction[];
|
|
41
|
+
}) => Promise<unknown>;
|
|
42
|
+
interface AgentEvalExpectations {
|
|
43
|
+
replyIncludes?: EvalMatcher[];
|
|
44
|
+
replyExcludes?: EvalMatcher[];
|
|
45
|
+
actionIncludes?: EvalMatcher[];
|
|
46
|
+
actionExcludes?: EvalMatcher[];
|
|
47
|
+
codeIncludes?: EvalMatcher[];
|
|
48
|
+
codeExcludes?: EvalMatcher[];
|
|
49
|
+
}
|
|
50
|
+
interface AgentEvalCheckContext {
|
|
51
|
+
conversation: AgentEvalConversation;
|
|
52
|
+
environment: Environment;
|
|
53
|
+
turnDir: string;
|
|
54
|
+
request: string;
|
|
55
|
+
responseText: string;
|
|
56
|
+
terminalKind: "reply" | "closure";
|
|
57
|
+
finalCode?: string;
|
|
58
|
+
actionSummary: string[];
|
|
59
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
60
|
+
result: unknown;
|
|
61
|
+
heap: SessionHeapSnapshot;
|
|
62
|
+
openPrompts: Prompt[];
|
|
63
|
+
liveDoc: Record<string, unknown>;
|
|
64
|
+
inspect: (code: string) => Promise<unknown>;
|
|
65
|
+
assertMatches: (label: string, text: string, includes?: EvalMatcher[], excludes?: EvalMatcher[]) => void;
|
|
66
|
+
}
|
|
67
|
+
type AgentEvalCheck = (context: AgentEvalCheckContext) => Promise<void> | void;
|
|
68
|
+
interface AgentEvalInspection {
|
|
69
|
+
code: string;
|
|
70
|
+
includes?: EvalMatcher[];
|
|
71
|
+
excludes?: EvalMatcher[];
|
|
72
|
+
check?: AgentEvalCheck;
|
|
73
|
+
}
|
|
74
|
+
interface AgentEvalSetupContext {
|
|
75
|
+
conversation: AgentEvalConversation;
|
|
76
|
+
environment: Environment;
|
|
77
|
+
turnDir: string;
|
|
78
|
+
}
|
|
79
|
+
interface AgentEvalSetup {
|
|
80
|
+
manifest?: ManifestContent;
|
|
81
|
+
records?: RecordObjectOptions[];
|
|
82
|
+
effects?: ToolWithHandler[];
|
|
83
|
+
run?: (input: AgentEvalSetupContext) => Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
interface AgentEvalPrepareContext {
|
|
86
|
+
conversation: AgentEvalConversation;
|
|
87
|
+
environment: Environment;
|
|
88
|
+
turnDir: string;
|
|
89
|
+
}
|
|
90
|
+
interface AgentEvalStep {
|
|
91
|
+
id?: string;
|
|
92
|
+
title?: string;
|
|
93
|
+
request: string;
|
|
94
|
+
setup?: AgentEvalSetup;
|
|
95
|
+
human?: AgentEvalPromptResponder;
|
|
96
|
+
expect?: AgentEvalExpectations;
|
|
97
|
+
inspect?: AgentEvalInspection | AgentEvalInspection[];
|
|
98
|
+
check?: AgentEvalCheck | AgentEvalCheck[];
|
|
99
|
+
maxIterations?: number;
|
|
100
|
+
autoAnswerPrompts?: boolean;
|
|
101
|
+
}
|
|
102
|
+
interface AgentEvalScenario {
|
|
103
|
+
id: string;
|
|
104
|
+
request?: string;
|
|
105
|
+
steps?: AgentEvalStep[];
|
|
106
|
+
setup?: AgentEvalSetup;
|
|
107
|
+
prepareRecords?: RecordObjectOptions[];
|
|
108
|
+
prepareTools?: ToolWithHandler[];
|
|
109
|
+
prepare?: (input: AgentEvalPrepareContext) => Promise<void>;
|
|
110
|
+
human?: AgentEvalPromptResponder;
|
|
111
|
+
expect?: AgentEvalExpectations;
|
|
112
|
+
verify?: AgentEvalInspection;
|
|
113
|
+
inspect?: AgentEvalInspection | AgentEvalInspection[];
|
|
114
|
+
check?: AgentEvalCheck | AgentEvalCheck[];
|
|
115
|
+
maxIterations?: number;
|
|
116
|
+
}
|
|
117
|
+
interface AgentEvalStepResult {
|
|
118
|
+
id: string;
|
|
119
|
+
request: string;
|
|
120
|
+
responseText: string;
|
|
121
|
+
terminalKind: "reply" | "closure";
|
|
122
|
+
finalCode?: string;
|
|
123
|
+
actionSummary: string[];
|
|
124
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
125
|
+
inspectionResults: unknown[];
|
|
126
|
+
turnDir: string;
|
|
127
|
+
}
|
|
128
|
+
interface AgentEvalResult {
|
|
129
|
+
scenario: AgentEvalScenario;
|
|
130
|
+
status: "passed" | "failed";
|
|
131
|
+
responseText: string;
|
|
132
|
+
terminalKind: "reply" | "closure";
|
|
133
|
+
finalCode?: string;
|
|
134
|
+
actionSummary: string[];
|
|
135
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
136
|
+
verification: unknown | null;
|
|
137
|
+
steps?: AgentEvalStepResult[];
|
|
138
|
+
turnDir: string;
|
|
139
|
+
error?: string;
|
|
140
|
+
}
|
|
141
|
+
interface AgentEvalSuiteResult {
|
|
142
|
+
artifactDir: string;
|
|
143
|
+
results: AgentEvalResult[];
|
|
144
|
+
}
|
|
145
|
+
interface AgentEvalHarnessOptions {
|
|
146
|
+
granular: Granular;
|
|
147
|
+
environmentId?: string;
|
|
148
|
+
openEnvironment?: (input: {
|
|
149
|
+
label: string;
|
|
150
|
+
clientId: string;
|
|
151
|
+
}) => Promise<Environment>;
|
|
152
|
+
generator: AgentEvalTurnGenerator;
|
|
153
|
+
artifactBaseDir?: string;
|
|
154
|
+
suiteName?: string;
|
|
155
|
+
controllerBudgets?: HarnessControllerBudgets;
|
|
156
|
+
chatTimeoutMs?: number;
|
|
157
|
+
jobTimeoutMs?: number;
|
|
158
|
+
pollIntervalMs?: number;
|
|
159
|
+
}
|
|
160
|
+
interface AgentEvalConversation {
|
|
161
|
+
label: string;
|
|
162
|
+
environment: Environment;
|
|
163
|
+
history: AgentEvalHistoryEntry[];
|
|
164
|
+
promptEvents: PendingPromptEvent[];
|
|
165
|
+
artifactDir: string;
|
|
166
|
+
turnCount: number;
|
|
167
|
+
}
|
|
168
|
+
interface AgentEvalPendingTurn {
|
|
169
|
+
conversation: AgentEvalConversation;
|
|
170
|
+
request: string;
|
|
171
|
+
turnDir: string;
|
|
172
|
+
boundaryTimestamp: number;
|
|
173
|
+
finalCode: string;
|
|
174
|
+
finalReply: string;
|
|
175
|
+
stdout: string[];
|
|
176
|
+
stderr: string[];
|
|
177
|
+
prompts: Prompt[];
|
|
178
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
179
|
+
job: {
|
|
180
|
+
id: string;
|
|
181
|
+
result: Promise<unknown>;
|
|
182
|
+
on: (event: string, handler: (data: unknown) => void) => void;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
interface AgentEvalCompletedTurn {
|
|
186
|
+
conversation: AgentEvalConversation;
|
|
187
|
+
request: string;
|
|
188
|
+
turnDir: string;
|
|
189
|
+
responseText: string;
|
|
190
|
+
terminalKind: "reply" | "closure";
|
|
191
|
+
finalCode?: string;
|
|
192
|
+
actionSummary: string[];
|
|
193
|
+
promptInteractions: AgentEvalPromptInteraction[];
|
|
194
|
+
verification: unknown | null;
|
|
195
|
+
result: unknown;
|
|
196
|
+
}
|
|
197
|
+
interface AgentEvalHistoryEntry {
|
|
198
|
+
role: "user" | "assistant";
|
|
199
|
+
content: string;
|
|
200
|
+
code?: string;
|
|
201
|
+
jobStatus?: string;
|
|
202
|
+
jobResultPreview?: string;
|
|
203
|
+
error?: string;
|
|
204
|
+
}
|
|
205
|
+
interface PendingPromptEvent {
|
|
206
|
+
prompt: Prompt;
|
|
207
|
+
receivedAt: number;
|
|
208
|
+
}
|
|
209
|
+
declare function createTimestampedArtifactDirectory(options?: {
|
|
210
|
+
baseDir?: string;
|
|
211
|
+
suiteName?: string;
|
|
212
|
+
}): string;
|
|
213
|
+
declare function createScriptedPromptResponder(rules: ScriptedPromptRule[], fallback?: AgentEvalPromptResponder): AgentEvalPromptResponder;
|
|
214
|
+
declare function createOpenAIChatTurnGenerator(options: {
|
|
215
|
+
apiKey: string;
|
|
216
|
+
model?: string;
|
|
217
|
+
baseUrl?: string;
|
|
218
|
+
temperature?: number;
|
|
219
|
+
headers?: Record<string, string>;
|
|
220
|
+
}): AgentEvalTurnGenerator;
|
|
221
|
+
declare function runAgentEvalSuite(options: {
|
|
222
|
+
harness: ReturnType<typeof createAgentEvalHarness>;
|
|
223
|
+
scenarios: AgentEvalScenario[];
|
|
224
|
+
}): Promise<AgentEvalSuiteResult>;
|
|
225
|
+
declare function createAgentEvalHarness(options: AgentEvalHarnessOptions): {
|
|
226
|
+
artifactDir: string;
|
|
227
|
+
openConversation: (label: string) => Promise<AgentEvalConversation>;
|
|
228
|
+
closeConversation: (conversation: AgentEvalConversation) => Promise<void>;
|
|
229
|
+
runTurn: (input: {
|
|
230
|
+
conversation: AgentEvalConversation;
|
|
231
|
+
request: string;
|
|
232
|
+
prepareRecords?: RecordObjectOptions[];
|
|
233
|
+
prepareTools?: ToolWithHandler[];
|
|
234
|
+
prepare?: (ctx: AgentEvalPrepareContext) => Promise<void>;
|
|
235
|
+
human?: AgentEvalPromptResponder;
|
|
236
|
+
verification?: AgentEvalInspection;
|
|
237
|
+
maxIterations?: number;
|
|
238
|
+
autoAnswerPrompts?: boolean;
|
|
239
|
+
}) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
240
|
+
resumePendingTurn: (pending: AgentEvalPendingTurn, responder: AgentEvalPromptResponder) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
241
|
+
};
|
|
242
|
+
type AgentTestTarget = {
|
|
243
|
+
environmentId: string;
|
|
244
|
+
} | {
|
|
245
|
+
connect: ConnectOptions;
|
|
246
|
+
} | {
|
|
247
|
+
createEnvironment: {
|
|
248
|
+
sandboxId: string;
|
|
249
|
+
data: CreateEnvironmentData;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
interface AgentTesterOptions {
|
|
253
|
+
granular?: Granular;
|
|
254
|
+
client?: Granular;
|
|
255
|
+
apiKey?: string;
|
|
256
|
+
token?: string;
|
|
257
|
+
apiUrl?: string;
|
|
258
|
+
local?: boolean;
|
|
259
|
+
granularOptions?: Omit<GranularOptions, "apiKey" | "token" | "apiUrl" | "endpointMode">;
|
|
260
|
+
generator?: AgentEvalTurnGenerator;
|
|
261
|
+
openai?: {
|
|
262
|
+
apiKey: string;
|
|
263
|
+
model?: string;
|
|
264
|
+
baseUrl?: string;
|
|
265
|
+
temperature?: number;
|
|
266
|
+
headers?: Record<string, string>;
|
|
267
|
+
};
|
|
268
|
+
model?: string;
|
|
269
|
+
target: AgentTestTarget;
|
|
270
|
+
artifactBaseDir?: string;
|
|
271
|
+
suiteName?: string;
|
|
272
|
+
controllerBudgets?: HarnessControllerBudgets;
|
|
273
|
+
chatTimeoutMs?: number;
|
|
274
|
+
jobTimeoutMs?: number;
|
|
275
|
+
pollIntervalMs?: number;
|
|
276
|
+
}
|
|
277
|
+
declare function createAgentTester(options: AgentTesterOptions): {
|
|
278
|
+
granular: Granular;
|
|
279
|
+
generator: AgentEvalTurnGenerator;
|
|
280
|
+
environmentId: string | null;
|
|
281
|
+
openThread: (label: string) => Promise<AgentEvalConversation>;
|
|
282
|
+
closeThread: (conversation: AgentEvalConversation) => Promise<void>;
|
|
283
|
+
runStep: (input: {
|
|
284
|
+
conversation: AgentEvalConversation;
|
|
285
|
+
request: string;
|
|
286
|
+
prepareRecords?: RecordObjectOptions[];
|
|
287
|
+
prepareTools?: ToolWithHandler[];
|
|
288
|
+
prepare?: (ctx: AgentEvalPrepareContext) => Promise<void>;
|
|
289
|
+
human?: AgentEvalPromptResponder;
|
|
290
|
+
verification?: AgentEvalInspection;
|
|
291
|
+
maxIterations?: number;
|
|
292
|
+
autoAnswerPrompts?: boolean;
|
|
293
|
+
}) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
294
|
+
continueStep: (pending: AgentEvalPendingTurn, responder: AgentEvalPromptResponder) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
295
|
+
runSuite: (scenarios: AgentEvalScenario[]) => Promise<AgentEvalSuiteResult>;
|
|
296
|
+
artifactDir: string;
|
|
297
|
+
openConversation: (label: string) => Promise<AgentEvalConversation>;
|
|
298
|
+
closeConversation: (conversation: AgentEvalConversation) => Promise<void>;
|
|
299
|
+
runTurn: (input: {
|
|
300
|
+
conversation: AgentEvalConversation;
|
|
301
|
+
request: string;
|
|
302
|
+
prepareRecords?: RecordObjectOptions[];
|
|
303
|
+
prepareTools?: ToolWithHandler[];
|
|
304
|
+
prepare?: (ctx: AgentEvalPrepareContext) => Promise<void>;
|
|
305
|
+
human?: AgentEvalPromptResponder;
|
|
306
|
+
verification?: AgentEvalInspection;
|
|
307
|
+
maxIterations?: number;
|
|
308
|
+
autoAnswerPrompts?: boolean;
|
|
309
|
+
}) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
310
|
+
resumePendingTurn: (pending: AgentEvalPendingTurn, responder: AgentEvalPromptResponder) => Promise<AgentEvalCompletedTurn | AgentEvalPendingTurn>;
|
|
311
|
+
};
|
|
312
|
+
declare function runAgentTests(options: {
|
|
313
|
+
tester: ReturnType<typeof createAgentTester> | ReturnType<typeof createAgentEvalHarness>;
|
|
314
|
+
scenarios: AgentEvalScenario[];
|
|
315
|
+
}): Promise<AgentEvalSuiteResult>;
|
|
316
|
+
declare const createHumanResponder: typeof createScriptedPromptResponder;
|
|
317
|
+
declare const createOpenAIGenerator: typeof createOpenAIChatTurnGenerator;
|
|
318
|
+
declare const createTestArtifactsDirectory: typeof createTimestampedArtifactDirectory;
|
|
319
|
+
|
|
320
|
+
export { type AgentEvalCheck, type AgentEvalCheckContext, type AgentEvalCompletedTurn, type AgentEvalConversation, type AgentEvalExpectations, type AgentEvalGenerationInput, type AgentEvalGenerationOutput, type AgentEvalHarnessOptions, type AgentEvalInspection, type AgentEvalPendingTurn, type AgentEvalPrepareContext, type AgentEvalPromptInteraction, type AgentEvalPromptResponder, type AgentEvalResult, type AgentEvalScenario, type AgentEvalSetup, type AgentEvalSetupContext, type AgentEvalStep, type AgentEvalStepResult, type AgentEvalSuiteResult, type AgentEvalTurnGenerator, type AgentTestTarget, type AgentTesterOptions, type EvalMatcher, type ScriptedPromptRule, createAgentEvalHarness, createAgentTester, createHumanResponder, createOpenAIChatTurnGenerator, createOpenAIGenerator, createScriptedPromptResponder, createTestArtifactsDirectory, createTimestampedArtifactDirectory, runAgentEvalSuite, runAgentTests };
|