@sanity/ailf 2.7.1 → 2.8.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.
Files changed (48) hide show
  1. package/dist/_vendor/ailf-core/artifact-registry.d.ts +72 -0
  2. package/dist/_vendor/ailf-core/artifact-registry.js +150 -0
  3. package/dist/_vendor/ailf-core/index.d.ts +2 -1
  4. package/dist/_vendor/ailf-core/index.js +2 -1
  5. package/dist/_vendor/ailf-core/ports/artifact-collector.d.ts +3 -3
  6. package/dist/_vendor/ailf-core/ports/artifact-writer.d.ts +56 -0
  7. package/dist/_vendor/ailf-core/ports/artifact-writer.js +28 -0
  8. package/dist/_vendor/ailf-core/ports/context.d.ts +13 -3
  9. package/dist/_vendor/ailf-core/ports/index.d.ts +3 -3
  10. package/dist/_vendor/ailf-core/ports/index.js +1 -1
  11. package/dist/_vendor/ailf-core/types/branded-ids.d.ts +9 -0
  12. package/dist/_vendor/ailf-core/types/branded-ids.js +21 -0
  13. package/dist/_vendor/ailf-core/types/index.d.ts +110 -68
  14. package/dist/_vendor/ailf-core/types/index.js +1 -1
  15. package/dist/_vendor/ailf-shared/index.d.ts +2 -0
  16. package/dist/_vendor/ailf-shared/index.js +2 -0
  17. package/dist/_vendor/ailf-shared/run-context.d.ts +55 -0
  18. package/dist/_vendor/ailf-shared/run-context.js +17 -0
  19. package/dist/_vendor/ailf-shared/run-trigger.d.ts +30 -0
  20. package/dist/_vendor/ailf-shared/run-trigger.js +13 -0
  21. package/dist/artifact-capture/api-gateway-artifact-writer.d.ts +39 -0
  22. package/dist/artifact-capture/api-gateway-artifact-writer.js +148 -0
  23. package/dist/artifact-capture/gcs-artifact-writer.d.ts +30 -0
  24. package/dist/artifact-capture/gcs-artifact-writer.js +119 -0
  25. package/dist/commands/publish.js +3 -2
  26. package/dist/composition-root.d.ts +3 -3
  27. package/dist/composition-root.js +20 -15
  28. package/dist/orchestration/build-step-sequence.js +6 -1
  29. package/dist/orchestration/steps/calculate-scores-step.js +42 -2
  30. package/dist/orchestration/steps/finalize-run-step.d.ts +29 -0
  31. package/dist/orchestration/steps/finalize-run-step.js +103 -0
  32. package/dist/orchestration/steps/publish-report-step.js +19 -39
  33. package/dist/pipeline/calculate-scores.js +13 -2
  34. package/dist/pipeline/provenance.d.ts +24 -44
  35. package/dist/pipeline/provenance.js +17 -165
  36. package/dist/pipeline/report-title.d.ts +2 -2
  37. package/dist/pipeline/run-context.d.ts +57 -0
  38. package/dist/pipeline/run-context.js +156 -0
  39. package/dist/pipeline/upload-test-outputs.d.ts +26 -0
  40. package/dist/pipeline/upload-test-outputs.js +34 -0
  41. package/dist/report-store.js +4 -2
  42. package/package.json +3 -3
  43. package/dist/_vendor/ailf-core/ports/artifact-uploader.d.ts +0 -35
  44. package/dist/_vendor/ailf-core/ports/artifact-uploader.js +0 -18
  45. package/dist/artifact-capture/api-gateway-artifact-uploader.d.ts +0 -41
  46. package/dist/artifact-capture/api-gateway-artifact-uploader.js +0 -123
  47. package/dist/artifact-capture/gcs-report-artifact-uploader.d.ts +0 -31
  48. package/dist/artifact-capture/gcs-report-artifact-uploader.js +0 -66
