@gestaltrun/dsh-agent-eval 0.0.0-stage → 0.1.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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.i18n.yaml +58 -0
  3. package/README.md +194 -2
  4. package/README.zh.md +195 -0
  5. package/cordis.patch.yml +13 -0
  6. package/lib/cs-hosting-plugin-B9bjLaoE.js +6980 -0
  7. package/lib/cs-hosting.js +2 -0
  8. package/lib/index.js +2 -0
  9. package/lib/types/agent-runs.d.ts +56 -0
  10. package/lib/types/cs-hosting-evaluation.d.ts +235 -0
  11. package/lib/types/cs-hosting-plugin.d.ts +10 -0
  12. package/lib/types/handoff.d.ts +4 -0
  13. package/lib/types/human-actions.d.ts +36 -0
  14. package/lib/types/im-purchase-intent.d.ts +12 -0
  15. package/lib/types/im-target.d.ts +45 -0
  16. package/lib/types/index.d.ts +22 -0
  17. package/lib/types/input-admission.d.ts +10 -0
  18. package/lib/types/practice-failure.d.ts +17 -0
  19. package/lib/types/product-field-policy.d.ts +129 -0
  20. package/lib/types/production-budget.d.ts +21 -0
  21. package/lib/types/production-buyers.d.ts +20 -0
  22. package/lib/types/production-workspace.d.ts +64 -0
  23. package/lib/types/purchase-intent.d.ts +66 -0
  24. package/lib/types/record.d.ts +169 -0
  25. package/lib/types/replay-world.d.ts +25 -0
  26. package/lib/types/reply-latency.d.ts +21 -0
  27. package/lib/types/runner.d.ts +97 -0
  28. package/lib/types/sales.d.ts +33 -0
  29. package/lib/types/script-production.d.ts +955 -0
  30. package/lib/types/server-script-source.d.ts +65 -0
  31. package/lib/types/simulated-buyer-role.d.ts +41 -0
  32. package/lib/types/snapshot-replay.d.ts +15 -0
  33. package/lib/types/step-failure.d.ts +25 -0
  34. package/lib/types/types.d.ts +174 -0
  35. package/locale/en.json +6 -0
  36. package/locale/zh.json +6 -0
  37. package/package.json +106 -3
