@xpert-ai/plugin-sdk 3.34.0 → 3.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-results.cjs.js +5 -1
- package/agent-results.esm.js +2 -2
- package/analytics-result.cjs.js +64 -27
- package/analytics-result.esm.js +62 -28
- package/analytics.cjs.js +157 -15
- package/analytics.esm.js +154 -17
- package/artifact-document.cjs.js +9 -3
- package/artifact-document.esm.js +9 -3
- package/collaboration-client.cjs.js +274 -140
- package/collaboration-client.esm.js +273 -141
- package/docs/README.md +23 -0
- package/index.cjs.js +214 -9
- package/index.esm.js +193 -15
- package/model-provider.cjs.js +8 -0
- package/model-provider.esm.js +7 -1
- package/package.json +8 -2
- package/remote-component.cjs.default.js +1 -0
- package/remote-component.cjs.js +143 -0
- package/remote-component.cjs.mjs +2 -0
- package/remote-component.d.ts +1 -0
- package/remote-component.esm.js +139 -0
- package/results.cjs.js +2 -6
- package/results.esm.js +2 -6
- package/src/analytics.d.ts +2 -0
- package/src/collaboration-client.d.ts +1 -0
- package/src/index.d.ts +1 -0
- package/src/lib/agent/handoff/agent-runtime-message.contract.d.ts +24 -24
- package/src/lib/agent/middleware/strategy.interface.d.ts +2 -0
- package/src/lib/agent/runtime/capability.d.ts +2 -0
- package/src/lib/agent/runtime/cli-model-profile.d.ts +14 -1
- package/src/lib/agent/runtime/dispatch.d.ts +298 -75
- package/src/lib/agent/runtime/execution-runner.d.ts +24 -5
- package/src/lib/agent/runtime/pipeline-scope.d.ts +4 -4
- package/src/lib/agent/runtime/results.d.ts +16 -219
- package/src/lib/agent/runtime/strategy.d.ts +3 -0
- package/src/lib/agent/runtime/types.d.ts +21 -0
- package/src/lib/agent-event/index.d.ts +55 -0
- package/src/lib/agent-event/journal.d.ts +30 -0
- package/src/lib/artifact-document/dependencies.d.ts +13 -13
- package/src/lib/artifact-document/protocol.d.ts +2 -2
- package/src/lib/artifact-document/scheduler.d.ts +3 -0
- package/src/lib/assistant-capability/middleware.d.ts +2 -1
- package/src/lib/collaboration/client.d.ts +6 -59
- package/src/lib/collaboration/index.d.ts +1 -0
- package/src/lib/collaboration/operations-client.d.ts +23 -0
- package/src/lib/collaboration/presence.d.ts +36 -0
- package/src/lib/collaboration/provider.registry.d.ts +2 -2
- package/src/lib/collaboration/transport.d.ts +24 -0
- package/src/lib/collaboration/types.d.ts +57 -5
- package/src/lib/content-resource/catalog.d.ts +23 -1
- package/src/lib/content-resource/editor.d.ts +36 -1
- package/src/lib/data/analytics/analysis-evidence.d.ts +757 -0
- package/src/lib/data/analytics/analytics-certification.d.ts +64 -0
- package/src/lib/data/analytics/analytics-provider.d.ts +9 -0
- package/src/lib/data/analytics/analytics-value.d.ts +5 -0
- package/src/lib/data/analytics/index.d.ts +1 -0
- package/src/lib/evolution/runtime-capability.d.ts +1 -0
- package/src/lib/project-pipeline/adapters.d.ts +9 -2
- package/src/lib/project-pipeline/registry.d.ts +53 -50
- package/src/lib/project-task/acceptance.d.ts +29 -0
- package/src/lib/project-task/index.d.ts +6 -0
- package/src/lib/runtime/capabilities/index.d.ts +2 -0
- package/src/lib/runtime/capabilities/plugin-test-access.d.ts +14 -0
- package/src/lib/runtime/capabilities/project-configuration.d.ts +166 -0
- package/src/lib/view-extension/provider.interface.d.ts +51 -0
- package/src/remote-component.d.ts +13 -0
package/agent-results.cjs.js
CHANGED
|
@@ -7,9 +7,13 @@ require('zod/v3');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
exports.AGENT_TASK_REPORT_MAX_BYTES = results.AGENT_TASK_REPORT_MAX_BYTES;
|
|
10
11
|
exports.AGENT_TASK_RESULTS_FEATURE = results.AGENT_TASK_RESULTS_FEATURE;
|
|
11
12
|
exports.agentResultItemSchema = results.agentResultItemSchema;
|
|
12
|
-
exports
|
|
13
|
+
Object.defineProperty(exports, "agentDeliveryRecoverySchema", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return contracts.agentDeliveryRecoverySchema; }
|
|
16
|
+
});
|
|
13
17
|
Object.defineProperty(exports, "agentOutputDeliverySchema", {
|
|
14
18
|
enumerable: true,
|
|
15
19
|
get: function () { return contracts.agentOutputDeliverySchema; }
|
package/agent-results.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as
|
|
2
|
-
export { agentOutputDeliverySchema, agentResultPathSchema } from '@xpert-ai/contracts';
|
|
1
|
+
export { A as AGENT_TASK_REPORT_MAX_BYTES, a as AGENT_TASK_RESULTS_FEATURE, b as agentResultItemSchema } from './results.esm.js';
|
|
2
|
+
export { agentDeliveryRecoverySchema, agentOutputDeliverySchema, agentResultPathSchema } from '@xpert-ai/contracts';
|
|
3
3
|
import './_extends.esm.js';
|
|
4
4
|
import 'zod/v3';
|
package/analytics-result.cjs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var v3 = require('zod/v3');
|
|
4
|
+
var _extends = require('./_extends.cjs.js');
|
|
4
5
|
|
|
5
6
|
const key = v3.z.string().regex(/^[A-Za-z][A-Za-z0-9_.-]{0,79}$/);
|
|
6
7
|
const value = v3.z.union([
|
|
@@ -104,7 +105,11 @@ const analyticsBindingSchema = analyticsBindingObjectSchema.superRefine(validate
|
|
|
104
105
|
const analyticsControlsSchema = v3.z.record(key, value).default({});
|
|
105
106
|
const analyticsQueryRequestSchema = v3.z.object({
|
|
106
107
|
binding: analyticsBindingSchema,
|
|
107
|
-
controls: analyticsControlsSchema
|
|
108
|
+
controls: analyticsControlsSchema,
|
|
109
|
+
cache: v3.z.object({
|
|
110
|
+
maxAgeMs: v3.z.number().int().min(0).max(60000),
|
|
111
|
+
forceRefresh: v3.z.boolean().optional()
|
|
112
|
+
}).strict().optional()
|
|
108
113
|
}).strict();
|
|
109
114
|
const analyticsDiscoveryRequestObjectSchema = v3.z.object({
|
|
110
115
|
source: analyticsSourceRefSchema,
|
|
@@ -143,6 +148,55 @@ const analyticsDiscoveryResultSchema = v3.z.object({
|
|
|
143
148
|
}
|
|
144
149
|
}
|
|
145
150
|
|
|
151
|
+
const identity = {
|
|
152
|
+
kind: v3.z.literal('business_metric'),
|
|
153
|
+
subjectId: v3.z.string().min(1).max(160),
|
|
154
|
+
verifiedAt: v3.z.string().datetime()
|
|
155
|
+
};
|
|
156
|
+
/** Parse only provider results. A valid shape alone never grants certification authority.
|
|
157
|
+
* Legacy records remain explicitly unverified; approval fields require a verified source proof. */ const analyticsCertificationSchema = v3.z.discriminatedUnion('status', [
|
|
158
|
+
v3.z.object(_extends._extends({}, identity, {
|
|
159
|
+
status: v3.z.literal('legacy_unverified')
|
|
160
|
+
})).strict(),
|
|
161
|
+
v3.z.object(_extends._extends({}, identity, {
|
|
162
|
+
status: v3.z.literal('verified'),
|
|
163
|
+
definitionHash: v3.z.string().regex(/^[a-f0-9]{64}$/),
|
|
164
|
+
dependency: v3.z.object({
|
|
165
|
+
id: v3.z.string().min(1).max(160),
|
|
166
|
+
version: v3.z.number().int().nonnegative()
|
|
167
|
+
}).strict(),
|
|
168
|
+
certifiedBy: v3.z.string().min(1).max(160),
|
|
169
|
+
certifiedAt: v3.z.string().datetime()
|
|
170
|
+
})).strict()
|
|
171
|
+
]);
|
|
172
|
+
/** The package supports hosts compiled without strictNullChecks; parsing still requires every field. */ function parseAnalyticsCertification(value) {
|
|
173
|
+
return analyticsCertificationSchema.parse(value);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Shared wire-value rules for normalized query results and immutable evidence snapshots. */ function isAnalyticsDate(value) {
|
|
177
|
+
// Date.parse normalizes some impossible dates; round-trip validation rejects that rollover.
|
|
178
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
|
|
179
|
+
}
|
|
180
|
+
/** int64/decimal stay strings on the wire to avoid JavaScript number rounding; never coerce them. */ function isAnalyticsCell(type, cell, nullable) {
|
|
181
|
+
if (cell === null) return nullable;
|
|
182
|
+
switch(type){
|
|
183
|
+
case 'string':
|
|
184
|
+
return typeof cell === 'string';
|
|
185
|
+
case 'boolean':
|
|
186
|
+
return typeof cell === 'boolean';
|
|
187
|
+
case 'float64':
|
|
188
|
+
return typeof cell === 'number' && Number.isFinite(cell);
|
|
189
|
+
case 'int64':
|
|
190
|
+
return typeof cell === 'string' && /^-?\d{1,19}$/.test(cell) && BigInt(cell) >= -(2n ** 63n) && BigInt(cell) < 2n ** 63n;
|
|
191
|
+
case 'decimal':
|
|
192
|
+
return typeof cell === 'string' && /^-?\d+(\.\d+)?$/.test(cell);
|
|
193
|
+
case 'date':
|
|
194
|
+
return typeof cell === 'string' && isAnalyticsDate(cell);
|
|
195
|
+
case 'timestamp':
|
|
196
|
+
return typeof cell === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/.test(cell) && isAnalyticsDate(cell.slice(0, 10)) && Number.isFinite(Date.parse(cell));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
146
200
|
function resolveAnalyticsParameters(binding, controls) {
|
|
147
201
|
const allowed = new Set(binding.parameters.map((parameter)=>parameter.controlId));
|
|
148
202
|
if (Object.keys(controls).some((name)=>!allowed.has(name))) throw new Error('ANALYTICS_UNKNOWN_CONTROL');
|
|
@@ -154,7 +208,7 @@ function resolveAnalyticsParameters(binding, controls) {
|
|
|
154
208
|
result[parameter.name] = null;
|
|
155
209
|
continue;
|
|
156
210
|
}
|
|
157
|
-
const valid = parameter.type === 'date' ? typeof value === 'string' &&
|
|
211
|
+
const valid = parameter.type === 'date' ? typeof value === 'string' && isAnalyticsDate(value) : typeof value === parameter.type && (typeof value !== 'number' || Number.isFinite(value));
|
|
158
212
|
if (!valid || parameter.allowedValues && !parameter.allowedValues.includes(value)) throw new Error('ANALYTICS_PARAMETER_INVALID');
|
|
159
213
|
result[parameter.name] = value;
|
|
160
214
|
}
|
|
@@ -170,7 +224,7 @@ function normalizeAnalyticsResult(binding, result, executionId, maxRows) {
|
|
|
170
224
|
});
|
|
171
225
|
const rows = result.rows.map((row)=>Object.fromEntries(fields.map((field, index)=>{
|
|
172
226
|
const cell = row[keys[index]];
|
|
173
|
-
if (cell === undefined || !
|
|
227
|
+
if (cell === undefined || !isAnalyticsCell(field.logicalType, cell, field.nullable)) throw new Error('ANALYTICS_FIELD_TYPE_MISMATCH');
|
|
174
228
|
return [
|
|
175
229
|
field.id,
|
|
176
230
|
cell
|
|
@@ -194,41 +248,22 @@ function normalizeAnalyticsResult(binding, result, executionId, maxRows) {
|
|
|
194
248
|
sourceFetchedAt: result.sourceFetchedAt,
|
|
195
249
|
dataAsOf: result.dataAsOf
|
|
196
250
|
},
|
|
197
|
-
provenance: {
|
|
251
|
+
provenance: _extends._extends({
|
|
198
252
|
executionId,
|
|
199
253
|
bindingId: binding.id,
|
|
200
254
|
providerId: binding.providerId,
|
|
201
255
|
sourceVersion: result.sourceVersion,
|
|
202
256
|
upstreamExecutionId: result.upstreamExecutionId,
|
|
203
257
|
auditRef: result.auditRef
|
|
204
|
-
}
|
|
258
|
+
}, result.certification !== undefined ? {
|
|
259
|
+
certification: parseAnalyticsCertification(result.certification)
|
|
260
|
+
} : {})
|
|
205
261
|
};
|
|
206
262
|
}
|
|
207
|
-
function validDate(value) {
|
|
208
|
-
return /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
|
|
209
|
-
}
|
|
210
|
-
function validCell(field, cell) {
|
|
211
|
-
if (cell === null) return field.nullable;
|
|
212
|
-
switch(field.logicalType){
|
|
213
|
-
case 'string':
|
|
214
|
-
return typeof cell === 'string';
|
|
215
|
-
case 'boolean':
|
|
216
|
-
return typeof cell === 'boolean';
|
|
217
|
-
case 'float64':
|
|
218
|
-
return typeof cell === 'number' && Number.isFinite(cell);
|
|
219
|
-
case 'int64':
|
|
220
|
-
return typeof cell === 'string' && /^-?\d{1,19}$/.test(cell) && BigInt(cell) >= -(2n ** 63n) && BigInt(cell) < 2n ** 63n;
|
|
221
|
-
case 'decimal':
|
|
222
|
-
return typeof cell === 'string' && /^-?\d+(\.\d+)?$/.test(cell);
|
|
223
|
-
case 'date':
|
|
224
|
-
return typeof cell === 'string' && validDate(cell);
|
|
225
|
-
case 'timestamp':
|
|
226
|
-
return typeof cell === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/.test(cell) && validDate(cell.slice(0, 10)) && Number.isFinite(Date.parse(cell));
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
263
|
|
|
230
264
|
exports.analyticsBindingObjectSchema = analyticsBindingObjectSchema;
|
|
231
265
|
exports.analyticsBindingSchema = analyticsBindingSchema;
|
|
266
|
+
exports.analyticsCertificationSchema = analyticsCertificationSchema;
|
|
232
267
|
exports.analyticsControlsSchema = analyticsControlsSchema;
|
|
233
268
|
exports.analyticsDiscoveryRequestObjectSchema = analyticsDiscoveryRequestObjectSchema;
|
|
234
269
|
exports.analyticsDiscoveryRequestSchema = analyticsDiscoveryRequestSchema;
|
|
@@ -239,6 +274,8 @@ exports.analyticsParameterSchema = analyticsParameterSchema;
|
|
|
239
274
|
exports.analyticsQueryRequestSchema = analyticsQueryRequestSchema;
|
|
240
275
|
exports.analyticsSourceKey = analyticsSourceKey;
|
|
241
276
|
exports.analyticsSourceRefSchema = analyticsSourceRefSchema;
|
|
277
|
+
exports.isAnalyticsCell = isAnalyticsCell;
|
|
242
278
|
exports.normalizeAnalyticsResult = normalizeAnalyticsResult;
|
|
279
|
+
exports.parseAnalyticsCertification = parseAnalyticsCertification;
|
|
243
280
|
exports.resolveAnalyticsParameters = resolveAnalyticsParameters;
|
|
244
281
|
exports.validateAnalyticsBinding = validateAnalyticsBinding;
|
package/analytics-result.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v3';
|
|
2
|
+
import { _ as _extends } from './_extends.esm.js';
|
|
2
3
|
|
|
3
4
|
const key = z.string().regex(/^[A-Za-z][A-Za-z0-9_.-]{0,79}$/);
|
|
4
5
|
const value = z.union([
|
|
@@ -102,7 +103,11 @@ const analyticsBindingSchema = analyticsBindingObjectSchema.superRefine(validate
|
|
|
102
103
|
const analyticsControlsSchema = z.record(key, value).default({});
|
|
103
104
|
const analyticsQueryRequestSchema = z.object({
|
|
104
105
|
binding: analyticsBindingSchema,
|
|
105
|
-
controls: analyticsControlsSchema
|
|
106
|
+
controls: analyticsControlsSchema,
|
|
107
|
+
cache: z.object({
|
|
108
|
+
maxAgeMs: z.number().int().min(0).max(60000),
|
|
109
|
+
forceRefresh: z.boolean().optional()
|
|
110
|
+
}).strict().optional()
|
|
106
111
|
}).strict();
|
|
107
112
|
const analyticsDiscoveryRequestObjectSchema = z.object({
|
|
108
113
|
source: analyticsSourceRefSchema,
|
|
@@ -141,6 +146,55 @@ const analyticsDiscoveryResultSchema = z.object({
|
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
|
|
149
|
+
const identity = {
|
|
150
|
+
kind: z.literal('business_metric'),
|
|
151
|
+
subjectId: z.string().min(1).max(160),
|
|
152
|
+
verifiedAt: z.string().datetime()
|
|
153
|
+
};
|
|
154
|
+
/** Parse only provider results. A valid shape alone never grants certification authority.
|
|
155
|
+
* Legacy records remain explicitly unverified; approval fields require a verified source proof. */ const analyticsCertificationSchema = z.discriminatedUnion('status', [
|
|
156
|
+
z.object(_extends({}, identity, {
|
|
157
|
+
status: z.literal('legacy_unverified')
|
|
158
|
+
})).strict(),
|
|
159
|
+
z.object(_extends({}, identity, {
|
|
160
|
+
status: z.literal('verified'),
|
|
161
|
+
definitionHash: z.string().regex(/^[a-f0-9]{64}$/),
|
|
162
|
+
dependency: z.object({
|
|
163
|
+
id: z.string().min(1).max(160),
|
|
164
|
+
version: z.number().int().nonnegative()
|
|
165
|
+
}).strict(),
|
|
166
|
+
certifiedBy: z.string().min(1).max(160),
|
|
167
|
+
certifiedAt: z.string().datetime()
|
|
168
|
+
})).strict()
|
|
169
|
+
]);
|
|
170
|
+
/** The package supports hosts compiled without strictNullChecks; parsing still requires every field. */ function parseAnalyticsCertification(value) {
|
|
171
|
+
return analyticsCertificationSchema.parse(value);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Shared wire-value rules for normalized query results and immutable evidence snapshots. */ function isAnalyticsDate(value) {
|
|
175
|
+
// Date.parse normalizes some impossible dates; round-trip validation rejects that rollover.
|
|
176
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
|
|
177
|
+
}
|
|
178
|
+
/** int64/decimal stay strings on the wire to avoid JavaScript number rounding; never coerce them. */ function isAnalyticsCell(type, cell, nullable) {
|
|
179
|
+
if (cell === null) return nullable;
|
|
180
|
+
switch(type){
|
|
181
|
+
case 'string':
|
|
182
|
+
return typeof cell === 'string';
|
|
183
|
+
case 'boolean':
|
|
184
|
+
return typeof cell === 'boolean';
|
|
185
|
+
case 'float64':
|
|
186
|
+
return typeof cell === 'number' && Number.isFinite(cell);
|
|
187
|
+
case 'int64':
|
|
188
|
+
return typeof cell === 'string' && /^-?\d{1,19}$/.test(cell) && BigInt(cell) >= -(2n ** 63n) && BigInt(cell) < 2n ** 63n;
|
|
189
|
+
case 'decimal':
|
|
190
|
+
return typeof cell === 'string' && /^-?\d+(\.\d+)?$/.test(cell);
|
|
191
|
+
case 'date':
|
|
192
|
+
return typeof cell === 'string' && isAnalyticsDate(cell);
|
|
193
|
+
case 'timestamp':
|
|
194
|
+
return typeof cell === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/.test(cell) && isAnalyticsDate(cell.slice(0, 10)) && Number.isFinite(Date.parse(cell));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
144
198
|
function resolveAnalyticsParameters(binding, controls) {
|
|
145
199
|
const allowed = new Set(binding.parameters.map((parameter)=>parameter.controlId));
|
|
146
200
|
if (Object.keys(controls).some((name)=>!allowed.has(name))) throw new Error('ANALYTICS_UNKNOWN_CONTROL');
|
|
@@ -152,7 +206,7 @@ function resolveAnalyticsParameters(binding, controls) {
|
|
|
152
206
|
result[parameter.name] = null;
|
|
153
207
|
continue;
|
|
154
208
|
}
|
|
155
|
-
const valid = parameter.type === 'date' ? typeof value === 'string' &&
|
|
209
|
+
const valid = parameter.type === 'date' ? typeof value === 'string' && isAnalyticsDate(value) : typeof value === parameter.type && (typeof value !== 'number' || Number.isFinite(value));
|
|
156
210
|
if (!valid || parameter.allowedValues && !parameter.allowedValues.includes(value)) throw new Error('ANALYTICS_PARAMETER_INVALID');
|
|
157
211
|
result[parameter.name] = value;
|
|
158
212
|
}
|
|
@@ -168,7 +222,7 @@ function normalizeAnalyticsResult(binding, result, executionId, maxRows) {
|
|
|
168
222
|
});
|
|
169
223
|
const rows = result.rows.map((row)=>Object.fromEntries(fields.map((field, index)=>{
|
|
170
224
|
const cell = row[keys[index]];
|
|
171
|
-
if (cell === undefined || !
|
|
225
|
+
if (cell === undefined || !isAnalyticsCell(field.logicalType, cell, field.nullable)) throw new Error('ANALYTICS_FIELD_TYPE_MISMATCH');
|
|
172
226
|
return [
|
|
173
227
|
field.id,
|
|
174
228
|
cell
|
|
@@ -192,37 +246,17 @@ function normalizeAnalyticsResult(binding, result, executionId, maxRows) {
|
|
|
192
246
|
sourceFetchedAt: result.sourceFetchedAt,
|
|
193
247
|
dataAsOf: result.dataAsOf
|
|
194
248
|
},
|
|
195
|
-
provenance: {
|
|
249
|
+
provenance: _extends({
|
|
196
250
|
executionId,
|
|
197
251
|
bindingId: binding.id,
|
|
198
252
|
providerId: binding.providerId,
|
|
199
253
|
sourceVersion: result.sourceVersion,
|
|
200
254
|
upstreamExecutionId: result.upstreamExecutionId,
|
|
201
255
|
auditRef: result.auditRef
|
|
202
|
-
}
|
|
256
|
+
}, result.certification !== undefined ? {
|
|
257
|
+
certification: parseAnalyticsCertification(result.certification)
|
|
258
|
+
} : {})
|
|
203
259
|
};
|
|
204
260
|
}
|
|
205
|
-
function validDate(value) {
|
|
206
|
-
return /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
|
|
207
|
-
}
|
|
208
|
-
function validCell(field, cell) {
|
|
209
|
-
if (cell === null) return field.nullable;
|
|
210
|
-
switch(field.logicalType){
|
|
211
|
-
case 'string':
|
|
212
|
-
return typeof cell === 'string';
|
|
213
|
-
case 'boolean':
|
|
214
|
-
return typeof cell === 'boolean';
|
|
215
|
-
case 'float64':
|
|
216
|
-
return typeof cell === 'number' && Number.isFinite(cell);
|
|
217
|
-
case 'int64':
|
|
218
|
-
return typeof cell === 'string' && /^-?\d{1,19}$/.test(cell) && BigInt(cell) >= -(2n ** 63n) && BigInt(cell) < 2n ** 63n;
|
|
219
|
-
case 'decimal':
|
|
220
|
-
return typeof cell === 'string' && /^-?\d+(\.\d+)?$/.test(cell);
|
|
221
|
-
case 'date':
|
|
222
|
-
return typeof cell === 'string' && validDate(cell);
|
|
223
|
-
case 'timestamp':
|
|
224
|
-
return typeof cell === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}:\d{2})$/.test(cell) && validDate(cell.slice(0, 10)) && Number.isFinite(Date.parse(cell));
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
261
|
|
|
228
|
-
export {
|
|
262
|
+
export { analyticsCertificationSchema as a, analyticsFieldSchema as b, analyticsBindingObjectSchema as c, analyticsBindingSchema as d, analyticsControlsSchema as e, analyticsDiscoveryRequestObjectSchema as f, analyticsDiscoveryRequestSchema as g, analyticsDiscoveryResultSchema as h, isAnalyticsCell as i, analyticsOptionsSchema as j, analyticsParameterSchema as k, analyticsQueryRequestSchema as l, analyticsSourceKey as m, analyticsSourceRefSchema as n, normalizeAnalyticsResult as o, parseAnalyticsCertification as p, resolveAnalyticsParameters as r, validateAnalyticsBinding as v };
|
package/analytics.cjs.js
CHANGED
|
@@ -2,20 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
var analyticsResult = require('./analytics-result.cjs.js');
|
|
4
4
|
var v3 = require('zod/v3');
|
|
5
|
+
var _object_without_properties_loose = require('./_object_without_properties_loose.cjs.js');
|
|
6
|
+
require('./_extends.cjs.js');
|
|
5
7
|
|
|
6
|
-
const key = v3.z.string().trim().min(1).max(128).refine((value)=>![
|
|
8
|
+
const key$1 = v3.z.string().trim().min(1).max(128).refine((value)=>![
|
|
7
9
|
'__proto__',
|
|
8
10
|
'constructor',
|
|
9
11
|
'prototype'
|
|
10
12
|
].includes(value));
|
|
11
|
-
const scalar = v3.z.union([
|
|
13
|
+
const scalar$1 = v3.z.union([
|
|
12
14
|
v3.z.string().max(512),
|
|
13
15
|
v3.z.number().finite(),
|
|
14
16
|
v3.z.boolean(),
|
|
15
17
|
v3.z.null()
|
|
16
18
|
]);
|
|
17
19
|
/** Validate one predicate's shape/cardinality; field existence, logical types and allowed scope require live dataset metadata. */ const resourceAnalysisFilterSchema = v3.z.object({
|
|
18
|
-
field: key,
|
|
20
|
+
field: key$1,
|
|
19
21
|
operator: v3.z.enum([
|
|
20
22
|
'eq',
|
|
21
23
|
'ne',
|
|
@@ -25,36 +27,41 @@ const scalar = v3.z.union([
|
|
|
25
27
|
'lt',
|
|
26
28
|
'lte'
|
|
27
29
|
]),
|
|
28
|
-
values: v3.z.array(scalar).min(1).max(50)
|
|
30
|
+
values: v3.z.array(scalar$1).min(1).max(50)
|
|
29
31
|
}).strict().refine((value)=>value.operator === 'in' || value.values.length === 1);
|
|
30
32
|
/**
|
|
31
33
|
* Shared authoring/server policy boundary: bounded nonempty allowlists, fixed-filter fields and supported mode combinations.
|
|
32
34
|
* Parsing does not establish source sharing authority or receiving-group consent; those remain runtime checks.
|
|
33
35
|
*/ const resourceAnalysisPolicySchema = v3.z.object({
|
|
36
|
+
execution: v3.z.enum([
|
|
37
|
+
'viewer_permissions',
|
|
38
|
+
'delegated_results'
|
|
39
|
+
]).optional(),
|
|
34
40
|
mode: v3.z.enum([
|
|
35
41
|
'bindings',
|
|
36
42
|
'explore'
|
|
37
43
|
]),
|
|
38
44
|
datasets: v3.z.array(v3.z.object({
|
|
39
|
-
key,
|
|
40
|
-
fields: v3.z.array(key).min(1).max(64),
|
|
41
|
-
filters: v3.z.array(resourceAnalysisFilterSchema).max(20)
|
|
45
|
+
key: key$1,
|
|
46
|
+
fields: v3.z.array(key$1).min(1).max(64),
|
|
47
|
+
filters: v3.z.array(resourceAnalysisFilterSchema).max(20),
|
|
48
|
+
controlValues: v3.z.record(key$1, v3.z.array(scalar$1).min(1).max(50)).refine((value)=>Object.keys(value).length <= 32).optional()
|
|
42
49
|
}).strict()).min(1).max(20),
|
|
43
50
|
allowDetails: v3.z.boolean(),
|
|
44
51
|
maxRows: v3.z.number().int().min(1).max(100)
|
|
45
|
-
}).strict().refine((value)=>new Set(value.datasets.map((item)=>item.key)).size === value.datasets.length).refine((value)=>value.datasets.every((item)=>new Set(item.fields).size === item.fields.length && item.filters.every((filter)=>item.fields.includes(filter.field)))).refine((value)=>value.mode !== 'bindings' || value.allowDetails);
|
|
52
|
+
}).strict().refine((value)=>value.execution === 'delegated_results' || value.datasets.every((item)=>!item.controlValues)).refine((value)=>new Set(value.datasets.map((item)=>item.key)).size === value.datasets.length).refine((value)=>value.datasets.every((item)=>new Set(item.fields).size === item.fields.length && item.filters.every((filter)=>item.fields.includes(filter.field)))).refine((value)=>value.mode !== 'bindings' || value.allowDetails);
|
|
46
53
|
/**
|
|
47
54
|
* Normalize public query input to ResourceAnalysisQuery, defaulting optional wire collections to empty values.
|
|
48
55
|
* Keep limit absent so the executor uses the live policy's maxRows; validate field/mode/budget permissions before querying.
|
|
49
56
|
*/ const resourceAnalysisQuerySchema = v3.z.object({
|
|
50
|
-
datasetKey: key,
|
|
51
|
-
controls: v3.z.record(key, scalar).refine((value)=>Object.keys(value).length <= 32).default({}),
|
|
52
|
-
select: v3.z.array(key).max(64).default([]),
|
|
57
|
+
datasetKey: key$1,
|
|
58
|
+
controls: v3.z.record(key$1, scalar$1).refine((value)=>Object.keys(value).length <= 32).default({}),
|
|
59
|
+
select: v3.z.array(key$1).max(64).default([]),
|
|
53
60
|
filters: v3.z.array(resourceAnalysisFilterSchema).max(20).default([]),
|
|
54
|
-
groupBy: v3.z.array(key).max(8).default([]),
|
|
61
|
+
groupBy: v3.z.array(key$1).max(8).default([]),
|
|
55
62
|
aggregates: v3.z.array(v3.z.object({
|
|
56
|
-
field: key.optional(),
|
|
57
|
-
key,
|
|
63
|
+
field: key$1.optional(),
|
|
64
|
+
key: key$1,
|
|
58
65
|
operation: v3.z.enum([
|
|
59
66
|
'count',
|
|
60
67
|
'sum',
|
|
@@ -63,7 +70,7 @@ const scalar = v3.z.union([
|
|
|
63
70
|
])
|
|
64
71
|
}).strict()).max(16).default([]),
|
|
65
72
|
orderBy: v3.z.array(v3.z.object({
|
|
66
|
-
field: key,
|
|
73
|
+
field: key$1,
|
|
67
74
|
direction: v3.z.enum([
|
|
68
75
|
'asc',
|
|
69
76
|
'desc'
|
|
@@ -86,8 +93,138 @@ const scalar = v3.z.union([
|
|
|
86
93
|
return true;
|
|
87
94
|
}
|
|
88
95
|
|
|
96
|
+
// Evidence is a bounded copy of a past result. Parsing establishes neither current source access
|
|
97
|
+
// nor certification authority; producers and readers enforce those checks in their own runtime.
|
|
98
|
+
const key = v3.z.string().min(1).max(160).refine((value)=>![
|
|
99
|
+
'__proto__',
|
|
100
|
+
'constructor',
|
|
101
|
+
'prototype'
|
|
102
|
+
].includes(value));
|
|
103
|
+
const scalar = v3.z.union([
|
|
104
|
+
v3.z.string().max(4000),
|
|
105
|
+
v3.z.number().finite(),
|
|
106
|
+
v3.z.boolean(),
|
|
107
|
+
v3.z.null()
|
|
108
|
+
]);
|
|
109
|
+
const dataset = v3.z.object({
|
|
110
|
+
schema: v3.z.literal('xpert.analytics.dataset'),
|
|
111
|
+
datasetId: key,
|
|
112
|
+
fields: v3.z.array(analyticsResult.analyticsFieldSchema).min(1).max(64),
|
|
113
|
+
rows: v3.z.array(v3.z.record(key, scalar)).max(1000),
|
|
114
|
+
grain: v3.z.array(key).max(64),
|
|
115
|
+
completeness: v3.z.object({
|
|
116
|
+
returnedRows: v3.z.number().int().nonnegative(),
|
|
117
|
+
totalRows: v3.z.number().int().nonnegative().optional(),
|
|
118
|
+
totalAccuracy: v3.z.enum([
|
|
119
|
+
'exact',
|
|
120
|
+
'estimated',
|
|
121
|
+
'unknown'
|
|
122
|
+
]),
|
|
123
|
+
scope: v3.z.enum([
|
|
124
|
+
'full_query_result',
|
|
125
|
+
'page',
|
|
126
|
+
'sample',
|
|
127
|
+
'top_n'
|
|
128
|
+
]),
|
|
129
|
+
truncated: v3.z.boolean()
|
|
130
|
+
}).strict(),
|
|
131
|
+
freshness: v3.z.object({
|
|
132
|
+
executedAt: v3.z.string().datetime(),
|
|
133
|
+
sourceFetchedAt: v3.z.string().datetime(),
|
|
134
|
+
dataAsOf: v3.z.string().max(160).optional()
|
|
135
|
+
}).strict(),
|
|
136
|
+
provenance: v3.z.object({
|
|
137
|
+
executionId: key,
|
|
138
|
+
bindingId: key,
|
|
139
|
+
providerId: key,
|
|
140
|
+
sourceVersion: v3.z.string().max(512).optional(),
|
|
141
|
+
upstreamExecutionId: key.optional(),
|
|
142
|
+
auditRef: v3.z.string().max(512).optional(),
|
|
143
|
+
certification: analyticsResult.analyticsCertificationSchema.optional()
|
|
144
|
+
}).strict()
|
|
145
|
+
}).strict().superRefine((value, ctx)=>{
|
|
146
|
+
const ids = new Set(value.fields.map((field)=>field.id));
|
|
147
|
+
if (ids.size !== value.fields.length || new Set(value.grain).size !== value.grain.length || value.grain.some((id)=>!ids.has(id)) || value.completeness.returnedRows !== value.rows.length || value.completeness.totalRows !== undefined && value.completeness.totalRows < value.rows.length || value.completeness.truncated && value.completeness.scope === 'full_query_result') ctx.addIssue({
|
|
148
|
+
code: 'custom',
|
|
149
|
+
message: 'Inconsistent evidence result'
|
|
150
|
+
});
|
|
151
|
+
for (const row of value.rows){
|
|
152
|
+
// Reuse result validation so transport never coerces values or relaxes their logical types.
|
|
153
|
+
if (Object.keys(row).length !== ids.size || Object.keys(row).some((id)=>!ids.has(id)) || value.fields.some((field)=>!Object.prototype.hasOwnProperty.call(row, field.id) || !analyticsResult.isAnalyticsCell(field.logicalType, row[field.id], field.nullable))) ctx.addIssue({
|
|
154
|
+
code: 'custom',
|
|
155
|
+
message: 'Invalid evidence cells'
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
const analysisEvidenceSchema = v3.z.object({
|
|
160
|
+
schema: v3.z.literal('xpert.analysis-evidence@1'),
|
|
161
|
+
id: v3.z.string().uuid(),
|
|
162
|
+
title: v3.z.string().min(1).max(200),
|
|
163
|
+
capturedAt: v3.z.string().datetime(),
|
|
164
|
+
source: v3.z.object({
|
|
165
|
+
artifactId: v3.z.string().uuid(),
|
|
166
|
+
versionId: v3.z.string().uuid(),
|
|
167
|
+
projectId: v3.z.string().uuid()
|
|
168
|
+
}).strict(),
|
|
169
|
+
controls: v3.z.record(key, scalar).refine((value)=>Object.keys(value).length <= 32),
|
|
170
|
+
datasets: v3.z.array(dataset).min(1).max(20),
|
|
171
|
+
statements: v3.z.array(v3.z.object({
|
|
172
|
+
kind: v3.z.enum([
|
|
173
|
+
'fact',
|
|
174
|
+
'inference',
|
|
175
|
+
'unverified'
|
|
176
|
+
]),
|
|
177
|
+
text: v3.z.string().min(1).max(2000),
|
|
178
|
+
citations: v3.z.array(v3.z.object({
|
|
179
|
+
datasetId: key,
|
|
180
|
+
row: v3.z.number().int().nonnegative(),
|
|
181
|
+
field: key
|
|
182
|
+
}).strict()).max(64)
|
|
183
|
+
}).strict()).max(1000),
|
|
184
|
+
sha256: v3.z.string().regex(/^[a-f0-9]{64}$/)
|
|
185
|
+
}).strict().superRefine((value, ctx)=>{
|
|
186
|
+
if (new Set(value.datasets.map((item)=>item.datasetId)).size !== value.datasets.length) ctx.addIssue({
|
|
187
|
+
code: 'custom',
|
|
188
|
+
message: 'Duplicate evidence dataset'
|
|
189
|
+
});
|
|
190
|
+
for (const statement of value.statements){
|
|
191
|
+
// A citation identifies an existing cell; it does not prove the statement's interpretation.
|
|
192
|
+
if (statement.kind === 'fact' && !statement.citations.length) ctx.addIssue({
|
|
193
|
+
code: 'custom',
|
|
194
|
+
message: 'Facts need cell citations'
|
|
195
|
+
});
|
|
196
|
+
for (const citation of statement.citations){
|
|
197
|
+
const data = value.datasets.find((item)=>item.datasetId === citation.datasetId);
|
|
198
|
+
if (!data || citation.row >= data.rows.length || !data.fields.some((field)=>field.id === citation.field)) ctx.addIssue({
|
|
199
|
+
code: 'custom',
|
|
200
|
+
message: 'Unknown evidence cell'
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (new TextEncoder().encode(JSON.stringify(value)).length > 2000000) ctx.addIssue({
|
|
205
|
+
code: 'custom',
|
|
206
|
+
message: 'Evidence exceeds limit'
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
/** Canonicalize validated JSON: sort object keys, but preserve array order and exact scalar values.
|
|
210
|
+
* Omitted optional properties do not affect the digest. Hashing stays in the consumer's runtime. */ function canonicalEvidenceJson(value) {
|
|
211
|
+
if (value === null || typeof value !== 'object') return JSON.stringify(value);
|
|
212
|
+
if (Array.isArray(value)) return '[' + value.map(canonicalEvidenceJson).join(',') + ']';
|
|
213
|
+
return '{' + Object.entries(value).filter(([, entry])=>entry !== undefined).sort(([a], [b])=>a < b ? -1 : a > b ? 1 : 0).map(([name, entry])=>JSON.stringify(name) + ':' + canonicalEvidenceJson(entry)).join(',') + '}';
|
|
214
|
+
}
|
|
215
|
+
/** Validate shape and cell references; callers must verify the digest and current source access separately. */ function parseAnalysisEvidence(value) {
|
|
216
|
+
return analysisEvidenceSchema.parse(value);
|
|
217
|
+
}
|
|
218
|
+
/** Exclude only the digest itself; source, capture time, cells and statement classifications stay covered. */ function analysisEvidenceDigestInput(value) {
|
|
219
|
+
const { sha256: _digest } = value, body = _object_without_properties_loose._object_without_properties_loose(value, [
|
|
220
|
+
"sha256"
|
|
221
|
+
]);
|
|
222
|
+
return canonicalEvidenceJson(body);
|
|
223
|
+
}
|
|
224
|
+
|
|
89
225
|
exports.analyticsBindingObjectSchema = analyticsResult.analyticsBindingObjectSchema;
|
|
90
226
|
exports.analyticsBindingSchema = analyticsResult.analyticsBindingSchema;
|
|
227
|
+
exports.analyticsCertificationSchema = analyticsResult.analyticsCertificationSchema;
|
|
91
228
|
exports.analyticsControlsSchema = analyticsResult.analyticsControlsSchema;
|
|
92
229
|
exports.analyticsDiscoveryRequestObjectSchema = analyticsResult.analyticsDiscoveryRequestObjectSchema;
|
|
93
230
|
exports.analyticsDiscoveryRequestSchema = analyticsResult.analyticsDiscoveryRequestSchema;
|
|
@@ -99,9 +236,14 @@ exports.analyticsQueryRequestSchema = analyticsResult.analyticsQueryRequestSchem
|
|
|
99
236
|
exports.analyticsSourceKey = analyticsResult.analyticsSourceKey;
|
|
100
237
|
exports.analyticsSourceRefSchema = analyticsResult.analyticsSourceRefSchema;
|
|
101
238
|
exports.normalizeAnalyticsResult = analyticsResult.normalizeAnalyticsResult;
|
|
239
|
+
exports.parseAnalyticsCertification = analyticsResult.parseAnalyticsCertification;
|
|
102
240
|
exports.resolveAnalyticsParameters = analyticsResult.resolveAnalyticsParameters;
|
|
103
241
|
exports.validateAnalyticsBinding = analyticsResult.validateAnalyticsBinding;
|
|
242
|
+
exports.analysisEvidenceDigestInput = analysisEvidenceDigestInput;
|
|
243
|
+
exports.analysisEvidenceSchema = analysisEvidenceSchema;
|
|
244
|
+
exports.canonicalEvidenceJson = canonicalEvidenceJson;
|
|
104
245
|
exports.isResourceAnalysisFilterValue = isResourceAnalysisFilterValue;
|
|
246
|
+
exports.parseAnalysisEvidence = parseAnalysisEvidence;
|
|
105
247
|
exports.resourceAnalysisFilterSchema = resourceAnalysisFilterSchema;
|
|
106
248
|
exports.resourceAnalysisPolicySchema = resourceAnalysisPolicySchema;
|
|
107
249
|
exports.resourceAnalysisQuerySchema = resourceAnalysisQuerySchema;
|