@zpi-dev/agent-sdk 0.0.0-stage → 0.1.60

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.
Files changed (150) hide show
  1. package/NOTICE +1206 -0
  2. package/README.md +54 -2
  3. package/dist/chunk-4WFFCN2C.js +29607 -0
  4. package/dist/chunk-4WFFCN2C.js.map +1 -0
  5. package/dist/chunk-AR5RMMMN.js +24353 -0
  6. package/dist/chunk-AR5RMMMN.js.map +1 -0
  7. package/dist/chunk-RAZL7ZAW.js +13451 -0
  8. package/dist/chunk-RAZL7ZAW.js.map +1 -0
  9. package/dist/chunk-TUOZKHGN.js +21 -0
  10. package/dist/chunk-TUOZKHGN.js.map +1 -0
  11. package/dist/chunk-YBW5XDR7.js +48 -0
  12. package/dist/chunk-YBW5XDR7.js.map +1 -0
  13. package/dist/host.d.ts +1 -0
  14. package/dist/host.js +34 -0
  15. package/dist/host.js.map +1 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +25 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/node-WXHENNL2.js +21 -0
  20. package/dist/node-WXHENNL2.js.map +1 -0
  21. package/dist/node-XSTAMDFW.js +2225 -0
  22. package/dist/node-XSTAMDFW.js.map +1 -0
  23. package/dist/src-7WDJXP5P.js +128 -0
  24. package/dist/src-7WDJXP5P.js.map +1 -0
  25. package/dist/types/agent/src/agent-loop.d.ts +3 -0
  26. package/dist/types/agent/src/agent.d.ts +21 -0
  27. package/dist/types/agent/src/index.d.ts +3 -0
  28. package/dist/types/agent/src/streaming-tool-coordinator.d.ts +10 -0
  29. package/dist/types/agent/src/tool-execution.d.ts +9 -0
  30. package/dist/types/agent/src/types.d.ts +144 -0
  31. package/dist/types/agent-sdk/src/hooks.d.ts +12 -0
  32. package/dist/types/agent-sdk/src/host.d.ts +4 -0
  33. package/dist/types/agent-sdk/src/index.d.ts +4 -0
  34. package/dist/types/agent-sdk/src/messages.d.ts +12 -0
  35. package/dist/types/agent-sdk/src/permissions.d.ts +10 -0
  36. package/dist/types/agent-sdk/src/query-result.d.ts +7 -0
  37. package/dist/types/agent-sdk/src/query.d.ts +6 -0
  38. package/dist/types/agent-sdk/src/resources.d.ts +16 -0
  39. package/dist/types/agent-sdk/src/runtime.d.ts +7 -0
  40. package/dist/types/agent-sdk/src/sessions.d.ts +48 -0
  41. package/dist/types/agent-sdk/src/tasks.d.ts +8 -0
  42. package/dist/types/agent-sdk/src/tools.d.ts +5 -0
  43. package/dist/types/agent-sdk/src/types.d.ts +428 -0
  44. package/dist/types/ai/src/api/anthropic-messages.d.ts +70 -0
  45. package/dist/types/ai/src/api/constrained-sampling.d.ts +5 -0
  46. package/dist/types/ai/src/api/github-copilot-headers.d.ts +7 -0
  47. package/dist/types/ai/src/api/openai-completions.d.ts +10 -0
  48. package/dist/types/ai/src/api/openai-responses.d.ts +5 -0
  49. package/dist/types/ai/src/api/responses-cache.d.ts +6 -0
  50. package/dist/types/ai/src/api/responses-events.d.ts +3 -0
  51. package/dist/types/ai/src/api/responses-session.d.ts +56 -0
  52. package/dist/types/ai/src/api/simple-options.d.ts +14 -0
  53. package/dist/types/ai/src/api/transform-messages.d.ts +3 -0
  54. package/dist/types/ai/src/auth/openai-chatgpt.d.ts +32 -0
  55. package/dist/types/ai/src/index.d.ts +20 -0
  56. package/dist/types/ai/src/providers/discovery.d.ts +14 -0
  57. package/dist/types/ai/src/providers/registry.d.ts +155 -0
  58. package/dist/types/ai/src/stream.d.ts +5 -0
  59. package/dist/types/ai/src/types.d.ts +394 -0
  60. package/dist/types/ai/src/utils/abort.d.ts +2 -0
  61. package/dist/types/ai/src/utils/context-breakdown.d.ts +3 -0
  62. package/dist/types/ai/src/utils/cost.d.ts +2 -0
  63. package/dist/types/ai/src/utils/diagnostics.d.ts +16 -0
  64. package/dist/types/ai/src/utils/error-body.d.ts +24 -0
  65. package/dist/types/ai/src/utils/estimate.d.ts +16 -0
  66. package/dist/types/ai/src/utils/event-stream.d.ts +15 -0
  67. package/dist/types/ai/src/utils/guard-model-stream.d.ts +3 -0
  68. package/dist/types/ai/src/utils/headers.d.ts +1 -0
  69. package/dist/types/ai/src/utils/json-parse.d.ts +7 -0
  70. package/dist/types/ai/src/utils/media-policy.d.ts +68 -0
  71. package/dist/types/ai/src/utils/model-performance.d.ts +23 -0
  72. package/dist/types/ai/src/utils/model-retry.d.ts +3 -0
  73. package/dist/types/ai/src/utils/option-map/compiler.d.ts +2 -0
  74. package/dist/types/ai/src/utils/option-map/evaluator.d.ts +3 -0
  75. package/dist/types/ai/src/utils/option-map/parser.d.ts +40 -0
  76. package/dist/types/ai/src/utils/option-map/tokenizer.d.ts +8 -0
  77. package/dist/types/ai/src/utils/option-map/types.d.ts +15 -0
  78. package/dist/types/ai/src/utils/overflow.d.ts +68 -0
  79. package/dist/types/ai/src/utils/provider-cache.d.ts +11 -0
  80. package/dist/types/ai/src/utils/provider-env.d.ts +2 -0
  81. package/dist/types/ai/src/utils/provider-retry.d.ts +17 -0
  82. package/dist/types/ai/src/utils/reasoning.d.ts +14 -0
  83. package/dist/types/ai/src/utils/redact-error.d.ts +2 -0
  84. package/dist/types/ai/src/utils/retry.d.ts +62 -0
  85. package/dist/types/ai/src/utils/sanitize-unicode.d.ts +21 -0
  86. package/dist/types/ai/src/utils/stream-idle-timeout.d.ts +36 -0
  87. package/dist/types/ai/src/utils/text.d.ts +9 -0
  88. package/dist/types/ai/src/utils/transcript.d.ts +41 -0
  89. package/dist/types/coding-agent/src/core/agent-session.d.ts +174 -0
  90. package/dist/types/coding-agent/src/core/commands.d.ts +19 -0
  91. package/dist/types/coding-agent/src/core/compaction-utils.d.ts +37 -0
  92. package/dist/types/coding-agent/src/core/compaction.d.ts +139 -0
  93. package/dist/types/coding-agent/src/core/file-rewind.d.ts +24 -0
  94. package/dist/types/coding-agent/src/core/fs.d.ts +1 -0
  95. package/dist/types/coding-agent/src/core/http-idle-timeout.d.ts +2 -0
  96. package/dist/types/coding-agent/src/core/image-limits.d.ts +19 -0
  97. package/dist/types/coding-agent/src/core/images.d.ts +18 -0
  98. package/dist/types/coding-agent/src/core/input.d.ts +3 -0
  99. package/dist/types/coding-agent/src/core/markdown-code.d.ts +7 -0
  100. package/dist/types/coding-agent/src/core/markdown.d.ts +13 -0
  101. package/dist/types/coding-agent/src/core/mentions.d.ts +12 -0
  102. package/dist/types/coding-agent/src/core/microcompact.d.ts +40 -0
  103. package/dist/types/coding-agent/src/core/model-performance.d.ts +57 -0
  104. package/dist/types/coding-agent/src/core/model-runtime.d.ts +51 -0
  105. package/dist/types/coding-agent/src/core/read-file-bounded.d.ts +2 -0
  106. package/dist/types/coding-agent/src/core/record-validation.d.ts +6 -0
  107. package/dist/types/coding-agent/src/core/resources.d.ts +51 -0
  108. package/dist/types/coding-agent/src/core/sdk.d.ts +50 -0
  109. package/dist/types/coding-agent/src/core/session-manager.d.ts +137 -0
  110. package/dist/types/coding-agent/src/core/session-state.d.ts +14 -0
  111. package/dist/types/coding-agent/src/core/settings-manager.d.ts +41 -0
  112. package/dist/types/coding-agent/src/core/streaming-tool-journal.d.ts +17 -0
  113. package/dist/types/coding-agent/src/core/system-prompt.d.ts +25 -0
  114. package/dist/types/coding-agent/src/core/tools/file-change.d.ts +21 -0
  115. package/dist/types/coding-agent/src/core/tools/index.d.ts +20 -0
  116. package/dist/types/coding-agent/src/core/tools/pi/bash.d.ts +185 -0
  117. package/dist/types/coding-agent/src/core/tools/pi/edit-diff.d.ts +84 -0
  118. package/dist/types/coding-agent/src/core/tools/pi/edit.d.ts +69 -0
  119. package/dist/types/coding-agent/src/core/tools/pi/file-mutation-queue.d.ts +5 -0
  120. package/dist/types/coding-agent/src/core/tools/pi/file-read-state.d.ts +12 -0
  121. package/dist/types/coding-agent/src/core/tools/pi/output-accumulator.d.ts +68 -0
  122. package/dist/types/coding-agent/src/core/tools/pi/path-utils.d.ts +7 -0
  123. package/dist/types/coding-agent/src/core/tools/pi/read.d.ts +63 -0
  124. package/dist/types/coding-agent/src/core/tools/pi/text-range-reader.d.ts +22 -0
  125. package/dist/types/coding-agent/src/core/tools/pi/tool-definition-wrapper.d.ts +4 -0
  126. package/dist/types/coding-agent/src/core/tools/pi/truncate.d.ts +60 -0
  127. package/dist/types/coding-agent/src/core/tools/pi/utils/bmp-source.d.ts +2 -0
  128. package/dist/types/coding-agent/src/core/tools/pi/utils/child-process.d.ts +13 -0
  129. package/dist/types/coding-agent/src/core/tools/pi/utils/image-budget.d.ts +16 -0
  130. package/dist/types/coding-agent/src/core/tools/pi/utils/image-process.d.ts +18 -0
  131. package/dist/types/coding-agent/src/core/tools/pi/utils/image-resize-core.d.ts +26 -0
  132. package/dist/types/coding-agent/src/core/tools/pi/utils/image-resize.d.ts +3 -0
  133. package/dist/types/coding-agent/src/core/tools/pi/utils/image-source.d.ts +11 -0
  134. package/dist/types/coding-agent/src/core/tools/pi/utils/mime.d.ts +3 -0
  135. package/dist/types/coding-agent/src/core/tools/pi/utils/paths.d.ts +16 -0
  136. package/dist/types/coding-agent/src/core/tools/pi/utils/read-file.d.ts +2 -0
  137. package/dist/types/coding-agent/src/core/tools/pi/utils/shell.d.ts +18 -0
  138. package/dist/types/coding-agent/src/core/tools/pi/utils/text.d.ts +5 -0
  139. package/dist/types/coding-agent/src/core/tools/pi/write.d.ts +44 -0
  140. package/dist/types/coding-agent/src/core/transcript-store.d.ts +71 -0
  141. package/dist/types/coding-agent/src/core/types.d.ts +60 -0
  142. package/dist/types/coding-agent/src/index.d.ts +42 -0
  143. package/dist/types/coding-agent/src/plugins/assembly.d.ts +37 -0
  144. package/dist/types/coding-agent/src/plugins/hooks.d.ts +82 -0
  145. package/dist/types/coding-agent/src/plugins/resources.d.ts +4 -0
  146. package/dist/types/coding-agent/src/plugins/session-hooks.d.ts +26 -0
  147. package/dist/types/coding-agent/src/plugins/types.d.ts +40 -0
  148. package/dist/types/plugin-compat/src/command-hooks.d.ts +184 -0
  149. package/dist/types/plugin-compat/src/index.d.ts +11 -0
  150. package/package.json +53 -4
