@vectorx/ai-sdk 1.0.0 → 1.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/lib/ai.d.ts +1 -1
- package/lib/ai.js +14 -0
- package/lib/model-type.d.ts +26 -0
- package/lib/models/Chat.d.ts +2 -2
- package/lib/models/Default/index.d.ts +1 -0
- package/lib/models/Default/index.js +27 -1
- package/lib/models/Qwen25T2iPreview/index.d.ts +3 -1
- package/lib/models/Qwen25T2iPreview/index.js +49 -0
- package/lib/models/Qwen3VlPlus/index.d.ts +2 -0
- package/lib/models/Qwen3VlPlus/index.js +66 -2
- package/lib/models/QwenCosyVoiceTTS/index.d.ts +8 -0
- package/lib/models/QwenCosyVoiceTTS/index.js +178 -0
- package/lib/models/QwenDocTurbo/adapters/DashScope.d.ts +2 -0
- package/lib/models/QwenDocTurbo/adapters/DashScope.js +86 -11
- package/lib/models/QwenDocTurbo/adapters/OpenAICompat.d.ts +2 -0
- package/lib/models/QwenDocTurbo/adapters/OpenAICompat.js +102 -3
- package/lib/models/QwenImage/index.d.ts +3 -1
- package/lib/models/QwenImage/index.js +52 -1
- package/lib/models/QwenImage20/index.d.ts +91 -0
- package/lib/models/QwenImage20/index.js +244 -0
- package/lib/models/QwenImageEdit/index.d.ts +3 -1
- package/lib/models/QwenImageEdit/index.js +52 -1
- package/lib/models/QwenSketchToImage/index.d.ts +1 -1
- package/lib/models/QwenStyleRepaintV1/index.d.ts +1 -1
- package/lib/models/QwenStyleRepaintV1/index.js +3 -1
- package/lib/models/QwenVlMax/index.d.ts +2 -0
- package/lib/models/QwenVlMax/index.js +67 -2
- package/lib/models/TTSModel.d.ts +11 -0
- package/lib/models/TTSModel.js +75 -0
- package/lib/models/Wan26Image/index.d.ts +3 -1
- package/lib/models/Wan26Image/index.js +52 -1
- package/lib/models/index.d.ts +25 -3
- package/lib/models/index.js +49 -2
- package/lib/models/react.d.ts +6 -2
- package/lib/models/react.js +22 -0
- package/lib/stream.js +10 -7
- package/lib/tokenManager.js +11 -1
- package/package.json +9 -7
package/lib/models/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { DefaultSimpleModel } from "./Default";
|
|
2
2
|
import { Qwen3VlPlus } from "./Qwen3VlPlus";
|
|
3
3
|
import { Qwen25T2iPreviewModel } from "./Qwen25T2iPreview";
|
|
4
|
+
import { AliyunCosyVoiceTTSModel } from "./QwenCosyVoiceTTS";
|
|
4
5
|
import { QwenDocTurbo } from "./QwenDocTurbo";
|
|
5
6
|
import { QwenImageModel } from "./QwenImage";
|
|
7
|
+
import { QwenImage20FastModel, QwenImage20ProModel } from "./QwenImage20";
|
|
6
8
|
import { QwenImageEditModel } from "./QwenImageEdit";
|
|
7
9
|
import { WanxSketchToImageLiteModel } from "./QwenSketchToImage";
|
|
8
10
|
import { QwenStyleRepaintV1Model } from "./QwenStyleRepaintV1";
|
|
9
11
|
import { QwenVlMax } from "./QwenVlMax";
|
|
12
|
+
import { SimpleTTSModel } from "./TTSModel";
|
|
10
13
|
import { Wan26ImageModel } from "./Wan26Image";
|
|
11
14
|
import { ReActModel } from "./react";
|
|
12
15
|
export declare enum ModelName {
|
|
@@ -19,6 +22,14 @@ export declare enum ModelName {
|
|
|
19
22
|
QwenVlOcr = "qwen-vl-ocr",
|
|
20
23
|
Wanx21T2iTurbo = "wanx2.1-t2i-turbo"
|
|
21
24
|
}
|
|
25
|
+
export declare enum TTSModelName {
|
|
26
|
+
CosyVoiceV35Flash = "cosyvoice-v3.5-flash",
|
|
27
|
+
CosyVoiceV35Plus = "cosyvoice-v3.5-plus",
|
|
28
|
+
CosyVoiceV3Flash = "cosyvoice-v3-flash",
|
|
29
|
+
CosyVoiceV3Plus = "cosyvoice-v3-plus",
|
|
30
|
+
CosyVoiceV2 = "cosyvoice-v2",
|
|
31
|
+
CosyVoiceV1 = "cosyvoice-v1"
|
|
32
|
+
}
|
|
22
33
|
export declare enum MultiModalModelName {
|
|
23
34
|
QvqMaxLatest = "qvq-max-latest",
|
|
24
35
|
QwenVlMax = "qwen-vl-max",
|
|
@@ -33,7 +44,9 @@ export declare enum MultiModalModelName {
|
|
|
33
44
|
Qwen25T2iPreview = "wan2.5-i2i-preview",
|
|
34
45
|
Wan26Image = "wan2.6-image",
|
|
35
46
|
WanxSketchToImageLite = "wanx-sketch-to-image-lite",
|
|
36
|
-
QwenStyleRepaintV1 = "wanx-style-repaint-v1"
|
|
47
|
+
QwenStyleRepaintV1 = "wanx-style-repaint-v1",
|
|
48
|
+
QwenImage20Pro = "qwen-image-2.0-pro",
|
|
49
|
+
QwenImage20 = "qwen-image-2.0"
|
|
37
50
|
}
|
|
38
51
|
export declare const modelName: {
|
|
39
52
|
"deepseek-r1": string;
|
|
@@ -43,6 +56,12 @@ export declare const modelName: {
|
|
|
43
56
|
"qwen-plus": string;
|
|
44
57
|
"qwen-turbo": string;
|
|
45
58
|
"qwen-vl-ocr": string;
|
|
59
|
+
"cosyvoice-v3.5-flash": string;
|
|
60
|
+
"cosyvoice-v3.5-plus": string;
|
|
61
|
+
"cosyvoice-v3-flash": string;
|
|
62
|
+
"cosyvoice-v3-plus": string;
|
|
63
|
+
"cosyvoice-v2": string;
|
|
64
|
+
"cosyvoice-v1": string;
|
|
46
65
|
"qvq-max-latest": string;
|
|
47
66
|
"qwen-vl-max": string;
|
|
48
67
|
"qwen3-vl-plus": string;
|
|
@@ -57,13 +76,16 @@ export declare const modelName: {
|
|
|
57
76
|
"wan2.6-image": string;
|
|
58
77
|
"wanx-sketch-to-image-lite": string;
|
|
59
78
|
"wanx-style-repaint-v1": string;
|
|
79
|
+
"qwen-image-2.0-pro": string;
|
|
80
|
+
"qwen-image-2.0": string;
|
|
60
81
|
};
|
|
61
|
-
export declare const isValidModel: (model: ModelName | MultiModalModelName) => model is ModelName | MultiModalModelName;
|
|
82
|
+
export declare const isValidModel: (model: ModelName | MultiModalModelName | TTSModelName) => model is ModelName | MultiModalModelName | TTSModelName;
|
|
62
83
|
export declare const isMultiModalModel: (model: ModelName | MultiModalModelName) => model is MultiModalModelName;
|
|
84
|
+
export declare const isTTSModel: (model: ModelName | MultiModalModelName | TTSModelName) => model is TTSModelName;
|
|
63
85
|
declare const toolMap: Map<string, Function>;
|
|
64
86
|
export declare const MODEL_REQUEST_PATTERNS: Map<string, {
|
|
65
87
|
domain: string;
|
|
66
88
|
paths: string[];
|
|
67
89
|
}>;
|
|
68
90
|
export declare function isModelRequestUrl(url: string): boolean;
|
|
69
|
-
export { DefaultSimpleModel, QwenDocTurbo, ReActModel, toolMap, WanxSketchToImageLiteModel, QwenImageModel, QwenImageEditModel, Qwen25T2iPreviewModel, Wan26ImageModel, Qwen3VlPlus, QwenVlMax, QwenStyleRepaintV1Model, };
|
|
91
|
+
export { SimpleTTSModel, AliyunCosyVoiceTTSModel, DefaultSimpleModel, QwenDocTurbo, ReActModel, toolMap, WanxSketchToImageLiteModel, QwenImageModel, QwenImageEditModel, QwenImage20ProModel, QwenImage20FastModel, Qwen25T2iPreviewModel, Wan26ImageModel, Qwen3VlPlus, QwenVlMax, QwenStyleRepaintV1Model, };
|
package/lib/models/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QwenStyleRepaintV1Model = exports.QwenVlMax = exports.Qwen3VlPlus = exports.Wan26ImageModel = exports.Qwen25T2iPreviewModel = exports.QwenImageEditModel = exports.QwenImageModel = exports.WanxSketchToImageLiteModel = exports.toolMap = exports.ReActModel = exports.QwenDocTurbo = exports.DefaultSimpleModel = exports.MODEL_REQUEST_PATTERNS = exports.isMultiModalModel = exports.isValidModel = exports.modelName = exports.MultiModalModelName = exports.ModelName = void 0;
|
|
3
|
+
exports.QwenStyleRepaintV1Model = exports.QwenVlMax = exports.Qwen3VlPlus = exports.Wan26ImageModel = exports.Qwen25T2iPreviewModel = exports.QwenImage20FastModel = exports.QwenImage20ProModel = exports.QwenImageEditModel = exports.QwenImageModel = exports.WanxSketchToImageLiteModel = exports.toolMap = exports.ReActModel = exports.QwenDocTurbo = exports.DefaultSimpleModel = exports.AliyunCosyVoiceTTSModel = exports.SimpleTTSModel = exports.MODEL_REQUEST_PATTERNS = exports.isTTSModel = exports.isMultiModalModel = exports.isValidModel = exports.modelName = exports.MultiModalModelName = exports.TTSModelName = exports.ModelName = void 0;
|
|
4
4
|
exports.isModelRequestUrl = isModelRequestUrl;
|
|
5
5
|
const Default_1 = require("./Default");
|
|
6
6
|
Object.defineProperty(exports, "DefaultSimpleModel", { enumerable: true, get: function () { return Default_1.DefaultSimpleModel; } });
|
|
@@ -8,10 +8,15 @@ const Qwen3VlPlus_1 = require("./Qwen3VlPlus");
|
|
|
8
8
|
Object.defineProperty(exports, "Qwen3VlPlus", { enumerable: true, get: function () { return Qwen3VlPlus_1.Qwen3VlPlus; } });
|
|
9
9
|
const Qwen25T2iPreview_1 = require("./Qwen25T2iPreview");
|
|
10
10
|
Object.defineProperty(exports, "Qwen25T2iPreviewModel", { enumerable: true, get: function () { return Qwen25T2iPreview_1.Qwen25T2iPreviewModel; } });
|
|
11
|
+
const QwenCosyVoiceTTS_1 = require("./QwenCosyVoiceTTS");
|
|
12
|
+
Object.defineProperty(exports, "AliyunCosyVoiceTTSModel", { enumerable: true, get: function () { return QwenCosyVoiceTTS_1.AliyunCosyVoiceTTSModel; } });
|
|
11
13
|
const QwenDocTurbo_1 = require("./QwenDocTurbo");
|
|
12
14
|
Object.defineProperty(exports, "QwenDocTurbo", { enumerable: true, get: function () { return QwenDocTurbo_1.QwenDocTurbo; } });
|
|
13
15
|
const QwenImage_1 = require("./QwenImage");
|
|
14
16
|
Object.defineProperty(exports, "QwenImageModel", { enumerable: true, get: function () { return QwenImage_1.QwenImageModel; } });
|
|
17
|
+
const QwenImage20_1 = require("./QwenImage20");
|
|
18
|
+
Object.defineProperty(exports, "QwenImage20FastModel", { enumerable: true, get: function () { return QwenImage20_1.QwenImage20FastModel; } });
|
|
19
|
+
Object.defineProperty(exports, "QwenImage20ProModel", { enumerable: true, get: function () { return QwenImage20_1.QwenImage20ProModel; } });
|
|
15
20
|
const QwenImageEdit_1 = require("./QwenImageEdit");
|
|
16
21
|
Object.defineProperty(exports, "QwenImageEditModel", { enumerable: true, get: function () { return QwenImageEdit_1.QwenImageEditModel; } });
|
|
17
22
|
const QwenSketchToImage_1 = require("./QwenSketchToImage");
|
|
@@ -20,6 +25,8 @@ const QwenStyleRepaintV1_1 = require("./QwenStyleRepaintV1");
|
|
|
20
25
|
Object.defineProperty(exports, "QwenStyleRepaintV1Model", { enumerable: true, get: function () { return QwenStyleRepaintV1_1.QwenStyleRepaintV1Model; } });
|
|
21
26
|
const QwenVlMax_1 = require("./QwenVlMax");
|
|
22
27
|
Object.defineProperty(exports, "QwenVlMax", { enumerable: true, get: function () { return QwenVlMax_1.QwenVlMax; } });
|
|
28
|
+
const TTSModel_1 = require("./TTSModel");
|
|
29
|
+
Object.defineProperty(exports, "SimpleTTSModel", { enumerable: true, get: function () { return TTSModel_1.SimpleTTSModel; } });
|
|
23
30
|
const Wan26Image_1 = require("./Wan26Image");
|
|
24
31
|
Object.defineProperty(exports, "Wan26ImageModel", { enumerable: true, get: function () { return Wan26Image_1.Wan26ImageModel; } });
|
|
25
32
|
const react_1 = require("./react");
|
|
@@ -35,6 +42,15 @@ var ModelName;
|
|
|
35
42
|
ModelName["QwenVlOcr"] = "qwen-vl-ocr";
|
|
36
43
|
ModelName["Wanx21T2iTurbo"] = "wanx2.1-t2i-turbo";
|
|
37
44
|
})(ModelName || (exports.ModelName = ModelName = {}));
|
|
45
|
+
var TTSModelName;
|
|
46
|
+
(function (TTSModelName) {
|
|
47
|
+
TTSModelName["CosyVoiceV35Flash"] = "cosyvoice-v3.5-flash";
|
|
48
|
+
TTSModelName["CosyVoiceV35Plus"] = "cosyvoice-v3.5-plus";
|
|
49
|
+
TTSModelName["CosyVoiceV3Flash"] = "cosyvoice-v3-flash";
|
|
50
|
+
TTSModelName["CosyVoiceV3Plus"] = "cosyvoice-v3-plus";
|
|
51
|
+
TTSModelName["CosyVoiceV2"] = "cosyvoice-v2";
|
|
52
|
+
TTSModelName["CosyVoiceV1"] = "cosyvoice-v1";
|
|
53
|
+
})(TTSModelName || (exports.TTSModelName = TTSModelName = {}));
|
|
38
54
|
var MultiModalModelName;
|
|
39
55
|
(function (MultiModalModelName) {
|
|
40
56
|
MultiModalModelName["QvqMaxLatest"] = "qvq-max-latest";
|
|
@@ -51,6 +67,8 @@ var MultiModalModelName;
|
|
|
51
67
|
MultiModalModelName["Wan26Image"] = "wan2.6-image";
|
|
52
68
|
MultiModalModelName["WanxSketchToImageLite"] = "wanx-sketch-to-image-lite";
|
|
53
69
|
MultiModalModelName["QwenStyleRepaintV1"] = "wanx-style-repaint-v1";
|
|
70
|
+
MultiModalModelName["QwenImage20Pro"] = "qwen-image-2.0-pro";
|
|
71
|
+
MultiModalModelName["QwenImage20"] = "qwen-image-2.0";
|
|
54
72
|
})(MultiModalModelName || (exports.MultiModalModelName = MultiModalModelName = {}));
|
|
55
73
|
exports.modelName = {
|
|
56
74
|
[ModelName.DeepSeekR1]: "deepseek-r1",
|
|
@@ -60,6 +78,12 @@ exports.modelName = {
|
|
|
60
78
|
[ModelName.QwenPlus]: "qwen-plus",
|
|
61
79
|
[ModelName.QwenTurbo]: "qwen-turbo",
|
|
62
80
|
[ModelName.QwenVlOcr]: "qwen-vl-ocr",
|
|
81
|
+
[TTSModelName.CosyVoiceV35Flash]: "cosyvoice-v3.5-flash",
|
|
82
|
+
[TTSModelName.CosyVoiceV35Plus]: "cosyvoice-v3.5-plus",
|
|
83
|
+
[TTSModelName.CosyVoiceV3Flash]: "cosyvoice-v3-flash",
|
|
84
|
+
[TTSModelName.CosyVoiceV3Plus]: "cosyvoice-v3-plus",
|
|
85
|
+
[TTSModelName.CosyVoiceV2]: "cosyvoice-v2",
|
|
86
|
+
[TTSModelName.CosyVoiceV1]: "cosyvoice-v1",
|
|
63
87
|
[MultiModalModelName.QvqMaxLatest]: "qvq-max-latest",
|
|
64
88
|
[MultiModalModelName.QwenVlMax]: "qwen-vl-max",
|
|
65
89
|
[MultiModalModelName.Qwen3VlPlus]: "qwen3-vl-plus",
|
|
@@ -74,6 +98,8 @@ exports.modelName = {
|
|
|
74
98
|
[MultiModalModelName.Wan26Image]: "wan2.6-image",
|
|
75
99
|
[MultiModalModelName.WanxSketchToImageLite]: "wanx-sketch-to-image-lite",
|
|
76
100
|
[MultiModalModelName.QwenStyleRepaintV1]: "wanx-style-repaint-v1",
|
|
101
|
+
[MultiModalModelName.QwenImage20Pro]: "qwen-image-2.0-pro",
|
|
102
|
+
[MultiModalModelName.QwenImage20]: "qwen-image-2.0",
|
|
77
103
|
};
|
|
78
104
|
const isValidModel = (model) => {
|
|
79
105
|
const modelNames = Object.values(exports.modelName);
|
|
@@ -84,6 +110,10 @@ const isMultiModalModel = (model) => {
|
|
|
84
110
|
return Object.values(MultiModalModelName).includes(model);
|
|
85
111
|
};
|
|
86
112
|
exports.isMultiModalModel = isMultiModalModel;
|
|
113
|
+
const isTTSModel = (model) => {
|
|
114
|
+
return Object.values(TTSModelName).includes(model);
|
|
115
|
+
};
|
|
116
|
+
exports.isTTSModel = isTTSModel;
|
|
87
117
|
const toolMap = new Map();
|
|
88
118
|
exports.toolMap = toolMap;
|
|
89
119
|
exports.MODEL_REQUEST_PATTERNS = new Map([
|
|
@@ -136,6 +166,20 @@ exports.MODEL_REQUEST_PATTERNS = new Map([
|
|
|
136
166
|
],
|
|
137
167
|
},
|
|
138
168
|
],
|
|
169
|
+
[
|
|
170
|
+
"qwen-image-2.0-pro",
|
|
171
|
+
{
|
|
172
|
+
domain: "https://dashscope.aliyuncs.com",
|
|
173
|
+
paths: ["api/v1/services/aigc/multimodal-generation/generation"],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
[
|
|
177
|
+
"qwen-image-2.0",
|
|
178
|
+
{
|
|
179
|
+
domain: "https://dashscope.aliyuncs.com",
|
|
180
|
+
paths: ["api/v1/services/aigc/multimodal-generation/generation"],
|
|
181
|
+
},
|
|
182
|
+
],
|
|
139
183
|
[
|
|
140
184
|
"qwen-vl-max",
|
|
141
185
|
{
|
|
@@ -154,7 +198,10 @@ exports.MODEL_REQUEST_PATTERNS = new Map([
|
|
|
154
198
|
"qwen-doc-turbo",
|
|
155
199
|
{
|
|
156
200
|
domain: "https://dashscope.aliyuncs.com",
|
|
157
|
-
paths: [
|
|
201
|
+
paths: [
|
|
202
|
+
"api/v1/services/aigc/text-generation/generation",
|
|
203
|
+
"compatible-mode/v1/chat/completions",
|
|
204
|
+
],
|
|
158
205
|
},
|
|
159
206
|
],
|
|
160
207
|
]);
|
package/lib/models/react.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import type { DoGenerateOutput, DoStreamOutput, ModelRequestOptions, ReqOptions } from "../model-type";
|
|
1
|
+
import type { DoGenerateOutput, DoGenerateSpeechOutput, DoStreamOutput, DoStreamSpeechOutput, ModelRequestOptions, ReqOptions, TTSRequestOptions } from "../model-type";
|
|
2
2
|
import type { SimpleChatModel } from "./Chat";
|
|
3
|
+
import type { SimpleTTSModel } from "./TTSModel";
|
|
3
4
|
export declare class ReActModel {
|
|
4
5
|
private model;
|
|
5
|
-
|
|
6
|
+
private ttsModel;
|
|
7
|
+
constructor(model: SimpleChatModel | SimpleTTSModel);
|
|
6
8
|
generateText(_input: ModelRequestOptions, options?: ReqOptions): Promise<DoGenerateOutput>;
|
|
7
9
|
streamText(_input: ModelRequestOptions, options?: ReqOptions): Promise<DoStreamOutput>;
|
|
10
|
+
streamSpeech(options: TTSRequestOptions): Promise<DoStreamSpeechOutput>;
|
|
11
|
+
generateSpeech(options: TTSRequestOptions): Promise<DoGenerateSpeechOutput>;
|
|
8
12
|
}
|
package/lib/models/react.js
CHANGED
|
@@ -13,6 +13,10 @@ exports.ReActModel = void 0;
|
|
|
13
13
|
class ReActModel {
|
|
14
14
|
constructor(model) {
|
|
15
15
|
this.model = model;
|
|
16
|
+
this.ttsModel = null;
|
|
17
|
+
if ("doStreamSpeech" in model) {
|
|
18
|
+
this.ttsModel = model;
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
generateText(_input, options) {
|
|
18
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -24,5 +28,23 @@ class ReActModel {
|
|
|
24
28
|
return this.model.doStream(_input, options);
|
|
25
29
|
});
|
|
26
30
|
}
|
|
31
|
+
streamSpeech(options) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
console.log("[ReActModel:streamSpeech] called, hasTtsModel:", !!this.ttsModel);
|
|
34
|
+
if (!this.ttsModel) {
|
|
35
|
+
throw new Error("streamSpeech is only available for TTS models (e.g. cosyvoice-v3-flash)");
|
|
36
|
+
}
|
|
37
|
+
return this.ttsModel.doStreamSpeech(options);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
generateSpeech(options) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
console.log("[ReActModel:generateSpeech] called, hasTtsModel:", !!this.ttsModel);
|
|
43
|
+
if (!this.ttsModel) {
|
|
44
|
+
throw new Error("generateSpeech is only available for TTS models (e.g. cosyvoice-v3-flash)");
|
|
45
|
+
}
|
|
46
|
+
return this.ttsModel.doGenerateSpeech(options);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
27
49
|
}
|
|
28
50
|
exports.ReActModel = ReActModel;
|
package/lib/stream.js
CHANGED
|
@@ -42,7 +42,9 @@ class TextDecoderStream {
|
|
|
42
42
|
constructor(encoding = "utf-8", options = {}) {
|
|
43
43
|
this.transform = new exports.TransformStream({
|
|
44
44
|
transform: (chunk, controller) => {
|
|
45
|
-
const value = this.handle.decode(new Uint8Array(chunk), {
|
|
45
|
+
const value = this.handle.decode(new Uint8Array(chunk), {
|
|
46
|
+
stream: true,
|
|
47
|
+
});
|
|
46
48
|
if (value) {
|
|
47
49
|
controller.enqueue(value);
|
|
48
50
|
}
|
|
@@ -98,17 +100,18 @@ function intoStandardStream(stream) {
|
|
|
98
100
|
.pipeThrough((0, exports.createEventSourceParserTransformStream)())
|
|
99
101
|
.pipeThrough(new exports.TransformStream({
|
|
100
102
|
transform(chunk, controller) {
|
|
103
|
+
var _a;
|
|
101
104
|
try {
|
|
105
|
+
if (chunk.data === "[DONE]") {
|
|
106
|
+
console.log("[intoStandardStream] received [DONE], terminating");
|
|
107
|
+
controller.terminate();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
102
110
|
const data = JSON.parse(chunk.data);
|
|
103
111
|
controller.enqueue(data);
|
|
104
112
|
}
|
|
105
113
|
catch (e) {
|
|
106
|
-
|
|
107
|
-
console.warn("Error when transforming event source data to json", e, chunk);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
controller.terminate();
|
|
111
|
-
}
|
|
114
|
+
console.warn("[intoStandardStream] Error parsing SSE data:", e, "raw:", (_a = chunk.data) === null || _a === void 0 ? void 0 : _a.slice(0, 200));
|
|
112
115
|
}
|
|
113
116
|
},
|
|
114
117
|
})));
|
package/lib/tokenManager.js
CHANGED
|
@@ -25,15 +25,25 @@ class TokenManager {
|
|
|
25
25
|
}
|
|
26
26
|
getValidToken() {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const _debug = process.env.VECTORX_DEBUG === "1";
|
|
29
|
+
if (_debug)
|
|
30
|
+
console.log("[TokenManager:getValidToken] fullUrl:", this.fullUrl);
|
|
28
31
|
if (process.env && process.env.RED_LOOK_API_KEY_TEMP) {
|
|
29
|
-
|
|
32
|
+
if (_debug)
|
|
33
|
+
console.log("[TokenManager] using RED_LOOK_API_KEY_TEMP env var");
|
|
30
34
|
return process.env.RED_LOOK_API_KEY_TEMP;
|
|
31
35
|
}
|
|
32
36
|
const now = Math.floor(Date.now() / 1000);
|
|
33
37
|
if (this.currentToken && this.tokenExpiresAt > now + this.refreshBufferSeconds) {
|
|
38
|
+
if (_debug)
|
|
39
|
+
console.log("[TokenManager] reusing cached token, expires in:", this.tokenExpiresAt - now, "s");
|
|
34
40
|
return this.currentToken;
|
|
35
41
|
}
|
|
42
|
+
if (_debug)
|
|
43
|
+
console.log("[TokenManager] refreshing token...");
|
|
36
44
|
yield this.refreshToken();
|
|
45
|
+
if (_debug)
|
|
46
|
+
console.log("[TokenManager] token refreshed successfully");
|
|
37
47
|
return this.currentToken;
|
|
38
48
|
});
|
|
39
49
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorx/ai-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Cloud AI SDK",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
6
7
|
"sideEffects": false,
|
|
7
8
|
"files": [
|
|
8
9
|
"lib",
|
|
9
|
-
"types",
|
|
10
10
|
"README.md"
|
|
11
11
|
],
|
|
12
12
|
"keywords": [
|
|
@@ -18,20 +18,22 @@
|
|
|
18
18
|
"author": "",
|
|
19
19
|
"license": "ISC",
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=20.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@mattiasbuelens/web-streams-adapter": "^0.1.0",
|
|
25
|
-
"@vectorx/ai-types": "1.0.0",
|
|
26
25
|
"langfuse": "^3.38.4",
|
|
27
26
|
"openai": "^4.103.0",
|
|
28
27
|
"text-encoding-shim": "^1.0.5",
|
|
29
28
|
"web-streams-polyfill": "^4.1.0",
|
|
30
|
-
"
|
|
29
|
+
"ws": "^8.18.0",
|
|
30
|
+
"zod": "^3.24.2",
|
|
31
|
+
"@vectorx/ai-types": "1.1.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@types/jest": "^29.5.12",
|
|
34
35
|
"@types/node": "^20.11.24",
|
|
36
|
+
"@types/ws": "^8.5.13",
|
|
35
37
|
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
36
38
|
"@typescript-eslint/parser": "^7.1.0",
|
|
37
39
|
"eslint": "^8.57.0",
|
|
@@ -42,8 +44,8 @@
|
|
|
42
44
|
"scripts": {
|
|
43
45
|
"dev": "tsc -w",
|
|
44
46
|
"build": "rimraf lib types && tsc",
|
|
47
|
+
"scan:models": "python3 scripts/scan-models.py",
|
|
45
48
|
"lint": "eslint 'src/**/*.ts'",
|
|
46
49
|
"fix": "eslint 'src/**/*.ts' --fix"
|
|
47
|
-
}
|
|
48
|
-
"readme": "### 小程序/智能体 ai sdk "
|
|
50
|
+
}
|
|
49
51
|
}
|