@ct-agents/prompts 0.2.0 → 0.2.2
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/package.json +3 -3
- package/src/index.ts +12 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ct-agents/prompts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"src"
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"zod": "4.4.3",
|
|
14
|
-
"@ct-agents/protocol": "0.2.
|
|
15
|
-
"@ct-agents/store": "0.2.
|
|
14
|
+
"@ct-agents/protocol": "0.2.2",
|
|
15
|
+
"@ct-agents/store": "0.2.2"
|
|
16
16
|
},
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
package/src/index.ts
CHANGED
|
@@ -49,6 +49,7 @@ type TemplateNode =
|
|
|
49
49
|
| { type: 'section'; key: string; inverted: boolean; children: TemplateNode[] };
|
|
50
50
|
|
|
51
51
|
const templateTagPattern = /\{\{\s*([#^/]?)\s*([a-zA-Z0-9_.-]+)\s*\}\}/g;
|
|
52
|
+
const tripleVariableTagPattern = /\{\{\{\s*([a-zA-Z0-9_.-]+)\s*\}\}\}/g;
|
|
52
53
|
|
|
53
54
|
function parseTemplate(template: string) {
|
|
54
55
|
const root: TemplateNode[] = [];
|
|
@@ -191,8 +192,16 @@ function renderNodes(nodes: TemplateNode[], stack: unknown[]): string {
|
|
|
191
192
|
}).join('');
|
|
192
193
|
}
|
|
193
194
|
|
|
194
|
-
|
|
195
|
-
|
|
195
|
+
/**
|
|
196
|
+
* 使用 Prompt Registry 支持的通用 Mustache 子集渲染持久化 Fragment。
|
|
197
|
+
*
|
|
198
|
+
* Config Version 投影与默认 Registry 必须复用同一入口,避免固定版本 Session
|
|
199
|
+
* 绕过 metadata 渲染并把占位符原样发送给模型。
|
|
200
|
+
*/
|
|
201
|
+
export function renderPromptTemplate(template: string, context: Record<string, unknown>) {
|
|
202
|
+
// 当前渲染器不执行 HTML 转义,因此双、三花括号变量具有相同输出语义。
|
|
203
|
+
const normalizedTemplate = template.replace(tripleVariableTagPattern, '{{$1}}');
|
|
204
|
+
return renderNodes(parseTemplate(normalizedTemplate), [context]);
|
|
196
205
|
}
|
|
197
206
|
|
|
198
207
|
export class DefaultPromptRegistry implements PromptRegistry {
|
|
@@ -217,7 +226,7 @@ export class DefaultPromptRegistry implements PromptRegistry {
|
|
|
217
226
|
if (fragmentId.startsWith('fragment:')) {
|
|
218
227
|
const persistedFragment = byId.get(fragmentId);
|
|
219
228
|
if (persistedFragment?.enabled) {
|
|
220
|
-
collected.push(
|
|
229
|
+
collected.push(renderPromptTemplate(persistedFragment.content, context));
|
|
221
230
|
}
|
|
222
231
|
continue;
|
|
223
232
|
}
|