@agentropy/core 0.0.0-bootstrap.0 → 0.1.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/LICENSE +202 -0
- package/README.md +37 -1
- package/dist/acceptance.d.ts +30 -0
- package/dist/acceptance.js +194 -0
- package/dist/agent.d.ts +284 -0
- package/dist/agent.js +1 -0
- package/dist/capability.d.ts +89 -0
- package/dist/capability.js +1 -0
- package/dist/catalog.d.ts +8 -0
- package/dist/catalog.js +217 -0
- package/dist/communication.d.ts +101 -0
- package/dist/communication.js +1 -0
- package/dist/cron.d.ts +2 -0
- package/dist/cron.js +55 -0
- package/dist/errors.d.ts +326 -0
- package/dist/errors.js +150 -0
- package/dist/implementation.d.ts +31 -0
- package/dist/implementation.js +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/lifecycle.d.ts +26 -0
- package/dist/lifecycle.js +101 -0
- package/dist/messaging.d.ts +112 -0
- package/dist/messaging.js +32 -0
- package/dist/providers.d.ts +82 -0
- package/dist/providers.js +5 -0
- package/dist/resolver.d.ts +30 -0
- package/dist/resolver.js +192 -0
- package/dist/schemas.d.ts +420 -0
- package/dist/schemas.js +364 -0
- package/dist/security.d.ts +48 -0
- package/dist/security.js +1 -0
- package/dist/skill.d.ts +52 -0
- package/dist/skill.js +1 -0
- package/dist/store.d.ts +123 -0
- package/dist/store.js +220 -0
- package/dist/telemetry.d.ts +72 -0
- package/dist/telemetry.js +69 -0
- package/dist/tool.d.ts +89 -0
- package/dist/tool.js +1 -0
- package/package.json +38 -5
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
/** JSON Schema 2020-12 documents for Agent v1 rev 7, Tool v1 and Skill v1, plus validation (ADR-0027). */
|
|
2
|
+
import { Ajv2020, } from 'ajv/dist/2020.js';
|
|
3
|
+
import addFormatsModule from 'ajv-formats';
|
|
4
|
+
import semver from 'semver';
|
|
5
|
+
import { AgentropyError } from './errors.js';
|
|
6
|
+
const addFormats = addFormatsModule;
|
|
7
|
+
const SEMVER = '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$';
|
|
8
|
+
const ID = '^[a-z0-9][a-z0-9._/-]{0,127}$';
|
|
9
|
+
const nonEmpty = { type: 'string', minLength: 1 };
|
|
10
|
+
const versionedRef = {
|
|
11
|
+
type: 'object',
|
|
12
|
+
required: ['id', 'version'],
|
|
13
|
+
additionalProperties: false,
|
|
14
|
+
properties: {
|
|
15
|
+
id: { type: 'string', pattern: ID },
|
|
16
|
+
version: { type: 'string', pattern: SEMVER },
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const jsonSchemaDoc = { type: ['object', 'boolean'] };
|
|
20
|
+
export const CAPABILITY_SELECTION_SCHEMA = {
|
|
21
|
+
$id: 'https://agentropy.dev/schemas/v1/capability-selection.json',
|
|
22
|
+
type: 'object',
|
|
23
|
+
required: ['id', 'versionRange'],
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
properties: {
|
|
26
|
+
id: { type: 'string', pattern: ID },
|
|
27
|
+
versionRange: nonEmpty,
|
|
28
|
+
config: { type: 'object' },
|
|
29
|
+
providerId: nonEmpty,
|
|
30
|
+
level: nonEmpty,
|
|
31
|
+
remove: { type: 'boolean' },
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export const TOOL_SELECTION_SCHEMA = {
|
|
35
|
+
$id: 'https://agentropy.dev/schemas/v1/tool-selection.json',
|
|
36
|
+
type: 'object',
|
|
37
|
+
required: ['id', 'versionRange'],
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
properties: {
|
|
40
|
+
id: { type: 'string', pattern: ID },
|
|
41
|
+
versionRange: nonEmpty,
|
|
42
|
+
required: { type: 'boolean' },
|
|
43
|
+
bindingId: nonEmpty,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
export const SKILL_SELECTION_SCHEMA = {
|
|
47
|
+
$id: 'https://agentropy.dev/schemas/v1/skill-selection.json',
|
|
48
|
+
type: 'object',
|
|
49
|
+
required: ['id', 'versionRange'],
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
properties: {
|
|
52
|
+
id: { type: 'string', pattern: ID },
|
|
53
|
+
versionRange: nonEmpty,
|
|
54
|
+
required: { type: 'boolean' },
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
export const AGENT_DEFINITION_SCHEMA = {
|
|
58
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
59
|
+
$id: 'https://agentropy.dev/schemas/v1/agent-definition.json',
|
|
60
|
+
title: 'AgentDefinition (Agent v1 revision 7)',
|
|
61
|
+
type: 'object',
|
|
62
|
+
required: [
|
|
63
|
+
'id',
|
|
64
|
+
'version',
|
|
65
|
+
'displayName',
|
|
66
|
+
'profile',
|
|
67
|
+
'implementation',
|
|
68
|
+
'inputSchema',
|
|
69
|
+
'runtimeRequirements',
|
|
70
|
+
'policyRef',
|
|
71
|
+
],
|
|
72
|
+
additionalProperties: false,
|
|
73
|
+
properties: {
|
|
74
|
+
id: { type: 'string', pattern: ID },
|
|
75
|
+
version: { type: 'string', pattern: SEMVER },
|
|
76
|
+
displayName: { type: 'string', minLength: 1, maxLength: 200 },
|
|
77
|
+
profile: versionedRef,
|
|
78
|
+
implementation: {
|
|
79
|
+
type: 'object',
|
|
80
|
+
required: ['providerId', 'providerVersion', 'artifact'],
|
|
81
|
+
additionalProperties: false,
|
|
82
|
+
properties: {
|
|
83
|
+
providerId: { type: 'string', pattern: ID },
|
|
84
|
+
providerVersion: { type: 'string', pattern: SEMVER },
|
|
85
|
+
artifact: versionedRef,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
inputSchema: jsonSchemaDoc,
|
|
89
|
+
runtimeRequirements: {
|
|
90
|
+
type: 'object',
|
|
91
|
+
required: ['guarantees'],
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
properties: {
|
|
94
|
+
guarantees: {
|
|
95
|
+
type: 'array',
|
|
96
|
+
items: { $ref: 'capability-selection.json' },
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
policyRef: versionedRef,
|
|
101
|
+
description: { type: 'string', maxLength: 4000 },
|
|
102
|
+
capabilities: {
|
|
103
|
+
type: 'array',
|
|
104
|
+
items: { $ref: 'capability-selection.json' },
|
|
105
|
+
},
|
|
106
|
+
skills: { type: 'array', items: { $ref: 'skill-selection.json' } },
|
|
107
|
+
tools: { type: 'array', items: { $ref: 'tool-selection.json' } },
|
|
108
|
+
outputSchema: jsonSchemaDoc,
|
|
109
|
+
modelRef: versionedRef,
|
|
110
|
+
memoryRef: versionedRef,
|
|
111
|
+
communicationRef: versionedRef,
|
|
112
|
+
retryPolicy: {
|
|
113
|
+
type: 'object',
|
|
114
|
+
required: ['maxAttempts', 'backoff'],
|
|
115
|
+
additionalProperties: false,
|
|
116
|
+
properties: {
|
|
117
|
+
maxAttempts: { type: 'integer', minimum: 1, maximum: 100 },
|
|
118
|
+
backoff: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
required: ['initialMs', 'maxMs', 'multiplier'],
|
|
121
|
+
additionalProperties: false,
|
|
122
|
+
properties: {
|
|
123
|
+
initialMs: { type: 'integer', minimum: 0 },
|
|
124
|
+
maxMs: { type: 'integer', minimum: 0 },
|
|
125
|
+
multiplier: { type: 'number', minimum: 1 },
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
export const TOOL_DESCRIPTOR_SCHEMA = {
|
|
133
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
134
|
+
$id: 'https://agentropy.dev/schemas/v1/tool-descriptor.json',
|
|
135
|
+
type: 'object',
|
|
136
|
+
required: [
|
|
137
|
+
'id',
|
|
138
|
+
'version',
|
|
139
|
+
'description',
|
|
140
|
+
'inputSchema',
|
|
141
|
+
'effect',
|
|
142
|
+
'idempotency',
|
|
143
|
+
'permission',
|
|
144
|
+
],
|
|
145
|
+
additionalProperties: false,
|
|
146
|
+
properties: {
|
|
147
|
+
id: {
|
|
148
|
+
type: 'string',
|
|
149
|
+
pattern: '^[a-z0-9]+(?:[._-][a-z0-9]+)*$',
|
|
150
|
+
maxLength: 128,
|
|
151
|
+
},
|
|
152
|
+
version: { type: 'string', pattern: SEMVER },
|
|
153
|
+
description: { type: 'string', minLength: 1, maxLength: 2000 },
|
|
154
|
+
inputSchema: jsonSchemaDoc,
|
|
155
|
+
outputSchema: jsonSchemaDoc,
|
|
156
|
+
effect: { enum: ['read', 'internal', 'external'] },
|
|
157
|
+
idempotency: { enum: ['idempotent', 'keyed', 'at-least-once'] },
|
|
158
|
+
permission: nonEmpty,
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
export const TOOL_BINDING_SCHEMA = {
|
|
162
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
163
|
+
$id: 'https://agentropy.dev/schemas/v1/tool-binding.json',
|
|
164
|
+
type: 'object',
|
|
165
|
+
required: [
|
|
166
|
+
'bindingId',
|
|
167
|
+
'toolId',
|
|
168
|
+
'toolVersion',
|
|
169
|
+
'providerId',
|
|
170
|
+
'providerVersion',
|
|
171
|
+
'config',
|
|
172
|
+
],
|
|
173
|
+
additionalProperties: false,
|
|
174
|
+
properties: {
|
|
175
|
+
bindingId: nonEmpty,
|
|
176
|
+
toolId: nonEmpty,
|
|
177
|
+
toolVersion: { type: 'string', pattern: SEMVER },
|
|
178
|
+
providerId: nonEmpty,
|
|
179
|
+
providerVersion: { type: 'string', pattern: SEMVER },
|
|
180
|
+
config: { type: 'object' },
|
|
181
|
+
credentialRef: nonEmpty,
|
|
182
|
+
default: { type: 'boolean' },
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
/** Agent Skills specification frontmatter (agentskills.io, 2026-11-05). */
|
|
186
|
+
export const SKILL_METADATA_SCHEMA = {
|
|
187
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
188
|
+
$id: 'https://agentropy.dev/schemas/v1/skill-metadata.json',
|
|
189
|
+
type: 'object',
|
|
190
|
+
required: ['name', 'description'],
|
|
191
|
+
additionalProperties: false,
|
|
192
|
+
properties: {
|
|
193
|
+
name: {
|
|
194
|
+
type: 'string',
|
|
195
|
+
minLength: 1,
|
|
196
|
+
maxLength: 64,
|
|
197
|
+
pattern: '^[a-z0-9]+(?:-[a-z0-9]+)*$',
|
|
198
|
+
},
|
|
199
|
+
description: { type: 'string', minLength: 1, maxLength: 1024 },
|
|
200
|
+
license: { type: 'string' },
|
|
201
|
+
compatibility: { type: 'string', minLength: 1, maxLength: 500 },
|
|
202
|
+
metadata: { type: 'object', additionalProperties: { type: 'string' } },
|
|
203
|
+
allowedTools: { type: 'array', items: { type: 'string', minLength: 1 } },
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
const contractAjv = addFormats(new Ajv2020({ allErrors: true, strict: true, allowUnionTypes: true }));
|
|
207
|
+
contractAjv
|
|
208
|
+
.addSchema(CAPABILITY_SELECTION_SCHEMA)
|
|
209
|
+
.addSchema(TOOL_SELECTION_SCHEMA)
|
|
210
|
+
.addSchema(SKILL_SELECTION_SCHEMA);
|
|
211
|
+
const validators = {
|
|
212
|
+
agentDefinition: contractAjv.compile(AGENT_DEFINITION_SCHEMA),
|
|
213
|
+
toolDescriptor: contractAjv.compile(TOOL_DESCRIPTOR_SCHEMA),
|
|
214
|
+
toolBinding: contractAjv.compile(TOOL_BINDING_SCHEMA),
|
|
215
|
+
skillMetadata: contractAjv.compile(SKILL_METADATA_SCHEMA),
|
|
216
|
+
};
|
|
217
|
+
/** Separate, non-strict instance for user-supplied schemas (inputSchema, outputSchema, tool and config schemas). */
|
|
218
|
+
const userAjv = addFormats(new Ajv2020({ allErrors: true, strict: false }));
|
|
219
|
+
const userCache = new WeakMap();
|
|
220
|
+
const formatErrors = (errors) => (errors ?? [])
|
|
221
|
+
.slice(0, 10)
|
|
222
|
+
.map((e) => `${e.instancePath || '/'} ${e.message ?? e.keyword}`);
|
|
223
|
+
function schemaViolation(what, errors, reason) {
|
|
224
|
+
return new AgentropyError('SchemaViolation', `${what} does not match its schema`, { details: { what, errors, ...(reason ? { reason } : {}) } });
|
|
225
|
+
}
|
|
226
|
+
/** Compile a user-supplied JSON Schema; an invalid schema is a configuration error, not a data error. */
|
|
227
|
+
export function compileUserSchema(schema, what = 'schema') {
|
|
228
|
+
if (typeof schema === 'boolean')
|
|
229
|
+
return userAjv.compile(schema);
|
|
230
|
+
const cached = userCache.get(schema);
|
|
231
|
+
if (cached)
|
|
232
|
+
return cached;
|
|
233
|
+
try {
|
|
234
|
+
const fn = userAjv.compile(schema);
|
|
235
|
+
userCache.set(schema, fn);
|
|
236
|
+
return fn;
|
|
237
|
+
}
|
|
238
|
+
catch (cause) {
|
|
239
|
+
throw new AgentropyError('InvalidConfiguration', `${what} is not a valid JSON Schema 2020-12 document`, { details: { what }, cause });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** Validate a value against a user-supplied schema; throws SchemaViolation. */
|
|
243
|
+
export function validateAgainst(schema, value, what) {
|
|
244
|
+
const fn = compileUserSchema(schema, what);
|
|
245
|
+
if (!fn(value))
|
|
246
|
+
throw schemaViolation(what, formatErrors(fn.errors));
|
|
247
|
+
}
|
|
248
|
+
function selectionsSemantics(kind, items, errors) {
|
|
249
|
+
const seen = new Set();
|
|
250
|
+
for (const [i, s] of (items ?? []).entries()) {
|
|
251
|
+
if (semver.validRange(s.versionRange) === null)
|
|
252
|
+
errors.push(`/${kind}/${i}/versionRange is not a valid SemVer range`);
|
|
253
|
+
if (seen.has(s.id))
|
|
254
|
+
errors.push(`/${kind}/${i} duplicates ${s.id}`);
|
|
255
|
+
seen.add(s.id);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/** Structural + semantic validation of an AgentDefinition. Returns the typed value or throws SchemaViolation/InvalidConfiguration. */
|
|
259
|
+
export function validateAgentDefinition(value) {
|
|
260
|
+
if (!validators.agentDefinition(value))
|
|
261
|
+
throw schemaViolation('AgentDefinition', formatErrors(validators.agentDefinition.errors));
|
|
262
|
+
const def = value;
|
|
263
|
+
const errors = [];
|
|
264
|
+
selectionsSemantics('capabilities', def.capabilities, errors);
|
|
265
|
+
selectionsSemantics('tools', def.tools, errors);
|
|
266
|
+
selectionsSemantics('skills', def.skills, errors);
|
|
267
|
+
selectionsSemantics('runtimeRequirements/guarantees', def.runtimeRequirements.guarantees, errors);
|
|
268
|
+
if (def.retryPolicy &&
|
|
269
|
+
def.retryPolicy.backoff.maxMs < def.retryPolicy.backoff.initialMs)
|
|
270
|
+
errors.push('/retryPolicy/backoff maxMs < initialMs');
|
|
271
|
+
if (errors.length)
|
|
272
|
+
throw schemaViolation('AgentDefinition', errors);
|
|
273
|
+
compileUserSchema(def.inputSchema, 'AgentDefinition.inputSchema');
|
|
274
|
+
if (def.outputSchema !== undefined)
|
|
275
|
+
compileUserSchema(def.outputSchema, 'AgentDefinition.outputSchema');
|
|
276
|
+
return def;
|
|
277
|
+
}
|
|
278
|
+
export function validateToolDescriptor(value) {
|
|
279
|
+
if (!validators.toolDescriptor(value))
|
|
280
|
+
throw schemaViolation('ToolDescriptor', formatErrors(validators.toolDescriptor.errors));
|
|
281
|
+
const d = value;
|
|
282
|
+
compileUserSchema(d.inputSchema, 'ToolDescriptor.inputSchema');
|
|
283
|
+
if (d.outputSchema !== undefined)
|
|
284
|
+
compileUserSchema(d.outputSchema, 'ToolDescriptor.outputSchema');
|
|
285
|
+
return d;
|
|
286
|
+
}
|
|
287
|
+
export function validateToolBinding(value) {
|
|
288
|
+
if (!validators.toolBinding(value))
|
|
289
|
+
throw schemaViolation('ToolBinding', formatErrors(validators.toolBinding.errors));
|
|
290
|
+
return value;
|
|
291
|
+
}
|
|
292
|
+
export function validateSkillMetadata(value) {
|
|
293
|
+
if (!validators.skillMetadata(value))
|
|
294
|
+
throw schemaViolation('SkillMetadata', formatErrors(validators.skillMetadata.errors));
|
|
295
|
+
return value;
|
|
296
|
+
}
|
|
297
|
+
const INSTANT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
298
|
+
/**
|
|
299
|
+
* A point in time the scheduler compares as a string (deadlines, timers, timeouts): an ISO-8601 instant with an
|
|
300
|
+
* explicit time zone, returned as UTC `toISOString()` form so string order is time order. Anything else — a date
|
|
301
|
+
* without a zone (local time is ambiguous), free text — is a `SchemaViolation` (FEAT-038.3).
|
|
302
|
+
*/
|
|
303
|
+
export function normalizeInstant(value, what) {
|
|
304
|
+
if (typeof value !== 'string' ||
|
|
305
|
+
!INSTANT.test(value) ||
|
|
306
|
+
Number.isNaN(Date.parse(value)))
|
|
307
|
+
throw new AgentropyError('SchemaViolation', `${what} must be an ISO-8601 instant with a time zone`, { details: { reason: what } });
|
|
308
|
+
return new Date(value).toISOString();
|
|
309
|
+
}
|
|
310
|
+
/** Envelope schema version this build accepts (messaging contract). */
|
|
311
|
+
export const MESSAGE_SCHEMA_VERSION = 1;
|
|
312
|
+
const agentMessageSchema = {
|
|
313
|
+
type: 'object',
|
|
314
|
+
required: [
|
|
315
|
+
'schemaVersion',
|
|
316
|
+
'kind',
|
|
317
|
+
'name',
|
|
318
|
+
'messageId',
|
|
319
|
+
'correlationId',
|
|
320
|
+
'tenantId',
|
|
321
|
+
'actor',
|
|
322
|
+
'createdAt',
|
|
323
|
+
'payload',
|
|
324
|
+
],
|
|
325
|
+
properties: {
|
|
326
|
+
schemaVersion: { type: 'integer' },
|
|
327
|
+
kind: { enum: ['command', 'query', 'event'] },
|
|
328
|
+
name: { type: 'string', minLength: 1 },
|
|
329
|
+
messageId: { type: 'string', minLength: 1 },
|
|
330
|
+
correlationId: { type: 'string', minLength: 1 },
|
|
331
|
+
causationId: { type: 'string' },
|
|
332
|
+
idempotencyKey: { type: 'string', minLength: 1 },
|
|
333
|
+
tenantId: { type: 'string', minLength: 1 },
|
|
334
|
+
actor: {
|
|
335
|
+
type: 'object',
|
|
336
|
+
required: ['principalId', 'principalType'],
|
|
337
|
+
properties: {
|
|
338
|
+
principalId: { type: 'string', minLength: 1 },
|
|
339
|
+
principalType: { enum: ['user', 'service', 'agent'] },
|
|
340
|
+
delegatedBy: { type: 'string' },
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
createdAt: { type: 'string', minLength: 1 },
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* Boundary validation of an AgentMessage envelope (AC-17): malformed envelopes, an unsupported
|
|
348
|
+
* `schemaVersion` and a command without an idempotency key are rejected with SchemaViolation.
|
|
349
|
+
*/
|
|
350
|
+
export function validateAgentMessage(value) {
|
|
351
|
+
validateAgainst(agentMessageSchema, value, 'AgentMessage');
|
|
352
|
+
const m = value;
|
|
353
|
+
if (m.schemaVersion !== MESSAGE_SCHEMA_VERSION)
|
|
354
|
+
throw new AgentropyError('SchemaViolation', `Unsupported AgentMessage schemaVersion ${m.schemaVersion}`, {
|
|
355
|
+
details: { reason: 'schemaVersion', supported: MESSAGE_SCHEMA_VERSION },
|
|
356
|
+
});
|
|
357
|
+
if (m.kind === 'command' && !m.idempotencyKey)
|
|
358
|
+
throw new AgentropyError('SchemaViolation', 'A command needs an idempotency key', { details: { reason: 'missingIdempotencyKey' } });
|
|
359
|
+
if (Number.isNaN(Date.parse(m.createdAt)))
|
|
360
|
+
throw new AgentropyError('SchemaViolation', 'createdAt must be ISO 8601', {
|
|
361
|
+
details: { reason: 'createdAt' },
|
|
362
|
+
});
|
|
363
|
+
return m;
|
|
364
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Security v1 (docs/contracts/security-v1.md): minimal M1 PEP/PDP/audit/credential shapes. */
|
|
2
|
+
import type { TrustedPrincipal } from './agent.js';
|
|
3
|
+
export interface PolicyRequest {
|
|
4
|
+
principal: TrustedPrincipal;
|
|
5
|
+
action: string;
|
|
6
|
+
resource: {
|
|
7
|
+
type: string;
|
|
8
|
+
id: string;
|
|
9
|
+
tenantId: string;
|
|
10
|
+
};
|
|
11
|
+
context?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
export type PolicyDecision = {
|
|
14
|
+
effect: 'allow';
|
|
15
|
+
policyVersion?: string;
|
|
16
|
+
} | {
|
|
17
|
+
effect: 'deny';
|
|
18
|
+
reason?: string;
|
|
19
|
+
policyVersion?: string;
|
|
20
|
+
};
|
|
21
|
+
export interface PolicyDecisionPoint {
|
|
22
|
+
decide(request: PolicyRequest, signal?: AbortSignal): Promise<PolicyDecision>;
|
|
23
|
+
}
|
|
24
|
+
export interface AuditEvent {
|
|
25
|
+
type: string;
|
|
26
|
+
tenantId: string;
|
|
27
|
+
principalId: string;
|
|
28
|
+
action: string;
|
|
29
|
+
resource: {
|
|
30
|
+
type: string;
|
|
31
|
+
id: string;
|
|
32
|
+
};
|
|
33
|
+
decision: 'allow' | 'deny' | 'error';
|
|
34
|
+
correlationId?: string;
|
|
35
|
+
taskId?: string;
|
|
36
|
+
details?: Record<string, unknown>;
|
|
37
|
+
at: string;
|
|
38
|
+
}
|
|
39
|
+
export interface AuditIntentWriter {
|
|
40
|
+
record(event: AuditEvent): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface CredentialProvider {
|
|
43
|
+
resolve(ref: string, ctx: {
|
|
44
|
+
tenantId: string;
|
|
45
|
+
principal: TrustedPrincipal;
|
|
46
|
+
purpose: string;
|
|
47
|
+
}): Promise<unknown>;
|
|
48
|
+
}
|
package/dist/security.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/skill.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Skill v1 (docs/contracts/skill-v1.md). */
|
|
2
|
+
import type { Version } from './agent.js';
|
|
3
|
+
import type { CapabilityRequirement } from './capability.js';
|
|
4
|
+
import type { ToolId } from './tool.js';
|
|
5
|
+
export declare const AGENT_SKILLS_SPEC_VERSION = "agentskills-2026-11-05";
|
|
6
|
+
export interface SkillMetadata {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
license?: string;
|
|
10
|
+
compatibility?: string;
|
|
11
|
+
metadata?: Record<string, string>;
|
|
12
|
+
allowedTools?: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface SkillRequirements {
|
|
15
|
+
capabilities?: CapabilityRequirement[];
|
|
16
|
+
tools?: {
|
|
17
|
+
id: ToolId;
|
|
18
|
+
versionRange: string;
|
|
19
|
+
}[];
|
|
20
|
+
}
|
|
21
|
+
export type SkillStatus = 'registered' | 'active' | 'revoked';
|
|
22
|
+
export interface SkillRecord {
|
|
23
|
+
id: string;
|
|
24
|
+
version: Version;
|
|
25
|
+
specVersion: string;
|
|
26
|
+
metadata: SkillMetadata;
|
|
27
|
+
digest: string;
|
|
28
|
+
provenance: {
|
|
29
|
+
publisher: string;
|
|
30
|
+
source: string;
|
|
31
|
+
verified: boolean;
|
|
32
|
+
};
|
|
33
|
+
requires: SkillRequirements;
|
|
34
|
+
files: string[];
|
|
35
|
+
status: SkillStatus;
|
|
36
|
+
revision: number;
|
|
37
|
+
}
|
|
38
|
+
export interface SkillPin {
|
|
39
|
+
id: string;
|
|
40
|
+
version: Version;
|
|
41
|
+
digest: string;
|
|
42
|
+
}
|
|
43
|
+
export interface SkillLoader {
|
|
44
|
+
metadata(pin: SkillPin): Promise<SkillMetadata>;
|
|
45
|
+
instructions(pin: SkillPin): Promise<string>;
|
|
46
|
+
resource(pin: SkillPin, relativePath: string): Promise<Uint8Array>;
|
|
47
|
+
}
|
|
48
|
+
export interface SkillAccess {
|
|
49
|
+
list(): SkillMetadata[];
|
|
50
|
+
instructions(skillId: string): Promise<string>;
|
|
51
|
+
resource(skillId: string, relativePath: string): Promise<Uint8Array>;
|
|
52
|
+
}
|
package/dist/skill.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const AGENT_SKILLS_SPEC_VERSION = 'agentskills-2026-11-05';
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Driver-neutral Store port (ADR-0017): named collections of JSON documents with revision CAS, a small set of
|
|
3
|
+
* indexed fields per collection, and an async unit of work. Adapters must make one `transaction` atomic and
|
|
4
|
+
* serialize transactions that touch the same store. No SQL-specific semantics leak through this interface.
|
|
5
|
+
*
|
|
6
|
+
* An adapter may re-run a transaction callback after a serialization conflict (ADR-0028), so callbacks must only
|
|
7
|
+
* read and write through `tx` and have no other effects.
|
|
8
|
+
*/
|
|
9
|
+
import { AgentropyError } from './errors.js';
|
|
10
|
+
export declare const STORE_COLLECTIONS: {
|
|
11
|
+
/** `callerId`, `ownerId` and `createdAt` let listings and quotas read what concerns them (FEAT-039.3). */
|
|
12
|
+
readonly tasks: readonly ["tenantId", "status", "instanceId", "parentTaskId", "callerId", "ownerId", "createdAt", "compactedAt"];
|
|
13
|
+
/** `runAt` and `tenantId` let a worker read what is due, and a tenant's running count, without scanning (FEAT-039.3). */
|
|
14
|
+
readonly executions: readonly ["taskId", "state", "runAt", "tenantId"];
|
|
15
|
+
readonly checkpoints: readonly ["taskId"];
|
|
16
|
+
readonly wakeups: readonly ["taskId", "status", "dueAt", "checkAt"];
|
|
17
|
+
readonly subscriptions: readonly ["taskId", "source", "status"];
|
|
18
|
+
readonly mailbox: readonly ["taskId", "subscriptionId", "consumed"];
|
|
19
|
+
/** `at` lets compaction read only the dedupe records that fell out of the window (TASK-066). */
|
|
20
|
+
readonly inboundEvents: readonly ["source", "at"];
|
|
21
|
+
readonly effects: readonly ["taskId"];
|
|
22
|
+
readonly outbox: readonly ["published", "aggregateId"];
|
|
23
|
+
/** `pending` (1 while an entry is unacknowledged and unpresented at its revision) lets the briefing read only those (FEAT-039.3). */
|
|
24
|
+
readonly inbox: readonly ["tenantId", "ownerId", "status", "pending"];
|
|
25
|
+
/** `dueAt` and `claimExpiresAt` let the expiry sweep read only what lapsed (FEAT-039.3). */
|
|
26
|
+
readonly humanActions: readonly ["taskId", "status", "dueAt", "claimExpiresAt"];
|
|
27
|
+
/** `taskId` lets compaction find a task's record (instance records have none) (FEAT-040.1). */
|
|
28
|
+
readonly idempotency: readonly ["tenantId", "taskId"];
|
|
29
|
+
/** `forwarded` (0/1) lets the forwarder read only rows still to send instead of the whole log (FEAT-039.1). */
|
|
30
|
+
readonly audit: readonly ["tenantId", "type", "forwarded"];
|
|
31
|
+
readonly gates: readonly ["taskId", "nextCheckAt"];
|
|
32
|
+
readonly instances: readonly ["tenantId", "ownerId"];
|
|
33
|
+
readonly sessions: readonly ["tenantId"];
|
|
34
|
+
readonly leases: readonly ["kind"];
|
|
35
|
+
readonly usage: readonly ["taskId"];
|
|
36
|
+
/** `taskId` finds one projection without scanning them all (FEAT-039.2). */
|
|
37
|
+
readonly remoteTasks: readonly ["tenantId", "status", "parentTaskId", "taskId", "observedAt"];
|
|
38
|
+
readonly auditPolicies: readonly ["tenantId"];
|
|
39
|
+
readonly auditHolds: readonly ["tenantId", "status"];
|
|
40
|
+
readonly auditReceipts: readonly ["tenantId"];
|
|
41
|
+
/** Per-tenant audit chain head (`id` = tenant ID): the last link's hash, so appends need no chain scan. */
|
|
42
|
+
readonly auditHeads: readonly ["tenantId"];
|
|
43
|
+
/** Policy decision cache invalidations shared by every worker on the store (FEAT-033.1); pruned after 10 min. */
|
|
44
|
+
readonly policyInvalidations: readonly ["tenantId"];
|
|
45
|
+
/** A2A push notification configs (FEAT-034.3); webhook secrets are stored only sealed. */
|
|
46
|
+
readonly pushConfigs: readonly ["tenantId", "taskId"];
|
|
47
|
+
/** A2A message history (FEAT-044.2): user messages kept per sending principal when the endpoint enables it. */
|
|
48
|
+
readonly a2aHistory: readonly ["tenantId", "taskId"];
|
|
49
|
+
/** Agent memory (FEAT-045): entries per tenant and acting principal (`ownerId`), with an optional expiry. */
|
|
50
|
+
readonly memories: readonly ["tenantId", "ownerId", "expiresAt"];
|
|
51
|
+
/** Status an operator set on a tool or skill version (FEAT-074), so it survives a restart and reaches every worker. */
|
|
52
|
+
readonly lifecycle: readonly ["kind"];
|
|
53
|
+
};
|
|
54
|
+
export type CollectionName = keyof typeof STORE_COLLECTIONS;
|
|
55
|
+
export type IndexField<C extends CollectionName> = (typeof STORE_COLLECTIONS)[C][number];
|
|
56
|
+
export type IndexValue = string | number | null;
|
|
57
|
+
export interface StoredDocument<T> {
|
|
58
|
+
id: string;
|
|
59
|
+
/** Starts at 1 and increases by one per update (compare-and-swap token). */
|
|
60
|
+
revision: number;
|
|
61
|
+
/**
|
|
62
|
+
* Store-wide order of committed inserts: a reader paging with `afterSeq` never skips a row that commits later.
|
|
63
|
+
* Inside the inserting transaction an adapter may expose a provisional value; the committed value is final.
|
|
64
|
+
*/
|
|
65
|
+
seq: number;
|
|
66
|
+
value: T;
|
|
67
|
+
}
|
|
68
|
+
export interface FindOptions<C extends CollectionName> {
|
|
69
|
+
where?: Partial<Record<IndexField<C>, IndexValue>>;
|
|
70
|
+
/** Inclusive range on one indexed field (e.g. due wake-ups: dueAt <= now). */
|
|
71
|
+
range?: {
|
|
72
|
+
field: IndexField<C>;
|
|
73
|
+
gte?: IndexValue;
|
|
74
|
+
lte?: IndexValue;
|
|
75
|
+
};
|
|
76
|
+
orderBy?: 'seq' | IndexField<C>;
|
|
77
|
+
/** Reverse the order (newest first for `seq`; nulls last for a field): with `limit`, the last N without reading all. */
|
|
78
|
+
descending?: boolean;
|
|
79
|
+
afterSeq?: number;
|
|
80
|
+
/** Only rows committed before this one (`seq < beforeSeq`): the page after a `descending` page by `seq`. */
|
|
81
|
+
beforeSeq?: number;
|
|
82
|
+
limit?: number;
|
|
83
|
+
}
|
|
84
|
+
export interface StoreTx {
|
|
85
|
+
get<T>(collection: CollectionName, id: string): Promise<StoredDocument<T> | undefined>;
|
|
86
|
+
/**
|
|
87
|
+
* Fails StaleRevision (`reason: "exists"`) when the ID is taken. An adapter may buffer the write and report the
|
|
88
|
+
* failure at a later call in the same transaction or when the transaction commits, so do not catch a write
|
|
89
|
+
* failure inside the callback and carry on: let the transaction fail.
|
|
90
|
+
*/
|
|
91
|
+
insert<T>(collection: CollectionName, id: string, value: T): Promise<StoredDocument<T>>;
|
|
92
|
+
/** Compare-and-swap; fails StaleRevision when `expectedRevision` is not current (possibly later, as for insert). */
|
|
93
|
+
update<T>(collection: CollectionName, id: string, expectedRevision: number, value: T): Promise<StoredDocument<T>>;
|
|
94
|
+
remove(collection: CollectionName, id: string, expectedRevision: number): Promise<void>;
|
|
95
|
+
find<T, C extends CollectionName = CollectionName>(collection: C, options?: FindOptions<C>): Promise<StoredDocument<T>[]>;
|
|
96
|
+
}
|
|
97
|
+
export interface Store {
|
|
98
|
+
/** Durability the adapter itself provides across a process restart. */
|
|
99
|
+
readonly durability: 'none' | 'durable-acceptance' | 'durable-execution';
|
|
100
|
+
/** Runs `fn` atomically. A thrown error rolls back every write made through `tx`. */
|
|
101
|
+
transaction<T>(fn: (tx: StoreTx) => Promise<T>): Promise<T>;
|
|
102
|
+
close(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
/** Extracts the indexed fields of a document value; missing fields index as null. */
|
|
105
|
+
export declare function indexValues(collection: CollectionName, value: unknown): Record<string, IndexValue>;
|
|
106
|
+
export declare const staleRevision: (collection: string, id: string, reason: "exists" | "missing" | "revision", expected?: number, actual?: number) => AgentropyError;
|
|
107
|
+
/** A FIFO async mutex: transactions on one store never interleave. */
|
|
108
|
+
export declare class AsyncMutex {
|
|
109
|
+
private tail;
|
|
110
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
111
|
+
}
|
|
112
|
+
/** Reference adapter (durability "none"): everything is lost when the process exits. */
|
|
113
|
+
export declare class MemoryStore implements Store {
|
|
114
|
+
readonly durability: "none";
|
|
115
|
+
private data;
|
|
116
|
+
private seq;
|
|
117
|
+
private closed;
|
|
118
|
+
private readonly mutex;
|
|
119
|
+
transaction<T>(fn: (tx: StoreTx) => Promise<T>): Promise<T>;
|
|
120
|
+
close(): Promise<void>;
|
|
121
|
+
private col;
|
|
122
|
+
private tx;
|
|
123
|
+
}
|