@@ -1,18 +0,0 @@
1
- /**
2
- * Port: ArtifactUploader — uploads report artifacts to external object storage.
3
- *
4
- * Separate from ArtifactCollector (which captures forensic archives).
5
- * This port puts structured files at known paths so Studio can fetch
6
- * them on demand via signed URLs.
7
- *
8
- * @see docs/design-docs/external-artifact-store.md
9
- * @see docs/decisions/D0030-external-artifact-store.md
10
- */
11
- /**
12
- * No-op uploader — always returns null. Used when GCS is not configured.
13
- */
14
- export class NoOpArtifactUploader {
15
- async upload() {
16
- return null;
17
- }
18
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * ApiGatewayArtifactUploader — uploads report artifacts via the API Gateway.
3
- *
4
- * Counterpart to GcsReportArtifactUploader. Used when the CLI runs locally
5
- * without GCS credentials. Two-step flow:
6
- *
7
- * 1. GET {apiBaseUrl}/v1/artifacts/{reportId}/upload-url?type={artifactType}
8
- * with Authorization: Bearer {apiKey} — returns a signed PUT URL.
9
- * 2. PUT the JSON to that URL with Content-Type: application/json and
10
- * x-goog-if-generation-match: 0 (overwrite-protection contract from
11
- * the gateway's signed URL).
12
- *
13
- * The gateway stays out of the data path — Vercel only signs the URL,
14
- * the artifact bytes go directly to GCS.
15
- *
16
- * Design principles:
17
- * - P5: Non-blocking — any failure returns null and warns, never throws.
18
- * - Stateless — no client to keep around between calls.
19
- *
20
- * @see docs/design-docs/external-artifact-store.md
21
- * @see docs/decisions/D0030-external-artifact-store.md
22
- */
23
- import type { ArtifactRef, ArtifactUploader } from "../_vendor/ailf-core/index.d.ts";
24
- export interface ApiGatewayUploaderOptions {
25
- /** Base URL of the API gateway (e.g., "https://api.ailf.sanity.io"). */
26
- apiBaseUrl: string;
27
- /** AILF API key with the `artifact:write` scope. */
28
- apiKey: string;
29
- /** GCS bucket name — included in the returned ArtifactRef. */
30
- bucket: string;
31
- }
32
- export declare class ApiGatewayArtifactUploader implements ArtifactUploader {
33
- private readonly options;
34
- constructor(options: ApiGatewayUploaderOptions);
35
- upload(reportId: string, fileName: string, data: unknown): Promise<ArtifactRef | null>;
36
- /**
37
- * Fetch a signed upload URL from the gateway. Returns null on any non-2xx
38
- * response or malformed body so the caller can stay non-blocking.
39
- */
40
- private fetchSignedUrl;
41
- }
@@ -1,123 +0,0 @@
1
- /**
2
- * ApiGatewayArtifactUploader — uploads report artifacts via the API Gateway.
3
- *
4
- * Counterpart to GcsReportArtifactUploader. Used when the CLI runs locally
5
- * without GCS credentials. Two-step flow:
6
- *
7
- * 1. GET {apiBaseUrl}/v1/artifacts/{reportId}/upload-url?type={artifactType}
8
- * with Authorization: Bearer {apiKey} — returns a signed PUT URL.
9
- * 2. PUT the JSON to that URL with Content-Type: application/json and
10
- * x-goog-if-generation-match: 0 (overwrite-protection contract from
11
- * the gateway's signed URL).
12
- *
13
- * The gateway stays out of the data path — Vercel only signs the URL,
14
- * the artifact bytes go directly to GCS.
15
- *
16
- * Design principles:
17
- * - P5: Non-blocking — any failure returns null and warns, never throws.
18
- * - Stateless — no client to keep around between calls.
19
- *
20
- * @see docs/design-docs/external-artifact-store.md
21
- * @see docs/decisions/D0030-external-artifact-store.md
22
- */
23
- // ---------------------------------------------------------------------------
24
- // File-name → artifact-type mapping (mirrors packages/api ARTIFACT_FILES)
25
- // ---------------------------------------------------------------------------
26
- /**
27
- * Reverse map of the API gateway's ARTIFACT_FILES. The uploader port speaks
28
- * file names; the gateway endpoint speaks artifact types. Keep these in sync
29
- * with packages/api/src/routes/artifacts.ts.
30
- */
31
- const FILE_TO_TYPE = {
32
- "eval-results.json": "evalResults",
33
- "grader-prompts.json": "graderPrompts",
34
- "rendered-prompts.json": "renderedPrompts",
35
- "task-definitions.json": "taskDefinitions",
36
- "test-outputs.json": "testOutputs",
37
- };
38
- export class ApiGatewayArtifactUploader {
39
- options;
40
- constructor(options) {
41
- this.options = options;
42
- }
43
- async upload(reportId, fileName, data) {
44
- const artifactType = FILE_TO_TYPE[fileName];
45
- if (!artifactType) {
46
- console.warn(` ⚠️ Artifact upload skipped (unknown fileName): ${fileName}`);
47
- return null;
48
- }
49
- const objectPath = `reports/${reportId}/${fileName}`;
50
- const json = JSON.stringify(data);
51
- const bytes = Buffer.byteLength(json, "utf-8");
52
- try {
53
- const signed = await this.fetchSignedUrl(reportId, artifactType);
54
- if (!signed)
55
- return null;
56
- const putRes = await fetch(signed.url, {
57
- body: json,
58
- headers: signed.requiredHeaders,
59
- method: "PUT",
60
- });
61
- if (!putRes.ok) {
62
- console.warn(` ⚠️ Artifact upload failed (non-blocking): ${objectPath} — GCS PUT ${putRes.status} ${putRes.statusText}`);
63
- return null;
64
- }
65
- return {
66
- bucket: signed.bucket,
67
- bytes,
68
- entryCount: extractEntryCount(data),
69
- path: signed.path,
70
- store: "gcs",
71
- };
72
- }
73
- catch (err) {
74
- const message = err instanceof Error ? err.message : String(err);
75
- console.warn(` ⚠️ Artifact upload failed (non-blocking): ${objectPath} — ${message}`);
76
- return null;
77
- }
78
- }
79
- /**
80
- * Fetch a signed upload URL from the gateway. Returns null on any non-2xx
81
- * response or malformed body so the caller can stay non-blocking.
82
- */
83
- async fetchSignedUrl(reportId, artifactType) {
84
- const url = `${this.options.apiBaseUrl.replace(/\/$/, "")}/v1/artifacts/${encodeURIComponent(reportId)}/upload-url?type=${encodeURIComponent(artifactType)}`;
85
- const res = await fetch(url, {
86
- headers: {
87
- Authorization: `Bearer ${this.options.apiKey}`,
88
- },
89
- method: "GET",
90
- });
91
- if (!res.ok) {
92
- console.warn(` ⚠️ Signed-URL request failed: ${res.status} ${res.statusText}`);
93
- return null;
94
- }
95
- const body = (await res.json());
96
- if (body.object !== "signed_upload_url" ||
97
- typeof body.url !== "string" ||
98
- typeof body.path !== "string" ||
99
- typeof body.bucket !== "string" ||
100
- !body.requiredHeaders) {
101
- console.warn(` ⚠️ Signed-URL response was malformed`);
102
- return null;
103
- }
104
- return {
105
- bucket: body.bucket,
106
- method: "PUT",
107
- object: "signed_upload_url",
108
- path: body.path,
109
- requiredHeaders: body.requiredHeaders,
110
- url: body.url,
111
- };
112
- }
113
- }
114
- function extractEntryCount(data) {
115
- if (typeof data === "object" &&
116
- data !== null &&
117
- "entries" in data &&
118
- typeof data.entries === "object") {
119
- return Object.keys(data.entries)
120
- .length;
121
- }
122
- return undefined;
123
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * GcsReportArtifactUploader — uploads report artifacts to known GCS paths.
3
- *
4
- * Separate from GcsArtifactCollector (which handles forensic capture archives).
5
- * This uploader puts structured JSON files at predictable paths so the
6
- * API Gateway can sign URLs and Studio can fetch them on demand.
7
- *
8
- * GCS path convention: reports/{reportId}/{fileName}
9
- * Example: reports/01926abc.../test-outputs.json
10
- *
11
- * Design principles:
12
- * - P5: Non-blocking — GCS upload failure returns null, never throws
13
- * - Lazy client — Storage created on first upload, not at construction
14
- * - Same credentials path as GcsArtifactCollector (ADC or key file)
15
- *
16
- * @see docs/design-docs/external-artifact-store.md
17
- * @see docs/decisions/D0030-external-artifact-store.md
18
- */
19
- import type { ArtifactRef, ArtifactUploader } from "../_vendor/ailf-core/index.d.ts";
20
- export interface GcsUploaderOptions {
21
- /** GCS bucket name (e.g., "ailf-artifacts") */
22
- bucket: string;
23
- }
24
- export declare class GcsReportArtifactUploader implements ArtifactUploader {
25
- private client;
26
- private readonly options;
27
- constructor(options: GcsUploaderOptions);
28
- upload(reportId: string, fileName: string, data: unknown): Promise<ArtifactRef | null>;
29
- /** Lazily create the GCS Storage client (ADC). */
30
- private getClient;
31
- }
@@ -1,66 +0,0 @@
1
- /**
2
- * GcsReportArtifactUploader — uploads report artifacts to known GCS paths.
3
- *
4
- * Separate from GcsArtifactCollector (which handles forensic capture archives).
5
- * This uploader puts structured JSON files at predictable paths so the
6
- * API Gateway can sign URLs and Studio can fetch them on demand.
7
- *
8
- * GCS path convention: reports/{reportId}/{fileName}
9
- * Example: reports/01926abc.../test-outputs.json
10
- *
11
- * Design principles:
12
- * - P5: Non-blocking — GCS upload failure returns null, never throws
13
- * - Lazy client — Storage created on first upload, not at construction
14
- * - Same credentials path as GcsArtifactCollector (ADC or key file)
15
- *
16
- * @see docs/design-docs/external-artifact-store.md
17
- * @see docs/decisions/D0030-external-artifact-store.md
18
- */
19
- import { Storage } from "@google-cloud/storage";
20
- export class GcsReportArtifactUploader {
21
- client = null;
22
- options;
23
- constructor(options) {
24
- this.options = options;
25
- }
26
- async upload(reportId, fileName, data) {
27
- const objectPath = `reports/${reportId}/${fileName}`;
28
- const json = JSON.stringify(data);
29
- const bytes = Buffer.byteLength(json, "utf-8");
30
- try {
31
- const storage = this.getClient();
32
- const file = storage.bucket(this.options.bucket).file(objectPath);
33
- await file.save(json, {
34
- contentType: "application/json",
35
- metadata: {
36
- reportId,
37
- },
38
- });
39
- return {
40
- store: "gcs",
41
- bucket: this.options.bucket,
42
- path: objectPath,
43
- bytes,
44
- entryCount: typeof data === "object" &&
45
- data !== null &&
46
- "entries" in data &&
47
- typeof data.entries === "object"
48
- ? Object.keys(data.entries)
49
- .length
50
- : undefined,
51
- };
52
- }
53
- catch (err) {
54
- const message = err instanceof Error ? err.message : String(err);
55
- console.warn(` ⚠️ Artifact upload failed (non-blocking): ${objectPath} — ${message}`);
56
- return null;
57
- }
58
- }
59
- /** Lazily create the GCS Storage client (ADC). */
60
- getClient() {
61
- if (this.client)
62
- return this.client;
63
- this.client = new Storage();
64
- return this.client;
65
- }
66
- }