@xiaozhiclaw/provider-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/aliyun-oss-file-upload-adapter.d.ts +44 -0
- package/dist/adapters/aliyun-oss-file-upload-adapter.js +96 -0
- package/dist/adapters/gemini-file-upload-adapter.d.ts +26 -0
- package/dist/adapters/gemini-file-upload-adapter.js +92 -0
- package/dist/adapters/hub-oss-file-upload-adapter.d.ts +29 -0
- package/dist/adapters/hub-oss-file-upload-adapter.js +53 -0
- package/dist/adapters/index.d.ts +10 -0
- package/dist/adapters/index.js +10 -0
- package/dist/adapters/openai-file-upload-adapter.d.ts +38 -0
- package/dist/adapters/openai-file-upload-adapter.js +56 -0
- package/dist/adapters/volcengine-file-upload-adapter.d.ts +24 -0
- package/dist/adapters/volcengine-file-upload-adapter.js +45 -0
- package/dist/builtin-providers.d.ts +8 -0
- package/dist/builtin-providers.js +2237 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/credentials.d.ts +1 -0
- package/dist/credentials.js +8 -0
- package/dist/debug-transport.d.ts +12 -0
- package/dist/debug-transport.js +99 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +12 -0
- package/dist/events.d.ts +48 -0
- package/dist/events.js +1 -0
- package/dist/file-upload-service.d.ts +68 -0
- package/dist/file-upload-service.js +110 -0
- package/dist/gemini-schema-utils.d.ts +17 -0
- package/dist/gemini-schema-utils.js +76 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +33 -0
- package/dist/llm-client.d.ts +43 -0
- package/dist/llm-client.js +217 -0
- package/dist/media-client.d.ts +42 -0
- package/dist/media-client.js +174 -0
- package/dist/media-transport.d.ts +176 -0
- package/dist/media-transport.js +16 -0
- package/dist/media.d.ts +2 -0
- package/dist/media.js +1 -0
- package/dist/model-detection.d.ts +22 -0
- package/dist/model-detection.js +28 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +11 -0
- package/dist/provider-def.d.ts +220 -0
- package/dist/provider-def.js +9 -0
- package/dist/provider-registry.d.ts +51 -0
- package/dist/provider-registry.js +130 -0
- package/dist/provider-tool-api.d.ts +44 -0
- package/dist/provider-tool-api.js +9 -0
- package/dist/provider-variant-resolver.d.ts +35 -0
- package/dist/provider-variant-resolver.js +174 -0
- package/dist/retry.d.ts +37 -0
- package/dist/retry.js +71 -0
- package/dist/transport.d.ts +281 -0
- package/dist/transport.js +27 -0
- package/dist/transports/anthropic-messages.d.ts +65 -0
- package/dist/transports/anthropic-messages.js +1004 -0
- package/dist/transports/gemini-cache-api.d.ts +86 -0
- package/dist/transports/gemini-cache-api.js +141 -0
- package/dist/transports/gemini-file-api.d.ts +90 -0
- package/dist/transports/gemini-file-api.js +164 -0
- package/dist/transports/gemini-generatecontent.d.ts +56 -0
- package/dist/transports/gemini-generatecontent.js +688 -0
- package/dist/transports/gemini-lyria-realtime.d.ts +117 -0
- package/dist/transports/gemini-lyria-realtime.js +295 -0
- package/dist/transports/gemini-media.d.ts +53 -0
- package/dist/transports/gemini-media.js +383 -0
- package/dist/transports/media-resolve.d.ts +50 -0
- package/dist/transports/media-resolve.js +91 -0
- package/dist/transports/minimax-media.d.ts +56 -0
- package/dist/transports/minimax-media.js +433 -0
- package/dist/transports/openai-chat.d.ts +81 -0
- package/dist/transports/openai-chat.js +782 -0
- package/dist/transports/openai-media.d.ts +24 -0
- package/dist/transports/openai-media.js +118 -0
- package/dist/transports/openai-responses.d.ts +63 -0
- package/dist/transports/openai-responses.js +778 -0
- package/dist/transports/qwen-media.d.ts +59 -0
- package/dist/transports/qwen-media.js +411 -0
- package/dist/transports/realtime-transport.d.ts +183 -0
- package/dist/transports/realtime-transport.js +332 -0
- package/dist/transports/volcengine-grounding.d.ts +58 -0
- package/dist/transports/volcengine-grounding.js +69 -0
- package/dist/transports/volcengine-media.d.ts +94 -0
- package/dist/transports/volcengine-media.js +801 -0
- package/dist/transports/volcengine-responses.d.ts +64 -0
- package/dist/transports/volcengine-responses.js +797 -0
- package/dist/transports/zhipu-media.d.ts +82 -0
- package/dist/transports/zhipu-media.js +522 -0
- package/dist/transports/zhipu-tool-api.d.ts +35 -0
- package/dist/transports/zhipu-tool-api.js +126 -0
- package/dist/wire-types.d.ts +51 -0
- package/dist/wire-types.js +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZhipuToolAPI 鈥?Zhipu-specific utility endpoints.
|
|
3
|
+
*
|
|
4
|
+
* Implements ProviderToolAPI for Zhipu GLM platform independent APIs:
|
|
5
|
+
* C1: Web Search 鈥?POST /tools/web-search
|
|
6
|
+
* C2: Reader 鈥?POST /tools/reader (extract web page content)
|
|
7
|
+
* C3: Tokenizer 鈥?POST /tokenizer
|
|
8
|
+
* C4: Moderations 鈥?POST /moderations
|
|
9
|
+
*
|
|
10
|
+
* Base URL: https://open.bigmodel.cn/api/paas/v4
|
|
11
|
+
* Auth: Authorization: Bearer $ZHIPU_API_KEY
|
|
12
|
+
*
|
|
13
|
+
* C5 (File Parser) is handled by document_parsing media handler.
|
|
14
|
+
* C6 (Realtime API) requires WebSocket 鈥?out of scope for this interface.
|
|
15
|
+
*/
|
|
16
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
17
|
+
export class ZhipuToolAPI {
|
|
18
|
+
capabilities = [
|
|
19
|
+
"web_search", "reader", "tokenizer", "moderations",
|
|
20
|
+
];
|
|
21
|
+
baseUrl;
|
|
22
|
+
apiKey;
|
|
23
|
+
timeoutMs;
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
26
|
+
this.apiKey = config.apiKey;
|
|
27
|
+
this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
28
|
+
}
|
|
29
|
+
// 鈹€鈹€ C1: Web Search 鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€
|
|
30
|
+
async webSearch(query, options) {
|
|
31
|
+
const url = `${this.baseUrl}/tools/web-search`;
|
|
32
|
+
const body = {
|
|
33
|
+
tool: "web-search-pro",
|
|
34
|
+
messages: [{ role: "user", content: query }],
|
|
35
|
+
stream: false,
|
|
36
|
+
};
|
|
37
|
+
// GLM web-search returns structured search_result in choices
|
|
38
|
+
const data = await this.postJSON(url, body);
|
|
39
|
+
// Extract results from either format
|
|
40
|
+
const results = [];
|
|
41
|
+
const maxResults = options?.maxResults ?? 10;
|
|
42
|
+
// Format 1: web_search array at top level
|
|
43
|
+
if (data.web_search) {
|
|
44
|
+
for (const r of data.web_search.slice(0, maxResults)) {
|
|
45
|
+
results.push({
|
|
46
|
+
title: r.title ?? "",
|
|
47
|
+
url: r.link ?? "",
|
|
48
|
+
snippet: (r.content ?? "").slice(0, 500),
|
|
49
|
+
content: r.content,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return results;
|
|
53
|
+
}
|
|
54
|
+
// Format 2: nested in choices[].message.tool_calls[].search_result
|
|
55
|
+
for (const choice of data.choices ?? []) {
|
|
56
|
+
for (const tc of choice.message?.tool_calls ?? []) {
|
|
57
|
+
for (const sr of tc.search_result ?? []) {
|
|
58
|
+
if (results.length >= maxResults)
|
|
59
|
+
break;
|
|
60
|
+
results.push({
|
|
61
|
+
title: sr.title ?? "",
|
|
62
|
+
url: sr.link ?? "",
|
|
63
|
+
snippet: (sr.content ?? "").slice(0, 500),
|
|
64
|
+
content: sr.content,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return results;
|
|
70
|
+
}
|
|
71
|
+
// 鈹€鈹€ C2: Reader 鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€
|
|
72
|
+
async reader(pageUrl) {
|
|
73
|
+
const url = `${this.baseUrl}/tools/reader`;
|
|
74
|
+
const body = {
|
|
75
|
+
tool: "reader",
|
|
76
|
+
messages: [{ role: "user", content: pageUrl }],
|
|
77
|
+
stream: false,
|
|
78
|
+
};
|
|
79
|
+
const data = await this.postJSON(url, body);
|
|
80
|
+
const content = data.choices?.[0]?.message?.content ?? "";
|
|
81
|
+
return {
|
|
82
|
+
title: "",
|
|
83
|
+
content,
|
|
84
|
+
url: pageUrl,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// 鈹€鈹€ C3: Tokenizer 鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€
|
|
88
|
+
async tokenize(text, model) {
|
|
89
|
+
const url = `${this.baseUrl}/tokenizer`;
|
|
90
|
+
const body = { model, messages: [{ role: "user", content: text }] };
|
|
91
|
+
const data = await this.postJSON(url, body);
|
|
92
|
+
return {
|
|
93
|
+
tokenCount: data.usage?.total_tokens ?? 0,
|
|
94
|
+
model,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// 鈹€鈹€ C4: Moderations 鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€
|
|
98
|
+
async moderate(text) {
|
|
99
|
+
const url = `${this.baseUrl}/moderations`;
|
|
100
|
+
const body = { input: text };
|
|
101
|
+
const data = await this.postJSON(url, body);
|
|
102
|
+
const first = data.results?.[0];
|
|
103
|
+
return {
|
|
104
|
+
flagged: first?.flagged ?? false,
|
|
105
|
+
categories: first?.categories ?? {},
|
|
106
|
+
scores: first?.category_scores,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// 鈹€鈹€ Helper 鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€
|
|
110
|
+
async postJSON(url, body) {
|
|
111
|
+
const res = await fetch(url, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: {
|
|
114
|
+
"Content-Type": "application/json",
|
|
115
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
116
|
+
},
|
|
117
|
+
body: JSON.stringify(body),
|
|
118
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
119
|
+
});
|
|
120
|
+
if (!res.ok) {
|
|
121
|
+
const errText = await res.text().catch(() => "");
|
|
122
|
+
throw new Error(`Zhipu Tool API error ${res.status}: ${errText}`);
|
|
123
|
+
}
|
|
124
|
+
return res.json();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type ChatMessageRole = "system" | "user" | "assistant" | "tool";
|
|
2
|
+
export interface ThinkingBlock {
|
|
3
|
+
thinking: string;
|
|
4
|
+
signature: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ToolCallMessage {
|
|
7
|
+
id: string;
|
|
8
|
+
type: "function";
|
|
9
|
+
function: {
|
|
10
|
+
name: string;
|
|
11
|
+
arguments: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface ChatMessage {
|
|
15
|
+
role: ChatMessageRole;
|
|
16
|
+
content: string | null;
|
|
17
|
+
tool_calls?: ToolCallMessage[];
|
|
18
|
+
tool_call_id?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
thinkingBlocks?: ThinkingBlock[];
|
|
21
|
+
imageUrls?: string[];
|
|
22
|
+
imageDetail?: "auto" | "low" | "high" | "xhigh";
|
|
23
|
+
imagePixelLimit?: {
|
|
24
|
+
minPixels?: number;
|
|
25
|
+
maxPixels?: number;
|
|
26
|
+
};
|
|
27
|
+
videoUrls?: string[];
|
|
28
|
+
videoFps?: number;
|
|
29
|
+
audioFormat?: "mp3" | "wav" | "aac" | "m4a";
|
|
30
|
+
audioUrls?: string[];
|
|
31
|
+
fileIds?: Array<{
|
|
32
|
+
id: string;
|
|
33
|
+
mimeType?: string;
|
|
34
|
+
size?: number;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export interface ToolDefinition {
|
|
38
|
+
type: "function";
|
|
39
|
+
function: {
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
parameters?: Record<string, unknown>;
|
|
43
|
+
};
|
|
44
|
+
meta?: {
|
|
45
|
+
serialOnly?: boolean;
|
|
46
|
+
parallelSafe?: boolean;
|
|
47
|
+
requiresApproval?: boolean;
|
|
48
|
+
isReadOnly?: boolean;
|
|
49
|
+
isDangerous?: boolean;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xiaozhiclaw/provider-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared QLogic LLM provider adaptation layer",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./*": {
|
|
14
|
+
"types": "./dist/*.d.ts",
|
|
15
|
+
"default": "./dist/*.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22.0.0"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.json",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
32
|
+
}
|
|
33
|
+
}
|