@dmindai/sdk 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 +145 -0
- package/dist/chat-types.d.ts +137 -0
- package/dist/chat-types.js +6 -0
- package/dist/chat-types.js.map +1 -0
- package/dist/chat.d.ts +16 -0
- package/dist/chat.js +286 -0
- package/dist/chat.js.map +1 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +10 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/parser.d.ts +3 -0
- package/dist/parser.js +160 -0
- package/dist/parser.js.map +1 -0
- package/dist/profiles.d.ts +3 -0
- package/dist/profiles.js +95 -0
- package/dist/profiles.js.map +1 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.js +54 -0
- package/dist/runtime.js.map +1 -0
- package/dist/sdk.d.ts +22 -0
- package/dist/sdk.js +58 -0
- package/dist/sdk.js.map +1 -0
- package/dist/tool.d.ts +47 -0
- package/dist/tool.js +61 -0
- package/dist/tool.js.map +1 -0
- package/dist/tools/execute-swap.d.ts +17 -0
- package/dist/tools/execute-swap.js +51 -0
- package/dist/tools/execute-swap.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +10 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/search-token.d.ts +14 -0
- package/dist/tools/search-token.js +43 -0
- package/dist/tools/search-token.js.map +1 -0
- package/dist/types.d.ts +81 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +73 -0
- package/dist/utils.js.map +1 -0
- package/dist/validator.d.ts +3 -0
- package/dist/validator.js +106 -0
- package/dist/validator.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# DMind SDK
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the [DMind AI](https://huggingface.co/DMindAI/DMind-3-nano) platform — chat completions with built-in crypto trading tools.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @dmindai/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import {
|
|
15
|
+
DMind,
|
|
16
|
+
SEARCH_TOKEN,
|
|
17
|
+
EXECUTE_SWAP,
|
|
18
|
+
type SearchTokenInput,
|
|
19
|
+
type ExecuteSwapInput,
|
|
20
|
+
} from "@dmindai/sdk";
|
|
21
|
+
|
|
22
|
+
// 1. Implement the two built-in tools with your own backend logic
|
|
23
|
+
// params is fully typed — IDE will auto-complete all fields from SearchTokenInput / ExecuteSwapInput
|
|
24
|
+
|
|
25
|
+
const searchToken = SEARCH_TOKEN.implement(async (params: SearchTokenInput) => {
|
|
26
|
+
const tokens = await myTokenService.search(params);
|
|
27
|
+
return { tokens };
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const executeSwap = EXECUTE_SWAP.implement(async (params: ExecuteSwapInput) => {
|
|
31
|
+
const result = await myDexService.buildSwap(params);
|
|
32
|
+
return { transaction: result.transaction, quote: result.quote };
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// 2. Create the DMind client
|
|
36
|
+
|
|
37
|
+
const dmind = new DMind({
|
|
38
|
+
baseUrl: "http://localhost:8000/v1", // vLLM local server
|
|
39
|
+
apiKey: "your-api-key", // optional
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 3. Send a chat request with tool definitions
|
|
43
|
+
|
|
44
|
+
const response = await dmind.chat.send({
|
|
45
|
+
messages: [{ role: "user", content: "Swap 1 SOL to USDC on Solana" }],
|
|
46
|
+
model: "dmind-3-nano",
|
|
47
|
+
tools: [searchToken.toDefinition(), executeSwap.toDefinition()],
|
|
48
|
+
toolChoice: "auto",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// 4. Handle the tool call
|
|
52
|
+
|
|
53
|
+
const toolCall = response.choices[0].message.toolCalls?.[0];
|
|
54
|
+
if (toolCall) {
|
|
55
|
+
const args = searchToken.parseInput(JSON.parse(toolCall.function.arguments));
|
|
56
|
+
console.log("Tool called:", toolCall.function.name, args);
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Built-in Tools
|
|
61
|
+
|
|
62
|
+
The SDK provides two fixed tools matching the [DMind-3-nano model card](https://huggingface.co/DMindAI/DMind-3-nano#tool-definitions--schemas). Their names, descriptions, and parameter schemas cannot be modified.
|
|
63
|
+
|
|
64
|
+
### SEARCH_TOKEN
|
|
65
|
+
|
|
66
|
+
Search for a cryptocurrency token on-chain to retrieve its metadata or address.
|
|
67
|
+
|
|
68
|
+
| Parameter | Type | Required | Description |
|
|
69
|
+
| --------- | ------ | -------- | ------------------------------------------------------ |
|
|
70
|
+
| symbol | string | No | Token ticker symbol (e.g. `SOL`, `USDC`) |
|
|
71
|
+
| address | string | No | Contract address of the token |
|
|
72
|
+
| chain | string | No | Target blockchain: `solana`, `ethereum`, `bsc`, `base` |
|
|
73
|
+
| keyword | string | No | Free-text search keywords |
|
|
74
|
+
|
|
75
|
+
### EXECUTE_SWAP
|
|
76
|
+
|
|
77
|
+
Propose a token swap transaction.
|
|
78
|
+
|
|
79
|
+
| Parameter | Type | Required | Description |
|
|
80
|
+
| -------------------- | ------ | -------- | --------------------------------------- |
|
|
81
|
+
| inputTokenSymbol | string | Yes | Symbol of the token being sold |
|
|
82
|
+
| inputTokenCA | string | No | Contract address of the input token |
|
|
83
|
+
| outputTokenCA | string | No | Contract address of the output token |
|
|
84
|
+
| inputTokenAmount | number | No | Absolute amount to swap |
|
|
85
|
+
| inputTokenPercentage | number | No | Percentage of balance to swap (0.0–1.0) |
|
|
86
|
+
| outputTokenAmount | number | No | Minimum output amount expected |
|
|
87
|
+
|
|
88
|
+
### Using Tools Without Execute Logic
|
|
89
|
+
|
|
90
|
+
The tools can also be used directly without `implement()` — for schema definitions and input parsing only:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { SEARCH_TOKEN, EXECUTE_SWAP } from "@dmindai/sdk";
|
|
94
|
+
|
|
95
|
+
// Get the fixed JSON schema for the chat API
|
|
96
|
+
const tools = [SEARCH_TOKEN.toDefinition(), EXECUTE_SWAP.toDefinition()];
|
|
97
|
+
|
|
98
|
+
// Parse and validate raw tool call arguments
|
|
99
|
+
const args = SEARCH_TOKEN.parseInput({ symbol: "SOL", chain: "solana" });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Streaming
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const stream = await dmind.chat.send({
|
|
106
|
+
messages: [{ role: "user", content: "Find the USDC token on Ethereum" }],
|
|
107
|
+
model: "dmind-3-nano",
|
|
108
|
+
tools: [searchToken.toDefinition()],
|
|
109
|
+
stream: true,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
for await (const chunk of stream) {
|
|
113
|
+
process.stdout.write(chunk.choices[0].delta.content ?? "");
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Multi-turn Tool Loop
|
|
118
|
+
|
|
119
|
+
For automated multi-turn conversations with tool execution:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { DMind, runLoop } from "@dmindai/sdk";
|
|
123
|
+
|
|
124
|
+
const dmind = new DMind({
|
|
125
|
+
modelGenerate: async (messages) => {
|
|
126
|
+
// call your model inference here
|
|
127
|
+
return modelResponse;
|
|
128
|
+
},
|
|
129
|
+
tools: {
|
|
130
|
+
SEARCH_TOKEN: async (args) => {
|
|
131
|
+
return await myTokenService.search(args);
|
|
132
|
+
},
|
|
133
|
+
EXECUTE_SWAP: async (args) => {
|
|
134
|
+
return await myDexService.buildSwap(args);
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const result = await runLoop(dmind, [
|
|
140
|
+
{ role: "user", content: "Swap 0.5 SOL to USDC" },
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
console.log(result.final); // final parsed result
|
|
144
|
+
console.log(result.toolHops); // number of tool calls executed
|
|
145
|
+
```
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export interface ContentPartText {
|
|
2
|
+
type: "text";
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ContentPartImage {
|
|
6
|
+
type: "image_url";
|
|
7
|
+
imageUrl: {
|
|
8
|
+
url: string;
|
|
9
|
+
detail?: "auto" | "low" | "high";
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export type ContentPart = ContentPartText | ContentPartImage;
|
|
13
|
+
export interface SystemMessage {
|
|
14
|
+
role: "system";
|
|
15
|
+
content: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface UserMessage {
|
|
19
|
+
role: "user";
|
|
20
|
+
content: string | ContentPart[];
|
|
21
|
+
name?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ChatAssistantMessage {
|
|
24
|
+
role: "assistant";
|
|
25
|
+
content?: string | null;
|
|
26
|
+
toolCalls?: ChatToolCall[];
|
|
27
|
+
reasoning?: string | null;
|
|
28
|
+
refusal?: string | null;
|
|
29
|
+
}
|
|
30
|
+
export interface ChatToolMessage {
|
|
31
|
+
role: "tool";
|
|
32
|
+
toolCallId: string;
|
|
33
|
+
content: string;
|
|
34
|
+
}
|
|
35
|
+
export type ChatMessage = SystemMessage | UserMessage | ChatAssistantMessage | ChatToolMessage;
|
|
36
|
+
export interface ChatToolCallFunction {
|
|
37
|
+
name: string;
|
|
38
|
+
arguments: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ChatToolCall {
|
|
41
|
+
id: string;
|
|
42
|
+
type: "function";
|
|
43
|
+
function: ChatToolCallFunction;
|
|
44
|
+
}
|
|
45
|
+
export interface ToolFunctionDefinition {
|
|
46
|
+
name: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
parameters?: Record<string, unknown>;
|
|
49
|
+
strict?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface ToolDefinition {
|
|
52
|
+
type: "function";
|
|
53
|
+
function: ToolFunctionDefinition;
|
|
54
|
+
}
|
|
55
|
+
export type ToolChoiceOption = "auto" | "none" | "required" | {
|
|
56
|
+
type: "function";
|
|
57
|
+
function: {
|
|
58
|
+
name: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export interface ChatRequest {
|
|
62
|
+
messages: ChatMessage[];
|
|
63
|
+
model?: string;
|
|
64
|
+
stream?: boolean;
|
|
65
|
+
temperature?: number;
|
|
66
|
+
maxTokens?: number;
|
|
67
|
+
maxCompletionTokens?: number;
|
|
68
|
+
topP?: number;
|
|
69
|
+
frequencyPenalty?: number;
|
|
70
|
+
presencePenalty?: number;
|
|
71
|
+
stop?: string | string[];
|
|
72
|
+
seed?: number;
|
|
73
|
+
tools?: ToolDefinition[];
|
|
74
|
+
toolChoice?: ToolChoiceOption;
|
|
75
|
+
parallelToolCalls?: boolean;
|
|
76
|
+
responseFormat?: {
|
|
77
|
+
type: "text" | "json_object";
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export interface TokenUsage {
|
|
81
|
+
completionTokens: number;
|
|
82
|
+
promptTokens: number;
|
|
83
|
+
totalTokens: number;
|
|
84
|
+
}
|
|
85
|
+
export interface ChatResponseChoice {
|
|
86
|
+
index: number;
|
|
87
|
+
message: ChatAssistantMessage;
|
|
88
|
+
finishReason: string | null;
|
|
89
|
+
}
|
|
90
|
+
export interface ChatResponse {
|
|
91
|
+
id: string;
|
|
92
|
+
object: "chat.completion";
|
|
93
|
+
created: number;
|
|
94
|
+
model: string;
|
|
95
|
+
choices: ChatResponseChoice[];
|
|
96
|
+
usage?: TokenUsage;
|
|
97
|
+
}
|
|
98
|
+
export interface ChatStreamingToolCall {
|
|
99
|
+
index: number;
|
|
100
|
+
id?: string;
|
|
101
|
+
type?: "function";
|
|
102
|
+
function?: {
|
|
103
|
+
name?: string;
|
|
104
|
+
arguments?: string;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export interface ChatStreamingDelta {
|
|
108
|
+
role?: "assistant";
|
|
109
|
+
content?: string | null;
|
|
110
|
+
toolCalls?: ChatStreamingToolCall[];
|
|
111
|
+
reasoning?: string | null;
|
|
112
|
+
refusal?: string | null;
|
|
113
|
+
}
|
|
114
|
+
export interface ChatStreamingChoice {
|
|
115
|
+
index: number;
|
|
116
|
+
delta: ChatStreamingDelta;
|
|
117
|
+
finishReason: string | null;
|
|
118
|
+
}
|
|
119
|
+
export interface ChatStreamingChunk {
|
|
120
|
+
id: string;
|
|
121
|
+
object: "chat.completion.chunk";
|
|
122
|
+
created: number;
|
|
123
|
+
model: string;
|
|
124
|
+
choices: ChatStreamingChoice[];
|
|
125
|
+
usage?: TokenUsage;
|
|
126
|
+
}
|
|
127
|
+
import type { ModelGenerate, ModelProfile, ProtocolMode, ToolHandlers } from "./types";
|
|
128
|
+
export interface DMindOptions {
|
|
129
|
+
apiKey?: string;
|
|
130
|
+
baseUrl?: string;
|
|
131
|
+
defaultModel?: string;
|
|
132
|
+
defaultHeaders?: Record<string, string>;
|
|
133
|
+
protocolMode?: ProtocolMode;
|
|
134
|
+
modelGenerate?: ModelGenerate;
|
|
135
|
+
tools?: ToolHandlers;
|
|
136
|
+
modelProfile?: ModelProfile;
|
|
137
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Message types
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
//# sourceMappingURL=chat-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-types.js","sourceRoot":"","sources":["../src/chat-types.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E"}
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ChatRequest, type ChatResponse, type ChatStreamingChunk, type DMindOptions } from "./chat-types";
|
|
2
|
+
export declare class Chat {
|
|
3
|
+
private readonly apiKey;
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly defaultModel?;
|
|
6
|
+
private readonly defaultHeaders;
|
|
7
|
+
/** @internal Created internally by the DMind constructor. */
|
|
8
|
+
constructor(options: DMindOptions);
|
|
9
|
+
send(request: ChatRequest & {
|
|
10
|
+
stream?: false;
|
|
11
|
+
}): Promise<ChatResponse>;
|
|
12
|
+
send(request: ChatRequest & {
|
|
13
|
+
stream: true;
|
|
14
|
+
}): Promise<AsyncIterable<ChatStreamingChunk>>;
|
|
15
|
+
send(request: ChatRequest): Promise<ChatResponse | AsyncIterable<ChatStreamingChunk>>;
|
|
16
|
+
}
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Chat = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// camelCase -> snake_case request serialization
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
function serializeContentPart(part) {
|
|
9
|
+
if (part.type === "text") {
|
|
10
|
+
return { type: "text", text: part.text };
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
type: "image_url",
|
|
14
|
+
image_url: { url: part.imageUrl.url, detail: part.imageUrl.detail },
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function serializeToolCall(tc) {
|
|
18
|
+
return {
|
|
19
|
+
id: tc.id,
|
|
20
|
+
type: tc.type,
|
|
21
|
+
function: { name: tc.function.name, arguments: tc.function.arguments },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function serializeMessage(msg) {
|
|
25
|
+
switch (msg.role) {
|
|
26
|
+
case "system":
|
|
27
|
+
return { role: "system", content: msg.content, ...(msg.name && { name: msg.name }) };
|
|
28
|
+
case "user": {
|
|
29
|
+
const content = typeof msg.content === "string"
|
|
30
|
+
? msg.content
|
|
31
|
+
: msg.content.map(serializeContentPart);
|
|
32
|
+
return { role: "user", content, ...(msg.name && { name: msg.name }) };
|
|
33
|
+
}
|
|
34
|
+
case "assistant": {
|
|
35
|
+
const out = { role: "assistant" };
|
|
36
|
+
if (msg.content !== undefined)
|
|
37
|
+
out.content = msg.content;
|
|
38
|
+
if (msg.toolCalls?.length)
|
|
39
|
+
out.tool_calls = msg.toolCalls.map(serializeToolCall);
|
|
40
|
+
if (msg.reasoning !== undefined)
|
|
41
|
+
out.reasoning = msg.reasoning;
|
|
42
|
+
if (msg.refusal !== undefined)
|
|
43
|
+
out.refusal = msg.refusal;
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
case "tool":
|
|
47
|
+
return { role: "tool", tool_call_id: msg.toolCallId, content: msg.content };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function serializeToolDef(def) {
|
|
51
|
+
return {
|
|
52
|
+
type: def.type,
|
|
53
|
+
function: {
|
|
54
|
+
name: def.function.name,
|
|
55
|
+
...(def.function.description && { description: def.function.description }),
|
|
56
|
+
...(def.function.parameters && { parameters: def.function.parameters }),
|
|
57
|
+
...(def.function.strict !== undefined && { strict: def.function.strict }),
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function serializeToolChoice(choice) {
|
|
62
|
+
if (typeof choice === "string")
|
|
63
|
+
return choice;
|
|
64
|
+
return { type: choice.type, function: { name: choice.function.name } };
|
|
65
|
+
}
|
|
66
|
+
function buildRequestBody(request, defaultModel) {
|
|
67
|
+
const body = {
|
|
68
|
+
messages: request.messages.map(serializeMessage),
|
|
69
|
+
};
|
|
70
|
+
const model = request.model ?? defaultModel;
|
|
71
|
+
if (model)
|
|
72
|
+
body.model = model;
|
|
73
|
+
if (request.stream !== undefined)
|
|
74
|
+
body.stream = request.stream;
|
|
75
|
+
if (request.temperature !== undefined)
|
|
76
|
+
body.temperature = request.temperature;
|
|
77
|
+
if (request.maxTokens !== undefined)
|
|
78
|
+
body.max_tokens = request.maxTokens;
|
|
79
|
+
if (request.maxCompletionTokens !== undefined)
|
|
80
|
+
body.max_completion_tokens = request.maxCompletionTokens;
|
|
81
|
+
if (request.topP !== undefined)
|
|
82
|
+
body.top_p = request.topP;
|
|
83
|
+
if (request.frequencyPenalty !== undefined)
|
|
84
|
+
body.frequency_penalty = request.frequencyPenalty;
|
|
85
|
+
if (request.presencePenalty !== undefined)
|
|
86
|
+
body.presence_penalty = request.presencePenalty;
|
|
87
|
+
if (request.stop !== undefined)
|
|
88
|
+
body.stop = request.stop;
|
|
89
|
+
if (request.seed !== undefined)
|
|
90
|
+
body.seed = request.seed;
|
|
91
|
+
if (request.tools?.length)
|
|
92
|
+
body.tools = request.tools.map(serializeToolDef);
|
|
93
|
+
if (request.toolChoice !== undefined)
|
|
94
|
+
body.tool_choice = serializeToolChoice(request.toolChoice);
|
|
95
|
+
if (request.parallelToolCalls !== undefined)
|
|
96
|
+
body.parallel_tool_calls = request.parallelToolCalls;
|
|
97
|
+
if (request.responseFormat !== undefined)
|
|
98
|
+
body.response_format = request.responseFormat;
|
|
99
|
+
return body;
|
|
100
|
+
}
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// snake_case -> camelCase response deserialization
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
function parseToolCall(raw) {
|
|
105
|
+
return {
|
|
106
|
+
id: raw.id,
|
|
107
|
+
type: raw.type ?? "function",
|
|
108
|
+
function: { name: raw.function.name, arguments: raw.function.arguments },
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function parseAssistantMessage(raw) {
|
|
112
|
+
const msg = { role: "assistant" };
|
|
113
|
+
if (raw.content !== undefined)
|
|
114
|
+
msg.content = raw.content;
|
|
115
|
+
if (raw.tool_calls?.length)
|
|
116
|
+
msg.toolCalls = raw.tool_calls.map(parseToolCall);
|
|
117
|
+
if (raw.reasoning !== undefined)
|
|
118
|
+
msg.reasoning = raw.reasoning;
|
|
119
|
+
if (raw.refusal !== undefined)
|
|
120
|
+
msg.refusal = raw.refusal;
|
|
121
|
+
return msg;
|
|
122
|
+
}
|
|
123
|
+
function parseUsage(raw) {
|
|
124
|
+
if (!raw)
|
|
125
|
+
return undefined;
|
|
126
|
+
return {
|
|
127
|
+
completionTokens: raw.completion_tokens ?? 0,
|
|
128
|
+
promptTokens: raw.prompt_tokens ?? 0,
|
|
129
|
+
totalTokens: raw.total_tokens ?? 0,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function parseChoice(raw) {
|
|
133
|
+
return {
|
|
134
|
+
index: raw.index ?? 0,
|
|
135
|
+
message: parseAssistantMessage(raw.message ?? {}),
|
|
136
|
+
finishReason: raw.finish_reason ?? null,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function parseChatResponse(raw) {
|
|
140
|
+
return {
|
|
141
|
+
id: raw.id ?? "",
|
|
142
|
+
object: "chat.completion",
|
|
143
|
+
created: raw.created ?? 0,
|
|
144
|
+
model: raw.model ?? "",
|
|
145
|
+
choices: (raw.choices ?? []).map(parseChoice),
|
|
146
|
+
usage: parseUsage(raw.usage),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function parseStreamingToolCall(raw) {
|
|
150
|
+
const tc = { index: raw.index ?? 0 };
|
|
151
|
+
if (raw.id !== undefined)
|
|
152
|
+
tc.id = raw.id;
|
|
153
|
+
if (raw.type !== undefined)
|
|
154
|
+
tc.type = raw.type;
|
|
155
|
+
if (raw.function) {
|
|
156
|
+
tc.function = {};
|
|
157
|
+
if (raw.function.name !== undefined)
|
|
158
|
+
tc.function.name = raw.function.name;
|
|
159
|
+
if (raw.function.arguments !== undefined)
|
|
160
|
+
tc.function.arguments = raw.function.arguments;
|
|
161
|
+
}
|
|
162
|
+
return tc;
|
|
163
|
+
}
|
|
164
|
+
function parseStreamingDelta(raw) {
|
|
165
|
+
const delta = {};
|
|
166
|
+
if (raw.role !== undefined)
|
|
167
|
+
delta.role = raw.role;
|
|
168
|
+
if (raw.content !== undefined)
|
|
169
|
+
delta.content = raw.content;
|
|
170
|
+
if (raw.tool_calls?.length)
|
|
171
|
+
delta.toolCalls = raw.tool_calls.map(parseStreamingToolCall);
|
|
172
|
+
if (raw.reasoning !== undefined)
|
|
173
|
+
delta.reasoning = raw.reasoning;
|
|
174
|
+
if (raw.refusal !== undefined)
|
|
175
|
+
delta.refusal = raw.refusal;
|
|
176
|
+
return delta;
|
|
177
|
+
}
|
|
178
|
+
function parseStreamingChoice(raw) {
|
|
179
|
+
return {
|
|
180
|
+
index: raw.index ?? 0,
|
|
181
|
+
delta: parseStreamingDelta(raw.delta ?? {}),
|
|
182
|
+
finishReason: raw.finish_reason ?? null,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function parseStreamingChunk(raw) {
|
|
186
|
+
return {
|
|
187
|
+
id: raw.id ?? "",
|
|
188
|
+
object: "chat.completion.chunk",
|
|
189
|
+
created: raw.created ?? 0,
|
|
190
|
+
model: raw.model ?? "",
|
|
191
|
+
choices: (raw.choices ?? []).map(parseStreamingChoice),
|
|
192
|
+
usage: parseUsage(raw.usage),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
// SSE async iterator
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
async function* parseSSEStream(body) {
|
|
199
|
+
const reader = body.getReader();
|
|
200
|
+
const decoder = new TextDecoder();
|
|
201
|
+
let buffer = "";
|
|
202
|
+
try {
|
|
203
|
+
while (true) {
|
|
204
|
+
const { done, value } = await reader.read();
|
|
205
|
+
if (done)
|
|
206
|
+
break;
|
|
207
|
+
buffer += decoder.decode(value, { stream: true });
|
|
208
|
+
const lines = buffer.split("\n");
|
|
209
|
+
buffer = lines.pop() ?? "";
|
|
210
|
+
for (const line of lines) {
|
|
211
|
+
const trimmed = line.trim();
|
|
212
|
+
if (!trimmed || trimmed.startsWith(":"))
|
|
213
|
+
continue;
|
|
214
|
+
if (trimmed.startsWith("data:")) {
|
|
215
|
+
const payload = trimmed.slice("data:".length).trim();
|
|
216
|
+
if (payload === "[DONE]")
|
|
217
|
+
return;
|
|
218
|
+
try {
|
|
219
|
+
yield parseStreamingChunk(JSON.parse(payload));
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
// skip malformed JSON chunks
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (buffer.trim().startsWith("data:")) {
|
|
228
|
+
const payload = buffer.trim().slice("data:".length).trim();
|
|
229
|
+
if (payload && payload !== "[DONE]") {
|
|
230
|
+
try {
|
|
231
|
+
yield parseStreamingChunk(JSON.parse(payload));
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
// skip
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
reader.releaseLock();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// ---------------------------------------------------------------------------
|
|
244
|
+
// Chat class
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
class Chat {
|
|
247
|
+
/** @internal Created internally by the DMind constructor. */
|
|
248
|
+
constructor(options) {
|
|
249
|
+
this.apiKey = options.apiKey ?? "";
|
|
250
|
+
this.baseUrl = (options.baseUrl ?? "").replace(/\/+$/, "");
|
|
251
|
+
this.defaultModel = options.defaultModel;
|
|
252
|
+
this.defaultHeaders = options.defaultHeaders ?? {};
|
|
253
|
+
}
|
|
254
|
+
async send(request) {
|
|
255
|
+
const body = buildRequestBody(request, this.defaultModel);
|
|
256
|
+
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
257
|
+
method: "POST",
|
|
258
|
+
headers: {
|
|
259
|
+
"Content-Type": "application/json",
|
|
260
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
261
|
+
...this.defaultHeaders,
|
|
262
|
+
},
|
|
263
|
+
body: JSON.stringify(body),
|
|
264
|
+
});
|
|
265
|
+
if (!response.ok) {
|
|
266
|
+
let detail;
|
|
267
|
+
try {
|
|
268
|
+
detail = await response.json();
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
detail = await response.text().catch(() => null);
|
|
272
|
+
}
|
|
273
|
+
throw new errors_1.SDKError("E_RUNTIME", `Chat API returned ${response.status}: ${response.statusText}`, detail);
|
|
274
|
+
}
|
|
275
|
+
if (request.stream) {
|
|
276
|
+
if (!response.body) {
|
|
277
|
+
throw new errors_1.SDKError("E_RUNTIME", "Streaming response has no body.");
|
|
278
|
+
}
|
|
279
|
+
return parseSSEStream(response.body);
|
|
280
|
+
}
|
|
281
|
+
const json = await response.json();
|
|
282
|
+
return parseChatResponse(json);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
exports.Chat = Chat;
|
|
286
|
+
//# sourceMappingURL=chat.js.map
|
package/dist/chat.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../src/chat.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAmBpC,8EAA8E;AAC9E,gDAAgD;AAChD,8EAA8E;AAE9E,SAAS,oBAAoB,CAAC,IAAiB;IAC7C,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAC3C,CAAC;IACD,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,SAAS,EAAE,EAAE,GAAG,EAAE,IAA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,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;CACF;AA5DD,oBA4DC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const OFFICIAL_START = "<start_function_call>";
|
|
2
|
+
export declare const OFFICIAL_END = "<end_function_call>";
|
|
3
|
+
export declare const LEGACY_START = "<function_calls>";
|
|
4
|
+
export declare const LEGACY_END = "</function_calls>";
|
|
5
|
+
export declare const FUNCTION_RESPONSE_START = "<function_response>";
|
|
6
|
+
export declare const FUNCTION_RESPONSE_END = "</function_response>";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FUNCTION_RESPONSE_END = exports.FUNCTION_RESPONSE_START = exports.LEGACY_END = exports.LEGACY_START = exports.OFFICIAL_END = exports.OFFICIAL_START = void 0;
|
|
4
|
+
exports.OFFICIAL_START = "<start_function_call>";
|
|
5
|
+
exports.OFFICIAL_END = "<end_function_call>";
|
|
6
|
+
exports.LEGACY_START = "<function_calls>";
|
|
7
|
+
exports.LEGACY_END = "</function_calls>";
|
|
8
|
+
exports.FUNCTION_RESPONSE_START = "<function_response>";
|
|
9
|
+
exports.FUNCTION_RESPONSE_END = "</function_response>";
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,uBAAuB,CAAC;AACzC,QAAA,YAAY,GAAG,qBAAqB,CAAC;AACrC,QAAA,YAAY,GAAG,kBAAkB,CAAC;AAClC,QAAA,UAAU,GAAG,mBAAmB,CAAC;AACjC,QAAA,uBAAuB,GAAG,qBAAqB,CAAC;AAChD,QAAA,qBAAqB,GAAG,sBAAsB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type SDKErrorCode = "E_NO_WRAPPER" | "E_WRONG_PROTOCOL" | "E_JSON_INVALID" | "E_TOOL_UNKNOWN" | "E_PARAM_MISSING" | "E_PARAM_FORBIDDEN" | "E_PARAM_INVALID" | "E_INVOKE_COUNT" | "E_RUNTIME";
|
|
2
|
+
export interface ValidationIssue {
|
|
3
|
+
code: SDKErrorCode;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class SDKError extends Error {
|
|
7
|
+
readonly code: SDKErrorCode;
|
|
8
|
+
readonly details?: unknown;
|
|
9
|
+
constructor(code: SDKErrorCode, message: string, details?: unknown);
|
|
10
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDKError = void 0;
|
|
4
|
+
class SDKError extends Error {
|
|
5
|
+
constructor(code, message, details) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "SDKError";
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.details = details;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.SDKError = SDKError;
|
|
13
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAgBA,MAAa,QAAS,SAAQ,KAAK;IAIjC,YAAY,IAAkB,EAAE,OAAe,EAAE,OAAiB;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAVD,4BAUC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./chat-types";
|
|
2
|
+
export * from "./chat";
|
|
3
|
+
export * from "./constants";
|
|
4
|
+
export * from "./errors";
|
|
5
|
+
export * from "./parser";
|
|
6
|
+
export * from "./profiles";
|
|
7
|
+
export * from "./runtime";
|
|
8
|
+
export * from "./sdk";
|
|
9
|
+
export * from "./tool";
|
|
10
|
+
export * from "./tools";
|
|
11
|
+
export * from "./types";
|
|
12
|
+
export * from "./validator";
|