@prompty/core 2.0.0-alpha.3 → 2.0.0-alpha.4

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/index.d.ts CHANGED
@@ -788,7 +788,7 @@ declare class Model {
788
788
  */
789
789
  id: string;
790
790
  /**
791
- * The provider of the model (e.g., 'openai', 'azure', 'anthropic')
791
+ * The provider of the model (e.g., 'openai', 'foundry', 'anthropic')
792
792
  */
793
793
  provider?: string | undefined;
794
794
  /**
@@ -1088,7 +1088,7 @@ declare class ObjectProperty extends Property {
1088
1088
  * Template format definition
1089
1089
  *
1090
1090
  */
1091
- declare class Format {
1091
+ declare class FormatConfig {
1092
1092
  /**
1093
1093
  * The shorthand property name for this type, if any.
1094
1094
  */
@@ -1106,56 +1106,56 @@ declare class Format {
1106
1106
  */
1107
1107
  options?: Record<string, unknown> | undefined;
1108
1108
  /**
1109
- * Initializes a new instance of Format.
1109
+ * Initializes a new instance of FormatConfig.
1110
1110
  */
1111
- constructor(init?: Partial<Format>);
1111
+ constructor(init?: Partial<FormatConfig>);
1112
1112
  /**
1113
- * Load a Format instance from a dictionary.
1113
+ * Load a FormatConfig instance from a dictionary.
1114
1114
  * @param data - The dictionary containing the data.
1115
1115
  * @param context - Optional context with pre/post processing callbacks.
1116
- * @returns The loaded Format instance.
1116
+ * @returns The loaded FormatConfig instance.
1117
1117
  */
1118
- static load(data: Record<string, unknown>, context?: LoadContext): Format;
1118
+ static load(data: Record<string, unknown>, context?: LoadContext): FormatConfig;
1119
1119
  /**
1120
- * Save the Format instance to a dictionary.
1120
+ * Save the FormatConfig instance to a dictionary.
1121
1121
  * @param context - Optional context with pre/post processing callbacks.
1122
1122
  * @returns The dictionary representation of this instance.
1123
1123
  */
1124
1124
  save(context?: SaveContext): Record<string, unknown>;
1125
1125
  /**
1126
- * Convert the Format instance to a YAML string.
1126
+ * Convert the FormatConfig instance to a YAML string.
1127
1127
  * @param context - Optional context with pre/post processing callbacks.
1128
1128
  * @returns The YAML string representation of this instance.
1129
1129
  */
1130
1130
  toYaml(context?: SaveContext): string;
1131
1131
  /**
1132
- * Convert the Format instance to a JSON string.
1132
+ * Convert the FormatConfig instance to a JSON string.
1133
1133
  * @param context - Optional context with pre/post processing callbacks.
1134
1134
  * @param indent - Number of spaces for indentation. Defaults to 2.
1135
1135
  * @returns The JSON string representation of this instance.
1136
1136
  */
1137
1137
  toJson(context?: SaveContext, indent?: number): string;
1138
1138
  /**
1139
- * Load a Format instance from a JSON string.
1139
+ * Load a FormatConfig instance from a JSON string.
1140
1140
  * @param json - The JSON string to parse.
1141
1141
  * @param context - Optional context with pre/post processing callbacks.
1142
- * @returns The loaded Format instance.
1142
+ * @returns The loaded FormatConfig instance.
1143
1143
  */
1144
- static fromJson(json: string, context?: LoadContext): Format;
1144
+ static fromJson(json: string, context?: LoadContext): FormatConfig;
1145
1145
  /**
1146
- * Load a Format instance from a YAML string.
1146
+ * Load a FormatConfig instance from a YAML string.
1147
1147
  * @param yaml - The YAML string to parse.
1148
1148
  * @param context - Optional context with pre/post processing callbacks.
1149
- * @returns The loaded Format instance.
1149
+ * @returns The loaded FormatConfig instance.
1150
1150
  */
1151
- static fromYaml(yaml: string, context?: LoadContext): Format;
1151
+ static fromYaml(yaml: string, context?: LoadContext): FormatConfig;
1152
1152
  }
1153
1153
 
1154
1154
  /**
1155
1155
  * Template parser definition
1156
1156
  *
1157
1157
  */
1158
- declare class Parser$1 {
1158
+ declare class ParserConfig {
1159
1159
  /**
1160
1160
  * The shorthand property name for this type, if any.
1161
1161
  */
@@ -1169,49 +1169,49 @@ declare class Parser$1 {
1169
1169
  */
1170
1170
  options?: Record<string, unknown> | undefined;
1171
1171
  /**
1172
- * Initializes a new instance of Parser.
1172
+ * Initializes a new instance of ParserConfig.
1173
1173
  */
1174
- constructor(init?: Partial<Parser$1>);
1174
+ constructor(init?: Partial<ParserConfig>);
1175
1175
  /**
1176
- * Load a Parser instance from a dictionary.
1176
+ * Load a ParserConfig instance from a dictionary.
1177
1177
  * @param data - The dictionary containing the data.
1178
1178
  * @param context - Optional context with pre/post processing callbacks.
1179
- * @returns The loaded Parser instance.
1179
+ * @returns The loaded ParserConfig instance.
1180
1180
  */
1181
- static load(data: Record<string, unknown>, context?: LoadContext): Parser$1;
1181
+ static load(data: Record<string, unknown>, context?: LoadContext): ParserConfig;
1182
1182
  /**
1183
- * Save the Parser instance to a dictionary.
1183
+ * Save the ParserConfig instance to a dictionary.
1184
1184
  * @param context - Optional context with pre/post processing callbacks.
1185
1185
  * @returns The dictionary representation of this instance.
1186
1186
  */
1187
1187
  save(context?: SaveContext): Record<string, unknown>;
1188
1188
  /**
1189
- * Convert the Parser instance to a YAML string.
1189
+ * Convert the ParserConfig instance to a YAML string.
1190
1190
  * @param context - Optional context with pre/post processing callbacks.
1191
1191
  * @returns The YAML string representation of this instance.
1192
1192
  */
1193
1193
  toYaml(context?: SaveContext): string;
1194
1194
  /**
1195
- * Convert the Parser instance to a JSON string.
1195
+ * Convert the ParserConfig instance to a JSON string.
1196
1196
  * @param context - Optional context with pre/post processing callbacks.
1197
1197
  * @param indent - Number of spaces for indentation. Defaults to 2.
1198
1198
  * @returns The JSON string representation of this instance.
1199
1199
  */
1200
1200
  toJson(context?: SaveContext, indent?: number): string;
1201
1201
  /**
1202
- * Load a Parser instance from a JSON string.
1202
+ * Load a ParserConfig instance from a JSON string.
1203
1203
  * @param json - The JSON string to parse.
1204
1204
  * @param context - Optional context with pre/post processing callbacks.
1205
- * @returns The loaded Parser instance.
1205
+ * @returns The loaded ParserConfig instance.
1206
1206
  */
1207
- static fromJson(json: string, context?: LoadContext): Parser$1;
1207
+ static fromJson(json: string, context?: LoadContext): ParserConfig;
1208
1208
  /**
1209
- * Load a Parser instance from a YAML string.
1209
+ * Load a ParserConfig instance from a YAML string.
1210
1210
  * @param yaml - The YAML string to parse.
1211
1211
  * @param context - Optional context with pre/post processing callbacks.
1212
- * @returns The loaded Parser instance.
1212
+ * @returns The loaded ParserConfig instance.
1213
1213
  */
1214
- static fromYaml(yaml: string, context?: LoadContext): Parser$1;
1214
+ static fromYaml(yaml: string, context?: LoadContext): ParserConfig;
1215
1215
  }
1216
1216
 
1217
1217
  /**
@@ -1233,11 +1233,11 @@ declare class Template {
1233
1233
  /**
1234
1234
  * Template rendering engine used for slot filling prompts (e.g., mustache, jinja2)
1235
1235
  */
1236
- format: Format;
1236
+ format: FormatConfig;
1237
1237
  /**
1238
1238
  * Parser used to process the rendered template into API-compatible format
1239
1239
  */
1240
- parser: Parser$1;
1240
+ parser: ParserConfig;
1241
1241
  /**
1242
1242
  * Initializes a new instance of Template.
1243
1243
  */
@@ -1801,6 +1801,75 @@ declare class OpenApiTool extends Tool {
1801
1801
  */
1802
1802
  static fromYaml(yaml: string, context?: LoadContext): OpenApiTool;
1803
1803
  }
1804
+ /**
1805
+ * A tool that references another .prompty file to be invoked as a tool.
1806
+ *
1807
+ * In `single` mode, the child prompty is executed with a single LLM call.
1808
+ * In `agentic` mode, the child prompty runs a full agent loop with its own tools.
1809
+ *
1810
+ */
1811
+ declare class PromptyTool extends Tool {
1812
+ /**
1813
+ * The shorthand property name for this type, if any.
1814
+ */
1815
+ static readonly shorthandProperty: string | undefined;
1816
+ /**
1817
+ * The kind identifier for prompty tools
1818
+ */
1819
+ kind: string;
1820
+ /**
1821
+ * Path to the child .prompty file, relative to the parent
1822
+ */
1823
+ path: string;
1824
+ /**
1825
+ * Execution mode: 'single' for one LLM call, 'agentic' for full agent loop
1826
+ */
1827
+ mode: string;
1828
+ /**
1829
+ * Initializes a new instance of PromptyTool.
1830
+ */
1831
+ constructor(init?: Partial<PromptyTool>);
1832
+ /**
1833
+ * Load a PromptyTool instance from a dictionary.
1834
+ * @param data - The dictionary containing the data.
1835
+ * @param context - Optional context with pre/post processing callbacks.
1836
+ * @returns The loaded PromptyTool instance.
1837
+ */
1838
+ static load(data: Record<string, unknown>, context?: LoadContext): PromptyTool;
1839
+ /**
1840
+ * Save the PromptyTool instance to a dictionary.
1841
+ * @param context - Optional context with pre/post processing callbacks.
1842
+ * @returns The dictionary representation of this instance.
1843
+ */
1844
+ save(context?: SaveContext): Record<string, unknown>;
1845
+ /**
1846
+ * Convert the PromptyTool instance to a YAML string.
1847
+ * @param context - Optional context with pre/post processing callbacks.
1848
+ * @returns The YAML string representation of this instance.
1849
+ */
1850
+ toYaml(context?: SaveContext): string;
1851
+ /**
1852
+ * Convert the PromptyTool instance to a JSON string.
1853
+ * @param context - Optional context with pre/post processing callbacks.
1854
+ * @param indent - Number of spaces for indentation. Defaults to 2.
1855
+ * @returns The JSON string representation of this instance.
1856
+ */
1857
+ toJson(context?: SaveContext, indent?: number): string;
1858
+ /**
1859
+ * Load a PromptyTool instance from a JSON string.
1860
+ * @param json - The JSON string to parse.
1861
+ * @param context - Optional context with pre/post processing callbacks.
1862
+ * @returns The loaded PromptyTool instance.
1863
+ */
1864
+ static fromJson(json: string, context?: LoadContext): PromptyTool;
1865
+ /**
1866
+ * Load a PromptyTool instance from a YAML string.
1867
+ * @param yaml - The YAML string to parse.
1868
+ * @param context - Optional context with pre/post processing callbacks.
1869
+ * @returns The loaded PromptyTool instance.
1870
+ */
1871
+ static fromYaml(yaml: string, context?: LoadContext): PromptyTool;
1872
+ }
1804
1873
 
1805
1874
  /**
1806
1875
  * A Prompty is a markdown file format for LLM prompts. The frontmatter defines
@@ -2125,6 +2194,13 @@ declare function run(agent: Prompty, messages: Message[], options?: {
2125
2194
  declare function execute(prompt: string | Prompty, inputs?: Record<string, unknown>, options?: {
2126
2195
  raw?: boolean;
2127
2196
  }): Promise<unknown>;
2197
+ /**
2198
+ * Resolve tool bindings: inject values from parentInputs into tool arguments.
2199
+ *
2200
+ * For each binding on the matched tool, looks up `binding.input` in parentInputs
2201
+ * and sets `args[binding.name]` to that value. Returns a new args object.
2202
+ */
2203
+ declare function resolveBindings(agent: Prompty, toolName: string, args: Record<string, unknown>, parentInputs?: Record<string, unknown>): Record<string, unknown>;
2128
2204
  /**
2129
2205
  * Run a prompt with automatic tool-call execution loop.
2130
2206
  */
@@ -2162,9 +2238,11 @@ declare class MustacheRenderer implements Renderer {
2162
2238
  /**
2163
2239
  * Prompty chat parser — splits rendered text into abstract messages.
2164
2240
  *
2165
- * Recognizes role markers (`system:`, `user:`, `assistant:`, `developer:`)
2166
- * and inline markdown images. Supports nonce-based sanitization when
2167
- * `Format.strict` is enabled.
2241
+ * Recognizes role markers (`system:`, `user:`, `assistant:`, `developer:`).
2242
+ * Supports nonce-based sanitization when `FormatConfig.strict` is enabled.
2243
+ *
2244
+ * Images should be passed via `kind: image` input properties rather than
2245
+ * inline markdown syntax. Inline `![alt](url)` is preserved as literal text.
2168
2246
  *
2169
2247
  * @module
2170
2248
  */
@@ -2176,8 +2254,6 @@ declare class PromptyChatParser implements Parser {
2176
2254
  private parseMessages;
2177
2255
  private buildMessage;
2178
2256
  private parseAttrs;
2179
- private parseContent;
2180
- private resolveImage;
2181
2257
  }
2182
2258
 
2183
2259
  /**
@@ -2324,4 +2400,74 @@ declare class PromptyTracer {
2324
2400
  private sanitizeName;
2325
2401
  }
2326
2402
 
2327
- export { Prompty as AgentDefinition, AnonymousConnection, ApiKeyConnection, ArrayProperty, type AudioPart, Binding, Connection, type ContentPart, CustomTool, type Executor, type FilePart, Format, FoundryConnection, FunctionTool, type ImagePart, InvokerError, LoadContext, McpApprovalMode, McpTool, Message, Model, ModelOptions, MustacheRenderer, NunjucksRenderer, OAuthConnection, ObjectProperty, OpenApiTool, type Parser, type Processor, Prompty as PromptAgent, Prompty, PromptyChatParser, PromptyStream, PromptyTracer, Property, RICH_KINDS, ROLES, ReferenceConnection, RemoteConnection, type Renderer, type Role, SaveContext, Parser$1 as SchemaParser, type SpanEmitter, Template, type TextPart, ThreadMarker, Tool, type ToolCall, Tracer, type TracerBackend, type TracerFactory, clearCache, clearConnections, consoleTracer, dictContentToPart, dictToMessage, execute, executeAgent, getConnection, getExecutor, getParser, getProcessor, getRenderer, load, parse, prepare, process, registerConnection, registerExecutor, registerParser, registerProcessor, registerRenderer, render, run, runAgent, sanitizeValue, text, textMessage, toSerializable, trace, traceMethod, traceSpan, validateInputs };
2403
+ /**
2404
+ * OpenTelemetry trace backend for Prompty.
2405
+ *
2406
+ * Plugs into the Tracer registry and emits OTel spans with structured
2407
+ * attributes. Requires `@opentelemetry/api` — install as a peer dependency.
2408
+ *
2409
+ * Usage:
2410
+ * ```typescript
2411
+ * import { Tracer } from "@prompty/core";
2412
+ * import { otelTracer } from "@prompty/core/tracing/otel";
2413
+ * import * as otelApi from "@opentelemetry/api";
2414
+ *
2415
+ * Tracer.add("otel", otelTracer(otelApi));
2416
+ * // or with custom tracer name:
2417
+ * Tracer.add("otel", otelTracer(otelApi, { tracerName: "my.service" }));
2418
+ * ```
2419
+ *
2420
+ * @module
2421
+ */
2422
+
2423
+ /** The subset of `@opentelemetry/api` needed by this module. */
2424
+ interface OtelApi {
2425
+ trace: {
2426
+ getTracer(name: string): {
2427
+ startSpan(name: string): OtelSpan;
2428
+ };
2429
+ setSpan(context: unknown, span: OtelSpan): unknown;
2430
+ };
2431
+ context: {
2432
+ active(): unknown;
2433
+ with<T>(context: unknown, fn: () => T): T;
2434
+ };
2435
+ SpanStatusCode: {
2436
+ OK: number;
2437
+ ERROR: number;
2438
+ };
2439
+ }
2440
+ interface OtelSpan {
2441
+ setAttribute(key: string, value: string | number | boolean): void;
2442
+ setStatus(status: {
2443
+ code: number;
2444
+ message?: string;
2445
+ }): void;
2446
+ recordException(exception: Error): void;
2447
+ end(): void;
2448
+ }
2449
+ /** Options for {@link otelTracer}. */
2450
+ interface OtelTracerOptions {
2451
+ /** OTel tracer name. Defaults to `"prompty"`. */
2452
+ tracerName?: string;
2453
+ }
2454
+ /**
2455
+ * Create an OTel trace backend compatible with `Tracer.add()`.
2456
+ *
2457
+ * Each call to the returned factory starts a new OTel span named after the
2458
+ * Prompty pipeline step. The backend receives `(key, value)` events and
2459
+ * sets them as span attributes. On `__end__`, the span is ended.
2460
+ *
2461
+ * Special handling:
2462
+ * - `error` key sets `StatusCode.ERROR` and records the exception.
2463
+ * - `__end__` key ends the span.
2464
+ * - All other values are serialized and expanded into dotted attributes.
2465
+ *
2466
+ * @param api - The `@opentelemetry/api` module. Pass `require("@opentelemetry/api")`
2467
+ * or the result of `await import("@opentelemetry/api")`.
2468
+ * @param options - Optional configuration.
2469
+ * @returns A `TracerFactory` suitable for `Tracer.add()`.
2470
+ */
2471
+ declare function otelTracer(api: OtelApi, options?: OtelTracerOptions): TracerFactory;
2472
+
2473
+ export { Prompty as AgentDefinition, AnonymousConnection, ApiKeyConnection, ArrayProperty, type AudioPart, Binding, Connection, type ContentPart, CustomTool, type Executor, type FilePart, FormatConfig, FoundryConnection, FunctionTool, type ImagePart, InvokerError, LoadContext, McpApprovalMode, McpTool, Message, Model, ModelOptions, MustacheRenderer, NunjucksRenderer, OAuthConnection, ObjectProperty, OpenApiTool, type OtelApi, type OtelTracerOptions, type Parser, ParserConfig, type Processor, Prompty as PromptAgent, Prompty, PromptyChatParser, PromptyStream, PromptyTool, PromptyTracer, Property, RICH_KINDS, ROLES, ReferenceConnection, RemoteConnection, type Renderer, type Role, SaveContext, type SpanEmitter, Template, type TextPart, ThreadMarker, Tool, type ToolCall, Tracer, type TracerBackend, type TracerFactory, clearCache, clearConnections, consoleTracer, dictContentToPart, dictToMessage, execute, executeAgent, getConnection, getExecutor, getParser, getProcessor, getRenderer, load, otelTracer, parse, prepare, process, registerConnection, registerExecutor, registerParser, registerProcessor, registerRenderer, render, resolveBindings, run, runAgent, sanitizeValue, text, textMessage, toSerializable, trace, traceMethod, traceSpan, validateInputs };