@lionhummer/constellation 0.5.0 → 0.9.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 +330 -152
- package/dist/index.js +431 -250
- package/dist/types/client-core/src/agent.d.ts +81 -0
- package/dist/types/client-core/src/index.d.ts +102 -130
- package/dist/types/client-core/src/input-receiver.d.ts +24 -0
- package/dist/types/sdk/src/index.d.ts +4 -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>;
|
|
@@ -57,9 +57,14 @@ type RequestFields = {
|
|
|
57
57
|
optionalParameters?: string[];
|
|
58
58
|
/** Only headers approved by the selected provider are forwarded; others produce warnings. */
|
|
59
59
|
headers?: Record<string, string>;
|
|
60
|
-
nativeContentPolicy?: "require" | "omitCompleted";
|
|
61
|
-
maxSteps?: number;
|
|
60
|
+
nativeContentPolicy?: "require" | "omitCompleted" | "omitIncompatible";
|
|
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";
|
|
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,50 +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
|
-
inputId: string;
|
|
307
|
-
signal: AbortSignal;
|
|
308
|
-
}) => Promise<Json>;
|
|
309
|
-
signal?: AbortSignal;
|
|
310
|
-
consumerId?: string;
|
|
311
|
-
toolTimeoutMs?: number;
|
|
312
|
-
onUpdate?: (state: Inspection) => void;
|
|
313
|
-
};
|
|
314
|
-
export type RequestEvent = {
|
|
315
|
-
seq: number;
|
|
316
|
-
type: string;
|
|
317
|
-
data: Record<string, Json>;
|
|
318
|
-
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
|
+
};
|
|
319
305
|
};
|
|
306
|
+
export type RequestEvent = WebhookEvent | ModelDeltaEvent;
|
|
320
307
|
export type Page<T> = {
|
|
321
308
|
items: T[];
|
|
322
309
|
total: number;
|
|
@@ -342,28 +329,46 @@ export type ModelResolution = ModelScope & {
|
|
|
342
329
|
optionalParameters?: string[];
|
|
343
330
|
/** Only headers approved by the selected provider are forwarded; others produce warnings. */
|
|
344
331
|
headers?: Record<string, string>;
|
|
345
|
-
nativeContentPolicy?: "require" | "omitCompleted";
|
|
332
|
+
nativeContentPolicy?: "require" | "omitCompleted" | "omitIncompatible";
|
|
346
333
|
};
|
|
347
|
-
export type
|
|
348
|
-
|
|
349
|
-
inputId: string;
|
|
350
|
-
kind: PendingInput["kind"];
|
|
351
|
-
payload: Record<string, Json>;
|
|
352
|
-
} | {
|
|
334
|
+
export type ModelCompletedEvent = {
|
|
335
|
+
id: string;
|
|
353
336
|
requestId: string;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
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;
|
|
358
351
|
requestId: string;
|
|
359
|
-
|
|
360
|
-
|
|
352
|
+
sequence: number;
|
|
353
|
+
createdAt: string;
|
|
354
|
+
type: "model.failed" | "model.cancelled";
|
|
355
|
+
data: Record<string, Json>;
|
|
361
356
|
};
|
|
362
357
|
export declare class ConstellationError extends Error {
|
|
363
358
|
status: number;
|
|
364
359
|
code: string;
|
|
365
360
|
constructor(status: number, code: string, message: string);
|
|
366
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;
|
|
367
372
|
export declare function uuid7(): string;
|
|
368
373
|
/** Provider-reported token counts. Missing usage is unknown, not zero. */
|
|
369
374
|
export type TokenUsage = {
|
|
@@ -448,10 +453,8 @@ export type RequestTimings = {
|
|
|
448
453
|
queueMs: number | null;
|
|
449
454
|
workerPreparationMs: number | null;
|
|
450
455
|
attemptMs: number | null;
|
|
451
|
-
callerWaitMs: number | null;
|
|
452
456
|
phases: TimingInterval[];
|
|
453
457
|
attempts: TimingInterval[];
|
|
454
|
-
callerWaits: TimingInterval[];
|
|
455
458
|
asOf: string;
|
|
456
459
|
complete: boolean;
|
|
457
460
|
truncated: boolean;
|
|
@@ -484,14 +487,6 @@ export type RequestListQuery = {
|
|
|
484
487
|
limit?: number;
|
|
485
488
|
offset?: number;
|
|
486
489
|
};
|
|
487
|
-
export type StartSpanOptions = {
|
|
488
|
-
stepId?: string;
|
|
489
|
-
attemptId?: string;
|
|
490
|
-
inputId?: string;
|
|
491
|
-
parentSpanId?: string;
|
|
492
|
-
startedAt?: string;
|
|
493
|
-
attributes?: Record<string, Json>;
|
|
494
|
-
};
|
|
495
490
|
type ClientOptions = {
|
|
496
491
|
baseUrl: string;
|
|
497
492
|
apiPrefix?: "/v1" | "/internal";
|
|
@@ -501,8 +496,6 @@ type ClientOptions = {
|
|
|
501
496
|
export declare class RequestClient {
|
|
502
497
|
#private;
|
|
503
498
|
constructor(options: ClientOptions);
|
|
504
|
-
/** Agent claims are leases. Keep one alive while a caller handler is running. */
|
|
505
|
-
private maintainClaim;
|
|
506
499
|
/** Client-safe discovery with an execution key. */
|
|
507
500
|
get models(): {
|
|
508
501
|
list: (scope: ModelScope, signal?: AbortSignal) => Promise<Json>;
|
|
@@ -510,9 +503,7 @@ export declare class RequestClient {
|
|
|
510
503
|
};
|
|
511
504
|
/** Durable requests. create returns an ID; execution continues independently. */
|
|
512
505
|
get requests(): {
|
|
513
|
-
|
|
514
|
-
id: string;
|
|
515
|
-
}>;
|
|
506
|
+
submit: (input: Admission, signal?: AbortSignal) => Promise<AdmissionReceipt>;
|
|
516
507
|
preview: (input: RequestInput, signal?: AbortSignal) => Promise<{
|
|
517
508
|
revision: number;
|
|
518
509
|
resolution: Record<string, Json>;
|
|
@@ -521,6 +512,8 @@ export declare class RequestClient {
|
|
|
521
512
|
dispatched: false;
|
|
522
513
|
}>;
|
|
523
514
|
get: (id: string, signal?: AbortSignal) => Promise<Inspection>;
|
|
515
|
+
/** Committed execution state, independent of diagnostic history and its budgets. */
|
|
516
|
+
getState: (id: string, signal?: AbortSignal) => Promise<Inspection>;
|
|
524
517
|
getSummary: (id: string, signal?: AbortSignal) => Promise<Inspection>;
|
|
525
518
|
getTimings: (id: string, signal?: AbortSignal) => Promise<RequestTimings>;
|
|
526
519
|
list: (query?: RequestListQuery, signal?: AbortSignal) => Promise<{
|
|
@@ -557,26 +550,5 @@ export declare class RequestClient {
|
|
|
557
550
|
limit?: number;
|
|
558
551
|
}, signal?: AbortSignal) => Promise<Json>;
|
|
559
552
|
};
|
|
560
|
-
/** The same handlers work with webhook delivery and explicit polling. */
|
|
561
|
-
get inputs(): {
|
|
562
|
-
handle: (requestId: string, inputId: string, handlers: InputHandlers) => Promise<Inspection>;
|
|
563
|
-
poll: (requestId: string, handlers: InputHandlers) => Promise<Inspection>;
|
|
564
|
-
claim: (requestId: string, inputId: string, claimId: string, signal?: AbortSignal) => Promise<void>;
|
|
565
|
-
respond: (requestId: string, inputId: string, response: InputResponse, signal?: AbortSignal) => Promise<void>;
|
|
566
|
-
};
|
|
567
|
-
get spans(): {
|
|
568
|
-
start: (requestId: string, name: string, options?: StartSpanOptions, signal?: AbortSignal) => Promise<{
|
|
569
|
-
id: string;
|
|
570
|
-
end: (options?: {
|
|
571
|
-
endedAt?: string;
|
|
572
|
-
status?: "ok" | "error" | "cancelled";
|
|
573
|
-
attributes?: Record<string, Json>;
|
|
574
|
-
}, signal?: AbortSignal) => Promise<void>;
|
|
575
|
-
}>;
|
|
576
|
-
add: (requestId: string, spans: Span[], signal?: AbortSignal) => Promise<void>;
|
|
577
|
-
};
|
|
578
|
-
get logs(): {
|
|
579
|
-
add: (requestId: string, logs: Log[], signal?: AbortSignal) => Promise<void>;
|
|
580
|
-
};
|
|
581
553
|
}
|
|
582
554
|
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
|
};
|
|
@@ -208,3 +203,5 @@ export declare class Constellation extends RequestClient {
|
|
|
208
203
|
verify: (request: Request, expectedToken: string) => Promise<WebhookEvent>;
|
|
209
204
|
};
|
|
210
205
|
}
|
|
206
|
+
export { PermanentEventError, HookConfigurationError, EventReceiver, prepareResponse, processEvent, ClientTelemetry, PERMANENT_RESPONSE_CODES } from "../../client-core/src/agent";
|
|
207
|
+
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.0",
|
|
4
|
+
"description": "TypeScript client for durable model requests and model events",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": {
|