@agenticprimitives/service-agent 0.0.0-alpha.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 +21 -0
- package/README.md +71 -0
- package/dist/assert.d.ts +11 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +30 -0
- package/dist/assert.js.map +1 -0
- package/dist/define-skill.d.ts +9 -0
- package/dist/define-skill.d.ts.map +1 -0
- package/dist/define-skill.js +14 -0
- package/dist/define-skill.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/plan.d.ts +49 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +153 -0
- package/dist/plan.js.map +1 -0
- package/dist/primitive-registry.d.ts +3 -0
- package/dist/primitive-registry.d.ts.map +1 -0
- package/dist/primitive-registry.js +34 -0
- package/dist/primitive-registry.js.map +1 -0
- package/dist/service-agent.d.ts +43 -0
- package/dist/service-agent.d.ts.map +1 -0
- package/dist/service-agent.js +169 -0
- package/dist/service-agent.js.map +1 -0
- package/dist/types.d.ts +333 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agentic Trust Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @agenticprimitives/service-agent
|
|
2
|
+
|
|
3
|
+
> **Status:** experimental (spec 283 PR1).
|
|
4
|
+
|
|
5
|
+
A generic framework for building **service agents** — agents that expose a catalog of capabilities
|
|
6
|
+
(skills) and execute them under layered authority. It is provider-neutral and Ring-0 pure: it depends only
|
|
7
|
+
on `@agenticprimitives/types` and imports no wallet, exchange, RPC, MCP, delegation, or policy code. The
|
|
8
|
+
concrete providers and authority evaluators are **injected** by the host.
|
|
9
|
+
|
|
10
|
+
Domain catalogs — e.g. `@agenticprimitives/treasury` — are separate packages that supply skill definitions
|
|
11
|
+
+ a provider-neutral plan; this package runs the lifecycle.
|
|
12
|
+
|
|
13
|
+
## The lifecycle
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
define → assert → entitle / delegate → primitive-plan → execute → receipt
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- **define** — a `SkillDefinition` states a skill's meaning: id, version, `effect`
|
|
20
|
+
(`read|sign|spend|trade|admin`), default `exposure`, the logical capabilities it `requires`, optional
|
|
21
|
+
I/O schemas, and a `compile()` that emits a **primitive plan**. A definition does NOT claim the host can
|
|
22
|
+
run it.
|
|
23
|
+
- **assert** — `assertSkills` resolves each definition's `requires` against the `PrimitiveRegistry`. A
|
|
24
|
+
skill asserts only when every non-optional requirement binds to an installed `Primitive` whose
|
|
25
|
+
constraints **cover** the requirement (monotonic). The result is an `AssertionReport`
|
|
26
|
+
(`asserted` / `unavailable` / `rejected`). The optional `publishAssertion` hook is the seam for public
|
|
27
|
+
disclosure (spec 282: vault claim → `atl:skills` → discovery + A2A card).
|
|
28
|
+
- **entitle / delegate / guard** — the plan's `.authorize('entitlement', …)`, `.authorize('delegation', …)`
|
|
29
|
+
and `.guard(…)` steps call the **injected** evaluators (mapping to `tool-policy`/`entitlements`,
|
|
30
|
+
`delegation`, and `tool-policy` at the host). Every gate must ALLOW; the first denial throws the typed
|
|
31
|
+
error and nothing further runs (fail-closed).
|
|
32
|
+
- **primitive-plan / execute** — `runPlan` resolves `ref()`s, calls registered primitives for `.step`s
|
|
33
|
+
(plus built-in `ledger.reserve`/`ledger.finalize`), and collects `.output`.
|
|
34
|
+
- **receipt** — `invoke` returns a normalized `ExecutionReceipt` (authority decisions + primitive bindings
|
|
35
|
+
+ outputs); the host sinks/signs it via `audit`.
|
|
36
|
+
|
|
37
|
+
## Example
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { ServiceAgent, defineSkill, createPrimitiveRegistry, primitivePlan, ref } from '@agenticprimitives/service-agent';
|
|
41
|
+
|
|
42
|
+
const balance = defineSkill<{ accountId: string }, { balance: string }>({
|
|
43
|
+
id: 'treasury.account.balance', version: '1.0.0', name: 'Read balance',
|
|
44
|
+
effect: 'read', defaultExposure: 'authenticated',
|
|
45
|
+
requires: [{ capability: 'account.balance' }],
|
|
46
|
+
compile: ({ input }) =>
|
|
47
|
+
primitivePlan('plan.balance')
|
|
48
|
+
.step('bal', 'account.balance', { accountId: input.accountId })
|
|
49
|
+
.output({ balance: ref('bal', 'balance') }),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const registry = createPrimitiveRegistry();
|
|
53
|
+
registry.register(myAccountProvider); // advertises { id: 'account.balance', version, constraints }
|
|
54
|
+
|
|
55
|
+
const agent = new ServiceAgent({ descriptor: { id: '0x…', name: 'Treasury', version: '1.0.0' }, primitives: registry });
|
|
56
|
+
agent.define(balance);
|
|
57
|
+
await agent.assert();
|
|
58
|
+
const receipt = await agent.invoke({ skillId: 'treasury.account.balance', input: { accountId: 'acct-1' } });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
For a spend skill, add `.authorize('entitlement', …)`, `.authorize('delegation', …)`, `.guard(…)`, and the
|
|
62
|
+
ledger reserve/finalize steps; wire `entitlements` / `delegations` / `policies` / `ledger` into
|
|
63
|
+
`ServiceAgentOptions`. See `test/conformance.test.ts` for the full lifecycle with fakes.
|
|
64
|
+
|
|
65
|
+
## What lives elsewhere
|
|
66
|
+
|
|
67
|
+
- **Providers** (EVM transfer, swap venue, RPC, KMS signer) — EXTERNAL (ADR-0037); they register as
|
|
68
|
+
`Primitive`s. Demos ship fakes.
|
|
69
|
+
- **Authority logic** — `delegation`, `tool-policy`, `entitlements`; injected as evaluators.
|
|
70
|
+
- **The treasury catalog** — `@agenticprimitives/treasury`. **Public disclosure** — the app, via
|
|
71
|
+
`publishAssertion` (spec 282).
|
package/dist/assert.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnySkillDefinition, AssertionReport, Exposure, PrimitiveRegistry } from './types.js';
|
|
2
|
+
export interface AssertSkillsArgs {
|
|
3
|
+
definitions: AnySkillDefinition[];
|
|
4
|
+
registry: PrimitiveRegistry;
|
|
5
|
+
/** Per-skill exposure override (default = the definition's defaultExposure). */
|
|
6
|
+
exposure?: (skill: AnySkillDefinition) => Exposure;
|
|
7
|
+
/** strict (default) fails the report's `rejected` empty-check elsewhere; this fn always returns the report. */
|
|
8
|
+
now?: () => string;
|
|
9
|
+
}
|
|
10
|
+
export declare function assertSkills(args: AssertSkillsArgs): AssertionReport;
|
|
11
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,QAAQ,EAAE,iBAAiB,EAAkB,MAAM,YAAY,CAAC;AAEnH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAClC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,gFAAgF;IAChF,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,QAAQ,CAAC;IACnD,+GAA+G;IAC/G,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,eAAe,CA2BpE"}
|
package/dist/assert.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function assertSkills(args) {
|
|
2
|
+
const now = args.now ?? (() => new Date(0).toISOString());
|
|
3
|
+
const report = { asserted: [], unavailable: [], rejected: [] };
|
|
4
|
+
for (const def of args.definitions) {
|
|
5
|
+
const bindings = [];
|
|
6
|
+
const missing = [];
|
|
7
|
+
for (const req of def.requires) {
|
|
8
|
+
const b = args.registry.resolve(req);
|
|
9
|
+
if (b)
|
|
10
|
+
bindings.push(b);
|
|
11
|
+
else if (!req.optional)
|
|
12
|
+
missing.push(req.capability);
|
|
13
|
+
}
|
|
14
|
+
if (missing.length > 0) {
|
|
15
|
+
report.unavailable.push({ skillId: def.id, missingCapabilities: missing });
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const assertion = {
|
|
19
|
+
skillId: def.id,
|
|
20
|
+
version: def.version,
|
|
21
|
+
exposure: args.exposure ? args.exposure(def) : def.defaultExposure,
|
|
22
|
+
primitiveBindings: bindings,
|
|
23
|
+
issuedAt: now(),
|
|
24
|
+
status: 'active', // pure capability resolution → active; the ServiceAgent layers health gating.
|
|
25
|
+
};
|
|
26
|
+
report.asserted.push(assertion);
|
|
27
|
+
}
|
|
28
|
+
return report;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=assert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAgBA,MAAM,UAAU,YAAY,CAAC,IAAsB;IACjD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAoB,EAAE,QAAQ,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAEhF,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACrC,IAAI,CAAC;gBAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;iBACnB,IAAI,CAAC,GAAG,CAAC,QAAQ;gBAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,EAAE,mBAAmB,EAAE,OAAO,EAAE,CAAC,CAAC;YAC3E,SAAS;QACX,CAAC;QACD,MAAM,SAAS,GAAmB;YAChC,OAAO,EAAE,GAAG,CAAC,EAAE;YACf,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,eAAe;YAClE,iBAAiB,EAAE,QAAQ;YAC3B,QAAQ,EAAE,GAAG,EAAE;YACf,MAAM,EAAE,QAAQ,EAAE,8EAA8E;SACjG,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnySkillDefinition, SkillDefinition } from './types.js';
|
|
2
|
+
export declare function defineSkill<Input, Output>(def: SkillDefinition<Input, Output>): SkillDefinition<Input, Output>;
|
|
3
|
+
/** Group definitions into a named, reusable profile. */
|
|
4
|
+
export declare function defineProfile(id: string, definitions: AnySkillDefinition[]): {
|
|
5
|
+
id: string;
|
|
6
|
+
definitions: AnySkillDefinition[];
|
|
7
|
+
skillIds: string[];
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=define-skill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-skill.d.ts","sourceRoot":"","sources":["../src/define-skill.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEtE,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAK9G;AAED,wDAAwD;AACxD,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAElJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function defineSkill(def) {
|
|
2
|
+
if (!def.id || !def.version)
|
|
3
|
+
throw new Error('[service-agent] skill needs id + version');
|
|
4
|
+
if (!def.requires)
|
|
5
|
+
throw new Error(`[service-agent] skill ${def.id} needs a requires[] (may be empty)`);
|
|
6
|
+
if (typeof def.compile !== 'function')
|
|
7
|
+
throw new Error(`[service-agent] skill ${def.id} needs a compile()`);
|
|
8
|
+
return def;
|
|
9
|
+
}
|
|
10
|
+
/** Group definitions into a named, reusable profile. */
|
|
11
|
+
export function defineProfile(id, definitions) {
|
|
12
|
+
return { id, definitions, skillIds: definitions.map((d) => d.id) };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=define-skill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-skill.js","sourceRoot":"","sources":["../src/define-skill.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,WAAW,CAAgB,GAAmC;IAC5E,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IACzF,IAAI,CAAC,GAAG,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,CAAC,EAAE,oCAAoC,CAAC,CAAC;IACxG,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,CAAC,EAAE,oBAAoB,CAAC,CAAC;IAC5G,OAAO,GAAG,CAAC;AACb,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,aAAa,CAAC,EAAU,EAAE,WAAiC;IACzE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACrE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export { defineSkill, defineProfile } from './define-skill.js';
|
|
3
|
+
export { createPrimitiveRegistry } from './primitive-registry.js';
|
|
4
|
+
export { primitivePlan, PlanBuilder, runPlan, ref } from './plan.js';
|
|
5
|
+
export type { RunPlanDeps, RunPlanResult, StepOpts, StepFailureRecord } from './plan.js';
|
|
6
|
+
export { assertSkills } from './assert.js';
|
|
7
|
+
export type { AssertSkillsArgs } from './assert.js';
|
|
8
|
+
export { ServiceAgent } from './service-agent.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACrE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @agenticprimitives/service-agent — generic service-agent capability framework (spec 283).
|
|
2
|
+
// define -> assert -> entitle/delegate -> primitive-plan -> execute -> receipt. Provider-neutral, Ring-0.
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export { defineSkill, defineProfile } from './define-skill.js';
|
|
5
|
+
export { createPrimitiveRegistry } from './primitive-registry.js';
|
|
6
|
+
export { primitivePlan, PlanBuilder, runPlan, ref } from './plan.js';
|
|
7
|
+
export { assertSkills } from './assert.js';
|
|
8
|
+
export { ServiceAgent } from './service-agent.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,0GAA0G;AAC1G,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/plan.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type AuthorityRecord, type DelegationEvaluator, type EntitlementEvaluator, type LedgerPrimitive, type PlanRef, type PolicyEvaluator, type PrimitivePlan, type PrimitiveRegistry, type InvocationContext, type StepFailurePolicy } from './types.js';
|
|
2
|
+
export declare const ref: (name: string, path?: string) => PlanRef;
|
|
3
|
+
/** Options for a `step` (spec 284 DAG): explicit dependencies + a per-step failure policy. */
|
|
4
|
+
export interface StepOpts {
|
|
5
|
+
dependsOn?: string[];
|
|
6
|
+
failure?: StepFailurePolicy;
|
|
7
|
+
}
|
|
8
|
+
/** Fluent compile-target builder. */
|
|
9
|
+
export declare class PlanBuilder {
|
|
10
|
+
private id;
|
|
11
|
+
private steps;
|
|
12
|
+
private outputSpec?;
|
|
13
|
+
constructor(id: string);
|
|
14
|
+
step(refName: string, capability: string, args: Record<string, unknown>, opts?: StepOpts): this;
|
|
15
|
+
authorize(refName: string, evaluator: 'entitlement' | 'delegation', action: string, args: Record<string, unknown>): this;
|
|
16
|
+
guard(refName: string, action: string, args: Record<string, unknown>): this;
|
|
17
|
+
checkpoint(refName: string, basedOn: PlanRef[]): this;
|
|
18
|
+
output(spec: Record<string, unknown>): PrimitivePlan;
|
|
19
|
+
build(): PrimitivePlan;
|
|
20
|
+
}
|
|
21
|
+
export declare const primitivePlan: (id: string) => PlanBuilder;
|
|
22
|
+
export interface RunPlanDeps {
|
|
23
|
+
registry: PrimitiveRegistry;
|
|
24
|
+
entitlements?: EntitlementEvaluator;
|
|
25
|
+
delegations?: DelegationEvaluator;
|
|
26
|
+
policies?: PolicyEvaluator;
|
|
27
|
+
ledger?: LedgerPrimitive;
|
|
28
|
+
context: InvocationContext;
|
|
29
|
+
}
|
|
30
|
+
export interface StepFailureRecord {
|
|
31
|
+
stepId: string;
|
|
32
|
+
reason: string;
|
|
33
|
+
handled: 'ignored' | 'compensated';
|
|
34
|
+
}
|
|
35
|
+
export interface RunPlanResult {
|
|
36
|
+
status: 'completed' | 'denied' | 'failed';
|
|
37
|
+
authority: AuthorityRecord[];
|
|
38
|
+
bindings: string[];
|
|
39
|
+
outputs: Record<string, unknown>;
|
|
40
|
+
reason?: string;
|
|
41
|
+
/** Steps that failed but were handled by their failure policy (ignore/compensate). Empty when none. */
|
|
42
|
+
failures?: StepFailureRecord[];
|
|
43
|
+
}
|
|
44
|
+
/** Execute a plan as a DAG (spec 284). Steps run in array order; `dependsOn` is validated fail-closed (a
|
|
45
|
+
* dependency on an unknown/later step rejects the plan). Authority gates throw the typed *DeniedError on
|
|
46
|
+
* denial (fail-closed, ADR-0013). A failing `step` is handled by its `failure` policy (abort/ignore/
|
|
47
|
+
* compensate); `abort` (default) fails the plan. */
|
|
48
|
+
export declare function runPlan(plan: PrimitivePlan, deps: RunPlanDeps): Promise<RunPlanResult>;
|
|
49
|
+
//# sourceMappingURL=plan.d.ts.map
|
|
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,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa;IAIpD,KAAK,IAAI,aAAa;CAGvB;AACD,eAAO,MAAM,aAAa,OAAQ,MAAM,KAAG,WAAkC,CAAC;AAE9E,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,iBAAiB,CAAC;CAC5B;AACD,MAAM,WAAW,iBAAiB;IAAG,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,SAAS,GAAG,aAAa,CAAA;CAAE;AACzG,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC1C,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uGAAuG;IACvG,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAChC;AAeD;;;qDAGqD;AACrD,wBAAsB,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAoF5F"}
|
package/dist/plan.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Primitive plan: a deterministic compile target (builder) + the runner (spec 283). A skill compiles ONLY
|
|
2
|
+
// into registered primitive operations + injected authority gates — no arbitrary execution. The runner
|
|
3
|
+
// enforces the effective envelope monotonically: every authorize/guard must ALLOW (logical AND) before any
|
|
4
|
+
// `step`/`output` after it runs; a denial throws the typed error and nothing further executes.
|
|
5
|
+
import { DelegationDeniedError, EntitlementDeniedError, PolicyDeniedError, } from './types.js';
|
|
6
|
+
export const ref = (name, path) => ({ __ref: name, path });
|
|
7
|
+
const isRef = (v) => typeof v === 'object' && v !== null && '__ref' in v;
|
|
8
|
+
/** Fluent compile-target builder. */
|
|
9
|
+
export class PlanBuilder {
|
|
10
|
+
id;
|
|
11
|
+
steps = [];
|
|
12
|
+
outputSpec;
|
|
13
|
+
constructor(id) {
|
|
14
|
+
this.id = id;
|
|
15
|
+
}
|
|
16
|
+
step(refName, capability, args, opts) {
|
|
17
|
+
this.steps.push({ kind: 'step', ref: refName, op: capability, args, dependsOn: opts?.dependsOn, failure: opts?.failure });
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
authorize(refName, evaluator, action, args) {
|
|
21
|
+
this.steps.push({ kind: 'authorize', ref: refName, evaluator, op: action, args });
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
guard(refName, action, args) {
|
|
25
|
+
this.steps.push({ kind: 'guard', ref: refName, evaluator: 'policy', op: action, args });
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
checkpoint(refName, basedOn) {
|
|
29
|
+
this.steps.push({ kind: 'checkpoint', ref: refName, basedOn });
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
output(spec) {
|
|
33
|
+
this.outputSpec = spec;
|
|
34
|
+
return { id: this.id, steps: this.steps, outputSpec: this.outputSpec };
|
|
35
|
+
}
|
|
36
|
+
build() {
|
|
37
|
+
return { id: this.id, steps: this.steps, outputSpec: this.outputSpec };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export const primitivePlan = (id) => new PlanBuilder(id);
|
|
41
|
+
function resolveValue(v, results) {
|
|
42
|
+
if (isRef(v)) {
|
|
43
|
+
const base = results[v.__ref];
|
|
44
|
+
if (v.path && base && typeof base === 'object')
|
|
45
|
+
return base[v.path];
|
|
46
|
+
return base;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(v))
|
|
49
|
+
return v.map((x) => resolveValue(x, results));
|
|
50
|
+
if (v && typeof v === 'object') {
|
|
51
|
+
return Object.fromEntries(Object.entries(v).map(([k, val]) => [k, resolveValue(val, results)]));
|
|
52
|
+
}
|
|
53
|
+
return v;
|
|
54
|
+
}
|
|
55
|
+
/** Execute a plan as a DAG (spec 284). Steps run in array order; `dependsOn` is validated fail-closed (a
|
|
56
|
+
* dependency on an unknown/later step rejects the plan). Authority gates throw the typed *DeniedError on
|
|
57
|
+
* denial (fail-closed, ADR-0013). A failing `step` is handled by its `failure` policy (abort/ignore/
|
|
58
|
+
* compensate); `abort` (default) fails the plan. */
|
|
59
|
+
export async function runPlan(plan, deps) {
|
|
60
|
+
const results = {};
|
|
61
|
+
const authority = [];
|
|
62
|
+
const bindings = [];
|
|
63
|
+
const failures = [];
|
|
64
|
+
const done = new Set();
|
|
65
|
+
const ctx = deps.context;
|
|
66
|
+
// Steps named as a compensation target run ONLY when their failing step triggers them — never in flow.
|
|
67
|
+
const compensationIds = new Set(plan.steps.flatMap((s) => (s.failure?.mode === 'compensate' ? [s.failure.compensationStepId] : [])));
|
|
68
|
+
// Execute one `step`-kind step (provider op or built-in ledger op); throws on failure.
|
|
69
|
+
const execStep = async (step, args) => {
|
|
70
|
+
const capability = step.op;
|
|
71
|
+
if (capability === 'ledger.reserve' && deps.ledger)
|
|
72
|
+
return deps.ledger.reserve(args);
|
|
73
|
+
if (capability === 'ledger.finalize' && deps.ledger)
|
|
74
|
+
return deps.ledger.finalize(args);
|
|
75
|
+
const binding = deps.registry.resolve({ capability });
|
|
76
|
+
if (!binding)
|
|
77
|
+
throw new Error(`no primitive for capability ${capability}`);
|
|
78
|
+
const primitive = deps.registry.get(binding.primitiveId);
|
|
79
|
+
bindings.push(`${binding.primitiveId}:${binding.capability}`);
|
|
80
|
+
return primitive.execute(capability, args, { agentId: ctx.agentId, subject: ctx.subject, correlationId: ctx.correlationId, idempotencyKey: ctx.idempotencyKey });
|
|
81
|
+
};
|
|
82
|
+
for (const step of plan.steps) {
|
|
83
|
+
if (compensationIds.has(step.ref))
|
|
84
|
+
continue; // compensation steps fire only on failure
|
|
85
|
+
// DAG edge validation — every named dependency must already have run (fail-closed).
|
|
86
|
+
for (const dep of step.dependsOn ?? []) {
|
|
87
|
+
if (!done.has(dep))
|
|
88
|
+
return { status: 'failed', authority, bindings, outputs: results, reason: `step ${step.ref} depends on ${dep}, which has not run`, failures };
|
|
89
|
+
}
|
|
90
|
+
const args = resolveValue(step.args ?? {}, results);
|
|
91
|
+
if (step.kind === 'authorize' || step.kind === 'guard') {
|
|
92
|
+
const evaluator = step.evaluator === 'entitlement' ? deps.entitlements
|
|
93
|
+
: step.evaluator === 'delegation' ? deps.delegations
|
|
94
|
+
: deps.policies;
|
|
95
|
+
const action = step.op ?? step.ref;
|
|
96
|
+
// No evaluator wired → fail closed (an authority gate with nothing to check it MUST deny).
|
|
97
|
+
const decision = evaluator
|
|
98
|
+
? await evaluator.evaluate({ action, resource: args.resource, subject: ctx.subject, agentId: ctx.agentId, input: args.input ?? args })
|
|
99
|
+
: { allow: false, reason: `no ${step.evaluator} evaluator configured` };
|
|
100
|
+
authority.push({ action, evaluator: step.evaluator ?? 'policy', decisionId: decision.decisionId, allow: decision.allow });
|
|
101
|
+
results[step.ref] = decision;
|
|
102
|
+
if (!decision.allow) {
|
|
103
|
+
const reason = decision.reason ?? `${step.evaluator} denied`;
|
|
104
|
+
if (step.evaluator === 'entitlement')
|
|
105
|
+
throw new EntitlementDeniedError(reason);
|
|
106
|
+
if (step.evaluator === 'delegation')
|
|
107
|
+
throw new DelegationDeniedError(reason);
|
|
108
|
+
throw new PolicyDeniedError(reason);
|
|
109
|
+
}
|
|
110
|
+
done.add(step.ref);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (step.kind === 'checkpoint') {
|
|
114
|
+
results[step.ref] = { ok: true };
|
|
115
|
+
done.add(step.ref);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (step.kind === 'step') {
|
|
119
|
+
try {
|
|
120
|
+
results[step.ref] = await execStep(step, args);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
124
|
+
const policy = step.failure ?? { mode: 'abort' };
|
|
125
|
+
if (policy.mode === 'ignore') {
|
|
126
|
+
failures.push({ stepId: step.ref, reason, handled: 'ignored' });
|
|
127
|
+
results[step.ref] = { failed: true, ignored: true, reason, expected: policy.expectedReason };
|
|
128
|
+
}
|
|
129
|
+
else if (policy.mode === 'compensate') {
|
|
130
|
+
const comp = plan.steps.find((s) => s.ref === policy.compensationStepId && s.kind === 'step');
|
|
131
|
+
if (!comp)
|
|
132
|
+
return { status: 'failed', authority, bindings, outputs: results, reason: `compensation step ${policy.compensationStepId} not found`, failures };
|
|
133
|
+
try {
|
|
134
|
+
results[comp.ref] = await execStep(comp, resolveValue(comp.args ?? {}, results));
|
|
135
|
+
done.add(comp.ref);
|
|
136
|
+
}
|
|
137
|
+
catch (ce) {
|
|
138
|
+
return { status: 'failed', authority, bindings, outputs: results, reason: `compensation ${comp.ref} failed: ${ce instanceof Error ? ce.message : String(ce)}`, failures };
|
|
139
|
+
}
|
|
140
|
+
failures.push({ stepId: step.ref, reason, handled: 'compensated' });
|
|
141
|
+
results[step.ref] = { failed: true, compensatedBy: comp.ref, reason };
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return { status: 'failed', authority, bindings, outputs: results, reason, failures };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
done.add(step.ref);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const outputs = plan.outputSpec ? resolveValue(plan.outputSpec, results) : results;
|
|
151
|
+
return { status: 'completed', authority, bindings, outputs, failures };
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=plan.js.map
|
package/dist/plan.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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AC,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;oBACpE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;gBACxE,CAAC;qBAAM,CAAC;oBACN,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;gBACvF,CAAC;YACH,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAE,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAA6B,CAAC,CAAC,CAAC,OAAO,CAAC;IAChH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive-registry.d.ts","sourceRoot":"","sources":["../src/primitive-registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAqF,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAavI,wBAAgB,uBAAuB,IAAI,iBAAiB,CAoB3D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Does the advertised capability's constraints cover the requirement's? (requirement ⊆ advertisement) */
|
|
2
|
+
function covers(req, cap) {
|
|
3
|
+
if (req.capability !== cap.id)
|
|
4
|
+
return false;
|
|
5
|
+
const rc = req.constraints;
|
|
6
|
+
if (!rc)
|
|
7
|
+
return true;
|
|
8
|
+
const ac = cap.constraints ?? {};
|
|
9
|
+
const subset = (need, have) => !need || need.length === 0 || (!!have && need.every((n) => have.includes(n)));
|
|
10
|
+
return subset(rc.networks, ac.networks) && subset(rc.assetTypes, ac.assetTypes) && subset(rc.operations, ac.operations);
|
|
11
|
+
}
|
|
12
|
+
export function createPrimitiveRegistry() {
|
|
13
|
+
const byId = new Map();
|
|
14
|
+
return {
|
|
15
|
+
register(primitive) {
|
|
16
|
+
byId.set(primitive.primitiveId, primitive);
|
|
17
|
+
},
|
|
18
|
+
resolve(requirement) {
|
|
19
|
+
for (const p of byId.values()) {
|
|
20
|
+
const cap = p.capabilities.find((c) => covers(requirement, c));
|
|
21
|
+
if (cap)
|
|
22
|
+
return { requirement: requirement.capability, primitiveId: p.primitiveId, capability: cap.id, version: cap.version };
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
},
|
|
26
|
+
get(primitiveId) {
|
|
27
|
+
return byId.get(primitiveId);
|
|
28
|
+
},
|
|
29
|
+
list() {
|
|
30
|
+
return [...byId.values()];
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=primitive-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive-registry.js","sourceRoot":"","sources":["../src/primitive-registry.ts"],"names":[],"mappings":"AAMA,0GAA0G;AAC1G,SAAS,MAAM,CAAC,GAAmC,EAAE,GAAwB;IAC3E,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,CAAC;IAC3B,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACrB,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;IACjC,MAAM,MAAM,GAAG,CAAC,IAAe,EAAE,IAAe,EAAE,EAAE,CAClD,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,IA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
|
+
import { type AnySkillDefinition, type AssertionReport, type Exposure, type ExecutionReceipt, type Offering, type ServiceAgentOptions, type SkillInvocation, type SkillProfile } from './types.js';
|
|
2
|
+
export declare class ServiceAgent {
|
|
3
|
+
private readonly options;
|
|
4
|
+
private definitions;
|
|
5
|
+
private assertions;
|
|
6
|
+
private readonly now;
|
|
7
|
+
constructor(options: ServiceAgentOptions);
|
|
8
|
+
define(def: AnySkillDefinition): this;
|
|
9
|
+
defineProfile(profile: SkillProfile): this;
|
|
10
|
+
/** Resolve which defined skills the host can execute, HEALTH-GATE them (spec 284), record assertions, and
|
|
11
|
+
* publish (spec 282) the ACTIVE ones if wired. An asserted skill is `suspended` if any bound primitive's
|
|
12
|
+
* `healthy?()` resolves false or any injected health check fails — "installed once" ≠ "safe now". */
|
|
13
|
+
assert(opts?: {
|
|
14
|
+
exposure?: (s: AnySkillDefinition) => Exposure;
|
|
15
|
+
strict?: boolean;
|
|
16
|
+
}): Promise<AssertionReport>;
|
|
17
|
+
/** Collect the reasons a skill should be suspended (empty = healthy/active). */
|
|
18
|
+
private healthReasons;
|
|
19
|
+
/** Re-run assertion (e.g. after a primitive's capability is revoked OR a dependency degrades) —
|
|
20
|
+
* retracts now-unsupported skills and re-evaluates suspension for the rest. */
|
|
21
|
+
reconcile(): Promise<AssertionReport>;
|
|
22
|
+
hasAssertion(skillId: string): boolean;
|
|
23
|
+
/** Is the skill asserted AND currently active (not suspended)? */
|
|
24
|
+
isActive(skillId: string): boolean;
|
|
25
|
+
/** A2A/card projection: the ACTIVE asserted skills at or below the requested exposure (private never
|
|
26
|
+
* projected; suspended never projected). The full entitlement/delegation decision still happens at
|
|
27
|
+
* invoke time — card visibility is not authorization. */
|
|
28
|
+
projectSkills(projection: 'public' | 'authenticated'): {
|
|
29
|
+
id: string;
|
|
30
|
+
version: string;
|
|
31
|
+
effect: string;
|
|
32
|
+
}[];
|
|
33
|
+
/** Project the asserted skills as first-class Offerings (spec 286) — the live, host-asserted drill-down
|
|
34
|
+
* behind discovery. Includes both active AND suspended assertions (status carries availability); private
|
|
35
|
+
* skills are never offered. `familyOf` (optional) maps a skill id to its coarse capability family. The
|
|
36
|
+
* result is host-asserted + live — callers MUST NOT persist it to the on-chain discovery A-box (ADR-0040). */
|
|
37
|
+
projectOfferings(projection: 'public' | 'authenticated', opts?: {
|
|
38
|
+
familyOf?: (skillId: string) => string;
|
|
39
|
+
}): Offering[];
|
|
40
|
+
/** Execute a skill: assert-gate → compile plan → run (entitlement ∩ delegation ∩ policy ∩ providers) → receipt. */
|
|
41
|
+
invoke<Input = unknown>(inv: SkillInvocation<Input>): Promise<ExecutionReceipt>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=service-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-agent.d.ts","sourceRoot":"","sources":["../src/service-agent.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAA0B,KAAK,QAAQ,EAAE,KAAK,gBAAgB,EAC3G,KAAK,QAAQ,EAAE,KAAK,mBAAmB,EAAuB,KAAK,eAAe,EAAE,KAAK,YAAY,EACtG,MAAM,YAAY,CAAC;AAEpB,qBAAa,YAAY;IAKX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,OAAO,CAAC,WAAW,CAAyC;IAC5D,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;gBAEN,OAAO,EAAE,mBAAmB;IAIzD,MAAM,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI;IAIrC,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAK1C;;0GAEsG;IAChG,MAAM,CAAC,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,QAAQ,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,eAAe,CAAC;IAgBvH,gFAAgF;YAClE,aAAa;IAqB3B;oFACgF;IAC1E,SAAS,IAAI,OAAO,CAAC,eAAe,CAAC;IAI3C,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAGtC,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIlC;;8DAE0D;IAC1D,aAAa,CAAC,UAAU,EAAE,QAAQ,GAAG,eAAe,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE;IAOxG;;;mHAG+G;IAC/G,gBAAgB,CAAC,UAAU,EAAE,QAAQ,GAAG,eAAe,EAAE,IAAI,GAAE;QAAE,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;KAAO,GAAG,QAAQ,EAAE;IAwB3H,mHAAmH;IAC7G,MAAM,CAAC,KAAK,GAAG,OAAO,EAAE,GAAG,EAAE,eAAe,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAoCtF"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// ServiceAgent (spec 283) — composition, NOT inheritance (no ServiceSmartAgent base exists; W1 is flat:
|
|
2
|
+
// SA address + AgentCard.type). Holds the skill definitions + assertions, runs the assert + invoke
|
|
3
|
+
// lifecycle, and projects an A2A skill list. Provider-neutral: registry + evaluators + ledger are injected.
|
|
4
|
+
import { assertSkills } from './assert.js';
|
|
5
|
+
import { runPlan } from './plan.js';
|
|
6
|
+
import { SkillNotAssertedError, SkillSuspendedError, } from './types.js';
|
|
7
|
+
export class ServiceAgent {
|
|
8
|
+
options;
|
|
9
|
+
definitions = new Map();
|
|
10
|
+
assertions = new Map();
|
|
11
|
+
now;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.now = options.now ?? (() => new Date(0).toISOString());
|
|
15
|
+
}
|
|
16
|
+
define(def) {
|
|
17
|
+
this.definitions.set(def.id, def);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
defineProfile(profile) {
|
|
21
|
+
for (const d of profile.definitions)
|
|
22
|
+
this.define(d);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
/** Resolve which defined skills the host can execute, HEALTH-GATE them (spec 284), record assertions, and
|
|
26
|
+
* publish (spec 282) the ACTIVE ones if wired. An asserted skill is `suspended` if any bound primitive's
|
|
27
|
+
* `healthy?()` resolves false or any injected health check fails — "installed once" ≠ "safe now". */
|
|
28
|
+
async assert(opts = {}) {
|
|
29
|
+
const report = assertSkills({ definitions: [...this.definitions.values()], registry: this.options.primitives, exposure: opts.exposure, now: this.now });
|
|
30
|
+
this.assertions.clear();
|
|
31
|
+
for (const a of report.asserted) {
|
|
32
|
+
const reasons = await this.healthReasons(a.skillId, a.primitiveBindings);
|
|
33
|
+
a.status = reasons.length === 0 ? 'active' : 'suspended';
|
|
34
|
+
if (reasons.length > 0)
|
|
35
|
+
a.suspendedReasons = reasons;
|
|
36
|
+
this.assertions.set(a.skillId, a);
|
|
37
|
+
if (a.status === 'active' && this.options.publishAssertion)
|
|
38
|
+
await this.options.publishAssertion(a);
|
|
39
|
+
}
|
|
40
|
+
if (opts.strict && (report.unavailable.length > 0 || report.rejected.length > 0)) {
|
|
41
|
+
throw new Error(`[service-agent] strict assert failed: ${report.unavailable.map((u) => u.skillId).join(', ')} unavailable`);
|
|
42
|
+
}
|
|
43
|
+
return report;
|
|
44
|
+
}
|
|
45
|
+
/** Collect the reasons a skill should be suspended (empty = healthy/active). */
|
|
46
|
+
async healthReasons(skillId, bindings) {
|
|
47
|
+
const reasons = [];
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
for (const b of bindings) {
|
|
50
|
+
if (seen.has(b.primitiveId))
|
|
51
|
+
continue;
|
|
52
|
+
seen.add(b.primitiveId);
|
|
53
|
+
const primitive = this.options.primitives.get(b.primitiveId);
|
|
54
|
+
if (primitive?.healthy) {
|
|
55
|
+
try {
|
|
56
|
+
if (!(await primitive.healthy()))
|
|
57
|
+
reasons.push(`provider ${b.primitiveId} unhealthy`);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
reasons.push(`provider ${b.primitiveId} health check threw: ${e instanceof Error ? e.message : String(e)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const def = this.definitions.get(skillId);
|
|
65
|
+
for (const check of this.options.healthChecks ?? []) {
|
|
66
|
+
if (!def)
|
|
67
|
+
break;
|
|
68
|
+
try {
|
|
69
|
+
const v = await check.evaluate({ skill: def, bindings });
|
|
70
|
+
if (!v.healthy)
|
|
71
|
+
reasons.push(v.reason ?? 'health check failed');
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
reasons.push(`health check threw: ${e instanceof Error ? e.message : String(e)}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return reasons;
|
|
78
|
+
}
|
|
79
|
+
/** Re-run assertion (e.g. after a primitive's capability is revoked OR a dependency degrades) —
|
|
80
|
+
* retracts now-unsupported skills and re-evaluates suspension for the rest. */
|
|
81
|
+
async reconcile() {
|
|
82
|
+
return this.assert();
|
|
83
|
+
}
|
|
84
|
+
hasAssertion(skillId) {
|
|
85
|
+
return this.assertions.has(skillId);
|
|
86
|
+
}
|
|
87
|
+
/** Is the skill asserted AND currently active (not suspended)? */
|
|
88
|
+
isActive(skillId) {
|
|
89
|
+
return this.assertions.get(skillId)?.status === 'active';
|
|
90
|
+
}
|
|
91
|
+
/** A2A/card projection: the ACTIVE asserted skills at or below the requested exposure (private never
|
|
92
|
+
* projected; suspended never projected). The full entitlement/delegation decision still happens at
|
|
93
|
+
* invoke time — card visibility is not authorization. */
|
|
94
|
+
projectSkills(projection) {
|
|
95
|
+
const allowed = projection === 'public' ? ['public'] : ['public', 'authenticated'];
|
|
96
|
+
return [...this.assertions.values()]
|
|
97
|
+
.filter((a) => a.status !== 'suspended' && allowed.includes(a.exposure))
|
|
98
|
+
.map((a) => ({ id: a.skillId, version: a.version, effect: this.definitions.get(a.skillId)?.effect ?? 'read' }));
|
|
99
|
+
}
|
|
100
|
+
/** Project the asserted skills as first-class Offerings (spec 286) — the live, host-asserted drill-down
|
|
101
|
+
* behind discovery. Includes both active AND suspended assertions (status carries availability); private
|
|
102
|
+
* skills are never offered. `familyOf` (optional) maps a skill id to its coarse capability family. The
|
|
103
|
+
* result is host-asserted + live — callers MUST NOT persist it to the on-chain discovery A-box (ADR-0040). */
|
|
104
|
+
projectOfferings(projection, opts = {}) {
|
|
105
|
+
const allowed = projection === 'public' ? ['public'] : ['public', 'authenticated'];
|
|
106
|
+
const out = [];
|
|
107
|
+
for (const a of this.assertions.values()) {
|
|
108
|
+
if (!allowed.includes(a.exposure))
|
|
109
|
+
continue;
|
|
110
|
+
const def = this.definitions.get(a.skillId);
|
|
111
|
+
if (!def)
|
|
112
|
+
continue;
|
|
113
|
+
out.push({
|
|
114
|
+
agentId: this.options.descriptor.id,
|
|
115
|
+
skillId: a.skillId,
|
|
116
|
+
version: a.version,
|
|
117
|
+
name: def.name,
|
|
118
|
+
description: def.description,
|
|
119
|
+
effect: def.effect,
|
|
120
|
+
exposure: a.exposure,
|
|
121
|
+
family: opts.familyOf?.(a.skillId),
|
|
122
|
+
requiredCapabilities: def.requires.map((r) => r.capability),
|
|
123
|
+
hasInputSchema: !!def.inputSchema,
|
|
124
|
+
status: a.status ?? 'active',
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
/** Execute a skill: assert-gate → compile plan → run (entitlement ∩ delegation ∩ policy ∩ providers) → receipt. */
|
|
130
|
+
async invoke(inv) {
|
|
131
|
+
const def = this.definitions.get(inv.skillId);
|
|
132
|
+
if (!def)
|
|
133
|
+
throw new SkillNotAssertedError(`unknown skill ${inv.skillId}`);
|
|
134
|
+
const assertion = this.assertions.get(inv.skillId);
|
|
135
|
+
if (!assertion)
|
|
136
|
+
throw new SkillNotAssertedError(`skill ${inv.skillId} not asserted`);
|
|
137
|
+
if (assertion.status === 'suspended') {
|
|
138
|
+
throw new SkillSuspendedError(`skill ${inv.skillId} is suspended: ${(assertion.suspendedReasons ?? []).join('; ') || 'unhealthy'}`);
|
|
139
|
+
}
|
|
140
|
+
if (def.effect !== 'read' && !inv.idempotencyKey) {
|
|
141
|
+
throw new Error(`[service-agent] ${inv.skillId} (effect=${def.effect}) requires an idempotencyKey`);
|
|
142
|
+
}
|
|
143
|
+
const startedAt = this.now();
|
|
144
|
+
const context = { agentId: this.options.descriptor.id, subject: inv.subject, tenant: inv.tenant, correlationId: inv.correlationId, idempotencyKey: inv.idempotencyKey };
|
|
145
|
+
const input = def.inputSchema ? def.inputSchema.parse(inv.input) : inv.input;
|
|
146
|
+
const plan = def.compile({ input: input, context });
|
|
147
|
+
const run = await runPlan(plan, {
|
|
148
|
+
registry: this.options.primitives,
|
|
149
|
+
entitlements: this.options.entitlements,
|
|
150
|
+
delegations: this.options.delegations,
|
|
151
|
+
policies: this.options.policies,
|
|
152
|
+
ledger: this.options.ledger,
|
|
153
|
+
context,
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
receiptId: `${inv.skillId}:${inv.idempotencyKey ?? inv.correlationId ?? startedAt}`,
|
|
157
|
+
agentId: this.options.descriptor.id,
|
|
158
|
+
skill: { id: def.id, version: def.version },
|
|
159
|
+
subject: inv.subject,
|
|
160
|
+
authority: run.authority,
|
|
161
|
+
execution: { planId: plan.id, primitiveBindings: run.bindings, outputs: run.outputs },
|
|
162
|
+
status: run.status === 'completed' ? 'completed' : 'failed',
|
|
163
|
+
reason: run.reason,
|
|
164
|
+
startedAt,
|
|
165
|
+
completedAt: this.now(),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=service-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAc,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7D,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE;YAC9B,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;YACjC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;YACvC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,WAAW;YACrC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;YAC/B,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;YAC3B,OAAO;SACR,CAAC,CAAC;QACH,OAAO;YACL,SAAS,EAAE,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,cAAc,IAAI,GAAG,CAAC,aAAa,IAAI,SAAS,EAAE;YACnF,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YACnC,KAAK,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;YAC3C,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,iBAAiB,EAAE,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE;YACrF,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ;YAC3D,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,SAAS;YACT,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE;SACxB,CAAC;IACJ,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import type { Address } from '@agenticprimitives/types';
|
|
2
|
+
/** What a skill does — drives default exposure + risk handling (spec 283). */
|
|
3
|
+
export type Effect = 'read' | 'sign' | 'spend' | 'trade' | 'admin';
|
|
4
|
+
/** Whether a skill is discoverable / remotely invocable. `private` = asserted but never projected. */
|
|
5
|
+
export type Exposure = 'private' | 'authenticated' | 'public';
|
|
6
|
+
/** Minimal input/output validator — duck-typed so the framework picks no schema lib. */
|
|
7
|
+
export interface Schema<T> {
|
|
8
|
+
parse(value: unknown): T;
|
|
9
|
+
}
|
|
10
|
+
/** Constraints a capability (requirement OR advertisement) is scoped by — networks/assets/operations. */
|
|
11
|
+
export interface CapabilityConstraints {
|
|
12
|
+
networks?: string[];
|
|
13
|
+
assetTypes?: string[];
|
|
14
|
+
operations?: string[];
|
|
15
|
+
}
|
|
16
|
+
/** A LOGICAL capability a skill requires (not a concrete provider). */
|
|
17
|
+
export interface PrimitiveCapabilityRequirement {
|
|
18
|
+
capability: string;
|
|
19
|
+
versionRange?: string;
|
|
20
|
+
optional?: boolean;
|
|
21
|
+
constraints?: CapabilityConstraints;
|
|
22
|
+
}
|
|
23
|
+
/** A capability an installed primitive advertises. */
|
|
24
|
+
export interface PrimitiveCapability {
|
|
25
|
+
id: string;
|
|
26
|
+
version: string;
|
|
27
|
+
constraints?: CapabilityConstraints;
|
|
28
|
+
}
|
|
29
|
+
/** Context passed to a primitive operation at run time. */
|
|
30
|
+
export interface PrimitiveContext {
|
|
31
|
+
agentId: string;
|
|
32
|
+
subject?: string;
|
|
33
|
+
correlationId?: string;
|
|
34
|
+
idempotencyKey?: string;
|
|
35
|
+
}
|
|
36
|
+
/** What execution shape(s) a plan step produces — see spec 284. `native-dag` decomposes into known
|
|
37
|
+
* primitive ops; `opaque-calldata` is provider tx data (decode + simulate + validate before signing);
|
|
38
|
+
* `offchain-order` is a signed venue/solver order (validate domain/market/expiry/collateral). */
|
|
39
|
+
export type PlanKind = 'native-dag' | 'opaque-calldata' | 'offchain-order';
|
|
40
|
+
/** Machine-readable provider manifest (spec 284): lets the host reason about a provider's shape + audit
|
|
41
|
+
* boundary without hard-coding it. All fields optional so existing providers stay valid (additive). */
|
|
42
|
+
export interface PrimitiveManifest {
|
|
43
|
+
planKinds?: PlanKind[];
|
|
44
|
+
supportsQuote?: boolean;
|
|
45
|
+
supportsSimulation?: boolean;
|
|
46
|
+
supportsCancellation?: boolean;
|
|
47
|
+
supportsRecovery?: boolean;
|
|
48
|
+
/** CAIP-2 namespaces / network ids this provider serves. */
|
|
49
|
+
chainNamespaces?: string[];
|
|
50
|
+
networks?: string[];
|
|
51
|
+
/** Free-form identifier of the audit scope this provider was reviewed under. */
|
|
52
|
+
auditBoundary?: string;
|
|
53
|
+
}
|
|
54
|
+
/** A registered provider: advertises capabilities + executes their operations. Concrete impls (EVM
|
|
55
|
+
* transfer, swap venue, …) live EXTERNAL (ADR-0037) and register here; the demo ships fakes. */
|
|
56
|
+
export interface Primitive {
|
|
57
|
+
primitiveId: string;
|
|
58
|
+
capabilities: PrimitiveCapability[];
|
|
59
|
+
execute(capability: string, input: unknown, ctx: PrimitiveContext): Promise<unknown>;
|
|
60
|
+
/** Liveness — when present and resolving false, the host SUSPENDS skills bound to this provider. */
|
|
61
|
+
healthy?(): Promise<boolean>;
|
|
62
|
+
/** Provider shape + audit boundary (spec 284). Optional. */
|
|
63
|
+
manifest?(): PrimitiveManifest;
|
|
64
|
+
}
|
|
65
|
+
/** Resolution of one requirement against the registry. */
|
|
66
|
+
export interface CapabilityBinding {
|
|
67
|
+
requirement: string;
|
|
68
|
+
primitiveId: string;
|
|
69
|
+
capability: string;
|
|
70
|
+
version: string;
|
|
71
|
+
}
|
|
72
|
+
/** The primitive registry — modeled on `payments` registerRail/getRail. */
|
|
73
|
+
export interface PrimitiveRegistry {
|
|
74
|
+
register(primitive: Primitive): void;
|
|
75
|
+
/** Resolve a requirement → a binding, or null if no installed primitive satisfies it. */
|
|
76
|
+
resolve(requirement: PrimitiveCapabilityRequirement): CapabilityBinding | null;
|
|
77
|
+
get(primitiveId: string): Primitive | undefined;
|
|
78
|
+
list(): Primitive[];
|
|
79
|
+
}
|
|
80
|
+
export interface AuthorityRequest {
|
|
81
|
+
action: string;
|
|
82
|
+
resource?: string;
|
|
83
|
+
subject?: string;
|
|
84
|
+
agentId?: string;
|
|
85
|
+
input?: unknown;
|
|
86
|
+
}
|
|
87
|
+
export interface AuthorityDecision {
|
|
88
|
+
allow: boolean;
|
|
89
|
+
decisionId?: string;
|
|
90
|
+
reason?: string;
|
|
91
|
+
}
|
|
92
|
+
/** "May this caller request this skill for this resource?" → tool-policy.evaluatePolicy + entitlements. */
|
|
93
|
+
export interface EntitlementEvaluator {
|
|
94
|
+
evaluate(req: AuthorityRequest): Promise<AuthorityDecision>;
|
|
95
|
+
}
|
|
96
|
+
/** "Does the agent have authority FROM the owner?" → delegation.evaluateCaveats / verifyAuthorization. */
|
|
97
|
+
export interface DelegationEvaluator {
|
|
98
|
+
evaluate(req: AuthorityRequest): Promise<AuthorityDecision>;
|
|
99
|
+
}
|
|
100
|
+
/** Runtime policy gate → tool-policy.evaluatePolicy. */
|
|
101
|
+
export interface PolicyEvaluator {
|
|
102
|
+
evaluate(req: AuthorityRequest): Promise<AuthorityDecision>;
|
|
103
|
+
}
|
|
104
|
+
/** Ledger reserve/finalize (NET-NEW, spec 283): double-spend guard before execute, reconcile after. */
|
|
105
|
+
export interface LedgerReservation {
|
|
106
|
+
reservationId: string;
|
|
107
|
+
}
|
|
108
|
+
export interface LedgerPrimitive {
|
|
109
|
+
reserve(args: {
|
|
110
|
+
accountId: string;
|
|
111
|
+
asset: string;
|
|
112
|
+
amount: string;
|
|
113
|
+
idempotencyKey: string;
|
|
114
|
+
}): Promise<LedgerReservation>;
|
|
115
|
+
finalize(args: {
|
|
116
|
+
reservationId: string;
|
|
117
|
+
settlement: unknown;
|
|
118
|
+
}): Promise<{
|
|
119
|
+
journalId: string;
|
|
120
|
+
}>;
|
|
121
|
+
release?(reservationId: string): Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
export type PlanStepKind = 'step' | 'authorize' | 'guard' | 'checkpoint' | 'output';
|
|
124
|
+
/** A reference to a prior step's output, resolved by the runner. */
|
|
125
|
+
export interface PlanRef {
|
|
126
|
+
__ref: string;
|
|
127
|
+
path?: string;
|
|
128
|
+
}
|
|
129
|
+
/** Per-step failure policy (spec 284 DAG plans). `abort` (default) fails the plan; `ignore` records the
|
|
130
|
+
* failure + continues (with a declared expected reason); `compensate` runs a named compensation step. */
|
|
131
|
+
export type StepFailurePolicy = {
|
|
132
|
+
mode: 'abort';
|
|
133
|
+
} | {
|
|
134
|
+
mode: 'ignore';
|
|
135
|
+
expectedReason: string;
|
|
136
|
+
} | {
|
|
137
|
+
mode: 'compensate';
|
|
138
|
+
compensationStepId: string;
|
|
139
|
+
};
|
|
140
|
+
export interface PlanStep {
|
|
141
|
+
kind: PlanStepKind;
|
|
142
|
+
ref: string;
|
|
143
|
+
op?: string;
|
|
144
|
+
evaluator?: 'entitlement' | 'delegation' | 'policy';
|
|
145
|
+
args?: Record<string, unknown>;
|
|
146
|
+
basedOn?: PlanRef[];
|
|
147
|
+
/** DAG edges (spec 284): refs of steps that MUST have run before this one. Validated fail-closed — a
|
|
148
|
+
* dependency on an unknown/later step rejects the plan. */
|
|
149
|
+
dependsOn?: string[];
|
|
150
|
+
/** What to do if a `step` fails (provider throws / no provider). Default `abort`. */
|
|
151
|
+
failure?: StepFailurePolicy;
|
|
152
|
+
}
|
|
153
|
+
export interface PrimitivePlan {
|
|
154
|
+
id: string;
|
|
155
|
+
steps: PlanStep[];
|
|
156
|
+
outputSpec?: Record<string, unknown>;
|
|
157
|
+
}
|
|
158
|
+
export interface SkillDefinition<Input = unknown, Output = unknown> {
|
|
159
|
+
id: string;
|
|
160
|
+
version: string;
|
|
161
|
+
name: string;
|
|
162
|
+
description?: string;
|
|
163
|
+
effect: Effect;
|
|
164
|
+
defaultExposure: Exposure;
|
|
165
|
+
requires: PrimitiveCapabilityRequirement[];
|
|
166
|
+
entitlement?: {
|
|
167
|
+
action: string;
|
|
168
|
+
resource?: (input: Input) => string | undefined;
|
|
169
|
+
};
|
|
170
|
+
delegation?: {
|
|
171
|
+
action: string;
|
|
172
|
+
resource?: (input: Input) => string | undefined;
|
|
173
|
+
};
|
|
174
|
+
inputSchema?: Schema<Input>;
|
|
175
|
+
outputSchema?: Schema<Output>;
|
|
176
|
+
compile: (args: {
|
|
177
|
+
input: Input;
|
|
178
|
+
context: InvocationContext;
|
|
179
|
+
}) => PrimitivePlan;
|
|
180
|
+
}
|
|
181
|
+
/** A skill definition of unknown concrete I/O — for heterogeneous storage (registry/profile/Map). The
|
|
182
|
+
* `any` params are deliberate: `SkillDefinition` is invariant (contravariant `compile`/`resolve` params),
|
|
183
|
+
* so a narrow `SkillDefinition<{...}>` is NOT assignable to `<unknown, unknown>`. */
|
|
184
|
+
export type AnySkillDefinition = SkillDefinition<any, any>;
|
|
185
|
+
export interface SkillProfile {
|
|
186
|
+
id: string;
|
|
187
|
+
definitions: AnySkillDefinition[];
|
|
188
|
+
}
|
|
189
|
+
/** Whether an asserted skill is safe to execute RIGHT NOW (spec 284). `active` = all required primitives
|
|
190
|
+
* resolved AND healthy AND every injected health check passed; `suspended` = capability resolved but a
|
|
191
|
+
* runtime dependency is degraded (provider unhealthy, delegation expired, risk engine offline, …).
|
|
192
|
+
* A suspended skill is never projected to a card and rejects at invoke — "installed once" ≠ "safe now." */
|
|
193
|
+
export type AssertionStatus = 'active' | 'suspended';
|
|
194
|
+
export interface SkillAssertion {
|
|
195
|
+
skillId: string;
|
|
196
|
+
version: string;
|
|
197
|
+
exposure: Exposure;
|
|
198
|
+
primitiveBindings: CapabilityBinding[];
|
|
199
|
+
issuedAt: string;
|
|
200
|
+
/** Defaults to `active` when produced by the pure `assertSkills` resolver; the ServiceAgent layers
|
|
201
|
+
* health gating on top and may flip this to `suspended`. */
|
|
202
|
+
status?: AssertionStatus;
|
|
203
|
+
/** Present when `status === 'suspended'` — one entry per failed health signal. */
|
|
204
|
+
suspendedReasons?: string[];
|
|
205
|
+
}
|
|
206
|
+
/** A runtime health signal layered on top of capability resolution (spec 284). Return `{healthy:false}`
|
|
207
|
+
* to SUSPEND the skill (e.g. delegation expired, risk engine offline, network unhealthy). */
|
|
208
|
+
export interface AssertionHealthCheck {
|
|
209
|
+
evaluate(args: {
|
|
210
|
+
skill: AnySkillDefinition;
|
|
211
|
+
bindings: CapabilityBinding[];
|
|
212
|
+
}): Promise<{
|
|
213
|
+
healthy: boolean;
|
|
214
|
+
reason?: string;
|
|
215
|
+
}>;
|
|
216
|
+
}
|
|
217
|
+
export interface AssertionReport {
|
|
218
|
+
asserted: SkillAssertion[];
|
|
219
|
+
unavailable: {
|
|
220
|
+
skillId: string;
|
|
221
|
+
missingCapabilities: string[];
|
|
222
|
+
}[];
|
|
223
|
+
rejected: {
|
|
224
|
+
skillId: string;
|
|
225
|
+
reason: string;
|
|
226
|
+
}[];
|
|
227
|
+
}
|
|
228
|
+
/** A first-class callable offering = (agent × asserted skill), advertised by a service agent (spec 286).
|
|
229
|
+
* Host-asserted + live — never persisted to the on-chain discovery A-box (ADR-0040). Private skills are
|
|
230
|
+
* never offered. `status` carries availability (a suspended skill is offered-but-not-callable). The
|
|
231
|
+
* `price`/`sla`/`evidence` fields are optional: price/sla are a future host-asserted economics layer;
|
|
232
|
+
* `evidence` is stamped by the discovery crawler (endpoint + observedAt + card digest), not the host. */
|
|
233
|
+
export interface Offering {
|
|
234
|
+
agentId: string;
|
|
235
|
+
skillId: string;
|
|
236
|
+
version: string;
|
|
237
|
+
name: string;
|
|
238
|
+
description?: string;
|
|
239
|
+
effect: Effect;
|
|
240
|
+
exposure: Exposure;
|
|
241
|
+
family?: string;
|
|
242
|
+
requiredCapabilities: string[];
|
|
243
|
+
hasInputSchema: boolean;
|
|
244
|
+
status: AssertionStatus;
|
|
245
|
+
price?: {
|
|
246
|
+
asset: string;
|
|
247
|
+
amount: string;
|
|
248
|
+
unit?: string;
|
|
249
|
+
};
|
|
250
|
+
sla?: {
|
|
251
|
+
latencyMs?: number;
|
|
252
|
+
availabilityBps?: number;
|
|
253
|
+
};
|
|
254
|
+
evidence?: {
|
|
255
|
+
endpoint: string;
|
|
256
|
+
observedAt: number;
|
|
257
|
+
cardDigest?: string;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
export interface InvocationContext {
|
|
261
|
+
agentId: string;
|
|
262
|
+
subject?: string;
|
|
263
|
+
tenant?: string;
|
|
264
|
+
correlationId?: string;
|
|
265
|
+
idempotencyKey?: string;
|
|
266
|
+
}
|
|
267
|
+
export interface SkillInvocation<Input = unknown> {
|
|
268
|
+
skillId: string;
|
|
269
|
+
input: Input;
|
|
270
|
+
subject?: string;
|
|
271
|
+
tenant?: string;
|
|
272
|
+
correlationId?: string;
|
|
273
|
+
idempotencyKey?: string;
|
|
274
|
+
}
|
|
275
|
+
export interface AuthorityRecord {
|
|
276
|
+
action: string;
|
|
277
|
+
evaluator: string;
|
|
278
|
+
decisionId?: string;
|
|
279
|
+
allow: boolean;
|
|
280
|
+
}
|
|
281
|
+
export interface ExecutionReceipt {
|
|
282
|
+
receiptId: string;
|
|
283
|
+
agentId: string;
|
|
284
|
+
skill: {
|
|
285
|
+
id: string;
|
|
286
|
+
version: string;
|
|
287
|
+
};
|
|
288
|
+
subject?: string;
|
|
289
|
+
authority: AuthorityRecord[];
|
|
290
|
+
execution: {
|
|
291
|
+
planId: string;
|
|
292
|
+
primitiveBindings: string[];
|
|
293
|
+
outputs: Record<string, unknown>;
|
|
294
|
+
};
|
|
295
|
+
status: 'completed' | 'failed' | 'denied';
|
|
296
|
+
reason?: string;
|
|
297
|
+
startedAt: string;
|
|
298
|
+
completedAt: string;
|
|
299
|
+
}
|
|
300
|
+
export interface ServiceAgentDescriptor {
|
|
301
|
+
id: string;
|
|
302
|
+
name: string;
|
|
303
|
+
version: string;
|
|
304
|
+
}
|
|
305
|
+
export interface ServiceAgentOptions {
|
|
306
|
+
descriptor: ServiceAgentDescriptor;
|
|
307
|
+
primitives: PrimitiveRegistry;
|
|
308
|
+
entitlements?: EntitlementEvaluator;
|
|
309
|
+
delegations?: DelegationEvaluator;
|
|
310
|
+
policies?: PolicyEvaluator;
|
|
311
|
+
ledger?: LedgerPrimitive;
|
|
312
|
+
/** Wires the public assertion to spec 282 (vault claim -> atl:skills) at the app layer. Optional. */
|
|
313
|
+
publishAssertion?: (assertion: SkillAssertion) => Promise<void>;
|
|
314
|
+
/** Runtime health signals layered on capability resolution (spec 284). Any failing check suspends the
|
|
315
|
+
* skill. Use for delegation expiry, risk-engine liveness, network health, provider-assertion freshness. */
|
|
316
|
+
healthChecks?: AssertionHealthCheck[];
|
|
317
|
+
/** Monotonic clock for receipt/assertion timestamps (injected; the framework avoids ambient Date). */
|
|
318
|
+
now?: () => string;
|
|
319
|
+
}
|
|
320
|
+
/** Thrown when authority is denied — distinct types so callers can branch (parity with the design). */
|
|
321
|
+
export declare class EntitlementDeniedError extends Error {
|
|
322
|
+
}
|
|
323
|
+
export declare class DelegationDeniedError extends Error {
|
|
324
|
+
}
|
|
325
|
+
export declare class PolicyDeniedError extends Error {
|
|
326
|
+
}
|
|
327
|
+
export declare class SkillNotAssertedError extends Error {
|
|
328
|
+
}
|
|
329
|
+
/** Thrown at invoke when a skill is asserted but currently SUSPENDED (a runtime dependency is degraded). */
|
|
330
|
+
export declare class SkillSuspendedError extends Error {
|
|
331
|
+
}
|
|
332
|
+
export type { Address };
|
|
333
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD,8EAA8E;AAC9E,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEnE,sGAAsG;AACtG,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,eAAe,GAAG,QAAQ,CAAC;AAE9D,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CAAC,EAAE,eAAe,CAAC;IACzB,qGAAqG;IACrG,gBAAgB,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE;gHAC4G;IAC5G,YAAY,CAAC,EAAE,oBAAoB,EAAE,CAAC;IACtC,sGAAsG;IACtG,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,uGAAuG;AACvG,qBAAa,sBAAuB,SAAQ,KAAK;CAAG;AACpD,qBAAa,qBAAsB,SAAQ,KAAK;CAAG;AACnD,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAC/C,qBAAa,qBAAsB,SAAQ,KAAK;CAAG;AACnD,4GAA4G;AAC5G,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD,YAAY,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Thrown when authority is denied — distinct types so callers can branch (parity with the design). */
|
|
2
|
+
export class EntitlementDeniedError extends Error {
|
|
3
|
+
}
|
|
4
|
+
export class DelegationDeniedError extends Error {
|
|
5
|
+
}
|
|
6
|
+
export class PolicyDeniedError extends Error {
|
|
7
|
+
}
|
|
8
|
+
export class SkillNotAssertedError extends Error {
|
|
9
|
+
}
|
|
10
|
+
/** Thrown at invoke when a skill is asserted but currently SUSPENDED (a runtime dependency is degraded). */
|
|
11
|
+
export class SkillSuspendedError extends Error {
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA4RA,uGAAuG;AACvG,MAAM,OAAO,sBAAuB,SAAQ,KAAK;CAAG;AACpD,MAAM,OAAO,qBAAsB,SAAQ,KAAK;CAAG;AACnD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;CAAG;AAC/C,MAAM,OAAO,qBAAsB,SAAQ,KAAK;CAAG;AACnD,4GAA4G;AAC5G,MAAM,OAAO,mBAAoB,SAAQ,KAAK;CAAG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agenticprimitives/service-agent",
|
|
3
|
+
"version": "0.0.0-alpha.0",
|
|
4
|
+
"description": "Generic service-agent capability framework (spec 283): define -> assert -> entitle -> delegate -> primitive-plan -> execute -> receipt. Provider-neutral; all authority evaluators + primitives are injected. Domain catalogs (e.g. @agenticprimitives/treasury) build on it.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/agentictrustlabs/agenticprimitives.git",
|
|
9
|
+
"directory": "packages/service-agent"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"vitest": "^4.1.8"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"agentic",
|
|
33
|
+
"primitives",
|
|
34
|
+
"service-agent",
|
|
35
|
+
"skills",
|
|
36
|
+
"capability"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@agenticprimitives/types": "1.0.0-alpha.13"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -p tsconfig.build.json",
|
|
43
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:unit": "vitest run test --passWithNoTests",
|
|
46
|
+
"clean": "rm -rf dist"
|
|
47
|
+
}
|
|
48
|
+
}
|