@@ -0,0 +1,19 @@
1
+ export declare const localCommands: readonly [{
2
+ readonly name: "compact";
3
+ readonly description: "摘要旧对话,保留完整历史";
4
+ }];
5
+ export declare function listCommands(commands?: readonly {
6
+ name: string;
7
+ description: string;
8
+ }[]): {
9
+ name: string;
10
+ description: string;
11
+ }[];
12
+ export type ParsedInput = {
13
+ kind: "prompt";
14
+ text: string;
15
+ } | {
16
+ kind: "compact";
17
+ args: string;
18
+ };
19
+ export declare function parseInput(text: string): ParsedInput;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Shared utilities for compaction and branch summarization.
3
+ */
4
+ import type { Message as AgentMessage } from "../../../ai/src/index.js";
5
+ import { type Message } from "../../../ai/src/index.js";
6
+ export interface FileOperations {
7
+ read: Set<string>;
8
+ written: Set<string>;
9
+ edited: Set<string>;
10
+ }
11
+ export declare function createFileOps(): FileOperations;
12
+ /**
13
+ * Extract file operations from tool calls in an assistant message.
14
+ */
15
+ export declare function extractFileOpsFromMessage(message: AgentMessage, fileOps: FileOperations): void;
16
+ /**
17
+ * Compute final file lists from file operations.
18
+ * Returns readFiles (files only read, not modified) and modifiedFiles.
19
+ */
20
+ export declare function computeFileLists(fileOps: FileOperations): {
21
+ readFiles: string[];
22
+ modifiedFiles: string[];
23
+ };
24
+ /**
25
+ * Format file operations as XML tags for summary.
26
+ */
27
+ export declare function formatFileOperations(readFiles: string[], modifiedFiles: string[]): string;
28
+ /**
29
+ * Serialize LLM messages to text for summarization.
30
+ * This prevents the model from treating it as a conversation to continue.
31
+ * Call convertToLlm() first to handle custom message types.
32
+ *
33
+ * Tool results are truncated to keep the summarization request within
34
+ * reasonable token budgets. Full content is not needed for summarization.
35
+ */
36
+ export declare function serializeConversation(messages: Message[]): string;
37
+ export declare const SUMMARIZATION_SYSTEM_PROMPT = "You are a context summarization assistant. Your task is to read a conversation between a user and an AI assistant, then produce a structured summary following the exact format specified.\n\nDo NOT continue the conversation. Do NOT respond to any questions in the conversation. ONLY output the structured summary.";
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Context compaction for long sessions.
3
+ *
4
+ * Pure functions for compaction logic. The session manager handles I/O,
5
+ * and after compaction the session is reloaded.
6
+ */
7
+ import type { AgentMessage, StreamFn, ThinkingLevel } from "../../../agent/src/index.js";
8
+ import type { AssistantMessage, Model, SimpleStreamOptions, TranscriptContext, Usage } from "../../../ai/src/index.js";
9
+ import { calculateContextTokens, type RetryCallbacks, type RetryPolicy } from "../../../ai/src/index.js";
10
+ import { type FileOperations } from "./compaction-utils.js";
11
+ import { type SessionEntry } from "./session-manager.js";
12
+ /** Details stored in CompactionEntry.details for file tracking */
13
+ export interface CompactionDetails {
14
+ readFiles: string[];
15
+ modifiedFiles: string[];
16
+ }
17
+ /** Result from compact() - SessionManager adds uuid/parentUuid when saving */
18
+ export interface CompactionResult<T = unknown> {
19
+ summary: string;
20
+ firstKeptEntryId: string;
21
+ tokensBefore: number;
22
+ estimatedTokensAfter?: number;
23
+ /** Usage from the LLM call(s) that generated this summary, if available */
24
+ usage?: Usage;
25
+ /** Extension-specific data (e.g., ArtifactIndex, version markers for structured compaction) */
26
+ details?: T;
27
+ }
28
+ export interface CompactionSettings {
29
+ enabled: boolean;
30
+ reserveTokens: number;
31
+ keepRecentTokens: number;
32
+ }
33
+ export declare const DEFAULT_COMPACTION_SETTINGS: CompactionSettings;
34
+ export { calculateContextTokens };
35
+ export interface ContextUsageEstimate {
36
+ tokens: number;
37
+ usageTokens: number;
38
+ trailingTokens: number;
39
+ lastUsageIndex: number | null;
40
+ }
41
+ /**
42
+ * Estimate context tokens from messages, using the last assistant usage when available.
43
+ * If there are messages after the last usage, estimate their tokens with estimateTokens.
44
+ */
45
+ export declare function estimateContextTokens(messages: AgentMessage[]): ContextUsageEstimate;
46
+ /**
47
+ * Check if compaction should trigger based on context usage.
48
+ */
49
+ export declare function shouldCompact(contextTokens: number, contextWindow: number, settings: CompactionSettings): boolean;
50
+ /**
51
+ * Estimate token count for a message using chars/4 heuristic.
52
+ * This is conservative (overestimates tokens).
53
+ */
54
+ export declare function estimateTokens(message: AgentMessage): number;
55
+ /**
56
+ * Find the context-visible user-role message that starts the turn containing the given entry index.
57
+ * Returns -1 if no turn start found before the index.
58
+ */
59
+ export declare function findTurnStartIndex(entries: SessionEntry[], entryIndex: number, startIndex: number): number;
60
+ export interface CutPointResult {
61
+ /** Index of first entry to keep */
62
+ firstKeptEntryIndex: number;
63
+ /** Index of user message that starts the turn being split, or -1 if not splitting */
64
+ turnStartIndex: number;
65
+ /** Whether this cut splits a turn (cut point is not a user message) */
66
+ isSplitTurn: boolean;
67
+ }
68
+ /**
69
+ * Find the cut point in session entries that keeps approximately `keepRecentTokens`.
70
+ *
71
+ * Algorithm: Walk backwards from newest, accumulating estimated message sizes.
72
+ * Stop when we've accumulated >= keepRecentTokens. Cut at that point.
73
+ *
74
+ * Can cut at user OR assistant messages (never tool results). When cutting at an
75
+ * assistant message with tool calls, its tool results come after and will be kept.
76
+ *
77
+ * Returns CutPointResult with:
78
+ * - firstKeptEntryIndex: the entry index to start keeping from
79
+ * - turnStartIndex: if cutting mid-turn, the user message that started that turn
80
+ * - isSplitTurn: whether we're cutting in the middle of a turn
81
+ *
82
+ * Only considers entries between `startIndex` and `endIndex` (exclusive).
83
+ */
84
+ export declare function findCutPoint(entries: SessionEntry[], startIndex: number, endIndex: number, keepRecentTokens: number, forceProgress?: boolean): CutPointResult;
85
+ /**
86
+ * Returns an error message when a summarization response cannot safely be persisted.
87
+ * A length stop contains partial text and must not become a session checkpoint.
88
+ */
89
+ export declare function getSummarizationFailure(response: AssistantMessage, label: string): string | undefined;
90
+ /**
91
+ * Shared choke point for every compaction/branch-summary summarization call. Wraps the
92
+ * single LLM call in {@link retryAssistantCall} so transient stream drops (e.g.
93
+ * `terminated`, socket close) honor the configured retry policy instead of failing
94
+ * the whole compaction on the first attempt. Deterministic errors and aborts return
95
+ * immediately (see {@link retryAssistantCall}).
96
+ */
97
+ export declare function completeSummarization(model: Model, context: TranscriptContext, options: SimpleStreamOptions, streamFn?: StreamFn, retry?: RetryPolicy, callbacks?: RetryCallbacks): Promise<AssistantMessage>;
98
+ /** Generate or update a conversation summary and return its provider usage. */
99
+ export declare function generateSummaryWithUsage(currentMessages: AgentMessage[], model: Model, reserveTokens: number, apiKey: string | undefined, headers?: Record<string, string>, signal?: AbortSignal, customInstructions?: string, previousSummary?: string, thinkingLevel?: ThinkingLevel, streamFn?: StreamFn, retry?: RetryPolicy, callbacks?: RetryCallbacks, sessionId?: string, onMediaProjection?: SimpleStreamOptions["onMediaProjection"]): Promise<{
100
+ text: string;
101
+ usage: Usage;
102
+ }>;
103
+ export interface CompactionPreparation {
104
+ /** UUID of first entry to keep */
105
+ firstKeptEntryId: string;
106
+ /** Messages that will be summarized and discarded */
107
+ messagesToSummarize: AgentMessage[];
108
+ /** Messages that will be turned into turn prefix summary (if splitting) */
109
+ turnPrefixMessages: AgentMessage[];
110
+ /** Whether this is a split turn (cut point in middle of turn) */
111
+ isSplitTurn: boolean;
112
+ tokensBefore: number;
113
+ /** Summary from previous compaction, for iterative update */
114
+ previousSummary?: string;
115
+ /** File operations extracted from messagesToSummarize */
116
+ fileOps: FileOperations;
117
+ /** Compaction settions from settings.jsonl */
118
+ settings: CompactionSettings;
119
+ }
120
+ export declare function prepareCompaction(pathEntries: SessionEntry[], settings: CompactionSettings): CompactionPreparation | undefined;
121
+ /**
122
+ * Generate summaries for compaction using prepared data.
123
+ * Returns CompactionResult - SessionManager adds uuid/parentUuid when saving.
124
+ *
125
+ * @param preparation - Pre-calculated preparation from prepareCompaction()
126
+ * @param customInstructions - Optional custom focus for the summary
127
+ * @param sessionId - Optional routing session ID forwarded without enabling prompt caching
128
+ */
129
+ export declare function compact(preparation: CompactionPreparation, model: Model, apiKey: string | undefined, headers?: Record<string, string>, customInstructions?: string, signal?: AbortSignal, thinkingLevel?: ThinkingLevel, streamFn?: StreamFn, retry?: RetryPolicy, callbacks?: RetryCallbacks, sessionId?: string, onMediaProjection?: SimpleStreamOptions["onMediaProjection"]): Promise<CompactionResult>;
130
+ export interface CompactionOptions {
131
+ microcompact?: import("./microcompact.js").MicrocompactConfig;
132
+ enabled?: boolean;
133
+ reserveTokens?: number;
134
+ keepRecentTokens?: number;
135
+ modelOverrides?: Record<string, {
136
+ reserveTokens?: number;
137
+ keepRecentTokens?: number;
138
+ }>;
139
+ }
@@ -0,0 +1,24 @@
1
+ import type { FileChange } from "./tools/file-change.js";
2
+ export interface FileRewindConflict {
3
+ path: string;
4
+ reason: string;
5
+ }
6
+ export interface FileRewindOptions {
7
+ checkPath?(path: string): void | Promise<void>;
8
+ readCheckpoint?(path: string): Promise<Buffer>;
9
+ }
10
+ interface RestoreFile {
11
+ path: string;
12
+ before: Buffer | null;
13
+ current: Buffer;
14
+ mode: number;
15
+ }
16
+ export interface FileRewindPlan {
17
+ files: RestoreFile[];
18
+ conflicts: FileRewindConflict[];
19
+ }
20
+ /** Preflight every checkpoint before touching any workspace file or conversation entry. */
21
+ export declare function planFileRewind(changes: readonly FileChange[], options?: FileRewindOptions): Promise<FileRewindPlan>;
22
+ /** Keep workspace and transcript together; roll workspace back if the transcript cannot commit. */
23
+ export declare function applyFileRewind(plan: FileRewindPlan, commit: () => void | Promise<void>): Promise<FileRewindConflict[]>;
24
+ export {};
@@ -0,0 +1 @@
1
+ export declare function syncDirectory(path: string): void;
@@ -0,0 +1,2 @@
1
+ /** Pi's header/body idle timeout, adapted for both Node fetch and Electron net.fetch. */
2
+ export declare function withHttpIdleTimeout(requestFetch: typeof fetch, timeoutMs: number): typeof fetch;
@@ -0,0 +1,19 @@
1
+ export declare const READ_MAX_OUTPUT_TOKENS = 25000;
2
+ export declare const READ_IMAGE_MAX_BASE64_BYTES: number;
3
+ export declare const READ_IMAGE_TARGET_BYTES: number;
4
+ export declare const READ_IMAGE_MAX_DIMENSION = 2000;
5
+ export declare const READ_IMAGE_MAX_INPUT_BYTES: number;
6
+ export declare const READ_IMAGE_TOKEN_TO_BASE64_CHAR_RATIO = 0.125;
7
+ export declare const READ_IMAGE_EFFECTIVE_BASE64_BYTES: number;
8
+ export declare const imageLimits: {
9
+ /** Imported and cached attachment originals. */
10
+ readonly sourceBytes: number;
11
+ /** Local/remote read-tool image inputs; attachments retain their stricter import cap. */
12
+ readonly readSourceBytes: number;
13
+ readonly count: 8;
14
+ readonly pixels: 40000000;
15
+ readonly messagePixels: 80000000;
16
+ };
17
+ import type { Attachment, ImageAttachment } from "../../../ai/src/index.js";
18
+ export type { Attachment, FileAttachment, ImageAttachment } from "../../../ai/src/index.js";
19
+ export declare function isImageAttachment(attachment: Attachment): attachment is ImageAttachment;
@@ -0,0 +1,18 @@
1
+ import type { ImageContent } from "../../../ai/src/index.js";
2
+ export { processImage as prepareInlineImage } from "./tools/pi/utils/image-process.js";
3
+ export { imageFormat } from "./tools/pi/utils/image-source.js";
4
+ /** Validate source bytes without creating a base64 copy for cache/import metadata. */
5
+ export declare function validateImageSource(bytes: Uint8Array): Promise<{
6
+ mimeType: string;
7
+ width: number;
8
+ height: number;
9
+ warning?: string | undefined;
10
+ }>;
11
+ /** Validate and retain the source for previews. Use prepareInlineImage before sending to a model. */
12
+ export declare function processImage(bytes: Uint8Array): Promise<{
13
+ bytes: Buffer;
14
+ image: ImageContent;
15
+ width: number;
16
+ height: number;
17
+ warning?: string;
18
+ }>;
@@ -0,0 +1,3 @@
1
+ export * from "./image-limits.js";
2
+ export * from "./markdown-code.js";
3
+ export * from "./mentions.js";
@@ -0,0 +1,7 @@
1
+ export interface MarkdownFence {
2
+ marker: string;
3
+ length: number;
4
+ }
5
+ /** Return a valid opening or closing fence for the current Markdown code block. */
6
+ export declare function markdownFence(line: string, active: MarkdownFence | null): MarkdownFence | null;
7
+ export declare function codeRanges(content: string, includeInline?: boolean): Array<[number, number]>;
@@ -0,0 +1,13 @@
1
+ import { type JsonObject } from "../../../ai/src/index.js";
2
+ export interface MarkdownFrontmatter {
3
+ fields: JsonObject;
4
+ body: string;
5
+ bodyOffset: number;
6
+ }
7
+ /** Match closed fences without parsing YAML, including during bounded metadata discovery. */
8
+ export declare function matchMarkdownFrontmatter(text: string): {
9
+ yaml: string;
10
+ bodyOffset: number;
11
+ } | undefined;
12
+ /** Syntax only: callers own required fields and whether frontmatter is mandatory. */
13
+ export declare function parseMarkdownFrontmatter(text: string): MarkdownFrontmatter | undefined;
@@ -0,0 +1,12 @@
1
+ export interface Mention {
2
+ kind: "file" | "skill" | "session";
3
+ label: string;
4
+ path: string;
5
+ start: number;
6
+ end: number;
7
+ markdown: string;
8
+ }
9
+ export declare function buildMentionMarkdown(label: string, path: string): string;
10
+ export declare function buildSessionMentionMarkdown(sessionId: string, label?: string): string;
11
+ export declare function extractSessionReferences(text: string): string[];
12
+ export declare function parseMentions(text: string): Mention[];
@@ -0,0 +1,40 @@
1
+ import { type Message } from "../../../ai/src/index.js";
2
+ export declare const MICROCOMPACT_CLEARED_TOOL_RESULT_MESSAGE = "[Old tool result content cleared]";
3
+ export declare const DEFAULT_MICROCOMPACT_KEEP_RECENT_TOOL_RESULTS = 5;
4
+ export declare const DEFAULT_MICROCOMPACT_IDLE_THRESHOLD_MINUTES = 60;
5
+ export declare const DEFAULT_MICROCOMPACT_MIN_TOKEN_SAVINGS = 256;
6
+ export declare const DEFAULT_MICROCOMPACT_COMPACTABLE_TOOLS: readonly ["Read", "Bash", "Grep", "Glob", "WebFetch", "WebSearch", "Edit", "Write", "ApplyPatch"];
7
+ export interface MicrocompactConfig {
8
+ enabled?: boolean;
9
+ thresholdTokens?: number;
10
+ idleThresholdMinutes?: number;
11
+ keepRecentToolResults?: number;
12
+ compactableToolNames?: readonly string[];
13
+ clearErrorResults?: boolean;
14
+ minTokenSavings?: number;
15
+ }
16
+ export interface MicrocompactBoundary {
17
+ trigger: "time_based" | "token_pressure";
18
+ strategy: "local_tool_result_clear";
19
+ preMicrocompactTokenCount: number;
20
+ postMicrocompactTokenCount: number;
21
+ tokensSaved: number;
22
+ clearedMessageCount: number;
23
+ clearedToolCallIds: string[];
24
+ keptToolCallIds: string[];
25
+ }
26
+ export declare function buildDefaultMicrocompactThreshold(autoCompactThreshold: number): number;
27
+ export declare function applyMicrocompactBoundary(messages: Message[], clearedToolCallIds: readonly string[]): Message[];
28
+ export declare function maybeMicrocompact(input: {
29
+ messages: Message[];
30
+ config?: MicrocompactConfig;
31
+ lastAssistantCompletedAtMs?: number;
32
+ nowMs?: number;
33
+ }): {
34
+ messages: Message[];
35
+ boundary?: MicrocompactBoundary;
36
+ };
37
+ export declare function microcompactClearedIds(entry: {
38
+ type: string;
39
+ data?: unknown;
40
+ }): string[];
@@ -0,0 +1,57 @@
1
+ import type { AssistantMessage, ModelPerformanceSample } from "../../../ai/src/index.js";
2
+ export interface ModelPerformance {
3
+ turns?: number;
4
+ steps?: number;
5
+ llmMs?: number;
6
+ toolMs?: number;
7
+ ttftMs?: number;
8
+ tokensPerSecond?: number;
9
+ inputTokens?: number;
10
+ outputTokens?: number;
11
+ cacheReadTokens?: number;
12
+ cacheWriteTokens?: number;
13
+ cacheHitRate?: number;
14
+ }
15
+ /** Constant-size, committed task totals. No prompts or generated content are retained. */
16
+ export declare const emptyPerformanceTotals: () => {
17
+ turns: number;
18
+ steps: number;
19
+ llmMs: number;
20
+ toolMs: number;
21
+ ttftMs: number;
22
+ ttftCount: number;
23
+ decodeMs: number;
24
+ decodeTokens: number;
25
+ inputTokens: number;
26
+ outputTokens: number;
27
+ cacheReadTokens: number;
28
+ cacheWriteTokens: number;
29
+ usageCount: number;
30
+ cacheCount: number;
31
+ };
32
+ export type ModelPerformanceTotals = ReturnType<typeof emptyPerformanceTotals> & {
33
+ turnsKnown?: false;
34
+ };
35
+ export declare function validPerformanceTotals(value: unknown): value is ModelPerformanceTotals;
36
+ export declare function modelPerformance(t: ModelPerformanceTotals): ModelPerformance;
37
+ /** Like the Harness dock, publish settled requests; keep prior readings while streaming. */
38
+ export declare class SessionPerformance {
39
+ private totals;
40
+ private epoch;
41
+ private countedTurn;
42
+ private tools;
43
+ private changed;
44
+ constructor(changed: (value: ModelPerformance, totals: ModelPerformanceTotals) => void, initial?: ModelPerformanceTotals);
45
+ get value(): ModelPerformance;
46
+ get snapshot(): ModelPerformanceTotals;
47
+ begin(): void;
48
+ request(): {
49
+ update: (next: ModelPerformanceSample) => void;
50
+ finish: (success: boolean, message?: Pick<AssistantMessage, "usage" | "usageAvailable" | "cacheUsageAvailable">) => void;
51
+ };
52
+ toolStart(id: string): void;
53
+ toolEnd(id: string): void;
54
+ settle(): void;
55
+ dispose(): void;
56
+ private publish;
57
+ }
@@ -0,0 +1,51 @@
1
+ import type { Api, AssistantMessageEventStream, Context, MediaBudgetStats, Model, ResponsesSessionDiagnostic, ResponsesSessionOptions, SimpleStreamOptions, TranscriptContext } from "../../../ai/src/index.js";
2
+ export interface ProviderChatModelConfig extends Omit<Model, "provider" | "api" | "baseUrl"> {
3
+ type?: "chat";
4
+ api?: Api;
5
+ }
6
+ export interface ProviderConfigInput {
7
+ name?: string;
8
+ baseUrl?: string;
9
+ api?: Api;
10
+ apiKey?: string;
11
+ /** A rejected key requests one credential recovery; other callers resolve normally. */
12
+ getApiKey?: (rejectedApiKey?: string) => Promise<string>;
13
+ headers?: Record<string, string>;
14
+ models?: ProviderChatModelConfig[];
15
+ streamSimple?: (model: Model, context: TranscriptContext, options?: SimpleStreamOptions) => AssistantMessageEventStream;
16
+ }
17
+ export interface MediaProjectionContext {
18
+ sessionId?: string;
19
+ provider: string;
20
+ modelId: string;
21
+ }
22
+ export interface ModelRuntimeOptions {
23
+ fetch?: typeof fetch;
24
+ /** Custom fetch implementations use HTTP unless the host explicitly enables WebSocket connections. */
25
+ responsesTransport?: "auto" | "http";
26
+ responsesProxy?: ResponsesSessionOptions["resolveProxy"];
27
+ /** Optional local diagnostics; the SDK has no dependency on a logging backend. */
28
+ onMediaProjection?: (stats: MediaBudgetStats, context: MediaProjectionContext) => void;
29
+ onResponsesDiagnostic?: (diagnostic: ResponsesSessionDiagnostic, context: MediaProjectionContext) => void;
30
+ }
31
+ export declare class ModelRuntime {
32
+ private providers;
33
+ private keys;
34
+ private requestFetch?;
35
+ private onMediaProjection?;
36
+ private onResponsesDiagnostic?;
37
+ private responsesTransport;
38
+ readonly responsesProxy?: ResponsesSessionOptions["resolveProxy"];
39
+ constructor(requestFetch?: typeof fetch, options?: ModelRuntimeOptions);
40
+ get fetch(): typeof fetch;
41
+ canUseResponsesSession(model: Model): boolean;
42
+ static create(options?: ModelRuntimeOptions): Promise<ModelRuntime>;
43
+ mediaProjectionObserver(model: Model, sessionId?: string): SimpleStreamOptions["onMediaProjection"];
44
+ responsesDiagnosticObserver(model: Model, sessionId?: string): ResponsesSessionOptions["onDiagnostic"];
45
+ clearProviders(): void;
46
+ registerProvider(id: string, config: ProviderConfigInput): void;
47
+ getModel(provider: string, id: string): Model | undefined;
48
+ getAvailable(): Promise<readonly Model[]>;
49
+ setRuntimeApiKey(provider: string, key: string): Promise<void>;
50
+ streamSimple(model: Model, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;
51
+ }
@@ -0,0 +1,2 @@
1
+ /** Read at most maxBytes + 1, including when a file grows after it was inspected. */
2
+ export declare function readFileBounded(path: string, maxBytes: number): Promise<Buffer>;
@@ -0,0 +1,6 @@
1
+ import type { Message } from "../../../ai/src/index.js";
2
+ import type { SessionEntry, SessionHeader } from "./session-manager.js";
3
+ export declare const maxSessionEntryBytes: number;
4
+ export declare function isSessionHeader(value: unknown): value is SessionHeader;
5
+ export declare function isSessionEntry(value: unknown): value is SessionEntry;
6
+ export declare function validateMessage(value: unknown): asserts value is Message;
@@ -0,0 +1,51 @@
1
+ import type { ResourceDiagnostic, ResourceLoader } from "./types.js";
2
+ export interface SkillMetadata {
3
+ name: string;
4
+ description: string;
5
+ path: string;
6
+ baseDir: string;
7
+ source: "user" | "project" | "plugin";
8
+ }
9
+ export interface DiscoveredSkill extends SkillMetadata {
10
+ enabled: boolean;
11
+ overriddenBy?: string;
12
+ }
13
+ export interface SkillPolicyOptions {
14
+ projectDir: string;
15
+ homeDir?: string;
16
+ projectResources?: boolean;
17
+ isSkillEnabled?: (path: string) => boolean;
18
+ }
19
+ export interface SkillList {
20
+ skills: SkillMetadata[];
21
+ diagnostics: ResourceDiagnostic[];
22
+ }
23
+ export interface LoadedSkill extends SkillMetadata {
24
+ body: string;
25
+ }
26
+ export declare class SkillCatalog {
27
+ private discovered;
28
+ private winners;
29
+ private catalog;
30
+ constructor(privateOptions: SkillPolicyOptions);
31
+ private options;
32
+ reload(): Promise<void>;
33
+ listSkills(): SkillList;
34
+ listDiscoveredSkills(): DiscoveredSkill[];
35
+ loadSkill(name: string): Promise<LoadedSkill>;
36
+ }
37
+ export declare class FileResourceLoader implements ResourceLoader {
38
+ private options;
39
+ private catalog;
40
+ private instructions;
41
+ private diagnostics;
42
+ constructor(options: SkillPolicyOptions);
43
+ getBaseInstructions(): undefined;
44
+ getInstructions(): string[];
45
+ reload(): Promise<void>;
46
+ listSkills(): SkillList;
47
+ listDiscoveredSkills(): DiscoveredSkill[];
48
+ loadSkill(name: string): Promise<LoadedSkill>;
49
+ getDiagnostics(): ResourceDiagnostic[];
50
+ }
51
+ export declare function formatSkillsForPrompt(skills: SkillMetadata[], tool?: "read" | "bash"): string;
@@ -0,0 +1,50 @@
1
+ import type { AgentTool, ThinkingLevel } from "../../../agent/src/index.js";
2
+ import type { Context, Model } from "../../../ai/src/index.js";
3
+ import { type SessionContributions } from "../plugins/assembly.js";
4
+ import type { HookRegistration } from "../plugins/hooks.js";
5
+ import { AgentSession } from "./agent-session.js";
6
+ import type { CompactionOptions } from "./compaction.js";
7
+ import type { ModelPerformanceTotals } from "./model-performance.js";
8
+ import { ModelRuntime } from "./model-runtime.js";
9
+ import { SessionManager } from "./session-manager.js";
10
+ import { SettingsManager } from "./settings-manager.js";
11
+ import { type PromptTemplate } from "./system-prompt.js";
12
+ import type { ResourceLoader } from "./types.js";
13
+ export interface SystemPromptContext {
14
+ tools: readonly AgentTool[];
15
+ pluginInstructions: readonly string[];
16
+ resourceLoader: ResourceLoader;
17
+ }
18
+ export interface CreateAgentSessionOptions extends SessionContributions {
19
+ /** Build tool definitions and selection once the shared resource catalog is loaded. */
20
+ prepareTools?: (loader: ResourceLoader) => Pick<SessionContributions, "customTools" | "tools">;
21
+ modelRequestOptions?: () => import("../../../ai/src/index.js").SimpleStreamOptions;
22
+ onCompaction?: (phase: "before" | "after", context: {
23
+ manual: boolean;
24
+ instructions: string;
25
+ }, signal?: AbortSignal) => Promise<void>;
26
+ /** Explicit complete prompt, evaluated again after resource refresh. */
27
+ systemPrompt?: string | ((context: SystemPromptContext) => string);
28
+ /** Host policy checked at each foreground model request, including continuation requests. */
29
+ beforeModelRequest?: (model: Model, context: Context) => void;
30
+ hooks?: readonly HookRegistration[];
31
+ modelPerformanceTotals?: ModelPerformanceTotals;
32
+ cwd?: string;
33
+ agentDir?: string;
34
+ modelRuntime?: ModelRuntime;
35
+ model?: Model;
36
+ thinkingLevel?: ThinkingLevel;
37
+ /** Literal additions, recomputed after resource reload when supplied as a function. */
38
+ customInstructions?: readonly string[] | (() => readonly string[]);
39
+ resourceLoader?: ResourceLoader;
40
+ sessionManager?: SessionManager;
41
+ homeDir?: string;
42
+ compaction?: CompactionOptions;
43
+ settingsManager?: SettingsManager;
44
+ promptTemplate?: () => PromptTemplate;
45
+ projectName?: string | (() => string);
46
+ }
47
+ export interface CreateAgentSessionResult {
48
+ session: AgentSession;
49
+ }
50
+ export declare function createAgentSession(options?: CreateAgentSessionOptions): Promise<CreateAgentSessionResult>;