@keelapi/sdk 0.1.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/LICENSE +21 -0
- package/README.md +196 -0
- package/dist/examples/express.d.ts +1 -0
- package/dist/examples/express.js +33 -0
- package/dist/examples/next-route.d.ts +6 -0
- package/dist/examples/next-route.js +29 -0
- package/dist/examples/permit.d.ts +1 -0
- package/dist/examples/permit.js +49 -0
- package/dist/src/client.d.ts +28 -0
- package/dist/src/client.js +48 -0
- package/dist/src/clients/execute.d.ts +8 -0
- package/dist/src/clients/execute.js +15 -0
- package/dist/src/clients/executions.d.ts +9 -0
- package/dist/src/clients/executions.js +22 -0
- package/dist/src/clients/jobs.d.ts +8 -0
- package/dist/src/clients/jobs.js +15 -0
- package/dist/src/clients/permits.d.ts +18 -0
- package/dist/src/clients/permits.js +72 -0
- package/dist/src/clients/proxy.d.ts +10 -0
- package/dist/src/clients/proxy.js +24 -0
- package/dist/src/clients/requests.d.ts +7 -0
- package/dist/src/clients/requests.js +12 -0
- package/dist/src/errors.d.ts +7 -0
- package/dist/src/errors.js +14 -0
- package/dist/src/http.d.ts +48 -0
- package/dist/src/http.js +303 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.js +25 -0
- package/dist/src/middleware/express.d.ts +4 -0
- package/dist/src/middleware/express.js +26 -0
- package/dist/src/middleware/next.d.ts +10 -0
- package/dist/src/middleware/next.js +26 -0
- package/dist/src/middleware/shared.d.ts +40 -0
- package/dist/src/middleware/shared.js +122 -0
- package/dist/src/streaming.d.ts +2 -0
- package/dist/src/streaming.js +82 -0
- package/dist/src/types.d.ts +622 -0
- package/dist/src/types.js +5 -0
- package/package.json +41 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseSSEStream = parseSSEStream;
|
|
4
|
+
async function* parseSSEStream(response) {
|
|
5
|
+
const reader = response.body?.getReader();
|
|
6
|
+
if (!reader) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const decoder = new TextDecoder();
|
|
10
|
+
let buffer = "";
|
|
11
|
+
let currentEvent = "message";
|
|
12
|
+
let dataLines = [];
|
|
13
|
+
try {
|
|
14
|
+
while (true) {
|
|
15
|
+
const { done, value } = await reader.read();
|
|
16
|
+
if (done)
|
|
17
|
+
break;
|
|
18
|
+
buffer += decoder.decode(value, { stream: true });
|
|
19
|
+
const lines = buffer.split("\n");
|
|
20
|
+
buffer = lines.pop() ?? "";
|
|
21
|
+
for (const rawLine of lines) {
|
|
22
|
+
const line = rawLine.replace(/\r$/, "");
|
|
23
|
+
if (line === "") {
|
|
24
|
+
if (dataLines.length > 0) {
|
|
25
|
+
const sse = {
|
|
26
|
+
event: currentEvent,
|
|
27
|
+
data: dataLines.join("\n"),
|
|
28
|
+
};
|
|
29
|
+
yield decodeSSEEvent(sse);
|
|
30
|
+
dataLines = [];
|
|
31
|
+
currentEvent = "message";
|
|
32
|
+
}
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (line.startsWith(":")) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (line.startsWith("event:")) {
|
|
39
|
+
currentEvent = line.slice(6).trimStart();
|
|
40
|
+
}
|
|
41
|
+
else if (line.startsWith("data:")) {
|
|
42
|
+
dataLines.push(line.slice(5).trimStart());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (dataLines.length > 0) {
|
|
47
|
+
const sse = {
|
|
48
|
+
event: currentEvent,
|
|
49
|
+
data: dataLines.join("\n"),
|
|
50
|
+
};
|
|
51
|
+
yield decodeSSEEvent(sse);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
reader.releaseLock();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function decodeSSEEvent(sse) {
|
|
59
|
+
let data;
|
|
60
|
+
try {
|
|
61
|
+
data = JSON.parse(sse.data);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return { event: sse.event, data: sse.data };
|
|
65
|
+
}
|
|
66
|
+
switch (sse.event) {
|
|
67
|
+
case "execution.started":
|
|
68
|
+
return { event: "execution.started", data };
|
|
69
|
+
case "content.delta":
|
|
70
|
+
return { event: "content.delta", data };
|
|
71
|
+
case "execution.completed":
|
|
72
|
+
return { event: "execution.completed", data };
|
|
73
|
+
case "execution.denied":
|
|
74
|
+
return { event: "execution.denied", data };
|
|
75
|
+
case "execution.error":
|
|
76
|
+
return { event: "execution.error", data };
|
|
77
|
+
case "done":
|
|
78
|
+
return { event: "done", data };
|
|
79
|
+
default:
|
|
80
|
+
return { event: sse.event, data };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
export type Decision = "allow" | "deny" | "challenge";
|
|
2
|
+
export type ExecutionOperation = "generate.text" | "embed.text" | "generate.image" | "edit.image" | "understand.image" | "generate.audio" | "transcribe.audio" | "generate.video" | "understand.video" | "run.batch" | "run.async" | "realtime.session" | "call.tools";
|
|
3
|
+
export type ExecutionMode = "sync" | "stream";
|
|
4
|
+
export type ExecutionRole = "system" | "user" | "assistant";
|
|
5
|
+
export type ExecutionAssetSource = "url" | "upload" | "base64" | "asset_ref";
|
|
6
|
+
export type ExecutionInputType = "text" | "json" | "image" | "audio" | "video" | "file" | "binary";
|
|
7
|
+
export type RoutingProvider = "openai" | "anthropic" | "google" | "xai" | "meta";
|
|
8
|
+
export type RoutingPriority = "cheap" | "balanced" | "quality";
|
|
9
|
+
export type RoutingReasonCode = "explicit_request" | "policy_preference" | "cost_optimization" | "quality_preference" | "routing_fitness" | "fallback_after_error";
|
|
10
|
+
export type JobStatus = "submitted" | "queued" | "processing" | "completed" | "failed";
|
|
11
|
+
export type PermitExportFormat = "json" | "csv";
|
|
12
|
+
export type PermitDryRunReplayOutcome = "fresh" | "would_reuse_existing" | "would_revalidate_existing" | "would_expire_existing";
|
|
13
|
+
export type ConditionMatch = "all" | "any";
|
|
14
|
+
export type ConditionOutcome = "allow" | "deny" | "indeterminate";
|
|
15
|
+
export interface Subject {
|
|
16
|
+
type: string;
|
|
17
|
+
id: string;
|
|
18
|
+
attributes?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface Action {
|
|
21
|
+
name: string;
|
|
22
|
+
attributes?: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
export interface InputDescriptor {
|
|
25
|
+
type: string;
|
|
26
|
+
source?: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
filename?: string;
|
|
29
|
+
mime_type?: string;
|
|
30
|
+
size_bytes?: number;
|
|
31
|
+
sha256?: string;
|
|
32
|
+
asset_id?: string;
|
|
33
|
+
base64_data?: string;
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
export interface ResourceAttributes {
|
|
37
|
+
provider: string;
|
|
38
|
+
model: string;
|
|
39
|
+
estimated_input_tokens: number;
|
|
40
|
+
estimated_output_tokens: number;
|
|
41
|
+
max_output_tokens_requested?: number | null;
|
|
42
|
+
operation?: string;
|
|
43
|
+
modality?: string;
|
|
44
|
+
execution_mode?: "sync" | "async";
|
|
45
|
+
inputs?: InputDescriptor[];
|
|
46
|
+
routing?: Record<string, unknown>;
|
|
47
|
+
callback_url?: string;
|
|
48
|
+
asset_summary?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
export interface Resource {
|
|
51
|
+
type: string;
|
|
52
|
+
id: string;
|
|
53
|
+
attributes: ResourceAttributes;
|
|
54
|
+
}
|
|
55
|
+
export interface PermitConditionRule {
|
|
56
|
+
field: string;
|
|
57
|
+
operator: string;
|
|
58
|
+
value?: unknown;
|
|
59
|
+
}
|
|
60
|
+
export interface PermitConditions {
|
|
61
|
+
match: ConditionMatch;
|
|
62
|
+
rules: PermitConditionRule[];
|
|
63
|
+
}
|
|
64
|
+
export interface PermitRequest {
|
|
65
|
+
project_id: string;
|
|
66
|
+
idempotency_key: string;
|
|
67
|
+
session_id?: string | null;
|
|
68
|
+
subject: Subject;
|
|
69
|
+
action: Action;
|
|
70
|
+
resource: Resource;
|
|
71
|
+
context?: Record<string, unknown> | null;
|
|
72
|
+
parent_permit_id?: string | null;
|
|
73
|
+
budget_envelope_id?: string | null;
|
|
74
|
+
conditions?: PermitConditions | null;
|
|
75
|
+
}
|
|
76
|
+
export interface ActionMessage {
|
|
77
|
+
type: string;
|
|
78
|
+
message: string;
|
|
79
|
+
}
|
|
80
|
+
export interface Metadata {
|
|
81
|
+
policy_id: string;
|
|
82
|
+
policy_version: string;
|
|
83
|
+
evaluated_at: string;
|
|
84
|
+
subject?: {
|
|
85
|
+
type: string;
|
|
86
|
+
id: string;
|
|
87
|
+
} | null;
|
|
88
|
+
action?: {
|
|
89
|
+
name: string;
|
|
90
|
+
} | null;
|
|
91
|
+
session_id?: string | null;
|
|
92
|
+
}
|
|
93
|
+
export interface DecisionDetails {
|
|
94
|
+
decision: string;
|
|
95
|
+
code: string;
|
|
96
|
+
reason: string;
|
|
97
|
+
[key: string]: unknown;
|
|
98
|
+
}
|
|
99
|
+
export interface RoutingTarget {
|
|
100
|
+
provider: RoutingProvider;
|
|
101
|
+
model: string;
|
|
102
|
+
}
|
|
103
|
+
export interface RoutingDecision {
|
|
104
|
+
decision_id: string;
|
|
105
|
+
decided_at: string;
|
|
106
|
+
requested_provider: RoutingProvider;
|
|
107
|
+
requested_model: string;
|
|
108
|
+
selected_provider: RoutingProvider;
|
|
109
|
+
selected_model: string;
|
|
110
|
+
reason_code: RoutingReasonCode;
|
|
111
|
+
fallback_occurred: boolean;
|
|
112
|
+
policy_id?: string | null;
|
|
113
|
+
policy_version?: string | null;
|
|
114
|
+
estimated_cost_usd_micros?: number | null;
|
|
115
|
+
priority?: RoutingPriority | null;
|
|
116
|
+
task_type?: string | null;
|
|
117
|
+
latency_target_ms?: number | null;
|
|
118
|
+
fallback_chain?: RoutingTarget[];
|
|
119
|
+
reason_metadata?: Record<string, unknown> | null;
|
|
120
|
+
}
|
|
121
|
+
export interface PermitResponse {
|
|
122
|
+
permit_id: string;
|
|
123
|
+
project_id: string;
|
|
124
|
+
decision: Decision;
|
|
125
|
+
reason: string;
|
|
126
|
+
constraints?: Record<string, unknown> | null;
|
|
127
|
+
budgets?: Record<string, unknown> | null;
|
|
128
|
+
actions: ActionMessage[];
|
|
129
|
+
metadata: Metadata;
|
|
130
|
+
parent_permit_id?: string | null;
|
|
131
|
+
delegation_depth?: number;
|
|
132
|
+
status?: string | null;
|
|
133
|
+
decision_details?: DecisionDetails | null;
|
|
134
|
+
routing?: RoutingDecision | null;
|
|
135
|
+
}
|
|
136
|
+
export interface PermitWithMetaResponse {
|
|
137
|
+
permit: PermitResponse;
|
|
138
|
+
request_id?: string;
|
|
139
|
+
}
|
|
140
|
+
export interface BudgetEnvelopeSummary {
|
|
141
|
+
envelope_id: string;
|
|
142
|
+
reservation_status?: string | null;
|
|
143
|
+
estimated_cost_usd_micros?: number | null;
|
|
144
|
+
total_budget_usd_micros?: number | null;
|
|
145
|
+
reserved_budget_usd_micros?: number | null;
|
|
146
|
+
spent_budget_usd_micros?: number | null;
|
|
147
|
+
remaining_budget_usd_micros?: number | null;
|
|
148
|
+
correction_usd_micros?: number | null;
|
|
149
|
+
}
|
|
150
|
+
export interface ConditionEvaluation {
|
|
151
|
+
outcome: ConditionOutcome;
|
|
152
|
+
evaluated_at: string;
|
|
153
|
+
match: ConditionMatch;
|
|
154
|
+
rule_count: number;
|
|
155
|
+
failed_rule_index?: number | null;
|
|
156
|
+
code?: string | null;
|
|
157
|
+
message?: string | null;
|
|
158
|
+
field?: string | null;
|
|
159
|
+
operator?: string | null;
|
|
160
|
+
expected_value?: unknown;
|
|
161
|
+
actual_value?: unknown;
|
|
162
|
+
}
|
|
163
|
+
export interface PermitDryRunResponse {
|
|
164
|
+
dry_run: true;
|
|
165
|
+
project_id: string;
|
|
166
|
+
existing_permit_id?: string | null;
|
|
167
|
+
replay_outcome: PermitDryRunReplayOutcome;
|
|
168
|
+
parent_permit_id?: string | null;
|
|
169
|
+
delegation_depth?: number;
|
|
170
|
+
decision: Decision;
|
|
171
|
+
reason: string;
|
|
172
|
+
status?: string | null;
|
|
173
|
+
constraints?: Record<string, unknown> | null;
|
|
174
|
+
budgets?: Record<string, unknown> | null;
|
|
175
|
+
actions: ActionMessage[];
|
|
176
|
+
decision_details?: DecisionDetails | null;
|
|
177
|
+
routing?: RoutingDecision | null;
|
|
178
|
+
metadata: Metadata;
|
|
179
|
+
budget_envelope?: BudgetEnvelopeSummary | null;
|
|
180
|
+
condition_evaluation?: ConditionEvaluation | null;
|
|
181
|
+
}
|
|
182
|
+
export interface PermitAuditItem {
|
|
183
|
+
id: string;
|
|
184
|
+
project_id: string;
|
|
185
|
+
parent_permit_id?: string | null;
|
|
186
|
+
delegation_depth?: number;
|
|
187
|
+
subject_type: string;
|
|
188
|
+
subject_id: string;
|
|
189
|
+
action_name: string;
|
|
190
|
+
resource_provider: string;
|
|
191
|
+
resource_model: string;
|
|
192
|
+
resource_operation?: string | null;
|
|
193
|
+
resource_modality?: string | null;
|
|
194
|
+
resource_inputs_json?: Array<Record<string, unknown>> | null;
|
|
195
|
+
resource_attributes_json?: Record<string, unknown> | null;
|
|
196
|
+
estimated_input_tokens: number;
|
|
197
|
+
estimated_output_tokens: number;
|
|
198
|
+
max_output_tokens_requested?: number | null;
|
|
199
|
+
decision: Decision;
|
|
200
|
+
reason: string;
|
|
201
|
+
status?: string | null;
|
|
202
|
+
constraints_json?: Record<string, unknown> | null;
|
|
203
|
+
budgets_json?: Record<string, unknown> | null;
|
|
204
|
+
budget_envelope?: BudgetEnvelopeSummary | null;
|
|
205
|
+
actions_json: Array<Record<string, unknown>>;
|
|
206
|
+
conditions?: PermitConditions | null;
|
|
207
|
+
condition_evaluation?: ConditionEvaluation | null;
|
|
208
|
+
decision_details?: DecisionDetails | null;
|
|
209
|
+
routing?: RoutingDecision | null;
|
|
210
|
+
actual_usage_json?: Record<string, unknown> | null;
|
|
211
|
+
policy_id: string;
|
|
212
|
+
policy_version: string;
|
|
213
|
+
metadata: Metadata;
|
|
214
|
+
idempotency_key: string;
|
|
215
|
+
request_fingerprint: string;
|
|
216
|
+
expires_at?: string | null;
|
|
217
|
+
created_at: string;
|
|
218
|
+
}
|
|
219
|
+
export interface PermitAuditListResponse {
|
|
220
|
+
items: PermitAuditItem[];
|
|
221
|
+
next_cursor: string | null;
|
|
222
|
+
}
|
|
223
|
+
export interface PermitListParams {
|
|
224
|
+
limit?: number;
|
|
225
|
+
project_id?: string;
|
|
226
|
+
before?: string;
|
|
227
|
+
subject_id?: string;
|
|
228
|
+
subject_type?: string;
|
|
229
|
+
action_name?: string;
|
|
230
|
+
start_date?: string;
|
|
231
|
+
end_date?: string;
|
|
232
|
+
decision?: Decision;
|
|
233
|
+
}
|
|
234
|
+
export interface PermitUsageReportRequest {
|
|
235
|
+
provider?: string | null;
|
|
236
|
+
model?: string | null;
|
|
237
|
+
actual_input_tokens?: number | null;
|
|
238
|
+
actual_output_tokens?: number | null;
|
|
239
|
+
actual_total_tokens?: number | null;
|
|
240
|
+
cost_usd?: string | number | null;
|
|
241
|
+
cost_usd_micros?: number | null;
|
|
242
|
+
usage_idempotency_key?: string | null;
|
|
243
|
+
normalized_usage?: Record<string, number> | null;
|
|
244
|
+
usage_metrics?: Array<Record<string, unknown>> | null;
|
|
245
|
+
metadata?: Record<string, unknown> | null;
|
|
246
|
+
}
|
|
247
|
+
export interface PermitUsageReportResponse {
|
|
248
|
+
permit_id: string;
|
|
249
|
+
project_id: string;
|
|
250
|
+
usage_reported_at?: string | null;
|
|
251
|
+
actual_input_tokens?: number | null;
|
|
252
|
+
actual_output_tokens?: number | null;
|
|
253
|
+
actual_total_tokens?: number | null;
|
|
254
|
+
actual_cost_usd_micros?: number | null;
|
|
255
|
+
actual_usage_json?: Record<string, unknown> | null;
|
|
256
|
+
status?: string | null;
|
|
257
|
+
}
|
|
258
|
+
export interface PermitAttestationRequest {
|
|
259
|
+
attestor: string;
|
|
260
|
+
attestation_type: "approve" | "reject";
|
|
261
|
+
evidence_url?: string | null;
|
|
262
|
+
}
|
|
263
|
+
export interface PermitAttestationOut {
|
|
264
|
+
id: string;
|
|
265
|
+
permit_id: string;
|
|
266
|
+
project_id: string;
|
|
267
|
+
attestor: string;
|
|
268
|
+
attestation_type: "approve" | "reject";
|
|
269
|
+
evidence_url?: string | null;
|
|
270
|
+
attested_at: string;
|
|
271
|
+
created_at: string;
|
|
272
|
+
}
|
|
273
|
+
export interface PermitAttestResponse {
|
|
274
|
+
permit: PermitResponse;
|
|
275
|
+
attestation: PermitAttestationOut;
|
|
276
|
+
}
|
|
277
|
+
export interface PermitEvidenceCreateRequest {
|
|
278
|
+
evidence_type: string;
|
|
279
|
+
evidence_value: string;
|
|
280
|
+
label: string;
|
|
281
|
+
attached_by: string;
|
|
282
|
+
}
|
|
283
|
+
export interface PermitEvidenceOut {
|
|
284
|
+
id: string;
|
|
285
|
+
permit_id: string;
|
|
286
|
+
project_id: string;
|
|
287
|
+
evidence_type: string;
|
|
288
|
+
evidence_value: string;
|
|
289
|
+
label: string;
|
|
290
|
+
attached_by: string;
|
|
291
|
+
attached_at: string;
|
|
292
|
+
}
|
|
293
|
+
export interface PermitEvidenceListResponse {
|
|
294
|
+
items: PermitEvidenceOut[];
|
|
295
|
+
}
|
|
296
|
+
export interface PermitLineageNodeSummary {
|
|
297
|
+
permit_id: string;
|
|
298
|
+
parent_permit_id?: string | null;
|
|
299
|
+
delegation_depth: number;
|
|
300
|
+
decision: Decision;
|
|
301
|
+
status?: string | null;
|
|
302
|
+
reason: string;
|
|
303
|
+
action_name: string;
|
|
304
|
+
resource_provider: string;
|
|
305
|
+
resource_model: string;
|
|
306
|
+
created_at: string;
|
|
307
|
+
expires_at?: string | null;
|
|
308
|
+
usage_reported_at?: string | null;
|
|
309
|
+
actual_total_tokens?: number | null;
|
|
310
|
+
actual_cost_usd_micros?: number | null;
|
|
311
|
+
}
|
|
312
|
+
export interface PermitLineageNode extends PermitLineageNodeSummary {
|
|
313
|
+
children: PermitLineageNode[];
|
|
314
|
+
}
|
|
315
|
+
export interface PermitLineageResponse {
|
|
316
|
+
project_id: string;
|
|
317
|
+
root_permit_id: string;
|
|
318
|
+
current_permit_id: string;
|
|
319
|
+
parent?: PermitLineageNodeSummary | null;
|
|
320
|
+
ancestors: PermitLineageNodeSummary[];
|
|
321
|
+
current: PermitLineageNode;
|
|
322
|
+
}
|
|
323
|
+
export interface PermitAuditBundle {
|
|
324
|
+
bundle_type: "permit_audit_bundle";
|
|
325
|
+
schema_version: number;
|
|
326
|
+
format: "json";
|
|
327
|
+
project_id: string;
|
|
328
|
+
permit_id: string;
|
|
329
|
+
generated_at: string;
|
|
330
|
+
record: Record<string, unknown>;
|
|
331
|
+
governance_events: Array<Record<string, unknown>>;
|
|
332
|
+
}
|
|
333
|
+
export interface ApiKey {
|
|
334
|
+
id: string;
|
|
335
|
+
project_id: string;
|
|
336
|
+
prefix: string;
|
|
337
|
+
created_at: string;
|
|
338
|
+
revoked_at: string | null;
|
|
339
|
+
}
|
|
340
|
+
export interface CreateApiKeyResponse extends ApiKey {
|
|
341
|
+
raw_key: string;
|
|
342
|
+
request_id?: string;
|
|
343
|
+
}
|
|
344
|
+
export interface ListApiKeysResponse {
|
|
345
|
+
items: ApiKey[];
|
|
346
|
+
request_id?: string;
|
|
347
|
+
}
|
|
348
|
+
export interface RevokeApiKeyResponse extends ApiKey {
|
|
349
|
+
request_id?: string;
|
|
350
|
+
}
|
|
351
|
+
export interface HealthResponse {
|
|
352
|
+
status: "ok";
|
|
353
|
+
request_id?: string;
|
|
354
|
+
}
|
|
355
|
+
export interface AuthedHealthResponse extends HealthResponse {
|
|
356
|
+
project_id: string;
|
|
357
|
+
}
|
|
358
|
+
export interface ExecutionMessage {
|
|
359
|
+
role: ExecutionRole;
|
|
360
|
+
content: string;
|
|
361
|
+
}
|
|
362
|
+
export interface ExecutionAssetInput {
|
|
363
|
+
source: ExecutionAssetSource;
|
|
364
|
+
url?: string;
|
|
365
|
+
asset_id?: string;
|
|
366
|
+
base64?: string;
|
|
367
|
+
mime_type?: string;
|
|
368
|
+
filename?: string;
|
|
369
|
+
size_bytes?: number;
|
|
370
|
+
metadata?: Record<string, unknown>;
|
|
371
|
+
}
|
|
372
|
+
export interface ExecutionInputPart {
|
|
373
|
+
type: ExecutionInputType;
|
|
374
|
+
role?: ExecutionRole;
|
|
375
|
+
text?: string;
|
|
376
|
+
json?: Record<string, unknown>;
|
|
377
|
+
asset?: ExecutionAssetInput;
|
|
378
|
+
metadata?: Record<string, unknown>;
|
|
379
|
+
}
|
|
380
|
+
export interface ExecutionRoutingTarget {
|
|
381
|
+
provider: RoutingProvider;
|
|
382
|
+
model: string;
|
|
383
|
+
}
|
|
384
|
+
export interface ExecutionRoutingInput {
|
|
385
|
+
provider?: RoutingProvider;
|
|
386
|
+
model?: string;
|
|
387
|
+
priority?: RoutingPriority;
|
|
388
|
+
task_type?: string;
|
|
389
|
+
latency_target_ms?: number;
|
|
390
|
+
allow_cross_provider_fallback?: boolean;
|
|
391
|
+
fallback_chain?: ExecutionRoutingTarget[];
|
|
392
|
+
}
|
|
393
|
+
export interface ExecutionParametersInput {
|
|
394
|
+
max_output_tokens?: number;
|
|
395
|
+
temperature?: number;
|
|
396
|
+
top_p?: number;
|
|
397
|
+
}
|
|
398
|
+
export type ExecutionProviderOptions = Partial<Record<RoutingProvider, Record<string, unknown>>>;
|
|
399
|
+
export interface ExecutionCreateRequest {
|
|
400
|
+
operation: ExecutionOperation;
|
|
401
|
+
mode?: ExecutionMode;
|
|
402
|
+
messages?: ExecutionMessage[];
|
|
403
|
+
inputs?: ExecutionInputPart[];
|
|
404
|
+
routing?: ExecutionRoutingInput;
|
|
405
|
+
parameters?: ExecutionParametersInput;
|
|
406
|
+
provider_options?: ExecutionProviderOptions;
|
|
407
|
+
}
|
|
408
|
+
export interface ExecuteRequest {
|
|
409
|
+
provider?: RoutingProvider;
|
|
410
|
+
model: string;
|
|
411
|
+
input: Record<string, unknown>;
|
|
412
|
+
}
|
|
413
|
+
export interface ExecutionOutputContentPart {
|
|
414
|
+
type: string;
|
|
415
|
+
role?: string;
|
|
416
|
+
text?: string;
|
|
417
|
+
[key: string]: unknown;
|
|
418
|
+
}
|
|
419
|
+
export interface ExecutionOutput {
|
|
420
|
+
content?: ExecutionOutputContentPart[];
|
|
421
|
+
embeddings?: unknown[];
|
|
422
|
+
raw?: Record<string, unknown>;
|
|
423
|
+
}
|
|
424
|
+
export interface ExecutionOutputAsset {
|
|
425
|
+
asset_id: string;
|
|
426
|
+
type: string;
|
|
427
|
+
mime_type: string;
|
|
428
|
+
size_bytes?: number | null;
|
|
429
|
+
uri?: string | null;
|
|
430
|
+
status?: string | null;
|
|
431
|
+
metadata?: Record<string, unknown>;
|
|
432
|
+
}
|
|
433
|
+
export interface ExecutionRoutingResult {
|
|
434
|
+
requested_provider?: RoutingProvider | null;
|
|
435
|
+
requested_model?: string | null;
|
|
436
|
+
selected_provider: RoutingProvider;
|
|
437
|
+
selected_model: string;
|
|
438
|
+
reason_code: string;
|
|
439
|
+
fallback_occurred: boolean;
|
|
440
|
+
}
|
|
441
|
+
export interface ExecutionGovernance {
|
|
442
|
+
decision: Decision;
|
|
443
|
+
reason: string;
|
|
444
|
+
actions: ActionMessage[];
|
|
445
|
+
constraints?: Record<string, unknown> | null;
|
|
446
|
+
budgets?: Record<string, unknown> | null;
|
|
447
|
+
}
|
|
448
|
+
export interface ExecutionUsage {
|
|
449
|
+
input_tokens?: number | null;
|
|
450
|
+
output_tokens?: number | null;
|
|
451
|
+
total_tokens?: number | null;
|
|
452
|
+
cost_usd_micros?: number | null;
|
|
453
|
+
estimated_final?: boolean;
|
|
454
|
+
metrics?: Array<Record<string, unknown>> | null;
|
|
455
|
+
}
|
|
456
|
+
export interface ExecutionTiming {
|
|
457
|
+
started_at?: string | null;
|
|
458
|
+
completed_at?: string | null;
|
|
459
|
+
duration_ms?: number | null;
|
|
460
|
+
}
|
|
461
|
+
export interface ExecutionErrorPayload {
|
|
462
|
+
stage?: string;
|
|
463
|
+
code: string;
|
|
464
|
+
message: string;
|
|
465
|
+
details?: Record<string, unknown> | null;
|
|
466
|
+
retry_class?: string | null;
|
|
467
|
+
status_code?: number | null;
|
|
468
|
+
}
|
|
469
|
+
export interface ExecutionResolved {
|
|
470
|
+
provider?: string;
|
|
471
|
+
model?: string;
|
|
472
|
+
}
|
|
473
|
+
export interface ExecutionResponse {
|
|
474
|
+
id: string;
|
|
475
|
+
object: "execution";
|
|
476
|
+
created_at: string | null;
|
|
477
|
+
status: "completed" | "in_progress" | "failed" | "denied";
|
|
478
|
+
status_code: number;
|
|
479
|
+
output?: ExecutionOutput | null;
|
|
480
|
+
output_assets: ExecutionOutputAsset[];
|
|
481
|
+
routing: ExecutionRoutingResult;
|
|
482
|
+
governance?: ExecutionGovernance | null;
|
|
483
|
+
usage?: ExecutionUsage | null;
|
|
484
|
+
timing: ExecutionTiming;
|
|
485
|
+
error?: ExecutionErrorPayload | null;
|
|
486
|
+
resolved?: ExecutionResolved | null;
|
|
487
|
+
}
|
|
488
|
+
export type ExecutionStreamEventName = "execution.started" | "content.delta" | "execution.completed" | "execution.denied" | "execution.error" | "done";
|
|
489
|
+
export interface ExecutionStartedEvent {
|
|
490
|
+
event: "execution.started";
|
|
491
|
+
data: {
|
|
492
|
+
id: string;
|
|
493
|
+
object: "execution";
|
|
494
|
+
created_at: string | null;
|
|
495
|
+
status: string;
|
|
496
|
+
status_code: number;
|
|
497
|
+
routing?: ExecutionRoutingResult | null;
|
|
498
|
+
governance?: ExecutionGovernance | null;
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
export interface ExecutionContentDelta {
|
|
502
|
+
event: "content.delta";
|
|
503
|
+
data: {
|
|
504
|
+
id: string;
|
|
505
|
+
object: "execution";
|
|
506
|
+
created_at: string | null;
|
|
507
|
+
delta: {
|
|
508
|
+
type: string;
|
|
509
|
+
text?: string;
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
export interface ExecutionCompletedEvent {
|
|
514
|
+
event: "execution.completed";
|
|
515
|
+
data: ExecutionResponse;
|
|
516
|
+
}
|
|
517
|
+
export interface ExecutionDeniedEvent {
|
|
518
|
+
event: "execution.denied";
|
|
519
|
+
data: ExecutionResponse;
|
|
520
|
+
}
|
|
521
|
+
export interface ExecutionErrorEvent {
|
|
522
|
+
event: "execution.error";
|
|
523
|
+
data: ExecutionResponse;
|
|
524
|
+
}
|
|
525
|
+
export interface ExecutionDoneEvent {
|
|
526
|
+
event: "done";
|
|
527
|
+
data: {
|
|
528
|
+
id: string;
|
|
529
|
+
object: "execution";
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
export interface ExecutionRawEvent {
|
|
533
|
+
event: string;
|
|
534
|
+
data: unknown;
|
|
535
|
+
}
|
|
536
|
+
export type ExecutionStreamEvent = ExecutionStartedEvent | ExecutionContentDelta | ExecutionCompletedEvent | ExecutionDeniedEvent | ExecutionErrorEvent | ExecutionDoneEvent | ExecutionRawEvent;
|
|
537
|
+
export interface JobSubmitRequest {
|
|
538
|
+
permit: PermitRequest;
|
|
539
|
+
provider_payload?: Record<string, unknown>;
|
|
540
|
+
metadata?: Record<string, unknown>;
|
|
541
|
+
}
|
|
542
|
+
export interface JobCreateResponse {
|
|
543
|
+
job_id: string;
|
|
544
|
+
status: JobStatus;
|
|
545
|
+
execution_mode: "async";
|
|
546
|
+
submitted_at: string;
|
|
547
|
+
permit_id?: string | null;
|
|
548
|
+
}
|
|
549
|
+
export interface JobStatusResponse {
|
|
550
|
+
job_id: string;
|
|
551
|
+
request_id: string;
|
|
552
|
+
permit_id?: string | null;
|
|
553
|
+
provider: string;
|
|
554
|
+
model: string;
|
|
555
|
+
operation: string;
|
|
556
|
+
execution_mode: "async";
|
|
557
|
+
status: JobStatus;
|
|
558
|
+
progress?: number | null;
|
|
559
|
+
callback_url?: string | null;
|
|
560
|
+
submitted_at: string;
|
|
561
|
+
started_at?: string | null;
|
|
562
|
+
completed_at?: string | null;
|
|
563
|
+
result_assets?: Array<Record<string, unknown>> | null;
|
|
564
|
+
usage_metrics?: Array<Record<string, unknown>> | null;
|
|
565
|
+
error?: Record<string, unknown> | null;
|
|
566
|
+
metadata?: Record<string, unknown> | null;
|
|
567
|
+
}
|
|
568
|
+
export type RequestTimelineEventSource = "permits" | "usage_ledger" | "usage_logs" | "governed_requests" | "execution_events" | "async_jobs" | "realtime_sessions";
|
|
569
|
+
export type RequestTimelinePhase = "permit" | "routing" | "firewall" | "execution" | "provider" | "usage" | "request" | "job" | "session" | "webhook";
|
|
570
|
+
export interface RequestTimelineEvent {
|
|
571
|
+
timestamp: string;
|
|
572
|
+
event_type: string;
|
|
573
|
+
source: RequestTimelineEventSource;
|
|
574
|
+
phase: RequestTimelinePhase;
|
|
575
|
+
provider?: string | null;
|
|
576
|
+
model?: string | null;
|
|
577
|
+
permit_id?: string | null;
|
|
578
|
+
request_id?: string | null;
|
|
579
|
+
job_id?: string | null;
|
|
580
|
+
session_id?: string | null;
|
|
581
|
+
metadata?: Record<string, unknown> | null;
|
|
582
|
+
}
|
|
583
|
+
export interface RequestTimelineResponse {
|
|
584
|
+
project_id: string;
|
|
585
|
+
request_id: string;
|
|
586
|
+
permit_ids: string[];
|
|
587
|
+
job_ids: string[];
|
|
588
|
+
session_ids: string[];
|
|
589
|
+
events: RequestTimelineEvent[];
|
|
590
|
+
}
|
|
591
|
+
export interface ExecutionTimelinePermit {
|
|
592
|
+
decision?: string | null;
|
|
593
|
+
timestamp?: string | null;
|
|
594
|
+
}
|
|
595
|
+
export interface ExecutionTimelineRouting {
|
|
596
|
+
provider?: string | null;
|
|
597
|
+
model?: string | null;
|
|
598
|
+
fallback_chain?: RoutingTarget[] | null;
|
|
599
|
+
}
|
|
600
|
+
export interface ExecutionTimelineQueue {
|
|
601
|
+
job_id?: string | null;
|
|
602
|
+
status?: string | null;
|
|
603
|
+
attempts?: number | null;
|
|
604
|
+
}
|
|
605
|
+
export interface ExecutionTimelineExecution {
|
|
606
|
+
started_at?: string | null;
|
|
607
|
+
completed_at?: string | null;
|
|
608
|
+
latency_ms?: number | null;
|
|
609
|
+
}
|
|
610
|
+
export interface ExecutionTimelineUsage {
|
|
611
|
+
input_tokens?: number | null;
|
|
612
|
+
output_tokens?: number | null;
|
|
613
|
+
cost_usd?: number | null;
|
|
614
|
+
}
|
|
615
|
+
export interface ExecutionTimelineResponse {
|
|
616
|
+
request_id: string;
|
|
617
|
+
permit: ExecutionTimelinePermit;
|
|
618
|
+
routing: ExecutionTimelineRouting;
|
|
619
|
+
queue: ExecutionTimelineQueue;
|
|
620
|
+
execution: ExecutionTimelineExecution;
|
|
621
|
+
usage: ExecutionTimelineUsage;
|
|
622
|
+
}
|