@modelprofile.com/flexharness 2.1.0 → 3.0.1
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/changelog.md +66 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.flexharness.d.ts +86 -30
- package/dist_ts/classes.flexharness.js +2593 -1131
- package/dist_ts/classes.stores.d.ts +19 -20
- package/dist_ts/classes.stores.js +968 -75
- package/dist_ts/errors.d.ts +5 -0
- package/dist_ts/errors.js +11 -1
- package/dist_ts/interfaces.d.ts +130 -23
- package/dist_ts/plugins.d.ts +3 -3
- package/dist_ts/plugins.js +3 -3
- package/dist_ts/utils.json.d.ts +4 -2
- package/dist_ts/utils.json.js +283 -140
- package/dist_ts/utils.prompt.d.ts +1 -2
- package/dist_ts/utils.prompt.js +3 -26
- package/dist_ts_migration/index.d.ts +1 -0
- package/dist_ts_migration/index.js +2 -0
- package/dist_ts_migration/v3_legacyflexharness.d.ts +17 -0
- package/dist_ts_migration/v3_legacyflexharness.js +426 -0
- package/package.json +17 -3
- package/readme.hints.md +13 -11
- package/readme.md +94 -27
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.flexharness.ts +2966 -1421
- package/ts/classes.stores.ts +1226 -97
- package/ts/errors.ts +20 -0
- package/ts/interfaces.ts +168 -22
- package/ts/plugins.ts +46 -3
- package/ts/utils.json.ts +341 -154
- package/ts/utils.prompt.ts +6 -27
- package/ts_migration/index.ts +1 -0
- package/ts_migration/v3_legacyflexharness.ts +620 -0
package/ts/errors.ts
CHANGED
|
@@ -97,6 +97,26 @@ export class FlexHarnessStoreFormatError extends FlexHarnessError {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
export class FlexHarnessStoreCommitUncertainError extends FlexHarnessError {
|
|
101
|
+
public readonly path: string;
|
|
102
|
+
public readonly operation: 'write' | 'delete-file' | 'delete-directory';
|
|
103
|
+
|
|
104
|
+
constructor(
|
|
105
|
+
path: string,
|
|
106
|
+
operation: 'write' | 'delete-file' | 'delete-directory',
|
|
107
|
+
options: ErrorOptions,
|
|
108
|
+
) {
|
|
109
|
+
super(
|
|
110
|
+
'FLEX_STORE_COMMIT_UNCERTAIN',
|
|
111
|
+
`Store ${operation} at "${path}" may have committed but could not be durably confirmed.`,
|
|
112
|
+
options,
|
|
113
|
+
);
|
|
114
|
+
this.name = 'FlexHarnessStoreCommitUncertainError';
|
|
115
|
+
this.path = path;
|
|
116
|
+
this.operation = operation;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
100
120
|
export class FlexHarnessRunError extends AggregateError {
|
|
101
121
|
public readonly code = 'FLEX_RUN_FAILED';
|
|
102
122
|
|
package/ts/interfaces.ts
CHANGED
|
@@ -8,17 +8,16 @@ export interface IJsonObject {
|
|
|
8
8
|
|
|
9
9
|
export type TJsonValue = TJsonPrimitive | IJsonObject | TJsonValue[];
|
|
10
10
|
|
|
11
|
-
export type
|
|
11
|
+
export type TFlexAgentSessionOptions = plugins.IAgentSessionOptions;
|
|
12
12
|
export type TFlexAgentRunResult = plugins.IAgentRunResult;
|
|
13
|
-
export type
|
|
14
|
-
export type
|
|
15
|
-
export type
|
|
16
|
-
export type
|
|
17
|
-
export type
|
|
18
|
-
export type
|
|
19
|
-
export type TFlexAgentCacheSetting = TFlexAgentRunOptions['cache'];
|
|
13
|
+
export type TFlexAgentModel = NonNullable<TFlexAgentSessionOptions['model']>;
|
|
14
|
+
export type TFlexAgentPrompt = Parameters<plugins.IAgentSession['beginGeneration']>[0];
|
|
15
|
+
export type TFlexAgentModelMessage = ReturnType<plugins.IAgentSession['getModelMessages']>[number];
|
|
16
|
+
export type TFlexAgentToolSet = NonNullable<TFlexAgentSessionOptions['tools']>;
|
|
17
|
+
export type TFlexAgentProviderOptions = TFlexAgentSessionOptions['providerOptions'];
|
|
18
|
+
export type TFlexAgentCacheSetting = TFlexAgentSessionOptions['cache'];
|
|
20
19
|
export type TFlexAgentToolCallFinishEvent = Parameters<
|
|
21
|
-
NonNullable<
|
|
20
|
+
NonNullable<TFlexAgentSessionOptions['onToolCallFinish']>
|
|
22
21
|
>[0];
|
|
23
22
|
|
|
24
23
|
export interface IFlexTextPromptPart {
|
|
@@ -60,6 +59,7 @@ export interface IFlexModelIdentity {
|
|
|
60
59
|
|
|
61
60
|
export type TFlexActivityStatus =
|
|
62
61
|
| 'idle'
|
|
62
|
+
| 'scheduled'
|
|
63
63
|
| 'running'
|
|
64
64
|
| 'waiting_permission'
|
|
65
65
|
| 'failed'
|
|
@@ -173,6 +173,14 @@ export interface IFlexPromptAdmission {
|
|
|
173
173
|
completion: Promise<IFlexPromptResult>;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
export interface IFlexSchedulePromptOptions extends IFlexPromptOptions {
|
|
177
|
+
debounceMs?: number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface IFlexScheduledPromptAdmission extends IFlexPromptAdmission {
|
|
181
|
+
scheduleKey: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
176
184
|
export interface IFlexMessagePageOptions {
|
|
177
185
|
limit?: number;
|
|
178
186
|
before?: string;
|
|
@@ -254,26 +262,97 @@ export interface IFlexToolProvider<TScope> {
|
|
|
254
262
|
): Promise<IFlexToolHandle | undefined> | IFlexToolHandle | undefined;
|
|
255
263
|
}
|
|
256
264
|
|
|
257
|
-
export interface
|
|
258
|
-
|
|
265
|
+
export interface IFlexSessionTombstone {
|
|
266
|
+
sessionId: string;
|
|
267
|
+
deletedAt: string;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export interface IFlexScopeSnapshot {
|
|
271
|
+
schemaVersion: 1;
|
|
272
|
+
revision: number;
|
|
273
|
+
sessions: IFlexSession[];
|
|
274
|
+
tombstones: IFlexSessionTombstone[];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface IFlexTerminalProjection {
|
|
278
|
+
runId: string;
|
|
279
|
+
status: 'completed' | 'failed' | 'cancelled';
|
|
280
|
+
userMessage: IFlexMessage;
|
|
281
|
+
assistantMessage: IFlexMessage;
|
|
282
|
+
model?: IFlexModelIdentity;
|
|
283
|
+
usage?: IFlexUsage;
|
|
284
|
+
finishReason?: string;
|
|
285
|
+
steps?: number;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface IFlexProjectionSnapshot {
|
|
289
|
+
schemaVersion: 1;
|
|
290
|
+
revision: number;
|
|
259
291
|
messages: IFlexMessage[];
|
|
260
|
-
|
|
261
|
-
rememberedPermissionKeys: string[];
|
|
292
|
+
stagedTerminals: IFlexTerminalProjection[];
|
|
262
293
|
}
|
|
263
294
|
|
|
264
|
-
export interface
|
|
295
|
+
export interface IFlexPermissionSnapshot {
|
|
265
296
|
schemaVersion: 1;
|
|
266
297
|
revision: number;
|
|
267
|
-
|
|
298
|
+
rememberedPermissionKeys: string[];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export interface IFlexScopeStore {
|
|
302
|
+
load(storageKey: string): Promise<IFlexScopeSnapshot | undefined>;
|
|
303
|
+
save(
|
|
304
|
+
storageKey: string,
|
|
305
|
+
snapshot: IFlexScopeSnapshot,
|
|
306
|
+
expectedRevision: number,
|
|
307
|
+
): Promise<void>;
|
|
268
308
|
}
|
|
269
309
|
|
|
270
|
-
export interface
|
|
271
|
-
load(storageKey: string): Promise<
|
|
310
|
+
export interface IFlexProjectionStore {
|
|
311
|
+
load(storageKey: string, sessionId: string): Promise<IFlexProjectionSnapshot | undefined>;
|
|
272
312
|
save(
|
|
273
313
|
storageKey: string,
|
|
274
|
-
|
|
314
|
+
sessionId: string,
|
|
315
|
+
snapshot: IFlexProjectionSnapshot,
|
|
275
316
|
expectedRevision: number,
|
|
276
317
|
): Promise<void>;
|
|
318
|
+
deleteSession(storageKey: string, sessionId: string): Promise<void>;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export interface IFlexPermissionStore {
|
|
322
|
+
load(storageKey: string, sessionId: string): Promise<IFlexPermissionSnapshot | undefined>;
|
|
323
|
+
save(
|
|
324
|
+
storageKey: string,
|
|
325
|
+
sessionId: string,
|
|
326
|
+
snapshot: IFlexPermissionSnapshot,
|
|
327
|
+
expectedRevision: number,
|
|
328
|
+
): Promise<void>;
|
|
329
|
+
deleteSession(storageKey: string, sessionId: string): Promise<void>;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export interface IFlexAgentEventStoreProvider {
|
|
333
|
+
getStore(
|
|
334
|
+
storageKey: string,
|
|
335
|
+
sessionId: string,
|
|
336
|
+
): Promise<plugins.IAgentEventStoreV2> | plugins.IAgentEventStoreV2;
|
|
337
|
+
releaseSession?(storageKey: string, sessionId: string): Promise<void> | void;
|
|
338
|
+
deleteSession(storageKey: string, sessionId: string): Promise<void>;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface IFlexToolJobStoreProvider {
|
|
342
|
+
getStore(
|
|
343
|
+
storageKey: string,
|
|
344
|
+
sessionId: string,
|
|
345
|
+
): Promise<plugins.IToolJobStore> | plugins.IToolJobStore;
|
|
346
|
+
releaseSession?(storageKey: string, sessionId: string): Promise<void> | void;
|
|
347
|
+
deleteSession(storageKey: string, sessionId: string): Promise<void>;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface IFlexHarnessStores {
|
|
351
|
+
scopes: IFlexScopeStore;
|
|
352
|
+
projections: IFlexProjectionStore;
|
|
353
|
+
permissions: IFlexPermissionStore;
|
|
354
|
+
agentEvents: IFlexAgentEventStoreProvider;
|
|
355
|
+
jobs: IFlexToolJobStoreProvider;
|
|
277
356
|
}
|
|
278
357
|
|
|
279
358
|
export interface IFlexJsonLimits {
|
|
@@ -290,10 +369,10 @@ export interface IFlexCallbackLimits {
|
|
|
290
369
|
export type TFlexExternalErrorSource =
|
|
291
370
|
| 'modelResolver'
|
|
292
371
|
| 'toolProvider'
|
|
293
|
-
| 'runner'
|
|
294
372
|
| 'toolExecution'
|
|
295
373
|
| 'toolCallback'
|
|
296
374
|
| 'toolCleanup'
|
|
375
|
+
| 'agentSession'
|
|
297
376
|
| 'persistence';
|
|
298
377
|
|
|
299
378
|
export interface IFlexExternalErrorContext {
|
|
@@ -308,17 +387,84 @@ export type TFlexExternalErrorProjector = (
|
|
|
308
387
|
context: IFlexExternalErrorContext,
|
|
309
388
|
) => IFlexErrorInfo;
|
|
310
389
|
|
|
390
|
+
export interface IFlexExecutionContextProviderContext<TScope> {
|
|
391
|
+
scopeId: string;
|
|
392
|
+
scope: TScope;
|
|
393
|
+
storageKey: string;
|
|
394
|
+
sessionId: string;
|
|
395
|
+
jobStore: plugins.IToolJobStore;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export interface IFlexExecutionContextHandle {
|
|
399
|
+
context: plugins.IToolExecutionContext;
|
|
400
|
+
close?(): Promise<void> | void;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export interface IFlexExecutionContextProvider<TScope> {
|
|
404
|
+
provideExecutionContext(
|
|
405
|
+
context: IFlexExecutionContextProviderContext<TScope>,
|
|
406
|
+
): Promise<IFlexExecutionContextHandle | undefined> | IFlexExecutionContextHandle | undefined;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export interface IFlexAgentSessionPolicy {
|
|
410
|
+
contextBuilder?: plugins.TAgentContextBuilder;
|
|
411
|
+
contextCompactor?: plugins.TAgentContextCompactor;
|
|
412
|
+
eventRetention?: TFlexAgentSessionOptions['eventRetention'];
|
|
413
|
+
changeListenerTimeoutMs?: number;
|
|
414
|
+
maxPendingSessionChanges?: number;
|
|
415
|
+
generationLeaseCleanupTimeoutMs?: number;
|
|
416
|
+
maxArchivedTransactionTombstones?: number;
|
|
417
|
+
maxContextOverflowRetries?: number;
|
|
418
|
+
}
|
|
419
|
+
|
|
311
420
|
export interface IFlexHarnessOptions<TScope> {
|
|
312
421
|
scopeResolver: IFlexScopeResolver<TScope>;
|
|
313
422
|
modelResolver: IFlexModelResolver<TScope>;
|
|
314
423
|
toolProvider?: IFlexToolProvider<TScope>;
|
|
315
|
-
|
|
316
|
-
|
|
424
|
+
executionContextProvider?: IFlexExecutionContextProvider<TScope>;
|
|
425
|
+
stores?: IFlexHarnessStores;
|
|
426
|
+
agentSessionPolicy?: IFlexAgentSessionPolicy;
|
|
317
427
|
toolOutputLimits?: IFlexJsonLimits;
|
|
318
428
|
callbackLimits?: IFlexCallbackLimits;
|
|
319
429
|
externalErrorProjector?: TFlexExternalErrorProjector;
|
|
320
430
|
}
|
|
321
431
|
|
|
432
|
+
export interface IFlexUncertainToolExecution {
|
|
433
|
+
intentId: string;
|
|
434
|
+
generationId: string;
|
|
435
|
+
toolCallId: string;
|
|
436
|
+
toolName: string;
|
|
437
|
+
input: TJsonValue;
|
|
438
|
+
timestamp: string;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export type TFlexToolExecutionReconciliation =
|
|
442
|
+
| {
|
|
443
|
+
resolution: 'executed';
|
|
444
|
+
output: TJsonValue;
|
|
445
|
+
}
|
|
446
|
+
| {
|
|
447
|
+
resolution: 'not-executed' | 'abandoned-unknown';
|
|
448
|
+
error?: string;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
export interface IFlexBackgroundExecution {
|
|
452
|
+
executionId: string;
|
|
453
|
+
type: string;
|
|
454
|
+
state: 'running' | 'finished' | 'failed' | 'aborted';
|
|
455
|
+
exitCode?: number | null;
|
|
456
|
+
startedAt?: string;
|
|
457
|
+
updatedAt?: string;
|
|
458
|
+
finishedAt?: string;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export interface IFlexEventArchiveMetadata {
|
|
462
|
+
archiveId: string;
|
|
463
|
+
sessionId: string;
|
|
464
|
+
createdAt: string;
|
|
465
|
+
eventCount: number;
|
|
466
|
+
}
|
|
467
|
+
|
|
322
468
|
export interface IFlexEventBase {
|
|
323
469
|
readonly eventId: string;
|
|
324
470
|
readonly sequence: number;
|
|
@@ -343,7 +489,7 @@ export interface IFlexSessionDeletedEvent extends IFlexEventBase {
|
|
|
343
489
|
}
|
|
344
490
|
|
|
345
491
|
export interface IFlexRunStartedEvent extends IFlexEventBase {
|
|
346
|
-
readonly type: 'run.started';
|
|
492
|
+
readonly type: 'run.started' | 'run.scheduled';
|
|
347
493
|
readonly runId: string;
|
|
348
494
|
readonly messageId: string;
|
|
349
495
|
readonly session: IFlexSession;
|
package/ts/plugins.ts
CHANGED
|
@@ -6,10 +6,53 @@ import * as path from 'node:path';
|
|
|
6
6
|
export { crypto, fs, path };
|
|
7
7
|
|
|
8
8
|
// @push.rocks scope
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
AgentEventStoreConflictError,
|
|
11
|
+
AgentSession,
|
|
12
|
+
buildModelMessages,
|
|
13
|
+
ToolJobStoreConflictError,
|
|
14
|
+
createAgentEvent,
|
|
15
|
+
getAgentGenerationTransactions,
|
|
16
|
+
modelMessagesToAgentEvents,
|
|
17
|
+
validateAgentEventArchiveV2,
|
|
18
|
+
validateAgentEventSnapshotV2,
|
|
19
|
+
} from '@push.rocks/smartagent';
|
|
10
20
|
|
|
11
|
-
export {
|
|
21
|
+
export {
|
|
22
|
+
AgentEventStoreConflictError,
|
|
23
|
+
AgentSession,
|
|
24
|
+
buildModelMessages,
|
|
25
|
+
ToolJobStoreConflictError,
|
|
26
|
+
createAgentEvent,
|
|
27
|
+
getAgentGenerationTransactions,
|
|
28
|
+
modelMessagesToAgentEvents,
|
|
29
|
+
validateAgentEventArchiveV2,
|
|
30
|
+
validateAgentEventSnapshotV2,
|
|
31
|
+
};
|
|
12
32
|
export type {
|
|
13
|
-
|
|
33
|
+
IAgentEventArchiveV2,
|
|
34
|
+
IAgentEventSnapshotV2,
|
|
35
|
+
IAgentEventStoreV2,
|
|
36
|
+
IAgentGenerateResult,
|
|
37
|
+
IAgentGenerationHandle,
|
|
38
|
+
IAgentGenerationLease,
|
|
14
39
|
IAgentRunResult,
|
|
40
|
+
IAgentSession,
|
|
41
|
+
IAgentSessionOptions,
|
|
42
|
+
IAgentRuntimeEventPayload,
|
|
43
|
+
IGenerationBegunEvent,
|
|
44
|
+
IGenerationExecutionCompletedEvent,
|
|
45
|
+
IGenerationExecutionStartedEvent,
|
|
46
|
+
IGenerationOutcomeEvent,
|
|
47
|
+
IToolExecutionContext,
|
|
48
|
+
IToolExecutionIntentEvent,
|
|
49
|
+
IToolJobSnapshot,
|
|
50
|
+
IToolJobState,
|
|
51
|
+
IToolJobStore,
|
|
52
|
+
TAgentContextBuilder,
|
|
53
|
+
TAgentContextCompactor,
|
|
54
|
+
TAgentEvent,
|
|
55
|
+
TAgentGenerationOutcome,
|
|
56
|
+
TAgentToolCallFinishEvent,
|
|
57
|
+
TAgentToolExecutionReconciliationOptions,
|
|
15
58
|
} from '@push.rocks/smartagent';
|