@veil-runtime/core 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 +201 -0
- package/README.md +480 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +21 -0
- package/dist/providers/storage/sqlite-job-store.d.ts +10 -0
- package/dist/providers/storage/sqlite-job-store.js +89 -0
- package/dist/runtime/events/event-bus.d.ts +6 -0
- package/dist/runtime/events/event-bus.js +2 -0
- package/dist/runtime/events/event-subscriber.d.ts +6 -0
- package/dist/runtime/events/event-subscriber.js +2 -0
- package/dist/runtime/events/memory-event-bus.d.ts +9 -0
- package/dist/runtime/events/memory-event-bus.js +31 -0
- package/dist/runtime/events/runtime-event.d.ts +10 -0
- package/dist/runtime/events/runtime-event.js +2 -0
- package/dist/runtime/execution/console-execution-logger.d.ts +13 -0
- package/dist/runtime/execution/console-execution-logger.js +37 -0
- package/dist/runtime/execution/execution-context.d.ts +13 -0
- package/dist/runtime/execution/execution-context.js +2 -0
- package/dist/runtime/execution/execution-logger.d.ts +15 -0
- package/dist/runtime/execution/execution-logger.js +2 -0
- package/dist/runtime/execution/plan-validator.d.ts +13 -0
- package/dist/runtime/execution/plan-validator.js +122 -0
- package/dist/runtime/execution/result-reference.d.ts +9 -0
- package/dist/runtime/execution/result-reference.js +59 -0
- package/dist/runtime/jobs/job-event.d.ts +8 -0
- package/dist/runtime/jobs/job-event.js +2 -0
- package/dist/runtime/jobs/job-manager.d.ts +17 -0
- package/dist/runtime/jobs/job-manager.js +214 -0
- package/dist/runtime/jobs/job-memory.d.ts +6 -0
- package/dist/runtime/jobs/job-memory.js +70 -0
- package/dist/runtime/jobs/job-status.d.ts +1 -0
- package/dist/runtime/jobs/job-status.js +2 -0
- package/dist/runtime/jobs/job-step.d.ts +10 -0
- package/dist/runtime/jobs/job-step.js +2 -0
- package/dist/runtime/jobs/job-store.d.ts +15 -0
- package/dist/runtime/jobs/job-store.js +52 -0
- package/dist/runtime/jobs/job.d.ts +20 -0
- package/dist/runtime/jobs/job.js +2 -0
- package/dist/runtime/logging/composite-log-sink.d.ts +7 -0
- package/dist/runtime/logging/composite-log-sink.js +13 -0
- package/dist/runtime/logging/console-log-sink.d.ts +6 -0
- package/dist/runtime/logging/console-log-sink.js +28 -0
- package/dist/runtime/logging/execution-log-sink.d.ts +4 -0
- package/dist/runtime/logging/execution-log-sink.js +2 -0
- package/dist/runtime/logging/sqlite-log-sink.d.ts +7 -0
- package/dist/runtime/logging/sqlite-log-sink.js +52 -0
- package/dist/runtime/modules/capability-module-manifest.d.ts +11 -0
- package/dist/runtime/modules/capability-module-manifest.js +2 -0
- package/dist/runtime/modules/capability-module.d.ts +6 -0
- package/dist/runtime/modules/capability-module.js +2 -0
- package/dist/runtime/operator-runtime.d.ts +31 -0
- package/dist/runtime/operator-runtime.js +71 -0
- package/dist/runtime/permissions/permissions.d.ts +7 -0
- package/dist/runtime/permissions/permissions.js +42 -0
- package/dist/runtime/planner/planner-definition.d.ts +9 -0
- package/dist/runtime/planner/planner-definition.js +2 -0
- package/dist/runtime/planner/planner-eligibility.d.ts +7 -0
- package/dist/runtime/planner/planner-eligibility.js +20 -0
- package/dist/runtime/planner/planner-provider.d.ts +11 -0
- package/dist/runtime/planner/planner-provider.js +2 -0
- package/dist/runtime/planner/planner-registry.d.ts +40 -0
- package/dist/runtime/planner/planner-registry.js +103 -0
- package/dist/runtime/planner/planner-router-registry.d.ts +17 -0
- package/dist/runtime/planner/planner-router-registry.js +37 -0
- package/dist/runtime/planner/planner-router.d.ts +14 -0
- package/dist/runtime/planner/planner-router.js +2 -0
- package/dist/runtime/planner/planner-runtime-state.d.ts +6 -0
- package/dist/runtime/planner/planner-runtime-state.js +2 -0
- package/dist/runtime/planner/planner-traits.d.ts +10 -0
- package/dist/runtime/planner/planner-traits.js +2 -0
- package/dist/runtime/planner/planner.d.ts +29 -0
- package/dist/runtime/planner/planner.js +2 -0
- package/dist/runtime/planner/strategies/planner-strategy-registry.d.ts +12 -0
- package/dist/runtime/planner/strategies/planner-strategy-registry.js +22 -0
- package/dist/runtime/planner/strategies/planner-strategy.d.ts +11 -0
- package/dist/runtime/planner/strategies/planner-strategy.js +2 -0
- package/dist/runtime/registry/capability.d.ts +15 -0
- package/dist/runtime/registry/capability.js +2 -0
- package/dist/runtime/registry/registry.d.ts +15 -0
- package/dist/runtime/registry/registry.js +25 -0
- package/dist/sdk/capability/capability-definition.d.ts +19 -0
- package/dist/sdk/capability/capability-definition.js +2 -0
- package/dist/sdk/capability/capability-middleware.d.ts +5 -0
- package/dist/sdk/capability/capability-middleware.js +2 -0
- package/dist/sdk/capability/create-capability.d.ts +3 -0
- package/dist/sdk/capability/create-capability.js +37 -0
- package/dist/sdk/capability/index.d.ts +5 -0
- package/dist/sdk/capability/index.js +9 -0
- package/dist/sdk/capability/lifecycle-logging-middleware.d.ts +7 -0
- package/dist/sdk/capability/lifecycle-logging-middleware.js +35 -0
- package/dist/sdk/capability/timeout-middleware.d.ts +7 -0
- package/dist/sdk/capability/timeout-middleware.js +43 -0
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.js +17 -0
- package/package.json +70 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CapabilityRisk } from '../registry/capability.js';
|
|
2
|
+
export interface PermissionDecision {
|
|
3
|
+
allowed: boolean;
|
|
4
|
+
requiresApproval: boolean;
|
|
5
|
+
reason?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function checkPermission(risk: CapabilityRisk, approved?: boolean): PermissionDecision;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkPermission = checkPermission;
|
|
4
|
+
function checkPermission(risk, approved = false) {
|
|
5
|
+
if (risk === 'read') {
|
|
6
|
+
return {
|
|
7
|
+
allowed: true,
|
|
8
|
+
requiresApproval: false,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
if (risk === 'write') {
|
|
12
|
+
if (approved) {
|
|
13
|
+
return {
|
|
14
|
+
allowed: true,
|
|
15
|
+
requiresApproval: false,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
allowed: false,
|
|
20
|
+
requiresApproval: true,
|
|
21
|
+
reason: 'Write capability requires explicit approval.',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (risk === 'destructive') {
|
|
25
|
+
if (approved) {
|
|
26
|
+
return {
|
|
27
|
+
allowed: true,
|
|
28
|
+
requiresApproval: false,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
allowed: false,
|
|
33
|
+
requiresApproval: true,
|
|
34
|
+
reason: 'Destructive capability requires explicit approval.',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
allowed: false,
|
|
39
|
+
requiresApproval: false,
|
|
40
|
+
reason: 'Unknown capability risk.',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PlannerDefinition } from './planner-definition.js';
|
|
2
|
+
import { PlannerRuntimeState } from './planner-runtime-state.js';
|
|
3
|
+
export interface PlannerEligibility {
|
|
4
|
+
eligible: boolean;
|
|
5
|
+
reasons: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare function evaluatePlannerEligibility(definition: PlannerDefinition, state: PlannerRuntimeState): PlannerEligibility;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluatePlannerEligibility = evaluatePlannerEligibility;
|
|
4
|
+
function evaluatePlannerEligibility(definition, state) {
|
|
5
|
+
const reasons = [];
|
|
6
|
+
if (!definition.enabled) {
|
|
7
|
+
reasons.push('Planner is disabled');
|
|
8
|
+
}
|
|
9
|
+
if (!state.available) {
|
|
10
|
+
reasons.push('Planner is unavailable');
|
|
11
|
+
}
|
|
12
|
+
if (!state.healthy) {
|
|
13
|
+
reasons.push(state.failureReason ??
|
|
14
|
+
'Planner is unhealthy');
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
eligible: reasons.length === 0,
|
|
18
|
+
reasons,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExecutionPlan, PlannerContext } from './planner.js';
|
|
2
|
+
export interface PlannerHealthResult {
|
|
3
|
+
healthy: boolean;
|
|
4
|
+
available: boolean;
|
|
5
|
+
reason?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface PlannerProvider {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
plan(goal: string, context?: PlannerContext): Promise<ExecutionPlan>;
|
|
10
|
+
healthCheck?(): Promise<PlannerHealthResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PlannerProvider } from './planner-provider.js';
|
|
2
|
+
import { PlannerDefinition } from './planner-definition.js';
|
|
3
|
+
import { PlannerRuntimeState } from './planner-runtime-state.js';
|
|
4
|
+
export interface RegisteredPlanner {
|
|
5
|
+
definition: PlannerDefinition;
|
|
6
|
+
provider: PlannerProvider;
|
|
7
|
+
state: PlannerRuntimeState;
|
|
8
|
+
}
|
|
9
|
+
interface RegisterPlannerOptions {
|
|
10
|
+
state?: Partial<PlannerRuntimeState>;
|
|
11
|
+
}
|
|
12
|
+
declare class PlannerRegistry {
|
|
13
|
+
private readonly planners;
|
|
14
|
+
register(definition: PlannerDefinition, provider: PlannerProvider, options?: RegisterPlannerOptions): void;
|
|
15
|
+
get(id: string): PlannerProvider | undefined;
|
|
16
|
+
getRegistered(id: string): RegisteredPlanner | undefined;
|
|
17
|
+
getEligibility(id: string): import("./planner-eligibility.js").PlannerEligibility;
|
|
18
|
+
list(): Array<{
|
|
19
|
+
name: string;
|
|
20
|
+
}>;
|
|
21
|
+
refreshHealth(id: string): Promise<RegisteredPlanner>;
|
|
22
|
+
refreshAllHealth(): Promise<void>;
|
|
23
|
+
listStatus(): {
|
|
24
|
+
id: string;
|
|
25
|
+
type: string;
|
|
26
|
+
enabled: boolean;
|
|
27
|
+
required: boolean;
|
|
28
|
+
traits: import("./planner-traits.js").PlannerTraits | undefined;
|
|
29
|
+
healthy: boolean;
|
|
30
|
+
available: boolean;
|
|
31
|
+
lastCheckedAt: string | undefined;
|
|
32
|
+
failureReason: string | undefined;
|
|
33
|
+
eligible: boolean;
|
|
34
|
+
reasons: string[];
|
|
35
|
+
}[];
|
|
36
|
+
listRegistered(): RegisteredPlanner[];
|
|
37
|
+
updateState(id: string, state: Partial<PlannerRuntimeState>): RegisteredPlanner;
|
|
38
|
+
}
|
|
39
|
+
export declare const plannerRegistry: PlannerRegistry;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plannerRegistry = void 0;
|
|
4
|
+
const planner_eligibility_js_1 = require("./planner-eligibility.js");
|
|
5
|
+
class PlannerRegistry {
|
|
6
|
+
planners = new Map();
|
|
7
|
+
register(definition, provider, options = {}) {
|
|
8
|
+
if (this.planners.has(definition.id)) {
|
|
9
|
+
throw new Error(`Planner already registered: ${definition.id}`);
|
|
10
|
+
}
|
|
11
|
+
const entry = {
|
|
12
|
+
definition,
|
|
13
|
+
provider,
|
|
14
|
+
state: {
|
|
15
|
+
healthy: true,
|
|
16
|
+
available: true,
|
|
17
|
+
...options.state,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
this.planners.set(definition.id, entry);
|
|
21
|
+
}
|
|
22
|
+
get(id) {
|
|
23
|
+
return this.planners.get(id)?.provider;
|
|
24
|
+
}
|
|
25
|
+
getRegistered(id) {
|
|
26
|
+
return this.planners.get(id);
|
|
27
|
+
}
|
|
28
|
+
getEligibility(id) {
|
|
29
|
+
const planner = this.planners.get(id);
|
|
30
|
+
if (!planner) {
|
|
31
|
+
throw new Error(`Planner not found: ${id}`);
|
|
32
|
+
}
|
|
33
|
+
return (0, planner_eligibility_js_1.evaluatePlannerEligibility)(planner.definition, planner.state);
|
|
34
|
+
}
|
|
35
|
+
list() {
|
|
36
|
+
return Array.from(this.planners.values()).map((entry) => ({
|
|
37
|
+
name: entry.definition.id,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
async refreshHealth(id) {
|
|
41
|
+
const planner = this.planners.get(id);
|
|
42
|
+
if (!planner) {
|
|
43
|
+
throw new Error(`Planner not found: ${id}`);
|
|
44
|
+
}
|
|
45
|
+
const checkedAt = new Date().toISOString();
|
|
46
|
+
if (!planner.provider.healthCheck) {
|
|
47
|
+
planner.state = {
|
|
48
|
+
...planner.state,
|
|
49
|
+
healthy: true,
|
|
50
|
+
available: true,
|
|
51
|
+
lastCheckedAt: checkedAt,
|
|
52
|
+
failureReason: undefined,
|
|
53
|
+
};
|
|
54
|
+
return planner;
|
|
55
|
+
}
|
|
56
|
+
const health = await planner.provider.healthCheck();
|
|
57
|
+
planner.state = {
|
|
58
|
+
...planner.state,
|
|
59
|
+
healthy: health.healthy,
|
|
60
|
+
available: health.available,
|
|
61
|
+
lastCheckedAt: checkedAt,
|
|
62
|
+
failureReason: health.reason,
|
|
63
|
+
};
|
|
64
|
+
return planner;
|
|
65
|
+
}
|
|
66
|
+
async refreshAllHealth() {
|
|
67
|
+
await Promise.all(Array.from(this.planners.keys()).map((id) => this.refreshHealth(id)));
|
|
68
|
+
}
|
|
69
|
+
listStatus() {
|
|
70
|
+
return Array.from(this.planners.values()).map((planner) => {
|
|
71
|
+
const eligibility = (0, planner_eligibility_js_1.evaluatePlannerEligibility)(planner.definition, planner.state);
|
|
72
|
+
return {
|
|
73
|
+
id: planner.definition.id,
|
|
74
|
+
type: planner.definition.type,
|
|
75
|
+
enabled: planner.definition.enabled,
|
|
76
|
+
required: planner.definition.required ??
|
|
77
|
+
false,
|
|
78
|
+
traits: planner.definition.traits,
|
|
79
|
+
healthy: planner.state.healthy,
|
|
80
|
+
available: planner.state.available,
|
|
81
|
+
lastCheckedAt: planner.state.lastCheckedAt,
|
|
82
|
+
failureReason: planner.state.failureReason,
|
|
83
|
+
eligible: eligibility.eligible,
|
|
84
|
+
reasons: eligibility.reasons,
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
listRegistered() {
|
|
89
|
+
return Array.from(this.planners.values());
|
|
90
|
+
}
|
|
91
|
+
updateState(id, state) {
|
|
92
|
+
const planner = this.planners.get(id);
|
|
93
|
+
if (!planner) {
|
|
94
|
+
throw new Error(`Planner not found: ${id}`);
|
|
95
|
+
}
|
|
96
|
+
planner.state = {
|
|
97
|
+
...planner.state,
|
|
98
|
+
...state,
|
|
99
|
+
};
|
|
100
|
+
return planner;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.plannerRegistry = new PlannerRegistry();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PlannerRouter } from './planner-router.js';
|
|
2
|
+
declare class PlannerRouterRegistry {
|
|
3
|
+
private readonly routers;
|
|
4
|
+
private defaultRouterId?;
|
|
5
|
+
register(id: string, router: PlannerRouter, options?: {
|
|
6
|
+
default?: boolean;
|
|
7
|
+
}): void;
|
|
8
|
+
get(id: string): PlannerRouter | undefined;
|
|
9
|
+
getDefault(): PlannerRouter | undefined;
|
|
10
|
+
getDefaultId(): string | undefined;
|
|
11
|
+
list(): Array<{
|
|
12
|
+
id: string;
|
|
13
|
+
default: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export declare const plannerRouterRegistry: PlannerRouterRegistry;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plannerRouterRegistry = void 0;
|
|
4
|
+
class PlannerRouterRegistry {
|
|
5
|
+
routers = new Map();
|
|
6
|
+
defaultRouterId;
|
|
7
|
+
register(id, router, options = {}) {
|
|
8
|
+
if (this.routers.has(id)) {
|
|
9
|
+
throw new Error(`Planner router already registered: ${id}`);
|
|
10
|
+
}
|
|
11
|
+
this.routers.set(id, router);
|
|
12
|
+
if (options.default) {
|
|
13
|
+
this.defaultRouterId =
|
|
14
|
+
id;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
get(id) {
|
|
18
|
+
return this.routers.get(id);
|
|
19
|
+
}
|
|
20
|
+
getDefault() {
|
|
21
|
+
if (!this.defaultRouterId) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
return this.routers.get(this.defaultRouterId);
|
|
25
|
+
}
|
|
26
|
+
getDefaultId() {
|
|
27
|
+
return this.defaultRouterId;
|
|
28
|
+
}
|
|
29
|
+
list() {
|
|
30
|
+
return Array.from(this.routers.keys()).map((id) => ({
|
|
31
|
+
id,
|
|
32
|
+
default: id ===
|
|
33
|
+
this.defaultRouterId,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.plannerRouterRegistry = new PlannerRouterRegistry();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PlannerContext } from './planner.js';
|
|
2
|
+
export interface PlannerRoutingRequest {
|
|
3
|
+
goal: string;
|
|
4
|
+
strategy?: string;
|
|
5
|
+
planner?: string;
|
|
6
|
+
context?: PlannerContext;
|
|
7
|
+
}
|
|
8
|
+
export interface PlannerSelection {
|
|
9
|
+
strategy: string;
|
|
10
|
+
reason?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface PlannerRouter {
|
|
13
|
+
select(request: PlannerRoutingRequest): Promise<PlannerSelection>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type PlannerCostClass = 'free' | 'low' | 'standard' | 'premium';
|
|
2
|
+
export type StructuredOutputSupport = 'none' | 'json' | 'schema';
|
|
3
|
+
export interface PlannerTraits {
|
|
4
|
+
local?: boolean;
|
|
5
|
+
costClass?: PlannerCostClass;
|
|
6
|
+
coding?: boolean;
|
|
7
|
+
structuredOutput?: StructuredOutputSupport;
|
|
8
|
+
toolReasoning?: boolean;
|
|
9
|
+
contextWindow?: number;
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface PlannerContext {
|
|
2
|
+
previousJobs?: Array<{
|
|
3
|
+
goal: string;
|
|
4
|
+
status: string;
|
|
5
|
+
capabilities: string[];
|
|
6
|
+
}>;
|
|
7
|
+
}
|
|
8
|
+
export interface ResultReference {
|
|
9
|
+
readonly $ref: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ExecutionStep {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly capability: string;
|
|
14
|
+
readonly capabilityVersion?: string;
|
|
15
|
+
readonly input?: unknown;
|
|
16
|
+
readonly reason?: string;
|
|
17
|
+
readonly idempotencyKey?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ExecutionPlan {
|
|
20
|
+
readonly version: string;
|
|
21
|
+
readonly id?: string;
|
|
22
|
+
readonly goal?: string;
|
|
23
|
+
readonly steps: readonly ExecutionStep[];
|
|
24
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
25
|
+
readonly idempotencyKey?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Planner {
|
|
28
|
+
plan(goal: string, context?: PlannerContext): Promise<ExecutionPlan>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PlannerStrategy } from './planner-strategy.js';
|
|
2
|
+
declare class PlannerStrategyRegistry {
|
|
3
|
+
private readonly strategies;
|
|
4
|
+
register(strategy: PlannerStrategy): void;
|
|
5
|
+
get(id: string): PlannerStrategy | undefined;
|
|
6
|
+
list(): {
|
|
7
|
+
id: string;
|
|
8
|
+
type: string;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
export declare const plannerStrategyRegistry: PlannerStrategyRegistry;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plannerStrategyRegistry = void 0;
|
|
4
|
+
class PlannerStrategyRegistry {
|
|
5
|
+
strategies = new Map();
|
|
6
|
+
register(strategy) {
|
|
7
|
+
if (this.strategies.has(strategy.id)) {
|
|
8
|
+
throw new Error(`Planner strategy already registered: ${strategy.id}`);
|
|
9
|
+
}
|
|
10
|
+
this.strategies.set(strategy.id, strategy);
|
|
11
|
+
}
|
|
12
|
+
get(id) {
|
|
13
|
+
return this.strategies.get(id);
|
|
14
|
+
}
|
|
15
|
+
list() {
|
|
16
|
+
return Array.from(this.strategies.values()).map((strategy) => ({
|
|
17
|
+
id: strategy.id,
|
|
18
|
+
type: strategy.type,
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.plannerStrategyRegistry = new PlannerStrategyRegistry();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExecutionPlan, PlannerContext } from '../planner.js';
|
|
2
|
+
export interface PlannerStrategyRequest {
|
|
3
|
+
goal: string;
|
|
4
|
+
planner?: string;
|
|
5
|
+
context?: PlannerContext;
|
|
6
|
+
}
|
|
7
|
+
export interface PlannerStrategy {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly type: string;
|
|
10
|
+
execute(request: PlannerStrategyRequest): Promise<ExecutionPlan>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ExecutionContext } from '../execution/execution-context.js';
|
|
2
|
+
export type CapabilityRisk = 'read' | 'write' | 'destructive';
|
|
3
|
+
export interface CapabilityInputField {
|
|
4
|
+
type: string;
|
|
5
|
+
required: boolean;
|
|
6
|
+
description: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Capability<TInput = unknown, TResult = unknown> {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly version: string;
|
|
11
|
+
readonly description: string;
|
|
12
|
+
readonly risk: CapabilityRisk;
|
|
13
|
+
inputSchema?: Record<string, CapabilityInputField>;
|
|
14
|
+
execute(input: TInput, context?: ExecutionContext): Promise<TResult>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Capability } from './capability.js';
|
|
2
|
+
declare class CapabilityRegistry {
|
|
3
|
+
private capabilities;
|
|
4
|
+
register(capability: Capability): void;
|
|
5
|
+
get(name: string): Capability | undefined;
|
|
6
|
+
list(): {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
description: string;
|
|
10
|
+
risk: import("./capability.js").CapabilityRisk;
|
|
11
|
+
inputSchema: Record<string, import("./capability.js").CapabilityInputField>;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
export declare const capabilityRegistry: CapabilityRegistry;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.capabilityRegistry = void 0;
|
|
4
|
+
class CapabilityRegistry {
|
|
5
|
+
capabilities = new Map();
|
|
6
|
+
register(capability) {
|
|
7
|
+
if (this.capabilities.has(capability.name)) {
|
|
8
|
+
throw new Error(`Capability already registered: ${capability.name}`);
|
|
9
|
+
}
|
|
10
|
+
this.capabilities.set(capability.name, capability);
|
|
11
|
+
}
|
|
12
|
+
get(name) {
|
|
13
|
+
return this.capabilities.get(name);
|
|
14
|
+
}
|
|
15
|
+
list() {
|
|
16
|
+
return Array.from(this.capabilities.values()).map((capability) => ({
|
|
17
|
+
name: capability.name,
|
|
18
|
+
version: capability.version,
|
|
19
|
+
description: capability.description,
|
|
20
|
+
risk: capability.risk,
|
|
21
|
+
inputSchema: capability.inputSchema ?? {},
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.capabilityRegistry = new CapabilityRegistry();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Capability, CapabilityInputField, CapabilityRisk } from '../../runtime/registry/capability.js';
|
|
2
|
+
import { ExecutionContext } from '../../runtime/execution/execution-context.js';
|
|
3
|
+
import { CapabilityMiddleware } from './capability-middleware.js';
|
|
4
|
+
export interface CapabilityExecution<TInput, TResult> {
|
|
5
|
+
input: TInput;
|
|
6
|
+
context?: ExecutionContext;
|
|
7
|
+
}
|
|
8
|
+
export interface CapabilityDefinition<TInput = unknown, TResult = unknown> {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
description: string;
|
|
12
|
+
risk: CapabilityRisk;
|
|
13
|
+
inputSchema?: Record<string, CapabilityInputField>;
|
|
14
|
+
lifecycleLogging?: boolean;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
middleware?: CapabilityMiddleware<TInput, TResult>[];
|
|
17
|
+
execute(execution: CapabilityExecution<TInput, TResult>): Promise<TResult>;
|
|
18
|
+
}
|
|
19
|
+
export type CreatedCapability<TInput, TResult> = Capability<TInput, TResult>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CapabilityExecution } from './capability-definition.js';
|
|
2
|
+
export type CapabilityNext<TResult> = () => Promise<TResult>;
|
|
3
|
+
export interface CapabilityMiddleware<TInput = unknown, TResult = unknown> {
|
|
4
|
+
execute(execution: CapabilityExecution<TInput, TResult>, next: CapabilityNext<TResult>): Promise<TResult>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Capability } from '../../runtime/registry/capability.js';
|
|
2
|
+
import { CapabilityDefinition } from './capability-definition.js';
|
|
3
|
+
export declare function createCapability<TInput = unknown, TResult = unknown>(definition: CapabilityDefinition<TInput, TResult>): Capability<TInput, TResult>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCapability = createCapability;
|
|
4
|
+
const lifecycle_logging_middleware_js_1 = require("./lifecycle-logging-middleware.js");
|
|
5
|
+
const timeout_middleware_js_1 = require("./timeout-middleware.js");
|
|
6
|
+
function createCapability(definition) {
|
|
7
|
+
return {
|
|
8
|
+
name: definition.name,
|
|
9
|
+
version: definition.version,
|
|
10
|
+
description: definition.description,
|
|
11
|
+
risk: definition.risk,
|
|
12
|
+
inputSchema: definition.inputSchema,
|
|
13
|
+
async execute(input, context) {
|
|
14
|
+
const execution = {
|
|
15
|
+
input,
|
|
16
|
+
context,
|
|
17
|
+
};
|
|
18
|
+
const middleware = [];
|
|
19
|
+
if (definition.lifecycleLogging ??
|
|
20
|
+
true) {
|
|
21
|
+
middleware.push(new lifecycle_logging_middleware_js_1.LifecycleLoggingMiddleware(definition.name));
|
|
22
|
+
}
|
|
23
|
+
if (definition.timeoutMs !==
|
|
24
|
+
undefined) {
|
|
25
|
+
middleware.push(new timeout_middleware_js_1.TimeoutMiddleware(definition.timeoutMs));
|
|
26
|
+
}
|
|
27
|
+
middleware.push(...(definition.middleware ?? []));
|
|
28
|
+
let next = () => definition.execute(execution);
|
|
29
|
+
for (let index = middleware.length - 1; index >= 0; index -= 1) {
|
|
30
|
+
const current = middleware[index];
|
|
31
|
+
const previousNext = next;
|
|
32
|
+
next = () => current.execute(execution, previousNext);
|
|
33
|
+
}
|
|
34
|
+
return next();
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createCapability, } from './create-capability.js';
|
|
2
|
+
export type { CapabilityDefinition, CapabilityExecution, CreatedCapability, } from './capability-definition.js';
|
|
3
|
+
export { LifecycleLoggingMiddleware, } from './lifecycle-logging-middleware.js';
|
|
4
|
+
export type { CapabilityMiddleware, CapabilityNext, } from './capability-middleware.js';
|
|
5
|
+
export { TimeoutMiddleware, } from './timeout-middleware.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimeoutMiddleware = exports.LifecycleLoggingMiddleware = exports.createCapability = void 0;
|
|
4
|
+
var create_capability_js_1 = require("./create-capability.js");
|
|
5
|
+
Object.defineProperty(exports, "createCapability", { enumerable: true, get: function () { return create_capability_js_1.createCapability; } });
|
|
6
|
+
var lifecycle_logging_middleware_js_1 = require("./lifecycle-logging-middleware.js");
|
|
7
|
+
Object.defineProperty(exports, "LifecycleLoggingMiddleware", { enumerable: true, get: function () { return lifecycle_logging_middleware_js_1.LifecycleLoggingMiddleware; } });
|
|
8
|
+
var timeout_middleware_js_1 = require("./timeout-middleware.js");
|
|
9
|
+
Object.defineProperty(exports, "TimeoutMiddleware", { enumerable: true, get: function () { return timeout_middleware_js_1.TimeoutMiddleware; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CapabilityMiddleware, CapabilityNext } from './capability-middleware.js';
|
|
2
|
+
import { CapabilityExecution } from './capability-definition.js';
|
|
3
|
+
export declare class LifecycleLoggingMiddleware<TInput = unknown, TResult = unknown> implements CapabilityMiddleware<TInput, TResult> {
|
|
4
|
+
private readonly capabilityName;
|
|
5
|
+
constructor(capabilityName: string);
|
|
6
|
+
execute(execution: CapabilityExecution<TInput, TResult>, next: CapabilityNext<TResult>): Promise<TResult>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LifecycleLoggingMiddleware = void 0;
|
|
4
|
+
class LifecycleLoggingMiddleware {
|
|
5
|
+
capabilityName;
|
|
6
|
+
constructor(capabilityName) {
|
|
7
|
+
this.capabilityName = capabilityName;
|
|
8
|
+
}
|
|
9
|
+
async execute(execution, next) {
|
|
10
|
+
const startedAt = Date.now();
|
|
11
|
+
execution.context?.logger.info('Capability execution started', {
|
|
12
|
+
capability: this.capabilityName,
|
|
13
|
+
});
|
|
14
|
+
try {
|
|
15
|
+
const result = await next();
|
|
16
|
+
execution.context?.logger.info('Capability execution completed', {
|
|
17
|
+
capability: this.capabilityName,
|
|
18
|
+
durationMs: Date.now() - startedAt,
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const message = error instanceof Error
|
|
24
|
+
? error.message
|
|
25
|
+
: 'Unknown capability error';
|
|
26
|
+
execution.context?.logger.error('Capability execution failed', {
|
|
27
|
+
capability: this.capabilityName,
|
|
28
|
+
durationMs: Date.now() - startedAt,
|
|
29
|
+
error: message,
|
|
30
|
+
});
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.LifecycleLoggingMiddleware = LifecycleLoggingMiddleware;
|