修复小壹知识库工具选择和固定模板恢复

This commit is contained in:
WuYongJie 2026-12-03 15:27:02 +08:00
parent f45b537d70
commit 500072d840
6 changed files with 26 additions and 6 deletions

View File

@ -1,7 +1,6 @@
import { canvasToolReceipts } from './stdio-canvas.mjs';
import { toolSchema, defineTool } from './tool-schema.mjs';
import { productRequestScope } from './production-recovery.mjs';
import { enterpriseTools } from './enterprise-knowledge.mjs';
import { executeWorkflow } from './workflow-execute.mjs';
import { PresentationBatch, StreamOutputMeter, StreamPresentation, presentText, stripProductionToolText } from './stream-presentation.mjs';
import path from 'node:path';
@ -258,7 +257,7 @@ const SYSTEM = `你是由壹点详情页的本地协作助手“小壹”。使
${PRODUCT_VOICE}
用「workflow_read」读取项目目标、商品、实时进度和图位分页。以 status 和 selectedCandidateId 为准。canvasFirst 项目直接用模板画布,不把旧向导空状态当阻塞。
用「context_read」读取当前绑定的规则。缺少关键资料时询问,用户新确认的信息覆盖旧信息。用「memory_set」保存明确确认的事实,引用用户原话;用「memory_search」读取历史。
用「tool_search」查找企业资料,按照本项目锁定的 Skill 和补充规则工作。通用建议可以直接讨论,不借用其他品牌的规则或臆测产品事实。
按照「context_read」返回的本项目锁定 Skill 和补充规则工作。通用建议可以直接讨论,不借用其他品牌的规则或臆测产品事实。
用「copywriting_options」提供卖点选项,用「copywriting_fields」提供逐格预览和采纳。「workflow_propose」只创建待审核建议,「workflow_navigate」只切换视图。用户取消表示未决定。
${LIVE_CANVAS_WRITES}
申请写入许可后执行实际修改。只确认经回执验证的结果;未知的付费或写入操作按原编号核查。`;
@ -340,7 +339,7 @@ function toolsFor(host) {
return receipt ?? {toolCallId:id,found:false,matches:await host.store.search(query,host.manager)};
}),
];
const projectResources = [...commands, ...enterpriseTools(host, make), ...productionVideoTools(host, make)];
const projectResources = [...commands, ...productionVideoTools(host, make)];
const productionKit = productionTools.map(([name, description, schema])=>({
...make(name,description,schema,(args,signal)=>callProductionTool(host,name,args,signal),
['read_output_screen','read_slot_images'].includes(name)?result=>result:

View File

@ -9,6 +9,7 @@ const errors = {
'session-unavailable': '素材库小壹知识库签发服务不可用(HTTP 503),请联系管理员核对配置',
'session-login': '素材库授权已失效,请重新登录',
'session-forbidden': '当前账户无权使用小壹知识库',
'session-invalid': '小壹知识库自动授权无效,请联系管理员',
'session-network': '连不上素材库服务器,请检查网络、VPN 或代理',
'session-timeout': '素材库换签请求超时,请检查网络后重试',
unconfigured: '企业知识库宿主未配置',

View File

@ -434,6 +434,7 @@ test('normal conversation reads the pinned Xiaoyi rules without the general know
template: { id: 'desk', enterprise: true, knowledgeVersion: 'desk@v1' },
});
x.host.enterpriseContext = { load: async () => assert.fail('一般知识库不应被调用') };
assert.ok(x.host.session.getAllTools().every(tool => !tool.name.startsWith('ekb_')));
await x.host.prompt('请读取当前模板规则。');
const context = x.calls[1].evidence;
assert.equal(context.currentWorkflow.template.knowledgeVersion, 'desk@v1');

View File

@ -284,6 +284,24 @@ test('first production prepares the component from only manifest bindings and re
assert.ok(requests.every(([route])=>route.startsWith('/api/xiaoyi/v1/')));
});
test('catalog-only intake is retained when rebuilding the selected fixed version', async t => {
const intake = {version:1,productFields:[{id:'material',label:'材质',type:'text',required:true}],barcodeFields:[]};
const {options} = await fixture(t,{withBindings:true});
const root = path.join(options.directory,'catalog-root');
const catalog = {items:[{templateId:'CHAIR',name:'Fixture chair',brand:'Fixture',category:'Chair',
version:'v1',knowledgeVersion:'CHAIR@v1',components:[{id:'detail'}],intake}]};
const fetch = async (url,init) => url.pathname === '/api/xiaoyi/v1/templates'
? Response.json(catalog) : options.fetch(url.pathname,init);
const common = {root,brandId:'ekb:brand:Fixture',brandName:'Fixture',categoryId:'ekb:category:Chair',categoryName:'Chair'};
const choice = await templateRequest({...common,action:'resource-component',resourceSetId:'CHAIR',componentId:'detail'},{fetch});
const original = choice.items[0].pack;
const projectDir = path.join(root,'catalog',sha(JSON.stringify(['CHAIR','v1'])));
const recovered = await xiaoyiPacks({templateId:'CHAIR',projectDir,cache:path.join(root,'blobs'),
name:'Fixture chair',brandId:common.brandId,categoryId:common.categoryId,
knowledgeVersion:'CHAIR@v1',intake:original.xiaoyi.intake},{fetch});
assert.deepEqual(recovered.packs.detail, original);
});
test('production Key browses brands, categories, templates and component mappings without downloading originals', async t => {
const intake = {version:1,productFields:[{id:'material',label:'材质',type:'text',required:true}],

View File

@ -140,7 +140,7 @@ fn account_credential(account: &Account) -> R<String> {
.ok_or(AUTOMATIC_INVALID)?;
let remaining = expiry.timestamp() - chrono::Utc::now().timestamp();
if remaining <= 5 { return Err(AUTOMATIC_INVALID.into()); }
let token = normalize_key(token)?;
let token = normalize_key(token).map_err(|_| AUTOMATIC_INVALID)?;
// Refresh frequently so remotely revoked access stops within 30 seconds.
let lifetime = u64::try_from((remaining - 5).min(30)).map_err(|_| AUTOMATIC_INVALID)?;
*cache = Some((token.clone(), std::time::Instant::now() + Duration::from_secs(lifetime)));
@ -395,7 +395,7 @@ fn emit_error(result: R<()>, emit: &mut impl FnMut(Value) -> R<()>) -> R<()> {
GATEWAY => ("gateway", GATEWAY),
SESSION_MISSING => ("session-missing", SESSION_MISSING),
SESSION_UNAVAILABLE => ("session-unavailable", SESSION_UNAVAILABLE),
AUTOMATIC_INVALID => ("credential", AUTOMATIC_INVALID),
AUTOMATIC_INVALID => ("session-invalid", AUTOMATIC_INVALID),
INVALID => ("boundary", INVALID),
_ => ("response", RESPONSE),
};

View File

@ -187,7 +187,8 @@ impl Backend {
let project_dir = root.join("catalog").join(hash(&json!([id, version]).to_string()));
let result = self.enterprise_template_request(json!({"action":"xiaoyi-pack","templateId":id,
"name":selected["name"],"brandId":brand,"categoryId":category,"projectDir":project_dir,
"cache":root.join("blobs"),"knowledgeVersion":format!("{id}@{version}")}))?;
"cache":root.join("blobs"),"knowledgeVersion":format!("{id}@{version}"),
"intake":selected["intake"]}))?;
let mut pack = result["packs"][component].clone();
pack["contentHash"] = json!(template_slots::pack_hash(&pack)?);
matching_pack(&pack, brand, category)?;