@tbox.cn/app-agent-sdk-server 0.3.7 → 1.0.0-alpha.6

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.
@@ -0,0 +1,207 @@
1
+ import { CardMeta, RequestContext } from '@tbox.cn/app-contracts';
2
+ import { z } from 'zod';
3
+ import { AsyncLocalStorage } from 'node:async_hooks';
4
+ import { Tool } from '@mastra/core/tools';
5
+
6
+ /**
7
+ * 工具出卡协议单源(v2)。
8
+ *
9
+ * 作者契约:工具 execute 返回 `{ ...顶层答话事实, cards: [{cardType, data, note?}] }`——
10
+ * `cards` 字段名为平台保留字(非出卡工具禁用此字段名承载其他语义)。
11
+ *
12
+ * capture 后模型可见面(模型上下文 / TOOL_CALL_RESULT 事件 / preTool reminder /
13
+ * inputs.preTools 落库)四面统一为 stripped 形态:
14
+ * `{ ...顶层, cards: [{id:"cN", cardType, note}] }`
15
+ * 同一工具同一产出,模型 tool-result 与 preTool reminder 两路所见 payload 同构——
16
+ * 由单点包装(wrapToolsForCardCapture)构造保证:两路执行同一 wrapped execute。
17
+ *
18
+ * 两层 id:
19
+ * - ref(c1..cN):线程内单调的 occurrence 引用(descriptor.id 即 ref,按设计出现在上述四个
20
+ * 模型可见面);不进出卡 payload(CUSTOM tbox:card)与历史快照;
21
+ * - 实例 id(card_<ts>_<rand>):emit 时生成(CardEmitter 现状),出卡实例身份与历史快照主键。
22
+ */
23
+
24
+ /** 出参 cards 字段名(平台保留字) */
25
+ declare const TOOL_CARDS_FIELD = "cards";
26
+ /** 出卡工具 description 标注关键词(平台段预告句共享——跨文件钉死断言防漂移) */
27
+ declare const CARD_EMISSION_HINT_KEYWORD = "\u53EF\u5C55\u793A\u5361\u7247";
28
+ /** 出卡工具 description 标注句基础形(withCardEmissionHint 单源) */
29
+ declare const CARD_EMISSION_HINT_BASE = "\u547D\u4E2D\u6570\u636E\u65F6\u7ED3\u679C\u9644\u53EF\u5C55\u793A\u5361\u7247\uFF08cards\uFF09\u3002";
30
+ /** 出卡工具 description 标注句动作卡后缀(卡上承载操作入口时追加) */
31
+ declare const CARD_EMISSION_HINT_ACTIONS = "\u64CD\u4F5C\u5165\u53E3\u5728\u5361\u7247\u4E0A\u3002";
32
+ /** descriptor 形状恒定(capture 后模型可见形态;供 outputSchema 组合,可选导出) */
33
+ declare const TOOL_CARD_DESCRIPTOR_SCHEMA: z.ZodObject<{
34
+ id: z.ZodString;
35
+ cardType: z.ZodString;
36
+ note: z.ZodString;
37
+ }, "strip", z.ZodTypeAny, {
38
+ id: string;
39
+ cardType: string;
40
+ note: string;
41
+ }, {
42
+ id: string;
43
+ cardType: string;
44
+ note: string;
45
+ }>;
46
+ /** 作者侧:工具 execute 出参中的卡条目 */
47
+ interface ToolCardSpec {
48
+ cardType: string;
49
+ data: Record<string, unknown>;
50
+ note?: string;
51
+ }
52
+ /** 模型侧:stripped 出参中的卡描述符 */
53
+ interface ToolCardDescriptor {
54
+ id: string;
55
+ cardType: string;
56
+ note: string;
57
+ }
58
+ /** 池条目(不可变:每个合法 cards occurrence 都是独立候选) */
59
+ interface PoolEntry {
60
+ ref: string;
61
+ cardType: string;
62
+ data: Record<string, unknown>;
63
+ note: string;
64
+ }
65
+ interface CardPoolOptions {
66
+ /** ChatEngine 使用线程级单调 ref;缺省时池内从 c1 开始。 */
67
+ allocateRef?: () => string;
68
+ }
69
+ interface CardPool {
70
+ /** 校验 + 注入;每个合法 occurrence 都创建独立 ref,校验失败 → null */
71
+ add(spec: ToolCardSpec, registry: Record<string, CardMeta>): ToolCardDescriptor | null;
72
+ /** ref 精确查找(大小写不敏感) */
73
+ byRef(ref: string): PoolEntry | undefined;
74
+ entries(): readonly PoolEntry[];
75
+ size(): number;
76
+ }
77
+ /** 候选池工厂(每 run 一个;每个 occurrence 独立 ref) */
78
+ declare function createCardPool(options?: CardPoolOptions): CardPool;
79
+ /**
80
+ * capture:校验 + 池注入 + 剥离(单函数三合一)。
81
+ * - raw 非对象或无 cards 字段 → 原样返回(no-op,不出卡工具零开销);
82
+ * - cards 非数组 → warn + 原样返回;
83
+ * - 逐条校验(非对象 / cardType 非 string / 未注册 / dataSchema 失败 → skip + warn);
84
+ * - 有效 ≥1 → `{ ...raw, cards: descriptors }`;全无效 → 浅拷贝删除 cards 键;
85
+ * - 条目数 > CARDS_WARN_LIMIT → warn(不截断)。
86
+ */
87
+ declare function captureToolCards(raw: unknown, pool: CardPool, registry: Record<string, CardMeta>): unknown;
88
+ /** run 级卡片池 ALS 上下文(chat/submitForm run 开始进入,finally 退出) */
89
+ declare const toolCardScope: AsyncLocalStorage<{
90
+ pool: CardPool;
91
+ }>;
92
+ /**
93
+ * 单点包装:浅拷贝每个 tool 仅替换 execute(禁变异原实例);无 execute 的原样保留。
94
+ * wrapped execute:双参 + 接收者透传(mastra 契约),产出经 captureToolCards
95
+ * (ALS 无池 → 引擎外直调原样返回)。模型路径(Agent.tools)与 preTool 路径
96
+ * (engine 按 id 替换执行体)共用同一 wrapped execute → 两路同构由构造保证。
97
+ */
98
+ declare function wrapToolsForCardCapture(tools: Record<string, Tool>, registry: Record<string, CardMeta>): Record<string, Tool>;
99
+
100
+ /** 工具 execute 第二参的结构型投影(只声明读取器消费的形状) */
101
+ interface ToolExecContextLike {
102
+ requestContext?: {
103
+ get(key: string): unknown;
104
+ };
105
+ toolCallId?: string;
106
+ agent?: {
107
+ toolCallId?: string;
108
+ };
109
+ }
110
+ interface ToolRunMetadata {
111
+ runId: string;
112
+ threadKey: string;
113
+ toolCallId: string;
114
+ }
115
+ /** Read trusted producer metadata from the execute context, never from model arguments. */
116
+ declare function getToolRunMetadata(execCtx: ToolExecContextLike | undefined): Readonly<ToolRunMetadata> | undefined;
117
+ /**
118
+ * 从工具 execute 第二参读取运行上下文(散键组装)。
119
+ * 返回 undefined 当 requestContext 缺失或 identity 键缺失(引擎外直调/匿名无身份)。
120
+ */
121
+ declare function getToolRequestContext(execCtx: ToolExecContextLike | undefined): Readonly<RequestContext> | undefined;
122
+ /**
123
+ * 严格变体:运行上下文缺失时抛 AUTH_FORBIDDEN(fail-visible——显式正确性优于静默降级)。
124
+ * @param toolId 诊断信息(缺失文案指明哪个工具、怎么修)
125
+ */
126
+ /**
127
+ * 取工具运行上下文(身份/凭证/attributes);缺失即抛错。
128
+ *
129
+ * @agentApi state
130
+ */
131
+ declare function requireToolRequestContext(execCtx: ToolExecContextLike | undefined, toolId?: string): Readonly<RequestContext>;
132
+ /**
133
+ * 测试/直调助手:由 plain RequestContext 构造工具 execute 第二参形态。
134
+ * 散键写入与引擎 buildRunRequestContext 同构(往返由 context-concurrency.test C2 锁定)。
135
+ */
136
+ declare function createToolExecContext(reqCtx: RequestContext): ToolExecContextLike;
137
+
138
+ /** 声明一张卡:恒等返回,负责类型绑定与样例自检。 */
139
+ /**
140
+ * 声明一张卡片的服务端元数据;类型上绑定 schema,dev 下先校验样例。
141
+ *
142
+ * @agentApi card
143
+ */
144
+ declare function defineCardMeta<S extends z.ZodTypeAny>(meta: CardMeta<S>): CardMeta<S>;
145
+ /** 类型化出卡条目:`data` 必须能过 meta 的 schema,`cardType` 取自 meta。 */
146
+ /**
147
+ * 组装一条出卡条目;data 必须能过 meta 的 schema。
148
+ *
149
+ * @agentApi tool-emits-card
150
+ */
151
+ declare function cardOf<S extends z.ZodTypeAny>(meta: CardMeta<S>, data: z.input<S>, note: string): ToolCardSpec;
152
+ /**
153
+ * 按用户隔离的进程内状态。
154
+ *
155
+ * 适用边界(必须知道):
156
+ * - 默认进程内、重启即丢;`persist: 'file'` 落盘到应用根 `.tbox/state/<name>.json`;
157
+ * - 多实例各存一份;跨重启或跨实例的强一致状态做成模块用 `ctx.state`;
158
+ * - 无 TTL:需要过期时自己在数据里记时间戳并清理;
159
+ * - 幂等判断放在写副作用之前,工具可能被重试。
160
+ */
161
+ interface UserState<T> {
162
+ get(userId: string): T;
163
+ update(userId: string, mutate: (draft: T) => T | void): T;
164
+ /** 测试与运维辅助:清空全部或指定用户 */
165
+ reset(userId?: string): void;
166
+ }
167
+ interface CreateUserStateOptions {
168
+ /**
169
+ * `'file'`:状态落盘到应用根 `<appRoot>/.tbox/state/<stateName>.json`,进程重启后恢复。
170
+ * 应用根 = 向上找到 `.tbox/app.json` 的目录;找不到时回落到 `process.cwd()`。
171
+ */
172
+ persist?: 'file';
173
+ /** 落盘文件名(缺省 `user-state`);同名的两个 state 会互相同步,务必区分 */
174
+ stateName?: string;
175
+ }
176
+ /** 已注册的用户状态:构造即登记,探针与场景按登记发现,不依赖文件路径约定。 */
177
+ interface RegisteredUserState {
178
+ name: string;
179
+ state: UserState<unknown>;
180
+ }
181
+ /** 取全部已注册的用户状态(按创建顺序)。 */
182
+ declare function userStates(): RegisteredUserState[];
183
+ /**
184
+ * 按用户隔离的进程内状态;`persist: 'file'` 时落盘到应用根。
185
+ *
186
+ * 构造即登记到进程内注册表(`userStates()`),探针、场景与测试按登记发现。
187
+ *
188
+ * @agentApi state
189
+ */
190
+ declare function createUserState<T>(init: (userId: string) => T, options?: CreateUserStateOptions): UserState<T>;
191
+ /**
192
+ * 取可信用户身份。缺失时抛带 toolId 的错误——`requireToolRequestContext` 的错误消息
193
+ * 已经指到正确写法,这里只补一层语义命名。
194
+ */
195
+ /**
196
+ * 取可信用户身份(userId/source)。
197
+ *
198
+ * @agentApi state
199
+ */
200
+ declare function toolUser(execCtx: ToolExecContextLike, toolId?: string): {
201
+ userId: string;
202
+ source: string;
203
+ displayName?: string;
204
+ avatar?: string;
205
+ };
206
+
207
+ export { type CardPool as C, type PoolEntry as P, type RegisteredUserState as R, TOOL_CARDS_FIELD as T, type UserState as U, CARD_EMISSION_HINT_ACTIONS as a, CARD_EMISSION_HINT_BASE as b, CARD_EMISSION_HINT_KEYWORD as c, type CardPoolOptions as d, type CreateUserStateOptions as e, TOOL_CARD_DESCRIPTOR_SCHEMA as f, type ToolCardDescriptor as g, type ToolCardSpec as h, type ToolExecContextLike as i, type ToolRunMetadata as j, captureToolCards as k, cardOf as l, createCardPool as m, createToolExecContext as n, createUserState as o, defineCardMeta as p, getToolRequestContext as q, getToolRunMetadata as r, requireToolRequestContext as s, toolCardScope as t, userStates as u, toolUser as v, wrapToolsForCardCapture as w };
@@ -0,0 +1 @@
1
+ import{AsyncLocalStorage as _}from"async_hooks";import{createServerLogger as L,recordCall as $}from"@tbox.cn/app-sdk-server";var j=L("EARLY-TOOL"),q=Symbol("tbox.earlyExecution"),T=new _;function ie(e){let t=new Map;return{submit(r,n,o,s){if(t.has(r))return;let a=e.tools[n];if(!a||typeof a.execute!="function"||a[q]!==!0){let l=a?typeof a.execute!="function"?"no-execute":"unmarked":"unknown-tool";e.journal.emit("tool_preexec",{toolCallId:r,toolName:n,outcome:"skip",trigger:s,reason:l});return}e.journal.emit("tool_preexec",{toolCallId:r,toolName:n,outcome:"fired",trigger:s});let i=Date.now(),d={requestContext:e.requestContext,toolCallId:r,...e.signal?{abortSignal:e.signal}:{}},u=$("tool",n,()=>a.execute.call(a,o,d)).then(l=>{if(l===void 0)throw new Error(`工具 ${n} 执行完成但未返回结果(undefined)——请检查工具实现是否缺少 return`);return l});u.then(void 0,()=>{}),t.set(r,{promise:u,toolName:n,startedAt:i,trigger:s})},invalidate(r,n){let o=t.get(r);o&&(t.delete(r),e.journal.emit("tool_preexec",{toolCallId:r,toolName:o.toolName,outcome:"invalidated",trigger:o.trigger,reason:n}))},take(r){let n=t.get(r);if(n)return t.delete(r),e.journal.emit("tool_preexec",{toolCallId:r,toolName:n.toolName,outcome:"hit",trigger:n.trigger,durMs:Date.now()-n.startedAt},n.startedAt),n.promise}}}function D(e){let t=new Map,r=(o,s)=>{let a=t.get(o);if(!(!a||a.firedAt!==void 0)&&a.args.trim()!=="")try{let i=JSON.parse(a.args);if(i===null||typeof i!="object"||Array.isArray(i))return;a.firedAt=a.args,e.submit(o,a.toolName,i,s)}catch{}},n=o=>{for(let s of t.keys())r(s,o)};return new TransformStream({transform(o,s){s.enqueue(o);try{let a=T.getStore();if(!a||a!==e)return;switch(o.type){case"tool-input-start":{n("next-start"),t.set(o.id,{toolName:o.toolName,args:""});break}case"tool-input-end":{r(o.id,"input-end");break}case"tool-input-delta":{let i=t.get(o.id);if(!i)break;i.args+=o.delta,i.firedAt!==void 0&&e.invalidate(o.id,"delta-after-fire");break}case"tool-call":{let i=t.get(o.toolCallId);i?.firedAt!==void 0&&i.firedAt!==o.input&&e.invalidate(o.toolCallId,"final-mismatch");break}default:break}}catch(a){j.warn("early-execution 流分析异常(透传不受影响):",a?.message??String(a))}},flush(){let o=T.getStore();!o||o!==e||n("flush")}})}function ce(e){let t=Object.create(e);return t.doStream=(async r=>{let n=await e.doStream(r),o=T.getStore(),s=n,a=s?.stream;return!o||!a||typeof a.pipeThrough!="function"?n:{...s,stream:a.pipeThrough(D(o))}}),t}function E(e){if(!(!e||typeof e!="string"))return T.getStore()?.take(e)}import{AsyncLocalStorage as U}from"async_hooks";import{z as R}from"zod";import{createServerLogger as O,recordCall as K}from"@tbox.cn/app-sdk-server";var z=O("TOOL"),g=O("TOOLCARDS"),S="cards",F="可展示卡片",ge=`命中数据时结果附${F}(cards)。`,ye="操作入口在卡片上。",xe=R.object({id:R.string(),cardType:R.string(),note:R.string()}),C=120,A=8;function J(e){try{return JSON.parse(JSON.stringify(e??null))}catch{return}}function Y(e,t,r){e===void 0&&g.warn(`note 缺失(${r})——按 note 契约补内容摘要(主体+关键事实,≤${C} 字符,不复述顶层 facts)`);let n=e??t?.displayName??r;return n.length>C?(g.warn(`note 超长截断(${n.length} → ${C}): ${r}`),n.slice(0,C)):n}function me(e={}){let t=new Map,r=[],n=0,o=e.allocateRef??(()=>`c${++n}`);return{add(s,a){let i=a[s.cardType];if(!i)return g.warn(`跳过未知卡片类型: ${s.cardType}`),null;let d=J(s.data);if(d==null||typeof d!="object"||Array.isArray(d))return g.warn(`跳过 ${s.cardType}: data 非 JSON 对象`),null;let c=i.dataSchema.safeParse(d);if(!c.success)return g.warn(`跳过 ${s.cardType}: dataSchema 校验失败(${c.error.message})`),null;let u=c.data,l=o(),f=l.toLowerCase();if(t.has(f))throw new Error(`card ref allocator returned duplicate ref: ${l}`);let p={ref:l,cardType:s.cardType,data:u,note:Y(s.note,i,s.cardType)};return t.set(f,p),r.push(p),{id:p.ref,cardType:p.cardType,note:p.note}},byRef(s){return t.get(s.toLowerCase())},entries(){return r},size(){return r.length}}}function b(e,t,r){if(e===null||typeof e!="object"||Array.isArray(e))return e;let n=e;if(!(S in n))return e;let o=n[S];if(!Array.isArray(o))return g.warn("工具出参 cards 非数组,忽略出卡"),e;o.length>A&&g.warn(`单工具出卡 ${o.length} 条(> ${A}),观测确认是否预期`);let s=[];for(let[a,i]of o.entries()){if(i===null||typeof i!="object"||Array.isArray(i)){g.warn(`跳过 cards[${a}]:非对象`);continue}let d=i,{cardType:c,data:u,note:l}=d;if(typeof c!="string"||c.length===0){g.warn(`跳过 cards[${a}]:cardType 非法`);continue}if(u===null||typeof u!="object"||Array.isArray(u)){g.warn(`跳过 cards[${a}](${c}):data 非对象`);continue}let f=t.add({cardType:c,data:u,...typeof l=="string"?{note:l}:{}},r);f&&s.push(f)}if(s.length===0){let a={};for(let[i,d]of Object.entries(n))i!==S&&(a[i]=d);return a}return{...n,[S]:s}}var k=new U,M=Symbol("tbox.toolCardCapture");function Te(e,t){let r={};for(let[n,o]of Object.entries(e)){let s=o;if(typeof s?.execute!="function"||s[M]){r[n]=o;continue}let a=o,i=s.execute,d=Object.create(Object.getPrototypeOf(o),Object.getOwnPropertyDescriptors(o)),c=String(o.id??"unknown");d.execute=async function(u,l){let f=l,p=f?.toolCallId??f?.agent?.toolCallId,w=E(p);if(w){let y=await w,m=k.getStore()?.pool;return m?b(y,m,t):y}return K("tool",c,async()=>{let y=await i.call(a,u,l);if(y===void 0)throw new Error(`工具 ${c} 执行完成但未返回结果(undefined)——请检查工具实现是否缺少 return`);let m=k.getStore()?.pool;return m?b(y,m,t):y},{logger:z,detail:{args:u}})},d[M]=!0,r[n]=d}return r}import{RequestContext as H}from"@mastra/core/request-context";import{AuthError as X}from"@tbox.cn/app-sdk-server";var I="tbox.engine.run",P=Symbol.for("tbox.engine.runMetadata");function we(e,t){e.set(I,Object.freeze({...t,[P]:!0}))}function Ee(e){let t=e?.requestContext?.get(I),r=e?.agent?.toolCallId??e?.toolCallId;if(!(!t||t[P]!==!0||typeof t.runId!="string"||typeof t.threadKey!="string"||typeof r!="string"||!r))return Object.freeze({runId:t.runId,threadKey:t.threadKey,toolCallId:r})}function W(e){let t=e?.requestContext;if(!t)return;let r=t.get("identity");if(!r)return;let n=t.get("conversationId"),o=t.get("credentials"),s=t.get("attributes");return{identity:r,...typeof n=="string"?{conversationId:n}:{},...o?{credentials:o}:{},...s?{attributes:s}:{}}}function h(e,t){let r=W(e);if(!r)throw X.forbidden(`工具运行上下文缺失${t?`(tool=${t})`:""}:请从 execute 第二参读取(const reqCtx = requireToolRequestContext(execCtx, toolId))`);return r}function Ae(e){let t=new H;return t.set("identity",e.identity),e.conversationId&&t.set("conversationId",e.conversationId),e.credentials&&t.set("credentials",e.credentials),e.attributes&&t.set("attributes",e.attributes),{requestContext:t}}import{existsSync as N,mkdirSync as B,readFileSync as Z,writeFileSync as G}from"fs";import x from"path";import{createServerLogger as V}from"@tbox.cn/app-sdk-server";var Q=V("APP");function Pe(e){if(process.env.NODE_ENV!=="production")for(let[t,r]of[["sampleData",e.sampleData],...(e.samples??[]).map((n,o)=>[`samples[${o}]`,n.data])]){let n=e.dataSchema.safeParse(r);n.success||Q.warn(`卡片样例与 dataSchema 不匹配:${e.cardType} ${t}`,n.error.message)}return e}function he(e,t,r){return{cardType:e.cardType,data:t,note:r}}var v=new Map,ee=0;function Ne(){return[...v.entries()].map(([e,t])=>({name:e,state:t}))}function ve(e,t={}){let r=new Map,n=process.env.TBOX_STATE_MEMORY==="1",o=t.persist==="file"&&!n?re(t.stateName??"user-state"):void 0;if(o)for(let[c,u]of ne(o))r.set(c,u);let s=()=>{o&&oe(o,r)},a=c=>{let u=r.get(c);return u===void 0&&(u=e(c),r.set(c,u)),u},i=t.stateName;i||(i=`state-${++ee}`);let d={get:c=>structuredClone(a(c)),update(c,u){let l=structuredClone(a(c)),f=u(l),p=f===void 0?l:f;return r.set(c,p),s(),structuredClone(p)},reset(c){c===void 0?r.clear():r.delete(c),s()}};return v.set(i,d),d}function _e(e,t){let n=h(e,t).identity;return{userId:n.userId,source:n.source,...n.displayName!==void 0?{displayName:n.displayName}:{},...n.avatar!==void 0?{avatar:n.avatar}:{}}}function te(e=process.cwd()){let t=x.resolve(e);for(;;){if(N(x.join(t,".tbox","app.json")))return t;let r=x.dirname(t);if(r===t)return x.resolve(e);t=r}}function re(e){return x.join(te(),".tbox","state",`${e}.json`)}function ne(e){let t=new Map;try{if(!N(e))return t;let r=JSON.parse(Z(e,"utf8"));for(let[n,o]of Object.entries(r))t.set(n,o)}catch{}return t}function oe(e,t){try{B(x.dirname(e),{recursive:!0}),G(e,JSON.stringify(Object.fromEntries(t),null,2))}catch{}}export{q as a,T as b,ie as c,ce as d,S as e,F as f,ge as g,ye as h,xe as i,me as j,b as k,k as l,Te as m,we as n,Ee as o,W as p,h as q,Ae as r,Pe as s,he as t,Ne as u,ve as v,_e as w};
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";var n=e.object({enableImageUpload:e.boolean().default(!0),enableVideoUpload:e.boolean().default(!0),enableTTS:e.boolean().default(!0),enableVoiceInput:e.boolean().default(!0),defaultInputMode:e.enum(["TEXT","VOICE"]).default("TEXT"),quickCommands:e.array(e.object({label:e.string().describe("展示文案"),query:e.string().describe("点击后发送给智能体的用户消息")}).passthrough()).default([]),identity:e.object({name:e.string().describe("展示名,如品牌或智能体名"),tagline:e.string().optional().describe("一句话说明,展示在名称下方")}).optional(),welcome:e.object({title:e.string(),subtitle:e.string().optional()}).optional(),retryOnError:e.boolean().default(!0)}),r=e.strictObject({instructions:e.array(e.string()).min(1).describe("必填;逐行拼接的业务提示词,拼接后不得全为空白;不替代平台规则"),memoryInstructions:e.array(e.string()).min(1).optional().describe("装配长期记忆时追加的业务提示词;在场时拼接后不得全为空白")}),t=e.union([e.boolean(),e.literal("auto"),e.record(e.string(),e.unknown())]),o=e.union([e.boolean(),e.literal("auto")]),l=e.object({modelName:e.string().min(1).optional().describe("模型路由名;缺席时使用 APP_AI_MODEL_NAME"),thinking:t.optional().describe("true/false 控制思考;auto 不注入;对象作为网关兼容请求字段,禁止凭证"),parallelToolCalls:o.optional().describe("true/false 控制并行工具调用;auto 使用网关默认"),contentTagHygiene:e.object({off:e.array(e.enum(["think","tool-call-text"])).optional(),extraTags:e.array(e.object({name:e.string().regex(/^[a-zA-Z][a-zA-Z0-9_-]{0,31}$/),family:e.enum(["think","tool-call-text"])})).max(16).optional()}).optional()});export{n as a,r as b,t as c,o as d,l as e};
package/dist/config.d.ts CHANGED
@@ -18,6 +18,30 @@ declare const chatConfigSchema: z.ZodObject<{
18
18
  label: z.ZodString;
19
19
  query: z.ZodString;
20
20
  }, z.ZodTypeAny, "passthrough">>, "many">>;
