@polka-codes/core 0.9.85 → 0.9.86

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.
@@ -232,6 +232,18 @@ export { ContinueStepSchema }
232
232
  export { ContinueStepSchema as ContinueStepSchema_alias_1 }
233
233
  export { ContinueStepSchema as ContinueStepSchema_alias_2 }
234
234
 
235
+ /**
236
+ * Convert a JSON Schema to a Zod schema
237
+ * Supports a subset of JSON SchemaDraft 7
238
+ *
239
+ * This is exported to allow reuse in other parts of the codebase that need to
240
+ * convert JSON schemas to Zod schemas (e.g., MCP server tool schema conversion).
241
+ */
242
+ declare function convertJsonSchemaToZod(schema: JsonSchema): z.ZodTypeAny;
243
+ export { convertJsonSchemaToZod }
244
+ export { convertJsonSchemaToZod as convertJsonSchemaToZod_alias_1 }
245
+ export { convertJsonSchemaToZod as convertJsonSchemaToZod_alias_2 }
246
+
235
247
  declare function createContext<TTools extends ToolRegistry>(tools: WorkflowTools<TTools>, stepFn?: StepFn, logger?: Logger): WorkflowContext<TTools>;
236
248
  export { createContext }
237
249
  export { createContext as createContext_alias_1 }
@@ -884,6 +896,27 @@ export { JsonResponseMessage }
884
896
  export { JsonResponseMessage as JsonResponseMessage_alias_1 }
885
897
  export { JsonResponseMessage as JsonResponseMessage_alias_2 }
886
898
 
899
+ declare interface JsonSchema {
900
+ type?: JsonSchemaType | JsonSchemaType[];
901
+ enum?: JsonSchemaEnum;
902
+ properties?: Record<string, JsonSchema>;
903
+ required?: string[];
904
+ items?: JsonSchema;
905
+ additionalProperties?: boolean | JsonSchema;
906
+ description?: string;
907
+ [key: string]: unknown;
908
+ }
909
+
910
+ /**
911
+ * JSON Schema enum values - can be string, number, or boolean
912
+ */
913
+ declare type JsonSchemaEnum = (string | number | boolean)[];
914
+
915
+ /**
916
+ * JSON Schema type to Zod type mapping
917
+ */
918
+ declare type JsonSchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
919
+
887
920
  declare interface JsonToolCallPart {
888
921
  type: 'tool-call';
889
922
  /**
package/dist/index.d.ts CHANGED
@@ -97,6 +97,7 @@ export { UsageMeter_alias_1 as UsageMeter } from './_tsup-dts-rollup.js';
97
97
  export { AgentWorkflowInput } from './_tsup-dts-rollup.js';
98
98
  export { AgentToolRegistry } from './_tsup-dts-rollup.js';
99
99
  export { agentWorkflow } from './_tsup-dts-rollup.js';
100
+ export { convertJsonSchemaToZod } from './_tsup-dts-rollup.js';
100
101
  export { validateWorkflowFile } from './_tsup-dts-rollup.js';
101
102
  export { parseDynamicWorkflowDefinition } from './_tsup-dts-rollup.js';
102
103
  export { createDynamicWorkflow } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -2403,8 +2403,18 @@ var WorkflowFileSchema = z20.object({
2403
2403
  var MAX_WHILE_LOOP_ITERATIONS = 1e3;
2404
2404
  function convertJsonSchemaToZod(schema) {
2405
2405
  if (schema.enum) {
2406
- const enumValues = schema.enum.map((v) => String(v));
2407
- return z21.enum(enumValues);
2406
+ const enumValues = schema.enum;
2407
+ if (enumValues.length === 0) {
2408
+ return z21.never();
2409
+ }
2410
+ if (enumValues.every((v) => typeof v === "string")) {
2411
+ return z21.enum(enumValues);
2412
+ }
2413
+ const literals = enumValues.map((v) => z21.literal(v));
2414
+ if (literals.length === 1) {
2415
+ return literals[0];
2416
+ }
2417
+ return z21.union([literals[0], literals[1], ...literals.slice(2)]);
2408
2418
  }
2409
2419
  if (Array.isArray(schema.type)) {
2410
2420
  const types = schema.type;
@@ -2573,8 +2583,13 @@ ${errors.map((e) => ` - ${e}`).join("\n")}`);
2573
2583
  }
2574
2584
  return validatedInput;
2575
2585
  }
2576
- function evaluateCondition(condition, input, state, allowUnsafeCodeExecution = false) {
2586
+ function evaluateCondition(condition, input, state, allowUnsafeCodeExecution = false, logger) {
2577
2587
  if (allowUnsafeCodeExecution) {
2588
+ if (logger) {
2589
+ logger.warn(
2590
+ `[SECURITY] Executing unsafe code evaluation for condition: ${condition}. This allows arbitrary JavaScript execution and should only be used for trusted workflows.`
2591
+ );
2592
+ }
2578
2593
  const functionBody = `
2579
2594
  try {
2580
2595
  return ${condition};
@@ -3466,6 +3481,7 @@ export {
3466
3481
  askFollowupQuestion_default as askFollowupQuestion,
3467
3482
  computeRateLimitBackoffSeconds,
3468
3483
  configSchema,
3484
+ convertJsonSchemaToZod,
3469
3485
  createContext,
3470
3486
  createDynamicWorkflow,
3471
3487
  executeCommand_default as executeCommand,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/core",
3
- "version": "0.9.85",
3
+ "version": "0.9.86",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",