@tbox.cn/app-agent-sdk-server 1.0.0-alpha.1 → 1.0.0-alpha.7
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/dist/app-primitives-BU-_eI-T.d.ts +207 -0
- package/dist/chunk-IZOFAJNX.js +1 -0
- package/dist/chunk-NJDW5VOH.js +1 -0
- package/dist/config.d.ts +42 -0
- package/dist/config.js +1 -1
- package/dist/server/index.d.ts +133 -132
- package/dist/server/index.js +41 -41
- package/dist/testing/index.d.ts +64 -0
- package/dist/testing/index.js +1 -0
- package/package.json +10 -6
- package/dist/chunk-2M4P57DG.js +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ServerContext, ServerRegistry, ComponentStateStore } from '@tbox.cn/app-sdk-server';
|
|
2
|
+
import { UserIdSource } from '@tbox.cn/app-contracts';
|
|
3
|
+
export { R as RegisteredUserState, u as userStates } from '../app-primitives-BU-_eI-T.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import 'node:async_hooks';
|
|
6
|
+
import '@mastra/core/tools';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 测试面:进程内直调应用原语,不需要端口、模型或浏览器。
|
|
10
|
+
*
|
|
11
|
+
* 用途是把「验证一次能力」从「起服务、连 WS、说一句话」压到一次函数调用:
|
|
12
|
+
* 装配 registry → 调工具 → 按注册的 `dataSchema` 校验收到的卡片。
|
|
13
|
+
*
|
|
14
|
+
* 只注册应用级原语(tools / cards);模块装配不在此列——模块有各自的注册链与副作用,
|
|
15
|
+
* 需要模块参与时用 `pnpm dev` + 卡片预览。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
interface HarnessCardCheck {
|
|
19
|
+
cardType: string;
|
|
20
|
+
valid: boolean;
|
|
21
|
+
issues: string[];
|
|
22
|
+
/** 卡片数据(证据包用它渲染场景实例;只含声明数据,不含令牌) */
|
|
23
|
+
data?: unknown;
|
|
24
|
+
}
|
|
25
|
+
interface HarnessCallResult {
|
|
26
|
+
/** 去掉 `cards` 保留字段后的事实出参 */
|
|
27
|
+
output: unknown;
|
|
28
|
+
cards: HarnessCardCheck[];
|
|
29
|
+
durationMs: number;
|
|
30
|
+
}
|
|
31
|
+
interface ToolHarness {
|
|
32
|
+
call(toolId: string, input?: unknown, opts?: {
|
|
33
|
+
user?: string;
|
|
34
|
+
source?: UserIdSource;
|
|
35
|
+
}): Promise<HarnessCallResult>;
|
|
36
|
+
/** 直调应用级卡片动作(不经模型、不签令牌——令牌链路由动作分发测试覆盖) */
|
|
37
|
+
act(actionId: string, input?: unknown, opts?: {
|
|
38
|
+
user?: string;
|
|
39
|
+
}): Promise<unknown>;
|
|
40
|
+
/** 已注册的工具 id(排序) */
|
|
41
|
+
toolIds(): string[];
|
|
42
|
+
/** 已登记的用户状态快照(构造即登记;探针与场景用它做状态差异) */
|
|
43
|
+
states(user?: string): {
|
|
44
|
+
name: string;
|
|
45
|
+
value: unknown;
|
|
46
|
+
}[];
|
|
47
|
+
/** 已注册的卡片类型(排序) */
|
|
48
|
+
cardTypes(): string[];
|
|
49
|
+
context: ServerContext;
|
|
50
|
+
}
|
|
51
|
+
interface ToolHarnessOptions {
|
|
52
|
+
registry: ServerRegistry;
|
|
53
|
+
/** 缺省用户:`local_harness` */
|
|
54
|
+
user?: {
|
|
55
|
+
userId?: string;
|
|
56
|
+
source?: UserIdSource;
|
|
57
|
+
};
|
|
58
|
+
state?: ComponentStateStore;
|
|
59
|
+
/** 调用工具时的额外上下文字段(如 attributes) */
|
|
60
|
+
attributes?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
declare function createToolHarness(opts: ToolHarnessOptions): ToolHarness;
|
|
63
|
+
|
|
64
|
+
export { type HarnessCallResult, type HarnessCardCheck, type ToolHarness, type ToolHarnessOptions, createToolHarness };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as v,l as C,m as $,r as k,u as x}from"../chunk-IZOFAJNX.js";import{checkActionResultShape as j,createServerContext as H}from"@tbox.cn/app-sdk-server";var P=e=>{if(e===null||typeof e!="object"||Array.isArray(e))return e;let{cards:n,...i}=e;return i};function A(e){let n={};for(let i of e.tools)n[i.id]=i;return{tools:n,cards:e.cards??{}}}function M(e){let n=H(e.state?{state:e.state}:{});for(let r of e.registry.tools)n.tools.register(r);for(let r of Object.values(e.registry.cards??{}))n.cards.register(r);for(let r of Object.values(e.registry.actions??{}))n.cardActions.register(r);let{tools:i,cards:b}=A(e.registry),R=$(i,b),w={userId:e.user?.userId??"local_harness",source:e.user?.source??"local"},E=()=>k({identity:w,...e.attributes?{attributes:e.attributes}:{}});return{context:n,toolIds:()=>e.registry.tools.map(r=>r.id).sort(),states:r=>x().map(({name:d,state:a})=>({name:d,value:a.get(r??w.userId)})),cardTypes:()=>Object.keys(e.registry.cards??{}).sort(),async act(r,d,a){let s=e.registry.actions?.[r];if(!s)throw new Error(`未注册的动作: ${r}(可用:${Object.keys(e.registry.actions??{}).join("、")||"无"})`);if(typeof s.execute!="function")throw new Error(`动作没有 execute: ${r}`);let p=d??{},l=s.inputSchema;if(l&&typeof l.safeParse=="function"){let o=l.safeParse(p);if(!o.success)throw new Error(`动作 ${r} 入参校验失败:${o.error?.message??"invalid input"}`);p=o.data}let u=await s.execute(p,{identity:{userId:a?.user??w.userId,source:w.source}}),y=j(u);if(y.length>0)throw new Error(`动作 ${r} 结果形状非法:${y.join(";")}`);let c=u,t=(Array.isArray(s.cardType)?s.cardType:[s.cardType]).filter(o=>typeof o=="string"),f="",g=(o,I,T)=>{if(o.length===0)return;let S=o.map(m=>e.registry.cards?.[m]).filter(Boolean);if(S.length===0)throw new Error(`动作 ${r} 的${T}卡片类型未注册:${o.join("、")}`);if(!S.some(m=>{let h=m.dataSchema.safeParse(I);return h.success?!0:(f=h.error.message,!1)}))throw new Error(`动作 ${r} 的${T}数据未通过 ${o.join("、")} dataSchema 校验:${f}`)};return c.update&&g(t,c.update.data,"update"),c.card&&g([c.card.cardType],c.card.data,"card"),u},async call(r,d,a){let s=R[r];if(!s)throw new Error(`未注册的工具: ${r}(可用:${e.registry.tools.map(t=>t.id).join("、")})`);let p=a?.user?k({identity:{userId:a.user,source:a.source??"local"}}):E(),l=Date.now();if(!s.execute)throw new Error(`工具没有 execute: ${r}`);let u=v(),y=await C.run({pool:u},()=>s.execute(d??{},p)),c=u.entries().map(t=>{let f=n.cards.resolve(t.cardType);if(!f)return{cardType:t.cardType,valid:!1,issues:[`未注册的卡片类型: ${t.cardType}`]};let g=f.dataSchema.safeParse(t.data);return g.success?{cardType:t.cardType,valid:!0,issues:[],data:t.data}:{cardType:t.cardType,valid:!1,issues:[g.error.message],data:t.data}});return{output:P(y),cards:c,durationMs:Date.now()-l}}}}export{M as createToolHarness,x as userStates};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-agent-sdk-server",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "tbox agent 应用框架 server 轴:chat 引擎、技能/前置工具/记忆、LLM provider、会话与 WS 通道、TTS、工具工厂、agent 配置。模块系统(注册表/装配/动作域/auth/inspector)在 @tbox.cn/app-sdk-server。",
|
|
6
6
|
"exports": {
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"./config": {
|
|
20
20
|
"types": "./dist/config.d.ts",
|
|
21
21
|
"import": "./dist/config.js"
|
|
22
|
+
},
|
|
23
|
+
"./testing": {
|
|
24
|
+
"types": "./dist/testing/index.d.ts",
|
|
25
|
+
"import": "./dist/testing/index.js"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
"files": [
|
|
@@ -38,16 +42,16 @@
|
|
|
38
42
|
"@mastra/core": "1.59.0",
|
|
39
43
|
"@mastra/observability": "1.16.5",
|
|
40
44
|
"@tbox.cn/agent-plugin": "0.1.0",
|
|
41
|
-
"@tbox.cn/app-contracts": "1.0.0-alpha.1",
|
|
42
|
-
"@tbox.cn/app-sdk-core": "1.0.0-alpha.1",
|
|
43
|
-
"@tbox.cn/app-sdk-server": "1.0.0-alpha.1",
|
|
44
45
|
"ai": "6.0.246",
|
|
45
46
|
"express": "4.22.2",
|
|
46
47
|
"gray-matter": "4.0.3",
|
|
47
48
|
"jsonc-parser": "3.3.1",
|
|
48
49
|
"undici": "7.29.0",
|
|
49
50
|
"ws": "8.21.3",
|
|
50
|
-
"zod": "3.25.76"
|
|
51
|
+
"zod": "3.25.76",
|
|
52
|
+
"@tbox.cn/app-contracts": "1.0.0-alpha.7",
|
|
53
|
+
"@tbox.cn/app-sdk-core": "1.0.0-alpha.7",
|
|
54
|
+
"@tbox.cn/app-sdk-server": "1.0.0-alpha.7"
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
|
53
57
|
"@mastra/schema-compat": "1.3.7",
|
|
@@ -59,7 +63,7 @@
|
|
|
59
63
|
"tsup": "8.5.1",
|
|
60
64
|
"typescript": "5.9.3",
|
|
61
65
|
"vitest": "4.1.10",
|
|
62
|
-
"@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.
|
|
66
|
+
"@tbox.cn/app-agent-sdk-client": "1.0.0-alpha.7"
|
|
63
67
|
},
|
|
64
68
|
"license": "MIT",
|
|
65
69
|
"scripts": {
|
package/dist/chunk-2M4P57DG.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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([])}),l=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")]),r=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,l as b,t as c,o as d,r as e};
|