@keystrokehq/keystroke 0.1.91 → 0.1.92

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 (27) hide show
  1. package/dist/agent-types.d.cts +2 -2
  2. package/dist/agent-types.d.mts +2 -2
  3. package/dist/agent.cjs +78 -8
  4. package/dist/agent.cjs.map +1 -1
  5. package/dist/agent.d.cts +3 -3
  6. package/dist/agent.d.mts +3 -3
  7. package/dist/agent.mjs +78 -8
  8. package/dist/agent.mjs.map +1 -1
  9. package/dist/{index-BKn5COTH.d.cts → index-BAERW4m3.d.mts} +4 -4
  10. package/dist/{index-BKn5COTH.d.cts.map → index-BAERW4m3.d.mts.map} +1 -1
  11. package/dist/{index-CjWSlYyq.d.mts → index-BNptJCCC.d.mts} +4 -4
  12. package/dist/{index-C61TSfQB.d.cts.map → index-BNptJCCC.d.mts.map} +1 -1
  13. package/dist/{index-DHfxB8DH.d.mts → index-C614Tmd_.d.cts} +4 -4
  14. package/dist/{index-DHfxB8DH.d.mts.map → index-C614Tmd_.d.cts.map} +1 -1
  15. package/dist/{index-skjc11Qf.d.mts → index-CIz44roq.d.mts} +2 -2
  16. package/dist/{index-skjc11Qf.d.mts.map → index-CIz44roq.d.mts.map} +1 -1
  17. package/dist/{index-BowkmvyU.d.cts → index-DFkYFZEw.d.cts} +2 -2
  18. package/dist/{index-BowkmvyU.d.cts.map → index-DFkYFZEw.d.cts.map} +1 -1
  19. package/dist/{index-C61TSfQB.d.cts → index-N9Wzbx7A.d.cts} +4 -4
  20. package/dist/{index-CjWSlYyq.d.mts.map → index-N9Wzbx7A.d.cts.map} +1 -1
  21. package/dist/{schemas-lSbMfQRy-D7NW7SCj.d.mts → schemas-lSbMfQRy-CIfs2xv6.d.mts} +2 -2
  22. package/dist/{schemas-lSbMfQRy-D7NW7SCj.d.mts.map → schemas-lSbMfQRy-CIfs2xv6.d.mts.map} +1 -1
  23. package/dist/{schemas-lSbMfQRy-DdpE4_dC.d.cts → schemas-lSbMfQRy-YsonGA_B.d.cts} +2 -2
  24. package/dist/{schemas-lSbMfQRy-DdpE4_dC.d.cts.map → schemas-lSbMfQRy-YsonGA_B.d.cts.map} +1 -1
  25. package/dist/trigger.d.cts +1 -1
  26. package/dist/trigger.d.mts +1 -1
  27. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
1
  import { i as AgentToolUpdateCallback, n as AgentToolParameters, r as AgentToolResult, t as AgentTool } from "./index-dDHyyZ6y.cjs";
2
- import { a as UIMessage } from "./index-BKn5COTH.cjs";
3
- import { c as AgentStreamEvent, i as AgentMessage, p as ThinkingLevel, s as AgentStepStartEvent, t as AgentContextCompactedEvent } from "./schemas-lSbMfQRy-DdpE4_dC.cjs";
2
+ import { a as UIMessage } from "./index-C614Tmd_.cjs";
3
+ import { c as AgentStreamEvent, i as AgentMessage, p as ThinkingLevel, s as AgentStepStartEvent, t as AgentContextCompactedEvent } from "./schemas-lSbMfQRy-YsonGA_B.cjs";
4
4
  export { AgentContextCompactedEvent, AgentMessage, AgentStepStartEvent, AgentStreamEvent, type AgentTool, type AgentToolParameters, type AgentToolResult, type AgentToolUpdateCallback, ThinkingLevel, type UIMessage };
@@ -1,4 +1,4 @@
1
1
  import { i as AgentToolUpdateCallback, n as AgentToolParameters, r as AgentToolResult, t as AgentTool } from "./index-dDHyyZ6y.mjs";
2
- import { a as UIMessage } from "./index-DHfxB8DH.mjs";
3
- import { c as AgentStreamEvent, i as AgentMessage, p as ThinkingLevel, s as AgentStepStartEvent, t as AgentContextCompactedEvent } from "./schemas-lSbMfQRy-D7NW7SCj.mjs";
2
+ import { a as UIMessage } from "./index-BAERW4m3.mjs";
3
+ import { c as AgentStreamEvent, i as AgentMessage, p as ThinkingLevel, s as AgentStepStartEvent, t as AgentContextCompactedEvent } from "./schemas-lSbMfQRy-CIfs2xv6.mjs";
4
4
  export { AgentContextCompactedEvent, AgentMessage, AgentStepStartEvent, AgentStreamEvent, type AgentTool, type AgentToolParameters, type AgentToolResult, type AgentToolUpdateCallback, ThinkingLevel, type UIMessage };
