openpencil/scripts/ab-corpus/clients/bailian.ts
Kayshen-X a7d73ebb62 feat(ai): pencil-style agentic design tool-loop, multi-chat tabs, #27 panel restyle
Built-in design generation now runs as an agentic MCP tool-loop (reusing the
agent-rs BuiltInProvider), gated behind OPENPENCIL_DESIGN_AGENT_LOOP / the
Settings experimental toggle; the orchestrator stays the default.

- design-agent system prompt + in-process design toolset (parity-locked with
  the MCP surface) + flag-gated Intent::Design routing
- spawn_agents execution as sequential sub-loops + live creation-mode badges
  (per-agent glow + 'N/M designing...' header)
- new MCP tools: get_guidelines, ToolSearch, get_screenshot, get_editor_state,
  export_nodes, spawn_agents; style-guide local audit
- #27 AI panel restyle: rounded tool cards + green check-rings, gray user
  bubbles, model-pill bottom toolbar, header, empty-state pills, the
  PARALLEL AGENTS (agent_team_size) 1x-6x chip dropdown
- multi-chat tabs: ChatSessions model (Deref-to-active) + tab row UI
  (switch / close / + / Cmd+T) with each run bound to its tab

Large checkpoint commit spanning the working tree (Rust shell crates).
2026-07-02 21:21:06 +08:00

48 lines
1.6 KiB
TypeScript

/**
* 百炼 (Alibaba DashScope Bailian) Coding Plan wrapper. Exposes
* third-party models — including GLM-5 and Kimi K2.5 — through a
* single DashScope endpoint, so the same API key (`DASHSCOPE_BAILIAN_CODING_KEY`)
* covers multiple target models. Cribbed from builtin-provider-presets.ts
* `bailian-coding` preset.
*
* Default baseURL: https://coding.dashscope.aliyuncs.com/v1 (CN).
* Override via `BAILIAN_BASE_URL` if you need the -intl variant.
*/
import type { ChatCallResult } from './openai-compat';
import { callOpenAICompat } from './openai-compat';
// User supplied the 百炼 CP (Coding Plan) key, which targets the
// coding-plan endpoint (not the regular compatible-mode endpoint).
// See builtin-provider-presets.ts `bailian-coding` preset for the
// canonical URL — this is separate from plain `bailian` tier.
const BAILIAN_BASE_URL = process.env.BAILIAN_BASE_URL ?? 'https://coding.dashscope.aliyuncs.com/v1';
const BAILIAN_API_KEY_ENV = 'DASHSCOPE_BAILIAN_CODING_KEY';
export interface CallBailianArgs {
model: string;
system: string;
user: string;
temperature?: number;
maxTokens?: number;
}
export async function callBailian(args: CallBailianArgs): Promise<ChatCallResult> {
const apiKey = process.env[BAILIAN_API_KEY_ENV];
if (!apiKey) {
throw new Error(
`${BAILIAN_API_KEY_ENV} not set — export it (the 百炼 CP sk-sp-... key) before running with --live`,
);
}
return callOpenAICompat({
baseURL: BAILIAN_BASE_URL,
apiKey,
model: args.model,
system: args.system,
user: args.user,
temperature: args.temperature,
maxTokens: args.maxTokens,
label: 'bailian',
});
}