@kevlns/art-workshop 0.5.1 → 0.6.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/AGENTS.md +25 -25
- package/LICENSE +21 -21
- package/README.md +65 -63
- package/art-workshop.mjs +219 -174
- package/docs/channels.md +49 -0
- package/docs/commands.md +2259 -22
- package/docs/configuration.md +90 -82
- package/docs/core-guidance.md +58 -50
- package/docs/data-formats.md +89 -85
- package/docs/deployment.md +32 -32
- package/docs/local-models/qwen-image-2.1.json +73 -73
- package/docs/local-models/qwen-image-2.1.md +33 -33
- package/docs/model-architecture.md +78 -78
- package/docs/modes.md +73 -67
- package/docs/release-0.6.0.md +9 -0
- package/lib/agent.mjs +32 -32
- package/lib/analysis-worker.mjs +36 -32
- package/lib/analyze.mjs +85 -85
- package/lib/asset-profile.mjs +23 -23
- package/lib/backends.mjs +2 -0
- package/lib/candidates.mjs +104 -103
- package/lib/channel-operation.mjs +84 -0
- package/lib/comfy-recovery.mjs +17 -17
- package/lib/conversation.mjs +77 -77
- package/lib/core.mjs +104 -75
- package/lib/deployment-guide.mjs +12 -12
- package/lib/design.mjs +29 -29
- package/lib/dimensions.mjs +22 -22
- package/lib/edit.mjs +43 -41
- package/lib/environment-operations.mjs +49 -49
- package/lib/environment-runtime.mjs +99 -99
- package/lib/environments.mjs +55 -55
- package/lib/executor.mjs +107 -107
- package/lib/generate.mjs +60 -58
- package/lib/generation-policy.mjs +1 -1
- package/lib/heartbeat.mjs +16 -16
- package/lib/images.mjs +1 -1
- package/lib/lifecycle.mjs +53 -53
- package/lib/migration.mjs +154 -154
- package/lib/object-format.mjs +1 -1
- package/lib/process-identity.mjs +22 -14
- package/lib/project.mjs +39 -39
- package/lib/prompt-structure.mjs +3 -3
- package/lib/refs.mjs +26 -26
- package/lib/runtime.mjs +25 -25
- package/lib/service.mjs +155 -126
- package/lib/settings.mjs +50 -50
- package/lib/shared.mjs +67 -67
- package/lib/style-bundle.mjs +98 -85
- package/lib/style-contract.mjs +74 -74
- package/lib/style-lifecycle.mjs +124 -125
- package/lib/style-review.mjs +14 -14
- package/lib/style-samples.mjs +92 -0
- package/lib/task-contract.mjs +94 -93
- package/lib/tasks.mjs +497 -497
- package/lib/templates.mjs +80 -80
- package/lib/video/PROVENANCE.json +63 -0
- package/lib/video/atomic.mjs +32 -0
- package/lib/video/channel.mjs +70 -0
- package/lib/video/contract-local-media.mjs +42 -0
- package/lib/video/contract-story.mjs +213 -0
- package/lib/video/contract-video.mjs +117 -0
- package/lib/video/contracts.mjs +3 -0
- package/lib/video/h3.mjs +232 -0
- package/lib/video/local-runtime.mjs +20 -0
- package/lib/video/media.mjs +223 -0
- package/lib/video/models.mjs +336 -0
- package/lib/video/path.mjs +18 -0
- package/lib/video/process.mjs +15 -0
- package/lib/video/resource.mjs +15 -0
- package/lib/video/service.mjs +731 -0
- package/lib/video/workflow.mjs +571 -0
- package/lib/video.mjs +12 -0
- package/lib/vision.mjs +56 -56
- package/lib/worker-process.mjs +6 -6
- package/lib/workspace.mjs +305 -292
- package/package.json +8 -3
- package/rules/core-guidance.json +22 -22
- package/skills/art-workshop/SKILL.md +19 -17
- package/skills/art-workshop/references/conversation.md +11 -11
- package/skills/art-workshop/references/expression.md +27 -27
- package/skills/art-workshop/references/project.md +119 -109
- package/skills/art-workshop/references/style-discussion.md +7 -3
- package/skills/art-workshop/references/video.md +13 -0
- package/v-cli.plugin.json +7240 -2747
package/lib/vision.mjs
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import {AnalysisError} from './errors.mjs';
|
|
2
|
-
import {readFileSync} from 'node:fs';
|
|
3
|
-
|
|
4
|
-
/** The harness supplies one selected credential in process memory, never in argv or run evidence. */
|
|
5
|
-
export async function callVision(args,{cancelled=()=>false,onRemoteCancel,onEvidence=()=>{},transport=fetch}={}) {
|
|
6
|
-
const config=JSON.parse(process.env.ART_VISION_CONFIG??'null'),key=process.env.ART_VISION_KEY;
|
|
7
|
-
if(!config||!key)throw new Error('视觉模型实例未配置');
|
|
8
|
-
const value=name=>args[args.indexOf(name)+1],model=value('--model');
|
|
9
|
-
const image=args.includes('--image')?value('--image'):null,text=args.includes('--prompt')?value('--prompt'):value('--message');
|
|
10
|
-
if(!model||!text)throw new Error('视觉调用缺少模型或提示');
|
|
11
|
-
if(config.model&&model!==config.model)throw new Error('视觉模型与授权实例不匹配');
|
|
12
|
-
const {effectiveMaxTokens:maxTokens}=visionOutputBudget(config);
|
|
13
|
-
const base=new URL(config.baseUrl);if(!['http:','https:'].includes(base.protocol)||base.username||base.password||base.search||base.hash)throw new Error('视觉模型地址非法');
|
|
14
|
-
let mime='image/png',data;if(image){const bytes=readFileSync(image);mime=bytes[0]===255?'image/jpeg':bytes.subarray(0,4).toString()==='RIFF'?'image/webp':'image/png';data=bytes.toString('base64');}
|
|
15
|
-
let endpoint,headers,body;
|
|
16
|
-
if(config.api==='openai-completions'){
|
|
17
|
-
endpoint='/chat/completions';headers={Authorization:'Bearer '+key};body={model,messages:[{role:'user',content:[{type:'text',text},...(data?[{type:'image_url',image_url:{url:`data:${mime};base64,${data}`}}]:[])]}],max_tokens:maxTokens};
|
|
18
|
-
}else if(config.api==='openai-responses'){
|
|
19
|
-
endpoint='/responses';headers={Authorization:'Bearer '+key};body={model,input:[{role:'user',content:[{type:'input_text',text},...(data?[{type:'input_image',image_url:`data:${mime};base64,${data}`}]:[])]}],max_output_tokens:maxTokens};
|
|
20
|
-
}else if(config.api==='anthropic-messages'){
|
|
21
|
-
endpoint='/messages';headers={'x-api-key':key,'anthropic-version':'2023-06-01'};body={model,max_tokens:maxTokens,messages:[{role:'user',content:[...(data?[{type:'image',source:{type:'base64',media_type:mime,data}}]:[]),{type:'text',text}]}]};
|
|
22
|
-
}else if(config.api==='google-generative-ai'){
|
|
23
|
-
endpoint='/models/'+encodeURIComponent(model)+':generateContent';headers={'x-goog-api-key':key};body={contents:[{role:'user',parts:[{text},...(data?[{inlineData:{mimeType:mime,data}}]:[])]}],generationConfig:{maxOutputTokens:maxTokens}};
|
|
24
|
-
}else throw new Error('视觉模型协议尚未适配');
|
|
25
|
-
if(cancelled())throw new Error('分析已取消');
|
|
26
|
-
const controller=new AbortController();let sent=false;
|
|
27
|
-
const timer=setInterval(()=>{if(cancelled())controller.abort();},100),timeout=setTimeout(()=>controller.abort(),300000);
|
|
28
|
-
try{
|
|
29
|
-
sent=true;
|
|
30
|
-
const response=await transport(base.href.replace(/\/$/,'')+endpoint,{method:'POST',headers:{...headers,'Content-Type':'application/json'},body:JSON.stringify(body),redirect:'error',signal:controller.signal});
|
|
31
|
-
if(!response.ok){
|
|
32
|
-
const reader=response.body?.getReader();let size=0,raw='';if(reader)try{while(size<8192){const next=await reader.read();if(next.done)break;size+=next.value.byteLength;raw+=Buffer.from(next.value).toString('utf8');}}finally{await reader.cancel().catch(()=>{});}
|
|
33
|
-
let code;try{const payload=JSON.parse(raw);const value=payload.error?.code??payload.code;if(typeof value==='string'&&/^[a-zA-Z0-9_.-]{1,100}$/.test(value)&&!value.includes(key))code=value;}catch{}
|
|
34
|
-
throw new AnalysisError('UPSTREAM_REJECTED','视觉模型请求失败(HTTP '+response.status+')'+(code?',错误码 '+code:''),{upstream:{status:response.status,...(code?{code}:{})},recovery:'fix-connection'});
|
|
35
|
-
}
|
|
36
|
-
const reader=response.body?.getReader();if(!reader)throw new Error('视觉模型未返回报告');
|
|
37
|
-
const chunks=[];let size=0;
|
|
38
|
-
while(true){const next=await reader.read();if(next.done)break;size+=next.value.byteLength;if(size>8_000_000){await reader.cancel();throw new Error('视觉响应过大');}chunks.push(next.value);}
|
|
39
|
-
const raw=Buffer.concat(chunks).toString('utf8');
|
|
40
|
-
const result=JSON.parse(raw);
|
|
41
|
-
// Return only assistant text, rather than recursively interpreting arbitrary response metadata as a report.
|
|
42
|
-
const texts=config.api==='openai-completions'?[result.choices?.[0]?.message?.content]:config.api==='openai-responses'?(result.output??[]).flatMap(item=>(item.content??[]).filter(c=>c.type==='output_text').map(c=>c.text)):config.api==='anthropic-messages'?(result.content??[]).filter(c=>c.type==='text').map(c=>c.text):(result.candidates??[]).flatMap(item=>(item.content?.parts??[]).map(c=>c.text));
|
|
43
|
-
const assistantText=texts.filter(t=>typeof t==='string').join('\n');
|
|
44
|
-
const truncated=result.choices?.[0]?.finish_reason==='length'||result.status==='incomplete'||result.stop_reason==='max_tokens'||result.candidates?.some(c=>c.finishReason==='MAX_TOKENS');
|
|
45
|
-
try{onEvidence({text:assistantText,effectiveMaxTokens:maxTokens,truncated});}catch(error){throw new AnalysisError('EVIDENCE_WRITE_FAILED','分析证据保存失败:'+error.message);}
|
|
46
|
-
if(truncated)throw new AnalysisError('OUTPUT_TRUNCATED','视觉报告超出模型输出额度(本次 '+maxTokens+' tokens);请核对实际额度,未回填截断结果',{effectiveMaxTokens:maxTokens,recovery:'review-budget'});
|
|
47
|
-
if(!assistantText.trim()||texts.some(t=>typeof t!=='string'))throw new Error('视觉模型未返回文字报告');
|
|
48
|
-
return {text:texts.join('\n')};
|
|
49
|
-
}catch(error){
|
|
50
|
-
if(error instanceof AnalysisError)throw error;
|
|
51
|
-
if(sent&&(controller.signal.aborted||error instanceof TypeError)){onRemoteCancel?.();throw new Error(cancelled()?'分析请求已取消;云端计算与计费是否停止无法确认,不会自动重发':'分析请求超时或连接中断;云端计算与计费是否停止无法确认,未回填报告,不会自动重发');}
|
|
52
|
-
throw new Error(/^视觉/.test(error.message)?error.message:'视觉模型响应解析失败');
|
|
53
|
-
}finally{clearInterval(timer);clearTimeout(timeout);}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function visionOutputBudget(config={}){const max=config.maxTokens??16384;if(!Number.isSafeInteger(max)||max<1)throw new AnalysisError('INVALID_OUTPUT_BUDGET','视觉模型输出额度非法',{recovery:'fix-input'});return {configuredMaxTokens:max,effectiveMaxTokens:max,limitReason:null};}
|
|
1
|
+
import {AnalysisError} from './errors.mjs';
|
|
2
|
+
import {readFileSync} from 'node:fs';
|
|
3
|
+
|
|
4
|
+
/** The harness supplies one selected credential in process memory, never in argv or run evidence. */
|
|
5
|
+
export async function callVision(args,{cancelled=()=>false,onRemoteCancel,onEvidence=()=>{},transport=fetch}={}) {
|
|
6
|
+
const config=JSON.parse(process.env.ART_VISION_CONFIG??'null'),key=process.env.ART_VISION_KEY;
|
|
7
|
+
if(!config||!key)throw new Error('视觉模型实例未配置');
|
|
8
|
+
const value=name=>args[args.indexOf(name)+1],model=value('--model');
|
|
9
|
+
const image=args.includes('--image')?value('--image'):null,text=args.includes('--prompt')?value('--prompt'):value('--message');
|
|
10
|
+
if(!model||!text)throw new Error('视觉调用缺少模型或提示');
|
|
11
|
+
if(config.model&&model!==config.model)throw new Error('视觉模型与授权实例不匹配');
|
|
12
|
+
const {effectiveMaxTokens:maxTokens}=visionOutputBudget(config);
|
|
13
|
+
const base=new URL(config.baseUrl);if(!['http:','https:'].includes(base.protocol)||base.username||base.password||base.search||base.hash)throw new Error('视觉模型地址非法');
|
|
14
|
+
let mime='image/png',data;if(image){const bytes=readFileSync(image);mime=bytes[0]===255?'image/jpeg':bytes.subarray(0,4).toString()==='RIFF'?'image/webp':'image/png';data=bytes.toString('base64');}
|
|
15
|
+
let endpoint,headers,body;
|
|
16
|
+
if(config.api==='openai-completions'){
|
|
17
|
+
endpoint='/chat/completions';headers={Authorization:'Bearer '+key};body={model,messages:[{role:'user',content:[{type:'text',text},...(data?[{type:'image_url',image_url:{url:`data:${mime};base64,${data}`}}]:[])]}],max_tokens:maxTokens};
|
|
18
|
+
}else if(config.api==='openai-responses'){
|
|
19
|
+
endpoint='/responses';headers={Authorization:'Bearer '+key};body={model,input:[{role:'user',content:[{type:'input_text',text},...(data?[{type:'input_image',image_url:`data:${mime};base64,${data}`}]:[])]}],max_output_tokens:maxTokens};
|
|
20
|
+
}else if(config.api==='anthropic-messages'){
|
|
21
|
+
endpoint='/messages';headers={'x-api-key':key,'anthropic-version':'2023-06-01'};body={model,max_tokens:maxTokens,messages:[{role:'user',content:[...(data?[{type:'image',source:{type:'base64',media_type:mime,data}}]:[]),{type:'text',text}]}]};
|
|
22
|
+
}else if(config.api==='google-generative-ai'){
|
|
23
|
+
endpoint='/models/'+encodeURIComponent(model)+':generateContent';headers={'x-goog-api-key':key};body={contents:[{role:'user',parts:[{text},...(data?[{inlineData:{mimeType:mime,data}}]:[])]}],generationConfig:{maxOutputTokens:maxTokens}};
|
|
24
|
+
}else throw new Error('视觉模型协议尚未适配');
|
|
25
|
+
if(cancelled())throw new Error('分析已取消');
|
|
26
|
+
const controller=new AbortController();let sent=false;
|
|
27
|
+
const timer=setInterval(()=>{if(cancelled())controller.abort();},100),timeout=setTimeout(()=>controller.abort(),300000);
|
|
28
|
+
try{
|
|
29
|
+
sent=true;
|
|
30
|
+
const response=await transport(base.href.replace(/\/$/,'')+endpoint,{method:'POST',headers:{...headers,'Content-Type':'application/json'},body:JSON.stringify(body),redirect:'error',signal:controller.signal});
|
|
31
|
+
if(!response.ok){
|
|
32
|
+
const reader=response.body?.getReader();let size=0,raw='';if(reader)try{while(size<8192){const next=await reader.read();if(next.done)break;size+=next.value.byteLength;raw+=Buffer.from(next.value).toString('utf8');}}finally{await reader.cancel().catch(()=>{});}
|
|
33
|
+
let code;try{const payload=JSON.parse(raw);const value=payload.error?.code??payload.code;if(typeof value==='string'&&/^[a-zA-Z0-9_.-]{1,100}$/.test(value)&&!value.includes(key))code=value;}catch{}
|
|
34
|
+
throw new AnalysisError('UPSTREAM_REJECTED','视觉模型请求失败(HTTP '+response.status+')'+(code?',错误码 '+code:''),{upstream:{status:response.status,...(code?{code}:{})},recovery:'fix-connection'});
|
|
35
|
+
}
|
|
36
|
+
const reader=response.body?.getReader();if(!reader)throw new Error('视觉模型未返回报告');
|
|
37
|
+
const chunks=[];let size=0;
|
|
38
|
+
while(true){const next=await reader.read();if(next.done)break;size+=next.value.byteLength;if(size>8_000_000){await reader.cancel();throw new Error('视觉响应过大');}chunks.push(next.value);}
|
|
39
|
+
const raw=Buffer.concat(chunks).toString('utf8');
|
|
40
|
+
const result=JSON.parse(raw);
|
|
41
|
+
// Return only assistant text, rather than recursively interpreting arbitrary response metadata as a report.
|
|
42
|
+
const texts=config.api==='openai-completions'?[result.choices?.[0]?.message?.content]:config.api==='openai-responses'?(result.output??[]).flatMap(item=>(item.content??[]).filter(c=>c.type==='output_text').map(c=>c.text)):config.api==='anthropic-messages'?(result.content??[]).filter(c=>c.type==='text').map(c=>c.text):(result.candidates??[]).flatMap(item=>(item.content?.parts??[]).map(c=>c.text));
|
|
43
|
+
const assistantText=texts.filter(t=>typeof t==='string').join('\n');
|
|
44
|
+
const truncated=result.choices?.[0]?.finish_reason==='length'||result.status==='incomplete'||result.stop_reason==='max_tokens'||result.candidates?.some(c=>c.finishReason==='MAX_TOKENS');
|
|
45
|
+
try{onEvidence({text:assistantText,effectiveMaxTokens:maxTokens,truncated});}catch(error){throw new AnalysisError('EVIDENCE_WRITE_FAILED','分析证据保存失败:'+error.message);}
|
|
46
|
+
if(truncated)throw new AnalysisError('OUTPUT_TRUNCATED','视觉报告超出模型输出额度(本次 '+maxTokens+' tokens);请核对实际额度,未回填截断结果',{effectiveMaxTokens:maxTokens,recovery:'review-budget'});
|
|
47
|
+
if(!assistantText.trim()||texts.some(t=>typeof t!=='string'))throw new Error('视觉模型未返回文字报告');
|
|
48
|
+
return {text:texts.join('\n')};
|
|
49
|
+
}catch(error){
|
|
50
|
+
if(error instanceof AnalysisError)throw error;
|
|
51
|
+
if(sent&&(controller.signal.aborted||error instanceof TypeError)){onRemoteCancel?.();throw new Error(cancelled()?'分析请求已取消;云端计算与计费是否停止无法确认,不会自动重发':'分析请求超时或连接中断;云端计算与计费是否停止无法确认,未回填报告,不会自动重发');}
|
|
52
|
+
throw new Error(/^视觉/.test(error.message)?error.message:'视觉模型响应解析失败');
|
|
53
|
+
}finally{clearInterval(timer);clearTimeout(timeout);}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function visionOutputBudget(config={}){const max=config.maxTokens??16384;if(!Number.isSafeInteger(max)||max<1)throw new AnalysisError('INVALID_OUTPUT_BUDGET','视觉模型输出额度非法',{recovery:'fix-input'});return {configuredMaxTokens:max,effectiveMaxTokens:max,limitReason:null};}
|
package/lib/worker-process.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {inspectProcess} from './process-identity.mjs';
|
|
2
2
|
import {hash} from './shared.mjs';
|
|
3
3
|
|
|
4
4
|
// A recycled PID is not evidence that an old task is still running.
|
|
5
5
|
// Unreadable identities remain live: uncertainty never authorizes termination.
|
|
6
|
-
export function workerAlive(task, inspect =
|
|
6
|
+
export function workerAlive(task, inspect = inspectProcess) {
|
|
7
7
|
const pid = task.workerPid;
|
|
8
8
|
if (!Number.isSafeInteger(pid) || pid <= 0) return false;
|
|
9
|
-
// ESRCH:PID 已消失。其余错误(Windows 的 EPERM/EACCES)只说明该 PID 存在
|
|
10
|
-
// 但不归我们管,通常是 PID 被复用;交给下面的身份比对判定。
|
|
11
9
|
try { process.kill(pid, 0); } catch (error) { if (error.code === 'ESRCH') return false; }
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
10
|
+
const result = inspect(pid);
|
|
11
|
+
if (result.state === 'missing') return false;
|
|
12
|
+
if (result.state !== 'running') return true;
|
|
13
|
+
const current = result.identity;
|
|
14
14
|
if (task.workerIdentity) return hash(current) === hash(task.workerIdentity);
|
|
15
15
|
// Historical receipts have no identity. A process born after the completed
|
|
16
16
|
// task cannot be its worker; allow one second for Unix ps time precision.
|