package/dist/agent.cjs CHANGED
@@ -841,6 +841,75 @@ function gateToolSetMedia(toolSet, capabilities) {
841
841
  }
842
842
  return gated;
843
843
  }
844
+ function withDescription(schema, source) {
845
+ return source.description ? schema.describe(source.description) : schema;
846
+ }
847
+ /** Wire accepts null; parse output uses undefined so `.optional()` consumers still match. */
848
+ function nullableWire(schema) {
849
+ return schema.nullable().transform((value) => value === null ? void 0 : value);
850
+ }
851
+ /**
852
+ * OpenAI (and Azure) strict structured outputs require every key in
853
+ * `properties` to also appear in `required`. Zod `.optional()` / `.nullish()`
854
+ * / `.default()` omit keys from `required`, which the API rejects before the
855
+ * model runs.
856
+ *
857
+ * Rewrite those wrappers to a wire-nullable shape, then map values back to what
858
+ * the original schema expects (null → undefined for `.optional()`, apply
859
+ * `.default()`), so workflow `output` / caller parses still succeed.
860
+ */
861
+ function toStrictStructuredOutputSchema(schema) {
862
+ return rewrite(schema);
863
+ }
864
+ /** Zod classic wrappers expose nested schemas as core `$ZodType`. */
865
+ function rewrite(schema) {
866
+ if (schema instanceof zod.z.ZodOptional) {
867
+ const transformed = rewrite(schema.unwrap());
868
+ if (transformed instanceof zod.z.ZodNullable) return withDescription(transformed, schema);
869
+ return withDescription(nullableWire(transformed), schema);
870
+ }
871
+ if (schema instanceof zod.z.ZodNullable) return withDescription(rewrite(schema.unwrap()).nullable(), schema);
872
+ if (schema instanceof zod.z.ZodDefault) {
873
+ const defaultValue = schema.def.defaultValue;
874
+ const inner = rewrite(schema.unwrap());
875
+ return withDescription(zod.z.union([inner, zod.z.null()]).transform((value) => {
876
+ if (value === null || value === void 0) return defaultValue;
877
+ return value;
878
+ }), schema);
879
+ }
880
+ if (schema instanceof zod.z.ZodObject) {
881
+ const shape = {};
882
+ for (const [key, value] of Object.entries(schema.shape)) shape[key] = rewrite(value);
883
+ const catchall = schema.def.catchall;
884
+ let objectSchema = zod.z.object(shape);
885
+ if (catchall instanceof zod.z.ZodUnknown) objectSchema = objectSchema.loose();
886
+ else if (catchall instanceof zod.z.ZodNever) objectSchema = objectSchema.strict();
887
+ else if (catchall) objectSchema = objectSchema.catchall(rewrite(catchall));
888
+ return withDescription(objectSchema, schema);
889
+ }
890
+ if (schema instanceof zod.z.ZodArray) return withDescription(zod.z.array(rewrite(schema.element)), schema);
891
+ if (schema instanceof zod.z.ZodUnion) {
892
+ const options = schema.options.map(rewrite);
893
+ const first = options[0];
894
+ const second = options[1];
895
+ if (!first || !second) return schema;
896
+ return withDescription(zod.z.union([
897
+ first,
898
+ second,
899
+ ...options.slice(2)
900
+ ]), schema);
901
+ }
902
+ if (schema instanceof zod.z.ZodTuple) {
903
+ const { items, rest } = schema.def;
904
+ const transformed = items.map(rewrite);
905
+ const first = transformed[0];
906
+ if (!first) return schema;
907
+ return withDescription(rest ? zod.z.tuple([first, ...transformed.slice(1)]).rest(rewrite(rest)) : zod.z.tuple([first, ...transformed.slice(1)]), schema);
908
+ }
909
+ if (schema instanceof zod.z.ZodRecord) return withDescription(zod.z.record(schema.keyType, rewrite(schema.valueType)), schema);
910
+ if (schema instanceof zod.z.ZodType) return schema;
911
+ throw new Error("Expected a Zod classic schema");
912
+ }
844
913
  function textFromContent(result) {
845
914
  return result.content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
846
915
  }
@@ -1183,13 +1252,14 @@ async function streamAgentPrompt(config, input, options) {
1183
1252
  ...instrumentAiToolSet(config.mcpToolSet)
1184
1253
  }, config.resolvedModel.capabilities);
1185
1254
  const structuredOutput = Boolean(options.outputSchema);
1255
+ const outputSchema = options.outputSchema ? toStrictStructuredOutputSchema(options.outputSchema) : void 0;
1186
1256
  const hasTools = Object.keys(aiTools).length > 0;
