@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/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./chat-types"), exports);
|
|
18
|
+
__exportStar(require("./chat"), exports);
|
|
19
|
+
__exportStar(require("./constants"), exports);
|
|
20
|
+
__exportStar(require("./errors"), exports);
|
|
21
|
+
__exportStar(require("./parser"), exports);
|
|
22
|
+
__exportStar(require("./profiles"), exports);
|
|
23
|
+
__exportStar(require("./runtime"), exports);
|
|
24
|
+
__exportStar(require("./sdk"), exports);
|
|
25
|
+
__exportStar(require("./tool"), exports);
|
|
26
|
+
__exportStar(require("./tools"), exports);
|
|
27
|
+
__exportStar(require("./types"), exports);
|
|
28
|
+
__exportStar(require("./validator"), exports);
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,yCAAuB;AACvB,8CAA4B;AAC5B,2CAAyB;AACzB,2CAAyB;AACzB,6CAA2B;AAC3B,4CAA0B;AAC1B,wCAAsB;AACtB,yCAAuB;AACvB,0CAAwB;AACxB,0CAAwB;AACxB,8CAA4B"}
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ParseOptions, ParsedResult, ProtocolMode, ToolCallResult } from "./types";
|
|
2
|
+
export declare function parse(raw: string, mode?: ProtocolMode, options?: ParseOptions): ParsedResult;
|
|
3
|
+
export declare function parseOfficial(raw: string, options?: ParseOptions): ToolCallResult | ParsedResult;
|
package/dist/parser.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = parse;
|
|
4
|
+
exports.parseOfficial = parseOfficial;
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const OFFICIAL_BLOCK_RE = /<start_function_call>([\s\S]*?)<end_function_call>/g;
|
|
8
|
+
const LEGACY_BLOCK_RE = /<function_calls>([\s\S]*?)<\/function_calls>/g;
|
|
9
|
+
const LEGACY_INVOKE_RE = /<invoke\s+name=(?:"([^"]+)"|'([^']+)')\s*>([\s\S]*?)<\/invoke>/g;
|
|
10
|
+
const LEGACY_PARAM_RE = /<parameter\s+name=(?:"([^"]+)"|'([^']+)')\s*>([\s\S]*?)<\/parameter>/g;
|
|
11
|
+
function parseOfficialPayload(payload, raw, options = {}) {
|
|
12
|
+
const trimmed = payload.trim();
|
|
13
|
+
if (!trimmed.startsWith("call:")) {
|
|
14
|
+
return (0, utils_1.makeParseError)("E_JSON_INVALID", "Official function call must start with `call:`.", raw);
|
|
15
|
+
}
|
|
16
|
+
const body = trimmed.slice("call:".length);
|
|
17
|
+
const jsonIndex = body.indexOf("{");
|
|
18
|
+
if (jsonIndex < 0) {
|
|
19
|
+
return (0, utils_1.makeParseError)("E_JSON_INVALID", "Official function call payload is missing JSON args.", raw);
|
|
20
|
+
}
|
|
21
|
+
const tool = body.slice(0, jsonIndex).trim();
|
|
22
|
+
const argsText = body.slice(jsonIndex).trim();
|
|
23
|
+
if (tool.length === 0) {
|
|
24
|
+
return (0, utils_1.makeParseError)("E_PARAM_MISSING", "Tool name is missing.", raw);
|
|
25
|
+
}
|
|
26
|
+
if (options.allowedTools && !options.allowedTools.has(tool)) {
|
|
27
|
+
return (0, utils_1.makeParseError)("E_TOOL_UNKNOWN", `Unknown tool: ${tool}.`, raw);
|
|
28
|
+
}
|
|
29
|
+
let args;
|
|
30
|
+
try {
|
|
31
|
+
args = JSON.parse(argsText);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return (0, utils_1.makeParseError)("E_JSON_INVALID", `Failed to parse tool args JSON: ${error.message}`, raw);
|
|
35
|
+
}
|
|
36
|
+
if (!(0, utils_1.isPlainObject)(args)) {
|
|
37
|
+
return (0, utils_1.makeParseError)("E_JSON_INVALID", "Tool args must be a JSON object.", raw);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
type: "tool_call",
|
|
41
|
+
tool,
|
|
42
|
+
args,
|
|
43
|
+
raw,
|
|
44
|
+
protocol: "official"
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function parseLegacyPayload(payload, raw, options = {}) {
|
|
48
|
+
const invokeMatches = [...payload.matchAll(LEGACY_INVOKE_RE)];
|
|
49
|
+
if (invokeMatches.length !== 1) {
|
|
50
|
+
return (0, utils_1.makeParseError)("E_INVOKE_COUNT", `Legacy payload must contain exactly 1 invoke node, got ${invokeMatches.length}.`, raw);
|
|
51
|
+
}
|
|
52
|
+
const [, dqName, sqName, invokeBody] = invokeMatches[0];
|
|
53
|
+
const tool = (dqName ?? sqName ?? "").trim();
|
|
54
|
+
if (tool.length === 0) {
|
|
55
|
+
return (0, utils_1.makeParseError)("E_PARAM_MISSING", "Tool name is missing.", raw);
|
|
56
|
+
}
|
|
57
|
+
if (options.allowedTools && !options.allowedTools.has(tool)) {
|
|
58
|
+
return (0, utils_1.makeParseError)("E_TOOL_UNKNOWN", `Unknown tool: ${tool}.`, raw);
|
|
59
|
+
}
|
|
60
|
+
const args = {};
|
|
61
|
+
for (const paramMatch of invokeBody.matchAll(LEGACY_PARAM_RE)) {
|
|
62
|
+
const [, dqParamName, sqParamName, paramValue] = paramMatch;
|
|
63
|
+
const key = (dqParamName ?? sqParamName ?? "").trim();
|
|
64
|
+
if (!key) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
args[key] = (0, utils_1.parseLooseXmlValue)(paramValue);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
type: "tool_call",
|
|
71
|
+
tool,
|
|
72
|
+
args,
|
|
73
|
+
raw,
|
|
74
|
+
protocol: "legacy"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function matchOfficial(raw, options = {}) {
|
|
78
|
+
const matches = [...raw.matchAll(OFFICIAL_BLOCK_RE)];
|
|
79
|
+
if (matches.length === 0) {
|
|
80
|
+
if (raw.includes("call:") ||
|
|
81
|
+
raw.includes(constants_1.OFFICIAL_START) ||
|
|
82
|
+
raw.includes(constants_1.OFFICIAL_END)) {
|
|
83
|
+
return (0, utils_1.makeParseError)("E_NO_WRAPPER", "Function call content detected but official wrapper is missing.", raw);
|
|
84
|
+
}
|
|
85
|
+
return { type: "text", text: raw, raw };
|
|
86
|
+
}
|
|
87
|
+
if (matches.length !== 1) {
|
|
88
|
+
return (0, utils_1.makeParseError)("E_INVOKE_COUNT", `Official mode expects exactly 1 function call block, got ${matches.length}.`, raw);
|
|
89
|
+
}
|
|
90
|
+
const [match] = matches;
|
|
91
|
+
const outside = raw.replace(match[0], "").trim();
|
|
92
|
+
if (outside.length > 0) {
|
|
93
|
+
return (0, utils_1.makeParseError)("E_WRONG_PROTOCOL", "Official function-call output cannot mix wrapper with extra text.", raw);
|
|
94
|
+
}
|
|
95
|
+
return parseOfficialPayload(match[1], raw, options);
|
|
96
|
+
}
|
|
97
|
+
function matchLegacy(raw, options = {}) {
|
|
98
|
+
const matches = [...raw.matchAll(LEGACY_BLOCK_RE)];
|
|
99
|
+
if (matches.length === 0) {
|
|
100
|
+
if (raw.includes(constants_1.LEGACY_START) ||
|
|
101
|
+
raw.includes(constants_1.LEGACY_END) ||
|
|
102
|
+
raw.includes("<invoke")) {
|
|
103
|
+
return (0, utils_1.makeParseError)("E_NO_WRAPPER", "Legacy function call tags detected but wrapper is incomplete.", raw);
|
|
104
|
+
}
|
|
105
|
+
return { type: "text", text: raw, raw };
|
|
106
|
+
}
|
|
107
|
+
if (matches.length !== 1) {
|
|
108
|
+
return (0, utils_1.makeParseError)("E_INVOKE_COUNT", `Legacy mode expects exactly 1 function_calls block, got ${matches.length}.`, raw);
|
|
109
|
+
}
|
|
110
|
+
const [match] = matches;
|
|
111
|
+
const outside = raw.replace(match[0], "").trim();
|
|
112
|
+
if (outside.length > 0) {
|
|
113
|
+
return (0, utils_1.makeParseError)("E_WRONG_PROTOCOL", "Legacy function-call output cannot mix wrapper with extra text.", raw);
|
|
114
|
+
}
|
|
115
|
+
return parseLegacyPayload(match[1], raw, options);
|
|
116
|
+
}
|
|
117
|
+
function hasLegacyTags(raw) {
|
|
118
|
+
return (raw.includes(constants_1.LEGACY_START) || raw.includes(constants_1.LEGACY_END) || raw.includes("<invoke"));
|
|
119
|
+
}
|
|
120
|
+
function hasOfficialTags(raw) {
|
|
121
|
+
return (raw.includes(constants_1.OFFICIAL_START) || raw.includes(constants_1.OFFICIAL_END) || raw.includes("call:"));
|
|
122
|
+
}
|
|
123
|
+
function parse(raw, mode = "official", options = {}) {
|
|
124
|
+
if (mode === "official") {
|
|
125
|
+
if (hasLegacyTags(raw)) {
|
|
126
|
+
return (0, utils_1.makeParseError)("E_WRONG_PROTOCOL", "Legacy protocol tags detected in official mode.", raw);
|
|
127
|
+
}
|
|
128
|
+
return matchOfficial(raw, options);
|
|
129
|
+
}
|
|
130
|
+
if (mode === "legacy") {
|
|
131
|
+
if (hasOfficialTags(raw)) {
|
|
132
|
+
return (0, utils_1.makeParseError)("E_WRONG_PROTOCOL", "Official protocol tags detected in legacy mode.", raw);
|
|
133
|
+
}
|
|
134
|
+
return matchLegacy(raw, options);
|
|
135
|
+
}
|
|
136
|
+
const officialCandidate = matchOfficial(raw, options);
|
|
137
|
+
if (officialCandidate.type === "tool_call") {
|
|
138
|
+
return officialCandidate;
|
|
139
|
+
}
|
|
140
|
+
if (officialCandidate.type === "parse_error" &&
|
|
141
|
+
officialCandidate.code !== "E_NO_WRAPPER") {
|
|
142
|
+
return officialCandidate;
|
|
143
|
+
}
|
|
144
|
+
const legacyCandidate = matchLegacy(raw, options);
|
|
145
|
+
if (legacyCandidate.type === "tool_call") {
|
|
146
|
+
return legacyCandidate;
|
|
147
|
+
}
|
|
148
|
+
if (legacyCandidate.type === "parse_error" &&
|
|
149
|
+
legacyCandidate.code !== "E_NO_WRAPPER") {
|
|
150
|
+
return legacyCandidate;
|
|
151
|
+
}
|
|
152
|
+
if (hasOfficialTags(raw) || hasLegacyTags(raw)) {
|
|
153
|
+
return (0, utils_1.makeParseError)("E_NO_WRAPPER", "Function call-like content detected but no valid wrapper found.", raw);
|
|
154
|
+
}
|
|
155
|
+
return { type: "text", text: raw, raw };
|
|
156
|
+
}
|
|
157
|
+
function parseOfficial(raw, options = {}) {
|
|
158
|
+
return parse(raw, "official", options);
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":";;AA4MA,sBA0DC;AAED,sCAKC;AA7QD,2CAKqB;AAErB,mCAA4E;AAE5E,MAAM,iBAAiB,GAAG,qDAAqD,CAAC;AAChF,MAAM,eAAe,GAAG,+CAA+C,CAAC;AACxE,MAAM,gBAAgB,GAAG,iEAAiE,CAAC;AAC3F,MAAM,eAAe,GACnB,uEAAuE,CAAC;AAE1E,SAAS,oBAAoB,CAC3B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Aa,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACtD,IAAI,iBAAiB,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC3C,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IACD,IACE,iBAAiB,CAAC,IAAI,KAAK,aAAa;QACxC,iBAAiB,CAAC,IAAI,KAAK,cAAc,EACzC,CAAC;QACD,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAClD,IAAI,eAAe,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACzC,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,IACE,eAAe,CAAC,IAAI,KAAK,aAAa;QACtC,eAAe,CAAC,IAAI,KAAK,cAAc,EACvC,CAAC;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO,IAAA,sBAAc,EACnB,cAAc,EACd,iEAAiE,EACjE,GAAG,CACJ,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAC1C,CAAC;AAED,SAAgB,aAAa,CAC3B,GAAW,EACX,UAAwB,EAAE;IAE1B,OAAO,KAAK,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/profiles.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DMIND_3_NANO_PROFILE = void 0;
|
|
4
|
+
exports.toolNameSet = toolNameSet;
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const CHAIN_VALUES = ["solana", "ethereum", "bsc", "base"];
|
|
7
|
+
function validateSearchToken(args) {
|
|
8
|
+
const errors = [];
|
|
9
|
+
const hasSearchSeed = (0, utils_1.isNonEmptyString)(args.symbol) ||
|
|
10
|
+
(0, utils_1.isNonEmptyString)(args.address) ||
|
|
11
|
+
(0, utils_1.isNonEmptyString)(args.keyword);
|
|
12
|
+
if (!hasSearchSeed) {
|
|
13
|
+
errors.push({
|
|
14
|
+
code: "E_PARAM_MISSING",
|
|
15
|
+
message: "SEARCH_TOKEN requires at least one of symbol, address, or keyword."
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (args.address !== undefined && (0, utils_1.isNonEmptyString)(args.address)) {
|
|
19
|
+
if (!(0, utils_1.isLikelyTokenAddress)(args.address)) {
|
|
20
|
+
errors.push({
|
|
21
|
+
code: "E_PARAM_INVALID",
|
|
22
|
+
message: "SEARCH_TOKEN.address format is invalid."
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return errors;
|
|
27
|
+
}
|
|
28
|
+
function validateExecuteSwap(args) {
|
|
29
|
+
const errors = [];
|
|
30
|
+
if (args.inputTokenAmount !== undefined &&
|
|
31
|
+
args.inputTokenPercentage !== undefined) {
|
|
32
|
+
errors.push({
|
|
33
|
+
code: "E_PARAM_FORBIDDEN",
|
|
34
|
+
message: "inputTokenAmount and inputTokenPercentage are mutually exclusive."
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (args.inputTokenAmount !== undefined &&
|
|
38
|
+
typeof args.inputTokenAmount === "number" &&
|
|
39
|
+
args.inputTokenAmount <= 0) {
|
|
40
|
+
errors.push({
|
|
41
|
+
code: "E_PARAM_INVALID",
|
|
42
|
+
message: "inputTokenAmount must be greater than 0."
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (args.outputTokenAmount !== undefined &&
|
|
46
|
+
typeof args.outputTokenAmount === "number" &&
|
|
47
|
+
args.outputTokenAmount <= 0) {
|
|
48
|
+
errors.push({
|
|
49
|
+
code: "E_PARAM_INVALID",
|
|
50
|
+
message: "outputTokenAmount must be greater than 0."
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const maybeAddressKeys = ["inputTokenCA", "outputTokenCA"];
|
|
54
|
+
for (const key of maybeAddressKeys) {
|
|
55
|
+
const value = args[key];
|
|
56
|
+
if (value !== undefined && (0, utils_1.isNonEmptyString)(value) && !(0, utils_1.isLikelyTokenAddress)(value)) {
|
|
57
|
+
errors.push({
|
|
58
|
+
code: "E_PARAM_INVALID",
|
|
59
|
+
message: `${key} format is invalid.`
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return errors;
|
|
64
|
+
}
|
|
65
|
+
exports.DMIND_3_NANO_PROFILE = {
|
|
66
|
+
id: "dmind-3-nano",
|
|
67
|
+
tools: {
|
|
68
|
+
SEARCH_TOKEN: {
|
|
69
|
+
strict: true,
|
|
70
|
+
parameters: {
|
|
71
|
+
symbol: { type: "string", nonEmpty: true },
|
|
72
|
+
address: { type: "string", nonEmpty: true },
|
|
73
|
+
chain: { type: "string", enum: CHAIN_VALUES, nonEmpty: true },
|
|
74
|
+
keyword: { type: "string", nonEmpty: true }
|
|
75
|
+
},
|
|
76
|
+
customValidate: validateSearchToken
|
|
77
|
+
},
|
|
78
|
+
EXECUTE_SWAP: {
|
|
79
|
+
strict: true,
|
|
80
|
+
parameters: {
|
|
81
|
+
inputTokenSymbol: { type: "string", required: true, nonEmpty: true },
|
|
82
|
+
inputTokenCA: { type: "string", nonEmpty: true },
|
|
83
|
+
outputTokenCA: { type: "string", nonEmpty: true },
|
|
84
|
+
inputTokenAmount: { type: "number" },
|
|
85
|
+
inputTokenPercentage: { type: "number", min: 0, max: 1 },
|
|
86
|
+
outputTokenAmount: { type: "number" }
|
|
87
|
+
},
|
|
88
|
+
customValidate: validateExecuteSwap
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function toolNameSet(profile) {
|
|
93
|
+
return new Set(Object.keys(profile.tools));
|
|
94
|
+
}
|
|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Q,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC3C,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC7D,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;aAC5C;YACD,cAAc,EAAE,mBAAmB;SACpC;QACD,YAAY,EAAE;YACZ,MAAM,EAAE,IAAI;YACZ,UAAU,EAAE;gBACV,gBAAgB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;gBACpE,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAChD,aAAa,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;gBACjD,gBAAgB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACpC,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;gBACxD,iBAAiB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;aACtC;YACD,cAAc,EAAE,mBAAmB;SACpC;KACF;CACF,CAAC;AAEF,SAAgB,WAAW,CAAC,OAAqB;IAC/C,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runLoop = runLoop;
|
|
4
|
+
function toParseError(raw, message) {
|
|
5
|
+
return {
|
|
6
|
+
type: "parse_error",
|
|
7
|
+
code: "E_INVOKE_COUNT",
|
|
8
|
+
message,
|
|
9
|
+
raw
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
async function runLoop(sdk, messages, options = {}) {
|
|
13
|
+
const mode = options.mode;
|
|
14
|
+
const maxToolHops = options.maxToolHops ?? 3;
|
|
15
|
+
const functionResponseRole = options.functionResponseRole ?? "user";
|
|
16
|
+
const history = [...messages];
|
|
17
|
+
let toolHops = 0;
|
|
18
|
+
while (true) {
|
|
19
|
+
const raw = await sdk.generate(history);
|
|
20
|
+
history.push({ role: "assistant", content: raw });
|
|
21
|
+
const parsed = sdk.parse(raw, mode);
|
|
22
|
+
if (parsed.type !== "tool_call") {
|
|
23
|
+
return { final: parsed, messages: history, toolHops };
|
|
24
|
+
}
|
|
25
|
+
if (toolHops >= maxToolHops) {
|
|
26
|
+
return {
|
|
27
|
+
final: toParseError(raw, `Tool call count exceeds maxToolHops=${maxToolHops}.`),
|
|
28
|
+
messages: history,
|
|
29
|
+
toolHops
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const validation = sdk.validate(parsed);
|
|
33
|
+
if (!validation.ok) {
|
|
34
|
+
return {
|
|
35
|
+
final: {
|
|
36
|
+
type: "parse_error",
|
|
37
|
+
code: "E_PARAM_INVALID",
|
|
38
|
+
message: validation.errors.join("; "),
|
|
39
|
+
raw
|
|
40
|
+
},
|
|
41
|
+
messages: history,
|
|
42
|
+
toolHops
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const result = await sdk.execute(parsed);
|
|
46
|
+
const payload = sdk.wrapResponse({ status: "ok", result });
|
|
47
|
+
history.push({
|
|
48
|
+
role: functionResponseRole,
|
|
49
|
+
content: payload
|
|
50
|
+
});
|
|
51
|
+
toolHops += 1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":";;AAiBA,0BAsDC;AA/DD,SAAS,YAAY,CAAC,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ACL,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE,iBAAiB;oBACvB,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;oBACrC,GAAG;iBACJ;gBACD,QAAQ,EAAE,OAAO;gBACjB,QAAQ;aACT,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAC3D,OAAO,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,oBAAoB;YAC1B,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;QACH,QAAQ,IAAI,CAAC,CAAC;IAChB,CAAC;AACH,CAAC"}
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Chat } from "./chat";
|
|
2
|
+
import type { DMindOptions } from "./chat-types";
|
|
3
|
+
import type { BasicValidationResult, DetailedValidationResult, SDKCore, Message, ParsedResult, ProtocolMode, ToolCallResult } from "./types";
|
|
4
|
+
export declare class DMind implements SDKCore {
|
|
5
|
+
readonly chat: Chat;
|
|
6
|
+
private readonly _apiKey?;
|
|
7
|
+
private readonly _baseUrl?;
|
|
8
|
+
private readonly protocolMode;
|
|
9
|
+
private readonly modelGenerate?;
|
|
10
|
+
private readonly tools;
|
|
11
|
+
private readonly modelProfile;
|
|
12
|
+
private readonly allowedTools;
|
|
13
|
+
constructor(options?: DMindOptions);
|
|
14
|
+
get apiKey(): string | undefined;
|
|
15
|
+
get baseUrl(): string | undefined;
|
|
16
|
+
generate(messages: Message[]): Promise<string>;
|
|
17
|
+
parse(raw: string, mode?: ProtocolMode): ParsedResult;
|
|
18
|
+
validate(call: ToolCallResult): BasicValidationResult;
|
|
19
|
+
validateDetailed(call: ToolCallResult): DetailedValidationResult;
|
|
20
|
+
execute(call: ToolCallResult): Promise<any>;
|
|
21
|
+
wrapResponse(payload: any): string;
|
|
22
|
+
}
|
package/dist/sdk.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DMind = void 0;
|
|
4
|
+
const chat_1 = require("./chat");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
const parser_1 = require("./parser");
|
|
8
|
+
const profiles_1 = require("./profiles");
|
|
9
|
+
const validator_1 = require("./validator");
|
|
10
|
+
class DMind {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this._apiKey = options.apiKey;
|
|
13
|
+
this._baseUrl = options.baseUrl;
|
|
14
|
+
this.protocolMode = options.protocolMode ?? "official";
|
|
15
|
+
this.modelGenerate = options.modelGenerate;
|
|
16
|
+
this.tools = options.tools ?? {};
|
|
17
|
+
this.modelProfile = options.modelProfile ?? profiles_1.DMIND_3_NANO_PROFILE;
|
|
18
|
+
this.allowedTools = (0, profiles_1.toolNameSet)(this.modelProfile);
|
|
19
|
+
this.chat = new chat_1.Chat(options);
|
|
20
|
+
}
|
|
21
|
+
get apiKey() {
|
|
22
|
+
return this._apiKey;
|
|
23
|
+
}
|
|
24
|
+
get baseUrl() {
|
|
25
|
+
return this._baseUrl;
|
|
26
|
+
}
|
|
27
|
+
async generate(messages) {
|
|
28
|
+
if (!this.modelGenerate) {
|
|
29
|
+
throw new errors_1.SDKError("E_RUNTIME", "modelGenerate is not configured. Pass options.modelGenerate in constructor.");
|
|
30
|
+
}
|
|
31
|
+
return this.modelGenerate(messages);
|
|
32
|
+
}
|
|
33
|
+
parse(raw, mode = this.protocolMode) {
|
|
34
|
+
return (0, parser_1.parse)(raw, mode, { allowedTools: this.allowedTools });
|
|
35
|
+
}
|
|
36
|
+
validate(call) {
|
|
37
|
+
return (0, validator_1.validate)(call, this.modelProfile);
|
|
38
|
+
}
|
|
39
|
+
validateDetailed(call) {
|
|
40
|
+
return (0, validator_1.validateDetailed)(call, this.modelProfile);
|
|
41
|
+
}
|
|
42
|
+
async execute(call) {
|
|
43
|
+
const validation = (0, validator_1.validateDetailed)(call, this.modelProfile);
|
|
44
|
+
if (!validation.ok) {
|
|
45
|
+
throw new errors_1.SDKError(validation.errors[0].code, validation.errors.map((x) => `${x.code}: ${x.message}`).join("; "), validation.errors);
|
|
46
|
+
}
|
|
47
|
+
const handler = this.tools[call.tool];
|
|
48
|
+
if (!handler) {
|
|
49
|
+
throw new errors_1.SDKError("E_TOOL_UNKNOWN", `No tool executor registered for ${call.tool}.`);
|
|
50
|
+
}
|
|
51
|
+
return handler(call.args);
|
|
52
|
+
}
|
|
53
|
+
wrapResponse(payload) {
|
|
54
|
+
return `${constants_1.FUNCTION_RESPONSE_START}${JSON.stringify(payload)}${constants_1.FUNCTION_RESPONSE_END}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.DMind = DMind;
|
|
58
|
+
//# sourceMappingURL=sdk.js.map
|
package/dist/sdk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAE9B,2CAGqB;AACrB,qCAAoC;AACpC,qCAAiC;AACjC,yCAA+D;AAY/D,2CAAyD;AAEzD,MAAa,KAAK;IAWhB,YAAY,UAAwB,EAAE;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,UAAU,CAAC;QACvD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QACjC,IAAI,CAAC,YA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AAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAClE,UAAU,CAAC,MAAM,CAClB,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,iBAAQ,CAChB,gBAAgB,EAChB,mCAAmC,IAAI,CAAC,IAAI,GAAG,CAChD,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,YAAY,CAAC,OAAY;QACvB,OAAO,GAAG,mCAAuB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,iCAAqB,EAAE,CAAC;IACxF,CAAC;CACF;AA3ED,sBA2EC"}
|
package/dist/tool.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { ToolDefinition } from "./chat-types";
|
|
3
|
+
export interface ToolExecuteContext {
|
|
4
|
+
numberOfTurns: number;
|
|
5
|
+
toolCallId?: string;
|
|
6
|
+
}
|
|
7
|
+
export type ToolExecuteFn<TInput, TOutput> = (params: TInput, context?: ToolExecuteContext) => Promise<TOutput> | TOutput;
|
|
8
|
+
export type ToolGeneratorFn<TInput, TOutput, TEvent> = (params: TInput, context?: ToolExecuteContext) => AsyncGenerator<TEvent, TOutput, unknown>;
|
|
9
|
+
export interface Tool<TInput = unknown, TOutput = unknown, TEvent = never> {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly description: string;
|
|
12
|
+
readonly inputSchema: z.ZodType<TInput>;
|
|
13
|
+
readonly outputSchema?: z.ZodType<TOutput>;
|
|
14
|
+
readonly eventSchema?: z.ZodType<TEvent>;
|
|
15
|
+
readonly execute: ToolExecuteFn<TInput, TOutput> | ToolGeneratorFn<TInput, TOutput, TEvent> | false;
|
|
16
|
+
readonly type: "regular" | "generator" | "manual";
|
|
17
|
+
toDefinition(): ToolDefinition;
|
|
18
|
+
parseInput(raw: unknown): TInput;
|
|
19
|
+
implement<R = TOutput>(fn: ToolExecuteFn<TInput, R>): Tool<TInput, R, never>;
|
|
20
|
+
}
|
|
21
|
+
interface BaseToolConfig<TInput, TOutput> {
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
inputSchema: z.ZodType<TInput>;
|
|
25
|
+
outputSchema?: z.ZodType<TOutput>;
|
|
26
|
+
/** Hardcoded JSON Schema parameters for toDefinition(). When set, bypasses Zod toJSONSchema(). */
|
|
27
|
+
jsonSchemaParameters?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export interface RegularToolConfig<TInput, TOutput> extends BaseToolConfig<TInput, TOutput> {
|
|
30
|
+
eventSchema?: undefined;
|
|
31
|
+
execute: ToolExecuteFn<TInput, TOutput>;
|
|
32
|
+
}
|
|
33
|
+
export interface GeneratorToolConfig<TInput, TOutput, TEvent> extends BaseToolConfig<TInput, TOutput> {
|
|
34
|
+
eventSchema: z.ZodType<TEvent>;
|
|
35
|
+
execute: ToolGeneratorFn<TInput, TOutput, TEvent>;
|
|
36
|
+
}
|
|
37
|
+
export interface ManualToolConfig<TInput, TOutput> extends BaseToolConfig<TInput, TOutput> {
|
|
38
|
+
execute: false;
|
|
39
|
+
}
|
|
40
|
+
export type ToolConfig<TInput, TOutput, TEvent = never> = RegularToolConfig<TInput, TOutput> | GeneratorToolConfig<TInput, TOutput, TEvent> | ManualToolConfig<TInput, TOutput>;
|
|
41
|
+
export type InferToolInput<T> = T extends Tool<infer I, any, any> ? I : never;
|
|
42
|
+
export type InferToolOutput<T> = T extends Tool<any, infer O, any> ? O : never;
|
|
43
|
+
export type InferToolEvent<T> = T extends Tool<any, any, infer E> ? E : never;
|
|
44
|
+
export declare function tool<TInput, TOutput>(config: RegularToolConfig<TInput, TOutput>): Tool<TInput, TOutput, never>;
|
|
45
|
+
export declare function tool<TInput, TOutput, TEvent>(config: GeneratorToolConfig<TInput, TOutput, TEvent>): Tool<TInput, TOutput, TEvent>;
|
|
46
|
+
export declare function tool<TInput, TOutput>(config: ManualToolConfig<TInput, TOutput>): Tool<TInput, TOutput, never>;
|
|
47
|
+
export {};
|
package/dist/tool.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tool = tool;
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// tool() factory
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
function buildDefinition(config) {
|
|
8
|
+
let parameters;
|
|
9
|
+
if (config.jsonSchemaParameters) {
|
|
10
|
+
parameters = config.jsonSchemaParameters;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const jsonSchema = config.inputSchema.toJSONSchema?.();
|
|
14
|
+
const { $schema: _, ...rest } = jsonSchema ?? {};
|
|
15
|
+
parameters = rest;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
type: "function",
|
|
19
|
+
function: {
|
|
20
|
+
name: config.name,
|
|
21
|
+
description: config.description,
|
|
22
|
+
parameters,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function createTool(config) {
|
|
27
|
+
const resolvedType = config.execute === false
|
|
28
|
+
? "manual"
|
|
29
|
+
: config.eventSchema
|
|
30
|
+
? "generator"
|
|
31
|
+
: "regular";
|
|
32
|
+
return {
|
|
33
|
+
name: config.name,
|
|
34
|
+
description: config.description,
|
|
35
|
+
inputSchema: config.inputSchema,
|
|
36
|
+
outputSchema: config.outputSchema,
|
|
37
|
+
eventSchema: config
|
|
38
|
+
.eventSchema,
|
|
39
|
+
execute: config.execute,
|
|
40
|
+
type: resolvedType,
|
|
41
|
+
toDefinition() {
|
|
42
|
+
return buildDefinition(config);
|
|
43
|
+
},
|
|
44
|
+
parseInput(raw) {
|
|
45
|
+
return config.inputSchema.parse(raw);
|
|
46
|
+
},
|
|
47
|
+
implement(fn) {
|
|
48
|
+
return createTool({
|
|
49
|
+
name: config.name,
|
|
50
|
+
description: config.description,
|
|
51
|
+
inputSchema: config.inputSchema,
|
|
52
|
+
jsonSchemaParameters: config.jsonSchemaParameters,
|
|
53
|
+
execute: fn,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function tool(config) {
|
|
59
|
+
return createTool(config);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=tool.js.map
|
package/dist/tool.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":";;AAsKA,oBAIC;AAnFD,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,SAAS,eAAe,CAAC,MAKxB;IACC,IAAI,UAAmC,CAAC;IAExC,IAAI,MAAM,CAAC,oBAAoB,EAAE,CAAC;QAChC,UAAU,GAAG,MAAM,CAAC,oBAAoB,CAAC;IAC3C,CAAC;SAAM,CAAC;QACN,MAAM,UAAU,GAAI,MAAM,CAAC,WAAmB,CAAC,YAAY,EAAE,EAAE,CAAC;QAChE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,UAAU,IAAI,EAAE,CAAC;QACjD,UAAU,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,UAAU;SACX;KACF,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CACjB,MAA2C;IAE3C,MAAM,YAAY,GAChB,MAAM,CAAC,OAAO,KAAK,KAAK;QACtB,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,MAAM,CAAC,WAAW;YAClB,CAAC,CAAC,WAAW;YACb,CAAC,CAAC,SAAS,CAAC;IAElB,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,WAAW,EAAG,MAAuD;aAClE,WAAW;QACd,OAAO,EAAE,MAAM,CAAC,OAAc;QAC9B,IAAI,EAAE,YAAY;QAElB,YAAY;YACV,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;QACjC,CAAC;QAED,UAAU,CAAC,GAAY;YACrB,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC;QAED,SAAS,CAAc,EAA4B;YACjD,OAAO,UAAU,CAAY;gBAC3B,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,oBAAoB,EAAE,MAAM,CAAC,oBAAoB;gBACjD,OAAO,EAAE,EAAE;aACZ,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AAWD,SAAgB,IAAI,CAClB,MAA2C;IAE3C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export interface ExecuteSwapInput {
|
|
3
|
+
/** Symbol of the token being sold (e.g. SOL) */
|
|
4
|
+
inputTokenSymbol: string;
|
|
5
|
+
/** Contract address of the input token */
|
|
6
|
+
inputTokenCA?: string;
|
|
7
|
+
/** Contract address of the output token */
|
|
8
|
+
outputTokenCA?: string;
|
|
9
|
+
/** Absolute amount of input token to swap */
|
|
10
|
+
inputTokenAmount?: number;
|
|
11
|
+
/** Percentage of input token balance to swap (0.0–1.0) */
|
|
12
|
+
inputTokenPercentage?: number;
|
|
13
|
+
/** Minimum amount of output token expected */
|
|
14
|
+
outputTokenAmount?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const executeSwapInputSchema: z.ZodType<ExecuteSwapInput>;
|
|
17
|
+
export declare const EXECUTE_SWAP: import("../tool").Tool<ExecuteSwapInput, unknown, never>;
|