feat(coding): add PI-105 product file host API

This commit is contained in:
2026-08-23 18:17:30 +08:00
parent 7680bfb0cf
commit 9520872d2f
17 changed files with 1419 additions and 38 deletions

View File

@@ -4,21 +4,17 @@ import {
BUNDLED_CODING_SKILL_IDS,
type BundledCodingSkillId,
} from '../../shared/coding-skills';
import type {
ProductCodingCommand,
ProductCodingSkill,
ProductPiCommandInput,
} from '../../shared/coding-product-tools';
export interface ProductCodingSkill {
id: BundledCodingSkillId;
name: string;
description: string;
selected: boolean;
}
export interface ProductCodingCommand {
name: string;
title: string;
description: string;
source: 'makelore' | 'pi' | 'skill';
skillId?: BundledCodingSkillId;
}
export type {
ProductCodingCommand,
ProductCodingSkill,
ProductPiCommandInput,
} from '../../shared/coding-product-tools';
const MAKELORE_COMMANDS: readonly ProductCodingCommand[] = [
{ name: 'models', title: '切换模型', description: '切换当前会话后续轮次使用的模型', source: 'makelore' },
@@ -28,6 +24,8 @@ const MAKELORE_COMMANDS: readonly ProductCodingCommand[] = [
{ name: 'recover', title: '恢复会话', description: '重新创建当前会话 worker 并恢复状态', source: 'makelore' },
] as const;
const COMMAND_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
function frontmatterScalar(content: string, key: string): string | undefined {
const block = content.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/)?.[1];
if (!block) return undefined;
@@ -70,14 +68,15 @@ export async function listProductCodingSkills(
export function buildProductCodingCommandCatalog(
skills: readonly ProductCodingSkill[],
piCommands: readonly { name: string; description?: string }[] = [],
piCommands: readonly ProductPiCommandInput[] = [],
): ProductCodingCommand[] {
const commands = [...MAKELORE_COMMANDS];
const used = new Set(commands.map((command) => command.name));
const used = new Set(commands.map((command) => command.name.toLocaleLowerCase()));
for (const command of piCommands) {
const name = command.name.trim();
if (!name || /\s/u.test(name) || used.has(name)) continue;
used.add(name);
const key = name.toLocaleLowerCase();
if (!COMMAND_NAME_PATTERN.test(name) || used.has(key)) continue;
used.add(key);
commands.push({
name,
title: name,
@@ -86,8 +85,9 @@ export function buildProductCodingCommandCatalog(
});
}
for (const skill of skills) {
if (!skill.selected || used.has(skill.id)) continue;
used.add(skill.id);
const key = skill.id.toLocaleLowerCase();
if (!skill.selected || used.has(key)) continue;
used.add(key);
commands.push({
name: skill.id,
title: skill.name,