21
+ /** 智能体身份:页头品牌区与空会话欢迎区共用(缺省回退 scope 回显的 mallName) */
22
+ identity: z.ZodOptional<z.ZodObject<{
23
+ name: z.ZodString;
24
+ tagline: z.ZodOptional<z.ZodString>;
25
+ }, "strip", z.ZodTypeAny, {
26
+ name: string;
27
+ tagline?: string | undefined;
28
+ }, {
29
+ name: string;
30
+ tagline?: string | undefined;
31
+ }>>;
32
+ /** 空会话欢迎区(无 home 槽时渲染) */
33
+ welcome: z.ZodOptional<z.ZodObject<{
34
+ title: z.ZodString;
35
+ subtitle: z.ZodOptional<z.ZodString>;
36
+ }, "strip", z.ZodTypeAny, {
37
+ title: string;
38
+ subtitle?: string | undefined;
39
+ }, {
40
+ title: string;
41
+ subtitle?: string | undefined;
42
+ }>>;
43
+ /** 出错消息是否提供「重试」入口(重发上一条用户消息),缺省 true */
44
+ retryOnError: z.ZodDefault<z.ZodBoolean>;
21
45
  }, "strip", z.ZodTypeAny, {
22
46
  enableImageUpload: boolean;
23
47
  enableVideoUpload: boolean;
@@ -28,6 +52,15 @@ declare const chatConfigSchema: z.ZodObject<{
28
52
  label: z.ZodString;
29
53
  query: z.ZodString;
30
54
  }, z.ZodTypeAny, "passthrough">[];
55
+ retryOnError: boolean;
56
+ identity?: {
57
+ name: string;
58
+ tagline?: string | undefined;
59
+ } | undefined;
60
+ welcome?: {
61
+ title: string;
62
+ subtitle?: string | undefined;
63
+ } | undefined;
31
64
  }, {
32
65
  enableImageUpload?: boolean | undefined;
33
66
  enableVideoUpload?: boolean | undefined;
@@ -38,6 +71,15 @@ declare const chatConfigSchema: z.ZodObject<{
38
71
  label: z.ZodString;
39
72
  query: z.ZodString;
40
73
  }, z.ZodTypeAny, "passthrough">[] | undefined;
74
+ identity?: {
75
+ name: string;
76
+ tagline?: string | undefined;
77
+ } | undefined;
78
+ welcome?: {
79
+ title: string;
80
+ subtitle?: string | undefined;
81
+ } | undefined;
82
+ retryOnError?: boolean | undefined;
41
83
  }>;
42
84
  declare const agentPromptFileSchema: z.ZodObject<{
43
85
  instructions: z.ZodArray<z.ZodString, "many">;
package/dist/config.js CHANGED
@@ -1 +1 @@
1
- import{a,b,c,d,e}from"./chunk-2M4P57DG.js";export{b as agentPromptFileSchema,a as chatConfigSchema,e as llmProviderFileSchema,d as parallelSchema,c as thinkingSchema};
1
+ import{a,b,c,d,e}from"./chunk-NJDW5VOH.js";export{b as agentPromptFileSchema,a as chatConfigSchema,e as llmProviderFileSchema,d as parallelSchema,c as thinkingSchema};