@dobbylab/liftlens-agent 0.0.0-stage → 0.1.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/README.md +11 -2
- package/coaches/README.md +32 -0
- package/coaches/_shared/metrics.md +40 -0
- package/coaches/_shared/protocol.md +26 -0
- package/coaches/_shared/sources.json +327 -0
- package/coaches/coach-china-fitness/SKILL.md +25 -0
- package/coaches/coach-china-fitness/references/gym-floor.md +22 -0
- package/coaches/coach-eastern-periodization/SKILL.md +25 -0
- package/coaches/coach-eastern-periodization/references/periodization.md +10 -0
- package/coaches/coach-ipf-referee/SKILL.md +28 -0
- package/coaches/coach-ipf-referee/references/ipf-checklist.md +23 -0
- package/coaches/coach-nsca-cscs/SKILL.md +24 -0
- package/coaches/coach-nsca-cscs/references/checkpoints.md +24 -0
- package/coaches/coach-rehab-pt/SKILL.md +25 -0
- package/coaches/coach-rehab-pt/references/risk-map.md +11 -0
- package/package.json +48 -4
- package/src/ai-run.mjs +122 -0
- package/src/build-id.mjs +14 -0
- package/src/cli-run.mjs +107 -0
- package/src/cli.mjs +366 -0
- package/src/config.mjs +90 -0
- package/src/runtimes.mjs +349 -0
- package/src/schemas.mjs +64 -0
- package/src/server.mjs +283 -0
- package/src/sync.mjs +110 -0
package/src/runtimes.mjs
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// Runtimes: which agent / model actually writes the coach review.
|
|
2
|
+
//
|
|
3
|
+
// - "claude-code" (default) shells out to the user's own Claude Code (`claude -p`) — see server.mjs.
|
|
4
|
+
// - Other coding-agent CLIs (Gemini CLI, Qwen Code, OpenCode) run headless — see cli-run.mjs.
|
|
5
|
+
// - Everything else goes through the Vercel AI SDK (`ai`) with a community / official provider;
|
|
6
|
+
// the popular OpenAI-compatible services are presets, so users only pass a key.
|
|
7
|
+
// Provider packages are NOT shipped with the agent: they are installed on first use into
|
|
8
|
+
// ~/.liftlens/runtimes (optional deps skipped, so e.g. Codex's bundled 300MB binary is never
|
|
9
|
+
// downloaded — we point the provider at the user's installed CLI instead).
|
|
10
|
+
//
|
|
11
|
+
// Secrets (API keys) live only in ~/.liftlens/config.json (0600) or environment variables.
|
|
12
|
+
|
|
13
|
+
import { execFileSync } from 'node:child_process'
|
|
14
|
+
import fs from 'node:fs'
|
|
15
|
+
import os from 'node:os'
|
|
16
|
+
import path from 'node:path'
|
|
17
|
+
import { createRequire } from 'node:module'
|
|
18
|
+
import { pathToFileURL } from 'node:url'
|
|
19
|
+
import { HOME, which } from './config.mjs'
|
|
20
|
+
|
|
21
|
+
export const RUNTIME_DIR = path.join(HOME, 'runtimes')
|
|
22
|
+
const CONFIG_FILE = path.join(HOME, 'config.json')
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------- config
|
|
25
|
+
|
|
26
|
+
export function readConfig() {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf8'))
|
|
29
|
+
} catch {
|
|
30
|
+
return {}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function writeConfig(cfg) {
|
|
34
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(cfg, null, 2), { mode: 0o600 })
|
|
35
|
+
}
|
|
36
|
+
const rcfg = (id) => readConfig().runtimes?.[id] ?? {}
|
|
37
|
+
|
|
38
|
+
// ---------------------------------------------------------------- on-demand provider install
|
|
39
|
+
|
|
40
|
+
function ensureRuntimeDir() {
|
|
41
|
+
fs.mkdirSync(RUNTIME_DIR, { recursive: true })
|
|
42
|
+
const pj = path.join(RUNTIME_DIR, 'package.json')
|
|
43
|
+
if (!fs.existsSync(pj)) fs.writeFileSync(pj, JSON.stringify({ name: 'liftlens-runtimes', private: true, type: 'module' }, null, 2))
|
|
44
|
+
}
|
|
45
|
+
export function isInstalled(pkg) {
|
|
46
|
+
return fs.existsSync(path.join(RUNTIME_DIR, 'node_modules', pkg, 'package.json'))
|
|
47
|
+
}
|
|
48
|
+
/** npm-install a provider package next to the agent (skips optional deps such as bundled CLI binaries). */
|
|
49
|
+
export function installPkg(spec) {
|
|
50
|
+
ensureRuntimeDir()
|
|
51
|
+
const npm = path.join(path.dirname(process.execPath), process.platform === 'win32' ? 'npm.cmd' : 'npm')
|
|
52
|
+
execFileSync(fs.existsSync(npm) ? npm : 'npm', ['install', spec, '--omit=optional', '--no-audit', '--no-fund', '--loglevel=error'], {
|
|
53
|
+
cwd: RUNTIME_DIR,
|
|
54
|
+
stdio: 'pipe',
|
|
55
|
+
timeout: 5 * 60 * 1000,
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
async function importPkg(pkg, sub = '') {
|
|
59
|
+
const req = createRequire(path.join(RUNTIME_DIR, 'package.json'))
|
|
60
|
+
return import(pathToFileURL(req.resolve(sub ? `${pkg}/${sub}` : pkg)).href)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ---------------------------------------------------------------- detection helpers
|
|
64
|
+
|
|
65
|
+
const env = (...names) => names.find((n) => process.env[n])
|
|
66
|
+
async function ollamaModels(baseURL) {
|
|
67
|
+
try {
|
|
68
|
+
const r = await fetch(`${baseURL.replace(/\/api\/?$/, '')}/api/tags`, { signal: AbortSignal.timeout(1500) })
|
|
69
|
+
if (!r.ok) return null
|
|
70
|
+
return ((await r.json()).models ?? []).map((m) => m.name)
|
|
71
|
+
} catch {
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function codexConfiguredModel() {
|
|
76
|
+
try {
|
|
77
|
+
const t = fs.readFileSync(path.join(os.homedir(), '.codex', 'config.toml'), 'utf8')
|
|
78
|
+
return /^\s*model\s*=\s*"([^"]+)"/m.exec(t)?.[1] ?? null
|
|
79
|
+
} catch {
|
|
80
|
+
return null
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------- factories
|
|
85
|
+
|
|
86
|
+
/** A popular OpenAI-compatible service as a one-flag preset: `use <id> --key ... --model ...`. */
|
|
87
|
+
function compat({ id, label, group = 'cloud', baseURL, envKey, keyless = false, defaultModel, noImages = false, note }) {
|
|
88
|
+
return {
|
|
89
|
+
id,
|
|
90
|
+
label,
|
|
91
|
+
group,
|
|
92
|
+
engine: 'ai-sdk',
|
|
93
|
+
pkg: '@ai-sdk/openai-compatible@^3',
|
|
94
|
+
note,
|
|
95
|
+
noImages,
|
|
96
|
+
detect: async () => {
|
|
97
|
+
const c = rcfg(id)
|
|
98
|
+
if (!keyless && !c.apiKey && !(envKey && process.env[envKey])) return { ok: false, reason: `未配置 API key(${envKey})` }
|
|
99
|
+
const model = c.model ?? defaultModel
|
|
100
|
+
return model ? { ok: true, model } : { ok: false, reason: '需要指定模型(--model)' }
|
|
101
|
+
},
|
|
102
|
+
create: (m, model) => {
|
|
103
|
+
const c = rcfg(id)
|
|
104
|
+
return m.createOpenAICompatible({ name: id, baseURL: c.baseURL ?? baseURL, apiKey: c.apiKey ?? (envKey ? process.env[envKey] : undefined) ?? (keyless ? 'local' : undefined) })(model)
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A coding-agent CLI the user is already logged into, run headless. */
|
|
110
|
+
function cliAgent({ id, label, bin, note, args }) {
|
|
111
|
+
return {
|
|
112
|
+
id,
|
|
113
|
+
label,
|
|
114
|
+
group: 'local',
|
|
115
|
+
engine: 'cli',
|
|
116
|
+
note,
|
|
117
|
+
args,
|
|
118
|
+
detect: async () => {
|
|
119
|
+
const p = rcfg(id).path ?? which(bin)
|
|
120
|
+
return p ? { ok: true, model: rcfg(id).model ?? `${label} 默认模型`, path: p } : { ok: false, reason: `没有找到 ${bin} 命令` }
|
|
121
|
+
},
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ---------------------------------------------------------------- registry
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Each runtime: { id, label, group: 'local'|'cloud', engine: 'claude-cli'|'cli'|'ai-sdk', pkg?, sub?,
|
|
129
|
+
* note, detect(): Promise<{ ok, reason?, model? }>, create(mod, model) => LanguageModel }
|
|
130
|
+
*/
|
|
131
|
+
export const RUNTIMES = [
|
|
132
|
+
{
|
|
133
|
+
id: 'claude-code',
|
|
134
|
+
label: 'Claude Code',
|
|
135
|
+
group: 'local',
|
|
136
|
+
engine: 'claude-cli',
|
|
137
|
+
note: '你电脑上已登录的 Claude Code(你自己的订阅)',
|
|
138
|
+
detect: async () => {
|
|
139
|
+
const p = process.env.LIFTLENS_CLAUDE ?? which('claude')
|
|
140
|
+
return p ? { ok: true, model: process.env.LIFTLENS_MODEL ?? 'Claude Code 默认模型' } : { ok: false, reason: '没有找到 claude 命令' }
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: 'codex',
|
|
145
|
+
label: 'Codex CLI',
|
|
146
|
+
group: 'local',
|
|
147
|
+
engine: 'ai-sdk',
|
|
148
|
+
pkg: 'ai-sdk-provider-codex-cli@^2',
|
|
149
|
+
note: '你电脑上已登录的 OpenAI Codex CLI(你自己的订阅)',
|
|
150
|
+
detect: async () => {
|
|
151
|
+
const p = rcfg('codex').path ?? which('codex')
|
|
152
|
+
if (!p) return { ok: false, reason: '没有找到 codex 命令' }
|
|
153
|
+
return { ok: true, model: rcfg('codex').model ?? codexConfiguredModel() ?? 'gpt-6-sol' }
|
|
154
|
+
},
|
|
155
|
+
create: (m, model) =>
|
|
156
|
+
m.createCodexExec({
|
|
157
|
+
defaultSettings: {
|
|
158
|
+
codexPath: rcfg('codex').path ?? which('codex'),
|
|
159
|
+
allowNpx: false,
|
|
160
|
+
skipGitRepoCheck: true,
|
|
161
|
+
sandboxMode: 'read-only',
|
|
162
|
+
approvalMode: 'never',
|
|
163
|
+
},
|
|
164
|
+
})(model),
|
|
165
|
+
},
|
|
166
|
+
// Headless coding-agent CLIs: prompt + attached files in, text out (JSON extracted locally).
|
|
167
|
+
cliAgent({
|
|
168
|
+
id: 'gemini-cli',
|
|
169
|
+
label: 'Gemini CLI',
|
|
170
|
+
bin: 'gemini',
|
|
171
|
+
note: '你电脑上已登录的 Gemini CLI(Google 账号免费额度或你的 API key)',
|
|
172
|
+
// `@path` pulls a file (images included) into the prompt; -y: never stop for a tool approval
|
|
173
|
+
args: ({ prompt, files, model }) => ['-p', `${prompt}\n\n${files.map((f) => `@${f}`).join(' ')}`, '-y', ...(model ? ['-m', model] : [])],
|
|
174
|
+
}),
|
|
175
|
+
cliAgent({
|
|
176
|
+
id: 'qwen-code',
|
|
177
|
+
label: 'Qwen Code',
|
|
178
|
+
bin: 'qwen',
|
|
179
|
+
note: '你电脑上已登录的 Qwen Code(通义账号免费额度或你的 API key)',
|
|
180
|
+
args: ({ prompt, files, model }) => ['-p', `${prompt}\n\n${files.map((f) => `@${f}`).join(' ')}`, '-y', ...(model ? ['-m', model] : [])],
|
|
181
|
+
}),
|
|
182
|
+
cliAgent({
|
|
183
|
+
id: 'opencode',
|
|
184
|
+
label: 'OpenCode',
|
|
185
|
+
bin: 'opencode',
|
|
186
|
+
note: '你电脑上的 OpenCode,用它里面配置好的模型(--model provider/model 可指定)',
|
|
187
|
+
args: ({ prompt, files, model }) => ['run', ...files.flatMap((f) => ['-f', f]), ...(model ? ['-m', model] : []), prompt],
|
|
188
|
+
}),
|
|
189
|
+
{
|
|
190
|
+
id: 'ollama',
|
|
191
|
+
label: 'Ollama 本地模型',
|
|
192
|
+
group: 'local',
|
|
193
|
+
engine: 'ai-sdk',
|
|
194
|
+
pkg: 'ollama-ai-provider-v2@^4',
|
|
195
|
+
note: '完全离线:本机 Ollama 上的视觉模型(需能看图,如 llava、qwen-vl 系列)',
|
|
196
|
+
detect: async () => {
|
|
197
|
+
const base = rcfg('ollama').baseURL ?? process.env.OLLAMA_BASE_URL ?? 'http://127.0.0.1:11434/api'
|
|
198
|
+
const models = await ollamaModels(base)
|
|
199
|
+
if (!models) return { ok: false, reason: 'Ollama 没有运行(127.0.0.1:11434)' }
|
|
200
|
+
const model = rcfg('ollama').model ?? models.find((n) => /vl|vision|llava|gemma3|qwen2\.5vl/i.test(n)) ?? models[0]
|
|
201
|
+
return model ? { ok: true, model } : { ok: false, reason: 'Ollama 里还没有模型,先 ollama pull 一个视觉模型' }
|
|
202
|
+
},
|
|
203
|
+
create: (m, model) => m.createOllama({ baseURL: rcfg('ollama').baseURL ?? process.env.OLLAMA_BASE_URL })(model),
|
|
204
|
+
},
|
|
205
|
+
compat({
|
|
206
|
+
id: 'lmstudio',
|
|
207
|
+
label: 'LM Studio 本地模型',
|
|
208
|
+
group: 'local',
|
|
209
|
+
baseURL: 'http://127.0.0.1:1234/v1',
|
|
210
|
+
keyless: true,
|
|
211
|
+
note: '完全离线:LM Studio 本地服务器(开发者 › 启动服务器),选一个能看图的模型',
|
|
212
|
+
}),
|
|
213
|
+
{
|
|
214
|
+
id: 'anthropic',
|
|
215
|
+
label: 'Claude API',
|
|
216
|
+
group: 'cloud',
|
|
217
|
+
engine: 'ai-sdk',
|
|
218
|
+
pkg: '@ai-sdk/anthropic@^4',
|
|
219
|
+
note: 'Anthropic API key(console.anthropic.com),按量计费',
|
|
220
|
+
detect: async () =>
|
|
221
|
+
rcfg('anthropic').apiKey || env('ANTHROPIC_API_KEY')
|
|
222
|
+
? { ok: true, model: rcfg('anthropic').model ?? 'claude-opus-5-5' }
|
|
223
|
+
: { ok: false, reason: '未配置 API key(ANTHROPIC_API_KEY)' },
|
|
224
|
+
create: (m, model) => m.createAnthropic({ apiKey: rcfg('anthropic').apiKey })(model),
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
id: 'bedrock',
|
|
228
|
+
label: 'Claude on Amazon Bedrock',
|
|
229
|
+
group: 'cloud',
|
|
230
|
+
engine: 'ai-sdk',
|
|
231
|
+
pkg: '@ai-sdk/amazon-bedrock@^5',
|
|
232
|
+
note: '用 AWS 凭证(AWS_PROFILE / AWS_ACCESS_KEY_ID)+ 区域',
|
|
233
|
+
detect: async () => {
|
|
234
|
+
const k = env('AWS_REGION', 'AWS_DEFAULT_REGION')
|
|
235
|
+
const region = rcfg('bedrock').region ?? (k ? process.env[k] : null)
|
|
236
|
+
return region
|
|
237
|
+
? { ok: true, model: rcfg('bedrock').model ?? 'anthropic.claude-opus-5-5' }
|
|
238
|
+
: { ok: false, reason: '未配置 AWS 区域(AWS_REGION)' }
|
|
239
|
+
},
|
|
240
|
+
create: (m, model) => m.createAmazonBedrock({ region: rcfg('bedrock').region })(model),
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: 'vertex',
|
|
244
|
+
label: 'Claude on Google Vertex AI',
|
|
245
|
+
group: 'cloud',
|
|
246
|
+
engine: 'ai-sdk',
|
|
247
|
+
pkg: '@ai-sdk/google-vertex@^5',
|
|
248
|
+
sub: 'anthropic',
|
|
249
|
+
note: '用 GCP 应用默认凭证(gcloud auth application-default login)+ 项目 + 区域',
|
|
250
|
+
detect: async () =>
|
|
251
|
+
rcfg('vertex').project || env('GOOGLE_VERTEX_PROJECT')
|
|
252
|
+
? { ok: true, model: rcfg('vertex').model ?? 'claude-opus-5-5' }
|
|
253
|
+
: { ok: false, reason: '未配置 GCP 项目(GOOGLE_VERTEX_PROJECT)' },
|
|
254
|
+
create: (m, model) =>
|
|
255
|
+
m.createGoogleVertexAnthropic({ project: rcfg('vertex').project, location: rcfg('vertex').location ?? process.env.GOOGLE_VERTEX_LOCATION ?? 'global' })(model),
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
id: 'google',
|
|
259
|
+
label: 'Gemini API',
|
|
260
|
+
group: 'cloud',
|
|
261
|
+
engine: 'ai-sdk',
|
|
262
|
+
pkg: '@ai-sdk/google@^4',
|
|
263
|
+
note: 'Google AI Studio API key',
|
|
264
|
+
detect: async () => {
|
|
265
|
+
if (!rcfg('google').apiKey && !env('GOOGLE_GENERATIVE_AI_API_KEY')) return { ok: false, reason: '未配置 API key(GOOGLE_GENERATIVE_AI_API_KEY)' }
|
|
266
|
+
return rcfg('google').model ? { ok: true, model: rcfg('google').model } : { ok: false, reason: '需要指定模型(--model)' }
|
|
267
|
+
},
|
|
268
|
+
create: (m, model) => m.createGoogle({ apiKey: rcfg('google').apiKey })(model),
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
id: 'openai',
|
|
272
|
+
label: 'OpenAI API',
|
|
273
|
+
group: 'cloud',
|
|
274
|
+
engine: 'ai-sdk',
|
|
275
|
+
pkg: '@ai-sdk/openai@^4',
|
|
276
|
+
note: 'OpenAI API key',
|
|
277
|
+
detect: async () => {
|
|
278
|
+
if (!rcfg('openai').apiKey && !env('OPENAI_API_KEY')) return { ok: false, reason: '未配置 API key(OPENAI_API_KEY)' }
|
|
279
|
+
return rcfg('openai').model ? { ok: true, model: rcfg('openai').model } : { ok: false, reason: '需要指定模型(--model)' }
|
|
280
|
+
},
|
|
281
|
+
create: (m, model) => m.createOpenAI({ apiKey: rcfg('openai').apiKey })(model),
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
id: 'openai-compatible',
|
|
285
|
+
label: 'OpenAI 兼容接口',
|
|
286
|
+
group: 'cloud',
|
|
287
|
+
engine: 'ai-sdk',
|
|
288
|
+
pkg: '@ai-sdk/openai-compatible@^3',
|
|
289
|
+
note: 'DeepSeek、通义千问、Kimi、智谱等兼容 OpenAI 接口的服务(需要支持看图的模型)',
|
|
290
|
+
detect: async () => {
|
|
291
|
+
const c = rcfg('openai-compatible')
|
|
292
|
+
if (!c.baseURL) return { ok: false, reason: '需要配置 --base-url' }
|
|
293
|
+
return c.model ? { ok: true, model: c.model } : { ok: false, reason: '需要指定模型(--model)' }
|
|
294
|
+
},
|
|
295
|
+
create: (m, model) => {
|
|
296
|
+
const c = rcfg('openai-compatible')
|
|
297
|
+
return m.createOpenAICompatible({ name: c.name ?? 'compatible', baseURL: c.baseURL, apiKey: c.apiKey })(model)
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
compat({ id: 'openrouter', label: 'OpenRouter', baseURL: 'https://openrouter.ai/api/v1', envKey: 'OPENROUTER_API_KEY', note: '一个 key 用几百个模型(Claude / GPT / Gemini / Qwen…),选能看图的' }),
|
|
301
|
+
compat({ id: 'qwen', label: '通义千问(阿里云百炼)', baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1', envKey: 'DASHSCOPE_API_KEY', note: '百炼 API key,视觉模型如 qwen-vl-max' }),
|
|
302
|
+
compat({ id: 'doubao', label: '豆包(火山方舟)', baseURL: 'https://ark.cn-beijing.volces.com/api/v3', envKey: 'ARK_API_KEY', note: '火山方舟 API key,模型填能看图的豆包模型或推理接入点 ID' }),
|
|
303
|
+
compat({ id: 'kimi', label: 'Kimi(月之暗面)', baseURL: 'https://api.moonshot.cn/v1', envKey: 'MOONSHOT_API_KEY', note: 'Moonshot API key,选带 vision 的模型' }),
|
|
304
|
+
compat({ id: 'glm', label: '智谱 GLM', baseURL: 'https://open.bigmodel.cn/api/paas/v4', envKey: 'ZHIPUAI_API_KEY', note: '智谱开放平台 API key,视觉模型如 GLM-4V 系列' }),
|
|
305
|
+
compat({ id: 'siliconflow', label: '硅基流动', baseURL: 'https://api.siliconflow.cn/v1', envKey: 'SILICONFLOW_API_KEY', note: '硅基流动 API key,选能看图的开源模型(Qwen-VL、GLM-V 等)' }),
|
|
306
|
+
compat({ id: 'deepseek', label: 'DeepSeek', baseURL: 'https://api.deepseek.com/v1', envKey: 'DEEPSEEK_API_KEY', defaultModel: 'deepseek-chat', noImages: true, note: 'DeepSeek API key;不能看图,只根据测量数据点评' }),
|
|
307
|
+
]
|
|
308
|
+
|
|
309
|
+
export const runtimeById = (id) => RUNTIMES.find((r) => r.id === id)
|
|
310
|
+
export const currentRuntimeId = () => readConfig().runtime ?? 'claude-code'
|
|
311
|
+
|
|
312
|
+
/** Public listing for the web UI — never includes secrets. */
|
|
313
|
+
export async function listRuntimes() {
|
|
314
|
+
const current = currentRuntimeId()
|
|
315
|
+
return Promise.all(
|
|
316
|
+
RUNTIMES.map(async (r) => {
|
|
317
|
+
const d = await r.detect()
|
|
318
|
+
return {
|
|
319
|
+
id: r.id,
|
|
320
|
+
label: r.label,
|
|
321
|
+
group: r.group,
|
|
322
|
+
note: r.note,
|
|
323
|
+
available: !!d.ok,
|
|
324
|
+
reason: d.reason ?? null,
|
|
325
|
+
model: d.model ?? null,
|
|
326
|
+
installed: r.engine !== 'ai-sdk' || !r.pkg ? true : isInstalled(r.pkg.replace(/@[^@/]*$/, '')),
|
|
327
|
+
current: r.id === current,
|
|
328
|
+
verified: r.id === 'claude-code',
|
|
329
|
+
engine: r.engine,
|
|
330
|
+
}
|
|
331
|
+
}),
|
|
332
|
+
)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Resolve a ready-to-use AI SDK LanguageModel for a runtime (installs its provider if needed). */
|
|
336
|
+
export async function createModel(id, onStatus = () => {}) {
|
|
337
|
+
const r = runtimeById(id)
|
|
338
|
+
if (!r) throw new Error(`未知的运行时:${id}`)
|
|
339
|
+
if (r.engine !== 'ai-sdk' || !r.pkg || !r.create) throw new Error(`${r.label} 不走 AI SDK`)
|
|
340
|
+
const d = await r.detect()
|
|
341
|
+
if (!d.ok) throw new Error(`${r.label} 不可用:${d.reason}`)
|
|
342
|
+
const name = r.pkg.replace(/@[^@/]*$/, '')
|
|
343
|
+
if (!isInstalled(name)) {
|
|
344
|
+
onStatus(`首次使用 ${r.label},正在安装适配包 ${name}…`)
|
|
345
|
+
installPkg(r.pkg)
|
|
346
|
+
}
|
|
347
|
+
const mod = await importPkg(name, r.sub)
|
|
348
|
+
return { model: r.create(mod, d.model), modelId: d.model, label: r.label, noImages: !!r.noImages }
|
|
349
|
+
}
|
package/src/schemas.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// JSON Schemas passed to `claude -p --json-schema`, so the agent's reply is
|
|
2
|
+
// validated structured output instead of free text we would have to parse.
|
|
3
|
+
|
|
4
|
+
const cue = {
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
title: { type: 'string', description: '一句话问题或要点(中文,≤20字)' },
|
|
8
|
+
detail: { type: 'string', description: '为什么 + 怎么改,具体到动作口令' },
|
|
9
|
+
priority: { type: 'string', enum: ['high', 'medium', 'low'] },
|
|
10
|
+
evidence: { type: 'string', description: '依据:引用的 metric 数值或关键帧文件名' },
|
|
11
|
+
sourceIds: { type: 'array', items: { type: 'string' }, description: '引用的 source id(必须来自 SOURCES 列表)' },
|
|
12
|
+
},
|
|
13
|
+
required: ['title', 'detail', 'priority', 'sourceIds'],
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const sessionSchema = {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
verdict: { type: 'string', enum: ['solid', 'needs_work', 'unsafe'] },
|
|
21
|
+
score: { type: 'integer', minimum: 0, maximum: 100, description: '动作质量分' },
|
|
22
|
+
summary: { type: 'string', description: '2~3 句总体评价' },
|
|
23
|
+
cues: { type: 'array', items: cue, maxItems: 6 },
|
|
24
|
+
metricDisagreements: {
|
|
25
|
+
type: 'array',
|
|
26
|
+
items: { type: 'string' },
|
|
27
|
+
description: '你从关键帧看到、但与程序测量结果不一致的地方(例如遮挡导致的误判)',
|
|
28
|
+
},
|
|
29
|
+
cameraAdvice: { type: 'string', description: '下次拍摄需要补充/调整的机位,没有则空字符串' },
|
|
30
|
+
nextSession: { type: 'string', description: '下次训练的具体建议(重量/次数/辅助练习)' },
|
|
31
|
+
},
|
|
32
|
+
required: ['verdict', 'score', 'summary', 'cues', 'metricDisagreements', 'cameraAdvice', 'nextSession'],
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const progressSchema = {
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
headline: { type: 'string' },
|
|
40
|
+
strengths: { type: 'array', items: { type: 'string' } },
|
|
41
|
+
weaknesses: { type: 'array', items: { type: 'string' } },
|
|
42
|
+
trends: {
|
|
43
|
+
type: 'array',
|
|
44
|
+
items: {
|
|
45
|
+
type: 'object',
|
|
46
|
+
properties: {
|
|
47
|
+
lift: { type: 'string' },
|
|
48
|
+
observation: { type: 'string' },
|
|
49
|
+
direction: { type: 'string', enum: ['up', 'flat', 'down'] },
|
|
50
|
+
},
|
|
51
|
+
required: ['lift', 'observation', 'direction'],
|
|
52
|
+
additionalProperties: false,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
plan: {
|
|
56
|
+
type: 'array',
|
|
57
|
+
description: '未来 2~4 周的建议,每条一句',
|
|
58
|
+
items: { type: 'string' },
|
|
59
|
+
},
|
|
60
|
+
sourceIds: { type: 'array', items: { type: 'string' } },
|
|
61
|
+
},
|
|
62
|
+
required: ['headline', 'strengths', 'weaknesses', 'trends', 'plan', 'sourceIds'],
|
|
63
|
+
additionalProperties: false,
|
|
64
|
+
}
|