@antdv-next/x-sdk 0.0.1 → 0.0.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 +21 -0
- package/dist/_util/resolveMaybeRef.d.ts +2 -0
- package/dist/_util/resolveMaybeRef.js +7 -0
- package/dist/_util/types.js +0 -0
- package/dist/chat-providers/AbstractChatProvider.d.ts +2 -2
- package/dist/chat-providers/AbstractChatProvider.js +42 -0
- package/dist/chat-providers/DeepSeekChatProvider.d.ts +2 -2
- package/dist/chat-providers/DeepSeekChatProvider.js +59 -0
- package/dist/chat-providers/DefaultChatProvider.d.ts +2 -2
- package/dist/chat-providers/DefaultChatProvider.js +26 -0
- package/dist/chat-providers/OpenAIChatProvider.d.ts +2 -2
- package/dist/chat-providers/OpenAIChatProvider.js +49 -0
- package/dist/chat-providers/index.js +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -3
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/expect/index.js +1467 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/pretty-format/index.js +884 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/runner/chunk-artifact.js +1513 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/snapshot/index.js +661 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/spy/index.js +384 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/chunk-pathe.M-eThtNZ.js +80 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/diff.js +1304 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/display.js +556 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/error.js +27 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/helpers.js +179 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/offset.js +25 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/serialize.js +75 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/source-map.js +371 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/utils/timers.js +35 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/chunks/_commonjsHelpers.D26ty3Ew.js +4 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/chunks/rpc.MzXet3jl.js +50 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/chunks/test.CBQUpOM3.js +2645 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/chunks/utils.BX5Fg8C4.js +42 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/vendor/chai.js +2872 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/vendor/magic-string.js +1009 -0
- package/dist/node_modules/.pnpm/@voidzero-dev_vite-plus-test@0.1.14_@types_node@24.12.0_@voidzero-dev_vite-plus-core@0._0c620f79340a656256b2ffe23b3e6dd1/node_modules/@voidzero-dev/vite-plus-test/dist/vendor/tinyrainbow.js +84 -0
- package/dist/x-chat/__tests__/index.test.d.ts +1 -0
- package/dist/x-chat/__tests__/index.test.js +258 -0
- package/dist/x-chat/index.d.ts +14 -23
- package/dist/x-chat/index.js +85 -67
- package/dist/x-chat/store.d.ts +2 -0
- package/dist/{store-C1diHqNH.js → x-chat/store.js} +15 -9
- package/dist/x-conversations/__tests__/index.test.d.ts +1 -0
- package/dist/x-conversations/__tests__/index.test.js +36 -0
- package/dist/x-conversations/index.d.ts +4 -4
- package/dist/x-conversations/index.js +37 -1
- package/dist/{x-conversations-BrKWhj5r.js → x-conversations/store.js} +2 -31
- package/dist/x-request/__tests__/index.test.d.ts +1 -0
- package/dist/x-request/__tests__/index.test.js +90 -0
- package/dist/x-request/index.d.ts +36 -11
- package/dist/x-request/index.js +246 -1
- package/dist/x-request/x-fetch.js +18 -0
- package/dist/x-stream/__tests__/index.test.d.ts +1 -0
- package/dist/x-stream/__tests__/index.test.js +62 -0
- package/dist/x-stream/index.js +16 -5
- package/package.json +2 -1
- package/dist/chat-providers-5x9Va7p5.js +0 -167
- package/dist/x-request-BSFGaKND.js +0 -234
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import XStream from "./x-stream/index.js";
|
|
2
|
-
//#region src/x-request/x-fetch.ts
|
|
3
|
-
var XFetch = async (baseURL, options) => {
|
|
4
|
-
const { fetch: fetchFn = globalThis.fetch, middlewares = {}, ...requestInit } = options;
|
|
5
|
-
if (typeof fetchFn !== "function") throw new Error("The options.fetch must be a typeof fetch function!");
|
|
6
|
-
let fetchArgs = [baseURL, requestInit];
|
|
7
|
-
if (typeof middlewares.onRequest === "function") fetchArgs = await middlewares.onRequest(...fetchArgs);
|
|
8
|
-
let response = await fetchFn(...fetchArgs);
|
|
9
|
-
if (typeof middlewares.onResponse === "function") {
|
|
10
|
-
const modifiedResponse = await middlewares.onResponse(response);
|
|
11
|
-
if (!(modifiedResponse instanceof Response)) throw new Error("The options.onResponse must return a Response instance!");
|
|
12
|
-
response = modifiedResponse;
|
|
13
|
-
}
|
|
14
|
-
if (!response.ok) throw new Error(`Fetch failed with status ${response.status}`);
|
|
15
|
-
if (!response.body) throw new Error("The response body is empty.");
|
|
16
|
-
return response;
|
|
17
|
-
};
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/x-request/index.ts
|
|
20
|
-
var globalOptions = {
|
|
21
|
-
manual: false,
|
|
22
|
-
headers: { "Content-Type": "application/json" }
|
|
23
|
-
};
|
|
24
|
-
function setXRequestGlobalOptions(options) {
|
|
25
|
-
Object.assign(globalOptions, options);
|
|
26
|
-
}
|
|
27
|
-
var LastEventId = "Last-Event-ID";
|
|
28
|
-
var AbstractXRequestClass = class {
|
|
29
|
-
baseURL;
|
|
30
|
-
options;
|
|
31
|
-
constructor(baseURL, options) {
|
|
32
|
-
if (!baseURL || typeof baseURL !== "string") throw new Error("The baseURL is not valid!");
|
|
33
|
-
this.baseURL = baseURL;
|
|
34
|
-
this.options = options || {};
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var XRequestClass = class extends AbstractXRequestClass {
|
|
38
|
-
_asyncHandler;
|
|
39
|
-
timeoutHandler;
|
|
40
|
-
_isTimeout = false;
|
|
41
|
-
streamTimeoutHandler;
|
|
42
|
-
_isStreamTimeout = false;
|
|
43
|
-
abortController;
|
|
44
|
-
_isRequesting = false;
|
|
45
|
-
_manual = false;
|
|
46
|
-
lastManualParams;
|
|
47
|
-
retryTimes = 0;
|
|
48
|
-
retryTimer;
|
|
49
|
-
lastEventId = void 0;
|
|
50
|
-
get asyncHandler() {
|
|
51
|
-
return this._asyncHandler;
|
|
52
|
-
}
|
|
53
|
-
get isTimeout() {
|
|
54
|
-
return this._isTimeout;
|
|
55
|
-
}
|
|
56
|
-
set isTimeout(value) {
|
|
57
|
-
this._isTimeout = value;
|
|
58
|
-
}
|
|
59
|
-
get isStreamTimeout() {
|
|
60
|
-
return this._isStreamTimeout;
|
|
61
|
-
}
|
|
62
|
-
set isStreamTimeout(value) {
|
|
63
|
-
this._isStreamTimeout = value;
|
|
64
|
-
}
|
|
65
|
-
get isRequesting() {
|
|
66
|
-
return this._isRequesting;
|
|
67
|
-
}
|
|
68
|
-
get manual() {
|
|
69
|
-
return this._manual;
|
|
70
|
-
}
|
|
71
|
-
constructor(baseURL, options) {
|
|
72
|
-
super(baseURL, options);
|
|
73
|
-
this._manual = options?.manual || false;
|
|
74
|
-
if (!this.manual) this.init();
|
|
75
|
-
}
|
|
76
|
-
run(params) {
|
|
77
|
-
if (this.manual) {
|
|
78
|
-
this.resetRetry();
|
|
79
|
-
this.lastManualParams = params;
|
|
80
|
-
this.init(params);
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
console.warn("The request is not manual, so it cannot be run!");
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
abort() {
|
|
87
|
-
clearTimeout(this.timeoutHandler);
|
|
88
|
-
clearTimeout(this.streamTimeoutHandler);
|
|
89
|
-
this.abortController.abort();
|
|
90
|
-
}
|
|
91
|
-
init(extraParams, extraHeaders) {
|
|
92
|
-
this.abortController = new AbortController();
|
|
93
|
-
const { callbacks, params, headers = {}, transformStream, fetch, timeout, streamTimeout, middlewares, streamSeparator, partSeparator, kvSeparator, ...otherOptions } = this.options;
|
|
94
|
-
const margeHeaders = Object.assign({}, globalOptions.headers || {}, headers, extraHeaders || {});
|
|
95
|
-
const requestInit = {
|
|
96
|
-
...otherOptions,
|
|
97
|
-
method: "POST",
|
|
98
|
-
body: JSON.stringify({
|
|
99
|
-
...params,
|
|
100
|
-
...extraParams
|
|
101
|
-
}),
|
|
102
|
-
params: {
|
|
103
|
-
...params,
|
|
104
|
-
...extraParams
|
|
105
|
-
},
|
|
106
|
-
headers: margeHeaders,
|
|
107
|
-
signal: this.abortController.signal,
|
|
108
|
-
middlewares
|
|
109
|
-
};
|
|
110
|
-
if (timeout && timeout > 0) this.timeoutHandler = window.setTimeout(() => {
|
|
111
|
-
this.isTimeout = true;
|
|
112
|
-
this.finishRequest();
|
|
113
|
-
callbacks?.onError?.(/* @__PURE__ */ new Error("TimeoutError"));
|
|
114
|
-
}, timeout);
|
|
115
|
-
this.startRequest();
|
|
116
|
-
this._asyncHandler = XFetch(this.baseURL, {
|
|
117
|
-
fetch,
|
|
118
|
-
...requestInit
|
|
119
|
-
}).then(async (response) => {
|
|
120
|
-
clearTimeout(this.timeoutHandler);
|
|
121
|
-
if (this.isTimeout) return;
|
|
122
|
-
if (transformStream) {
|
|
123
|
-
let transformer = transformStream;
|
|
124
|
-
if (typeof transformStream === "function") transformer = transformStream(this.baseURL, response.headers);
|
|
125
|
-
await this.customResponseHandler(response, callbacks, transformer, streamTimeout, streamSeparator, partSeparator, kvSeparator);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const contentType = response.headers.get("content-type") || "";
|
|
129
|
-
switch (contentType.split(";")[0].trim()) {
|
|
130
|
-
case "text/event-stream":
|
|
131
|
-
await this.sseResponseHandler(response, callbacks, streamTimeout, streamSeparator, partSeparator, kvSeparator);
|
|
132
|
-
break;
|
|
133
|
-
case "application/json":
|
|
134
|
-
await this.jsonResponseHandler(response, callbacks);
|
|
135
|
-
break;
|
|
136
|
-
default: throw new Error(`The response content-type: ${contentType} is not support!`);
|
|
137
|
-
}
|
|
138
|
-
}).catch((error) => {
|
|
139
|
-
clearTimeout(this.timeoutHandler);
|
|
140
|
-
this.finishRequest();
|
|
141
|
-
const err = error instanceof Error || error instanceof DOMException ? error : /* @__PURE__ */ new Error("Unknown error!");
|
|
142
|
-
const returnOfOnError = callbacks?.onError?.(err);
|
|
143
|
-
if (err.name !== "AbortError") {
|
|
144
|
-
const retryInterval = typeof returnOfOnError === "number" ? returnOfOnError : this.options.retryInterval;
|
|
145
|
-
if (retryInterval && retryInterval > 0) {
|
|
146
|
-
if (typeof this.options.retryTimes === "number" && this.retryTimes >= this.options.retryTimes) return;
|
|
147
|
-
clearTimeout(this.retryTimer);
|
|
148
|
-
this.retryTimer = setTimeout(() => {
|
|
149
|
-
const extraHeaders = {};
|
|
150
|
-
if (typeof this.lastEventId !== "undefined") extraHeaders[LastEventId] = this.lastEventId;
|
|
151
|
-
this.init(this.lastManualParams, extraHeaders);
|
|
152
|
-
}, retryInterval);
|
|
153
|
-
this.retryTimes = this.retryTimes + 1;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
startRequest() {
|
|
159
|
-
this._isRequesting = true;
|
|
160
|
-
}
|
|
161
|
-
finishRequest() {
|
|
162
|
-
this._isRequesting = false;
|
|
163
|
-
}
|
|
164
|
-
customResponseHandler = async (response, callbacks, transformStream, streamTimeout, streamSeparator, partSeparator, kvSeparator) => {
|
|
165
|
-
const stream = XStream({
|
|
166
|
-
readableStream: response.body,
|
|
167
|
-
transformStream,
|
|
168
|
-
streamSeparator,
|
|
169
|
-
partSeparator,
|
|
170
|
-
kvSeparator
|
|
171
|
-
});
|
|
172
|
-
await this.processStream(stream, response, callbacks, streamTimeout);
|
|
173
|
-
};
|
|
174
|
-
sseResponseHandler = async (response, callbacks, streamTimeout, streamSeparator, partSeparator, kvSeparator) => {
|
|
175
|
-
const stream = XStream({
|
|
176
|
-
readableStream: response.body,
|
|
177
|
-
streamSeparator,
|
|
178
|
-
partSeparator,
|
|
179
|
-
kvSeparator
|
|
180
|
-
});
|
|
181
|
-
await this.processStream(stream, response, callbacks, streamTimeout);
|
|
182
|
-
};
|
|
183
|
-
async processStream(stream, response, callbacks, streamTimeout) {
|
|
184
|
-
const chunks = [];
|
|
185
|
-
const iterator = stream[Symbol.asyncIterator]();
|
|
186
|
-
let result;
|
|
187
|
-
do {
|
|
188
|
-
if (streamTimeout) this.streamTimeoutHandler = window.setTimeout(() => {
|
|
189
|
-
this.isStreamTimeout = true;
|
|
190
|
-
this.finishRequest();
|
|
191
|
-
callbacks?.onError?.(/* @__PURE__ */ new Error("StreamTimeoutError"), void 0, response.headers);
|
|
192
|
-
}, streamTimeout);
|
|
193
|
-
result = await iterator.next();
|
|
194
|
-
clearTimeout(this.streamTimeoutHandler);
|
|
195
|
-
if (this.isStreamTimeout) break;
|
|
196
|
-
if (result.value) {
|
|
197
|
-
chunks.push(result.value);
|
|
198
|
-
callbacks?.onUpdate?.(result.value, response.headers);
|
|
199
|
-
if (typeof result?.value?.id !== "undefined") this.lastEventId = result.value.id;
|
|
200
|
-
}
|
|
201
|
-
} while (!result.done);
|
|
202
|
-
if (streamTimeout) {
|
|
203
|
-
clearTimeout(this.streamTimeoutHandler);
|
|
204
|
-
if (this.isStreamTimeout) {
|
|
205
|
-
this.finishRequest();
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
this.finishRequest();
|
|
210
|
-
callbacks?.onSuccess?.(chunks, response.headers);
|
|
211
|
-
}
|
|
212
|
-
jsonResponseHandler = async (response, callbacks) => {
|
|
213
|
-
const chunk = await response.json();
|
|
214
|
-
if (chunk?.success === false) {
|
|
215
|
-
const error = new Error(chunk.message || "System error");
|
|
216
|
-
error.name = chunk.name || "SystemError";
|
|
217
|
-
callbacks?.onError?.(error, chunk, response.headers);
|
|
218
|
-
} else {
|
|
219
|
-
callbacks?.onUpdate?.(chunk, response.headers);
|
|
220
|
-
this.finishRequest();
|
|
221
|
-
callbacks?.onSuccess?.([chunk], response.headers);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
resetRetry() {
|
|
225
|
-
clearTimeout(this.retryTimer);
|
|
226
|
-
this.retryTimes = 0;
|
|
227
|
-
this.lastEventId = void 0;
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
function XRequest(baseURL, options) {
|
|
231
|
-
return new XRequestClass(baseURL, options);
|
|
232
|
-
}
|
|
233
|
-
//#endregion
|
|
234
|
-
export { setXRequestGlobalOptions as i, XRequest as n, XRequestClass as r, AbstractXRequestClass as t };
|