@copilotkit/shared 1.51.4-next.6 → 1.51.4-next.8

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 (91) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +18 -12
  3. package/dist/{chunk-64DYJ27R.mjs → chunk-3DK3UMRW.mjs} +22 -6
  4. package/dist/chunk-3DK3UMRW.mjs.map +1 -0
  5. package/dist/{chunk-AVIYBZYY.mjs → chunk-7YHHOGQR.mjs} +14 -5
  6. package/dist/chunk-7YHHOGQR.mjs.map +1 -0
  7. package/dist/{chunk-BOKE4OKY.mjs → chunk-GS5BLXSZ.mjs} +1 -1
  8. package/dist/{chunk-BOKE4OKY.mjs.map → chunk-GS5BLXSZ.mjs.map} +1 -1
  9. package/dist/{chunk-6W2UEO2M.mjs → chunk-M2RJI5BZ.mjs} +1 -1
  10. package/dist/{chunk-6W2UEO2M.mjs.map → chunk-M2RJI5BZ.mjs.map} +1 -1
  11. package/dist/{chunk-4QKW3U57.mjs → chunk-QPTUDD4F.mjs} +2 -2
  12. package/dist/chunk-QPTUDD4F.mjs.map +1 -0
  13. package/dist/{chunk-PL5WNHFZ.mjs → chunk-V7BSERGI.mjs} +19 -7
  14. package/dist/chunk-V7BSERGI.mjs.map +1 -0
  15. package/dist/{chunk-XEMZTHQZ.mjs → chunk-WAZHII6M.mjs} +1 -1
  16. package/dist/chunk-WAZHII6M.mjs.map +1 -0
  17. package/dist/{chunk-AKRG3IXS.mjs → chunk-XYPFY2IY.mjs} +7 -4
  18. package/dist/chunk-XYPFY2IY.mjs.map +1 -0
  19. package/dist/{chunk-GYZIHHE6.mjs → chunk-ZIC6V6S5.mjs} +1 -1
  20. package/dist/{chunk-GYZIHHE6.mjs.map → chunk-ZIC6V6S5.mjs.map} +1 -1
  21. package/dist/{chunk-6QGXWNS5.mjs → chunk-ZUE2VR7D.mjs} +7 -3
  22. package/dist/chunk-ZUE2VR7D.mjs.map +1 -0
  23. package/dist/constants/index.js.map +1 -1
  24. package/dist/constants/index.mjs +1 -1
  25. package/dist/index.js +56 -16
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +10 -10
  28. package/dist/index.umd.js +1 -1
  29. package/dist/index.umd.js.map +1 -1
  30. package/dist/telemetry/events.js.map +1 -1
  31. package/dist/telemetry/index.js +5 -2
  32. package/dist/telemetry/index.js.map +1 -1
  33. package/dist/telemetry/index.mjs +3 -3
  34. package/dist/telemetry/scarf-client.js +1 -1
  35. package/dist/telemetry/scarf-client.js.map +1 -1
  36. package/dist/telemetry/scarf-client.mjs +1 -1
  37. package/dist/telemetry/telemetry-client.js +5 -2
  38. package/dist/telemetry/telemetry-client.js.map +1 -1
  39. package/dist/telemetry/telemetry-client.mjs +3 -3
  40. package/dist/telemetry/utils.js +6 -2
  41. package/dist/telemetry/utils.js.map +1 -1
  42. package/dist/telemetry/utils.mjs +1 -1
  43. package/dist/types/action.js.map +1 -1
  44. package/dist/types/error.js.map +1 -1
  45. package/dist/types/openai-assistant.js.map +1 -1
  46. package/dist/utils/conditions.js +18 -6
  47. package/dist/utils/conditions.js.map +1 -1
  48. package/dist/utils/conditions.mjs +1 -1
  49. package/dist/utils/console-styling.js.map +1 -1
  50. package/dist/utils/console-styling.mjs +1 -1
  51. package/dist/utils/errors.d.ts +1 -1
  52. package/dist/utils/errors.js +13 -4
  53. package/dist/utils/errors.js.map +1 -1
  54. package/dist/utils/errors.mjs +10 -10
  55. package/dist/utils/index.js +52 -15
  56. package/dist/utils/index.js.map +1 -1
  57. package/dist/utils/index.mjs +10 -10
  58. package/dist/utils/json-schema.js +21 -5
  59. package/dist/utils/json-schema.js.map +1 -1
  60. package/dist/utils/json-schema.mjs +1 -1
  61. package/dist/utils/random-id.js.map +1 -1
  62. package/dist/utils/random-id.mjs +1 -1
  63. package/dist/utils/requests.js.map +1 -1
  64. package/dist/utils/requests.mjs +1 -1
  65. package/dist/utils/types.d.ts +1 -1
  66. package/dist/utils/types.js.map +1 -1
  67. package/package.json +1 -2
  68. package/src/constants/index.ts +2 -1
  69. package/src/telemetry/events.ts +4 -1
  70. package/src/telemetry/telemetry-client.ts +17 -6
  71. package/src/telemetry/utils.ts +6 -2
  72. package/src/types/action.ts +9 -5
  73. package/src/types/error.ts +11 -2
  74. package/src/types/openai-assistant.ts +6 -2
  75. package/src/utils/conditions.ts +27 -9
  76. package/src/utils/console-styling.ts +4 -2
  77. package/src/utils/errors.ts +49 -16
  78. package/src/utils/json-schema.test.ts +29 -5
  79. package/src/utils/json-schema.ts +34 -9
  80. package/src/utils/random-id.ts +5 -2
  81. package/src/utils/requests.ts +3 -1
  82. package/src/utils/types.ts +5 -1
  83. package/tsconfig.json +1 -1
  84. package/tsup.config.ts +5 -1
  85. package/dist/chunk-4QKW3U57.mjs.map +0 -1
  86. package/dist/chunk-64DYJ27R.mjs.map +0 -1
  87. package/dist/chunk-6QGXWNS5.mjs.map +0 -1
  88. package/dist/chunk-AKRG3IXS.mjs.map +0 -1
  89. package/dist/chunk-AVIYBZYY.mjs.map +0 -1
  90. package/dist/chunk-PL5WNHFZ.mjs.map +0 -1
  91. package/dist/chunk-XEMZTHQZ.mjs.map +0 -1
