@ai-sdk/gmicloud 2.0.1 → 3.0.2
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/CHANGELOG.md +17 -4
- package/dist/index.d.ts +5 -5
- package/dist/index.js +43 -52
- package/dist/index.js.map +1 -1
- package/package.json +10 -11
- package/src/gmicloud-chat-language-model.ts +29 -1
- package/src/gmicloud-provider.ts +7 -7
- package/dist/index.d.mts +0 -62
- package/dist/index.mjs +0 -99
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
# @ai-sdk/gmicloud
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 3.0.2
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- Updated dependencies [
|
|
8
|
-
- @ai-sdk/
|
|
9
|
-
|
|
7
|
+
- Updated dependencies [86892f3]
|
|
8
|
+
- @ai-sdk/openai-compatible@3.0.31
|
|
9
|
+
|
|
10
|
+
## 3.0.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [7fbfc6d]
|
|
15
|
+
- @ai-sdk/provider-utils@5.0.27
|
|
16
|
+
- @ai-sdk/openai-compatible@3.0.30
|
|
17
|
+
|
|
18
|
+
## 3.0.0
|
|
19
|
+
|
|
20
|
+
### Major Changes
|
|
21
|
+
|
|
22
|
+
- 74556f7: feat(gmicloud): add GMI Cloud provider with OpenAI-compatible chat completions and unwrapped error diagnostics
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
|
|
@@ -25,19 +25,19 @@ interface GmicloudProviderSettings {
|
|
|
25
25
|
*/
|
|
26
26
|
fetch?: FetchFunction;
|
|
27
27
|
}
|
|
28
|
-
interface GmicloudProvider extends
|
|
28
|
+
interface GmicloudProvider extends ProviderV4 {
|
|
29
29
|
/**
|
|
30
30
|
* Creates a GMI Cloud model for text generation.
|
|
31
31
|
*/
|
|
32
|
-
(modelId: GmicloudChatModelId):
|
|
32
|
+
(modelId: GmicloudChatModelId): LanguageModelV4;
|
|
33
33
|
/**
|
|
34
34
|
* Creates a GMI Cloud model for text generation.
|
|
35
35
|
*/
|
|
36
|
-
languageModel(modelId: GmicloudChatModelId):
|
|
36
|
+
languageModel(modelId: GmicloudChatModelId): LanguageModelV4;
|
|
37
37
|
/**
|
|
38
38
|
* Creates a GMI Cloud chat model for text generation.
|
|
39
39
|
*/
|
|
40
|
-
chat(modelId: GmicloudChatModelId):
|
|
40
|
+
chat(modelId: GmicloudChatModelId): LanguageModelV4;
|
|
41
41
|
/**
|
|
42
42
|
* @deprecated Use `embeddingModel` instead.
|
|
43
43
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,50 +1,42 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
VERSION: () => VERSION,
|
|
24
|
-
createGmicloud: () => createGmicloud,
|
|
25
|
-
gmicloud: () => gmicloud
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/gmicloud-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadApiKey,
|
|
7
|
+
withoutTrailingSlash,
|
|
8
|
+
withUserAgentSuffix
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
32
10
|
|
|
33
11
|
// src/gmicloud-chat-language-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
import { OpenAICompatibleChatLanguageModel } from "@ai-sdk/openai-compatible";
|
|
13
|
+
import {
|
|
14
|
+
serializeModelOptions,
|
|
15
|
+
WORKFLOW_DESERIALIZE,
|
|
16
|
+
WORKFLOW_SERIALIZE
|
|
17
|
+
} from "@ai-sdk/provider-utils";
|
|
18
|
+
var GmicloudChatLanguageModel = class _GmicloudChatLanguageModel extends OpenAICompatibleChatLanguageModel {
|
|
19
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
20
|
+
return serializeModelOptions({
|
|
21
|
+
modelId: model.modelId,
|
|
22
|
+
config: model.config
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
26
|
+
return new _GmicloudChatLanguageModel(options.modelId, options.config);
|
|
27
|
+
}
|
|
36
28
|
};
|
|
37
29
|
|
|
38
30
|
// src/gmicloud-error.ts
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var gmicloudErrorDataSchema =
|
|
42
|
-
error:
|
|
43
|
-
message:
|
|
44
|
-
type:
|
|
45
|
-
param:
|
|
46
|
-
code:
|
|
47
|
-
details:
|
|
31
|
+
import { secureJsonParse } from "@ai-sdk/provider-utils";
|
|
32
|
+
import { z } from "zod/v4";
|
|
33
|
+
var gmicloudErrorDataSchema = z.object({
|
|
34
|
+
error: z.object({
|
|
35
|
+
message: z.string(),
|
|
36
|
+
type: z.string().nullish(),
|
|
37
|
+
param: z.any().nullish(),
|
|
38
|
+
code: z.union([z.string(), z.number()]).nullish(),
|
|
39
|
+
details: z.string().nullish()
|
|
48
40
|
})
|
|
49
41
|
});
|
|
50
42
|
function unwrapDetailsMessage(details) {
|
|
@@ -54,7 +46,7 @@ function unwrapDetailsMessage(details) {
|
|
|
54
46
|
}
|
|
55
47
|
let parsed;
|
|
56
48
|
try {
|
|
57
|
-
parsed =
|
|
49
|
+
parsed = secureJsonParse(details);
|
|
58
50
|
} catch (e) {
|
|
59
51
|
return void 0;
|
|
60
52
|
}
|
|
@@ -70,17 +62,17 @@ var gmicloudErrorStructure = {
|
|
|
70
62
|
};
|
|
71
63
|
|
|
72
64
|
// src/version.ts
|
|
73
|
-
var VERSION = true ? "
|
|
65
|
+
var VERSION = true ? "3.0.2" : "0.0.0-test";
|
|
74
66
|
|
|
75
67
|
// src/gmicloud-provider.ts
|
|
76
68
|
function createGmicloud(options = {}) {
|
|
77
69
|
var _a;
|
|
78
|
-
const baseURL =
|
|
70
|
+
const baseURL = withoutTrailingSlash(
|
|
79
71
|
(_a = options.baseURL) != null ? _a : "https://api.gmi-serving.com/v1"
|
|
80
72
|
);
|
|
81
|
-
const getHeaders = () =>
|
|
73
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
82
74
|
{
|
|
83
|
-
Authorization: `Bearer ${
|
|
75
|
+
Authorization: `Bearer ${loadApiKey({
|
|
84
76
|
apiKey: options.apiKey,
|
|
85
77
|
environmentVariableName: "GMI_CLOUD_APIKEY",
|
|
86
78
|
description: "GMI Cloud API key"
|
|
@@ -100,23 +92,22 @@ function createGmicloud(options = {}) {
|
|
|
100
92
|
});
|
|
101
93
|
};
|
|
102
94
|
const provider = (modelId) => createLanguageModel(modelId);
|
|
103
|
-
provider.specificationVersion = "
|
|
95
|
+
provider.specificationVersion = "v4";
|
|
104
96
|
provider.languageModel = createLanguageModel;
|
|
105
97
|
provider.chat = createLanguageModel;
|
|
106
98
|
provider.embeddingModel = (modelId) => {
|
|
107
|
-
throw new
|
|
99
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
108
100
|
};
|
|
109
101
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
110
102
|
provider.imageModel = (modelId) => {
|
|
111
|
-
throw new
|
|
103
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
112
104
|
};
|
|
113
105
|
return provider;
|
|
114
106
|
}
|
|
115
107
|
var gmicloud = createGmicloud();
|
|
116
|
-
|
|
117
|
-
0 && (module.exports = {
|
|
108
|
+
export {
|
|
118
109
|
VERSION,
|
|
119
110
|
createGmicloud,
|
|
120
111
|
gmicloud
|
|
121
|
-
}
|
|
112
|
+
};
|
|
122
113
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/gmicloud-provider.ts","../src/gmicloud-chat-language-model.ts","../src/gmicloud-error.ts","../src/version.ts"],"sourcesContent":["import {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { GmicloudChatLanguageModel } from './gmicloud-chat-language-model';\nimport type { GmicloudChatModelId } from './gmicloud-chat-options';\nimport { gmicloudErrorStructure } from './gmicloud-error';\nimport { VERSION } from './version';\n\nexport interface GmicloudProviderSettings {\n /**\n * GMI Cloud API key. Defaults to the `GMI_CLOUD_APIKEY` environment\n * variable (matching GMI's own SDK package).\n */\n apiKey?: string;\n /**\n * Base URL for the API calls. Defaults to\n * `https://api.gmi-serving.com/v1`.\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept\n * requests, or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface GmicloudProvider extends ProviderV4 {\n /**\n * Creates a GMI Cloud model for text generation.\n */\n (modelId: GmicloudChatModelId): LanguageModelV4;\n\n /**\n * Creates a GMI Cloud model for text generation.\n */\n languageModel(modelId: GmicloudChatModelId): LanguageModelV4;\n\n /**\n * Creates a GMI Cloud chat model for text generation.\n */\n chat(modelId: GmicloudChatModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport function createGmicloud(\n options: GmicloudProviderSettings = {},\n): GmicloudProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.gmi-serving.com/v1',\n );\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'GMI_CLOUD_APIKEY',\n description: 'GMI Cloud API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk/gmicloud/${VERSION}`,\n );\n\n const createLanguageModel = (modelId: GmicloudChatModelId) => {\n return new GmicloudChatLanguageModel(modelId, {\n provider: `gmicloud.chat`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n errorStructure: gmicloudErrorStructure,\n includeUsage: true,\n });\n };\n\n const provider = (modelId: GmicloudChatModelId) =>\n createLanguageModel(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createLanguageModel;\n provider.chat = createLanguageModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n\nexport const gmicloud = createGmicloud();\n","import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';\nimport type { LanguageModelV4 } from '@ai-sdk/provider';\nimport {\n serializeModelOptions,\n WORKFLOW_DESERIALIZE,\n WORKFLOW_SERIALIZE,\n} from '@ai-sdk/provider-utils';\nimport type { GmicloudChatModelId } from './gmicloud-chat-language-model-options';\n\ntype GmicloudChatConfig = ConstructorParameters<\n typeof OpenAICompatibleChatLanguageModel\n>[1];\n\n/**\n * GMI Cloud chat completions over the OpenAI-compatible protocol. The only\n * customization is the error structure (see ./gmicloud-error.ts): GMI's edge\n * nests the backend engine's diagnostic in `error.details`, which the default\n * OpenAI-compatible error handling drops.\n */\nexport class GmicloudChatLanguageModel\n extends OpenAICompatibleChatLanguageModel\n implements LanguageModelV4\n{\n static [WORKFLOW_SERIALIZE](model: GmicloudChatLanguageModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: GmicloudChatModelId;\n config: GmicloudChatConfig;\n }) {\n return new GmicloudChatLanguageModel(options.modelId, options.config);\n }\n}\n","import type { ProviderErrorStructure } from '@ai-sdk/openai-compatible';\nimport { secureJsonParse } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\nexport const gmicloudErrorDataSchema = z.object({\n error: z.object({\n message: z.string(),\n type: z.string().nullish(),\n param: z.any().nullish(),\n code: z.union([z.string(), z.number()]).nullish(),\n details: z.string().nullish(),\n }),\n});\n\nexport type GmicloudErrorData = z.infer<typeof gmicloudErrorDataSchema>;\n\nfunction unwrapDetailsMessage(details: string | null | undefined) {\n if (details == null || details === '') {\n return undefined;\n }\n let parsed: unknown;\n try {\n parsed = secureJsonParse(details);\n } catch {\n return undefined;\n }\n const message = (parsed as { error?: { message?: unknown } })?.error?.message;\n return typeof message === 'string' && message.trim() !== ''\n ? message\n : undefined;\n}\n\nexport const gmicloudErrorStructure: ProviderErrorStructure<GmicloudErrorData> =\n {\n errorSchema: gmicloudErrorDataSchema,\n errorToMessage: data =>\n unwrapDetailsMessage(data.error.details) ?? data.error.message,\n };\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACVP,SAAS,yCAAyC;AAElD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAaA,IAAM,4BAAN,MAAM,mCACH,kCAEV;AAAA,EACE,QAAQ,kBAAkB,EAAE,OAAkC;AAC5D,WAAO,sBAAsB;AAAA,MAC3B,SAAS,MAAM;AAAA,MACf,QAAQ,MAAM;AAAA,IAChB,CAAC;AAAA,EACH;AAAA,EAEA,QAAQ,oBAAoB,EAAE,SAG3B;AACD,WAAO,IAAI,2BAA0B,QAAQ,SAAS,QAAQ,MAAM;AAAA,EACtE;AACF;;;ACnCA,SAAS,uBAAuB;AAChC,SAAS,SAAS;AAEX,IAAM,0BAA0B,EAAE,OAAO;AAAA,EAC9C,OAAO,EAAE,OAAO;AAAA,IACd,SAAS,EAAE,OAAO;AAAA,IAClB,MAAM,EAAE,OAAO,EAAE,QAAQ;AAAA,IACzB,OAAO,EAAE,IAAI,EAAE,QAAQ;AAAA,IACvB,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,QAAQ;AAAA,IAChD,SAAS,EAAE,OAAO,EAAE,QAAQ;AAAA,EAC9B,CAAC;AACH,CAAC;AAID,SAAS,qBAAqB,SAAoC;AAhBlE;AAiBE,MAAI,WAAW,QAAQ,YAAY,IAAI;AACrC,WAAO;AAAA,EACT;AACA,MAAI;AACJ,MAAI;AACF,aAAS,gBAAgB,OAAO;AAAA,EAClC,SAAQ;AACN,WAAO;AAAA,EACT;AACA,QAAM,WAAW,sCAA8C,UAA9C,mBAAqD;AACtE,SAAO,OAAO,YAAY,YAAY,QAAQ,KAAK,MAAM,KACrD,UACA;AACN;AAEO,IAAM,yBACX;AAAA,EACE,aAAa;AAAA,EACb,gBAAgB,UAAK;AAnCzB;AAoCM,sCAAqB,KAAK,MAAM,OAAO,MAAvC,YAA4C,KAAK,MAAM;AAAA;AAC3D;;;ACnCK,IAAM,UACX,OACI,UACA;;;AHuDC,SAAS,eACd,UAAoC,CAAC,GACnB;AA9DpB;AA+DE,QAAM,UAAU;AAAA,KACd,aAAQ,YAAR,YAAmB;AAAA,EACrB;AACA,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,eAAe,UAAU,WAAW;AAAA,QAClC,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC,CAAC;AAAA,MACF,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,mBAAmB,OAAO;AAAA,EAC5B;AAEF,QAAM,sBAAsB,CAAC,YAAiC;AAC5D,WAAO,IAAI,0BAA0B,SAAS;AAAA,MAC5C,UAAU;AAAA,MACV,KAAK,CAAC,EAAE,KAAK,MAAM,GAAG,OAAO,GAAG,IAAI;AAAA,MACpC,SAAS;AAAA,MACT,OAAO,QAAQ;AAAA,MACf,gBAAgB;AAAA,MAChB,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AAEA,QAAM,WAAW,CAAC,YAChB,oBAAoB,OAAO;AAE7B,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAEhB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAEO,IAAM,WAAW,eAAe;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/gmicloud",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "3.0.2",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
|
-
"module": "./dist/index.mjs",
|
|
9
8
|
"types": "./dist/index.d.ts",
|
|
10
9
|
"files": [
|
|
11
10
|
"dist/**/*",
|
|
@@ -25,18 +24,18 @@
|
|
|
25
24
|
"./package.json": "./package.json",
|
|
26
25
|
".": {
|
|
27
26
|
"types": "./dist/index.d.ts",
|
|
28
|
-
"import": "./dist/index.
|
|
29
|
-
"
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"default": "./dist/index.js"
|
|
30
29
|
}
|
|
31
30
|
},
|
|
32
31
|
"dependencies": {
|
|
33
|
-
"@ai-sdk/openai-compatible": "
|
|
34
|
-
"@ai-sdk/provider": "
|
|
35
|
-
"@ai-sdk/provider-utils": "
|
|
32
|
+
"@ai-sdk/openai-compatible": "3.0.31",
|
|
33
|
+
"@ai-sdk/provider": "4.0.7",
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.27"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
|
-
"@types/node": "
|
|
39
|
-
"tsup": "^8",
|
|
37
|
+
"@types/node": "22.19.19",
|
|
38
|
+
"tsup": "^8.5.1",
|
|
40
39
|
"typescript": "5.8.3",
|
|
41
40
|
"zod": "3.25.76",
|
|
42
41
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
@@ -45,7 +44,7 @@
|
|
|
45
44
|
"zod": "^3.25.76 || ^4.1.8"
|
|
46
45
|
},
|
|
47
46
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
47
|
+
"node": ">=22"
|
|
49
48
|
},
|
|
50
49
|
"publishConfig": {
|
|
51
50
|
"access": "public",
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';
|
|
2
|
+
import type { LanguageModelV4 } from '@ai-sdk/provider';
|
|
3
|
+
import {
|
|
4
|
+
serializeModelOptions,
|
|
5
|
+
WORKFLOW_DESERIALIZE,
|
|
6
|
+
WORKFLOW_SERIALIZE,
|
|
7
|
+
} from '@ai-sdk/provider-utils';
|
|
8
|
+
import type { GmicloudChatModelId } from './gmicloud-chat-language-model-options';
|
|
9
|
+
|
|
10
|
+
type GmicloudChatConfig = ConstructorParameters<
|
|
11
|
+
typeof OpenAICompatibleChatLanguageModel
|
|
12
|
+
>[1];
|
|
2
13
|
|
|
3
14
|
/**
|
|
4
15
|
* GMI Cloud chat completions over the OpenAI-compatible protocol. The only
|
|
@@ -6,4 +17,21 @@ import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';
|
|
|
6
17
|
* nests the backend engine's diagnostic in `error.details`, which the default
|
|
7
18
|
* OpenAI-compatible error handling drops.
|
|
8
19
|
*/
|
|
9
|
-
export class GmicloudChatLanguageModel
|
|
20
|
+
export class GmicloudChatLanguageModel
|
|
21
|
+
extends OpenAICompatibleChatLanguageModel
|
|
22
|
+
implements LanguageModelV4
|
|
23
|
+
{
|
|
24
|
+
static [WORKFLOW_SERIALIZE](model: GmicloudChatLanguageModel) {
|
|
25
|
+
return serializeModelOptions({
|
|
26
|
+
modelId: model.modelId,
|
|
27
|
+
config: model.config,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
32
|
+
modelId: GmicloudChatModelId;
|
|
33
|
+
config: GmicloudChatConfig;
|
|
34
|
+
}) {
|
|
35
|
+
return new GmicloudChatLanguageModel(options.modelId, options.config);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/gmicloud-provider.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NoSuchModelError,
|
|
3
|
-
type
|
|
4
|
-
type
|
|
3
|
+
type LanguageModelV4,
|
|
4
|
+
type ProviderV4,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
loadApiKey,
|
|
@@ -36,21 +36,21 @@ export interface GmicloudProviderSettings {
|
|
|
36
36
|
fetch?: FetchFunction;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export interface GmicloudProvider extends
|
|
39
|
+
export interface GmicloudProvider extends ProviderV4 {
|
|
40
40
|
/**
|
|
41
41
|
* Creates a GMI Cloud model for text generation.
|
|
42
42
|
*/
|
|
43
|
-
(modelId: GmicloudChatModelId):
|
|
43
|
+
(modelId: GmicloudChatModelId): LanguageModelV4;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Creates a GMI Cloud model for text generation.
|
|
47
47
|
*/
|
|
48
|
-
languageModel(modelId: GmicloudChatModelId):
|
|
48
|
+
languageModel(modelId: GmicloudChatModelId): LanguageModelV4;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Creates a GMI Cloud chat model for text generation.
|
|
52
52
|
*/
|
|
53
|
-
chat(modelId: GmicloudChatModelId):
|
|
53
|
+
chat(modelId: GmicloudChatModelId): LanguageModelV4;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* @deprecated Use `embeddingModel` instead.
|
|
@@ -91,7 +91,7 @@ export function createGmicloud(
|
|
|
91
91
|
const provider = (modelId: GmicloudChatModelId) =>
|
|
92
92
|
createLanguageModel(modelId);
|
|
93
93
|
|
|
94
|
-
provider.specificationVersion = '
|
|
94
|
+
provider.specificationVersion = 'v4' as const;
|
|
95
95
|
provider.languageModel = createLanguageModel;
|
|
96
96
|
provider.chat = createLanguageModel;
|
|
97
97
|
|
package/dist/index.d.mts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
2
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { z } from 'zod/v4';
|
|
4
|
-
|
|
5
|
-
type GmicloudChatModelId = 'deepseek-ai/DeepSeek-V4-Flash-0731' | 'Qwen/Qwen3.8-Max' | 'moonshotai/kimi-k3' | 'zai-org/GLM-5.2-FP8' | 'MiniMaxAI/MiniMax-M3' | (string & {});
|
|
6
|
-
|
|
7
|
-
interface GmicloudProviderSettings {
|
|
8
|
-
/**
|
|
9
|
-
* GMI Cloud API key. Defaults to the `GMI_CLOUD_APIKEY` environment
|
|
10
|
-
* variable (matching GMI's own SDK package).
|
|
11
|
-
*/
|
|
12
|
-
apiKey?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Base URL for the API calls. Defaults to
|
|
15
|
-
* `https://api.gmi-serving.com/v1`.
|
|
16
|
-
*/
|
|
17
|
-
baseURL?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Custom headers to include in the requests.
|
|
20
|
-
*/
|
|
21
|
-
headers?: Record<string, string>;
|
|
22
|
-
/**
|
|
23
|
-
* Custom fetch implementation. You can use it as a middleware to intercept
|
|
24
|
-
* requests, or to provide a custom fetch implementation for e.g. testing.
|
|
25
|
-
*/
|
|
26
|
-
fetch?: FetchFunction;
|
|
27
|
-
}
|
|
28
|
-
interface GmicloudProvider extends ProviderV3 {
|
|
29
|
-
/**
|
|
30
|
-
* Creates a GMI Cloud model for text generation.
|
|
31
|
-
*/
|
|
32
|
-
(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
33
|
-
/**
|
|
34
|
-
* Creates a GMI Cloud model for text generation.
|
|
35
|
-
*/
|
|
36
|
-
languageModel(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a GMI Cloud chat model for text generation.
|
|
39
|
-
*/
|
|
40
|
-
chat(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
41
|
-
/**
|
|
42
|
-
* @deprecated Use `embeddingModel` instead.
|
|
43
|
-
*/
|
|
44
|
-
textEmbeddingModel(modelId: string): never;
|
|
45
|
-
}
|
|
46
|
-
declare function createGmicloud(options?: GmicloudProviderSettings): GmicloudProvider;
|
|
47
|
-
declare const gmicloud: GmicloudProvider;
|
|
48
|
-
|
|
49
|
-
declare const gmicloudErrorDataSchema: z.ZodObject<{
|
|
50
|
-
error: z.ZodObject<{
|
|
51
|
-
message: z.ZodString;
|
|
52
|
-
type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
53
|
-
param: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
|
|
54
|
-
code: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
55
|
-
details: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
56
|
-
}, z.core.$strip>;
|
|
57
|
-
}, z.core.$strip>;
|
|
58
|
-
type GmicloudErrorData = z.infer<typeof gmicloudErrorDataSchema>;
|
|
59
|
-
|
|
60
|
-
declare const VERSION: string;
|
|
61
|
-
|
|
62
|
-
export { type GmicloudErrorData, type GmicloudProvider, type GmicloudProviderSettings, VERSION, createGmicloud, gmicloud };
|
package/dist/index.mjs
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// src/gmicloud-provider.ts
|
|
2
|
-
import {
|
|
3
|
-
NoSuchModelError
|
|
4
|
-
} from "@ai-sdk/provider";
|
|
5
|
-
import {
|
|
6
|
-
loadApiKey,
|
|
7
|
-
withoutTrailingSlash,
|
|
8
|
-
withUserAgentSuffix
|
|
9
|
-
} from "@ai-sdk/provider-utils";
|
|
10
|
-
|
|
11
|
-
// src/gmicloud-chat-language-model.ts
|
|
12
|
-
import { OpenAICompatibleChatLanguageModel } from "@ai-sdk/openai-compatible";
|
|
13
|
-
var GmicloudChatLanguageModel = class extends OpenAICompatibleChatLanguageModel {
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// src/gmicloud-error.ts
|
|
17
|
-
import { secureJsonParse } from "@ai-sdk/provider-utils";
|
|
18
|
-
import { z } from "zod/v4";
|
|
19
|
-
var gmicloudErrorDataSchema = z.object({
|
|
20
|
-
error: z.object({
|
|
21
|
-
message: z.string(),
|
|
22
|
-
type: z.string().nullish(),
|
|
23
|
-
param: z.any().nullish(),
|
|
24
|
-
code: z.union([z.string(), z.number()]).nullish(),
|
|
25
|
-
details: z.string().nullish()
|
|
26
|
-
})
|
|
27
|
-
});
|
|
28
|
-
function unwrapDetailsMessage(details) {
|
|
29
|
-
var _a;
|
|
30
|
-
if (details == null || details === "") {
|
|
31
|
-
return void 0;
|
|
32
|
-
}
|
|
33
|
-
let parsed;
|
|
34
|
-
try {
|
|
35
|
-
parsed = secureJsonParse(details);
|
|
36
|
-
} catch (e) {
|
|
37
|
-
return void 0;
|
|
38
|
-
}
|
|
39
|
-
const message = (_a = parsed == null ? void 0 : parsed.error) == null ? void 0 : _a.message;
|
|
40
|
-
return typeof message === "string" && message.trim() !== "" ? message : void 0;
|
|
41
|
-
}
|
|
42
|
-
var gmicloudErrorStructure = {
|
|
43
|
-
errorSchema: gmicloudErrorDataSchema,
|
|
44
|
-
errorToMessage: (data) => {
|
|
45
|
-
var _a;
|
|
46
|
-
return (_a = unwrapDetailsMessage(data.error.details)) != null ? _a : data.error.message;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// src/version.ts
|
|
51
|
-
var VERSION = true ? "2.0.1" : "0.0.0-test";
|
|
52
|
-
|
|
53
|
-
// src/gmicloud-provider.ts
|
|
54
|
-
function createGmicloud(options = {}) {
|
|
55
|
-
var _a;
|
|
56
|
-
const baseURL = withoutTrailingSlash(
|
|
57
|
-
(_a = options.baseURL) != null ? _a : "https://api.gmi-serving.com/v1"
|
|
58
|
-
);
|
|
59
|
-
const getHeaders = () => withUserAgentSuffix(
|
|
60
|
-
{
|
|
61
|
-
Authorization: `Bearer ${loadApiKey({
|
|
62
|
-
apiKey: options.apiKey,
|
|
63
|
-
environmentVariableName: "GMI_CLOUD_APIKEY",
|
|
64
|
-
description: "GMI Cloud API key"
|
|
65
|
-
})}`,
|
|
66
|
-
...options.headers
|
|
67
|
-
},
|
|
68
|
-
`ai-sdk/gmicloud/${VERSION}`
|
|
69
|
-
);
|
|
70
|
-
const createLanguageModel = (modelId) => {
|
|
71
|
-
return new GmicloudChatLanguageModel(modelId, {
|
|
72
|
-
provider: `gmicloud.chat`,
|
|
73
|
-
url: ({ path }) => `${baseURL}${path}`,
|
|
74
|
-
headers: getHeaders,
|
|
75
|
-
fetch: options.fetch,
|
|
76
|
-
errorStructure: gmicloudErrorStructure,
|
|
77
|
-
includeUsage: true
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
const provider = (modelId) => createLanguageModel(modelId);
|
|
81
|
-
provider.specificationVersion = "v3";
|
|
82
|
-
provider.languageModel = createLanguageModel;
|
|
83
|
-
provider.chat = createLanguageModel;
|
|
84
|
-
provider.embeddingModel = (modelId) => {
|
|
85
|
-
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
86
|
-
};
|
|
87
|
-
provider.textEmbeddingModel = provider.embeddingModel;
|
|
88
|
-
provider.imageModel = (modelId) => {
|
|
89
|
-
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
90
|
-
};
|
|
91
|
-
return provider;
|
|
92
|
-
}
|
|
93
|
-
var gmicloud = createGmicloud();
|
|
94
|
-
export {
|
|
95
|
-
VERSION,
|
|
96
|
-
createGmicloud,
|
|
97
|
-
gmicloud
|
|
98
|
-
};
|
|
99
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/gmicloud-provider.ts","../src/gmicloud-chat-language-model.ts","../src/gmicloud-error.ts","../src/version.ts"],"sourcesContent":["import {\n NoSuchModelError,\n type LanguageModelV3,\n type ProviderV3,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { GmicloudChatLanguageModel } from './gmicloud-chat-language-model';\nimport type { GmicloudChatModelId } from './gmicloud-chat-options';\nimport { gmicloudErrorStructure } from './gmicloud-error';\nimport { VERSION } from './version';\n\nexport interface GmicloudProviderSettings {\n /**\n * GMI Cloud API key. Defaults to the `GMI_CLOUD_APIKEY` environment\n * variable (matching GMI's own SDK package).\n */\n apiKey?: string;\n /**\n * Base URL for the API calls. Defaults to\n * `https://api.gmi-serving.com/v1`.\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept\n * requests, or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface GmicloudProvider extends ProviderV3 {\n /**\n * Creates a GMI Cloud model for text generation.\n */\n (modelId: GmicloudChatModelId): LanguageModelV3;\n\n /**\n * Creates a GMI Cloud model for text generation.\n */\n languageModel(modelId: GmicloudChatModelId): LanguageModelV3;\n\n /**\n * Creates a GMI Cloud chat model for text generation.\n */\n chat(modelId: GmicloudChatModelId): LanguageModelV3;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport function createGmicloud(\n options: GmicloudProviderSettings = {},\n): GmicloudProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.gmi-serving.com/v1',\n );\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'GMI_CLOUD_APIKEY',\n description: 'GMI Cloud API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk/gmicloud/${VERSION}`,\n );\n\n const createLanguageModel = (modelId: GmicloudChatModelId) => {\n return new GmicloudChatLanguageModel(modelId, {\n provider: `gmicloud.chat`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n errorStructure: gmicloudErrorStructure,\n includeUsage: true,\n });\n };\n\n const provider = (modelId: GmicloudChatModelId) =>\n createLanguageModel(modelId);\n\n provider.specificationVersion = 'v3' as const;\n provider.languageModel = createLanguageModel;\n provider.chat = createLanguageModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n\nexport const gmicloud = createGmicloud();\n","import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';\n\n/**\n * GMI Cloud chat completions over the OpenAI-compatible protocol. The only\n * customization is the error structure (see ./gmicloud-error.ts): GMI's edge\n * nests the backend engine's diagnostic in `error.details`, which the default\n * OpenAI-compatible error handling drops.\n */\nexport class GmicloudChatLanguageModel extends OpenAICompatibleChatLanguageModel {}\n","import type { ProviderErrorStructure } from '@ai-sdk/openai-compatible';\nimport { secureJsonParse } from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\n\nexport const gmicloudErrorDataSchema = z.object({\n error: z.object({\n message: z.string(),\n type: z.string().nullish(),\n param: z.any().nullish(),\n code: z.union([z.string(), z.number()]).nullish(),\n details: z.string().nullish(),\n }),\n});\n\nexport type GmicloudErrorData = z.infer<typeof gmicloudErrorDataSchema>;\n\nfunction unwrapDetailsMessage(details: string | null | undefined) {\n if (details == null || details === '') {\n return undefined;\n }\n let parsed: unknown;\n try {\n parsed = secureJsonParse(details);\n } catch {\n return undefined;\n }\n const message = (parsed as { error?: { message?: unknown } })?.error?.message;\n return typeof message === 'string' && message.trim() !== ''\n ? message\n : undefined;\n}\n\nexport const gmicloudErrorStructure: ProviderErrorStructure<GmicloudErrorData> =\n {\n errorSchema: gmicloudErrorDataSchema,\n errorToMessage: data =>\n unwrapDetailsMessage(data.error.details) ?? data.error.message,\n };\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACVP,SAAS,yCAAyC;AAQ3C,IAAM,4BAAN,cAAwC,kCAAkC;AAAC;;;ACPlF,SAAS,uBAAuB;AAChC,SAAS,SAAS;AAEX,IAAM,0BAA0B,EAAE,OAAO;AAAA,EAC9C,OAAO,EAAE,OAAO;AAAA,IACd,SAAS,EAAE,OAAO;AAAA,IAClB,MAAM,EAAE,OAAO,EAAE,QAAQ;AAAA,IACzB,OAAO,EAAE,IAAI,EAAE,QAAQ;AAAA,IACvB,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,QAAQ;AAAA,IAChD,SAAS,EAAE,OAAO,EAAE,QAAQ;AAAA,EAC9B,CAAC;AACH,CAAC;AAID,SAAS,qBAAqB,SAAoC;AAhBlE;AAiBE,MAAI,WAAW,QAAQ,YAAY,IAAI;AACrC,WAAO;AAAA,EACT;AACA,MAAI;AACJ,MAAI;AACF,aAAS,gBAAgB,OAAO;AAAA,EAClC,SAAQ;AACN,WAAO;AAAA,EACT;AACA,QAAM,WAAW,sCAA8C,UAA9C,mBAAqD;AACtE,SAAO,OAAO,YAAY,YAAY,QAAQ,KAAK,MAAM,KACrD,UACA;AACN;AAEO,IAAM,yBACX;AAAA,EACE,aAAa;AAAA,EACb,gBAAgB,UAAK;AAnCzB;AAoCM,sCAAqB,KAAK,MAAM,OAAO,MAAvC,YAA4C,KAAK,MAAM;AAAA;AAC3D;;;ACnCK,IAAM,UACX,OACI,UACA;;;AHuDC,SAAS,eACd,UAAoC,CAAC,GACnB;AA9DpB;AA+DE,QAAM,UAAU;AAAA,KACd,aAAQ,YAAR,YAAmB;AAAA,EACrB;AACA,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,eAAe,UAAU,WAAW;AAAA,QAClC,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC,CAAC;AAAA,MACF,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,mBAAmB,OAAO;AAAA,EAC5B;AAEF,QAAM,sBAAsB,CAAC,YAAiC;AAC5D,WAAO,IAAI,0BAA0B,SAAS;AAAA,MAC5C,UAAU;AAAA,MACV,KAAK,CAAC,EAAE,KAAK,MAAM,GAAG,OAAO,GAAG,IAAI;AAAA,MACpC,SAAS;AAAA,MACT,OAAO,QAAQ;AAAA,MACf,gBAAgB;AAAA,MAChB,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AAEA,QAAM,WAAW,CAAC,YAChB,oBAAoB,OAAO;AAE7B,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAEhB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAEO,IAAM,WAAW,eAAe;","names":[]}
|