@mu-agent/mu 0.0.1
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 +81 -0
- package/THIRD_PARTY_LICENSES.txt +32 -0
- package/dist/index.js +226 -0
- package/dist/mu.js +397 -0
- package/dist/types/ai/auth.d.ts +2 -0
- package/dist/types/ai/catalog.d.ts +20 -0
- package/dist/types/ai/cost.d.ts +4 -0
- package/dist/types/ai/errors.d.ts +13 -0
- package/dist/types/ai/index.d.ts +22 -0
- package/dist/types/ai/json.d.ts +4 -0
- package/dist/types/ai/provider-config.d.ts +15 -0
- package/dist/types/ai/providers/anthropic.d.ts +4 -0
- package/dist/types/ai/providers/gemini.d.ts +4 -0
- package/dist/types/ai/providers/github-copilot.d.ts +2 -0
- package/dist/types/ai/providers/openai-completions.d.ts +4 -0
- package/dist/types/ai/providers/openai.d.ts +6 -0
- package/dist/types/ai/providers/radius.d.ts +5 -0
- package/dist/types/ai/providers/request.d.ts +6 -0
- package/dist/types/ai/providers/shared.d.ts +6 -0
- package/dist/types/ai/registry.d.ts +4 -0
- package/dist/types/ai/retry.d.ts +6 -0
- package/dist/types/ai/sse.d.ts +5 -0
- package/dist/types/ai/stream.d.ts +18 -0
- package/dist/types/ai/testing/replay.d.ts +31 -0
- package/dist/types/ai/types.d.ts +187 -0
- package/dist/types/core/checkpoint.d.ts +39 -0
- package/dist/types/core/commands.d.ts +30 -0
- package/dist/types/core/compaction.d.ts +45 -0
- package/dist/types/core/events.d.ts +109 -0
- package/dist/types/core/extensions.d.ts +97 -0
- package/dist/types/core/index.d.ts +27 -0
- package/dist/types/core/loop.d.ts +69 -0
- package/dist/types/core/messages.d.ts +15 -0
- package/dist/types/core/microcompaction.d.ts +14 -0
- package/dist/types/core/permission.d.ts +27 -0
- package/dist/types/core/process.d.ts +79 -0
- package/dist/types/core/profile.d.ts +46 -0
- package/dist/types/core/recovery.d.ts +14 -0
- package/dist/types/core/session.d.ts +103 -0
- package/dist/types/core/testing/fake-provider.d.ts +19 -0
- package/dist/types/core/tools.d.ts +22 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/profile-coding/checkpoint.d.ts +29 -0
- package/dist/types/profile-coding/context.d.ts +76 -0
- package/dist/types/profile-coding/index.d.ts +35 -0
- package/dist/types/profile-coding/permissions.d.ts +13 -0
- package/dist/types/profile-coding/prompts.d.ts +2 -0
- package/dist/types/profile-coding/shell.d.ts +12 -0
- package/dist/types/profile-coding/state.d.ts +10 -0
- package/dist/types/profile-coding/tools/bash.d.ts +21 -0
- package/dist/types/profile-coding/tools/files.d.ts +32 -0
- package/dist/types/profile-coding/tools/search.d.ts +23 -0
- package/dist/types/profile-coding/tools/tasks.d.ts +9 -0
- package/dist/types/profile-coding/tools/todo.d.ts +16 -0
- package/dist/types/profile-coding/truncate.d.ts +8 -0
- package/dist/types/sdk/agent.d.ts +144 -0
- package/dist/types/sdk/auth-page.d.ts +9 -0
- package/dist/types/sdk/auth.d.ts +78 -0
- package/dist/types/sdk/budget.d.ts +9 -0
- package/dist/types/sdk/commands.d.ts +30 -0
- package/dist/types/sdk/extension-loader.d.ts +15 -0
- package/dist/types/sdk/file-store.d.ts +13 -0
- package/dist/types/sdk/index.d.ts +31 -0
- package/dist/types/sdk/markdown-commands.d.ts +29 -0
- package/dist/types/sdk/mcp.d.ts +22 -0
- package/dist/types/sdk/profile.d.ts +6 -0
- package/dist/types/sdk/shell-hooks.d.ts +14 -0
- package/dist/types/sdk/skills.d.ts +12 -0
- package/dist/types/sdk/structured-output.d.ts +5 -0
- package/dist/types/sdk/testing/mcp-fixture-server.d.ts +1 -0
- package/dist/types/sdk/tool.d.ts +19 -0
- package/package.json +72 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Credential, ModelInfo, Provider } from "./types.js";
|
|
2
|
+
type CatalogFetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
3
|
+
export interface ModelDiscoveryOptions {
|
|
4
|
+
fetch?: CatalogFetch;
|
|
5
|
+
url?: string;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
getCredentials?: (provider: string) => Promise<Credential | undefined>;
|
|
8
|
+
clientVersion?: string;
|
|
9
|
+
providers?: Iterable<Provider>;
|
|
10
|
+
onWarning?: (warning: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function discoverModels(options?: ModelDiscoveryOptions): Promise<ModelInfo[]>;
|
|
13
|
+
export declare function refreshModels(options?: ModelDiscoveryOptions): Promise<ModelInfo[]>;
|
|
14
|
+
export declare function listModels(): ModelInfo[];
|
|
15
|
+
export declare function registerModels(extra: ModelInfo[]): void;
|
|
16
|
+
export declare function findModel(ref: string): ModelInfo | undefined;
|
|
17
|
+
export declare function modelRef(model: ModelInfo): string;
|
|
18
|
+
export declare function providerHasCredentials(provider: string, env?: NodeJS.ProcessEnv): boolean;
|
|
19
|
+
export declare function defaultModelRef(env?: NodeJS.ProcessEnv, authenticatedProviders?: Iterable<string>): string;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type AiErrorKind = "auth" | "rate_limit" | "overloaded" | "context_too_long" | "bad_request" | "not_found" | "network" | "api";
|
|
2
|
+
export declare class AiError extends Error {
|
|
3
|
+
readonly kind: AiErrorKind;
|
|
4
|
+
readonly status?: number;
|
|
5
|
+
readonly retryAfterMs?: number;
|
|
6
|
+
constructor(kind: AiErrorKind, message: string, opts?: {
|
|
7
|
+
status?: number;
|
|
8
|
+
retryAfterMs?: number;
|
|
9
|
+
});
|
|
10
|
+
get retryable(): boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function isContextTooLongMessage(message: string): boolean;
|
|
13
|
+
export declare function classifyHttpError(status: number, body: string, headers: Headers): AiError;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { resolveCredential } from "./auth.js";
|
|
2
|
+
export type { ModelDiscoveryOptions } from "./catalog.js";
|
|
3
|
+
export { defaultModelRef, discoverModels, findModel, listModels, modelRef, providerHasCredentials, refreshModels, registerModels, } from "./catalog.js";
|
|
4
|
+
export { addUsage, computeCostUsd, zeroUsage } from "./cost.js";
|
|
5
|
+
export type { AiErrorKind } from "./errors.js";
|
|
6
|
+
export { AiError, classifyHttpError, isContextTooLongMessage } from "./errors.js";
|
|
7
|
+
export { parseJsonWithRepair, parsePartialJson, repairJson, salvageToolArgs } from "./json.js";
|
|
8
|
+
export { builtinProviderConfigs, modelApi, providerBaseUrl, providerConfig, providerEnvVars, } from "./provider-config.js";
|
|
9
|
+
export { anthropic, streamAnthropic } from "./providers/anthropic.js";
|
|
10
|
+
export { gemini, streamGemini } from "./providers/gemini.js";
|
|
11
|
+
export { discoverGitHubCopilotModels } from "./providers/github-copilot.js";
|
|
12
|
+
export { discoverOpenAICodexModels, openai, openaiCodex, streamOpenAI, } from "./providers/openai.js";
|
|
13
|
+
export { openaiCompletions, streamOpenAICompletions } from "./providers/openai-completions.js";
|
|
14
|
+
export { getProvider, providers, registerProvider } from "./registry.js";
|
|
15
|
+
export type { RetryOpts } from "./retry.js";
|
|
16
|
+
export { withRetries } from "./retry.js";
|
|
17
|
+
export type { SseEvent } from "./sse.js";
|
|
18
|
+
export { iterateSse } from "./sse.js";
|
|
19
|
+
export { AssistantStream, EventStream } from "./stream.js";
|
|
20
|
+
export type { Cassette, RecordedInteraction, ReplayCall, ReplayHandle } from "./testing/replay.js";
|
|
21
|
+
export { recordFetch, replayFetch } from "./testing/replay.js";
|
|
22
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function repairJson(json: string): string;
|
|
2
|
+
export declare function parseJsonWithRepair<T = unknown>(json: string): T;
|
|
3
|
+
export declare function parsePartialJson(text: string): unknown;
|
|
4
|
+
export declare function salvageToolArgs(partialJson: string | undefined): Record<string, unknown>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LlmApi, ModelInfo } from "./types.js";
|
|
2
|
+
export interface BuiltinProviderConfig {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
api: LlmApi;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
env: string[];
|
|
8
|
+
auth?: "bearer" | "anthropic" | "google" | "azure" | "cloudflare";
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
export declare const builtinProviderConfigs: Map<string, BuiltinProviderConfig>;
|
|
12
|
+
export declare function providerConfig(id: string): BuiltinProviderConfig | undefined;
|
|
13
|
+
export declare function modelApi(model: ModelInfo): LlmApi;
|
|
14
|
+
export declare function providerBaseUrl(model: ModelInfo): string | undefined;
|
|
15
|
+
export declare function providerEnvVars(provider: string): readonly string[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AssistantStream } from "../stream.js";
|
|
2
|
+
import type { LlmContext, ModelInfo, Provider, StreamOpts } from "../types.js";
|
|
3
|
+
export declare function streamAnthropic(model: ModelInfo, ctx: LlmContext, opts?: StreamOpts): AssistantStream;
|
|
4
|
+
export declare const anthropic: Provider;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AssistantStream } from "../stream.js";
|
|
2
|
+
import type { LlmContext, ModelInfo, Provider, StreamOpts } from "../types.js";
|
|
3
|
+
export declare function streamGemini(model: ModelInfo, ctx: LlmContext, opts?: StreamOpts): AssistantStream;
|
|
4
|
+
export declare const gemini: Provider;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AssistantStream } from "../stream.js";
|
|
2
|
+
import type { LlmContext, ModelInfo, Provider, StreamOpts } from "../types.js";
|
|
3
|
+
export declare function streamOpenAICompletions(model: ModelInfo, ctx: LlmContext, opts?: StreamOpts): AssistantStream;
|
|
4
|
+
export declare const openaiCompletions: Provider;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AssistantStream } from "../stream.js";
|
|
2
|
+
import type { LlmContext, ModelInfo, Provider, ProviderModelDiscoveryOptions, StreamOpts } from "../types.js";
|
|
3
|
+
export declare function discoverOpenAICodexModels(options: ProviderModelDiscoveryOptions): Promise<ModelInfo[] | undefined>;
|
|
4
|
+
export declare function streamOpenAI(model: ModelInfo, ctx: LlmContext, opts?: StreamOpts): AssistantStream;
|
|
5
|
+
export declare const openai: Provider;
|
|
6
|
+
export declare const openaiCodex: Provider;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AssistantStream } from "../stream.js";
|
|
2
|
+
import type { LlmContext, ModelInfo, Provider, ProviderModelDiscoveryOptions, StreamOpts } from "../types.js";
|
|
3
|
+
export declare function discoverRadiusModels(options: ProviderModelDiscoveryOptions): Promise<ModelInfo[] | undefined>;
|
|
4
|
+
export declare function streamRadius(model: ModelInfo, context: LlmContext, opts?: StreamOpts): AssistantStream;
|
|
5
|
+
export declare const radius: Provider;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Credential, ModelInfo, StreamOpts } from "../types.js";
|
|
2
|
+
export declare function resolveProviderCredential(model: ModelInfo, opts?: StreamOpts): Promise<Credential>;
|
|
3
|
+
export declare function resolvedBaseUrl(model: ModelInfo, opts?: StreamOpts): string;
|
|
4
|
+
export declare function apiPath(baseUrl: string, path: string): string;
|
|
5
|
+
export declare function credentialHeaders(model: ModelInfo, credential: Credential): Record<string, string>;
|
|
6
|
+
export declare function credentialBaseUrl(model: ModelInfo, credential: Credential, opts?: StreamOpts): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AssistantStream } from "../stream.js";
|
|
2
|
+
import type { AssistantMessage, ModelInfo, StreamOpts } from "../types.js";
|
|
3
|
+
export declare function newAssistantMessage(model: ModelInfo): AssistantMessage;
|
|
4
|
+
export declare function updateCost(model: ModelInfo, output: AssistantMessage): void;
|
|
5
|
+
export declare function driveStream(model: ModelInfo, opts: StreamOpts | undefined, fn: (stream: AssistantStream, output: AssistantMessage) => Promise<void>): AssistantStream;
|
|
6
|
+
export declare function postSse(url: string, headers: Record<string, string>, body: unknown, opts?: StreamOpts): Promise<Response>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AssistantMessage, ProviderStreamEvent } from "./types.js";
|
|
2
|
+
export declare class EventStream<T, R = T> implements AsyncIterable<T> {
|
|
3
|
+
private isComplete;
|
|
4
|
+
private extractResult;
|
|
5
|
+
private queue;
|
|
6
|
+
private waiting;
|
|
7
|
+
private done;
|
|
8
|
+
private finalResult;
|
|
9
|
+
private resolveFinal;
|
|
10
|
+
constructor(isComplete: (event: T) => boolean, extractResult: (event: T) => R);
|
|
11
|
+
push(event: T): void;
|
|
12
|
+
end(): void;
|
|
13
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
14
|
+
result(): Promise<R>;
|
|
15
|
+
}
|
|
16
|
+
export declare class AssistantStream extends EventStream<ProviderStreamEvent, AssistantMessage> {
|
|
17
|
+
constructor();
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface RecordedInteraction {
|
|
2
|
+
request: {
|
|
3
|
+
method: string;
|
|
4
|
+
url: string;
|
|
5
|
+
body?: string;
|
|
6
|
+
};
|
|
7
|
+
response: {
|
|
8
|
+
status: number;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
body: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface Cassette {
|
|
14
|
+
interactions: RecordedInteraction[];
|
|
15
|
+
}
|
|
16
|
+
export interface ReplayCall {
|
|
17
|
+
method: string;
|
|
18
|
+
url: string;
|
|
19
|
+
headers: Record<string, string>;
|
|
20
|
+
body?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ReplayHandle {
|
|
23
|
+
fetch: typeof fetch;
|
|
24
|
+
calls: ReplayCall[];
|
|
25
|
+
assertExhausted(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function replayFetch(cassette: Cassette): ReplayHandle;
|
|
28
|
+
export declare function recordFetch(base?: typeof fetch): {
|
|
29
|
+
fetch: typeof fetch;
|
|
30
|
+
cassette: Cassette;
|
|
31
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
export interface TextContent {
|
|
2
|
+
type: "text";
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ThinkingContent {
|
|
6
|
+
type: "thinking";
|
|
7
|
+
thinking: string;
|
|
8
|
+
signature?: string;
|
|
9
|
+
redacted?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ImageContent {
|
|
12
|
+
type: "image";
|
|
13
|
+
mimeType: string;
|
|
14
|
+
data: string;
|
|
15
|
+
evictable?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface ToolCallContent {
|
|
18
|
+
type: "toolCall";
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
arguments: Record<string, unknown>;
|
|
22
|
+
signature?: string;
|
|
23
|
+
}
|
|
24
|
+
export type UserContent = TextContent | ImageContent;
|
|
25
|
+
export type AssistantContent = TextContent | ThinkingContent | ToolCallContent;
|
|
26
|
+
export type ToolResultContent = TextContent | ImageContent;
|
|
27
|
+
export interface Usage {
|
|
28
|
+
inputTokens: number;
|
|
29
|
+
outputTokens: number;
|
|
30
|
+
cacheReadTokens: number;
|
|
31
|
+
cacheWriteTokens: number;
|
|
32
|
+
costUsd?: number;
|
|
33
|
+
}
|
|
34
|
+
export type StopReason = "end" | "toolUse" | "length" | "aborted" | "error";
|
|
35
|
+
export interface UserMessage {
|
|
36
|
+
role: "user";
|
|
37
|
+
content: UserContent[];
|
|
38
|
+
timestamp: number;
|
|
39
|
+
}
|
|
40
|
+
export interface AssistantMessage {
|
|
41
|
+
role: "assistant";
|
|
42
|
+
content: AssistantContent[];
|
|
43
|
+
model: string;
|
|
44
|
+
usage: Usage;
|
|
45
|
+
stopReason: StopReason;
|
|
46
|
+
errorMessage?: string;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
}
|
|
49
|
+
export interface ToolResultMessage {
|
|
50
|
+
role: "toolResult";
|
|
51
|
+
toolCallId: string;
|
|
52
|
+
toolName: string;
|
|
53
|
+
content: ToolResultContent[];
|
|
54
|
+
details?: unknown;
|
|
55
|
+
isError: boolean;
|
|
56
|
+
evicted?: boolean;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
}
|
|
59
|
+
export type AiMessage = UserMessage | AssistantMessage | ToolResultMessage;
|
|
60
|
+
export interface PromptSection {
|
|
61
|
+
text: string;
|
|
62
|
+
dynamic?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface ToolSpec {
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
inputSchema: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
export interface LlmContext {
|
|
70
|
+
systemPrompt?: PromptSection[];
|
|
71
|
+
messages: AiMessage[];
|
|
72
|
+
tools?: ToolSpec[];
|
|
73
|
+
}
|
|
74
|
+
export interface ModelPricing {
|
|
75
|
+
input: number;
|
|
76
|
+
output: number;
|
|
77
|
+
cacheRead: number;
|
|
78
|
+
cacheWrite: number;
|
|
79
|
+
}
|
|
80
|
+
export type LlmApi = "anthropic-messages" | "google-generative-ai" | "google-vertex" | "openai-completions" | "openai-responses";
|
|
81
|
+
export interface ModelInfo {
|
|
82
|
+
provider: string;
|
|
83
|
+
id: string;
|
|
84
|
+
name?: string;
|
|
85
|
+
api?: LlmApi;
|
|
86
|
+
baseUrl?: string;
|
|
87
|
+
headers?: Record<string, string>;
|
|
88
|
+
contextWindow: number;
|
|
89
|
+
maxOutput: number;
|
|
90
|
+
modalities: ("text" | "image")[];
|
|
91
|
+
thinking?: boolean;
|
|
92
|
+
thinkingMode?: "adaptive" | "budget";
|
|
93
|
+
pricing: ModelPricing;
|
|
94
|
+
}
|
|
95
|
+
export type ThinkingLevel = "off" | "low" | "medium" | "high";
|
|
96
|
+
export type Credential = {
|
|
97
|
+
type: "apiKey";
|
|
98
|
+
apiKey: string;
|
|
99
|
+
} | {
|
|
100
|
+
type: "oauth";
|
|
101
|
+
accessToken: string;
|
|
102
|
+
accountId?: string;
|
|
103
|
+
baseUrl?: string;
|
|
104
|
+
headers?: Record<string, string>;
|
|
105
|
+
availableModelIds?: string[];
|
|
106
|
+
};
|
|
107
|
+
export type CredentialResolver = () => Promise<Credential | undefined>;
|
|
108
|
+
export interface ProviderModelDiscoveryOptions {
|
|
109
|
+
fetch?: typeof fetch;
|
|
110
|
+
signal?: AbortSignal;
|
|
111
|
+
getCredentials?: CredentialResolver;
|
|
112
|
+
clientVersion?: string;
|
|
113
|
+
currentModels: readonly ModelInfo[];
|
|
114
|
+
}
|
|
115
|
+
export interface StreamOpts {
|
|
116
|
+
apiKey?: string;
|
|
117
|
+
getCredentials?: CredentialResolver;
|
|
118
|
+
baseUrl?: string;
|
|
119
|
+
sessionId?: string;
|
|
120
|
+
maxTokens?: number;
|
|
121
|
+
temperature?: number;
|
|
122
|
+
thinkingLevel?: ThinkingLevel;
|
|
123
|
+
signal?: AbortSignal;
|
|
124
|
+
maxRetries?: number;
|
|
125
|
+
headers?: Record<string, string>;
|
|
126
|
+
fetch?: typeof fetch;
|
|
127
|
+
}
|
|
128
|
+
export type ProviderStreamEvent = {
|
|
129
|
+
type: "start";
|
|
130
|
+
partial: AssistantMessage;
|
|
131
|
+
} | {
|
|
132
|
+
type: "text_start";
|
|
133
|
+
contentIndex: number;
|
|
134
|
+
partial: AssistantMessage;
|
|
135
|
+
} | {
|
|
136
|
+
type: "text_delta";
|
|
137
|
+
contentIndex: number;
|
|
138
|
+
delta: string;
|
|
139
|
+
partial: AssistantMessage;
|
|
140
|
+
} | {
|
|
141
|
+
type: "text_end";
|
|
142
|
+
contentIndex: number;
|
|
143
|
+
content: string;
|
|
144
|
+
partial: AssistantMessage;
|
|
145
|
+
} | {
|
|
146
|
+
type: "thinking_start";
|
|
147
|
+
contentIndex: number;
|
|
148
|
+
partial: AssistantMessage;
|
|
149
|
+
} | {
|
|
150
|
+
type: "thinking_delta";
|
|
151
|
+
contentIndex: number;
|
|
152
|
+
delta: string;
|
|
153
|
+
partial: AssistantMessage;
|
|
154
|
+
} | {
|
|
155
|
+
type: "thinking_end";
|
|
156
|
+
contentIndex: number;
|
|
157
|
+
content: string;
|
|
158
|
+
partial: AssistantMessage;
|
|
159
|
+
} | {
|
|
160
|
+
type: "toolcall_start";
|
|
161
|
+
contentIndex: number;
|
|
162
|
+
partial: AssistantMessage;
|
|
163
|
+
} | {
|
|
164
|
+
type: "toolcall_delta";
|
|
165
|
+
contentIndex: number;
|
|
166
|
+
delta: string;
|
|
167
|
+
partial: AssistantMessage;
|
|
168
|
+
} | {
|
|
169
|
+
type: "toolcall_end";
|
|
170
|
+
contentIndex: number;
|
|
171
|
+
toolCall: ToolCallContent;
|
|
172
|
+
partial: AssistantMessage;
|
|
173
|
+
} | {
|
|
174
|
+
type: "done";
|
|
175
|
+
message: AssistantMessage;
|
|
176
|
+
} | {
|
|
177
|
+
type: "error";
|
|
178
|
+
reason: Extract<StopReason, "aborted" | "error">;
|
|
179
|
+
errorKind?: string;
|
|
180
|
+
error: AssistantMessage;
|
|
181
|
+
};
|
|
182
|
+
import type { AssistantStream } from "./stream.js";
|
|
183
|
+
export interface Provider {
|
|
184
|
+
id: string;
|
|
185
|
+
stream(model: ModelInfo, ctx: LlmContext, opts?: StreamOpts): AssistantStream;
|
|
186
|
+
discoverModels?(options: ProviderModelDiscoveryOptions): Promise<ModelInfo[] | undefined>;
|
|
187
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface CheckpointDiffFile {
|
|
2
|
+
path: string;
|
|
3
|
+
added: number;
|
|
4
|
+
removed: number;
|
|
5
|
+
hunks: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface CheckpointProvider {
|
|
8
|
+
snapshot(label?: string): Promise<string | undefined>;
|
|
9
|
+
restore(ref: string): Promise<void>;
|
|
10
|
+
restoreResources?(ref: string, resources: string[]): Promise<void>;
|
|
11
|
+
diff(fromRef: string, toRef?: string): Promise<CheckpointDiffFile[]>;
|
|
12
|
+
}
|
|
13
|
+
export interface CheckpointEntry {
|
|
14
|
+
id: string;
|
|
15
|
+
beforeEntryId: string | null;
|
|
16
|
+
beforeRef: string;
|
|
17
|
+
afterRef: string;
|
|
18
|
+
redoRef?: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare class CheckpointHistory {
|
|
22
|
+
private done;
|
|
23
|
+
private undone;
|
|
24
|
+
record(entry: CheckpointEntry): void;
|
|
25
|
+
get canUndo(): boolean;
|
|
26
|
+
get canRedo(): boolean;
|
|
27
|
+
peekUndo(): CheckpointEntry | undefined;
|
|
28
|
+
commitUndo(expected: CheckpointEntry, redoRef?: string): void;
|
|
29
|
+
peekRedo(): CheckpointEntry | undefined;
|
|
30
|
+
commitRedo(expected: CheckpointEntry): void;
|
|
31
|
+
restore(done: CheckpointEntry[], undone?: CheckpointEntry[]): void;
|
|
32
|
+
state(): {
|
|
33
|
+
done: CheckpointEntry[];
|
|
34
|
+
undone: CheckpointEntry[];
|
|
35
|
+
};
|
|
36
|
+
all(): CheckpointEntry[];
|
|
37
|
+
first(): CheckpointEntry | undefined;
|
|
38
|
+
last(): CheckpointEntry | undefined;
|
|
39
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AgentMessage } from "./messages.js";
|
|
2
|
+
export interface CommandContext {
|
|
3
|
+
args: string;
|
|
4
|
+
inject: (message: AgentMessage) => void;
|
|
5
|
+
print: (text: string) => void;
|
|
6
|
+
getModel: () => string;
|
|
7
|
+
setModel: (ref: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface CommandResult {
|
|
10
|
+
handled: boolean;
|
|
11
|
+
message?: string;
|
|
12
|
+
data?: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface Command {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
run: (ctx: CommandContext) => CommandResult | void | Promise<CommandResult | void>;
|
|
18
|
+
}
|
|
19
|
+
export declare class CommandRegistry {
|
|
20
|
+
private commands;
|
|
21
|
+
register(command: Command): void;
|
|
22
|
+
get(name: string): Command | undefined;
|
|
23
|
+
list(): Command[];
|
|
24
|
+
has(name: string): boolean;
|
|
25
|
+
parse(input: string): {
|
|
26
|
+
name: string;
|
|
27
|
+
args: string;
|
|
28
|
+
} | undefined;
|
|
29
|
+
execute(input: string, ctx: Omit<CommandContext, "args">): Promise<CommandResult>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ModelInfo, Provider, StreamOpts, Usage } from "../ai/index.js";
|
|
2
|
+
import type { AgentMessage } from "./messages.js";
|
|
3
|
+
export declare function estimateTokens(messages: AgentMessage[]): number;
|
|
4
|
+
export interface ContextState {
|
|
5
|
+
tokens: number;
|
|
6
|
+
limit: number;
|
|
7
|
+
percent: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function contextState(model: ModelInfo, messages: AgentMessage[], lastUsage?: Usage, estimatedTokensAtLastUsage?: number): ContextState;
|
|
10
|
+
export declare const AUTO_COMPACT_THRESHOLD = 0.85;
|
|
11
|
+
export declare function shouldCompact(state: ContextState, threshold?: number): boolean;
|
|
12
|
+
export interface CompactionRequest {
|
|
13
|
+
messages: AgentMessage[];
|
|
14
|
+
keepFromIndex: number;
|
|
15
|
+
carryover?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export interface CompactionResult {
|
|
18
|
+
summary: string;
|
|
19
|
+
carryover?: unknown;
|
|
20
|
+
keptMessages: AgentMessage[];
|
|
21
|
+
tokensFreed: number;
|
|
22
|
+
usage: Usage;
|
|
23
|
+
}
|
|
24
|
+
type CompactionTranscript = Omit<CompactionResult, "usage">;
|
|
25
|
+
export declare class CompactionError extends Error {
|
|
26
|
+
readonly usage?: Usage | undefined;
|
|
27
|
+
constructor(message: string, usage?: Usage | undefined);
|
|
28
|
+
}
|
|
29
|
+
export declare function planCompaction(messages: AgentMessage[], keepRatio?: number): {
|
|
30
|
+
keepFromIndex: number;
|
|
31
|
+
};
|
|
32
|
+
export declare const SUMMARY_PROMPT = "Summarize the conversation so far so that work can continue without the original transcript.\n\nPreserve, in this order:\n1. What the user asked for \u2014 the goal, in their terms, including any constraints they stated.\n2. Decisions taken and why, including approaches tried and rejected.\n3. Current task state: what is done, what is in progress, what remains.\n4. Concrete facts discovered that would be expensive to rediscover (file locations, API shapes, error messages, command invocations that work).\n5. Anything the user corrected you on.\n\nBe specific and factual. Do not include pleasantries or narration. This summary replaces the transcript, so anything you omit is lost.";
|
|
33
|
+
export interface CompactorOptions {
|
|
34
|
+
provider: Provider;
|
|
35
|
+
model: ModelInfo;
|
|
36
|
+
carryoverExtractor?: (messages: AgentMessage[]) => unknown;
|
|
37
|
+
keepRatio?: number;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
streamOpts?: StreamOpts;
|
|
40
|
+
}
|
|
41
|
+
export declare function compact(messages: AgentMessage[], options: CompactorOptions): Promise<CompactionResult>;
|
|
42
|
+
export declare function applyCompaction(result: CompactionTranscript): AgentMessage[];
|
|
43
|
+
export declare function compactionSummaryMessage(summary: string, carryover?: unknown, timestamp?: number): AgentMessage;
|
|
44
|
+
export declare function formatCarryover(carryover: unknown): string;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { AssistantMessage, ToolResultContent, ToolResultMessage, Usage } from "../ai/index.js";
|
|
2
|
+
import type { AgentMessage } from "./messages.js";
|
|
3
|
+
import type { PermissionRequest } from "./permission.js";
|
|
4
|
+
export type StreamDelta = {
|
|
5
|
+
kind: "text_start";
|
|
6
|
+
contentIndex: number;
|
|
7
|
+
} | {
|
|
8
|
+
kind: "text_delta";
|
|
9
|
+
contentIndex: number;
|
|
10
|
+
text: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "text_end";
|
|
13
|
+
contentIndex: number;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "thinking_start";
|
|
16
|
+
contentIndex: number;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "thinking_delta";
|
|
19
|
+
contentIndex: number;
|
|
20
|
+
text: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "thinking_end";
|
|
23
|
+
contentIndex: number;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "toolcall_start";
|
|
26
|
+
contentIndex: number;
|
|
27
|
+
} | {
|
|
28
|
+
kind: "toolcall_delta";
|
|
29
|
+
contentIndex: number;
|
|
30
|
+
argsFragment: string;
|
|
31
|
+
} | {
|
|
32
|
+
kind: "toolcall_end";
|
|
33
|
+
contentIndex: number;
|
|
34
|
+
toolCallId: string;
|
|
35
|
+
};
|
|
36
|
+
export type AgentEndReason = "done" | "aborted" | "budget" | "maxTurns" | "error";
|
|
37
|
+
export type AgentEvent = {
|
|
38
|
+
type: "agent_start";
|
|
39
|
+
} | {
|
|
40
|
+
type: "agent_end";
|
|
41
|
+
messages: AgentMessage[];
|
|
42
|
+
reason: AgentEndReason;
|
|
43
|
+
} | {
|
|
44
|
+
type: "turn_start";
|
|
45
|
+
} | {
|
|
46
|
+
type: "turn_end";
|
|
47
|
+
message: AssistantMessage;
|
|
48
|
+
toolResults: ToolResultMessage[];
|
|
49
|
+
} | {
|
|
50
|
+
type: "message_start";
|
|
51
|
+
message: AgentMessage;
|
|
52
|
+
} | {
|
|
53
|
+
type: "message_update";
|
|
54
|
+
message: AssistantMessage;
|
|
55
|
+
delta: StreamDelta;
|
|
56
|
+
} | {
|
|
57
|
+
type: "message_end";
|
|
58
|
+
message: AgentMessage;
|
|
59
|
+
} | {
|
|
60
|
+
type: "tool_execution_start";
|
|
61
|
+
toolCallId: string;
|
|
62
|
+
toolName: string;
|
|
63
|
+
args: unknown;
|
|
64
|
+
} | {
|
|
65
|
+
type: "tool_execution_update";
|
|
66
|
+
toolCallId: string;
|
|
67
|
+
partial: ToolResultContent[];
|
|
68
|
+
} | {
|
|
69
|
+
type: "tool_execution_end";
|
|
70
|
+
toolCallId: string;
|
|
71
|
+
result: ToolResultMessage;
|
|
72
|
+
} | {
|
|
73
|
+
type: "permission_asked";
|
|
74
|
+
request: PermissionRequest;
|
|
75
|
+
} | {
|
|
76
|
+
type: "permission_resolved";
|
|
77
|
+
requestId: string;
|
|
78
|
+
outcome: "allow" | "deny";
|
|
79
|
+
remembered?: boolean;
|
|
80
|
+
} | {
|
|
81
|
+
type: "compaction_start";
|
|
82
|
+
layer: 1 | 2 | 3;
|
|
83
|
+
} | {
|
|
84
|
+
type: "compaction_end";
|
|
85
|
+
layer: 1 | 2 | 3;
|
|
86
|
+
tokensFreed: number;
|
|
87
|
+
summaryEntryId?: string;
|
|
88
|
+
} | {
|
|
89
|
+
type: "task_started";
|
|
90
|
+
taskId: string;
|
|
91
|
+
command: string;
|
|
92
|
+
background: boolean;
|
|
93
|
+
} | {
|
|
94
|
+
type: "task_output";
|
|
95
|
+
taskId: string;
|
|
96
|
+
chunk: string;
|
|
97
|
+
} | {
|
|
98
|
+
type: "task_exited";
|
|
99
|
+
taskId: string;
|
|
100
|
+
exitCode: number | null;
|
|
101
|
+
status?: "exited" | "killed";
|
|
102
|
+
} | {
|
|
103
|
+
type: "usage_updated";
|
|
104
|
+
sessionTotals: Usage;
|
|
105
|
+
contextTokens: number;
|
|
106
|
+
contextPercent: number;
|
|
107
|
+
};
|
|
108
|
+
export type AgentEventType = AgentEvent["type"];
|
|
109
|
+
export type EventSink = (event: AgentEvent) => void | Promise<void>;
|