1187
1257
  const submitToolOutput = usesStructuredOutputSubmitTool({
1188
1258
  modelId: config.resolvedModel.modelId,
1189
1259
  structuredOutput,
1190
1260
  hasTools
1191
1261
  });
1192
- if (submitToolOutput && options.outputSchema) aiTools = appendStructuredOutputSubmitTool(aiTools, options.outputSchema);
1262
+ if (submitToolOutput && outputSchema) aiTools = appendStructuredOutputSubmitTool(aiTools, outputSchema);
1193
1263
  let messagesForModel = await applyCapabilityPlaceholderToMessages(priorMessages, config.resolvedModel.capabilities);
1194
1264
  if (config.experimentalDownload) messagesForModel = await hydrateChatAttachmentMessages(messagesForModel, config.experimentalDownload);
1195
1265
  const modelMessages = await require_dist$2.convertToModelMessages(messagesForModel, resume ? { ignoreIncompleteToolCalls: true } : void 0);
@@ -1288,7 +1358,7 @@ async function streamAgentPrompt(config, input, options) {
1288
1358
  tools: aiTools,
1289
1359
  reasoning: config.thinkingLevel,
1290
1360
  ...config.experimentalDownload ? { experimental_download: config.experimentalDownload } : {},
1291
- ...!submitToolOutput && options.outputSchema ? { output: require_dist$2.output_exports.object({ schema: options.outputSchema }) } : {},
1361
+ ...!submitToolOutput && outputSchema ? { output: require_dist$2.output_exports.object({ schema: outputSchema }) } : {},
1292
1362
  ...providerOptions ? { providerOptions } : {},
1293
1363
  prepareStep: prepareStepOnce,
1294
1364
  stopWhen
@@ -1390,10 +1460,10 @@ async function streamAgentPrompt(config, input, options) {
1390
1460
  });
1391
1461
  }
1392
1462
  text = await streamResult.text;
1393
- if (options.outputSchema) if (submitToolOutput) {
1463
+ if (outputSchema) if (submitToolOutput) {
1394
1464
  output = extractStructuredOutputFromSubmitTool({
1395
1465
  steps: await streamResult.steps,
1396
- schema: options.outputSchema
1466
+ schema: outputSchema
1397
1467
  });
1398
1468
  if (output === void 0) throw new Error(`Structured output was not submitted via ${STRUCTURED_OUTPUT_SUBMIT_TOOL_NAME}`);
1399
1469
  } else try {
@@ -1401,7 +1471,7 @@ async function streamAgentPrompt(config, input, options) {
1401
1471
  } catch (caught) {
1402
1472
  const repaired = parseRepairedStructuredOutput({
1403
1473
  text,
1404
- schema: options.outputSchema
1474
+ schema: outputSchema
1405
1475
  });
1406
1476
  if (repaired !== void 0) output = repaired;
1407
1477
  else throw caught;
@@ -2788,7 +2858,7 @@ async function runPromptText(opts, hooks) {
2788
2858
  return result.text;
2789
2859
  }
2790
2860
  async function runPromptObjectViaSubmitTool(opts, hooks) {
2791
- const schema = opts.outputSchema;
2861
+ const schema = opts.outputSchema ? toStrictStructuredOutputSchema(opts.outputSchema) : void 0;
2792
2862
  if (!schema) throw new Error("outputSchema is required for structured LLM output");
2793
2863
  const resolved = await resolvePromptModel(opts.model);
2794
2864
  const providerOptions = resolveProviderOptions({
@@ -2833,14 +2903,14 @@ async function runPromptObjectViaSubmitTool(opts, hooks) {
2833
2903
  throw new Error(`Structured output was not submitted via ${STRUCTURED_OUTPUT_SUBMIT_TOOL_NAME}`);
2834
2904
  }
2835
2905
  async function runPromptObject(opts, hooks) {
2836
- const schema = opts.outputSchema;
2837
- if (!schema) throw new Error("outputSchema is required for structured LLM output");
2838
2906
  const resolved = await resolvePromptModel(opts.model);
2839
2907
  if (usesStructuredOutputSubmitTool({
2840
2908
  modelId: resolved.modelId,
2841
2909
  structuredOutput: true,
2842
2910
  promptLlm: true
2843
2911
  })) return runPromptObjectViaSubmitTool(opts, hooks);
2912
+ const schema = opts.outputSchema ? toStrictStructuredOutputSchema(opts.outputSchema) : void 0;
2913
+ if (!schema) throw new Error("outputSchema is required for structured LLM output");
2844
2914
  const providerOptions = resolveProviderOptions({
2845
2915
  modelId: resolved.modelId,
2846
2916
  structuredOutput: true