@redditech/agent-protocol 0.0.0-stage → 0.2.1

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 (55) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +394 -2
  4. package/dist/adl.d.ts +141 -0
  5. package/dist/adl.js +3601 -0
  6. package/dist/agent-stack-fixtures.d.ts +743 -0
  7. package/dist/agent-stack-fixtures.js +1554 -0
  8. package/dist/ai-catalog.d.ts +128 -0
  9. package/dist/ai-catalog.js +373 -0
  10. package/dist/attestation-reputation.d.ts +102 -0
  11. package/dist/attestation-reputation.js +279 -0
  12. package/dist/audd-rail-config.d.ts +102 -0
  13. package/dist/audd-rail-config.js +294 -0
  14. package/dist/browser-wallet-approval.d.ts +293 -0
  15. package/dist/browser-wallet-approval.js +1201 -0
  16. package/dist/discovery-source.d.ts +115 -0
  17. package/dist/discovery-source.js +251 -0
  18. package/dist/evidence-archive.d.ts +73 -0
  19. package/dist/evidence-archive.js +238 -0
  20. package/dist/index.d.ts +23 -0
  21. package/dist/index.js +23 -0
  22. package/dist/mpp-tempo-receipt-shapes.d.ts +201 -0
  23. package/dist/mpp-tempo-receipt-shapes.js +330 -0
  24. package/dist/okf-adapter.d.ts +229 -0
  25. package/dist/okf-adapter.js +556 -0
  26. package/dist/okf-conformance.d.ts +208 -0
  27. package/dist/okf-conformance.js +651 -0
  28. package/dist/okf-instruction-safety.d.ts +192 -0
  29. package/dist/okf-instruction-safety.js +509 -0
  30. package/dist/onboarding-analyser-handoff.d.ts +391 -0
  31. package/dist/onboarding-analyser-handoff.js +959 -0
  32. package/dist/onboarding-state-machine.d.ts +228 -0
  33. package/dist/onboarding-state-machine.js +432 -0
  34. package/dist/payment-records.d.ts +181 -0
  35. package/dist/payment-records.js +599 -0
  36. package/dist/policy.d.ts +33 -0
  37. package/dist/policy.js +45 -0
  38. package/dist/provider-trust.d.ts +113 -0
  39. package/dist/provider-trust.js +346 -0
  40. package/dist/quasar-registry-compatibility.d.ts +113 -0
  41. package/dist/quasar-registry-compatibility.js +214 -0
  42. package/dist/ranking-explainability.d.ts +202 -0
  43. package/dist/ranking-explainability.js +302 -0
  44. package/dist/receipt-v2.d.ts +202 -0
  45. package/dist/receipt-v2.js +418 -0
  46. package/dist/repo-explorer-evidence-manifest.d.ts +387 -0
  47. package/dist/repo-explorer-evidence-manifest.js +1187 -0
  48. package/dist/source-diagnostics.d.ts +84 -0
  49. package/dist/source-diagnostics.js +193 -0
  50. package/dist/source-trust-conformance-matrix.d.ts +207 -0
  51. package/dist/source-trust-conformance-matrix.js +672 -0
  52. package/examples/ard-no-spend-ai-catalog.json +51 -0
  53. package/examples/ard-no-spend-demo.mjs +355 -0
  54. package/examples/interpretation-guide-scenarios.mjs +302 -0
  55. package/package.json +144 -4
