@lionhummer/constellation 0.6.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +327 -160
- package/dist/index.js +443 -281
- package/dist/types/client-core/src/agent.d.ts +81 -0
- package/dist/types/client-core/src/index.d.ts +102 -131
- package/dist/types/client-core/src/input-receiver.d.ts +24 -0
- package/dist/types/sdk/src/index.d.ts +5 -7
- package/examples/quickstart.mjs +3 -3
- package/package.json +2 -2
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type Admission, type AdmissionReceipt, type Json, type Log, type Message, type ModelCompletedEvent, type Observations, type RequestClient, type RequestInput, type Span, type WebhookEvent } from "./index";
|
|
2
|
+
/** Response-submission error codes that never succeed on retry. Generated from
|
|
3
|
+
* the server's error table and checked by its tests. */
|
|
4
|
+
export declare const PERMANENT_RESPONSE_CODES: ReadonlySet<string>;
|
|
5
|
+
export declare class PermanentEventError extends Error {
|
|
6
|
+
readonly status: number;
|
|
7
|
+
readonly code: string;
|
|
8
|
+
constructor(status: number, code: string, message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class HookConfigurationError extends PermanentEventError {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
/** Application-owned durable event checkpoints. All methods must survive process restart. */
|
|
14
|
+
export interface EventStore {
|
|
15
|
+
/** Atomically retain the event before processing it.
|
|
16
|
+
* Duplicate IDs must compare equal payloads. Resolve only after durable receipt. */
|
|
17
|
+
accept(event: WebhookEvent): Promise<void>;
|
|
18
|
+
/** Serialize processing per event. Return the saved response if present; otherwise
|
|
19
|
+
* run prepare and durably store its exact result before returning. A crash can
|
|
20
|
+
* rerun prepare: tool/billing effects must use the supplied stable identities. */
|
|
21
|
+
prepare(event: WebhookEvent, prepare: () => Promise<Admission | null>): Promise<Admission | null>;
|
|
22
|
+
/** Atomically mark the event processed after its saved response settled. `receipt.outcome` is
|
|
23
|
+
* `accepted`, `already_accepted` or `event_closed`; for `event_closed`, `receipt.observationsRecorded`
|
|
24
|
+
* says whether the continuation's telemetry was kept. `null` when no response was submitted. */
|
|
25
|
+
complete(eventId: string, receipt: AdmissionReceipt | null): Promise<void>;
|
|
26
|
+
/** Durably stop retries of a rejected saved response. Replays must rethrow this rejection. */
|
|
27
|
+
reject(eventId: string, error: PermanentEventError): Promise<void>;
|
|
28
|
+
/** Persist retry count, first/last failure timestamps and latest error in the existing inbox. Non-HTTP failures use status 0; alert on age/repeated failures.
|
|
29
|
+
* If this hook throws, processEvent still rethrows the original failure, with the hook error as its `retryHookError` property. */
|
|
30
|
+
retry?(eventId: string, error: {
|
|
31
|
+
status: number;
|
|
32
|
+
code: string;
|
|
33
|
+
message: string;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export declare class EventReceiver {
|
|
37
|
+
private readonly store;
|
|
38
|
+
constructor(store: EventStore);
|
|
39
|
+
/** Call after webhook authentication. Return a successful HTTP response only after this resolves. */
|
|
40
|
+
receive(event: WebhookEvent): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export declare class ClientTelemetry {
|
|
43
|
+
readonly parentSpanId?: string | undefined;
|
|
44
|
+
readonly spans: Span[];
|
|
45
|
+
readonly logs: Log[];
|
|
46
|
+
constructor(parentSpanId?: string | undefined);
|
|
47
|
+
log(level: Log["level"], message: string, attributes?: Record<string, Json>): void;
|
|
48
|
+
span<T>(name: string, attributes: Record<string, Json>, work: (telemetry: ClientTelemetry) => Promise<T>): Promise<T>;
|
|
49
|
+
snapshot(): Observations;
|
|
50
|
+
}
|
|
51
|
+
export type ToolResult = NonNullable<Message["toolResults"]>[number];
|
|
52
|
+
export type HookContext = {
|
|
53
|
+
event: WebhookEvent;
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
telemetry: ClientTelemetry;
|
|
56
|
+
};
|
|
57
|
+
export interface AgentHooks {
|
|
58
|
+
/** Required only when continuing. Returns the complete next model input. */
|
|
59
|
+
prepareRequest?: (context: HookContext & {
|
|
60
|
+
event: ModelCompletedEvent;
|
|
61
|
+
toolResults: ToolResult[];
|
|
62
|
+
}) => Promise<Omit<RequestInput, "idempotencyKey" | "inReplyTo" | "telemetry">>;
|
|
63
|
+
tools?: Record<string, (args: Json, context: HookContext & {
|
|
64
|
+
toolCallId: string;
|
|
65
|
+
effectId: string;
|
|
66
|
+
}) => Promise<Json>>;
|
|
67
|
+
/** Defaults to continue when tools were called, otherwise stop. Deduplicate business effects by event.id. */
|
|
68
|
+
onStepComplete?: (context: HookContext & {
|
|
69
|
+
event: ModelCompletedEvent;
|
|
70
|
+
toolResults: ToolResult[];
|
|
71
|
+
}) => Promise<"continue" | "stop">;
|
|
72
|
+
/** Return normally to record failure observations and stop; throw to leave the inbox item retryable. */
|
|
73
|
+
onError?: (error: unknown, context: HookContext) => Promise<void>;
|
|
74
|
+
toolConcurrency?: number;
|
|
75
|
+
}
|
|
76
|
+
/** Record the client processing interval and its actual child-span hierarchy. */
|
|
77
|
+
export declare function prepareResponse(event: WebhookEvent, hooks: AgentHooks, signal?: AbortSignal): Promise<Admission | null>;
|
|
78
|
+
/** Process an authenticated event using an application-owned durable checkpoint.
|
|
79
|
+
* Any receipt (`accepted`, `already_accepted`, `event_closed`) completes the checkpoint; a permanent
|
|
80
|
+
* error code rejects it with PermanentEventError; anything else reports through `store.retry` and throws. */
|
|
81
|
+
export declare function processEvent(client: RequestClient, store: EventStore, event: WebhookEvent, hooks: AgentHooks, signal?: AbortSignal): Promise<void>;
|
|
@@ -58,8 +58,13 @@ type RequestFields = {
|
|
|
58
58
|
/** Only headers approved by the selected provider are forwarded; others produce warnings. */
|
|
59
59
|
headers?: Record<string, string>;
|
|
60
60
|
nativeContentPolicy?: "require" | "omitCompleted" | "omitIncompatible";
|
|
61
|
-
maxSteps?: number;
|
|
62
61
|
timeoutMs?: number;
|
|
62
|
+
/** Optional per-provider limits. Omitted values use the request deadline; operator liveness watchdogs may be shorter. */
|
|
63
|
+
attemptTimeoutMs?: number;
|
|
64
|
+
firstByteTimeoutMs?: number;
|
|
65
|
+
idleTimeoutMs?: number;
|
|
66
|
+
/** Actual offering attempts, including preparation failures; default 32, maximum 256. */
|
|
67
|
+
maxProviderAttempts?: number;
|
|
63
68
|
maxOutputTokens?: number;
|
|
64
69
|
cache?: {
|
|
65
70
|
mode: "automatic" | "explicit";
|
|
@@ -80,20 +85,53 @@ type RequestFields = {
|
|
|
80
85
|
};
|
|
81
86
|
};
|
|
82
87
|
export type RequestEventModes = {
|
|
83
|
-
beforeModel?: "off" | "notify" | "wait";
|
|
84
|
-
afterModel?: "off" | "notify" | "wait";
|
|
85
|
-
afterStep?: "off" | "notify" | "wait";
|
|
86
|
-
outputDelta?: "off" | "notify";
|
|
87
88
|
terminal?: "off" | "notify";
|
|
88
89
|
};
|
|
89
90
|
/** One execution protocol; events determine where the caller participates. */
|
|
91
|
+
export type EventReference = {
|
|
92
|
+
requestId: string;
|
|
93
|
+
eventId: string;
|
|
94
|
+
};
|
|
95
|
+
export type Observations = {
|
|
96
|
+
spans?: Span[];
|
|
97
|
+
logs?: Log[];
|
|
98
|
+
};
|
|
90
99
|
export type RequestInput = RequestFields & {
|
|
91
100
|
events?: RequestEventModes;
|
|
101
|
+
inReplyTo?: EventReference;
|
|
102
|
+
telemetry?: Observations;
|
|
103
|
+
};
|
|
104
|
+
export type ObservationResponse = {
|
|
105
|
+
action: "observe";
|
|
106
|
+
idempotencyKey: string;
|
|
107
|
+
inReplyTo: EventReference;
|
|
108
|
+
telemetry: Observations;
|
|
109
|
+
error?: {
|
|
110
|
+
code: string;
|
|
111
|
+
message: string;
|
|
112
|
+
};
|
|
92
113
|
};
|
|
93
|
-
export type
|
|
114
|
+
export type Admission = RequestInput | ObservationResponse;
|
|
115
|
+
/** Event-response outcome. `accepted` committed this response; `already_accepted` is an identical retry;
|
|
116
|
+
* `event_closed` means the source event closed before this continuation (nothing was scheduled). */
|
|
117
|
+
export type ResponseOutcome = "accepted" | "already_accepted" | "event_closed";
|
|
118
|
+
export type AdmissionReceipt = {
|
|
119
|
+
id: string;
|
|
120
|
+
scheduled?: boolean;
|
|
121
|
+
/** Present on event responses (`inReplyTo`). */
|
|
122
|
+
outcome?: ResponseOutcome;
|
|
123
|
+
/** With `event_closed`: whether the continuation's telemetry was kept as late observations. */
|
|
124
|
+
observationsRecorded?: boolean;
|
|
125
|
+
};
|
|
126
|
+
export type Status = "queued" | "running" | "client_processing" | "completed" | "failed" | "cancelled";
|
|
94
127
|
export type RequestRecord = {
|
|
95
128
|
id: string;
|
|
96
129
|
externalId: string | null;
|
|
130
|
+
diagnostics?: {
|
|
131
|
+
omitted: boolean;
|
|
132
|
+
reason: string;
|
|
133
|
+
limitBytes?: number;
|
|
134
|
+
};
|
|
97
135
|
workspaceId: string;
|
|
98
136
|
userId: string | null;
|
|
99
137
|
requestedModel: string;
|
|
@@ -158,6 +196,8 @@ export type Attempt = {
|
|
|
158
196
|
committed: boolean;
|
|
159
197
|
supplierPrice: Json;
|
|
160
198
|
customerPrice: Json;
|
|
199
|
+
/** Captured supplier/customer pricing and realized accounting facts. */
|
|
200
|
+
billing?: Json;
|
|
161
201
|
parameters: Json;
|
|
162
202
|
usage: Json;
|
|
163
203
|
supplierCost: string | null;
|
|
@@ -174,49 +214,10 @@ export type Attempt = {
|
|
|
174
214
|
startedAt: string;
|
|
175
215
|
endedAt: string | null;
|
|
176
216
|
};
|
|
177
|
-
export type PreparedStep = {
|
|
178
|
-
model: string;
|
|
179
|
-
instructions: string;
|
|
180
|
-
messages: Message[];
|
|
181
|
-
tools: Tool[];
|
|
182
|
-
parameters: InferenceParameters;
|
|
183
|
-
optionalParameters?: string[];
|
|
184
|
-
/** Only headers approved by the selected provider are forwarded; others produce warnings. */
|
|
185
|
-
headers?: Record<string, string>;
|
|
186
|
-
nativeContentPolicy?: "require" | "omitCompleted" | "omitIncompatible";
|
|
187
|
-
maxOutputTokens: number;
|
|
188
|
-
cache: RequestInput["cache"] | null;
|
|
189
|
-
};
|
|
190
|
-
export type PendingInput = {
|
|
191
|
-
id: string;
|
|
192
|
-
requestId: string;
|
|
193
|
-
stepId: string | null;
|
|
194
|
-
kind: "tool" | "user_input" | "before_model" | "after_model" | "after_step";
|
|
195
|
-
payload: {
|
|
196
|
-
providerCallId?: string;
|
|
197
|
-
name?: string;
|
|
198
|
-
arguments?: Json;
|
|
199
|
-
validationError?: string | null;
|
|
200
|
-
toolCalls?: ToolCall[];
|
|
201
|
-
toolResults?: Message["toolResults"];
|
|
202
|
-
usage?: Json;
|
|
203
|
-
customerCost?: string | null;
|
|
204
|
-
supplierCost?: string | null;
|
|
205
|
-
customerPrice?: Json;
|
|
206
|
-
customerPricing?: CustomerPricing;
|
|
207
|
-
billing?: BillingFacts;
|
|
208
|
-
output?: Json;
|
|
209
|
-
};
|
|
210
|
-
claimId: string | null;
|
|
211
|
-
claimUntil?: string | null;
|
|
212
|
-
response: Json;
|
|
213
|
-
resolvedAt: string | null;
|
|
214
|
-
};
|
|
215
217
|
export type Span = {
|
|
216
218
|
id: string;
|
|
217
219
|
stepId?: string | null;
|
|
218
220
|
attemptId?: string | null;
|
|
219
|
-
inputId?: string | null;
|
|
220
221
|
parentSpanId?: string | null;
|
|
221
222
|
name: string;
|
|
222
223
|
startedAt: string;
|
|
@@ -240,7 +241,6 @@ export type TimelineRow = {
|
|
|
240
241
|
derivedFrom?: string[];
|
|
241
242
|
source?: "caller" | "constellation";
|
|
242
243
|
parentSpanId?: string | null;
|
|
243
|
-
inputId?: string | null;
|
|
244
244
|
stepId?: string | null;
|
|
245
245
|
attemptId?: string | null;
|
|
246
246
|
[key: string]: Json | undefined;
|
|
@@ -248,6 +248,7 @@ export type TimelineRow = {
|
|
|
248
248
|
export type Timeline = {
|
|
249
249
|
workspaceId: string;
|
|
250
250
|
externalId: string | null;
|
|
251
|
+
inReplyTo?: EventReference | null;
|
|
251
252
|
rows: TimelineRow[];
|
|
252
253
|
total: number;
|
|
253
254
|
offset: number;
|
|
@@ -273,52 +274,36 @@ export type Inspection = {
|
|
|
273
274
|
request: RequestRecord;
|
|
274
275
|
steps: Step[];
|
|
275
276
|
attempts: Attempt[];
|
|
276
|
-
inputs: PendingInput[];
|
|
277
277
|
spans: Span[];
|
|
278
278
|
logs: Log[];
|
|
279
279
|
};
|
|
280
280
|
export type RecordTypes = {
|
|
281
281
|
steps: Step;
|
|
282
282
|
attempts: Attempt;
|
|
283
|
-
inputs: PendingInput;
|
|
284
283
|
spans: Span;
|
|
285
284
|
logs: Log;
|
|
286
285
|
};
|
|
287
|
-
export type
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
};
|
|
294
|
-
export type
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}) => Promise<Json>>;
|
|
307
|
-
userInput?: (state: Inspection, context: {
|
|
308
|
-
inputId: string;
|
|
309
|
-
signal: AbortSignal;
|
|
310
|
-
}) => Promise<Json>;
|
|
311
|
-
signal?: AbortSignal;
|
|
312
|
-
consumerId?: string;
|
|
313
|
-
toolTimeoutMs?: number;
|
|
314
|
-
onUpdate?: (state: Inspection) => void;
|
|
315
|
-
};
|
|
316
|
-
export type RequestEvent = {
|
|
317
|
-
seq: number;
|
|
318
|
-
type: string;
|
|
319
|
-
data: Record<string, Json>;
|
|
320
|
-
timestamp: string;
|
|
286
|
+
export type ModelStreamFrame = {
|
|
287
|
+
event: {
|
|
288
|
+
type: string;
|
|
289
|
+
[key: string]: Json;
|
|
290
|
+
};
|
|
291
|
+
frame: Record<string, Json>;
|
|
292
|
+
};
|
|
293
|
+
export type ModelDeltaEvent = {
|
|
294
|
+
id: string;
|
|
295
|
+
requestId: string;
|
|
296
|
+
sequence: number;
|
|
297
|
+
createdAt: string;
|
|
298
|
+
type: "model.delta";
|
|
299
|
+
data: {
|
|
300
|
+
stepId: string;
|
|
301
|
+
stepNumber: number;
|
|
302
|
+
attemptId: string;
|
|
303
|
+
events: ModelStreamFrame[];
|
|
304
|
+
};
|
|
321
305
|
};
|
|
306
|
+
export type RequestEvent = WebhookEvent | ModelDeltaEvent;
|
|
322
307
|
export type Page<T> = {
|
|
323
308
|
items: T[];
|
|
324
309
|
total: number;
|
|
@@ -346,26 +331,44 @@ export type ModelResolution = ModelScope & {
|
|
|
346
331
|
headers?: Record<string, string>;
|
|
347
332
|
nativeContentPolicy?: "require" | "omitCompleted" | "omitIncompatible";
|
|
348
333
|
};
|
|
349
|
-
export type
|
|
350
|
-
|
|
351
|
-
inputId: string;
|
|
352
|
-
kind: PendingInput["kind"];
|
|
353
|
-
payload: Record<string, Json>;
|
|
354
|
-
} | {
|
|
334
|
+
export type ModelCompletedEvent = {
|
|
335
|
+
id: string;
|
|
355
336
|
requestId: string;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
337
|
+
sequence: number;
|
|
338
|
+
createdAt: string;
|
|
339
|
+
type: "model.completed";
|
|
340
|
+
data: {
|
|
341
|
+
message: Message;
|
|
342
|
+
result: Record<string, Json>;
|
|
343
|
+
events?: Json[];
|
|
344
|
+
stepId?: string;
|
|
345
|
+
stepNumber?: number;
|
|
346
|
+
attemptId?: string;
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
export type WebhookEvent = ModelCompletedEvent | {
|
|
350
|
+
id: string;
|
|
360
351
|
requestId: string;
|
|
361
|
-
|
|
362
|
-
|
|
352
|
+
sequence: number;
|
|
353
|
+
createdAt: string;
|
|
354
|
+
type: "model.failed" | "model.cancelled";
|
|
355
|
+
data: Record<string, Json>;
|
|
363
356
|
};
|
|
364
357
|
export declare class ConstellationError extends Error {
|
|
365
358
|
status: number;
|
|
366
359
|
code: string;
|
|
367
360
|
constructor(status: number, code: string, message: string);
|
|
368
361
|
}
|
|
362
|
+
/** Size of the server's typed observation representation, including absent optionals. */
|
|
363
|
+
export declare function observationBytes(observations: Observations): number;
|
|
364
|
+
/** Millisecond UTC ISO-8601 (`...sss` + `Z`). The server re-serializes timestamps with chrono,
|
|
365
|
+
* which widens 1/2-digit fractions to 3 and 4/7-digit fractions to 6/9; normalizing first keeps
|
|
366
|
+
* the client byte estimate an upper bound. Unparseable values are left for validation. */
|
|
367
|
+
export declare function normalizeTimestamp(value: string): string;
|
|
368
|
+
/** Copy observations with every caller-supplied timestamp in millisecond `Z` form. */
|
|
369
|
+
export declare function normalizeObservations(observations: Observations): Observations;
|
|
370
|
+
/** Validate response telemetry before any HTTP admission attempt. */
|
|
371
|
+
export declare function validateObservations(observations: Observations): void;
|
|
369
372
|
export declare function uuid7(): string;
|
|
370
373
|
/** Provider-reported token counts. Missing usage is unknown, not zero. */
|
|
371
374
|
export type TokenUsage = {
|
|
@@ -450,10 +453,8 @@ export type RequestTimings = {
|
|
|
450
453
|
queueMs: number | null;
|
|
451
454
|
workerPreparationMs: number | null;
|
|
452
455
|
attemptMs: number | null;
|
|
453
|
-
callerWaitMs: number | null;
|
|
454
456
|
phases: TimingInterval[];
|
|
455
457
|
attempts: TimingInterval[];
|
|
456
|
-
callerWaits: TimingInterval[];
|
|
457
458
|
asOf: string;
|
|
458
459
|
complete: boolean;
|
|
459
460
|
truncated: boolean;
|
|
@@ -486,25 +487,17 @@ export type RequestListQuery = {
|
|
|
486
487
|
limit?: number;
|
|
487
488
|
offset?: number;
|
|
488
489
|
};
|
|
489
|
-
export type StartSpanOptions = {
|
|
490
|
-
stepId?: string;
|
|
491
|
-
attemptId?: string;
|
|
492
|
-
inputId?: string;
|
|
493
|
-
parentSpanId?: string;
|
|
494
|
-
startedAt?: string;
|
|
495
|
-
attributes?: Record<string, Json>;
|
|
496
|
-
};
|
|
497
490
|
type ClientOptions = {
|
|
498
491
|
baseUrl: string;
|
|
499
492
|
apiPrefix?: "/v1" | "/internal";
|
|
500
493
|
fetch?: typeof fetch;
|
|
501
494
|
timeoutMs?: number;
|
|
495
|
+
/** gzip JSON bodies of at least 16 KiB (default true). */
|
|
496
|
+
compressRequests?: boolean;
|
|
502
497
|
};
|
|
503
498
|
export declare class RequestClient {
|
|
504
499
|
#private;
|
|
505
500
|
constructor(options: ClientOptions);
|
|
506
|
-
/** Agent claims are leases. Keep one alive while a caller handler is running. */
|
|
507
|
-
private maintainClaim;
|
|
508
501
|
/** Client-safe discovery with an execution key. */
|
|
509
502
|
get models(): {
|
|
510
503
|
list: (scope: ModelScope, signal?: AbortSignal) => Promise<Json>;
|
|
@@ -512,9 +505,7 @@ export declare class RequestClient {
|
|
|
512
505
|
};
|
|
513
506
|
/** Durable requests. create returns an ID; execution continues independently. */
|
|
514
507
|
get requests(): {
|
|
515
|
-
|
|
516
|
-
id: string;
|
|
517
|
-
}>;
|
|
508
|
+
submit: (input: Admission, signal?: AbortSignal) => Promise<AdmissionReceipt>;
|
|
518
509
|
preview: (input: RequestInput, signal?: AbortSignal) => Promise<{
|
|
519
510
|
revision: number;
|
|
520
511
|
resolution: Record<string, Json>;
|
|
@@ -523,6 +514,8 @@ export declare class RequestClient {
|
|
|
523
514
|
dispatched: false;
|
|
524
515
|
}>;
|
|
525
516
|
get: (id: string, signal?: AbortSignal) => Promise<Inspection>;
|
|
517
|
+
/** Committed execution state, independent of diagnostic history and its budgets. */
|
|
518
|
+
getState: (id: string, signal?: AbortSignal) => Promise<Inspection>;
|
|
526
519
|
getSummary: (id: string, signal?: AbortSignal) => Promise<Inspection>;
|
|
527
520
|
getTimings: (id: string, signal?: AbortSignal) => Promise<RequestTimings>;
|
|
528
521
|
list: (query?: RequestListQuery, signal?: AbortSignal) => Promise<{
|
|
@@ -559,27 +552,5 @@ export declare class RequestClient {
|
|
|
559
552
|
limit?: number;
|
|
560
553
|
}, signal?: AbortSignal) => Promise<Json>;
|
|
561
554
|
};
|
|
562
|
-
/** The same handlers work with webhook delivery and explicit polling. */
|
|
563
|
-
get inputs(): {
|
|
564
|
-
handle: (requestId: string, inputId: string, handlers: InputHandlers) => Promise<Inspection>;
|
|
565
|
-
poll: (requestId: string, handlers: InputHandlers) => Promise<Inspection>;
|
|
566
|
-
claim: (requestId: string, inputId: string, claimId: string, signal?: AbortSignal) => Promise<void>;
|
|
567
|
-
respond: (requestId: string, inputId: string, response: InputResponse, signal?: AbortSignal) => Promise<void>;
|
|
568
|
-
};
|
|
569
|
-
get spans(): {
|
|
570
|
-
start: (requestId: string, name: string, options?: StartSpanOptions, signal?: AbortSignal) => Promise<{
|
|
571
|
-
id: string;
|
|
572
|
-
end: (options?: {
|
|
573
|
-
endedAt?: string;
|
|
574
|
-
status?: "ok" | "error" | "cancelled";
|
|
575
|
-
attributes?: Record<string, Json>;
|
|
576
|
-
spans?: Span[];
|
|
577
|
-
}, signal?: AbortSignal) => Promise<void>;
|
|
578
|
-
}>;
|
|
579
|
-
add: (requestId: string, spans: Span[], signal?: AbortSignal) => Promise<void>;
|
|
580
|
-
};
|
|
581
|
-
get logs(): {
|
|
582
|
-
add: (requestId: string, logs: Log[], signal?: AbortSignal) => Promise<void>;
|
|
583
|
-
};
|
|
584
555
|
}
|
|
585
556
|
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** A bounded event receiver. Local scheduling is disposable: the server retains
|
|
2
|
+
* unresolved inputs and redelivers after processing claims expire. */
|
|
3
|
+
export interface InputNotification {
|
|
4
|
+
requestId: string;
|
|
5
|
+
inputId: string;
|
|
6
|
+
}
|
|
7
|
+
export interface InputReceiverOptions {
|
|
8
|
+
maxInFlight: number;
|
|
9
|
+
process: (notification: InputNotification, signal: AbortSignal) => Promise<void>;
|
|
10
|
+
onError: (error: unknown, notification: InputNotification) => void;
|
|
11
|
+
}
|
|
12
|
+
export type InputAcceptance = "accepted" | "duplicate" | "busy" | "closed";
|
|
13
|
+
export declare class InputReceiver {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(options: InputReceiverOptions);
|
|
16
|
+
/** Return HTTP 202 for accepted/duplicate, HTTP 503 for busy/closed.
|
|
17
|
+
* Authenticate and validate notifications before calling this method.
|
|
18
|
+
* No tool execution or remote inspection is awaited by this boundary. */
|
|
19
|
+
accept(notification: InputNotification): InputAcceptance;
|
|
20
|
+
get active(): number;
|
|
21
|
+
/** Graceful shutdown stops acceptance and cancels handlers. The server remains
|
|
22
|
+
* responsible for recovering unresolved inputs; no local queue is persisted. */
|
|
23
|
+
close(): Promise<void>;
|
|
24
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** External server SDK. Operator APIs and cookie sessions are internal-only clients. */
|
|
2
2
|
import { RequestClient, type WebhookEvent, type Json, type Page, type PageQuery, type ModelResolution, type RequestRecord, type RequestEvent, type RecordTypes, type Timeline, type TimelineRow, type RequestListQuery, type RequestRecordsQuery, type RequestTimings, type TokenUsage } from "../../client-core/src/index";
|
|
3
|
-
export { ConstellationError, uuid7 } from "../../client-core/src/index";
|
|
4
|
-
export type { InferenceParameters, Json, Tool, ToolCall, Message, RequestEventModes, RequestInput, RequestTimings, TimingInterval, TokenUsage, TokenPrice, CustomerPricing, BillingFacts, Status, RequestRecord, Step, Attempt,
|
|
3
|
+
export { ConstellationError, uuid7, normalizeTimestamp } from "../../client-core/src/index";
|
|
4
|
+
export type { InferenceParameters, Json, Tool, ToolCall, Message, RequestEventModes, RequestInput, Admission, AdmissionReceipt, ResponseOutcome, ObservationResponse, Observations, EventReference, ModelCompletedEvent, ModelDeltaEvent, ModelStreamFrame, RequestTimings, TimingInterval, TokenUsage, TokenPrice, CustomerPricing, BillingFacts, Status, RequestRecord, Step, Attempt, Span, TimelineRow, Timeline, Log, Inspection, RecordTypes, RequestEvent, Page, PageQuery, ModelScope, ModelResolution, WebhookEvent, RequestRecordsQuery, RequestListQuery } from "../../client-core/src/index";
|
|
5
5
|
/** OpenAPI contract filtered to this key's permissions and scope. */
|
|
6
6
|
export type DiscoveryDocument = {
|
|
7
7
|
openapi: string;
|
|
@@ -64,10 +64,6 @@ export type TelemetryRequest = OptionalContent<RequestRecord, "output" | "error"
|
|
|
64
64
|
export type TelemetryRecords = {
|
|
65
65
|
steps: OptionalContent<RecordTypes["steps"], "input" | "output" | "resolution" | "rules" | "customerPrice">;
|
|
66
66
|
attempts: OptionalContent<RecordTypes["attempts"], "endpoint" | "parameters" | "supplierPrice" | "customerPrice" | "error">;
|
|
67
|
-
inputs: Partial<RecordTypes["inputs"]> & {
|
|
68
|
-
id: string;
|
|
69
|
-
requestId: string;
|
|
70
|
-
};
|
|
71
67
|
spans: Partial<RecordTypes["spans"]> & {
|
|
72
68
|
id: string;
|
|
73
69
|
requestId: string;
|
|
@@ -88,7 +84,6 @@ export type TelemetryInspection = {
|
|
|
88
84
|
effectiveInput?: Json;
|
|
89
85
|
steps: TelemetryRecords["steps"][];
|
|
90
86
|
attempts: TelemetryRecords["attempts"][];
|
|
91
|
-
inputs: TelemetryRecords["inputs"][];
|
|
92
87
|
spans: TelemetryRecords["spans"][];
|
|
93
88
|
logs: TelemetryRecords["logs"][];
|
|
94
89
|
};
|
|
@@ -99,6 +94,7 @@ export declare class Constellation extends RequestClient {
|
|
|
99
94
|
apiKey: string;
|
|
100
95
|
fetch?: typeof fetch;
|
|
101
96
|
timeoutMs?: number;
|
|
97
|
+
compressRequests?: boolean;
|
|
102
98
|
});
|
|
103
99
|
/** Discover HTTP operations available to this bearer key. */
|
|
104
100
|
discover(signal?: AbortSignal): Promise<DiscoveryDocument>;
|
|
@@ -208,3 +204,5 @@ export declare class Constellation extends RequestClient {
|
|
|
208
204
|
verify: (request: Request, expectedToken: string) => Promise<WebhookEvent>;
|
|
209
205
|
};
|
|
210
206
|
}
|
|
207
|
+
export { PermanentEventError, HookConfigurationError, EventReceiver, prepareResponse, processEvent, ClientTelemetry, PERMANENT_RESPONSE_CODES } from "../../client-core/src/agent";
|
|
208
|
+
export type { EventStore, AgentHooks, HookContext, ToolResult } from "../../client-core/src/agent";
|
package/examples/quickstart.mjs
CHANGED
|
@@ -30,14 +30,14 @@ if (!model) {
|
|
|
30
30
|
messages: [{ role: "user", text: "Say hello in one short sentence." }],
|
|
31
31
|
maxOutputTokens: 256,
|
|
32
32
|
timeoutMs: 120_000,
|
|
33
|
-
|
|
33
|
+
events: { terminal: "off", },
|
|
34
34
|
};
|
|
35
|
-
const { id } = await client.requests.
|
|
35
|
+
const { id } = await client.requests.submit(input);
|
|
36
36
|
console.log("Request ID:", id);
|
|
37
37
|
for await (const event of client.requests.streamEvents(id, {
|
|
38
38
|
signal: AbortSignal.timeout(150_000),
|
|
39
39
|
})) {
|
|
40
|
-
console.log(event.
|
|
40
|
+
console.log(event.sequence, event.type);
|
|
41
41
|
}
|
|
42
42
|
const { request } = await client.requests.getSummary(id);
|
|
43
43
|
console.log("Final status:", request.status);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lionhummer/constellation",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "TypeScript client for durable model requests and
|
|
3
|
+
"version": "0.9.1",
|
|
4
|
+
"description": "TypeScript client for durable model requests and model events",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": {
|