thatgfsj-code 0.4.0 → 0.5.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/dist/app/index.d.ts +6 -14
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +28 -30
- package/dist/app/index.js.map +1 -1
- package/dist/cmd/index.js +64 -8
- package/dist/cmd/index.js.map +1 -1
- package/dist/llm/anthropic.d.ts +4 -17
- package/dist/llm/anthropic.d.ts.map +1 -1
- package/dist/llm/anthropic.js +54 -12
- package/dist/llm/anthropic.js.map +1 -1
- package/dist/llm/gemini.d.ts +3 -16
- package/dist/llm/gemini.d.ts.map +1 -1
- package/dist/llm/gemini.js +26 -22
- package/dist/llm/gemini.js.map +1 -1
- package/dist/llm/index.d.ts +5 -19
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +86 -87
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/openai.d.ts +9 -23
- package/dist/llm/openai.d.ts.map +1 -1
- package/dist/llm/openai.js +48 -14
- package/dist/llm/openai.js.map +1 -1
- package/dist/llm/provider.d.ts +11 -16
- package/dist/llm/provider.d.ts.map +1 -1
- package/dist/tui/input.d.ts +0 -1
- package/dist/tui/input.d.ts.map +1 -1
- package/dist/tui/input.js +2 -5
- package/dist/tui/input.js.map +1 -1
- package/dist/tui/output.d.ts +36 -12
- package/dist/tui/output.d.ts.map +1 -1
- package/dist/tui/output.js +172 -40
- package/dist/tui/output.js.map +1 -1
- package/dist/tui/repl.d.ts +0 -10
- package/dist/tui/repl.d.ts.map +1 -1
- package/dist/tui/repl.js +91 -43
- package/dist/tui/repl.js.map +1 -1
- package/dist/tui/welcome.d.ts +1 -11
- package/dist/tui/welcome.d.ts.map +1 -1
- package/dist/tui/welcome.js +60 -56
- package/dist/tui/welcome.js.map +1 -1
- package/package.json +1 -1
- package/src/app/index.ts +28 -33
- package/src/cmd/index.ts +53 -8
- package/src/llm/anthropic.ts +60 -14
- package/src/llm/gemini.ts +31 -24
- package/src/llm/index.ts +93 -92
- package/src/llm/openai.ts +58 -15
- package/src/llm/provider.ts +12 -16
- package/src/tui/input.ts +2 -5
- package/src/tui/output.ts +192 -40
- package/src/tui/repl.ts +94 -44
- package/src/tui/welcome.ts +62 -59
- package/src/app/agent.ts +0 -140
package/dist/app/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* App - Core application singleton
|
|
3
|
-
*
|
|
4
|
-
* Replaces the scattered initialization in old src/index.ts
|
|
3
|
+
* Simplified: directly uses LLMService (which has built-in agent loop)
|
|
5
4
|
*/
|
|
6
5
|
import { ConfigManager } from '../config/index.js';
|
|
7
6
|
import { LLMService } from '../llm/index.js';
|
|
@@ -9,7 +8,7 @@ import { SessionManager } from '../session/index.js';
|
|
|
9
8
|
import { ToolRegistry } from '../tools/index.js';
|
|
10
9
|
import { HookManager } from '../hooks/index.js';
|
|
11
10
|
import { SystemPromptBuilder } from '../prompts/index.js';
|
|
12
|
-
import {
|
|
11
|
+
import type { ChatMessage } from '../types.js';
|
|
13
12
|
export declare class App {
|
|
14
13
|
config: ConfigManager;
|
|
15
14
|
llm: LLMService;
|
|
@@ -17,23 +16,16 @@ export declare class App {
|
|
|
17
16
|
tools: ToolRegistry;
|
|
18
17
|
hooks: HookManager;
|
|
19
18
|
prompts: SystemPromptBuilder;
|
|
20
|
-
private agent;
|
|
21
19
|
private constructor();
|
|
20
|
+
static create(): Promise<App>;
|
|
22
21
|
/**
|
|
23
|
-
*
|
|
22
|
+
* Stream a response for the current session messages.
|
|
23
|
+
* The LLMService handles the full agent loop internally.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
streamResponse(messages?: ChatMessage[]): AsyncGenerator<string, void>;
|
|
26
26
|
/**
|
|
27
27
|
* Run a single prompt (non-interactive mode)
|
|
28
28
|
*/
|
|
29
29
|
runPrompt(prompt: string): Promise<string>;
|
|
30
|
-
/**
|
|
31
|
-
* Get the agent for streaming control
|
|
32
|
-
*/
|
|
33
|
-
getAgent(): Agent;
|
|
34
|
-
/**
|
|
35
|
-
* Get current config
|
|
36
|
-
*/
|
|
37
|
-
getConfig(): ConfigManager;
|
|
38
30
|
}
|
|
39
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/app/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AAE7D,qBAAa,GAAG;IACd,MAAM,EAAE,aAAa,CAAC;IACtB,GAAG,EAAE,UAAU,CAAC;IAChB,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,mBAAmB,CAAC;IAE7B,OAAO;WAgBM,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC;IAuBnC;;;OAGG;IACI,cAAc,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC;IAO7E;;OAEG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAqBjD"}
|
package/dist/app/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* App - Core application singleton
|
|
3
|
-
*
|
|
4
|
-
* Replaces the scattered initialization in old src/index.ts
|
|
3
|
+
* Simplified: directly uses LLMService (which has built-in agent loop)
|
|
5
4
|
*/
|
|
6
5
|
import { ConfigManager } from '../config/index.js';
|
|
7
6
|
import { LLMService } from '../llm/index.js';
|
|
@@ -9,7 +8,6 @@ import { SessionManager } from '../session/index.js';
|
|
|
9
8
|
import { ToolRegistry } from '../tools/index.js';
|
|
10
9
|
import { HookManager } from '../hooks/index.js';
|
|
11
10
|
import { SystemPromptBuilder } from '../prompts/index.js';
|
|
12
|
-
import { Agent } from './agent.js';
|
|
13
11
|
export class App {
|
|
14
12
|
config;
|
|
15
13
|
llm;
|
|
@@ -17,24 +15,17 @@ export class App {
|
|
|
17
15
|
tools;
|
|
18
16
|
hooks;
|
|
19
17
|
prompts;
|
|
20
|
-
|
|
21
|
-
constructor(config, llm, session, tools, hooks, prompts, agent) {
|
|
18
|
+
constructor(config, llm, session, tools, hooks, prompts) {
|
|
22
19
|
this.config = config;
|
|
23
20
|
this.llm = llm;
|
|
24
21
|
this.session = session;
|
|
25
22
|
this.tools = tools;
|
|
26
23
|
this.hooks = hooks;
|
|
27
24
|
this.prompts = prompts;
|
|
28
|
-
this.agent = agent;
|
|
29
25
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Create and initialize the App
|
|
32
|
-
*/
|
|
33
26
|
static async create() {
|
|
34
|
-
// Load config
|
|
35
27
|
const config = await ConfigManager.load();
|
|
36
28
|
const aiConfig = config.getAIConfig();
|
|
37
|
-
// Create services
|
|
38
29
|
const llm = LLMService.fromConfig(aiConfig);
|
|
39
30
|
const session = new SessionManager();
|
|
40
31
|
const tools = new ToolRegistry();
|
|
@@ -44,11 +35,21 @@ export class App {
|
|
|
44
35
|
tools: tools.list(),
|
|
45
36
|
permissionMode: 'ask',
|
|
46
37
|
});
|
|
47
|
-
//
|
|
48
|
-
|
|
38
|
+
// Register tools with LLM service
|
|
39
|
+
llm.registerTools(tools.list());
|
|
49
40
|
// Set up system prompt
|
|
50
41
|
session.addMessage('system', prompts.build());
|
|
51
|
-
return new App(config, llm, session, tools, hooks, prompts
|
|
42
|
+
return new App(config, llm, session, tools, hooks, prompts);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Stream a response for the current session messages.
|
|
46
|
+
* The LLMService handles the full agent loop internally.
|
|
47
|
+
*/
|
|
48
|
+
async *streamResponse(messages) {
|
|
49
|
+
const msgs = messages || this.session.getMessages();
|
|
50
|
+
for await (const chunk of this.llm.chatStream(msgs)) {
|
|
51
|
+
yield chunk;
|
|
52
|
+
}
|
|
52
53
|
}
|
|
53
54
|
/**
|
|
54
55
|
* Run a single prompt (non-interactive mode)
|
|
@@ -56,25 +57,22 @@ export class App {
|
|
|
56
57
|
async runPrompt(prompt) {
|
|
57
58
|
this.session.addMessage('user', prompt);
|
|
58
59
|
let fullResponse = '';
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
try {
|
|
61
|
+
for await (const chunk of this.streamResponse()) {
|
|
62
|
+
process.stdout.write(chunk);
|
|
63
|
+
fullResponse += chunk;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
// Re-throw after saving partial response
|
|
68
|
+
if (fullResponse) {
|
|
69
|
+
this.session.addMessage('assistant', fullResponse);
|
|
70
|
+
}
|
|
71
|
+
throw err;
|
|
62
72
|
}
|
|
63
|
-
console.log();
|
|
73
|
+
console.log();
|
|
64
74
|
this.session.addMessage('assistant', fullResponse);
|
|
65
75
|
return fullResponse;
|
|
66
76
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Get the agent for streaming control
|
|
69
|
-
*/
|
|
70
|
-
getAgent() {
|
|
71
|
-
return this.agent;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Get current config
|
|
75
|
-
*/
|
|
76
|
-
getConfig() {
|
|
77
|
-
return this.config;
|
|
78
|
-
}
|
|
79
77
|
}
|
|
80
78
|
//# sourceMappingURL=index.js.map
|
package/dist/app/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,MAAM,OAAO,GAAG;IACd,MAAM,CAAgB;IACtB,GAAG,CAAa;IAChB,OAAO,CAAiB;IACxB,KAAK,CAAe;IACpB,KAAK,CAAc;IACnB,OAAO,CAAsB;IAE7B,YACE,MAAqB,EACrB,GAAe,EACf,OAAuB,EACvB,KAAmB,EACnB,KAAkB,EAClB,OAA4B;QAE5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM;QACjB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,EAAE,CAA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O,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAC5B,YAAY,IAAI,KAAK,CAAC;YACxB,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,yCAAyC;YACzC,IAAI,YAAY,EAAE,CAAC;gBACjB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;YACrD,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;QAED,OAAO,CAAC,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QACnD,OAAO,YAAY,CAAC;IACtB,CAAC;CACF"}
|
package/dist/cmd/index.js
CHANGED
|
@@ -20,7 +20,6 @@ import chalk from 'chalk';
|
|
|
20
20
|
import { App } from '../app/index.js';
|
|
21
21
|
import { REPL } from '../tui/repl.js';
|
|
22
22
|
import { WelcomeScreen } from '../tui/welcome.js';
|
|
23
|
-
import { ProjectContext } from '../utils/project.js';
|
|
24
23
|
// ==================== Error Handling ====================
|
|
25
24
|
process.on('uncaughtException', (error) => {
|
|
26
25
|
console.error(chalk.red('\n❌ Error:'), error.message);
|
|
@@ -34,7 +33,7 @@ process.on('unhandledRejection', (reason) => {
|
|
|
34
33
|
program
|
|
35
34
|
.name('gfcode')
|
|
36
35
|
.description('🤖 Thatgfsj Code - AI Coding Assistant')
|
|
37
|
-
.version('0.
|
|
36
|
+
.version('0.5.0')
|
|
38
37
|
.argument('[prompt]', 'Task to execute (omit to start interactive mode)')
|
|
39
38
|
.option('-m, --model <model>', 'Specify model')
|
|
40
39
|
.option('-i, --interactive', 'Force interactive mode')
|
|
@@ -60,12 +59,69 @@ program
|
|
|
60
59
|
await repl.start();
|
|
61
60
|
}
|
|
62
61
|
else {
|
|
63
|
-
// Single prompt mode
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
// Single prompt mode - use same UI as REPL
|
|
63
|
+
const { REPLOutput } = await import('../tui/output.js');
|
|
64
|
+
const out = new REPLOutput();
|
|
65
|
+
out.printBanner();
|
|
66
|
+
out.printUserInput(prompt);
|
|
67
|
+
out.startThinking();
|
|
68
|
+
app.session.addMessage('user', prompt);
|
|
69
|
+
let fullResponse = '';
|
|
70
|
+
let hasStarted = false;
|
|
71
|
+
try {
|
|
72
|
+
const stream = app.streamResponse();
|
|
73
|
+
for await (const chunk of stream) {
|
|
74
|
+
out.stopThinking();
|
|
75
|
+
if (chunk.includes('@@TOOL@@')) {
|
|
76
|
+
const parts = chunk.split('\n');
|
|
77
|
+
for (const part of parts) {
|
|
78
|
+
if (part.startsWith('@@TOOL@@')) {
|
|
79
|
+
try {
|
|
80
|
+
const data = JSON.parse(part.slice(8));
|
|
81
|
+
if (data.action === 'call') {
|
|
82
|
+
if (hasStarted) {
|
|
83
|
+
out.endAssistant();
|
|
84
|
+
hasStarted = false;
|
|
85
|
+
}
|
|
86
|
+
out.printToolCall(data.name, data.args || '');
|
|
87
|
+
out.startExecuting(data.name);
|
|
88
|
+
}
|
|
89
|
+
else if (data.action === 'result') {
|
|
90
|
+
out.stopThinking();
|
|
91
|
+
out.printToolResult(data.output || data.error || '', !!data.error);
|
|
92
|
+
out.printToolEnd();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch { }
|
|
96
|
+
}
|
|
97
|
+
else if (part) {
|
|
98
|
+
if (!hasStarted) {
|
|
99
|
+
out.beginAssistant();
|
|
100
|
+
hasStarted = true;
|
|
101
|
+
}
|
|
102
|
+
out.writeChunk(part + '\n');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
if (!hasStarted) {
|
|
108
|
+
out.beginAssistant();
|
|
109
|
+
hasStarted = true;
|
|
110
|
+
}
|
|
111
|
+
out.writeChunk(chunk);
|
|
112
|
+
}
|
|
113
|
+
fullResponse += chunk;
|
|
114
|
+
}
|
|
115
|
+
if (hasStarted)
|
|
116
|
+
out.endAssistant();
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (hasStarted)
|
|
120
|
+
out.endAssistant();
|
|
121
|
+
out.stopThinkingFail(error.message);
|
|
122
|
+
out.error(error.message);
|
|
123
|
+
}
|
|
124
|
+
app.session.addMessage('assistant', fullResponse);
|
|
69
125
|
}
|
|
70
126
|
}
|
|
71
127
|
catch (error) {
|
package/dist/cmd/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cmd/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG;AAEH,yBAAyB;AACzB,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;IACjC,IAAI,CAAC;QACH,OAAO,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1F,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;AACZ,CAAC;AAED,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cmd/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG;AAEH,yBAAyB;AACzB,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;IACjC,IAAI,CAAC;QACH,OAAO,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,C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/anthropic.d.ts
CHANGED
|
@@ -15,31 +15,18 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { ChatMessage, ChatResponse, ChatOptions } from '../types.js';
|
|
17
17
|
import type { Tool } from '../tools/types.js';
|
|
18
|
-
import type { LLMProvider, ProviderConfig } from './provider.js';
|
|
18
|
+
import type { LLMProvider, StreamChunk, ProviderConfig } from './provider.js';
|
|
19
19
|
export declare class AnthropicProvider implements LLMProvider {
|
|
20
20
|
readonly name = "anthropic";
|
|
21
21
|
protected config: ProviderConfig;
|
|
22
22
|
constructor(config: ProviderConfig);
|
|
23
23
|
buildTools(tools: Tool[]): any[];
|
|
24
|
-
chat(messages: ChatMessage[], options?: ChatOptions): Promise<ChatResponse>;
|
|
25
|
-
chatStream(messages: ChatMessage[], options?: ChatOptions): AsyncGenerator<
|
|
24
|
+
chat(messages: ChatMessage[], options?: ChatOptions, tools?: Tool[]): Promise<ChatResponse>;
|
|
25
|
+
chatStream(messages: ChatMessage[], options?: ChatOptions, tools?: Tool[]): AsyncGenerator<StreamChunk, ChatResponse>;
|
|
26
26
|
/**
|
|
27
27
|
* Build request body for Anthropic API
|
|
28
28
|
*/
|
|
29
|
-
protected buildRequest(messages: ChatMessage[], stream: boolean, options?: ChatOptions):
|
|
30
|
-
messages: ({
|
|
31
|
-
role: string;
|
|
32
|
-
content: any[];
|
|
33
|
-
} | {
|
|
34
|
-
role: string;
|
|
35
|
-
content: string;
|
|
36
|
-
})[];
|
|
37
|
-
stream: boolean;
|
|
38
|
-
system?: string | undefined;
|
|
39
|
-
model: string;
|
|
40
|
-
max_tokens: number;
|
|
41
|
-
temperature: number;
|
|
42
|
-
};
|
|
29
|
+
protected buildRequest(messages: ChatMessage[], stream: boolean, options?: ChatOptions, tools?: Tool[]): any;
|
|
43
30
|
/**
|
|
44
31
|
* Execute the HTTP request
|
|
45
32
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/llm/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/llm/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAY,MAAM,aAAa,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE9E,qBAAa,iBAAkB,YAAW,WAAW;IACnD,QAAQ,CAAC,IAAI,eAAe;IAC5B,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC;gBAErB,MAAM,EAAE,cAAc;IAIlC,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,GAAG,EAAE;IAc1B,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAsC1F,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC;IAwF5H;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE;IAwDtG;;OAEG;cACa,SAAS,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;CAYxD"}
|
package/dist/llm/anthropic.js
CHANGED
|
@@ -30,8 +30,8 @@ export class AnthropicProvider {
|
|
|
30
30
|
},
|
|
31
31
|
}));
|
|
32
32
|
}
|
|
33
|
-
async chat(messages, options) {
|
|
34
|
-
const body = this.buildRequest(messages, false, options);
|
|
33
|
+
async chat(messages, options, tools) {
|
|
34
|
+
const body = this.buildRequest(messages, false, options, tools);
|
|
35
35
|
const response = await this.doRequest(body);
|
|
36
36
|
if (!response.ok) {
|
|
37
37
|
const text = await response.text().catch(() => '');
|
|
@@ -62,8 +62,8 @@ export class AnthropicProvider {
|
|
|
62
62
|
tool_calls: toolCalls,
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
async *chatStream(messages, options) {
|
|
66
|
-
const body = this.buildRequest(messages, true, options);
|
|
65
|
+
async *chatStream(messages, options, tools) {
|
|
66
|
+
const body = this.buildRequest(messages, true, options, tools);
|
|
67
67
|
const response = await this.doRequest(body);
|
|
68
68
|
if (!response.ok || !response.body) {
|
|
69
69
|
const text = await response.text().catch(() => '');
|
|
@@ -73,6 +73,10 @@ export class AnthropicProvider {
|
|
|
73
73
|
const decoder = new TextDecoder();
|
|
74
74
|
let fullContent = '';
|
|
75
75
|
let buffer = '';
|
|
76
|
+
// Track tool use blocks
|
|
77
|
+
const toolUseBlocks = new Map();
|
|
78
|
+
let currentBlockIndex = -1;
|
|
79
|
+
let currentBlockType = '';
|
|
76
80
|
try {
|
|
77
81
|
while (true) {
|
|
78
82
|
const { done, value } = await reader.read();
|
|
@@ -87,11 +91,31 @@ export class AnthropicProvider {
|
|
|
87
91
|
continue;
|
|
88
92
|
try {
|
|
89
93
|
const data = JSON.parse(trimmed.slice(6));
|
|
90
|
-
//
|
|
91
|
-
if (data.type === '
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
// content_block_start: track block types
|
|
95
|
+
if (data.type === 'content_block_start') {
|
|
96
|
+
currentBlockIndex = data.index ?? 0;
|
|
97
|
+
currentBlockType = data.content_block?.type || '';
|
|
98
|
+
if (currentBlockType === 'tool_use') {
|
|
99
|
+
toolUseBlocks.set(currentBlockIndex, {
|
|
100
|
+
id: data.content_block.id || '',
|
|
101
|
+
name: data.content_block.name || '',
|
|
102
|
+
input: '',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// content_block_delta: incremental text or tool input
|
|
107
|
+
if (data.type === 'content_block_delta') {
|
|
108
|
+
if (data.delta?.type === 'text_delta') {
|
|
109
|
+
const text = data.delta.text;
|
|
110
|
+
fullContent += text;
|
|
111
|
+
yield { type: 'text', content: text };
|
|
112
|
+
}
|
|
113
|
+
else if (data.delta?.type === 'input_json_delta') {
|
|
114
|
+
const buf = toolUseBlocks.get(currentBlockIndex);
|
|
115
|
+
if (buf) {
|
|
116
|
+
buf.input += data.delta.partial_json || '';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
95
119
|
}
|
|
96
120
|
}
|
|
97
121
|
catch {
|
|
@@ -103,12 +127,26 @@ export class AnthropicProvider {
|
|
|
103
127
|
finally {
|
|
104
128
|
reader.releaseLock();
|
|
105
129
|
}
|
|
106
|
-
|
|
130
|
+
// Convert tool use blocks to ToolCall[]
|
|
131
|
+
const toolCalls = [];
|
|
132
|
+
for (const [, buf] of toolUseBlocks) {
|
|
133
|
+
if (buf.id && buf.name) {
|
|
134
|
+
toolCalls.push({
|
|
135
|
+
id: buf.id,
|
|
136
|
+
type: 'function',
|
|
137
|
+
function: { name: buf.name, arguments: buf.input },
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (toolCalls.length > 0) {
|
|
142
|
+
yield { type: 'tool_calls', toolCalls };
|
|
143
|
+
}
|
|
144
|
+
return { content: fullContent, role: 'assistant', tool_calls: toolCalls.length > 0 ? toolCalls : undefined };
|
|
107
145
|
}
|
|
108
146
|
/**
|
|
109
147
|
* Build request body for Anthropic API
|
|
110
148
|
*/
|
|
111
|
-
buildRequest(messages, stream, options) {
|
|
149
|
+
buildRequest(messages, stream, options, tools) {
|
|
112
150
|
// Anthropic uses separate system message
|
|
113
151
|
const systemMsg = messages.find(m => m.role === 'system');
|
|
114
152
|
const nonSystemMsgs = messages.filter(m => m.role !== 'system');
|
|
@@ -146,7 +184,7 @@ export class AnthropicProvider {
|
|
|
146
184
|
content: m.content,
|
|
147
185
|
};
|
|
148
186
|
});
|
|
149
|
-
|
|
187
|
+
const body = {
|
|
150
188
|
model: this.config.model,
|
|
151
189
|
max_tokens: options?.maxTokens ?? this.config.maxTokens ?? 4096,
|
|
152
190
|
temperature: options?.temperature ?? this.config.temperature,
|
|
@@ -154,6 +192,10 @@ export class AnthropicProvider {
|
|
|
154
192
|
messages: anthropicMessages,
|
|
155
193
|
stream,
|
|
156
194
|
};
|
|
195
|
+
if (tools && tools.length > 0) {
|
|
196
|
+
body.tools = this.buildTools(tools);
|
|
197
|
+
}
|
|
198
|
+
return body;
|
|
157
199
|
}
|
|
158
200
|
/**
|
|
159
201
|
* Execute the HTTP request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/llm/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,MAAM,OAAO,iBAAiB;IACnB,IAAI,GAAG,WAAW,CAAC;IAClB,MAAM,CAAiB;IAEjC,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,UAAU,CAAC,KAAa;QACtB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACxB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,YAAY,EAAE,IAAI,CAAC,WAAW,IAAI;gBAChC,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,MAAM,CAAC,WAAW,CAC5B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE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AG,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,SAAS,CAAC,IAAS;QACjC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,WAAW,CAAC;QAC9C,OAAO,KAAK,CAAC,GAAG,EAAE;YAChB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC/B,mBAAmB,EAAE,YAAY;aAClC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/llm/gemini.d.ts
CHANGED
|
@@ -1,29 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Google Gemini Provider
|
|
3
|
-
*
|
|
4
|
-
* API: POST {baseUrl}/models/{model}:streamGenerateContent?key={apiKey}
|
|
5
|
-
* Auth: API key in URL query parameter
|
|
6
|
-
* Streaming: JSON array chunks (not SSE)
|
|
7
|
-
*
|
|
8
|
-
* Key differences:
|
|
9
|
-
* - No "system" role in contents, use "systemInstruction" field
|
|
10
|
-
* - Roles are "user" and "model" (not "assistant")
|
|
11
|
-
* - Content is array of "parts" with "text" field
|
|
12
|
-
* - Auth via URL query param, not header
|
|
13
3
|
*/
|
|
14
4
|
import type { ChatMessage, ChatResponse, ChatOptions } from '../types.js';
|
|
15
5
|
import type { Tool } from '../tools/types.js';
|
|
16
|
-
import type { LLMProvider, ProviderConfig } from './provider.js';
|
|
6
|
+
import type { LLMProvider, StreamChunk, ProviderConfig } from './provider.js';
|
|
17
7
|
export declare class GeminiProvider implements LLMProvider {
|
|
18
8
|
readonly name = "gemini";
|
|
19
9
|
protected config: ProviderConfig;
|
|
20
10
|
constructor(config: ProviderConfig);
|
|
21
11
|
buildTools(tools: Tool[]): any[];
|
|
22
|
-
chat(messages: ChatMessage[], options?: ChatOptions): Promise<ChatResponse>;
|
|
23
|
-
chatStream(messages: ChatMessage[], options?: ChatOptions): AsyncGenerator<
|
|
24
|
-
/**
|
|
25
|
-
* Build request body for Gemini API
|
|
26
|
-
*/
|
|
12
|
+
chat(messages: ChatMessage[], options?: ChatOptions, tools?: Tool[]): Promise<ChatResponse>;
|
|
13
|
+
chatStream(messages: ChatMessage[], options?: ChatOptions, tools?: Tool[]): AsyncGenerator<StreamChunk, ChatResponse>;
|
|
27
14
|
private buildRequest;
|
|
28
15
|
}
|
|
29
16
|
//# sourceMappingURL=gemini.d.ts.map
|
package/dist/llm/gemini.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../src/llm/gemini.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../src/llm/gemini.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAY,MAAM,aAAa,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE9E,qBAAa,cAAe,YAAW,WAAW;IAChD,QAAQ,CAAC,IAAI,YAAY;IACzB,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC;gBAErB,MAAM,EAAE,cAAc;IAIlC,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,GAAG,EAAE;IAgB1B,IAAI,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAyC1F,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC;IAqE5H,OAAO,CAAC,YAAY;CA0BrB"}
|
package/dist/llm/gemini.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Google Gemini Provider
|
|
3
|
-
*
|
|
4
|
-
* API: POST {baseUrl}/models/{model}:streamGenerateContent?key={apiKey}
|
|
5
|
-
* Auth: API key in URL query parameter
|
|
6
|
-
* Streaming: JSON array chunks (not SSE)
|
|
7
|
-
*
|
|
8
|
-
* Key differences:
|
|
9
|
-
* - No "system" role in contents, use "systemInstruction" field
|
|
10
|
-
* - Roles are "user" and "model" (not "assistant")
|
|
11
|
-
* - Content is array of "parts" with "text" field
|
|
12
|
-
* - Auth via URL query param, not header
|
|
13
3
|
*/
|
|
14
4
|
export class GeminiProvider {
|
|
15
5
|
name = 'gemini';
|
|
@@ -30,8 +20,8 @@ export class GeminiProvider {
|
|
|
30
20
|
})),
|
|
31
21
|
}];
|
|
32
22
|
}
|
|
33
|
-
async chat(messages, options) {
|
|
34
|
-
const body = this.buildRequest(messages, options);
|
|
23
|
+
async chat(messages, options, tools) {
|
|
24
|
+
const body = this.buildRequest(messages, options, tools);
|
|
35
25
|
const url = `${this.config.baseUrl}/models/${this.config.model}:generateContent?key=${this.config.apiKey}`;
|
|
36
26
|
const response = await fetch(url, {
|
|
37
27
|
method: 'POST',
|
|
@@ -46,7 +36,6 @@ export class GeminiProvider {
|
|
|
46
36
|
const candidate = data.candidates?.[0];
|
|
47
37
|
const parts = candidate?.content?.parts || [];
|
|
48
38
|
const text = parts.map((p) => p.text).filter(Boolean).join('');
|
|
49
|
-
// Extract function calls
|
|
50
39
|
const functionCalls = parts.filter((p) => p.functionCall).map((p) => ({
|
|
51
40
|
id: `call_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
52
41
|
type: 'function',
|
|
@@ -66,8 +55,8 @@ export class GeminiProvider {
|
|
|
66
55
|
tool_calls: functionCalls.length > 0 ? functionCalls : undefined,
|
|
67
56
|
};
|
|
68
57
|
}
|
|
69
|
-
async *chatStream(messages, options) {
|
|
70
|
-
const body = this.buildRequest(messages, options);
|
|
58
|
+
async *chatStream(messages, options, tools) {
|
|
59
|
+
const body = this.buildRequest(messages, options, tools);
|
|
71
60
|
const url = `${this.config.baseUrl}/models/${this.config.model}:streamGenerateContent?alt=sse&key=${this.config.apiKey}`;
|
|
72
61
|
const response = await fetch(url, {
|
|
73
62
|
method: 'POST',
|
|
@@ -82,6 +71,7 @@ export class GeminiProvider {
|
|
|
82
71
|
const decoder = new TextDecoder();
|
|
83
72
|
let fullContent = '';
|
|
84
73
|
let buffer = '';
|
|
74
|
+
const functionCalls = [];
|
|
85
75
|
try {
|
|
86
76
|
while (true) {
|
|
87
77
|
const { done, value } = await reader.read();
|
|
@@ -100,7 +90,17 @@ export class GeminiProvider {
|
|
|
100
90
|
for (const part of parts) {
|
|
101
91
|
if (part.text) {
|
|
102
92
|
fullContent += part.text;
|
|
103
|
-
yield part.text;
|
|
93
|
+
yield { type: 'text', content: part.text };
|
|
94
|
+
}
|
|
95
|
+
if (part.functionCall) {
|
|
96
|
+
functionCalls.push({
|
|
97
|
+
id: `call_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
98
|
+
type: 'function',
|
|
99
|
+
function: {
|
|
100
|
+
name: part.functionCall.name,
|
|
101
|
+
arguments: JSON.stringify(part.functionCall.args || {}),
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -113,19 +113,19 @@ export class GeminiProvider {
|
|
|
113
113
|
finally {
|
|
114
114
|
reader.releaseLock();
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
if (functionCalls.length > 0) {
|
|
117
|
+
yield { type: 'tool_calls', toolCalls: functionCalls };
|
|
118
|
+
}
|
|
119
|
+
return { content: fullContent, role: 'assistant', tool_calls: functionCalls.length > 0 ? functionCalls : undefined };
|
|
117
120
|
}
|
|
118
|
-
|
|
119
|
-
* Build request body for Gemini API
|
|
120
|
-
*/
|
|
121
|
-
buildRequest(messages, options) {
|
|
121
|
+
buildRequest(messages, options, tools) {
|
|
122
122
|
const systemMsg = messages.find(m => m.role === 'system');
|
|
123
123
|
const nonSystemMsgs = messages.filter(m => m.role !== 'system');
|
|
124
124
|
const contents = nonSystemMsgs.map(m => ({
|
|
125
125
|
role: m.role === 'assistant' ? 'model' : 'user',
|
|
126
126
|
parts: [{ text: m.content }],
|
|
127
127
|
}));
|
|
128
|
-
|
|
128
|
+
const body = {
|
|
129
129
|
contents,
|
|
130
130
|
...(systemMsg && {
|
|
131
131
|
systemInstruction: { parts: [{ text: systemMsg.content }] },
|
|
@@ -135,6 +135,10 @@ export class GeminiProvider {
|
|
|
135
135
|
maxOutputTokens: options?.maxTokens ?? this.config.maxTokens,
|
|
136
136
|
},
|
|
137
137
|
};
|
|
138
|
+
if (tools && tools.length > 0) {
|
|
139
|
+
body.tools = this.buildTools(tools);
|
|
140
|
+
}
|
|
141
|
+
return body;
|
|
138
142
|
}
|
|
139
143
|
}
|
|
140
144
|
//# sourceMappingURL=gemini.js.map
|