@moxxy/plugin-provider-zai 0.45.0 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,CAAC;AAQrB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,kCAazB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,kCAsBnC,CAAC;AAEH,eAAO,MAAM,SAAS,6BAIpB,CAAC;AAEH,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,CAAC;AAQrB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,kCAgBzB,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,kCAsBnC,CAAC;AAEH,eAAO,MAAM,SAAS,6BAIpB,CAAC;AAEH,eAAe,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -21,6 +21,9 @@ const ZAI_DEFAULT_MODEL = 'glm-4.6';
21
21
  * user's OpenAI credential to a third-party host on a misconfigured provider.
22
22
  */
23
23
  export const zaiProviderDef = defineOpenAICompatProvider({
24
+ // Z.ai documents only Chat Completions and checks the key before the route,
25
+ // so a Responses attempt cannot be shown safe: stay on Chat Completions.
26
+ api: 'chat-completions',
24
27
  name: 'zai',
25
28
  baseURL: ZAI_OPENAI_BASE_URL,
26
29
  defaultModel: ZAI_DEFAULT_MODEL,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"A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+1,6 @@
1
1
  {
2
2
  "name": "@moxxy/plugin-provider-zai",
3
- "version": "0.45.0",
3
+ "version": "0.46.0",
4
4
  "description": "z.ai (Zhipu GLM) LLMProvider plugin for moxxy. Ships two providers: `zai` (pay-as-you-go, OpenAI-compatible endpoint) and `zai-coding-plan` (GLM Coding Plan, Anthropic-compatible endpoint).",
5
5
  "keywords": [
6
6
  "moxxy",
@@ -62,9 +62,9 @@
62
62
  }
63
63
  },
64
64
  "dependencies": {
65
- "@moxxy/plugin-provider-anthropic": "0.45.0",
66
- "@moxxy/plugin-provider-openai": "0.45.0",
67
- "@moxxy/sdk": "0.45.0"
65
+ "@moxxy/plugin-provider-anthropic": "0.46.0",
66
+ "@moxxy/plugin-provider-openai": "0.46.0",
67
+ "@moxxy/sdk": "0.46.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/node": "^22.20.5",
package/src/index.ts CHANGED
@@ -24,6 +24,9 @@ const ZAI_DEFAULT_MODEL = 'glm-4.6';
24
24
  * user's OpenAI credential to a third-party host on a misconfigured provider.
25
25
  */
26
26
  export const zaiProviderDef = defineOpenAICompatProvider({
27
+ // Z.ai documents only Chat Completions and checks the key before the route,
28
+ // so a Responses attempt cannot be shown safe: stay on Chat Completions.
29
+ api: 'chat-completions',
27
30
  name: 'zai',
28
31
  baseURL: ZAI_OPENAI_BASE_URL,
29
32
  defaultModel: ZAI_DEFAULT_MODEL,
@@ -0,0 +1,37 @@
1
+ import { createServer } from 'node:http';
2
+ import { once } from 'node:events';
3
+ import { expect, it } from 'vitest';
4
+ import type { LLMProvider } from '@moxxy/sdk';
5
+ import { zaiProviderDef } from './index.js';
6
+
7
+ // Z.ai documents only Chat Completions, and checks the key before the route,
8
+ // so a Responses attempt cannot be shown safe without a real account: Z.ai
9
+ // goes straight to Chat Completions. The vendor server is the boundary.
10
+ it('talks to Z.ai over Chat Completions only, never trying the Responses route', async () => {
11
+ const paths: string[] = [];
12
+ const server = createServer(async (req, res) => {
13
+ for await (const _chunk of req) { /* drain */ }
14
+ paths.push(req.url ?? '');
15
+ res.writeHead(200, { 'Content-Type': 'text/event-stream' });
16
+ const chunk = (delta: object, finish: string | null) => ({ id: 'c', object: 'chat.completion.chunk', created: 0, model: 'glm-4.6', choices: [{ index: 0, delta, finish_reason: finish }] });
17
+ res.end(`data: ${JSON.stringify(chunk({ role: 'assistant', content: 'hello' }, null))}\n\ndata: ${JSON.stringify(chunk({}, 'stop'))}\n\ndata: [DONE]\n\n`);
18
+ });
19
+ server.listen(0, '127.0.0.1');
20
+ await once(server, 'listening');
21
+ try {
22
+ const address = server.address();
23
+ if (!address || typeof address === 'string') throw new Error('No test server');
24
+ const client = zaiProviderDef.createClient({ apiKey: 'zai-test', baseURL: `http://127.0.0.1:${address.port}/api/paas/v4`, maxRetries: 0 }) as LLMProvider;
25
+ let text = '';
26
+ for await (const event of client.stream({ model: 'glm-4.6', messages: [{ role: 'user', content: [{ type: 'text', text: 'hi' }] }] })) {
27
+ if (event.type === 'text_delta') text += event.delta;
28
+ }
29
+ expect(text).toBe('hello');
30
+ expect(paths).toEqual(['/api/paas/v4/chat/completions']);
31
+ } finally {
32
+ const closing = once(server, 'close');
33
+ server.close();
34
+ server.closeAllConnections();
35
+ await closing;
36
+ }
37
+ });