@peer-agent/runtime-core 0.0.1-beta.43
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 +26 -0
- package/dist/capability-registry.d.ts +15 -0
- package/dist/capability-registry.js +88 -0
- package/dist/compaction-progress.d.ts +51 -0
- package/dist/compaction-progress.js +83 -0
- package/dist/context-accounting-lifecycle.d.ts +41 -0
- package/dist/context-accounting-lifecycle.js +90 -0
- package/dist/context-accounting-pipeline.d.ts +98 -0
- package/dist/context-accounting-pipeline.js +561 -0
- package/dist/context-compaction.d.ts +70 -0
- package/dist/context-compaction.js +192 -0
- package/dist/context-projection-lifecycle.d.ts +32 -0
- package/dist/context-projection-lifecycle.js +65 -0
- package/dist/context-projection.d.ts +74 -0
- package/dist/context-projection.js +183 -0
- package/dist/contracts.d.ts +218 -0
- package/dist/contracts.js +1 -0
- package/dist/conversation-history-projector.d.ts +52 -0
- package/dist/conversation-history-projector.js +472 -0
- package/dist/decision.d.ts +4 -0
- package/dist/decision.js +23 -0
- package/dist/evidence.d.ts +64 -0
- package/dist/evidence.js +127 -0
- package/dist/hooks.d.ts +5 -0
- package/dist/hooks.js +4 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -0
- package/dist/local-tool-contracts.d.ts +60 -0
- package/dist/local-tool-contracts.js +64 -0
- package/dist/microcompact.d.ts +38 -0
- package/dist/microcompact.js +354 -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/dist/runtime-usage-accounting.d.ts +19 -0
- package/dist/runtime-usage-accounting.js +79 -0
- package/package.json +47 -0
|
@@ -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,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical persisted-conversation -> active provider history projection.
|
|
3
|
+
*
|
|
4
|
+
* Desktop send, Desktop restore and CLI/TUI restore must all cross this seam.
|
|
5
|
+
* Provider adapters may lower the camelCase tool fields to their wire format,
|
|
6
|
+
* but must not reinterpret persisted segments.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CANONICAL_HISTORY_PROJECTOR_VERSION = 1;
|
|
9
|
+
export type CanonicalHistoryContentPart = {
|
|
10
|
+
readonly type: 'text';
|
|
11
|
+
readonly text: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: 'image_url';
|
|
14
|
+
readonly image_url: {
|
|
15
|
+
readonly url: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export interface CanonicalHistoryToolCall {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly arguments: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CanonicalHistoryMessage {
|
|
24
|
+
readonly role: 'user' | 'assistant' | 'tool';
|
|
25
|
+
readonly content: string | readonly CanonicalHistoryContentPart[] | null;
|
|
26
|
+
readonly name?: string;
|
|
27
|
+
readonly toolCallId?: string;
|
|
28
|
+
readonly toolCalls?: readonly CanonicalHistoryToolCall[];
|
|
29
|
+
}
|
|
30
|
+
export interface CanonicalHistoryContinuity {
|
|
31
|
+
readonly summary: string;
|
|
32
|
+
readonly sourceMessageId: string;
|
|
33
|
+
readonly method: string;
|
|
34
|
+
readonly originalMessageCount: number | null;
|
|
35
|
+
readonly beforeTokens: number | null;
|
|
36
|
+
readonly afterTokens: number | null;
|
|
37
|
+
}
|
|
38
|
+
export interface CanonicalConversationHistory {
|
|
39
|
+
readonly messages: readonly CanonicalHistoryMessage[];
|
|
40
|
+
readonly continuityContext?: string;
|
|
41
|
+
readonly continuity?: CanonicalHistoryContinuity;
|
|
42
|
+
readonly compactionBoundaryIndex: number;
|
|
43
|
+
readonly projectorVersion: number;
|
|
44
|
+
readonly historyFingerprint: string;
|
|
45
|
+
}
|
|
46
|
+
export declare function sanitizeCanonicalAssistantHistoryText(content: string): string;
|
|
47
|
+
export declare function formatCanonicalHistoricalLocalRecord(input: {
|
|
48
|
+
readonly tool?: unknown;
|
|
49
|
+
readonly args?: unknown;
|
|
50
|
+
readonly result?: unknown;
|
|
51
|
+
}): string;
|
|
52
|
+
export declare function projectConversationHistory(values: readonly unknown[]): CanonicalConversationHistory;
|