@yourgpt/copilot-sdk 1.4.31 → 1.4.33

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.
@@ -1600,17 +1600,107 @@ function createSSEStream(generator) {
1600
1600
 
1601
1601
  // src/core/utils/zod-to-json-schema.ts
1602
1602
  function isZodSchema(value) {
1603
- return value !== null && typeof value === "object" && "_def" in value && typeof value._def === "object";
1603
+ if (value === null || typeof value !== "object") return false;
1604
+ const obj = value;
1605
+ return "_def" in obj && typeof obj._def === "object" || "_zod" in obj && typeof obj._zod === "object" || "~standard" in obj;
1604
1606
  }
1605
1607
  function getZodTypeName(schema) {
1606
1608
  if (!isZodSchema(schema)) return "unknown";
1607
- const def = schema._def;
1608
- return def.typeName || "unknown";
1609
+ const obj = schema;
1610
+ if ("_zod" in obj) {
1611
+ const zod = obj._zod;
1612
+ if (zod.def && typeof zod.def === "object") {
1613
+ const def2 = zod.def;
1614
+ if (def2.type) return `Zod${capitalize(def2.type)}`;
1615
+ }
1616
+ }
1617
+ if ("~standard" in obj) {
1618
+ const standard = obj["~standard"];
1619
+ if (standard.type === "object") return "ZodObject";
1620
+ if (standard.type === "string") return "ZodString";
1621
+ if (standard.type === "number") return "ZodNumber";
1622
+ if (standard.type === "boolean") return "ZodBoolean";
1623
+ if (standard.type === "array") return "ZodArray";
1624
+ }
1625
+ const def = obj._def;
1626
+ if (def?.typeName) return def.typeName;
1627
+ return "unknown";
1628
+ }
1629
+ function capitalize(str) {
1630
+ return str.charAt(0).toUpperCase() + str.slice(1);
1609
1631
  }
1610
1632
  function getZodDescription(schema) {
1611
1633
  if (!isZodSchema(schema)) return void 0;
1612
- const def = schema._def;
1613
- return def.description;
1634
+ const obj = schema;
1635
+ if ("_zod" in obj) {
1636
+ const zod = obj._zod;
1637
+ if (zod.def && typeof zod.def === "object") {
1638
+ const def2 = zod.def;
1639
+ if (def2.description) return def2.description;
1640
+ }
1641
+ }
1642
+ const def = obj._def;
1643
+ return def?.description;
1644
+ }
1645
+ function getZodObjectShape(schema) {
1646
+ if (!isZodSchema(schema)) return null;
1647
+ const obj = schema;
1648
+ if ("shape" in obj && typeof obj.shape === "object" && obj.shape !== null) {
1649
+ return obj.shape;
1650
+ }
1651
+ if ("_zod" in obj) {
1652
+ const zod = obj._zod;
1653
+ if (zod.def && typeof zod.def === "object") {
1654
+ const def2 = zod.def;
1655
+ if (def2.shape && typeof def2.shape === "object") {
1656
+ return def2.shape;
1657
+ }
1658
+ }
1659
+ }
1660
+ const def = obj._def;
1661
+ if (def?.shape) {
1662
+ const shape = def.shape;
1663
+ if (typeof shape === "function") return shape();
1664
+ if (typeof shape === "object") return shape;
1665
+ }
1666
+ return null;
1667
+ }
1668
+ function getZodInnerType(schema) {
1669
+ if (!isZodSchema(schema)) return null;
1670
+ const obj = schema;
1671
+ if ("_zod" in obj) {
1672
+ const zod = obj._zod;
1673
+ if (zod.def && typeof zod.def === "object") {
1674
+ const def2 = zod.def;
1675
+ if (def2.innerType) return def2.innerType;
1676
+ if (def2.element) return def2.element;
1677
+ }
1678
+ }
1679
+ const def = obj._def;
1680
+ if (def?.innerType) return def.innerType;
1681
+ if (def?.type) return def.type;
1682
+ return null;
1683
+ }
1684
+ function getZodEnumValues(schema) {
1685
+ if (!isZodSchema(schema)) return null;
1686
+ const obj = schema;
1687
+ if ("_zod" in obj) {
1688
+ const zod = obj._zod;
1689
+ if (zod.def && typeof zod.def === "object") {
1690
+ const def2 = zod.def;
1691
+ if (def2.entries && Array.isArray(def2.entries)) {
1692
+ return def2.entries;
1693
+ }
1694
+ if (def2.values && Array.isArray(def2.values)) {
1695
+ return def2.values;
1696
+ }
1697
+ }
1698
+ }
1699
+ const def = obj._def;
1700
+ if (def?.values && Array.isArray(def.values)) {
1701
+ return def.values;
1702
+ }
1703
+ return null;
1614
1704
  }
1615
1705
  function zodToJsonSchema(schema) {
1616
1706
  if (!isZodSchema(schema)) {
@@ -1618,32 +1708,19 @@ function zodToJsonSchema(schema) {
1618
1708
  }
1619
1709
  const typeName = getZodTypeName(schema);
1620
1710
  const description = getZodDescription(schema);
1621
- const def = schema._def;
1622
1711
  switch (typeName) {
1623
1712
  case "ZodString": {
1624
1713
  const result2 = { type: "string" };
1625
1714
  if (description) result2.description = description;
1626
- const checks = def.checks;
1627
- if (checks) {
1628
- for (const check of checks) {
1629
- if (check.kind === "min") result2.minLength = check.value;
1630
- if (check.kind === "max") result2.maxLength = check.value;
1631
- if (check.kind === "regex") result2.pattern = String(check.value);
1632
- }
1633
- }
1634
1715
  return result2;
1635
1716
  }
1636
- case "ZodNumber": {
1637
- const result2 = { type: "number" };
1717
+ case "ZodNumber":
1718
+ case "ZodInt":
1719
+ case "ZodFloat": {
1720
+ const result2 = {
1721
+ type: typeName === "ZodInt" ? "integer" : "number"
1722
+ };
1638
1723
  if (description) result2.description = description;
1639
- const checks = def.checks;
1640
- if (checks) {
1641
- for (const check of checks) {
1642
- if (check.kind === "min") result2.minimum = check.value;
1643
- if (check.kind === "max") result2.maximum = check.value;
1644
- if (check.kind === "int") result2.type = "integer";
1645
- }
1646
- }
1647
1724
  return result2;
1648
1725
  }
1649
1726
  case "ZodBoolean": {
@@ -1652,26 +1729,31 @@ function zodToJsonSchema(schema) {
1652
1729
  return result2;
1653
1730
  }
1654
1731
  case "ZodEnum": {
1655
- const values = def.values;
1656
- const result2 = {
1657
- type: typeof values[0] === "number" ? "number" : "string",
1658
- enum: values
1659
- };
1660
- if (description) result2.description = description;
1661
- return result2;
1732
+ const values = getZodEnumValues(schema);
1733
+ if (values && values.length > 0) {
1734
+ const result2 = {
1735
+ type: typeof values[0] === "number" ? "number" : "string",
1736
+ enum: values
1737
+ };
1738
+ if (description) result2.description = description;
1739
+ return result2;
1740
+ }
1741
+ return { type: "string", description };
1662
1742
  }
1663
1743
  case "ZodArray": {
1664
- const innerType = def.type;
1744
+ const innerType = getZodInnerType(schema);
1665
1745
  const result2 = {
1666
1746
  type: "array",
1667
- items: zodToJsonSchema(innerType)
1747
+ items: innerType ? zodToJsonSchema(innerType) : { type: "string" }
1668
1748
  };
1669
1749
  if (description) result2.description = description;
1670
1750
  return result2;
1671
1751
  }
1672
1752
  case "ZodObject": {
1673
- const shape = def.shape;
1674
- const shapeObj = typeof shape === "function" ? shape() : shape;
1753
+ const shapeObj = getZodObjectShape(schema);
1754
+ if (!shapeObj) {
1755
+ return { type: "object", properties: {}, description };
1756
+ }
1675
1757
  const properties = {};
1676
1758
  const required = [];
1677
1759
  for (const [key, value] of Object.entries(shapeObj)) {
@@ -1691,30 +1773,57 @@ function zodToJsonSchema(schema) {
1691
1773
  }
1692
1774
  case "ZodOptional":
1693
1775
  case "ZodNullable": {
1694
- const innerType = def.innerType;
1695
- return zodToJsonSchema(innerType);
1776
+ const innerType = getZodInnerType(schema);
1777
+ if (innerType) {
1778
+ return zodToJsonSchema(innerType);
1779
+ }
1780
+ return { type: "string", description };
1696
1781
  }
1697
1782
  case "ZodDefault": {
1698
- const innerType = def.innerType;
1699
- const defaultValue = def.defaultValue;
1700
- const result2 = zodToJsonSchema(innerType);
1701
- result2.default = typeof defaultValue === "function" ? defaultValue() : defaultValue;
1702
- return result2;
1783
+ const innerType = getZodInnerType(schema);
1784
+ if (innerType) {
1785
+ const result2 = zodToJsonSchema(innerType);
1786
+ return result2;
1787
+ }
1788
+ return { type: "string", description };
1703
1789
  }
1704
1790
  case "ZodLiteral": {
1705
- const value = def.value;
1706
- return {
1707
- type: typeof value === "number" ? "number" : typeof value === "boolean" ? "boolean" : "string",
1708
- enum: [value],
1709
- description
1710
- };
1791
+ const obj = schema;
1792
+ let value;
1793
+ if ("_zod" in obj) {
1794
+ const zod = obj._zod;
1795
+ const def = zod.def;
1796
+ value = def?.value;
1797
+ }
1798
+ if (value === void 0) {
1799
+ const def = obj._def;
1800
+ value = def?.value;
1801
+ }
1802
+ if (value !== void 0) {
1803
+ return {
1804
+ type: typeof value === "number" ? "number" : typeof value === "boolean" ? "boolean" : "string",
1805
+ enum: [value],
1806
+ description
1807
+ };
1808
+ }
1809
+ return { type: "string", description };
1711
1810
  }
1712
1811
  case "ZodUnion": {
1713
- const options = def.options;
1812
+ const obj = schema;
1813
+ let options;
1814
+ if ("_zod" in obj) {
1815
+ const zod = obj._zod;
1816
+ const def = zod.def;
1817
+ options = def?.options;
1818
+ }
1819
+ if (!options) {
1820
+ const def = obj._def;
1821
+ options = def?.options;
1822
+ }
1714
1823
  if (options && options.length > 0) {
1715
1824
  return zodToJsonSchema(options[0]);
1716
1825
  }
1717
- return { type: "string" };
1826
+ return { type: "string", description };
1718
1827
  }
1719
1828
  default:
1720
1829
  const result = { type: "string" };
@@ -2765,5 +2874,5 @@ function createThreadManager(config, callbacks) {
2765
2874
  }
2766
2875
 
2767
2876
  export { CLOUD_MAX_FILE_SIZE, DEFAULT_YOURGPT_ENDPOINT, SimpleThreadManagerState, ThreadManager, actionToTool, builtinTools, captureCurrentLogs, captureScreenshot, clearConsoleLogs, clearNetworkRequests, consoleLogsTool, createAssistantMessage, createCloudStorage, createConsoleLogsTool, createCustomDetector, createLocalStorageAdapter, createMemoryAdapter, createMessage, createNetworkRequestsTool, createSSEStream, createScreenshotTool, createServerAdapter, createThreadManager, createToolCall, createToolMessage, createToolResult, createUserMessage, defaultSystemMessage, defineClientTool, defineServerTool, defineTool, detectIntent, failure, formatLogsForAI, formatRequestsForAI, formatSSE, generateId, generateMessageId, generateSuggestionReason, generateThreadId, generateThreadTitle, generateToolCallId, getAttachmentTypeFromMime, getConsoleErrors, getConsoleLogs, getConsoleWarnings, getFailedRequests, getNetworkRequests, getPrimaryTool, hasToolCalls, hasToolSuggestions, isConsoleCaptureActive, isNetworkCaptureActive, isScreenshotSupported, isToolResult, localStorageAdapter, networkRequestsTool, noopAdapter, parseSSELine, parseStreamEvent, parseToolCallArgs, processFileToAttachment, resizeScreenshot, screenshotTool, serializeStreamEvent, startConsoleCapture, startNetworkCapture, stopConsoleCapture, stopNetworkCapture, streamSSE, success, tool, toolToAnthropicFormat, toolToOpenAIFormat, zodObjectToInputSchema, zodToJsonSchema };
2768
- //# sourceMappingURL=chunk-55EABH45.js.map
2769
- //# sourceMappingURL=chunk-55EABH45.js.map
2877
+ //# sourceMappingURL=chunk-JM7PB2LP.js.map
2878
+ //# sourceMappingURL=chunk-JM7PB2LP.js.map