gencode-ai 0.1.3 → 0.2.0
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/README.md +2 -1
- package/dist/agent/agent.d.ts +35 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +93 -3
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/types.d.ts +6 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/checkpointing/checkpoint-manager.d.ts +87 -0
- package/dist/checkpointing/checkpoint-manager.d.ts.map +1 -0
- package/dist/checkpointing/checkpoint-manager.js +281 -0
- package/dist/checkpointing/checkpoint-manager.js.map +1 -0
- package/dist/checkpointing/index.d.ts +29 -0
- package/dist/checkpointing/index.d.ts.map +1 -0
- package/dist/checkpointing/index.js +29 -0
- package/dist/checkpointing/index.js.map +1 -0
- package/dist/checkpointing/types.d.ts +98 -0
- package/dist/checkpointing/types.d.ts.map +1 -0
- package/dist/checkpointing/types.js +7 -0
- package/dist/checkpointing/types.js.map +1 -0
- package/dist/cli/components/App.d.ts.map +1 -1
- package/dist/cli/components/App.js +157 -6
- package/dist/cli/components/App.js.map +1 -1
- package/dist/cli/components/CommandSuggestions.d.ts.map +1 -1
- package/dist/cli/components/CommandSuggestions.js +5 -0
- package/dist/cli/components/CommandSuggestions.js.map +1 -1
- package/dist/cli/components/Messages.d.ts +7 -1
- package/dist/cli/components/Messages.d.ts.map +1 -1
- package/dist/cli/components/Messages.js +11 -2
- package/dist/cli/components/Messages.js.map +1 -1
- package/dist/cli/components/ModeIndicator.d.ts +42 -0
- package/dist/cli/components/ModeIndicator.d.ts.map +1 -0
- package/dist/cli/components/ModeIndicator.js +52 -0
- package/dist/cli/components/ModeIndicator.js.map +1 -0
- package/dist/cli/components/PlanApproval.d.ts +36 -0
- package/dist/cli/components/PlanApproval.d.ts.map +1 -0
- package/dist/cli/components/PlanApproval.js +154 -0
- package/dist/cli/components/PlanApproval.js.map +1 -0
- package/dist/cli/components/theme.d.ts +2 -0
- package/dist/cli/components/theme.d.ts.map +1 -1
- package/dist/cli/components/theme.js +3 -0
- package/dist/cli/components/theme.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/planning/index.d.ts +13 -0
- package/dist/planning/index.d.ts.map +1 -0
- package/dist/planning/index.js +15 -0
- package/dist/planning/index.js.map +1 -0
- package/dist/planning/plan-file.d.ts +59 -0
- package/dist/planning/plan-file.d.ts.map +1 -0
- package/dist/planning/plan-file.js +278 -0
- package/dist/planning/plan-file.js.map +1 -0
- package/dist/planning/state.d.ts +127 -0
- package/dist/planning/state.d.ts.map +1 -0
- package/dist/planning/state.js +261 -0
- package/dist/planning/state.js.map +1 -0
- package/dist/planning/tools/enter-plan-mode.d.ts +25 -0
- package/dist/planning/tools/enter-plan-mode.d.ts.map +1 -0
- package/dist/planning/tools/enter-plan-mode.js +98 -0
- package/dist/planning/tools/enter-plan-mode.js.map +1 -0
- package/dist/planning/tools/exit-plan-mode.d.ts +24 -0
- package/dist/planning/tools/exit-plan-mode.d.ts.map +1 -0
- package/dist/planning/tools/exit-plan-mode.js +149 -0
- package/dist/planning/tools/exit-plan-mode.js.map +1 -0
- package/dist/planning/types.d.ts +100 -0
- package/dist/planning/types.d.ts.map +1 -0
- package/dist/planning/types.js +28 -0
- package/dist/planning/types.js.map +1 -0
- package/dist/pricing/calculator.d.ts +21 -0
- package/dist/pricing/calculator.d.ts.map +1 -0
- package/dist/pricing/calculator.js +59 -0
- package/dist/pricing/calculator.js.map +1 -0
- package/dist/pricing/index.d.ts +7 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +7 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/pricing/models.d.ts +20 -0
- package/dist/pricing/models.d.ts.map +1 -0
- package/dist/pricing/models.js +322 -0
- package/dist/pricing/models.js.map +1 -0
- package/dist/pricing/types.d.ts +30 -0
- package/dist/pricing/types.d.ts.map +1 -0
- package/dist/pricing/types.js +5 -0
- package/dist/pricing/types.js.map +1 -0
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +17 -10
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/gemini.d.ts.map +1 -1
- package/dist/providers/gemini.js +21 -14
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +12 -8
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/types.d.ts +2 -0
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/vertex-ai.d.ts.map +1 -1
- package/dist/providers/vertex-ai.js +17 -10
- package/dist/providers/vertex-ai.js.map +1 -1
- package/dist/session/manager.d.ts +4 -0
- package/dist/session/manager.d.ts.map +1 -1
- package/dist/session/manager.js +8 -0
- package/dist/session/manager.js.map +1 -1
- package/dist/tools/index.d.ts +7 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +7 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/registry.d.ts +13 -0
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +79 -2
- package/dist/tools/registry.js.map +1 -1
- package/docs/cost-tracking-comparison.md +904 -0
- package/docs/operating-modes.md +96 -0
- package/docs/proposals/0025-cost-tracking.md +60 -2
- package/docs/proposals/README.md +1 -1
- package/examples/test-checkpointing.ts +121 -0
- package/examples/test-cost-tracking.ts +77 -0
- package/examples/test-interrupt-cleanup.ts +94 -0
- package/package.json +1 -1
- package/src/agent/agent.ts +110 -3
- package/src/agent/types.ts +6 -0
- package/src/checkpointing/checkpoint-manager.ts +327 -0
- package/src/checkpointing/index.ts +45 -0
- package/src/checkpointing/types.ts +104 -0
- package/src/cli/components/App.tsx +204 -5
- package/src/cli/components/CommandSuggestions.tsx +5 -0
- package/src/cli/components/Messages.tsx +23 -4
- package/src/cli/components/ModeIndicator.tsx +174 -0
- package/src/cli/components/PlanApproval.tsx +327 -0
- package/src/cli/components/theme.ts +3 -0
- package/src/index.ts +15 -0
- package/src/planning/index.ts +53 -0
- package/src/planning/plan-file.ts +326 -0
- package/src/planning/state.ts +305 -0
- package/src/planning/tools/enter-plan-mode.ts +111 -0
- package/src/planning/tools/exit-plan-mode.ts +170 -0
- package/src/planning/types.ts +150 -0
- package/src/pricing/calculator.ts +71 -0
- package/src/pricing/index.ts +7 -0
- package/src/pricing/models.ts +334 -0
- package/src/pricing/types.ts +32 -0
- package/src/providers/anthropic.ts +21 -10
- package/src/providers/gemini.ts +25 -14
- package/src/providers/openai.ts +17 -8
- package/src/providers/types.ts +3 -0
- package/src/providers/vertex-ai.ts +21 -10
- package/src/session/manager.ts +9 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/registry.ts +95 -2
- package/.gencode/settings.local.json +0 -7
- package/CLAUDE.md +0 -86
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnterPlanMode Tool
|
|
3
|
+
*
|
|
4
|
+
* Transitions the agent into plan mode for designing implementation
|
|
5
|
+
* approaches before writing code. In plan mode, only read-only tools
|
|
6
|
+
* are available.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import type { Tool } from '../../tools/types.js';
|
|
10
|
+
declare const EnterPlanModeInputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
11
|
+
export type EnterPlanModeInput = z.infer<typeof EnterPlanModeInputSchema>;
|
|
12
|
+
/**
|
|
13
|
+
* EnterPlanMode Tool
|
|
14
|
+
*
|
|
15
|
+
* Use this tool when you need to plan an implementation before writing code.
|
|
16
|
+
* This is recommended for:
|
|
17
|
+
* - New feature implementations
|
|
18
|
+
* - Tasks with multiple valid approaches
|
|
19
|
+
* - Architectural decisions
|
|
20
|
+
* - Multi-file changes
|
|
21
|
+
* - Unclear requirements
|
|
22
|
+
*/
|
|
23
|
+
export declare const enterPlanModeTool: Tool<EnterPlanModeInput>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=enter-plan-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enter-plan-mode.d.ts","sourceRoot":"","sources":["../../../src/planning/tools/enter-plan-mode.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAA2B,MAAM,sBAAsB,CAAC;AAS1E,QAAA,MAAM,wBAAwB,gCAAe,CAAC;AAE9C,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,EAAE,IAAI,CAAC,kBAAkB,CA6EtD,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnterPlanMode Tool
|
|
3
|
+
*
|
|
4
|
+
* Transitions the agent into plan mode for designing implementation
|
|
5
|
+
* approaches before writing code. In plan mode, only read-only tools
|
|
6
|
+
* are available.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { getPlanModeManager } from '../state.js';
|
|
10
|
+
import { createPlanFile, getDisplayPath } from '../plan-file.js';
|
|
11
|
+
import { PLAN_MODE_ALLOWED_TOOLS, PLAN_MODE_BLOCKED_TOOLS } from '../types.js';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Tool Definition
|
|
14
|
+
// ============================================================================
|
|
15
|
+
const EnterPlanModeInputSchema = z.object({});
|
|
16
|
+
/**
|
|
17
|
+
* EnterPlanMode Tool
|
|
18
|
+
*
|
|
19
|
+
* Use this tool when you need to plan an implementation before writing code.
|
|
20
|
+
* This is recommended for:
|
|
21
|
+
* - New feature implementations
|
|
22
|
+
* - Tasks with multiple valid approaches
|
|
23
|
+
* - Architectural decisions
|
|
24
|
+
* - Multi-file changes
|
|
25
|
+
* - Unclear requirements
|
|
26
|
+
*/
|
|
27
|
+
export const enterPlanModeTool = {
|
|
28
|
+
name: 'EnterPlanMode',
|
|
29
|
+
description: `Transition into plan mode to design an implementation approach before writing code.
|
|
30
|
+
|
|
31
|
+
Use this tool when:
|
|
32
|
+
- Implementing new features that require design decisions
|
|
33
|
+
- Tasks with multiple valid approaches
|
|
34
|
+
- Changes that affect existing behavior or structure
|
|
35
|
+
- Architectural decisions between patterns or technologies
|
|
36
|
+
- Multi-file changes (more than 2-3 files)
|
|
37
|
+
- Unclear requirements that need exploration
|
|
38
|
+
|
|
39
|
+
In plan mode:
|
|
40
|
+
- Only read-only tools are available (Read, Glob, Grep, WebFetch, WebSearch, TodoWrite, AskUserQuestion)
|
|
41
|
+
- Write, Edit, and Bash tools are blocked
|
|
42
|
+
- You can explore the codebase and design an approach
|
|
43
|
+
- Use ExitPlanMode when ready to request user approval
|
|
44
|
+
|
|
45
|
+
This tool REQUIRES user approval before entering plan mode.`,
|
|
46
|
+
parameters: EnterPlanModeInputSchema,
|
|
47
|
+
async execute(_input, context) {
|
|
48
|
+
const manager = getPlanModeManager();
|
|
49
|
+
// Check if already in plan mode
|
|
50
|
+
if (manager.isActive()) {
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
output: '',
|
|
54
|
+
error: 'Already in plan mode. Use ExitPlanMode to exit first.',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
// Create plan file
|
|
59
|
+
const planFile = await createPlanFile(context.cwd);
|
|
60
|
+
const displayPath = getDisplayPath(planFile.path, context.cwd);
|
|
61
|
+
// Enter plan mode
|
|
62
|
+
manager.enter(planFile.path);
|
|
63
|
+
// Build response
|
|
64
|
+
const output = `
|
|
65
|
+
Entered PLAN mode.
|
|
66
|
+
|
|
67
|
+
Plan file: ${displayPath}
|
|
68
|
+
|
|
69
|
+
In plan mode, you have access to read-only tools for exploration:
|
|
70
|
+
${PLAN_MODE_ALLOWED_TOOLS.map((t) => ` - ${t}`).join('\n')}
|
|
71
|
+
|
|
72
|
+
Blocked tools (write/execute operations):
|
|
73
|
+
${PLAN_MODE_BLOCKED_TOOLS.map((t) => ` - ${t}`).join('\n')}
|
|
74
|
+
|
|
75
|
+
Instructions:
|
|
76
|
+
1. Explore the codebase using Read, Glob, Grep tools
|
|
77
|
+
2. Research if needed using WebFetch, WebSearch
|
|
78
|
+
3. Design your implementation approach
|
|
79
|
+
4. Write your plan to the plan file using Write (plan file only)
|
|
80
|
+
5. Call ExitPlanMode when ready for user approval
|
|
81
|
+
|
|
82
|
+
Use Shift+Tab to toggle between Plan and Build modes.
|
|
83
|
+
`.trim();
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
output,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return {
|
|
91
|
+
success: false,
|
|
92
|
+
output: '',
|
|
93
|
+
error: `Failed to enter plan mode: ${error instanceof Error ? error.message : String(error)}`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=enter-plan-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enter-plan-mode.js","sourceRoot":"","sources":["../../../src/planning/tools/enter-plan-mode.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE/E,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAI9C;;;;;;;;;;GAUG;AACH,MAAM,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AK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;aAC9F,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExitPlanMode Tool
|
|
3
|
+
*
|
|
4
|
+
* Exits plan mode and requests user approval for the implementation plan.
|
|
5
|
+
* Supports pre-approving permissions for bash commands needed during execution.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import type { Tool } from '../../tools/types.js';
|
|
9
|
+
declare const ExitPlanModeInputSchema: z.ZodObject<{
|
|
10
|
+
allowedPrompts: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
11
|
+
tool: z.ZodLiteral<"Bash">;
|
|
12
|
+
prompt: z.ZodString;
|
|
13
|
+
}, z.core.$strip>>>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type ExitPlanModeInput = z.infer<typeof ExitPlanModeInputSchema>;
|
|
16
|
+
/**
|
|
17
|
+
* ExitPlanMode Tool
|
|
18
|
+
*
|
|
19
|
+
* Call this when you have finished writing your plan and are ready
|
|
20
|
+
* for user approval. The plan file should already be written.
|
|
21
|
+
*/
|
|
22
|
+
export declare const exitPlanModeTool: Tool<ExitPlanModeInput>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=exit-plan-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-plan-mode.d.ts","sourceRoot":"","sources":["../../../src/planning/tools/exit-plan-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAA2B,MAAM,sBAAsB,CAAC;AAc1E,QAAA,MAAM,uBAAuB;;;;;iBAK3B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,IAAI,CAAC,iBAAiB,CAoIpD,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExitPlanMode Tool
|
|
3
|
+
*
|
|
4
|
+
* Exits plan mode and requests user approval for the implementation plan.
|
|
5
|
+
* Supports pre-approving permissions for bash commands needed during execution.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { getPlanModeManager } from '../state.js';
|
|
9
|
+
import { readPlanFile, parseFilesToChange, parsePreApprovedPermissions, getDisplayPath } from '../plan-file.js';
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Tool Definition
|
|
12
|
+
// ============================================================================
|
|
13
|
+
const AllowedPromptSchema = z.object({
|
|
14
|
+
tool: z.literal('Bash').describe('The tool this permission applies to'),
|
|
15
|
+
prompt: z.string().describe('Semantic description of the action, e.g., "run tests", "install dependencies"'),
|
|
16
|
+
});
|
|
17
|
+
const ExitPlanModeInputSchema = z.object({
|
|
18
|
+
allowedPrompts: z
|
|
19
|
+
.array(AllowedPromptSchema)
|
|
20
|
+
.optional()
|
|
21
|
+
.describe('Prompt-based permissions needed to implement the plan'),
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* ExitPlanMode Tool
|
|
25
|
+
*
|
|
26
|
+
* Call this when you have finished writing your plan and are ready
|
|
27
|
+
* for user approval. The plan file should already be written.
|
|
28
|
+
*/
|
|
29
|
+
export const exitPlanModeTool = {
|
|
30
|
+
name: 'ExitPlanMode',
|
|
31
|
+
description: `Exit plan mode and request user approval for the implementation plan.
|
|
32
|
+
|
|
33
|
+
## How This Tool Works
|
|
34
|
+
- You should have already written your plan to the plan file
|
|
35
|
+
- This tool reads the plan from the file you wrote
|
|
36
|
+
- The user will see the plan contents and approve/modify/cancel
|
|
37
|
+
|
|
38
|
+
## Requesting Permissions (allowedPrompts)
|
|
39
|
+
Request prompt-based permissions for bash commands your plan will need:
|
|
40
|
+
|
|
41
|
+
\`\`\`json
|
|
42
|
+
{
|
|
43
|
+
"allowedPrompts": [
|
|
44
|
+
{ "tool": "Bash", "prompt": "run tests" },
|
|
45
|
+
{ "tool": "Bash", "prompt": "install dependencies" },
|
|
46
|
+
{ "tool": "Bash", "prompt": "build the project" }
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
\`\`\`
|
|
50
|
+
|
|
51
|
+
Guidelines for prompts:
|
|
52
|
+
- Use semantic descriptions that capture the action's purpose
|
|
53
|
+
- "run tests" matches: npm test, pytest, go test, etc.
|
|
54
|
+
- "install dependencies" matches: npm install, pip install, etc.
|
|
55
|
+
- Keep descriptions concise but descriptive
|
|
56
|
+
- Only request permissions you actually need
|
|
57
|
+
- Scope permissions narrowly
|
|
58
|
+
|
|
59
|
+
## When to Use This Tool
|
|
60
|
+
Only use this tool when you have finished planning and are ready for approval.
|
|
61
|
+
Do NOT use this tool for research tasks - only for implementation planning.`,
|
|
62
|
+
parameters: ExitPlanModeInputSchema,
|
|
63
|
+
async execute(input, context) {
|
|
64
|
+
const manager = getPlanModeManager();
|
|
65
|
+
// Check if in plan mode
|
|
66
|
+
if (!manager.isActive()) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
output: '',
|
|
70
|
+
error: 'Not in plan mode. Use EnterPlanMode first.',
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const planFilePath = manager.getPlanFilePath();
|
|
74
|
+
if (!planFilePath) {
|
|
75
|
+
return {
|
|
76
|
+
success: false,
|
|
77
|
+
output: '',
|
|
78
|
+
error: 'No plan file found. This should not happen.',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
// Read plan file
|
|
83
|
+
const planFile = await readPlanFile(planFilePath);
|
|
84
|
+
if (!planFile) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
output: '',
|
|
88
|
+
error: `Could not read plan file: ${planFilePath}`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// Parse plan content
|
|
92
|
+
const filesToChange = parseFilesToChange(planFile.content);
|
|
93
|
+
const planPermissions = parsePreApprovedPermissions(planFile.content);
|
|
94
|
+
// Combine with input permissions
|
|
95
|
+
const requestedPermissions = [
|
|
96
|
+
...planPermissions,
|
|
97
|
+
...(input.allowedPrompts || []),
|
|
98
|
+
];
|
|
99
|
+
// Store permissions for approval UI
|
|
100
|
+
manager.setRequestedPermissions(requestedPermissions);
|
|
101
|
+
manager.setPhase('approval');
|
|
102
|
+
// Build response for the LLM
|
|
103
|
+
const displayPath = getDisplayPath(planFilePath, context.cwd);
|
|
104
|
+
let output = `
|
|
105
|
+
Plan ready for approval.
|
|
106
|
+
|
|
107
|
+
Plan file: ${displayPath}
|
|
108
|
+
|
|
109
|
+
`;
|
|
110
|
+
// Summary of files to change
|
|
111
|
+
if (filesToChange.length > 0) {
|
|
112
|
+
output += 'Files to change:\n';
|
|
113
|
+
for (const file of filesToChange) {
|
|
114
|
+
const icon = file.action === 'create' ? '+' : file.action === 'modify' ? '~' : '-';
|
|
115
|
+
output += ` ${icon} ${file.path} (${file.action})\n`;
|
|
116
|
+
}
|
|
117
|
+
output += '\n';
|
|
118
|
+
}
|
|
119
|
+
// Requested permissions
|
|
120
|
+
if (requestedPermissions.length > 0) {
|
|
121
|
+
output += 'Requested permissions:\n';
|
|
122
|
+
for (const perm of requestedPermissions) {
|
|
123
|
+
output += ` - ${perm.tool}(prompt: ${perm.prompt})\n`;
|
|
124
|
+
}
|
|
125
|
+
output += '\n';
|
|
126
|
+
}
|
|
127
|
+
output += `
|
|
128
|
+
The user will now be prompted to:
|
|
129
|
+
1. Approve - Accept plan and proceed with execution
|
|
130
|
+
2. Modify - Go back and modify the plan
|
|
131
|
+
3. Cancel - Exit plan mode without executing
|
|
132
|
+
|
|
133
|
+
Waiting for user decision...
|
|
134
|
+
`.trim();
|
|
135
|
+
return {
|
|
136
|
+
success: true,
|
|
137
|
+
output,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
return {
|
|
142
|
+
success: false,
|
|
143
|
+
output: '',
|
|
144
|
+
error: `Failed to exit plan mode: ${error instanceof Error ? error.message : String(error)}`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=exit-plan-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exit-plan-mode.js","sourceRoot":"","sources":["../../../src/planning/tools/exit-plan-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGhH,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,qCAAqC,CAAC;IACvE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+EAA+E,CAAC;CAC7G,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,cAAc,EAAE,CAAC;SACd,KAAK,CAAC,mBAAmB,CAAC;SAC1B,QAAQ,EAAE;SACV,QAAQ,CAAC,uDAAuD,CAAC;CACrE,CAAC,CAAC;AAIH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA4B;IACvD,IAAI,EAAE,cAAc;IAEpB,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4EA8B6D;IAE1E,UAAU,EAAE,uBAAu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,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Mode Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Types for Plan Mode - a read-only exploration mode that allows
|
|
5
|
+
* the LLM to plan implementations before executing changes.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Plan mode phases following Claude Code's workflow
|
|
9
|
+
*/
|
|
10
|
+
export type PlanPhase = 'understanding' | 'design' | 'review' | 'final' | 'approval';
|
|
11
|
+
/**
|
|
12
|
+
* User approval options for plan mode
|
|
13
|
+
*/
|
|
14
|
+
export type PlanApprovalOption = 'approve' | 'approve_clear' | 'approve_manual' | 'modify' | 'cancel';
|
|
15
|
+
/**
|
|
16
|
+
* Pre-approved permission request (Claude Code ExitPlanMode style)
|
|
17
|
+
*/
|
|
18
|
+
export interface AllowedPrompt {
|
|
19
|
+
tool: 'Bash';
|
|
20
|
+
prompt: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Plan mode state
|
|
24
|
+
*/
|
|
25
|
+
export interface PlanModeState {
|
|
26
|
+
/** Whether plan mode is currently active */
|
|
27
|
+
active: boolean;
|
|
28
|
+
/** Current phase of planning */
|
|
29
|
+
phase: PlanPhase;
|
|
30
|
+
/** Path to the plan file */
|
|
31
|
+
planFilePath: string | null;
|
|
32
|
+
/** User's original request that triggered plan mode */
|
|
33
|
+
originalRequest: string | null;
|
|
34
|
+
/** Requested permissions for execution phase */
|
|
35
|
+
requestedPermissions: AllowedPrompt[];
|
|
36
|
+
/** Timestamp when plan mode was entered */
|
|
37
|
+
enteredAt: Date | null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Plan file structure
|
|
41
|
+
*/
|
|
42
|
+
export interface PlanFile {
|
|
43
|
+
/** Plan file path */
|
|
44
|
+
path: string;
|
|
45
|
+
/** Plan content in markdown */
|
|
46
|
+
content: string;
|
|
47
|
+
/** Creation timestamp */
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
/** Last update timestamp */
|
|
50
|
+
updatedAt: Date;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Tools allowed in plan mode (read-only + planning tools)
|
|
54
|
+
*/
|
|
55
|
+
export declare const PLAN_MODE_ALLOWED_TOOLS: readonly ["Read", "Glob", "Grep", "WebFetch", "WebSearch", "TodoWrite", "AskUserQuestion", "EnterPlanMode", "ExitPlanMode"];
|
|
56
|
+
/**
|
|
57
|
+
* Tools blocked in plan mode (write/execute operations)
|
|
58
|
+
*/
|
|
59
|
+
export declare const PLAN_MODE_BLOCKED_TOOLS: readonly ["Write", "Edit", "Bash"];
|
|
60
|
+
export type PlanModeAllowedTool = (typeof PLAN_MODE_ALLOWED_TOOLS)[number];
|
|
61
|
+
export type PlanModeBlockedTool = (typeof PLAN_MODE_BLOCKED_TOOLS)[number];
|
|
62
|
+
/**
|
|
63
|
+
* Operating mode (cycle with Shift+Tab: normal → plan → accept → normal)
|
|
64
|
+
* - normal: Default mode, edits require confirmation
|
|
65
|
+
* - plan: Read-only exploration mode, edits blocked
|
|
66
|
+
* - accept: Auto-accept mode, edits approved without confirmation
|
|
67
|
+
*/
|
|
68
|
+
export type ModeType = 'normal' | 'plan' | 'accept';
|
|
69
|
+
/**
|
|
70
|
+
* Plan approval UI state
|
|
71
|
+
*/
|
|
72
|
+
export interface PlanApprovalState {
|
|
73
|
+
/** Plan content for display */
|
|
74
|
+
planContent: string;
|
|
75
|
+
/** Summary of files to change */
|
|
76
|
+
filesToChange: Array<{
|
|
77
|
+
path: string;
|
|
78
|
+
action: 'create' | 'modify' | 'delete';
|
|
79
|
+
}>;
|
|
80
|
+
/** Requested permissions */
|
|
81
|
+
requestedPermissions: AllowedPrompt[];
|
|
82
|
+
/** Callback when user makes decision */
|
|
83
|
+
onDecision: (option: PlanApprovalOption) => void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Plan mode events for UI updates
|
|
87
|
+
*/
|
|
88
|
+
export type PlanModeEvent = {
|
|
89
|
+
type: 'enter';
|
|
90
|
+
planFilePath: string;
|
|
91
|
+
} | {
|
|
92
|
+
type: 'phase_change';
|
|
93
|
+
phase: PlanPhase;
|
|
94
|
+
} | {
|
|
95
|
+
type: 'exit';
|
|
96
|
+
approved: boolean;
|
|
97
|
+
} | {
|
|
98
|
+
type: 'toggle';
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/planning/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,eAAe,GACf,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,UAAU,CAAC;AAEf;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,SAAS,GACT,eAAe,GACf,gBAAgB,GAChB,QAAQ,GACR,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,MAAM,EAAE,OAAO,CAAC;IAEhB,gCAAgC;IAChC,KAAK,EAAE,SAAS,CAAC;IAEjB,4BAA4B;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B,uDAAuD;IACvD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B,gDAAgD;IAChD,oBAAoB,EAAE,aAAa,EAAE,CAAC;IAEtC,2CAA2C;IAC3C,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IAEb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAEhB,yBAAyB;IACzB,SAAS,EAAE,IAAI,CAAC;IAEhB,4BAA4B;IAC5B,SAAS,EAAE,IAAI,CAAC;CACjB;AAMD;;GAEG;AACH,eAAO,MAAM,uBAAuB,6HAU1B,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,uBAAuB,oCAAqC,CAAC;AAE1E,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC3E,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAM3E;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;IAEpB,iCAAiC;IACjC,aAAa,EAAE,KAAK,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;KACxC,CAAC,CAAC;IAEH,4BAA4B;IAC5B,oBAAoB,EAAE,aAAa,EAAE,CAAC;IAEtC,wCAAwC;IACxC,UAAU,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;CAClD;AAMD;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan Mode Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Types for Plan Mode - a read-only exploration mode that allows
|
|
5
|
+
* the LLM to plan implementations before executing changes.
|
|
6
|
+
*/
|
|
7
|
+
// ============================================================================
|
|
8
|
+
// Tool Filtering Types
|
|
9
|
+
// ============================================================================
|
|
10
|
+
/**
|
|
11
|
+
* Tools allowed in plan mode (read-only + planning tools)
|
|
12
|
+
*/
|
|
13
|
+
export const PLAN_MODE_ALLOWED_TOOLS = [
|
|
14
|
+
'Read',
|
|
15
|
+
'Glob',
|
|
16
|
+
'Grep',
|
|
17
|
+
'WebFetch',
|
|
18
|
+
'WebSearch',
|
|
19
|
+
'TodoWrite',
|
|
20
|
+
'AskUserQuestion',
|
|
21
|
+
'EnterPlanMode', // Can re-enter if needed
|
|
22
|
+
'ExitPlanMode', // To exit plan mode
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Tools blocked in plan mode (write/execute operations)
|
|
26
|
+
*/
|
|
27
|
+
export const PLAN_MODE_BLOCKED_TOOLS = ['Write', 'Edit', 'Bash'];
|
|
28
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/planning/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0EH,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,MAAM;IACN,MAAM;IACN,MAAM;IACN,UAAU;IACV,WAAW;IACX,WAAW;IACX,iBAAiB;IACjB,eAAe,EAAE,yBAAyB;IAC1C,cAAc,EAAE,oBAAoB;CAC5B,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost calculation utilities
|
|
3
|
+
*/
|
|
4
|
+
import { CostEstimate, TokenUsage } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Calculate cost from token usage
|
|
7
|
+
*/
|
|
8
|
+
export declare function calculateCost(provider: string, model: string, tokens: TokenUsage): CostEstimate;
|
|
9
|
+
/**
|
|
10
|
+
* Format cost for display
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatCost(cost: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Format token count for display
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatTokens(count: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Format cost estimate for display
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatCostEstimate(estimate: CostEstimate): string;
|
|
21
|
+
//# sourceMappingURL=calculator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.d.ts","sourceRoot":"","sources":["../../src/pricing/calculator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEtD;;GAEG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,UAAU,GACjB,YAAY,CAuBd;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQlD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM,CAEjE"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost calculation utilities
|
|
3
|
+
*/
|
|
4
|
+
import { getModelPricing } from './models.js';
|
|
5
|
+
/**
|
|
6
|
+
* Calculate cost from token usage
|
|
7
|
+
*/
|
|
8
|
+
export function calculateCost(provider, model, tokens) {
|
|
9
|
+
const pricing = getModelPricing(provider, model);
|
|
10
|
+
// If no pricing found, return zero cost
|
|
11
|
+
if (!pricing) {
|
|
12
|
+
return {
|
|
13
|
+
inputCost: 0,
|
|
14
|
+
outputCost: 0,
|
|
15
|
+
totalCost: 0,
|
|
16
|
+
currency: 'USD',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// Calculate cost per token type
|
|
20
|
+
const inputCost = (tokens.inputTokens / 1_000_000) * pricing.inputPer1M;
|
|
21
|
+
const outputCost = (tokens.outputTokens / 1_000_000) * pricing.outputPer1M;
|
|
22
|
+
return {
|
|
23
|
+
inputCost,
|
|
24
|
+
outputCost,
|
|
25
|
+
totalCost: inputCost + outputCost,
|
|
26
|
+
currency: 'USD',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Format cost for display
|
|
31
|
+
*/
|
|
32
|
+
export function formatCost(cost) {
|
|
33
|
+
if (cost === 0) {
|
|
34
|
+
return '$0.00';
|
|
35
|
+
}
|
|
36
|
+
if (cost < 0.01) {
|
|
37
|
+
return '<$0.01';
|
|
38
|
+
}
|
|
39
|
+
return `$${cost.toFixed(2)}`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Format token count for display
|
|
43
|
+
*/
|
|
44
|
+
export function formatTokens(count) {
|
|
45
|
+
if (count >= 1_000_000) {
|
|
46
|
+
return `${(count / 1_000_000).toFixed(1)}M`;
|
|
47
|
+
}
|
|
48
|
+
if (count >= 1_000) {
|
|
49
|
+
return `${(count / 1_000).toFixed(1)}K`;
|
|
50
|
+
}
|
|
51
|
+
return count.toString();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Format cost estimate for display
|
|
55
|
+
*/
|
|
56
|
+
export function formatCostEstimate(estimate) {
|
|
57
|
+
return formatCost(estimate.totalCost);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.js","sourceRoot":"","sources":["../../src/pricing/calculator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EA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,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IAC1C,CAAC;IACD,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAsB;IACvD,OAAO,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pricing/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pricing/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model pricing database
|
|
3
|
+
* Prices are per 1M tokens in USD
|
|
4
|
+
* Updated: January 2025
|
|
5
|
+
*/
|
|
6
|
+
import { ModelPricing } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Pricing data for all supported models
|
|
9
|
+
* Source: Official provider pricing pages as of January 2025
|
|
10
|
+
*/
|
|
11
|
+
export declare const MODEL_PRICING: ModelPricing[];
|
|
12
|
+
/**
|
|
13
|
+
* Get pricing for a specific model
|
|
14
|
+
*/
|
|
15
|
+
export declare function getModelPricing(provider: string, model: string): ModelPricing | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Get all pricing for a provider
|
|
18
|
+
*/
|
|
19
|
+
export declare function getProviderPricing(provider: string): ModelPricing[];
|
|
20
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/pricing/models.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,YAAY,EA8SvC,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,YAAY,GAAG,SAAS,CAI1B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE,CAEnE"}
|