@lionhummer/constellation 0.2.0 → 0.3.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.
@@ -1,4 +1,4 @@
1
- /** Durable request client. No provider credentials or application policy live here. */
1
+ /** Shared execution wire types and client mechanics. Authentication belongs to each client. */
2
2
  export type Json = null | boolean | number | string | Json[] | {
3
3
  [key: string]: Json;
4
4
  };
@@ -327,106 +327,53 @@ export declare class ConstellationError extends Error {
327
327
  constructor(status: number, code: string, message: string);
328
328
  }
329
329
  export declare function uuid7(): string;
330
- export declare class Constellation {
331
- private options;
332
- private fetcher;
333
- constructor(options: {
334
- baseUrl: string;
335
- apiKey?: string;
336
- apiPrefix?: "/v1" | "/internal";
337
- fetch?: typeof fetch;
338
- timeoutMs?: number;
339
- });
340
- private url;
341
- private call;
342
- submit(input: RequestInput, signal?: AbortSignal): Promise<{
343
- id: string;
344
- }>;
345
- inspect(id: string, signal?: AbortSignal): Promise<Inspection>;
346
- /** Canonical API timeline shared with the console. Derived rows disclose their timestamp basis. */
347
- timeline(id: string, options?: {
348
- requestId?: string;
349
- signal?: AbortSignal;
350
- }): Promise<Timeline>;
351
- /** Request context without loading historical telemetry. Fetch records by page. */
352
- inspectSummary(id: string, signal?: AbortSignal): Promise<Inspection>;
353
- records<K extends keyof RecordTypes>(id: string, kind: K, query?: {
354
- id?: string;
355
- q?: string;
356
- level?: Log["level"];
357
- offset?: number;
358
- limit?: number;
359
- }, signal?: AbortSignal): Promise<{
360
- items: RecordTypes[K][];
361
- total: number;
362
- offset: number;
363
- limit: number;
364
- }>;
365
- resolve(input: RequestInput, signal?: AbortSignal): Promise<{
366
- revision: number;
367
- resolution: Record<string, Json>;
368
- rules: Record<string, Json>;
369
- allowed: boolean;
370
- dispatched: false;
371
- }>;
372
- list(query?: {
373
- q?: string;
374
- requestId?: string;
375
- requestIdNot?: string;
376
- externalId?: string;
377
- externalIdNot?: string;
378
- externalIdContains?: string;
379
- externalIdNotContains?: string;
380
- workspaceId?: string;
381
- workspaceIdNot?: string;
382
- userId?: string;
383
- userIdNot?: string;
384
- status?: Status;
385
- statusNot?: Status;
386
- requestedModel?: string;
387
- requestedModelNot?: string;
388
- requestedModelContains?: string;
389
- requestedModelNotContains?: string;
390
- limit?: number;
391
- offset?: number;
392
- }, signal?: AbortSignal): Promise<{
393
- items: RequestRecord[];
394
- total: number;
395
- offset: number;
396
- limit: number;
397
- }>;
398
- cancel(id: string, signal?: AbortSignal): Promise<void>;
399
- claim(id: string, inputId: string, claimId: string, signal?: AbortSignal): Promise<void>;
330
+ export type RequestRecordsQuery = {
331
+ id?: string;
332
+ q?: string;
333
+ level?: Log["level"];
334
+ offset?: number;
335
+ limit?: number;
336
+ };
337
+ export type RequestListQuery = {
338
+ q?: string;
339
+ requestId?: string;
340
+ requestIdNot?: string;
341
+ externalId?: string;
342
+ externalIdNot?: string;
343
+ externalIdContains?: string;
344
+ externalIdNotContains?: string;
345
+ workspaceId?: string;
346
+ workspaceIdNot?: string;
347
+ userId?: string;
348
+ userIdNot?: string;
349
+ status?: Status;
350
+ statusNot?: Status;
351
+ requestedModel?: string;
352
+ requestedModelNot?: string;
353
+ requestedModelContains?: string;
354
+ requestedModelNotContains?: string;
355
+ limit?: number;
356
+ offset?: number;
357
+ };
358
+ export type StartSpanOptions = {
359
+ stepId?: string;
360
+ attemptId?: string;
361
+ inputId?: string;
362
+ parentSpanId?: string;
363
+ startedAt?: string;
364
+ attributes?: Record<string, Json>;
365
+ };
366
+ type ClientOptions = {
367
+ baseUrl: string;
368
+ apiPrefix?: "/v1" | "/internal";
369
+ fetch?: typeof fetch;
370
+ timeoutMs?: number;
371
+ };
372
+ export declare class RequestClient {
373
+ #private;
374
+ constructor(options: ClientOptions);
400
375
  /** Agent claims are leases. Keep one alive while a caller handler is running. */
401
376
  private maintainClaim;
402
- private whileClaimed;
403
- respond(id: string, inputId: string, response: InputResponse, signal?: AbortSignal): Promise<void>;
404
- addSpans(id: string, spans: Span[], signal?: AbortSignal): Promise<void>;
405
- addLogs(id: string, logs: Log[], signal?: AbortSignal): Promise<void>;
406
- startSpan(id: string, name: string, options?: {
407
- stepId?: string;
408
- attemptId?: string;
409
- inputId?: string;
410
- parentSpanId?: string;
411
- startedAt?: string;
412
- attributes?: Record<string, Json>;
413
- }, signal?: AbortSignal): Promise<{
414
- id: string;
415
- end: (options?: {
416
- endedAt?: string;
417
- status?: "ok" | "error" | "cancelled";
418
- attributes?: Record<string, Json>;
419
- }, signal?: AbortSignal) => Promise<void>;
420
- }>;
421
- /** Live SSE delivery with durable cursor replay after disconnects. */
422
- events(id: string, options?: {
423
- after?: number;
424
- signal?: AbortSignal;
425
- }): AsyncGenerator<RequestEvent>;
426
- /** Process one delivered input and exit. An input notification can be retried safely. */
427
- private handleInput;
428
- /** Handle pending inputs until the request ends. */
429
- private processInputs;
430
377
  /** Client-safe discovery with an execution key. */
431
378
  get models(): {
432
379
  list: (scope: ModelScope, signal?: AbortSignal) => Promise<Json>;
@@ -446,7 +393,7 @@ export declare class Constellation {
446
393
  }>;
447
394
  get: (id: string, signal?: AbortSignal) => Promise<Inspection>;
448
395
  getSummary: (id: string, signal?: AbortSignal) => Promise<Inspection>;
449
- list: (query?: Parameters<Constellation["list"]>[0], signal?: AbortSignal) => Promise<{
396
+ list: (query?: RequestListQuery, signal?: AbortSignal) => Promise<{
450
397
  items: RequestRecord[];
451
398
  total: number;
452
399
  offset: number;
@@ -460,7 +407,7 @@ export declare class Constellation {
460
407
  after?: number;
461
408
  signal?: AbortSignal;
462
409
  }) => AsyncGenerator<RequestEvent, any, any>;
463
- listRecords: <K extends keyof RecordTypes>(id: string, kind: K, query?: Parameters<Constellation["records"]>[2], signal?: AbortSignal) => Promise<{
410
+ listRecords: <K extends keyof RecordTypes>(id: string, kind: K, query?: RequestRecordsQuery, signal?: AbortSignal) => Promise<{
464
411
  items: RecordTypes[K][];
465
412
  total: number;
466
413
  offset: number;
@@ -485,7 +432,7 @@ export declare class Constellation {
485
432
  respond: (requestId: string, inputId: string, response: InputResponse, signal?: AbortSignal) => Promise<void>;
486
433
  };
487
434
  get spans(): {
488
- start: (requestId: string, name: string, options?: Parameters<Constellation["startSpan"]>[2], signal?: AbortSignal) => Promise<{
435
+ start: (requestId: string, name: string, options?: StartSpanOptions, signal?: AbortSignal) => Promise<{
489
436
  id: string;
490
437
  end: (options?: {
491
438
  endedAt?: string;
@@ -498,114 +445,5 @@ export declare class Constellation {
498
445
  get logs(): {
499
446
  add: (requestId: string, logs: Log[], signal?: AbortSignal) => Promise<void>;
500
447
  };
501
- /** Configuration endpoints require a management key. */
502
- get management(): {
503
- registry: {
504
- get: (signal?: AbortSignal) => Promise<Json>;
505
- listRows: (kind: "models" | "providers" | "plans" | "rules", query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
506
- update: (input: {
507
- expectedRevision: number;
508
- catalog: Json;
509
- }, signal?: AbortSignal) => Promise<Json>;
510
- applyChanges: (changes: Json[], signal?: AbortSignal) => Promise<Json>;
511
- listHistory: (kind: string, id: string, query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
512
- rollback: (kind: string, id: string, input: {
513
- toVersion: number;
514
- expectedVersion: number;
515
- }, signal?: AbortSignal) => Promise<Json>;
516
- preview: (input: ModelResolution, signal?: AbortSignal) => Promise<Json>;
517
- testRules: (scope: {
518
- workspaceId: string;
519
- userId?: string;
520
- }, signal?: AbortSignal) => Promise<Json>;
521
- };
522
- keys: {
523
- list: (signal?: AbortSignal) => Promise<Json>;
524
- listPage: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
525
- create: (input: Json, signal?: AbortSignal) => Promise<Json>;
526
- revoke: (id: string, signal?: AbortSignal) => Promise<void>;
527
- setInputWebhook: (id: string, input: {
528
- url: string | null;
529
- token?: string;
530
- }, signal?: AbortSignal) => Promise<Json>;
531
- };
532
- credentials: {
533
- list: (signal?: AbortSignal) => Promise<Json>;
534
- listPage: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
535
- create: (input: Json, signal?: AbortSignal) => Promise<Json>;
536
- update: (ref: string, input: Json, signal?: AbortSignal) => Promise<void>;
537
- delete: (ref: string, signal?: AbortSignal) => Promise<void>;
538
- };
539
- executionSettings: {
540
- get: (signal?: AbortSignal) => Promise<Json>;
541
- update: (input: Json, signal?: AbortSignal) => Promise<Json>;
542
- listHistory: (signal?: AbortSignal) => Promise<Json>;
543
- };
544
- };
545
- /** Read-only operational endpoints require a telemetry key. */
546
- get telemetry(): {
547
- requests: {
548
- list: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<RequestRecord>>;
549
- get: (id: string, signal?: AbortSignal) => Promise<Inspection>;
550
- getSummary: (id: string, signal?: AbortSignal) => Promise<Inspection>;
551
- listEvents: (id: string, after?: number, signal?: AbortSignal) => Promise<{
552
- items: RequestEvent[];
553
- }>;
554
- listRecords: <K extends keyof RecordTypes>(id: string, kind: K, query?: PageQuery, signal?: AbortSignal) => Promise<Page<RecordTypes[K]>>;
555
- getTimeline: (id: string, options?: {
556
- requestId?: string;
557
- signal?: AbortSignal;
558
- }) => Promise<Timeline>;
559
- getHttpExchange: (id: string, attemptId: string, signal?: AbortSignal) => Promise<Json>;
560
- getHttpBody: (id: string, attemptId: string, query: {
561
- direction: "request" | "response";
562
- offset?: number;
563
- limit?: number;
564
- }, signal?: AbortSignal) => Promise<Json>;
565
- };
566
- system: {
567
- get: (signal?: AbortSignal) => Promise<Json>;
568
- listHistory: (query?: {
569
- hours?: 1 | 24 | 168;
570
- }, signal?: AbortSignal) => Promise<Json>;
571
- getComponent: (component: string, signal?: AbortSignal) => Promise<Json>;
572
- };
573
- observability: {
574
- get: (query?: PageQuery, signal?: AbortSignal) => Promise<Json>;
575
- getSeries: (query: {
576
- source: "local" | "gateway";
577
- hours?: 1 | 24 | 168;
578
- providerId?: string;
579
- modelId?: string;
580
- }, signal?: AbortSignal) => Promise<Json>;
581
- getTiming: (query?: {
582
- hours?: 1 | 24 | 168;
583
- }, signal?: AbortSignal) => Promise<Json>;
584
- };
585
- jobs: {
586
- listHistory: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
587
- };
588
- notifications: {
589
- list: (query?: PageQuery & {
590
- status?: "active" | "resolved";
591
- }, signal?: AbortSignal) => Promise<Page<Json>>;
592
- get: (id: string, query?: PageQuery, signal?: AbortSignal) => Promise<Json>;
593
- listEvents: (query?: {
594
- after?: number;
595
- }, signal?: AbortSignal) => Promise<Json>;
596
- };
597
- logs: {
598
- searchSystem: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
599
- searchRequests: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
600
- searchAudit: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
601
- };
602
- };
603
- get health(): {
604
- live: (signal?: AbortSignal) => Promise<Json>;
605
- ready: (signal?: AbortSignal) => Promise<Json>;
606
- };
607
- get webhooks(): {
608
- verify: (request: Request, expectedToken: string) => Promise<WebhookEvent>;
609
- };
610
448
  }
611
449
  export {};
@@ -0,0 +1,96 @@
1
+ /** External server SDK. Operator APIs and cookie sessions are internal-only clients. */
2
+ import { RequestClient, type WebhookEvent, type Json, type Page, type PageQuery, type ModelResolution, type RequestRecord, type Inspection, type RequestEvent, type RecordTypes, type Timeline } from "../../client-core/src/index";
3
+ export { ConstellationError, uuid7 } from "../../client-core/src/index";
4
+ export type { Json, Tool, ToolCall, Message, RequestEventModes, RequestInput, Status, RequestRecord, Step, Attempt, PreparedStep, PendingInput, Span, TimelineRow, Timeline, Log, Inspection, RecordTypes, InputResponse, InputHandlers, RequestEvent, Page, PageQuery, ModelScope, ModelResolution, WebhookEvent, RequestRecordsQuery, RequestListQuery, StartSpanOptions } from "../../client-core/src/index";
5
+ export declare class Constellation extends RequestClient {
6
+ #private;
7
+ constructor(options: {
8
+ baseUrl: string;
9
+ apiKey: string;
10
+ fetch?: typeof fetch;
11
+ timeoutMs?: number;
12
+ });
13
+ /** Registry authoring only; keys, credentials and capacity controls are internal. */
14
+ get management(): {
15
+ registry: {
16
+ get: (signal?: AbortSignal) => Promise<Json>;
17
+ listRows: (kind: "models" | "providers" | "plans" | "rules", query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
18
+ update: (input: {
19
+ expectedRevision: number;
20
+ catalog: Json;
21
+ }, signal?: AbortSignal) => Promise<Json>;
22
+ applyChanges: (changes: Json[], signal?: AbortSignal) => Promise<Json>;
23
+ listHistory: (kind: string, id: string, query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
24
+ rollback: (kind: string, id: string, input: {
25
+ toVersion: number;
26
+ expectedVersion: number;
27
+ }, signal?: AbortSignal) => Promise<Json>;
28
+ preview: (input: ModelResolution, signal?: AbortSignal) => Promise<Json>;
29
+ testRules: (scope: {
30
+ workspaceId: string;
31
+ userId?: string;
32
+ }, signal?: AbortSignal) => Promise<Json>;
33
+ };
34
+ };
35
+ /** Read-only operational endpoints require a telemetry key. */
36
+ get telemetry(): {
37
+ requests: {
38
+ list: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<RequestRecord>>;
39
+ get: (id: string, signal?: AbortSignal) => Promise<Inspection>;
40
+ getSummary: (id: string, signal?: AbortSignal) => Promise<Inspection>;
41
+ listEvents: (id: string, after?: number, signal?: AbortSignal) => Promise<{
42
+ items: RequestEvent[];
43
+ }>;
44
+ listRecords: <K extends keyof RecordTypes>(id: string, kind: K, query?: PageQuery, signal?: AbortSignal) => Promise<Page<RecordTypes[K]>>;
45
+ getTimeline: (id: string, options?: {
46
+ requestId?: string;
47
+ signal?: AbortSignal;
48
+ }) => Promise<Timeline>;
49
+ getHttpExchange: (id: string, attemptId: string, signal?: AbortSignal) => Promise<Json>;
50
+ getHttpBody: (id: string, attemptId: string, query: {
51
+ direction: "request" | "response";
52
+ offset?: number;
53
+ limit?: number;
54
+ }, signal?: AbortSignal) => Promise<Json>;
55
+ };
56
+ system: {
57
+ get: (signal?: AbortSignal) => Promise<Json>;
58
+ listHistory: (query?: {
59
+ hours?: 1 | 24 | 168;
60
+ }, signal?: AbortSignal) => Promise<Json>;
61
+ getComponent: (component: string, signal?: AbortSignal) => Promise<Json>;
62
+ };
63
+ observability: {
64
+ get: (query?: PageQuery, signal?: AbortSignal) => Promise<Json>;
65
+ getSeries: (query: {
66
+ source: "local" | "gateway";
67
+ hours?: 1 | 24 | 168;
68
+ providerId?: string;
69
+ modelId?: string;
70
+ }, signal?: AbortSignal) => Promise<Json>;
71
+ getTiming: (query?: {
72
+ hours?: 1 | 24 | 168;
73
+ }, signal?: AbortSignal) => Promise<Json>;
74
+ };
75
+ jobs: {
76
+ listHistory: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
77
+ };
78
+ notifications: {
79
+ list: (query?: PageQuery & {
80
+ status?: "active" | "resolved";
81
+ }, signal?: AbortSignal) => Promise<Page<Json>>;
82
+ get: (id: string, query?: PageQuery, signal?: AbortSignal) => Promise<Json>;
83
+ listEvents: (query?: {
84
+ after?: number;
85
+ }, signal?: AbortSignal) => Promise<Json>;
86
+ };
87
+ logs: {
88
+ searchSystem: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
89
+ searchRequests: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
90
+ searchAudit: (query?: PageQuery, signal?: AbortSignal) => Promise<Page<Json>>;
91
+ };
92
+ };
93
+ get webhooks(): {
94
+ verify: (request: Request, expectedToken: string) => Promise<WebhookEvent>;
95
+ };
96
+ }
@@ -0,0 +1,48 @@
1
+ import { Constellation, uuid7 } from "@lionhummer/constellation";
2
+
3
+ function required(name) {
4
+ const value = process.env[name];
5
+ if (!value) throw new Error(`Set ${name} in your server environment.`);
6
+ return value;
7
+ }
8
+
9
+ const workspaceId = required("CONSTELLATION_WORKSPACE_ID");
10
+ const userId = process.env.CONSTELLATION_USER_ID || undefined;
11
+ const planId = process.env.CONSTELLATION_PLAN_ID || undefined;
12
+ const client = new Constellation({
13
+ baseUrl: required("CONSTELLATION_BASE_URL"),
14
+ apiKey: required("CONSTELLATION_EXECUTION_KEY"),
15
+ });
16
+
17
+ // Discovery uses the same scope as execution. It does not call a provider.
18
+ const catalog = await client.models.list({ workspaceId, userId, planId });
19
+ console.log("Available models:", JSON.stringify(catalog, null, 2));
20
+ const model = process.env.CONSTELLATION_MODEL;
21
+ if (!model) {
22
+ console.log("Set CONSTELLATION_MODEL to one of the returned models[].id values, then rerun.");
23
+ } else {
24
+ const input = {
25
+ idempotencyKey: uuid7(), // Save this input/key if submission needs retrying.
26
+ workspaceId,
27
+ userId,
28
+ planId,
29
+ model,
30
+ messages: [{ role: "user", text: "Say hello in one short sentence." }],
31
+ maxOutputTokens: 256,
32
+ timeoutMs: 120_000,
33
+ // No tools or wait checkpoints: no webhook or input consumer is needed.
34
+ };
35
+ const { id } = await client.requests.create(input);
36
+ console.log("Request ID:", id);
37
+ for await (const event of client.requests.streamEvents(id, {
38
+ signal: AbortSignal.timeout(150_000),
39
+ })) {
40
+ console.log(event.seq, event.type);
41
+ }
42
+ const { request } = await client.requests.getSummary(id);
43
+ console.log("Final status:", request.status);
44
+ console.log("Output:", request.output?.text ?? "");
45
+ if (request.status !== "completed") {
46
+ throw new Error(`Request ${id} ended as ${request.status}: ${request.reason ?? "inspect the request error and attempts"}`);
47
+ }
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lionhummer/constellation",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "TypeScript client for durable model requests and caller events",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -9,23 +9,33 @@
9
9
  "url": "git+https://github.com/FlatFilers/constellation.git",
10
10
  "directory": "packages/sdk"
11
11
  },
12
- "files": ["dist", "README.md"],
13
- "publishConfig": { "access": "public" },
14
- "types": "./dist/index.d.ts",
12
+ "files": [
13
+ "dist/index.js",
14
+ "dist/types/**/*.d.ts",
15
+ "examples/quickstart.mjs",
16
+ "README.md"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "types": "./dist/types/sdk/src/index.d.ts",
15
22
  "exports": {
16
23
  ".": {
17
- "types": "./dist/index.d.ts",
24
+ "types": "./dist/types/sdk/src/index.d.ts",
18
25
  "import": "./dist/index.js",
19
26
  "default": "./dist/index.js"
20
27
  }
21
28
  },
22
29
  "scripts": {
23
- "build": "tsc -p tsconfig.build.json",
30
+ "build": "tsc -p tsconfig.build.json && bun build ./src/index.ts --target node --format esm --outdir ./dist",
24
31
  "prepack": "bun run build",
25
32
  "test": "bun test",
26
33
  "typecheck": "tsc --noEmit --strict --target ES2022 --module ESNext --moduleResolution Bundler --lib ES2022,DOM src/index.ts"
27
34
  },
28
35
  "devDependencies": {
29
36
  "typescript": "^5.9.0"
37
+ },
38
+ "engines": {
39
+ "node": ">=22"
30
40
  }
31
41
  }