- Added support for caching the stable prefix of the system prompt for Anthropic models. - Introduced a new option `cacheSystemPrefix` in SessionOptions to enable caching. - Implemented a nudge escalation system that reminds users to update the TODO.md file, capped at three nudges. - Created a new `scaffoldWorkflowFiles` function to generate TODO.md, ROADMAP.md, and docs/ directory when they are missing. - Updated the App component to scaffold workflow files during initialization. - Added hooks functionality to allow external scripts to modify tool input and manage approvals. - Implemented tests for the new hooks functionality, ensuring proper approval and execution flow.
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import type { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
import type { AppHooks } from '../src/ui/App';
|
|
|
|
/**
|
|
* A `usage` chunk for `simulateReadableStream`, typed so the cast goes away.
|
|
*
|
|
* The same object was copied verbatim into 17 test files with `as any`, one per
|
|
* stream finish. This builds the real `LanguageModelV4Usage` shape with the
|
|
* numbers a test cares about and the cache fields zeroed.
|
|
*/
|
|
export function usageOf(input: number, output = 1): LanguageModelV4Usage {
|
|
return {
|
|
inputTokens: { total: input, noCache: input, cacheRead: 0, cacheWrite: 0 },
|
|
outputTokens: { total: output, text: output, reasoning: 0 },
|
|
};
|
|
}
|
|
|
|
/** Default AppHooks for UI tests; override only what a test cares about. */
|
|
export function testHooks(over: Partial<AppHooks> = {}): AppHooks {
|
|
return {
|
|
sessionId: 'test1234',
|
|
config: () => ({ provider: 'openai', model: 'gpt-5' }),
|
|
switchModel: (id) => `model is now ${id}`,
|
|
switchAgent: (name) => `agent is now ${name}`,
|
|
switchThinking: (level) => `thinking is now ${level}`,
|
|
agentName: () => 'default',
|
|
thinkingLevel: () => 'medium',
|
|
applyProvider: async () => 'configured',
|
|
listModels: async () => ({ models: [] }),
|
|
listSessions: async () => 'no saved sessions',
|
|
searchSessions: async () => '',
|
|
forkSession: async () => 'forked',
|
|
listSkills: () => 'no skills loaded',
|
|
listPlugins: () => 'no plugins active',
|
|
listMemory: async () => 'nothing remembered yet',
|
|
summarizeMemory: async () => 'nothing to compact',
|
|
resumeSession: async () => 'resumed',
|
|
saveSession: async () => 'saved',
|
|
instructionFiles: () => [],
|
|
listPaths: async () => [],
|
|
fileChangeSeq: () => 0,
|
|
registry: {
|
|
list: async () => [],
|
|
installed: async () => [],
|
|
stage: async () => {
|
|
throw new Error('no registry in tests unless a test provides one');
|
|
},
|
|
install: async () => 'installed',
|
|
remove: async () => 'removed',
|
|
},
|
|
mcp: {
|
|
names: () => [],
|
|
list: () => 'no mcp servers configured',
|
|
add: async (result) => `added ${result.name}`,
|
|
remove: async (name) => `removed ${name}`,
|
|
},
|
|
initPrompt: 'write AGENTS.md',
|
|
scaffoldWorkflow: () => [],
|
|
history: [],
|
|
recordPrompt: () => {},
|
|
...over,
|
|
};
|
|
}
|