@arnilo/prism 0.2.4 → 0.2.6
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/CHANGELOG.md +10 -0
- package/dist/agent-session/create-agent.d.ts +6 -0
- package/dist/agent-session/create-agent.js +13 -0
- package/dist/agent-session/event-subscriber.d.ts +17 -0
- package/dist/agent-session/event-subscriber.js +68 -0
- package/dist/agent-session/helpers.d.ts +44 -0
- package/dist/agent-session/helpers.js +194 -0
- package/dist/agent-session/session.d.ts +101 -0
- package/dist/agent-session/session.js +1568 -0
- package/dist/agent-session.d.ts +6 -105
- package/dist/agent-session.js +6 -1833
- package/dist/contracts-core/agent.d.ts +257 -0
- package/dist/contracts-core/agent.js +5 -0
- package/dist/contracts-core/compaction.d.ts +72 -0
- package/dist/contracts-core/compaction.js +2 -0
- package/dist/contracts-core/content.d.ts +116 -0
- package/dist/contracts-core/content.js +2 -0
- package/dist/contracts-core/extensions.d.ts +163 -0
- package/dist/contracts-core/extensions.js +2 -0
- package/dist/contracts-core/loop.d.ts +98 -0
- package/dist/contracts-core/loop.js +2 -0
- package/dist/contracts-core/persistence.d.ts +366 -0
- package/dist/contracts-core/persistence.js +9 -0
- package/dist/contracts-core/provider.d.ts +97 -0
- package/dist/contracts-core/provider.js +2 -0
- package/dist/contracts-core/resources.d.ts +44 -0
- package/dist/contracts-core/resources.js +7 -0
- package/dist/contracts-core/run-limits.d.ts +81 -0
- package/dist/contracts-core/run-limits.js +2 -0
- package/dist/contracts-core/session.d.ts +187 -0
- package/dist/contracts-core/session.js +131 -0
- package/dist/contracts-core.d.ts +13 -1425
- package/dist/contracts-core.js +10 -138
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/docs/0.1.0-readiness.md +10 -10
- package/docs/acp.md +2 -0
- package/docs/browser-automation.md +1 -1
- package/docs/coding-agent-tools.md +5 -4
- package/docs/coding-review-and-diagnostics.md +76 -0
- package/docs/coding-security.md +2 -0
- package/docs/coding-workspaces.md +69 -0
- package/docs/forge-integration.md +6 -0
- package/docs/index.md +5 -5
- package/docs/indexed-code-search.md +82 -0
- package/docs/language-intelligence.md +15 -0
- package/docs/migration.md +20 -0
- package/docs/process-sessions.md +58 -3
- package/docs/release-and-install.md +71 -3
- package/docs/work-artifacts-and-review.md +4 -0
- package/package.json +2 -2
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/** Contracts-core agent family (0.2.5 plan 025 Task 1 split).
|
|
2
|
+
* Moved verbatim from contracts-core.ts; public surface unchanged behind the barrel. */
|
|
3
|
+
import type { AgentRunStateOptions, AgentSession } from "../contracts-run-state.js";
|
|
4
|
+
import type { ContributionRegistries } from "../contributions.js";
|
|
5
|
+
import type { InputAssemblyLayout, RunLedger, ToolDefinition, ToolEffectStore, ToolRegistry } from "../contracts-protocol.js";
|
|
6
|
+
import type { MiddlewareRegistry } from "../middleware.js";
|
|
7
|
+
import type { PermissionPolicy, TrustPolicy } from "../security.js";
|
|
8
|
+
import type { SecretRedactor } from "../redaction.js";
|
|
9
|
+
import type { ToolValidator } from "../tools.js";
|
|
10
|
+
import type { AIProvider, ProviderRequestOptions, ProviderResolver } from "./provider.js";
|
|
11
|
+
import type { AgentLoopOptions, AgentLoopStrategy } from "./loop.js";
|
|
12
|
+
import type { CompactionOptions, RetryOptions } from "./compaction.js";
|
|
13
|
+
import type { ContentBlock, ErrorInfo, JsonObject, Message, ModelConfig } from "./content.js";
|
|
14
|
+
import type { ProviderRequestPolicy, SystemPromptConfig } from "./extensions.js";
|
|
15
|
+
import type { Guardrails, RunLimits } from "./run-limits.js";
|
|
16
|
+
import type { OwnershipScope } from "./persistence.js";
|
|
17
|
+
import type { ResourceLoader } from "./resources.js";
|
|
18
|
+
import type { SessionStore } from "./session.js";
|
|
19
|
+
export interface AgentDefinition {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly description?: string;
|
|
22
|
+
/** Direct model config, or a model id resolved from `registries.models`. */
|
|
23
|
+
readonly model?: ModelConfig | string;
|
|
24
|
+
/** Tool names to activate from the active tool registry / `registries.tools`. */
|
|
25
|
+
readonly tools?: readonly string[];
|
|
26
|
+
/** Skill names resolved through `resolveActiveSkills()`; `toolNames` enforcement applies. */
|
|
27
|
+
readonly skills?: readonly string[];
|
|
28
|
+
/** Context provider names from `registries.contextProviders`. */
|
|
29
|
+
readonly context?: readonly string[];
|
|
30
|
+
readonly systemPrompt?: SystemPromptConfig;
|
|
31
|
+
readonly instructions?: string;
|
|
32
|
+
readonly loop?: AgentLoopStrategy | AgentLoopOptions;
|
|
33
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
34
|
+
/** Optional escape hatch. When present, overrides declarative resolution. */
|
|
35
|
+
create?(config?: AgentConfig): Promise<Agent> | Agent;
|
|
36
|
+
}
|
|
37
|
+
/** Input to {@link resolveAgentDefinition}. All fields are optional; the host
|
|
38
|
+
* controls scope by which registries it passes. */
|
|
39
|
+
export interface AgentDefinitionResolutionContext {
|
|
40
|
+
readonly registries?: ContributionRegistries;
|
|
41
|
+
readonly providerSource?: ProviderResolver;
|
|
42
|
+
readonly tools?: ToolRegistry | readonly ToolDefinition[];
|
|
43
|
+
readonly skillsRegistry?: SkillRegistry;
|
|
44
|
+
/** Migration-only: omitted `tools`/`skills` activate every in-scope tool/skill. Defaults to fail-closed. */
|
|
45
|
+
readonly activateAllCapabilities?: true;
|
|
46
|
+
readonly overrides?: Partial<AgentConfig>;
|
|
47
|
+
}
|
|
48
|
+
export interface AgentConfig {
|
|
49
|
+
readonly id?: string;
|
|
50
|
+
readonly name?: string;
|
|
51
|
+
readonly instructions?: string;
|
|
52
|
+
readonly model: ModelConfig;
|
|
53
|
+
readonly provider?: AIProvider;
|
|
54
|
+
readonly providerSource?: ProviderResolver;
|
|
55
|
+
readonly tools?: ToolRegistry | readonly ToolDefinition[];
|
|
56
|
+
readonly context?: readonly ContextProvider[];
|
|
57
|
+
readonly skills?: SkillRegistry | readonly Skill[];
|
|
58
|
+
/** Migration opt-in: activate every registry skill by default when run options do not narrow activation. */
|
|
59
|
+
readonly activateAllSkills?: true;
|
|
60
|
+
/** Progressive: catalog (name+description) unless loaded; eager: full instructions every turn. Default progressive. */
|
|
61
|
+
readonly skillsDisclosure?: import("../skill-disclosure.js").SkillsDisclosure;
|
|
62
|
+
/** Opt-in projection-only fold for aged large tool results in provider view; store untouched. */
|
|
63
|
+
readonly toolResultFold?: import("../tool-result-fold.js").ToolResultFoldOptions;
|
|
64
|
+
readonly inputBuilder?: InputBuilder;
|
|
65
|
+
readonly promptBuilder?: PromptBuilder;
|
|
66
|
+
readonly middleware?: MiddlewareRegistry;
|
|
67
|
+
readonly resourceLoader?: ResourceLoader;
|
|
68
|
+
readonly store?: SessionStore;
|
|
69
|
+
readonly permission?: PermissionPolicy;
|
|
70
|
+
/** Optional trust check for tool and resource targets. */
|
|
71
|
+
readonly trust?: TrustPolicy;
|
|
72
|
+
readonly providerOptions?: ProviderRequestOptions;
|
|
73
|
+
readonly providerRequestPolicies?: ProviderRequestPolicy | readonly ProviderRequestPolicy[];
|
|
74
|
+
readonly systemPrompt?: SystemPromptConfig;
|
|
75
|
+
readonly redactor?: SecretRedactor;
|
|
76
|
+
readonly runLedger?: RunLedger;
|
|
77
|
+
/** Optional durable recovery store. */
|
|
78
|
+
readonly effectStore?: ToolEffectStore;
|
|
79
|
+
readonly ownership?: OwnershipScope;
|
|
80
|
+
/** Host-verified identity default for sessions created from this agent. */
|
|
81
|
+
readonly identity?: import("../identity.js").AgentIdentity;
|
|
82
|
+
readonly idempotencyKey?: string;
|
|
83
|
+
readonly compaction?: false | CompactionOptions;
|
|
84
|
+
readonly retry?: false | RetryOptions;
|
|
85
|
+
/** Agent-wide ceilings; per-run limits may only narrow these values. */
|
|
86
|
+
readonly limits?: RunLimits;
|
|
87
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
88
|
+
readonly validator?: ToolValidator;
|
|
89
|
+
readonly instructionInjectors?: readonly InstructionInjector[];
|
|
90
|
+
readonly inputLayout?: InputAssemblyLayout;
|
|
91
|
+
readonly loop?: AgentLoopStrategy | AgentLoopOptions;
|
|
92
|
+
readonly guardrails?: Guardrails;
|
|
93
|
+
/** Opt-in durable interruption/checkpointing default for this agent. */
|
|
94
|
+
readonly runState?: AgentRunStateOptions;
|
|
95
|
+
/** Internal marker set by createSecureAgent(); makes security defaults immutable per run. */
|
|
96
|
+
readonly secure?: true;
|
|
97
|
+
}
|
|
98
|
+
/** Opt-in fail-closed composition over the normal explicit AgentConfig API. */
|
|
99
|
+
export interface SecureAgentOptions extends Omit<AgentConfig, "tools" | "validator" | "redactor" | "permission" | "trust" | "ownership" | "identity" | "limits" | "runState" | "secure"> {
|
|
100
|
+
readonly id: string;
|
|
101
|
+
readonly tools: readonly ToolDefinition[];
|
|
102
|
+
readonly toolArgumentValidator: import("../tools.js").ToolArgumentValidator;
|
|
103
|
+
readonly redactor: SecretRedactor;
|
|
104
|
+
readonly permission: PermissionPolicy;
|
|
105
|
+
readonly trust: TrustPolicy;
|
|
106
|
+
readonly ownership: OwnershipScope;
|
|
107
|
+
/** Optional host-verified identity; when set must match `ownership`. */
|
|
108
|
+
readonly identity?: import("../identity.js").AgentIdentity;
|
|
109
|
+
readonly limits: RunLimits;
|
|
110
|
+
readonly definitionRevision: string;
|
|
111
|
+
readonly runState: Omit<AgentRunStateOptions, "definitionRevision" | "interruptBeforeTool">;
|
|
112
|
+
}
|
|
113
|
+
export interface Agent {
|
|
114
|
+
readonly config: AgentConfig;
|
|
115
|
+
createSession(config?: AgentSessionConfig): AgentSession;
|
|
116
|
+
}
|
|
117
|
+
export interface AgentSessionConfig {
|
|
118
|
+
readonly id?: string;
|
|
119
|
+
readonly agent?: Agent;
|
|
120
|
+
readonly store?: SessionStore;
|
|
121
|
+
readonly leafId?: string;
|
|
122
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
123
|
+
}
|
|
124
|
+
export interface AgentSessionForkOptions {
|
|
125
|
+
readonly leafId?: string;
|
|
126
|
+
}
|
|
127
|
+
export interface AgentSessionCloneOptions {
|
|
128
|
+
readonly id?: string;
|
|
129
|
+
readonly leafId?: string;
|
|
130
|
+
}
|
|
131
|
+
export type SubscriberOverflowPolicy = "close" | "drop_oldest" | "drop_newest";
|
|
132
|
+
export interface SubscribeOptions {
|
|
133
|
+
/** Maximum queued events for a subscriber that is not actively awaiting `next()`. Defaults to 1024. */
|
|
134
|
+
readonly maxQueuedEvents?: number;
|
|
135
|
+
/** What to do when `maxQueuedEvents` is reached. Defaults to `close`. */
|
|
136
|
+
readonly overflow?: SubscriberOverflowPolicy;
|
|
137
|
+
}
|
|
138
|
+
export interface CommandDefinition {
|
|
139
|
+
readonly name: string;
|
|
140
|
+
readonly description?: string;
|
|
141
|
+
readonly parameters?: JsonObject;
|
|
142
|
+
execute(args: JsonObject, context: CommandExecutionContext): Promise<CommandResult> | CommandResult;
|
|
143
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
144
|
+
}
|
|
145
|
+
export interface CommandExecutionContext {
|
|
146
|
+
readonly sessionId?: string;
|
|
147
|
+
readonly runId?: string;
|
|
148
|
+
readonly signal?: AbortSignal;
|
|
149
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
150
|
+
}
|
|
151
|
+
export interface CommandResult {
|
|
152
|
+
readonly name: string;
|
|
153
|
+
readonly content?: readonly ContentBlock[];
|
|
154
|
+
readonly value?: unknown;
|
|
155
|
+
readonly error?: ErrorInfo;
|
|
156
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
157
|
+
}
|
|
158
|
+
export interface ContextBlock {
|
|
159
|
+
readonly id?: string;
|
|
160
|
+
readonly title?: string;
|
|
161
|
+
readonly content: string | readonly ContentBlock[];
|
|
162
|
+
readonly priority?: number;
|
|
163
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
164
|
+
}
|
|
165
|
+
export interface ContextProvider {
|
|
166
|
+
readonly name: string;
|
|
167
|
+
resolve(context: ContextResolutionContext): Promise<readonly ContextBlock[]> | readonly ContextBlock[];
|
|
168
|
+
}
|
|
169
|
+
export interface ContextResolutionContext {
|
|
170
|
+
readonly sessionId?: string;
|
|
171
|
+
readonly runId?: string;
|
|
172
|
+
readonly messages: readonly Message[];
|
|
173
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
174
|
+
readonly signal?: AbortSignal;
|
|
175
|
+
}
|
|
176
|
+
/** When an {@link InstructionInjector} contributes to the assembled provider input. */
|
|
177
|
+
export type InstructionTiming = "first_turn" | "every_turn" | "on_input";
|
|
178
|
+
/** Runtime turn scope handed to an {@link InstructionInjector}. Mirrors {@link LoopContext}
|
|
179
|
+
* scope using already-redacted input/history so predicates cannot recover secrets. */
|
|
180
|
+
export interface InstructionContext {
|
|
181
|
+
readonly sessionId: string;
|
|
182
|
+
readonly runId: string;
|
|
183
|
+
readonly turn: number;
|
|
184
|
+
readonly input: readonly Message[];
|
|
185
|
+
readonly history: readonly Message[];
|
|
186
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
187
|
+
readonly signal: AbortSignal;
|
|
188
|
+
}
|
|
189
|
+
/** Output of an {@link InstructionInjector}. Only `instructions` and `contextBlocks` are
|
|
190
|
+
* honored; other fields grant nothing (no tools, skills, or permissions). */
|
|
191
|
+
export interface InstructionContribution {
|
|
192
|
+
readonly instructions?: string;
|
|
193
|
+
readonly contextBlocks?: readonly ContextBlock[];
|
|
194
|
+
readonly when: InstructionTiming;
|
|
195
|
+
/** Used only when `when === "on_input"`; absent predicate means apply every turn. */
|
|
196
|
+
readonly predicate?: (ctx: InstructionContext) => boolean;
|
|
197
|
+
}
|
|
198
|
+
/** Additive instruction/context contribution that a package registers through
|
|
199
|
+
* {@link ExtensionAPI.registerInstructionInjector} and the host selects on
|
|
200
|
+
* {@link AgentConfig.instructionInjectors} / {@link RunOptions.instructionInjectors}.
|
|
201
|
+
* Inert until selected; cannot grant privileges beyond text/context blocks. */
|
|
202
|
+
export interface InstructionInjector {
|
|
203
|
+
readonly name: string;
|
|
204
|
+
readonly description?: string;
|
|
205
|
+
apply(ctx: InstructionContext): InstructionContribution;
|
|
206
|
+
}
|
|
207
|
+
export interface InputBuilder {
|
|
208
|
+
readonly name: string;
|
|
209
|
+
build(input: string | Message | readonly Message[], context?: InputBuildContext): Promise<readonly Message[]> | readonly Message[];
|
|
210
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
211
|
+
}
|
|
212
|
+
export interface InputBuildContext {
|
|
213
|
+
readonly inputLayout?: InputAssemblyLayout;
|
|
214
|
+
readonly sessionId?: string;
|
|
215
|
+
readonly runId?: string;
|
|
216
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
217
|
+
readonly signal?: AbortSignal;
|
|
218
|
+
readonly permission?: PermissionPolicy;
|
|
219
|
+
readonly trust?: TrustPolicy;
|
|
220
|
+
}
|
|
221
|
+
export interface PromptBuilder {
|
|
222
|
+
readonly name: string;
|
|
223
|
+
build(request: PromptBuildRequest): Promise<readonly Message[]> | readonly Message[];
|
|
224
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
225
|
+
}
|
|
226
|
+
export interface PromptBuildRequest {
|
|
227
|
+
readonly messages: readonly Message[];
|
|
228
|
+
readonly context?: readonly ContextBlock[];
|
|
229
|
+
readonly skills?: readonly Skill[];
|
|
230
|
+
readonly skillsDisclosure?: import("../skill-disclosure.js").SkillsDisclosure;
|
|
231
|
+
readonly loadedSkills?: import("../skill-disclosure.js").LoadedSkillSet;
|
|
232
|
+
/** Skills demoted to catalog-only by context budget this turn. */
|
|
233
|
+
readonly demotedSkillBodies?: readonly string[];
|
|
234
|
+
readonly tools?: readonly ToolDefinition[];
|
|
235
|
+
/** Model being prompted; lets builders adapt composition to declared capabilities
|
|
236
|
+
* (e.g. the default builder omits the `Available tools:` text for tool-capable models). */
|
|
237
|
+
readonly model?: ModelConfig;
|
|
238
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
239
|
+
readonly signal?: AbortSignal;
|
|
240
|
+
}
|
|
241
|
+
export interface Skill {
|
|
242
|
+
readonly name: string;
|
|
243
|
+
readonly description?: string;
|
|
244
|
+
readonly instructions?: string;
|
|
245
|
+
readonly context?: readonly ContextProvider[];
|
|
246
|
+
readonly toolNames?: readonly string[];
|
|
247
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
248
|
+
}
|
|
249
|
+
export interface SkillRegistry {
|
|
250
|
+
register(skill: Skill): void;
|
|
251
|
+
get(name: string): Skill | undefined;
|
|
252
|
+
resolve(name: string): Skill;
|
|
253
|
+
list(): readonly Skill[];
|
|
254
|
+
}
|
|
255
|
+
/** Directory-name spelling for discovered contribution kinds. Maps to a
|
|
256
|
+
* {@link ManifestContributionDeclaration} kind for non-skill kinds:
|
|
257
|
+
* `context` → `contextProvider`, `instructions` → `systemPromptContribution`. */
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
/** Directory-name spelling for discovered contribution kinds. Maps to a
|
|
3
|
+
* {@link ManifestContributionDeclaration} kind for non-skill kinds:
|
|
4
|
+
* `context` → `contextProvider`, `instructions` → `systemPromptContribution`. */
|
|
5
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Contracts-core compaction family (0.2.5 plan 025 Task 1 split).
|
|
2
|
+
* Moved verbatim from contracts-core.ts; public surface unchanged behind the barrel. */
|
|
3
|
+
import type { ErrorInfo } from "./content.js";
|
|
4
|
+
import type { SessionEntry } from "./session.js";
|
|
5
|
+
export interface CompactionStrategy {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
compact(context: CompactionContext): Promise<CompactionResult> | CompactionResult;
|
|
8
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
9
|
+
}
|
|
10
|
+
export interface CompactionContext {
|
|
11
|
+
readonly sessionId: string;
|
|
12
|
+
readonly entries: readonly SessionEntry[];
|
|
13
|
+
readonly keepRecentEntries?: number;
|
|
14
|
+
readonly trigger?: "manual" | "auto" | string;
|
|
15
|
+
readonly secrets?: readonly (string | undefined)[];
|
|
16
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
17
|
+
readonly signal?: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
export interface CompactionResult {
|
|
20
|
+
readonly summary: string;
|
|
21
|
+
readonly entries?: readonly SessionEntry[];
|
|
22
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
23
|
+
}
|
|
24
|
+
export interface CompactionOptions {
|
|
25
|
+
readonly strategy?: CompactionStrategy;
|
|
26
|
+
readonly thresholdEntries?: number;
|
|
27
|
+
readonly keepRecentEntries?: number;
|
|
28
|
+
readonly maxSummaryChars?: number;
|
|
29
|
+
readonly secrets?: readonly (string | undefined)[];
|
|
30
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
31
|
+
readonly signal?: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
export interface CompactionMiddlewarePayload {
|
|
34
|
+
readonly context: CompactionContext;
|
|
35
|
+
readonly result: CompactionResult;
|
|
36
|
+
}
|
|
37
|
+
export interface CompactionEntryData {
|
|
38
|
+
readonly throughEntryId?: string;
|
|
39
|
+
readonly keepEntryIds?: readonly string[];
|
|
40
|
+
readonly strategy?: string;
|
|
41
|
+
readonly trigger?: "manual" | "auto" | string;
|
|
42
|
+
}
|
|
43
|
+
export interface RetryPolicy {
|
|
44
|
+
readonly name: string;
|
|
45
|
+
decide(context: RetryContext): Promise<RetryDecision> | RetryDecision;
|
|
46
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
47
|
+
}
|
|
48
|
+
export interface RetryContext {
|
|
49
|
+
readonly sessionId: string;
|
|
50
|
+
readonly runId: string;
|
|
51
|
+
readonly attempt: number;
|
|
52
|
+
readonly error: ErrorInfo;
|
|
53
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
54
|
+
readonly signal?: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
export interface RetryDecision {
|
|
57
|
+
readonly retry: boolean;
|
|
58
|
+
readonly delayMs?: number;
|
|
59
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
60
|
+
}
|
|
61
|
+
export interface RetryOptions {
|
|
62
|
+
readonly policy?: RetryPolicy;
|
|
63
|
+
readonly maxAttempts?: number;
|
|
64
|
+
readonly baseDelayMs?: number;
|
|
65
|
+
readonly maxDelayMs?: number;
|
|
66
|
+
readonly secrets?: readonly (string | undefined)[];
|
|
67
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
68
|
+
}
|
|
69
|
+
export interface RetryMiddlewarePayload {
|
|
70
|
+
readonly context: RetryContext;
|
|
71
|
+
readonly decision: RetryDecision;
|
|
72
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/** Contracts-core content family (0.2.5 plan 025 Task 1 split).
|
|
2
|
+
* Moved verbatim from contracts-core.ts; public surface unchanged behind the barrel. */
|
|
3
|
+
import type { AudioContent, DocumentContent, FileContent } from "../content.js";
|
|
4
|
+
import type { ModelCacheCapabilities } from "./provider.js";
|
|
5
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
6
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
7
|
+
export interface JsonObject {
|
|
8
|
+
readonly [key: string]: JsonValue;
|
|
9
|
+
}
|
|
10
|
+
export interface ErrorInfo {
|
|
11
|
+
readonly name?: string;
|
|
12
|
+
readonly message: string;
|
|
13
|
+
readonly code?: string | number;
|
|
14
|
+
/** Provider backpressure hint (e.g. from a `Retry-After` header); retry policies
|
|
15
|
+
* honor it capped at their own `maxDelayMs`. */
|
|
16
|
+
readonly retryAfterMs?: number;
|
|
17
|
+
readonly cause?: unknown;
|
|
18
|
+
}
|
|
19
|
+
export type ContentBlock = TextContent | ImageContent | AudioContent | FileContent | DocumentContent | ThinkingContent | ToolCallDeltaContent | ToolCallContent | ToolResultContent;
|
|
20
|
+
export interface TextContent {
|
|
21
|
+
readonly type: "text";
|
|
22
|
+
readonly text: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ImageContent {
|
|
25
|
+
readonly type: "image";
|
|
26
|
+
readonly mimeType?: string;
|
|
27
|
+
readonly data?: string;
|
|
28
|
+
readonly url?: string;
|
|
29
|
+
readonly resourceUri?: string;
|
|
30
|
+
readonly name?: string;
|
|
31
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
32
|
+
}
|
|
33
|
+
export interface ThinkingContent {
|
|
34
|
+
readonly type: "thinking";
|
|
35
|
+
readonly text: string;
|
|
36
|
+
readonly signature?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ToolCallDeltaContent {
|
|
39
|
+
readonly type: "tool_call_delta";
|
|
40
|
+
readonly index: number;
|
|
41
|
+
readonly id?: string;
|
|
42
|
+
readonly name?: string;
|
|
43
|
+
readonly argumentsText?: string;
|
|
44
|
+
/** Who executes the call. `"provider-hosted"` = the provider runs it server-side;
|
|
45
|
+
* the host must NOT dispatch it or send a `tool_result`. Defaults to `"host"`. */
|
|
46
|
+
readonly authority?: ToolCallAuthority;
|
|
47
|
+
}
|
|
48
|
+
export type ToolCallAuthority = "host" | "provider-hosted";
|
|
49
|
+
export interface ToolCallContent {
|
|
50
|
+
readonly type: "tool_call";
|
|
51
|
+
readonly id: string;
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly arguments: JsonObject;
|
|
54
|
+
/** Set when streamed arguments failed JSON parse; dispatch blocks without execute(). */
|
|
55
|
+
readonly argumentsError?: ErrorInfo;
|
|
56
|
+
/** Who executes the call. `"provider-hosted"` = the provider already ran it
|
|
57
|
+
* server-side; the host must NOT dispatch it or append a `tool_result`. The
|
|
58
|
+
* assistant response text already incorporates the call's effect. */
|
|
59
|
+
readonly authority?: ToolCallAuthority;
|
|
60
|
+
}
|
|
61
|
+
export interface ToolResultContent {
|
|
62
|
+
readonly type: "tool_result";
|
|
63
|
+
readonly toolCallId: string;
|
|
64
|
+
readonly name: string;
|
|
65
|
+
readonly result?: unknown;
|
|
66
|
+
readonly error?: ErrorInfo;
|
|
67
|
+
}
|
|
68
|
+
export interface Message {
|
|
69
|
+
readonly id?: string;
|
|
70
|
+
readonly role: "system" | "user" | "assistant" | "tool";
|
|
71
|
+
readonly content: readonly ContentBlock[];
|
|
72
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
73
|
+
}
|
|
74
|
+
export interface ModelConfig {
|
|
75
|
+
readonly provider: string;
|
|
76
|
+
readonly model: string;
|
|
77
|
+
readonly displayName?: string;
|
|
78
|
+
readonly capabilities?: ModelCapabilities;
|
|
79
|
+
readonly limits?: ModelLimits;
|
|
80
|
+
readonly cost?: ModelCost;
|
|
81
|
+
readonly cache?: ModelCacheCapabilities;
|
|
82
|
+
readonly compat?: JsonObject;
|
|
83
|
+
readonly parameters?: Readonly<Record<string, unknown>>;
|
|
84
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
85
|
+
}
|
|
86
|
+
export interface ModelCapabilities {
|
|
87
|
+
/** Known values include `text`, `image`, `audio`, `file`, and `document`. */
|
|
88
|
+
readonly input?: readonly string[];
|
|
89
|
+
readonly output?: readonly string[];
|
|
90
|
+
readonly reasoning?: boolean;
|
|
91
|
+
readonly tools?: boolean;
|
|
92
|
+
readonly streaming?: boolean;
|
|
93
|
+
/** Native JSON-schema structured output support for this model. */
|
|
94
|
+
readonly structuredOutput?: boolean | "json_schema";
|
|
95
|
+
}
|
|
96
|
+
export interface ModelLimits {
|
|
97
|
+
readonly contextWindow?: number;
|
|
98
|
+
readonly maxOutputTokens?: number;
|
|
99
|
+
}
|
|
100
|
+
export interface ModelCost {
|
|
101
|
+
readonly input?: number;
|
|
102
|
+
readonly output?: number;
|
|
103
|
+
readonly cacheRead?: number;
|
|
104
|
+
readonly cacheWrite?: number;
|
|
105
|
+
readonly currency?: string;
|
|
106
|
+
readonly unit?: string;
|
|
107
|
+
}
|
|
108
|
+
export interface Usage {
|
|
109
|
+
readonly inputTokens?: number;
|
|
110
|
+
readonly outputTokens?: number;
|
|
111
|
+
readonly totalTokens?: number;
|
|
112
|
+
readonly cacheReadTokens?: number;
|
|
113
|
+
readonly cacheWriteTokens?: number;
|
|
114
|
+
readonly cost?: number;
|
|
115
|
+
readonly currency?: string;
|
|
116
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** Contracts-core extensions family (0.2.5 plan 025 Task 1 split).
|
|
2
|
+
* Moved verbatim from contracts-core.ts; public surface unchanged behind the barrel. */
|
|
3
|
+
import type { ContributionRegistries } from "../contributions.js";
|
|
4
|
+
import type { ManifestContributionDeclaration } from "../manifests.js";
|
|
5
|
+
import type { Middleware, MiddlewareHookName, MiddlewareRegistry } from "../middleware.js";
|
|
6
|
+
import type { ToolDefinition } from "../contracts-protocol.js";
|
|
7
|
+
import type { AIProvider, ProviderRequest } from "./provider.js";
|
|
8
|
+
import type { AgentDefinition, CommandDefinition, ContextProvider, InputBuilder, InstructionInjector, PromptBuilder, Skill } from "./agent.js";
|
|
9
|
+
import type { CompactionStrategy, RetryPolicy } from "./compaction.js";
|
|
10
|
+
import type { Credential, CredentialResolver, ResourceLoader, SettingsProvider } from "./resources.js";
|
|
11
|
+
import type { ErrorInfo, ModelConfig } from "./content.js";
|
|
12
|
+
import type { StoreFactory } from "./persistence.js";
|
|
13
|
+
export type ContributionFileKind = "skill" | "tool" | "context" | "instructions";
|
|
14
|
+
/** Inert envelope emitted by the host/CLI discovery scanner. Carries the
|
|
15
|
+
* realized {@link Skill} for skill kinds and a manifest-referenced
|
|
16
|
+
* {@link ManifestContributionDeclaration} for other kinds; the host owns
|
|
17
|
+
* any executable behavior. Contains no code, no credential. */
|
|
18
|
+
export interface DiscoveredContribution {
|
|
19
|
+
readonly kind: ContributionFileKind;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly origin: "global" | "workspace";
|
|
22
|
+
readonly path: string;
|
|
23
|
+
/** Present when `kind === "skill"`. */
|
|
24
|
+
readonly skill?: Skill;
|
|
25
|
+
/** Present for non-skill kinds. */
|
|
26
|
+
readonly declaration?: ManifestContributionDeclaration;
|
|
27
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
28
|
+
}
|
|
29
|
+
export type ExtensionLifecycleEventName = "resource_discovery" | "session_start" | "session_shutdown" | "before_agent_start" | "turn" | "context" | "provider_request" | "tool_call" | "tool_result" | "compaction" | "retry";
|
|
30
|
+
export interface ExtensionEvent {
|
|
31
|
+
readonly type: ExtensionLifecycleEventName | "extension_error" | string;
|
|
32
|
+
readonly payload?: unknown;
|
|
33
|
+
readonly extension?: string;
|
|
34
|
+
readonly error?: ErrorInfo;
|
|
35
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
36
|
+
}
|
|
37
|
+
export interface Extension {
|
|
38
|
+
readonly name: string;
|
|
39
|
+
setup(api: ExtensionAPI): void | Promise<void>;
|
|
40
|
+
/** Host-attested signature/digest for `ExtensionLoadPolicy.verifySignature`. */
|
|
41
|
+
readonly signature?: string;
|
|
42
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
43
|
+
}
|
|
44
|
+
export interface ProviderPackage {
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly version?: string;
|
|
47
|
+
readonly description?: string;
|
|
48
|
+
readonly docs?: ProviderPackageDocs;
|
|
49
|
+
setup(api: ProviderPackageAPI): void | Promise<void>;
|
|
50
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
51
|
+
}
|
|
52
|
+
export interface ProviderPackageDocs {
|
|
53
|
+
readonly description?: string;
|
|
54
|
+
readonly links?: readonly string[];
|
|
55
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
56
|
+
}
|
|
57
|
+
export interface ProviderPackageAPI extends ExtensionAPI {
|
|
58
|
+
}
|
|
59
|
+
export type AuthMethod = ApiKeyAuthMethod | OAuthAuthMethod | CustomAuthMethod;
|
|
60
|
+
export interface ApiKeyAuthMethod {
|
|
61
|
+
readonly kind: "api_key";
|
|
62
|
+
readonly provider: string;
|
|
63
|
+
readonly name?: string;
|
|
64
|
+
readonly credentialName?: string;
|
|
65
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
66
|
+
}
|
|
67
|
+
export interface OAuthAuthMethod {
|
|
68
|
+
readonly kind: "oauth";
|
|
69
|
+
readonly provider: string;
|
|
70
|
+
readonly name?: string;
|
|
71
|
+
readonly oauth?: OAuthProvider;
|
|
72
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
73
|
+
}
|
|
74
|
+
export interface OAuthLoginCallbacks {
|
|
75
|
+
onAuth?(url: string): void | Promise<void>;
|
|
76
|
+
onDeviceCode?(code: {
|
|
77
|
+
readonly userCode: string;
|
|
78
|
+
readonly verificationUri: string;
|
|
79
|
+
readonly expiresAt?: string;
|
|
80
|
+
}): void | Promise<void>;
|
|
81
|
+
onPrompt?(message: string): string | undefined | Promise<string | undefined>;
|
|
82
|
+
onSelect?(prompt: {
|
|
83
|
+
readonly message: string;
|
|
84
|
+
readonly choices: readonly string[];
|
|
85
|
+
}): string | undefined | Promise<string | undefined>;
|
|
86
|
+
/** Aborts OAuth login flows and device-code polling when signaled. */
|
|
87
|
+
readonly signal?: AbortSignal;
|
|
88
|
+
}
|
|
89
|
+
export interface OAuthCredentials {
|
|
90
|
+
readonly access?: string;
|
|
91
|
+
readonly refresh?: string;
|
|
92
|
+
readonly expires?: string | number;
|
|
93
|
+
readonly accountId?: string;
|
|
94
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
95
|
+
}
|
|
96
|
+
export interface OAuthProvider {
|
|
97
|
+
readonly id: string;
|
|
98
|
+
login(callbacks?: OAuthLoginCallbacks): Promise<OAuthCredentials> | OAuthCredentials;
|
|
99
|
+
refresh?(credentials: OAuthCredentials): Promise<OAuthCredentials> | OAuthCredentials;
|
|
100
|
+
/** Best-effort upstream revocation; the store delete is what fails closed locally. */
|
|
101
|
+
revoke?(credentials: OAuthCredentials): Promise<void> | void;
|
|
102
|
+
getCredential?(credentials: OAuthCredentials): Promise<Credential | undefined> | Credential | undefined;
|
|
103
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
104
|
+
}
|
|
105
|
+
export interface CustomAuthMethod {
|
|
106
|
+
readonly kind: "custom" | string;
|
|
107
|
+
readonly provider: string;
|
|
108
|
+
readonly name?: string;
|
|
109
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
110
|
+
}
|
|
111
|
+
export interface ProviderRequestPolicy {
|
|
112
|
+
readonly name: string;
|
|
113
|
+
apply(context: ProviderRequestPolicyContext): Promise<ProviderRequest | ProviderRequestPolicyResult> | ProviderRequest | ProviderRequestPolicyResult;
|
|
114
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
115
|
+
}
|
|
116
|
+
export interface ProviderRequestPolicyContext {
|
|
117
|
+
readonly request: ProviderRequest;
|
|
118
|
+
readonly sessionId?: string;
|
|
119
|
+
readonly runId?: string;
|
|
120
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
121
|
+
readonly signal?: AbortSignal;
|
|
122
|
+
}
|
|
123
|
+
export interface ProviderRequestPolicyResult {
|
|
124
|
+
readonly request: ProviderRequest;
|
|
125
|
+
readonly secrets?: readonly (string | undefined)[];
|
|
126
|
+
}
|
|
127
|
+
export type SystemPromptMode = "append" | "prepend" | "replace" | "disable";
|
|
128
|
+
export type SystemPromptSource = "package" | "app" | "user" | "run" | string;
|
|
129
|
+
export interface SystemPromptContribution {
|
|
130
|
+
readonly id: string;
|
|
131
|
+
readonly source?: SystemPromptSource;
|
|
132
|
+
readonly mode?: SystemPromptMode;
|
|
133
|
+
readonly text: string;
|
|
134
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
135
|
+
}
|
|
136
|
+
export type SystemPromptConfig = false | SystemPromptContribution | readonly SystemPromptContribution[];
|
|
137
|
+
export interface ExtensionAPI {
|
|
138
|
+
readonly registries: ContributionRegistries;
|
|
139
|
+
readonly middleware: MiddlewareRegistry;
|
|
140
|
+
on(type: ExtensionLifecycleEventName | string, handler: (event: ExtensionEvent) => void | Promise<void>): () => void;
|
|
141
|
+
emit(event: ExtensionEvent): Promise<void>;
|
|
142
|
+
use<T>(hook: MiddlewareHookName | string, middleware: Middleware<T>): () => void;
|
|
143
|
+
registerProvider(provider: AIProvider): void;
|
|
144
|
+
registerModel(model: ModelConfig): void;
|
|
145
|
+
registerTool(tool: ToolDefinition): void;
|
|
146
|
+
registerContextProvider(provider: ContextProvider): void;
|
|
147
|
+
registerSkill(skill: Skill): void;
|
|
148
|
+
registerCommand(command: CommandDefinition): void;
|
|
149
|
+
registerAgent(agent: AgentDefinition): void;
|
|
150
|
+
registerInputBuilder(builder: InputBuilder): void;
|
|
151
|
+
registerPromptBuilder(builder: PromptBuilder): void;
|
|
152
|
+
registerCompactionStrategy(strategy: CompactionStrategy): void;
|
|
153
|
+
registerRetryPolicy(policy: RetryPolicy): void;
|
|
154
|
+
registerStoreFactory(factory: StoreFactory): void;
|
|
155
|
+
registerResourceLoader(key: string, loader: ResourceLoader): void;
|
|
156
|
+
registerSettingsProvider(key: string, provider: SettingsProvider): void;
|
|
157
|
+
registerCredentialResolver(key: string, resolver: CredentialResolver): void;
|
|
158
|
+
registerProviderPackage(providerPackage: ProviderPackage): void;
|
|
159
|
+
registerAuthMethod(method: AuthMethod): void;
|
|
160
|
+
registerProviderRequestPolicy(policy: ProviderRequestPolicy): void;
|
|
161
|
+
registerSystemPromptContribution(contribution: SystemPromptContribution): void;
|
|
162
|
+
registerInstructionInjector(injector: InstructionInjector): void;
|
|
163
|
+
}
|