@onco-foundry/agent-template 0.3.0 → 0.4.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.
@@ -2,7 +2,7 @@ import { type AgentSpec, type ModelClient, type ToolDefinition } from 'agent-lat
2
2
  import { z } from 'zod';
3
3
  import { type Capability } from '@onco-foundry/capability-registry';
4
4
  import type { CapabilityDelegation } from '@onco-foundry/agent-runtime';
5
- import { type VersionedResource } from '@onco-foundry/resource-versioning';
5
+ import { type VersionedResource, type VersionedResourceStore } from '@onco-foundry/resource-versioning';
6
6
  import { type Tracer } from '@onco-foundry/trace-port';
7
7
  /**
8
8
  * 版本化 prompt 资源的 manifest 形状:结构版本号与内容版本号分开,
@@ -80,8 +80,14 @@ export type AgentTemplateDeclaration<I, O, C = undefined> = {
80
80
  /**
81
81
  * 版本化 prompt 资源根(含 current.json 指针):
82
82
  * new URL('./resources/prompts/', import.meta.url)。生效版本解析归模板,编排方零感知。
83
+ * 与 promptStore 二选一。
83
84
  */
84
- promptDir: URL;
85
+ promptDir?: URL;
86
+ /**
87
+ * prompt 资源存储后端:资源不在文件系统(如 MySQL)时注入,与 promptDir 二选一。
88
+ * 生效版本解析与 sha256 完整性校验不变,仍归模板。
89
+ */
90
+ promptStore?: VersionedResourceStore;
85
91
  /**
86
92
  * 可选限额。缺省:maxTokens 16384、maxTurns 10、thinking 关闭;
87
93
  * thinkingBudgetTokens 给了才开 thinking(按 clampThinkingBudgetTokens 钳制到 maxTokens 以内)。
@@ -48,6 +48,20 @@ export const defineAgentTemplate = (declaration) => {
48
48
  throw new AppError(`模板 id 必须是 kebab-case(小写字母数字与连字符):${declaration.id}`);
49
49
  }
50
50
  const { id } = declaration;
51
+ /**
52
+ * prompt 来源在 loadPrompt 时才解析:声明对象允许在定义后补齐 promptDir/promptStore
53
+ * (测试夹具在 beforeAll 里指向临时资源就是这种用法),但同一时刻二者只能有一个。
54
+ */
55
+ const resolvePromptSource = () => {
56
+ if (declaration.promptDir !== undefined && declaration.promptStore !== undefined) {
57
+ throw new AppError(`模板 ${id} 的 promptDir 与 promptStore 只能二选一`);
58
+ }
59
+ if (declaration.promptStore !== undefined)
60
+ return { store: declaration.promptStore };
61
+ if (declaration.promptDir !== undefined)
62
+ return { baseDir: declaration.promptDir };
63
+ throw new AppError(`模板 ${id} 必须声明 promptDir 或 promptStore 之一(prompt 资源在哪里,模板必须知道)`);
64
+ };
51
65
  const card = {
52
66
  name: id,
53
67
  kind: 'agent',
@@ -70,7 +84,7 @@ export const defineAgentTemplate = (declaration) => {
70
84
  const loadPrompt = async (loadOptions) => {
71
85
  const adapter = declaration.promptManifest ?? defaultPromptManifest;
72
86
  const promptResource = await loadActiveVersionedResource({
73
- baseDir: declaration.promptDir,
87
+ ...resolvePromptSource(),
74
88
  manifestSchema: adapter.manifestSchema,
75
89
  ...(loadOptions?.promptVersion !== undefined
76
90
  ? { versionOverride: loadOptions.promptVersion }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onco-foundry/agent-template",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -14,11 +14,11 @@
14
14
  "dependencies": {
15
15
  "agent-lattice": "0.25.0",
16
16
  "zod": "^4.4.3",
17
+ "@onco-foundry/resource-versioning": "0.3.0",
17
18
  "@onco-foundry/agent-runtime": "0.2.2",
18
- "@onco-foundry/capability-registry": "0.1.1",
19
+ "@onco-foundry/trace-port": "0.3.2",
19
20
  "@onco-foundry/errors": "0.1.1",
20
- "@onco-foundry/resource-versioning": "0.2.0",
21
- "@onco-foundry/trace-port": "0.3.2"
21
+ "@onco-foundry/capability-registry": "0.1.1"
22
22
  },
23
23
  "publishConfig": {
24
24
  "access": "public"