@@ -12,8 +12,12 @@ import type {
1212 AgentRuntimeDeps ,
1313 AgentRuntimeScopedDeps ,
1414} from '@codebuff/common/types/contracts/agent-runtime'
15+ import type { Logger } from '@codebuff/common/types/contracts/logger'
1516
16- export const CLI_AGENT_RUNTIME_IMPL : Omit <
17+ export function getAgentRuntimeImpl ( params : {
18+ logger ?: Logger
19+ apiKey : string
20+ } ) : Omit <
1721 AgentRuntimeDeps & AgentRuntimeScopedDeps ,
1822 | 'addAgentStep'
1923 | 'promptAiSdkStream'
@@ -26,50 +30,54 @@ export const CLI_AGENT_RUNTIME_IMPL: Omit<
2630 | 'requestOptionalFile'
2731 | 'sendAction'
2832 | 'sendSubagentChunk'
29- > = {
30- // Database
31- getUserInfoFromApiKey,
32- fetchAgentFromDatabase,
33- startAgentRun,
34- finishAgentRun,
35- // addAgentStep: AddAgentStepFn
33+ > {
34+ const { logger, apiKey } = params
35+
36+ return {
37+ // Database
38+ getUserInfoFromApiKey,
39+ fetchAgentFromDatabase,
40+ startAgentRun,
41+ finishAgentRun,
42+ // addAgentStep: AddAgentStepFn
3643
37- // Billing
38- consumeCreditsWithFallback : async ( ) =>
39- success ( {
40- chargedToOrganization : false ,
41- } ) ,
44+ // Billing
45+ consumeCreditsWithFallback : async ( ) =>
46+ success ( {
47+ chargedToOrganization : false ,
48+ } ) ,
4249
43- // LLM
44- // promptAiSdkStream: PromptAiSdkStreamFn,
45- // promptAiSdk: PromptAiSdkFn,
46- // promptAiSdkStructured: PromptAiSdkStructuredFn,
50+ // LLM
51+ // promptAiSdkStream: PromptAiSdkStreamFn,
52+ // promptAiSdk: PromptAiSdkFn,
53+ // promptAiSdkStructured: PromptAiSdkStructuredFn,
4754
48- // Mutable State
49- databaseAgentCache : new Map ( ) ,
50- liveUserInputRecord : { } ,
51- sessionConnections : { } ,
55+ // Mutable State
56+ databaseAgentCache : new Map ( ) ,
57+ liveUserInputRecord : { } ,
58+ sessionConnections : { } ,
5259
53- // Analytics
54- trackEvent,
60+ // Analytics
61+ trackEvent,
5562
56- // Other
57- logger : {
58- info : ( ) => { } ,
59- debug : ( ) => { } ,
60- warn : ( ) => { } ,
61- error : ( ) => { } ,
62- } ,
63- fetch : globalThis . fetch ,
63+ // Other
64+ logger : logger ?? {
65+ info : ( ) => { } ,
66+ debug : ( ) => { } ,
67+ warn : ( ) => { } ,
68+ error : ( ) => { } ,
69+ } ,
70+ fetch : globalThis . fetch ,
6471
65- // Client (WebSocket)
66- // handleStepsLogChunk: HandleStepsLogChunkFn,
67- // requestToolCall: RequestToolCallFn,
68- // requestMcpToolData: RequestMcpToolDataFn,
69- // requestFiles: RequestFilesFn,
70- // requestOptionalFile: RequestOptionalFileFn,
71- // sendAction: SendActionFn,
72- // sendSubagentChunk: SendSubagentChunkFn,
72+ // Client (WebSocket)
73+ // handleStepsLogChunk: HandleStepsLogChunkFn,
74+ // requestToolCall: RequestToolCallFn,
75+ // requestMcpToolData: RequestMcpToolDataFn,
76+ // requestFiles: RequestFilesFn,
77+ // requestOptionalFile: RequestOptionalFileFn,
78+ // sendAction: SendActionFn,
79+ // sendSubagentChunk: SendSubagentChunkFn,
7380
74- apiKey : process . env . CODEBUFF_API_KEY ?? '' ,
81+ apiKey,
82+ }
7583}
0 commit comments