@fastpaca/cria 1.4.0 → 1.5.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.
Files changed (116) hide show
  1. package/README.md +25 -22
  2. package/dist/dsl/builder.d.ts +243 -0
  3. package/dist/dsl/builder.d.ts.map +1 -0
  4. package/dist/dsl/builder.js +458 -0
  5. package/dist/dsl/builder.js.map +1 -0
  6. package/dist/dsl/index.d.ts +71 -0
  7. package/dist/dsl/index.d.ts.map +1 -0
  8. package/dist/dsl/index.js +82 -0
  9. package/dist/dsl/index.js.map +1 -0
  10. package/dist/dsl/strategies.d.ts +29 -0
  11. package/dist/dsl/strategies.d.ts.map +1 -0
  12. package/dist/dsl/strategies.js +62 -0
  13. package/dist/dsl/strategies.js.map +1 -0
  14. package/dist/dsl/summary.d.ts +50 -0
  15. package/dist/dsl/summary.d.ts.map +1 -0
  16. package/dist/dsl/summary.js +56 -0
  17. package/dist/dsl/summary.js.map +1 -0
  18. package/dist/dsl/templating.d.ts +31 -0
  19. package/dist/dsl/templating.d.ts.map +1 -0
  20. package/dist/dsl/templating.js +83 -0
  21. package/dist/dsl/templating.js.map +1 -0
  22. package/dist/{components → dsl}/vector-search.d.ts +11 -34
  23. package/dist/dsl/vector-search.d.ts.map +1 -0
  24. package/dist/{components → dsl}/vector-search.js +12 -34
  25. package/dist/dsl/vector-search.js.map +1 -0
  26. package/dist/eval/index.d.ts +13 -2
  27. package/dist/eval/index.d.ts.map +1 -1
  28. package/dist/eval/judge.d.ts +6 -5
  29. package/dist/eval/judge.d.ts.map +1 -1
  30. package/dist/eval/judge.js +18 -5
  31. package/dist/eval/judge.js.map +1 -1
  32. package/dist/index.d.ts +5 -9
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +3 -6
  35. package/dist/index.js.map +1 -1
  36. package/dist/instrumentation/otel.js +5 -14
  37. package/dist/instrumentation/otel.js.map +1 -1
  38. package/dist/providers/ai-sdk.d.ts +29 -0
  39. package/dist/providers/ai-sdk.d.ts.map +1 -0
  40. package/dist/providers/ai-sdk.js +104 -0
  41. package/dist/providers/ai-sdk.js.map +1 -0
  42. package/dist/providers/anthropic.d.ts +30 -0
  43. package/dist/providers/anthropic.d.ts.map +1 -0
  44. package/dist/providers/anthropic.js +160 -0
  45. package/dist/providers/anthropic.js.map +1 -0
  46. package/dist/providers/openai.d.ts +37 -0
  47. package/dist/providers/openai.d.ts.map +1 -0
  48. package/dist/providers/openai.js +164 -0
  49. package/dist/providers/openai.js.map +1 -0
  50. package/dist/render.d.ts +24 -22
  51. package/dist/render.d.ts.map +1 -1
  52. package/dist/render.js +191 -63
  53. package/dist/render.js.map +1 -1
  54. package/dist/testing/plaintext.d.ts +28 -0
  55. package/dist/testing/plaintext.d.ts.map +1 -0
  56. package/dist/testing/plaintext.js +71 -0
  57. package/dist/testing/plaintext.js.map +1 -0
  58. package/dist/types.d.ts +204 -163
  59. package/dist/types.d.ts.map +1 -1
  60. package/dist/types.js +37 -100
  61. package/dist/types.js.map +1 -1
  62. package/package.json +7 -33
  63. package/dist/components/index.d.ts +0 -147
  64. package/dist/components/index.d.ts.map +0 -1
  65. package/dist/components/index.js +0 -181
  66. package/dist/components/index.js.map +0 -1
  67. package/dist/components/summary.d.ts +0 -89
  68. package/dist/components/summary.d.ts.map +0 -1
  69. package/dist/components/summary.js +0 -118
  70. package/dist/components/summary.js.map +0 -1
  71. package/dist/components/vector-search.d.ts.map +0 -1
  72. package/dist/components/vector-search.js.map +0 -1
  73. package/dist/dsl.d.ts +0 -233
  74. package/dist/dsl.d.ts.map +0 -1
  75. package/dist/dsl.js +0 -428
  76. package/dist/dsl.js.map +0 -1
  77. package/dist/integrations/ai-sdk.d.ts +0 -22
  78. package/dist/integrations/ai-sdk.d.ts.map +0 -1
  79. package/dist/integrations/ai-sdk.js +0 -172
  80. package/dist/integrations/ai-sdk.js.map +0 -1
  81. package/dist/integrations/anthropic.d.ts +0 -50
  82. package/dist/integrations/anthropic.d.ts.map +0 -1
  83. package/dist/integrations/anthropic.js +0 -220
  84. package/dist/integrations/anthropic.js.map +0 -1
  85. package/dist/integrations/openai.d.ts +0 -48
  86. package/dist/integrations/openai.d.ts.map +0 -1
  87. package/dist/integrations/openai.js +0 -265
  88. package/dist/integrations/openai.js.map +0 -1
  89. package/dist/jsx/index.d.ts +0 -6
  90. package/dist/jsx/index.d.ts.map +0 -1
  91. package/dist/jsx/index.js +0 -7
  92. package/dist/jsx/index.js.map +0 -1
  93. package/dist/jsx/jsx-dev-runtime.d.ts +0 -2
  94. package/dist/jsx/jsx-dev-runtime.d.ts.map +0 -1
  95. package/dist/jsx/jsx-dev-runtime.js +0 -3
  96. package/dist/jsx/jsx-dev-runtime.js.map +0 -1
  97. package/dist/jsx/jsx-runtime.d.ts +0 -40
  98. package/dist/jsx/jsx-runtime.d.ts.map +0 -1
  99. package/dist/jsx/jsx-runtime.js +0 -40
  100. package/dist/jsx/jsx-runtime.js.map +0 -1
  101. package/dist/renderers/markdown.d.ts +0 -3
  102. package/dist/renderers/markdown.d.ts.map +0 -1
  103. package/dist/renderers/markdown.js +0 -43
  104. package/dist/renderers/markdown.js.map +0 -1
  105. package/dist/renderers/shared.d.ts +0 -82
  106. package/dist/renderers/shared.d.ts.map +0 -1
  107. package/dist/renderers/shared.js +0 -156
  108. package/dist/renderers/shared.js.map +0 -1
  109. package/dist/snapshot.d.ts +0 -47
  110. package/dist/snapshot.d.ts.map +0 -1
  111. package/dist/snapshot.js +0 -144
  112. package/dist/snapshot.js.map +0 -1
  113. package/dist/tokenizers.d.ts +0 -14
  114. package/dist/tokenizers.d.ts.map +0 -1
  115. package/dist/tokenizers.js +0 -45
  116. package/dist/tokenizers.js.map +0 -1
