@vectorx/ai-types 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ ### 小程序/智能体 ai sdk
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractRequestFactory = exports.AbstractRequest = void 0;
4
+ class AbstractRequest {
5
+ constructor(config = {}) {
6
+ const { timeout, timeoutMsg, restrictedMethods, defaultHeaders = {} } = config;
7
+ this.defaultHeaders = defaultHeaders;
8
+ this.timeout = timeout || 0;
9
+ this.timeoutMsg = timeoutMsg || "请求超时";
10
+ this.restrictedMethods = restrictedMethods || ["get", "post", "upload", "download"];
11
+ }
12
+ getTimeout() {
13
+ return this.timeout;
14
+ }
15
+ getTimeoutMsg() {
16
+ return this.timeoutMsg;
17
+ }
18
+ getRestrictedMethods() {
19
+ return this.restrictedMethods;
20
+ }
21
+ getDefaultHeaders() {
22
+ return this.defaultHeaders;
23
+ }
24
+ isMethodRestricted(method) {
25
+ return this.restrictedMethods.includes(method);
26
+ }
27
+ }
28
+ exports.AbstractRequest = AbstractRequest;
29
+ class AbstractRequestFactory {
30
+ }
31
+ exports.AbstractRequestFactory = AbstractRequestFactory;
package/lib/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractRequestFactory = exports.AbstractRequest = void 0;
4
+ var abstract_request_1 = require("./abstract-request");
5
+ Object.defineProperty(exports, "AbstractRequest", { enumerable: true, get: function () { return abstract_request_1.AbstractRequest; } });
6
+ Object.defineProperty(exports, "AbstractRequestFactory", { enumerable: true, get: function () { return abstract_request_1.AbstractRequestFactory; } });
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@vectorx/ai-types",
3
+ "version": "0.1.0",
4
+ "description": "Cloud AI Types",
5
+ "main": "lib/index.js",
6
+ "types": "types/index.d.ts",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "lib",
10
+ "types",
11
+ "README.md"
12
+ ],
13
+ "keywords": [
14
+ "ai",
15
+ "sdk",
16
+ "cloud",
17
+ "types",
18
+ "typescript"
19
+ ],
20
+ "author": "",
21
+ "license": "ISC",
22
+ "engines": {
23
+ "node": ">=18.0.0"
24
+ },
25
+ "dependencies": {},
26
+ "devDependencies": {
27
+ "@types/jest": "^29.5.12",
28
+ "@types/node": "^20.11.24",
29
+ "@typescript-eslint/eslint-plugin": "^7.1.0",
30
+ "@typescript-eslint/parser": "^7.1.0",
31
+ "eslint": "^8.57.0",
32
+ "jest": "^29.7.0",
33
+ "typescript": "^5.3.3"
34
+ },
35
+ "scripts": {
36
+ "dev": "tsc -w",
37
+ "build": "rimraf lib types && tsc",
38
+ "lint": "eslint 'src/**/*.ts'",
39
+ "fix": "eslint 'src/**/*.ts' --fix"
40
+ },
41
+ "readme": "### 小程序/智能体 ai sdk "
42
+ }
@@ -0,0 +1,64 @@
1
+ export type IRequestMethod = "get" | "post" | "put" | "upload" | "download";
2
+ export interface IRequestConfig {
3
+ timeout?: number;
4
+ timeoutMsg?: string;
5
+ restrictedMethods?: Array<IRequestMethod>;
6
+ defaultHeaders?: Record<string, string>;
7
+ }
8
+ export interface IRequestOptions {
9
+ url?: string;
10
+ headers?: Record<string, string>;
11
+ data?: any;
12
+ responseType?: string;
13
+ withCredentials?: boolean;
14
+ body?: any;
15
+ method?: string;
16
+ file?: File;
17
+ name?: string;
18
+ }
19
+ export interface IFetchOptions {
20
+ url: string;
21
+ headers?: HeadersInit;
22
+ body?: any;
23
+ method?: string;
24
+ enableAbort?: boolean;
25
+ stream?: boolean;
26
+ }
27
+ export interface ResponseObject<T = any> {
28
+ data?: T;
29
+ statusCode?: number;
30
+ [key: string]: any;
31
+ }
32
+ export interface IAbstractRequest {
33
+ get<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
34
+ post<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
35
+ put<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
36
+ upload<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
37
+ download(options: IRequestOptions): Promise<unknown>;
38
+ fetch(options: IFetchOptions): Promise<ResponseObject>;
39
+ }
40
+ export declare abstract class AbstractRequest implements IAbstractRequest {
41
+ protected readonly timeout: number;
42
+ protected readonly timeoutMsg: string;
43
+ protected readonly restrictedMethods: Array<IRequestMethod>;
44
+ protected readonly defaultHeaders: Record<string, string>;
45
+ constructor(config?: IRequestConfig);
46
+ abstract get<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
47
+ abstract post<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
48
+ abstract put<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
49
+ abstract upload<T = any>(options: IRequestOptions): Promise<ResponseObject<T>>;
50
+ abstract download(options: IRequestOptions): Promise<unknown>;
51
+ abstract fetch(options: IFetchOptions): Promise<ResponseObject>;
52
+ protected abstract request(options: IRequestOptions, enableAbort?: boolean): Promise<ResponseObject>;
53
+ protected getTimeout(): number;
54
+ protected getTimeoutMsg(): string;
55
+ protected getRestrictedMethods(): Array<IRequestMethod>;
56
+ protected getDefaultHeaders(): Record<string, string>;
57
+ protected isMethodRestricted(method: IRequestMethod): boolean;
58
+ }
59
+ export interface IRequestFactory {
60
+ create(config?: IRequestConfig): IAbstractRequest;
61
+ }
62
+ export declare abstract class AbstractRequestFactory implements IRequestFactory {
63
+ abstract create(config?: IRequestConfig): IAbstractRequest;
64
+ }
@@ -0,0 +1,2 @@
1
+ export type { IRequestMethod, IRequestConfig, IRequestOptions, IFetchOptions, ResponseObject, IAbstractRequest, IRequestFactory, } from "./abstract-request";
2
+ export { AbstractRequest, AbstractRequestFactory, } from "./abstract-request";