feat: add task-bound real browser checks and verified page delivery
This commit is contained in:
@@ -8,7 +8,7 @@ export class ArtifactStore {
|
||||
if (fs.lstatSync(this.root).isSymbolicLink()) throw new Error('执行工件目录不能是链接。');
|
||||
}
|
||||
write(session, run, value, { kind = 'tool-result', mediaType = 'application/json' } = {}) {
|
||||
const bytes = Buffer.from(typeof value === 'string' ? value : JSON.stringify(value), 'utf8');
|
||||
const bytes = Buffer.isBuffer(value) ? Buffer.from(value) : Buffer.from(typeof value === 'string' ? value : JSON.stringify(value), 'utf8');
|
||||
if (bytes.length > 8 * 1024 * 1024) throw new Error('单项执行工件超过8MB,请缩小输出范围。');
|
||||
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
||||
const relative = sha256.slice(0, 2) + '/' + sha256 + '.blob';
|
||||
@@ -30,11 +30,15 @@ export class ArtifactStore {
|
||||
runId: run?.id ?? session.runId ?? null, kind, mediaType, sha256, bytes: bytes.length, relative, createdAt: new Date().toISOString(), status: 'stored' };
|
||||
}
|
||||
read(artifact) {
|
||||
if (artifact.mediaType?.startsWith('image/')) throw new Error('图片工件需要读取原字节,请从浏览器检查面板查看或下载。');
|
||||
return this.readBytes(artifact).toString('utf8');
|
||||
}
|
||||
readBytes(artifact) {
|
||||
if (!/^[a-f0-9]{2}\/[a-f0-9]{64}\.blob$/.test(artifact.relative)) throw new Error('执行工件路径无效。');
|
||||
const file = path.join(this.root, artifact.relative);
|
||||
if (fs.lstatSync(path.dirname(file)).isSymbolicLink() || fs.lstatSync(file).isSymbolicLink()) throw new Error('执行工件不能是链接。');
|
||||
const bytes = fs.readFileSync(file);
|
||||
if (bytes.length !== artifact.bytes || createHash('sha256').update(bytes).digest('hex') !== artifact.sha256) throw new Error('执行工件校验失败,实际结果需要核对。');
|
||||
return bytes.toString('utf8');
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user