@@ -23,7 +23,7 @@ import {
23
23
  isStructuredCopilotKitError,
24
24
  parseJson,
25
25
  tryMap
26
- } from "../chunk-AVIYBZYY.mjs";
26
+ } from "../chunk-7YHHOGQR.mjs";
27
27
  import {
28
28
  ConsoleColors,
29
29
  ConsoleStyles,
@@ -31,22 +31,22 @@ import {
31
31
  logStyled,
32
32
  publicApiKeyRequired,
33
33
  styledConsole
34
- } from "../chunk-6W2UEO2M.mjs";
34
+ } from "../chunk-M2RJI5BZ.mjs";
35
35
  import {
36
36
  actionParametersToJsonSchema,
37
37
  convertJsonSchemaToZodSchema,
38
38
  getZodParameters,
39
39
  jsonSchemaToActionParameters
40
- } from "../chunk-64DYJ27R.mjs";
40
+ } from "../chunk-3DK3UMRW.mjs";
41
41
  import {
42
42
  dataToUUID,
43
43
  isValidUUID,
44
44
  randomId,
45
45
  randomUUID
46
- } from "../chunk-BOKE4OKY.mjs";
46
+ } from "../chunk-GS5BLXSZ.mjs";
47
47
  import {
48
48
  readBody
49
- } from "../chunk-XEMZTHQZ.mjs";
49
+ } from "../chunk-WAZHII6M.mjs";
50
50
  import "../chunk-XTHC46M2.mjs";
51
51
  import "../chunk-N5EP5OD5.mjs";
52
52
  import "../chunk-NAFEBKSO.mjs";
@@ -57,12 +57,12 @@ import "../chunk-IAFBVORQ.mjs";
57
57
  import "../chunk-FCCOSO5L.mjs";
58
58
  import {
59
59
  executeConditions
60
- } from "../chunk-PL5WNHFZ.mjs";
61
- import "../chunk-GYZIHHE6.mjs";
60
+ } from "../chunk-V7BSERGI.mjs";
61
+ import "../chunk-ZIC6V6S5.mjs";
62
62
  import "../chunk-P7STFMPO.mjs";