@@ -1,265 +0,0 @@
1
- import { markdownRenderer } from "../renderers/markdown";
2
- import { coalesceTextParts, collectMessageNodes, collectSemanticParts, partsToText, safeStringify, } from "../renderers/shared";
3
- /**
4
- * Renderer that outputs ChatCompletionMessageParam[] for the OpenAI Chat Completions API.
5
- * Pass this to render() to get messages compatible with client.chat.completions.create().
6
- *
7
- * @example
8
- * ```ts
9
- * import { render } from "@fastpaca/cria";
10
- * import { chatCompletions } from "@fastpaca/cria/openai";
11
- *
12
- * const messages = await render(prompt, { tokenizer, budget, renderer: chatCompletions });
13
- * const response = await openai.chat.completions.create({ model: "gpt-4", messages });
14
- * ```
15
- */
16
- export const chatCompletions = {
17
- name: "openai-chat-completions",
18
- tokenString: markdownRenderer.tokenString,
19
- render: (element) => renderToChatCompletions(element),
20
- empty: () => [],
21
- };
22
- function renderToChatCompletions(root) {
23
- const messageNodes = collectMessageNodes(root);
24
- const result = [];
25
- for (const messageNode of messageNodes) {
26
- result.push(...messageNodeToParams(messageNode));
27
- }
28
- return result;
29
- }
30
- function messageNodeToParams(messageNode) {
31
- const parts = coalesceTextParts(collectSemanticParts(messageNode.children));
32
- if (messageNode.role === "system") {
33
- return [toSystemMessage(parts)];
34
- }
35
- if (messageNode.role === "user") {
36
- return [toUserMessage(parts)];
37
- }
38
- // Assistant message: may contain tool calls, and tool results become separate messages
39
- // Preserve original part ordering - only separate out tool results
40
- const assistantParts = parts.filter((p) => p.type !== "tool-result");
41
- const toolResultParts = parts.filter((p) => p.type === "tool-result");
42
- const result = [];
43
- if (assistantParts.length > 0 || toolResultParts.length === 0) {
44
- result.push(toAssistantMessage(assistantParts));
45
- }
46
- for (const toolResult of toolResultParts) {
47
- result.push(toToolMessage(toolResult));
48
- }
49
- return result;
50
- }
51
- function toSystemMessage(parts) {
52
- return {
53
- role: "system",
54
- content: partsToText(parts, { wrapReasoning: true }),
55
- };
56
- }
57
- function toUserMessage(parts) {
58
- return {
59
- role: "user",
60
- content: partsToText(parts, { wrapReasoning: true }),
61
- };
62
- }
63
- function toAssistantMessage(parts) {
64
- const textContent = partsToText(parts, { wrapReasoning: true });
65
- const toolCalls = parts
66
- .filter((part) => part.type === "tool-call")
67
- .map((part) => ({
68
- id: part.toolCallId,
69
- type: "function",
70
- function: {
71
- name: part.toolName,
72
- arguments: safeStringify(part.input),
73
- },
74
- }));
75
- const result = {
76
- role: "assistant",
77
- };
78
- if (textContent.length > 0) {
79
- result.content = textContent;
80
- }
81
- if (toolCalls.length > 0) {
82
- result.tool_calls = toolCalls;
83
- }
84
- return result;
85
- }
86
- function toToolMessage(part) {
87
- return {
88
- role: "tool",
89
- tool_call_id: part.toolCallId,
90
- content: safeStringify(part.output),
91
- };
92
- }
93
- /**
94
- * Renderer that outputs ResponseInputItem[] for the OpenAI Responses API.
95
- * Use this with reasoning models that support native reasoning.
96
- *
97
- * @example
98
- * ```ts
99
- * import { render } from "@fastpaca/cria";
100
- * import { responses } from "@fastpaca/cria/openai";
101
- *
102
- * const input = await render(prompt, { tokenizer, budget, renderer: responses });
103
- * const response = await openai.responses.create({ model: "o3", input });
104
- * ```
105
- */
106
- export const responses = {
107
- name: "openai-responses",
108
- tokenString: markdownRenderer.tokenString,
109
- render: (element) => renderToResponses(element),
110
- empty: () => [],
111
- };
112
- function renderToResponses(root) {
113
- const result = [];
114
- collectResponseItems(root, result);
115
- return result;
116
- }
117
- /**
118
- * Convert a message element's parts into ResponseInputItems.
119
- * Handles text, reasoning, tool calls, and tool results.
120
- */
121
- function collectMessageResponseItems(element, acc) {
122
- const parts = coalesceTextParts(collectSemanticParts(element.children));
123
- const role = mapRoleForResponses(element.role);
124
- let textBuffer = "";
125
- let reasoningIndex = 0;
126
- const flushTextBuffer = () => {
127
- if (textBuffer.length > 0) {
128
- acc.push({ role, content: textBuffer });
129
- textBuffer = "";
130
- }
131
- };
132
- for (const part of parts) {
133
- switch (part.type) {
134
- case "text":
135
- textBuffer += part.text;
136
- break;
137
- case "reasoning": {
138
- flushTextBuffer();
139
- acc.push({
140
- id: element.id
141
- ? `${element.id}-reasoning-${reasoningIndex}`
142
- : `reasoning_${reasoningIndex}`,
143
- type: "reasoning",
144
- summary: [{ type: "summary_text", text: part.text }],
145
- });
146
- reasoningIndex += 1;
147
- break;
148
- }
149
- case "tool-call":
150
- flushTextBuffer();
151
- acc.push({
152
- type: "function_call",
153
- call_id: part.toolCallId,
154
- name: part.toolName,
155
- arguments: safeStringify(part.input),
156
- });
157
- break;
158
- case "tool-result":
159
- flushTextBuffer();
160
- acc.push({
161
- type: "function_call_output",
162
- call_id: part.toolCallId,
163
- output: safeStringify(part.output),
164
- });
165
- break;
166
- default:
167
- // Exhaustive check - all SemanticPart types handled above
168
- break;
169
- }
170
- }
171
- flushTextBuffer();
172
- }
173
- function collectResponseItems(element, acc) {
174
- switch (element.kind) {
175
- case "message": {
176
- collectMessageResponseItems(element, acc);
177
- break;
178
- }
179
- case "reasoning": {
180
- // Native reasoning support in Responses API
181
- if (element.text.length > 0) {
182
- const reasoningItem = {
183
- id: element.id ?? `rs_${Date.now()}`,
184
- type: "reasoning",
185
- summary: [{ type: "summary_text", text: element.text }],
186
- };
187
- acc.push(reasoningItem);
188
- }
189
- break;
190
- }
191
- case "tool-call": {
192
- const toolCall = {
193
- type: "function_call",
194
- call_id: element.toolCallId,
195
- name: element.toolName,
196
- arguments: safeStringify(element.input),
197
- };
198
- acc.push(toolCall);
199
- break;
200
- }
201
- case "tool-result": {
202
- const toolResult = {
203
- type: "function_call_output",
204
- call_id: element.toolCallId,
205
- output: safeStringify(element.output),
206
- };
207
- acc.push(toolResult);
208
- break;
209
- }
210
- default: {
211
- // Recurse into children for regions without semantic kind
212
- for (const child of element.children) {
213
- if (typeof child !== "string") {
214
- collectResponseItems(child, acc);
215
- }
216
- }
217
- }
218
- }
219
- }
220
- const RESPONSE_ROLE_MAP = {
221
- system: "system",
222
- developer: "developer",
223
- user: "user",
224
- };
225
- function mapRoleForResponses(role) {
226
- return RESPONSE_ROLE_MAP[role] ?? "assistant";
227
- }
228
- /**
229
- * Create a ModelProvider for the OpenAI Chat Completions API.
230
- *
231
- * @example
232
- * ```typescript
233
- * import OpenAI from "openai";
234
- * import { createProvider } from "@fastpaca/cria/openai";
235
- *
236
- * const client = new OpenAI();
237
- * const provider = createProvider(client, "gpt-4o");
238
- * ```
239
- */
240
- export function createProvider(client, model, options = {}) {
241
- return {
242
- name: "openai",
243
- ...(options.tokenizer ? { tokenizer: options.tokenizer } : {}),
244
- renderer: chatCompletions,
245
- async completion(messages) {
246
- const response = await client.chat.completions.create({
247
- model,
248
- messages,
249
- });
250
- return response.choices[0]?.message?.content ?? "";
251
- },
252
- async object(messages, schema) {
253
- const response = await client.chat.completions.create({
254
- model,
255
- messages,
256
- response_format: {
257
- type: "json_object",
258
- },
259
- });
260
- const text = response.choices[0]?.message?.content ?? "";
261
- return schema.parse(JSON.parse(text));
262
- },
263
- };
264
- }
265
- //# sourceMappingURL=openai.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/integrations/openai.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,EAEX,aAAa,GAEd,MAAM,qBAAqB,CAAC;AAQ7B;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,eAAe,GAAiD;IAC3E,IAAI,EAAE,yBAAyB;IAC/B,WAAW,EAAE,gBAAgB,CAAC,WAAW;IACzC,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,uBAAuB,CAAC,OAAO,CAAC;IACrD,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE;CAChB,CAAC;AAEF,SAAS,uBAAuB,CAC9B,IAAmB;IAEnB,MAAM,YAAY,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAiC,EAAE,CAAC;IAEhD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACvC,MAAM,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,mBAAmB,CAC1B,WA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Aa,EACb,UAAqC,EAAE;IAEvC,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,QAAQ,EAAE,eAAe;QAEzB,KAAK,CAAC,UAAU,CAAC,QAAQ;YACvB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;gBACpD,KAAK;gBACL,QAAQ;aACT,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;QACrD,CAAC;QAED,KAAK,CAAC,MAAM,CACV,QAAsC,EACtC,MAAoB;YAEpB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;gBACpD,KAAK;gBACL,QAAQ;gBACR,eAAe,EAAE;oBACf,IAAI,EAAE,aAAa;iBACpB;aACF,CAAC,CAAC;YACH,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;YACzD,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Optional JSX surface. Prefer the fluent DSL from `@fastpaca/cria` as the default.
3
- */
4
- export * from "../components";
5
- export { Fragment, jsx, jsxs } from "./jsx-runtime";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/jsx/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC"}
package/dist/jsx/index.js DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Optional JSX surface. Prefer the fluent DSL from `@fastpaca/cria` as the default.
3
- */
4
- // biome-ignore lint/performance/noBarrelFile: JSX entrypoint intentionally re-exports components
5
- export * from "../components";
6
- export { Fragment, jsx, jsxs } from "./jsx-runtime";
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/jsx/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,iGAAiG;AACjG,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC"}
@@ -1,2 +0,0 @@
1
- export { Fragment, type JSX, jsx, jsx as jsxDEV, jsxs } from "./jsx-runtime";
2
- //# sourceMappingURL=jsx-dev-runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../../src/jsx/jsx-dev-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC"}
@@ -1,3 +0,0 @@
1
- // biome-ignore lint/performance/noBarrelFile: JSX dev runtime re-export
2
- export { Fragment, jsx, jsx as jsxDEV, jsxs } from "./jsx-runtime";
3
- //# sourceMappingURL=jsx-dev-runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsx-dev-runtime.js","sourceRoot":"","sources":["../../src/jsx/jsx-dev-runtime.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,QAAQ,EAAY,GAAG,EAAE,GAAG,IAAI,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC"}
@@ -1,40 +0,0 @@
1
- import type { MaybePromise, PromptChildren, PromptElement } from "../types";
2
- type ComponentFn = (props: Props) => MaybePromise<PromptElement>;
3
- /**
4
- * JSX child input type (pre-normalization).
5
- *
6
- * Why this exists:
7
- * - `PromptElement.children` (the IR) is always stored as canonical `PromptChildren`
8
- * (`PromptElement | string` flattened into an array).
9
- * - But JSX syntax allows much more: numbers, booleans, null/undefined, and nested arrays.
10
- * TypeScript will type-check those against the component prop type.
11
- *
12
- * This type represents what JSX can pass in; `normalizeChildren()` is the only place
13
- * we flatten/filter/coerce into the canonical IR representation.
14
- *
15
- * Keep this type local to the JSX runtime to avoid leaking JSX-specific concerns
16
- * into core IR and renderer types.
17
- */
18
- export type Child = PromptElement | Promise<PromptElement> | string | number | boolean | null | undefined | readonly Child[];
19
- type Props = Record<string, unknown> & {
20
- children?: Child;
21
- };
22
- export declare const Fragment: unique symbol;
23
- export declare function jsx(type: ComponentFn | typeof Fragment, props: Props): Promise<PromptElement>;
24
- export declare function jsxs(type: ComponentFn | typeof Fragment, props: Props): Promise<PromptElement>;
25
- export declare namespace JSX {
26
- type Element = MaybePromise<PromptElement>;
27
- type LibraryManagedAttributes<_C, P> = P extends {
28
- children?: PromptChildren;
29
- } ? Omit<P, "children"> & {
30
- children?: Child;
31
- } : P;
32
- interface IntrinsicElements {
33
- [key: string]: never;
34
- }
35
- interface ElementChildrenAttribute {
36
- children: unknown;
37
- }
38
- }
39
- export {};
40
- //# sourceMappingURL=jsx-runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../../src/jsx/jsx-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE5E,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,YAAY,CAAC,aAAa,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,KAAK,GACb,aAAa,GACb,OAAO,CAAC,aAAa,CAAC,GACtB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT,SAAS,KAAK,EAAE,CAAC;AAErB,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAmC5D,eAAO,MAAM,QAAQ,eAA8B,CAAC;AAGpD,wBAAsB,GAAG,CACvB,IAAI,EAAE,WAAW,GAAG,OAAO,QAAQ,EACnC,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,aAAa,CAAC,CASxB;AAGD,wBAAsB,IAAI,CACxB,IAAI,EAAE,WAAW,GAAG,OAAO,QAAQ,EACnC,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,aAAa,CAAC,CAExB;AAGD,MAAM,CAAC,OAAO,WAAW,GAAG,CAAC;IAC3B,KAAK,OAAO,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;IAE3C,KAAK,wBAAwB,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS;QAC/C,QAAQ,CAAC,EAAE,cAAc,CAAC;KAC3B,GACG,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG;QAAE,QAAQ,CAAC,EAAE,KAAK,CAAA;KAAE,GAC1C,CAAC,CAAC;IACN,UAAU,iBAAiB;QACzB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC;KACtB;IACD,UAAU,wBAAwB;QAChC,QAAQ,EAAE,OAAO,CAAC;KACnB;CACF"}
@@ -1,40 +0,0 @@
1
- // Normalize children: flatten arrays, filter nullish, coerce numbers to strings
2
- async function normalizeChildren(children) {
3
- if (children === undefined || children === null) {
4
- return [];
5
- }
6
- if (typeof children === "boolean") {
7
- return [];
8
- }
9
- if (typeof children === "string") {
10
- return [children];
11
- }
12
- if (typeof children === "number") {
13
- return [String(children)];
14
- }
15
- if (isChildrenArray(children)) {
16
- const normalized = await Promise.all(children.map((child) => normalizeChildren(child)));
17
- return normalized.flat();
18
- }
19
- // It's a PromptElement (or a promise for one)
20
- return [await children];
21
- }
22
- function isChildrenArray(value) {
23
- return Array.isArray(value);
24
- }
25
- // Fragment: just returns children (inlined into parent)
26
- export const Fragment = Symbol.for("cria.fragment");
27
- // jsx: called by TypeScript for single child
28
- export async function jsx(type, props) {
29
- const children = await normalizeChildren(props.children);
30
- if (type === Fragment) {
31
- // Fragment returns a wrapper element that just holds children
32
- return { priority: 0, children };
33
- }
34
- return await type({ ...props, children });
35
- }
36
- // jsxs: called by TypeScript for multiple children (same behavior)
37
- export async function jsxs(type, props) {
38
- return await jsx(type, props);
39
- }
40
- //# sourceMappingURL=jsx-runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsx-runtime.js","sourceRoot":"","sources":["../../src/jsx/jsx-runtime.ts"],"names":[],"mappings":"AA+BA,gFAAgF;AAChF,KAAK,UAAU,iBAAiB,CAC9B,QAA2B;IAE3B,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,QAAQ,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,GAAG,CAClC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAClD,CAAC;QACF,OAAO,UAAU,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IAED,8CAA8C;IAC9C,OAAO,CAAC,MAAM,QAAQ,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,eAAe,CAAC,KAAY;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,wDAAwD;AACxD,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAEpD,6CAA6C;AAC7C,MAAM,CAAC,KAAK,UAAU,GAAG,CACvB,IAAmC,EACnC,KAAY;IAEZ,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEzD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtB,8DAA8D;QAC9D,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnC,CAAC;IAED,OAAO,MAAM,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,mEAAmE;AACnE,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,IAAmC,EACnC,KAAY;IAEZ,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAChC,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { PromptRenderer } from "../types";
2
- export declare const markdownRenderer: PromptRenderer<string>;
3
- //# sourceMappingURL=markdown.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/renderers/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiC,cAAc,EAAE,MAAM,UAAU,CAAC;AAG9E,eAAO,MAAM,gBAAgB,EAAE,cAAc,CAAC,MAAM,CAKnD,CAAC"}
@@ -1,43 +0,0 @@
1
- import { safeStringify } from "./shared";
2
- export const markdownRenderer = {
3
- name: "markdown",
4
- tokenString: (element) => renderToMarkdown(element),
5
- render: (element) => renderToMarkdown(element),
6
- empty: () => "",
7
- };
8
- const ROLE_LABELS = {
9
- system: "System",
10
- user: "User",
11
- assistant: "Assistant",
12
- };
13
- function renderToMarkdown(element) {
14
- switch (element.kind) {
15
- case "message": {
16
- const content = renderChildrenToMarkdown(element.children).trimEnd();
17
- const label = ROLE_LABELS[element.role] ?? element.role;
18
- return `${label}: ${content}\n\n`;
19
- }
20
- case "reasoning": {
21
- return `<thinking>\n${element.text}\n</thinking>\n`;
22
- }
23
- case "tool-call": {
24
- const inputText = safeStringify(element.input, true);
25
- return `<tool_call name="${element.toolName}">\n${inputText}\n</tool_call>\n`;
26
- }
27
- case "tool-result": {
28
- const outputText = safeStringify(element.output, true);
29
- return `<tool_result name="${element.toolName}">\n${outputText}\n</tool_result>\n`;
30
- }
31
- default: {
32
- return renderChildrenToMarkdown(element.children);
33
- }
34
- }
35
- }
36
- function renderChildrenToMarkdown(children) {
37
- let result = "";
38
- for (const child of children) {
39
- result += typeof child === "string" ? child : renderToMarkdown(child);
40
- }
41
- return result;
42
- }
43
- //# sourceMappingURL=markdown.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/renderers/markdown.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,CAAC,MAAM,gBAAgB,GAA2B;IACtD,IAAI,EAAE,UAAU;IAChB,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC;IACnD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC;IAC9C,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE;CAChB,CAAC;AAEF,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,WAAW;CACvB,CAAC;AAEF,SAAS,gBAAgB,CAAC,OA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type { PromptChildren, PromptElement } from "../types";
2
- /**
3
- * Semantic representation of prompt content parts.
4
- * Used by renderers to convert prompt trees into provider-specific formats.
5
- */
6
- export type SemanticPart = {
7
- type: "text";
8
- text: string;
9
- } | {
10
- type: "reasoning";
11
- text: string;
12
- } | {
13
- type: "tool-call";
14
- toolCallId: string;
15
- toolName: string;
16
- input: unknown;
17
- } | {
18
- type: "tool-result";
19
- toolCallId: string;
20
- toolName: string;
21
- output: unknown;
22
- };
23
- export type ToolCallPart = Extract<SemanticPart, {
24
- type: "tool-call";
25
- }>;
26
- export type ToolResultPart = Extract<SemanticPart, {
27
- type: "tool-result";
28
- }>;
29
- export type TextPart = Extract<SemanticPart, {
30
- type: "text";
31
- }>;
32
- export type ReasoningPart = Extract<SemanticPart, {
33
- type: "reasoning";
34
- }>;
35
- export type MessageElement = Extract<PromptElement, {
36
- kind: "message";
37
- }>;
38
- /**
39
- * Collect all message nodes from the prompt tree.
40
- */
41
- export declare function collectMessageNodes(element: PromptElement, acc?: MessageElement[]): MessageElement[];
42
- /**
43
- * Extract semantic parts from prompt children.
44
- */
45
- export declare function collectSemanticParts(children: PromptChildren): SemanticPart[];
46
- /**
47
- * Extract semantic parts from a single prompt element.
48
- */
49
- export declare function semanticPartsFromElement(element: PromptElement): SemanticPart[];
50
- /**
51
- * Coalesce adjacent text parts into single parts.
52
- */
53
- export declare function coalesceTextParts(parts: readonly SemanticPart[]): SemanticPart[];
54
- /**
55
- * Safely stringify a value to JSON string.
56
- * Returns string values directly, handles undefined, and catches JSON errors.
57
- *
58
- * @param value - The value to stringify
59
- * @param pretty - If true, format with 2-space indentation (default: false)
60
- */
61
- export declare function safeStringify(value: unknown, pretty?: boolean): string;
62
- /**
63
- * Categorized parts from a semantic parts list.
64
- */
65
- export interface CategorizedParts {
66
- textParts: TextPart[];
67
- toolCallParts: ToolCallPart[];
68
- toolResultParts: ToolResultPart[];
69
- reasoningParts: ReasoningPart[];
70
- }
71
- /**
72
- * Categorize semantic parts by type for easier processing.
73
- */
74
- export declare function categorizeParts(parts: readonly SemanticPart[]): CategorizedParts;
75
- /**
76
- * Extract text content from semantic parts.
77
- * Optionally wraps reasoning parts in thinking tags.
78
- */
79
- export declare function partsToText(parts: readonly SemanticPart[], options?: {
80
- wrapReasoning?: boolean;
81
- }): string;
82
- //# sourceMappingURL=shared.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/renderers/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC3E;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEN,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AACxE,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AAC5E,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAC/D,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CA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