@inkeep/agents-core 0.6.0 → 0.6.5

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.cjs CHANGED
@@ -1813,6 +1813,22 @@ var PaginationQueryParamsSchema = zodOpenapi.z.object({
1813
1813
 
1814
1814
  // src/context/ContextConfig.ts
1815
1815
  var logger = getLogger("context-config");
1816
+ var RequestContextSchemaBuilder = class {
1817
+ constructor(options) {
1818
+ __publicField(this, "schema");
1819
+ this.schema = options.schema;
1820
+ }
1821
+ /** Template function for request context paths with type-safe autocomplete */
1822
+ toTemplate(path2) {
1823
+ return `{{requestContext.${path2}}}`;
1824
+ }
1825
+ getSchema() {
1826
+ return this.schema;
1827
+ }
1828
+ getJsonSchema() {
1829
+ return convertZodToJsonSchema(this.schema);
1830
+ }
1831
+ };
1816
1832
  function convertZodToJsonSchema(zodSchema) {
1817
1833
  try {
1818
1834
  return zod.z.toJSONSchema(zodSchema, { target: "draft-7" });
@@ -1835,23 +1851,34 @@ var ContextConfigBuilder = class {
1835
1851
  this.tenantId = options.tenantId || "default";
1836
1852
  this.projectId = options.projectId || "default";
1837
1853
  this.baseURL = process.env.INKEEP_AGENTS_MANAGE_API_URL || "http://localhost:3002";
1838
- let requestContextSchema;
1854
+ let requestContextSchema2;
1839
1855
  if (options.requestContextSchema) {
1856
+ const actualSchema = options.requestContextSchema instanceof RequestContextSchemaBuilder ? options.requestContextSchema.getSchema() : options.requestContextSchema;
1840
1857
  logger.info(
1841
1858
  {
1842
1859
  requestContextSchema: options.requestContextSchema
1843
1860
  },
1844
1861
  "Converting request headers schema to JSON Schema for database storage"
1845
1862
  );
1846
- let schema = options.requestContextSchema;
1847
- if (schema instanceof zod.z.ZodObject) {
1848
- schema = schema.loose();
1863
+ requestContextSchema2 = convertZodToJsonSchema(actualSchema);
1864
+ }
1865
+ const processedContextVariables = {};
1866
+ if (options.contextVariables) {
1867
+ for (const [key, definition] of Object.entries(options.contextVariables)) {
1868
+ const { credentialReference, ...rest } = definition;
1869
+ processedContextVariables[key] = {
1870
+ ...rest,
1871
+ responseSchema: convertZodToJsonSchema(definition.responseSchema),
1872
+ credentialReferenceId: credentialReference?.id
1873
+ };
1849
1874
  logger.debug(
1850
- { schemaType: "ZodObject" },
1851
- "Applied .loose() to ZodObject requestContextSchema for more permissive validation"
1875
+ {
1876
+ contextVariableKey: key,
1877
+ originalSchema: definition.responseSchema
1878
+ },
1879
+ "Converting contextVariable responseSchema to JSON Schema for database storage"
1852
1880
  );
1853
1881
  }
1854
- requestContextSchema = convertZodToJsonSchema(schema);
1855
1882
  }
1856
1883
  this.config = {
1857
1884
  id: options.id,
@@ -1859,8 +1886,8 @@ var ContextConfigBuilder = class {
1859
1886
  projectId: this.projectId,
1860
1887
  name: options.name,
1861
1888
  description: options.description || "",
1862
- requestContextSchema,
1863
- contextVariables: options.contextVariables || {}
1889
+ requestContextSchema: requestContextSchema2,
1890
+ contextVariables: processedContextVariables
1864
1891
  };
1865
1892
  logger.info(
1866
1893
  {
@@ -1870,6 +1897,22 @@ var ContextConfigBuilder = class {
1870
1897
  "ContextConfig builder initialized"
1871
1898
  );
1872
1899
  }
1900
+ /**
1901
+ * Convert the builder to a plain object for database operations
1902
+ */
1903
+ toObject() {
1904
+ return {
1905
+ id: this.getId(),
1906
+ tenantId: this.tenantId,
1907
+ projectId: this.projectId,
1908
+ name: this.getName(),
1909
+ description: this.getDescription(),
1910
+ requestContextSchema: this.getRequestContextSchema(),
1911
+ contextVariables: this.getContextVariables(),
1912
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1913
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1914
+ };
1915
+ }
1873
1916
  // Getter methods
1874
1917
  getId() {
1875
1918
  if (!this.config.id) {
@@ -1892,35 +1935,14 @@ var ContextConfigBuilder = class {
1892
1935
  getContextVariables() {
1893
1936
  return this.config.contextVariables || {};
1894
1937
  }
1895
- /**
1896
- * Convert the builder to a plain object for database operations
1897
- */
1898
- toObject() {
1899
- return {
1900
- id: this.getId(),
1901
- tenantId: this.tenantId,
1902
- projectId: this.projectId,
1903
- name: this.getName(),
1904
- description: this.getDescription(),
1905
- requestContextSchema: this.getRequestContextSchema(),
1906
- contextVariables: this.getContextVariables(),
1907
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1908
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1909
- };
1910
- }
1911
1938
  // Builder methods for fluent API
1912
1939
  withRequestContextSchema(schema) {
1913
1940
  this.config.requestContextSchema = schema;
1914
1941
  return this;
1915
1942
  }
1916
- withContextVariable(key, definition) {
1917
- this.config.contextVariables = this.config.contextVariables || {};
1918
- this.config.contextVariables[key] = definition;
1919
- return this;
1920
- }
1921
- withContextVariables(variables) {
1922
- this.config.contextVariables = variables;
1923
- return this;
1943
+ /** 4) The function you ship: path autocomplete + validation, returns {{path}} */
1944
+ toTemplate(path2) {
1945
+ return `{{${path2}}}`;
1924
1946
  }
1925
1947
  // Validation method
1926
1948
  validate() {
@@ -2065,15 +2087,11 @@ var ContextConfigBuilder = class {
2065
2087
  function contextConfig(options) {
2066
2088
  return new ContextConfigBuilder(options);
2067
2089
  }
2090
+ function requestContextSchema(options) {
2091
+ return new RequestContextSchemaBuilder(options);
2092
+ }
2068
2093
  function fetchDefinition(options) {
2069
- const fetchConfig = options.fetchConfig || {
2070
- url: options.url,
2071
- method: options.method,
2072
- headers: options.headers,
2073
- body: options.body,
2074
- transform: options.transform,
2075
- timeout: options.timeout
2076
- };
2094
+ const fetchConfig = options.fetchConfig;
2077
2095
  return {
2078
2096
  id: options.id,
2079
2097
  name: options.name,
@@ -2086,9 +2104,9 @@ function fetchDefinition(options) {
2086
2104
  transform: fetchConfig.transform,
2087
2105
  timeout: fetchConfig.timeout
2088
2106
  },
2089
- responseSchema: options.responseSchema ? convertZodToJsonSchema(options.responseSchema) : void 0,
2107
+ responseSchema: options.responseSchema,
2090
2108
  defaultValue: options.defaultValue,
2091
- credentialReferenceId: options.credential?.id
2109
+ credentialReferenceId: options.credentialReference?.id
2092
2110
  };
2093
2111
  }
2094
2112
  var logger2 = getLogger("template-engine");
@@ -8121,7 +8139,7 @@ var McpClient = class {
8121
8139
  if (!activeTools) return;
8122
8140
  for (const item of activeTools) {
8123
8141
  if (tools2.includes(item)) continue;
8124
- throw new Error(`[Tools] Tool ${item} not found in tools`);
8142
+ console.warn(`[Tools] Tool ${item} not found in tools`);
8125
8143
  }
8126
8144
  }
8127
8145
  async selectTools() {
@@ -8786,21 +8804,62 @@ var ContextResolver = class {
8786
8804
  var logger7 = getLogger("context-validation");
8787
8805
  var ajv = new Ajv__default.default({ allErrors: true, strict: false });
8788
8806
  var HTTP_REQUEST_PARTS = ["headers"];
8807
+ var MAX_SCHEMA_CACHE_SIZE = 1e3;
8789
8808
  var schemaCache = /* @__PURE__ */ new Map();
8790
8809
  function isValidHttpRequest(obj) {
8791
8810
  return obj != null && typeof obj === "object" && !Array.isArray(obj) && "headers" in obj;
8792
8811
  }
8793
8812
  function getCachedValidator(schema) {
8794
8813
  const key = JSON.stringify(schema);
8795
- if (!schemaCache.has(key)) {
8796
- schemaCache.set(key, ajv.compile(schema));
8814
+ if (schemaCache.has(key)) {
8815
+ const validator2 = schemaCache.get(key);
8816
+ if (!validator2) {
8817
+ throw new Error("Unexpected: validator not found in cache after has() check");
8818
+ }
8819
+ schemaCache.delete(key);
8820
+ schemaCache.set(key, validator2);
8821
+ return validator2;
8797
8822
  }
8798
- const validator = schemaCache.get(key);
8799
- if (!validator) {
8800
- throw new Error("Failed to compile JSON schema");
8823
+ if (schemaCache.size >= MAX_SCHEMA_CACHE_SIZE) {
8824
+ const firstKey = schemaCache.keys().next().value;
8825
+ if (firstKey) {
8826
+ schemaCache.delete(firstKey);
8827
+ }
8801
8828
  }
8829
+ const permissiveSchema = makeSchemaPermissive(schema);
8830
+ const validator = ajv.compile(permissiveSchema);
8831
+ schemaCache.set(key, validator);
8802
8832
  return validator;
8803
8833
  }
8834
+ function makeSchemaPermissive(schema) {
8835
+ if (!schema || typeof schema !== "object") {
8836
+ return schema;
8837
+ }
8838
+ const permissiveSchema = { ...schema };
8839
+ if (permissiveSchema.type === "object") {
8840
+ permissiveSchema.additionalProperties = true;
8841
+ if (permissiveSchema.properties && typeof permissiveSchema.properties === "object") {
8842
+ const newProperties = {};
8843
+ for (const [key, value] of Object.entries(permissiveSchema.properties)) {
8844
+ newProperties[key] = makeSchemaPermissive(value);
8845
+ }
8846
+ permissiveSchema.properties = newProperties;
8847
+ }
8848
+ }
8849
+ if (permissiveSchema.type === "array" && permissiveSchema.items) {
8850
+ permissiveSchema.items = makeSchemaPermissive(permissiveSchema.items);
8851
+ }
8852
+ if (permissiveSchema.oneOf) {
8853
+ permissiveSchema.oneOf = permissiveSchema.oneOf.map(makeSchemaPermissive);
8854
+ }
8855
+ if (permissiveSchema.anyOf) {
8856
+ permissiveSchema.anyOf = permissiveSchema.anyOf.map(makeSchemaPermissive);
8857
+ }
8858
+ if (permissiveSchema.allOf) {
8859
+ permissiveSchema.allOf = permissiveSchema.allOf.map(makeSchemaPermissive);
8860
+ }
8861
+ return permissiveSchema;
8862
+ }
8804
8863
  function validationHelper(jsonSchema) {
8805
8864
  return getCachedValidator(jsonSchema);
8806
8865
  }
@@ -10702,6 +10761,7 @@ exports.projectsRelations = projectsRelations;
10702
10761
  exports.removeArtifactComponentFromAgent = removeArtifactComponentFromAgent;
10703
10762
  exports.removeDataComponentFromAgent = removeDataComponentFromAgent;
10704
10763
  exports.removeToolFromAgent = removeToolFromAgent;
10764
+ exports.requestContextSchema = requestContextSchema;
10705
10765
  exports.resourceIdSchema = resourceIdSchema;
10706
10766
  exports.setActiveAgentForConversation = setActiveAgentForConversation;
10707
10767
  exports.setActiveAgentForThread = setActiveAgentForThread;