63
- import "../chunk-AKRG3IXS.mjs";
64
- import "../chunk-4QKW3U57.mjs";
65
- import "../chunk-6QGXWNS5.mjs";
63
+ import "../chunk-XYPFY2IY.mjs";
64
+ import "../chunk-QPTUDD4F.mjs";
65
+ import "../chunk-ZUE2VR7D.mjs";
66
66
  export {
67
67
  BANNER_ERROR_NAMES,
68
68
  COPILOT_CLOUD_ERROR_NAMES,
@@ -51,7 +51,11 @@ function jsonSchemaToActionParameters(jsonSchema) {
51
51
  const parameters = [];
52
52
  const requiredFields = jsonSchema.required || [];
53
53
  for (const [name, schema] of Object.entries(jsonSchema.properties)) {
54
- const parameter = convertJsonSchemaToParameter(name, schema, requiredFields.includes(name));
54
+ const parameter = convertJsonSchemaToParameter(
55
+ name,
56
+ schema,
57
+ requiredFields.includes(name)
58
+ );
55
59
  parameters.push(parameter);
56
60
  }
57
61
  return parameters;
@@ -81,9 +85,15 @@ function convertJsonSchemaToParameter(name, schema, isRequired) {
81
85
  if (schema.properties) {
82
86
  const attributes = [];
83
87
  const requiredFields = schema.required || [];
84
- for (const [propName, propSchema] of Object.entries(schema.properties)) {
88
+ for (const [propName, propSchema] of Object.entries(
89
+ schema.properties
90
+ )) {
85
91
  attributes.push(
86
- convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName))
92
+ convertJsonSchemaToParameter(
93
+ propName,
94
+ propSchema,
95
+ requiredFields.includes(propName)
96
+ )
87
97
  );
88
98
  }
89
99
  return {
@@ -100,9 +110,15 @@ function convertJsonSchemaToParameter(name, schema, isRequired) {
100
110
  if (schema.items.type === "object" && "properties" in schema.items) {
101
111
  const attributes = [];
102
112
  const requiredFields = schema.items.required || [];
103
- for (const [propName, propSchema] of Object.entries(schema.items.properties || {})) {
113
+ for (const [propName, propSchema] of Object.entries(
114
+ schema.items.properties || {}
115
+ )) {
104
116
  attributes.push(
105
- convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName))
117
+ convertJsonSchemaToParameter(
118
+ propName,
119
+ propSchema,
120
+ requiredFields.includes(propName)
121
+ )
106
122
  );
107
123
  }
108
124
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/json-schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(actionParameters: Parameter[]): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(jsonSchema: JSONSchema): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(name, schema, requiredFields.includes(name));\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(schema.properties)) {\n attributes.push(\n convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName)),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(schema.items.properties || {})) {\n attributes.push(\n convertJsonSchemaToParameter(propName, propSchema, requiredFields.includes(propName)),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function convertJsonSchemaToZodSchema(jsonSchema: any, required: boolean): z.ZodSchema {\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(\n value,\n jsonSchema.required ? jsonSchema.required.includes(key) : false,\n );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\") {\n let schema = z.number().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n throw new Error(\"Invalid JSON schema\");\n}\n\nexport function getZodParameters<T extends [] | Parameter[] | undefined>(parameters: T): any {\n if (!parameters) return z.object({});\n const jsonParams = actionParametersToJsonSchema(parameters);\n return convertJsonSchemaToZodSchema(jsonParams, true);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAuCX,SAAS,6BAA6B,kBAA2C;AAEtF,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C,eAAW,UAAU,IAAI,IAAI,iBAAiB,SAAS;AAAA,EACzD;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,oBAAoB,CAAC,GAAG;AACtC,QAAI,IAAI,aAAa,OAAO;AAC1B,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AACF;AAGO,SAAS,6BAA6B,YAAqC;AAChF,MAAI,WAAW,SAAS,YAAY,CAAC,WAAW,YAAY;AAC1D,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,aAA0B,CAAC;AACjC,QAAM,iBAAiB,WAAW,YAAY,CAAC;AAE/C,aAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,WAAW,UAAU,GAAG;AAClE,UAAM,YAAY,6BAA6B,MAAM,QAAQ,eAAe,SAAS,IAAI,CAAC;AAC1F,eAAW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;AAAA,EAC7C,WAAW,WAAW,SAAS,SAAS;AACtC,QAAI,aAAa,6BAA6B,WAAW,OAAO,IAAI;AACpE,QAAI,SAAS,aAAE,MAAM,UAAU,EAAE,SAAS,WAAW,WAAW;AAChE,WAAO,WAAW,SAAS,OAAO,SAAS;AAAA,EAC7C;AACA,QAAM,IAAI,MAAM,qBAAqB;AACvC;AAEO,SAAS,iBAAyD,YAAoB;AAC3F,MAAI,CAAC;AAAY,WAAO,aAAE,OAAO,CAAC,CAAC;AACnC,QAAM,aAAa,6BAA6B,UAAU;AAC1D,SAAO,6BAA6B,YAAY,IAAI;AACtD;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/json-schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Parameter } from \"../types\";\n\nexport type JSONSchemaString = {\n type: \"string\";\n description?: string;\n enum?: string[];\n};\n\nexport type JSONSchemaNumber = {\n type: \"number\";\n description?: string;\n};\n\nexport type JSONSchemaBoolean = {\n type: \"boolean\";\n description?: string;\n};\n\nexport type JSONSchemaObject = {\n type: \"object\";\n properties?: Record<string, JSONSchema>;\n required?: string[];\n description?: string;\n};\n\nexport type JSONSchemaArray = {\n type: \"array\";\n items: JSONSchema;\n description?: string;\n};\n\nexport type JSONSchema =\n | JSONSchemaString\n | JSONSchemaNumber\n | JSONSchemaBoolean\n | JSONSchemaObject\n | JSONSchemaArray;\n\nexport function actionParametersToJsonSchema(\n actionParameters: Parameter[],\n): JSONSchema {\n // Create the parameters object based on the argumentAnnotations\n let parameters: { [key: string]: any } = {};\n for (let parameter of actionParameters || []) {\n parameters[parameter.name] = convertAttribute(parameter);\n }\n\n let requiredParameterNames: string[] = [];\n for (let arg of actionParameters || []) {\n if (arg.required !== false) {\n requiredParameterNames.push(arg.name);\n }\n }\n\n // Create the ChatCompletionFunctions object\n return {\n type: \"object\",\n properties: parameters,\n required: requiredParameterNames,\n };\n}\n\n// Convert JSONSchema to Parameter[]\nexport function jsonSchemaToActionParameters(\n jsonSchema: JSONSchema,\n): Parameter[] {\n if (jsonSchema.type !== \"object\" || !jsonSchema.properties) {\n return [];\n }\n\n const parameters: Parameter[] = [];\n const requiredFields = jsonSchema.required || [];\n\n for (const [name, schema] of Object.entries(jsonSchema.properties)) {\n const parameter = convertJsonSchemaToParameter(\n name,\n schema,\n requiredFields.includes(name),\n );\n parameters.push(parameter);\n }\n\n return parameters;\n}\n\n// Convert JSONSchema property to Parameter\nfunction convertJsonSchemaToParameter(\n name: string,\n schema: JSONSchema,\n isRequired: boolean,\n): Parameter {\n const baseParameter: Parameter = {\n name,\n description: schema.description,\n };\n\n if (!isRequired) {\n baseParameter.required = false;\n }\n\n switch (schema.type) {\n case \"string\":\n return {\n ...baseParameter,\n type: \"string\",\n ...(schema.enum && { enum: schema.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n ...baseParameter,\n type: schema.type,\n };\n case \"object\":\n if (schema.properties) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.properties,\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object\",\n attributes,\n };\n }\n return {\n ...baseParameter,\n type: \"object\",\n };\n case \"array\":\n if (schema.items.type === \"object\" && \"properties\" in schema.items) {\n const attributes: Parameter[] = [];\n const requiredFields = schema.items.required || [];\n\n for (const [propName, propSchema] of Object.entries(\n schema.items.properties || {},\n )) {\n attributes.push(\n convertJsonSchemaToParameter(\n propName,\n propSchema,\n requiredFields.includes(propName),\n ),\n );\n }\n\n return {\n ...baseParameter,\n type: \"object[]\",\n attributes,\n };\n } else if (schema.items.type === \"array\") {\n throw new Error(\"Nested arrays are not supported\");\n } else {\n return {\n ...baseParameter,\n type: `${schema.items.type}[]`,\n };\n }\n default:\n return {\n ...baseParameter,\n type: \"string\",\n };\n }\n}\n\nfunction convertAttribute(attribute: Parameter): JSONSchema {\n switch (attribute.type) {\n case \"string\":\n return {\n type: \"string\",\n description: attribute.description,\n ...(attribute.enum && { enum: attribute.enum }),\n };\n case \"number\":\n case \"boolean\":\n return {\n type: attribute.type,\n description: attribute.description,\n };\n case \"object\":\n case \"object[]\":\n const properties = attribute.attributes?.reduce(\n (acc, attr) => {\n acc[attr.name] = convertAttribute(attr);\n return acc;\n },\n {} as Record<string, any>,\n );\n const required = attribute.attributes\n ?.filter((attr) => attr.required !== false)\n .map((attr) => attr.name);\n if (attribute.type === \"object[]\") {\n return {\n type: \"array\",\n items: {\n type: \"object\",\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n },\n description: attribute.description,\n };\n }\n return {\n type: \"object\",\n description: attribute.description,\n ...(properties && { properties }),\n ...(required && required.length > 0 && { required }),\n };\n default:\n // Handle arrays of primitive types and undefined attribute.type\n if (attribute.type?.endsWith(\"[]\")) {\n const itemType = attribute.type.slice(0, -2);\n return {\n type: \"array\",\n items: { type: itemType as any },\n description: attribute.description,\n };\n }\n // Fallback for undefined type or any other unexpected type\n return {\n type: \"string\",\n description: attribute.description,\n };\n }\n}\n\nexport function convertJsonSchemaToZodSchema(\n jsonSchema: any,\n required: boolean,\n): z.ZodSchema {\n if (jsonSchema.type === \"object\") {\n const spec: { [key: string]: z.ZodSchema } = {};\n\n if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {\n return !required ? z.object(spec).optional() : z.object(spec);\n }\n\n for (const [key, value] of Object.entries(jsonSchema.properties)) {\n spec[key] = convertJsonSchemaToZodSchema(\n value,\n jsonSchema.required ? jsonSchema.required.includes(key) : false,\n );\n }\n let schema = z.object(spec).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"string\") {\n let schema = z.string().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"number\") {\n let schema = z.number().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"boolean\") {\n let schema = z.boolean().describe(jsonSchema.description);\n return required ? schema : schema.optional();\n } else if (jsonSchema.type === \"array\") {\n let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);\n let schema = z.array(itemSchema).describe(jsonSchema.description);\n return required ? schema : schema.optional();\n }\n throw new Error(\"Invalid JSON schema\");\n}\n\nexport function getZodParameters<T extends [] | Parameter[] | undefined>(\n parameters: T,\n): any {\n if (!parameters) return z.object({});\n const jsonParams = actionParametersToJsonSchema(parameters);\n return convertJsonSchemaToZodSchema(jsonParams, true);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAkB;AAuCX,SAAS,6BACd,kBACY;AAEZ,MAAI,aAAqC,CAAC;AAC1C,WAAS,aAAa,oBAAoB,CAAC,GAAG;AAC5C,eAAW,UAAU,IAAI,IAAI,iBAAiB,SAAS;AAAA,EACzD;AAEA,MAAI,yBAAmC,CAAC;AACxC,WAAS,OAAO,oBAAoB,CAAC,GAAG;AACtC,QAAI,IAAI,aAAa,OAAO;AAC1B,6BAAuB,KAAK,IAAI,IAAI;AAAA,IACtC;AAAA,EACF;AAGA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU;AAAA,EACZ;AACF;AAGO,SAAS,6BACd,YACa;AACb,MAAI,WAAW,SAAS,YAAY,CAAC,WAAW,YAAY;AAC1D,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,aAA0B,CAAC;AACjC,QAAM,iBAAiB,WAAW,YAAY,CAAC;AAE/C,aAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,WAAW,UAAU,GAAG;AAClE,UAAM,YAAY;AAAA,MAChB;AAAA,MACA;AAAA,MACA,eAAe,SAAS,IAAI;AAAA,IAC9B;AACA,eAAW,KAAK,SAAS;AAAA,EAC3B;AAEA,SAAO;AACT;AAGA,SAAS,6BACP,MACA,QACA,YACW;AACX,QAAM,gBAA2B;AAAA,IAC/B;AAAA,IACA,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AO,IAAI;AACpE,QAAI,SAAS,aAAE,MAAM,UAAU,EAAE,SAAS,WAAW,WAAW;AAChE,WAAO,WAAW,SAAS,OAAO,SAAS;AAAA,EAC7C;AACA,QAAM,IAAI,MAAM,qBAAqB;AACvC;AAEO,SAAS,iBACd,YACK;AACL,MAAI,CAAC;AAAY,WAAO,aAAE,OAAO,CAAC,CAAC;AACnC,QAAM,aAAa,6BAA6B,UAAU;AAC1D,SAAO,6BAA6B,YAAY,IAAI;AACtD;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  convertJsonSchemaToZodSchema,
4
4
  getZodParameters,
5
5
  jsonSchemaToActionParameters
6
- } from "../chunk-64DYJ27R.mjs";
6
+ } from "../chunk-3DK3UMRW.mjs";
7
7
  export {
8
8
  actionParametersToJsonSchema,
9
9
  convertJsonSchemaToZodSchema,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/random-id.ts"],"sourcesContent":["import { v4 as uuidv4, validate, v5 as uuidv5 } from \"uuid\";\n\nexport function randomId() {\n return \"ck-\" + uuidv4();\n}\n\nexport function randomUUID() {\n return uuidv4();\n}\n\n/**\n * Recursively converts an object to a serializable form by converting functions to their string representation.\n */\nfunction toSerializable(value: unknown): unknown {\n if (typeof value === \"function\") {\n return value.toString();\n }\n if (Array.isArray(value)) {\n return value.map(toSerializable);\n }\n if (value !== null && typeof value === \"object\") {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(value)) {\n result[key] = toSerializable((value as Record<string, unknown>)[key]);\n }\n return result;\n }\n return value;\n}\n\nexport function dataToUUID(input: string | object, namespace?: string): string {\n const BASE_NAMESPACE = \"e4b01160-ff74-4c6e-9b27-d53cd930fe8e\";\n // Since namespace needs to be a uuid, we are creating a uuid for it.\n const boundNamespace = namespace ? uuidv5(namespace, BASE_NAMESPACE) : BASE_NAMESPACE;\n\n const stringInput = typeof input === \"string\" ? input : JSON.stringify(toSerializable(input));\n return uuidv5(stringInput, boundNamespace);\n}\n\nexport function isValidUUID(uuid: string) {\n return validate(uuid);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqD;AAE9C,SAAS,WAAW;AACzB,SAAO,YAAQ,YAAAA,IAAO;AACxB;AAEO,SAAS,aAAa;AAC3B,aAAO,YAAAA,IAAO;AAChB;AAKA,SAAS,eAAe,OAAyB;AAC/C,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,MAAM,SAAS;AAAA,EACxB;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,IAAI,cAAc;AAAA,EACjC;AACA,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAC/C,UAAM,SAAkC,CAAC;AACzC,eAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,aAAO,GAAG,IAAI,eAAgB,MAAkC,GAAG,CAAC;AAAA,IACtE;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,SAAS,WAAW,OAAwB,WAA4B;AAC7E,QAAM,iBAAiB;AAEvB,QAAM,iBAAiB,gBAAY,YAAAC,IAAO,WAAW,cAAc,IAAI;AAEvE,QAAM,cAAc,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,eAAe,KAAK,CAAC;AAC5F,aAAO,YAAAA,IAAO,aAAa,cAAc;AAC3C;AAEO,SAAS,YAAY,MAAc;AACxC,aAAO,sBAAS,IAAI;AACtB;","names":["uuidv4","uuidv5"]}
1
+ {"version":3,"sources":["../../src/utils/random-id.ts"],"sourcesContent":["import { v4 as uuidv4, validate, v5 as uuidv5 } from \"uuid\";\n\nexport function randomId() {\n return \"ck-\" + uuidv4();\n}\n\nexport function randomUUID() {\n return uuidv4();\n}\n\n/**\n * Recursively converts an object to a serializable form by converting functions to their string representation.\n */\nfunction toSerializable(value: unknown): unknown {\n if (typeof value === \"function\") {\n return value.toString();\n }\n if (Array.isArray(value)) {\n return value.map(toSerializable);\n }\n if (value !== null && typeof value === \"object\") {\n const result: Record<string, unknown> = {};\n for (const key of Object.keys(value)) {\n result[key] = toSerializable((value as Record<string, unknown>)[key]);\n }\n return result;\n }\n return value;\n}\n\nexport function dataToUUID(input: string | object, namespace?: string): string {\n const BASE_NAMESPACE = \"e4b01160-ff74-4c6e-9b27-d53cd930fe8e\";\n // Since namespace needs to be a uuid, we are creating a uuid for it.\n const boundNamespace = namespace\n ? uuidv5(namespace, BASE_NAMESPACE)\n : BASE_NAMESPACE;\n\n const stringInput =\n typeof input === \"string\" ? input : JSON.stringify(toSerializable(input));\n return uuidv5(stringInput, boundNamespace);\n}\n\nexport function isValidUUID(uuid: string) {\n return validate(uuid);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqD;AAE9C,SAAS,WAAW;AACzB,SAAO,YAAQ,YAAAA,IAAO;AACxB;AAEO,SAAS,aAAa;AAC3B,aAAO,YAAAA,IAAO;AAChB;AAKA,SAAS,eAAe,OAAyB;AAC/C,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,MAAM,SAAS;AAAA,EACxB;AACA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM,IAAI,cAAc;AAAA,EACjC;AACA,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAC/C,UAAM,SAAkC,CAAC;AACzC,eAAW,OAAO,OAAO,KAAK,KAAK,GAAG;AACpC,aAAO,GAAG,IAAI,eAAgB,MAAkC,GAAG,CAAC;AAAA,IACtE;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,SAAS,WAAW,OAAwB,WAA4B;AAC7E,QAAM,iBAAiB;AAEvB,QAAM,iBAAiB,gBACnB,YAAAC,IAAO,WAAW,cAAc,IAChC;AAEJ,QAAM,cACJ,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,eAAe,KAAK,CAAC;AAC1E,aAAO,YAAAA,IAAO,aAAa,cAAc;AAC3C;AAEO,SAAS,YAAY,MAAc;AACxC,aAAO,sBAAS,IAAI;AACtB;","names":["uuidv4","uuidv5"]}
@@ -3,7 +3,7 @@ import {
3
3
  isValidUUID,
4
4
  randomId,
5
5
  randomUUID
6
- } from "../chunk-BOKE4OKY.mjs";
6
+ } from "../chunk-GS5BLXSZ.mjs";
7
7
  export {
8
8
  dataToUUID,
9
9
  isValidUUID,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/requests.ts"],"sourcesContent":["/**\n * Safely read a Response/Request body with sensible defaults:\n * - clones the response/request to avoid consuming the original response/request\n * - Skips GET/HEAD\n * - Tries JSON first regardless of content-type\n * - Falls back to text and optionally parses when it \"looks\" like JSON\n */\nexport async function readBody<T extends Response | Request>(r: T): Promise<unknown> {\n // skip GET/HEAD requests (unchanged)\n const method = \"method\" in r ? r.method.toUpperCase() : undefined;\n if (method === \"GET\" || method === \"HEAD\") {\n return undefined;\n }\n\n // no body at all → undefined (unchanged)\n if (!(\"body\" in r) || r.body == null) {\n return undefined;\n }\n\n // 1) try JSON (unchanged)\n try {\n return await r.clone().json();\n } catch {\n // 2) try text (unchanged + your whitespace/JSON-heuristic)\n try {\n const text = await r.clone().text();\n const trimmed = text.trim();\n\n if (trimmed.length === 0) return text;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return text;\n }\n }\n return text;\n } catch {\n // 3) FINAL FALLBACK: manual read that accepts string or bytes\n try {\n const c = r.clone();\n const stream: ReadableStream | null = c.body ?? null;\n if (!stream) return undefined;\n\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let out = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (typeof value === \"string\") {\n out += value; // accept string chunks\n } else {\n out += decoder.decode(value, { stream: true }); // bytes\n }\n }\n out += decoder.decode(); // flush\n\n const trimmed = out.trim();\n if (trimmed.length === 0) return out;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return out;\n }\n }\n return out;\n } catch {\n return undefined; // same \"give up\" behavior you had\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,eAAsB,SAAuC,GAAwB;AAEnF,QAAM,SAAS,YAAY,IAAI,EAAE,OAAO,YAAY,IAAI;AACxD,MAAI,WAAW,SAAS,WAAW,QAAQ;AACzC,WAAO;AAAA,EACT;AAGA,MAAI,EAAE,UAAU,MAAM,EAAE,QAAQ,MAAM;AACpC,WAAO;AAAA,EACT;AAGA,MAAI;AACF,WAAO,MAAM,EAAE,MAAM,EAAE,KAAK;AAAA,EAC9B,QAAE;AAEA,QAAI;AACF,YAAM,OAAO,MAAM,EAAE,MAAM,EAAE,KAAK;AAClC,YAAM,UAAU,KAAK,KAAK;AAE1B,UAAI,QAAQ,WAAW;AAAG,eAAO;AAEjC,UAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAAG;AACtD,YAAI;AACF,iBAAO,KAAK,MAAM,OAAO;AAAA,QAC3B,QAAE;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,QAAE;AAEA,UAAI;AACF,cAAM,IAAI,EAAE,MAAM;AAClB,cAAM,SAAgC,EAAE,QAAQ;AAChD,YAAI,CAAC;AAAQ,iBAAO;AAEpB,cAAM,SAAS,OAAO,UAAU;AAChC,cAAM,UAAU,IAAI,YAAY;AAChC,YAAI,MAAM;AAEV,eAAO,MAAM;AACX,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI;AAAM;AACV,cAAI,OAAO,UAAU,UAAU;AAC7B,mBAAO;AAAA,UACT,OAAO;AACL,mBAAO,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAAA,UAC/C;AAAA,QACF;AACA,eAAO,QAAQ,OAAO;AAEtB,cAAM,UAAU,IAAI,KAAK;AACzB,YAAI,QAAQ,WAAW;AAAG,iBAAO;AAEjC,YAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAAG;AACtD,cAAI;AACF,mBAAO,KAAK,MAAM,OAAO;AAAA,UAC3B,QAAE;AACA,mBAAO;AAAA,UACT;AAAA,QACF;AACA,eAAO;AAAA,MACT,QAAE;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/requests.ts"],"sourcesContent":["/**\n * Safely read a Response/Request body with sensible defaults:\n * - clones the response/request to avoid consuming the original response/request\n * - Skips GET/HEAD\n * - Tries JSON first regardless of content-type\n * - Falls back to text and optionally parses when it \"looks\" like JSON\n */\nexport async function readBody<T extends Response | Request>(\n r: T,\n): Promise<unknown> {\n // skip GET/HEAD requests (unchanged)\n const method = \"method\" in r ? r.method.toUpperCase() : undefined;\n if (method === \"GET\" || method === \"HEAD\") {\n return undefined;\n }\n\n // no body at all → undefined (unchanged)\n if (!(\"body\" in r) || r.body == null) {\n return undefined;\n }\n\n // 1) try JSON (unchanged)\n try {\n return await r.clone().json();\n } catch {\n // 2) try text (unchanged + your whitespace/JSON-heuristic)\n try {\n const text = await r.clone().text();\n const trimmed = text.trim();\n\n if (trimmed.length === 0) return text;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return text;\n }\n }\n return text;\n } catch {\n // 3) FINAL FALLBACK: manual read that accepts string or bytes\n try {\n const c = r.clone();\n const stream: ReadableStream | null = c.body ?? null;\n if (!stream) return undefined;\n\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let out = \"\";\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (typeof value === \"string\") {\n out += value; // accept string chunks\n } else {\n out += decoder.decode(value, { stream: true }); // bytes\n }\n }\n out += decoder.decode(); // flush\n\n const trimmed = out.trim();\n if (trimmed.length === 0) return out;\n\n if (trimmed.startsWith(\"{\") || trimmed.startsWith(\"[\")) {\n try {\n return JSON.parse(trimmed);\n } catch {\n return out;\n }\n }\n return out;\n } catch {\n return undefined; // same \"give up\" behavior you had\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,eAAsB,SACpB,GACkB;AAElB,QAAM,SAAS,YAAY,IAAI,EAAE,OAAO,YAAY,IAAI;AACxD,MAAI,WAAW,SAAS,WAAW,QAAQ;AACzC,WAAO;AAAA,EACT;AAGA,MAAI,EAAE,UAAU,MAAM,EAAE,QAAQ,MAAM;AACpC,WAAO;AAAA,EACT;AAGA,MAAI;AACF,WAAO,MAAM,EAAE,MAAM,EAAE,KAAK;AAAA,EAC9B,QAAE;AAEA,QAAI;AACF,YAAM,OAAO,MAAM,EAAE,MAAM,EAAE,KAAK;AAClC,YAAM,UAAU,KAAK,KAAK;AAE1B,UAAI,QAAQ,WAAW;AAAG,eAAO;AAEjC,UAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAAG;AACtD,YAAI;AACF,iBAAO,KAAK,MAAM,OAAO;AAAA,QAC3B,QAAE;AACA,iBAAO;AAAA,QACT;AAAA,MACF;AACA,aAAO;AAAA,IACT,QAAE;AAEA,UAAI;AACF,cAAM,IAAI,EAAE,MAAM;AAClB,cAAM,SAAgC,EAAE,QAAQ;AAChD,YAAI,CAAC;AAAQ,iBAAO;AAEpB,cAAM,SAAS,OAAO,UAAU;AAChC,cAAM,UAAU,IAAI,YAAY;AAChC,YAAI,MAAM;AAEV,eAAO,MAAM;AACX,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,cAAI;AAAM;AACV,cAAI,OAAO,UAAU,UAAU;AAC7B,mBAAO;AAAA,UACT,OAAO;AACL,mBAAO,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAAA,UAC/C;AAAA,QACF;AACA,eAAO,QAAQ,OAAO;AAEtB,cAAM,UAAU,IAAI,KAAK;AACzB,YAAI,QAAQ,WAAW;AAAG,iBAAO;AAEjC,YAAI,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,GAAG,GAAG;AACtD,cAAI;AACF,mBAAO,KAAK,MAAM,OAAO;AAAA,UAC3B,QAAE;AACA,mBAAO;AAAA,UACT;AAAA,QACF;AACA,eAAO;AAAA,MACT,QAAE;AACA,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  readBody
3
- } from "../chunk-XEMZTHQZ.mjs";
3
+ } from "../chunk-WAZHII6M.mjs";
4
4
  export {
5
5
  readBody
6
6
  };
@@ -2,7 +2,7 @@ type MaybePromise<T> = T | PromiseLike<T>;
2
2
  /**
3
3
  * More specific utility for records with at least one key
4
4
  */
5
- type NonEmptyRecord<T> = T extends Record<string, unknown> ? (keyof T extends never ? never : T) : never;
5
+ type NonEmptyRecord<T> = T extends Record<string, unknown> ? keyof T extends never ? never : T : never;
6
6
  /**
7
7
  * Type representing an agent's basic information
8
8
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/types.ts"],"sourcesContent":["export type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * More specific utility for records with at least one key\n */\nexport type NonEmptyRecord<T> =\n T extends Record<string, unknown> ? (keyof T extends never ? never : T) : never;\n\n/**\n * Type representing an agent's basic information\n */\nexport interface AgentDescription {\n name: string;\n className: string;\n description: string;\n}\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/types.ts"],"sourcesContent":["export type MaybePromise<T> = T | PromiseLike<T>;\n\n/**\n * More specific utility for records with at least one key\n */\nexport type NonEmptyRecord<T> =\n T extends Record<string, unknown>\n ? keyof T extends never\n ? never\n : T\n : never;\n\n/**\n * Type representing an agent's basic information\n */\nexport interface AgentDescription {\n name: string;\n className: string;\n description: string;\n}\n\nexport interface RuntimeInfo {\n version: string;\n agents: Record<string, AgentDescription>;\n audioFileTranscriptionEnabled: boolean;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.51.4-next.6",
12
+ "version": "1.51.4-next.8",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -63,7 +63,6 @@
63
63
  "dev": "tsup --watch --no-splitting",
64
64
  "test": "jest --passWithNoTests",
65
65
  "check-types": "tsc --noEmit",
66
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next",
67
66
  "link:global": "pnpm link --global",
68
67
  "unlink:global": "pnpm unlink --global"
69
68
  }
@@ -1,4 +1,5 @@
1
1
  export const COPILOT_CLOUD_API_URL = "https://api.cloud.copilotkit.ai";
2
2
  export const COPILOT_CLOUD_VERSION = "v1";
3
3
  export const COPILOT_CLOUD_CHAT_URL = `${COPILOT_CLOUD_API_URL}/copilotkit/${COPILOT_CLOUD_VERSION}`;
4
- export const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER = "X-CopilotCloud-Public-Api-Key";
4
+ export const COPILOT_CLOUD_PUBLIC_API_KEY_HEADER =
5
+ "X-CopilotCloud-Public-Api-Key";
@@ -11,7 +11,10 @@ export type AnalyticsEvents = {
11
11
  "oss.runtime.remote_action_executed": RemoteActionExecutionInfo;
12
12
  "oss.runtime.agent_execution_stream_started": { hashedLgcKey?: string };
13
13
  "oss.runtime.agent_execution_stream_ended": AgentExecutionResponseInfo;
14
- "oss.runtime.agent_execution_stream_errored": { hashedLgcKey?: string; error?: string };
14
+ "oss.runtime.agent_execution_stream_errored": {
15
+ hashedLgcKey?: string;
16
+ error?: string;
17
+ };
15
18
  };
16
19
 
17
20
  export interface RuntimeInstanceCreatedInfo {
@@ -12,9 +12,12 @@ import scarfClient from "./scarf-client";
12
12
  */
13
13
  export function isTelemetryDisabled(): boolean {
14
14
  return (
15
- (process.env as Record<string, string | undefined>).COPILOTKIT_TELEMETRY_DISABLED === "true" ||
16
- (process.env as Record<string, string | undefined>).COPILOTKIT_TELEMETRY_DISABLED === "1" ||
17
- (process.env as Record<string, string | undefined>).DO_NOT_TRACK === "true" ||
15
+ (process.env as Record<string, string | undefined>)
16
+ .COPILOTKIT_TELEMETRY_DISABLED === "true" ||
17
+ (process.env as Record<string, string | undefined>)
18
+ .COPILOTKIT_TELEMETRY_DISABLED === "1" ||
19
+ (process.env as Record<string, string | undefined>).DO_NOT_TRACK ===
20
+ "true" ||
18
21
  (process.env as Record<string, string | undefined>).DO_NOT_TRACK === "1"
19
22
  );
20
23
  }
@@ -53,7 +56,9 @@ export class TelemetryClient {
53
56
  this.setSampleRate(sampleRate);
54
57
 
55
58
  // eslint-disable-next-line
56
- const writeKey = process.env.COPILOTKIT_SEGMENT_WRITE_KEY || "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
59
+ const writeKey =
60
+ process.env.COPILOTKIT_SEGMENT_WRITE_KEY ||
61
+ "n7XAZtQCGS2v1vvBy3LgBCv2h3Y8whja";
57
62
 
58
63
  this.segment = new Analytics({
59
64
  writeKey,
@@ -70,7 +75,10 @@ export class TelemetryClient {
70
75
  return randomNumber < this.sampleRate;
71
76
  }
72
77
 
73
- async capture<K extends keyof AnalyticsEvents>(event: K, properties: AnalyticsEvents[K]) {
78
+ async capture<K extends keyof AnalyticsEvents>(
79
+ event: K,
80
+ properties: AnalyticsEvents[K],
81
+ ) {
74
82
  if (!this.shouldSendEvent() || !this.segment) {
75
83
  return;
76
84
  }
@@ -103,7 +111,10 @@ export class TelemetryClient {
103
111
 
104
112
  setGlobalProperties(properties: Record<string, any>) {
105
113
  const flattenedProperties = flattenObject(properties);
106
- this.globalProperties = { ...this.globalProperties, ...flattenedProperties };
114
+ this.globalProperties = {
115
+ ...this.globalProperties,
116
+ ...flattenedProperties,
117
+ };
107
118
  }
108
119
 
109
120
  setCloudConfiguration(properties: { publicApiKey: string; baseUrl: string }) {
@@ -29,9 +29,13 @@ export function printSecurityNotice(advisory: {
29
29
  }[advisory.severity.toLowerCase()] || chalk.white;
30
30
 
31
31
  console.log();
32
- console.log(`━━━━━━━━━━━━━━━━━━ ${chalk.bold(`CopilotKit`)} ━━━━━━━━━━━━━━━━━━`);
32
+ console.log(
33
+ `━━━━━━━━━━━━━━━━━━ ${chalk.bold(`CopilotKit`)} ━━━━━━━━━━━━━━━━━━`,
34
+ );
33
35
  console.log();
34
- console.log(`${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`);
36
+ console.log(
37
+ `${chalk.bold(`Severity: ${severityColor(advisory.severity.toUpperCase())}`)}`,
38
+ );
35
39
  console.log();
36
40
  console.log(`${chalk.bold(advisory.message)}`);
37
41
  console.log();
@@ -31,16 +31,18 @@ interface ObjectArrayParameter extends AbstractParameter {
31
31
  attributes?: Parameter[];
32
32
  }
33
33
 
34
- type SpecialParameters = StringParameter | ObjectParameter | ObjectArrayParameter;
34
+ type SpecialParameters =
35
+ | StringParameter
36
+ | ObjectParameter
37
+ | ObjectArrayParameter;
35
38
  interface BaseParameter extends AbstractParameter {
36
39
  type?: Exclude<AbstractParameter["type"], SpecialParameters["type"]>;
37
40
  }
38
41
 
39
42
  export type Parameter = BaseParameter | SpecialParameters;
40
43
 
41
- type OptionalParameterType<P extends AbstractParameter> = P["required"] extends false
42
- ? undefined
43
- : never;
44
+ type OptionalParameterType<P extends AbstractParameter> =
45
+ P["required"] extends false ? undefined : never;
44
46
 
45
47
  type StringParameterType<P> = P extends StringParameter
46
48
  ? P extends { enum?: Array<infer E> }
@@ -61,7 +63,9 @@ type ObjectArrayParameterType<P> = P extends ObjectArrayParameter
61
63
  : never;
62
64
 
63
65
  type MappedTypeOrString<T> = T extends keyof TypeMap ? TypeMap[T] : string;
64
- type BaseParameterType<P extends AbstractParameter> = P extends { type: infer T }
66
+ type BaseParameterType<P extends AbstractParameter> = P extends {
67
+ type: infer T;
68
+ }
65
69
  ? T extends BaseParameter["type"]
66
70
  ? MappedTypeOrString<T>
67
71
  : never
@@ -1,5 +1,12 @@
1
1
  export interface CopilotErrorEvent {
2
- type: "error" | "request" | "response" | "agent_state" | "action" | "message" | "performance";
2
+ type:
3
+ | "error"
4
+ | "request"
5
+ | "response"
6
+ | "agent_state"
7
+ | "action"
8
+ | "message"
9
+ | "performance";
3
10
  timestamp: number;
4
11
  context: CopilotRequestContext;
5
12
  error?: any; // Present when type is 'error'
@@ -67,4 +74,6 @@ export interface CopilotRequestContext {
67
74
  metadata?: Record<string, any>;
68
75
  }
69
76
 
70
- export type CopilotErrorHandler = (errorEvent: CopilotErrorEvent) => void | Promise<void>;
77
+ export type CopilotErrorHandler = (
78
+ errorEvent: CopilotErrorEvent,
79
+ ) => void | Promise<void>;
@@ -32,7 +32,9 @@ export interface FunctionCallHandlerArguments {
32
32
  args: any;
33
33
  }
34
34
 
35
- export type FunctionCallHandler = (args: FunctionCallHandlerArguments) => Promise<any>;
35
+ export type FunctionCallHandler = (
36
+ args: FunctionCallHandlerArguments,
37
+ ) => Promise<any>;
36
38
 
37
39
  export type CoAgentStateRenderHandlerArguments = {
38
40
  name: string;
@@ -40,7 +42,9 @@ export type CoAgentStateRenderHandlerArguments = {
40
42
  state: any;
41
43
  };
42
44
 
43
- export type CoAgentStateRenderHandler = (args: CoAgentStateRenderHandlerArguments) => Promise<any>;
45
+ export type CoAgentStateRenderHandler = (
46
+ args: CoAgentStateRenderHandlerArguments,
47
+ ) => Promise<any>;
44
48
 
45
49
  export type AssistantMessage = {
46
50
  id: string;
@@ -32,7 +32,10 @@ export interface ExistenceCondition extends BaseCondition {
32
32
  rule: ExistenceRule;
33
33
  }
34
34
 
35
- export type Condition = ComparisonCondition | LogicalCondition | ExistenceCondition;
35
+ export type Condition =
36
+ | ComparisonCondition
37
+ | LogicalCondition
38
+ | ExistenceCondition;
36
39
 
37
40
  export function executeConditions({
38
41
  conditions,
@@ -49,16 +52,24 @@ export function executeConditions({
49
52
  }
50
53
 
51
54
  function executeCondition(condition: Condition, value: any): boolean {
52
- const targetValue = condition.path ? getValueFromPath(value, condition.path) : value;
55
+ const targetValue = condition.path
56
+ ? getValueFromPath(value, condition.path)
57
+ : value;
53
58
 
54
59
  switch (condition.rule) {
55
60
  // Logical
56
61
  case "AND":
57
- return (condition as LogicalCondition).conditions.every((c) => executeCondition(c, value));
62
+ return (condition as LogicalCondition).conditions.every((c) =>
63
+ executeCondition(c, value),
64
+ );
58
65
  case "OR":
59
- return (condition as LogicalCondition).conditions.some((c) => executeCondition(c, value));
66
+ return (condition as LogicalCondition).conditions.some((c) =>
67
+ executeCondition(c, value),
68
+ );
60
69
  case "NOT":
61
- return !(condition as LogicalCondition).conditions.every((c) => executeCondition(c, value));
70
+ return !(condition as LogicalCondition).conditions.every((c) =>
71
+ executeCondition(c, value),
72
+ );
62
73
 
63
74
  // Comparison
64
75
  case "EQUALS":
@@ -71,7 +82,8 @@ function executeCondition(condition: Condition, value: any): boolean {
71
82
  return targetValue < (condition as ComparisonCondition).value;
72
83
  case "CONTAINS":
73
84
  return (
74
- Array.isArray(targetValue) && targetValue.includes((condition as ComparisonCondition).value)
85
+ Array.isArray(targetValue) &&
86
+ targetValue.includes((condition as ComparisonCondition).value)
75
87
  );
76
88
  case "NOT_CONTAINS":
77
89
  return (
@@ -79,11 +91,17 @@ function executeCondition(condition: Condition, value: any): boolean {
79
91
  !targetValue.includes((condition as ComparisonCondition).value)
80
92
  );
81
93
  case "MATCHES":
82
- return new RegExp((condition as ComparisonCondition).value).test(String(targetValue));
94
+ return new RegExp((condition as ComparisonCondition).value).test(
95
+ String(targetValue),
96
+ );
83
97
  case "STARTS_WITH":
84
- return String(targetValue).startsWith((condition as ComparisonCondition).value);
98
+ return String(targetValue).startsWith(
99
+ (condition as ComparisonCondition).value,
100
+ );
85
101
  case "ENDS_WITH":
86
- return String(targetValue).endsWith((condition as ComparisonCondition).value);
102
+ return String(targetValue).endsWith(
103
+ (condition as ComparisonCondition).value,
104
+ );
87
105
 
88
106
  // Existence
89
107
  case "EXISTS":
@@ -105,13 +105,15 @@ export function logStyled(template: string, styles: string[]) {
105
105
  */
106
106
  export const styledConsole = {
107
107
  /** Log a success message */
108
- success: (message: string) => logStyled(`%c✅ ${message}`, [ConsoleStyles.section]),
108
+ success: (message: string) =>
109
+ logStyled(`%c✅ ${message}`, [ConsoleStyles.section]),
109
110
 
110
111
  /** Log an info message */
111
112
  info: (message: string) => logStyled(`%cℹ️ ${message}`, [ConsoleStyles.info]),
112
113
 
113
114
  /** Log a feature highlight */
114
- feature: (message: string) => logStyled(`%c✨ ${message}`, [ConsoleStyles.highlight]),
115
+ feature: (message: string) =>
116
+ logStyled(`%c✨ ${message}`, [ConsoleStyles.highlight]),
115
117
 
116
118
  /** Log a call-to-action */
117
119
  cta: (message: string) => logStyled(`%c🚀 ${message}`, [ConsoleStyles.cta]),