@open-dy/ai_coding_sdk 1.0.19 → 1.0.20
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.
|
@@ -14,7 +14,7 @@ function sleep(ms) {
|
|
|
14
14
|
class AIPlatformLLMClient {
|
|
15
15
|
constructor(options = {}) {
|
|
16
16
|
this.appEnv = (0, core_1.getAIPlatformAppEnv)();
|
|
17
|
-
this.accessToken = options.accessToken;
|
|
17
|
+
this.accessToken = options.accessToken ?? options.delegateToken;
|
|
18
18
|
this.timeoutMs = options.timeoutMs ?? core_1.AI_PLATFORM_DEFAULT_REQUEST_TIMEOUT_MS;
|
|
19
19
|
this.imageTimeoutMs = options.imageTimeoutMs ?? core_1.AI_PLATFORM_DEFAULT_IMAGE_TIMEOUT_MS;
|
|
20
20
|
this.streamTimeoutMs = options.streamTimeoutMs ?? core_1.AI_PLATFORM_DEFAULT_STREAM_TIMEOUT_MS;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AIPlatformCallOptions, AIPlatformEvent, AIPlatformLLMClientOptions, AIPlatformOpenAPIResponse } from './types';
|
|
2
2
|
export type AIPlatformAppEnv = 'DEV' | 'PROD';
|
|
3
|
+
export type AIPlatformRuntimeEnv = 'INNER_SANDBOX' | 'CLOUD_DEV' | 'CLOUD_PROD';
|
|
4
|
+
export declare function getAIPlatformRuntimeEnv(): AIPlatformRuntimeEnv;
|
|
3
5
|
export declare function getAIPlatformAppEnv(): AIPlatformAppEnv;
|
|
4
6
|
export declare function getAIPlatformGatewayOrigin(appEnv?: AIPlatformAppEnv): string;
|
|
5
7
|
export declare function createAIPlatformClientOptions(options?: AIPlatformCallOptions): AIPlatformLLMClientOptions;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AI_PLATFORM_DEFAULT_STREAM_TIMEOUT_MS = exports.AI_PLATFORM_DEFAULT_IMAGE_TIMEOUT_MS = exports.AI_PLATFORM_DEFAULT_REQUEST_TIMEOUT_MS = void 0;
|
|
4
|
+
exports.getAIPlatformRuntimeEnv = getAIPlatformRuntimeEnv;
|
|
4
5
|
exports.getAIPlatformAppEnv = getAIPlatformAppEnv;
|
|
5
6
|
exports.getAIPlatformGatewayOrigin = getAIPlatformGatewayOrigin;
|
|
6
7
|
exports.createAIPlatformClientOptions = createAIPlatformClientOptions;
|
|
@@ -14,11 +15,25 @@ const CLOUD_CALL_DOMAIN_MAP = {
|
|
|
14
15
|
const DEFAULT_REQUEST_TIMEOUT_MS = 60000;
|
|
15
16
|
const DEFAULT_IMAGE_TIMEOUT_MS = 120000;
|
|
16
17
|
const DEFAULT_STREAM_TIMEOUT_MS = 120000;
|
|
17
|
-
function
|
|
18
|
-
|
|
18
|
+
function getCloudEnv() {
|
|
19
|
+
const cloudEnv = process.env.CLOUD_ENV?.trim();
|
|
20
|
+
return cloudEnv ? cloudEnv : undefined;
|
|
21
|
+
}
|
|
22
|
+
function isInnerSandboxEnvironment() {
|
|
23
|
+
return process.env.APP_ENV === 'DEV' && !getCloudEnv();
|
|
24
|
+
}
|
|
25
|
+
function getAIPlatformRuntimeEnv() {
|
|
26
|
+
const cloudEnv = getCloudEnv();
|
|
27
|
+
if (isInnerSandboxEnvironment()) {
|
|
28
|
+
return 'INNER_SANDBOX';
|
|
29
|
+
}
|
|
30
|
+
if (cloudEnv === 'DEV') {
|
|
31
|
+
return 'CLOUD_DEV';
|
|
32
|
+
}
|
|
33
|
+
return 'CLOUD_PROD';
|
|
19
34
|
}
|
|
20
35
|
function getAIPlatformAppEnv() {
|
|
21
|
-
return
|
|
36
|
+
return isInnerSandboxEnvironment() ? 'DEV' : 'PROD';
|
|
22
37
|
}
|
|
23
38
|
function getAIPlatformGatewayOrigin(appEnv = getAIPlatformAppEnv()) {
|
|
24
39
|
if (appEnv === 'DEV') {
|
|
@@ -33,7 +48,7 @@ function createAIPlatformClientOptions(options) {
|
|
|
33
48
|
...(options?.logid ? { 'x-tt-logid': options.logid } : {}),
|
|
34
49
|
};
|
|
35
50
|
return {
|
|
36
|
-
accessToken: options?.accessToken,
|
|
51
|
+
accessToken: options?.accessToken ?? options?.delegateToken,
|
|
37
52
|
timeoutMs: options?.timeoutMs,
|
|
38
53
|
defaultHeaders,
|
|
39
54
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { AIPlatformLLMClient, generate, generateImage, generateVideo, queryVideoTask, streamGenerate, waitVideoTask } from './client';
|
|
2
|
-
export { AI_PLATFORM_DEFAULT_IMAGE_TIMEOUT_MS, AI_PLATFORM_DEFAULT_REQUEST_TIMEOUT_MS, AI_PLATFORM_DEFAULT_STREAM_TIMEOUT_MS, createAIPlatformClientOptions, getAIPlatformAppEnv, getAIPlatformGatewayOrigin, parseSSEStream, postAIPlatformJSON, streamAIPlatform } from './core';
|
|
2
|
+
export { AI_PLATFORM_DEFAULT_IMAGE_TIMEOUT_MS, AI_PLATFORM_DEFAULT_REQUEST_TIMEOUT_MS, AI_PLATFORM_DEFAULT_STREAM_TIMEOUT_MS, createAIPlatformClientOptions, getAIPlatformAppEnv, getAIPlatformGatewayOrigin, getAIPlatformRuntimeEnv, parseSSEStream, postAIPlatformJSON, streamAIPlatform } from './core';
|
|
3
|
+
export type { AIPlatformRuntimeEnv } from './core';
|
|
3
4
|
export type { AIPlatformCallOptions, AIPlatformEvent, AIPlatformLLMClientOptions, AIPlatformMessageEventPayload, AIPlatformOpenAPIResponse, AIPlatformUsage, ContentPart, GenerateImageRequest, GenerateImageResponseData, GenerateMessage, GenerateModelParams, GenerateRequest, GenerateResponseData, GenerateVideoRequest, GenerateVideoResponseData, Message, ModelParams, QueryVideoTaskRequest, QueryVideoTaskResponseData, Role, StreamGenerateRequest, ToolCall } from './types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.streamAIPlatform = exports.postAIPlatformJSON = exports.parseSSEStream = exports.getAIPlatformGatewayOrigin = exports.getAIPlatformAppEnv = exports.createAIPlatformClientOptions = exports.AI_PLATFORM_DEFAULT_STREAM_TIMEOUT_MS = exports.AI_PLATFORM_DEFAULT_REQUEST_TIMEOUT_MS = exports.AI_PLATFORM_DEFAULT_IMAGE_TIMEOUT_MS = exports.waitVideoTask = exports.streamGenerate = exports.queryVideoTask = exports.generateVideo = exports.generateImage = exports.generate = exports.AIPlatformLLMClient = void 0;
|
|
3
|
+
exports.streamAIPlatform = exports.postAIPlatformJSON = exports.parseSSEStream = exports.getAIPlatformRuntimeEnv = exports.getAIPlatformGatewayOrigin = exports.getAIPlatformAppEnv = exports.createAIPlatformClientOptions = exports.AI_PLATFORM_DEFAULT_STREAM_TIMEOUT_MS = exports.AI_PLATFORM_DEFAULT_REQUEST_TIMEOUT_MS = exports.AI_PLATFORM_DEFAULT_IMAGE_TIMEOUT_MS = exports.waitVideoTask = exports.streamGenerate = exports.queryVideoTask = exports.generateVideo = exports.generateImage = exports.generate = exports.AIPlatformLLMClient = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "AIPlatformLLMClient", { enumerable: true, get: function () { return client_1.AIPlatformLLMClient; } });
|
|
6
6
|
Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return client_1.generate; } });
|
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "AI_PLATFORM_DEFAULT_STREAM_TIMEOUT_MS", { enumer
|
|
|
16
16
|
Object.defineProperty(exports, "createAIPlatformClientOptions", { enumerable: true, get: function () { return core_1.createAIPlatformClientOptions; } });
|
|
17
17
|
Object.defineProperty(exports, "getAIPlatformAppEnv", { enumerable: true, get: function () { return core_1.getAIPlatformAppEnv; } });
|
|
18
18
|
Object.defineProperty(exports, "getAIPlatformGatewayOrigin", { enumerable: true, get: function () { return core_1.getAIPlatformGatewayOrigin; } });
|
|
19
|
+
Object.defineProperty(exports, "getAIPlatformRuntimeEnv", { enumerable: true, get: function () { return core_1.getAIPlatformRuntimeEnv; } });
|
|
19
20
|
Object.defineProperty(exports, "parseSSEStream", { enumerable: true, get: function () { return core_1.parseSSEStream; } });
|
|
20
21
|
Object.defineProperty(exports, "postAIPlatformJSON", { enumerable: true, get: function () { return core_1.postAIPlatformJSON; } });
|
|
21
22
|
Object.defineProperty(exports, "streamAIPlatform", { enumerable: true, get: function () { return core_1.streamAIPlatform; } });
|
|
@@ -280,6 +280,12 @@ export interface QueryVideoTaskResponseData {
|
|
|
280
280
|
}
|
|
281
281
|
export interface AIPlatformLLMClientOptions {
|
|
282
282
|
accessToken?: string;
|
|
283
|
+
/**
|
|
284
|
+
* `accessToken` 的兼容别名。
|
|
285
|
+
*
|
|
286
|
+
* @deprecated 请改用 `accessToken`。
|
|
287
|
+
*/
|
|
288
|
+
delegateToken?: string;
|
|
283
289
|
timeoutMs?: number;
|
|
284
290
|
imageTimeoutMs?: number;
|
|
285
291
|
streamTimeoutMs?: number;
|
|
@@ -288,6 +294,12 @@ export interface AIPlatformLLMClientOptions {
|
|
|
288
294
|
}
|
|
289
295
|
export interface AIPlatformCallOptions {
|
|
290
296
|
accessToken?: string;
|
|
297
|
+
/**
|
|
298
|
+
* `accessToken` 的兼容别名。
|
|
299
|
+
*
|
|
300
|
+
* @deprecated 请改用 `accessToken`。
|
|
301
|
+
*/
|
|
302
|
+
delegateToken?: string;
|
|
291
303
|
logid?: string;
|
|
292
304
|
timeoutMs?: number;
|
|
293
305
|
defaultHeaders?: Record<string, string>;
|