@roam-agent/roam-sdk 0.0.0-stage → 0.2.51
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 +32 -0
- package/README.md +144 -2
- package/anthropic.js +75 -0
- package/api.d.ts +841 -0
- package/api.js +2280 -0
- package/bedrock-converse-stream.js +89 -0
- package/core/export-html/template.css +1085 -0
- package/core/export-html/template.html +56 -0
- package/core/export-html/template.js +2044 -0
- package/core/export-html/vendor/highlight.min.js +1213 -0
- package/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/core/export-html/vendor/marked.min.js +79 -0
- package/github-copilot.js +2 -0
- package/image-resize-worker.js +2 -0
- package/kimi-coding.js +2 -0
- package/modes/interactive/assets/clankolas.png +0 -0
- package/modes/interactive/theme/dark.json +78 -0
- package/modes/interactive/theme/light.json +78 -0
- package/openai-codex.js +75 -0
- package/openrouter.js +75 -0
- package/package.json +42 -5
- package/radius.js +75 -0
- package/xai.js +2 -0
package/api.d.ts
ADDED
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public type contract for the "roam" npm package's programmatic entry
|
|
3
|
+
* (api.js). Hand-authored mirror of src/api.ts: the runtime is fully
|
|
4
|
+
* self-contained in api.js (built from this repo with the roam override
|
|
5
|
+
* layer baked in), so this file only needs to re-export the upstream SDK
|
|
6
|
+
* types and declare the roam additions. A vitest drift guard
|
|
7
|
+
* (test/api.test.ts) asserts every runtime export of src/api.ts appears here.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export * from "@earendil-works/pi-coding-agent";
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
ProgressCallback,
|
|
14
|
+
SettingsManager,
|
|
15
|
+
} from "@earendil-works/pi-coding-agent";
|
|
16
|
+
|
|
17
|
+
import type {
|
|
18
|
+
AgentSession,
|
|
19
|
+
AgentSessionRuntime,
|
|
20
|
+
CreateAgentSessionOptions,
|
|
21
|
+
CreateAgentSessionResult,
|
|
22
|
+
EventBus,
|
|
23
|
+
ExtensionCommandContextActions,
|
|
24
|
+
ExtensionContext,
|
|
25
|
+
ExtensionError,
|
|
26
|
+
ExtensionUIContext,
|
|
27
|
+
InlineExtension,
|
|
28
|
+
LoadedMcpConfig,
|
|
29
|
+
LoadExtensionsResult,
|
|
30
|
+
McpExposure,
|
|
31
|
+
McpServerConfig,
|
|
32
|
+
PromptTemplate,
|
|
33
|
+
ResourceDiagnostic,
|
|
34
|
+
SessionInfo,
|
|
35
|
+
SlashCommandInfo,
|
|
36
|
+
Skill,
|
|
37
|
+
Theme,
|
|
38
|
+
ToolCallEvent,
|
|
39
|
+
ToolCallEventResult,
|
|
40
|
+
} from "@earendil-works/pi-coding-agent";
|
|
41
|
+
|
|
42
|
+
/** Options for running a Bash command through an embedding host. */
|
|
43
|
+
export type ExecuteBashOptions = NonNullable<Parameters<AgentSession["executeBash"]>[2]>;
|
|
44
|
+
/** Result of a Bash command run through an embedding host. */
|
|
45
|
+
export type ExecuteBashResult = Awaited<ReturnType<AgentSession["executeBash"]>>;
|
|
46
|
+
/** Runtime returned by `createPlusAgentSessionRuntime`, including host-owned Bash execution. */
|
|
47
|
+
export type PlusAgentSessionRuntime = AgentSessionRuntime & {
|
|
48
|
+
executeBash(command: string, onChunk?: (chunk: string) => void, options?: ExecuteBashOptions): Promise<ExecuteBashResult>;
|
|
49
|
+
abortBash(): void;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Value import for the SessionManager static shadow below (the augmented
|
|
53
|
+
// instance side is reachable via interface merging; statics are not).
|
|
54
|
+
import { SessionManager as UpstreamSessionManager } from "@earendil-works/pi-coding-agent";
|
|
55
|
+
|
|
56
|
+
// roam runtime addition: the SettingsManager wrapper patches a setter +
|
|
57
|
+
// raw getter pair onto the upstream class next to its existing read-side
|
|
58
|
+
// getExternalEditorCommand (see packages/plus/src/coding-agent/core/settings-manager.ts).
|
|
59
|
+
// The write is queued like every other save — await manager.flush() to persist.
|
|
60
|
+
declare module "@earendil-works/pi-coding-agent" {
|
|
61
|
+
interface SettingsManager {
|
|
62
|
+
/** Persist the external editor command; undefined removes the key and
|
|
63
|
+
* restores the $VISUAL/$EDITOR fallback (roam patch, runtime only). */
|
|
64
|
+
setExternalEditorCommand(command: string | undefined): void;
|
|
65
|
+
/** Raw persisted external editor command, undefined when unset — unlike
|
|
66
|
+
* getExternalEditorCommand, no $VISUAL/$EDITOR fallback (roam patch). */
|
|
67
|
+
getExternalEditorSetting(): string | undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// roam session overlay: the transcript header carries an optional
|
|
72
|
+
// `interactive` host-mode marker (false = headless run, hidden from user-facing
|
|
73
|
+
// history), NewSessionOptions accepts it, and every SessionInfo reports it.
|
|
74
|
+
// See packages/plus/src/coding-agent/core/session-manager.ts.
|
|
75
|
+
declare module "@earendil-works/pi-coding-agent" {
|
|
76
|
+
interface SessionHeader {
|
|
77
|
+
/** False when written by a headless host; undefined on pre-marker files. */
|
|
78
|
+
interactive?: boolean;
|
|
79
|
+
}
|
|
80
|
+
interface NewSessionOptions {
|
|
81
|
+
/** Per-session override of the process default (see setDefaultSessionInteractive). */
|
|
82
|
+
interactive?: boolean;
|
|
83
|
+
}
|
|
84
|
+
interface SessionInfo {
|
|
85
|
+
/** Copied from the transcript header; undefined when the file is unmarked. */
|
|
86
|
+
interactive?: boolean;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// roam session surface: the SDK bundle redirects the upstream core modules
|
|
91
|
+
// onto the packages/plus overlays, so at runtime the embedded classes carry
|
|
92
|
+
// these roam members. The published upstream package does not declare them
|
|
93
|
+
// (Override Policy: upstream stays pristine), so the contract adds them here:
|
|
94
|
+
// instance-side via interface merging, static-side via a shadowing class
|
|
95
|
+
// declaration (an explicit export shadows the star re-export above).
|
|
96
|
+
declare module "@earendil-works/pi-coding-agent" {
|
|
97
|
+
interface AgentSession {
|
|
98
|
+
/** Slash commands invokable through prompt(): extension commands, prompt
|
|
99
|
+
* templates, and `skill:<name>` entries — the TUI autocomplete set minus
|
|
100
|
+
* interactive-mode-only builtins (roam overlay). */
|
|
101
|
+
getSlashCommands(): SlashCommandInfo[];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare class SessionManager extends UpstreamSessionManager {
|
|
106
|
+
/** Delete a persisted session transcript file (.jsonl); returns whether the
|
|
107
|
+
* file was removed, throws for paths outside the session-file convention
|
|
108
|
+
* (roam overlay). */
|
|
109
|
+
static deleteSession(filePath: string): boolean;
|
|
110
|
+
/** Case-insensitive substring search over session history: session name,
|
|
111
|
+
* first user message, or any user/assistant message text; SessionInfo
|
|
112
|
+
* entries ordered by last activity (roam overlay). */
|
|
113
|
+
static search(
|
|
114
|
+
query: string,
|
|
115
|
+
sessionDir?: string,
|
|
116
|
+
onProgress?: (loaded: number, total: number, partialSessions?: readonly SessionInfo[]) => void,
|
|
117
|
+
signal?: AbortSignal,
|
|
118
|
+
): Promise<SessionInfo[]>;
|
|
119
|
+
}
|
|
120
|
+
export { SessionManager };
|
|
121
|
+
|
|
122
|
+
/** Session dir for a cwd under the agent dir's sessions tree (roam SDK
|
|
123
|
+
* re-export; the upstream barrel does not export this). */
|
|
124
|
+
export declare function getDefaultSessionDir(cwd: string, agentDir?: string): string;
|
|
125
|
+
|
|
126
|
+
// Mirrors of upstream-internal types the roam SDK surface exposes but the
|
|
127
|
+
// published upstream barrel does not re-export (kept pristine per the Override
|
|
128
|
+
// Policy). Shapes copied from packages/coding-agent/src/core.
|
|
129
|
+
export interface ConfiguredPackage {
|
|
130
|
+
source: string;
|
|
131
|
+
scope: "user" | "project";
|
|
132
|
+
filtered: boolean;
|
|
133
|
+
installedPath?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface PackageUpdate {
|
|
137
|
+
source: string;
|
|
138
|
+
displayName: string;
|
|
139
|
+
type: "npm" | "git";
|
|
140
|
+
scope: "user" | "project";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface DefaultResourceLoaderOptions {
|
|
144
|
+
cwd: string;
|
|
145
|
+
agentDir: string;
|
|
146
|
+
settingsManager?: SettingsManager;
|
|
147
|
+
eventBus?: EventBus;
|
|
148
|
+
additionalExtensionPaths?: string[];
|
|
149
|
+
additionalSkillPaths?: string[];
|
|
150
|
+
additionalPromptTemplatePaths?: string[];
|
|
151
|
+
additionalThemePaths?: string[];
|
|
152
|
+
extensionFactories?: InlineExtension[];
|
|
153
|
+
noExtensions?: boolean;
|
|
154
|
+
/** Built-in extensions not to load, by name (such as `mcp`), even when settings or `-e` enable them. */
|
|
155
|
+
disabledBuiltinExtensions?: string[];
|
|
156
|
+
noSkills?: boolean;
|
|
157
|
+
noPromptTemplates?: boolean;
|
|
158
|
+
noThemes?: boolean;
|
|
159
|
+
noContextFiles?: boolean;
|
|
160
|
+
systemPrompt?: string;
|
|
161
|
+
appendSystemPrompt?: string[];
|
|
162
|
+
extensionsOverride?: (base: LoadExtensionsResult) => LoadExtensionsResult;
|
|
163
|
+
skillsOverride?: (base: { skills: Skill[]; diagnostics: ResourceDiagnostic[] }) => {
|
|
164
|
+
skills: Skill[];
|
|
165
|
+
diagnostics: ResourceDiagnostic[];
|
|
166
|
+
};
|
|
167
|
+
promptsOverride?: (base: { prompts: PromptTemplate[]; diagnostics: ResourceDiagnostic[] }) => {
|
|
168
|
+
prompts: PromptTemplate[];
|
|
169
|
+
diagnostics: ResourceDiagnostic[];
|
|
170
|
+
};
|
|
171
|
+
themesOverride?: (base: { themes: Theme[]; diagnostics: ResourceDiagnostic[] }) => {
|
|
172
|
+
themes: Theme[];
|
|
173
|
+
diagnostics: ResourceDiagnostic[];
|
|
174
|
+
};
|
|
175
|
+
agentsFilesOverride?: (base: { agentsFiles: Array<{ path: string; content: string }> }) => {
|
|
176
|
+
agentsFiles: Array<{ path: string; content: string }>;
|
|
177
|
+
};
|
|
178
|
+
systemPromptOverride?: (base: string | undefined) => string | undefined;
|
|
179
|
+
appendSystemPromptOverride?: (base: string[]) => string[];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Declare whether this process counts as a human-driven host. Process-global
|
|
183
|
+
* (roam overlay) because session-replacing paths carry no per-call option. */
|
|
184
|
+
export declare function setDefaultSessionInteractive(interactive: boolean): void;
|
|
185
|
+
export declare function getDefaultSessionInteractive(): boolean;
|
|
186
|
+
|
|
187
|
+
/** Hidden roam extension factories for SDK hosts. `agentDir` (the session's
|
|
188
|
+
* agent dir) pins the hub profile for spawned sub-agent children (`--as`):
|
|
189
|
+
* SDK hosts set no PI_CODING_AGENT_DIR per session, so without the pin a
|
|
190
|
+
* child re-resolves the stored default profile and runs the session's model
|
|
191
|
+
* against that profile's endpoint. Unset falls back to the env (roam CLI). */
|
|
192
|
+
export declare function createPlusSdkExtensionFactories(agentDir?: string): InlineExtension[];
|
|
193
|
+
|
|
194
|
+
/** Default env-fallback binding: `createPlusSdkExtensionFactories()`. */
|
|
195
|
+
export declare const plusSdkExtensionFactories: InlineExtension[];
|
|
196
|
+
|
|
197
|
+
// --- roam-permissions (bypass | acceptEdits | auto | plan tool-call gate) ---
|
|
198
|
+
|
|
199
|
+
export type PermissionMode = "bypass" | "acceptEdits" | "auto" | "plan";
|
|
200
|
+
|
|
201
|
+
/** Canonical order; hosts cycle forward through this list on their shortcut. */
|
|
202
|
+
export declare const PERMISSION_MODES: PermissionMode[];
|
|
203
|
+
|
|
204
|
+
export declare const PERMISSION_MODE_LABELS: Record<PermissionMode, string>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Auto mode replaces "ask the human" with "ask the model": reads and
|
|
208
|
+
* in-project edits run unattended, everything else is judged by an action
|
|
209
|
+
* classifier (session model by default). A block is offered to the user for
|
|
210
|
+
* override when a UI is present; with no UI the block is final. Paths holding
|
|
211
|
+
* agent/VCS/startup configuration are denied before the classifier and are
|
|
212
|
+
* never classifier-approvable.
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
/** Verdict on one pending tool call. `unavailable` means "no verdict". */
|
|
216
|
+
export interface ClassifierDecision {
|
|
217
|
+
status: "allow" | "block" | "unavailable";
|
|
218
|
+
reason?: string;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** What the classifier is shown about a pending call. */
|
|
222
|
+
export interface ClassifierAction {
|
|
223
|
+
toolName: string;
|
|
224
|
+
/** Human-readable one-liner (tool + arguments). */
|
|
225
|
+
description: string;
|
|
226
|
+
/** Truncated serialization of the tool input. */
|
|
227
|
+
input?: string;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Signature of the judge: default model-backed, replaceable by hosts/tests. */
|
|
231
|
+
export type ActionClassifier = (
|
|
232
|
+
action: ClassifierAction,
|
|
233
|
+
ctx: ExtensionContext,
|
|
234
|
+
signal?: AbortSignal,
|
|
235
|
+
) => Promise<ClassifierDecision>;
|
|
236
|
+
|
|
237
|
+
/** Consecutive-deny counter used to warn once when auto mode keeps blocking. */
|
|
238
|
+
export declare class DenialTracker {
|
|
239
|
+
readonly maxConsecutive: number;
|
|
240
|
+
constructor(maxConsecutive?: number);
|
|
241
|
+
recordBlock(): number;
|
|
242
|
+
recordAllow(): void;
|
|
243
|
+
shouldNotify(): boolean;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Mutable holder shared between the host and the extension. */
|
|
247
|
+
export interface PermissionModeState {
|
|
248
|
+
mode: PermissionMode;
|
|
249
|
+
/** Auto-mode deny streak tracking; created lazily by the gate. */
|
|
250
|
+
denials?: DenialTracker;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** User-editable auto-mode policy bullets (`autoMode` setting). */
|
|
254
|
+
export interface AutoModeRules {
|
|
255
|
+
allow: string[];
|
|
256
|
+
deny: string[];
|
|
257
|
+
environment: string[];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export declare function readAutoModeRules(cwd: string): AutoModeRules;
|
|
261
|
+
export declare function formatAutoModeRules(rules: AutoModeRules): string | undefined;
|
|
262
|
+
export declare function buildClassifierSystemPrompt(policyAddendum?: string): string;
|
|
263
|
+
export declare function buildClassifierUserPrompt(action: ClassifierAction, transcript: string): string;
|
|
264
|
+
export declare function buildTranscript(ctx: ExtensionContext, maxChars?: number): string;
|
|
265
|
+
export declare function parseClassifierResponse(
|
|
266
|
+
text: string,
|
|
267
|
+
): { block: boolean; reason?: string } | undefined;
|
|
268
|
+
export declare function classifyAction(
|
|
269
|
+
action: ClassifierAction,
|
|
270
|
+
params: unknown,
|
|
271
|
+
): Promise<ClassifierDecision>;
|
|
272
|
+
export declare function createModelClassifier(options?: unknown): ActionClassifier;
|
|
273
|
+
/** Why writing `path` is denied in auto mode regardless of the classifier. */
|
|
274
|
+
export declare function autoModeWriteDenial(path: string, cwd: string): string | undefined;
|
|
275
|
+
|
|
276
|
+
export interface PermissionGateDeps {
|
|
277
|
+
classifier?: ActionClassifier;
|
|
278
|
+
state?: PermissionModeState;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface PermissionsExtensionOptions {
|
|
282
|
+
/** Host-owned state; a fresh bypass-on holder is created when omitted. */
|
|
283
|
+
state?: PermissionModeState;
|
|
284
|
+
/** Called after every mode change, including host-side writes. */
|
|
285
|
+
onModeChange?: (mode: PermissionMode) => void;
|
|
286
|
+
/** Override the auto-mode action classifier (tests or a custom model). */
|
|
287
|
+
classifier?: ActionClassifier;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export declare function parsePermissionMode(arg: string): PermissionMode | undefined;
|
|
291
|
+
|
|
292
|
+
export declare function gatePermissionToolCall(
|
|
293
|
+
event: ToolCallEvent,
|
|
294
|
+
mode: PermissionMode,
|
|
295
|
+
ctx: ExtensionContext,
|
|
296
|
+
deps?: PermissionGateDeps,
|
|
297
|
+
): Promise<ToolCallEventResult | undefined>;
|
|
298
|
+
|
|
299
|
+
/** Build the roam-permissions inline extension for a host. */
|
|
300
|
+
export declare function createPermissionsExtension(options?: PermissionsExtensionOptions): InlineExtension;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Holder the plan extension couples to (see plan/index.ts): embedding hosts
|
|
304
|
+
* (roam-desktop) inject a per-tab state via createPermissionsExtension,
|
|
305
|
+
* and plan-mode engage/exit must read/write THAT holder, because the
|
|
306
|
+
* permissions gate re-syncs the shared plan gate state from its own holder's
|
|
307
|
+
* mode on every tool call — coupling to the module default would let the
|
|
308
|
+
* first tool call silently tear plan mode down. Registered by the factory,
|
|
309
|
+
* last-write-wins; falls back to the module default until one registers.
|
|
310
|
+
*/
|
|
311
|
+
export declare function setActivePermissionState(
|
|
312
|
+
state: PermissionModeState,
|
|
313
|
+
onModeChange?: (mode: PermissionMode) => void,
|
|
314
|
+
): void;
|
|
315
|
+
export declare function getActivePermissionState(): PermissionModeState;
|
|
316
|
+
/** Mirror a plan-side mode switch into the host UI (the registered onModeChange, if any). */
|
|
317
|
+
export declare function notifyActivePermissionModeChange(mode: PermissionMode): void;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Pick from a host's dedicated plan-review dialog (roam-desktop renders
|
|
321
|
+
* the plan as markdown with Claude Code style choices). "approveAcceptEdits" /
|
|
322
|
+
* "approveAuto" / "approveBypass" approve AND select the post-approval
|
|
323
|
+
* permission mode, so the plan runs with the chosen level of automation.
|
|
324
|
+
* undefined = dismissed.
|
|
325
|
+
*/
|
|
326
|
+
export type PlanReviewDialogChoice =
|
|
327
|
+
| "approveAcceptEdits"
|
|
328
|
+
| "approveAuto"
|
|
329
|
+
| "approveBypass"
|
|
330
|
+
| "edit"
|
|
331
|
+
| "stay";
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Optional ExtensionUIContext extension SDK hosts provide via
|
|
335
|
+
* createPlusUIContext to take over the plan-review presentation.
|
|
336
|
+
*/
|
|
337
|
+
export interface PlanReviewDialogUI {
|
|
338
|
+
planReview(plan: string): Promise<PlanReviewDialogChoice | undefined>;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface PlusUIDialogHandlers {
|
|
342
|
+
select(title: string, options: string[]): Promise<string | undefined>;
|
|
343
|
+
confirm(title: string, message: string): Promise<boolean>;
|
|
344
|
+
input(title: string, placeholder?: string): Promise<string | undefined>;
|
|
345
|
+
editor?(title: string, prefill?: string): Promise<string | undefined>;
|
|
346
|
+
/**
|
|
347
|
+
* Dedicated plan-review dialog (ExitPlanMode). The host renders the plan
|
|
348
|
+
* markdown and offers Claude Code style choices; "approveAcceptEdits" /
|
|
349
|
+
* "approveBypass" approve the plan AND set the post-approval permission
|
|
350
|
+
* mode. Return undefined when dismissed (stays in plan mode). Omit to fall
|
|
351
|
+
* back to the plain-text select.
|
|
352
|
+
*/
|
|
353
|
+
planReview?(plan: string): Promise<PlanReviewDialogChoice | undefined>;
|
|
354
|
+
notify?(message: string, type?: "info" | "warning" | "error"): void;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export declare function createPlusUIContext(handlers: PlusUIDialogHandlers): ExtensionUIContext;
|
|
358
|
+
|
|
359
|
+
// --- roam-session-recap failure feed (shared core, recap/events.ts) -------
|
|
360
|
+
|
|
361
|
+
/** Why a recap run failed: the auto-title call timed out, or the provider errored. */
|
|
362
|
+
export type RecapFailureReason = "timeout" | "error";
|
|
363
|
+
|
|
364
|
+
/** One failed session-recap run. */
|
|
365
|
+
export interface RecapFailure {
|
|
366
|
+
/** Session that owned the recap run. */
|
|
367
|
+
sessionId: string;
|
|
368
|
+
reason: RecapFailureReason;
|
|
369
|
+
/** Human-readable detail (timeout note or the provider error message). */
|
|
370
|
+
message: string;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Subscribe to session recap failures from every session in this process: the
|
|
375
|
+
* auto-title LLM call (after the first prompt and after every compaction)
|
|
376
|
+
* hitting its 30s timeout ("timeout") or a provider error ("error"). Fires
|
|
377
|
+
* after each failed run; returns an unsubscribe function. In-process only —
|
|
378
|
+
* hosts embed roam in-process, which this covers. Hosts that also wire
|
|
379
|
+
* PlusUIDialogHandlers.notify receive the same failure as a transcript warning
|
|
380
|
+
* through the notify bridge.
|
|
381
|
+
*/
|
|
382
|
+
export declare function subscribeToRecapFailures(
|
|
383
|
+
listener: (failure: RecapFailure) => void,
|
|
384
|
+
): () => void;
|
|
385
|
+
|
|
386
|
+
/** Options shared by the package-maintenance entries. */
|
|
387
|
+
export interface PlusPackageMaintenanceOptions {
|
|
388
|
+
/** Project directory for project-scope declarations (default `process.cwd()`). */
|
|
389
|
+
cwd?: string;
|
|
390
|
+
/** Agent dir holding user-scope settings.json (default pi's agent dir). */
|
|
391
|
+
agentDir?: string;
|
|
392
|
+
/**
|
|
393
|
+
* Caller-owned settings manager. When given, `cwd`/`agentDir`/
|
|
394
|
+
* `projectTrusted` are not used for settings resolution (the manager's own
|
|
395
|
+
* storage decides), and `agentDir` still defaults to pi's agent dir for
|
|
396
|
+
* install locations.
|
|
397
|
+
*/
|
|
398
|
+
settingsManager?: SettingsManager;
|
|
399
|
+
/**
|
|
400
|
+
* Whether project-scope settings are honored (default true). Embedding
|
|
401
|
+
* hosts decide project trust themselves — mirroring
|
|
402
|
+
* `createPlusAgentSessionRuntime`'s `projectTrusted` — instead of pi's
|
|
403
|
+
* interactive trust prompt.
|
|
404
|
+
*/
|
|
405
|
+
projectTrusted?: boolean;
|
|
406
|
+
/** Receives progress events from installs/updates (clone/npm stages). */
|
|
407
|
+
onProgress?: ProgressCallback;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export interface PlusPackageInstallOptions extends PlusPackageMaintenanceOptions {
|
|
411
|
+
/**
|
|
412
|
+
* Persist the source in the project's `.pi/settings.json` instead of the
|
|
413
|
+
* user settings. Requires a project-trusted settings manager.
|
|
414
|
+
*/
|
|
415
|
+
local?: boolean;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/** Configured packages from both scopes, in user-then-project order. Synchronous. */
|
|
419
|
+
export declare function listPackages(options?: PlusPackageMaintenanceOptions): ConfiguredPackage[];
|
|
420
|
+
/** Install a package source and persist it in settings (user scope unless `local`). */
|
|
421
|
+
export declare function installPackage(source: string, options?: PlusPackageInstallOptions): Promise<void>;
|
|
422
|
+
/** Remove a package source from settings; returns false when nothing matched. */
|
|
423
|
+
export declare function removePackage(source: string, options?: PlusPackageInstallOptions): Promise<boolean>;
|
|
424
|
+
/**
|
|
425
|
+
* Reconcile installed packages with their configured sources (clone/npm ref
|
|
426
|
+
* refreshes — pinned refs do not move). Pass `source` to update one package;
|
|
427
|
+
* omit it to update everything in both scopes.
|
|
428
|
+
*/
|
|
429
|
+
export declare function updatePackages(source?: string, options?: PlusPackageMaintenanceOptions): Promise<void>;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Drop every cached extension factory so the next session rebuilds them from
|
|
433
|
+
* disk. The loader memoizes factories per resolved path for the life of the
|
|
434
|
+
* process — right for a short-lived CLI run, but a long-lived host (desktop
|
|
435
|
+
* app) would keep serving stale code after a package update. Call after a
|
|
436
|
+
* successful install/remove/update.
|
|
437
|
+
*/
|
|
438
|
+
export declare function clearExtensionCache(): void;
|
|
439
|
+
|
|
440
|
+
// ---------------------------------------------------------------------------
|
|
441
|
+
// MCP server maintenance — the programmatic equivalent of `pi mcp
|
|
442
|
+
// list/add/remove/login/logout`. roam disables the TUI's /mcp commands, so
|
|
443
|
+
// hosts (desktop frontends, IDE adapters) manage MCP servers through these
|
|
444
|
+
// entries: config CRUD on the same two files pi loads (<agentDir>/mcp.json and
|
|
445
|
+
// a trusted project's <cwd>/.pi/mcp.json), live status checks, and the OAuth
|
|
446
|
+
// sign-in/out flow — all reusing pi's own MCP runtime. Re-exported from
|
|
447
|
+
// packages/plus-api/src/mcp.ts; the runtime bundle inlines the module.
|
|
448
|
+
// ---------------------------------------------------------------------------
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Copy of the type from packages/coding-agent/src/extensions/mcp/config.ts
|
|
452
|
+
* (not exported by the upstream barrel). Only presentation keys are patchable;
|
|
453
|
+
* connection config changes go through addMcpServer.
|
|
454
|
+
*/
|
|
455
|
+
export interface McpServerConfigPatch {
|
|
456
|
+
enabled?: boolean | undefined;
|
|
457
|
+
exposure?: McpExposure | undefined;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/** Host options locating the two MCP config files. */
|
|
461
|
+
export interface PlusMcpOptions {
|
|
462
|
+
/** Project root whose `.pi/mcp.json` participates. Defaults to `process.cwd()`. */
|
|
463
|
+
cwd?: string;
|
|
464
|
+
/** Pi agent directory holding the global `mcp.json`. Defaults to `getAgentDir()`. */
|
|
465
|
+
agentDir?: string;
|
|
466
|
+
/** Whether the project may contribute local MCP config. Defaults to true. */
|
|
467
|
+
projectTrusted?: boolean;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** Options for writes choosing between the global and the project file. */
|
|
471
|
+
export interface PlusMcpEditOptions extends PlusMcpOptions {
|
|
472
|
+
/** true targets `<cwd>/.pi/mcp.json`; false/undefined `<agentDir>/mcp.json`. */
|
|
473
|
+
local?: boolean;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** Options for updates that need to find the file actually defining the server. */
|
|
477
|
+
export interface PlusMcpUpdateOptions extends PlusMcpOptions {
|
|
478
|
+
/**
|
|
479
|
+
* Where to write the patch. Omitted: the file that defines or overrides the
|
|
480
|
+
* server. "project" writes/creates a project override; "user" forces the
|
|
481
|
+
* global file.
|
|
482
|
+
*/
|
|
483
|
+
scope?: "user" | "project";
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** Absolute paths of the two mcp.json files for these options. */
|
|
487
|
+
export declare function getMcpConfigPaths(options?: PlusMcpOptions): { global: string; project: string };
|
|
488
|
+
/** Merged MCP config pi would start a session with; broken files report in `errors`, never throw. */
|
|
489
|
+
export declare function listMcpServers(options?: PlusMcpOptions): LoadedMcpConfig;
|
|
490
|
+
/** Validate a raw mcp.json entry pi's way without writing it: config or error string. */
|
|
491
|
+
export declare function validateMcpServer(name: string, raw: unknown): McpServerConfig | string;
|
|
492
|
+
/** Add or replace a server in the scope's mcp.json (validated first; invalid configs throw). */
|
|
493
|
+
export declare function addMcpServer(
|
|
494
|
+
name: string,
|
|
495
|
+
config: McpServerConfig,
|
|
496
|
+
options?: PlusMcpEditOptions,
|
|
497
|
+
): { replaced: boolean; path: string };
|
|
498
|
+
/** Remove a server from the scope's mcp.json. Does not touch OAuth credentials. */
|
|
499
|
+
export declare function removeMcpServer(name: string, options?: PlusMcpEditOptions): { removed: boolean; path: string };
|
|
500
|
+
/** Patch `enabled`/`exposure` of an existing server without touching its connection config. */
|
|
501
|
+
export declare function updateMcpServer(
|
|
502
|
+
name: string,
|
|
503
|
+
patch: McpServerConfigPatch,
|
|
504
|
+
options?: PlusMcpUpdateOptions,
|
|
505
|
+
): { path: string };
|
|
506
|
+
|
|
507
|
+
/** One server as `pi mcp list` reports it: static config plus live state when enabled. */
|
|
508
|
+
export interface McpServerStatus {
|
|
509
|
+
name: string;
|
|
510
|
+
scope: "global" | "project" | "extension";
|
|
511
|
+
/** File defining the entry. */
|
|
512
|
+
source: string;
|
|
513
|
+
/** File overriding it, when a project override exists. */
|
|
514
|
+
override?: string;
|
|
515
|
+
enabled: boolean;
|
|
516
|
+
/** Server-level exposure; pi defaults to "codemode". */
|
|
517
|
+
exposure: string;
|
|
518
|
+
/** `"stdio"` (command line) or the server URL. */
|
|
519
|
+
transport: string;
|
|
520
|
+
/** "disabled" when not enabled; otherwise the runtime state after a connect attempt. */
|
|
521
|
+
state: "disabled" | "connecting" | "connected" | "disconnected" | "needs-auth" | "failed" | "closed";
|
|
522
|
+
/** Registered tool names (namespaced), empty unless connected. */
|
|
523
|
+
tools: string[];
|
|
524
|
+
/** Per-tool exposure overrides differing from `exposure`. */
|
|
525
|
+
toolExposure?: Record<string, string>;
|
|
526
|
+
resources?: boolean;
|
|
527
|
+
error?: string;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** Result of checkMcpServers. */
|
|
531
|
+
export interface PlusMcpCheckResult {
|
|
532
|
+
servers: McpServerStatus[];
|
|
533
|
+
/** Config-load problems (unreadable file, invalid entries). */
|
|
534
|
+
errors: string[];
|
|
535
|
+
/** Set when the project config exists but the project is not trusted. */
|
|
536
|
+
note?: string;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/** Connect to every enabled server in parallel and report state/tools, like `pi mcp list`. */
|
|
540
|
+
export declare function checkMcpServers(options?: PlusMcpOptions): Promise<PlusMcpCheckResult>;
|
|
541
|
+
|
|
542
|
+
/** Options for loginMcpServer. */
|
|
543
|
+
export interface PlusMcpLoginOptions extends PlusMcpOptions {
|
|
544
|
+
/** Open the authorization URL in the user's browser (hosts own shell access). */
|
|
545
|
+
openUrl: (url: string) => void;
|
|
546
|
+
/**
|
|
547
|
+
* Ask the user to paste the redirected URL when the loopback callback cannot
|
|
548
|
+
* reach this machine. Omitted: sign-in waits for the callback only.
|
|
549
|
+
*/
|
|
550
|
+
promptForRedirectUrl?: (signal: AbortSignal) => Promise<string | undefined>;
|
|
551
|
+
/** Whole-flow timeout in ms. Defaults to 300000, like `pi mcp login`. */
|
|
552
|
+
timeoutMs?: number;
|
|
553
|
+
/** Cancels the flow with McpSignInCancelledError. */
|
|
554
|
+
signal?: AbortSignal;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** Default deadline for `pi mcp login`-equivalent sign-in. */
|
|
558
|
+
export declare const DEFAULT_MCP_LOGIN_TIMEOUT_MS: number;
|
|
559
|
+
/**
|
|
560
|
+
* Run pi's OAuth sign-in for one configured server. An already-authenticated
|
|
561
|
+
* server resolves immediately; `needs-auth` opens `openUrl` and waits for the
|
|
562
|
+
* loopback callback. Returns the connected tool names; tokens are stored in
|
|
563
|
+
* `<agentDir>/mcp-auth.json`.
|
|
564
|
+
*/
|
|
565
|
+
export declare function loginMcpServer(name: string, options: PlusMcpLoginOptions): Promise<string[]>;
|
|
566
|
+
/** Remove a server's stored OAuth credentials; false when it never signed in. */
|
|
567
|
+
export declare function logoutMcpServer(name: string, options?: PlusMcpOptions): boolean;
|
|
568
|
+
|
|
569
|
+
/** One stored OAuth credential record, keyed like `<agentDir>/mcp-auth.json`. */
|
|
570
|
+
export interface McpCredentialInfo {
|
|
571
|
+
key: string;
|
|
572
|
+
hasClientInformation: boolean;
|
|
573
|
+
hasTokens: boolean;
|
|
574
|
+
tokensExpireAt?: number;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/** Summarize `<agentDir>/mcp-auth.json` without secret material; empty when absent. */
|
|
578
|
+
export declare function listMcpCredentials(options?: PlusMcpOptions): McpCredentialInfo[];
|
|
579
|
+
|
|
580
|
+
export interface CreatePlusAgentSessionOptions extends CreateAgentSessionOptions {
|
|
581
|
+
extensionFactories?: InlineExtension[];
|
|
582
|
+
ui?: PlusUIDialogHandlers;
|
|
583
|
+
/**
|
|
584
|
+
* Whether sessions this host writes count as user history (transcript header
|
|
585
|
+
* `interactive` flag, which history surfaces hide when false). Defaults to
|
|
586
|
+
* `ui !== undefined`. Process-global — set before creating sessions.
|
|
587
|
+
*/
|
|
588
|
+
interactive?: boolean;
|
|
589
|
+
commandContextActions?: ExtensionCommandContextActions;
|
|
590
|
+
abortHandler?: () => void;
|
|
591
|
+
shutdownHandler?: () => void;
|
|
592
|
+
onError?: (error: ExtensionError) => void;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export declare function createPlusAgentSession(
|
|
596
|
+
options?: CreatePlusAgentSessionOptions,
|
|
597
|
+
): Promise<CreateAgentSessionResult>;
|
|
598
|
+
|
|
599
|
+
export interface CreatePlusAgentSessionRuntimeOptions extends CreateAgentSessionOptions {
|
|
600
|
+
extensionFactories?: InlineExtension[];
|
|
601
|
+
ui?: PlusUIDialogHandlers;
|
|
602
|
+
/**
|
|
603
|
+
* Whether sessions this host writes count as user history (transcript header
|
|
604
|
+
* `interactive` flag). Defaults to `ui !== undefined`. Process-global.
|
|
605
|
+
*/
|
|
606
|
+
interactive?: boolean;
|
|
607
|
+
/** Overrides the runtime-routed actions (switchSession/fork/newSession/...)
|
|
608
|
+
* the factory wires by default, same shape as bindExtensions' binding. */
|
|
609
|
+
commandContextActions?: ExtensionCommandContextActions;
|
|
610
|
+
abortHandler?: () => void;
|
|
611
|
+
shutdownHandler?: () => void;
|
|
612
|
+
onError?: (error: ExtensionError) => void;
|
|
613
|
+
/** Called after every extension bind: the initial session and each session
|
|
614
|
+
* replacement. Re-subscribe to the new session here; the previous
|
|
615
|
+
* AgentSession object is disposed after a replacement. */
|
|
616
|
+
onRebind?: (session: AgentSession) => void | Promise<void>;
|
|
617
|
+
/** Project-trust flag for per-cwd SettingsManagers (default true). */
|
|
618
|
+
projectTrusted?: boolean;
|
|
619
|
+
/** Loader passthroughs (additionalSkillPaths, noSkills, systemPrompt, ...)
|
|
620
|
+
* applied on every recreation; cwd/agentDir/settingsManager/extensionFactories are owned by the factory. */
|
|
621
|
+
resourceLoaderOptions?: Omit<
|
|
622
|
+
DefaultResourceLoaderOptions,
|
|
623
|
+
"cwd" | "agentDir" | "settingsManager" | "extensionFactories"
|
|
624
|
+
>;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/** Runtime-backed createPlusAgentSession: same roam layer and binding rules,
|
|
628
|
+
* but returns an AgentSessionRuntime with CLI-level session replacement
|
|
629
|
+
* (/cd, newSession, fork/clone, switchSession). The live session is
|
|
630
|
+
* `runtime.session` — it changes on every replacement; hosts must NOT call
|
|
631
|
+
* bindExtensions themselves. */
|
|
632
|
+
export declare function createPlusAgentSessionRuntime(
|
|
633
|
+
options?: CreatePlusAgentSessionRuntimeOptions,
|
|
634
|
+
): Promise<PlusAgentSessionRuntime>;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Profile management: the curated @roam-agent/roam-hub surface bundled into
|
|
638
|
+
* api.js (profiles.json CRUD + per-profile materialized agent dirs). Types are
|
|
639
|
+
* declared inline because pi-hub is not a dependency of this package — keep
|
|
640
|
+
* them in sync with packages/hub/src/types.ts.
|
|
641
|
+
*/
|
|
642
|
+
export interface CustomModel {
|
|
643
|
+
id: string;
|
|
644
|
+
name?: string;
|
|
645
|
+
api?: string;
|
|
646
|
+
baseUrl?: string;
|
|
647
|
+
reasoning?: boolean;
|
|
648
|
+
contextWindow?: number;
|
|
649
|
+
maxTokens?: number;
|
|
650
|
+
[key: string]: unknown;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/** Model list entry: a catalog model id, or a custom model definition. */
|
|
654
|
+
export type ModelEntry = string | CustomModel;
|
|
655
|
+
|
|
656
|
+
export interface Profile {
|
|
657
|
+
provider?: string;
|
|
658
|
+
model?: string;
|
|
659
|
+
models?: ModelEntry[];
|
|
660
|
+
thinking?: string;
|
|
661
|
+
token?: string;
|
|
662
|
+
url?: string;
|
|
663
|
+
/** Arbitrary settings.json overrides, merged over the source agent settings.
|
|
664
|
+
* A null value deletes the key from the materialized settings.json. */
|
|
665
|
+
settings?: Record<string, unknown>;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
export interface ProfilesData {
|
|
669
|
+
profiles: Record<string, Profile>;
|
|
670
|
+
default?: string;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
export interface AgentSettingsData {
|
|
674
|
+
defaultProvider?: string;
|
|
675
|
+
defaultModel?: string;
|
|
676
|
+
defaultThinkingLevel?: string;
|
|
677
|
+
skills?: unknown;
|
|
678
|
+
[key: string]: unknown;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
export declare const THINKING_LEVELS: string[];
|
|
682
|
+
|
|
683
|
+
/** The model id of a model list entry (a plain catalog id, or a custom
|
|
684
|
+
* definition's `id`). */
|
|
685
|
+
export declare function modelId(entry: ModelEntry): string;
|
|
686
|
+
|
|
687
|
+
/** Source agent dir (PI_CODING_AGENT_DIR or ~/.pi/agent): profiles without an applied profile. */
|
|
688
|
+
export declare const AGENT_DIR: string;
|
|
689
|
+
|
|
690
|
+
export declare function loadProfiles(): ProfilesData;
|
|
691
|
+
export declare function findProfile(name: string): Profile | undefined;
|
|
692
|
+
export declare function getDefaultProfileName(): string | undefined;
|
|
693
|
+
export declare function setDefaultProfile(name: string): void;
|
|
694
|
+
export declare function clearDefaultProfile(): void;
|
|
695
|
+
/** Select a profile's default model (list position 1, materialized as
|
|
696
|
+
* settings.defaultModel); adds it when absent. Throws for an unknown profile,
|
|
697
|
+
* an empty model, or a new model beyond the 3-per-profile bound. */
|
|
698
|
+
export declare function setProfileDefaultModel(name: string, model: string): string;
|
|
699
|
+
export declare function addProfile(name: string, profile: Profile): void;
|
|
700
|
+
/** Append a model to a profile without selecting it; becomes the default when
|
|
701
|
+
* the profile had no model. Throws for an unknown profile, a duplicate or
|
|
702
|
+
* empty model, or a fourth model. */
|
|
703
|
+
export declare function addProfileModel(name: string, model: string): string;
|
|
704
|
+
export declare function updateProfile(name: string, profile: Profile): void;
|
|
705
|
+
export declare function removeProfile(name: string): void;
|
|
706
|
+
/** Remove a model from a profile; the default promotes to the next remaining
|
|
707
|
+
* model, and removing the last clears both `models` and `model`. A model not
|
|
708
|
+
* in the list is a no-op with a message; throws for an unknown profile. */
|
|
709
|
+
export declare function removeProfileModel(name: string, model: string): string;
|
|
710
|
+
export declare function renameProfile(oldName: string, newName: string): void;
|
|
711
|
+
export declare function profileDirFor(name: string): string;
|
|
712
|
+
export declare function materializeProfile(name: string, profile: Profile): string;
|
|
713
|
+
/** Re-create the shared source→profile links (sessions, extensions, …) for an
|
|
714
|
+
* already-materialized profile dir. Link-only repair: unlike materializeProfile
|
|
715
|
+
* it never writes auth.json/settings.json, so it is safe to run at startup for
|
|
716
|
+
* every stored profile (adopts profile-only content into the source when the
|
|
717
|
+
* shared dir was never linked). No-op when the dir does not exist. */
|
|
718
|
+
export declare function refreshSharedLinks(dir: string): void;
|
|
719
|
+
export declare function removeProfileDir(name: string): void;
|
|
720
|
+
export declare function syncProfilePackagesToSource(profileDir: string): boolean;
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Provider login: roam's programmatic provider login bundled into api.js
|
|
724
|
+
* (packages/plus/src/auth/login.ts) — pi's interactive /login equivalent,
|
|
725
|
+
* which roam disables in the TUI. The credential is persisted to
|
|
726
|
+
* <agentDir>/auth.json, the same store pi reads at launch. The auth
|
|
727
|
+
* vocabulary is declared inline because pi-ai is not a dependency of this
|
|
728
|
+
* package — keep it in sync with packages/ai/src/auth/types.ts.
|
|
729
|
+
*/
|
|
730
|
+
export type AuthType = "api_key" | "oauth";
|
|
731
|
+
|
|
732
|
+
export interface ApiKeyCredential {
|
|
733
|
+
type: "api_key";
|
|
734
|
+
key?: string;
|
|
735
|
+
env?: Record<string, string>;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
export interface OAuthCredential {
|
|
739
|
+
type: "oauth";
|
|
740
|
+
refresh: string;
|
|
741
|
+
access: string;
|
|
742
|
+
expires: number;
|
|
743
|
+
[key: string]: unknown;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
export type Credential = ApiKeyCredential | OAuthCredential;
|
|
747
|
+
|
|
748
|
+
export interface AuthInfoLink {
|
|
749
|
+
url: string;
|
|
750
|
+
label?: string;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
export type AuthPrompt = { signal?: AbortSignal } & (
|
|
754
|
+
| { type: "text"; message: string; placeholder?: string }
|
|
755
|
+
| { type: "secret"; message: string; placeholder?: string }
|
|
756
|
+
| { type: "select"; message: string; options: readonly { id: string; label: string; description?: string }[] }
|
|
757
|
+
| { type: "manual_code"; message: string; placeholder?: string }
|
|
758
|
+
);
|
|
759
|
+
|
|
760
|
+
export type AuthEvent =
|
|
761
|
+
| { type: "info"; message: string; links?: readonly AuthInfoLink[] }
|
|
762
|
+
| { type: "auth_url"; url: string; instructions?: string }
|
|
763
|
+
| {
|
|
764
|
+
type: "device_code";
|
|
765
|
+
userCode: string;
|
|
766
|
+
verificationUri: string;
|
|
767
|
+
intervalSeconds?: number;
|
|
768
|
+
expiresInSeconds?: number;
|
|
769
|
+
}
|
|
770
|
+
| { type: "progress"; message: string };
|
|
771
|
+
|
|
772
|
+
export interface AuthInteraction {
|
|
773
|
+
signal?: AbortSignal;
|
|
774
|
+
prompt(prompt: AuthPrompt): Promise<string>;
|
|
775
|
+
notify(event: AuthEvent): void;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
export interface LoginProviderOptions {
|
|
779
|
+
/** Agent dir whose auth.json stores the credential. Defaults to the active agent dir. */
|
|
780
|
+
agentDir?: string;
|
|
781
|
+
/** Flow UI callbacks. Defaults to a terminal interaction (stdin prompts + browser). */
|
|
782
|
+
interaction?: AuthInteraction;
|
|
783
|
+
/** Cancels the flow. */
|
|
784
|
+
signal?: AbortSignal;
|
|
785
|
+
/** Force a login method; defaults to oauth when the provider offers it, then api_key. */
|
|
786
|
+
method?: AuthType;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
export declare function loginProvider(providerId: string, options?: LoginProviderOptions): Promise<Credential>;
|
|
790
|
+
|
|
791
|
+
/** Readline-based AuthInteraction for terminal use (prompts on stdin, auth URLs opened in the browser). */
|
|
792
|
+
export declare function createTerminalAuthInteraction(): AuthInteraction;
|
|
793
|
+
|
|
794
|
+
// ---------------------------------------------------------------------------
|
|
795
|
+
// roam settings store — the `roam` block of the base agent
|
|
796
|
+
// ~/.pi/agent/settings.json (resolved through the hub-profile layering, so CLI
|
|
797
|
+
// and embedded hosts share exactly one store). Auto-compaction threshold
|
|
798
|
+
// percent, context floor buffer and context window cap are the typed keys;
|
|
799
|
+
// readRoamSettings/updateRoamSettings expose the block generically for
|
|
800
|
+
// host-owned keys (e.g. a desktop app's defaultPermissionMode, theme, sidebar
|
|
801
|
+
// width). Re-exported from packages/plus/src/context/plus-settings.ts; the
|
|
802
|
+
// runtime bundle inlines the module.
|
|
803
|
+
// ---------------------------------------------------------------------------
|
|
804
|
+
|
|
805
|
+
export interface PlusSettings {
|
|
806
|
+
/** Percent (1-100) of the effective context window at which auto-compaction triggers. */
|
|
807
|
+
autoCompactThresholdPercent?: number;
|
|
808
|
+
/** Minimum floor buffer (tokens) for the effective context window (>= 13000). */
|
|
809
|
+
contextFloorTokens?: number;
|
|
810
|
+
/** Cap (tokens >= 32768) on the context window used for auto-compact math. */
|
|
811
|
+
contextWindowCapTokens?: number;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/** Raw roam block including host-owned keys; {} when absent or malformed. */
|
|
815
|
+
export declare function readRoamSettings(): Record<string, unknown>;
|
|
816
|
+
/** Merge keys into the roam block under the settings-file lock; a key set to
|
|
817
|
+
* undefined is deleted; all other settings.json content is preserved. */
|
|
818
|
+
export declare function updateRoamSettings(patch: Record<string, unknown | undefined>): void;
|
|
819
|
+
|
|
820
|
+
/** Default threshold: 80% of the effective context window. */
|
|
821
|
+
export declare const DEFAULT_AUTO_COMPACT_THRESHOLD_PERCENT: number;
|
|
822
|
+
export declare function getAutoCompactThresholdPercent(): number;
|
|
823
|
+
/** Persist a choice; undefined resets to the default (deletes the key). */
|
|
824
|
+
export declare function setAutoCompactThresholdPercent(percent: number | undefined): void;
|
|
825
|
+
export declare function formatAutoCompactThresholdPercent(percent: number): string;
|
|
826
|
+
export declare function parseAutoCompactThresholdChoice(choice: string): number;
|
|
827
|
+
|
|
828
|
+
/** Default/built-in minimum context floor buffer. */
|
|
829
|
+
export declare const DEFAULT_CONTEXT_FLOOR_TOKENS: number;
|
|
830
|
+
export declare const MIN_CONTEXT_FLOOR_TOKENS: number;
|
|
831
|
+
export declare function getContextFloorTokens(): number;
|
|
832
|
+
export declare function setContextFloorTokens(tokens: number | undefined): void;
|
|
833
|
+
export declare function formatContextFloorTokens(tokens: number): string;
|
|
834
|
+
export declare function parseContextFloorChoice(choice: string): number;
|
|
835
|
+
|
|
836
|
+
/** Lowest accepted context window cap; undefined means no cap. */
|
|
837
|
+
export declare const MIN_CONTEXT_WINDOW_CAP_TOKENS: number;
|
|
838
|
+
export declare function getContextWindowCapTokens(): number | undefined;
|
|
839
|
+
export declare function setContextWindowCapTokens(tokens: number | undefined): void;
|
|
840
|
+
export declare function formatContextWindowCapTokens(tokens: number | undefined): string;
|
|
841
|
+
export declare function parseContextWindowCapChoice(choice: string): number | undefined;
|