@escapeaihq/client-core 0.12.0 → 0.49.0
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 +32 -7
- package/dist/adapters/capabilities.d.ts +10 -0
- package/dist/adapters/capabilities.d.ts.map +1 -0
- package/dist/adapters/capabilities.js +2 -0
- package/dist/adapters/capabilities.js.map +1 -0
- package/dist/adapters/chatAdapter.d.ts +38 -0
- package/dist/adapters/chatAdapter.d.ts.map +1 -0
- package/dist/adapters/chatAdapter.js +88 -0
- package/dist/adapters/chatAdapter.js.map +1 -0
- package/dist/adapters/directorAdapter.d.ts +62 -0
- package/dist/adapters/directorAdapter.d.ts.map +1 -0
- package/dist/adapters/directorAdapter.js +71 -0
- package/dist/adapters/directorAdapter.js.map +1 -0
- package/dist/adapters/imageAdapter.d.ts +44 -0
- package/dist/adapters/imageAdapter.d.ts.map +1 -0
- package/dist/adapters/imageAdapter.js +73 -0
- package/dist/adapters/imageAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +47 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +41 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/registry.d.ts +98 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +106 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/worldAdapter.d.ts +142 -0
- package/dist/adapters/worldAdapter.d.ts.map +1 -0
- package/dist/adapters/worldAdapter.js +164 -0
- package/dist/adapters/worldAdapter.js.map +1 -0
- package/dist/admin.d.ts +323 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +198 -0
- package/dist/admin.js.map +1 -0
- package/dist/api.d.ts +1512 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +820 -52
- package/dist/api.js.map +1 -1
- package/dist/audio.d.ts +33 -1
- package/dist/audio.d.ts.map +1 -1
- package/dist/audio.js +4 -1
- package/dist/audio.js.map +1 -1
- package/dist/castProjection.d.ts +35 -0
- package/dist/castProjection.d.ts.map +1 -0
- package/dist/castProjection.js +80 -0
- package/dist/castProjection.js.map +1 -0
- package/dist/conversation/binding.d.ts +77 -0
- package/dist/conversation/binding.d.ts.map +1 -0
- package/dist/conversation/binding.js +57 -0
- package/dist/conversation/binding.js.map +1 -0
- package/dist/conversation/controller.d.ts +209 -0
- package/dist/conversation/controller.d.ts.map +1 -0
- package/dist/conversation/controller.js +350 -0
- package/dist/conversation/controller.js.map +1 -0
- package/dist/conversation/effectiveModel.d.ts +62 -0
- package/dist/conversation/effectiveModel.d.ts.map +1 -0
- package/dist/conversation/effectiveModel.js +73 -0
- package/dist/conversation/effectiveModel.js.map +1 -0
- package/dist/conversation/index.d.ts +27 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +27 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/participant.d.ts +66 -0
- package/dist/conversation/participant.d.ts.map +1 -0
- package/dist/conversation/participant.js +36 -0
- package/dist/conversation/participant.js.map +1 -0
- package/dist/conversation/presence.d.ts +56 -0
- package/dist/conversation/presence.d.ts.map +1 -0
- package/dist/conversation/presence.js +34 -0
- package/dist/conversation/presence.js.map +1 -0
- package/dist/conversation/presenceBus.d.ts +42 -0
- package/dist/conversation/presenceBus.d.ts.map +1 -0
- package/dist/conversation/presenceBus.js +81 -0
- package/dist/conversation/presenceBus.js.map +1 -0
- package/dist/conversation/presenceRegistry.d.ts +49 -0
- package/dist/conversation/presenceRegistry.d.ts.map +1 -0
- package/dist/conversation/presenceRegistry.js +59 -0
- package/dist/conversation/presenceRegistry.js.map +1 -0
- package/dist/conversation/roster.d.ts +72 -0
- package/dist/conversation/roster.d.ts.map +1 -0
- package/dist/conversation/roster.js +69 -0
- package/dist/conversation/roster.js.map +1 -0
- package/dist/conversation/rosterProjection.d.ts +52 -0
- package/dist/conversation/rosterProjection.d.ts.map +1 -0
- package/dist/conversation/rosterProjection.js +74 -0
- package/dist/conversation/rosterProjection.js.map +1 -0
- package/dist/conversation/router.d.ts +74 -0
- package/dist/conversation/router.d.ts.map +1 -0
- package/dist/conversation/router.js +58 -0
- package/dist/conversation/router.js.map +1 -0
- package/dist/conversation/runtime.d.ts +64 -0
- package/dist/conversation/runtime.d.ts.map +1 -0
- package/dist/conversation/runtime.js +172 -0
- package/dist/conversation/runtime.js.map +1 -0
- package/dist/conversation/types.d.ts +99 -0
- package/dist/conversation/types.d.ts.map +1 -0
- package/dist/conversation/types.js +13 -0
- package/dist/conversation/types.js.map +1 -0
- package/dist/conversation/voice.d.ts +185 -0
- package/dist/conversation/voice.d.ts.map +1 -0
- package/dist/conversation/voice.js +307 -0
- package/dist/conversation/voice.js.map +1 -0
- package/dist/graphSchema.d.ts +201 -13
- package/dist/graphSchema.d.ts.map +1 -1
- package/dist/graphSchema.js +258 -9
- package/dist/graphSchema.js.map +1 -1
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +57 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/platformAssistant.d.ts +155 -0
- package/dist/platformAssistant.d.ts.map +1 -0
- package/dist/platformAssistant.js +256 -0
- package/dist/platformAssistant.js.map +1 -0
- package/dist/reactor/chunkDistribution.d.ts +43 -0
- package/dist/reactor/chunkDistribution.d.ts.map +1 -0
- package/dist/reactor/chunkDistribution.js +85 -0
- package/dist/reactor/chunkDistribution.js.map +1 -0
- package/dist/reactor/index.d.ts +2 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +5 -0
- package/dist/reactor/index.js.map +1 -1
- package/dist/reactor/longLiveCommandDispatcher.d.ts +103 -0
- package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -0
- package/dist/reactor/longLiveCommandDispatcher.js +87 -0
- package/dist/reactor/longLiveCommandDispatcher.js.map +1 -0
- package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -1
- package/dist/reactor/scenesFromEnrichment.js +2 -66
- package/dist/reactor/scenesFromEnrichment.js.map +1 -1
- package/dist/reactor/seedImageOrchestrator.d.ts +6 -9
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +12 -13
- package/dist/reactor/seedImageOrchestrator.js.map +1 -1
- package/dist/reactor/storyTimeline.d.ts +44 -0
- package/dist/reactor/storyTimeline.d.ts.map +1 -0
- package/dist/reactor/storyTimeline.js +95 -0
- package/dist/reactor/storyTimeline.js.map +1 -0
- package/dist/storyGraph.d.ts +70 -0
- package/dist/storyGraph.d.ts.map +1 -0
- package/dist/storyGraph.js +178 -0
- package/dist/storyGraph.js.map +1 -0
- package/dist/vision/VisionSourceController.d.ts +127 -0
- package/dist/vision/VisionSourceController.d.ts.map +1 -0
- package/dist/vision/VisionSourceController.js +284 -0
- package/dist/vision/VisionSourceController.js.map +1 -0
- package/dist/vision/index.d.ts +4 -0
- package/dist/vision/index.d.ts.map +1 -1
- package/dist/vision/index.js +2 -0
- package/dist/vision/index.js.map +1 -1
- package/dist/vision/sourceKinds.d.ts +65 -0
- package/dist/vision/sourceKinds.d.ts.map +1 -0
- package/dist/vision/sourceKinds.js +26 -0
- package/dist/vision/sourceKinds.js.map +1 -0
- package/dist/websocket.d.ts +92 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/adapters-capabilities.test.ts +46 -0
- package/src/__tests__/adapters-chat.test.ts +172 -0
- package/src/__tests__/adapters-director.test.ts +95 -0
- package/src/__tests__/adapters-image.test.ts +133 -0
- package/src/__tests__/adapters-platform.test.ts +95 -0
- package/src/__tests__/adapters-registry.test.ts +189 -0
- package/src/__tests__/adapters-world.test.ts +296 -0
- package/src/__tests__/admin.test.ts +312 -0
- package/src/__tests__/adventures-party.test.ts +219 -0
- package/src/__tests__/adventures.test.ts +282 -0
- package/src/__tests__/api-pollers.test.ts +4 -0
- package/src/__tests__/api.clip-lookup.test.ts +64 -0
- package/src/__tests__/api.list-images-filters.test.ts +103 -0
- package/src/__tests__/api.test.ts +553 -0
- package/src/__tests__/audio.test.ts +65 -0
- package/src/__tests__/cast.test.ts +95 -0
- package/src/__tests__/castProjection.test.ts +167 -0
- package/src/__tests__/conversation/binding.test.ts +62 -0
- package/src/__tests__/conversation/controller.test.ts +732 -0
- package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
- package/src/__tests__/conversation/headlessRenderer.ts +46 -0
- package/src/__tests__/conversation/presenceBus.test.ts +236 -0
- package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
- package/src/__tests__/conversation/roster.test.ts +100 -0
- package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
- package/src/__tests__/conversation/router.test.ts +81 -0
- package/src/__tests__/conversation/runtime.test.ts +206 -0
- package/src/__tests__/conversation/voice.test.ts +440 -0
- package/src/__tests__/documents.test.ts +360 -0
- package/src/__tests__/graphSchema.test.ts +218 -9
- package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
- package/src/__tests__/monitoring.test.ts +162 -0
- package/src/__tests__/persona-generation.test.ts +352 -0
- package/src/__tests__/platformAssistant.test.ts +484 -0
- package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
- package/src/__tests__/regeneration.test.ts +486 -0
- package/src/__tests__/stories.test.ts +171 -0
- package/src/__tests__/storyGraph.test.ts +134 -0
- package/src/__tests__/tools-wrappers.test.ts +272 -0
- package/src/__tests__/videoGraph.test.ts +94 -0
- package/src/__tests__/websocket.test.ts +263 -0
- package/src/adapters/capabilities.ts +24 -0
- package/src/adapters/chatAdapter.ts +114 -0
- package/src/adapters/directorAdapter.ts +126 -0
- package/src/adapters/imageAdapter.ts +100 -0
- package/src/adapters/index.ts +67 -0
- package/src/adapters/registry.ts +159 -0
- package/src/adapters/worldAdapter.ts +272 -0
- package/src/admin.ts +517 -0
- package/src/api.ts +2215 -95
- package/src/audio.ts +35 -0
- package/src/castProjection.ts +95 -0
- package/src/conversation/binding.ts +100 -0
- package/src/conversation/controller.ts +447 -0
- package/src/conversation/effectiveModel.ts +111 -0
- package/src/conversation/index.ts +27 -0
- package/src/conversation/participant.ts +71 -0
- package/src/conversation/presence.ts +60 -0
- package/src/conversation/presenceBus.ts +109 -0
- package/src/conversation/presenceRegistry.ts +83 -0
- package/src/conversation/roster.ts +111 -0
- package/src/conversation/rosterProjection.ts +98 -0
- package/src/conversation/router.ts +96 -0
- package/src/conversation/runtime.ts +188 -0
- package/src/conversation/types.ts +100 -0
- package/src/conversation/voice.ts +402 -0
- package/src/graphSchema.ts +396 -13
- package/src/http.ts +72 -0
- package/src/index.ts +9 -0
- package/src/platformAssistant.ts +347 -0
- package/src/reactor/chunkDistribution.ts +98 -0
- package/src/reactor/index.ts +5 -0
- package/src/reactor/longLiveCommandDispatcher.ts +156 -0
- package/src/reactor/scenesFromEnrichment.ts +11 -76
- package/src/reactor/seedImageOrchestrator.ts +12 -13
- package/src/reactor/storyTimeline.ts +127 -0
- package/src/storyGraph.ts +298 -0
- package/src/vision/VisionSourceController.ts +354 -0
- package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
- package/src/vision/index.ts +13 -0
- package/src/vision/sourceKinds.ts +75 -0
- package/src/websocket.ts +99 -3
package/src/admin.ts
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin control-plane client (GitHub #215 Phase 2): the prompt-defaults editor.
|
|
3
|
+
*
|
|
4
|
+
* Additive surface — a new `AdminClient` class plus its `PromptDefault*` types.
|
|
5
|
+
* It does NOT touch `ApiClient`'s public API (the `^0.x`-pinned external
|
|
6
|
+
* consumer must keep working). The admin endpoints live on the CHAT API base
|
|
7
|
+
* (the router is mounted in `api/chat/app.py`), so `AdminClient` is constructed
|
|
8
|
+
* with the chat base URL + session token, mirroring how `ApiClient` routes
|
|
9
|
+
* persona/chat calls through `chatRequest`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { requestJson } from './http';
|
|
13
|
+
|
|
14
|
+
/** Where a prompt's effective value comes from. Mirrors the backend enum. */
|
|
15
|
+
export type PromptDefaultSource = 'db' | 'code';
|
|
16
|
+
|
|
17
|
+
/** One row in the editor list: identity + source + audit metadata (no body). */
|
|
18
|
+
export interface PromptDefaultSummary {
|
|
19
|
+
promptKey: string;
|
|
20
|
+
label: string;
|
|
21
|
+
group: string;
|
|
22
|
+
source: PromptDefaultSource;
|
|
23
|
+
updatedAt: string | null;
|
|
24
|
+
updatedBy: string | null;
|
|
25
|
+
editable: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Response for `GET /api/v1/admin/prompts`. */
|
|
29
|
+
export interface PromptDefaultsListResponse {
|
|
30
|
+
prompts: PromptDefaultSummary[];
|
|
31
|
+
traceId: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Single-key detail: effective value + in-code default (for diff) + metadata. */
|
|
35
|
+
export interface PromptDefaultDetail {
|
|
36
|
+
promptKey: string;
|
|
37
|
+
label: string;
|
|
38
|
+
group: string;
|
|
39
|
+
source: PromptDefaultSource;
|
|
40
|
+
value: string;
|
|
41
|
+
codeDefault: string;
|
|
42
|
+
previousValue: string | null;
|
|
43
|
+
updatedAt: string | null;
|
|
44
|
+
updatedBy: string | null;
|
|
45
|
+
editable: boolean;
|
|
46
|
+
traceId: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Body for `PUT /api/v1/admin/prompts/{key}`. */
|
|
50
|
+
export interface UpdatePromptDefaultRequest {
|
|
51
|
+
value: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* One read-only regeneration base prompt from `GET /api/v1/admin/regen-prompts`
|
|
56
|
+
* (R6d). Mirrors the backend `RegenBasePrompt` (`api/admin/schemas.py`) EXACTLY.
|
|
57
|
+
* These prompts are eval-gated (tuned via observability/eval promotion,
|
|
58
|
+
* tech-debt #336) — `editable` is always `false` and the API exposes NO write
|
|
59
|
+
* path for them.
|
|
60
|
+
*/
|
|
61
|
+
export interface RegenBasePrompt {
|
|
62
|
+
promptKey: string;
|
|
63
|
+
label: string;
|
|
64
|
+
group: string;
|
|
65
|
+
/** Regeneration scope kind: 'acts' | 'characters' | 'scene' | 'arc'. */
|
|
66
|
+
scopeKind: string;
|
|
67
|
+
/** The in-code base prompt text, verbatim. */
|
|
68
|
+
prompt: string;
|
|
69
|
+
editable: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Response for `GET /api/v1/admin/regen-prompts` (read-only list). */
|
|
73
|
+
export interface RegenBasePromptsResponse {
|
|
74
|
+
prompts: RegenBasePrompt[];
|
|
75
|
+
traceId: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One scored synthetic-eval run from `GET /api/v1/admin/eval-runs` (M12 S4/S5).
|
|
80
|
+
*
|
|
81
|
+
* Mirrors the backend `EvalRunSummary` (`api/admin/schemas.py`) EXACTLY —
|
|
82
|
+
* same camelCase field names + nullability. The internal PK/SK/gsi1pk/gsi1sk
|
|
83
|
+
* storage keys are dropped server-side, so they never appear here. `metrics`
|
|
84
|
+
* and the optional provenance fields are always sent by the endpoint (the
|
|
85
|
+
* Python model merely defaults them).
|
|
86
|
+
*/
|
|
87
|
+
export interface EvalRunSummary {
|
|
88
|
+
evalRunId: string;
|
|
89
|
+
benchmarkId: string;
|
|
90
|
+
scenarioId: string;
|
|
91
|
+
status: string;
|
|
92
|
+
createdAt: string;
|
|
93
|
+
metrics: Record<string, number>;
|
|
94
|
+
scenarioSetId: string | null;
|
|
95
|
+
scenarioType: string | null;
|
|
96
|
+
promptVersion: string | null;
|
|
97
|
+
pipelineVersion: string | null;
|
|
98
|
+
modelId: string | null;
|
|
99
|
+
routeName: string | null;
|
|
100
|
+
costTier: string | null;
|
|
101
|
+
latencyMs: number | null;
|
|
102
|
+
estimatedCostUsd: number | null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** One cursor-paginated page from `GET /api/v1/admin/eval-runs`. */
|
|
106
|
+
export interface EvalRunsListResponse {
|
|
107
|
+
runs: EvalRunSummary[];
|
|
108
|
+
nextCursor: string | null;
|
|
109
|
+
traceId: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Query params for `listEvalRuns`.
|
|
114
|
+
*
|
|
115
|
+
* The server enforces an XOR contract: provide EXACTLY ONE of `benchmarkId`
|
|
116
|
+
* (base-table access path) or `promptVersion` (GSI1 access path) — neither or
|
|
117
|
+
* both yields a 422. The client does not pre-validate; it forwards whatever is
|
|
118
|
+
* given.
|
|
119
|
+
*/
|
|
120
|
+
export interface ListEvalRunsParams {
|
|
121
|
+
benchmarkId?: string;
|
|
122
|
+
promptVersion?: string;
|
|
123
|
+
limit?: number;
|
|
124
|
+
cursor?: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Result of `listAllEvalRuns`: the accumulated runs plus whether the page cap
|
|
129
|
+
* was hit. `truncated` is `true` when {@link MAX_EVAL_RUN_PAGES} was reached
|
|
130
|
+
* with more pages still pending — `runs` is then a newest-first PREFIX, NOT the
|
|
131
|
+
* full series, so the caller must warn rather than present it as complete.
|
|
132
|
+
*/
|
|
133
|
+
export interface AllEvalRunsResult {
|
|
134
|
+
runs: EvalRunSummary[];
|
|
135
|
+
truncated: boolean;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// --------------------------------------------------------------------------- //
|
|
139
|
+
// C4 Phase 3 — admin monitoring tools. Read-only proxies over CloudWatch
|
|
140
|
+
// (GetMetricData) + X-Ray (GetTraceSummaries / BatchGetTraces), behind the same
|
|
141
|
+
// require_admin gate. Mirror the backend schemas in `api/admin/schemas.py`
|
|
142
|
+
// EXACTLY (camelCase + nullability).
|
|
143
|
+
// --------------------------------------------------------------------------- //
|
|
144
|
+
|
|
145
|
+
/** One allowlisted metric the admin tools may chart (catalog view). */
|
|
146
|
+
export interface MonitoringMetricCatalogEntry {
|
|
147
|
+
metricId: string;
|
|
148
|
+
namespace: string;
|
|
149
|
+
metricName: string;
|
|
150
|
+
stat: string;
|
|
151
|
+
unit: string;
|
|
152
|
+
label: string;
|
|
153
|
+
dimensionKeys: string[];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Response for `GET /api/v1/admin/monitoring/metrics` (catalog list). */
|
|
157
|
+
export interface MonitoringMetricCatalogResponse {
|
|
158
|
+
metrics: MonitoringMetricCatalogEntry[];
|
|
159
|
+
traceId: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** One (timestamp, value) point on a metric series. */
|
|
163
|
+
export interface MonitoringMetricDatapoint {
|
|
164
|
+
timestamp: string;
|
|
165
|
+
value: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A resolved CloudWatch series for one allowlisted metric. */
|
|
169
|
+
export interface MonitoringMetricSeriesResponse {
|
|
170
|
+
metricId: string;
|
|
171
|
+
label: string;
|
|
172
|
+
unit: string;
|
|
173
|
+
periodSeconds: number;
|
|
174
|
+
startTime: string;
|
|
175
|
+
endTime: string;
|
|
176
|
+
/** May be empty (no data in window / seam not yet instrumented). */
|
|
177
|
+
datapoints: MonitoringMetricDatapoint[];
|
|
178
|
+
traceId: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** One X-Ray trace in the explorer list view. */
|
|
182
|
+
export interface MonitoringTraceSummary {
|
|
183
|
+
traceId: string;
|
|
184
|
+
durationSeconds: number | null;
|
|
185
|
+
responseTimeSeconds: number | null;
|
|
186
|
+
hasError: boolean;
|
|
187
|
+
hasFault: boolean;
|
|
188
|
+
hasThrottle: boolean;
|
|
189
|
+
httpStatus: number | null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Response for `GET /api/v1/admin/monitoring/traces` (X-Ray summaries). */
|
|
193
|
+
export interface MonitoringTraceSummariesResponse {
|
|
194
|
+
startTime: string;
|
|
195
|
+
endTime: string;
|
|
196
|
+
/** Empty until more seams are instrumented (only bedrock.converse so far). */
|
|
197
|
+
traces: MonitoringTraceSummary[];
|
|
198
|
+
traceId: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Response for `GET /api/v1/admin/monitoring/traces/{xrayTraceId}`.
|
|
203
|
+
*
|
|
204
|
+
* `found=false` (200, empty `segments`) when X-Ray has no such trace. `segments`
|
|
205
|
+
* is the raw X-Ray segment-document list for the client-side waterfall renderer.
|
|
206
|
+
*/
|
|
207
|
+
export interface MonitoringTraceDetailResponse {
|
|
208
|
+
xrayTraceId: string;
|
|
209
|
+
found: boolean;
|
|
210
|
+
segments: Array<Record<string, unknown>>;
|
|
211
|
+
traceId: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Query params for `getMetricSeries`. */
|
|
215
|
+
export interface MetricSeriesParams {
|
|
216
|
+
/** Look-back window in seconds (server clamps to <= 14 days). */
|
|
217
|
+
rangeSeconds?: number;
|
|
218
|
+
/** Aggregation bucket in seconds (server clamps to [60, 86400]). */
|
|
219
|
+
periodSeconds?: number;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Query params for `listTraces`. */
|
|
223
|
+
export interface ListTracesParams {
|
|
224
|
+
/** Filter by the seer.job_id span annotation. */
|
|
225
|
+
jobId?: string;
|
|
226
|
+
/** Filter by the seer.video_id span annotation. */
|
|
227
|
+
videoId?: string;
|
|
228
|
+
/** Look-back window in seconds (server clamps to <= 6 hours). */
|
|
229
|
+
rangeSeconds?: number;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const ADMIN_PROMPTS_PATH = '/api/v1/admin/prompts';
|
|
233
|
+
const ADMIN_EVAL_RUNS_PATH = '/api/v1/admin/eval-runs';
|
|
234
|
+
const ADMIN_REGEN_PROMPTS_PATH = '/api/v1/admin/regen-prompts';
|
|
235
|
+
const ADMIN_MONITORING_PATH = '/api/v1/admin/monitoring';
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Safety cap on `listAllEvalRuns` pagination. A misbehaving server that always
|
|
239
|
+
* returns a non-null `nextCursor` would otherwise loop forever; 50 pages at the
|
|
240
|
+
* default page limit is plenty for an admin trend view, so we stop (not throw)
|
|
241
|
+
* at the cap and the page renders what it has.
|
|
242
|
+
*/
|
|
243
|
+
export const MAX_EVAL_RUN_PAGES = 50;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Client for the admin prompt-defaults CRUD surface.
|
|
247
|
+
*
|
|
248
|
+
* The auth gate is the allow-all `get_user_id` floor today (any authenticated
|
|
249
|
+
* user); the per-user/admin gate is deferred to the future RBAC milestone. The
|
|
250
|
+
* server enforces the editable-key carve-out (extraction-template keys are not
|
|
251
|
+
* editable) regardless — a non-editable key yields a 404, surfaced here as a
|
|
252
|
+
* thrown `Error`.
|
|
253
|
+
*/
|
|
254
|
+
export class AdminClient {
|
|
255
|
+
private chatBaseUrl: string;
|
|
256
|
+
private sessionToken?: string;
|
|
257
|
+
|
|
258
|
+
constructor(chatBaseUrl: string, sessionToken?: string) {
|
|
259
|
+
this.chatBaseUrl = chatBaseUrl;
|
|
260
|
+
this.sessionToken = sessionToken;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Update the bearer token (e.g. after a Descope session refresh). */
|
|
264
|
+
setSessionToken(token: string | undefined): void {
|
|
265
|
+
this.sessionToken = token;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** List every editable prompt key with its source (db|code) + audit metadata. */
|
|
269
|
+
async listPromptDefaults(
|
|
270
|
+
options: { signal?: AbortSignal } = {},
|
|
271
|
+
): Promise<PromptDefaultsListResponse> {
|
|
272
|
+
return requestJson<PromptDefaultsListResponse>(
|
|
273
|
+
this.chatBaseUrl,
|
|
274
|
+
ADMIN_PROMPTS_PATH,
|
|
275
|
+
this.sessionToken,
|
|
276
|
+
{ signal: options.signal },
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Get one key's effective value, in-code default (for diff), and metadata. */
|
|
281
|
+
async getPromptDefault(
|
|
282
|
+
promptKey: string,
|
|
283
|
+
options: { signal?: AbortSignal } = {},
|
|
284
|
+
): Promise<PromptDefaultDetail> {
|
|
285
|
+
return requestJson<PromptDefaultDetail>(
|
|
286
|
+
this.chatBaseUrl,
|
|
287
|
+
`${ADMIN_PROMPTS_PATH}/${encodeURIComponent(promptKey)}`,
|
|
288
|
+
this.sessionToken,
|
|
289
|
+
{ signal: options.signal },
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Create or update an override (201 on create, 200 on update server-side). */
|
|
294
|
+
async updatePromptDefault(
|
|
295
|
+
promptKey: string,
|
|
296
|
+
body: UpdatePromptDefaultRequest,
|
|
297
|
+
options: { signal?: AbortSignal } = {},
|
|
298
|
+
): Promise<PromptDefaultDetail> {
|
|
299
|
+
return requestJson<PromptDefaultDetail>(
|
|
300
|
+
this.chatBaseUrl,
|
|
301
|
+
`${ADMIN_PROMPTS_PATH}/${encodeURIComponent(promptKey)}`,
|
|
302
|
+
this.sessionToken,
|
|
303
|
+
{ method: 'PUT', body: JSON.stringify(body), signal: options.signal },
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** One-step revert: restores the previous value, else the in-code default. */
|
|
308
|
+
async revertPromptDefault(
|
|
309
|
+
promptKey: string,
|
|
310
|
+
options: { signal?: AbortSignal } = {},
|
|
311
|
+
): Promise<PromptDefaultDetail> {
|
|
312
|
+
return requestJson<PromptDefaultDetail>(
|
|
313
|
+
this.chatBaseUrl,
|
|
314
|
+
`${ADMIN_PROMPTS_PATH}/${encodeURIComponent(promptKey)}/revert`,
|
|
315
|
+
this.sessionToken,
|
|
316
|
+
{ method: 'POST', signal: options.signal },
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* List the AI-tuned regeneration base prompts (acts/characters/scene/arc),
|
|
322
|
+
* READ-ONLY (R6d). There is no corresponding write method — the backend
|
|
323
|
+
* exposes no PUT/POST for these prompts; they are tuned via the eval-gated
|
|
324
|
+
* promotion (tech-debt #336), never the admin editor.
|
|
325
|
+
*/
|
|
326
|
+
async listRegenBasePrompts(
|
|
327
|
+
options: { signal?: AbortSignal } = {},
|
|
328
|
+
): Promise<RegenBasePromptsResponse> {
|
|
329
|
+
return requestJson<RegenBasePromptsResponse>(
|
|
330
|
+
this.chatBaseUrl,
|
|
331
|
+
ADMIN_REGEN_PROMPTS_PATH,
|
|
332
|
+
this.sessionToken,
|
|
333
|
+
{ signal: options.signal },
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Fetch one cursor-paginated page of scored synthetic-eval runs (M12 S5).
|
|
339
|
+
*
|
|
340
|
+
* The server enforces the XOR contract — EXACTLY ONE of `benchmarkId` or
|
|
341
|
+
* `promptVersion` (neither/both → 422). This client does NOT pre-validate; it
|
|
342
|
+
* forwards the params as given and lets `requestJson` surface a 422 as a
|
|
343
|
+
* thrown `Error`. Only defined params are appended to the query string.
|
|
344
|
+
*/
|
|
345
|
+
async listEvalRuns(
|
|
346
|
+
params: ListEvalRunsParams,
|
|
347
|
+
options: { signal?: AbortSignal } = {},
|
|
348
|
+
): Promise<EvalRunsListResponse> {
|
|
349
|
+
const search = new URLSearchParams();
|
|
350
|
+
if (params.benchmarkId !== undefined) {
|
|
351
|
+
search.set('benchmarkId', params.benchmarkId);
|
|
352
|
+
}
|
|
353
|
+
if (params.promptVersion !== undefined) {
|
|
354
|
+
search.set('promptVersion', params.promptVersion);
|
|
355
|
+
}
|
|
356
|
+
if (params.limit !== undefined) {
|
|
357
|
+
search.set('limit', String(params.limit));
|
|
358
|
+
}
|
|
359
|
+
if (params.cursor !== undefined) {
|
|
360
|
+
search.set('cursor', params.cursor);
|
|
361
|
+
}
|
|
362
|
+
const qs = search.toString();
|
|
363
|
+
const path = qs ? `${ADMIN_EVAL_RUNS_PATH}?${qs}` : ADMIN_EVAL_RUNS_PATH;
|
|
364
|
+
return requestJson<EvalRunsListResponse>(
|
|
365
|
+
this.chatBaseUrl,
|
|
366
|
+
path,
|
|
367
|
+
this.sessionToken,
|
|
368
|
+
{ signal: options.signal },
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Page through ALL eval runs for the given selector, newest-first.
|
|
374
|
+
*
|
|
375
|
+
* Follows `nextCursor` until it is `null`, accumulating runs. Stops (does NOT
|
|
376
|
+
* throw) at {@link MAX_EVAL_RUN_PAGES} so a misbehaving server — or simply a
|
|
377
|
+
* benchmark with more history than the cap covers — cannot spin forever. When
|
|
378
|
+
* the cap is hit with pages still pending, the returned `runs` is a
|
|
379
|
+
* newest-first PREFIX and `truncated` is `true`, so the caller can warn rather
|
|
380
|
+
* than present a partial series as complete (the `/observability` page does).
|
|
381
|
+
* The caller's `params` are never mutated (the cursor lives in a local). Any
|
|
382
|
+
* `params.cursor` is IGNORED — "list ALL" always starts from the newest page,
|
|
383
|
+
* so a stray cursor can't silently begin mid-series. Honors `options.signal`
|
|
384
|
+
* on every page request.
|
|
385
|
+
*/
|
|
386
|
+
async listAllEvalRuns(
|
|
387
|
+
params: ListEvalRunsParams,
|
|
388
|
+
options: { signal?: AbortSignal } = {},
|
|
389
|
+
): Promise<AllEvalRunsResult> {
|
|
390
|
+
const runs: EvalRunSummary[] = [];
|
|
391
|
+
// Start at the newest page regardless of any caller-supplied params.cursor —
|
|
392
|
+
// mid-series start would silently return a truncated history.
|
|
393
|
+
let cursor: string | undefined = undefined;
|
|
394
|
+
for (let page = 0; page < MAX_EVAL_RUN_PAGES; page += 1) {
|
|
395
|
+
const response = await this.listEvalRuns({ ...params, cursor }, options);
|
|
396
|
+
runs.push(...response.runs);
|
|
397
|
+
if (response.nextCursor === null) {
|
|
398
|
+
return { runs, truncated: false };
|
|
399
|
+
}
|
|
400
|
+
cursor = response.nextCursor;
|
|
401
|
+
}
|
|
402
|
+
// Exhausted the page cap with a non-null cursor still pending — partial.
|
|
403
|
+
return { runs, truncated: true };
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Client for the C4 Phase-3 admin monitoring tools (read-only).
|
|
409
|
+
*
|
|
410
|
+
* Wraps the four `require_admin`-gated `/api/v1/admin/monitoring/*` read proxies
|
|
411
|
+
* over CloudWatch (GetMetricData) + X-Ray (GetTraceSummaries / BatchGetTraces).
|
|
412
|
+
* Like {@link AdminClient}, it targets the CHAT API base (the router is mounted
|
|
413
|
+
* in `api/chat/app.py`) and carries the Descope session token. Additive — it
|
|
414
|
+
* does NOT touch the public `ApiClient` surface. A metric is selected by its
|
|
415
|
+
* allowlist `metricId` (from {@link listMetrics}); there is no raw
|
|
416
|
+
* namespace/metric-name pass-through.
|
|
417
|
+
*/
|
|
418
|
+
export class MonitoringClient {
|
|
419
|
+
private chatBaseUrl: string;
|
|
420
|
+
private sessionToken?: string;
|
|
421
|
+
|
|
422
|
+
constructor(chatBaseUrl: string, sessionToken?: string) {
|
|
423
|
+
this.chatBaseUrl = chatBaseUrl;
|
|
424
|
+
this.sessionToken = sessionToken;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** Update the bearer token (e.g. after a Descope session refresh). */
|
|
428
|
+
setSessionToken(token: string | undefined): void {
|
|
429
|
+
this.sessionToken = token;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** List the allowlisted metric catalog (what can be charted; no AWS call). */
|
|
433
|
+
async listMetrics(
|
|
434
|
+
options: { signal?: AbortSignal } = {},
|
|
435
|
+
): Promise<MonitoringMetricCatalogResponse> {
|
|
436
|
+
return requestJson<MonitoringMetricCatalogResponse>(
|
|
437
|
+
this.chatBaseUrl,
|
|
438
|
+
`${ADMIN_MONITORING_PATH}/metrics`,
|
|
439
|
+
this.sessionToken,
|
|
440
|
+
{ signal: options.signal },
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Fetch a CloudWatch series for ONE allowlisted metric over a clamped window.
|
|
446
|
+
* An unknown `metricId` yields a 404 (thrown `Error`); an empty `datapoints`
|
|
447
|
+
* is normal (no data / seam not yet wired).
|
|
448
|
+
*/
|
|
449
|
+
async getMetricSeries(
|
|
450
|
+
metricId: string,
|
|
451
|
+
params: MetricSeriesParams = {},
|
|
452
|
+
options: { signal?: AbortSignal } = {},
|
|
453
|
+
): Promise<MonitoringMetricSeriesResponse> {
|
|
454
|
+
const search = new URLSearchParams();
|
|
455
|
+
if (params.rangeSeconds !== undefined) {
|
|
456
|
+
search.set('rangeSeconds', String(params.rangeSeconds));
|
|
457
|
+
}
|
|
458
|
+
if (params.periodSeconds !== undefined) {
|
|
459
|
+
search.set('periodSeconds', String(params.periodSeconds));
|
|
460
|
+
}
|
|
461
|
+
const qs = search.toString();
|
|
462
|
+
const base = `${ADMIN_MONITORING_PATH}/metrics/${encodeURIComponent(metricId)}`;
|
|
463
|
+
const path = qs ? `${base}?${qs}` : base;
|
|
464
|
+
return requestJson<MonitoringMetricSeriesResponse>(
|
|
465
|
+
this.chatBaseUrl,
|
|
466
|
+
path,
|
|
467
|
+
this.sessionToken,
|
|
468
|
+
{ signal: options.signal },
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* List recent X-Ray traces, optionally filtered by `jobId` / `videoId` (the
|
|
474
|
+
* `seer.*` span annotations) + window. An empty list is normal until more
|
|
475
|
+
* seams are instrumented. A malformed id (quotes/whitespace) yields a 422.
|
|
476
|
+
*/
|
|
477
|
+
async listTraces(
|
|
478
|
+
params: ListTracesParams = {},
|
|
479
|
+
options: { signal?: AbortSignal } = {},
|
|
480
|
+
): Promise<MonitoringTraceSummariesResponse> {
|
|
481
|
+
const search = new URLSearchParams();
|
|
482
|
+
if (params.jobId !== undefined) {
|
|
483
|
+
search.set('jobId', params.jobId);
|
|
484
|
+
}
|
|
485
|
+
if (params.videoId !== undefined) {
|
|
486
|
+
search.set('videoId', params.videoId);
|
|
487
|
+
}
|
|
488
|
+
if (params.rangeSeconds !== undefined) {
|
|
489
|
+
search.set('rangeSeconds', String(params.rangeSeconds));
|
|
490
|
+
}
|
|
491
|
+
const qs = search.toString();
|
|
492
|
+
const base = `${ADMIN_MONITORING_PATH}/traces`;
|
|
493
|
+
const path = qs ? `${base}?${qs}` : base;
|
|
494
|
+
return requestJson<MonitoringTraceSummariesResponse>(
|
|
495
|
+
this.chatBaseUrl,
|
|
496
|
+
path,
|
|
497
|
+
this.sessionToken,
|
|
498
|
+
{ signal: options.signal },
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Fetch the full segment documents for ONE X-Ray trace (for the waterfall
|
|
504
|
+
* view). `found=false` (with empty `segments`) when X-Ray has no such trace.
|
|
505
|
+
*/
|
|
506
|
+
async getTraceDetail(
|
|
507
|
+
xrayTraceId: string,
|
|
508
|
+
options: { signal?: AbortSignal } = {},
|
|
509
|
+
): Promise<MonitoringTraceDetailResponse> {
|
|
510
|
+
return requestJson<MonitoringTraceDetailResponse>(
|
|
511
|
+
this.chatBaseUrl,
|
|
512
|
+
`${ADMIN_MONITORING_PATH}/traces/${encodeURIComponent(xrayTraceId)}`,
|
|
513
|
+
this.sessionToken,
|
|
514
|
+
{ signal: options.signal },
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
}
|