@omaikit/agents 0.1.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 +31 -0
- package/dist/agent.d.ts +31 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +30 -0
- package/dist/agent.js.map +1 -0
- package/dist/ai-provider/anthropic.d.ts +13 -0
- package/dist/ai-provider/anthropic.d.ts.map +1 -0
- package/dist/ai-provider/anthropic.js +85 -0
- package/dist/ai-provider/anthropic.js.map +1 -0
- package/dist/ai-provider/factory.d.ts +3 -0
- package/dist/ai-provider/factory.d.ts.map +1 -0
- package/dist/ai-provider/factory.js +22 -0
- package/dist/ai-provider/factory.js.map +1 -0
- package/dist/ai-provider/openai.d.ts +16 -0
- package/dist/ai-provider/openai.d.ts.map +1 -0
- package/dist/ai-provider/openai.js +252 -0
- package/dist/ai-provider/openai.js.map +1 -0
- package/dist/ai-provider/provider.d.ts +25 -0
- package/dist/ai-provider/provider.d.ts.map +1 -0
- package/dist/ai-provider/provider.js +2 -0
- package/dist/ai-provider/provider.js.map +1 -0
- package/dist/ai-provider/token-manager.d.ts +12 -0
- package/dist/ai-provider/token-manager.d.ts.map +1 -0
- package/dist/ai-provider/token-manager.js +63 -0
- package/dist/ai-provider/token-manager.js.map +1 -0
- package/dist/coder/code-parser.d.ts +23 -0
- package/dist/coder/code-parser.d.ts.map +1 -0
- package/dist/coder/code-parser.js +184 -0
- package/dist/coder/code-parser.js.map +1 -0
- package/dist/coder/coder.d.ts +79 -0
- package/dist/coder/coder.d.ts.map +1 -0
- package/dist/coder/coder.js +476 -0
- package/dist/coder/coder.js.map +1 -0
- package/dist/coder/dependency-resolver.d.ts +23 -0
- package/dist/coder/dependency-resolver.d.ts.map +1 -0
- package/dist/coder/dependency-resolver.js +94 -0
- package/dist/coder/dependency-resolver.js.map +1 -0
- package/dist/coder/language-handlers.d.ts +38 -0
- package/dist/coder/language-handlers.d.ts.map +1 -0
- package/dist/coder/language-handlers.js +264 -0
- package/dist/coder/language-handlers.js.map +1 -0
- package/dist/coder/linter-integration.d.ts +37 -0
- package/dist/coder/linter-integration.d.ts.map +1 -0
- package/dist/coder/linter-integration.js +200 -0
- package/dist/coder/linter-integration.js.map +1 -0
- package/dist/coder/prompt-templates.d.ts +13 -0
- package/dist/coder/prompt-templates.d.ts.map +1 -0
- package/dist/coder/prompt-templates.js +78 -0
- package/dist/coder/prompt-templates.js.map +1 -0
- package/dist/coder/quality-checker.d.ts +31 -0
- package/dist/coder/quality-checker.d.ts.map +1 -0
- package/dist/coder/quality-checker.js +264 -0
- package/dist/coder/quality-checker.js.map +1 -0
- package/dist/coder/syntax-validator.d.ts +21 -0
- package/dist/coder/syntax-validator.d.ts.map +1 -0
- package/dist/coder/syntax-validator.js +169 -0
- package/dist/coder/syntax-validator.js.map +1 -0
- package/dist/coder.d.ts +2 -0
- package/dist/coder.d.ts.map +1 -0
- package/dist/coder.js +2 -0
- package/dist/coder.js.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +16 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +12 -0
- package/dist/logger.js.map +1 -0
- package/dist/manager/manager.d.ts +31 -0
- package/dist/manager/manager.d.ts.map +1 -0
- package/dist/manager/manager.js +162 -0
- package/dist/manager/manager.js.map +1 -0
- package/dist/memory/memory-store.d.ts +20 -0
- package/dist/memory/memory-store.d.ts.map +1 -0
- package/dist/memory/memory-store.js +68 -0
- package/dist/memory/memory-store.js.map +1 -0
- package/dist/planner/clarification-handler.d.ts +11 -0
- package/dist/planner/clarification-handler.d.ts.map +1 -0
- package/dist/planner/clarification-handler.js +60 -0
- package/dist/planner/clarification-handler.js.map +1 -0
- package/dist/planner/plan-parser.d.ts +11 -0
- package/dist/planner/plan-parser.d.ts.map +1 -0
- package/dist/planner/plan-parser.js +136 -0
- package/dist/planner/plan-parser.js.map +1 -0
- package/dist/planner/plan-validator.d.ts +29 -0
- package/dist/planner/plan-validator.d.ts.map +1 -0
- package/dist/planner/plan-validator.js +123 -0
- package/dist/planner/plan-validator.js.map +1 -0
- package/dist/planner/planner.d.ts +25 -0
- package/dist/planner/planner.d.ts.map +1 -0
- package/dist/planner/planner.js +334 -0
- package/dist/planner/planner.js.map +1 -0
- package/dist/planner/prompt-templates.d.ts +9 -0
- package/dist/planner/prompt-templates.d.ts.map +1 -0
- package/dist/planner/prompt-templates.js +168 -0
- package/dist/planner/prompt-templates.js.map +1 -0
- package/dist/planner.d.ts +2 -0
- package/dist/planner.d.ts.map +1 -0
- package/dist/planner.js +2 -0
- package/dist/planner.js.map +1 -0
- package/dist/reviewer/reviewer.d.ts +29 -0
- package/dist/reviewer/reviewer.d.ts.map +1 -0
- package/dist/reviewer/reviewer.js +40 -0
- package/dist/reviewer/reviewer.js.map +1 -0
- package/dist/reviewer.d.ts +2 -0
- package/dist/reviewer.d.ts.map +1 -0
- package/dist/reviewer.js +2 -0
- package/dist/reviewer.js.map +1 -0
- package/dist/tester/coverage-analyzer.d.ts +9 -0
- package/dist/tester/coverage-analyzer.d.ts.map +1 -0
- package/dist/tester/coverage-analyzer.js +18 -0
- package/dist/tester/coverage-analyzer.js.map +1 -0
- package/dist/tester/coverage-validator.d.ts +10 -0
- package/dist/tester/coverage-validator.d.ts.map +1 -0
- package/dist/tester/coverage-validator.js +14 -0
- package/dist/tester/coverage-validator.js.map +1 -0
- package/dist/tester/framework-detector.d.ts +4 -0
- package/dist/tester/framework-detector.d.ts.map +1 -0
- package/dist/tester/framework-detector.js +26 -0
- package/dist/tester/framework-detector.js.map +1 -0
- package/dist/tester/prompt-templates.d.ts +6 -0
- package/dist/tester/prompt-templates.d.ts.map +1 -0
- package/dist/tester/prompt-templates.js +30 -0
- package/dist/tester/prompt-templates.js.map +1 -0
- package/dist/tester/test-executor.d.ts +11 -0
- package/dist/tester/test-executor.d.ts.map +1 -0
- package/dist/tester/test-executor.js +24 -0
- package/dist/tester/test-executor.js.map +1 -0
- package/dist/tester/test-parser.d.ts +10 -0
- package/dist/tester/test-parser.d.ts.map +1 -0
- package/dist/tester/test-parser.js +83 -0
- package/dist/tester/test-parser.js.map +1 -0
- package/dist/tester/test-patterns.d.ts +10 -0
- package/dist/tester/test-patterns.d.ts.map +1 -0
- package/dist/tester/test-patterns.js +65 -0
- package/dist/tester/test-patterns.js.map +1 -0
- package/dist/tester/tester.d.ts +56 -0
- package/dist/tester/tester.d.ts.map +1 -0
- package/dist/tester/tester.js +246 -0
- package/dist/tester/tester.js.map +1 -0
- package/dist/tester.d.ts +3 -0
- package/dist/tester.d.ts.map +1 -0
- package/dist/tester.js +2 -0
- package/dist/tester.js.map +1 -0
- package/dist/tools/default-registry.d.ts +3 -0
- package/dist/tools/default-registry.d.ts.map +1 -0
- package/dist/tools/default-registry.js +12 -0
- package/dist/tools/default-registry.js.map +1 -0
- package/dist/tools/edit.d.ts +4 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +95 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/read.d.ts +4 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +39 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/registry.d.ts +11 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +31 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/search.d.ts +4 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +52 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/types.d.ts +37 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/utils.d.ts +10 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +76 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
## @omaikit/agents
|
|
2
|
+
|
|
3
|
+
Agent implementations for Omaikit. This package provides the core agent classes that power planning, code generation, and testing.
|
|
4
|
+
|
|
5
|
+
### Included Agents
|
|
6
|
+
|
|
7
|
+
- Manager (context initialization)
|
|
8
|
+
- Planner (plan generation)
|
|
9
|
+
- Coder (code generation)
|
|
10
|
+
- Tester (test generation)
|
|
11
|
+
- Reviewer (code review)
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { CoderAgent } from '@omaikit/agents';
|
|
17
|
+
|
|
18
|
+
const coder = new CoderAgent();
|
|
19
|
+
await coder.init();
|
|
20
|
+
const output = await coder.execute({
|
|
21
|
+
task: { /* task data */ } as any,
|
|
22
|
+
plan: null,
|
|
23
|
+
projectContext: { /* context */ } as any,
|
|
24
|
+
history: [],
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Notes
|
|
29
|
+
|
|
30
|
+
- Agent memory is stored under `.omaikit/memory/` during execution.
|
|
31
|
+
- Type declarations are consolidated at the repo root in types.d.ts for local development.
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base agent implementation
|
|
3
|
+
*/
|
|
4
|
+
import { AgentInput, AgentOutput } from './types.js';
|
|
5
|
+
import { Logger } from './logger.js';
|
|
6
|
+
export declare abstract class Agent {
|
|
7
|
+
protected logger: Logger;
|
|
8
|
+
name: string;
|
|
9
|
+
constructor(logger?: Logger);
|
|
10
|
+
/**
|
|
11
|
+
* Initialize agent resources. Called once before execution.
|
|
12
|
+
*/
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Hook before execution.
|
|
16
|
+
*/
|
|
17
|
+
beforeExecute(input: AgentInput): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Execute the agent's main logic.
|
|
20
|
+
*/
|
|
21
|
+
abstract execute(input: AgentInput): Promise<AgentOutput>;
|
|
22
|
+
/**
|
|
23
|
+
* Hook after execution.
|
|
24
|
+
*/
|
|
25
|
+
afterExecute(output: AgentOutput): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Error handler hook.
|
|
28
|
+
*/
|
|
29
|
+
onError(error: Error): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,8BAAsB,KAAK;IACzB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAW;gBAElB,MAAM,CAAC,EAAE,MAAM;IAI3B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAE3B;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAErD;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;IAEzD;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAEtD;;OAEG;IACG,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAG3C"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base agent implementation
|
|
3
|
+
*/
|
|
4
|
+
import { Logger } from './logger.js';
|
|
5
|
+
export class Agent {
|
|
6
|
+
logger;
|
|
7
|
+
name = 'Agent';
|
|
8
|
+
constructor(logger) {
|
|
9
|
+
this.logger = logger ?? new Logger();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Initialize agent resources. Called once before execution.
|
|
13
|
+
*/
|
|
14
|
+
async init() { }
|
|
15
|
+
/**
|
|
16
|
+
* Hook before execution.
|
|
17
|
+
*/
|
|
18
|
+
async beforeExecute(input) { }
|
|
19
|
+
/**
|
|
20
|
+
* Hook after execution.
|
|
21
|
+
*/
|
|
22
|
+
async afterExecute(output) { }
|
|
23
|
+
/**
|
|
24
|
+
* Error handler hook.
|
|
25
|
+
*/
|
|
26
|
+
async onError(error) {
|
|
27
|
+
this.logger.error('Agent error', { error: String(error) });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,OAAgB,KAAK;IACf,MAAM,CAAS;IAClB,IAAI,GAAW,OAAO,CAAC;IAE9B,YAAY,MAAe;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,KAAmB,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,KAAiB,IAAkB,CAAC;IAOxD;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,MAAmB,IAAkB,CAAC;IAEzD;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,KAAY;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AIProvider, AIProviderOptions } from './provider.js';
|
|
2
|
+
export declare class AnthropicProvider implements AIProvider {
|
|
3
|
+
private apiKey?;
|
|
4
|
+
private client;
|
|
5
|
+
constructor(apiKey?: string);
|
|
6
|
+
init(config?: Record<string, unknown>): Promise<void>;
|
|
7
|
+
generate(prompt: string, options?: AIProviderOptions): Promise<string>;
|
|
8
|
+
private generateStream;
|
|
9
|
+
complete(prompt: string): Promise<string>;
|
|
10
|
+
onProgress(_callback: (chunk: string) => void): void;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/ai-provider/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE3D,qBAAa,iBAAkB,YAAW,UAAU;IAClD,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,MAAM,CAA0B;gBAE5B,MAAM,CAAC,EAAE,MAAM;IAIrB,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAarD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;YAmC9D,cAAc;IA2BtB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/C,UAAU,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAI9C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
export class AnthropicProvider {
|
|
3
|
+
apiKey;
|
|
4
|
+
client = null;
|
|
5
|
+
constructor(apiKey) {
|
|
6
|
+
this.apiKey = apiKey ?? process.env.ANTHROPIC_API_KEY;
|
|
7
|
+
}
|
|
8
|
+
async init(config) {
|
|
9
|
+
if (config && config.apiKey)
|
|
10
|
+
this.apiKey = config.apiKey;
|
|
11
|
+
if (!this.apiKey)
|
|
12
|
+
return;
|
|
13
|
+
try {
|
|
14
|
+
this.client = new Anthropic({ apiKey: this.apiKey });
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
// Client may not be available in all environments
|
|
18
|
+
this.client = null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async generate(prompt, options) {
|
|
22
|
+
if (!this.client) {
|
|
23
|
+
// Fallback echo mode when client not available
|
|
24
|
+
if (!this.apiKey)
|
|
25
|
+
return `ANTHROPIC_ECHO:\n${prompt}`;
|
|
26
|
+
// Try to initialize if not done yet
|
|
27
|
+
await this.init();
|
|
28
|
+
if (!this.client)
|
|
29
|
+
return `ANTHROPIC_ECHO:\n${prompt}`;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const model = (options && options.model) || 'claude-3-5-sonnet-20241022';
|
|
33
|
+
const maxTokens = options?.maxTokens || 1024;
|
|
34
|
+
if (options?.stream && options?.onProgress) {
|
|
35
|
+
// Use streaming with official SDK
|
|
36
|
+
return await this.generateStream(prompt, model, maxTokens, options.onProgress);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Non-streaming completion
|
|
40
|
+
const message = await this.client.messages.create({
|
|
41
|
+
model,
|
|
42
|
+
max_tokens: maxTokens,
|
|
43
|
+
messages: [{ role: 'user', content: prompt }],
|
|
44
|
+
});
|
|
45
|
+
const text = message.content[0]?.text || '';
|
|
46
|
+
if (options?.onProgress)
|
|
47
|
+
options.onProgress(text);
|
|
48
|
+
return text;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const err = error;
|
|
53
|
+
const message = err?.message || String(error);
|
|
54
|
+
throw new Error(`Anthropic API error: ${message}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async generateStream(prompt, model, maxTokens, onProgress) {
|
|
58
|
+
let accumulated = '';
|
|
59
|
+
const stream = this.client?.messages.stream({
|
|
60
|
+
model,
|
|
61
|
+
max_tokens: maxTokens,
|
|
62
|
+
messages: [{ role: 'user', content: prompt }],
|
|
63
|
+
});
|
|
64
|
+
for await (const chunk of stream ?? []) {
|
|
65
|
+
if (chunk.type === 'content_block_delta' && chunk.delta?.type === 'text_delta') {
|
|
66
|
+
const text = chunk.delta.text;
|
|
67
|
+
if (text) {
|
|
68
|
+
accumulated += text;
|
|
69
|
+
onProgress(text);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return accumulated;
|
|
74
|
+
}
|
|
75
|
+
async complete(prompt) {
|
|
76
|
+
return this.generate(prompt);
|
|
77
|
+
}
|
|
78
|
+
onProgress(_callback) {
|
|
79
|
+
// Progress callback handled in generate method
|
|
80
|
+
}
|
|
81
|
+
async close() {
|
|
82
|
+
// Anthropic client doesn't need explicit closing
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/ai-provider/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAG1C,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAU;IAChB,MAAM,GAAqB,IAAI,CAAC;IAExC,YAAY,MAAe;Q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CAAC,IAAI,CAAC;gBACvC,IAAI,IAAI,EAAE,CAAC;oBACT,WAAW,IAAI,IAAI,CAAC;oBACpB,UAAU,CAAC,IAAI,CAAC,CAAC;gBACnB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,UAAU,CAAC,SAAkC;QAC3C,+CAA+C;IACjD,CAAC;IAED,KAAK,CAAC,KAAK;QACT,iDAAiD;IACnD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/ai-provider/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAKxC,wBAAgB,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAqB1F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { OpenAIProvider } from './openai.js';
|
|
2
|
+
import { AnthropicProvider } from './anthropic.js';
|
|
3
|
+
import { loadConfig } from '@omaikit/config';
|
|
4
|
+
export function createProvider(name, config) {
|
|
5
|
+
const cfg = loadConfig();
|
|
6
|
+
const providerName = (name || cfg.provider || process.env.OMAIKIT_PROVIDER || 'openai')
|
|
7
|
+
.toString()
|
|
8
|
+
.toLowerCase();
|
|
9
|
+
switch (providerName) {
|
|
10
|
+
case 'openai':
|
|
11
|
+
return new OpenAIProvider(cfg.openaiApiKey ??
|
|
12
|
+
(config && config.apiKey) ??
|
|
13
|
+
process.env.OPENAI_API_KEY);
|
|
14
|
+
case 'anthropic':
|
|
15
|
+
return new AnthropicProvider(cfg.anthropicApiKey ??
|
|
16
|
+
(config && config.apiKey) ??
|
|
17
|
+
process.env.ANTHROPIC_API_KEY);
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Unknown provider: ${providerName}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/ai-provider/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,UAAU,cAAc,CAAC,IAAa,EAAE,MAAgC;IAC5E,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,MAAM,YAAY,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,QAAQ,CAAC;SACpF,QAAQ,EAAE;SACV,WAAW,EAAE,CAAC;IACjB,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,IAAI,cAAc,CACvB,GAAG,CAAC,YAAY;gBACb,CAAC,MAAM,IAAK,MAAc,CAAC,MAAM,CAAwB;gBAC1D,OAAO,CAAC,GAAG,CAAC,cAAc,CAC7B,CAAC;QACJ,KAAK,WAAW;YACd,OAAO,IAAI,iBAAiB,CAC1B,GAAG,CAAC,eAAe;gBAChB,CAAC,MAAM,IAAK,MAAc,CAAC,MAAM,CAAwB;gBAC1D,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAChC,CAAC;QACJ;YACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,YAAY,EAAE,CAAC,CAAC;IACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AIProvider, AIProviderOptions } from './provider.js';
|
|
2
|
+
export declare class OpenAIProvider implements AIProvider {
|
|
3
|
+
private apiKey?;
|
|
4
|
+
private client;
|
|
5
|
+
constructor(apiKey?: string);
|
|
6
|
+
init(config?: Record<string, unknown>): Promise<void>;
|
|
7
|
+
generate(prompt: string, options?: AIProviderOptions): Promise<string>;
|
|
8
|
+
generateCodex(prompt: string, options?: AIProviderOptions): Promise<string>;
|
|
9
|
+
private formatToolsForResponses;
|
|
10
|
+
complete(prompt: string): Promise<string>;
|
|
11
|
+
onProgress(_callback: (chunk: string) => void): void;
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
private resolveTools;
|
|
14
|
+
private extractToolCalls;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/ai-provider/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAK3D,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,MAAM,CAAuB;gBAEzB,MAAM,CAAC,EAAE,MAAM;IAIrB,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAYrD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAgGtE,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IA4EjF,OAAO,CAAC,uBAAuB;IAUzB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/C,UAAU,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAI9C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,gBAAgB;CA4CzB"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
export class OpenAIProvider {
|
|
3
|
+
apiKey;
|
|
4
|
+
client = null;
|
|
5
|
+
constructor(apiKey) {
|
|
6
|
+
this.apiKey = apiKey ?? process.env.OPENAI_API_KEY;
|
|
7
|
+
}
|
|
8
|
+
async init(config) {
|
|
9
|
+
if (config && config.apiKey)
|
|
10
|
+
this.apiKey = config.apiKey;
|
|
11
|
+
if (!this.apiKey)
|
|
12
|
+
return;
|
|
13
|
+
try {
|
|
14
|
+
this.client = new OpenAI({ apiKey: this.apiKey });
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
// Client may not be available in all environments
|
|
18
|
+
this.client = null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async generate(prompt, options) {
|
|
22
|
+
if (!this.client) {
|
|
23
|
+
// Fallback echo mode when client not available
|
|
24
|
+
if (!this.apiKey)
|
|
25
|
+
return `OPENAI_ECHO:\n${prompt}`;
|
|
26
|
+
// Try to initialize if not done yet
|
|
27
|
+
await this.init();
|
|
28
|
+
if (!this.client)
|
|
29
|
+
return `OPENAI_ECHO:\n${prompt}`;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const model = (options && options.model) || 'gpt-5-mini';
|
|
33
|
+
const maxTokens = options?.maxTokens || undefined;
|
|
34
|
+
const temperature = options?.temperature || undefined;
|
|
35
|
+
const tools = this.resolveTools(options);
|
|
36
|
+
if (tools.length > 0) {
|
|
37
|
+
if (!options?.toolRegistry) {
|
|
38
|
+
throw new Error('Tool calls requested but no tool registry provided');
|
|
39
|
+
}
|
|
40
|
+
const messages = [{ role: 'user', content: prompt }];
|
|
41
|
+
const maxToolCalls = options.maxToolCalls ?? 3;
|
|
42
|
+
let lastContent = '';
|
|
43
|
+
for (let i = 0; i <= maxToolCalls; i += 1) {
|
|
44
|
+
const response = await this.client.chat.completions.create({
|
|
45
|
+
model,
|
|
46
|
+
max_completion_tokens: maxTokens,
|
|
47
|
+
temperature,
|
|
48
|
+
messages,
|
|
49
|
+
tools: tools.map((tool) => ({
|
|
50
|
+
type: 'function',
|
|
51
|
+
function: {
|
|
52
|
+
name: tool.name,
|
|
53
|
+
description: tool.description,
|
|
54
|
+
parameters: tool.parameters,
|
|
55
|
+
},
|
|
56
|
+
})),
|
|
57
|
+
tool_choice: normalizeToolChoice(options.toolChoice),
|
|
58
|
+
});
|
|
59
|
+
const message = response.choices[0]?.message;
|
|
60
|
+
if (!message) {
|
|
61
|
+
return lastContent;
|
|
62
|
+
}
|
|
63
|
+
if (message.content) {
|
|
64
|
+
lastContent = message.content;
|
|
65
|
+
}
|
|
66
|
+
if (!message.tool_calls || message.tool_calls.length === 0) {
|
|
67
|
+
return message.content || lastContent;
|
|
68
|
+
}
|
|
69
|
+
messages.push(message);
|
|
70
|
+
for (const toolCall of message.tool_calls) {
|
|
71
|
+
const toolName = toolCall.function?.name;
|
|
72
|
+
const rawArgs = toolCall.function?.arguments || '{}';
|
|
73
|
+
if (!toolName) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const args = parseToolArgs(rawArgs);
|
|
77
|
+
const result = await options.toolRegistry.call(toolName, args, options.toolContext ?? {});
|
|
78
|
+
messages.push({
|
|
79
|
+
role: 'tool',
|
|
80
|
+
tool_call_id: toolCall.id,
|
|
81
|
+
content: JSON.stringify(result),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return lastContent;
|
|
86
|
+
}
|
|
87
|
+
const message = await this.client.chat.completions.create({
|
|
88
|
+
model,
|
|
89
|
+
max_completion_tokens: maxTokens,
|
|
90
|
+
temperature,
|
|
91
|
+
messages: [{ role: 'user', content: prompt }],
|
|
92
|
+
});
|
|
93
|
+
const text = message.choices[0]?.message?.content || '';
|
|
94
|
+
if (options?.onProgress)
|
|
95
|
+
options.onProgress(text);
|
|
96
|
+
return text;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const err = error;
|
|
100
|
+
const message = err?.message || String(error);
|
|
101
|
+
throw new Error(`OpenAI API error: ${message}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async generateCodex(prompt, options) {
|
|
105
|
+
if (!this.client) {
|
|
106
|
+
if (!this.apiKey)
|
|
107
|
+
return `OPENAI_ECHO:\n${prompt}`;
|
|
108
|
+
await this.init();
|
|
109
|
+
if (!this.client)
|
|
110
|
+
return `OPENAI_ECHO:\n${prompt}`;
|
|
111
|
+
}
|
|
112
|
+
const model = (options && options.model) || 'gpt-5-mini';
|
|
113
|
+
const maxTokens = options?.maxTokens || undefined;
|
|
114
|
+
const temperature = options?.temperature || undefined;
|
|
115
|
+
const tools = this.resolveTools(options);
|
|
116
|
+
const maxToolCalls = options?.maxToolCalls ?? 3;
|
|
117
|
+
let previousResponseId = null;
|
|
118
|
+
let input = prompt;
|
|
119
|
+
let lastContent = '';
|
|
120
|
+
for (let i = 0; i <= maxToolCalls; i += 1) {
|
|
121
|
+
const response = await this.client.responses.create({
|
|
122
|
+
model,
|
|
123
|
+
input,
|
|
124
|
+
max_output_tokens: maxTokens,
|
|
125
|
+
temperature,
|
|
126
|
+
tools: tools.length > 0 ? this.formatToolsForResponses(tools) : undefined,
|
|
127
|
+
tool_choice: normalizeToolChoice(options?.toolChoice),
|
|
128
|
+
previous_response_id: previousResponseId || undefined,
|
|
129
|
+
});
|
|
130
|
+
previousResponseId = response.id;
|
|
131
|
+
const outputText = response.output_text;
|
|
132
|
+
if (outputText && outputText.length > 0) {
|
|
133
|
+
lastContent = outputText;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const output = response.output;
|
|
137
|
+
const collected = (output || [])
|
|
138
|
+
.flatMap((item) => item.content || [])
|
|
139
|
+
.filter((item) => item.type === 'output_text' || item.type === 'text')
|
|
140
|
+
.map((item) => item.text || '')
|
|
141
|
+
.join('');
|
|
142
|
+
if (collected) {
|
|
143
|
+
lastContent = collected;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const toolCalls = this.extractToolCalls(response);
|
|
147
|
+
console.log('Extracted tool calls:', toolCalls);
|
|
148
|
+
if (toolCalls.length === 0) {
|
|
149
|
+
return lastContent;
|
|
150
|
+
}
|
|
151
|
+
if (!options?.toolRegistry) {
|
|
152
|
+
throw new Error('Tool calls requested but no tool registry provided');
|
|
153
|
+
}
|
|
154
|
+
const toolOutputs = [];
|
|
155
|
+
for (const toolCall of toolCalls) {
|
|
156
|
+
const result = await options.toolRegistry.call(toolCall.name, parseToolArgs(toolCall.arguments), options.toolContext ?? {});
|
|
157
|
+
toolOutputs.push({
|
|
158
|
+
type: 'function_call_output',
|
|
159
|
+
call_id: toolCall.call_id,
|
|
160
|
+
output: JSON.stringify(result),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
input = [{ role: 'user', content: prompt }, ...toolOutputs];
|
|
164
|
+
console.log('Tool outputs:', toolOutputs);
|
|
165
|
+
}
|
|
166
|
+
return lastContent;
|
|
167
|
+
}
|
|
168
|
+
formatToolsForResponses(tools) {
|
|
169
|
+
return tools.map((tool) => ({
|
|
170
|
+
type: 'function',
|
|
171
|
+
name: tool.name,
|
|
172
|
+
description: tool.description,
|
|
173
|
+
parameters: tool.parameters,
|
|
174
|
+
strict: false,
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
async complete(prompt) {
|
|
178
|
+
return this.generate(prompt);
|
|
179
|
+
}
|
|
180
|
+
onProgress(_callback) {
|
|
181
|
+
// Progress callback handled in generate method
|
|
182
|
+
}
|
|
183
|
+
async close() {
|
|
184
|
+
// OpenAI client doesn't need explicit closing
|
|
185
|
+
}
|
|
186
|
+
resolveTools(options) {
|
|
187
|
+
if (options?.tools && options.tools.length > 0) {
|
|
188
|
+
return options.tools;
|
|
189
|
+
}
|
|
190
|
+
if (options?.toolRegistry) {
|
|
191
|
+
return options.toolRegistry.getDefinitions();
|
|
192
|
+
}
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
extractToolCalls(response) {
|
|
196
|
+
const toolCalls = [];
|
|
197
|
+
const output = response?.output;
|
|
198
|
+
if (!output) {
|
|
199
|
+
return toolCalls;
|
|
200
|
+
}
|
|
201
|
+
for (const item of output) {
|
|
202
|
+
if (item?.tool_calls && Array.isArray(item.tool_calls)) {
|
|
203
|
+
for (const toolCall of item.tool_calls) {
|
|
204
|
+
if (toolCall?.name) {
|
|
205
|
+
toolCalls.push({
|
|
206
|
+
id: toolCall.id || toolCall.tool_call_id || `tool_${toolCalls.length + 1}`,
|
|
207
|
+
name: toolCall.name,
|
|
208
|
+
arguments: toolCall.arguments || '{}',
|
|
209
|
+
call_id: toolCall.call_id || toolCall.id || `tool_${toolCalls.length + 1}`,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (item?.type === 'tool_call' && item?.name) {
|
|
215
|
+
toolCalls.push({
|
|
216
|
+
id: item.id || item.tool_call_id || `tool_${toolCalls.length + 1}`,
|
|
217
|
+
name: item.name,
|
|
218
|
+
arguments: item.arguments || '{}',
|
|
219
|
+
call_id: item.call_id || item.id || `tool_${toolCalls.length + 1}`,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (item?.type === 'function_call' && item?.name) {
|
|
223
|
+
toolCalls.push({
|
|
224
|
+
id: item.id || `tool_${toolCalls.length + 1}`,
|
|
225
|
+
name: item.name,
|
|
226
|
+
arguments: item.arguments || '{}',
|
|
227
|
+
call_id: item.call_id || `call_${toolCalls.length + 1}`,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return toolCalls;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function parseToolArgs(rawArgs) {
|
|
235
|
+
try {
|
|
236
|
+
const parsed = JSON.parse(rawArgs);
|
|
237
|
+
if (parsed && typeof parsed === 'object') {
|
|
238
|
+
return parsed;
|
|
239
|
+
}
|
|
240
|
+
return {};
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return {};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function normalizeToolChoice(choice) {
|
|
247
|
+
if (!choice || choice === 'auto' || choice === 'none') {
|
|
248
|
+
return choice ?? 'auto';
|
|
249
|
+
}
|
|
250
|
+
return { type: 'function', function: { name: choice.name } };
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/ai-provider/openai.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,MAAM,OAAO,cAAc;IACjB,MAAM,CAAU;IAChB,MAAM,GAAkB,IAAI,CAAC;IAErC,YAAY,MAAe;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAgC;QACzC,IAAI,MAAM,IAAK,MAAc,CAAC,MAAM;YAAE,IAAI,CAAC,MAAM,GAAI,MAAc,CAAC,MAAgB,CAAC;QACrF,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO;QAEzB,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,kDAAkD;YAClD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,OAA2B;QACxD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,+CAA+C;YAC/C,IAAI,CAAC,IAAI,CAA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CAAC,SAAS,IAAI,IAAI;oBACjC,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,QAAQ,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;iBACxD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAED,SAAS,aAAa,CAAC,OAAe;IACpC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACnC,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YACzC,OAAO,MAAiC,CAAC;QAC3C,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,MAA2C;IACtE,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtD,OAAO,MAAM,IAAI,MAAM,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ToolDefinition, ToolContext } from '../tools/types.js';
|
|
2
|
+
import { ToolRegistry } from '../tools/registry.js';
|
|
3
|
+
export interface AIProviderOptions {
|
|
4
|
+
model?: string;
|
|
5
|
+
stream?: boolean;
|
|
6
|
+
maxTokens?: number;
|
|
7
|
+
temperature?: number;
|
|
8
|
+
onProgress?: (chunk: string) => void;
|
|
9
|
+
tools?: ToolDefinition[];
|
|
10
|
+
toolRegistry?: ToolRegistry;
|
|
11
|
+
toolContext?: ToolContext;
|
|
12
|
+
toolChoice?: 'auto' | 'none' | {
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
maxToolCalls?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface AIProvider {
|
|
18
|
+
init?(config?: Record<string, unknown>): Promise<void> | void;
|
|
19
|
+
generate(prompt: string, options?: AIProviderOptions): Promise<string>;
|
|
20
|
+
generateCodex?(prompt: string, options?: AIProviderOptions): Promise<string>;
|
|
21
|
+
close?(): Promise<void> | void;
|
|
22
|
+
complete?(prompt: string): Promise<string>;
|
|
23
|
+
onProgress?(callback: (chunk: string) => void): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/ai-provider/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC9D,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,aAAa,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7E,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC;CACtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/ai-provider/provider.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class TokenManager {
|
|
2
|
+
private limitPerMinute;
|
|
3
|
+
private usedInWindow;
|
|
4
|
+
private windowStart;
|
|
5
|
+
private tokenizer;
|
|
6
|
+
constructor(limitPerMinute?: number);
|
|
7
|
+
private loadTokenizer;
|
|
8
|
+
countTokens(text: string, model?: string): number;
|
|
9
|
+
canConsume(tokens: number): boolean;
|
|
10
|
+
consume(tokens: number): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=token-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-manager.d.ts","sourceRoot":"","sources":["../../src/ai-provider/token-manager.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IACvB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAoB;gBAEzB,cAAc,GAAE,MAAc;IAO1C,OAAO,CAAC,aAAa;IAkBrB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM;IAkBjD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IASnC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAI9B"}
|