@mcoda/mswarm 0.1.89 → 0.1.91

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 (116) hide show
  1. package/dist/codali-executor.d.ts +107 -6
  2. package/dist/codali-executor.d.ts.map +1 -1
  3. package/dist/codali-executor.js +500 -26
  4. package/dist/codali-executor.js.map +1 -1
  5. package/dist/runtime.d.ts +6 -3
  6. package/dist/runtime.d.ts.map +1 -1
  7. package/dist/runtime.js +18 -5
  8. package/dist/runtime.js.map +1 -1
  9. package/dist/server.d.ts.map +1 -1
  10. package/dist/server.js +18 -3
  11. package/dist/server.js.map +1 -1
  12. package/dist/vendor/codali/cli/DatasetCommand.d.ts +38 -0
  13. package/dist/vendor/codali/cli/DatasetCommand.d.ts.map +1 -0
  14. package/dist/vendor/codali/cli/DatasetCommand.js +959 -0
  15. package/dist/vendor/codali/cli/EvalCommand.d.ts +3 -0
  16. package/dist/vendor/codali/cli/EvalCommand.d.ts.map +1 -1
  17. package/dist/vendor/codali/cli/EvalCommand.js +55 -1
  18. package/dist/vendor/codali/cli/ImprovementCommand.d.ts +97 -0
  19. package/dist/vendor/codali/cli/ImprovementCommand.d.ts.map +1 -0
  20. package/dist/vendor/codali/cli/ImprovementCommand.js +1879 -0
  21. package/dist/vendor/codali/cli.d.ts.map +1 -1
  22. package/dist/vendor/codali/cli.js +15 -0
  23. package/dist/vendor/codali/dataset-cli.d.ts +3 -0
  24. package/dist/vendor/codali/dataset-cli.d.ts.map +1 -0
  25. package/dist/vendor/codali/dataset-cli.js +30 -0
  26. package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.d.ts +90 -1
  27. package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.d.ts.map +1 -1
  28. package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.js +443 -9
  29. package/dist/vendor/codali/eval/GatewayDatasetEval.d.ts +70 -0
  30. package/dist/vendor/codali/eval/GatewayDatasetEval.d.ts.map +1 -0
  31. package/dist/vendor/codali/eval/GatewayDatasetEval.js +477 -0
  32. package/dist/vendor/codali/eval/GatewayEvalSuite.d.ts +52 -0
  33. package/dist/vendor/codali/eval/GatewayEvalSuite.d.ts.map +1 -1
  34. package/dist/vendor/codali/eval/GatewayEvalSuite.js +135 -1
  35. package/dist/vendor/codali/gateway/CodaliGateway.d.ts +4 -0
  36. package/dist/vendor/codali/gateway/CodaliGateway.d.ts.map +1 -1
  37. package/dist/vendor/codali/gateway/CodaliGateway.js +37 -1
  38. package/dist/vendor/codali/gateway/CodaliGatewaySchemas.d.ts.map +1 -1
  39. package/dist/vendor/codali/gateway/CodaliGatewaySchemas.js +0 -4
  40. package/dist/vendor/codali/gateway/CodaliGatewayStore.d.ts.map +1 -1
  41. package/dist/vendor/codali/gateway/CodaliGatewayStore.js +1 -0
  42. package/dist/vendor/codali/gateway/GatewayPlanner.d.ts.map +1 -1
  43. package/dist/vendor/codali/gateway/GatewayPlanner.js +355 -41
  44. package/dist/vendor/codali/gateway/GatewayStateMachine.d.ts +1 -0
  45. package/dist/vendor/codali/gateway/GatewayStateMachine.d.ts.map +1 -1
  46. package/dist/vendor/codali/gateway/GatewayStateMachine.js +221 -5
  47. package/dist/vendor/codali/improvement/CandidateReleaseBuilder.d.ts +201 -0
  48. package/dist/vendor/codali/improvement/CandidateReleaseBuilder.d.ts.map +1 -0
  49. package/dist/vendor/codali/improvement/CandidateReleaseBuilder.js +1175 -0
  50. package/dist/vendor/codali/improvement/DatasetEligibilityGate.d.ts +75 -0
  51. package/dist/vendor/codali/improvement/DatasetEligibilityGate.d.ts.map +1 -0
  52. package/dist/vendor/codali/improvement/DatasetEligibilityGate.js +497 -0
  53. package/dist/vendor/codali/improvement/DatasetExportManifestReader.d.ts +88 -0
  54. package/dist/vendor/codali/improvement/DatasetExportManifestReader.d.ts.map +1 -0
  55. package/dist/vendor/codali/improvement/DatasetExportManifestReader.js +333 -0
  56. package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.d.ts +192 -0
  57. package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.d.ts.map +1 -0
  58. package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.js +625 -0
  59. package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.d.ts +173 -0
  60. package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.d.ts.map +1 -0
  61. package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.js +363 -0
  62. package/dist/vendor/codali/improvement/FineTuneJobPlanner.d.ts +281 -0
  63. package/dist/vendor/codali/improvement/FineTuneJobPlanner.d.ts.map +1 -0
  64. package/dist/vendor/codali/improvement/FineTuneJobPlanner.js +823 -0
  65. package/dist/vendor/codali/improvement/ImprovementEvalRunner.d.ts +50 -0
  66. package/dist/vendor/codali/improvement/ImprovementEvalRunner.d.ts.map +1 -0
  67. package/dist/vendor/codali/improvement/ImprovementEvalRunner.js +648 -0
  68. package/dist/vendor/codali/improvement/ImprovementPolicy.d.ts +272 -0
  69. package/dist/vendor/codali/improvement/ImprovementPolicy.d.ts.map +1 -0
  70. package/dist/vendor/codali/improvement/ImprovementPolicy.js +1450 -0
  71. package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.d.ts +186 -0
  72. package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.d.ts.map +1 -0
  73. package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.js +880 -0
  74. package/dist/vendor/codali/improvement/OperatorInspector.d.ts +182 -0
  75. package/dist/vendor/codali/improvement/OperatorInspector.d.ts.map +1 -0
  76. package/dist/vendor/codali/improvement/OperatorInspector.js +604 -0
  77. package/dist/vendor/codali/improvement/ProductionGovernance.d.ts +91 -0
  78. package/dist/vendor/codali/improvement/ProductionGovernance.d.ts.map +1 -0
  79. package/dist/vendor/codali/improvement/ProductionGovernance.js +329 -0
  80. package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.d.ts +152 -0
  81. package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.d.ts.map +1 -0
  82. package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.js +480 -0
  83. package/dist/vendor/codali/improvement/PublishOrchestrator.d.ts +113 -0
  84. package/dist/vendor/codali/improvement/PublishOrchestrator.d.ts.map +1 -0
  85. package/dist/vendor/codali/improvement/PublishOrchestrator.js +590 -0
  86. package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.d.ts +133 -0
  87. package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.d.ts.map +1 -0
  88. package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.js +501 -0
  89. package/dist/vendor/codali/improvement/StorageServiceImprovementClient.d.ts +71 -0
  90. package/dist/vendor/codali/improvement/StorageServiceImprovementClient.d.ts.map +1 -0
  91. package/dist/vendor/codali/improvement/StorageServiceImprovementClient.js +245 -0
  92. package/dist/vendor/codali/index.d.ts +43 -0
  93. package/dist/vendor/codali/index.d.ts.map +1 -1
  94. package/dist/vendor/codali/index.js +21 -0
  95. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +0 -2
  96. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
  97. package/dist/vendor/codali/runtime/CodaliRuntime.js +0 -5
  98. package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.d.ts +138 -0
  99. package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.d.ts.map +1 -0
  100. package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.js +417 -0
  101. package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.d.ts +50 -0
  102. package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.d.ts.map +1 -0
  103. package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.js +141 -0
  104. package/dist/vendor/codali/storage/CodaliStorageContracts.d.ts +337 -0
  105. package/dist/vendor/codali/storage/CodaliStorageContracts.d.ts.map +1 -0
  106. package/dist/vendor/codali/storage/CodaliStorageContracts.js +1555 -0
  107. package/dist/vendor/codali/storage/DatasetExportJob.d.ts +51 -0
  108. package/dist/vendor/codali/storage/DatasetExportJob.d.ts.map +1 -0
  109. package/dist/vendor/codali/storage/DatasetExportJob.js +358 -0
  110. package/dist/vendor/codali/storage/DatasetReviewQueue.d.ts +98 -0
  111. package/dist/vendor/codali/storage/DatasetReviewQueue.d.ts.map +1 -0
  112. package/dist/vendor/codali/storage/DatasetReviewQueue.js +426 -0
  113. package/dist/vendor/codali/storage/GatewayDatasetStore.d.ts +233 -0
  114. package/dist/vendor/codali/storage/GatewayDatasetStore.d.ts.map +1 -0
  115. package/dist/vendor/codali/storage/GatewayDatasetStore.js +2070 -0
  116. package/package.json +3 -3
