bashkit 0.5.0 → 0.5.2
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/dist/index.d.ts +3 -3
- package/dist/index.js +473 -255
- package/dist/tools/index.d.ts +3 -1
- package/dist/tools/task.d.ts +3 -0
- package/dist/tools/web-constants.d.ts +5 -0
- package/dist/types.d.ts +27 -3
- package/dist/utils/budget-tracking.d.ts +19 -0
- package/dist/utils/compact-conversation.d.ts +72 -2
- package/dist/utils/context-status.d.ts +2 -0
- package/dist/utils/debug.d.ts +5 -6
- package/dist/utils/helpers.d.ts +21 -0
- package/dist/utils/index.d.ts +3 -2
- package/package.json +1 -1
- package/dist/cloudflare/index.d.ts +0 -20
- package/dist/cloudflare/index.js +0 -1251
- package/dist/durable/durable-session.d.ts +0 -220
- package/dist/durable/index.d.ts +0 -41
- package/dist/durable/index.js +0 -159
- package/dist/durable/schema.d.ts +0 -51
- package/dist/durable/types.d.ts +0 -208
- package/dist/react/index.d.ts +0 -42
- package/dist/react/index.js +0 -10
- package/dist/react/types.d.ts +0 -333
- package/dist/react/use-agent.d.ts +0 -33
- package/dist/react/use-durable-chat.d.ts +0 -39
- package/dist/workflow.d.ts +0 -52
- package/dist/workflow.js +0 -1051
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ToolSet } from "ai";
|
|
2
2
|
import type { Sandbox } from "../sandbox/interface";
|
|
3
3
|
import type { AgentConfig } from "../types";
|
|
4
|
-
import { type BudgetTracker } from "../utils/budget-tracking";
|
|
4
|
+
import { type BudgetTracker, type ModelInfo } from "../utils/budget-tracking";
|
|
5
5
|
import { type PlanModeState } from "./enter-plan-mode";
|
|
6
6
|
/**
|
|
7
7
|
* Result from createAgentTools including tools and optional shared state.
|
|
@@ -13,6 +13,8 @@ export interface AgentToolsResult {
|
|
|
13
13
|
planModeState?: PlanModeState;
|
|
14
14
|
/** Budget tracker (only present when budget config is set) */
|
|
15
15
|
budget?: BudgetTracker;
|
|
16
|
+
/** Model info from OpenRouter (only present when modelRegistry or budget pricingProvider is configured) */
|
|
17
|
+
openRouterModels?: Map<string, ModelInfo>;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Creates agent tools for AI SDK's generateText/streamText.
|
package/dist/tools/task.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -94,16 +94,37 @@ export type CacheConfig = boolean | CacheStore | {
|
|
|
94
94
|
* Supported pricing providers for automatic model cost lookup.
|
|
95
95
|
*/
|
|
96
96
|
export type PricingProvider = "openRouter";
|
|
97
|
+
/**
|
|
98
|
+
* Supported model registry providers.
|
|
99
|
+
* Add new providers here as union types (e.g., 'openRouter' | 'together')
|
|
100
|
+
*/
|
|
101
|
+
export type ModelRegistryProvider = "openRouter";
|
|
102
|
+
/**
|
|
103
|
+
* Configuration for fetching model info (pricing + context lengths) from a provider.
|
|
104
|
+
* Used by budget tracking and compaction.
|
|
105
|
+
*/
|
|
106
|
+
export type ModelRegistryConfig = {
|
|
107
|
+
/** Provider to fetch model info from */
|
|
108
|
+
provider: ModelRegistryProvider;
|
|
109
|
+
/** API key for the provider (optional, passed as bearer token) */
|
|
110
|
+
apiKey?: string;
|
|
111
|
+
};
|
|
97
112
|
/**
|
|
98
113
|
* Budget tracking configuration.
|
|
99
|
-
* At least one of `pricingProvider` or `
|
|
114
|
+
* At least one of `pricingProvider`, `modelPricing`, or top-level `modelRegistry` must be provided.
|
|
100
115
|
*/
|
|
101
116
|
export type BudgetConfig = {
|
|
102
117
|
/** Maximum budget in USD (must be positive) */
|
|
103
118
|
maxUsd: number;
|
|
104
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* Pricing provider for automatic model cost lookup. Omit to skip fetching.
|
|
121
|
+
* @deprecated Use top-level `modelRegistry` instead.
|
|
122
|
+
*/
|
|
105
123
|
pricingProvider?: PricingProvider;
|
|
106
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* API key for the pricing provider. Passed as bearer token.
|
|
126
|
+
* @deprecated Use top-level `modelRegistry` instead.
|
|
127
|
+
*/
|
|
107
128
|
apiKey?: string;
|
|
108
129
|
/** Per-model pricing overrides (always highest priority over provider data) */
|
|
109
130
|
modelPricing?: Record<string, ModelPricing>;
|
|
@@ -129,6 +150,9 @@ export type AgentConfig = {
|
|
|
129
150
|
webFetch?: WebFetchConfig;
|
|
130
151
|
/** Enable tool result caching */
|
|
131
152
|
cache?: CacheConfig;
|
|
153
|
+
/** Fetch model info (pricing + context lengths) from a provider.
|
|
154
|
+
* Used by budget tracking and compaction. */
|
|
155
|
+
modelRegistry?: ModelRegistryConfig;
|
|
132
156
|
/** Budget tracking configuration */
|
|
133
157
|
budget?: BudgetConfig;
|
|
134
158
|
defaultTimeout?: number;
|
|
@@ -12,6 +12,10 @@ export interface ModelPricing {
|
|
|
12
12
|
cacheReadPerToken?: number;
|
|
13
13
|
cacheWritePerToken?: number;
|
|
14
14
|
}
|
|
15
|
+
export interface ModelInfo {
|
|
16
|
+
pricing: ModelPricing;
|
|
17
|
+
contextLength: number;
|
|
18
|
+
}
|
|
15
19
|
export interface BudgetStatus {
|
|
16
20
|
totalCostUsd: number;
|
|
17
21
|
maxUsd: number;
|
|
@@ -37,6 +41,14 @@ export interface BudgetTracker {
|
|
|
37
41
|
* On failure, throws an error (callers decide whether to rethrow or fall back).
|
|
38
42
|
*/
|
|
39
43
|
export declare function fetchOpenRouterPricing(apiKey?: string): Promise<Map<string, ModelPricing>>;
|
|
44
|
+
/**
|
|
45
|
+
* Fetches model info (pricing + context length) from OpenRouter's public API.
|
|
46
|
+
* Results are cached at module level. Concurrent calls are deduplicated.
|
|
47
|
+
* Shares the same fetch and cache as `fetchOpenRouterPricing`.
|
|
48
|
+
*
|
|
49
|
+
* On failure, throws an error (callers decide whether to rethrow or fall back).
|
|
50
|
+
*/
|
|
51
|
+
export declare function fetchOpenRouterModels(apiKey?: string): Promise<Map<string, ModelInfo>>;
|
|
40
52
|
/**
|
|
41
53
|
* Reset the OpenRouter cache. Primarily for testing.
|
|
42
54
|
* @internal
|
|
@@ -55,6 +67,13 @@ export declare function getModelMatchVariants(model: string): string[];
|
|
|
55
67
|
* 3. Reverse containment: cost entry variant *contains* response model variant
|
|
56
68
|
*/
|
|
57
69
|
export declare function searchModelInCosts(model: string, costsMap: Map<string, ModelPricing>): ModelPricing | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Looks up a model's context length from the models map using the same
|
|
72
|
+
* 3-tier matching strategy as pricing lookup (exact, contained, reverse).
|
|
73
|
+
*
|
|
74
|
+
* Returns `undefined` if the model is not found or has no context length data.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getModelContextLength(model: string, modelsMap: Map<string, ModelInfo>): number | undefined;
|
|
58
77
|
/**
|
|
59
78
|
* Finds pricing for a model, checking user overrides first then OpenRouter cache.
|
|
60
79
|
* Pass a `warnedModels` set to suppress duplicate warnings per tracker instance.
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { type LanguageModel, type ModelMessage } from "ai";
|
|
1
|
+
import { type LanguageModel, type ModelMessage, type PrepareStepFunction, type ToolSet } from "ai";
|
|
2
|
+
import { type ModelInfo } from "./budget-tracking";
|
|
3
|
+
export declare class CompactionError extends Error {
|
|
4
|
+
readonly name = "CompactionError";
|
|
5
|
+
}
|
|
2
6
|
export interface CompactConversationConfig {
|
|
3
7
|
/** Model's context limit (e.g., 200000 for Claude) */
|
|
4
8
|
maxTokens: number;
|
|
@@ -10,6 +14,8 @@ export interface CompactConversationConfig {
|
|
|
10
14
|
summarizerModel: LanguageModel;
|
|
11
15
|
/** The original task/goal the agent is working on - helps preserve context */
|
|
12
16
|
taskContext?: string;
|
|
17
|
+
/** Extra instructions for the summarizer (e.g., "Focus on database schema decisions") */
|
|
18
|
+
summaryInstructions?: string;
|
|
13
19
|
}
|
|
14
20
|
export interface CompactConversationState {
|
|
15
21
|
/** Accumulated summary from previous compactions */
|
|
@@ -63,9 +69,42 @@ export interface CompactConversationResult {
|
|
|
63
69
|
* ```
|
|
64
70
|
*/
|
|
65
71
|
export declare function compactConversation(messages: ModelMessage[], config: CompactConversationConfig, state?: CompactConversationState): Promise<CompactConversationResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Create an auto-compaction helper that integrates with the AI SDK's `prepareStep` hook.
|
|
74
|
+
*
|
|
75
|
+
* Returns a `prepareStep` function that monitors context usage and automatically
|
|
76
|
+
* compacts the conversation when the threshold is exceeded.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* import { createAutoCompaction } from 'bashkit';
|
|
81
|
+
*
|
|
82
|
+
* const compaction = createAutoCompaction({
|
|
83
|
+
* maxTokens: 200_000,
|
|
84
|
+
* summarizerModel: anthropic('claude-haiku-4'),
|
|
85
|
+
* taskContext: 'Building a REST API',
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* const result = await generateText({
|
|
89
|
+
* model: anthropic('claude-sonnet-4-5'),
|
|
90
|
+
* tools,
|
|
91
|
+
* messages,
|
|
92
|
+
* prepareStep: compaction.prepareStep,
|
|
93
|
+
* stopWhen: stepCountIs(20),
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function createAutoCompaction(config: CompactConversationConfig): {
|
|
98
|
+
prepareStep: PrepareStepFunction<ToolSet>;
|
|
99
|
+
getState: () => Readonly<CompactConversationState>;
|
|
100
|
+
};
|
|
66
101
|
/**
|
|
67
102
|
* Pre-configured token limits for common models.
|
|
68
103
|
* Use these with compactConversation config.
|
|
104
|
+
*
|
|
105
|
+
* @deprecated Use `fetchOpenRouterModels()` + `createCompactConfigFromModels()` instead.
|
|
106
|
+
* This static table goes stale as models evolve. The OpenRouter-based approach
|
|
107
|
+
* fetches up-to-date context lengths automatically.
|
|
69
108
|
*/
|
|
70
109
|
export declare const MODEL_CONTEXT_LIMITS: {
|
|
71
110
|
readonly "claude-opus-4-5": 200000;
|
|
@@ -78,8 +117,39 @@ export declare const MODEL_CONTEXT_LIMITS: {
|
|
|
78
117
|
readonly "gemini-2.5-pro": 1000000;
|
|
79
118
|
readonly "gemini-2.5-flash": 1000000;
|
|
80
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* @deprecated Use `fetchOpenRouterModels()` + `createCompactConfigFromModels()` instead.
|
|
122
|
+
*/
|
|
81
123
|
export type ModelContextLimit = keyof typeof MODEL_CONTEXT_LIMITS;
|
|
82
124
|
/**
|
|
83
|
-
* Helper to create config with model preset
|
|
125
|
+
* Helper to create config with model preset.
|
|
126
|
+
*
|
|
127
|
+
* @deprecated Use `createCompactConfigFromModels()` instead, which looks up
|
|
128
|
+
* context lengths dynamically from OpenRouter data.
|
|
84
129
|
*/
|
|
85
130
|
export declare function createCompactConfig(modelId: ModelContextLimit, summarizerModel: LanguageModel, overrides?: Partial<Omit<CompactConversationConfig, "summarizerModel">>): CompactConversationConfig;
|
|
131
|
+
/**
|
|
132
|
+
* Create a compaction config by looking up the model's context length from
|
|
133
|
+
* an OpenRouter models map. This replaces the static `MODEL_CONTEXT_LIMITS`
|
|
134
|
+
* table with dynamic, always-up-to-date values.
|
|
135
|
+
*
|
|
136
|
+
* @param modelId - Model ID to look up (e.g., "claude-sonnet-4-5", "anthropic/claude-sonnet-4-5")
|
|
137
|
+
* @param summarizerModel - Language model to use for summarization
|
|
138
|
+
* @param modelsMap - Models map from `fetchOpenRouterModels()`
|
|
139
|
+
* @param overrides - Optional config overrides
|
|
140
|
+
* @returns CompactConversationConfig
|
|
141
|
+
* @throws If the model's context length cannot be found in the models map
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import { fetchOpenRouterModels, createCompactConfigFromModels } from 'bashkit';
|
|
146
|
+
*
|
|
147
|
+
* const models = await fetchOpenRouterModels();
|
|
148
|
+
* const config = createCompactConfigFromModels(
|
|
149
|
+
* 'claude-sonnet-4-5',
|
|
150
|
+
* anthropic('claude-haiku-4'),
|
|
151
|
+
* models,
|
|
152
|
+
* );
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function createCompactConfigFromModels(modelId: string, summarizerModel: LanguageModel, modelsMap: Map<string, ModelInfo>, overrides?: Partial<Omit<CompactConversationConfig, "summarizerModel">>): CompactConversationConfig;
|
|
@@ -29,6 +29,8 @@ export interface ContextStatusConfig {
|
|
|
29
29
|
highGuidance?: string | ((metrics: ContextMetrics) => string);
|
|
30
30
|
/** Custom guidance message for 'critical' status */
|
|
31
31
|
criticalGuidance?: string | ((metrics: ContextMetrics) => string);
|
|
32
|
+
/** Pre-computed token count to skip re-estimation */
|
|
33
|
+
knownTokenCount?: number;
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* Get the current context window status for a conversation.
|
package/dist/utils/debug.d.ts
CHANGED
|
@@ -59,13 +59,12 @@ export declare function debugEnd(id: string, tool: string, options: {
|
|
|
59
59
|
*/
|
|
60
60
|
export declare function debugError(id: string, tool: string, error: string | Error): void;
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* Run a function with a debug parent context.
|
|
63
|
+
* All tool calls within `fn` (including async continuations) will have
|
|
64
|
+
* their `parent` field set to `parentId`. Safe for parallel execution —
|
|
65
|
+
* each call gets its own isolated async context via AsyncLocalStorage.
|
|
63
66
|
*/
|
|
64
|
-
export declare function
|
|
65
|
-
/**
|
|
66
|
-
* Pop the current parent context.
|
|
67
|
-
*/
|
|
68
|
-
export declare function popParent(): void;
|
|
67
|
+
export declare function runWithDebugParent<T>(parentId: string, fn: () => T): T;
|
|
69
68
|
/**
|
|
70
69
|
* Get all debug logs (memory mode only).
|
|
71
70
|
* @returns Array of debug events, or empty array if not in memory mode
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ToolCallPart, ToolResultPart } from "ai";
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for tool call content parts in AI SDK messages.
|
|
4
|
+
* Checks the `type` discriminant to avoid false positives from objects
|
|
5
|
+
* that happen to have `toolName` and `input` properties.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isToolCallPart(part: unknown): part is ToolCallPart;
|
|
8
|
+
/**
|
|
9
|
+
* Type guard for tool result content parts in AI SDK messages.
|
|
10
|
+
* Checks the `type` discriminant to avoid false positives from objects
|
|
11
|
+
* that happen to have `toolName` and `output` properties.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isToolResultPart(part: unknown): part is ToolResultPart;
|
|
14
|
+
/**
|
|
15
|
+
* Middle-truncates text, keeping the first half and last half with a
|
|
16
|
+
* marker in between. Preserves both the beginning context and the
|
|
17
|
+
* actionable end (error summaries, test failures).
|
|
18
|
+
*
|
|
19
|
+
* Inspired by OpenAI Codex's truncate.rs — 50/50 head/tail split.
|
|
20
|
+
*/
|
|
21
|
+
export declare function middleTruncate(text: string, maxLength: number): string;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { type BudgetStatus, type BudgetTracker, type ModelPricing, createBudgetTracker, } from "./budget-tracking";
|
|
2
|
-
export { type CompactConversationConfig, type CompactConversationResult, type CompactConversationState, compactConversation, createCompactConfig, MODEL_CONTEXT_LIMITS, type ModelContextLimit, } from "./compact-conversation";
|
|
1
|
+
export { type BudgetStatus, type BudgetTracker, type ModelInfo, type ModelPricing, createBudgetTracker, fetchOpenRouterModels, getModelContextLength, } from "./budget-tracking";
|
|
2
|
+
export { type CompactConversationConfig, type CompactConversationResult, type CompactConversationState, CompactionError, compactConversation, createAutoCompaction, createCompactConfig, createCompactConfigFromModels, MODEL_CONTEXT_LIMITS, type ModelContextLimit, } from "./compact-conversation";
|
|
3
3
|
export { type ContextMetrics, type ContextStatus, type ContextStatusConfig, type ContextStatusLevel, contextNeedsAttention, contextNeedsCompaction, getContextStatus, } from "./context-status";
|
|
4
4
|
export { type DebugEvent, clearDebugLogs, getDebugLogs, isDebugEnabled, reinitDebugMode, } from "./debug";
|
|
5
|
+
export { middleTruncate } from "./helpers";
|
|
5
6
|
export { estimateMessagesTokens, estimateMessageTokens, estimateTokens, type PruneMessagesConfig, pruneMessagesByTokens, } from "./prune-messages";
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* bashkit/cloudflare - Cloudflare Workers compatible exports
|
|
3
|
-
*
|
|
4
|
-
* This module exports only the parts of bashkit that work in Cloudflare Workers.
|
|
5
|
-
* It excludes local sandbox (uses Bun/Node APIs) and bundled ripgrep.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { createE2BSandbox, createBashTool } from 'bashkit/cloudflare';
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export { createE2BSandbox, type E2BSandboxConfig } from "../sandbox/e2b";
|
|
13
|
-
export type { ExecOptions, ExecResult, Sandbox } from "../sandbox/interface";
|
|
14
|
-
export { createBashTool } from "../tools/bash";
|
|
15
|
-
export { createReadTool } from "../tools/read";
|
|
16
|
-
export { createWriteTool } from "../tools/write";
|
|
17
|
-
export { createEditTool } from "../tools/edit";
|
|
18
|
-
export { createGlobTool } from "../tools/glob";
|
|
19
|
-
export { createGrepTool } from "../tools/grep";
|
|
20
|
-
export type { BashOutput, BashError, ReadOutput, ReadError, WriteOutput, WriteError, EditOutput, EditError, GlobOutput, GlobError, GrepOutput, GrepError, } from "../tools";
|