@peer-agent/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 +21 -0
- package/README.md +35 -0
- package/dist/capability-registry.d.ts +15 -0
- package/dist/capability-registry.js +88 -0
- package/dist/contracts.d.ts +218 -0
- package/dist/contracts.js +1 -0
- package/dist/decision.d.ts +4 -0
- package/dist/decision.js +23 -0
- package/dist/evidence.d.ts +52 -0
- package/dist/evidence.js +86 -0
- package/dist/hooks.d.ts +5 -0
- package/dist/hooks.js +4 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/permission.d.ts +18 -0
- package/dist/permission.js +50 -0
- package/dist/projection-materializers.d.ts +18 -0
- package/dist/projection-materializers.js +34 -0
- package/dist/projection.d.ts +15 -0
- package/dist/projection.js +78 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 梁音
|
|
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,35 @@
|
|
|
1
|
+
# @peer-agent/runtime-core
|
|
2
|
+
|
|
3
|
+
Host-neutral governance primitives for Peer Agent runtimes.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @peer-agent/runtime-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Scope
|
|
12
|
+
|
|
13
|
+
This package provides the reusable primitives behind the Runtime governance chain:
|
|
14
|
+
|
|
15
|
+
- capability provider registry
|
|
16
|
+
- projection and projection materializers
|
|
17
|
+
- permission decisions
|
|
18
|
+
- Hook decision merging
|
|
19
|
+
- Evidence bundles
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import {
|
|
23
|
+
createCapabilityProviderRegistry,
|
|
24
|
+
createEvidenceBundle,
|
|
25
|
+
mostRestrictiveHookDecision,
|
|
26
|
+
} from '@peer-agent/runtime-core';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`@peer-agent/runtime-core` does not execute external commands and does not depend on Electron, filesystem APIs, child processes, network clients, or UI frameworks. Host-specific implementations belong in adapters such as `@peer-agent/runtime-node`.
|
|
30
|
+
|
|
31
|
+
Use the package root export only. Deep imports into `src` or `dist` are not public API.
|
|
32
|
+
|
|
33
|
+
## Compatibility
|
|
34
|
+
|
|
35
|
+
This package follows SemVer independently from the Peer Agent Desktop application. `@peer-agent/runtime-sdk` declares its supported core range as a normal package dependency.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CapabilityExecutionContext, CapabilityProvider, CapabilityRequest, CapabilityResult, RuntimeCapabilityId, RuntimeProviderId } from './contracts.ts';
|
|
2
|
+
export type CapabilityRegistryErrorCode = 'invalid_provider' | 'duplicate_provider' | 'duplicate_capability' | 'capability_not_found';
|
|
3
|
+
export declare class CapabilityRegistryError extends Error {
|
|
4
|
+
readonly code: CapabilityRegistryErrorCode;
|
|
5
|
+
constructor(message: string, code: CapabilityRegistryErrorCode);
|
|
6
|
+
}
|
|
7
|
+
export interface CapabilityProviderRegistry {
|
|
8
|
+
register(provider: CapabilityProvider): void;
|
|
9
|
+
getProvider(capabilityId: RuntimeCapabilityId): CapabilityProvider | undefined;
|
|
10
|
+
execute(request: CapabilityRequest, context: CapabilityExecutionContext): Promise<CapabilityResult>;
|
|
11
|
+
hasCapability(capabilityId: RuntimeCapabilityId): boolean;
|
|
12
|
+
listCapabilityIds(): RuntimeCapabilityId[];
|
|
13
|
+
listProviderIds(): RuntimeProviderId[];
|
|
14
|
+
}
|
|
15
|
+
export declare function createCapabilityProviderRegistry(initialProviders?: readonly CapabilityProvider[]): CapabilityProviderRegistry;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export class CapabilityRegistryError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(message, code) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'CapabilityRegistryError';
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function providerCapabilityIds(provider) {
|
|
10
|
+
if (Array.isArray(provider.capabilityIds)) {
|
|
11
|
+
return provider.capabilityIds;
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(provider.capabilities)) {
|
|
14
|
+
return provider.capabilities.map((capability) => capability.capabilityId);
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
function assertProvider(provider) {
|
|
19
|
+
if (!provider || typeof provider !== 'object') {
|
|
20
|
+
throw new CapabilityRegistryError('Capability provider must be an object.', 'invalid_provider');
|
|
21
|
+
}
|
|
22
|
+
if (!provider.providerId) {
|
|
23
|
+
throw new CapabilityRegistryError('Capability provider must declare providerId.', 'invalid_provider');
|
|
24
|
+
}
|
|
25
|
+
const hasIds = providerCapabilityIds(provider).length > 0;
|
|
26
|
+
const hasPrefix = typeof provider.capabilityPrefix === 'string' && provider.capabilityPrefix.length > 0;
|
|
27
|
+
const hasCanHandle = typeof provider.canHandle === 'function';
|
|
28
|
+
if (!hasIds && !hasPrefix && !hasCanHandle) {
|
|
29
|
+
throw new CapabilityRegistryError('Capability provider must declare capabilityIds, capabilities, capabilityPrefix, or canHandle().', 'invalid_provider');
|
|
30
|
+
}
|
|
31
|
+
if (typeof provider.execute !== 'function') {
|
|
32
|
+
throw new CapabilityRegistryError('Capability provider must implement execute().', 'invalid_provider');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function createCapabilityProviderRegistry(initialProviders = []) {
|
|
36
|
+
const providersById = new Map();
|
|
37
|
+
const providerByCapabilityId = new Map();
|
|
38
|
+
const prefixProviders = [];
|
|
39
|
+
const customProviders = [];
|
|
40
|
+
function register(provider) {
|
|
41
|
+
assertProvider(provider);
|
|
42
|
+
if (providersById.has(provider.providerId)) {
|
|
43
|
+
throw new CapabilityRegistryError(`Duplicate capability provider: ${provider.providerId}`, 'duplicate_provider');
|
|
44
|
+
}
|
|
45
|
+
providersById.set(provider.providerId, provider);
|
|
46
|
+
for (const capabilityId of providerCapabilityIds(provider)) {
|
|
47
|
+
if (providerByCapabilityId.has(capabilityId)) {
|
|
48
|
+
throw new CapabilityRegistryError(`Duplicate capability id: ${capabilityId}`, 'duplicate_capability');
|
|
49
|
+
}
|
|
50
|
+
providerByCapabilityId.set(capabilityId, provider);
|
|
51
|
+
}
|
|
52
|
+
if (provider.capabilityPrefix) {
|
|
53
|
+
prefixProviders.push(provider);
|
|
54
|
+
}
|
|
55
|
+
if (provider.canHandle) {
|
|
56
|
+
customProviders.push(provider);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function getProvider(capabilityId) {
|
|
60
|
+
const direct = providerByCapabilityId.get(capabilityId);
|
|
61
|
+
if (direct) {
|
|
62
|
+
return direct;
|
|
63
|
+
}
|
|
64
|
+
const prefixed = prefixProviders.find((provider) => capabilityId.startsWith(provider.capabilityPrefix ?? ''));
|
|
65
|
+
if (prefixed) {
|
|
66
|
+
return prefixed;
|
|
67
|
+
}
|
|
68
|
+
return customProviders.find((provider) => provider.canHandle?.(capabilityId));
|
|
69
|
+
}
|
|
70
|
+
async function execute(request, context) {
|
|
71
|
+
const provider = getProvider(request.capabilityId);
|
|
72
|
+
if (!provider) {
|
|
73
|
+
throw new CapabilityRegistryError(`No capability provider found for ${request.capabilityId}`, 'capability_not_found');
|
|
74
|
+
}
|
|
75
|
+
return provider.execute(request, context);
|
|
76
|
+
}
|
|
77
|
+
for (const provider of initialProviders) {
|
|
78
|
+
register(provider);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
register,
|
|
82
|
+
getProvider,
|
|
83
|
+
execute,
|
|
84
|
+
hasCapability: (capabilityId) => Boolean(getProvider(capabilityId)),
|
|
85
|
+
listCapabilityIds: () => [...providerByCapabilityId.keys()],
|
|
86
|
+
listProviderIds: () => [...providersById.keys()],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
export type RuntimeCapabilityId = string;
|
|
2
|
+
export type RuntimeProviderId = string;
|
|
3
|
+
export type RuntimeRunId = string;
|
|
4
|
+
export type RuntimeSessionId = string;
|
|
5
|
+
export type RuntimeDecision = 'allow' | 'ask' | 'deny';
|
|
6
|
+
export type RuntimeToolStatus = 'completed' | 'failed' | 'denied' | 'waiting_user' | 'timeout' | 'cancelled';
|
|
7
|
+
export type RuntimeRiskLevel = 'L0_inert' | 'L1_readonly' | 'L2_low_write' | 'L3_sensitive' | 'L4_external_side_effect' | 'L5_destructive' | 'unknown';
|
|
8
|
+
export type RuntimeModeScope = 'chat' | 'goal' | 'plan' | 'compact' | 'system' | string;
|
|
9
|
+
export type RuntimeJsonObject = Readonly<Record<string, unknown>>;
|
|
10
|
+
export interface RuntimeWorkspaceRef {
|
|
11
|
+
readonly root?: string;
|
|
12
|
+
readonly id?: string;
|
|
13
|
+
readonly name?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface RuntimeToolCall {
|
|
16
|
+
readonly toolCallId: string;
|
|
17
|
+
readonly capabilityId: RuntimeCapabilityId;
|
|
18
|
+
readonly name?: string;
|
|
19
|
+
readonly input?: unknown;
|
|
20
|
+
readonly inputPreview?: unknown;
|
|
21
|
+
readonly reason?: string;
|
|
22
|
+
readonly mode?: RuntimeModeScope;
|
|
23
|
+
readonly metadata?: RuntimeJsonObject;
|
|
24
|
+
}
|
|
25
|
+
export interface RuntimeToolError {
|
|
26
|
+
readonly code: string;
|
|
27
|
+
readonly message: string;
|
|
28
|
+
readonly recoverable?: boolean;
|
|
29
|
+
readonly details?: unknown;
|
|
30
|
+
}
|
|
31
|
+
export interface RuntimeToolResult {
|
|
32
|
+
readonly toolCallId: string;
|
|
33
|
+
readonly capabilityId: RuntimeCapabilityId;
|
|
34
|
+
readonly status: RuntimeToolStatus;
|
|
35
|
+
readonly output?: unknown;
|
|
36
|
+
readonly outputPreview?: unknown;
|
|
37
|
+
readonly permissionGrant?: PermissionGrant;
|
|
38
|
+
readonly evidence?: EvidenceBundle;
|
|
39
|
+
readonly error?: RuntimeToolError;
|
|
40
|
+
readonly metadata?: RuntimeJsonObject;
|
|
41
|
+
}
|
|
42
|
+
export interface CapabilityManifest {
|
|
43
|
+
readonly capabilityId: RuntimeCapabilityId;
|
|
44
|
+
readonly displayName: string;
|
|
45
|
+
readonly description?: string;
|
|
46
|
+
readonly riskLevel?: RuntimeRiskLevel;
|
|
47
|
+
readonly inputSchema?: unknown;
|
|
48
|
+
readonly outputSchema?: unknown;
|
|
49
|
+
readonly modeScopes?: readonly RuntimeModeScope[];
|
|
50
|
+
readonly metadata?: RuntimeJsonObject;
|
|
51
|
+
}
|
|
52
|
+
export interface CapabilityRequest {
|
|
53
|
+
readonly toolCall: RuntimeToolCall;
|
|
54
|
+
readonly capabilityId: RuntimeCapabilityId;
|
|
55
|
+
readonly input?: unknown;
|
|
56
|
+
readonly metadata?: RuntimeJsonObject;
|
|
57
|
+
}
|
|
58
|
+
export interface CapabilityResult extends RuntimeToolResult {
|
|
59
|
+
}
|
|
60
|
+
export interface CapabilityProvider {
|
|
61
|
+
readonly providerId: RuntimeProviderId;
|
|
62
|
+
readonly capabilities?: readonly CapabilityManifest[];
|
|
63
|
+
readonly capabilityIds?: readonly RuntimeCapabilityId[];
|
|
64
|
+
readonly capabilityPrefix?: string;
|
|
65
|
+
canHandle?(capabilityId: RuntimeCapabilityId): boolean;
|
|
66
|
+
execute(request: CapabilityRequest, context: CapabilityExecutionContext): Promise<CapabilityResult> | CapabilityResult;
|
|
67
|
+
}
|
|
68
|
+
export interface CapabilityExecutionContext extends RuntimeExecutionContext {
|
|
69
|
+
}
|
|
70
|
+
export interface RuntimeExecutionContext {
|
|
71
|
+
readonly runId: RuntimeRunId;
|
|
72
|
+
readonly sessionId?: RuntimeSessionId;
|
|
73
|
+
readonly workspace?: RuntimeWorkspaceRef;
|
|
74
|
+
readonly mode?: RuntimeModeScope;
|
|
75
|
+
readonly signal?: AbortSignal;
|
|
76
|
+
readonly permissions?: PermissionGateway;
|
|
77
|
+
readonly hooks?: HookPipeline;
|
|
78
|
+
readonly evidence?: EvidenceSink;
|
|
79
|
+
readonly events?: RuntimeEventSink;
|
|
80
|
+
readonly logger?: RuntimeLogger;
|
|
81
|
+
readonly metadata?: RuntimeJsonObject;
|
|
82
|
+
}
|
|
83
|
+
export interface RuntimeLogger {
|
|
84
|
+
debug?(message: string, metadata?: RuntimeJsonObject): void;
|
|
85
|
+
info?(message: string, metadata?: RuntimeJsonObject): void;
|
|
86
|
+
warn?(message: string, metadata?: RuntimeJsonObject): void;
|
|
87
|
+
error?(message: string, metadata?: RuntimeJsonObject): void;
|
|
88
|
+
}
|
|
89
|
+
export interface PermissionRequest {
|
|
90
|
+
readonly capabilityId: RuntimeCapabilityId;
|
|
91
|
+
readonly toolCall: RuntimeToolCall;
|
|
92
|
+
readonly riskLevel?: RuntimeRiskLevel;
|
|
93
|
+
readonly reason?: string;
|
|
94
|
+
readonly metadata?: RuntimeJsonObject;
|
|
95
|
+
}
|
|
96
|
+
export interface PermissionDecision {
|
|
97
|
+
readonly decision: RuntimeDecision;
|
|
98
|
+
readonly source: string;
|
|
99
|
+
readonly reason?: string;
|
|
100
|
+
readonly metadata?: RuntimeJsonObject;
|
|
101
|
+
}
|
|
102
|
+
export interface PermissionGrant {
|
|
103
|
+
readonly grantId: string;
|
|
104
|
+
readonly capabilityId: RuntimeCapabilityId;
|
|
105
|
+
readonly decision: RuntimeDecision;
|
|
106
|
+
readonly grantedAt: string;
|
|
107
|
+
readonly source: string;
|
|
108
|
+
readonly reason?: string;
|
|
109
|
+
readonly evidenceRefs?: readonly EvidenceRef[];
|
|
110
|
+
readonly metadata?: RuntimeJsonObject;
|
|
111
|
+
}
|
|
112
|
+
export interface PermissionPolicy {
|
|
113
|
+
readonly policyId: string;
|
|
114
|
+
decide(request: PermissionRequest, context: RuntimeExecutionContext): Promise<PermissionDecision> | PermissionDecision;
|
|
115
|
+
}
|
|
116
|
+
export interface HumanApprovalRequest extends PermissionRequest {
|
|
117
|
+
readonly prompt: string;
|
|
118
|
+
readonly defaultDecision?: RuntimeDecision;
|
|
119
|
+
}
|
|
120
|
+
export interface HumanApprovalPort {
|
|
121
|
+
requestApproval(request: HumanApprovalRequest, context: RuntimeExecutionContext): Promise<PermissionDecision> | PermissionDecision;
|
|
122
|
+
}
|
|
123
|
+
export interface PermissionGateway {
|
|
124
|
+
decide(request: PermissionRequest, context: RuntimeExecutionContext): Promise<PermissionDecision> | PermissionDecision;
|
|
125
|
+
createGrant?(decision: PermissionDecision, request: PermissionRequest, context: RuntimeExecutionContext): Promise<PermissionGrant> | PermissionGrant;
|
|
126
|
+
}
|
|
127
|
+
export type HookEventName = 'PreToolUse' | 'PostToolUse' | 'UserPromptSubmit' | 'SessionStart' | 'Stop' | 'SubagentStop' | 'PreCompact';
|
|
128
|
+
export type HookDecision = RuntimeDecision;
|
|
129
|
+
export interface HookInput {
|
|
130
|
+
readonly event: HookEventName;
|
|
131
|
+
readonly toolCall?: RuntimeToolCall;
|
|
132
|
+
readonly toolResult?: RuntimeToolResult;
|
|
133
|
+
readonly metadata?: RuntimeJsonObject;
|
|
134
|
+
}
|
|
135
|
+
export interface HookRecord {
|
|
136
|
+
readonly event: HookEventName;
|
|
137
|
+
readonly hookId: string;
|
|
138
|
+
readonly decision: HookDecision;
|
|
139
|
+
readonly reason?: string;
|
|
140
|
+
readonly startedAt: string;
|
|
141
|
+
readonly completedAt: string;
|
|
142
|
+
readonly exitCode?: number;
|
|
143
|
+
readonly timedOut?: boolean;
|
|
144
|
+
readonly metadata?: RuntimeJsonObject;
|
|
145
|
+
}
|
|
146
|
+
export interface HookRunner {
|
|
147
|
+
run(event: HookEventName, input: HookInput, context: RuntimeExecutionContext): Promise<readonly HookRecord[]> | readonly HookRecord[];
|
|
148
|
+
}
|
|
149
|
+
export interface HookPipeline extends HookRunner {
|
|
150
|
+
}
|
|
151
|
+
export type EvidenceRef = string;
|
|
152
|
+
export interface EvidenceRecord {
|
|
153
|
+
readonly evidenceId?: string;
|
|
154
|
+
readonly kind: string;
|
|
155
|
+
readonly source: string;
|
|
156
|
+
readonly createdAt: string;
|
|
157
|
+
readonly capabilityId?: RuntimeCapabilityId;
|
|
158
|
+
readonly toolCallId?: string;
|
|
159
|
+
readonly message?: string;
|
|
160
|
+
readonly data?: unknown;
|
|
161
|
+
readonly refs?: readonly EvidenceRef[];
|
|
162
|
+
readonly metadata?: RuntimeJsonObject;
|
|
163
|
+
}
|
|
164
|
+
export interface EvidenceBundle {
|
|
165
|
+
readonly records?: readonly EvidenceRecord[];
|
|
166
|
+
readonly refs?: readonly EvidenceRef[];
|
|
167
|
+
readonly metadata?: RuntimeJsonObject;
|
|
168
|
+
}
|
|
169
|
+
export interface EvidenceSink {
|
|
170
|
+
record(record: EvidenceRecord, context: RuntimeExecutionContext): Promise<EvidenceRef> | EvidenceRef;
|
|
171
|
+
}
|
|
172
|
+
export type RuntimeEvent = {
|
|
173
|
+
readonly type: 'tool_call_started';
|
|
174
|
+
readonly call: RuntimeToolCall;
|
|
175
|
+
readonly createdAt: string;
|
|
176
|
+
} | {
|
|
177
|
+
readonly type: 'permission_decided';
|
|
178
|
+
readonly call: RuntimeToolCall;
|
|
179
|
+
readonly decision: PermissionDecision;
|
|
180
|
+
readonly createdAt: string;
|
|
181
|
+
} | {
|
|
182
|
+
readonly type: 'tool_call_completed';
|
|
183
|
+
readonly call: RuntimeToolCall;
|
|
184
|
+
readonly result: RuntimeToolResult;
|
|
185
|
+
readonly createdAt: string;
|
|
186
|
+
} | {
|
|
187
|
+
readonly type: 'evidence_recorded';
|
|
188
|
+
readonly record: EvidenceRecord;
|
|
189
|
+
readonly ref?: EvidenceRef;
|
|
190
|
+
readonly createdAt: string;
|
|
191
|
+
} | {
|
|
192
|
+
readonly type: 'runtime_log';
|
|
193
|
+
readonly level: 'debug' | 'info' | 'warn' | 'error';
|
|
194
|
+
readonly message: string;
|
|
195
|
+
readonly createdAt: string;
|
|
196
|
+
readonly metadata?: RuntimeJsonObject;
|
|
197
|
+
};
|
|
198
|
+
export interface RuntimeEventSink {
|
|
199
|
+
emit(event: RuntimeEvent, context: RuntimeExecutionContext): Promise<void> | void;
|
|
200
|
+
}
|
|
201
|
+
export interface RuntimeToolDefinition {
|
|
202
|
+
readonly name: string;
|
|
203
|
+
readonly capabilityId: RuntimeCapabilityId;
|
|
204
|
+
readonly description?: string;
|
|
205
|
+
readonly inputSchema?: unknown;
|
|
206
|
+
readonly modeScopes?: readonly RuntimeModeScope[];
|
|
207
|
+
readonly metadata?: RuntimeJsonObject;
|
|
208
|
+
}
|
|
209
|
+
export interface RuntimeProjection {
|
|
210
|
+
readonly tools: readonly RuntimeToolDefinition[];
|
|
211
|
+
readonly mode?: RuntimeModeScope;
|
|
212
|
+
readonly createdAt?: string;
|
|
213
|
+
readonly metadata?: RuntimeJsonObject;
|
|
214
|
+
}
|
|
215
|
+
export interface ProjectionMaterializer<TToolSchema = unknown> {
|
|
216
|
+
readonly providerFamily: string;
|
|
217
|
+
materialize(projection: RuntimeProjection): readonly TToolSchema[];
|
|
218
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RuntimeDecision } from './contracts.ts';
|
|
2
|
+
export declare function compareRuntimeDecision(a: RuntimeDecision, b: RuntimeDecision): number;
|
|
3
|
+
export declare function mostRestrictiveDecision(decisions: readonly (RuntimeDecision | null | undefined)[]): RuntimeDecision;
|
|
4
|
+
export declare function isDecisionAtLeast(decision: RuntimeDecision, minimum: RuntimeDecision): boolean;
|
package/dist/decision.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const DECISION_RANK = {
|
|
2
|
+
allow: 0,
|
|
3
|
+
ask: 1,
|
|
4
|
+
deny: 2,
|
|
5
|
+
};
|
|
6
|
+
export function compareRuntimeDecision(a, b) {
|
|
7
|
+
return DECISION_RANK[a] - DECISION_RANK[b];
|
|
8
|
+
}
|
|
9
|
+
export function mostRestrictiveDecision(decisions) {
|
|
10
|
+
let finalDecision = 'allow';
|
|
11
|
+
for (const decision of decisions) {
|
|
12
|
+
if (!decision) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (DECISION_RANK[decision] > DECISION_RANK[finalDecision]) {
|
|
16
|
+
finalDecision = decision;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return finalDecision;
|
|
20
|
+
}
|
|
21
|
+
export function isDecisionAtLeast(decision, minimum) {
|
|
22
|
+
return DECISION_RANK[decision] >= DECISION_RANK[minimum];
|
|
23
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { EvidenceRecord, EvidenceRef, RuntimeDecision, RuntimeJsonObject } from './contracts.ts';
|
|
2
|
+
export type EvidenceRedactor = (record: EvidenceRecord) => EvidenceRecord;
|
|
3
|
+
export type RuntimeEvidenceObject = Readonly<Record<string, unknown>>;
|
|
4
|
+
export interface CreateEvidenceBundleOptions {
|
|
5
|
+
readonly evidenceId?: string;
|
|
6
|
+
readonly toolCallId?: string;
|
|
7
|
+
readonly summary?: string;
|
|
8
|
+
readonly locale?: string;
|
|
9
|
+
readonly returnedToCloud?: boolean;
|
|
10
|
+
readonly dataLevel?: string;
|
|
11
|
+
readonly redactions?: readonly string[];
|
|
12
|
+
readonly artifactRefs?: readonly EvidenceRef[];
|
|
13
|
+
readonly records?: readonly EvidenceRecord[];
|
|
14
|
+
readonly refs?: readonly EvidenceRef[];
|
|
15
|
+
readonly metadata?: RuntimeJsonObject;
|
|
16
|
+
}
|
|
17
|
+
export interface AppendEvidenceRecordsOptions {
|
|
18
|
+
readonly refs?: readonly EvidenceRef[];
|
|
19
|
+
readonly metadata?: RuntimeJsonObject;
|
|
20
|
+
}
|
|
21
|
+
export interface HookEvidenceRecordSource {
|
|
22
|
+
readonly id?: string;
|
|
23
|
+
readonly hookId?: string;
|
|
24
|
+
readonly event?: string;
|
|
25
|
+
readonly decision?: RuntimeDecision;
|
|
26
|
+
readonly reason?: string;
|
|
27
|
+
readonly outcome?: string;
|
|
28
|
+
readonly durationMs?: number;
|
|
29
|
+
readonly exitCode?: number | null;
|
|
30
|
+
}
|
|
31
|
+
export interface HookEvidenceRecord {
|
|
32
|
+
readonly id?: string;
|
|
33
|
+
readonly event?: string;
|
|
34
|
+
readonly decision?: RuntimeDecision;
|
|
35
|
+
readonly reason?: string;
|
|
36
|
+
readonly outcome?: string;
|
|
37
|
+
readonly durationMs?: number;
|
|
38
|
+
readonly exitCode?: number | null;
|
|
39
|
+
}
|
|
40
|
+
export interface AppendHookEvidenceOptions {
|
|
41
|
+
readonly recordedAt?: string;
|
|
42
|
+
readonly now?: () => string;
|
|
43
|
+
}
|
|
44
|
+
export declare function createEvidenceBundle(options?: CreateEvidenceBundleOptions): RuntimeEvidenceObject;
|
|
45
|
+
export declare function applyEvidenceRedactors(record: EvidenceRecord, redactors?: readonly EvidenceRedactor[]): EvidenceRecord;
|
|
46
|
+
export declare function appendEvidenceRecords<T extends {
|
|
47
|
+
readonly evidence?: unknown;
|
|
48
|
+
}>(result: T, records?: readonly EvidenceRecord[], options?: AppendEvidenceRecordsOptions): T;
|
|
49
|
+
export declare function sanitizeHookEvidenceRecord(record: HookEvidenceRecordSource): HookEvidenceRecord;
|
|
50
|
+
export declare function appendHookEvidence<T extends {
|
|
51
|
+
readonly evidence?: unknown;
|
|
52
|
+
}>(result: T, hookRecords?: readonly HookEvidenceRecordSource[], finalDecision?: RuntimeDecision | undefined, options?: AppendHookEvidenceOptions): T;
|
package/dist/evidence.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
function isEvidenceObject(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
function asReadonlyArray(value) {
|
|
5
|
+
return Array.isArray(value) ? value : [];
|
|
6
|
+
}
|
|
7
|
+
export function createEvidenceBundle(options = {}) {
|
|
8
|
+
return {
|
|
9
|
+
evidenceId: options.evidenceId,
|
|
10
|
+
toolCallId: options.toolCallId,
|
|
11
|
+
summary: options.summary,
|
|
12
|
+
locale: options.locale,
|
|
13
|
+
returnedToCloud: options.returnedToCloud ?? false,
|
|
14
|
+
dataLevel: options.dataLevel ?? 'D0_public',
|
|
15
|
+
redactions: [...asReadonlyArray(options.redactions)],
|
|
16
|
+
artifactRefs: [...asReadonlyArray(options.artifactRefs)],
|
|
17
|
+
...(options.records ? { records: [...options.records] } : {}),
|
|
18
|
+
...(options.refs ? { refs: [...options.refs] } : {}),
|
|
19
|
+
...(options.metadata ? { metadata: options.metadata } : {}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function applyEvidenceRedactors(record, redactors = []) {
|
|
23
|
+
return redactors.reduce((current, redact) => redact(current), record);
|
|
24
|
+
}
|
|
25
|
+
export function appendEvidenceRecords(result, records = [], options = {}) {
|
|
26
|
+
if (!result || !Array.isArray(records) || records.length === 0)
|
|
27
|
+
return result;
|
|
28
|
+
const existingEvidence = isEvidenceObject(result.evidence) ? result.evidence : {};
|
|
29
|
+
const existingRecords = asReadonlyArray(existingEvidence.records);
|
|
30
|
+
const nextEvidence = {
|
|
31
|
+
...existingEvidence,
|
|
32
|
+
records: [
|
|
33
|
+
...existingRecords,
|
|
34
|
+
...records,
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
if (options.refs && options.refs.length > 0) {
|
|
38
|
+
nextEvidence.refs = [
|
|
39
|
+
...asReadonlyArray(existingEvidence.refs),
|
|
40
|
+
...options.refs,
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
if (options.metadata) {
|
|
44
|
+
nextEvidence.metadata = {
|
|
45
|
+
...(isEvidenceObject(existingEvidence.metadata) ? existingEvidence.metadata : {}),
|
|
46
|
+
...options.metadata,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
...result,
|
|
51
|
+
evidence: nextEvidence,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function sanitizeHookEvidenceRecord(record) {
|
|
55
|
+
return {
|
|
56
|
+
id: record.id ?? record.hookId,
|
|
57
|
+
event: record.event,
|
|
58
|
+
decision: record.decision,
|
|
59
|
+
reason: record.reason,
|
|
60
|
+
outcome: record.outcome,
|
|
61
|
+
durationMs: record.durationMs,
|
|
62
|
+
exitCode: record.exitCode,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function appendHookEvidence(result, hookRecords = [], finalDecision = undefined, options = {}) {
|
|
66
|
+
if (!result || !Array.isArray(hookRecords) || hookRecords.length === 0)
|
|
67
|
+
return result;
|
|
68
|
+
const existingEvidence = isEvidenceObject(result.evidence) ? result.evidence : {};
|
|
69
|
+
const existingHooks = asReadonlyArray(existingEvidence.hooks);
|
|
70
|
+
const recordedAt = options.recordedAt ?? options.now?.();
|
|
71
|
+
const nextEvidence = {
|
|
72
|
+
...existingEvidence,
|
|
73
|
+
hooks: [
|
|
74
|
+
...existingHooks,
|
|
75
|
+
...hookRecords.map(sanitizeHookEvidenceRecord),
|
|
76
|
+
],
|
|
77
|
+
hookFinalDecision: finalDecision ?? existingEvidence.hookFinalDecision,
|
|
78
|
+
};
|
|
79
|
+
if (recordedAt) {
|
|
80
|
+
nextEvidence.hookRecordedAt = recordedAt;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
...result,
|
|
84
|
+
evidence: nextEvidence,
|
|
85
|
+
};
|
|
86
|
+
}
|
package/dist/hooks.d.ts
ADDED
package/dist/hooks.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './contracts.ts';
|
|
2
|
+
export * from './decision.ts';
|
|
3
|
+
export * from './evidence.ts';
|
|
4
|
+
export * from './hooks.ts';
|
|
5
|
+
export * from './permission.ts';
|
|
6
|
+
export * from './capability-registry.ts';
|
|
7
|
+
export * from './projection.ts';
|
|
8
|
+
export * from './projection-materializers.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./contracts.js";
|
|
2
|
+
export * from "./decision.js";
|
|
3
|
+
export * from "./evidence.js";
|
|
4
|
+
export * from "./hooks.js";
|
|
5
|
+
export * from "./permission.js";
|
|
6
|
+
export * from "./capability-registry.js";
|
|
7
|
+
export * from "./projection.js";
|
|
8
|
+
export * from "./projection-materializers.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EvidenceRef, PermissionDecision, PermissionGrant, PermissionRequest, RuntimeDecision, RuntimeJsonObject } from './contracts.ts';
|
|
2
|
+
export type PermissionDecisionLike = RuntimeDecision | PermissionDecision | null | undefined;
|
|
3
|
+
export interface MergePermissionDecisionsOptions {
|
|
4
|
+
readonly defaultSource?: string;
|
|
5
|
+
readonly defaultReason?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CreatePermissionGrantDraftOptions {
|
|
8
|
+
readonly grantId: string;
|
|
9
|
+
readonly grantedAt: string;
|
|
10
|
+
readonly evidenceRefs?: readonly EvidenceRef[];
|
|
11
|
+
readonly metadata?: RuntimeJsonObject;
|
|
12
|
+
}
|
|
13
|
+
export declare function mostRestrictivePermissionDecision(decisions?: readonly PermissionDecisionLike[]): RuntimeDecision;
|
|
14
|
+
export declare function mergePermissionDecisions(decisions?: readonly (PermissionDecision | null | undefined)[], options?: MergePermissionDecisionsOptions): PermissionDecision;
|
|
15
|
+
export declare function isPermissionAllowed(decision: PermissionDecisionLike): boolean;
|
|
16
|
+
export declare function isPermissionAsking(decision: PermissionDecisionLike): boolean;
|
|
17
|
+
export declare function isPermissionDenied(decision: PermissionDecisionLike): boolean;
|
|
18
|
+
export declare function createPermissionGrantDraft(decision: PermissionDecision, request: Pick<PermissionRequest, 'capabilityId'>, options: CreatePermissionGrantDraftOptions): PermissionGrant;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { mostRestrictiveDecision } from "./decision.js";
|
|
2
|
+
function decisionValue(decision) {
|
|
3
|
+
if (!decision) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
if (typeof decision === 'string') {
|
|
7
|
+
return decision;
|
|
8
|
+
}
|
|
9
|
+
return decision.decision;
|
|
10
|
+
}
|
|
11
|
+
export function mostRestrictivePermissionDecision(decisions = []) {
|
|
12
|
+
return mostRestrictiveDecision(decisions.map(decisionValue));
|
|
13
|
+
}
|
|
14
|
+
export function mergePermissionDecisions(decisions = [], options = {}) {
|
|
15
|
+
const validDecisions = decisions.filter((decision) => Boolean(decision));
|
|
16
|
+
const finalDecision = mostRestrictivePermissionDecision(validDecisions);
|
|
17
|
+
const sourceDecision = validDecisions.find((decision) => decision.decision === finalDecision);
|
|
18
|
+
const reason = sourceDecision?.reason ?? options.defaultReason;
|
|
19
|
+
const metadata = sourceDecision?.metadata;
|
|
20
|
+
return {
|
|
21
|
+
decision: finalDecision,
|
|
22
|
+
source: sourceDecision?.source ?? options.defaultSource ?? 'runtime_core_default',
|
|
23
|
+
...(reason !== undefined ? { reason } : {}),
|
|
24
|
+
...(metadata !== undefined ? { metadata } : {}),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function isPermissionAllowed(decision) {
|
|
28
|
+
return decisionValue(decision) === 'allow';
|
|
29
|
+
}
|
|
30
|
+
export function isPermissionAsking(decision) {
|
|
31
|
+
return decisionValue(decision) === 'ask';
|
|
32
|
+
}
|
|
33
|
+
export function isPermissionDenied(decision) {
|
|
34
|
+
return decisionValue(decision) === 'deny';
|
|
35
|
+
}
|
|
36
|
+
export function createPermissionGrantDraft(decision, request, options) {
|
|
37
|
+
return {
|
|
38
|
+
grantId: options.grantId,
|
|
39
|
+
capabilityId: request.capabilityId,
|
|
40
|
+
decision: decision.decision,
|
|
41
|
+
grantedAt: options.grantedAt,
|
|
42
|
+
source: decision.source,
|
|
43
|
+
reason: decision.reason,
|
|
44
|
+
evidenceRefs: options.evidenceRefs,
|
|
45
|
+
metadata: {
|
|
46
|
+
...decision.metadata,
|
|
47
|
+
...options.metadata,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ProjectionMaterializer, RuntimeProjection } from './contracts.ts';
|
|
2
|
+
export interface OpenAIFunctionToolSchema {
|
|
3
|
+
readonly type: 'function';
|
|
4
|
+
readonly function: {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly description: string;
|
|
7
|
+
readonly parameters: unknown;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface AnthropicToolSchema {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly description: string;
|
|
13
|
+
readonly input_schema: unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare function materializeOpenAITools(projection: RuntimeProjection): readonly OpenAIFunctionToolSchema[];
|
|
16
|
+
export declare function materializeAnthropicTools(projection: RuntimeProjection): readonly AnthropicToolSchema[];
|
|
17
|
+
export declare const openAIProjectionMaterializer: ProjectionMaterializer<OpenAIFunctionToolSchema>;
|
|
18
|
+
export declare const anthropicProjectionMaterializer: ProjectionMaterializer<AnthropicToolSchema>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function toolDescription(tool) {
|
|
2
|
+
return tool.description ?? '';
|
|
3
|
+
}
|
|
4
|
+
function toolInputSchema(tool) {
|
|
5
|
+
return tool.inputSchema ?? {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {},
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export function materializeOpenAITools(projection) {
|
|
11
|
+
return projection.tools.map((tool) => ({
|
|
12
|
+
type: 'function',
|
|
13
|
+
function: {
|
|
14
|
+
name: tool.name,
|
|
15
|
+
description: toolDescription(tool),
|
|
16
|
+
parameters: toolInputSchema(tool),
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
export function materializeAnthropicTools(projection) {
|
|
21
|
+
return projection.tools.map((tool) => ({
|
|
22
|
+
name: tool.name,
|
|
23
|
+
description: toolDescription(tool),
|
|
24
|
+
input_schema: toolInputSchema(tool),
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
export const openAIProjectionMaterializer = {
|
|
28
|
+
providerFamily: 'openai',
|
|
29
|
+
materialize: materializeOpenAITools,
|
|
30
|
+
};
|
|
31
|
+
export const anthropicProjectionMaterializer = {
|
|
32
|
+
providerFamily: 'anthropic',
|
|
33
|
+
materialize: materializeAnthropicTools,
|
|
34
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RuntimeJsonObject, RuntimeModeScope, RuntimeProjection, RuntimeToolDefinition } from './contracts.ts';
|
|
2
|
+
export type RuntimeProjectionErrorCode = 'invalid_tool_definition' | 'duplicate_tool_name';
|
|
3
|
+
export declare class RuntimeProjectionError extends Error {
|
|
4
|
+
readonly code: RuntimeProjectionErrorCode;
|
|
5
|
+
constructor(message: string, code: RuntimeProjectionErrorCode);
|
|
6
|
+
}
|
|
7
|
+
export interface CreateRuntimeProjectionOptions {
|
|
8
|
+
readonly mode?: RuntimeModeScope | null;
|
|
9
|
+
readonly createdAt?: string;
|
|
10
|
+
readonly now?: () => string;
|
|
11
|
+
readonly metadata?: RuntimeJsonObject;
|
|
12
|
+
}
|
|
13
|
+
export declare function isRuntimeToolAvailableInMode(tool: RuntimeToolDefinition, mode?: RuntimeModeScope | null): boolean;
|
|
14
|
+
export declare function filterRuntimeToolsForMode(tools: readonly RuntimeToolDefinition[], mode?: RuntimeModeScope | null): readonly RuntimeToolDefinition[];
|
|
15
|
+
export declare function createRuntimeProjection(tools: readonly RuntimeToolDefinition[], options?: CreateRuntimeProjectionOptions): RuntimeProjection;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export class RuntimeProjectionError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(message, code) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'RuntimeProjectionError';
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function assertToolDefinition(tool) {
|
|
10
|
+
if (!tool || typeof tool !== 'object') {
|
|
11
|
+
throw new RuntimeProjectionError('Runtime tool definition must be an object.', 'invalid_tool_definition');
|
|
12
|
+
}
|
|
13
|
+
if (typeof tool.name !== 'string' || tool.name.trim().length === 0) {
|
|
14
|
+
throw new RuntimeProjectionError('Runtime tool definition must declare a non-empty name.', 'invalid_tool_definition');
|
|
15
|
+
}
|
|
16
|
+
if (typeof tool.capabilityId !== 'string' || tool.capabilityId.trim().length === 0) {
|
|
17
|
+
throw new RuntimeProjectionError(`Runtime tool definition ${tool.name} must declare a non-empty capabilityId.`, 'invalid_tool_definition');
|
|
18
|
+
}
|
|
19
|
+
if (tool.description !== undefined && typeof tool.description !== 'string') {
|
|
20
|
+
throw new RuntimeProjectionError(`Runtime tool definition ${tool.name} must use a string description.`, 'invalid_tool_definition');
|
|
21
|
+
}
|
|
22
|
+
if (tool.modeScopes !== undefined
|
|
23
|
+
&& (!Array.isArray(tool.modeScopes)
|
|
24
|
+
|| tool.modeScopes.some((mode) => typeof mode !== 'string' || mode.trim().length === 0))) {
|
|
25
|
+
throw new RuntimeProjectionError(`Runtime tool definition ${tool.name} must use non-empty string mode scopes.`, 'invalid_tool_definition');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function freezeToolDefinition(tool) {
|
|
29
|
+
const modeScopes = tool.modeScopes === undefined
|
|
30
|
+
? undefined
|
|
31
|
+
: Object.freeze([...tool.modeScopes]);
|
|
32
|
+
const metadata = tool.metadata === undefined
|
|
33
|
+
? undefined
|
|
34
|
+
: Object.freeze({ ...tool.metadata });
|
|
35
|
+
return Object.freeze({
|
|
36
|
+
...tool,
|
|
37
|
+
...(modeScopes === undefined ? {} : { modeScopes }),
|
|
38
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export function isRuntimeToolAvailableInMode(tool, mode) {
|
|
42
|
+
if (mode == null)
|
|
43
|
+
return true;
|
|
44
|
+
const modeScopes = tool.modeScopes;
|
|
45
|
+
if (!Array.isArray(modeScopes) || modeScopes.length === 0) {
|
|
46
|
+
return mode !== 'explorer';
|
|
47
|
+
}
|
|
48
|
+
return modeScopes.includes(mode);
|
|
49
|
+
}
|
|
50
|
+
export function filterRuntimeToolsForMode(tools, mode) {
|
|
51
|
+
return tools.filter((tool) => isRuntimeToolAvailableInMode(tool, mode));
|
|
52
|
+
}
|
|
53
|
+
export function createRuntimeProjection(tools, options = {}) {
|
|
54
|
+
if (!Array.isArray(tools)) {
|
|
55
|
+
throw new RuntimeProjectionError('Runtime projection requires an array of tool definitions.', 'invalid_tool_definition');
|
|
56
|
+
}
|
|
57
|
+
const toolNames = new Set();
|
|
58
|
+
const normalizedTools = tools.map((tool) => {
|
|
59
|
+
assertToolDefinition(tool);
|
|
60
|
+
if (toolNames.has(tool.name)) {
|
|
61
|
+
throw new RuntimeProjectionError(`Duplicate runtime tool definition: ${tool.name}`, 'duplicate_tool_name');
|
|
62
|
+
}
|
|
63
|
+
toolNames.add(tool.name);
|
|
64
|
+
return freezeToolDefinition(tool);
|
|
65
|
+
});
|
|
66
|
+
const projectedTools = Object.freeze([
|
|
67
|
+
...filterRuntimeToolsForMode(normalizedTools, options.mode),
|
|
68
|
+
]);
|
|
69
|
+
const metadata = options.metadata === undefined
|
|
70
|
+
? undefined
|
|
71
|
+
: Object.freeze({ ...options.metadata });
|
|
72
|
+
return Object.freeze({
|
|
73
|
+
tools: projectedTools,
|
|
74
|
+
...(options.mode == null ? {} : { mode: options.mode }),
|
|
75
|
+
createdAt: options.createdAt ?? options.now?.() ?? new Date().toISOString(),
|
|
76
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
77
|
+
});
|
|
78
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peer-agent/runtime-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Host-neutral capability, permission, projection, and Evidence primitives for Peer Agent runtimes.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=20"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/yinLiangDream/Peer-Agent.git",
|
|
14
|
+
"directory": "packages/runtime-core"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/yinLiangDream/Peer-Agent#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/yinLiangDream/Peer-Agent/issues"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "^5.9.3"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -p tsconfig.build.json",
|
|
40
|
+
"test": "node --test src/*.test.ts",
|
|
41
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
42
|
+
}
|
|
43
|
+
}
|