@mcoda/mswarm 0.1.90 → 0.1.94

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 (113) 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 +4 -2
  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/vendor/codali/cli/DatasetCommand.d.ts +38 -0
  10. package/dist/vendor/codali/cli/DatasetCommand.d.ts.map +1 -0
  11. package/dist/vendor/codali/cli/DatasetCommand.js +959 -0
  12. package/dist/vendor/codali/cli/EvalCommand.d.ts +3 -0
  13. package/dist/vendor/codali/cli/EvalCommand.d.ts.map +1 -1
  14. package/dist/vendor/codali/cli/EvalCommand.js +55 -1
  15. package/dist/vendor/codali/cli/ImprovementCommand.d.ts +97 -0
  16. package/dist/vendor/codali/cli/ImprovementCommand.d.ts.map +1 -0
  17. package/dist/vendor/codali/cli/ImprovementCommand.js +1879 -0
  18. package/dist/vendor/codali/cli.d.ts.map +1 -1
  19. package/dist/vendor/codali/cli.js +15 -0
  20. package/dist/vendor/codali/dataset-cli.d.ts +3 -0
  21. package/dist/vendor/codali/dataset-cli.d.ts.map +1 -0
  22. package/dist/vendor/codali/dataset-cli.js +30 -0
  23. package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.d.ts +90 -1
  24. package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.d.ts.map +1 -1
  25. package/dist/vendor/codali/eval/CodaliGatewayLiveHarness.js +443 -9
  26. package/dist/vendor/codali/eval/GatewayDatasetEval.d.ts +70 -0
  27. package/dist/vendor/codali/eval/GatewayDatasetEval.d.ts.map +1 -0
  28. package/dist/vendor/codali/eval/GatewayDatasetEval.js +477 -0
  29. package/dist/vendor/codali/eval/GatewayEvalSuite.d.ts +52 -0
  30. package/dist/vendor/codali/eval/GatewayEvalSuite.d.ts.map +1 -1
  31. package/dist/vendor/codali/eval/GatewayEvalSuite.js +135 -1
  32. package/dist/vendor/codali/gateway/CodaliGateway.d.ts +4 -0
  33. package/dist/vendor/codali/gateway/CodaliGateway.d.ts.map +1 -1
  34. package/dist/vendor/codali/gateway/CodaliGateway.js +37 -1
  35. package/dist/vendor/codali/gateway/CodaliGatewaySchemas.d.ts.map +1 -1
  36. package/dist/vendor/codali/gateway/CodaliGatewaySchemas.js +0 -4
  37. package/dist/vendor/codali/gateway/CodaliGatewayStore.d.ts.map +1 -1
  38. package/dist/vendor/codali/gateway/CodaliGatewayStore.js +1 -0
  39. package/dist/vendor/codali/gateway/GatewayPlanner.d.ts.map +1 -1
  40. package/dist/vendor/codali/gateway/GatewayPlanner.js +355 -41
  41. package/dist/vendor/codali/gateway/GatewayStateMachine.d.ts +1 -0
  42. package/dist/vendor/codali/gateway/GatewayStateMachine.d.ts.map +1 -1
  43. package/dist/vendor/codali/gateway/GatewayStateMachine.js +221 -5
  44. package/dist/vendor/codali/improvement/CandidateReleaseBuilder.d.ts +201 -0
  45. package/dist/vendor/codali/improvement/CandidateReleaseBuilder.d.ts.map +1 -0
  46. package/dist/vendor/codali/improvement/CandidateReleaseBuilder.js +1175 -0
  47. package/dist/vendor/codali/improvement/DatasetEligibilityGate.d.ts +75 -0
  48. package/dist/vendor/codali/improvement/DatasetEligibilityGate.d.ts.map +1 -0
  49. package/dist/vendor/codali/improvement/DatasetEligibilityGate.js +497 -0
  50. package/dist/vendor/codali/improvement/DatasetExportManifestReader.d.ts +88 -0
  51. package/dist/vendor/codali/improvement/DatasetExportManifestReader.d.ts.map +1 -0
  52. package/dist/vendor/codali/improvement/DatasetExportManifestReader.js +333 -0
  53. package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.d.ts +192 -0
  54. package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.d.ts.map +1 -0
  55. package/dist/vendor/codali/improvement/DocdexRetrievalCandidateBuilder.js +625 -0
  56. package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.d.ts +173 -0
  57. package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.d.ts.map +1 -0
  58. package/dist/vendor/codali/improvement/EvalReplayCandidateBuilder.js +363 -0
  59. package/dist/vendor/codali/improvement/FineTuneJobPlanner.d.ts +281 -0
  60. package/dist/vendor/codali/improvement/FineTuneJobPlanner.d.ts.map +1 -0
  61. package/dist/vendor/codali/improvement/FineTuneJobPlanner.js +823 -0
  62. package/dist/vendor/codali/improvement/ImprovementEvalRunner.d.ts +50 -0
  63. package/dist/vendor/codali/improvement/ImprovementEvalRunner.d.ts.map +1 -0
  64. package/dist/vendor/codali/improvement/ImprovementEvalRunner.js +648 -0
  65. package/dist/vendor/codali/improvement/ImprovementPolicy.d.ts +272 -0
  66. package/dist/vendor/codali/improvement/ImprovementPolicy.d.ts.map +1 -0
  67. package/dist/vendor/codali/improvement/ImprovementPolicy.js +1450 -0
  68. package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.d.ts +186 -0
  69. package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.d.ts.map +1 -0
  70. package/dist/vendor/codali/improvement/ModelRouterCandidateBuilder.js +880 -0
  71. package/dist/vendor/codali/improvement/OperatorInspector.d.ts +182 -0
  72. package/dist/vendor/codali/improvement/OperatorInspector.d.ts.map +1 -0
  73. package/dist/vendor/codali/improvement/OperatorInspector.js +604 -0
  74. package/dist/vendor/codali/improvement/ProductionGovernance.d.ts +91 -0
  75. package/dist/vendor/codali/improvement/ProductionGovernance.d.ts.map +1 -0
  76. package/dist/vendor/codali/improvement/ProductionGovernance.js +329 -0
  77. package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.d.ts +152 -0
  78. package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.d.ts.map +1 -0
  79. package/dist/vendor/codali/improvement/PromptSchemaToolMetadataCandidateBuilder.js +480 -0
  80. package/dist/vendor/codali/improvement/PublishOrchestrator.d.ts +113 -0
  81. package/dist/vendor/codali/improvement/PublishOrchestrator.d.ts.map +1 -0
  82. package/dist/vendor/codali/improvement/PublishOrchestrator.js +590 -0
  83. package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.d.ts +133 -0
  84. package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.d.ts.map +1 -0
  85. package/dist/vendor/codali/improvement/ReleaseOutcomeReporter.js +501 -0
  86. package/dist/vendor/codali/improvement/StorageServiceImprovementClient.d.ts +71 -0
  87. package/dist/vendor/codali/improvement/StorageServiceImprovementClient.d.ts.map +1 -0
  88. package/dist/vendor/codali/improvement/StorageServiceImprovementClient.js +245 -0
  89. package/dist/vendor/codali/index.d.ts +43 -0
  90. package/dist/vendor/codali/index.d.ts.map +1 -1
  91. package/dist/vendor/codali/index.js +21 -0
  92. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts +0 -2
  93. package/dist/vendor/codali/runtime/CodaliRuntime.d.ts.map +1 -1
  94. package/dist/vendor/codali/runtime/CodaliRuntime.js +0 -5
  95. package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.d.ts +138 -0
  96. package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.d.ts.map +1 -0
  97. package/dist/vendor/codali/storage/CodaliDatasetPrivacyEngine.js +417 -0
  98. package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.d.ts +50 -0
  99. package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.d.ts.map +1 -0
  100. package/dist/vendor/codali/storage/CodaliFeedbackReviewIngestion.js +141 -0
  101. package/dist/vendor/codali/storage/CodaliStorageContracts.d.ts +337 -0
  102. package/dist/vendor/codali/storage/CodaliStorageContracts.d.ts.map +1 -0
  103. package/dist/vendor/codali/storage/CodaliStorageContracts.js +1555 -0
  104. package/dist/vendor/codali/storage/DatasetExportJob.d.ts +51 -0
  105. package/dist/vendor/codali/storage/DatasetExportJob.d.ts.map +1 -0
  106. package/dist/vendor/codali/storage/DatasetExportJob.js +358 -0
  107. package/dist/vendor/codali/storage/DatasetReviewQueue.d.ts +98 -0
  108. package/dist/vendor/codali/storage/DatasetReviewQueue.d.ts.map +1 -0
  109. package/dist/vendor/codali/storage/DatasetReviewQueue.js +426 -0
  110. package/dist/vendor/codali/storage/GatewayDatasetStore.d.ts +233 -0
  111. package/dist/vendor/codali/storage/GatewayDatasetStore.d.ts.map +1 -0
  112. package/dist/vendor/codali/storage/GatewayDatasetStore.js +2070 -0
  113. package/package.json +3 -3
