paseo-plugin-zcode-provider 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/NOTICE.md +29 -0
- package/README.md +112 -2
- package/client/account.tsx +827 -0
- package/client/diagnostics.tsx +379 -0
- package/client/runtime.tsx +296 -0
- package/client/settings.tsx +84 -0
- package/client/value.tsx +20 -0
- package/icon.svg +1 -0
- package/index.client.tsx +22 -0
- package/index.server.ts +39 -0
- package/package.json +77 -4
- package/paseo-plugin.json +6 -0
- package/server/account.ts +781 -0
- package/server/attachments.ts +150 -0
- package/server/build-info.ts +2 -0
- package/server/conversation.ts +319 -0
- package/server/diagnostics.ts +252 -0
- package/server/discovery/discover.ts +225 -0
- package/server/discovery/manifest.ts +36 -0
- package/server/discovery/types.ts +30 -0
- package/server/errors.ts +36 -0
- package/server/host/bridge.ts +490 -0
- package/server/host/schemas.ts +119 -0
- package/server/logger.ts +19 -0
- package/server/mapping.ts +270 -0
- package/server/models.ts +68 -0
- package/server/persistence.ts +146 -0
- package/server/presentation.ts +470 -0
- package/server/provider-status.ts +81 -0
- package/server/provider.ts +838 -0
- package/server/runtime/managed.ts +501 -0
- package/server/runtime/pins.ts +72 -0
- package/server/runtime-setup.ts +77 -0
- package/server/session-types.ts +49 -0
- package/server/session.ts +866 -0
- package/server/status.ts +89 -0
- package/server/timeline.ts +18 -0
- package/server/usage.ts +362 -0
- package/server/vendor/zcode/LICENSE +202 -0
- package/server/vendor/zcode/NOTICE.md +70 -0
- package/server/vendor/zcode/THIRD-PARTY-NOTICES.md +37 -0
- package/server/vendor/zcode/packages/model-option-map/src/compiler.ts +92 -0
- package/server/vendor/zcode/packages/model-option-map/src/evaluator.ts +214 -0
- package/server/vendor/zcode/packages/model-option-map/src/index.ts +5 -0
- package/server/vendor/zcode/packages/model-option-map/src/merge-patch.ts +97 -0
- package/server/vendor/zcode/packages/model-option-map/src/option-maps.ts +42 -0
- package/server/vendor/zcode/packages/model-option-map/src/parser.ts +240 -0
- package/server/vendor/zcode/packages/model-option-map/src/tokenizer.ts +141 -0
- package/server/vendor/zcode/packages/model-option-map/src/types.ts +36 -0
- package/server/vendor/zcode/packages/rpc/src/buffer.ts +88 -0
- package/server/vendor/zcode/packages/rpc/src/channelClient.ts +275 -0
- package/server/vendor/zcode/packages/rpc/src/channelServer.ts +283 -0
- package/server/vendor/zcode/packages/rpc/src/channels.shared.ts +66 -0
- package/server/vendor/zcode/packages/rpc/src/channels.ts +4 -0
- package/server/vendor/zcode/packages/rpc/src/delayedChannel.ts +17 -0
- package/server/vendor/zcode/packages/rpc/src/foundation.ts +260 -0
- package/server/vendor/zcode/packages/rpc/src/protocol.ts +397 -0
- package/server/vendor/zcode/packages/rpc/src/proxy-channel.ts +213 -0
- package/server/vendor/zcode/packages/rpc/src/serialization.ts +291 -0
- package/server/vendor/zcode/packages/shared/src/account-provider-state.ts +13 -0
- package/server/vendor/zcode/packages/shared/src/background-bash-output.ts +24 -0
- package/server/vendor/zcode/packages/shared/src/background-task-controls.ts +404 -0
- package/server/vendor/zcode/packages/shared/src/bash-output-display.ts +11 -0
- package/server/vendor/zcode/packages/shared/src/bots.ts +558 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/backend.ts +80 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/command-metadata.ts +170 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/commands.ts +588 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/result.ts +130 -0
- package/server/vendor/zcode/packages/shared/src/browser-use/snapshot.ts +77 -0
- package/server/vendor/zcode/packages/shared/src/command-types.ts +96 -0
- package/server/vendor/zcode/packages/shared/src/config-schema.ts +8 -0
- package/server/vendor/zcode/packages/shared/src/cuaAccessibilitySettings.ts +41 -0
- package/server/vendor/zcode/packages/shared/src/database-startup.ts +178 -0
- package/server/vendor/zcode/packages/shared/src/env.ts +63 -0
- package/server/vendor/zcode/packages/shared/src/execution-output-preview.ts +14 -0
- package/server/vendor/zcode/packages/shared/src/localTtft.ts +192 -0
- package/server/vendor/zcode/packages/shared/src/model-config.ts +123 -0
- package/server/vendor/zcode/packages/shared/src/model-execution.ts +23 -0
- package/server/vendor/zcode/packages/shared/src/model-provider-family.ts +171 -0
- package/server/vendor/zcode/packages/shared/src/model-provider-types.ts +81 -0
- package/server/vendor/zcode/packages/shared/src/model-selection.ts +60 -0
- package/server/vendor/zcode/packages/shared/src/oauth.ts +203 -0
- package/server/vendor/zcode/packages/shared/src/official-mcp-auth.ts +272 -0
- package/server/vendor/zcode/packages/shared/src/official-mcp-tool-error.ts +68 -0
- package/server/vendor/zcode/packages/shared/src/process-diagnostic.ts +42 -0
- package/server/vendor/zcode/packages/shared/src/protocol.ts +369 -0
- package/server/vendor/zcode/packages/shared/src/provider-family-connection-selection.ts +32 -0
- package/server/vendor/zcode/packages/shared/src/remoteAssetInstallMode.ts +11 -0
- package/server/vendor/zcode/packages/shared/src/remoteResourcePackages.ts +91 -0
- package/server/vendor/zcode/packages/shared/src/runtimeEnv.ts +315 -0
- package/server/vendor/zcode/packages/shared/src/settings-source.ts +10 -0
- package/server/vendor/zcode/packages/shared/src/usage-quota.ts +74 -0
- package/server/vendor/zcode/packages/shared/src/usage-stats.ts +462 -0
- package/server/vendor/zcode/packages/shared/src/validationAppSettings.ts +562 -0
- package/server/vendor/zcode/packages/shared/src/workspacePurpose.ts +2 -0
- package/server/vendor/zcode/packages/shared/src/wslUserValidation.ts +33 -0
- package/server/vendor/zcode/packages/shared/src/zcode-agent-policy.ts +25 -0
- package/server/vendor/zcode/packages/shared/src/zcode-media-policy.ts +10 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol/index.ts +3720 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-legacy-types.ts +529 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/apply.ts +218 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/attachment-ref.ts +14 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/command.ts +482 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/core.ts +100 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/create-workflow-display.ts +156 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/cuaPermission.ts +41 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/delta.ts +147 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/input-intent.ts +69 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/rows.ts +432 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/session-config.ts +43 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/sessions-index-workflow-activity.ts +195 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/sessions-index.ts +85 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/shared-context-import.ts +38 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/shared-context-ref.ts +10 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/snapshot.ts +509 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/submission.ts +5 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/toolDisplay.ts +264 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/transport.ts +1152 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-assembler.ts +574 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-binary.ts +65 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-codec.ts +240 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire-fault.ts +39 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/wire.ts +159 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-artifacts.ts +291 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-observation-display.ts +281 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-row-meta.ts +163 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-run-settings-command.ts +62 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-runs-delta.ts +517 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workflow-runs.ts +512 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workspace-config.ts +81 -0
- package/server/vendor/zcode/packages/shared/src/zcode-protocol-v4/workspace-hook-review.ts +210 -0
- package/server/vendor/zcode/packages/shared/src/zcode-task-mode-schema.ts +6 -0
- package/server/vendor/zcode/packages/shared/src/zcode-task-types-core.ts +1187 -0
- package/server/vendor/zcode/packages/shared/src/zcodeEndpoint.ts +296 -0
- package/server/vendor/zcode/provenance.json +405 -0
- package/shared/account.ts +201 -0
- package/shared/diagnostics.ts +52 -0
- package/shared/runtime-setup.ts +73 -0
- package/vendor/acp-registry/LICENSE +176 -0
- package/vendor/paseo/LICENSE +211 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import type { ZCodeEnv } from "./env.js";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_ZCODE_ENDPOINT_ORIGIN = "https://zcode.z.ai";
|
|
4
|
+
export const DEFAULT_BIGMODEL_API_ORIGIN = "https://bigmodel.cn";
|
|
5
|
+
export const DEFAULT_ZAI_OAUTH_ORIGIN = "https://chat.z.ai";
|
|
6
|
+
export const DEFAULT_ZAI_BUSINESS_BASE_URL = "https://api.z.ai";
|
|
7
|
+
export const DEFAULT_ZAI_OAUTH_CLIENT_ID = "client_P8X5CMWmlaRO9gyO-KSqtg";
|
|
8
|
+
|
|
9
|
+
// 构建仅注入公开链接;Node 调用方仍可显式传 env,避免读取另一进程的配置。
|
|
10
|
+
declare const __ZCODE_ENDPOINT_ENV__: Record<string, string | undefined> | undefined;
|
|
11
|
+
export function pickProductEndpointEnv(
|
|
12
|
+
env: Record<string, string | undefined>,
|
|
13
|
+
): Record<string, string> {
|
|
14
|
+
const keys = [
|
|
15
|
+
"ZCODE_BASE_URL",
|
|
16
|
+
"ZCODE_ENDPOINT_ORIGIN",
|
|
17
|
+
"BIGMODEL_API_BASE_URL",
|
|
18
|
+
"ZAI_OAUTH_ORIGIN",
|
|
19
|
+
"ZAI_BUSINESS_BASE_URL",
|
|
20
|
+
"ZAI_OAUTH_CLIENT_ID",
|
|
21
|
+
"ZAI_OAUTH_APP_ID",
|
|
22
|
+
];
|
|
23
|
+
return Object.fromEntries(
|
|
24
|
+
keys.flatMap((key) => (env[key]?.trim() ? [[key, env[key]!.trim()]] : [])),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
export function readProductEndpointEnv(): Record<string, string | undefined> {
|
|
28
|
+
return {
|
|
29
|
+
...(typeof __ZCODE_ENDPOINT_ENV__ === "undefined" ? {} : __ZCODE_ENDPOINT_ENV__),
|
|
30
|
+
...pickProductEndpointEnv(typeof process === "undefined" ? {} : process.env),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ZCodeEndpointUrls {
|
|
35
|
+
origin: string;
|
|
36
|
+
apiBaseUrl: string;
|
|
37
|
+
webShareCallbackUrl: string;
|
|
38
|
+
zcodePlanOpenAiBaseUrl: string;
|
|
39
|
+
zcodePlanAnthropicBaseUrl: string;
|
|
40
|
+
zcodePlanBillingCurrentUrl: string;
|
|
41
|
+
zcodePlanBillingBalanceUrl: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface RuntimeZCodeEndpointEnv {
|
|
45
|
+
[key: string]: string | undefined;
|
|
46
|
+
ZCODE_ENV?: string;
|
|
47
|
+
ZCODE_BASE_URL?: string;
|
|
48
|
+
ZCODE_ENDPOINT_ORIGIN?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface RuntimeBigModelApiEnv {
|
|
52
|
+
[key: string]: string | undefined;
|
|
53
|
+
ZCODE_ENV?: string;
|
|
54
|
+
BIGMODEL_API_BASE_URL?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface RuntimeZaiEndpointEnv {
|
|
58
|
+
[key: string]: string | undefined;
|
|
59
|
+
ZCODE_ENV?: string;
|
|
60
|
+
ZAI_OAUTH_ORIGIN?: string;
|
|
61
|
+
ZAI_BUSINESS_BASE_URL?: string;
|
|
62
|
+
ZAI_OAUTH_CLIENT_ID?: string;
|
|
63
|
+
ZAI_OAUTH_APP_ID?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface RuntimeProductEndpointEnv
|
|
67
|
+
extends RuntimeZCodeEndpointEnv, RuntimeBigModelApiEnv, RuntimeZaiEndpointEnv {}
|
|
68
|
+
|
|
69
|
+
export interface RuntimeProductEndpointConfig {
|
|
70
|
+
zcodeEnv: ZCodeEnv;
|
|
71
|
+
zcodeEndpointOrigin: string;
|
|
72
|
+
zcodeEndpointUrls: ZCodeEndpointUrls;
|
|
73
|
+
zaiOAuthOrigin: string;
|
|
74
|
+
zaiBusinessBaseUrl: string;
|
|
75
|
+
zaiOAuthClientId: string;
|
|
76
|
+
bigModelApiOrigin: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function readRuntimeEnvValue(
|
|
80
|
+
env: Record<string, string | undefined>,
|
|
81
|
+
key: string,
|
|
82
|
+
): string | undefined {
|
|
83
|
+
const value = env[key]?.trim();
|
|
84
|
+
return value ? value : undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function normalizeZCodeEndpointOrigin(value: string): string {
|
|
88
|
+
const trimmed = value.trim();
|
|
89
|
+
if (!trimmed) {
|
|
90
|
+
throw new Error("ZCode endpoint origin is empty");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const parsed = new URL(trimmed);
|
|
94
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
95
|
+
throw new Error("ZCode endpoint origin must use http or https");
|
|
96
|
+
}
|
|
97
|
+
return parsed.origin;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function isLoopbackHostname(hostname: string): boolean {
|
|
101
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function isTrustedCodingPlanWebviewOrigin(
|
|
105
|
+
value: string | null | undefined,
|
|
106
|
+
options?: {
|
|
107
|
+
e2eStoreBridgeEnabled?: boolean;
|
|
108
|
+
},
|
|
109
|
+
): boolean {
|
|
110
|
+
if (!value) return false;
|
|
111
|
+
try {
|
|
112
|
+
const origin = normalizeZCodeEndpointOrigin(value);
|
|
113
|
+
if (
|
|
114
|
+
origin === DEFAULT_ZCODE_ENDPOINT_ORIGIN ||
|
|
115
|
+
origin === resolveRuntimeZCodeEndpointOrigin()
|
|
116
|
+
) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
const parsed = new URL(origin);
|
|
120
|
+
return options?.e2eStoreBridgeEnabled === true && isLoopbackHostname(parsed.hostname);
|
|
121
|
+
} catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function resolveZCodeEndpointOrigin(options?: {
|
|
127
|
+
env?: ZCodeEnv;
|
|
128
|
+
envBaseOrigin?: string | null;
|
|
129
|
+
overrideOrigin?: string | null;
|
|
130
|
+
}): string {
|
|
131
|
+
const origin = options?.overrideOrigin?.trim() || options?.envBaseOrigin?.trim();
|
|
132
|
+
return origin ? normalizeZCodeEndpointOrigin(origin) : DEFAULT_ZCODE_ENDPOINT_ORIGIN;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function resolveRuntimeZCodeEnv(
|
|
136
|
+
env: RuntimeZCodeEndpointEnv = readProductEndpointEnv(),
|
|
137
|
+
): ZCodeEnv {
|
|
138
|
+
// 产品身份仅用于既有展示与安装标识,不参与地址解析。
|
|
139
|
+
return env.ZCODE_ENV?.trim().toLowerCase() === "test" ? "test" : "production";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function resolveRuntimeZCodeEndpointOrigin(
|
|
143
|
+
env: RuntimeZCodeEndpointEnv = readProductEndpointEnv(),
|
|
144
|
+
options?: { overrideOrigin?: string | null },
|
|
145
|
+
): string {
|
|
146
|
+
return resolveZCodeEndpointOrigin({
|
|
147
|
+
envBaseOrigin:
|
|
148
|
+
readRuntimeEnvValue(env, "ZCODE_BASE_URL") ??
|
|
149
|
+
readRuntimeEnvValue(env, "ZCODE_ENDPOINT_ORIGIN"),
|
|
150
|
+
overrideOrigin: options?.overrideOrigin,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function buildRuntimeZCodeEndpointUrls(
|
|
155
|
+
env: RuntimeZCodeEndpointEnv = readProductEndpointEnv(),
|
|
156
|
+
): ZCodeEndpointUrls {
|
|
157
|
+
return buildZCodeEndpointUrls(resolveRuntimeZCodeEndpointOrigin(env));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function buildRuntimeZCodeApiUrl(
|
|
161
|
+
env: RuntimeZCodeEndpointEnv = readProductEndpointEnv(),
|
|
162
|
+
path: string,
|
|
163
|
+
): string {
|
|
164
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
165
|
+
return `${resolveRuntimeZCodeEndpointOrigin(env)}${normalizedPath}`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function resolveBigModelApiOrigin(
|
|
169
|
+
env: RuntimeBigModelApiEnv = readProductEndpointEnv(),
|
|
170
|
+
): string {
|
|
171
|
+
return normalizeZCodeEndpointOrigin(
|
|
172
|
+
readRuntimeEnvValue(env, "BIGMODEL_API_BASE_URL") ?? DEFAULT_BIGMODEL_API_ORIGIN,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function buildBigModelApiUrl(
|
|
177
|
+
env: RuntimeBigModelApiEnv = readProductEndpointEnv(),
|
|
178
|
+
path: string,
|
|
179
|
+
): string {
|
|
180
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
181
|
+
return `${resolveBigModelApiOrigin(env)}${normalizedPath}`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function buildBigModelCodingPlanPersonalManageUrl(
|
|
185
|
+
env: RuntimeBigModelApiEnv = readProductEndpointEnv(),
|
|
186
|
+
): string {
|
|
187
|
+
// 管理页与业务 API 共用显式 origin,避免把已登录账号带到另一个部署。
|
|
188
|
+
return buildBigModelApiUrl(env, "/coding-plan/personal/overview");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function buildBigModelCodingPlanTeamManageUrl(
|
|
192
|
+
env: RuntimeBigModelApiEnv = readProductEndpointEnv(),
|
|
193
|
+
): string {
|
|
194
|
+
return buildBigModelApiUrl(env, "/coding-plan/team/plans");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function resolveZaiOAuthOrigin(
|
|
198
|
+
env: RuntimeZaiEndpointEnv = readProductEndpointEnv(),
|
|
199
|
+
): string {
|
|
200
|
+
return normalizeZCodeEndpointOrigin(
|
|
201
|
+
readRuntimeEnvValue(env, "ZAI_OAUTH_ORIGIN") ?? DEFAULT_ZAI_OAUTH_ORIGIN,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function resolveZaiBusinessBaseUrl(
|
|
206
|
+
env: RuntimeZaiEndpointEnv = readProductEndpointEnv(),
|
|
207
|
+
): string {
|
|
208
|
+
return normalizeZCodeEndpointOrigin(
|
|
209
|
+
readRuntimeEnvValue(env, "ZAI_BUSINESS_BASE_URL") ?? DEFAULT_ZAI_BUSINESS_BASE_URL,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function resolveZaiOAuthClientId(
|
|
214
|
+
env: RuntimeZaiEndpointEnv = readProductEndpointEnv(),
|
|
215
|
+
): string {
|
|
216
|
+
return (
|
|
217
|
+
readRuntimeEnvValue(env, "ZAI_OAUTH_CLIENT_ID") ??
|
|
218
|
+
readRuntimeEnvValue(env, "ZAI_OAUTH_APP_ID") ??
|
|
219
|
+
DEFAULT_ZAI_OAUTH_CLIENT_ID
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function buildZaiOAuthUrl(origin: string, path: string): string {
|
|
224
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
225
|
+
return `${normalizeZCodeEndpointOrigin(origin)}${normalizedPath}`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function buildRuntimeZaiOAuthUrl(
|
|
229
|
+
env: RuntimeZaiEndpointEnv = readProductEndpointEnv(),
|
|
230
|
+
path: string,
|
|
231
|
+
): string {
|
|
232
|
+
return buildZaiOAuthUrl(resolveZaiOAuthOrigin(env), path);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function buildRuntimeZaiBusinessUrl(
|
|
236
|
+
env: RuntimeZaiEndpointEnv = readProductEndpointEnv(),
|
|
237
|
+
path: string,
|
|
238
|
+
): string {
|
|
239
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
240
|
+
return `${resolveZaiBusinessBaseUrl(env)}${normalizedPath}`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function resolveRuntimeProductEndpointConfig(
|
|
244
|
+
env: RuntimeProductEndpointEnv = readProductEndpointEnv(),
|
|
245
|
+
): RuntimeProductEndpointConfig {
|
|
246
|
+
const zcodeEnv = resolveRuntimeZCodeEnv(env);
|
|
247
|
+
const zcodeEndpointOrigin = resolveRuntimeZCodeEndpointOrigin(env);
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
zcodeEnv,
|
|
251
|
+
zcodeEndpointOrigin,
|
|
252
|
+
zcodeEndpointUrls: buildZCodeEndpointUrls(zcodeEndpointOrigin),
|
|
253
|
+
zaiOAuthOrigin: resolveZaiOAuthOrigin(env),
|
|
254
|
+
zaiBusinessBaseUrl: resolveZaiBusinessBaseUrl(env),
|
|
255
|
+
zaiOAuthClientId: resolveZaiOAuthClientId(env),
|
|
256
|
+
bigModelApiOrigin: resolveBigModelApiOrigin(env),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function buildZCodeEndpointUrls(origin: string): ZCodeEndpointUrls {
|
|
261
|
+
const normalizedOrigin = normalizeZCodeEndpointOrigin(origin);
|
|
262
|
+
return {
|
|
263
|
+
origin: normalizedOrigin,
|
|
264
|
+
apiBaseUrl: `${normalizedOrigin}/api/v1`,
|
|
265
|
+
webShareCallbackUrl: `${normalizedOrigin}/cn/share/callback`,
|
|
266
|
+
zcodePlanOpenAiBaseUrl: `${normalizedOrigin}/api/v1/zcode-plan`,
|
|
267
|
+
zcodePlanAnthropicBaseUrl: `${normalizedOrigin}/api/v1/zcode-plan/anthropic`,
|
|
268
|
+
zcodePlanBillingCurrentUrl: `${normalizedOrigin}/api/v1/zcode-plan/billing/current`,
|
|
269
|
+
zcodePlanBillingBalanceUrl: `${normalizedOrigin}/api/v1/zcode-plan/billing/balance`,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function rewriteZCodeEndpointUrl(input: string | URL, endpointOrigin: string): string | URL {
|
|
274
|
+
const originalUrl = typeof input === "string" ? input : input.toString();
|
|
275
|
+
let parsed: URL;
|
|
276
|
+
try {
|
|
277
|
+
parsed = new URL(originalUrl);
|
|
278
|
+
} catch {
|
|
279
|
+
return input;
|
|
280
|
+
}
|
|
281
|
+
const sourceOrigin = DEFAULT_ZCODE_ENDPOINT_ORIGIN;
|
|
282
|
+
if (parsed.origin !== sourceOrigin) {
|
|
283
|
+
return input;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const targetOrigin = normalizeZCodeEndpointOrigin(endpointOrigin);
|
|
287
|
+
if (targetOrigin === sourceOrigin) {
|
|
288
|
+
return input;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const target = new URL(targetOrigin);
|
|
292
|
+
target.pathname = parsed.pathname;
|
|
293
|
+
target.search = parsed.search;
|
|
294
|
+
target.hash = parsed.hash;
|
|
295
|
+
return target.toString();
|
|
296
|
+
}
|