@zhivex-ai/zai 0.0.0 → 0.1.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/README.md +79 -4
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +694 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -4
package/README.md
CHANGED
|
@@ -1,7 +1,82 @@
|
|
|
1
1
|
# @zhivex-ai/zai
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
official Zhivex Z.ai provider package.
|
|
3
|
+
Native Z.ai GLM adapter for Zhivex AI SDK.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @zhivex-ai/zai @zhivex-ai/core zod
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## GLM-5.2 on the general API
|
|
12
|
+
|
|
13
|
+
The general pay-as-you-go endpoint is the safe default because it is the endpoint currently documented for `glm-5.2`.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { generateText } from "@zhivex-ai/core";
|
|
17
|
+
import { createZAI } from "@zhivex-ai/zai";
|
|
18
|
+
|
|
19
|
+
const zai = createZAI({ apiKey: process.env.ZAI_API_KEY });
|
|
20
|
+
|
|
21
|
+
const result = await generateText({
|
|
22
|
+
model: zai("glm-5.2"),
|
|
23
|
+
prompt: "Explain why passkeys resist phishing.",
|
|
24
|
+
reasoning: { effort: "high" }
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
console.log(result.text);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The default base URL is `https://api.z.ai/api/paas/v4`. `ZAI_BASE_URL` or the `baseURL` option can override it for compatible gateways.
|
|
31
|
+
|
|
32
|
+
## GLM-5.3 on Coding Plan
|
|
33
|
+
|
|
34
|
+
As of August 14, 2026, Z.ai documents `glm-5.3` for all Coding Plan tiers. It is not yet listed in the standard Model API OpenAPI catalog or pay-as-you-go pricing. Select the Coding Plan endpoint explicitly:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const coding = createZAI({
|
|
38
|
+
apiKey: process.env.ZAI_API_KEY,
|
|
39
|
+
endpoint: "coding"
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const result = await generateText({
|
|
43
|
+
model: coding("glm-5.3"),
|
|
44
|
+
prompt: "Review this authorization boundary.",
|
|
45
|
+
reasoning: { effort: "max" }
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Coding Plan is limited by Z.ai's usage policy to supported coding and agent tools. On that endpoint, requests for `glm-5.2` or `glm-5.1` may be routed upstream to `glm-5.3`; use the general endpoint when exact GLM-5.2 behavior matters.
|
|
50
|
+
|
|
51
|
+
## Contract
|
|
52
|
+
|
|
53
|
+
- Text generation and SSE streaming through Chat Completions.
|
|
54
|
+
- Local function-tool loops with automatic tool selection. Forced, required, `none`, hosted tools, and provider-advertised parallel calls are not exposed because only `tool_choice: "auto"` is currently documented.
|
|
55
|
+
- `reasoning_content` is preserved as Z.ai `provider-data` and replayed unchanged across tool turns. The adapter sends `thinking.clear_thinking: false` when tool state must be preserved.
|
|
56
|
+
- GLM-5.3 requires thinking and accepts shared efforts `low`, `high`, and `max`. `none`, `disabled`, and unsupported aliases fail before network I/O.
|
|
57
|
+
- GLM-5.2 maps `none`/`minimal` to disabled thinking, `low`/`medium` to `high`, and `xhigh` to `max`.
|
|
58
|
+
- Structured output uses Z.ai JSON-object mode plus a schema prompt, followed by local Zod validation. Z.ai does not document strict native JSON Schema enforcement.
|
|
59
|
+
- Cached input usage and documented provider finish reasons are normalized into the shared contract.
|
|
60
|
+
- The adapter is text-only and does not claim embeddings, vision, audio, realtime, hosted web search, or remote MCP.
|
|
61
|
+
|
|
62
|
+
Use `providerOptions` for documented Z.ai fields such as `thinking`, `reasoning_effort`, `top_p`, `do_sample`, `stop`, `request_id`, and `user_id`. Do not put private information in provider user identifiers.
|
|
63
|
+
|
|
64
|
+
## Live smoke
|
|
65
|
+
|
|
66
|
+
General GLM-5.2 smoke:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
ZAI_API_KEY=... bun run test:integration:zai
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Coding Plan GLM-5.3 smoke:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
ZAI_API_KEY=... \
|
|
76
|
+
ZAI_ENDPOINT=coding \
|
|
77
|
+
ZAI_INTEGRATION_MODEL=glm-5.3 \
|
|
78
|
+
ZAI_EXTENDED_INTEGRATION=1 \
|
|
79
|
+
bun run test:integration:zai
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
A skipped smoke or offline fixture test is not authenticated provider certification.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ProviderAdapter, type LanguageModel } from "@zhivex-ai/core";
|
|
2
|
+
type TypedCallableProviderAdapter<TLanguageModel extends LanguageModel> = Omit<ProviderAdapter, "languageModel"> & ((modelId: string) => TLanguageModel) & {
|
|
3
|
+
languageModel(modelId: string): TLanguageModel;
|
|
4
|
+
};
|
|
5
|
+
export declare const ZAI_GENERAL_BASE_URL = "https://api.z.ai/api/paas/v4";
|
|
6
|
+
export declare const ZAI_CODING_BASE_URL = "https://api.z.ai/api/coding/paas/v4";
|
|
7
|
+
export type ZAIEndpoint = "general" | "coding";
|
|
8
|
+
export type ZAIReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
9
|
+
export interface ZAIProviderOptions {
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
/** Overrides the selected official endpoint. */
|
|
12
|
+
baseURL?: string;
|
|
13
|
+
/** Selects the general pay-as-you-go API (default) or the Coding Plan endpoint. */
|
|
14
|
+
endpoint?: ZAIEndpoint;
|
|
15
|
+
fetch?: typeof globalThis.fetch;
|
|
16
|
+
allowUnsafeEndpoints?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface ZAILanguageModelOptions {
|
|
19
|
+
thinking?: {
|
|
20
|
+
type: "enabled" | "disabled";
|
|
21
|
+
/** Preserve reasoning across tool turns when false. */
|
|
22
|
+
clear_thinking?: boolean;
|
|
23
|
+
};
|
|
24
|
+
reasoning_effort?: ZAIReasoningEffort;
|
|
25
|
+
temperature?: number;
|
|
26
|
+
top_p?: number;
|
|
27
|
+
max_tokens?: number;
|
|
28
|
+
response_format?: {
|
|
29
|
+
type: "text" | "json_object";
|
|
30
|
+
};
|
|
31
|
+
stop?: string[];
|
|
32
|
+
tool_stream?: boolean;
|
|
33
|
+
tool_choice?: "auto";
|
|
34
|
+
do_sample?: boolean;
|
|
35
|
+
request_id?: string;
|
|
36
|
+
user_id?: string;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
export declare const createZAI: (options?: ZAIProviderOptions) => TypedCallableProviderAdapter<LanguageModel<ZAILanguageModelOptions>> & {
|
|
40
|
+
rawFetch: typeof globalThis.fetch;
|
|
41
|
+
endpoint: ZAIEndpoint;
|
|
42
|
+
};
|
|
43
|
+
/** Conventional camel-case alias for consumers that do not use acronym casing. */
|
|
44
|
+
export declare const createZai: (options?: ZAIProviderOptions) => TypedCallableProviderAdapter<LanguageModel<ZAILanguageModelOptions>> & {
|
|
45
|
+
rawFetch: typeof globalThis.fetch;
|
|
46
|
+
endpoint: ZAIEndpoint;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAiBL,KAAK,eAAe,EAGpB,KAAK,aAAa,EAKnB,MAAM,iBAAiB,CAAC;AAEzB,KAAK,4BAA4B,CAAC,cAAc,SAAS,aAAa,IAAI,IAAI,CAC5E,eAAe,EACf,eAAe,CAChB,GACC,CAAC,CAAC,OAA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ACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAowBD,eAAO,MAAM,SAAS,GACpB,UAAS,kBAAuB,KAC/B,4BAA4B,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAC,GAAG;IACxE,QAAQ,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAClC,QAAQ,EAAE,WAAW,CAAC;CAoBvB,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,SAAS,aA1BX,kBAAkB,KAC1B,4BAA4B,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAC,GAAG;IACxE,QAAQ,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAClC,QAAQ,EAAE,WAAW,CAAC;CAuBU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
import { toJSONSchema } from "zod";
|
|
2
|
+
import { ConfigurationError, ParseError, ProviderHTTPError, UnsupportedFeatureError, ValidationError, assertTrustedEndpoint, createProviderAdapter, isCallableToolDefinition, normalizeFinishReason, providerDataPart, readErrorBodyWithLimit, readJsonWithLimit, serializeJsonValue, streamSSE, withRetry, withTimeoutSignal } from "@zhivex-ai/core";
|
|
3
|
+
export const ZAI_GENERAL_BASE_URL = "https://api.z.ai/api/paas/v4";
|
|
4
|
+
export const ZAI_CODING_BASE_URL = "https://api.z.ai/api/coding/paas/v4";
|
|
5
|
+
const baseCapabilities = {
|
|
6
|
+
streaming: true,
|
|
7
|
+
tools: true,
|
|
8
|
+
structuredOutput: true,
|
|
9
|
+
jsonMode: true,
|
|
10
|
+
toolChoice: false,
|
|
11
|
+
parallelToolCalls: false,
|
|
12
|
+
vision: false,
|
|
13
|
+
files: false,
|
|
14
|
+
audioInput: false,
|
|
15
|
+
audioOutput: false,
|
|
16
|
+
embeddings: false,
|
|
17
|
+
contextCaching: true,
|
|
18
|
+
reasoning: false,
|
|
19
|
+
webSearch: false,
|
|
20
|
+
agentCapabilities: {
|
|
21
|
+
supportTier: "tier-b",
|
|
22
|
+
toolChoiceNone: false,
|
|
23
|
+
approvalRequests: false,
|
|
24
|
+
hostedWebSearch: false,
|
|
25
|
+
hostedFileSearch: false,
|
|
26
|
+
remoteMcp: false,
|
|
27
|
+
computerUse: false,
|
|
28
|
+
codeExecution: false,
|
|
29
|
+
toolsets: false
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const isGLM53 = (modelId) => modelId.toLowerCase() === "glm-5.3";
|
|
33
|
+
const isGLM52 = (modelId) => modelId.toLowerCase() === "glm-5.2";
|
|
34
|
+
const capabilitiesForModel = (modelId) => ({
|
|
35
|
+
...baseCapabilities,
|
|
36
|
+
reasoning: isGLM53(modelId) || isGLM52(modelId),
|
|
37
|
+
reasoningEfforts: isGLM53(modelId)
|
|
38
|
+
? ["low", "high", "max"]
|
|
39
|
+
: isGLM52(modelId)
|
|
40
|
+
? ["none", "minimal", "low", "medium", "high", "xhigh", "max"]
|
|
41
|
+
: undefined
|
|
42
|
+
});
|
|
43
|
+
const isJsonObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
44
|
+
const mapContentParts = (message) => message.parts
|
|
45
|
+
.filter((part) => part.type === "text")
|
|
46
|
+
.map((part) => part.text)
|
|
47
|
+
.join("");
|
|
48
|
+
const reasoningContentFromMessage = (message) => message.parts
|
|
49
|
+
.filter((part) => {
|
|
50
|
+
if (part.type !== "provider-data" || part.provider !== "zai" || !isJsonObject(part.data)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return part.data.type === "reasoning_content" && typeof part.data.reasoningContent === "string";
|
|
54
|
+
})
|
|
55
|
+
.map((part) => part.type === "provider-data" && isJsonObject(part.data) ? String(part.data.reasoningContent) : "")
|
|
56
|
+
.join("");
|
|
57
|
+
const hasReasoningHistory = (messages) => messages.some((message) => reasoningContentFromMessage(message).length > 0);
|
|
58
|
+
const parseToolArguments = (value) => {
|
|
59
|
+
let parsed = value ?? {};
|
|
60
|
+
if (typeof parsed === "string") {
|
|
61
|
+
try {
|
|
62
|
+
parsed = JSON.parse(parsed);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new ParseError("Z.ai tool call arguments contained invalid JSON.", { cause: error });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!isJsonObject(parsed)) {
|
|
69
|
+
throw new ValidationError("Z.ai tool call arguments must be a JSON object.");
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
return serializeJsonValue(parsed);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new ValidationError("Z.ai tool call arguments must be JSON-compatible.", { cause: error });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const mergeStreamFragment = (current, fragment) => {
|
|
79
|
+
if (typeof fragment !== "string" || !fragment) {
|
|
80
|
+
return current;
|
|
81
|
+
}
|
|
82
|
+
if (!current || fragment.startsWith(current)) {
|
|
83
|
+
return fragment;
|
|
84
|
+
}
|
|
85
|
+
if (fragment === current || current.endsWith(fragment)) {
|
|
86
|
+
return current;
|
|
87
|
+
}
|
|
88
|
+
return current + fragment;
|
|
89
|
+
};
|
|
90
|
+
const mapMessages = (messages) => messages.map((message) => {
|
|
91
|
+
if (message.role === "tool") {
|
|
92
|
+
const toolResult = message.parts.find((part) => part.type === "tool-result");
|
|
93
|
+
return {
|
|
94
|
+
role: "tool",
|
|
95
|
+
tool_call_id: toolResult?.type === "tool-result" ? toolResult.toolResult.toolCallId : undefined,
|
|
96
|
+
content: toolResult?.type === "tool-result"
|
|
97
|
+
? JSON.stringify(toolResult.toolResult.isError ? toolResult.toolResult.error : toolResult.toolResult.output)
|
|
98
|
+
: ""
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const toolCalls = message.parts
|
|
102
|
+
.filter((part) => part.type === "tool-call")
|
|
103
|
+
.map((part) => ({
|
|
104
|
+
id: part.toolCall.id,
|
|
105
|
+
type: "function",
|
|
106
|
+
function: {
|
|
107
|
+
name: part.toolCall.name,
|
|
108
|
+
arguments: JSON.stringify(part.toolCall.input)
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
111
|
+
const payload = {
|
|
112
|
+
role: message.role,
|
|
113
|
+
content: mapContentParts(message)
|
|
114
|
+
};
|
|
115
|
+
const reasoningContent = reasoningContentFromMessage(message);
|
|
116
|
+
if (reasoningContent) {
|
|
117
|
+
payload.reasoning_content = reasoningContent;
|
|
118
|
+
}
|
|
119
|
+
if (toolCalls.length) {
|
|
120
|
+
payload.tool_calls = toolCalls;
|
|
121
|
+
}
|
|
122
|
+
return payload;
|
|
123
|
+
});
|
|
124
|
+
const ensureJsonOutputInstruction = (messages, responseFormat, structuredOutput) => {
|
|
125
|
+
if (responseFormat?.type !== "json_object") {
|
|
126
|
+
return messages;
|
|
127
|
+
}
|
|
128
|
+
const schema = structuredOutput?.mode === "native" ? JSON.stringify(toJSONSchema(structuredOutput.schema)) : undefined;
|
|
129
|
+
if (!schema && messages.some((message) => /\bjson\b/i.test(mapContentParts(message)))) {
|
|
130
|
+
return messages;
|
|
131
|
+
}
|
|
132
|
+
return [
|
|
133
|
+
{
|
|
134
|
+
role: "system",
|
|
135
|
+
parts: [
|
|
136
|
+
{
|
|
137
|
+
type: "text",
|
|
138
|
+
text: schema
|
|
139
|
+
? `Return only valid JSON matching this JSON Schema: ${schema}`
|
|
140
|
+
: "Return only valid JSON."
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
...messages
|
|
145
|
+
];
|
|
146
|
+
};
|
|
147
|
+
const mapTools = (tools) => {
|
|
148
|
+
if (!tools) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
const definitions = Object.values(tools);
|
|
152
|
+
if (definitions.length > 128) {
|
|
153
|
+
throw new ValidationError("Z.ai accepts at most 128 function tools per request.");
|
|
154
|
+
}
|
|
155
|
+
const callableTools = definitions.filter(isCallableToolDefinition);
|
|
156
|
+
if (callableTools.length !== definitions.length) {
|
|
157
|
+
throw new UnsupportedFeatureError('Provider "zai" does not support hosted tools.');
|
|
158
|
+
}
|
|
159
|
+
return callableTools.map((tool) => {
|
|
160
|
+
if (!/^[A-Za-z0-9_-]{1,64}$/.test(tool.name)) {
|
|
161
|
+
throw new ValidationError(`Z.ai tool name "${tool.name}" must contain 1-64 letters, numbers, underscores, or hyphens.`);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
type: "function",
|
|
165
|
+
function: {
|
|
166
|
+
name: tool.name,
|
|
167
|
+
description: tool.description ?? tool.name,
|
|
168
|
+
parameters: toJSONSchema(tool.schema)
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
const mapStructuredOutput = (input) => input.structuredOutput?.mode === "native" ? { type: "json_object" } : undefined;
|
|
174
|
+
const unsupportedReasoningFields = (input) => {
|
|
175
|
+
if (input.reasoning?.budgetTokens !== undefined) {
|
|
176
|
+
throw new UnsupportedFeatureError('Provider "zai" does not support "reasoning.budgetTokens".');
|
|
177
|
+
}
|
|
178
|
+
if (input.reasoning?.mode !== undefined || input.reasoning?.context !== undefined) {
|
|
179
|
+
throw new UnsupportedFeatureError('Provider "zai" does not support "reasoning.mode" or "reasoning.context".');
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const mapSharedReasoning = (modelId, input) => {
|
|
183
|
+
const reasoning = input.reasoning;
|
|
184
|
+
if (!reasoning) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
unsupportedReasoningFields(input);
|
|
188
|
+
const effort = reasoning.effort;
|
|
189
|
+
if (isGLM53(modelId)) {
|
|
190
|
+
if (reasoning.includeThoughts === false) {
|
|
191
|
+
throw new UnsupportedFeatureError('Provider "zai" cannot hide reasoning content while GLM-5.3 thinking is enabled.');
|
|
192
|
+
}
|
|
193
|
+
if (effort !== undefined && effort !== "low" && effort !== "high" && effort !== "max") {
|
|
194
|
+
throw new UnsupportedFeatureError('Z.ai GLM-5.3 supports shared reasoning effort "low", "high", or "max" only.');
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
thinking: { type: "enabled" },
|
|
198
|
+
...(effort ? { reasoningEffort: effort } : {})
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
if (isGLM52(modelId)) {
|
|
202
|
+
if (effort === "none" || effort === "minimal") {
|
|
203
|
+
if (reasoning.includeThoughts) {
|
|
204
|
+
throw new UnsupportedFeatureError('Provider "zai" cannot include reasoning content while reasoning effort is disabled.');
|
|
205
|
+
}
|
|
206
|
+
return { thinking: { type: "disabled" } };
|
|
207
|
+
}
|
|
208
|
+
if (reasoning.includeThoughts === false) {
|
|
209
|
+
throw new UnsupportedFeatureError('Provider "zai" cannot hide reasoning content while thinking mode is enabled.');
|
|
210
|
+
}
|
|
211
|
+
const mappedEffort = effort === "xhigh" || effort === "max" ? "max" : effort ? "high" : undefined;
|
|
212
|
+
return {
|
|
213
|
+
thinking: { type: "enabled" },
|
|
214
|
+
...(mappedEffort ? { reasoningEffort: mappedEffort } : {})
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
throw new UnsupportedFeatureError(`Provider "zai" model "${modelId}" has no documented shared reasoning contract.`);
|
|
218
|
+
};
|
|
219
|
+
const validateStringLength = (value, field, min, max) => {
|
|
220
|
+
if (value !== undefined && (typeof value !== "string" || value.length < min || value.length > max)) {
|
|
221
|
+
throw new ValidationError(`Z.ai "${field}" must contain ${min}-${max} characters.`);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const validateProviderOptions = (modelId, input) => {
|
|
225
|
+
const options = input.providerOptions;
|
|
226
|
+
if (input.reasoning && (options?.thinking !== undefined || options?.reasoning_effort !== undefined)) {
|
|
227
|
+
throw new ValidationError('Do not combine shared "reasoning" with Z.ai "providerOptions.thinking" or "providerOptions.reasoning_effort".');
|
|
228
|
+
}
|
|
229
|
+
if (options?.thinking !== undefined &&
|
|
230
|
+
(!isJsonObject(options.thinking) ||
|
|
231
|
+
(options.thinking.type !== "enabled" && options.thinking.type !== "disabled") ||
|
|
232
|
+
(options.thinking.clear_thinking !== undefined && typeof options.thinking.clear_thinking !== "boolean"))) {
|
|
233
|
+
throw new ValidationError('Z.ai "thinking" must include type "enabled" or "disabled" and optional boolean "clear_thinking".');
|
|
234
|
+
}
|
|
235
|
+
const effort = options?.reasoning_effort;
|
|
236
|
+
if (effort !== undefined &&
|
|
237
|
+
!["none", "minimal", "low", "medium", "high", "xhigh", "max"].includes(effort)) {
|
|
238
|
+
throw new ValidationError('Z.ai "reasoning_effort" must be "none", "minimal", "low", "medium", "high", "xhigh", or "max".');
|
|
239
|
+
}
|
|
240
|
+
if (isGLM53(modelId)) {
|
|
241
|
+
if (options?.thinking?.type === "disabled") {
|
|
242
|
+
throw new UnsupportedFeatureError('Z.ai GLM-5.3 requires thinking.type "enabled".');
|
|
243
|
+
}
|
|
244
|
+
if (effort !== undefined && effort !== "low" && effort !== "high" && effort !== "max") {
|
|
245
|
+
throw new UnsupportedFeatureError('Z.ai GLM-5.3 supports reasoning_effort "low", "high", or "max" only.');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (options?.thinking?.type === "disabled" && effort !== undefined) {
|
|
249
|
+
throw new UnsupportedFeatureError('Z.ai does not accept "reasoning_effort" while thinking is disabled.');
|
|
250
|
+
}
|
|
251
|
+
const temperature = input.temperature ?? options?.temperature;
|
|
252
|
+
if (temperature !== undefined &&
|
|
253
|
+
(typeof temperature !== "number" || !Number.isFinite(temperature) || temperature < 0 || temperature > 1)) {
|
|
254
|
+
throw new ValidationError('Z.ai "temperature" must be between 0 and 1.');
|
|
255
|
+
}
|
|
256
|
+
if (options?.top_p !== undefined &&
|
|
257
|
+
(typeof options.top_p !== "number" || !Number.isFinite(options.top_p) || options.top_p < 0.01 || options.top_p > 1)) {
|
|
258
|
+
throw new ValidationError('Z.ai "top_p" must be between 0.01 and 1.');
|
|
259
|
+
}
|
|
260
|
+
const maxTokens = input.maxTokens ?? options?.max_tokens;
|
|
261
|
+
if (maxTokens !== undefined && (!Number.isSafeInteger(maxTokens) || maxTokens <= 0 || maxTokens > 131_072)) {
|
|
262
|
+
throw new ValidationError('Z.ai "max_tokens" must be a positive safe integer no greater than 131072.');
|
|
263
|
+
}
|
|
264
|
+
if (options?.stop !== undefined &&
|
|
265
|
+
(!Array.isArray(options.stop) || options.stop.length > 4 || options.stop.some((value) => typeof value !== "string"))) {
|
|
266
|
+
throw new ValidationError('Z.ai "stop" must be an array of at most 4 strings.');
|
|
267
|
+
}
|
|
268
|
+
if (options?.tool_stream !== undefined && typeof options.tool_stream !== "boolean") {
|
|
269
|
+
throw new ValidationError('Z.ai "tool_stream" must be a boolean.');
|
|
270
|
+
}
|
|
271
|
+
if (options?.tool_choice !== undefined && options.tool_choice !== "auto") {
|
|
272
|
+
throw new UnsupportedFeatureError('Z.ai supports tool_choice "auto" only.');
|
|
273
|
+
}
|
|
274
|
+
if (options?.response_format !== undefined &&
|
|
275
|
+
(!isJsonObject(options.response_format) ||
|
|
276
|
+
(options.response_format.type !== "text" && options.response_format.type !== "json_object"))) {
|
|
277
|
+
throw new ValidationError('Z.ai "response_format.type" must be "text" or "json_object".');
|
|
278
|
+
}
|
|
279
|
+
if (options?.do_sample !== undefined && typeof options.do_sample !== "boolean") {
|
|
280
|
+
throw new ValidationError('Z.ai "do_sample" must be a boolean.');
|
|
281
|
+
}
|
|
282
|
+
validateStringLength(options?.request_id, "request_id", 6, 64);
|
|
283
|
+
validateStringLength(options?.user_id, "user_id", 6, 128);
|
|
284
|
+
};
|
|
285
|
+
const mapProviderOptions = (providerOptions) => {
|
|
286
|
+
const { thinking: _thinking, reasoning_effort: _reasoningEffort, temperature: _temperature, max_tokens: _maxTokens, response_format: _responseFormat, tool_stream: _toolStream, tool_choice: _toolChoice, model: _model, messages: _messages, tools: _tools, stream: _stream, ...rest } = providerOptions ?? {};
|
|
287
|
+
return rest;
|
|
288
|
+
};
|
|
289
|
+
const resolveRequestOptions = (modelId, input) => {
|
|
290
|
+
validateProviderOptions(modelId, input);
|
|
291
|
+
const providerOptions = input.providerOptions;
|
|
292
|
+
const sharedReasoning = mapSharedReasoning(modelId, input);
|
|
293
|
+
let thinking = sharedReasoning?.thinking ?? providerOptions?.thinking;
|
|
294
|
+
const reasoningHistory = hasReasoningHistory(input.messages);
|
|
295
|
+
if (isGLM53(modelId) && !thinking) {
|
|
296
|
+
thinking = { type: "enabled" };
|
|
297
|
+
}
|
|
298
|
+
const preserveThinking = reasoningHistory || Boolean(input.tools && Object.keys(input.tools).length);
|
|
299
|
+
const rawThinkingDisabled = isGLM52(modelId) &&
|
|
300
|
+
!sharedReasoning &&
|
|
301
|
+
(providerOptions?.reasoning_effort === "none" || providerOptions?.reasoning_effort === "minimal");
|
|
302
|
+
if (preserveThinking &&
|
|
303
|
+
!rawThinkingDisabled &&
|
|
304
|
+
(thinking?.type === "enabled" || (!thinking && (isGLM53(modelId) || isGLM52(modelId))))) {
|
|
305
|
+
thinking = { ...(thinking ?? { type: "enabled" }), clear_thinking: false };
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
bodyOptions: mapProviderOptions(providerOptions),
|
|
309
|
+
thinking,
|
|
310
|
+
reasoningEffort: sharedReasoning?.reasoningEffort ?? providerOptions?.reasoning_effort,
|
|
311
|
+
temperature: input.temperature ?? providerOptions?.temperature,
|
|
312
|
+
maxTokens: input.maxTokens ?? providerOptions?.max_tokens,
|
|
313
|
+
responseFormat: mapStructuredOutput(input) ?? providerOptions?.response_format,
|
|
314
|
+
toolStream: providerOptions?.tool_stream,
|
|
315
|
+
toolChoice: providerOptions?.tool_choice
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
const jsonHeaders = (apiKey) => ({
|
|
319
|
+
"content-type": "application/json",
|
|
320
|
+
authorization: `Bearer ${apiKey}`
|
|
321
|
+
});
|
|
322
|
+
const parseRetryAfterMs = (value) => {
|
|
323
|
+
if (!value) {
|
|
324
|
+
return undefined;
|
|
325
|
+
}
|
|
326
|
+
const seconds = Number(value.trim());
|
|
327
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
328
|
+
return Math.min(seconds * 1_000, 60_000);
|
|
329
|
+
}
|
|
330
|
+
const date = Date.parse(value);
|
|
331
|
+
if (!Number.isFinite(date)) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
return Math.min(Math.max(date - Date.now(), 0), 60_000);
|
|
335
|
+
};
|
|
336
|
+
const errorStatusFromCode = (code) => {
|
|
337
|
+
const numericCode = Number(code);
|
|
338
|
+
if (Number.isInteger(numericCode) && numericCode >= 400 && numericCode <= 599) {
|
|
339
|
+
return numericCode;
|
|
340
|
+
}
|
|
341
|
+
switch (numericCode) {
|
|
342
|
+
case 1000:
|
|
343
|
+
case 1001:
|
|
344
|
+
case 1003:
|
|
345
|
+
case 1005:
|
|
346
|
+
return 401;
|
|
347
|
+
case 1210:
|
|
348
|
+
case 1211:
|
|
349
|
+
case 1212:
|
|
350
|
+
case 1213:
|
|
351
|
+
case 1214:
|
|
352
|
+
case 1215:
|
|
353
|
+
case 1221:
|
|
354
|
+
case 1222:
|
|
355
|
+
case 1261:
|
|
356
|
+
case 1301:
|
|
357
|
+
return 400;
|
|
358
|
+
case 1220:
|
|
359
|
+
return 403;
|
|
360
|
+
case 1113:
|
|
361
|
+
case 1302:
|
|
362
|
+
case 1305:
|
|
363
|
+
case 1308:
|
|
364
|
+
case 1309:
|
|
365
|
+
case 1310:
|
|
366
|
+
case 1311:
|
|
367
|
+
case 1313:
|
|
368
|
+
case 1314:
|
|
369
|
+
case 1315:
|
|
370
|
+
case 1316:
|
|
371
|
+
case 1317:
|
|
372
|
+
case 1318:
|
|
373
|
+
case 1319:
|
|
374
|
+
case 1320:
|
|
375
|
+
case 1321:
|
|
376
|
+
return 429;
|
|
377
|
+
case 1200:
|
|
378
|
+
case 1230:
|
|
379
|
+
case 1234:
|
|
380
|
+
return 500;
|
|
381
|
+
default:
|
|
382
|
+
return 500;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const providerErrorFromPayload = (payload, fallbackStatus = 0, retryAfterMs) => {
|
|
386
|
+
const error = isJsonObject(payload.error) ? payload.error : undefined;
|
|
387
|
+
const code = error?.code ?? payload.code;
|
|
388
|
+
const message = error?.message ?? payload.message;
|
|
389
|
+
const status = fallbackStatus >= 400 && fallbackStatus <= 599 ? fallbackStatus : errorStatusFromCode(code);
|
|
390
|
+
return new ProviderHTTPError(typeof message === "string" && message ? `Z.ai request failed: ${message}` : "Z.ai request failed.", status, { responseBody: JSON.stringify(payload), retryAfterMs });
|
|
391
|
+
};
|
|
392
|
+
const assertNoErrorPayload = (payload) => {
|
|
393
|
+
if (!isJsonObject(payload)) {
|
|
394
|
+
throw new ParseError("Z.ai returned a non-object response payload.");
|
|
395
|
+
}
|
|
396
|
+
if (payload.error !== undefined || (payload.code !== undefined && !Array.isArray(payload.choices))) {
|
|
397
|
+
throw providerErrorFromPayload(payload);
|
|
398
|
+
}
|
|
399
|
+
return payload;
|
|
400
|
+
};
|
|
401
|
+
const assertResponseOk = async (response) => {
|
|
402
|
+
if (!response.ok) {
|
|
403
|
+
const body = await readErrorBodyWithLimit(response);
|
|
404
|
+
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
|
|
405
|
+
let payload;
|
|
406
|
+
try {
|
|
407
|
+
const parsed = JSON.parse(body);
|
|
408
|
+
payload = isJsonObject(parsed) ? parsed : undefined;
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
// Preserve the bounded raw body below.
|
|
412
|
+
}
|
|
413
|
+
if (payload) {
|
|
414
|
+
throw providerErrorFromPayload(payload, response.status, retryAfterMs);
|
|
415
|
+
}
|
|
416
|
+
throw new ProviderHTTPError(`Z.ai request failed with status ${response.status}.`, response.status, {
|
|
417
|
+
responseBody: body,
|
|
418
|
+
retryAfterMs
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
const parseJson = async (response) => {
|
|
423
|
+
await assertResponseOk(response);
|
|
424
|
+
const json = await readJsonWithLimit(response, {
|
|
425
|
+
maxBytes: 128 * 1024 * 1024,
|
|
426
|
+
provider: "zai",
|
|
427
|
+
endpoint: response.url || undefined
|
|
428
|
+
});
|
|
429
|
+
return assertNoErrorPayload(json);
|
|
430
|
+
};
|
|
431
|
+
const mapUsage = (usage) => usage
|
|
432
|
+
? {
|
|
433
|
+
inputTokens: usage.prompt_tokens,
|
|
434
|
+
cachedInputTokens: usage.prompt_tokens_details?.cached_tokens,
|
|
435
|
+
outputTokens: usage.completion_tokens,
|
|
436
|
+
reasoningTokens: usage.completion_tokens_details?.reasoning_tokens,
|
|
437
|
+
totalTokens: usage.total_tokens
|
|
438
|
+
}
|
|
439
|
+
: undefined;
|
|
440
|
+
const normalizeZAIFinishReason = (finishReason) => {
|
|
441
|
+
switch (finishReason) {
|
|
442
|
+
case "sensitive":
|
|
443
|
+
return "content-filter";
|
|
444
|
+
case "model_context_window_exceeded":
|
|
445
|
+
return "length";
|
|
446
|
+
case "network_error":
|
|
447
|
+
return "error";
|
|
448
|
+
default:
|
|
449
|
+
return normalizeFinishReason(finishReason);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
const parseAssistantMessage = (message) => {
|
|
453
|
+
if (!isJsonObject(message)) {
|
|
454
|
+
throw new ParseError("Z.ai response did not contain an assistant message object.");
|
|
455
|
+
}
|
|
456
|
+
if (message.tool_calls !== undefined && !Array.isArray(message.tool_calls)) {
|
|
457
|
+
throw new ParseError("Z.ai assistant tool_calls must be an array.");
|
|
458
|
+
}
|
|
459
|
+
const toolCalls = (message.tool_calls ?? []).map((call) => {
|
|
460
|
+
if (!isJsonObject(call) || !isJsonObject(call.function)) {
|
|
461
|
+
throw new ParseError("Z.ai returned a malformed tool call.");
|
|
462
|
+
}
|
|
463
|
+
if (typeof call.id !== "string" || !call.id || typeof call.function.name !== "string" || !call.function.name) {
|
|
464
|
+
throw new ParseError("Z.ai tool calls require non-empty string id and function name fields.");
|
|
465
|
+
}
|
|
466
|
+
return {
|
|
467
|
+
type: "tool-call",
|
|
468
|
+
toolCall: {
|
|
469
|
+
id: call.id,
|
|
470
|
+
name: call.function.name,
|
|
471
|
+
input: parseToolArguments(call.function.arguments)
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
});
|
|
475
|
+
return {
|
|
476
|
+
role: "assistant",
|
|
477
|
+
parts: [
|
|
478
|
+
...(typeof message.reasoning_content === "string" && message.reasoning_content
|
|
479
|
+
? [providerDataPart("zai", { type: "reasoning_content", reasoningContent: message.reasoning_content })]
|
|
480
|
+
: []),
|
|
481
|
+
...(typeof message.content === "string" && message.content
|
|
482
|
+
? [{ type: "text", text: message.content }]
|
|
483
|
+
: []),
|
|
484
|
+
...toolCalls
|
|
485
|
+
]
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
class ZAILanguageModel {
|
|
489
|
+
modelId;
|
|
490
|
+
apiKey;
|
|
491
|
+
baseURL;
|
|
492
|
+
fetcher;
|
|
493
|
+
provider = "zai";
|
|
494
|
+
capabilities;
|
|
495
|
+
constructor(modelId, apiKey, baseURL, fetcher) {
|
|
496
|
+
this.modelId = modelId;
|
|
497
|
+
this.apiKey = apiKey;
|
|
498
|
+
this.baseURL = baseURL;
|
|
499
|
+
this.fetcher = fetcher;
|
|
500
|
+
this.capabilities = capabilitiesForModel(modelId);
|
|
501
|
+
}
|
|
502
|
+
async generate(input) {
|
|
503
|
+
const { signal, cleanup } = withTimeoutSignal(input);
|
|
504
|
+
try {
|
|
505
|
+
const options = resolveRequestOptions(this.modelId, input);
|
|
506
|
+
const tools = mapTools(input.tools);
|
|
507
|
+
const json = await withRetry(async () => {
|
|
508
|
+
const response = await this.fetcher(`${this.baseURL}/chat/completions`, {
|
|
509
|
+
method: "POST",
|
|
510
|
+
headers: jsonHeaders(this.apiKey),
|
|
511
|
+
signal,
|
|
512
|
+
body: JSON.stringify({
|
|
513
|
+
...options.bodyOptions,
|
|
514
|
+
model: this.modelId,
|
|
515
|
+
messages: mapMessages(ensureJsonOutputInstruction(input.messages, options.responseFormat, input.structuredOutput)),
|
|
516
|
+
tools,
|
|
517
|
+
tool_choice: tools?.length ? options.toolChoice ?? "auto" : options.toolChoice,
|
|
518
|
+
response_format: options.responseFormat,
|
|
519
|
+
temperature: options.temperature,
|
|
520
|
+
max_tokens: options.maxTokens,
|
|
521
|
+
stream: false,
|
|
522
|
+
...(options.thinking ? { thinking: options.thinking } : {}),
|
|
523
|
+
...(options.reasoningEffort ? { reasoning_effort: options.reasoningEffort } : {})
|
|
524
|
+
})
|
|
525
|
+
});
|
|
526
|
+
return parseJson(response);
|
|
527
|
+
}, { ...input, abortSignal: signal });
|
|
528
|
+
const choices = json.choices;
|
|
529
|
+
if (!Array.isArray(choices) || !choices.length || !isJsonObject(choices[0])) {
|
|
530
|
+
throw new ParseError("Z.ai response did not contain a completion choice.");
|
|
531
|
+
}
|
|
532
|
+
const choice = choices[0];
|
|
533
|
+
const message = parseAssistantMessage(choice.message);
|
|
534
|
+
const providerFinishReason = typeof choice.finish_reason === "string" ? choice.finish_reason : undefined;
|
|
535
|
+
return {
|
|
536
|
+
messages: [message],
|
|
537
|
+
text: message.parts.filter((part) => part.type === "text").map((part) => part.text).join(""),
|
|
538
|
+
finishReason: normalizeZAIFinishReason(providerFinishReason),
|
|
539
|
+
providerFinishReason,
|
|
540
|
+
usage: mapUsage(json.usage),
|
|
541
|
+
rawResponse: json
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
finally {
|
|
545
|
+
cleanup();
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
async stream(input) {
|
|
549
|
+
const { signal, cleanup } = withTimeoutSignal(input);
|
|
550
|
+
let response;
|
|
551
|
+
try {
|
|
552
|
+
const options = resolveRequestOptions(this.modelId, input);
|
|
553
|
+
const tools = mapTools(input.tools);
|
|
554
|
+
response = await withRetry(async () => {
|
|
555
|
+
const result = await this.fetcher(`${this.baseURL}/chat/completions`, {
|
|
556
|
+
method: "POST",
|
|
557
|
+
headers: jsonHeaders(this.apiKey),
|
|
558
|
+
signal,
|
|
559
|
+
body: JSON.stringify({
|
|
560
|
+
...options.bodyOptions,
|
|
561
|
+
model: this.modelId,
|
|
562
|
+
messages: mapMessages(ensureJsonOutputInstruction(input.messages, options.responseFormat, input.structuredOutput)),
|
|
563
|
+
tools,
|
|
564
|
+
tool_choice: tools?.length ? options.toolChoice ?? "auto" : options.toolChoice,
|
|
565
|
+
response_format: options.responseFormat,
|
|
566
|
+
temperature: options.temperature,
|
|
567
|
+
max_tokens: options.maxTokens,
|
|
568
|
+
stream: true,
|
|
569
|
+
tool_stream: tools?.length ? options.toolStream ?? true : options.toolStream,
|
|
570
|
+
...(options.thinking ? { thinking: options.thinking } : {}),
|
|
571
|
+
...(options.reasoningEffort ? { reasoning_effort: options.reasoningEffort } : {})
|
|
572
|
+
})
|
|
573
|
+
});
|
|
574
|
+
await assertResponseOk(result);
|
|
575
|
+
return result;
|
|
576
|
+
}, { ...input, abortSignal: signal });
|
|
577
|
+
}
|
|
578
|
+
catch (error) {
|
|
579
|
+
cleanup();
|
|
580
|
+
throw error;
|
|
581
|
+
}
|
|
582
|
+
return (async function* () {
|
|
583
|
+
try {
|
|
584
|
+
const toolBuffers = new Map();
|
|
585
|
+
let lastFinishReason;
|
|
586
|
+
let lastUsage;
|
|
587
|
+
for await (const event of streamSSE(response)) {
|
|
588
|
+
if (event.data === "[DONE]") {
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
let parsed;
|
|
592
|
+
try {
|
|
593
|
+
parsed = JSON.parse(event.data);
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
throw new ParseError("Z.ai streaming response contained invalid JSON.", { cause: error });
|
|
597
|
+
}
|
|
598
|
+
const json = assertNoErrorPayload(parsed);
|
|
599
|
+
const choice = json.choices?.[0];
|
|
600
|
+
const delta = choice?.delta;
|
|
601
|
+
const usage = json.usage ?? choice?.usage;
|
|
602
|
+
if (usage) {
|
|
603
|
+
lastUsage = usage;
|
|
604
|
+
}
|
|
605
|
+
if (delta?.reasoning_content) {
|
|
606
|
+
yield {
|
|
607
|
+
type: "provider-data",
|
|
608
|
+
provider: "zai",
|
|
609
|
+
data: { type: "reasoning_content", reasoningContent: delta.reasoning_content }
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
if (delta?.content) {
|
|
613
|
+
yield { type: "text-delta", textDelta: delta.content };
|
|
614
|
+
}
|
|
615
|
+
if (delta?.tool_calls !== undefined && !Array.isArray(delta.tool_calls)) {
|
|
616
|
+
throw new ParseError("Z.ai streaming tool_calls must be an array.");
|
|
617
|
+
}
|
|
618
|
+
for (const toolCall of delta?.tool_calls ?? []) {
|
|
619
|
+
if (!isJsonObject(toolCall)) {
|
|
620
|
+
throw new ParseError("Z.ai returned a malformed streaming tool call.");
|
|
621
|
+
}
|
|
622
|
+
if (!Number.isSafeInteger(toolCall.index) || toolCall.index < 0) {
|
|
623
|
+
throw new ParseError("Z.ai streaming tool calls require a non-negative integer index.");
|
|
624
|
+
}
|
|
625
|
+
const index = toolCall.index;
|
|
626
|
+
const existing = toolBuffers.get(index) ?? { id: "", name: "", args: "" };
|
|
627
|
+
existing.id = mergeStreamFragment(existing.id, toolCall.id);
|
|
628
|
+
const toolFunction = isJsonObject(toolCall.function) ? toolCall.function : undefined;
|
|
629
|
+
existing.name = mergeStreamFragment(existing.name, toolFunction?.name);
|
|
630
|
+
existing.args += typeof toolFunction?.arguments === "string" ? toolFunction.arguments : "";
|
|
631
|
+
toolBuffers.set(index, existing);
|
|
632
|
+
}
|
|
633
|
+
if (choice?.finish_reason === "tool_calls") {
|
|
634
|
+
for (const [index, toolCall] of [...toolBuffers.entries()].sort(([left], [right]) => left - right)) {
|
|
635
|
+
if (!toolCall.id || !toolCall.name) {
|
|
636
|
+
throw new ParseError("Z.ai fragmented tool calls require non-empty id and function name fields.");
|
|
637
|
+
}
|
|
638
|
+
yield {
|
|
639
|
+
type: "tool-call",
|
|
640
|
+
toolCall: {
|
|
641
|
+
id: toolCall.id,
|
|
642
|
+
name: toolCall.name,
|
|
643
|
+
input: parseToolArguments(toolCall.args)
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
toolBuffers.clear();
|
|
648
|
+
}
|
|
649
|
+
if (choice?.finish_reason) {
|
|
650
|
+
lastFinishReason = choice.finish_reason;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (toolBuffers.size) {
|
|
654
|
+
throw new ParseError("Z.ai streaming response ended before fragmented tool calls were completed.");
|
|
655
|
+
}
|
|
656
|
+
if (!lastFinishReason) {
|
|
657
|
+
throw new ParseError("Z.ai streaming response ended without a finish reason.");
|
|
658
|
+
}
|
|
659
|
+
yield {
|
|
660
|
+
type: "finish",
|
|
661
|
+
finishReason: normalizeZAIFinishReason(lastFinishReason),
|
|
662
|
+
providerFinishReason: lastFinishReason,
|
|
663
|
+
usage: mapUsage(lastUsage)
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
finally {
|
|
667
|
+
cleanup();
|
|
668
|
+
}
|
|
669
|
+
})();
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
export const createZAI = (options = {}) => {
|
|
673
|
+
const apiKey = options.apiKey ?? process.env.ZAI_API_KEY;
|
|
674
|
+
if (!apiKey) {
|
|
675
|
+
throw new ConfigurationError("Missing Z.ai API key.");
|
|
676
|
+
}
|
|
677
|
+
const endpoint = options.endpoint ?? "general";
|
|
678
|
+
const selectedBaseURL = endpoint === "coding" ? ZAI_CODING_BASE_URL : ZAI_GENERAL_BASE_URL;
|
|
679
|
+
const baseURL = assertTrustedEndpoint(options.baseURL ?? process.env.ZAI_BASE_URL ?? selectedBaseURL, {
|
|
680
|
+
label: "Z.ai baseURL",
|
|
681
|
+
protocols: ["https"],
|
|
682
|
+
allowUnsafe: options.allowUnsafeEndpoints
|
|
683
|
+
}).toString().replace(/\/+$/, "");
|
|
684
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
685
|
+
return createProviderAdapter({
|
|
686
|
+
name: "zai",
|
|
687
|
+
endpoint,
|
|
688
|
+
languageModel: (modelId) => new ZAILanguageModel(modelId, apiKey, baseURL, fetcher),
|
|
689
|
+
rawFetch: fetcher
|
|
690
|
+
});
|
|
691
|
+
};
|
|
692
|
+
/** Conventional camel-case alias for consumers that do not use acronym casing. */
|
|
693
|
+
export const createZai = createZAI;
|
|
694
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,iBAAiB,EASlB,MAAM,iBAAiB,CAAC;AAUzB,MAAM,CAAC,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;AACnE,MAAM,CAAC,MAAM,mBAAmB,GAAG,qCAAqC,CAAC;AAmCzE,MAAM,gBAAgB,GAAsB;IAC1C,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;IACX,gBAAgB,EAAE,IAAI;IACtB,QAAQ,EAAE,IAAI;IACd,UAAU,EAAE,KAAK;IACjB,iBAAiB,EAAE,KAAK;IACxB,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,KAAK;IACZ,UAAU,EAAE,KAAK;IACjB,WAAW,EAAE,KAAK;IAClB,UAAU,EAAE,KAAK;IACjB,cAAc,EAAE,IAAI;IACpB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,iBAAiB,EAAE;QACjB,WAAW,EAAE,QAAQ;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C;QACpB,WAAW,EAAE,OAAO,CAAC,oBAAoB;KAC1C,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC;IAClD,OAAO,qBAAqB,CAAC;QAC3B,IAAI,EAAE,KAAK;QACX,QAAQ;QACR,aAAa,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC;QACnF,QAAQ,EAAE,OAAO;KAClB,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhivex-ai/zai",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Z.ai GLM adapter for Zhivex AI SDK.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=18.18.0",
|
|
11
|
+
"bun": ">=1.3.7"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": false,
|
|
6
24
|
"repository": {
|
|
7
25
|
"type": "git",
|
|
8
26
|
"url": "git+https://github.com/Zhivex/zhivex-ai-sdk.git",
|
|
9
27
|
"directory": "packages/zai"
|
|
10
28
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
29
|
+
"homepage": "https://github.com/Zhivex/zhivex-ai-sdk#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/Zhivex/zhivex-ai-sdk/issues"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"ai",
|
|
35
|
+
"sdk",
|
|
36
|
+
"zai",
|
|
37
|
+
"glm",
|
|
38
|
+
"llm",
|
|
39
|
+
"typescript"
|
|
13
40
|
],
|
|
14
41
|
"publishConfig": {
|
|
15
42
|
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@zhivex-ai/core": "^1.3.0",
|
|
46
|
+
"zod": "^4.4.3"
|
|
16
47
|
}
|
|
17
48
|
}
|