la-machina-engine 0.7.2 → 0.7.3

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.cts CHANGED
@@ -2020,11 +2020,19 @@ interface RunOptions {
2020
2020
  */
2021
2021
  readonly outputFormat?: 'text' | 'json' | undefined;
2022
2022
  /**
2023
- * Zod schema for structured output. Only used when outputFormat is 'json'.
2024
- * Injected into system prompt as JSON Schema description, used to
2025
- * validate the model's response. If validation fails, retries once.
2023
+ * Schema for structured output. Only used when outputFormat is 'json'.
2024
+ * Injected into the system prompt and (for Zod schemas) used to
2025
+ * validate the model's response.
2026
+ *
2027
+ * Two shapes accepted:
2028
+ * - A Zod schema — strictly validated via `safeParse`; retries
2029
+ * once on failure with a corrective prompt.
2030
+ * - A plain JSON Schema object — used verbatim in the prompt; no
2031
+ * server-side strict validation (callers wanting that should
2032
+ * pass Zod). This shape is what serialized workflow definitions
2033
+ * (e.g. nikaido) carry, since they can't embed Zod instances.
2026
2034
  */
2027
- readonly outputSchema?: zod.ZodTypeAny | undefined;
2035
+ readonly outputSchema?: zod.ZodTypeAny | Record<string, unknown> | undefined;
2028
2036
  /**
2029
2037
  * Per-run skill override (Plan 017). When present, the engine IGNORES
2030
2038
  * `config.skills.autoload` + `config.skills.path` and uses this list
@@ -3047,11 +3055,21 @@ declare const defaultToolResultSummarizer: ToolResultSummarizerV1;
3047
3055
  * All pure JS — no `node:` imports, Workers-compatible.
3048
3056
  */
3049
3057
 
3058
+ /**
3059
+ * Schema users can supply for structured output. Either:
3060
+ * - a Zod schema (typed validation, runs `safeParse` post-parse), or
3061
+ * - a plain JSON Schema object (used verbatim in the system prompt;
3062
+ * no strict server-side validation in v1).
3063
+ *
3064
+ * Workflow definitions stored as JSON (e.g. nikaido) can only carry
3065
+ * the JSON Schema variant; native TS callers may use either.
3066
+ */
3067
+ type OutputSchema = ZodTypeAny | Record<string, unknown>;
3050
3068
  /**
3051
3069
  * Build the output format section to append to the system prompt.
3052
3070
  * Called when outputFormat is 'json'.
3053
3071
  */
3054
- declare function buildSchemaPrompt(schema?: ZodTypeAny): string;
3072
+ declare function buildSchemaPrompt(schema?: OutputSchema): string;
3055
3073
  interface ParseResult {
3056
3074
  readonly ok: boolean;
3057
3075
  readonly value?: unknown;
@@ -3065,10 +3083,14 @@ interface ParseResult {
3065
3083
  */
3066
3084
  declare function tryParseJSON(text: string): ParseResult;
3067
3085
  /**
3068
- * Validate parsed JSON against a Zod schema.
3069
- * Returns the validated data or an error message.
3086
+ * Validate parsed JSON against a schema.
3087
+ *
3088
+ * Zod schemas get strict `safeParse` validation. Plain JSON Schema
3089
+ * objects are NOT strictly validated (skipping ajv keeps the bundle
3090
+ * small for Workers); the prompt-injected schema is the contract and
3091
+ * the caller can validate downstream if needed.
3070
3092
  */
3071
- declare function validateOutput(value: unknown, schema: ZodTypeAny): {
3093
+ declare function validateOutput(value: unknown, schema: OutputSchema): {
3072
3094
  ok: true;
3073
3095
  data: unknown;
3074
3096
  } | {
package/dist/index.d.ts CHANGED
@@ -2020,11 +2020,19 @@ interface RunOptions {
2020
2020
  */
2021
2021
  readonly outputFormat?: 'text' | 'json' | undefined;
2022
2022
  /**
2023
- * Zod schema for structured output. Only used when outputFormat is 'json'.
2024
- * Injected into system prompt as JSON Schema description, used to
2025
- * validate the model's response. If validation fails, retries once.
2023
+ * Schema for structured output. Only used when outputFormat is 'json'.
2024
+ * Injected into the system prompt and (for Zod schemas) used to
2025
+ * validate the model's response.
2026
+ *
2027
+ * Two shapes accepted:
2028
+ * - A Zod schema — strictly validated via `safeParse`; retries
2029
+ * once on failure with a corrective prompt.
2030
+ * - A plain JSON Schema object — used verbatim in the prompt; no
2031
+ * server-side strict validation (callers wanting that should
2032
+ * pass Zod). This shape is what serialized workflow definitions
2033
+ * (e.g. nikaido) carry, since they can't embed Zod instances.
2026
2034
  */
2027
- readonly outputSchema?: zod.ZodTypeAny | undefined;
2035
+ readonly outputSchema?: zod.ZodTypeAny | Record<string, unknown> | undefined;
2028
2036
  /**
2029
2037
  * Per-run skill override (Plan 017). When present, the engine IGNORES
2030
2038
  * `config.skills.autoload` + `config.skills.path` and uses this list
@@ -3047,11 +3055,21 @@ declare const defaultToolResultSummarizer: ToolResultSummarizerV1;
3047
3055
  * All pure JS — no `node:` imports, Workers-compatible.
3048
3056
  */
3049
3057
 
3058
+ /**
3059
+ * Schema users can supply for structured output. Either:
3060
+ * - a Zod schema (typed validation, runs `safeParse` post-parse), or
3061
+ * - a plain JSON Schema object (used verbatim in the system prompt;
3062
+ * no strict server-side validation in v1).
3063
+ *
3064
+ * Workflow definitions stored as JSON (e.g. nikaido) can only carry
3065
+ * the JSON Schema variant; native TS callers may use either.
3066
+ */
3067
+ type OutputSchema = ZodTypeAny | Record<string, unknown>;
3050
3068
  /**
3051
3069
  * Build the output format section to append to the system prompt.
3052
3070
  * Called when outputFormat is 'json'.
3053
3071
  */
3054
- declare function buildSchemaPrompt(schema?: ZodTypeAny): string;
3072
+ declare function buildSchemaPrompt(schema?: OutputSchema): string;
3055
3073
  interface ParseResult {
3056
3074
  readonly ok: boolean;
3057
3075
  readonly value?: unknown;
@@ -3065,10 +3083,14 @@ interface ParseResult {
3065
3083
  */
3066
3084
  declare function tryParseJSON(text: string): ParseResult;
3067
3085
  /**
3068
- * Validate parsed JSON against a Zod schema.
3069
- * Returns the validated data or an error message.
3086
+ * Validate parsed JSON against a schema.
3087
+ *
3088
+ * Zod schemas get strict `safeParse` validation. Plain JSON Schema
3089
+ * objects are NOT strictly validated (skipping ajv keeps the bundle
3090
+ * small for Workers); the prompt-injected schema is the contract and
3091
+ * the caller can validate downstream if needed.
3070
3092
  */
3071
- declare function validateOutput(value: unknown, schema: ZodTypeAny): {
3093
+ declare function validateOutput(value: unknown, schema: OutputSchema): {
3072
3094
  ok: true;
3073
3095
  data: unknown;
3074
3096
  } | {
package/dist/index.js CHANGED
@@ -7767,6 +7767,9 @@ async function collectSkills(storage, skillsDir) {
7767
7767
  // src/engine/jsonOutput.ts
7768
7768
  init_esm_shims();
7769
7769
  import { zodToJsonSchema as zodToJsonSchema2 } from "zod-to-json-schema";
7770
+ function isZodSchema(s) {
7771
+ return s !== null && typeof s === "object" && "_def" in s && typeof s.safeParse === "function";
7772
+ }
7770
7773
  function buildSchemaPrompt(schema) {
7771
7774
  const lines = [
7772
7775
  "# Output Format",
@@ -7776,11 +7779,18 @@ function buildSchemaPrompt(schema) {
7776
7779
  "Do NOT wrap in ```json ... ```. Just raw JSON."
7777
7780
  ];
7778
7781
  if (schema) {
7779
- const jsonSchema2 = zodToJsonSchema2(schema, {
7780
- target: "jsonSchema7",
7781
- $refStrategy: "none"
7782
- });
7783
- const { $schema: _, ...clean } = jsonSchema2;
7782
+ let clean;
7783
+ if (isZodSchema(schema)) {
7784
+ const jsonSchema2 = zodToJsonSchema2(schema, {
7785
+ target: "jsonSchema7",
7786
+ $refStrategy: "none"
7787
+ });
7788
+ const { $schema: _z, ...rest } = jsonSchema2;
7789
+ clean = rest;
7790
+ } else {
7791
+ const { $schema: _j, ...rest } = schema;
7792
+ clean = rest;
7793
+ }
7784
7794
  lines.push("", "The JSON MUST conform to this schema:", JSON.stringify(clean, null, 2));
7785
7795
  } else {
7786
7796
  lines.push("", "Return a JSON object with the relevant data.");
@@ -7816,6 +7826,9 @@ function tryParseJSON2(text2) {
7816
7826
  return { ok: false, error: "No valid JSON found in response" };
7817
7827
  }
7818
7828
  function validateOutput(value, schema) {
7829
+ if (!isZodSchema(schema)) {
7830
+ return { ok: true, data: value };
7831
+ }
7819
7832
  const result = schema.safeParse(value);
7820
7833
  if (result.success) {
7821
7834
  return { ok: true, data: result.data };