@open-multi-agent/core 1.4.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/LICENSE +21 -0
- package/README.md +373 -0
- package/dist/agent/agent.d.ts +153 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +559 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/loop-detector.d.ts +39 -0
- package/dist/agent/loop-detector.d.ts.map +1 -0
- package/dist/agent/loop-detector.js +122 -0
- package/dist/agent/loop-detector.js.map +1 -0
- package/dist/agent/pool.d.ts +158 -0
- package/dist/agent/pool.d.ts.map +1 -0
- package/dist/agent/pool.js +320 -0
- package/dist/agent/pool.js.map +1 -0
- package/dist/agent/runner.d.ts +242 -0
- package/dist/agent/runner.d.ts.map +1 -0
- package/dist/agent/runner.js +943 -0
- package/dist/agent/runner.js.map +1 -0
- package/dist/agent/structured-output.d.ts +33 -0
- package/dist/agent/structured-output.d.ts.map +1 -0
- package/dist/agent/structured-output.js +116 -0
- package/dist/agent/structured-output.js.map +1 -0
- package/dist/cli/oma.d.ts +30 -0
- package/dist/cli/oma.d.ts.map +1 -0
- package/dist/cli/oma.js +433 -0
- package/dist/cli/oma.js.map +1 -0
- package/dist/dashboard/layout-tasks.d.ts +23 -0
- package/dist/dashboard/layout-tasks.d.ts.map +1 -0
- package/dist/dashboard/layout-tasks.js +79 -0
- package/dist/dashboard/layout-tasks.js.map +1 -0
- package/dist/dashboard/render-team-run-dashboard.d.ts +11 -0
- package/dist/dashboard/render-team-run-dashboard.d.ts.map +1 -0
- package/dist/dashboard/render-team-run-dashboard.js +456 -0
- package/dist/dashboard/render-team-run-dashboard.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/adapter.d.ts +54 -0
- package/dist/llm/adapter.d.ts.map +1 -0
- package/dist/llm/adapter.js +101 -0
- package/dist/llm/adapter.js.map +1 -0
- package/dist/llm/anthropic.d.ts +57 -0
- package/dist/llm/anthropic.d.ts.map +1 -0
- package/dist/llm/anthropic.js +432 -0
- package/dist/llm/anthropic.js.map +1 -0
- package/dist/llm/azure-openai.d.ts +74 -0
- package/dist/llm/azure-openai.d.ts.map +1 -0
- package/dist/llm/azure-openai.js +267 -0
- package/dist/llm/azure-openai.js.map +1 -0
- package/dist/llm/bedrock.d.ts +41 -0
- package/dist/llm/bedrock.d.ts.map +1 -0
- package/dist/llm/bedrock.js +345 -0
- package/dist/llm/bedrock.js.map +1 -0
- package/dist/llm/copilot.d.ts +92 -0
- package/dist/llm/copilot.d.ts.map +1 -0
- package/dist/llm/copilot.js +433 -0
- package/dist/llm/copilot.js.map +1 -0
- package/dist/llm/deepseek.d.ts +21 -0
- package/dist/llm/deepseek.d.ts.map +1 -0
- package/dist/llm/deepseek.js +24 -0
- package/dist/llm/deepseek.js.map +1 -0
- package/dist/llm/gemini.d.ts +65 -0
- package/dist/llm/gemini.d.ts.map +1 -0
- package/dist/llm/gemini.js +427 -0
- package/dist/llm/gemini.js.map +1 -0
- package/dist/llm/grok.d.ts +21 -0
- package/dist/llm/grok.d.ts.map +1 -0
- package/dist/llm/grok.js +24 -0
- package/dist/llm/grok.js.map +1 -0
- package/dist/llm/minimax.d.ts +21 -0
- package/dist/llm/minimax.d.ts.map +1 -0
- package/dist/llm/minimax.js +24 -0
- package/dist/llm/minimax.js.map +1 -0
- package/dist/llm/openai-common.d.ts +65 -0
- package/dist/llm/openai-common.d.ts.map +1 -0
- package/dist/llm/openai-common.js +286 -0
- package/dist/llm/openai-common.js.map +1 -0
- package/dist/llm/openai.d.ts +63 -0
- package/dist/llm/openai.d.ts.map +1 -0
- package/dist/llm/openai.js +256 -0
- package/dist/llm/openai.js.map +1 -0
- package/dist/llm/qiniu.d.ts +21 -0
- package/dist/llm/qiniu.d.ts.map +1 -0
- package/dist/llm/qiniu.js +24 -0
- package/dist/llm/qiniu.js.map +1 -0
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +2 -0
- package/dist/mcp.js.map +1 -0
- package/dist/memory/shared.d.ts +162 -0
- package/dist/memory/shared.d.ts.map +1 -0
- package/dist/memory/shared.js +294 -0
- package/dist/memory/shared.js.map +1 -0
- package/dist/memory/store.d.ts +72 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +121 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +245 -0
- package/dist/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator.js +1400 -0
- package/dist/orchestrator/orchestrator.js.map +1 -0
- package/dist/orchestrator/scheduler.d.ts +112 -0
- package/dist/orchestrator/scheduler.d.ts.map +1 -0
- package/dist/orchestrator/scheduler.js +256 -0
- package/dist/orchestrator/scheduler.js.map +1 -0
- package/dist/task/queue.d.ts +191 -0
- package/dist/task/queue.d.ts.map +1 -0
- package/dist/task/queue.js +408 -0
- package/dist/task/queue.js.map +1 -0
- package/dist/task/task.d.ts +90 -0
- package/dist/task/task.d.ts.map +1 -0
- package/dist/task/task.js +206 -0
- package/dist/task/task.js.map +1 -0
- package/dist/team/messaging.d.ts +106 -0
- package/dist/team/messaging.d.ts.map +1 -0
- package/dist/team/messaging.js +183 -0
- package/dist/team/messaging.js.map +1 -0
- package/dist/team/team.d.ts +141 -0
- package/dist/team/team.d.ts.map +1 -0
- package/dist/team/team.js +293 -0
- package/dist/team/team.js.map +1 -0
- package/dist/tool/built-in/bash.d.ts +12 -0
- package/dist/tool/built-in/bash.d.ts.map +1 -0
- package/dist/tool/built-in/bash.js +133 -0
- package/dist/tool/built-in/bash.js.map +1 -0
- package/dist/tool/built-in/delegate.d.ts +29 -0
- package/dist/tool/built-in/delegate.d.ts.map +1 -0
- package/dist/tool/built-in/delegate.js +92 -0
- package/dist/tool/built-in/delegate.js.map +1 -0
- package/dist/tool/built-in/file-edit.d.ts +14 -0
- package/dist/tool/built-in/file-edit.d.ts.map +1 -0
- package/dist/tool/built-in/file-edit.js +130 -0
- package/dist/tool/built-in/file-edit.js.map +1 -0
- package/dist/tool/built-in/file-read.d.ts +12 -0
- package/dist/tool/built-in/file-read.d.ts.map +1 -0
- package/dist/tool/built-in/file-read.js +82 -0
- package/dist/tool/built-in/file-read.js.map +1 -0
- package/dist/tool/built-in/file-write.d.ts +11 -0
- package/dist/tool/built-in/file-write.d.ts.map +1 -0
- package/dist/tool/built-in/file-write.js +70 -0
- package/dist/tool/built-in/file-write.js.map +1 -0
- package/dist/tool/built-in/fs-walk.d.ts +23 -0
- package/dist/tool/built-in/fs-walk.d.ts.map +1 -0
- package/dist/tool/built-in/fs-walk.js +78 -0
- package/dist/tool/built-in/fs-walk.js.map +1 -0
- package/dist/tool/built-in/glob.d.ts +12 -0
- package/dist/tool/built-in/glob.d.ts.map +1 -0
- package/dist/tool/built-in/glob.js +82 -0
- package/dist/tool/built-in/glob.js.map +1 -0
- package/dist/tool/built-in/grep.d.ts +15 -0
- package/dist/tool/built-in/grep.d.ts.map +1 -0
- package/dist/tool/built-in/grep.js +218 -0
- package/dist/tool/built-in/grep.js.map +1 -0
- package/dist/tool/built-in/index.d.ts +48 -0
- package/dist/tool/built-in/index.d.ts.map +1 -0
- package/dist/tool/built-in/index.js +56 -0
- package/dist/tool/built-in/index.js.map +1 -0
- package/dist/tool/executor.d.ts +100 -0
- package/dist/tool/executor.d.ts.map +1 -0
- package/dist/tool/executor.js +184 -0
- package/dist/tool/executor.js.map +1 -0
- package/dist/tool/framework.d.ts +167 -0
- package/dist/tool/framework.d.ts.map +1 -0
- package/dist/tool/framework.js +402 -0
- package/dist/tool/framework.js.map +1 -0
- package/dist/tool/mcp.d.ts +31 -0
- package/dist/tool/mcp.d.ts.map +1 -0
- package/dist/tool/mcp.js +175 -0
- package/dist/tool/mcp.js.map +1 -0
- package/dist/tool/text-tool-extractor.d.ts +32 -0
- package/dist/tool/text-tool-extractor.d.ts.map +1 -0
- package/dist/tool/text-tool-extractor.js +195 -0
- package/dist/tool/text-tool-extractor.js.map +1 -0
- package/dist/types.d.ts +916 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/keywords.d.ts +18 -0
- package/dist/utils/keywords.d.ts.map +1 -0
- package/dist/utils/keywords.js +32 -0
- package/dist/utils/keywords.js.map +1 -0
- package/dist/utils/semaphore.d.ts +49 -0
- package/dist/utils/semaphore.d.ts.map +1 -0
- package/dist/utils/semaphore.js +89 -0
- package/dist/utils/semaphore.js.map +1 -0
- package/dist/utils/tokens.d.ts +7 -0
- package/dist/utils/tokens.d.ts.map +1 -0
- package/dist/utils/tokens.js +30 -0
- package/dist/utils/tokens.js.map +1 -0
- package/dist/utils/trace.d.ts +12 -0
- package/dist/utils/trace.d.ts.map +1 -0
- package/dist/utils/trace.js +30 -0
- package/dist/utils/trace.js.map +1 -0
- package/docs/DECISIONS.md +49 -0
- package/docs/cli.md +265 -0
- package/docs/context-management.md +24 -0
- package/docs/featured-partner.md +28 -0
- package/docs/observability.md +56 -0
- package/docs/providers.md +78 -0
- package/docs/shared-memory.md +27 -0
- package/docs/tool-configuration.md +152 -0
- package/package.json +96 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Google Gemini adapter implementing {@link LLMAdapter}.
|
|
3
|
+
*
|
|
4
|
+
* Built for `@google/genai` (the unified Google Gen AI SDK, v1.x), NOT the
|
|
5
|
+
* legacy `@google/generative-ai` package.
|
|
6
|
+
*
|
|
7
|
+
* Converts between the framework's internal {@link ContentBlock} types and the
|
|
8
|
+
* `@google/genai` SDK's wire format, handling tool definitions, system prompts,
|
|
9
|
+
* and both batch and streaming response paths.
|
|
10
|
+
*
|
|
11
|
+
* API key resolution order:
|
|
12
|
+
* 1. `apiKey` constructor argument
|
|
13
|
+
* 2. `GEMINI_API_KEY` environment variable
|
|
14
|
+
* 3. `GOOGLE_API_KEY` environment variable
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { GeminiAdapter } from './gemini.js'
|
|
19
|
+
*
|
|
20
|
+
* const adapter = new GeminiAdapter()
|
|
21
|
+
* const response = await adapter.chat(messages, {
|
|
22
|
+
* model: 'gemini-2.5-flash',
|
|
23
|
+
* maxTokens: 1024,
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import type { LLMAdapter, LLMChatOptions, LLMMessage, LLMResponse, LLMStreamOptions, StreamEvent } from '../types.js';
|
|
28
|
+
/**
|
|
29
|
+
* LLM adapter backed by the Google Gemini API via `@google/genai`.
|
|
30
|
+
*
|
|
31
|
+
* Thread-safe — a single instance may be shared across concurrent agent runs.
|
|
32
|
+
* The underlying SDK client is stateless across requests.
|
|
33
|
+
*/
|
|
34
|
+
export declare class GeminiAdapter implements LLMAdapter {
|
|
35
|
+
#private;
|
|
36
|
+
readonly name = "gemini";
|
|
37
|
+
constructor(apiKey?: string);
|
|
38
|
+
/**
|
|
39
|
+
* Send a synchronous (non-streaming) chat request and return the complete
|
|
40
|
+
* {@link LLMResponse}.
|
|
41
|
+
*
|
|
42
|
+
* Uses `ai.models.generateContent()` with the full conversation as `contents`,
|
|
43
|
+
* which is the idiomatic pattern for `@google/genai`.
|
|
44
|
+
*/
|
|
45
|
+
chat(messages: LLMMessage[], options: LLMChatOptions): Promise<LLMResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Send a streaming chat request and yield {@link StreamEvent}s as they
|
|
48
|
+
* arrive from the API.
|
|
49
|
+
*
|
|
50
|
+
* Uses `ai.models.generateContentStream()` which returns an
|
|
51
|
+
* `AsyncGenerator<GenerateContentResponse>`. Each yielded chunk has the same
|
|
52
|
+
* shape as a full response but contains only the delta for that chunk.
|
|
53
|
+
*
|
|
54
|
+
* Because `@google/genai` doesn't expose a `finalMessage()` helper like the
|
|
55
|
+
* Anthropic SDK, we accumulate content and token counts as we stream so that
|
|
56
|
+
* the terminal `done` event carries a complete and accurate {@link LLMResponse}.
|
|
57
|
+
*
|
|
58
|
+
* Sequence guarantees (matching the Anthropic adapter):
|
|
59
|
+
* - Zero or more `text` events with incremental deltas
|
|
60
|
+
* - Zero or more `tool_use` events (one per call; Gemini doesn't stream args)
|
|
61
|
+
* - Exactly one terminal event: `done` or `error`
|
|
62
|
+
*/
|
|
63
|
+
stream(messages: LLMMessage[], options: LLMStreamOptions): AsyncIterable<StreamEvent>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../src/llm/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAcH,OAAO,KAAK,EAEV,UAAU,EACV,cAAc,EACd,UAAU,EACV,WAAW,EACX,gBAAgB,EAGhB,WAAW,EAGZ,MAAM,aAAa,CAAA;AAgTpB;;;;;GAKG;AACH,qBAAa,aAAc,YAAW,UAAU;;IAC9C,QAAQ,CAAC,IAAI,YAAW;gBAIZ,MAAM,CAAC,EAAE,MAAM;IAU3B;;;;;;OAMG;IACG,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;IAiBjF;;;;;;;;;;;;;;;;OAgBG;IACI,MAAM,CACX,QAAQ,EAAE,UAAU,EAAE,EACtB,OAAO,EAAE,gBAAgB,GACxB,aAAa,CAAC,WAAW,CAAC;CA0E9B"}
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Google Gemini adapter implementing {@link LLMAdapter}.
|
|
3
|
+
*
|
|
4
|
+
* Built for `@google/genai` (the unified Google Gen AI SDK, v1.x), NOT the
|
|
5
|
+
* legacy `@google/generative-ai` package.
|
|
6
|
+
*
|
|
7
|
+
* Converts between the framework's internal {@link ContentBlock} types and the
|
|
8
|
+
* `@google/genai` SDK's wire format, handling tool definitions, system prompts,
|
|
9
|
+
* and both batch and streaming response paths.
|
|
10
|
+
*
|
|
11
|
+
* API key resolution order:
|
|
12
|
+
* 1. `apiKey` constructor argument
|
|
13
|
+
* 2. `GEMINI_API_KEY` environment variable
|
|
14
|
+
* 3. `GOOGLE_API_KEY` environment variable
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { GeminiAdapter } from './gemini.js'
|
|
19
|
+
*
|
|
20
|
+
* const adapter = new GeminiAdapter()
|
|
21
|
+
* const response = await adapter.chat(messages, {
|
|
22
|
+
* model: 'gemini-2.5-flash',
|
|
23
|
+
* maxTokens: 1024,
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import { GoogleGenAI, FunctionCallingConfigMode, } from '@google/genai';
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Internal helpers
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
/**
|
|
32
|
+
* Map framework role names to Gemini role names.
|
|
33
|
+
*
|
|
34
|
+
* Gemini uses `"model"` instead of `"assistant"`.
|
|
35
|
+
*/
|
|
36
|
+
function toGeminiRole(role) {
|
|
37
|
+
return role === 'assistant' ? 'model' : 'user';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convert framework messages into Gemini's {@link Content}[] format.
|
|
41
|
+
*
|
|
42
|
+
* Key differences from Anthropic:
|
|
43
|
+
* - Gemini uses `"model"` instead of `"assistant"`.
|
|
44
|
+
* - `functionResponse` parts (tool results) must appear in `"user"` turns.
|
|
45
|
+
* - `functionCall` parts appear in `"model"` turns.
|
|
46
|
+
* - We build a name lookup map from tool_use blocks so tool_result blocks
|
|
47
|
+
* can resolve the function name required by Gemini's `functionResponse`.
|
|
48
|
+
*
|
|
49
|
+
* Reasoning handling: Gemini's `thoughtSignature` is a top-level field on
|
|
50
|
+
* Part that accompanies a functionCall Part, identifying the signed thought
|
|
51
|
+
* sequence that produced the call. We attach it to the outgoing Part
|
|
52
|
+
* whenever the source {@link ToolUseBlock} carries a signature. Thought
|
|
53
|
+
* summaries (incoming text Parts with `thought: true` surfaced as
|
|
54
|
+
* {@link ReasoningBlock}) are echoed back only when they carry a signature
|
|
55
|
+
* — Gemini 3 recommends round-tripping these signatures, but unsigned
|
|
56
|
+
* reasoning (e.g. cross-provider blocks or Gemini 2.5 thought summaries
|
|
57
|
+
* which never carry signatures) is dropped to keep context lean.
|
|
58
|
+
*/
|
|
59
|
+
function toGeminiContents(messages) {
|
|
60
|
+
// First pass: build id → name map for resolving tool results.
|
|
61
|
+
const toolNameById = new Map();
|
|
62
|
+
for (const msg of messages) {
|
|
63
|
+
for (const block of msg.content) {
|
|
64
|
+
if (block.type === 'tool_use') {
|
|
65
|
+
toolNameById.set(block.id, block.name);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return messages.map((msg) => {
|
|
70
|
+
const parts = [];
|
|
71
|
+
for (const block of msg.content) {
|
|
72
|
+
switch (block.type) {
|
|
73
|
+
case 'reasoning': {
|
|
74
|
+
// Echo only when we have a signature to round-trip — see JSDoc
|
|
75
|
+
// above. Drop unsigned reasoning silently rather than emitting an
|
|
76
|
+
// empty/unsigned text part that would inflate context for no
|
|
77
|
+
// protocol benefit.
|
|
78
|
+
if (block.signature === undefined)
|
|
79
|
+
break;
|
|
80
|
+
const part = {
|
|
81
|
+
text: block.text,
|
|
82
|
+
thought: true,
|
|
83
|
+
thoughtSignature: block.signature,
|
|
84
|
+
};
|
|
85
|
+
parts.push(part);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'text':
|
|
89
|
+
parts.push({ text: block.text });
|
|
90
|
+
break;
|
|
91
|
+
case 'tool_use': {
|
|
92
|
+
const part = {
|
|
93
|
+
functionCall: {
|
|
94
|
+
id: block.id,
|
|
95
|
+
name: block.name,
|
|
96
|
+
args: block.input,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
if (block.signature !== undefined) {
|
|
100
|
+
// thoughtSignature is a top-level field on Part (NOT nested under
|
|
101
|
+
// functionCall) — see Part schema in @google/genai. Required by
|
|
102
|
+
// Gemini 3+ to maintain extended-thinking context across tool-use
|
|
103
|
+
// turns.
|
|
104
|
+
part.thoughtSignature = block.signature;
|
|
105
|
+
}
|
|
106
|
+
parts.push(part);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'tool_result': {
|
|
110
|
+
const name = toolNameById.get(block.tool_use_id) ?? block.tool_use_id;
|
|
111
|
+
parts.push({
|
|
112
|
+
functionResponse: {
|
|
113
|
+
id: block.tool_use_id,
|
|
114
|
+
name,
|
|
115
|
+
response: {
|
|
116
|
+
content: typeof block.content === 'string'
|
|
117
|
+
? block.content
|
|
118
|
+
: JSON.stringify(block.content),
|
|
119
|
+
isError: block.is_error ?? false,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case 'image':
|
|
126
|
+
parts.push({
|
|
127
|
+
inlineData: {
|
|
128
|
+
mimeType: block.source.media_type,
|
|
129
|
+
data: block.source.data,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
break;
|
|
133
|
+
default: {
|
|
134
|
+
const _exhaustive = block;
|
|
135
|
+
throw new Error(`Unhandled content block type: ${JSON.stringify(_exhaustive)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return { role: toGeminiRole(msg.role), parts };
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Convert framework {@link LLMToolDef}s into a Gemini `tools` config array.
|
|
144
|
+
*
|
|
145
|
+
* In `@google/genai`, function declarations use `parametersJsonSchema` (not
|
|
146
|
+
* `parameters` or `input_schema`). All declarations are grouped under a single
|
|
147
|
+
* tool entry.
|
|
148
|
+
*/
|
|
149
|
+
function toGeminiTools(tools) {
|
|
150
|
+
const functionDeclarations = tools.map((t) => ({
|
|
151
|
+
name: t.name,
|
|
152
|
+
description: t.description,
|
|
153
|
+
parametersJsonSchema: t.inputSchema,
|
|
154
|
+
}));
|
|
155
|
+
return [{ functionDeclarations }];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Convert the framework's {@link ThinkingConfig} into Gemini's
|
|
159
|
+
* `thinkingConfig`. Returns `undefined` when the caller hasn't opted in,
|
|
160
|
+
* leaving the field absent so server defaults apply.
|
|
161
|
+
*
|
|
162
|
+
* `includeThoughts` defaults on when extended thinking is enabled — the
|
|
163
|
+
* thought-summary stream is the only way for callers to surface model
|
|
164
|
+
* reasoning, and the cost of the metadata is negligible. `thinkingBudget`
|
|
165
|
+
* is forwarded only when the caller specifies one (Gemini accepts -1 to
|
|
166
|
+
* mean "dynamic").
|
|
167
|
+
*/
|
|
168
|
+
function toGeminiThinkingConfig(thinking) {
|
|
169
|
+
if (thinking === undefined || !thinking.enabled)
|
|
170
|
+
return undefined;
|
|
171
|
+
const config = { includeThoughts: true };
|
|
172
|
+
if (thinking.budgetTokens !== undefined) {
|
|
173
|
+
config.thinkingBudget = thinking.budgetTokens;
|
|
174
|
+
}
|
|
175
|
+
return config;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Build the {@link GenerateContentConfig} shared by chat() and stream().
|
|
179
|
+
*/
|
|
180
|
+
function buildConfig(options) {
|
|
181
|
+
return {
|
|
182
|
+
maxOutputTokens: options.maxTokens ?? 4096,
|
|
183
|
+
temperature: options.temperature,
|
|
184
|
+
systemInstruction: options.systemPrompt,
|
|
185
|
+
tools: options.tools ? toGeminiTools(options.tools) : undefined,
|
|
186
|
+
toolConfig: options.tools
|
|
187
|
+
? { functionCallingConfig: { mode: FunctionCallingConfigMode.AUTO } }
|
|
188
|
+
: undefined,
|
|
189
|
+
thinkingConfig: toGeminiThinkingConfig(options.thinking),
|
|
190
|
+
abortSignal: options.abortSignal,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Generate a stable pseudo-random ID string for tool use blocks.
|
|
195
|
+
*
|
|
196
|
+
* Gemini may not always return call IDs (especially in streaming), so we
|
|
197
|
+
* fabricate them when absent to satisfy the framework's {@link ToolUseBlock}
|
|
198
|
+
* contract.
|
|
199
|
+
*/
|
|
200
|
+
function generateId() {
|
|
201
|
+
return `gemini-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Extract the function call ID from a Gemini part, or generate one.
|
|
205
|
+
*
|
|
206
|
+
* The `id` field exists in newer API versions but may be absent in older
|
|
207
|
+
* responses, so we cast conservatively and fall back to a generated ID.
|
|
208
|
+
*/
|
|
209
|
+
function getFunctionCallId(part) {
|
|
210
|
+
return part.functionCall?.id ?? generateId();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Extract `thoughtSignature` from a Gemini Part.
|
|
214
|
+
*
|
|
215
|
+
* Gemini puts thoughtSignature as a top-level field on Part (NOT nested
|
|
216
|
+
* under functionCall, despite some early docs implying otherwise — see
|
|
217
|
+
* the Part schema in @google/genai). Gemini 3+ rejects subsequent turns
|
|
218
|
+
* when the signature isn't echoed back unchanged on the corresponding
|
|
219
|
+
* functionCall part.
|
|
220
|
+
*/
|
|
221
|
+
function getThoughtSignature(part) {
|
|
222
|
+
return part.thoughtSignature;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Convert a single Gemini {@link Part} into zero or one framework
|
|
226
|
+
* {@link ContentBlock}s. Returns `null` for parts we don't model so the
|
|
227
|
+
* caller can skip them without inflating the content array.
|
|
228
|
+
*
|
|
229
|
+
* Recognised inputs:
|
|
230
|
+
* - text part with `thought: true` → {@link ReasoningBlock} (thought summary,
|
|
231
|
+
* carries `thoughtSignature` on Gemini 3 if present)
|
|
232
|
+
* - regular text part → {@link TextBlock}
|
|
233
|
+
* - functionCall part → {@link ToolUseBlock} (with optional signature)
|
|
234
|
+
*/
|
|
235
|
+
function fromGeminiPart(part) {
|
|
236
|
+
if (part.functionCall !== undefined) {
|
|
237
|
+
const block = {
|
|
238
|
+
type: 'tool_use',
|
|
239
|
+
id: getFunctionCallId(part),
|
|
240
|
+
name: part.functionCall.name ?? '',
|
|
241
|
+
input: (part.functionCall.args ?? {}),
|
|
242
|
+
};
|
|
243
|
+
const signature = getThoughtSignature(part);
|
|
244
|
+
if (signature !== undefined) {
|
|
245
|
+
return { ...block, signature };
|
|
246
|
+
}
|
|
247
|
+
return block;
|
|
248
|
+
}
|
|
249
|
+
if (part.text !== undefined && part.text !== '') {
|
|
250
|
+
if (part.thought === true) {
|
|
251
|
+
const reasoning = { type: 'reasoning', text: part.text };
|
|
252
|
+
// Gemini 3 may attach thoughtSignature to thought-summary parts too.
|
|
253
|
+
// Preserve it on the framework block so the next turn can echo it
|
|
254
|
+
// back — see toGeminiContents reasoning case for the round-trip.
|
|
255
|
+
const signature = getThoughtSignature(part);
|
|
256
|
+
if (signature !== undefined) {
|
|
257
|
+
return { ...reasoning, signature };
|
|
258
|
+
}
|
|
259
|
+
return reasoning;
|
|
260
|
+
}
|
|
261
|
+
return { type: 'text', text: part.text };
|
|
262
|
+
}
|
|
263
|
+
// inlineData echoes and other part types are silently ignored.
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Convert a Gemini {@link GenerateContentResponse} into a framework
|
|
268
|
+
* {@link LLMResponse}.
|
|
269
|
+
*/
|
|
270
|
+
function fromGeminiResponse(response, id, model) {
|
|
271
|
+
const candidate = response.candidates?.[0];
|
|
272
|
+
const content = [];
|
|
273
|
+
for (const part of candidate?.content?.parts ?? []) {
|
|
274
|
+
const block = fromGeminiPart(part);
|
|
275
|
+
if (block !== null)
|
|
276
|
+
content.push(block);
|
|
277
|
+
}
|
|
278
|
+
// Map Gemini finish reasons to framework stop_reason vocabulary.
|
|
279
|
+
const finishReason = candidate?.finishReason;
|
|
280
|
+
let stop_reason = 'end_turn';
|
|
281
|
+
if (finishReason === 'MAX_TOKENS') {
|
|
282
|
+
stop_reason = 'max_tokens';
|
|
283
|
+
}
|
|
284
|
+
else if (content.some((b) => b.type === 'tool_use')) {
|
|
285
|
+
// Gemini may report STOP even when it returned function calls.
|
|
286
|
+
stop_reason = 'tool_use';
|
|
287
|
+
}
|
|
288
|
+
const usage = response.usageMetadata;
|
|
289
|
+
return {
|
|
290
|
+
id,
|
|
291
|
+
content,
|
|
292
|
+
model,
|
|
293
|
+
stop_reason,
|
|
294
|
+
usage: {
|
|
295
|
+
input_tokens: usage?.promptTokenCount ?? 0,
|
|
296
|
+
output_tokens: usage?.candidatesTokenCount ?? 0,
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
// Adapter implementation
|
|
302
|
+
// ---------------------------------------------------------------------------
|
|
303
|
+
/**
|
|
304
|
+
* LLM adapter backed by the Google Gemini API via `@google/genai`.
|
|
305
|
+
*
|
|
306
|
+
* Thread-safe — a single instance may be shared across concurrent agent runs.
|
|
307
|
+
* The underlying SDK client is stateless across requests.
|
|
308
|
+
*/
|
|
309
|
+
export class GeminiAdapter {
|
|
310
|
+
name = 'gemini';
|
|
311
|
+
#client;
|
|
312
|
+
constructor(apiKey) {
|
|
313
|
+
this.#client = new GoogleGenAI({
|
|
314
|
+
apiKey: apiKey ?? process.env['GEMINI_API_KEY'] ?? process.env['GOOGLE_API_KEY'],
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
// -------------------------------------------------------------------------
|
|
318
|
+
// chat()
|
|
319
|
+
// -------------------------------------------------------------------------
|
|
320
|
+
/**
|
|
321
|
+
* Send a synchronous (non-streaming) chat request and return the complete
|
|
322
|
+
* {@link LLMResponse}.
|
|
323
|
+
*
|
|
324
|
+
* Uses `ai.models.generateContent()` with the full conversation as `contents`,
|
|
325
|
+
* which is the idiomatic pattern for `@google/genai`.
|
|
326
|
+
*/
|
|
327
|
+
async chat(messages, options) {
|
|
328
|
+
const id = generateId();
|
|
329
|
+
const contents = toGeminiContents(messages);
|
|
330
|
+
const response = await this.#client.models.generateContent({
|
|
331
|
+
model: options.model,
|
|
332
|
+
contents,
|
|
333
|
+
config: buildConfig(options),
|
|
334
|
+
});
|
|
335
|
+
return fromGeminiResponse(response, id, options.model);
|
|
336
|
+
}
|
|
337
|
+
// -------------------------------------------------------------------------
|
|
338
|
+
// stream()
|
|
339
|
+
// -------------------------------------------------------------------------
|
|
340
|
+
/**
|
|
341
|
+
* Send a streaming chat request and yield {@link StreamEvent}s as they
|
|
342
|
+
* arrive from the API.
|
|
343
|
+
*
|
|
344
|
+
* Uses `ai.models.generateContentStream()` which returns an
|
|
345
|
+
* `AsyncGenerator<GenerateContentResponse>`. Each yielded chunk has the same
|
|
346
|
+
* shape as a full response but contains only the delta for that chunk.
|
|
347
|
+
*
|
|
348
|
+
* Because `@google/genai` doesn't expose a `finalMessage()` helper like the
|
|
349
|
+
* Anthropic SDK, we accumulate content and token counts as we stream so that
|
|
350
|
+
* the terminal `done` event carries a complete and accurate {@link LLMResponse}.
|
|
351
|
+
*
|
|
352
|
+
* Sequence guarantees (matching the Anthropic adapter):
|
|
353
|
+
* - Zero or more `text` events with incremental deltas
|
|
354
|
+
* - Zero or more `tool_use` events (one per call; Gemini doesn't stream args)
|
|
355
|
+
* - Exactly one terminal event: `done` or `error`
|
|
356
|
+
*/
|
|
357
|
+
async *stream(messages, options) {
|
|
358
|
+
const id = generateId();
|
|
359
|
+
const contents = toGeminiContents(messages);
|
|
360
|
+
try {
|
|
361
|
+
const streamResponse = await this.#client.models.generateContentStream({
|
|
362
|
+
model: options.model,
|
|
363
|
+
contents,
|
|
364
|
+
config: buildConfig(options),
|
|
365
|
+
});
|
|
366
|
+
// Accumulators for building the done payload.
|
|
367
|
+
const accumulatedContent = [];
|
|
368
|
+
let inputTokens = 0;
|
|
369
|
+
let outputTokens = 0;
|
|
370
|
+
let lastFinishReason;
|
|
371
|
+
for await (const chunk of streamResponse) {
|
|
372
|
+
const candidate = chunk.candidates?.[0];
|
|
373
|
+
// Accumulate token counts — the API emits these on the final chunk.
|
|
374
|
+
if (chunk.usageMetadata) {
|
|
375
|
+
inputTokens = chunk.usageMetadata.promptTokenCount ?? inputTokens;
|
|
376
|
+
outputTokens = chunk.usageMetadata.candidatesTokenCount ?? outputTokens;
|
|
377
|
+
}
|
|
378
|
+
if (candidate?.finishReason) {
|
|
379
|
+
lastFinishReason = candidate.finishReason;
|
|
380
|
+
}
|
|
381
|
+
for (const part of candidate?.content?.parts ?? []) {
|
|
382
|
+
const block = fromGeminiPart(part);
|
|
383
|
+
if (block === null)
|
|
384
|
+
continue;
|
|
385
|
+
accumulatedContent.push(block);
|
|
386
|
+
switch (block.type) {
|
|
387
|
+
case 'text':
|
|
388
|
+
yield { type: 'text', data: block.text };
|
|
389
|
+
break;
|
|
390
|
+
case 'reasoning':
|
|
391
|
+
// Thought summary delta — surface as a reasoning event so
|
|
392
|
+
// observers can stream model thinking the same way they do
|
|
393
|
+
// for Anthropic's `thinking_delta`.
|
|
394
|
+
yield { type: 'reasoning', data: block.text };
|
|
395
|
+
break;
|
|
396
|
+
case 'tool_use':
|
|
397
|
+
yield { type: 'tool_use', data: block };
|
|
398
|
+
break;
|
|
399
|
+
// No other block types come back from Gemini parts.
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
// Determine stop_reason from the accumulated response.
|
|
404
|
+
const hasToolUse = accumulatedContent.some((b) => b.type === 'tool_use');
|
|
405
|
+
let stop_reason = 'end_turn';
|
|
406
|
+
if (lastFinishReason === 'MAX_TOKENS') {
|
|
407
|
+
stop_reason = 'max_tokens';
|
|
408
|
+
}
|
|
409
|
+
else if (hasToolUse) {
|
|
410
|
+
stop_reason = 'tool_use';
|
|
411
|
+
}
|
|
412
|
+
const finalResponse = {
|
|
413
|
+
id,
|
|
414
|
+
content: accumulatedContent,
|
|
415
|
+
model: options.model,
|
|
416
|
+
stop_reason,
|
|
417
|
+
usage: { input_tokens: inputTokens, output_tokens: outputTokens },
|
|
418
|
+
};
|
|
419
|
+
yield { type: 'done', data: finalResponse };
|
|
420
|
+
}
|
|
421
|
+
catch (err) {
|
|
422
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
423
|
+
yield { type: 'error', data: error };
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
//# sourceMappingURL=gemini.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.js","sourceRoot":"","sources":["../../src/llm/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EACL,WAAW,EACX,yBAAyB,GAQ1B,MAAM,eAAe,CAAA;AAgBtB,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;;GAIG;AACH,SAAS,YAAY,CAAC,IAA0B;IAC9C,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAA;AAChD,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,gBAAgB,CAAC,QAAsB;IAC9C,8DAA8D;IAC9D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC9C,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAChC,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBAC9B,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;YACx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,UAAU,EAAE,IAAI,EAAE,KAAK,EAAwB,CAAA;4BAC7D,MAAK;wBACP,oDAAoD;oBACtD,CAAC;gBACH,CAAC;YACH,CAAC;YAED,uDAAuD;YACvD,MAAM,UAAU,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAA;YACxE,IAAI,WAAW,GAA+B,UAAU,CAAA;YACxD,IAAI,gBAAgB,KAAK,YAAY,EAAE,CAAC;gBACtC,WAAW,GAAG,YAAY,CAAA;YAC5B,CAAC;iBAAM,IAAI,UAAU,EAAE,CAAC;gBACtB,WAAW,GAAG,UAAU,CAAA;YAC1B,CAAC;YAED,MAAM,aAAa,GAAgB;gBACjC,EAAE;gBACF,OAAO,EAAE,kBAAkB;gBAC3B,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,WAAW;gBACX,KAAK,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE;aAClE,CAAA;YAED,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAwB,CAAA;QACnE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,KAAK,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;YACjE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAwB,CAAA;QAC5D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Grok (xAI) adapter.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper around OpenAIAdapter that hard-codes the official xAI endpoint
|
|
5
|
+
* and XAI_API_KEY environment variable fallback.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAIAdapter } from './openai.js';
|
|
8
|
+
/**
|
|
9
|
+
* LLM adapter for Grok models (grok-4 series and future models).
|
|
10
|
+
*
|
|
11
|
+
* Thread-safe. Can be shared across agents.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* provider: 'grok'
|
|
15
|
+
* model: 'grok-4' (or any current Grok model name)
|
|
16
|
+
*/
|
|
17
|
+
export declare class GrokAdapter extends OpenAIAdapter {
|
|
18
|
+
readonly name = "grok";
|
|
19
|
+
constructor(apiKey?: string, baseURL?: string);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=grok.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok.d.ts","sourceRoot":"","sources":["../../src/llm/grok.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C;;;;;;;;GAQG;AACH,qBAAa,WAAY,SAAQ,aAAa;IAC5C,QAAQ,CAAC,IAAI,UAAS;gBAEV,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAO9C"}
|
package/dist/llm/grok.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Grok (xAI) adapter.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper around OpenAIAdapter that hard-codes the official xAI endpoint
|
|
5
|
+
* and XAI_API_KEY environment variable fallback.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAIAdapter } from './openai.js';
|
|
8
|
+
/**
|
|
9
|
+
* LLM adapter for Grok models (grok-4 series and future models).
|
|
10
|
+
*
|
|
11
|
+
* Thread-safe. Can be shared across agents.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* provider: 'grok'
|
|
15
|
+
* model: 'grok-4' (or any current Grok model name)
|
|
16
|
+
*/
|
|
17
|
+
export class GrokAdapter extends OpenAIAdapter {
|
|
18
|
+
name = 'grok';
|
|
19
|
+
constructor(apiKey, baseURL) {
|
|
20
|
+
// Allow override of baseURL (for proxies or future changes) but default to official xAI endpoint.
|
|
21
|
+
super(apiKey ?? process.env['XAI_API_KEY'], baseURL ?? 'https://api.x.ai/v1');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=grok.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grok.js","sourceRoot":"","sources":["../../src/llm/grok.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAY,SAAQ,aAAa;IACnC,IAAI,GAAG,MAAM,CAAA;IAEtB,YAAY,MAAe,EAAE,OAAgB;QAC3C,kGAAkG;QAClG,KAAK,CACH,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,EACpC,OAAO,IAAI,qBAAqB,CACjC,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MiniMax adapter.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper around OpenAIAdapter that hard-codes the official MiniMax
|
|
5
|
+
* OpenAI-compatible endpoint and MINIMAX_API_KEY environment variable fallback.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAIAdapter } from './openai.js';
|
|
8
|
+
/**
|
|
9
|
+
* LLM adapter for MiniMax models (MiniMax-M2.7 series and future models).
|
|
10
|
+
*
|
|
11
|
+
* Thread-safe. Can be shared across agents.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* provider: 'minimax'
|
|
15
|
+
* model: 'MiniMax-M2.7' (or any current MiniMax model name)
|
|
16
|
+
*/
|
|
17
|
+
export declare class MiniMaxAdapter extends OpenAIAdapter {
|
|
18
|
+
readonly name = "minimax";
|
|
19
|
+
constructor(apiKey?: string, baseURL?: string);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=minimax.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimax.d.ts","sourceRoot":"","sources":["../../src/llm/minimax.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C;;;;;;;;GAQG;AACH,qBAAa,cAAe,SAAQ,aAAa;IAC/C,QAAQ,CAAC,IAAI,aAAY;gBAEb,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAO9C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MiniMax adapter.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper around OpenAIAdapter that hard-codes the official MiniMax
|
|
5
|
+
* OpenAI-compatible endpoint and MINIMAX_API_KEY environment variable fallback.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAIAdapter } from './openai.js';
|
|
8
|
+
/**
|
|
9
|
+
* LLM adapter for MiniMax models (MiniMax-M2.7 series and future models).
|
|
10
|
+
*
|
|
11
|
+
* Thread-safe. Can be shared across agents.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* provider: 'minimax'
|
|
15
|
+
* model: 'MiniMax-M2.7' (or any current MiniMax model name)
|
|
16
|
+
*/
|
|
17
|
+
export class MiniMaxAdapter extends OpenAIAdapter {
|
|
18
|
+
name = 'minimax';
|
|
19
|
+
constructor(apiKey, baseURL) {
|
|
20
|
+
// Allow override of baseURL (for proxies or future changes) but default to official MiniMax endpoint.
|
|
21
|
+
super(apiKey ?? process.env['MINIMAX_API_KEY'], baseURL ?? process.env['MINIMAX_BASE_URL'] ?? 'https://api.minimax.io/v1');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=minimax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimax.js","sourceRoot":"","sources":["../../src/llm/minimax.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAe,SAAQ,aAAa;IACtC,IAAI,GAAG,SAAS,CAAA;IAEzB,YAAY,MAAe,EAAE,OAAgB;QAC3C,sGAAsG;QACtG,KAAK,CACH,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,EACxC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,2BAA2B,CAC1E,CAAA;IACH,CAAC;CACF"}
|