@@ -0,0 +1,173 @@
1
+ import { type CodaliStorageDatasetKind, type CodaliStorageExportKind, type CodaliStorageObjectPrivacyFlags } from "../storage/CodaliStorageContracts.js";
2
+ import { CODALI_DATASET_REPLAY_FIXTURE_SCHEMA_VERSION } from "../storage/DatasetExportJob.js";
3
+ import type { DatasetEligibilityGateAcceptedExample, DatasetEligibilityGateRejectedExample } from "./DatasetEligibilityGate.js";
4
+ import type { DatasetExportManifestReaderResult } from "./DatasetExportManifestReader.js";
5
+ export declare const CODALI_EVAL_REPLAY_CANDIDATE_SCHEMA_VERSION: "codali.improvement.eval_replay_candidate.v1";
6
+ export type CodaliEvalReplayProposalArtifact = "eval";
7
+ export interface CodaliEvalReplayObjectRefSummary {
8
+ refId: string;
9
+ kind: string;
10
+ contentHash: string;
11
+ byteSize: number;
12
+ mimeType: string;
13
+ deletionGroupId: string;
14
+ privacyFlags: CodaliStorageObjectPrivacyFlags;
15
+ uri?: string;
16
+ mediaType?: string;
17
+ metadataKeys: string[];
18
+ }
19
+ export interface CodaliEvalReplayRecordShape {
20
+ requiredFields: string[];
21
+ optionalRefFields: string[];
22
+ presentFields: string[];
23
+ missingRequiredFields: string[];
24
+ bodyPolicy: "object_refs_only";
25
+ }
26
+ export interface CodaliEvalReplayRecordRefSummary {
27
+ recordId: string;
28
+ datasetKind?: CodaliStorageDatasetKind;
29
+ sourceGatewayRecordId?: string;
30
+ inputRef?: CodaliEvalReplayObjectRefSummary;
31
+ outputRef?: CodaliEvalReplayObjectRefSummary;
32
+ evidenceRefs: CodaliEvalReplayObjectRefSummary[];
33
+ quality?: {
34
+ score?: number;
35
+ reviewed?: boolean;
36
+ labels: string[];
37
+ };
38
+ metadataShape: {
39
+ keys: string[];
40
+ evalStage?: string;
41
+ exampleType?: string;
42
+ role?: string;
43
+ tool?: string;
44
+ sourceType?: string;
45
+ };
46
+ expectedShape: CodaliEvalReplayRecordShape;
47
+ }
48
+ export interface CodaliEvalReplayAcceptedEvidence {
49
+ recordId: string;
50
+ sourceGatewayRecordId?: string;
51
+ lineageKey: DatasetEligibilityGateAcceptedExample["lineageKey"];
52
+ deletionGroupIds: string[];
53
+ runIds: string[];
54
+ artifactTypes: string[];
55
+ preferenceSignals: string[];
56
+ priorityScore: number;
57
+ recordShape: CodaliEvalReplayRecordShape;
58
+ objectRefs: {
59
+ inputRef?: CodaliEvalReplayObjectRefSummary;
60
+ outputRef?: CodaliEvalReplayObjectRefSummary;
61
+ evidenceRefs: CodaliEvalReplayObjectRefSummary[];
62
+ };
63
+ }
64
+ export interface CodaliEvalReplayRejectedEvidence {
65
+ targetType: DatasetEligibilityGateRejectedExample["targetType"];
66
+ recordId?: string;
67
+ dedupeKey?: string;
68
+ failureLabels: string[];
69
+ reasons: Array<{
70
+ code: string;
71
+ message: string;
72
+ path?: string;
73
+ details?: Record<string, unknown>;
74
+ }>;
75
+ }
76
+ export interface CodaliEvalReplayExpectedShape {
77
+ schemaVersion: typeof CODALI_EVAL_REPLAY_CANDIDATE_SCHEMA_VERSION;
78
+ artifact: CodaliEvalReplayProposalArtifact;
79
+ evalFixture: {
80
+ requiredFields: string[];
81
+ caseRequiredFields: string[];
82
+ evidenceFields: string[];
83
+ bodyPolicy: "object_refs_only";
84
+ };
85
+ replayFixture: {
86
+ schemaVersion: typeof CODALI_DATASET_REPLAY_FIXTURE_SCHEMA_VERSION;
87
+ requiredFields: string[];
88
+ recordRequiredFields: string[];
89
+ bodyPolicy: "object_refs_only";
90
+ };
91
+ }
92
+ export interface CodaliEvalFixtureCandidate {
93
+ fixtureId: string;
94
+ sourceExportId: string;
95
+ caseCount: number;
96
+ cases: Array<{
97
+ caseId: string;
98
+ sourceRecordId: string;
99
+ datasetKind?: CodaliStorageDatasetKind;
100
+ expectedShape: CodaliEvalReplayRecordShape;
101
+ acceptedEvidenceRecordId: string;
102
+ rejectedEvidenceRecordIds: string[];
103
+ failureLabels: string[];
104
+ objectRefs: {
105
+ inputRef?: CodaliEvalReplayObjectRefSummary;
106
+ outputRef?: CodaliEvalReplayObjectRefSummary;
107
+ evidenceRefs: CodaliEvalReplayObjectRefSummary[];
108
+ };
109
+ }>;
110
+ }
111
+ export interface CodaliReplayFixtureCandidate {
112
+ fixtureId: string;
113
+ schemaVersion: typeof CODALI_DATASET_REPLAY_FIXTURE_SCHEMA_VERSION;
114
+ sourceExportId: string;
115
+ exportKind: CodaliStorageExportKind;
116
+ generatedAt: string;
117
+ bodyStorage: "object_ref" | "record_refs_only";
118
+ bodyRef?: CodaliEvalReplayObjectRefSummary;
119
+ recordCount: number;
120
+ records: CodaliEvalReplayRecordRefSummary[];
121
+ }
122
+ export interface CodaliEvalReplayImprovementCandidateSummary {
123
+ candidateId: string;
124
+ candidateKind: "eval_replay";
125
+ status: "proposed" | "blocked";
126
+ fixtureIds: {
127
+ evalFixtureId: string;
128
+ replayFixtureId: string;
129
+ };
130
+ sourceExportIds: string[];
131
+ sourceRecordIds: string[];
132
+ artifactIds: string[];
133
+ exampleCount: number;
134
+ objectBytes: number;
135
+ failureLabels: string[];
136
+ }
137
+ export interface CodaliEvalReplayCandidateBundle {
138
+ schemaVersion: typeof CODALI_EVAL_REPLAY_CANDIDATE_SCHEMA_VERSION;
139
+ artifact: CodaliEvalReplayProposalArtifact;
140
+ source: {
141
+ exportId: string;
142
+ manifestId: string;
143
+ manifestPath: string;
144
+ exportKind: CodaliStorageExportKind;
145
+ checksum: string;
146
+ recordCount: number;
147
+ primaryArtifactRef: CodaliEvalReplayObjectRefSummary;
148
+ replayFixtureRef?: CodaliEvalReplayObjectRefSummary;
149
+ };
150
+ generationPolicy: {
151
+ deterministic: true;
152
+ modifiesRuntimePrompts: false;
153
+ modifiesRuntimeCode: false;
154
+ bodyPolicy: "object_refs_only";
155
+ };
156
+ expectedShape: CodaliEvalReplayExpectedShape;
157
+ fixtureIds: {
158
+ evalFixtureId: string;
159
+ replayFixtureId: string;
160
+ };
161
+ acceptedEvidence: CodaliEvalReplayAcceptedEvidence[];
162
+ rejectedEvidence: CodaliEvalReplayRejectedEvidence[];
163
+ failureLabels: string[];
164
+ evalFixture: CodaliEvalFixtureCandidate;
165
+ replayFixture: CodaliReplayFixtureCandidate;
166
+ candidates: CodaliEvalReplayImprovementCandidateSummary[];
167
+ }
168
+ export interface BuildCodaliEvalReplayCandidateBundleInput {
169
+ inspection: DatasetExportManifestReaderResult;
170
+ artifact?: CodaliEvalReplayProposalArtifact;
171
+ }
172
+ export declare const buildCodaliEvalReplayCandidateBundle: (input: BuildCodaliEvalReplayCandidateBundleInput) => CodaliEvalReplayCandidateBundle;
173
+ //# sourceMappingURL=EvalReplayCandidateBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EvalReplayCandidateBuilder.d.ts","sourceRoot":"","sources":["../../src/improvement/EvalReplayCandidateBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,+BAA+B,EAErC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,4CAA4C,EAAE,MAAM,gCAAgC,CAAC;AAC9F,OAAO,KAAK,EACV,qCAAqC,EACrC,qCAAqC,EAEtC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,kCAAkC,CAAC;AAE1F,eAAO,MAAM,2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,MAAM,WAAW,yCAAyC;IACxD,UAAU,EAAE,iCAAiC,CAAC;IAC9C,QAAQ,CAAC,EAAE,gCAAgC,CAAC;CAC7C;AAuTD,eAAO,MAAM,oCAAoC,GAC/C,OAAO,yCAAyC,KAC/C,+BAyHF,CAAC"}
@@ -0,0 +1,363 @@
1
+ import { createHash } from "node:crypto";
2
+ import { CODALI_DATASET_REPLAY_FIXTURE_SCHEMA_VERSION } from "../storage/DatasetExportJob.js";
3
+ export const CODALI_EVAL_REPLAY_CANDIDATE_SCHEMA_VERSION = "codali.improvement.eval_replay_candidate.v1";
4
+ const isRecord = (value) => Boolean(value && typeof value === "object" && !Array.isArray(value));
5
+ const stableJson = (value) => {
6
+ if (Array.isArray(value))
7
+ return `[${value.map(stableJson).join(",")}]`;
8
+ if (!isRecord(value))
9
+ return JSON.stringify(value);
10
+ return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(",")}}`;
11
+ };
12
+ const sha256Hex = (value) => createHash("sha256").update(stableJson(value)).digest("hex");
13
+ const stableId = (prefix, value) => `${prefix}-${sha256Hex(value).slice(0, 16)}`;
14
+ const uniqueSorted = (values) => Array.from(new Set(values
15
+ .map((value) => value?.trim())
16
+ .filter((value) => Boolean(value))))
17
+ .sort();
18
+ const readString = (record, keys) => {
19
+ for (const key of keys) {
20
+ const value = record?.[key];
21
+ if (typeof value === "string" && value.trim())
22
+ return value.trim();
23
+ }
24
+ return undefined;
25
+ };
26
+ const readNumber = (record, key) => {
27
+ const value = record?.[key];
28
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
29
+ };
30
+ const readBoolean = (record, key) => {
31
+ const value = record?.[key];
32
+ return typeof value === "boolean" ? value : undefined;
33
+ };
34
+ const stringList = (value) => Array.isArray(value)
35
+ ? value.filter((entry) => typeof entry === "string")
36
+ : [];
37
+ const objectRefFromValue = (value) => isRecord(value) &&
38
+ typeof value.refId === "string" &&
39
+ typeof value.contentHash === "string" &&
40
+ typeof value.byteSize === "number" &&
41
+ typeof value.mimeType === "string" &&
42
+ typeof value.deletionGroupId === "string" &&
43
+ isRecord(value.privacyFlags)
44
+ ? value
45
+ : undefined;
46
+ const summarizeObjectRef = (ref) => ({
47
+ refId: ref.refId,
48
+ kind: ref.kind,
49
+ contentHash: ref.contentHash,
50
+ byteSize: ref.byteSize,
51
+ mimeType: ref.mimeType,
52
+ deletionGroupId: ref.deletionGroupId,
53
+ privacyFlags: ref.privacyFlags,
54
+ ...(ref.uri ? { uri: ref.uri } : {}),
55
+ ...(ref.mediaType ? { mediaType: ref.mediaType } : {}),
56
+ metadataKeys: isRecord(ref.metadata) ? Object.keys(ref.metadata).sort() : [],
57
+ });
58
+ const refsForRow = (row) => {
59
+ const record = isRecord(row) ? row : {};
60
+ const evidenceRefs = Array.isArray(record.evidenceRefs)
61
+ ? record.evidenceRefs.map(objectRefFromValue)
62
+ .filter((ref) => Boolean(ref))
63
+ : [];
64
+ return {
65
+ inputRef: objectRefFromValue(record.inputRef),
66
+ outputRef: objectRefFromValue(record.outputRef),
67
+ evidenceRefs,
68
+ };
69
+ };
70
+ const recordIdForRow = (row) => isRecord(row) ? readString(row, ["recordId", "record_id"]) : undefined;
71
+ const rowsByRecordId = (rows) => {
72
+ const output = new Map();
73
+ for (const row of rows) {
74
+ if (!isRecord(row))
75
+ continue;
76
+ const recordId = recordIdForRow(row);
77
+ if (recordId)
78
+ output.set(recordId, row);
79
+ }
80
+ return output;
81
+ };
82
+ const expectedRecordShape = (row) => {
83
+ const presentFields = isRecord(row) ? Object.keys(row).sort() : [];
84
+ const requiredFields = ["datasetKind", "inputRef", "privacy", "recordId"];
85
+ return {
86
+ requiredFields,
87
+ optionalRefFields: ["outputRef", "evidenceRefs"],
88
+ presentFields,
89
+ missingRequiredFields: requiredFields
90
+ .filter((field) => !presentFields.includes(field)),
91
+ bodyPolicy: "object_refs_only",
92
+ };
93
+ };
94
+ const metadataShapeForRow = (row) => {
95
+ const metadata = isRecord(row.metadata) ? row.metadata : {};
96
+ return {
97
+ keys: Object.keys(metadata).sort(),
98
+ ...(readString(metadata, ["evalStage", "eval_stage", "gatewayEvalStage", "gateway_eval_stage"])
99
+ ? { evalStage: readString(metadata, ["evalStage", "eval_stage", "gatewayEvalStage", "gateway_eval_stage"]) }
100
+ : {}),
101
+ ...(readString(metadata, ["exampleType", "example_type"])
102
+ ? { exampleType: readString(metadata, ["exampleType", "example_type"]) }
103
+ : {}),
104
+ ...(readString(metadata, ["role"]) ? { role: readString(metadata, ["role"]) } : {}),
105
+ ...(readString(metadata, ["tool"]) ? { tool: readString(metadata, ["tool"]) } : {}),
106
+ ...(readString(metadata, ["sourceType", "source_type"])
107
+ ? { sourceType: readString(metadata, ["sourceType", "source_type"]) }
108
+ : {}),
109
+ };
110
+ };
111
+ const summarizeRecordRow = (row) => {
112
+ const refs = refsForRow(row);
113
+ const quality = isRecord(row.quality) ? row.quality : undefined;
114
+ return {
115
+ recordId: readString(row, ["recordId", "record_id"]) ?? "unknown-record",
116
+ ...(readString(row, ["datasetKind", "dataset_kind"])
117
+ ? { datasetKind: readString(row, ["datasetKind", "dataset_kind"]) }
118
+ : {}),
119
+ ...(readString(row, ["sourceGatewayRecordId", "source_gateway_record_id"])
120
+ ? { sourceGatewayRecordId: readString(row, ["sourceGatewayRecordId", "source_gateway_record_id"]) }
121
+ : {}),
122
+ ...(refs.inputRef ? { inputRef: summarizeObjectRef(refs.inputRef) } : {}),
123
+ ...(refs.outputRef ? { outputRef: summarizeObjectRef(refs.outputRef) } : {}),
124
+ evidenceRefs: refs.evidenceRefs.map(summarizeObjectRef),
125
+ ...(quality ? {
126
+ quality: {
127
+ score: readNumber(quality, "score"),
128
+ reviewed: readBoolean(quality, "reviewed"),
129
+ labels: stringList(quality.labels).sort(),
130
+ },
131
+ } : {}),
132
+ metadataShape: metadataShapeForRow(row),
133
+ expectedShape: expectedRecordShape(row),
134
+ };
135
+ };
136
+ const failureLabelsForReasons = (reasons) => uniqueSorted(reasons.map((reason) => reason.code));
137
+ const rejectedEvidence = (rejected) => rejected.map((item) => ({
138
+ targetType: item.targetType,
139
+ ...(item.recordId ? { recordId: item.recordId } : {}),
140
+ ...(item.dedupeKey ? { dedupeKey: item.dedupeKey } : {}),
141
+ failureLabels: failureLabelsForReasons(item.reasons),
142
+ reasons: item.reasons.map((reason) => ({
143
+ code: reason.code,
144
+ message: reason.message,
145
+ ...(reason.path ? { path: reason.path } : {}),
146
+ ...(reason.details ? { details: reason.details } : {}),
147
+ })),
148
+ }));
149
+ const acceptedEvidence = (accepted, rowMap) => accepted.map((item) => {
150
+ const row = rowMap.get(item.recordId);
151
+ const refs = refsForRow(row);
152
+ return {
153
+ recordId: item.recordId,
154
+ ...(item.sourceGatewayRecordId ? { sourceGatewayRecordId: item.sourceGatewayRecordId } : {}),
155
+ lineageKey: item.lineageKey,
156
+ deletionGroupIds: item.deletionGroupIds,
157
+ runIds: item.runIds,
158
+ artifactTypes: item.artifactTypes,
159
+ preferenceSignals: item.preferenceSignals,
160
+ priorityScore: item.priorityScore,
161
+ recordShape: expectedRecordShape(row),
162
+ objectRefs: {
163
+ ...(refs.inputRef ? { inputRef: summarizeObjectRef(refs.inputRef) } : {}),
164
+ ...(refs.outputRef ? { outputRef: summarizeObjectRef(refs.outputRef) } : {}),
165
+ evidenceRefs: refs.evidenceRefs.map(summarizeObjectRef),
166
+ },
167
+ };
168
+ });
169
+ const allFailureLabels = (inspection) => {
170
+ const curationLabels = inspection.curationReport.rejected
171
+ .flatMap((item) => item.reasons.map((reason) => reason.code));
172
+ const warningLabels = inspection.warnings.map((warning) => warning.code);
173
+ return uniqueSorted([
174
+ ...curationLabels,
175
+ ...warningLabels,
176
+ inspection.curationReport.acceptedCount === 0 ? "no_accepted_examples" : undefined,
177
+ inspection.manifest.exportKind !== "eval-replay" ? "export_kind_not_eval_replay" : undefined,
178
+ inspection.curationReport.artifactReadAllowed ? undefined : "artifact_payload_read_blocked",
179
+ inspection.curationReport.lineageValid ? undefined : "lineage_invalid",
180
+ ]);
181
+ };
182
+ const replayFixtureRefForInspection = (inspection) => inspection.manifest.artifactRefs.find((ref) => {
183
+ const metadata = isRecord(ref.metadata) ? ref.metadata : {};
184
+ return readString(metadata, ["artifactType", "artifact_type"]) === "replay_fixture";
185
+ });
186
+ const primaryArtifactRefForInspection = (inspection) => {
187
+ const ref = inspection.primaryArtifact?.ref ?? inspection.manifest.artifactRefs[0];
188
+ if (!ref) {
189
+ throw new Error("CODALI_EVAL_REPLAY_PRIMARY_ARTIFACT_MISSING");
190
+ }
191
+ return ref;
192
+ };
193
+ const expectedShape = (artifact) => ({
194
+ schemaVersion: CODALI_EVAL_REPLAY_CANDIDATE_SCHEMA_VERSION,
195
+ artifact,
196
+ evalFixture: {
197
+ requiredFields: [
198
+ "fixtureId",
199
+ "cases",
200
+ "acceptedEvidence",
201
+ "rejectedEvidence",
202
+ "failureLabels",
203
+ ],
204
+ caseRequiredFields: [
205
+ "caseId",
206
+ "sourceRecordId",
207
+ "expectedShape",
208
+ "objectRefs",
209
+ ],
210
+ evidenceFields: [
211
+ "recordId",
212
+ "lineageKey",
213
+ "artifactTypes",
214
+ "preferenceSignals",
215
+ ],
216
+ bodyPolicy: "object_refs_only",
217
+ },
218
+ replayFixture: {
219
+ schemaVersion: CODALI_DATASET_REPLAY_FIXTURE_SCHEMA_VERSION,
220
+ requiredFields: ["fixtureId", "schemaVersion", "records"],
221
+ recordRequiredFields: ["recordId", "datasetKind", "inputRef"],
222
+ bodyPolicy: "object_refs_only",
223
+ },
224
+ });
225
+ const objectBytesForRecords = (rows, replayFixtureRef) => {
226
+ const refs = new Map();
227
+ for (const row of rows) {
228
+ const rowRefs = refsForRow(row);
229
+ for (const ref of [
230
+ rowRefs.inputRef,
231
+ rowRefs.outputRef,
232
+ ...rowRefs.evidenceRefs,
233
+ ]) {
234
+ if (ref)
235
+ refs.set(`${ref.refId}:${ref.contentHash}`, ref);
236
+ }
237
+ }
238
+ if (replayFixtureRef) {
239
+ refs.set(`${replayFixtureRef.refId}:${replayFixtureRef.contentHash}`, replayFixtureRef);
240
+ }
241
+ return Array.from(refs.values())
242
+ .reduce((total, ref) => total + ref.byteSize, 0);
243
+ };
244
+ export const buildCodaliEvalReplayCandidateBundle = (input) => {
245
+ const artifact = input.artifact ?? "eval";
246
+ const inspection = input.inspection;
247
+ const rowMap = rowsByRecordId(inspection.primaryArtifactRows);
248
+ const acceptedRows = inspection.curationReport.acceptedRecordIds
249
+ .map((recordId) => rowMap.get(recordId))
250
+ .filter((row) => Boolean(row));
251
+ const replayFixtureRef = replayFixtureRefForInspection(inspection);
252
+ const failureLabels = allFailureLabels(inspection);
253
+ const idSeed = {
254
+ artifact,
255
+ manifestId: inspection.manifest.manifestId,
256
+ checksum: inspection.manifest.checksum,
257
+ acceptedRecordIds: inspection.curationReport.acceptedRecordIds,
258
+ failureLabels,
259
+ };
260
+ const evalFixtureId = stableId("eval-fixture", idSeed);
261
+ const replayFixtureId = stableId("replay-fixture", {
262
+ ...idSeed,
263
+ replayFixtureContentHash: replayFixtureRef?.contentHash,
264
+ });
265
+ const candidateId = stableId("candidate", {
266
+ ...idSeed,
267
+ evalFixtureId,
268
+ replayFixtureId,
269
+ });
270
+ const accepted = acceptedEvidence(inspection.curationReport.accepted, rowMap);
271
+ const rejected = rejectedEvidence(inspection.curationReport.rejected);
272
+ const replayRecords = acceptedRows.map(summarizeRecordRow);
273
+ const evalCases = replayRecords.map((record) => ({
274
+ caseId: stableId("eval-case", {
275
+ evalFixtureId,
276
+ recordId: record.recordId,
277
+ inputHash: record.inputRef?.contentHash,
278
+ outputHash: record.outputRef?.contentHash,
279
+ }),
280
+ sourceRecordId: record.recordId,
281
+ ...(record.datasetKind ? { datasetKind: record.datasetKind } : {}),
282
+ expectedShape: record.expectedShape,
283
+ acceptedEvidenceRecordId: record.recordId,
284
+ rejectedEvidenceRecordIds: rejected
285
+ .filter((item) => item.recordId === record.recordId)
286
+ .map((item) => item.recordId)
287
+ .filter((recordId) => Boolean(recordId)),
288
+ failureLabels: rejected
289
+ .filter((item) => item.recordId === record.recordId)
290
+ .flatMap((item) => item.failureLabels),
291
+ objectRefs: {
292
+ ...(record.inputRef ? { inputRef: record.inputRef } : {}),
293
+ ...(record.outputRef ? { outputRef: record.outputRef } : {}),
294
+ evidenceRefs: record.evidenceRefs,
295
+ },
296
+ }));
297
+ const candidateStatus = acceptedRows.length > 0 &&
298
+ inspection.manifest.exportKind === "eval-replay" &&
299
+ inspection.curationReport.artifactReadAllowed &&
300
+ inspection.curationReport.lineageValid
301
+ ? "proposed"
302
+ : "blocked";
303
+ return {
304
+ schemaVersion: CODALI_EVAL_REPLAY_CANDIDATE_SCHEMA_VERSION,
305
+ artifact,
306
+ source: {
307
+ exportId: inspection.exportId,
308
+ manifestId: inspection.manifest.manifestId,
309
+ manifestPath: inspection.manifestPath,
310
+ exportKind: inspection.manifest.exportKind,
311
+ checksum: inspection.manifest.checksum,
312
+ recordCount: inspection.manifest.recordCount,
313
+ primaryArtifactRef: summarizeObjectRef(primaryArtifactRefForInspection(inspection)),
314
+ ...(replayFixtureRef ? { replayFixtureRef: summarizeObjectRef(replayFixtureRef) } : {}),
315
+ },
316
+ generationPolicy: {
317
+ deterministic: true,
318
+ modifiesRuntimePrompts: false,
319
+ modifiesRuntimeCode: false,
320
+ bodyPolicy: "object_refs_only",
321
+ },
322
+ expectedShape: expectedShape(artifact),
323
+ fixtureIds: {
324
+ evalFixtureId,
325
+ replayFixtureId,
326
+ },
327
+ acceptedEvidence: accepted,
328
+ rejectedEvidence: rejected,
329
+ failureLabels,
330
+ evalFixture: {
331
+ fixtureId: evalFixtureId,
332
+ sourceExportId: inspection.manifest.manifestId,
333
+ caseCount: evalCases.length,
334
+ cases: evalCases,
335
+ },
336
+ replayFixture: {
337
+ fixtureId: replayFixtureId,
338
+ schemaVersion: CODALI_DATASET_REPLAY_FIXTURE_SCHEMA_VERSION,
339
+ sourceExportId: inspection.manifest.manifestId,
340
+ exportKind: inspection.manifest.exportKind,
341
+ generatedAt: inspection.manifest.createdAt,
342
+ bodyStorage: replayFixtureRef ? "object_ref" : "record_refs_only",
343
+ ...(replayFixtureRef ? { bodyRef: summarizeObjectRef(replayFixtureRef) } : {}),
344
+ recordCount: replayRecords.length,
345
+ records: replayRecords,
346
+ },
347
+ candidates: [{
348
+ candidateId,
349
+ candidateKind: "eval_replay",
350
+ status: candidateStatus,
351
+ fixtureIds: {
352
+ evalFixtureId,
353
+ replayFixtureId,
354
+ },
355
+ sourceExportIds: [inspection.manifest.manifestId],
356
+ sourceRecordIds: inspection.curationReport.acceptedRecordIds,
357
+ artifactIds: inspection.manifest.artifactRefs.map((ref) => ref.refId),
358
+ exampleCount: acceptedRows.length,
359
+ objectBytes: objectBytesForRecords(acceptedRows, replayFixtureRef),
360
+ failureLabels,
361
+ }],
362
+ };
363
+ };