@@ -0,0 +1,2 @@
1
+ import { n as inject, r as name, t as apply } from "./cs-hosting-plugin-B9bjLaoE.js";
2
+ export { apply, inject, name };
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { A as EvaluationReplyTimeout, C as planHumanActions, D as EvaluationMessage, E as EvaluationCheck, O as EvaluationTime, S as humanActionChannel, T as EvaluationCaseRecord, _ as EvaluationSalesHumanComparison, a as ImPurchaseIntentObserver, b as humanComparisonsFor, c as MerchantServerScriptSource, d as CustomerServiceReplayWorld, f as SimulatedBuyerRole, g as deterministicRole, h as EvaluationRunner, i as AgentEvaluationService, j as EvaluationStepFailure, k as EvaluationCaseFailure, l as merchantScriptReader, m as Config, o as EvaluationPurchaseIntent, p as ImEvaluationTarget, s as PurchaseIntentCapture, t as apply, u as scriptOf, v as EvaluationSalesOptions, w as EVALUATION_CONTRACT_REVISION, x as salesRecordFor, y as EvaluationSalesRecord } from "./cs-hosting-plugin-B9bjLaoE.js";
2
+ export { AgentEvaluationService, Config, CustomerServiceReplayWorld, EVALUATION_CONTRACT_REVISION, EvaluationCaseFailure, EvaluationCaseRecord, EvaluationCheck, EvaluationMessage, EvaluationPurchaseIntent, EvaluationReplyTimeout, EvaluationRunner, EvaluationSalesHumanComparison, EvaluationSalesOptions, EvaluationSalesRecord, EvaluationStepFailure, EvaluationTime, ImEvaluationTarget, ImPurchaseIntentObserver, MerchantServerScriptSource, PurchaseIntentCapture, SimulatedBuyerRole, apply as applyCsHostingEvaluation, deterministicRole, humanActionChannel, humanComparisonsFor, merchantScriptReader, planHumanActions, salesRecordFor, scriptOf };
@@ -0,0 +1,56 @@
1
+ /** Process-local evaluation task observations; Session logs remain the durable transcript. */
2
+ import type { CsHostingAgentTask } from '@gestaltrun/dsh-cs-hosting';
3
+ import type { SessionEvent } from '@deepseek-ai/dsh-session';
4
+ import type { EvaluationCaseRecord } from './record.ts';
5
+ /** An opened task Session and its optional IM pairing. */
6
+ export type AgentTaskStart = Omit<CsHostingAgentTask, 'sessions' | 'taskKey'> & {
7
+ readonly taskKey: string;
8
+ readonly sessionId: string;
9
+ };
10
+ /** Task references could not be saved before execution. */
11
+ export declare class AgentTaskPersistenceError extends Error {
12
+ readonly code = "EVALUATION_TASK_METADATA_UNCONFIRMED";
13
+ /** @param cause - Host-only storage failure. */
14
+ constructor(cause: unknown);
15
+ }
16
+ /** @param tasks - Task references from a live run or storage. @returns The references without process-local simulation instance ids, which restored tasks never carry. */
17
+ export declare function inspectionTasks(tasks: readonly CsHostingAgentTask[]): readonly CsHostingAgentTask[];
18
+ /** One evaluation's observable tasks, grouped across revision-driven Session reopens. */
19
+ export declare class AgentRuns {
20
+ private readonly recentLimit;
21
+ private readonly changed;
22
+ private readonly persist;
23
+ private tasks;
24
+ private readonly submissions;
25
+ /** @param recentLimit - Number of ended tasks retained beside active tasks. @param changed - Publish updated evaluation state. @param persist - Wait for durable task references. */
26
+ constructor(recentLimit: number, changed: () => void, persist?: () => Promise<void>);
27
+ /** @returns After task references have been persisted. */
28
+ flush(): Promise<void>;
29
+ /** @param input - Task identity and opened Session. @param at - Start time. @param resumedAfterRestart - Session continued after Host restart. */
30
+ start({ sessionId, ...input }: AgentTaskStart, at?: number, resumedAfterRestart?: boolean): void;
31
+ /** @param sessionId - Observed Session. @param command - Tool name or CLI command without arguments. */
32
+ step(sessionId: string, command: string): void;
33
+ /** @param sessionId - Session whose submission the Host rejected. */
34
+ reject(sessionId: string): void;
35
+ /** @param sessionId - Completed Session. @param status - Terminal outcome. @param reasonCode - Stable failure code. @param at - End time. */
36
+ finish(sessionId: string, status: 'submitted' | 'failed' | 'cancelled', reasonCode?: string, at?: number): void;
37
+ /** @param sessionId - Tested Session. @param count - Delivered buyer message count. */
38
+ messages(sessionId: string, count: number): void;
39
+ /** @param taskKey - Practice task identity. @param status - Settled runner outcome. @param reasonCode - Failure code. */
40
+ finishTask(taskKey: string, status: 'submitted' | 'failed' | 'cancelled', reasonCode?: string): void;
41
+ /** @param taskKey - Practice task identity. @param reason - Outcome recorded by the runner after the pair stops. */
42
+ completePractice(taskKey: string, reason: EvaluationCaseRecord['endReason']): void;
43
+ /** @param sessionId - Event owner. @param event - Logged tool call or result. */
44
+ observe(sessionId: string, event: SessionEvent): void;
45
+ /** @returns All task references retained for a hosting transition, independent of the visible recent limit. */
46
+ retainedTasks(): readonly CsHostingAgentTask[];
47
+ /** @param tasks - Validated persisted task references. Restore inspection only; no Agent is resumed. */
48
+ restore(tasks: readonly CsHostingAgentTask[]): void;
49
+ /** @param interruptedAt - Last executor report as an estimate, when available. */
50
+ interruptForRestart(interruptedAt?: number): void;
51
+ /** @returns Every owned transcript reference, including tasks outside the visible recent limit. */
52
+ sessionIds(): readonly string[];
53
+ /** @returns Active tasks and the configured number of most recently ended tasks, with complete Session histories. */
54
+ snapshot(): readonly CsHostingAgentTask[];
55
+ private update;
56
+ }
@@ -0,0 +1,235 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import { z } from 'zod';
3
+ import { CsHostingEvaluation, type CsHostingEvaluationRun, type CsHostingEvaluationView, type CsHostingEvaluationResume } from '@gestaltrun/dsh-cs-hosting';
4
+ import { type CsHostingAgentTask, type CsHostingEvaluationCommandId, type CsHostingEvaluationJobId, type CsHostingScriptCap } from '@gestaltrun/dsh-cs-hosting/types';
5
+ import { type EvaluationHumanAction } from './human-actions.ts';
6
+ import { type EvaluationReplyObservation } from './runner.ts';
7
+ import { type ServerEvaluationScript } from './server-script-source.ts';
8
+ import { ScriptRecoveryRequest, type ProductionOperations } from './script-production.ts';
9
+ import type { EvaluationCaseRecord } from './record.ts';
10
+ /** Deployment limits and estimates for the pre-evaluation run. */
11
+ export interface Config {
12
+ /** Explicit administrator-started script recovery; its operation id is applied once per checkpoint. */
13
+ readonly productionScriptRecovery?: z.input<typeof ScriptRecoveryRequest>;
14
+ /** Recently ended Agent tasks beside active tasks; defaults to 20. */
15
+ readonly recentAgentTaskLimit?: number;
16
+ /** Initially selected buyer/last-message window, 1–180 days; defaults to 30. Must occur in historyWindowOptions. */
17
+ readonly historyWindowDays?: number;
18
+ /** Selectable history windows, unique integers from 1–180; defaults to 7, 30, 90 and 180. */
19
+ readonly historyWindowOptions?: readonly number[];
20
+ /** Script admission cap. `auto` admits at most 200 cases the quota can pay for; 50, 100, or 200 admit at most that many. */
21
+ readonly scriptCap?: 'auto' | 50 | 100 | 200;
22
+ /** Maximum desktop evaluations in flight; defaults to 2. */
23
+ readonly desktopConcurrency?: number;
24
+ /** Consecutive settled Host/transport failures of the same code before stopping; defaults to 3. */
25
+ readonly practiceSystemicFailureLimit?: number;
26
+ /** Case-data workers; configurable from cordis.yml, defaults to 2. */
27
+ readonly productionTaskConcurrency?: number;
28
+ /** Script-authoring workers; configurable from cordis.yml, integers 1–16, defaults to 4. */
29
+ readonly productionScriptConcurrency?: number;
30
+ /** Delay between production job reads; defaults to 1000 ms. */
31
+ readonly productionPollIntervalMs?: number;
32
+ /** Maximum wait for one server production job; defaults to 30 minutes. */
33
+ readonly productionJobTimeoutMs?: number;
34
+ /** Maximum duration of one case-data Session; defaults to 10 minutes. */
35
+ readonly productionTaskTimeoutMs?: number;
36
+ /** Maximum duration of one script-authoring Session; defaults to 20 minutes. */
37
+ readonly productionScriptTaskTimeoutMs?: number;
38
+ /** Refill attempts when a case revision changes; defaults to 3. */
39
+ readonly productionRevisionRetries?: number;
40
+ /** Additional transient case-page read attempts; defaults to 3. */
41
+ readonly productionCaseReadRetries?: number;
42
+ /** First exponential case-page retry delay; defaults to 1000 ms. */
43
+ readonly productionCaseReadRetryInitialMs?: number;
44
+ /** Case-page retry-delay ceiling; defaults to 10000 ms. */
45
+ readonly productionCaseReadRetryMaxMs?: number;
46
+ /** Days after the final case message covered by order matching; defaults to 7. */
47
+ readonly productionDealWindowDays?: number;
48
+ /** Days before the first case message included in order search; defaults to 30. */
49
+ readonly productionOrderLookbackDays?: number;
50
+ /** Estimated tokens for collecting one case; defaults to 8000. */
51
+ readonly estimatedDataTokensPerCase?: number;
52
+ /** Estimated USD for collecting one case; defaults to 0.03. */
53
+ readonly estimatedDataCostUsdPerCase?: number;
54
+ /** Estimated tokens for authoring one script; defaults to 6000. */
55
+ readonly estimatedScriptTokensPerCase?: number;
56
+ /** Estimated USD for authoring one script; defaults to 0.02. */
57
+ readonly estimatedScriptCostUsdPerCase?: number;
58
+ /** Estimated cases for each not-yet-aggregated buyer; defaults to 2. */
59
+ readonly estimatedCasesPerBuyer?: number;
60
+ /** Real milliseconds allowed for one tested-Agent reply; defaults to 120000. */
61
+ readonly responseTimeoutMs?: number;
62
+ /** Real milliseconds allowed for one simulated-buyer step; defaults to 120000. */
63
+ readonly buyerStepTimeoutMs?: number;
64
+ /** First-reply latency target in milliseconds; reporting only, defaults to 30000. */
65
+ readonly firstReplyTargetMs?: number;
66
+ /** Buyer message ceiling per case. */
67
+ readonly maxBuyerMessages?: number;
68
+ /** Estimated input+output tokens per case for the start-page budget. */
69
+ readonly estimatedTokensPerCase?: number;
70
+ /** Estimated USD per case for the real monthly quota check. */
71
+ readonly estimatedCostUsdPerCase?: number;
72
+ /** Explicit provider input price used by the target's usage observation. */
73
+ readonly inputPerMillion?: number;
74
+ /** Explicit provider output price used by the target's usage observation. */
75
+ readonly outputPerMillion?: number;
76
+ /** Currency for target usage. */
77
+ readonly currency?: string;
78
+ /** Delay between report reads while server judging is pending; defaults to 1000 ms. */
79
+ readonly reportPollIntervalMs?: number;
80
+ /** Eligible cases receiving one authored action; defaults to 3. */
81
+ readonly humanActionSampleSize?: number;
82
+ /** Reproducible action seed; trimmed value must contain 1–120 characters. Omission generates and records one per run. */
83
+ readonly humanActionSeed?: string;
84
+ }
85
+ /** @param script - Frozen case and judge inputs. @param signal - Case lifetime. @param humanAction - Optional Host-selected action; omission runs without operator input. @param onReplyTiming - Observes accepted buyer rounds without changing the server record. @returns The settled case record. */
86
+ export type EvaluationCaseDriver = (script: ServerEvaluationScript, signal: AbortSignal, humanAction?: EvaluationHumanAction, onReplyTiming?: (value: EvaluationReplyObservation) => void) => Promise<EvaluationCaseRecord>;
87
+ /** One pre-evaluation run owned by the Host; the tested Agent and simulated buyer use production presets. */
88
+ export declare class AgentEvaluationService extends CsHostingEvaluation {
89
+ private readonly drive?;
90
+ private readonly productionOperations?;
91
+ static inject: string[];
92
+ private readonly metadata;
93
+ private readonly config;
94
+ private summary;
95
+ private loading;
96
+ private error;
97
+ private errorCode;
98
+ private skippedOutsideWindow;
99
+ private skippedPrescreen;
100
+ private prepareCounts;
101
+ private dataProgress;
102
+ private scriptProgress;
103
+ private collectionRestart;
104
+ private productionFromCollection;
105
+ private dataCollection;
106
+ private collectionFailureCount;
107
+ private collectionFailureReasons;
108
+ private scriptFailureCount;
109
+ private scriptFailureReasons;
110
+ private invalidScripts;
111
+ private scriptRecoveryOperationIds;
112
+ private selectedHistoryWindowDays;
113
+ private selectedScriptCap;
114
+ private runHistoryWindowDays;
115
+ private previewAbort;
116
+ private metadataBlocked;
117
+ private run;
118
+ private plan;
119
+ private practiceMissing;
120
+ private firstReplies;
121
+ private productionSetId;
122
+ private resumeWindow;
123
+ private runCoverageSetId;
124
+ private abort;
125
+ private execution;
126
+ private starting;
127
+ private startingJobId;
128
+ private startingCommandId;
129
+ private activeJobId;
130
+ private activeCommandId;
131
+ private resuming;
132
+ private lastResume;
133
+ private lastResumeRequestId;
134
+ private cancelling;
135
+ private runIdentity;
136
+ private summaryIdentity;
137
+ private scopeGeneration;
138
+ private closed;
139
+ private hostingPending;
140
+ private cleanupUnconfirmed;
141
+ private cleanupCause;
142
+ private preparingHosting;
143
+ private preparingScope;
144
+ /** Exact settled projection and identity certified by NOT_FOUND plus the durable batch audit. */
145
+ private completedProductionCancellation;
146
+ private readonly lifetime;
147
+ private readonly refreshes;
148
+ private readonly shopReadiness;
149
+ private agentRuns;
150
+ /** Run and serialized task list most recently written to, or restored from, run metadata. */
151
+ private retainedAgentTasks;
152
+ private agentTaskWrites;
153
+ private agentTaskWriteFailure;
154
+ /** @param ctx - Host context. @param config - deployment limits and estimates. */
155
+ constructor(ctx: Context, config?: Config, drive?: EvaluationCaseDriver | undefined, productionOperations?: ProductionOperations | undefined);
156
+ /** @returns start-page facts and the latest run projection. */
157
+ view(): CsHostingEvaluationView;
158
+ /** @returns All task references of the current run, independent of the local recent limit. */
159
+ retainedTasks(): readonly CsHostingAgentTask[];
160
+ private noteStageProgress;
161
+ private rememberProduction;
162
+ private failureView;
163
+ private failureMetadata;
164
+ private isAdmin;
165
+ /**
166
+ * Create one server run, coalescing concurrent starts, then execute the T4 runner in the background.
167
+ * @returns the initial running projection.
168
+ */
169
+ start(jobId?: CsHostingEvaluationJobId, commandId?: CsHostingEvaluationCommandId): Promise<CsHostingEvaluationRun>;
170
+ /** @param jobId - Server assignment. @param interruptedAt - Last executor report, if known. @param commandId - Individual command identity, if recovering a claimed command. @returns Its matching local recovery, or null if it has not started. */
171
+ resumeAssigned(jobId: CsHostingEvaluationJobId, interruptedAt: string | null, commandId?: CsHostingEvaluationCommandId): Promise<CsHostingEvaluationResume | null>;
172
+ /** @param jobId - Server assignment. @param runId - Current Host run. @returns Whether this captured shop owns the exact assignment. */
173
+ ownsAssignment(jobId: CsHostingEvaluationJobId, runId: string): boolean;
174
+ /** @param runId - Persisted server run. @param interruptedAt - Last executor report, if known. @returns Restored execution and recovery times. */
175
+ resume(runId: string, interruptedAt: string | null): Promise<CsHostingEvaluationResume>;
176
+ private resumeRun;
177
+ /** @returns A fresh immutable set with forced collection, or the unfinished restart batch; administrator only. */
178
+ restartFromCollection(jobId?: CsHostingEvaluationJobId, commandId?: CsHostingEvaluationCommandId): Promise<CsHostingEvaluationRun>;
179
+ /** @returns The active production batch after audited retry grants for failed primary cases, alternates and script slots; only idle administrators may invoke it. */
180
+ retryFailedCases(jobId?: CsHostingEvaluationJobId, commandId?: CsHostingEvaluationCommandId): Promise<CsHostingEvaluationRun>;
181
+ /**
182
+ * Select a configured history window and replace the complete preview; active runs keep their admitted range.
183
+ * @param days - One of the configured historyWindowOptions.
184
+ * @returns After the replacement preview settles; previous reads are aborted and joined on disposal.
185
+ */
186
+ setHistoryWindowDays(days: number): Promise<void>;
187
+ /**
188
+ * Select how many scripts the next run may admit and refresh the preview.
189
+ * @param cap - `auto` or a fixed cap of 50, 100, or 200.
190
+ * @returns After the replacement preview settles. An in-progress run keeps the cap it started with.
191
+ */
192
+ setScriptCap(cap: CsHostingScriptCap): Promise<void>;
193
+ private startRun;
194
+ /** @returns the server-confirmed run, or its last known state with a visible cancellation failure. */
195
+ cancel(): Promise<CsHostingEvaluationRun | null>;
196
+ private cancelOperation;
197
+ /** @returns After evaluation joins and confirms cancellation; unknown cleanup blocks formal hosting. */
198
+ prepareForHosting(): Promise<void>;
199
+ private prepareHosting;
200
+ private cleanupStep;
201
+ private logCleanupPhase;
202
+ private checkPendingCreations;
203
+ private writeMetadata;
204
+ private cancelRun;
205
+ private cancelRunResult;
206
+ private cancelPersistedProduction;
207
+ private productionWorkspace;
208
+ private productionPipeline;
209
+ private produce;
210
+ private createServerRun;
211
+ private execute;
212
+ private productionDriver;
213
+ private submit;
214
+ private poll;
215
+ private observe;
216
+ private control;
217
+ private identity;
218
+ private fail;
219
+ private failProduction;
220
+ private emit;
221
+ private createAgentRuns;
222
+ /** Persist task references before their Sessions perform work. */
223
+ private retainAgentTasks;
224
+ private refresh;
225
+ private previewRefreshAllowed;
226
+ private followShopReadiness;
227
+ private readinessStopped;
228
+ private track;
229
+ private productionBudget;
230
+ private productionSummary;
231
+ private collectionRestartPreview;
232
+ private refreshData;
233
+ }
234
+ /** @param count - Uncapped admission count. @param cap - Operator cap. @returns The count production and the preview may admit. */
235
+ export declare function applyScriptCap(count: number, cap: CsHostingScriptCap): number;
@@ -0,0 +1,10 @@
1
+ /** Cordis plugin that registers the server-backed pre-evaluation service. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ import { type Config } from './cs-hosting-evaluation.ts';
4
+ export declare const name = "gestaltrun-agent-eval-cs-hosting";
5
+ export declare const inject: string[];
6
+ /**
7
+ * @param ctx - Host context.
8
+ * @param config - deployment limits and estimates.
9
+ */
10
+ export declare function apply(ctx: Context, config?: Config): Promise<void>;
@@ -0,0 +1,4 @@
1
+ /** Confirmed transfer state shared by evaluation role and target adapters. */
2
+ import type { ImHandlingControl } from '@gestaltrun/dsh-im-runtime';
3
+ /** @param control - Current automatic-handling state. @returns Whether the shop AI confirmed a transfer to staff. */
4
+ export declare function isConfirmedHandoff(control: ImHandlingControl | undefined): boolean;
@@ -0,0 +1,36 @@
1
+ import type { EvaluationCaseRecord } from './record.ts';
2
+ import type { EvaluationSalesOptions } from './sales.ts';
3
+ import type { EvaluationScript } from './types.ts';
4
+ /** One script-authored action at a buyer turn's boundary. */
5
+ export interface EvaluationHumanAction {
6
+ readonly kind: EvaluationCaseRecord['humanActions'][number]['kind'];
7
+ readonly turn: number;
8
+ readonly phase: 'before-buyer' | 'after-buyer' | 'after-reply';
9
+ readonly text: string;
10
+ }
11
+ /** One selected case and action; a case is selected at most once. */
12
+ export interface EvaluationHumanActionSelection {
13
+ readonly caseId: EvaluationCaseRecord['caseId'];
14
+ readonly action: EvaluationHumanAction;
15
+ }
16
+ /** Run-level observations; individual case records retain the server's version-1 fields. */
17
+ export interface EvaluationRunRecord {
18
+ readonly schemaVersion: 1;
19
+ readonly seed: string;
20
+ readonly plannedHumanActions: readonly EvaluationHumanActionSelection[];
21
+ readonly cases: readonly EvaluationCaseRecord[];
22
+ /** Server sales-run options; paired groups share the pair and comparison ids and differ only by annotation. */
23
+ readonly sales?: EvaluationSalesOptions;
24
+ }
25
+ /** @param action - Script-authored action. @param turns - Available buyer turns. @returns Validated action; invalid or unreachable turns reject before a target opens. */
26
+ export declare function validateHumanAction(action: EvaluationHumanAction, turns: number): EvaluationHumanAction;
27
+ /** @param kind - Script-authored action kind. @returns Conversation for public answers/corrections, otherwise private operator input. */
28
+ export declare function humanActionChannel(kind: EvaluationHumanAction['kind']): 'conversation' | 'private';
29
+ /**
30
+ * Rank eligible cases and their authored actions using SHA-256; input order does not affect selection.
31
+ * @param scripts - Unique case identities and optional action plans.
32
+ * @param seed - Run seed, recorded by the caller before replay.
33
+ * @param count - Maximum number of distinct cases to select; zero disables human actions.
34
+ * @returns One validated action per selected case in stable rank order; no text is generated.
35
+ */
36
+ export declare function planHumanActions(scripts: readonly EvaluationScript[], seed: string, count: number): EvaluationHumanActionSelection[];
@@ -0,0 +1,12 @@
1
+ import type { BuyingInsights } from '@gestaltrun/dsh-cs-hosting';
2
+ import type { ImEvaluationBinding } from './im-target.ts';
3
+ import { type PurchaseIntentObserver, type PurchaseIntentObserverFactory } from './purchase-intent.ts';
4
+ import type { EvaluationScript } from './types.ts';
5
+ /** Only a running pair's tested Session may supply purchase-intent observations. */
6
+ export declare class ImPurchaseIntentObserver implements PurchaseIntentObserverFactory<ImEvaluationBinding> {
7
+ private readonly insights;
8
+ /** @param insights - Shop-owned raw analysis source; opening a reader performs no analysis. */
9
+ constructor(insights: Pick<BuyingInsights, 'observeAdmissions'>);
10
+ /** @param _script - Frozen evaluation case. @param binding - Pair and tested Agent owned by that case. @returns An effect-owned reader matched to persisted buyer admissions. */
11
+ open(_script: EvaluationScript, binding: ImEvaluationBinding): PurchaseIntentObserver;
12
+ }
@@ -0,0 +1,45 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import type { ImSimulationInstanceView, ImRuntimeService } from '@gestaltrun/dsh-im-runtime';
3
+ import type { Agent } from '@deepseek-ai/dsh-agent';
4
+ import type { WorkspaceId } from '@deepseek-ai/dsh-workspace';
5
+ import type { AgentRuns } from './agent-runs.ts';
6
+ import type { EvaluationConversation, EvaluationScript, EvaluationTarget } from './types.ts';
7
+ /** References passed only to the customer-service world and role adapters. */
8
+ export interface ImEvaluationBinding {
9
+ readonly instance: ImSimulationInstanceView;
10
+ /** Tested customer-service Agent. */
11
+ readonly agent: Agent;
12
+ /** Simulated-user Agent in the evaluation buyer Workspace. */
13
+ readonly buyer: Agent;
14
+ readonly runtime: ImRuntimeService;
15
+ }
16
+ /** Host-selected buyer workspace and explicit provider prices. */
17
+ export interface ImEvaluationTargetOptions {
18
+ readonly agentRuns?: AgentRuns;
19
+ /** Display title supplied by the script source, with no effect on model input. */
20
+ readonly title?: (script: EvaluationScript) => string;
21
+ readonly buyerWorkspaceId: WorkspaceId;
22
+ readonly buyerPreset: string;
23
+ readonly pricing: {
24
+ readonly inputPerMillion: number;
25
+ readonly outputPerMillion: number;
26
+ readonly currency: string;
27
+ };
28
+ }
29
+ /** Production target; every run owns a new pair and keeps durable Sessions for inspection. */
30
+ export declare class ImEvaluationTarget implements EvaluationTarget<ImEvaluationBinding> {
31
+ private readonly ctx;
32
+ private readonly options;
33
+ /** @param ctx - Host with the production IM runtime, presets, workspaces and Session persistence. @param options - Prepared buyer workspace and provider pricing. */
34
+ constructor(ctx: Context, options: ImEvaluationTargetOptions);
35
+ /** @param script - Frozen case. @param signal - Caller lifetime. @returns New isolated pair using the configured target route's real preset. */
36
+ open(script: EvaluationScript, signal: AbortSignal): Promise<EvaluationConversation<ImEvaluationBinding>>;
37
+ private requireHandoff;
38
+ private closePair;
39
+ private send;
40
+ private intervene;
41
+ private injectHuman;
42
+ private perform;
43
+ private uncheckedError;
44
+ private collect;
45
+ }
@@ -0,0 +1,22 @@
1
+ /** Product-owned evaluation execution and extension points. */
2
+ export { EvaluationRunner, Config, deterministicRole } from './runner.ts';
3
+ export type { EvaluationPairedRequest, EvaluationPairedResult, EvaluationRequest, EvaluationRunRequest } from './runner.ts';
4
+ export { EvaluationCaseRecord, EvaluationMessage, EvaluationCheck, EvaluationTime, EVALUATION_CONTRACT_REVISION } from './record.ts';
5
+ export { EvaluationSalesOptions, EvaluationSalesRecord, EvaluationSalesHumanComparison, humanComparisonsFor, salesRecordFor } from './sales.ts';
6
+ export type * from './types.ts';
7
+ export { ImEvaluationTarget } from './im-target.ts';
8
+ export type { ImEvaluationBinding, ImEvaluationTargetOptions } from './im-target.ts';
9
+ export { SimulatedBuyerRole } from './simulated-buyer-role.ts';
10
+ export type { SimulatedBuyerRoleOptions } from './simulated-buyer-role.ts';
11
+ export { CustomerServiceReplayWorld } from './replay-world.ts';
12
+ export type { ReplayEntry, ReplayWorldOptions } from './replay-world.ts';
13
+ export { EvaluationStepFailure, EvaluationCaseFailure, EvaluationReplyTimeout } from './step-failure.ts';
14
+ export { MerchantServerScriptSource, merchantScriptReader, scriptOf } from './server-script-source.ts';
15
+ export type { ServerEvaluationScript, ServerScriptAccount, ServerScriptReader, ServerScriptSourceOptions } from './server-script-source.ts';
16
+ export { planHumanActions, humanActionChannel } from './human-actions.ts';
17
+ export type { EvaluationHumanAction, EvaluationHumanActionSelection, EvaluationRunRecord } from './human-actions.ts';
18
+ export { AgentEvaluationService, type Config as AgentEvaluationConfig } from './cs-hosting-evaluation.ts';
19
+ export { ImPurchaseIntentObserver } from './im-purchase-intent.ts';
20
+ export { EvaluationPurchaseIntent, PurchaseIntentCapture } from './purchase-intent.ts';
21
+ export type { EvaluationInputId, EvaluationAdmissionId, PurchaseIntentStep, PurchaseIntentAdmission, PurchaseIntentObserver, PurchaseIntentObserverFactory } from './purchase-intent.ts';
22
+ export { apply as applyCsHostingEvaluation } from './cs-hosting-plugin.ts';
@@ -0,0 +1,10 @@
1
+ /** Match accepted simulation inputs to their durable Session messages. */
2
+ import type { SessionEvent } from '@deepseek-ai/dsh-session';
3
+ import type { MessageId } from '@deepseek-ai/dsh-llm';
4
+ import type { ImMessageId } from '@gestaltrun/dsh-im-runtime';
5
+ /** Transport input or private operator-message identity, with its original brand. */
6
+ export type EvaluationReceiptId = ImMessageId | MessageId;
7
+ /** @param event - Persisted event. @param id - Accepted transport or private-message identity. @returns Whether the model-visible input consumes that receipt; queued inbox items are not yet model input. */
8
+ export declare function consumesInput(event: SessionEvent, id: EvaluationReceiptId): boolean;
9
+ /** @param event - Persisted event. @param id - Accepted transport or private-message identity. @returns Whether the Agent durably queued that input, even if a later pre-step discards it. */
10
+ export declare function queuesInput(event: SessionEvent, id: EvaluationReceiptId): boolean;
@@ -0,0 +1,17 @@
1
+ import type { EvaluationCaseRecord } from './record.ts';
2
+ import type { ServerEvaluationScript } from './server-script-source.ts';
3
+ /** Failure disposition used by the case-local retry and systemic stop policy. */
4
+ export interface PracticeFailure {
5
+ readonly kind: 'case' | 'host' | 'transport';
6
+ readonly code: string;
7
+ }
8
+ /** A run-level stop that must retain its checkpoint and all submitted cases. */
9
+ export declare class PracticeRunFailure extends Error {
10
+ readonly code: string;
11
+ /** @param code - Stable systemic, budget, evidence or uncertain-write reason. */
12
+ constructor(code: string);
13
+ }
14
+ /** @param error - Original failure, or absence for a returned terminal record. @param record - Settled evidence when available. @returns Stable reason and systemic category. */
15
+ export declare function practiceFailure(error: unknown, record?: EvaluationCaseRecord): PracticeFailure;
16
+ /** @param script - Frozen source identifiers and permitted knowledge. @param currency - Observed-cost currency. @returns Empty observed evidence when a driver supplies none; no buyer message or inferred expenditure is invented. */
17
+ export declare function emptyPracticeEvidence(script: ServerEvaluationScript, currency: string): EvaluationCaseRecord;
@@ -0,0 +1,129 @@
1
+ /** Product fields admitted from collection-time details or historical observations. */
2
+ import type { CliResult } from '@gestaltrun/dsh-cs-hosting/merchant-cli';
3
+ type Screen = 'first' | 'second';
4
+ type Change = 'slow' | 'fast' | 'mixed';
5
+ interface FieldRule {
6
+ readonly subject: string;
7
+ readonly change: Change;
8
+ readonly screens: readonly Screen[];
9
+ readonly fields: readonly string[];
10
+ readonly snapshotOverride?: boolean;
11
+ }
12
+ /** Explicit volatility and screen table; dotted paths override parent policies, * selects map keys and [] selects array rows. */
13
+ export declare const PRODUCT_FIELD_POLICY: readonly [{
14
+ readonly subject: "标题";
15
+ readonly snapshotOverride: true;
16
+ readonly change: "slow";
17
+ readonly screens: readonly ["first"];
18
+ readonly fields: readonly ["title", "itemTitle", "name", "subTitle"];
19
+ }, {
20
+ readonly subject: "主图与图片";
21
+ readonly snapshotOverride: true;
22
+ readonly change: "slow";
23
+ readonly screens: readonly ["first"];
24
+ readonly fields: readonly ["pictures", "images", "auctionPictures", "mainPic", "picUrl", "extraImageMap"];
25
+ }, {
26
+ readonly subject: "类目";
27
+ readonly snapshotOverride: true;
28
+ readonly change: "slow";
29
+ readonly screens: readonly ["first"];
30
+ readonly fields: readonly ["category", "categoryId", "catId", "catDOList"];
31
+ }, {
32
+ readonly subject: "行程与地点";
33
+ readonly change: "slow";
34
+ readonly screens: readonly ["second"];
35
+ readonly fields: readonly ["itinerary", "duration", "location", "address", "cityName", "city", "prov"];
36
+ }, {
37
+ readonly subject: "费用包含、不含与自费";
38
+ readonly change: "slow";
39
+ readonly screens: readonly ["second"];
40
+ readonly fields: readonly ["include", "exclude", "costInclude", "costExclude", "feesIncluded", "feesExcluded", "selfPaid", "selfPay", "optionalCosts"];
41
+ }, {
42
+ readonly subject: "退改";
43
+ readonly change: "slow";
44
+ readonly screens: readonly ["second"];
45
+ readonly fields: readonly ["refundRules", "cancellationPolicy", "cancelRules", "refund"];
46
+ }, {
47
+ readonly subject: "预订须知与服务";
48
+ readonly change: "slow";
49
+ readonly screens: readonly ["second"];
50
+ readonly fields: readonly ["bookingNotice", "bookingNotices", "bookingInstructions", "booking", "services", "terms"];
51
+ }, {
52
+ readonly subject: "规格";
53
+ readonly change: "slow";
54
+ readonly screens: readonly ["first"];
55
+ readonly fields: readonly ["sku.data.props"];
56
+ }, {
57
+ readonly subject: "详情行程";
58
+ readonly change: "slow";
59
+ readonly screens: readonly ["second"];
60
+ readonly fields: readonly ["itineraryInfo"];
61
+ }, {
62
+ readonly subject: "详情费用、须知与改期";
63
+ readonly change: "slow";
64
+ readonly screens: readonly ["second"];
65
+ readonly fields: readonly ["feeInfo.data.feeDetailVOList[].feeInclude", "feeInfo.data.feeDetailVOList[].feeExclude", "feeInfo.data.feeDetailVOList[].feeExtraDesc", "feeInfo.data.feeDetailVOList[].notice", "feeInfo.data.feeDetailVOList[].richNotice", "feeInfo.data.feeDetailVOList[].travelReschedule"];
66
+ }, {
67
+ readonly subject: "详情退改与安全须知";
68
+ readonly change: "slow";
69
+ readonly screens: readonly ["second"];
70
+ readonly fields: readonly ["standardRefund.data", "safeNotice"];
71
+ }, {
72
+ readonly subject: "详情当前价格";
73
+ readonly change: "fast";
74
+ readonly screens: readonly ["first"];
75
+ readonly fields: readonly ["price.price.priceText", "price.firstLinePrice.priceText"];
76
+ }, {
77
+ readonly subject: "当前日期价格与库存(仅供余位推算的当前库存输入)";
78
+ readonly change: "fast";
79
+ readonly screens: readonly ["first"];
80
+ readonly fields: readonly ["sku.data.skuMap.*[].dateRanges", "sku.data.skuMap.*[].firstLinePrice.priceText", "sku.data.skuMap.*[].quantity", "sku.data.skuMap.*[].hasQuantity"];
81
+ }, {
82
+ readonly subject: "价格与日历价";
83
+ readonly change: "fast";
84
+ readonly screens: readonly ["first"];
85
+ readonly fields: readonly ["price", "displayPrice", "priceInfo", "calendarPrice", "calendarPrices", "calendar", "datePrices", "salePrice"];
86
+ }, {
87
+ readonly subject: "余位";
88
+ readonly change: "fast";
89
+ readonly screens: readonly ["first"];
90
+ readonly fields: readonly ["stock", "inventory", "quantity", "amount", "num", "remaining", "remainingSeats", "availability"];
91
+ }, {
92
+ readonly subject: "团期与 SKU";
93
+ readonly change: "fast";
94
+ readonly screens: readonly ["first"];
95
+ readonly fields: readonly ["sku", "skuList", "skus", "skuInfo", "skuBase", "skuCore", "skuInfoDOList", "departures", "departureDate", "departureDates", "startDate", "endDate", "date", "useDate"];
96
+ }, {
97
+ readonly subject: "下架时间";
98
+ readonly change: "fast";
99
+ readonly screens: readonly ["first"];
100
+ readonly fields: readonly ["delistTime"];
101
+ }, {
102
+ readonly subject: "促销";
103
+ readonly change: "fast";
104
+ readonly screens: readonly ["first"];
105
+ readonly fields: readonly ["promotion", "promotions", "discount", "discounts", "coupon", "coupons", "activityPrice"];
106
+ }, {
107
+ readonly subject: "混合正文与属性";
108
+ readonly change: "mixed";
109
+ readonly screens: readonly ["first", "second"];
110
+ readonly fields: readonly ["description", "desc", "descContent", "wirelessDesc", "wirelessDescription", "wirelessDescDO", "content", "properties", "pvDOList", "features"];
111
+ }];
112
+ /** JSON values already admitted by the CLI result parser. */
113
+ export type ProductFields = NonNullable<CliResult['data']>;
114
+ type Json = ProductFields[string];
115
+ /** @param field - Original field name or declared dotted path. @returns Its declared policy, or undefined for an unclassified field. */
116
+ export declare function productFieldRule(field: string): FieldRule | undefined;
117
+ /**
118
+ * Select named stable or historical dynamic fields without turning opaque mixed text into stable facts.
119
+ * @param fields - Original projected product fields.
120
+ * @param screen - Requested detail screen.
121
+ * @param change - Collection admits slow fields; historical snapshots admit fast fields.
122
+ * @returns Original names and values, omitting empty values and unclassified roots.
123
+ */
124
+ export declare function projectProductFields(fields: ProductFields, screen: string, change: 'slow' | 'fast'): ProductFields;
125
+ /** @param value - Projected JSON. @returns Whether it contains a nonempty business value; zero and false remain recorded facts. */
126
+ export declare function productValuePresent(value: Json | undefined): boolean;
127
+ /** @param value - Parsed CLI JSON. @returns Its object fields, excluding arrays and scalars. */
128
+ export declare function productObject(value: Json | undefined): ProductFields | undefined;
129
+ export {};
@@ -0,0 +1,21 @@
1
+ /** Per-case cost estimates shared by the start page and production admission checks. */
2
+ /** Remaining model work; completed data submissions and attached scripts have zero remaining units. */
3
+ export interface ProductionWork {
4
+ readonly data: number;
5
+ readonly scripts: number;
6
+ readonly evaluation: number;
7
+ }
8
+ /** Resolved deployment estimates for each kind of model task. */
9
+ export interface ProductionPrices {
10
+ readonly estimatedDataTokensPerCase: number;
11
+ readonly estimatedDataCostUsdPerCase: number;
12
+ readonly estimatedScriptTokensPerCase: number;
13
+ readonly estimatedScriptCostUsdPerCase: number;
14
+ readonly estimatedTokensPerCase: number;
15
+ readonly estimatedCostUsdPerCase: number;
16
+ }
17
+ /** @param work - Remaining task counts. @param prices - Configured per-case estimates. @returns Total estimated tokens and USD. */
18
+ export declare function productionEstimate(work: ProductionWork, prices: ProductionPrices): {
19
+ tokens: number;
20
+ costUsd: number;
21
+ };
@@ -0,0 +1,20 @@
1
+ /** Formal-message buyer discovery with one fixed server window across cursor pages. */
2
+ import type { MerchantAccount } from '@gestaltrun/dsh-merchant-account';
3
+ /** Fixed formal-message interval requested by the Host. */
4
+ export interface ProductionWindow {
5
+ readonly from: string;
6
+ readonly to: string;
7
+ }
8
+ /** Distinct buyers found within the fixed Host interval. */
9
+ export interface ProductionBuyers extends ProductionWindow {
10
+ readonly buyers: readonly string[];
11
+ }
12
+ /**
13
+ * Enumerate formal-message buyers independently of local IM history and existing cases.
14
+ * @param account - Tenant-bound merchant request capability.
15
+ * @param window - Fixed Host interval sent on every page; the server must return the same timestamps.
16
+ * @param signal - Shop and caller lifetime; late responses are discarded.
17
+ * @returns Every distinct buyer in the requested window after the terminal cursor.
18
+ * @throws ProductionFailure on refusal, a stalled cursor or a changed window; no partial list is returned.
19
+ */
20
+ export declare function readProductionBuyers(account: Pick<MerchantAccount, 'request'>, window: ProductionWindow, signal: AbortSignal): Promise<ProductionBuyers>;