@ai-sdk/gmicloud 1.0.0 → 2.0.1
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 +8 -0
- package/dist/index.d.mts +9 -5
- package/dist/index.d.ts +9 -5
- package/dist/index.js +18 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/gmicloud-error.ts +8 -14
- package/src/gmicloud-provider.ts +15 -9
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderV3, LanguageModelV3 } 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,23 @@ interface GmicloudProviderSettings {
|
|
|
25
25
|
*/
|
|
26
26
|
fetch?: FetchFunction;
|
|
27
27
|
}
|
|
28
|
-
interface GmicloudProvider extends
|
|
28
|
+
interface GmicloudProvider extends ProviderV3 {
|
|
29
29
|
/**
|
|
30
30
|
* Creates a GMI Cloud model for text generation.
|
|
31
31
|
*/
|
|
32
|
-
(modelId: GmicloudChatModelId):
|
|
32
|
+
(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
33
33
|
/**
|
|
34
34
|
* Creates a GMI Cloud model for text generation.
|
|
35
35
|
*/
|
|
36
|
-
languageModel(modelId: GmicloudChatModelId):
|
|
36
|
+
languageModel(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
37
37
|
/**
|
|
38
38
|
* Creates a GMI Cloud chat model for text generation.
|
|
39
39
|
*/
|
|
40
|
-
chat(modelId: GmicloudChatModelId):
|
|
40
|
+
chat(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use `embeddingModel` instead.
|
|
43
|
+
*/
|
|
44
|
+
textEmbeddingModel(modelId: string): never;
|
|
41
45
|
}
|
|
42
46
|
declare function createGmicloud(options?: GmicloudProviderSettings): GmicloudProvider;
|
|
43
47
|
declare const gmicloud: GmicloudProvider;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProviderV3, LanguageModelV3 } 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,23 @@ interface GmicloudProviderSettings {
|
|
|
25
25
|
*/
|
|
26
26
|
fetch?: FetchFunction;
|
|
27
27
|
}
|
|
28
|
-
interface GmicloudProvider extends
|
|
28
|
+
interface GmicloudProvider extends ProviderV3 {
|
|
29
29
|
/**
|
|
30
30
|
* Creates a GMI Cloud model for text generation.
|
|
31
31
|
*/
|
|
32
|
-
(modelId: GmicloudChatModelId):
|
|
32
|
+
(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
33
33
|
/**
|
|
34
34
|
* Creates a GMI Cloud model for text generation.
|
|
35
35
|
*/
|
|
36
|
-
languageModel(modelId: GmicloudChatModelId):
|
|
36
|
+
languageModel(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
37
37
|
/**
|
|
38
38
|
* Creates a GMI Cloud chat model for text generation.
|
|
39
39
|
*/
|
|
40
|
-
chat(modelId: GmicloudChatModelId):
|
|
40
|
+
chat(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use `embeddingModel` instead.
|
|
43
|
+
*/
|
|
44
|
+
textEmbeddingModel(modelId: string): never;
|
|
41
45
|
}
|
|
42
46
|
declare function createGmicloud(options?: GmicloudProviderSettings): GmicloudProvider;
|
|
43
47
|
declare const gmicloud: GmicloudProvider;
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/gmicloud-provider.ts
|
|
30
30
|
var import_provider = require("@ai-sdk/provider");
|
|
31
|
-
var
|
|
31
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/gmicloud-chat-language-model.ts
|
|
34
34
|
var import_openai_compatible = require("@ai-sdk/openai-compatible");
|
|
@@ -36,6 +36,7 @@ var GmicloudChatLanguageModel = class extends import_openai_compatible.OpenAICom
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
// src/gmicloud-error.ts
|
|
39
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
39
40
|
var import_v4 = require("zod/v4");
|
|
40
41
|
var gmicloudErrorDataSchema = import_v4.z.object({
|
|
41
42
|
error: import_v4.z.object({
|
|
@@ -46,19 +47,18 @@ var gmicloudErrorDataSchema = import_v4.z.object({
|
|
|
46
47
|
details: import_v4.z.string().nullish()
|
|
47
48
|
})
|
|
48
49
|
});
|
|
49
|
-
function tryParseDetails(details) {
|
|
50
|
-
try {
|
|
51
|
-
return JSON.parse(details);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
return void 0;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
50
|
function unwrapDetailsMessage(details) {
|
|
57
|
-
var _a
|
|
51
|
+
var _a;
|
|
58
52
|
if (details == null || details === "") {
|
|
59
53
|
return void 0;
|
|
60
54
|
}
|
|
61
|
-
|
|
55
|
+
let parsed;
|
|
56
|
+
try {
|
|
57
|
+
parsed = (0, import_provider_utils.secureJsonParse)(details);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
const message = (_a = parsed == null ? void 0 : parsed.error) == null ? void 0 : _a.message;
|
|
62
62
|
return typeof message === "string" && message.trim() !== "" ? message : void 0;
|
|
63
63
|
}
|
|
64
64
|
var gmicloudErrorStructure = {
|
|
@@ -70,17 +70,17 @@ var gmicloudErrorStructure = {
|
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
// src/version.ts
|
|
73
|
-
var VERSION = true ? "
|
|
73
|
+
var VERSION = true ? "2.0.1" : "0.0.0-test";
|
|
74
74
|
|
|
75
75
|
// src/gmicloud-provider.ts
|
|
76
76
|
function createGmicloud(options = {}) {
|
|
77
77
|
var _a;
|
|
78
|
-
const baseURL = (0,
|
|
78
|
+
const baseURL = (0, import_provider_utils2.withoutTrailingSlash)(
|
|
79
79
|
(_a = options.baseURL) != null ? _a : "https://api.gmi-serving.com/v1"
|
|
80
80
|
);
|
|
81
|
-
const getHeaders = () => (0,
|
|
81
|
+
const getHeaders = () => (0, import_provider_utils2.withUserAgentSuffix)(
|
|
82
82
|
{
|
|
83
|
-
Authorization: `Bearer ${(0,
|
|
83
|
+
Authorization: `Bearer ${(0, import_provider_utils2.loadApiKey)({
|
|
84
84
|
apiKey: options.apiKey,
|
|
85
85
|
environmentVariableName: "GMI_CLOUD_APIKEY",
|
|
86
86
|
description: "GMI Cloud API key"
|
|
@@ -100,12 +100,13 @@ function createGmicloud(options = {}) {
|
|
|
100
100
|
});
|
|
101
101
|
};
|
|
102
102
|
const provider = (modelId) => createLanguageModel(modelId);
|
|
103
|
-
provider.specificationVersion = "
|
|
103
|
+
provider.specificationVersion = "v3";
|
|
104
104
|
provider.languageModel = createLanguageModel;
|
|
105
105
|
provider.chat = createLanguageModel;
|
|
106
|
-
provider.
|
|
107
|
-
throw new import_provider.NoSuchModelError({ modelId, modelType: "
|
|
106
|
+
provider.embeddingModel = (modelId) => {
|
|
107
|
+
throw new import_provider.NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
108
108
|
};
|
|
109
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
109
110
|
provider.imageModel = (modelId) => {
|
|
110
111
|
throw new import_provider.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
111
112
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/gmicloud-provider.ts","../src/gmicloud-chat-language-model.ts","../src/gmicloud-error.ts","../src/version.ts"],"sourcesContent":["export { createGmicloud, gmicloud } from './gmicloud-provider';\nexport type {\n GmicloudProvider,\n GmicloudProviderSettings,\n} from './gmicloud-provider';\nexport type { GmicloudErrorData } from './gmicloud-error';\nexport { VERSION } from './version';\n","import {\n NoSuchModelError,\n type
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/gmicloud-provider.ts","../src/gmicloud-chat-language-model.ts","../src/gmicloud-error.ts","../src/version.ts"],"sourcesContent":["export { createGmicloud, gmicloud } from './gmicloud-provider';\nexport type {\n GmicloudProvider,\n GmicloudProviderSettings,\n} from './gmicloud-provider';\nexport type { GmicloudErrorData } from './gmicloud-error';\nexport { VERSION } from './version';\n","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;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAIO;AACP,IAAAA,yBAKO;;;ACVP,+BAAkD;AAQ3C,IAAM,4BAAN,cAAwC,2DAAkC;AAAC;;;ACPlF,4BAAgC;AAChC,gBAAkB;AAEX,IAAM,0BAA0B,YAAE,OAAO;AAAA,EAC9C,OAAO,YAAE,OAAO;AAAA,IACd,SAAS,YAAE,OAAO;AAAA,IAClB,MAAM,YAAE,OAAO,EAAE,QAAQ;AAAA,IACzB,OAAO,YAAE,IAAI,EAAE,QAAQ;AAAA,IACvB,MAAM,YAAE,MAAM,CAAC,YAAE,OAAO,GAAG,YAAE,OAAO,CAAC,CAAC,EAAE,QAAQ;AAAA,IAChD,SAAS,YAAE,OAAO,EAAE,QAAQ;AAAA,EAC9B,CAAC;AACH,CAAC;AAID,SAA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AAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iCAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAEO,IAAM,WAAW,eAAe;","names":["import_provider_utils"]}
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,7 @@ var GmicloudChatLanguageModel = class extends OpenAICompatibleChatLanguageModel
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
// src/gmicloud-error.ts
|
|
17
|
+
import { secureJsonParse } from "@ai-sdk/provider-utils";
|
|
17
18
|
import { z } from "zod/v4";
|
|
18
19
|
var gmicloudErrorDataSchema = z.object({
|
|
19
20
|
error: z.object({
|
|
@@ -24,19 +25,18 @@ var gmicloudErrorDataSchema = z.object({
|
|
|
24
25
|
details: z.string().nullish()
|
|
25
26
|
})
|
|
26
27
|
});
|
|
27
|
-
function tryParseDetails(details) {
|
|
28
|
-
try {
|
|
29
|
-
return JSON.parse(details);
|
|
30
|
-
} catch (e) {
|
|
31
|
-
return void 0;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
28
|
function unwrapDetailsMessage(details) {
|
|
35
|
-
var _a
|
|
29
|
+
var _a;
|
|
36
30
|
if (details == null || details === "") {
|
|
37
31
|
return void 0;
|
|
38
32
|
}
|
|
39
|
-
|
|
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
40
|
return typeof message === "string" && message.trim() !== "" ? message : void 0;
|
|
41
41
|
}
|
|
42
42
|
var gmicloudErrorStructure = {
|
|
@@ -48,7 +48,7 @@ var gmicloudErrorStructure = {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
// src/version.ts
|
|
51
|
-
var VERSION = true ? "
|
|
51
|
+
var VERSION = true ? "2.0.1" : "0.0.0-test";
|
|
52
52
|
|
|
53
53
|
// src/gmicloud-provider.ts
|
|
54
54
|
function createGmicloud(options = {}) {
|
|
@@ -78,12 +78,13 @@ function createGmicloud(options = {}) {
|
|
|
78
78
|
});
|
|
79
79
|
};
|
|
80
80
|
const provider = (modelId) => createLanguageModel(modelId);
|
|
81
|
-
provider.specificationVersion = "
|
|
81
|
+
provider.specificationVersion = "v3";
|
|
82
82
|
provider.languageModel = createLanguageModel;
|
|
83
83
|
provider.chat = createLanguageModel;
|
|
84
|
-
provider.
|
|
85
|
-
throw new NoSuchModelError({ modelId, modelType: "
|
|
84
|
+
provider.embeddingModel = (modelId) => {
|
|
85
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
86
86
|
};
|
|
87
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
87
88
|
provider.imageModel = (modelId) => {
|
|
88
89
|
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
89
90
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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;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AAO;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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/gmicloud",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ai-sdk/openai-compatible": "
|
|
34
|
-
"@ai-sdk/provider": "
|
|
35
|
-
"@ai-sdk/provider-utils": "
|
|
33
|
+
"@ai-sdk/openai-compatible": "2.0.68",
|
|
34
|
+
"@ai-sdk/provider": "3.0.15",
|
|
35
|
+
"@ai-sdk/provider-utils": "4.0.46"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "20.17.24",
|
package/src/gmicloud-error.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProviderErrorStructure } from '@ai-sdk/openai-compatible';
|
|
2
|
+
import { secureJsonParse } from '@ai-sdk/provider-utils';
|
|
2
3
|
import { z } from 'zod/v4';
|
|
3
4
|
|
|
4
5
|
export const gmicloudErrorDataSchema = z.object({
|
|
@@ -13,24 +14,17 @@ export const gmicloudErrorDataSchema = z.object({
|
|
|
13
14
|
|
|
14
15
|
export type GmicloudErrorData = z.infer<typeof gmicloudErrorDataSchema>;
|
|
15
16
|
|
|
16
|
-
// The parsed value is only read, never merged, so a guarded parse
|
|
17
|
-
// (secureJsonParse) is not required here; the v5 provider-utils package does
|
|
18
|
-
// not re-export it.
|
|
19
|
-
function tryParseDetails(details: string): unknown {
|
|
20
|
-
try {
|
|
21
|
-
return JSON.parse(details);
|
|
22
|
-
} catch {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
17
|
function unwrapDetailsMessage(details: string | null | undefined) {
|
|
28
18
|
if (details == null || details === '') {
|
|
29
19
|
return undefined;
|
|
30
20
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
let parsed: unknown;
|
|
22
|
+
try {
|
|
23
|
+
parsed = secureJsonParse(details);
|
|
24
|
+
} catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const message = (parsed as { error?: { message?: unknown } })?.error?.message;
|
|
34
28
|
return typeof message === 'string' && message.trim() !== ''
|
|
35
29
|
? message
|
|
36
30
|
: undefined;
|
package/src/gmicloud-provider.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NoSuchModelError,
|
|
3
|
-
type
|
|
4
|
-
type
|
|
3
|
+
type LanguageModelV3,
|
|
4
|
+
type ProviderV3,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
loadApiKey,
|
|
@@ -36,21 +36,26 @@ export interface GmicloudProviderSettings {
|
|
|
36
36
|
fetch?: FetchFunction;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export interface GmicloudProvider extends
|
|
39
|
+
export interface GmicloudProvider extends ProviderV3 {
|
|
40
40
|
/**
|
|
41
41
|
* Creates a GMI Cloud model for text generation.
|
|
42
42
|
*/
|
|
43
|
-
(modelId: GmicloudChatModelId):
|
|
43
|
+
(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Creates a GMI Cloud model for text generation.
|
|
47
47
|
*/
|
|
48
|
-
languageModel(modelId: GmicloudChatModelId):
|
|
48
|
+
languageModel(modelId: GmicloudChatModelId): LanguageModelV3;
|
|
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): LanguageModelV3;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated Use `embeddingModel` instead.
|
|
57
|
+
*/
|
|
58
|
+
textEmbeddingModel(modelId: string): never;
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
export function createGmicloud(
|
|
@@ -86,13 +91,14 @@ export function createGmicloud(
|
|
|
86
91
|
const provider = (modelId: GmicloudChatModelId) =>
|
|
87
92
|
createLanguageModel(modelId);
|
|
88
93
|
|
|
89
|
-
provider.specificationVersion = '
|
|
94
|
+
provider.specificationVersion = 'v3' as const;
|
|
90
95
|
provider.languageModel = createLanguageModel;
|
|
91
96
|
provider.chat = createLanguageModel;
|
|
92
97
|
|
|
93
|
-
provider.
|
|
94
|
-
throw new NoSuchModelError({ modelId, modelType: '
|
|
98
|
+
provider.embeddingModel = (modelId: string) => {
|
|
99
|
+
throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });
|
|
95
100
|
};
|
|
101
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
96
102
|
provider.imageModel = (modelId: string) => {
|
|
97
103
|
throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
|
|
98
104
|
};
|