@@ -0,0 +1,128 @@
1
+ export declare const AI_CATALOG_SCHEMA_VERSION: "ai-catalog.v1";
2
+ export type AiCatalogResourceType = string;
3
+ export type AiCatalogValidationErrorCode = 'malformed_catalog' | 'unsupported_resource_type' | 'invalid_identifier' | 'invalid_reference' | 'unsafe_url' | 'nested_catalog_boundary' | 'credential_leakage_rejected' | 'catalog_too_large';
4
+ export type AiCatalogValidationError = {
5
+ code: AiCatalogValidationErrorCode;
6
+ path: string;
7
+ message: string;
8
+ };
9
+ export type AiCatalogPublisherSnapshot = {
10
+ id: string;
11
+ name?: string;
12
+ domain?: string;
13
+ };
14
+ export type AiCatalogResourceSnapshot = {
15
+ id: string;
16
+ type: AiCatalogResourceType;
17
+ mediaType: string;
18
+ name: string;
19
+ description?: string;
20
+ url?: string;
21
+ endpoint?: string;
22
+ catalogUrl?: string;
23
+ trustManifest?: unknown;
24
+ capabilities?: unknown;
25
+ payment?: unknown;
26
+ auth?: unknown;
27
+ raw: unknown;
28
+ };
29
+ export type AiCatalogSnapshot = {
30
+ schemaVersion: typeof AI_CATALOG_SCHEMA_VERSION;
31
+ publisher: AiCatalogPublisherSnapshot;
32
+ resources: AiCatalogResourceSnapshot[];
33
+ rawSnapshotRef?: string;
34
+ };
35
+ export type AiCatalogValidationSuccess = {
36
+ ok: true;
37
+ catalog: AiCatalogSnapshot;
38
+ warnings: AiCatalogValidationError[];
39
+ };
40
+ export type AiCatalogValidationFailure = {
41
+ ok: false;
42
+ errors: AiCatalogValidationError[];
43
+ };
44
+ export type AiCatalogValidationResult = AiCatalogValidationSuccess | AiCatalogValidationFailure;
45
+ export type AiCatalogValidationOptions = {
46
+ rawSnapshotRef?: string;
47
+ maxBytes?: number;
48
+ };
49
+ export type AiCatalogFixtureCase = {
50
+ description: string;
51
+ catalog: unknown;
52
+ expectedValid: boolean;
53
+ expectedErrorCodes: AiCatalogValidationErrorCode[];
54
+ };
55
+ export declare function validateAiCatalog(input: unknown, options?: AiCatalogValidationOptions): AiCatalogValidationResult;
56
+ export declare function createAiCatalogSnapshot(input: unknown, options?: AiCatalogValidationOptions): AiCatalogSnapshot;
57
+ export declare const aiCatalogFixtures: {
58
+ readonly happyPath: {
59
+ readonly specVersion: "1.0";
60
+ readonly host: {
61
+ readonly identifier: "reddi.tech";
62
+ readonly displayName: "Reddi";
63
+ };
64
+ readonly entries: readonly [{
65
+ readonly identifier: "urn:ai:reddi.tech:specialists:code-review";
66
+ readonly mediaType: "application/mcp-server-card+json";
67
+ readonly displayName: "Code Review Specialist";
68
+ readonly description: "Reviews pull requests and emits RAP-compatible evidence.";
69
+ readonly url: "https://agents.reddi.tech/code-review/mcp.json";
70
+ readonly metadata: {
71
+ readonly capabilities: readonly ["code_review", "risk_analysis"];
72
+ readonly rap: {
73
+ readonly payment: {
74
+ readonly protocol: "rap";
75
+ readonly quoteMode: "preflight";
76
+ readonly assets: readonly [{
77
+ readonly asset: "AUDD";
78
+ readonly network: "solana-devnet";
79
+ }];
80
+ };
81
+ readonly auth: {
82
+ readonly type: "oauth";
83
+ readonly scopes: readonly ["repo:read"];
84
+ };
85
+ };
86
+ };
87
+ readonly trustManifest: {
88
+ readonly identity: "urn:ai:reddi.tech:specialists:code-review";
89
+ readonly signature: {
90
+ readonly format: "dsse";
91
+ readonly status: "claimed";
92
+ };
93
+ };
94
+ }, {
95
+ readonly identifier: "urn:ai:reddi.tech:apis:receipt-validator";
96
+ readonly mediaType: "application/openapi+json";
97
+ readonly displayName: "Receipt Validator API";
98
+ readonly url: "https://agents.reddi.tech/apis/receipt-validator";
99
+ readonly metadata: {
100
+ readonly capabilities: readonly ["receipt_validation"];
101
+ };
102
+ }];
103
+ };
104
+ readonly nestedCatalog: {
105
+ readonly specVersion: "1.0";
106
+ readonly host: {
107
+ readonly displayName: "Reddi";
108
+ readonly identifier: "reddi.tech";
109
+ };
110
+ readonly entries: readonly [{
111
+ readonly identifier: "urn:ai:reddi.tech:catalogs:local-specialists";
112
+ readonly mediaType: "application/ai-catalog+json";
113
+ readonly displayName: "Local Specialists Catalog";
114
+ readonly url: "https://agents.reddi.tech/.well-known/local-specialists.ai-catalog.json";
115
+ }];
116
+ };
117
+ readonly localhostFixture: {
118
+ readonly specVersion: "1.0";
119
+ readonly host: "localhost";
120
+ readonly entries: readonly [{
121
+ readonly identifier: "urn:ai:localhost:fixtures:demo-specialist";
122
+ readonly mediaType: "application/mcp-server-card+json";
123
+ readonly displayName: "Demo MCP Specialist";
124
+ readonly url: "http://localhost:4317/mcp";
125
+ }];
126
+ };
127
+ };
128
+ export declare const aiCatalogFixtureCases: Record<string, AiCatalogFixtureCase>;
@@ -0,0 +1,373 @@
1
+ export const AI_CATALOG_SCHEMA_VERSION = 'ai-catalog.v1';
2
+ const AI_CATALOG_MEDIA_TYPE = 'application/ai-catalog+json';
3
+ const AI_IDENTIFIER_PATTERN = /^(urn:[a-z0-9][a-z0-9-]*:.+|https?:\/\/.+)$/i;
4
+ const MEDIA_TYPE_PATTERN = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*(?:\+[a-z0-9][a-z0-9!#$&^_.+-]*)?$/i;
5
+ const LEGACY_TYPE_PATTERN = /^[a-z0-9][a-z0-9._-]*$/i;
6
+ const SECRET_KEY_PATTERN = /(^|[_-])(api[_-]?key|access[_-]?token|refresh[_-]?token|private[_-]?key|client[_-]?secret|authorization|bearer|password|secret|token)($|[_-])/i;
7
+ const SECRET_VALUE_PATTERN = /(authorization:\s*bearer\s+|sk-[a-z0-9_-]{8,}|xox[baprs]-|-----BEGIN [A-Z ]*PRIVATE KEY-----)/i;
8
+ function error(code, path, message) {
9
+ return { code, path, message };
10
+ }
11
+ function isPlainObject(value) {
12
+ if (value === null || typeof value !== 'object')
13
+ return false;
14
+ const prototype = Object.getPrototypeOf(value);
15
+ return prototype === Object.prototype || prototype === null;
16
+ }
17
+ function asString(value) {
18
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
19
+ }
20
+ function byteLength(value) {
21
+ try {
22
+ return new TextEncoder().encode(JSON.stringify(value)).length;
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ function containsCredentialMaterial(value, path = '$') {
29
+ if (typeof value === 'string') {
30
+ if (SECRET_VALUE_PATTERN.test(value)) {
31
+ return error('credential_leakage_rejected', path, 'Credential-shaped string values are not allowed in AI Catalog metadata.');
32
+ }
33
+ return undefined;
34
+ }
35
+ if (Array.isArray(value)) {
36
+ for (let index = 0; index < value.length; index += 1) {
37
+ const child = containsCredentialMaterial(value[index], `${path}[${index}]`);
38
+ if (child)
39
+ return child;
40
+ }
41
+ return undefined;
42
+ }
43
+ if (isPlainObject(value)) {
44
+ for (const [key, childValue] of Object.entries(value)) {
45
+ const childPath = `${path}.${key}`;
46
+ if (SECRET_KEY_PATTERN.test(key)) {
47
+ return error('credential_leakage_rejected', childPath, 'Credential-shaped keys are not allowed in AI Catalog metadata.');
48
+ }
49
+ const child = containsCredentialMaterial(childValue, childPath);
50
+ if (child)
51
+ return child;
52
+ }
53
+ }
54
+ return undefined;
55
+ }
56
+ function validateSafeUrl(value, path) {
57
+ let parsed;
58
+ try {
59
+ parsed = new URL(value);
60
+ }
61
+ catch {
62
+ return error('invalid_reference', path, 'Reference must be a valid URL.');
63
+ }
64
+ if (parsed.username || parsed.password) {
65
+ return error('unsafe_url', path, 'Reference URLs must not embed credentials.');
66
+ }
67
+ for (const key of parsed.searchParams.keys()) {
68
+ if (SECRET_KEY_PATTERN.test(key)) {
69
+ return error('credential_leakage_rejected', `${path}.${key}`, 'Reference URLs must not include credential-shaped query parameters.');
70
+ }
71
+ }
72
+ for (const value of parsed.searchParams.values()) {
73
+ if (SECRET_VALUE_PATTERN.test(value)) {
74
+ return error('credential_leakage_rejected', path, 'Reference URLs must not include credential-shaped query values.');
75
+ }
76
+ }
77
+ if (parsed.protocol === 'https:')
78
+ return undefined;
79
+ const localhost = parsed.hostname === 'localhost' || parsed.hostname === '127.0.0.1' || parsed.hostname === '::1';
80
+ if (parsed.protocol === 'http:' && localhost)
81
+ return undefined;
82
+ return error('unsafe_url', path, 'Reference URLs must use HTTPS, except localhost HTTP fixtures.');
83
+ }
84
+ function parsePublisher(value, path, errors) {
85
+ if (typeof value === 'string' && value.trim())
86
+ return { id: value.trim() };
87
+ if (!isPlainObject(value)) {
88
+ errors.push(error('malformed_catalog', path, 'Catalog host/publisher must be a string or object.'));
89
+ return undefined;
90
+ }
91
+ const id = asString(value.identifier) ?? asString(value.id) ?? asString(value.domain) ?? asString(value.displayName) ?? asString(value.name);
92
+ if (!id) {
93
+ errors.push(error('malformed_catalog', `${path}.identifier`, 'Catalog host/publisher must include identifier, id, domain, displayName, or name.'));
94
+ return undefined;
95
+ }
96
+ return {
97
+ id,
98
+ name: asString(value.displayName) ?? asString(value.name),
99
+ domain: asString(value.domain),
100
+ };
101
+ }
102
+ function parseResources(value, errors) {
103
+ const rawResources = value.entries ?? value.resources ?? value.items;
104
+ const resourcesPath = Array.isArray(value.entries) ? '$.entries' : Array.isArray(value.resources) ? '$.resources' : '$.items';
105
+ if (!Array.isArray(rawResources)) {
106
+ errors.push(error('malformed_catalog', '$.entries', 'Catalog must include an entries array.'));
107
+ return [];
108
+ }
109
+ const resources = [];
110
+ for (let index = 0; index < rawResources.length; index += 1) {
111
+ const path = `${resourcesPath}[${index}]`;
112
+ const raw = rawResources[index];
113
+ if (!isPlainObject(raw)) {
114
+ errors.push(error('malformed_catalog', path, 'Catalog resource must be an object.'));
115
+ continue;
116
+ }
117
+ const id = asString(raw.identifier) ?? asString(raw.id);
118
+ if (!id || !AI_IDENTIFIER_PATTERN.test(id)) {
119
+ errors.push(error('invalid_identifier', `${path}.identifier`, 'Catalog entry identifier must be a stable URN or URL.'));
120
+ }
121
+ const mediaType = asString(raw.mediaType) ?? asString(raw.type);
122
+ if (!mediaType || (!MEDIA_TYPE_PATTERN.test(mediaType) && !LEGACY_TYPE_PATTERN.test(mediaType))) {
123
+ errors.push(error('unsupported_resource_type', `${path}.mediaType`, 'Catalog entry mediaType must be a valid media type or legacy resource type.'));
124
+ }
125
+ const name = asString(raw.displayName) ?? asString(raw.name);
126
+ if (!name) {
127
+ errors.push(error('malformed_catalog', `${path}.displayName`, 'Catalog entry must include a non-empty displayName.'));
128
+ }
129
+ const url = asString(raw.url);
130
+ const endpoint = asString(raw.endpoint);
131
+ const catalogUrlRaw = asString(raw.catalogUrl) ?? asString(raw.catalog_url);
132
+ const isNestedCatalog = mediaType === AI_CATALOG_MEDIA_TYPE || mediaType === 'catalog';
133
+ const catalogUrl = isNestedCatalog ? (catalogUrlRaw ?? url) : catalogUrlRaw;
134
+ const hasInlineData = Object.prototype.hasOwnProperty.call(raw, 'data');
135
+ const referenceCount = [url, endpoint, catalogUrlRaw].filter(Boolean).length;
136
+ if (hasInlineData && referenceCount > 0) {
137
+ errors.push(error('invalid_reference', path, 'Catalog resources must not mix inline data with URL references.'));
138
+ }
139
+ if (!hasInlineData && referenceCount > 1) {
140
+ errors.push(error('invalid_reference', path, 'Catalog resources must include exactly one URL reference.'));
141
+ }
142
+ if (!hasInlineData && referenceCount === 0) {
143
+ errors.push(error('invalid_reference', path, 'Catalog resources must include inline data or one URL reference.'));
144
+ }
145
+ for (const [key, reference] of Object.entries({ url, endpoint, catalogUrl })) {
146
+ if (!reference)
147
+ continue;
148
+ const invalidUrl = validateSafeUrl(reference, `${path}.${key}`);
149
+ if (invalidUrl)
150
+ errors.push(invalidUrl);
151
+ }
152
+ if (isNestedCatalog) {
153
+ if (!catalogUrl || hasInlineData || endpoint || (url && catalogUrlRaw)) {
154
+ errors.push(error('nested_catalog_boundary', path, 'Nested catalog entries must use a single URL reference.'));
155
+ }
156
+ }
157
+ else if (catalogUrl) {
158
+ errors.push(error('nested_catalog_boundary', `${path}.catalogUrl`, 'Only catalog resources may reference nested catalogs.'));
159
+ }
160
+ const metadata = isPlainObject(raw.metadata) ? raw.metadata : undefined;
161
+ const rapMetadata = metadata && isPlainObject(metadata.rap) ? metadata.rap : undefined;
162
+ if (id && mediaType && name) {
163
+ resources.push({
164
+ id,
165
+ type: mediaType,
166
+ mediaType,
167
+ name,
168
+ description: asString(raw.description),
169
+ url,
170
+ endpoint,
171
+ catalogUrl,
172
+ trustManifest: raw.trustManifest,
173
+ capabilities: raw.capabilities ?? metadata?.capabilities,
174
+ payment: raw.payment ?? rapMetadata?.payment ?? metadata?.payment,
175
+ auth: raw.auth ?? rapMetadata?.auth ?? metadata?.auth,
176
+ raw,
177
+ });
178
+ }
179
+ }
180
+ return resources;
181
+ }
182
+ export function validateAiCatalog(input, options = {}) {
183
+ const maxBytes = options.maxBytes ?? 64_000;
184
+ const errors = [];
185
+ if (!isPlainObject(input)) {
186
+ return { ok: false, errors: [error('malformed_catalog', '$', 'AI Catalog must be a plain object.')] };
187
+ }
188
+ const size = byteLength(input);
189
+ if (size === undefined) {
190
+ return { ok: false, errors: [error('malformed_catalog', '$', 'AI Catalog must be JSON-serializable.')] };
191
+ }
192
+ if (size > maxBytes) {
193
+ return { ok: false, errors: [error('catalog_too_large', '$', `AI Catalog exceeds ${maxBytes} bytes.`)] };
194
+ }
195
+ const credentialLeak = containsCredentialMaterial(input);
196
+ if (credentialLeak)
197
+ return { ok: false, errors: [credentialLeak] };
198
+ if (!asString(input.specVersion) && Object.prototype.hasOwnProperty.call(input, 'entries')) {
199
+ errors.push(error('malformed_catalog', '$.specVersion', 'AI Catalog entries require a specVersion string.'));
200
+ }
201
+ const hostOrPublisher = input.host ?? input.publisher;
202
+ const publisherPath = Object.prototype.hasOwnProperty.call(input, 'host') ? '$.host' : '$.publisher';
203
+ const publisher = hostOrPublisher === undefined ? { id: 'unknown' } : parsePublisher(hostOrPublisher, publisherPath, errors);
204
+ const resources = parseResources(input, errors);
205
+ if (!publisher || errors.length > 0)
206
+ return { ok: false, errors };
207
+ return {
208
+ ok: true,
209
+ catalog: {
210
+ schemaVersion: AI_CATALOG_SCHEMA_VERSION,
211
+ publisher,
212
+ resources,
213
+ rawSnapshotRef: options.rawSnapshotRef,
214
+ },
215
+ warnings: [],
216
+ };
217
+ }
218
+ export function createAiCatalogSnapshot(input, options = {}) {
219
+ const result = validateAiCatalog(input, options);
220
+ if (!result.ok) {
221
+ throw new Error(`invalid_ai_catalog:${result.errors.map((item) => item.code).join(',')}`);
222
+ }
223
+ return result.catalog;
224
+ }
225
+ export const aiCatalogFixtures = {
226
+ happyPath: {
227
+ specVersion: '1.0',
228
+ host: {
229
+ identifier: 'reddi.tech',
230
+ displayName: 'Reddi',
231
+ },
232
+ entries: [
233
+ {
234
+ identifier: 'urn:ai:reddi.tech:specialists:code-review',
235
+ mediaType: 'application/mcp-server-card+json',
236
+ displayName: 'Code Review Specialist',
237
+ description: 'Reviews pull requests and emits RAP-compatible evidence.',
238
+ url: 'https://agents.reddi.tech/code-review/mcp.json',
239
+ metadata: {
240
+ capabilities: ['code_review', 'risk_analysis'],
241
+ rap: {
242
+ payment: {
243
+ protocol: 'rap',
244
+ quoteMode: 'preflight',
245
+ assets: [{ asset: 'AUDD', network: 'solana-devnet' }],
246
+ },
247
+ auth: {
248
+ type: 'oauth',
249
+ scopes: ['repo:read'],
250
+ },
251
+ },
252
+ },
253
+ trustManifest: {
254
+ identity: 'urn:ai:reddi.tech:specialists:code-review',
255
+ signature: {
256
+ format: 'dsse',
257
+ status: 'claimed',
258
+ },
259
+ },
260
+ },
261
+ {
262
+ identifier: 'urn:ai:reddi.tech:apis:receipt-validator',
263
+ mediaType: 'application/openapi+json',
264
+ displayName: 'Receipt Validator API',
265
+ url: 'https://agents.reddi.tech/apis/receipt-validator',
266
+ metadata: {
267
+ capabilities: ['receipt_validation'],
268
+ },
269
+ },
270
+ ],
271
+ },
272
+ nestedCatalog: {
273
+ specVersion: '1.0',
274
+ host: {
275
+ displayName: 'Reddi',
276
+ identifier: 'reddi.tech',
277
+ },
278
+ entries: [
279
+ {
280
+ identifier: 'urn:ai:reddi.tech:catalogs:local-specialists',
281
+ mediaType: AI_CATALOG_MEDIA_TYPE,
282
+ displayName: 'Local Specialists Catalog',
283
+ url: 'https://agents.reddi.tech/.well-known/local-specialists.ai-catalog.json',
284
+ },
285
+ ],
286
+ },
287
+ localhostFixture: {
288
+ specVersion: '1.0',
289
+ host: 'localhost',
290
+ entries: [
291
+ {
292
+ identifier: 'urn:ai:localhost:fixtures:demo-specialist',
293
+ mediaType: 'application/mcp-server-card+json',
294
+ displayName: 'Demo MCP Specialist',
295
+ url: 'http://localhost:4317/mcp',
296
+ },
297
+ ],
298
+ },
299
+ };
300
+ export const aiCatalogFixtureCases = {
301
+ happyPath: {
302
+ description: 'Valid AI Catalog with RAP-compatible agent and API resources.',
303
+ catalog: aiCatalogFixtures.happyPath,
304
+ expectedValid: true,
305
+ expectedErrorCodes: [],
306
+ },
307
+ nestedCatalog: {
308
+ description: 'Valid nested catalog reference that keeps catalog boundaries explicit.',
309
+ catalog: aiCatalogFixtures.nestedCatalog,
310
+ expectedValid: true,
311
+ expectedErrorCodes: [],
312
+ },
313
+ malformedCatalog: {
314
+ description: 'Missing publisher and resources fails closed.',
315
+ catalog: { name: 'not enough catalog shape' },
316
+ expectedValid: false,
317
+ expectedErrorCodes: ['malformed_catalog'],
318
+ },
319
+ unsupportedResourceType: {
320
+ description: 'Unknown resource types are rejected.',
321
+ catalog: {
322
+ specVersion: '1.0',
323
+ host: 'reddi.tech',
324
+ entries: [
325
+ {
326
+ identifier: 'urn:ai:reddi.tech:unknown:thing',
327
+ mediaType: 'not a media type!',
328
+ displayName: 'Unsupported Thing',
329
+ url: 'https://agents.reddi.tech/unsupported',
330
+ },
331
+ ],
332
+ },
333
+ expectedValid: false,
334
+ expectedErrorCodes: ['unsupported_resource_type'],
335
+ },
336
+ unsafeUrl: {
337
+ description: 'Non-HTTPS non-localhost references are rejected.',
338
+ catalog: {
339
+ specVersion: '1.0',
340
+ host: 'reddi.tech',
341
+ entries: [
342
+ {
343
+ identifier: 'urn:ai:reddi.tech:specialists:unsafe',
344
+ mediaType: 'application/mcp-server-card+json',
345
+ displayName: 'Unsafe Specialist',
346
+ url: 'http://agents.reddi.tech/unsafe',
347
+ },
348
+ ],
349
+ },
350
+ expectedValid: false,
351
+ expectedErrorCodes: ['unsafe_url'],
352
+ },
353
+ credentialLeakage: {
354
+ description: 'Credential-shaped metadata is rejected before ingestion.',
355
+ catalog: {
356
+ specVersion: '1.0',
357
+ host: 'reddi.tech',
358
+ entries: [
359
+ {
360
+ identifier: 'urn:ai:reddi.tech:specialists:leaky',
361
+ mediaType: 'application/mcp-server-card+json',
362
+ displayName: 'Leaky Specialist',
363
+ url: 'https://agents.reddi.tech/leaky',
364
+ auth: {
365
+ accessToken: 'tok_should_not_be_in_catalogs',
366
+ },
367
+ },
368
+ ],
369
+ },
370
+ expectedValid: false,
371
+ expectedErrorCodes: ['credential_leakage_rejected'],
372
+ },
373
+ };
@@ -0,0 +1,102 @@
1
+ export declare const ATTESTATION_RECORD_SCHEMA_VERSION: "reddi.attestation.v1";
2
+ export declare const REPUTATION_EVENT_SCHEMA_VERSION: "reddi.reputation-event.v1";
3
+ export declare const REPUTATION_STATE_SCHEMA_VERSION: "reddi.reputation-state.v1";
4
+ export declare const DEFAULT_ATTESTATION_RUBRIC_DIMENSIONS: readonly ["evidence_integrity", "policy_compliance", "delivery_quality"];
5
+ export type AttestationVerdict = 'passed' | 'failed' | 'disputed' | 'refunded';
6
+ export type AttestationWorkStatus = 'completed' | 'failed' | 'disputed' | 'refunded';
7
+ export type AttestationTrustBoundary = 'self_attested' | 'external_attested' | 'reddi_attested' | 'verified';
8
+ export type ReputationRoutingImpact = 'preferred' | 'eligible' | 'watch' | 'deprioritized' | 'blocked' | 'unproven';
9
+ export type AttestationRubricDimension = {
10
+ id: string;
11
+ score: number;
12
+ weight: number;
13
+ summary: string;
14
+ reasonCodes: string[];
15
+ };
16
+ export type AttestationRecord = {
17
+ schemaVersion: typeof ATTESTATION_RECORD_SCHEMA_VERSION;
18
+ id: string;
19
+ receiptId: string;
20
+ evidenceId: string;
21
+ evidenceRef: string;
22
+ evidenceHash: string;
23
+ attestor: {
24
+ id: string;
25
+ type: 'self' | 'external' | 'reddi' | 'local-fixture';
26
+ };
27
+ trustBoundary: AttestationTrustBoundary;
28
+ verdict: AttestationVerdict;
29
+ workStatus: AttestationWorkStatus;
30
+ confidence: number;
31
+ rubric: {
32
+ dimensions: AttestationRubricDimension[];
33
+ };
34
+ createdAt: string;
35
+ metadata?: Record<string, unknown>;
36
+ };
37
+ export type ReputationState = {
38
+ schemaVersion: typeof REPUTATION_STATE_SCHEMA_VERSION;
39
+ subject: {
40
+ id: string;
41
+ type: 'specialist' | 'provider' | 'listing';
42
+ };
43
+ score: number;
44
+ routingImpact: ReputationRoutingImpact;
45
+ completedJobs: number;
46
+ attestedJobs: number;
47
+ failedJobs: number;
48
+ disputedJobs: number;
49
+ refundedJobs: number;
50
+ lastEventId?: string;
51
+ updatedAt: string;
52
+ };
53
+ export type ReputationEventReasonCode = 'attestation_passed' | 'attestation_failed' | 'work_disputed' | 'work_refunded' | 'low_confidence' | 'rubric_below_threshold' | 'evidence_attached';
54
+ export type ReputationEvent = {
55
+ schemaVersion: typeof REPUTATION_EVENT_SCHEMA_VERSION;
56
+ id: string;
57
+ subjectId: string;
58
+ receiptId: string;
59
+ attestationId: string;
60
+ evidenceId: string;
61
+ verdict: AttestationVerdict;
62
+ workStatus: AttestationWorkStatus;
63
+ trustBoundary: AttestationTrustBoundary;
64
+ confidence: number;
65
+ rubricScore: number;
66
+ delta: number;
67
+ previousScore: number;
68
+ nextScore: number;
69
+ routingImpact: ReputationRoutingImpact;
70
+ reasonCodes: ReputationEventReasonCode[];
71
+ createdAt: string;
72
+ };
73
+ export type AttestationValidationErrorCode = 'malformed_attestation' | 'missing_rubric_dimension' | 'invalid_rubric_dimension' | 'credential_leakage_rejected';
74
+ export type AttestationValidationError = {
75
+ code: AttestationValidationErrorCode;
76
+ path: string;
77
+ message: string;
78
+ };
79
+ export type AttestationValidationResult = {
80
+ ok: true;
81
+ attestation: AttestationRecord;
82
+ } | {
83
+ ok: false;
84
+ errors: AttestationValidationError[];
85
+ };
86
+ export type ReputationUpdateResult = {
87
+ ok: true;
88
+ event: ReputationEvent;
89
+ state: ReputationState;
90
+ } | {
91
+ ok: false;
92
+ errors: AttestationValidationError[];
93
+ state: ReputationState;
94
+ };
95
+ export type ReputationApplyOptions = {
96
+ subject?: ReputationState['subject'];
97
+ now?: string;
98
+ };
99
+ export declare function validateAttestationRecord(input: unknown): AttestationValidationResult;
100
+ export declare function createAttestationRecord(input: AttestationRecord): AttestationRecord;
101
+ export declare function createInitialReputationState(subject: ReputationState['subject'], updatedAt?: string): ReputationState;
102
+ export declare function applyAttestationToReputation(attestationInput: unknown, previousState?: ReputationState, options?: ReputationApplyOptions): ReputationUpdateResult;