@warpllm/warpllm 0.1.3
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 +202 -0
- package/README.md +39 -0
- package/dist/client.d.ts +21 -0
- package/dist/client.js +60 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +88 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +16 -0
- package/dist/types.d.ts +164 -0
- package/dist/types.js +2 -0
- package/index.d.ts +10 -0
- package/index.js +592 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# warpllm
|
|
2
|
+
|
|
3
|
+
A warp-speed, robust AI gateway written for rust, node, and python applications - built for planet scale by the community.
|
|
4
|
+
|
|
5
|
+
[](https://discord.gg/tSSQTxFnsC)
|
|
6
|
+
[](https://www.reddit.com/r/warpllm/)
|
|
7
|
+
|
|
8
|
+
## Community
|
|
9
|
+
|
|
10
|
+
> [!IMPORTANT]
|
|
11
|
+
> **warpllm is community-led.**
|
|
12
|
+
>
|
|
13
|
+
> The roadmap, examples, integrations, and rough edges should be shaped in the open by the people building with it. Bring ideas, questions, provider requests, bug reports, benchmarks, and experiments.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
1. **Provider-agnostic API** - switch between different providers and models without having to learn a new integration.
|
|
18
|
+
1. [Coming Soon] **Failover** - define multiple models to handle outages / errors
|
|
19
|
+
1. [Coming Soon] **Load Balancing** - define a % of requests to be handled per model
|
|
20
|
+
1. [Coming Soon] **You decide** - post in discord or reddit! Drive the future of warpllm.
|
|
21
|
+
|
|
22
|
+
## Key focus points
|
|
23
|
+
|
|
24
|
+
1. **Native SDK support** - Written once in rust, compiled for maximum performance, available for rust/typescript/python.
|
|
25
|
+
1. **Self hostable** - Avoid vendor lock-in (e.g. from the cloud provider), or data leaving your infra.
|
|
26
|
+
1. **Warp-speed execution** - What we named ourselves after. Machine level code, faster than a typescript or python native library.
|
|
27
|
+
1. **Compact file size** - Pre-compiled into binary format, not verbose text files.
|
|
28
|
+
|
|
29
|
+
## Roadmap
|
|
30
|
+
|
|
31
|
+
Next up: streaming, more providers and endpoints, and pip/npm packages — then failover, load balancing, caching, and metrics. See the full [ROADMAP.md](https://github.com/warpllm/warpllm/blob/main/ROADMAP.md).
|
|
32
|
+
|
|
33
|
+
## Quickstart
|
|
34
|
+
|
|
35
|
+
In progress.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The warpllm core is open source under the [Apache License 2.0](https://github.com/warpllm/warpllm/blob/main/LICENSE).
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Client as NativeClient } from '../index.js';
|
|
2
|
+
import type { ChatCompletion, ChatCompletionCreateParams, WarpLLMOptions } from './types.js';
|
|
3
|
+
declare class Completions {
|
|
4
|
+
private readonly native;
|
|
5
|
+
constructor(native: NativeClient);
|
|
6
|
+
create(params: ChatCompletionCreateParams): Promise<ChatCompletion>;
|
|
7
|
+
}
|
|
8
|
+
declare class Chat {
|
|
9
|
+
readonly completions: Completions;
|
|
10
|
+
constructor(native: NativeClient);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Model strings are `provider/model`, e.g. `"openai/gpt-4o"`. API keys fall
|
|
14
|
+
* back to OPENAI_API_KEY; a provider's key is only required when a request
|
|
15
|
+
* targets that provider.
|
|
16
|
+
*/
|
|
17
|
+
export declare class WarpLLM {
|
|
18
|
+
readonly chat: Chat;
|
|
19
|
+
constructor(options?: WarpLLMOptions);
|
|
20
|
+
}
|
|
21
|
+
export {};
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WarpLLM = void 0;
|
|
4
|
+
const index_js_1 = require("../index.js");
|
|
5
|
+
const errors_js_1 = require("./errors.js");
|
|
6
|
+
class Completions {
|
|
7
|
+
native;
|
|
8
|
+
constructor(native) {
|
|
9
|
+
this.native = native;
|
|
10
|
+
}
|
|
11
|
+
async create(params) {
|
|
12
|
+
const request = {
|
|
13
|
+
model: params.model,
|
|
14
|
+
messages: params.messages,
|
|
15
|
+
temperature: params.temperature,
|
|
16
|
+
max_tokens: params.maxTokens,
|
|
17
|
+
top_p: params.topP,
|
|
18
|
+
stop: params.stop,
|
|
19
|
+
stream: params.stream || undefined,
|
|
20
|
+
};
|
|
21
|
+
let raw;
|
|
22
|
+
try {
|
|
23
|
+
raw = await this.native.chatCompletion(JSON.stringify(request));
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
(0, errors_js_1.throwFromWire)(err);
|
|
27
|
+
}
|
|
28
|
+
return JSON.parse(raw);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class Chat {
|
|
32
|
+
completions;
|
|
33
|
+
constructor(native) {
|
|
34
|
+
this.completions = new Completions(native);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Model strings are `provider/model`, e.g. `"openai/gpt-4o"`. API keys fall
|
|
39
|
+
* back to OPENAI_API_KEY; a provider's key is only required when a request
|
|
40
|
+
* targets that provider.
|
|
41
|
+
*/
|
|
42
|
+
class WarpLLM {
|
|
43
|
+
chat;
|
|
44
|
+
constructor(options = {}) {
|
|
45
|
+
const config = {
|
|
46
|
+
openai_api_key: options.openaiApiKey,
|
|
47
|
+
base_url: options.baseUrl,
|
|
48
|
+
timeout_secs: options.timeout,
|
|
49
|
+
};
|
|
50
|
+
let native;
|
|
51
|
+
try {
|
|
52
|
+
native = new index_js_1.Client(JSON.stringify(config));
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
(0, errors_js_1.throwFromWire)(err);
|
|
56
|
+
}
|
|
57
|
+
this.chat = new Chat(native);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.WarpLLM = WarpLLM;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class WarpLLMError extends Error {
|
|
2
|
+
/** Stable machine-readable slug, e.g. `"provider_error"`. */
|
|
3
|
+
code: string;
|
|
4
|
+
constructor(message: string, code?: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class InvalidRequestError extends WarpLLMError {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class APIConnectionError extends WarpLLMError {
|
|
10
|
+
provider?: string;
|
|
11
|
+
constructor(message: string, provider?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class APIStatusError extends WarpLLMError {
|
|
14
|
+
status?: number;
|
|
15
|
+
provider?: string;
|
|
16
|
+
errorType?: string;
|
|
17
|
+
constructor(message: string, opts?: {
|
|
18
|
+
status?: number;
|
|
19
|
+
provider?: string;
|
|
20
|
+
errorType?: string;
|
|
21
|
+
code?: string;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export declare class AuthenticationError extends APIStatusError {
|
|
25
|
+
}
|
|
26
|
+
export declare class RateLimitError extends APIStatusError {
|
|
27
|
+
}
|
|
28
|
+
export declare class NotImplementedError extends WarpLLMError {
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
/** Translates the native layer's wire-format JSON message into typed errors. */
|
|
32
|
+
export declare function throwFromWire(err: unknown): never;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotImplementedError = exports.RateLimitError = exports.AuthenticationError = exports.APIStatusError = exports.APIConnectionError = exports.InvalidRequestError = exports.WarpLLMError = void 0;
|
|
4
|
+
exports.throwFromWire = throwFromWire;
|
|
5
|
+
class WarpLLMError extends Error {
|
|
6
|
+
/** Stable machine-readable slug, e.g. `"provider_error"`. */
|
|
7
|
+
code;
|
|
8
|
+
constructor(message, code = 'error') {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = new.target.name;
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.WarpLLMError = WarpLLMError;
|
|
15
|
+
class InvalidRequestError extends WarpLLMError {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message, 'invalid_request');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.InvalidRequestError = InvalidRequestError;
|
|
21
|
+
class APIConnectionError extends WarpLLMError {
|
|
22
|
+
provider;
|
|
23
|
+
constructor(message, provider) {
|
|
24
|
+
super(message, 'connection_error');
|
|
25
|
+
this.provider = provider;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.APIConnectionError = APIConnectionError;
|
|
29
|
+
class APIStatusError extends WarpLLMError {
|
|
30
|
+
status;
|
|
31
|
+
provider;
|
|
32
|
+
errorType;
|
|
33
|
+
constructor(message, opts = {}) {
|
|
34
|
+
super(message, opts.code ?? 'provider_error');
|
|
35
|
+
this.status = opts.status;
|
|
36
|
+
this.provider = opts.provider;
|
|
37
|
+
this.errorType = opts.errorType;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.APIStatusError = APIStatusError;
|
|
41
|
+
class AuthenticationError extends APIStatusError {
|
|
42
|
+
}
|
|
43
|
+
exports.AuthenticationError = AuthenticationError;
|
|
44
|
+
class RateLimitError extends APIStatusError {
|
|
45
|
+
}
|
|
46
|
+
exports.RateLimitError = RateLimitError;
|
|
47
|
+
class NotImplementedError extends WarpLLMError {
|
|
48
|
+
constructor(message) {
|
|
49
|
+
super(message, 'not_implemented');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.NotImplementedError = NotImplementedError;
|
|
53
|
+
/** Translates the native layer's wire-format JSON message into typed errors. */
|
|
54
|
+
function throwFromWire(err) {
|
|
55
|
+
const raw = err instanceof Error ? err.message : String(err);
|
|
56
|
+
let wire;
|
|
57
|
+
try {
|
|
58
|
+
wire = JSON.parse(raw);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
throw new WarpLLMError(raw);
|
|
62
|
+
}
|
|
63
|
+
const message = wire.message ?? raw;
|
|
64
|
+
switch (wire.code) {
|
|
65
|
+
case 'not_implemented':
|
|
66
|
+
throw new NotImplementedError(message);
|
|
67
|
+
case 'invalid_request':
|
|
68
|
+
throw new InvalidRequestError(message);
|
|
69
|
+
case 'missing_api_key':
|
|
70
|
+
throw new AuthenticationError(message, { provider: wire.provider, code: wire.code });
|
|
71
|
+
case 'connection_error':
|
|
72
|
+
throw new APIConnectionError(message, wire.provider);
|
|
73
|
+
case 'provider_error': {
|
|
74
|
+
const opts = {
|
|
75
|
+
status: wire.status,
|
|
76
|
+
provider: wire.provider,
|
|
77
|
+
errorType: wire.error_type ?? undefined,
|
|
78
|
+
};
|
|
79
|
+
if (wire.status === 401)
|
|
80
|
+
throw new AuthenticationError(message, opts);
|
|
81
|
+
if (wire.status === 429)
|
|
82
|
+
throw new RateLimitError(message, opts);
|
|
83
|
+
throw new APIStatusError(message, opts);
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
throw new WarpLLMError(message, wire.code);
|
|
87
|
+
}
|
|
88
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { version, echo } from '../index.js';
|
|
2
|
+
export { WarpLLM } from './client.js';
|
|
3
|
+
export { APIConnectionError, APIStatusError, AuthenticationError, InvalidRequestError, NotImplementedError, RateLimitError, WarpLLMError, } from './errors.js';
|
|
4
|
+
export type { Annotation, AnnotationURLCitation, ChatCompletion, ChatCompletionAudio, ChatCompletionCreateParams, ChatCompletionMessage, ChatCompletionMessageCustomToolCall, ChatCompletionMessageFunctionToolCall, ChatCompletionMessageToolCall, ChatCompletionTokenLogprob, ChatMessage, Choice, ChoiceLogprobs, CompletionTokensDetails, CompletionUsage, Error, FunctionCall, Moderation, ModerationResult, ModerationResults, PromptTokensDetails, TopLogprob, WarpLLMOptions, } from './types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WarpLLMError = exports.RateLimitError = exports.NotImplementedError = exports.InvalidRequestError = exports.AuthenticationError = exports.APIStatusError = exports.APIConnectionError = exports.WarpLLM = exports.echo = exports.version = void 0;
|
|
4
|
+
var index_js_1 = require("../index.js");
|
|
5
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return index_js_1.version; } });
|
|
6
|
+
Object.defineProperty(exports, "echo", { enumerable: true, get: function () { return index_js_1.echo; } });
|
|
7
|
+
var client_js_1 = require("./client.js");
|
|
8
|
+
Object.defineProperty(exports, "WarpLLM", { enumerable: true, get: function () { return client_js_1.WarpLLM; } });
|
|
9
|
+
var errors_js_1 = require("./errors.js");
|
|
10
|
+
Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return errors_js_1.APIConnectionError; } });
|
|
11
|
+
Object.defineProperty(exports, "APIStatusError", { enumerable: true, get: function () { return errors_js_1.APIStatusError; } });
|
|
12
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
|
|
13
|
+
Object.defineProperty(exports, "InvalidRequestError", { enumerable: true, get: function () { return errors_js_1.InvalidRequestError; } });
|
|
14
|
+
Object.defineProperty(exports, "NotImplementedError", { enumerable: true, get: function () { return errors_js_1.NotImplementedError; } });
|
|
15
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
|
|
16
|
+
Object.defineProperty(exports, "WarpLLMError", { enumerable: true, get: function () { return errors_js_1.WarpLLMError; } });
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
export interface WarpLLMOptions {
|
|
2
|
+
/** Falls back to the OPENAI_API_KEY environment variable. */
|
|
3
|
+
openaiApiKey?: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
/** Request timeout in seconds (default 600, matching the OpenAI SDK). */
|
|
6
|
+
timeout?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ChatMessage {
|
|
9
|
+
role: 'system' | 'user' | 'assistant';
|
|
10
|
+
content: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ChatCompletionCreateParams {
|
|
13
|
+
/** `provider/model`, e.g. `"openai/gpt-4o"`. */
|
|
14
|
+
model: string;
|
|
15
|
+
messages: ChatMessage[];
|
|
16
|
+
temperature?: number;
|
|
17
|
+
maxTokens?: number;
|
|
18
|
+
topP?: number;
|
|
19
|
+
stop?: string[];
|
|
20
|
+
/** Not yet implemented; `true` rejects with code `not_implemented`. */
|
|
21
|
+
stream?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ChatCompletion {
|
|
24
|
+
id: string;
|
|
25
|
+
choices: Choice[];
|
|
26
|
+
created: number;
|
|
27
|
+
/** Echoes the caller-supplied `provider/model` string. */
|
|
28
|
+
model: string;
|
|
29
|
+
/** Always `"chat.completion"`. */
|
|
30
|
+
object: string;
|
|
31
|
+
moderation?: Moderation;
|
|
32
|
+
service_tier?: 'auto' | 'default' | 'flex' | 'scale' | 'priority';
|
|
33
|
+
/** Deprecated upstream but still returned; passed through as-is. */
|
|
34
|
+
system_fingerprint?: string;
|
|
35
|
+
usage?: CompletionUsage;
|
|
36
|
+
}
|
|
37
|
+
export interface Choice {
|
|
38
|
+
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
|
|
39
|
+
index: number;
|
|
40
|
+
/**
|
|
41
|
+
* Optional per the docs; some OpenAI-compatible backends emit an explicit
|
|
42
|
+
* `"logprobs": null`, which the gateway normalizes to absent.
|
|
43
|
+
*/
|
|
44
|
+
logprobs?: ChoiceLogprobs;
|
|
45
|
+
message: ChatCompletionMessage;
|
|
46
|
+
}
|
|
47
|
+
/** Both arrays are required and non-nullable when `logprobs` is present. */
|
|
48
|
+
export interface ChoiceLogprobs {
|
|
49
|
+
content: ChatCompletionTokenLogprob[];
|
|
50
|
+
refusal: ChatCompletionTokenLogprob[];
|
|
51
|
+
}
|
|
52
|
+
export interface ChatCompletionTokenLogprob {
|
|
53
|
+
token: string;
|
|
54
|
+
bytes: number[] | null;
|
|
55
|
+
logprob: number;
|
|
56
|
+
top_logprobs: TopLogprob[];
|
|
57
|
+
}
|
|
58
|
+
export interface TopLogprob {
|
|
59
|
+
token: string;
|
|
60
|
+
bytes: number[] | null;
|
|
61
|
+
logprob: number;
|
|
62
|
+
}
|
|
63
|
+
export interface ChatCompletionMessage {
|
|
64
|
+
content: string | null;
|
|
65
|
+
refusal: string | null;
|
|
66
|
+
role: 'assistant';
|
|
67
|
+
annotations?: Annotation[];
|
|
68
|
+
audio?: ChatCompletionAudio;
|
|
69
|
+
/** Deprecated upstream in favor of `tool_calls`. */
|
|
70
|
+
function_call?: FunctionCall;
|
|
71
|
+
tool_calls?: ChatCompletionMessageToolCall[];
|
|
72
|
+
}
|
|
73
|
+
export interface Annotation {
|
|
74
|
+
type: 'url_citation';
|
|
75
|
+
url_citation: AnnotationURLCitation;
|
|
76
|
+
}
|
|
77
|
+
export interface AnnotationURLCitation {
|
|
78
|
+
end_index: number;
|
|
79
|
+
start_index: number;
|
|
80
|
+
title: string;
|
|
81
|
+
url: string;
|
|
82
|
+
}
|
|
83
|
+
/** Deprecated upstream in favor of tool calls. */
|
|
84
|
+
export interface FunctionCall {
|
|
85
|
+
/** JSON-encoded arguments; model-generated, so may be invalid JSON. */
|
|
86
|
+
arguments: string;
|
|
87
|
+
name: string;
|
|
88
|
+
}
|
|
89
|
+
/** Union discriminated by `type`. */
|
|
90
|
+
export type ChatCompletionMessageToolCall = ChatCompletionMessageFunctionToolCall | ChatCompletionMessageCustomToolCall;
|
|
91
|
+
export interface ChatCompletionMessageFunctionToolCall {
|
|
92
|
+
id: string;
|
|
93
|
+
type: 'function';
|
|
94
|
+
function: {
|
|
95
|
+
/** JSON-encoded arguments; model-generated, so may be invalid JSON. */
|
|
96
|
+
arguments: string;
|
|
97
|
+
name: string;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export interface ChatCompletionMessageCustomToolCall {
|
|
101
|
+
id: string;
|
|
102
|
+
type: 'custom';
|
|
103
|
+
custom: {
|
|
104
|
+
input: string;
|
|
105
|
+
name: string;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export interface ChatCompletionAudio {
|
|
109
|
+
id: string;
|
|
110
|
+
/** Base64-encoded audio bytes. */
|
|
111
|
+
data: string;
|
|
112
|
+
expires_at: number;
|
|
113
|
+
transcript: string;
|
|
114
|
+
}
|
|
115
|
+
export interface CompletionUsage {
|
|
116
|
+
completion_tokens: number;
|
|
117
|
+
prompt_tokens: number;
|
|
118
|
+
total_tokens: number;
|
|
119
|
+
completion_tokens_details?: CompletionTokensDetails;
|
|
120
|
+
prompt_tokens_details?: PromptTokensDetails;
|
|
121
|
+
}
|
|
122
|
+
export interface CompletionTokensDetails {
|
|
123
|
+
accepted_prediction_tokens?: number;
|
|
124
|
+
audio_tokens?: number;
|
|
125
|
+
reasoning_tokens?: number;
|
|
126
|
+
rejected_prediction_tokens?: number;
|
|
127
|
+
}
|
|
128
|
+
export interface PromptTokensDetails {
|
|
129
|
+
audio_tokens?: number;
|
|
130
|
+
/** Unadjusted number of prompt tokens written to cache. */
|
|
131
|
+
cache_write_tokens?: number;
|
|
132
|
+
cached_tokens?: number;
|
|
133
|
+
}
|
|
134
|
+
/** Moderation results for the request input and the generated output. */
|
|
135
|
+
export interface Moderation {
|
|
136
|
+
input: ModerationResults | Error;
|
|
137
|
+
output: ModerationResults | Error;
|
|
138
|
+
}
|
|
139
|
+
export interface ModerationResults {
|
|
140
|
+
type: 'moderation_results';
|
|
141
|
+
model: string;
|
|
142
|
+
results: ModerationResult[];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* One verdict in `ModerationResults.results`. The docs leave this element
|
|
146
|
+
* object unnamed; named here after its `type` string.
|
|
147
|
+
*/
|
|
148
|
+
export interface ModerationResult {
|
|
149
|
+
categories: Record<string, boolean>;
|
|
150
|
+
category_applied_input_types: Record<string, string[]>;
|
|
151
|
+
category_scores: Record<string, number>;
|
|
152
|
+
flagged: boolean;
|
|
153
|
+
model: string;
|
|
154
|
+
type: 'moderation_result';
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Moderation error. Exact upstream name; it shadows the global `Error` type
|
|
158
|
+
* in this module and wherever it is imported unaliased.
|
|
159
|
+
*/
|
|
160
|
+
export interface Error {
|
|
161
|
+
type: 'error';
|
|
162
|
+
code: string;
|
|
163
|
+
message: string;
|
|
164
|
+
}
|
package/dist/types.js
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class Client {
|
|
4
|
+
constructor(configJson: string)
|
|
5
|
+
chatCompletion(requestJson: string): Promise<string>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare function echo(msg: string): Promise<string>
|
|
9
|
+
|
|
10
|
+
export declare function version(): string
|
package/index.js
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const { readFileSync } = require('fs')
|
|
7
|
+
let nativeBinding = null
|
|
8
|
+
const loadErrors = []
|
|
9
|
+
|
|
10
|
+
const isMusl = () => {
|
|
11
|
+
let musl = false
|
|
12
|
+
if (process.platform === 'linux') {
|
|
13
|
+
musl = isMuslFromFilesystem()
|
|
14
|
+
if (musl === null) {
|
|
15
|
+
musl = isMuslFromReport()
|
|
16
|
+
}
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromChildProcess()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return musl
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
25
|
+
|
|
26
|
+
const isMuslFromFilesystem = () => {
|
|
27
|
+
try {
|
|
28
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
29
|
+
} catch {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isMuslFromReport = () => {
|
|
35
|
+
let report = null
|
|
36
|
+
if (process.report && typeof process.report.getReport === 'function') {
|
|
37
|
+
process.report.excludeNetwork = true
|
|
38
|
+
report = process.report.getReport()
|
|
39
|
+
}
|
|
40
|
+
if (!report) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
47
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isMuslFromChildProcess = () => {
|
|
55
|
+
try {
|
|
56
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
57
|
+
} catch (e) {
|
|
58
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function requireNative() {
|
|
64
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
65
|
+
try {
|
|
66
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
loadErrors.push(err)
|
|
69
|
+
}
|
|
70
|
+
} else if (process.platform === 'android') {
|
|
71
|
+
if (process.arch === 'arm64') {
|
|
72
|
+
try {
|
|
73
|
+
return require('./warpllm.android-arm64.node')
|
|
74
|
+
} catch (e) {
|
|
75
|
+
loadErrors.push(e)
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const binding = require('@warpllm/warpllm-android-arm64')
|
|
79
|
+
const bindingPackageVersion = require('@warpllm/warpllm-android-arm64/package.json').version
|
|
80
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
|
+
}
|
|
83
|
+
return binding
|
|
84
|
+
} catch (e) {
|
|
85
|
+
loadErrors.push(e)
|
|
86
|
+
}
|
|
87
|
+
} else if (process.arch === 'arm') {
|
|
88
|
+
try {
|
|
89
|
+
return require('./warpllm.android-arm-eabi.node')
|
|
90
|
+
} catch (e) {
|
|
91
|
+
loadErrors.push(e)
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const binding = require('@warpllm/warpllm-android-arm-eabi')
|
|
95
|
+
const bindingPackageVersion = require('@warpllm/warpllm-android-arm-eabi/package.json').version
|
|
96
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
|
+
}
|
|
99
|
+
return binding
|
|
100
|
+
} catch (e) {
|
|
101
|
+
loadErrors.push(e)
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
105
|
+
}
|
|
106
|
+
} else if (process.platform === 'win32') {
|
|
107
|
+
if (process.arch === 'x64') {
|
|
108
|
+
if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
|
|
109
|
+
try {
|
|
110
|
+
return require('./warpllm.win32-x64-gnu.node')
|
|
111
|
+
} catch (e) {
|
|
112
|
+
loadErrors.push(e)
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const binding = require('@warpllm/warpllm-win32-x64-gnu')
|
|
116
|
+
const bindingPackageVersion = require('@warpllm/warpllm-win32-x64-gnu/package.json').version
|
|
117
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
|
+
}
|
|
120
|
+
return binding
|
|
121
|
+
} catch (e) {
|
|
122
|
+
loadErrors.push(e)
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
try {
|
|
126
|
+
return require('./warpllm.win32-x64-msvc.node')
|
|
127
|
+
} catch (e) {
|
|
128
|
+
loadErrors.push(e)
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const binding = require('@warpllm/warpllm-win32-x64-msvc')
|
|
132
|
+
const bindingPackageVersion = require('@warpllm/warpllm-win32-x64-msvc/package.json').version
|
|
133
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
|
+
}
|
|
136
|
+
return binding
|
|
137
|
+
} catch (e) {
|
|
138
|
+
loadErrors.push(e)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else if (process.arch === 'ia32') {
|
|
142
|
+
try {
|
|
143
|
+
return require('./warpllm.win32-ia32-msvc.node')
|
|
144
|
+
} catch (e) {
|
|
145
|
+
loadErrors.push(e)
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const binding = require('@warpllm/warpllm-win32-ia32-msvc')
|
|
149
|
+
const bindingPackageVersion = require('@warpllm/warpllm-win32-ia32-msvc/package.json').version
|
|
150
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
|
+
}
|
|
153
|
+
return binding
|
|
154
|
+
} catch (e) {
|
|
155
|
+
loadErrors.push(e)
|
|
156
|
+
}
|
|
157
|
+
} else if (process.arch === 'arm64') {
|
|
158
|
+
try {
|
|
159
|
+
return require('./warpllm.win32-arm64-msvc.node')
|
|
160
|
+
} catch (e) {
|
|
161
|
+
loadErrors.push(e)
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const binding = require('@warpllm/warpllm-win32-arm64-msvc')
|
|
165
|
+
const bindingPackageVersion = require('@warpllm/warpllm-win32-arm64-msvc/package.json').version
|
|
166
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
|
+
}
|
|
169
|
+
return binding
|
|
170
|
+
} catch (e) {
|
|
171
|
+
loadErrors.push(e)
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
175
|
+
}
|
|
176
|
+
} else if (process.platform === 'darwin') {
|
|
177
|
+
try {
|
|
178
|
+
return require('./warpllm.darwin-universal.node')
|
|
179
|
+
} catch (e) {
|
|
180
|
+
loadErrors.push(e)
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const binding = require('@warpllm/warpllm-darwin-universal')
|
|
184
|
+
const bindingPackageVersion = require('@warpllm/warpllm-darwin-universal/package.json').version
|
|
185
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
|
+
}
|
|
188
|
+
return binding
|
|
189
|
+
} catch (e) {
|
|
190
|
+
loadErrors.push(e)
|
|
191
|
+
}
|
|
192
|
+
if (process.arch === 'x64') {
|
|
193
|
+
try {
|
|
194
|
+
return require('./warpllm.darwin-x64.node')
|
|
195
|
+
} catch (e) {
|
|
196
|
+
loadErrors.push(e)
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const binding = require('@warpllm/warpllm-darwin-x64')
|
|
200
|
+
const bindingPackageVersion = require('@warpllm/warpllm-darwin-x64/package.json').version
|
|
201
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
|
+
}
|
|
204
|
+
return binding
|
|
205
|
+
} catch (e) {
|
|
206
|
+
loadErrors.push(e)
|
|
207
|
+
}
|
|
208
|
+
} else if (process.arch === 'arm64') {
|
|
209
|
+
try {
|
|
210
|
+
return require('./warpllm.darwin-arm64.node')
|
|
211
|
+
} catch (e) {
|
|
212
|
+
loadErrors.push(e)
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const binding = require('@warpllm/warpllm-darwin-arm64')
|
|
216
|
+
const bindingPackageVersion = require('@warpllm/warpllm-darwin-arm64/package.json').version
|
|
217
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
|
+
}
|
|
220
|
+
return binding
|
|
221
|
+
} catch (e) {
|
|
222
|
+
loadErrors.push(e)
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
226
|
+
}
|
|
227
|
+
} else if (process.platform === 'freebsd') {
|
|
228
|
+
if (process.arch === 'x64') {
|
|
229
|
+
try {
|
|
230
|
+
return require('./warpllm.freebsd-x64.node')
|
|
231
|
+
} catch (e) {
|
|
232
|
+
loadErrors.push(e)
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const binding = require('@warpllm/warpllm-freebsd-x64')
|
|
236
|
+
const bindingPackageVersion = require('@warpllm/warpllm-freebsd-x64/package.json').version
|
|
237
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
|
+
}
|
|
240
|
+
return binding
|
|
241
|
+
} catch (e) {
|
|
242
|
+
loadErrors.push(e)
|
|
243
|
+
}
|
|
244
|
+
} else if (process.arch === 'arm64') {
|
|
245
|
+
try {
|
|
246
|
+
return require('./warpllm.freebsd-arm64.node')
|
|
247
|
+
} catch (e) {
|
|
248
|
+
loadErrors.push(e)
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
const binding = require('@warpllm/warpllm-freebsd-arm64')
|
|
252
|
+
const bindingPackageVersion = require('@warpllm/warpllm-freebsd-arm64/package.json').version
|
|
253
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
|
+
}
|
|
256
|
+
return binding
|
|
257
|
+
} catch (e) {
|
|
258
|
+
loadErrors.push(e)
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
262
|
+
}
|
|
263
|
+
} else if (process.platform === 'linux') {
|
|
264
|
+
if (process.arch === 'x64') {
|
|
265
|
+
if (isMusl()) {
|
|
266
|
+
try {
|
|
267
|
+
return require('./warpllm.linux-x64-musl.node')
|
|
268
|
+
} catch (e) {
|
|
269
|
+
loadErrors.push(e)
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
const binding = require('@warpllm/warpllm-linux-x64-musl')
|
|
273
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-x64-musl/package.json').version
|
|
274
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
|
+
}
|
|
277
|
+
return binding
|
|
278
|
+
} catch (e) {
|
|
279
|
+
loadErrors.push(e)
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
try {
|
|
283
|
+
return require('./warpllm.linux-x64-gnu.node')
|
|
284
|
+
} catch (e) {
|
|
285
|
+
loadErrors.push(e)
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
const binding = require('@warpllm/warpllm-linux-x64-gnu')
|
|
289
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-x64-gnu/package.json').version
|
|
290
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
|
+
}
|
|
293
|
+
return binding
|
|
294
|
+
} catch (e) {
|
|
295
|
+
loadErrors.push(e)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} else if (process.arch === 'arm64') {
|
|
299
|
+
if (isMusl()) {
|
|
300
|
+
try {
|
|
301
|
+
return require('./warpllm.linux-arm64-musl.node')
|
|
302
|
+
} catch (e) {
|
|
303
|
+
loadErrors.push(e)
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const binding = require('@warpllm/warpllm-linux-arm64-musl')
|
|
307
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-arm64-musl/package.json').version
|
|
308
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
|
+
}
|
|
311
|
+
return binding
|
|
312
|
+
} catch (e) {
|
|
313
|
+
loadErrors.push(e)
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
try {
|
|
317
|
+
return require('./warpllm.linux-arm64-gnu.node')
|
|
318
|
+
} catch (e) {
|
|
319
|
+
loadErrors.push(e)
|
|
320
|
+
}
|
|
321
|
+
try {
|
|
322
|
+
const binding = require('@warpllm/warpllm-linux-arm64-gnu')
|
|
323
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-arm64-gnu/package.json').version
|
|
324
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
|
+
}
|
|
327
|
+
return binding
|
|
328
|
+
} catch (e) {
|
|
329
|
+
loadErrors.push(e)
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
} else if (process.arch === 'arm') {
|
|
333
|
+
if (isMusl()) {
|
|
334
|
+
try {
|
|
335
|
+
return require('./warpllm.linux-arm-musleabihf.node')
|
|
336
|
+
} catch (e) {
|
|
337
|
+
loadErrors.push(e)
|
|
338
|
+
}
|
|
339
|
+
try {
|
|
340
|
+
const binding = require('@warpllm/warpllm-linux-arm-musleabihf')
|
|
341
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-arm-musleabihf/package.json').version
|
|
342
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
|
+
}
|
|
345
|
+
return binding
|
|
346
|
+
} catch (e) {
|
|
347
|
+
loadErrors.push(e)
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
try {
|
|
351
|
+
return require('./warpllm.linux-arm-gnueabihf.node')
|
|
352
|
+
} catch (e) {
|
|
353
|
+
loadErrors.push(e)
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
const binding = require('@warpllm/warpllm-linux-arm-gnueabihf')
|
|
357
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-arm-gnueabihf/package.json').version
|
|
358
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
|
+
}
|
|
361
|
+
return binding
|
|
362
|
+
} catch (e) {
|
|
363
|
+
loadErrors.push(e)
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
} else if (process.arch === 'loong64') {
|
|
367
|
+
if (isMusl()) {
|
|
368
|
+
try {
|
|
369
|
+
return require('./warpllm.linux-loong64-musl.node')
|
|
370
|
+
} catch (e) {
|
|
371
|
+
loadErrors.push(e)
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
const binding = require('@warpllm/warpllm-linux-loong64-musl')
|
|
375
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-loong64-musl/package.json').version
|
|
376
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
|
+
}
|
|
379
|
+
return binding
|
|
380
|
+
} catch (e) {
|
|
381
|
+
loadErrors.push(e)
|
|
382
|
+
}
|
|
383
|
+
} else {
|
|
384
|
+
try {
|
|
385
|
+
return require('./warpllm.linux-loong64-gnu.node')
|
|
386
|
+
} catch (e) {
|
|
387
|
+
loadErrors.push(e)
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
const binding = require('@warpllm/warpllm-linux-loong64-gnu')
|
|
391
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-loong64-gnu/package.json').version
|
|
392
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
|
+
}
|
|
395
|
+
return binding
|
|
396
|
+
} catch (e) {
|
|
397
|
+
loadErrors.push(e)
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
} else if (process.arch === 'riscv64') {
|
|
401
|
+
if (isMusl()) {
|
|
402
|
+
try {
|
|
403
|
+
return require('./warpllm.linux-riscv64-musl.node')
|
|
404
|
+
} catch (e) {
|
|
405
|
+
loadErrors.push(e)
|
|
406
|
+
}
|
|
407
|
+
try {
|
|
408
|
+
const binding = require('@warpllm/warpllm-linux-riscv64-musl')
|
|
409
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-riscv64-musl/package.json').version
|
|
410
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
|
+
}
|
|
413
|
+
return binding
|
|
414
|
+
} catch (e) {
|
|
415
|
+
loadErrors.push(e)
|
|
416
|
+
}
|
|
417
|
+
} else {
|
|
418
|
+
try {
|
|
419
|
+
return require('./warpllm.linux-riscv64-gnu.node')
|
|
420
|
+
} catch (e) {
|
|
421
|
+
loadErrors.push(e)
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
const binding = require('@warpllm/warpllm-linux-riscv64-gnu')
|
|
425
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-riscv64-gnu/package.json').version
|
|
426
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
|
+
}
|
|
429
|
+
return binding
|
|
430
|
+
} catch (e) {
|
|
431
|
+
loadErrors.push(e)
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
} else if (process.arch === 'ppc64') {
|
|
435
|
+
try {
|
|
436
|
+
return require('./warpllm.linux-ppc64-gnu.node')
|
|
437
|
+
} catch (e) {
|
|
438
|
+
loadErrors.push(e)
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
const binding = require('@warpllm/warpllm-linux-ppc64-gnu')
|
|
442
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-ppc64-gnu/package.json').version
|
|
443
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
|
+
}
|
|
446
|
+
return binding
|
|
447
|
+
} catch (e) {
|
|
448
|
+
loadErrors.push(e)
|
|
449
|
+
}
|
|
450
|
+
} else if (process.arch === 's390x') {
|
|
451
|
+
try {
|
|
452
|
+
return require('./warpllm.linux-s390x-gnu.node')
|
|
453
|
+
} catch (e) {
|
|
454
|
+
loadErrors.push(e)
|
|
455
|
+
}
|
|
456
|
+
try {
|
|
457
|
+
const binding = require('@warpllm/warpllm-linux-s390x-gnu')
|
|
458
|
+
const bindingPackageVersion = require('@warpllm/warpllm-linux-s390x-gnu/package.json').version
|
|
459
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
|
+
}
|
|
462
|
+
return binding
|
|
463
|
+
} catch (e) {
|
|
464
|
+
loadErrors.push(e)
|
|
465
|
+
}
|
|
466
|
+
} else {
|
|
467
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
468
|
+
}
|
|
469
|
+
} else if (process.platform === 'openharmony') {
|
|
470
|
+
if (process.arch === 'arm64') {
|
|
471
|
+
try {
|
|
472
|
+
return require('./warpllm.openharmony-arm64.node')
|
|
473
|
+
} catch (e) {
|
|
474
|
+
loadErrors.push(e)
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
const binding = require('@warpllm/warpllm-openharmony-arm64')
|
|
478
|
+
const bindingPackageVersion = require('@warpllm/warpllm-openharmony-arm64/package.json').version
|
|
479
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
|
+
}
|
|
482
|
+
return binding
|
|
483
|
+
} catch (e) {
|
|
484
|
+
loadErrors.push(e)
|
|
485
|
+
}
|
|
486
|
+
} else if (process.arch === 'x64') {
|
|
487
|
+
try {
|
|
488
|
+
return require('./warpllm.openharmony-x64.node')
|
|
489
|
+
} catch (e) {
|
|
490
|
+
loadErrors.push(e)
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
const binding = require('@warpllm/warpllm-openharmony-x64')
|
|
494
|
+
const bindingPackageVersion = require('@warpllm/warpllm-openharmony-x64/package.json').version
|
|
495
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
|
+
}
|
|
498
|
+
return binding
|
|
499
|
+
} catch (e) {
|
|
500
|
+
loadErrors.push(e)
|
|
501
|
+
}
|
|
502
|
+
} else if (process.arch === 'arm') {
|
|
503
|
+
try {
|
|
504
|
+
return require('./warpllm.openharmony-arm.node')
|
|
505
|
+
} catch (e) {
|
|
506
|
+
loadErrors.push(e)
|
|
507
|
+
}
|
|
508
|
+
try {
|
|
509
|
+
const binding = require('@warpllm/warpllm-openharmony-arm')
|
|
510
|
+
const bindingPackageVersion = require('@warpllm/warpllm-openharmony-arm/package.json').version
|
|
511
|
+
if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
|
+
}
|
|
514
|
+
return binding
|
|
515
|
+
} catch (e) {
|
|
516
|
+
loadErrors.push(e)
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
nativeBinding = requireNative()
|
|
527
|
+
|
|
528
|
+
// NAPI_RS_FORCE_WASI is a tri-state flag:
|
|
529
|
+
// unset / any other value → native binding preferred, WASI is only a fallback
|
|
530
|
+
// 'true' → force WASI fallback even if native loaded
|
|
531
|
+
// 'error' → force WASI and throw if no WASI binding is found
|
|
532
|
+
// Treating any non-empty string as truthy (the historical behavior) meant
|
|
533
|
+
// NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
|
|
534
|
+
// the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
|
|
535
|
+
const forceWasi =
|
|
536
|
+
process.env.NAPI_RS_FORCE_WASI === 'true' || process.env.NAPI_RS_FORCE_WASI === 'error'
|
|
537
|
+
|
|
538
|
+
if (!nativeBinding || forceWasi) {
|
|
539
|
+
let wasiBinding = null
|
|
540
|
+
let wasiBindingError = null
|
|
541
|
+
try {
|
|
542
|
+
wasiBinding = require('./warpllm.wasi.cjs')
|
|
543
|
+
nativeBinding = wasiBinding
|
|
544
|
+
} catch (err) {
|
|
545
|
+
if (forceWasi) {
|
|
546
|
+
wasiBindingError = err
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (!nativeBinding || forceWasi) {
|
|
550
|
+
try {
|
|
551
|
+
wasiBinding = require('@warpllm/warpllm-wasm32-wasi')
|
|
552
|
+
nativeBinding = wasiBinding
|
|
553
|
+
} catch (err) {
|
|
554
|
+
if (forceWasi) {
|
|
555
|
+
if (!wasiBindingError) {
|
|
556
|
+
wasiBindingError = err
|
|
557
|
+
} else {
|
|
558
|
+
wasiBindingError.cause = err
|
|
559
|
+
}
|
|
560
|
+
loadErrors.push(err)
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
|
|
565
|
+
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
|
|
566
|
+
error.cause = wasiBindingError
|
|
567
|
+
throw error
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (!nativeBinding) {
|
|
572
|
+
if (loadErrors.length > 0) {
|
|
573
|
+
const error = new Error(
|
|
574
|
+
`Cannot find native binding. ` +
|
|
575
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
576
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
577
|
+
)
|
|
578
|
+
// assign instead of the `new Error(message, { cause })` options form,
|
|
579
|
+
// which Node < 16.9 silently ignores
|
|
580
|
+
error.cause = loadErrors.reduce((err, cur) => {
|
|
581
|
+
cur.cause = err
|
|
582
|
+
return cur
|
|
583
|
+
})
|
|
584
|
+
throw error
|
|
585
|
+
}
|
|
586
|
+
throw new Error(`Failed to load native binding`)
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
module.exports = nativeBinding
|
|
590
|
+
module.exports.Client = nativeBinding.Client
|
|
591
|
+
module.exports.echo = nativeBinding.echo
|
|
592
|
+
module.exports.version = nativeBinding.version
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@warpllm/warpllm",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "A warp-speed, robust AI gateway",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/warpllm/warpllm.git",
|
|
9
|
+
"directory": "bindings/node"
|
|
10
|
+
},
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"index.js",
|
|
16
|
+
"index.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"registry": "https://registry.npmjs.org/",
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">= 20"
|
|
24
|
+
},
|
|
25
|
+
"napi": {
|
|
26
|
+
"binaryName": "warpllm",
|
|
27
|
+
"targets": [
|
|
28
|
+
"x86_64-apple-darwin",
|
|
29
|
+
"aarch64-apple-darwin",
|
|
30
|
+
"x86_64-pc-windows-msvc",
|
|
31
|
+
"aarch64-pc-windows-msvc",
|
|
32
|
+
"x86_64-unknown-linux-gnu",
|
|
33
|
+
"aarch64-unknown-linux-gnu",
|
|
34
|
+
"x86_64-unknown-linux-musl",
|
|
35
|
+
"aarch64-unknown-linux-musl"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"artifacts": "napi artifacts",
|
|
40
|
+
"build": "napi build --platform --release && npm run build:ts",
|
|
41
|
+
"build:debug": "napi build --platform && npm run build:ts",
|
|
42
|
+
"build:ts": "tsc -p tsconfig.build.json",
|
|
43
|
+
"create-npm-dirs": "napi create-npm-dirs",
|
|
44
|
+
"prepack": "node -e \"fs.copyFileSync('../../README.md','README.md');fs.copyFileSync('../../LICENSE','LICENSE')\"",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
46
|
+
"test": "npm run build:ts && npm run typecheck && vitest run"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@napi-rs/cli": "^3.7",
|
|
50
|
+
"@types/node": "25.9.4",
|
|
51
|
+
"openai": "6.45.0",
|
|
52
|
+
"typescript": "^5",
|
|
53
|
+
"vitest": "^3"
|
|
54
|
+
},
|
|
55
|
+
"optionalDependencies": {
|
|
56
|
+
"@warpllm/warpllm-darwin-arm64": "0.1.3",
|
|
57
|
+
"@warpllm/warpllm-darwin-x64": "0.1.3",
|
|
58
|
+
"@warpllm/warpllm-linux-arm64-gnu": "0.1.3",
|
|
59
|
+
"@warpllm/warpllm-linux-arm64-musl": "0.1.3",
|
|
60
|
+
"@warpllm/warpllm-linux-x64-gnu": "0.1.3",
|
|
61
|
+
"@warpllm/warpllm-linux-x64-musl": "0.1.3",
|
|
62
|
+
"@warpllm/warpllm-win32-arm64-msvc": "0.1.3",
|
|
63
|
+
"@warpllm/warpllm-win32-x64-msvc": "0.1.3"
|
|
64
|
+
}
|
|
65
|
+
}
|