@@ -0,0 +1,51 @@
1
+ import { type CodaliStorageDatasetRecord, type CodaliStorageExportKind, type CodaliStorageExportManifest, type CodaliStorageObjectRef } from "./CodaliStorageContracts.js";
2
+ import { type CodaliDatasetPrivacyPurpose } from "./CodaliDatasetPrivacyEngine.js";
3
+ import { type GatewayDatasetObjectStore, type GatewayDatasetStorageScope } from "./GatewayDatasetStore.js";
4
+ export declare const CODALI_DATASET_EXPORT_JOB_SCHEMA_VERSION: "codali.dataset.export.job.v1";
5
+ export declare const CODALI_DATASET_REPLAY_FIXTURE_SCHEMA_VERSION: "codali.dataset.replay.fixture.v1";
6
+ export declare const CODALI_DATASET_SFT_EXPORT_KINDS: ("extractor-sft" | "tool-router-sft" | "planner-sft" | "verifier-sft" | "query-expander-sft" | "repair-sft" | "context-refiner-sft")[];
7
+ export type CodaliDatasetExportStatus = "dry_run" | "exported" | "blocked";
8
+ export interface CodaliDatasetExportExclusionReason {
9
+ recordId: string;
10
+ code: string;
11
+ message: string;
12
+ purpose: CodaliDatasetPrivacyPurpose;
13
+ path?: string;
14
+ }
15
+ export interface CodaliDatasetExportDryRunSummary {
16
+ totalCount: number;
17
+ eligibleCount: number;
18
+ excludedCount: number;
19
+ exclusionReasonCounts: Record<string, number>;
20
+ }
21
+ export interface CodaliDatasetExportJobInput {
22
+ exportKind: CodaliStorageExportKind;
23
+ records: CodaliStorageDatasetRecord[];
24
+ objectStore: GatewayDatasetObjectStore;
25
+ scope: GatewayDatasetStorageScope;
26
+ dryRun?: boolean;
27
+ generatedBy?: string;
28
+ manifestId?: string;
29
+ exportFormat?: "jsonl";
30
+ now?: () => Date;
31
+ metadata?: Record<string, unknown>;
32
+ }
33
+ export interface CodaliDatasetExportJobResult {
34
+ schemaVersion: typeof CODALI_DATASET_EXPORT_JOB_SCHEMA_VERSION;
35
+ accepted: boolean;
36
+ status: CodaliDatasetExportStatus;
37
+ dryRun: CodaliDatasetExportDryRunSummary;
38
+ exportKind: CodaliStorageExportKind;
39
+ exportFormat: "jsonl";
40
+ manifest?: CodaliStorageExportManifest;
41
+ manifestRef?: CodaliStorageObjectRef;
42
+ jsonlRef?: CodaliStorageObjectRef;
43
+ replayFixtureRef?: CodaliStorageObjectRef;
44
+ exclusionReasons: CodaliDatasetExportExclusionReason[];
45
+ }
46
+ export declare class CodaliDatasetExportJobError extends Error {
47
+ readonly code: string;
48
+ constructor(code: string, message: string);
49
+ }
50
+ export declare const runCodaliDatasetExportJob: (input: CodaliDatasetExportJobInput) => Promise<CodaliDatasetExportJobResult>;
51
+ //# sourceMappingURL=DatasetExportJob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatasetExportJob.d.ts","sourceRoot":"","sources":["../../src/storage/DatasetExportJob.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,0BAA0B,EAE/B,KAAK,uBAAuB,EAE5B,KAAK,2BAA2B,EAIhC,KAAK,sBAAsB,EAE5B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAGL,KAAK,2BAA2B,EACjC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAIL,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAChC,MAAM,0BAA0B,CAAC;AAElC,eAAO,MAAM,wCAAwC,EAAG,8BAAuC,CAAC;AAChG,eAAO,MAAM,4CAA4C,EACvD,kCAA2C,CAAC;AAE9C,eAAO,MAAM,+BAA+B,wIAE3C,CAAC;AAEF,MAAM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sB,CAAC;IAC1C,gBAAgB,EAAE,kCAAkC,EAAE,CAAC;CACxD;AAED,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAqQD,eAAO,MAAM,yBAAyB,GACpC,OAAO,2BAA2B,KACjC,OAAO,CAAC,4BAA4B,CAiKtC,CAAC"}
@@ -0,0 +1,358 @@
1
+ import { CODALI_STORAGE_CONTRACT_SCHEMA_VERSION, CODALI_STORAGE_EXPORT_KINDS, validateCodaliStorageDatasetRecord, validateCodaliStorageExportManifest, } from "./CodaliStorageContracts.js";
2
+ import { evaluateCodaliDatasetObjectPayloadRead, } from "./CodaliDatasetPrivacyEngine.js";
3
+ import { createGatewayDatasetLocalOnlyObjectPrivacyFlags, createGatewayDatasetLocalOnlyPrivacy, hashGatewayDatasetRequestBody, } from "./GatewayDatasetStore.js";
4
+ export const CODALI_DATASET_EXPORT_JOB_SCHEMA_VERSION = "codali.dataset.export.job.v1";
5
+ export const CODALI_DATASET_REPLAY_FIXTURE_SCHEMA_VERSION = "codali.dataset.replay.fixture.v1";
6
+ export const CODALI_DATASET_SFT_EXPORT_KINDS = CODALI_STORAGE_EXPORT_KINDS.filter((kind) => kind.endsWith("-sft"));
7
+ export class CodaliDatasetExportJobError extends Error {
8
+ constructor(code, message) {
9
+ super(`${code}: ${message}`);
10
+ this.name = "CodaliDatasetExportJobError";
11
+ this.code = code;
12
+ }
13
+ }
14
+ const isSftExportKind = (kind) => CODALI_DATASET_SFT_EXPORT_KINDS.includes(kind);
15
+ const validateRecordOrThrow = (record) => {
16
+ const validation = validateCodaliStorageDatasetRecord(record);
17
+ if (!validation.ok) {
18
+ throw new CodaliDatasetExportJobError("CODALI_DATASET_EXPORT_RECORD_INVALID", validation.issues
19
+ .map((issue) => `${issue.path}:${issue.code}:${issue.message}`)
20
+ .join("; "));
21
+ }
22
+ return validation.value;
23
+ };
24
+ const refsForRecord = (record) => [
25
+ record.inputRef,
26
+ ...(record.outputRef ? [record.outputRef] : []),
27
+ ...(record.evidenceRefs ?? []),
28
+ ];
29
+ const addReasonCounts = (counts, reasons) => {
30
+ for (const reason of reasons) {
31
+ counts[reason.code] = (counts[reason.code] ?? 0) + 1;
32
+ }
33
+ };
34
+ const blockerToReason = (recordId, purpose, blocker) => ({
35
+ recordId,
36
+ purpose,
37
+ code: blocker.code,
38
+ message: blocker.message,
39
+ ...(blocker.path ? { path: blocker.path } : {}),
40
+ });
41
+ const requiredReadPurposes = (exportKind) => {
42
+ const purposes = ["export"];
43
+ if (exportKind === "eval-replay")
44
+ purposes.push("eval", "replay");
45
+ if (isSftExportKind(exportKind))
46
+ purposes.push("training");
47
+ return purposes;
48
+ };
49
+ const evaluateRecordEligibility = (exportKind, record) => {
50
+ const reasons = [];
51
+ for (const purpose of requiredReadPurposes(exportKind)) {
52
+ for (const ref of refsForRecord(record)) {
53
+ const decision = evaluateCodaliDatasetObjectPayloadRead(purpose, ref, record.privacy);
54
+ if (!decision.allowed) {
55
+ reasons.push(...decision.blockers.map((blocker) => blockerToReason(record.recordId, purpose, blocker)));
56
+ }
57
+ }
58
+ }
59
+ return reasons;
60
+ };
61
+ const mergeFlags = (current, ref) => ({
62
+ containsPersonalData: current.containsPersonalData || ref.privacyFlags.containsPersonalData,
63
+ containsSecrets: current.containsSecrets || ref.privacyFlags.containsSecrets,
64
+ containsTenantPrivateData: current.containsTenantPrivateData || ref.privacyFlags.containsTenantPrivateData,
65
+ containsSourceCode: current.containsSourceCode || ref.privacyFlags.containsSourceCode,
66
+ containsCustomerData: current.containsCustomerData || ref.privacyFlags.containsCustomerData,
67
+ trainingAllowed: current.trainingAllowed && ref.privacyFlags.trainingAllowed,
68
+ evalAllowed: current.evalAllowed && ref.privacyFlags.evalAllowed,
69
+ replayAllowed: current.replayAllowed && ref.privacyFlags.replayAllowed,
70
+ exportAllowed: current.exportAllowed && ref.privacyFlags.exportAllowed,
71
+ });
72
+ const increment = (counts, key) => {
73
+ if (!key)
74
+ return;
75
+ counts[key] = (counts[key] ?? 0) + 1;
76
+ };
77
+ const privacySummaryForRecords = (records) => {
78
+ const classifications = {};
79
+ const redactionStatuses = {};
80
+ const policyTags = new Set();
81
+ let exportAllowedCount = 0;
82
+ let trainingAllowedCount = 0;
83
+ let evalAllowedCount = 0;
84
+ let replayAllowedCount = 0;
85
+ let mergedFlags = createGatewayDatasetLocalOnlyObjectPrivacyFlags({
86
+ containsTenantPrivateData: false,
87
+ containsCustomerData: false,
88
+ trainingAllowed: true,
89
+ evalAllowed: true,
90
+ replayAllowed: true,
91
+ exportAllowed: true,
92
+ });
93
+ for (const record of records) {
94
+ increment(classifications, record.privacy.classification);
95
+ increment(redactionStatuses, record.privacy.redactionStatus);
96
+ for (const tag of record.privacy.policyTags ?? [])
97
+ policyTags.add(tag);
98
+ const refs = refsForRecord(record);
99
+ for (const ref of refs)
100
+ mergedFlags = mergeFlags(mergedFlags, ref);
101
+ if (record.privacy.exportAllowed && refs.every((ref) => ref.privacyFlags.exportAllowed)) {
102
+ exportAllowedCount += 1;
103
+ }
104
+ if (record.privacy.trainingAllowed && refs.every((ref) => ref.privacyFlags.trainingAllowed)) {
105
+ trainingAllowedCount += 1;
106
+ }
107
+ if (refs.every((ref) => ref.privacyFlags.evalAllowed))
108
+ evalAllowedCount += 1;
109
+ if (refs.every((ref) => ref.privacyFlags.replayAllowed))
110
+ replayAllowedCount += 1;
111
+ }
112
+ return {
113
+ recordCount: records.length,
114
+ containsPersonalData: records.some((record) => record.privacy.containsPersonalData) ||
115
+ mergedFlags.containsPersonalData,
116
+ containsSecrets: mergedFlags.containsSecrets,
117
+ containsTenantPrivateData: mergedFlags.containsTenantPrivateData,
118
+ containsSourceCode: mergedFlags.containsSourceCode,
119
+ containsCustomerData: mergedFlags.containsCustomerData,
120
+ exportAllowedCount,
121
+ trainingAllowedCount,
122
+ evalAllowedCount,
123
+ replayAllowedCount,
124
+ classifications,
125
+ redactionStatuses,
126
+ ...(policyTags.size ? { policyTags: [...policyTags].sort() } : {}),
127
+ };
128
+ };
129
+ const deletionGroupSnapshotForRecords = (records, capturedAt) => {
130
+ const allIds = new Set();
131
+ const byRecordId = {};
132
+ for (const record of records) {
133
+ const ids = [...new Set(refsForRecord(record).map((ref) => ref.deletionGroupId))].sort();
134
+ byRecordId[record.recordId] = ids;
135
+ ids.forEach((id) => allIds.add(id));
136
+ }
137
+ return {
138
+ capturedAt,
139
+ deletionGroupIds: [...allIds].sort(),
140
+ byRecordId,
141
+ };
142
+ };
143
+ const lineageForRecords = (exportKind, records, generatedBy) => ({
144
+ exportKind,
145
+ sourceRecordIds: records.map((record) => record.recordId),
146
+ sourceGatewayRecordIds: [
147
+ ...new Set(records.flatMap((record) => record.sourceGatewayRecordId ? [record.sourceGatewayRecordId] : [])),
148
+ ].sort(),
149
+ sourceObjectHashes: [
150
+ ...new Set(records.flatMap((record) => refsForRecord(record).map((ref) => ref.contentHash))),
151
+ ].sort(),
152
+ ...(generatedBy ? { generatedBy } : {}),
153
+ });
154
+ const primaryRecordObjectRef = (record) => record.outputRef ?? record.inputRef;
155
+ const manifestRecordRefs = (records) => records.map((record) => ({
156
+ recordType: record.recordType,
157
+ recordId: record.recordId,
158
+ schemaVersion: record.schemaVersion,
159
+ objectRef: primaryRecordObjectRef(record),
160
+ }));
161
+ const exportRows = (records) => records.map((record) => ({
162
+ schemaVersion: CODALI_DATASET_EXPORT_JOB_SCHEMA_VERSION,
163
+ recordType: record.recordType,
164
+ recordId: record.recordId,
165
+ datasetKind: record.datasetKind,
166
+ sourceGatewayRecordId: record.sourceGatewayRecordId,
167
+ inputRef: record.inputRef,
168
+ outputRef: record.outputRef,
169
+ evidenceRefs: record.evidenceRefs,
170
+ quality: record.quality,
171
+ privacy: record.privacy,
172
+ metadata: record.metadata,
173
+ }));
174
+ const toJsonl = (rows) => rows.map((row) => JSON.stringify(row)).join("\n") + "\n";
175
+ const replayFixturePayload = (exportKind, generatedAt, records) => ({
176
+ schemaVersion: CODALI_DATASET_REPLAY_FIXTURE_SCHEMA_VERSION,
177
+ exportKind,
178
+ generatedAt,
179
+ records: records.map((record) => ({
180
+ recordId: record.recordId,
181
+ datasetKind: record.datasetKind,
182
+ sourceGatewayRecordId: record.sourceGatewayRecordId,
183
+ inputRef: record.inputRef,
184
+ outputRef: record.outputRef,
185
+ evidenceRefs: record.evidenceRefs,
186
+ quality: record.quality,
187
+ metadata: record.metadata,
188
+ })),
189
+ });
190
+ const manifestPrivacy = (summary) => createGatewayDatasetLocalOnlyPrivacy({
191
+ containsPersonalData: summary.containsPersonalData,
192
+ redactionStatus: summary.containsPersonalData ? "redacted" : "not_required",
193
+ exportAllowed: true,
194
+ trainingAllowed: false,
195
+ metadata: {
196
+ exportPrivacySummary: summary,
197
+ },
198
+ });
199
+ const artifactPrivacyFlags = (summary) => createGatewayDatasetLocalOnlyObjectPrivacyFlags({
200
+ containsPersonalData: summary.containsPersonalData,
201
+ containsSecrets: summary.containsSecrets,
202
+ containsTenantPrivateData: summary.containsTenantPrivateData,
203
+ containsSourceCode: summary.containsSourceCode,
204
+ containsCustomerData: summary.containsCustomerData,
205
+ exportAllowed: true,
206
+ trainingAllowed: false,
207
+ evalAllowed: true,
208
+ replayAllowed: true,
209
+ });
210
+ export const runCodaliDatasetExportJob = async (input) => {
211
+ if (!CODALI_STORAGE_EXPORT_KINDS.includes(input.exportKind)) {
212
+ throw new CodaliDatasetExportJobError("CODALI_DATASET_EXPORT_KIND_INVALID", `Unsupported dataset export kind: ${input.exportKind}.`);
213
+ }
214
+ if (input.exportFormat && input.exportFormat !== "jsonl") {
215
+ throw new CodaliDatasetExportJobError("CODALI_DATASET_EXPORT_FORMAT_INVALID", "The dataset exporter currently supports JSONL output.");
216
+ }
217
+ const records = input.records.map(validateRecordOrThrow);
218
+ const exclusionReasons = [];
219
+ const eligibleRecords = [];
220
+ for (const record of records) {
221
+ const reasons = evaluateRecordEligibility(input.exportKind, record);
222
+ if (reasons.length > 0) {
223
+ exclusionReasons.push(...reasons);
224
+ }
225
+ else {
226
+ eligibleRecords.push(record);
227
+ }
228
+ }
229
+ const exclusionReasonCounts = {};
230
+ addReasonCounts(exclusionReasonCounts, exclusionReasons);
231
+ const dryRunSummary = {
232
+ totalCount: records.length,
233
+ eligibleCount: eligibleRecords.length,
234
+ excludedCount: exclusionReasons.length === 0
235
+ ? 0
236
+ : records.length - eligibleRecords.length,
237
+ exclusionReasonCounts,
238
+ };
239
+ if (input.dryRun) {
240
+ return {
241
+ schemaVersion: CODALI_DATASET_EXPORT_JOB_SCHEMA_VERSION,
242
+ accepted: true,
243
+ status: "dry_run",
244
+ dryRun: dryRunSummary,
245
+ exportKind: input.exportKind,
246
+ exportFormat: "jsonl",
247
+ exclusionReasons,
248
+ };
249
+ }
250
+ if (records.length === 0 || exclusionReasons.length > 0 || eligibleRecords.length !== records.length) {
251
+ return {
252
+ schemaVersion: CODALI_DATASET_EXPORT_JOB_SCHEMA_VERSION,
253
+ accepted: false,
254
+ status: "blocked",
255
+ dryRun: dryRunSummary,
256
+ exportKind: input.exportKind,
257
+ exportFormat: "jsonl",
258
+ exclusionReasons,
259
+ };
260
+ }
261
+ const now = input.now ?? (() => new Date());
262
+ const createdAt = now().toISOString();
263
+ const manifestId = input.manifestId ??
264
+ `dataset-export-${hashGatewayDatasetRequestBody({
265
+ exportKind: input.exportKind,
266
+ createdAt,
267
+ records: records.map((record) => record.recordId),
268
+ }).slice(0, 16)}`;
269
+ const summary = privacySummaryForRecords(records);
270
+ const privacyFlags = artifactPrivacyFlags(summary);
271
+ const rows = exportRows(records);
272
+ const jsonlPayload = toJsonl(rows);
273
+ const jsonlRef = await input.objectStore.putObject({
274
+ scope: input.scope,
275
+ ownerType: "export_manifest",
276
+ ownerId: manifestId,
277
+ kind: "export",
278
+ mimeType: "application/x-ndjson",
279
+ retentionClass: "dataset",
280
+ privacyFlags,
281
+ payload: jsonlPayload,
282
+ metadata: {
283
+ artifactType: "jsonl",
284
+ exportKind: input.exportKind,
285
+ recordCount: records.length,
286
+ },
287
+ });
288
+ const replayFixtureRef = await input.objectStore.putObject({
289
+ scope: input.scope,
290
+ ownerType: "export_manifest",
291
+ ownerId: manifestId,
292
+ kind: "export",
293
+ mimeType: "application/json",
294
+ retentionClass: "dataset",
295
+ privacyFlags,
296
+ payload: replayFixturePayload(input.exportKind, createdAt, records),
297
+ metadata: {
298
+ artifactType: "replay_fixture",
299
+ exportKind: input.exportKind,
300
+ recordCount: records.length,
301
+ },
302
+ });
303
+ const manifest = {
304
+ schemaVersion: CODALI_STORAGE_CONTRACT_SCHEMA_VERSION,
305
+ recordType: "export_manifest",
306
+ manifestId,
307
+ createdAt,
308
+ exportKind: input.exportKind,
309
+ exportFormat: "jsonl",
310
+ recordCount: records.length,
311
+ records: manifestRecordRefs(records),
312
+ artifactRefs: [jsonlRef, replayFixtureRef],
313
+ checksum: jsonlRef.contentHash,
314
+ privacySummary: summary,
315
+ lineage: lineageForRecords(input.exportKind, records, input.generatedBy),
316
+ deletionGroupSnapshot: deletionGroupSnapshotForRecords(records, createdAt),
317
+ generatedBy: input.generatedBy,
318
+ privacy: manifestPrivacy(summary),
319
+ metadata: {
320
+ schemaVersion: CODALI_DATASET_EXPORT_JOB_SCHEMA_VERSION,
321
+ explicitExport: true,
322
+ dryRun: false,
323
+ ...(input.metadata ?? {}),
324
+ },
325
+ };
326
+ const validation = validateCodaliStorageExportManifest(manifest);
327
+ if (!validation.ok) {
328
+ throw new CodaliDatasetExportJobError("CODALI_DATASET_EXPORT_MANIFEST_INVALID", validation.issues.map((issue) => `${issue.path}:${issue.code}`).join("; "));
329
+ }
330
+ const manifestRef = await input.objectStore.putObject({
331
+ scope: input.scope,
332
+ ownerType: "export_manifest",
333
+ ownerId: manifestId,
334
+ kind: "export",
335
+ mimeType: "application/json",
336
+ retentionClass: "dataset",
337
+ privacyFlags,
338
+ payload: validation.value,
339
+ metadata: {
340
+ artifactType: "manifest",
341
+ exportKind: input.exportKind,
342
+ recordCount: records.length,
343
+ },
344
+ });
345
+ return {
346
+ schemaVersion: CODALI_DATASET_EXPORT_JOB_SCHEMA_VERSION,
347
+ accepted: true,
348
+ status: "exported",
349
+ dryRun: dryRunSummary,
350
+ exportKind: input.exportKind,
351
+ exportFormat: "jsonl",
352
+ manifest: validation.value,
353
+ manifestRef,
354
+ jsonlRef,
355
+ replayFixtureRef,
356
+ exclusionReasons,
357
+ };
358
+ };
@@ -0,0 +1,98 @@
1
+ import { type CodaliStorageDatasetRecord, type CodaliStorageReviewDecision, type CodaliStorageReviewPromotionTarget } from "./CodaliStorageContracts.js";
2
+ import type { GatewayDatasetStorageScope } from "./GatewayDatasetStore.js";
3
+ export declare const CODALI_DATASET_RECORDS_FILE = "records.jsonl";
4
+ export interface LocalDatasetBatch {
5
+ raw: Record<string, unknown>;
6
+ collectedAt?: string;
7
+ idempotencyKey?: string;
8
+ scope: GatewayDatasetStorageScope;
9
+ records: CodaliStorageDatasetRecord[];
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ export interface LocalDatasetCollection {
13
+ directory: string;
14
+ recordsPath: string;
15
+ batches: LocalDatasetBatch[];
16
+ invalidLineCount: number;
17
+ invalidRecordCount: number;
18
+ }
19
+ export interface DatasetRecordEntry {
20
+ record: CodaliStorageDatasetRecord;
21
+ batchIndex: number;
22
+ recordIndex: number;
23
+ scope: GatewayDatasetStorageScope;
24
+ collectedAt?: string;
25
+ idempotencyKey?: string;
26
+ batchMetadata?: Record<string, unknown>;
27
+ }
28
+ export interface DatasetSampleOptions {
29
+ seed?: string;
30
+ limit?: number;
31
+ tenantId?: string;
32
+ productId?: string;
33
+ deploymentId?: string;
34
+ runId?: string;
35
+ failureCluster?: string;
36
+ integration?: string;
37
+ confidence?: string;
38
+ businessValue?: string;
39
+ unreviewedOnly?: boolean;
40
+ }
41
+ export interface DatasetCollectionSummary {
42
+ directory: string;
43
+ recordsPath: string;
44
+ batchCount: number;
45
+ totalRecordRows: number;
46
+ uniqueRecordCount: number;
47
+ invalidLineCount: number;
48
+ invalidRecordCount: number;
49
+ reviewedCount: number;
50
+ unreviewedCount: number;
51
+ exportAllowedCount: number;
52
+ trainingAllowedCount: number;
53
+ byTenant: Record<string, number>;
54
+ byProduct: Record<string, number>;
55
+ byDatasetKind: Record<string, number>;
56
+ byExampleType: Record<string, number>;
57
+ byFailureCluster: Record<string, number>;
58
+ byIntegration: Record<string, number>;
59
+ byConfidence: Record<string, number>;
60
+ byBusinessValue: Record<string, number>;
61
+ }
62
+ export interface DatasetLabelInput extends DatasetSampleOptions {
63
+ recordId: string;
64
+ labels: string[];
65
+ reviewerId?: string;
66
+ reason?: string;
67
+ now?: () => Date;
68
+ }
69
+ export interface DatasetPromotionInput extends DatasetSampleOptions {
70
+ recordId: string;
71
+ promotionTarget: CodaliStorageReviewPromotionTarget;
72
+ decision?: CodaliStorageReviewDecision;
73
+ labels?: string[];
74
+ reasons?: string[];
75
+ reviewerId?: string;
76
+ now?: () => Date;
77
+ }
78
+ export interface DatasetMutationResult {
79
+ updatedCount: number;
80
+ recordIds: string[];
81
+ }
82
+ export declare const datasetRecordFailureCluster: (record: CodaliStorageDatasetRecord) => string;
83
+ export declare const datasetRecordIntegration: (record: CodaliStorageDatasetRecord) => string;
84
+ export declare const datasetRecordConfidence: (record: CodaliStorageDatasetRecord) => string;
85
+ export declare const datasetRecordBusinessValue: (record: CodaliStorageDatasetRecord) => string;
86
+ export declare const readLocalDatasetCollection: (input: {
87
+ directory: string;
88
+ recordsFileName?: string;
89
+ }) => Promise<LocalDatasetCollection>;
90
+ export declare const writeLocalDatasetCollection: (collection: LocalDatasetCollection) => Promise<void>;
91
+ export declare const datasetRecordEntries: (collection: LocalDatasetCollection) => DatasetRecordEntry[];
92
+ export declare const latestDatasetRecordEntries: (collection: LocalDatasetCollection) => DatasetRecordEntry[];
93
+ export declare const matchesDatasetSampleOptions: (entry: DatasetRecordEntry, options: DatasetSampleOptions) => boolean;
94
+ export declare const sampleDatasetRecordEntries: (collection: LocalDatasetCollection, options?: DatasetSampleOptions) => DatasetRecordEntry[];
95
+ export declare const summarizeDatasetCollection: (collection: LocalDatasetCollection) => DatasetCollectionSummary;
96
+ export declare const applyDatasetLabel: (collection: LocalDatasetCollection, input: DatasetLabelInput) => DatasetMutationResult;
97
+ export declare const applyDatasetPromotionTarget: (collection: LocalDatasetCollection, input: DatasetPromotionInput) => DatasetMutationResult;
98
+ //# sourceMappingURL=DatasetReviewQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatasetReviewQueue.d.ts","sourceRoot":"","sources":["../../src/storage/DatasetReviewQueue.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,KAAK,kCAAkC,EACxC,MAAM,6BAA6B,CAAC;AAKrC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAE3E,eAAO,MAAM,2BAA2B,kBAAkB,CAAC;AAE3D,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,0BAA0B,CAAC;IAClC,OAAO,EAAE,0BAA0B,EAAE,CAAC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,0BAA0B,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IAC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