@leettools/core 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/LICENSE +201 -0
- package/README.md +33 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.d.ts +128 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +543 -0
- package/dist/llm.js.map +1 -0
- package/dist/mcp.d.ts +68 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +157 -0
- package/dist/mcp.js.map +1 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @leettools/core
|
|
2
|
+
|
|
3
|
+
Standalone client-side capabilities configured with explicit inputs. It depends only on
|
|
4
|
+
`@leettools/common` and does not know about the LeetTools backend or the `User`, `Org`,
|
|
5
|
+
and `KnowledgeBase` context.
|
|
6
|
+
|
|
7
|
+
## LLM routing
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { LlmApiCaller } from '@leettools/core/llm'
|
|
11
|
+
|
|
12
|
+
const llm = new LlmApiCaller([{
|
|
13
|
+
name: 'primary',
|
|
14
|
+
protocol: 'openai-compatible',
|
|
15
|
+
apiKey: process.env.LLM_API_KEY ?? '',
|
|
16
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
17
|
+
defaultModel: 'gpt-5-mini',
|
|
18
|
+
}])
|
|
19
|
+
|
|
20
|
+
const response = await llm.complete({
|
|
21
|
+
messages: [{ role: 'user', content: 'Summarize this document.' }],
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Built-in protocols are `openai-compatible`, `anthropic`, and `gemini`. Additional
|
|
26
|
+
provider protocols can be added with `registerAdapter` without changing callers.
|
|
27
|
+
|
|
28
|
+
## MCP
|
|
29
|
+
|
|
30
|
+
`@leettools/core/mcp` provides MCP initialization, tool discovery, invocation, local
|
|
31
|
+
tool registration, and Streamable HTTP transport.
|
|
32
|
+
|
|
33
|
+
Web search, scraping, and crawling live in `@leettools/web`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
|
package/dist/llm.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { type JsonObject } from '@leettools/common';
|
|
2
|
+
export declare const DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
3
|
+
export type LlmRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
4
|
+
export type LlmContentPart = {
|
|
5
|
+
type: 'text';
|
|
6
|
+
text: string;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'image';
|
|
9
|
+
url: string;
|
|
10
|
+
mediaType?: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'tool_call';
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
arguments: JsonObject;
|
|
16
|
+
} | {
|
|
17
|
+
type: 'tool_result';
|
|
18
|
+
toolCallId: string;
|
|
19
|
+
toolName: string;
|
|
20
|
+
content: string;
|
|
21
|
+
isError?: boolean;
|
|
22
|
+
};
|
|
23
|
+
export interface LlmMessage {
|
|
24
|
+
role: LlmRole;
|
|
25
|
+
content: string | LlmContentPart[];
|
|
26
|
+
}
|
|
27
|
+
export interface LlmTool {
|
|
28
|
+
name: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
inputSchema: JsonObject;
|
|
31
|
+
}
|
|
32
|
+
export type LlmResponseFormat = {
|
|
33
|
+
type: 'text';
|
|
34
|
+
} | {
|
|
35
|
+
type: 'json_object';
|
|
36
|
+
} | {
|
|
37
|
+
type: 'json_schema';
|
|
38
|
+
name: string;
|
|
39
|
+
schema: JsonObject;
|
|
40
|
+
strict?: boolean;
|
|
41
|
+
};
|
|
42
|
+
export interface LlmRequest {
|
|
43
|
+
provider?: string;
|
|
44
|
+
model?: string;
|
|
45
|
+
messages: LlmMessage[];
|
|
46
|
+
tools?: LlmTool[];
|
|
47
|
+
toolChoice?: 'auto' | 'required' | 'none' | {
|
|
48
|
+
name: string;
|
|
49
|
+
};
|
|
50
|
+
responseFormat?: LlmResponseFormat;
|
|
51
|
+
temperature?: number;
|
|
52
|
+
maxTokens?: number;
|
|
53
|
+
stop?: string[];
|
|
54
|
+
metadata?: JsonObject;
|
|
55
|
+
}
|
|
56
|
+
export interface LlmUsage {
|
|
57
|
+
inputTokens: number;
|
|
58
|
+
outputTokens: number;
|
|
59
|
+
totalTokens: number;
|
|
60
|
+
cachedInputTokens?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface LlmResponse {
|
|
63
|
+
id: string;
|
|
64
|
+
provider: string;
|
|
65
|
+
model: string;
|
|
66
|
+
message: LlmMessage;
|
|
67
|
+
finishReason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'error' | 'unknown';
|
|
68
|
+
usage: LlmUsage;
|
|
69
|
+
raw: unknown;
|
|
70
|
+
}
|
|
71
|
+
export type LlmProviderProtocol = 'openai-compatible' | 'anthropic' | 'gemini';
|
|
72
|
+
export interface LlmProviderConfig {
|
|
73
|
+
name: string;
|
|
74
|
+
protocol: LlmProviderProtocol;
|
|
75
|
+
apiKey: string;
|
|
76
|
+
baseUrl?: string;
|
|
77
|
+
defaultModel?: string;
|
|
78
|
+
headers?: Record<string, string>;
|
|
79
|
+
fetch?: typeof fetch;
|
|
80
|
+
}
|
|
81
|
+
export interface LlmProviderAdapter {
|
|
82
|
+
readonly protocol: LlmProviderProtocol;
|
|
83
|
+
complete(config: LlmProviderConfig, request: LlmRequest): Promise<LlmResponse>;
|
|
84
|
+
}
|
|
85
|
+
export declare class LlmApiError extends Error {
|
|
86
|
+
readonly provider: string;
|
|
87
|
+
readonly status?: number | undefined;
|
|
88
|
+
readonly detail?: unknown | undefined;
|
|
89
|
+
constructor(message: string, provider: string, status?: number | undefined, detail?: unknown | undefined);
|
|
90
|
+
}
|
|
91
|
+
export interface CreateApiClientOptions {
|
|
92
|
+
apiKey?: string | null;
|
|
93
|
+
baseUrl?: string | null;
|
|
94
|
+
providerName?: string;
|
|
95
|
+
defaultModel?: string;
|
|
96
|
+
env?: Record<string, string | undefined>;
|
|
97
|
+
fetch?: typeof fetch;
|
|
98
|
+
}
|
|
99
|
+
export declare function ensureProtocol(url: string): string;
|
|
100
|
+
export declare function resolveBaseUrl(baseUrl?: string | null, env?: Record<string, string | undefined>): string;
|
|
101
|
+
export declare function createApiClient(options?: CreateApiClientOptions): LlmApiCaller;
|
|
102
|
+
export declare function createAsyncApiClient(options?: CreateApiClientOptions): LlmApiCaller;
|
|
103
|
+
export declare function extractRepoPythonFilesFromStacktrace(trace: readonly string[], packageRoots?: readonly string[]): string[];
|
|
104
|
+
export declare function extractLeettoolsFilesFromStacktrace(trace: readonly string[]): string[];
|
|
105
|
+
export declare function getMimeType(filePath: string): string;
|
|
106
|
+
export declare class LlmApiCaller {
|
|
107
|
+
private readonly providers;
|
|
108
|
+
private readonly adapters;
|
|
109
|
+
constructor(configs?: LlmProviderConfig[], adapters?: LlmProviderAdapter[]);
|
|
110
|
+
registerProvider(config: LlmProviderConfig): this;
|
|
111
|
+
registerAdapter(adapter: LlmProviderAdapter): this;
|
|
112
|
+
hasProvider(name: string): boolean;
|
|
113
|
+
complete(request: LlmRequest): Promise<LlmResponse>;
|
|
114
|
+
private resolveProvider;
|
|
115
|
+
}
|
|
116
|
+
export declare class OpenAiCompatibleAdapter implements LlmProviderAdapter {
|
|
117
|
+
readonly protocol: "openai-compatible";
|
|
118
|
+
complete(config: LlmProviderConfig, request: LlmRequest): Promise<LlmResponse>;
|
|
119
|
+
}
|
|
120
|
+
export declare class AnthropicAdapter implements LlmProviderAdapter {
|
|
121
|
+
readonly protocol: "anthropic";
|
|
122
|
+
complete(config: LlmProviderConfig, request: LlmRequest): Promise<LlmResponse>;
|
|
123
|
+
}
|
|
124
|
+
export declare class GeminiAdapter implements LlmProviderAdapter {
|
|
125
|
+
readonly protocol: "gemini";
|
|
126
|
+
complete(config: LlmProviderConfig, request: LlmRequest): Promise<LlmResponse>;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=llm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,UAAU,EAAkB,MAAM,mBAAmB,CAAA;AAEtG,eAAO,MAAM,uBAAuB,8BAA8B,CAAA;AAElE,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAA;AAE9D,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,MAAM,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,EAAE,kBAAkB,GAAG,IAAI;IAKlD,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI5B,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;IAczD,OAAO,CAAC,eAAe;CAaxB;AAED,qBAAa,uBAAwB,YAAW,kBAAkB;IAChE,QAAQ,CAAC,QAAQ,EAAG,mBAAmB,CAAS;IAE1C,QAAQ,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;CAkErF;AAED,qBAAa,gBAAiB,YAAW,kBAAkB;IACzD,QAAQ,CAAC,QAAQ,EAAG,WAAW,CAAS;IAElC,QAAQ,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;CA8DrF;AAED,qBAAa,aAAc,YAAW,kBAAkB;IACtD,QAAQ,CAAC,QAAQ,EAAG,QAAQ,CAAS;IAE/B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;CA8ErF"}
|
package/dist/llm.js
ADDED
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import { UnexpectedCaseError, isJsonObject } from '@leettools/common';
|
|
2
|
+
export const DEFAULT_OPENAI_BASE_URL = 'https://api.openai.com/v1';
|
|
3
|
+
export class LlmApiError extends Error {
|
|
4
|
+
provider;
|
|
5
|
+
status;
|
|
6
|
+
detail;
|
|
7
|
+
constructor(message, provider, status, detail) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.provider = provider;
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.detail = detail;
|
|
12
|
+
this.name = 'LlmApiError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function ensureProtocol(url) {
|
|
16
|
+
const normalized = url.trim();
|
|
17
|
+
if (!normalized) {
|
|
18
|
+
return normalized;
|
|
19
|
+
}
|
|
20
|
+
return /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(normalized)
|
|
21
|
+
? normalized
|
|
22
|
+
: `https://${normalized}`;
|
|
23
|
+
}
|
|
24
|
+
export function resolveBaseUrl(baseUrl, env = process.env) {
|
|
25
|
+
const rawValue = baseUrl ?? env.EDS_LLM_BASE_URL;
|
|
26
|
+
const normalized = rawValue?.trim() ?? '';
|
|
27
|
+
return normalized ? ensureProtocol(normalized) : DEFAULT_OPENAI_BASE_URL;
|
|
28
|
+
}
|
|
29
|
+
export function createApiClient(options = {}) {
|
|
30
|
+
const env = options.env ?? process.env;
|
|
31
|
+
const apiKey = options.apiKey ?? env.EDS_LLM_API_KEY;
|
|
32
|
+
if (!apiKey) {
|
|
33
|
+
throw new Error('No API key provided and EDS_LLM_API_KEY environment variable not set');
|
|
34
|
+
}
|
|
35
|
+
return new LlmApiCaller([
|
|
36
|
+
{
|
|
37
|
+
name: options.providerName ?? 'openai-compatible',
|
|
38
|
+
protocol: 'openai-compatible',
|
|
39
|
+
apiKey,
|
|
40
|
+
baseUrl: resolveBaseUrl(options.baseUrl, env),
|
|
41
|
+
defaultModel: options.defaultModel,
|
|
42
|
+
fetch: options.fetch,
|
|
43
|
+
},
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
export function createAsyncApiClient(options = {}) {
|
|
47
|
+
return createApiClient(options);
|
|
48
|
+
}
|
|
49
|
+
export function extractRepoPythonFilesFromStacktrace(trace, packageRoots = ['leettools', '/tests/']) {
|
|
50
|
+
const repoFiles = [];
|
|
51
|
+
for (const line of trace) {
|
|
52
|
+
const match = /File "([^"]+\.py)"/.exec(line);
|
|
53
|
+
if (match && packageRoots.some((root) => match[1].includes(root))) {
|
|
54
|
+
repoFiles.push(match[1]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return repoFiles;
|
|
58
|
+
}
|
|
59
|
+
export function extractLeettoolsFilesFromStacktrace(trace) {
|
|
60
|
+
return extractRepoPythonFilesFromStacktrace(trace);
|
|
61
|
+
}
|
|
62
|
+
const SUPPORTED_MIME_TYPES = {
|
|
63
|
+
'.pdf': 'application/pdf',
|
|
64
|
+
'.txt': 'text/plain',
|
|
65
|
+
'.md': 'text/markdown',
|
|
66
|
+
'.doc': 'application/msword',
|
|
67
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
68
|
+
};
|
|
69
|
+
export function getMimeType(filePath) {
|
|
70
|
+
const extension = /\.[^./\\]+$/.exec(filePath)?.[0].toLowerCase() ?? '';
|
|
71
|
+
const mimeType = SUPPORTED_MIME_TYPES[extension];
|
|
72
|
+
if (!mimeType) {
|
|
73
|
+
throw new UnexpectedCaseError(`Unsupported file type: ${extension}. Supported file types are: ${Object.keys(SUPPORTED_MIME_TYPES).join(', ')}`);
|
|
74
|
+
}
|
|
75
|
+
return mimeType;
|
|
76
|
+
}
|
|
77
|
+
export class LlmApiCaller {
|
|
78
|
+
providers = new Map();
|
|
79
|
+
adapters = new Map();
|
|
80
|
+
constructor(configs = [], adapters = []) {
|
|
81
|
+
for (const adapter of [
|
|
82
|
+
new OpenAiCompatibleAdapter(),
|
|
83
|
+
new AnthropicAdapter(),
|
|
84
|
+
new GeminiAdapter(),
|
|
85
|
+
...adapters,
|
|
86
|
+
]) {
|
|
87
|
+
this.adapters.set(adapter.protocol, adapter);
|
|
88
|
+
}
|
|
89
|
+
for (const config of configs) {
|
|
90
|
+
this.registerProvider(config);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
registerProvider(config) {
|
|
94
|
+
const name = config.name.trim();
|
|
95
|
+
if (!name) {
|
|
96
|
+
throw new TypeError('LLM provider name must not be empty');
|
|
97
|
+
}
|
|
98
|
+
if (!this.adapters.has(config.protocol)) {
|
|
99
|
+
throw new TypeError(`No adapter is registered for LLM protocol '${config.protocol}'`);
|
|
100
|
+
}
|
|
101
|
+
this.providers.set(name, { ...config, name });
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
registerAdapter(adapter) {
|
|
105
|
+
this.adapters.set(adapter.protocol, adapter);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
hasProvider(name) {
|
|
109
|
+
return this.providers.has(name);
|
|
110
|
+
}
|
|
111
|
+
async complete(request) {
|
|
112
|
+
validateRequest(request);
|
|
113
|
+
const config = this.resolveProvider(request.provider);
|
|
114
|
+
const model = request.model || config.defaultModel;
|
|
115
|
+
if (!model) {
|
|
116
|
+
throw new TypeError(`No model was supplied for LLM provider '${config.name}'`);
|
|
117
|
+
}
|
|
118
|
+
const adapter = this.adapters.get(config.protocol);
|
|
119
|
+
if (!adapter) {
|
|
120
|
+
throw new TypeError(`No adapter is registered for LLM protocol '${config.protocol}'`);
|
|
121
|
+
}
|
|
122
|
+
return adapter.complete(config, { ...request, provider: config.name, model });
|
|
123
|
+
}
|
|
124
|
+
resolveProvider(name) {
|
|
125
|
+
if (name) {
|
|
126
|
+
const config = this.providers.get(name);
|
|
127
|
+
if (!config) {
|
|
128
|
+
throw new TypeError(`Unknown LLM provider '${name}'`);
|
|
129
|
+
}
|
|
130
|
+
return config;
|
|
131
|
+
}
|
|
132
|
+
if (this.providers.size !== 1) {
|
|
133
|
+
throw new TypeError('provider is required when more than one LLM provider is configured');
|
|
134
|
+
}
|
|
135
|
+
return this.providers.values().next().value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export class OpenAiCompatibleAdapter {
|
|
139
|
+
protocol = 'openai-compatible';
|
|
140
|
+
async complete(config, request) {
|
|
141
|
+
const body = {
|
|
142
|
+
model: requiredModel(request),
|
|
143
|
+
messages: request.messages.map(toOpenAiMessage),
|
|
144
|
+
};
|
|
145
|
+
setOptional(body, 'temperature', request.temperature);
|
|
146
|
+
setOptional(body, 'max_tokens', request.maxTokens);
|
|
147
|
+
setOptional(body, 'stop', request.stop);
|
|
148
|
+
if (request.tools?.length) {
|
|
149
|
+
body.tools = request.tools.map((tool) => ({
|
|
150
|
+
type: 'function',
|
|
151
|
+
function: {
|
|
152
|
+
name: tool.name,
|
|
153
|
+
description: tool.description ?? '',
|
|
154
|
+
parameters: tool.inputSchema,
|
|
155
|
+
},
|
|
156
|
+
}));
|
|
157
|
+
body.tool_choice = toOpenAiToolChoice(request.toolChoice);
|
|
158
|
+
}
|
|
159
|
+
if (request.responseFormat && request.responseFormat.type !== 'text') {
|
|
160
|
+
body.response_format = request.responseFormat.type === 'json_object'
|
|
161
|
+
? { type: 'json_object' }
|
|
162
|
+
: {
|
|
163
|
+
type: 'json_schema',
|
|
164
|
+
json_schema: {
|
|
165
|
+
name: request.responseFormat.name,
|
|
166
|
+
schema: request.responseFormat.schema,
|
|
167
|
+
strict: request.responseFormat.strict ?? true,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const raw = await postJson(endpoint(config.baseUrl, 'https://api.openai.com/v1', 'chat/completions'), body, bearerHeaders(config), config.name, config.fetch);
|
|
172
|
+
const choice = objectAt(arrayAt(raw, 'choices'), 0);
|
|
173
|
+
const message = objectAt(choice, 'message');
|
|
174
|
+
const content = [];
|
|
175
|
+
const text = stringAt(message, 'content', '');
|
|
176
|
+
if (text) {
|
|
177
|
+
content.push({ type: 'text', text });
|
|
178
|
+
}
|
|
179
|
+
for (const item of arrayAt(message, 'tool_calls', [])) {
|
|
180
|
+
if (!isJsonObject(item))
|
|
181
|
+
continue;
|
|
182
|
+
const fn = objectAt(item, 'function');
|
|
183
|
+
content.push({
|
|
184
|
+
type: 'tool_call',
|
|
185
|
+
id: stringAt(item, 'id'),
|
|
186
|
+
name: stringAt(fn, 'name'),
|
|
187
|
+
arguments: parseArguments(stringAt(fn, 'arguments', '{}')),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
id: stringAt(raw, 'id'),
|
|
192
|
+
provider: config.name,
|
|
193
|
+
model: stringAt(raw, 'model', requiredModel(request)),
|
|
194
|
+
message: { role: 'assistant', content: content.length === 1 && content[0]?.type === 'text' ? text : content },
|
|
195
|
+
finishReason: normalizeFinishReason(stringAt(choice, 'finish_reason', 'unknown')),
|
|
196
|
+
usage: openAiUsage(objectAt(raw, 'usage', {})),
|
|
197
|
+
raw,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
export class AnthropicAdapter {
|
|
202
|
+
protocol = 'anthropic';
|
|
203
|
+
async complete(config, request) {
|
|
204
|
+
const system = request.messages
|
|
205
|
+
.filter((message) => message.role === 'system')
|
|
206
|
+
.map(messageText)
|
|
207
|
+
.join('\n\n');
|
|
208
|
+
const body = {
|
|
209
|
+
model: requiredModel(request),
|
|
210
|
+
max_tokens: request.maxTokens ?? 4096,
|
|
211
|
+
messages: request.messages
|
|
212
|
+
.filter((message) => message.role !== 'system')
|
|
213
|
+
.map(toAnthropicMessage),
|
|
214
|
+
};
|
|
215
|
+
setOptional(body, 'system', system || undefined);
|
|
216
|
+
setOptional(body, 'temperature', request.temperature);
|
|
217
|
+
setOptional(body, 'stop_sequences', request.stop);
|
|
218
|
+
if (request.tools?.length) {
|
|
219
|
+
body.tools = request.tools.map((tool) => ({
|
|
220
|
+
name: tool.name,
|
|
221
|
+
description: tool.description ?? '',
|
|
222
|
+
input_schema: tool.inputSchema,
|
|
223
|
+
}));
|
|
224
|
+
body.tool_choice = toAnthropicToolChoice(request.toolChoice);
|
|
225
|
+
}
|
|
226
|
+
const raw = await postJson(endpoint(config.baseUrl, 'https://api.anthropic.com/v1', 'messages'), body, {
|
|
227
|
+
'x-api-key': config.apiKey,
|
|
228
|
+
'anthropic-version': '2023-06-01',
|
|
229
|
+
...config.headers,
|
|
230
|
+
}, config.name, config.fetch);
|
|
231
|
+
const content = [];
|
|
232
|
+
for (const item of arrayAt(raw, 'content', [])) {
|
|
233
|
+
if (!isJsonObject(item))
|
|
234
|
+
continue;
|
|
235
|
+
if (item.type === 'text') {
|
|
236
|
+
content.push({ type: 'text', text: stringAt(item, 'text') });
|
|
237
|
+
}
|
|
238
|
+
else if (item.type === 'tool_use') {
|
|
239
|
+
content.push({
|
|
240
|
+
type: 'tool_call',
|
|
241
|
+
id: stringAt(item, 'id'),
|
|
242
|
+
name: stringAt(item, 'name'),
|
|
243
|
+
arguments: objectAt(item, 'input', {}),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const usage = objectAt(raw, 'usage', {});
|
|
248
|
+
const inputTokens = numberAt(usage, 'input_tokens');
|
|
249
|
+
const outputTokens = numberAt(usage, 'output_tokens');
|
|
250
|
+
return {
|
|
251
|
+
id: stringAt(raw, 'id'),
|
|
252
|
+
provider: config.name,
|
|
253
|
+
model: stringAt(raw, 'model', requiredModel(request)),
|
|
254
|
+
message: { role: 'assistant', content },
|
|
255
|
+
finishReason: normalizeFinishReason(stringAt(raw, 'stop_reason', 'unknown')),
|
|
256
|
+
usage: { inputTokens, outputTokens, totalTokens: inputTokens + outputTokens },
|
|
257
|
+
raw,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
export class GeminiAdapter {
|
|
262
|
+
protocol = 'gemini';
|
|
263
|
+
async complete(config, request) {
|
|
264
|
+
const model = requiredModel(request);
|
|
265
|
+
const systemText = request.messages
|
|
266
|
+
.filter((message) => message.role === 'system')
|
|
267
|
+
.map(messageText)
|
|
268
|
+
.join('\n\n');
|
|
269
|
+
const body = {
|
|
270
|
+
contents: request.messages
|
|
271
|
+
.filter((message) => message.role !== 'system')
|
|
272
|
+
.map(toGeminiContent),
|
|
273
|
+
};
|
|
274
|
+
if (systemText) {
|
|
275
|
+
body.systemInstruction = { parts: [{ text: systemText }] };
|
|
276
|
+
}
|
|
277
|
+
const generationConfig = {};
|
|
278
|
+
setOptional(generationConfig, 'temperature', request.temperature);
|
|
279
|
+
setOptional(generationConfig, 'maxOutputTokens', request.maxTokens);
|
|
280
|
+
setOptional(generationConfig, 'stopSequences', request.stop);
|
|
281
|
+
if (request.responseFormat?.type === 'json_object') {
|
|
282
|
+
generationConfig.responseMimeType = 'application/json';
|
|
283
|
+
}
|
|
284
|
+
else if (request.responseFormat?.type === 'json_schema') {
|
|
285
|
+
generationConfig.responseMimeType = 'application/json';
|
|
286
|
+
generationConfig.responseSchema = request.responseFormat.schema;
|
|
287
|
+
}
|
|
288
|
+
if (Object.keys(generationConfig).length) {
|
|
289
|
+
body.generationConfig = generationConfig;
|
|
290
|
+
}
|
|
291
|
+
if (request.tools?.length) {
|
|
292
|
+
body.tools = [{
|
|
293
|
+
functionDeclarations: request.tools.map((tool) => ({
|
|
294
|
+
name: tool.name,
|
|
295
|
+
description: tool.description ?? '',
|
|
296
|
+
parameters: tool.inputSchema,
|
|
297
|
+
})),
|
|
298
|
+
}];
|
|
299
|
+
}
|
|
300
|
+
const baseUrl = (config.baseUrl || 'https://generativelanguage.googleapis.com/v1beta').replace(/\/+$/, '');
|
|
301
|
+
const url = new URL(`${baseUrl}/models/${encodeURIComponent(model)}:generateContent`);
|
|
302
|
+
url.searchParams.set('key', config.apiKey);
|
|
303
|
+
const raw = await postJson(url.toString(), body, config.headers ?? {}, config.name, config.fetch);
|
|
304
|
+
const candidate = objectAt(arrayAt(raw, 'candidates'), 0);
|
|
305
|
+
const responseContent = objectAt(candidate, 'content');
|
|
306
|
+
const content = [];
|
|
307
|
+
// Gemini returns no call ids, so synthesize them. Index by call count rather than by overall
|
|
308
|
+
// part count, or interleaved text parts make the ids skip numbers (gemini-0, gemini-2, ...).
|
|
309
|
+
let toolCallCount = 0;
|
|
310
|
+
for (const part of arrayAt(responseContent, 'parts', [])) {
|
|
311
|
+
if (!isJsonObject(part))
|
|
312
|
+
continue;
|
|
313
|
+
if (typeof part.text === 'string') {
|
|
314
|
+
content.push({ type: 'text', text: part.text });
|
|
315
|
+
}
|
|
316
|
+
else if (isJsonObject(part.functionCall)) {
|
|
317
|
+
content.push({
|
|
318
|
+
type: 'tool_call',
|
|
319
|
+
id: `${config.name}-${toolCallCount++}`,
|
|
320
|
+
name: stringAt(part.functionCall, 'name'),
|
|
321
|
+
arguments: objectAt(part.functionCall, 'args', {}),
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const usage = objectAt(raw, 'usageMetadata', {});
|
|
326
|
+
const inputTokens = numberAt(usage, 'promptTokenCount');
|
|
327
|
+
const outputTokens = numberAt(usage, 'candidatesTokenCount');
|
|
328
|
+
return {
|
|
329
|
+
id: stringAt(raw, 'responseId', ''),
|
|
330
|
+
provider: config.name,
|
|
331
|
+
model,
|
|
332
|
+
message: { role: 'assistant', content },
|
|
333
|
+
finishReason: normalizeFinishReason(stringAt(candidate, 'finishReason', 'unknown')),
|
|
334
|
+
usage: {
|
|
335
|
+
inputTokens,
|
|
336
|
+
outputTokens,
|
|
337
|
+
totalTokens: numberAt(usage, 'totalTokenCount', inputTokens + outputTokens),
|
|
338
|
+
cachedInputTokens: numberAt(usage, 'cachedContentTokenCount') || undefined,
|
|
339
|
+
},
|
|
340
|
+
raw,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function validateRequest(request) {
|
|
345
|
+
if (!request.messages.length) {
|
|
346
|
+
throw new TypeError('At least one LLM message is required');
|
|
347
|
+
}
|
|
348
|
+
if (request.temperature !== undefined && (request.temperature < 0 || request.temperature > 2)) {
|
|
349
|
+
throw new RangeError('temperature must be between 0 and 2');
|
|
350
|
+
}
|
|
351
|
+
if (request.maxTokens !== undefined && request.maxTokens <= 0) {
|
|
352
|
+
throw new RangeError('maxTokens must be greater than zero');
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function requiredModel(request) {
|
|
356
|
+
if (!request.model)
|
|
357
|
+
throw new TypeError('LLM model is required');
|
|
358
|
+
return request.model;
|
|
359
|
+
}
|
|
360
|
+
function endpoint(baseUrl, fallback, path) {
|
|
361
|
+
return `${resolveBaseUrl(baseUrl || fallback).replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`;
|
|
362
|
+
}
|
|
363
|
+
function bearerHeaders(config) {
|
|
364
|
+
return { Authorization: `Bearer ${config.apiKey}`, ...config.headers };
|
|
365
|
+
}
|
|
366
|
+
async function postJson(url, body, headers, provider, fetcher = fetch) {
|
|
367
|
+
const response = await fetcher(url, {
|
|
368
|
+
method: 'POST',
|
|
369
|
+
headers: { 'content-type': 'application/json', ...headers },
|
|
370
|
+
body: JSON.stringify(body),
|
|
371
|
+
});
|
|
372
|
+
const text = await response.text();
|
|
373
|
+
let parsed = null;
|
|
374
|
+
if (text) {
|
|
375
|
+
try {
|
|
376
|
+
parsed = JSON.parse(text);
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
parsed = text;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (!response.ok) {
|
|
383
|
+
throw new LlmApiError(`LLM provider '${provider}' returned HTTP ${response.status}`, provider, response.status, parsed);
|
|
384
|
+
}
|
|
385
|
+
if (!isJsonObject(parsed)) {
|
|
386
|
+
throw new LlmApiError(`LLM provider '${provider}' returned an invalid response`, provider);
|
|
387
|
+
}
|
|
388
|
+
return parsed;
|
|
389
|
+
}
|
|
390
|
+
function setOptional(target, key, value) {
|
|
391
|
+
if (value !== undefined && (!Array.isArray(value) || value.length > 0)) {
|
|
392
|
+
target[key] = value;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function messageText(message) {
|
|
396
|
+
return typeof message.content === 'string'
|
|
397
|
+
? message.content
|
|
398
|
+
: message.content.filter((part) => part.type === 'text').map((part) => part.text).join('\n');
|
|
399
|
+
}
|
|
400
|
+
function toOpenAiMessage(message) {
|
|
401
|
+
if (typeof message.content === 'string') {
|
|
402
|
+
return { role: message.role, content: message.content };
|
|
403
|
+
}
|
|
404
|
+
const toolResult = message.content.find((part) => part.type === 'tool_result');
|
|
405
|
+
if (message.role === 'tool' && toolResult?.type === 'tool_result') {
|
|
406
|
+
return { role: 'tool', tool_call_id: toolResult.toolCallId, content: toolResult.content };
|
|
407
|
+
}
|
|
408
|
+
const content = message.content
|
|
409
|
+
.filter((part) => part.type === 'text' || part.type === 'image')
|
|
410
|
+
.map((part) => part.type === 'text'
|
|
411
|
+
? { type: 'text', text: part.text }
|
|
412
|
+
: { type: 'image_url', image_url: { url: part.url } });
|
|
413
|
+
const toolCalls = message.content
|
|
414
|
+
.filter((part) => part.type === 'tool_call')
|
|
415
|
+
.map((part) => part.type === 'tool_call' ? {
|
|
416
|
+
id: part.id,
|
|
417
|
+
type: 'function',
|
|
418
|
+
function: { name: part.name, arguments: JSON.stringify(part.arguments) },
|
|
419
|
+
} : null)
|
|
420
|
+
.filter((part) => part !== null);
|
|
421
|
+
const result = { role: message.role, content };
|
|
422
|
+
if (toolCalls.length)
|
|
423
|
+
result.tool_calls = toolCalls;
|
|
424
|
+
return result;
|
|
425
|
+
}
|
|
426
|
+
function toAnthropicMessage(message) {
|
|
427
|
+
const role = message.role === 'assistant' ? 'assistant' : 'user';
|
|
428
|
+
if (typeof message.content === 'string')
|
|
429
|
+
return { role, content: message.content };
|
|
430
|
+
const content = message.content.map((part) => {
|
|
431
|
+
if (part.type === 'text')
|
|
432
|
+
return { type: 'text', text: part.text };
|
|
433
|
+
if (part.type === 'tool_call')
|
|
434
|
+
return { type: 'tool_use', id: part.id, name: part.name, input: part.arguments };
|
|
435
|
+
if (part.type === 'tool_result') {
|
|
436
|
+
return { type: 'tool_result', tool_use_id: part.toolCallId, content: part.content, is_error: part.isError ?? false };
|
|
437
|
+
}
|
|
438
|
+
return { type: 'image', source: { type: 'url', url: part.url } };
|
|
439
|
+
});
|
|
440
|
+
return { role, content };
|
|
441
|
+
}
|
|
442
|
+
// Gemini associates a functionResponse with its call by function name, not by call id -- it
|
|
443
|
+
// returns no call id at all, so the synthetic ids this adapter generates would never match a
|
|
444
|
+
// declared function. LlmContentPart requires toolName precisely so this stays a lookup-free map.
|
|
445
|
+
function toGeminiContent(message) {
|
|
446
|
+
const role = message.role === 'assistant' ? 'model' : 'user';
|
|
447
|
+
if (typeof message.content === 'string')
|
|
448
|
+
return { role, parts: [{ text: message.content }] };
|
|
449
|
+
const parts = message.content.map((part) => {
|
|
450
|
+
if (part.type === 'text')
|
|
451
|
+
return { text: part.text };
|
|
452
|
+
if (part.type === 'tool_call')
|
|
453
|
+
return { functionCall: { name: part.name, args: part.arguments } };
|
|
454
|
+
if (part.type === 'tool_result') {
|
|
455
|
+
// Guard for JavaScript callers, who get no compile-time check on the required field. A
|
|
456
|
+
// missing name would otherwise surface as an opaque rejection from the Gemini API.
|
|
457
|
+
if (!part.toolName) {
|
|
458
|
+
throw new TypeError(`tool_result '${part.toolCallId}' is missing toolName, required for Gemini`);
|
|
459
|
+
}
|
|
460
|
+
return { functionResponse: { name: part.toolName, response: { content: part.content } } };
|
|
461
|
+
}
|
|
462
|
+
return { fileData: { mimeType: part.mediaType ?? 'image/*', fileUri: part.url } };
|
|
463
|
+
});
|
|
464
|
+
return { role, parts };
|
|
465
|
+
}
|
|
466
|
+
function toOpenAiToolChoice(choice) {
|
|
467
|
+
if (!choice)
|
|
468
|
+
return 'auto';
|
|
469
|
+
return typeof choice === 'string'
|
|
470
|
+
? choice
|
|
471
|
+
: { type: 'function', function: { name: choice.name } };
|
|
472
|
+
}
|
|
473
|
+
function toAnthropicToolChoice(choice) {
|
|
474
|
+
if (!choice || choice === 'auto')
|
|
475
|
+
return { type: 'auto' };
|
|
476
|
+
if (choice === 'required')
|
|
477
|
+
return { type: 'any' };
|
|
478
|
+
if (choice === 'none')
|
|
479
|
+
return { type: 'none' };
|
|
480
|
+
return { type: 'tool', name: choice.name };
|
|
481
|
+
}
|
|
482
|
+
function parseArguments(value) {
|
|
483
|
+
try {
|
|
484
|
+
const parsed = JSON.parse(value);
|
|
485
|
+
return isJsonObject(parsed) ? parsed : {};
|
|
486
|
+
}
|
|
487
|
+
catch {
|
|
488
|
+
return {};
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
function openAiUsage(usage) {
|
|
492
|
+
const inputTokens = numberAt(usage, 'prompt_tokens');
|
|
493
|
+
const outputTokens = numberAt(usage, 'completion_tokens');
|
|
494
|
+
return {
|
|
495
|
+
inputTokens,
|
|
496
|
+
outputTokens,
|
|
497
|
+
totalTokens: numberAt(usage, 'total_tokens', inputTokens + outputTokens),
|
|
498
|
+
cachedInputTokens: numberAt(objectAt(usage, 'prompt_tokens_details', {}), 'cached_tokens') || undefined,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
function normalizeFinishReason(value) {
|
|
502
|
+
const normalized = value.toLowerCase();
|
|
503
|
+
if (['stop', 'end_turn'].includes(normalized))
|
|
504
|
+
return 'stop';
|
|
505
|
+
if (['length', 'max_tokens', 'max_tokens_exceeded'].includes(normalized))
|
|
506
|
+
return 'length';
|
|
507
|
+
if (['tool_calls', 'tool_use'].includes(normalized))
|
|
508
|
+
return 'tool_calls';
|
|
509
|
+
if (['content_filter', 'safety', 'recitation', 'blocked'].includes(normalized))
|
|
510
|
+
return 'content_filter';
|
|
511
|
+
return 'unknown';
|
|
512
|
+
}
|
|
513
|
+
function objectAt(value, key, fallback) {
|
|
514
|
+
const child = typeof key === 'number'
|
|
515
|
+
? (Array.isArray(value) ? value[key] : undefined)
|
|
516
|
+
: (isJsonObject(value) ? value[key] : undefined);
|
|
517
|
+
if (isJsonObject(child))
|
|
518
|
+
return child;
|
|
519
|
+
if (fallback)
|
|
520
|
+
return fallback;
|
|
521
|
+
throw new LlmApiError(`Missing object field '${String(key)}' in LLM response`, 'unknown');
|
|
522
|
+
}
|
|
523
|
+
function arrayAt(value, key, fallback) {
|
|
524
|
+
const child = isJsonObject(value) ? value[key] : undefined;
|
|
525
|
+
if (Array.isArray(child))
|
|
526
|
+
return child;
|
|
527
|
+
if (fallback)
|
|
528
|
+
return fallback;
|
|
529
|
+
throw new LlmApiError(`Missing array field '${key}' in LLM response`, 'unknown');
|
|
530
|
+
}
|
|
531
|
+
function stringAt(value, key, fallback) {
|
|
532
|
+
const child = isJsonObject(value) ? value[key] : undefined;
|
|
533
|
+
if (typeof child === 'string')
|
|
534
|
+
return child;
|
|
535
|
+
if (fallback !== undefined)
|
|
536
|
+
return fallback;
|
|
537
|
+
throw new LlmApiError(`Missing string field '${key}' in LLM response`, 'unknown');
|
|
538
|
+
}
|
|
539
|
+
function numberAt(value, key, fallback = 0) {
|
|
540
|
+
const child = isJsonObject(value) ? value[key] : undefined;
|
|
541
|
+
return typeof child === 'number' && Number.isFinite(child) ? child : fallback;
|
|
542
|
+
}
|
|
543
|
+
//# sourceMappingURL=llm.js.map
|
package/dist/llm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAmC,MAAM,mBAAmB,CAAA;AAEtG,MAAM,CAAC,MAAM,uBAAuB,GAAG,2BAA2B,CAAA;AA+ElE,MAAM,OAAO,WAAY,SAAQ,KAAK;IAGzB;IACA;IACA;IAJX,YACE,OAAe,EACN,QAAgB,EAChB,MAAe,EACf,MAAgB;QAEzB,KAAK,CAAC,OAAO,CAAC,CAAA;QAJL,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAS;QACf,WAAM,GAAN,MAAM,CAAU;QAGzB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF;AAWD,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,EAAE,CAAA;IAC7B,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,UAAU,CAAA;IACnB,CAAC;IACD,OAAO,+BAA+B,CAAC,IAAI,CAAC,UAAU,CAAC;QACrD,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,WAAW,UAAU,EAAE,CAAA;AAC7B,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,OAAuB,EACvB,MAA0C,OAAO,CAAC,GAAG;IAErD,MAAM,QAAQ,GAAG,OAAO,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CAAC;AAED,SAAS,QAAQ,CAAC,KAAc,EAAE,GAAW,EAAE,QAAQ,GAAG,CAAC;IACzD,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC1D,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAA;AAC/E,CAAC"}
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type JsonObject, type JsonValue } from '@leettools/common';
|
|
2
|
+
export interface McpTool {
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
inputSchema: JsonObject;
|
|
6
|
+
annotations?: JsonObject;
|
|
7
|
+
}
|
|
8
|
+
export type McpContent = {
|
|
9
|
+
type: 'text';
|
|
10
|
+
text: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'image';
|
|
13
|
+
data: string;
|
|
14
|
+
mimeType: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'audio';
|
|
17
|
+
data: string;
|
|
18
|
+
mimeType: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'resource';
|
|
21
|
+
resource: JsonObject;
|
|
22
|
+
};
|
|
23
|
+
export interface McpToolResult {
|
|
24
|
+
content: McpContent[];
|
|
25
|
+
isError?: boolean;
|
|
26
|
+
structuredContent?: JsonObject;
|
|
27
|
+
}
|
|
28
|
+
export interface McpTransport {
|
|
29
|
+
request(method: string, params?: JsonObject): Promise<JsonValue>;
|
|
30
|
+
close?(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export interface McpClientOptions {
|
|
33
|
+
name?: string;
|
|
34
|
+
version?: string;
|
|
35
|
+
protocolVersion?: string;
|
|
36
|
+
capabilities?: JsonObject;
|
|
37
|
+
}
|
|
38
|
+
export type LocalMcpToolHandler = (arguments_: JsonObject) => Promise<McpToolResult> | McpToolResult;
|
|
39
|
+
export declare class McpClient {
|
|
40
|
+
private readonly transport;
|
|
41
|
+
private readonly options;
|
|
42
|
+
private initialized;
|
|
43
|
+
private toolCache;
|
|
44
|
+
private readonly localTools;
|
|
45
|
+
constructor(transport: McpTransport, options?: McpClientOptions);
|
|
46
|
+
registerTool(definition: McpTool, handler: LocalMcpToolHandler): this;
|
|
47
|
+
listTools(options?: {
|
|
48
|
+
refresh?: boolean;
|
|
49
|
+
}): Promise<McpTool[]>;
|
|
50
|
+
callTool(name: string, arguments_?: JsonObject): Promise<McpToolResult>;
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
private ensureInitialized;
|
|
53
|
+
}
|
|
54
|
+
export interface StreamableHttpMcpTransportOptions {
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
fetch?: typeof fetch;
|
|
57
|
+
}
|
|
58
|
+
export declare class StreamableHttpMcpTransport implements McpTransport {
|
|
59
|
+
private readonly endpoint;
|
|
60
|
+
private readonly options;
|
|
61
|
+
private requestId;
|
|
62
|
+
private sessionId;
|
|
63
|
+
private readonly fetcher;
|
|
64
|
+
constructor(endpoint: string, options?: StreamableHttpMcpTransportOptions);
|
|
65
|
+
request(method: string, params?: JsonObject): Promise<JsonValue>;
|
|
66
|
+
close(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAEjF,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,UAAU,CAAA;IACvB,WAAW,CAAC,EAAE,UAAU,CAAA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AY,EACvB,OAAO,GAAE,gBAAqB;IAGjD,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAM/D,SAAS,CAAC,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAclE,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,GAAE,UAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAS3E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAId,iBAAiB;CAahC;AAED,MAAM,WAAW,iCAAiC;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB;AAED,qBAAa,0BAA2B,YAAW,YAAY;IAM3D,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN1B,OAAO,CAAC,SAAS,CAAI;IACrB,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;gBAGnB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,iCAAsC;IAK5D,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IA4BhE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ7B"}
|
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { isJsonObject } from '@leettools/common';
|
|
2
|
+
export class McpClient {
|
|
3
|
+
transport;
|
|
4
|
+
options;
|
|
5
|
+
initialized = false;
|
|
6
|
+
toolCache = null;
|
|
7
|
+
localTools = new Map();
|
|
8
|
+
constructor(transport, options = {}) {
|
|
9
|
+
this.transport = transport;
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
registerTool(definition, handler) {
|
|
13
|
+
this.localTools.set(definition.name, { definition, handler });
|
|
14
|
+
this.toolCache = null;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
async listTools(options = {}) {
|
|
18
|
+
if (this.toolCache && !options.refresh)
|
|
19
|
+
return this.toolCache;
|
|
20
|
+
await this.ensureInitialized();
|
|
21
|
+
const result = await this.transport.request('tools/list');
|
|
22
|
+
const remoteTools = isJsonObject(result) && Array.isArray(result.tools)
|
|
23
|
+
? result.tools.map(parseTool).filter((tool) => tool !== null)
|
|
24
|
+
: [];
|
|
25
|
+
this.toolCache = [
|
|
26
|
+
...Array.from(this.localTools.values(), ({ definition }) => definition),
|
|
27
|
+
...remoteTools.filter((tool) => !this.localTools.has(tool.name)),
|
|
28
|
+
];
|
|
29
|
+
return this.toolCache;
|
|
30
|
+
}
|
|
31
|
+
async callTool(name, arguments_ = {}) {
|
|
32
|
+
const local = this.localTools.get(name);
|
|
33
|
+
if (local)
|
|
34
|
+
return local.handler(arguments_);
|
|
35
|
+
await this.ensureInitialized();
|
|
36
|
+
const result = await this.transport.request('tools/call', { name, arguments: arguments_ });
|
|
37
|
+
if (!isJsonObject(result))
|
|
38
|
+
throw new Error(`MCP tool '${name}' returned an invalid result`);
|
|
39
|
+
return parseToolResult(result);
|
|
40
|
+
}
|
|
41
|
+
async close() {
|
|
42
|
+
await this.transport.close?.();
|
|
43
|
+
}
|
|
44
|
+
async ensureInitialized() {
|
|
45
|
+
if (this.initialized)
|
|
46
|
+
return;
|
|
47
|
+
await this.transport.request('initialize', {
|
|
48
|
+
protocolVersion: this.options.protocolVersion ?? '2025-03-26',
|
|
49
|
+
capabilities: this.options.capabilities ?? {},
|
|
50
|
+
clientInfo: {
|
|
51
|
+
name: this.options.name ?? '@leettools/core',
|
|
52
|
+
version: this.options.version ?? '0.1.0',
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
await this.transport.request('notifications/initialized');
|
|
56
|
+
this.initialized = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class StreamableHttpMcpTransport {
|
|
60
|
+
endpoint;
|
|
61
|
+
options;
|
|
62
|
+
requestId = 0;
|
|
63
|
+
sessionId = null;
|
|
64
|
+
fetcher;
|
|
65
|
+
constructor(endpoint, options = {}) {
|
|
66
|
+
this.endpoint = endpoint;
|
|
67
|
+
this.options = options;
|
|
68
|
+
this.fetcher = options.fetch ?? fetch;
|
|
69
|
+
}
|
|
70
|
+
async request(method, params) {
|
|
71
|
+
const notification = method.startsWith('notifications/');
|
|
72
|
+
const payload = { jsonrpc: '2.0', method };
|
|
73
|
+
if (!notification)
|
|
74
|
+
payload.id = ++this.requestId;
|
|
75
|
+
if (params)
|
|
76
|
+
payload.params = params;
|
|
77
|
+
const response = await this.fetcher(this.endpoint, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: {
|
|
80
|
+
accept: 'application/json, text/event-stream',
|
|
81
|
+
'content-type': 'application/json',
|
|
82
|
+
...(this.sessionId ? { 'mcp-session-id': this.sessionId } : {}),
|
|
83
|
+
...this.options.headers,
|
|
84
|
+
},
|
|
85
|
+
body: JSON.stringify(payload),
|
|
86
|
+
});
|
|
87
|
+
this.sessionId = response.headers.get('mcp-session-id') ?? this.sessionId;
|
|
88
|
+
if (!response.ok)
|
|
89
|
+
throw new Error(`MCP transport returned HTTP ${response.status}: ${await response.text()}`);
|
|
90
|
+
if (notification || response.status === 202)
|
|
91
|
+
return null;
|
|
92
|
+
const text = await response.text();
|
|
93
|
+
const envelope = parseMcpEnvelope(text, response.headers.get('content-type'));
|
|
94
|
+
if (isJsonObject(envelope.error)) {
|
|
95
|
+
throw new Error(`MCP error ${String(envelope.error.code ?? '')}: ${String(envelope.error.message ?? 'Unknown error')}`);
|
|
96
|
+
}
|
|
97
|
+
return envelope.result ?? null;
|
|
98
|
+
}
|
|
99
|
+
async close() {
|
|
100
|
+
if (!this.sessionId)
|
|
101
|
+
return;
|
|
102
|
+
await this.fetcher(this.endpoint, {
|
|
103
|
+
method: 'DELETE',
|
|
104
|
+
headers: { 'mcp-session-id': this.sessionId, ...this.options.headers },
|
|
105
|
+
});
|
|
106
|
+
this.sessionId = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function parseMcpEnvelope(text, contentType) {
|
|
110
|
+
const payloadText = contentType?.includes('text/event-stream')
|
|
111
|
+
? text.split(/\r?\n/).filter((line) => line.startsWith('data:')).map((line) => line.slice(5).trim()).at(-1)
|
|
112
|
+
: text;
|
|
113
|
+
const value = JSON.parse(payloadText || '{}');
|
|
114
|
+
if (!isJsonObject(value))
|
|
115
|
+
throw new Error('MCP transport returned an invalid JSON-RPC envelope');
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
function parseTool(value) {
|
|
119
|
+
if (!isJsonObject(value) || typeof value.name !== 'string')
|
|
120
|
+
return null;
|
|
121
|
+
const inputSchema = isJsonObject(value.inputSchema)
|
|
122
|
+
? value.inputSchema
|
|
123
|
+
: isJsonObject(value.input_schema) ? value.input_schema : { type: 'object' };
|
|
124
|
+
return {
|
|
125
|
+
name: value.name,
|
|
126
|
+
description: typeof value.description === 'string' ? value.description : undefined,
|
|
127
|
+
inputSchema,
|
|
128
|
+
annotations: isJsonObject(value.annotations) ? value.annotations : undefined,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function parseToolResult(value) {
|
|
132
|
+
const content = [];
|
|
133
|
+
if (Array.isArray(value.content)) {
|
|
134
|
+
for (const item of value.content) {
|
|
135
|
+
if (!isJsonObject(item) || typeof item.type !== 'string')
|
|
136
|
+
continue;
|
|
137
|
+
if (item.type === 'text' && typeof item.text === 'string') {
|
|
138
|
+
content.push({ type: 'text', text: item.text });
|
|
139
|
+
}
|
|
140
|
+
else if (item.type === 'image' && typeof item.data === 'string' && typeof item.mimeType === 'string') {
|
|
141
|
+
content.push({ type: 'image', data: item.data, mimeType: item.mimeType });
|
|
142
|
+
}
|
|
143
|
+
else if (item.type === 'audio' && typeof item.data === 'string' && typeof item.mimeType === 'string') {
|
|
144
|
+
content.push({ type: 'audio', data: item.data, mimeType: item.mimeType });
|
|
145
|
+
}
|
|
146
|
+
else if (item.type === 'resource' && isJsonObject(item.resource)) {
|
|
147
|
+
content.push({ type: 'resource', resource: item.resource });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
content,
|
|
153
|
+
isError: typeof value.isError === 'boolean' ? value.isError : undefined,
|
|
154
|
+
structuredContent: isJsonObject(value.structuredContent) ? value.structuredContent : undefined,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=mcp.js.map
|
package/dist/mcp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAmC,MAAM,mBAAmB,CAAA;AAmCjF,MAAM,OAAO,SAAS;IAMD;IACA;IANX,WAAW,GAAG,KAAK,CAAA;IACnB,SAAS,GAAqB,IAAI,CAAA;IACzB,UAAU,GAAG,IAAI,GAAG,EAAiE,CAAA;IAEtG,YACmB,SAAuB,EACvB,UAA4B,EAAE;QAD9B,cAAS,GAAT,SAAS,CAAc;QACvB,YAAO,GAAP,OAAO,CAAuB;IAC9C,CAAC;IAEJ,YAAY,CAAC,UAAmB,EAAE,OAA4B;QAC5D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAA;QAC7D,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QACrB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,UAAiC,EAAE;QACjD,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC,SAAS,CAAA;QAC7D,MAAM,IAAI,CAAC,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AAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;YAC3E,CAAC;iBAAM,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBACvG,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;YAC3E,CAAC;iBAAM,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACnE,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;YAC7D,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO;QACL,OAAO;QACP,OAAO,EAAE,OAAO,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;QACvE,iBAAiB,EAAE,YAAY,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,SAAS;KAC/F,CAAA;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leettools/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Client-safe LeetTools domain contracts and request preparation.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./llm": {
|
|
14
|
+
"types": "./dist/llm.d.ts",
|
|
15
|
+
"import": "./dist/llm.js"
|
|
16
|
+
},
|
|
17
|
+
"./mcp": {
|
|
18
|
+
"types": "./dist/mcp.d.ts",
|
|
19
|
+
"import": "./dist/mcp.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@leettools/common": "0.1.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.json",
|
|
33
|
+
"clean": "rm -rf dist",
|
|
34
|
+
"test": "pnpm build && node --test test/*.test.mjs"
|
|
35
|
+
}
|
|
36
|
+
}
|