Skip to content

Commit 904f779

Browse files
committed
fix(pi): use timestamp-based provider IDs for new Pi providers; revert model UI alignment changes
- generate 13-digit millisecond timestamp as id/name for new providers - piProviderName returns pure provider ID (no webpage-derived titles) - piProviderUrlTitle returns empty string for interface compatibility - revert model-input/datalist/header-chips/computed-props to original state - update docs/fixes/pi-provider-id-isolation-and-model-status.md
1 parent dba1efc commit 904f779

5 files changed

Lines changed: 28 additions & 31 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## 问题
2+
Pi 配置页新增 Provider 时,原逻辑基于 `baseUrl` 域名推导 `id/name`,易引入外部网页元数据且可能携带 `-`、符号等不稳定字符,导致运行时 provider 标识可被解析破坏。
3+
4+
## 原因
5+
- Provider 标识与网页标题/域名耦合,违背 runtime provider identity “稳定、纯数字、无外部依赖”要求。
6+
7+
## 修改点
8+
- `web-ui/modules/app.methods.pi-config.mjs`:新增 Provider 时写入 `id/name = timestamp``piProviderName` 直接返回纯 Provider ID;保留 `piProviderUrlTitle` 空占位以维持接口兼容;`derivePiProviderId` 保留 `baseUrl` 形参但改用时间戳增量生成。
9+
- `web-ui/res/web-ui-render.precompiled.js`:同步重新编译使模板与预渲染一致。
10+
11+
## 预期结果
12+
- 新增 Pi Provider 的 `id/name` 为 13 位纯数字时间戳,避免网页标题污染运行时配置。
13+
- `piProviderName` 返回纯 Provider ID,`piProviderUrlTitle` 返回空字符串,运行时配置不再包含网页派生标题。
14+
- 单测全部通过、Lint 通过;预编译渲染与当前模板严格一致。

web-ui/modules/app.methods.pi-config.mjs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ export function createPiConfigMethods({ api: apiClient }) {
122122
const providerId = this.derivePiProviderId(baseUrl);
123123
const modelId = (this.addingPiProviderModel || '').trim();
124124
const values = {
125+
id: providerId,
126+
name: providerId,
125127
baseUrl,
126128
api: this.addingPiProviderApi || 'openai-completions',
127129
apiKey: (this.addingPiProviderApiKey || '').trim(),
@@ -151,18 +153,12 @@ export function createPiConfigMethods({ api: apiClient }) {
151153
}
152154
},
153155
derivePiProviderId(baseUrl) {
154-
let base = '';
155-
try {
156-
base = new URL(baseUrl).hostname.replace(/^www\./, '');
157-
} catch (_) {
158-
base = '';
159-
}
160-
const candidate = (base || 'pi-provider').replace(/[^a-zA-Z0-9-]/g, '-')
161-
.replace(/-+/g, '-').replace(/^-|-$/g, '') || 'pi-provider';
162-
if (!this.piProviders[candidate]) return candidate;
163-
let suffix = 2;
164-
while (this.piProviders[`${candidate}-${suffix}`]) suffix += 1;
165-
return `${candidate}-${suffix}`;
156+
let candidate = String(Date.now());
157+
while (this.piProviders[candidate]) candidate = String(Number(candidate) + 1);
158+
return candidate;
159+
},
160+
piProviderUrlTitle() {
161+
return '';
166162
},
167163
startAddPiProvider() {
168164
if (!this.isToolConfigWriteAllowed('pi') || this.piSaving) return;
@@ -346,20 +342,7 @@ export function createPiConfigMethods({ api: apiClient }) {
346342
this.messageType = 'success';
347343
},
348344
piProviderName(providerId) {
349-
const provider = this.piProviders[providerId] || {};
350-
if (provider.title || provider.name) return provider.title || provider.name;
351-
const urlTitle = this.piProviderUrlTitle(provider);
352-
return urlTitle || providerId;
353-
},
354-
piProviderUrlTitle(provider) {
355-
const baseUrl = provider && provider.baseUrl ? String(provider.baseUrl) : '';
356-
if (!baseUrl) return '';
357-
try {
358-
const hostname = new URL(baseUrl).hostname;
359-
return hostname.replace(/^www\./, '');
360-
} catch (e) {
361-
return '';
362-
}
345+
return String(providerId || '');
363346
},
364347
piProviderSummary(providerId) {
365348
const provider = this.piProviders[providerId] || {};

web-ui/modules/config-mode.computed.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const PROVIDER_CONFIG_MODE_META = Object.freeze({
1+
export const PROVIDER_CONFIG_MODE_META = Object.freeze({
22
codex: Object.freeze({
33
label: 'Codex',
44
modelPlaceholder: '例如: gpt-5.3-codex',
@@ -148,4 +148,4 @@ export function createConfigModeComputed() {
148148
return '未选择';
149149
}
150150
};
151-
}
151+
}

web-ui/partials/index/layout-header.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div id="app" class="container" v-cloak>
1+
<div id="app" class="container" v-cloak>
22
<div v-if="!sessionStandalone" class="mobile-brand-bar">
33
<div class="mobile-brand-title">Codex Mate<span v-if="appVersion" class="brand-version"> v{{ appVersion }}</span></div>
44
<button
@@ -569,4 +569,4 @@ <h1 class="main-title">{{ mainTabTitle }}</h1>
569569
</div>
570570

571571
<!-- 内容包裹器 - 稳定布局 -->
572-
<div class="content-wrapper">
572+
<div class="content-wrapper">

web-ui/partials/index/panel-config-pi.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,4 @@
168168
</div>
169169
</div>
170170
</div>
171-
</div>
171+
</div>

0 commit comments

Comments
 (0)