openpencil/scripts/ab-corpus/clients/ark.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

60 lines
2.2 KiB
TypeScript

/**
* 方舟 (Volcengine Ark) Coding Plan wrapper. One API key covers
* multiple third-party models hosted on Ark's coding tier —
* currently GLM-5.1 and KIMI-K2.6. Cribbed from builtin-provider-
* presets.ts `ark-coding` preset.
*
* Default baseURL: https://ark.cn-beijing.volces.com/api/coding/v3
* Override via `ARK_BASE_URL` if Volcengine ever ships a regional
* variant (none published as of 2026-04-22).
*
* Key env var: `ARK_CODING_KEY` — Volcengine's UUID-format ARK
* access key. NOT committed to the repo; export in your shell
* before running `bun scripts/ab-corpus/run.ts --live`.
*/
import type { ChatCallResult } from './openai-compat';
import { callOpenAICompat } from './openai-compat';
const ARK_BASE_URL = process.env.ARK_BASE_URL ?? 'https://ark.cn-beijing.volces.com/api/coding/v3';
const ARK_API_KEY_ENV = 'ARK_CODING_KEY';
export interface CallArkArgs {
model: string;
system: string;
user: string;
temperature?: number;
maxTokens?: number;
}
export async function callArk(args: CallArkArgs): Promise<ChatCallResult> {
const apiKey = process.env[ARK_API_KEY_ENV];
if (!apiKey) {
throw new Error(
`${ARK_API_KEY_ENV} not set — export it (Volcengine 方舟 CP UUID key) before running with --live`,
);
}
// Kimi-K2.6 on Ark CP is markedly more brownout-prone than GLM-5.1
// — ab-v5 (2026-05-02) cut its T arm garbage rate to 17% from
// ab-v2's 42%, but it still contributed 9/14 of the T arm garbage
// and ARK's empty-content / 120s-timeout were the only failure
// modes. Bump the kimi branch to retries=3 (extra 4000ms backoff
// attempt) + timeoutMs=180000 (60s headroom) so slow-but-eventually-
// OK responses don't get clipped. GLM-5.1 keeps the existing
// retries=2 + 120s defaults — its garbage rate is already <2%,
// pushing those would just burn budget on healthy calls.
const isKimi = /^kimi/i.test(args.model);
return callOpenAICompat({
baseURL: ARK_BASE_URL,
apiKey,
model: args.model,
system: args.system,
user: args.user,
temperature: args.temperature,
maxTokens: args.maxTokens,
label: 'ark',
retries: isKimi ? 3 : 2,
timeoutMs: isKimi ? 180_000 : undefined,
});
}