@inkeep/agents-core 0.5.0 → 0.6.4

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
@@ -790,6 +790,7 @@ var apiKeys = sqliteCore.sqliteTable(
790
790
  // Hashed API key (never store plaintext)
791
791
  keyPrefix: sqliteCore.text("key_prefix").notNull(),
792
792
  // First 8 chars for identification (e.g., "sk_live_abc...")
793
+ name: sqliteCore.text("name"),
793
794
  lastUsedAt: sqliteCore.text("last_used_at"),
794
795
  expiresAt: sqliteCore.text("expires_at"),
795
796
  createdAt: sqliteCore.text("created_at").notNull().default(drizzleOrm.sql`CURRENT_TIMESTAMP`),
@@ -1423,8 +1424,6 @@ var ArtifactComponentApiInsertSchema = ArtifactComponentInsertSchema.omit({
1423
1424
  projectId: true,
1424
1425
  createdAt: true,
1425
1426
  updatedAt: true
1426
- }).extend({
1427
- id: resourceIdSchema.optional()
1428
1427
  });
1429
1428
  var ArtifactComponentApiUpdateSchema = createApiUpdateSchema(
1430
1429
  ArtifactComponentUpdateSchema
@@ -1644,10 +1643,13 @@ var StatusUpdateSchema = zodOpenapi.z.object({
1644
1643
  prompt: zodOpenapi.z.string().max(2e3, "Custom prompt cannot exceed 2000 characters").optional(),
1645
1644
  statusComponents: zodOpenapi.z.array(StatusComponentSchema).optional()
1646
1645
  });
1646
+ var CanUseItemSchema = zodOpenapi.z.object({
1647
+ toolId: zodOpenapi.z.string(),
1648
+ toolSelection: zodOpenapi.z.array(zodOpenapi.z.string()).nullable().optional()
1649
+ });
1647
1650
  var FullGraphAgentInsertSchema = AgentApiInsertSchema.extend({
1648
1651
  type: zodOpenapi.z.literal("internal"),
1649
- tools: zodOpenapi.z.array(zodOpenapi.z.string()),
1650
- selectedTools: zodOpenapi.z.record(zodOpenapi.z.string(), zodOpenapi.z.array(zodOpenapi.z.string())).optional(),
1652
+ canUse: zodOpenapi.z.array(CanUseItemSchema),
1651
1653
  dataComponents: zodOpenapi.z.array(zodOpenapi.z.string()).optional(),
1652
1654
  artifactComponents: zodOpenapi.z.array(zodOpenapi.z.string()).optional(),
1653
1655
  canTransferTo: zodOpenapi.z.array(zodOpenapi.z.string()).optional(),
@@ -1811,6 +1813,22 @@ var PaginationQueryParamsSchema = zodOpenapi.z.object({
1811
1813
 
1812
1814
  // src/context/ContextConfig.ts
1813
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
+ };
1814
1832
  function convertZodToJsonSchema(zodSchema) {
1815
1833
  try {
1816
1834
  return zod.z.toJSONSchema(zodSchema, { target: "draft-7" });
@@ -1833,23 +1851,34 @@ var ContextConfigBuilder = class {
1833
1851
  this.tenantId = options.tenantId || "default";
1834
1852
  this.projectId = options.projectId || "default";
1835
1853
  this.baseURL = process.env.INKEEP_AGENTS_MANAGE_API_URL || "http://localhost:3002";
1836
- let requestContextSchema;
1854
+ let requestContextSchema2;
1837
1855
  if (options.requestContextSchema) {
1856
+ const actualSchema = options.requestContextSchema instanceof RequestContextSchemaBuilder ? options.requestContextSchema.getSchema() : options.requestContextSchema;
1838
1857
  logger.info(
1839
1858
  {
1840
1859
  requestContextSchema: options.requestContextSchema
1841
1860
  },
1842
1861
  "Converting request headers schema to JSON Schema for database storage"
1843
1862
  );
1844
- let schema = options.requestContextSchema;
1845
- if (schema instanceof zod.z.ZodObject) {
1846
- 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
+ };
1847
1874
  logger.debug(
1848
- { schemaType: "ZodObject" },
1849
- "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"
1850
1880
  );
1851
1881
  }
1852
- requestContextSchema = convertZodToJsonSchema(schema);
1853
1882
  }
1854
1883
  this.config = {
1855
1884
  id: options.id,
@@ -1857,8 +1886,8 @@ var ContextConfigBuilder = class {
1857
1886
  projectId: this.projectId,
1858
1887
  name: options.name,
1859
1888
  description: options.description || "",
1860
- requestContextSchema,
1861
- contextVariables: options.contextVariables || {}
1889
+ requestContextSchema: requestContextSchema2,
1890
+ contextVariables: processedContextVariables
1862
1891
  };
1863
1892
  logger.info(
1864
1893
  {
@@ -1868,6 +1897,22 @@ var ContextConfigBuilder = class {
1868
1897
  "ContextConfig builder initialized"
1869
1898
  );
1870
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
+ }
1871
1916
  // Getter methods
1872
1917
  getId() {
1873
1918
  if (!this.config.id) {
@@ -1890,35 +1935,14 @@ var ContextConfigBuilder = class {
1890
1935
  getContextVariables() {
1891
1936
  return this.config.contextVariables || {};
1892
1937
  }
1893
- /**
1894
- * Convert the builder to a plain object for database operations
1895
- */
1896
- toObject() {
1897
- return {
1898
- id: this.getId(),
1899
- tenantId: this.tenantId,
1900
- projectId: this.projectId,
1901
- name: this.getName(),
1902
- description: this.getDescription(),
1903
- requestContextSchema: this.getRequestContextSchema(),
1904
- contextVariables: this.getContextVariables(),
1905
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1906
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1907
- };
1908
- }
1909
1938
  // Builder methods for fluent API
1910
1939
  withRequestContextSchema(schema) {
1911
1940
  this.config.requestContextSchema = schema;
1912
1941
  return this;
1913
1942
  }
1914
- withContextVariable(key, definition) {
1915
- this.config.contextVariables = this.config.contextVariables || {};
1916
- this.config.contextVariables[key] = definition;
1917
- return this;
1918
- }
1919
- withContextVariables(variables) {
1920
- this.config.contextVariables = variables;
1921
- return this;
1943
+ /** 4) The function you ship: path autocomplete + validation, returns {{path}} */
1944
+ toTemplate(path2) {
1945
+ return `{{${path2}}}`;
1922
1946
  }
1923
1947
  // Validation method
1924
1948
  validate() {
@@ -2063,15 +2087,11 @@ var ContextConfigBuilder = class {
2063
2087
  function contextConfig(options) {
2064
2088
  return new ContextConfigBuilder(options);
2065
2089
  }
2090
+ function requestContextSchema(options) {
2091
+ return new RequestContextSchemaBuilder(options);
2092
+ }
2066
2093
  function fetchDefinition(options) {
2067
- const fetchConfig = options.fetchConfig || {
2068
- url: options.url,
2069
- method: options.method,
2070
- headers: options.headers,
2071
- body: options.body,
2072
- transform: options.transform,
2073
- timeout: options.timeout
2074
- };
2094
+ const fetchConfig = options.fetchConfig;
2075
2095
  return {
2076
2096
  id: options.id,
2077
2097
  name: options.name,
@@ -2084,9 +2104,9 @@ function fetchDefinition(options) {
2084
2104
  transform: fetchConfig.transform,
2085
2105
  timeout: fetchConfig.timeout
2086
2106
  },
2087
- responseSchema: options.responseSchema ? convertZodToJsonSchema(options.responseSchema) : void 0,
2107
+ responseSchema: options.responseSchema,
2088
2108
  defaultValue: options.defaultValue,
2089
- credentialReferenceId: options.credential?.id
2109
+ credentialReferenceId: options.credentialReference?.id
2090
2110
  };
2091
2111
  }
2092
2112
  var logger2 = getLogger("template-engine");
@@ -2609,16 +2629,21 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
2609
2629
  name: agents.name,
2610
2630
  description: agents.description,
2611
2631
  relationType: agentRelations.relationType
2612
- }).from(agentRelations).innerJoin(agents, drizzleOrm.eq(agentRelations.targetAgentId, agents.id)).where(
2632
+ }).from(agentRelations).innerJoin(
2633
+ agents,
2634
+ drizzleOrm.and(
2635
+ drizzleOrm.eq(agentRelations.targetAgentId, agents.id),
2636
+ drizzleOrm.eq(agentRelations.tenantId, agents.tenantId),
2637
+ drizzleOrm.eq(agentRelations.projectId, agents.projectId),
2638
+ drizzleOrm.eq(agentRelations.graphId, agents.graphId)
2639
+ )
2640
+ ).where(
2613
2641
  drizzleOrm.and(
2614
2642
  drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
2615
2643
  drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
2616
2644
  drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
2617
2645
  drizzleOrm.eq(agentRelations.sourceAgentId, params.agentId),
2618
- drizzleOrm.isNotNull(agentRelations.targetAgentId),
2619
- drizzleOrm.eq(agents.tenantId, params.scopes.tenantId),
2620
- drizzleOrm.eq(agents.projectId, params.scopes.projectId),
2621
- drizzleOrm.eq(agents.graphId, params.scopes.graphId)
2646
+ drizzleOrm.isNotNull(agentRelations.targetAgentId)
2622
2647
  )
2623
2648
  );
2624
2649
  const externalRelations = await db.select({
@@ -2630,16 +2655,21 @@ var getRelatedAgentsForGraph = (db) => async (params) => {
2630
2655
  description: externalAgents.description,
2631
2656
  baseUrl: externalAgents.baseUrl
2632
2657
  }
2633
- }).from(agentRelations).innerJoin(externalAgents, drizzleOrm.eq(agentRelations.externalAgentId, externalAgents.id)).where(
2658
+ }).from(agentRelations).innerJoin(
2659
+ externalAgents,
2660
+ drizzleOrm.and(
2661
+ drizzleOrm.eq(agentRelations.externalAgentId, externalAgents.id),
2662
+ drizzleOrm.eq(agentRelations.tenantId, externalAgents.tenantId),
2663
+ drizzleOrm.eq(agentRelations.projectId, externalAgents.projectId),
2664
+ drizzleOrm.eq(agentRelations.graphId, externalAgents.graphId)
2665
+ )
2666
+ ).where(
2634
2667
  drizzleOrm.and(
2635
2668
  drizzleOrm.eq(agentRelations.tenantId, params.scopes.tenantId),
2636
2669
  drizzleOrm.eq(agentRelations.projectId, params.scopes.projectId),
2637
2670
  drizzleOrm.eq(agentRelations.graphId, params.scopes.graphId),
2638
2671
  drizzleOrm.eq(agentRelations.sourceAgentId, params.agentId),
2639
- drizzleOrm.isNotNull(agentRelations.externalAgentId),
2640
- drizzleOrm.eq(externalAgents.tenantId, params.scopes.tenantId),
2641
- drizzleOrm.eq(externalAgents.projectId, params.scopes.projectId),
2642
- drizzleOrm.eq(externalAgents.graphId, params.scopes.graphId)
2672
+ drizzleOrm.isNotNull(agentRelations.externalAgentId)
2643
2673
  )
2644
2674
  );
2645
2675
  return {
@@ -2902,7 +2932,14 @@ var getToolsForAgent = (db) => async (params) => {
2902
2932
  availableTools: tools.availableTools,
2903
2933
  credentialReferenceId: tools.credentialReferenceId
2904
2934
  }
2905
- }).from(agentToolRelations).innerJoin(tools, drizzleOrm.eq(agentToolRelations.toolId, tools.id)).where(
2935
+ }).from(agentToolRelations).innerJoin(
2936
+ tools,
2937
+ drizzleOrm.and(
2938
+ drizzleOrm.eq(agentToolRelations.tenantId, tools.tenantId),
2939
+ drizzleOrm.eq(agentToolRelations.projectId, tools.projectId),
2940
+ drizzleOrm.eq(agentToolRelations.toolId, tools.id)
2941
+ )
2942
+ ).where(
2906
2943
  drizzleOrm.and(
2907
2944
  drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
2908
2945
  drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
@@ -2950,7 +2987,15 @@ var getAgentsForTool = (db) => async (params) => {
2950
2987
  createdAt: agents.createdAt,
2951
2988
  updatedAt: agents.updatedAt
2952
2989
  }
2953
- }).from(agentToolRelations).innerJoin(agents, drizzleOrm.eq(agentToolRelations.agentId, agents.id)).where(
2990
+ }).from(agentToolRelations).innerJoin(
2991
+ agents,
2992
+ drizzleOrm.and(
2993
+ drizzleOrm.eq(agentToolRelations.agentId, agents.id),
2994
+ drizzleOrm.eq(agentToolRelations.tenantId, agents.tenantId),
2995
+ drizzleOrm.eq(agentToolRelations.projectId, agents.projectId),
2996
+ drizzleOrm.eq(agentToolRelations.graphId, agents.graphId)
2997
+ )
2998
+ ).where(
2954
2999
  drizzleOrm.and(
2955
3000
  drizzleOrm.eq(agentToolRelations.tenantId, params.scopes.tenantId),
2956
3001
  drizzleOrm.eq(agentToolRelations.projectId, params.scopes.projectId),
@@ -3637,8 +3682,20 @@ var getFullGraphDefinition = (db) => async ({
3637
3682
  availableTools: tools.availableTools,
3638
3683
  lastToolsSync: tools.lastToolsSync,
3639
3684
  selectedTools: agentToolRelations.selectedTools
3640
- }).from(agentToolRelations).innerJoin(tools, drizzleOrm.eq(agentToolRelations.toolId, tools.id)).where(
3641
- drizzleOrm.and(drizzleOrm.eq(agentToolRelations.tenantId, tenantId), drizzleOrm.eq(agentToolRelations.agentId, agent.id))
3685
+ }).from(agentToolRelations).innerJoin(
3686
+ tools,
3687
+ drizzleOrm.and(
3688
+ drizzleOrm.eq(agentToolRelations.toolId, tools.id),
3689
+ drizzleOrm.eq(agentToolRelations.tenantId, tools.tenantId),
3690
+ drizzleOrm.eq(agentToolRelations.projectId, tools.projectId)
3691
+ )
3692
+ ).where(
3693
+ drizzleOrm.and(
3694
+ drizzleOrm.eq(agentToolRelations.tenantId, tenantId),
3695
+ drizzleOrm.eq(agentToolRelations.projectId, projectId),
3696
+ drizzleOrm.eq(agentToolRelations.graphId, graphId),
3697
+ drizzleOrm.eq(agentToolRelations.agentId, agent.id)
3698
+ )
3642
3699
  );
3643
3700
  const agentDataComponentRelations = await db.query.agentDataComponents.findMany({
3644
3701
  where: drizzleOrm.and(
@@ -3656,12 +3713,10 @@ var getFullGraphDefinition = (db) => async ({
3656
3713
  const agentArtifactComponentIds = agentArtifactComponentRelations.map(
3657
3714
  (rel) => rel.artifactComponentId
3658
3715
  );
3659
- const selectedTools = {};
3660
- agentTools.forEach((tool2) => {
3661
- if (tool2.selectedTools && Array.isArray(tool2.selectedTools)) {
3662
- selectedTools[tool2.id] = tool2.selectedTools;
3663
- }
3664
- });
3716
+ const canUse = agentTools.map((tool2) => ({
3717
+ toolId: tool2.id,
3718
+ toolSelection: tool2.selectedTools || null
3719
+ }));
3665
3720
  return {
3666
3721
  id: agent.id,
3667
3722
  name: agent.name,
@@ -3673,20 +3728,8 @@ var getFullGraphDefinition = (db) => async ({
3673
3728
  canDelegateTo,
3674
3729
  dataComponents: agentDataComponentIds,
3675
3730
  artifactComponents: agentArtifactComponentIds,
3676
- ...Object.keys(selectedTools).length > 0 && { selectedTools },
3677
- tools: agentTools.map((tool2) => ({
3678
- id: tool2.id,
3679
- name: tool2.name,
3680
- config: tool2.config,
3681
- imageUrl: tool2.imageUrl || void 0,
3682
- status: tool2.status,
3683
- capabilities: tool2.capabilities || void 0,
3684
- lastHealthCheck: tool2.lastHealthCheck && !Number.isNaN(new Date(tool2.lastHealthCheck).getTime()) ? new Date(tool2.lastHealthCheck).toISOString() : void 0,
3685
- lastError: tool2.lastError || void 0,
3686
- availableTools: tool2.availableTools || void 0,
3687
- activeTools: tool2.config?.mcp?.activeTools || void 0,
3688
- lastToolsSync: tool2.lastToolsSync && !Number.isNaN(new Date(tool2.lastToolsSync).getTime()) ? new Date(tool2.lastToolsSync).toISOString() : void 0
3689
- }))
3731
+ canUse
3732
+ // Use the new canUse structure
3690
3733
  };
3691
3734
  })
3692
3735
  );
@@ -3709,7 +3752,6 @@ var getFullGraphDefinition = (db) => async ({
3709
3752
  (agent) => agent !== null
3710
3753
  );
3711
3754
  const agentsObject = {};
3712
- const toolsObject = {};
3713
3755
  for (const agent of validAgents) {
3714
3756
  const isExternalAgent2 = "baseUrl" in agent && agent.baseUrl;
3715
3757
  if (isExternalAgent2) {
@@ -3720,22 +3762,7 @@ var getFullGraphDefinition = (db) => async ({
3720
3762
  baseUrl: agent.baseUrl
3721
3763
  };
3722
3764
  } else {
3723
- const toolsData = agent.tools || [];
3724
- const toolIds = [];
3725
- const agentSelectedTools = {};
3726
- for (const tool2 of toolsData) {
3727
- toolsObject[tool2.id] = tool2;
3728
- toolIds.push(tool2.id);
3729
- if (tool2.selectedTools !== null && tool2.selectedTools !== void 0) {
3730
- agentSelectedTools[tool2.id] = tool2.selectedTools;
3731
- }
3732
- }
3733
- agentsObject[agent.id] = {
3734
- ...agent,
3735
- tools: toolIds,
3736
- // Replace tool objects with tool IDs
3737
- ...Object.keys(agentSelectedTools).length > 0 && { selectedTools: agentSelectedTools }
3738
- };
3765
+ agentsObject[agent.id] = agent;
3739
3766
  }
3740
3767
  }
3741
3768
  let contextConfig2 = null;
@@ -3749,11 +3776,10 @@ var getFullGraphDefinition = (db) => async ({
3749
3776
  console.warn(`Failed to retrieve contextConfig ${graph.contextConfigId}:`, error);
3750
3777
  }
3751
3778
  }
3752
- let dataComponentsObject = {};
3753
3779
  try {
3754
3780
  const internalAgentIds = graphAgents.map((agent) => agent.id);
3755
3781
  const agentIds = Array.from(internalAgentIds);
3756
- dataComponentsObject = await fetchComponentRelationships(db)(
3782
+ await fetchComponentRelationships(db)(
3757
3783
  { tenantId, projectId },
3758
3784
  agentIds,
3759
3785
  {
@@ -3772,11 +3798,10 @@ var getFullGraphDefinition = (db) => async ({
3772
3798
  } catch (error) {
3773
3799
  console.warn("Failed to retrieve dataComponents:", error);
3774
3800
  }
3775
- let artifactComponentsObject = {};
3776
3801
  try {
3777
3802
  const internalAgentIds = graphAgents.map((agent) => agent.id);
3778
3803
  const agentIds = Array.from(internalAgentIds);
3779
- artifactComponentsObject = await fetchComponentRelationships(db)(
3804
+ await fetchComponentRelationships(db)(
3780
3805
  { tenantId, projectId },
3781
3806
  agentIds,
3782
3807
  {
@@ -3802,7 +3827,7 @@ var getFullGraphDefinition = (db) => async ({
3802
3827
  description: graph.description,
3803
3828
  defaultAgentId: graph.defaultAgentId,
3804
3829
  agents: agentsObject,
3805
- tools: toolsObject,
3830
+ // No tools field - tools are defined at project level
3806
3831
  createdAt: graph.createdAt && !Number.isNaN(new Date(graph.createdAt).getTime()) ? new Date(graph.createdAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
3807
3832
  updatedAt: graph.updatedAt && !Number.isNaN(new Date(graph.updatedAt).getTime()) ? new Date(graph.updatedAt).toISOString() : (/* @__PURE__ */ new Date()).toISOString()
3808
3833
  };
@@ -3827,12 +3852,6 @@ var getFullGraphDefinition = (db) => async ({
3827
3852
  contextVariables: contextConfig2.contextVariables
3828
3853
  };
3829
3854
  }
3830
- if (Object.keys(dataComponentsObject).length > 0) {
3831
- result.dataComponents = dataComponentsObject;
3832
- }
3833
- if (Object.keys(artifactComponentsObject).length > 0) {
3834
- result.artifactComponents = artifactComponentsObject;
3835
- }
3836
3855
  try {
3837
3856
  if (!db.query?.projects?.findFirst) {
3838
3857
  return result;
@@ -4035,6 +4054,7 @@ var createApiKey = (db) => async (params) => {
4035
4054
  const now = (/* @__PURE__ */ new Date()).toISOString();
4036
4055
  const [apiKey] = await db.insert(apiKeys).values({
4037
4056
  id: params.id,
4057
+ name: params.name,
4038
4058
  tenantId: params.tenantId,
4039
4059
  projectId: params.projectId,
4040
4060
  graphId: params.graphId,
@@ -4050,6 +4070,7 @@ var createApiKey = (db) => async (params) => {
4050
4070
  var updateApiKey = (db) => async (params) => {
4051
4071
  const now = (/* @__PURE__ */ new Date()).toISOString();
4052
4072
  const [updatedKey] = await db.update(apiKeys).set({
4073
+ name: params.data.name,
4053
4074
  expiresAt: params.data.expiresAt,
4054
4075
  updatedAt: now
4055
4076
  }).where(
@@ -4103,12 +4124,13 @@ var countApiKeys = (db) => async (params) => {
4103
4124
  return typeof total === "string" ? Number.parseInt(total, 10) : total;
4104
4125
  };
4105
4126
  var generateAndCreateApiKey = async (params, db) => {
4106
- const { tenantId, projectId, graphId, expiresAt } = params;
4127
+ const { tenantId, projectId, graphId, expiresAt, name } = params;
4107
4128
  const keyData = await generateApiKey();
4108
4129
  const apiKey = await createApiKey(db)({
4109
4130
  tenantId,
4110
4131
  projectId,
4111
4132
  graphId,
4133
+ name,
4112
4134
  expiresAt,
4113
4135
  ...keyData
4114
4136
  });
@@ -4304,7 +4326,21 @@ var isArtifactComponentAssociatedWithAgent = (db) => async (params) => {
4304
4326
  return result.length > 0;
4305
4327
  };
4306
4328
  var graphHasArtifactComponents = (db) => async (params) => {
4307
- const result = await db.select({ count: drizzleOrm.count() }).from(agentArtifactComponents).innerJoin(agents, drizzleOrm.eq(agentArtifactComponents.agentId, agents.id)).innerJoin(agentRelations, drizzleOrm.eq(agents.id, agentRelations.sourceAgentId)).where(
4329
+ const result = await db.select({ count: drizzleOrm.count() }).from(agentArtifactComponents).innerJoin(
4330
+ agents,
4331
+ drizzleOrm.and(
4332
+ drizzleOrm.eq(agentArtifactComponents.agentId, agents.id),
4333
+ drizzleOrm.eq(agentArtifactComponents.tenantId, agents.tenantId)
4334
+ )
4335
+ ).innerJoin(
4336
+ agentRelations,
4337
+ drizzleOrm.and(
4338
+ drizzleOrm.eq(agents.id, agentRelations.sourceAgentId),
4339
+ drizzleOrm.eq(agents.tenantId, agentRelations.tenantId),
4340
+ drizzleOrm.eq(agents.projectId, agentRelations.projectId),
4341
+ drizzleOrm.eq(agents.graphId, agentRelations.graphId)
4342
+ )
4343
+ ).where(
4308
4344
  drizzleOrm.and(
4309
4345
  drizzleOrm.eq(agentArtifactComponents.tenantId, params.scopes.tenantId),
4310
4346
  drizzleOrm.eq(agentArtifactComponents.projectId, params.scopes.projectId),
@@ -5067,10 +5103,10 @@ function validateToolReferences(graphData, availableToolIds) {
5067
5103
  }
5068
5104
  const errors = [];
5069
5105
  for (const [agentId, agentData] of Object.entries(graphData.agents)) {
5070
- if (isInternalAgent(agentData) && agentData.tools && Array.isArray(agentData.tools)) {
5071
- for (const toolId of agentData.tools) {
5072
- if (!availableToolIds.has(toolId)) {
5073
- errors.push(`Agent '${agentId}' references non-existent tool '${toolId}'`);
5106
+ if (isInternalAgent(agentData) && agentData.canUse && Array.isArray(agentData.canUse)) {
5107
+ for (const canUseItem of agentData.canUse) {
5108
+ if (!availableToolIds.has(canUseItem.toolId)) {
5109
+ errors.push(`Agent '${agentId}' references non-existent tool '${canUseItem.toolId}'`);
5074
5110
  }
5075
5111
  }
5076
5112
  }
@@ -5605,22 +5641,22 @@ var createFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
5605
5641
  }
5606
5642
  const agentToolPromises = [];
5607
5643
  for (const [agentId, agentData] of Object.entries(typed.agents)) {
5608
- if (isInternalAgent(agentData) && agentData.tools && Array.isArray(agentData.tools)) {
5609
- for (const toolId of agentData.tools) {
5644
+ if (isInternalAgent(agentData) && agentData.canUse && Array.isArray(agentData.canUse)) {
5645
+ for (const canUseItem of agentData.canUse) {
5610
5646
  agentToolPromises.push(
5611
5647
  (async () => {
5612
5648
  try {
5613
- const selectedTools = agentData.selectedTools?.[toolId];
5649
+ const { toolId, toolSelection } = canUseItem;
5614
5650
  logger11.info({ agentId, toolId }, "Processing agent-tool relation");
5615
5651
  await upsertAgentToolRelation(db)({
5616
5652
  scopes: { tenantId, projectId, graphId: finalGraphId },
5617
5653
  agentId,
5618
5654
  toolId,
5619
- selectedTools
5655
+ selectedTools: toolSelection || void 0
5620
5656
  });
5621
5657
  logger11.info({ agentId, toolId }, "Agent-tool relation processed successfully");
5622
5658
  } catch (error) {
5623
- logger11.error({ agentId, toolId, error }, "Failed to create agent-tool relation");
5659
+ logger11.error({ agentId, toolId: canUseItem.toolId, error }, "Failed to create agent-tool relation");
5624
5660
  }
5625
5661
  })()
5626
5662
  );
@@ -5998,23 +6034,23 @@ var updateFullGraphServerSide = (db, logger11 = defaultLogger) => async (scopes,
5998
6034
  }
5999
6035
  const agentToolPromises = [];
6000
6036
  for (const [agentId, agentData] of Object.entries(typedGraphDefinition.agents)) {
6001
- if (isInternalAgent(agentData) && agentData.tools && Array.isArray(agentData.tools)) {
6002
- for (const toolId of agentData.tools) {
6037
+ if (isInternalAgent(agentData) && agentData.canUse && Array.isArray(agentData.canUse)) {
6038
+ for (const canUseItem of agentData.canUse) {
6003
6039
  agentToolPromises.push(
6004
6040
  (async () => {
6005
6041
  try {
6006
- const selectedTools = agentData.selectedTools?.[toolId];
6042
+ const { toolId, toolSelection } = canUseItem;
6007
6043
  await createAgentToolRelation(db)({
6008
6044
  scopes: { tenantId, projectId, graphId: finalGraphId },
6009
6045
  data: {
6010
6046
  agentId,
6011
6047
  toolId,
6012
- selectedTools
6048
+ selectedTools: toolSelection || void 0
6013
6049
  }
6014
6050
  });
6015
6051
  logger11.info({ agentId, toolId }, "Agent-tool relation created");
6016
6052
  } catch (error) {
6017
- logger11.error({ agentId, toolId, error }, "Failed to create agent-tool relation");
6053
+ logger11.error({ agentId, toolId: canUseItem.toolId, error }, "Failed to create agent-tool relation");
6018
6054
  }
6019
6055
  })()
6020
6056
  );
@@ -6878,7 +6914,6 @@ var createFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
6878
6914
  );
6879
6915
  await upsertArtifactComponent(db)({
6880
6916
  data: {
6881
- id: componentId,
6882
6917
  ...componentData,
6883
6918
  tenantId,
6884
6919
  projectId: typed.id
@@ -7184,7 +7219,6 @@ var updateFullProjectServerSide = (db, logger11 = defaultLogger2) => async (scop
7184
7219
  );
7185
7220
  await upsertArtifactComponent(db)({
7186
7221
  data: {
7187
- id: componentId,
7188
7222
  ...componentData,
7189
7223
  tenantId,
7190
7224
  projectId: typed.id
@@ -7310,14 +7344,10 @@ var getFullProject = (db, logger11 = defaultLogger2) => async (params) => {
7310
7344
  id: tool2.id,
7311
7345
  name: tool2.name,
7312
7346
  config: tool2.config,
7313
- imageUrl: tool2.imageUrl || void 0,
7314
- status: tool2.status,
7315
- capabilities: tool2.capabilities || void 0,
7316
- lastHealthCheck: tool2.lastHealthCheck && !Number.isNaN(new Date(tool2.lastHealthCheck).getTime()) ? new Date(tool2.lastHealthCheck).toISOString() : void 0,
7317
- lastError: tool2.lastError || void 0,
7318
- availableTools: tool2.availableTools || void 0,
7319
- activeTools: tool2.config?.mcp?.activeTools || void 0,
7320
- lastToolsSync: tool2.lastToolsSync && !Number.isNaN(new Date(tool2.lastToolsSync).getTime()) ? new Date(tool2.lastToolsSync).toISOString() : void 0
7347
+ credentialReferenceId: tool2.credentialReferenceId || void 0,
7348
+ imageUrl: tool2.imageUrl || void 0
7349
+ // Don't include runtime fields in configuration
7350
+ // status, capabilities, lastHealthCheck, lastError, availableTools, activeTools, lastToolsSync are all runtime
7321
7351
  };
7322
7352
  }
7323
7353
  logger11.info(
@@ -8774,21 +8804,62 @@ var ContextResolver = class {
8774
8804
  var logger7 = getLogger("context-validation");
8775
8805
  var ajv = new Ajv__default.default({ allErrors: true, strict: false });
8776
8806
  var HTTP_REQUEST_PARTS = ["headers"];
8807
+ var MAX_SCHEMA_CACHE_SIZE = 1e3;
8777
8808
  var schemaCache = /* @__PURE__ */ new Map();
8778
8809
  function isValidHttpRequest(obj) {
8779
8810
  return obj != null && typeof obj === "object" && !Array.isArray(obj) && "headers" in obj;
8780
8811
  }
8781
8812
  function getCachedValidator(schema) {
8782
8813
  const key = JSON.stringify(schema);
8783
- if (!schemaCache.has(key)) {
8784
- 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;
8785
8822
  }
8786
- const validator = schemaCache.get(key);
8787
- if (!validator) {
8788
- 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
+ }
8789
8828
  }
8829
+ const permissiveSchema = makeSchemaPermissive(schema);
8830
+ const validator = ajv.compile(permissiveSchema);
8831
+ schemaCache.set(key, validator);
8790
8832
  return validator;
8791
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
+ }
8792
8863
  function validationHelper(jsonSchema) {
8793
8864
  return getCachedValidator(jsonSchema);
8794
8865
  }
@@ -10233,7 +10304,7 @@ var loadEnvironmentFiles = () => {
10233
10304
  loadEnvironmentFiles();
10234
10305
  var envSchema = zod.z.object({
10235
10306
  ENVIRONMENT: zod.z.enum(["development", "production", "pentest", "test"]).optional(),
10236
- DB_FILE_NAME: zod.z.string(),
10307
+ DB_FILE_NAME: zod.z.string().optional(),
10237
10308
  OTEL_TRACES_FORCE_FLUSH_ENABLED: zod.z.coerce.boolean().optional()
10238
10309
  });
10239
10310
  var parseEnv = () => {
@@ -10323,6 +10394,7 @@ exports.ArtifactComponentApiUpdateSchema = ArtifactComponentApiUpdateSchema;
10323
10394
  exports.ArtifactComponentInsertSchema = ArtifactComponentInsertSchema;
10324
10395
  exports.ArtifactComponentSelectSchema = ArtifactComponentSelectSchema;
10325
10396
  exports.ArtifactComponentUpdateSchema = ArtifactComponentUpdateSchema;
10397
+ exports.CanUseItemSchema = CanUseItemSchema;
10326
10398
  exports.ContextCache = ContextCache;
10327
10399
  exports.ContextCacheApiInsertSchema = ContextCacheApiInsertSchema;
10328
10400
  exports.ContextCacheApiSelectSchema = ContextCacheApiSelectSchema;
@@ -10689,6 +10761,7 @@ exports.projectsRelations = projectsRelations;
10689
10761
  exports.removeArtifactComponentFromAgent = removeArtifactComponentFromAgent;
10690
10762
  exports.removeDataComponentFromAgent = removeDataComponentFromAgent;
10691
10763
  exports.removeToolFromAgent = removeToolFromAgent;
10764
+ exports.requestContextSchema = requestContextSchema;
10692
10765
  exports.resourceIdSchema = resourceIdSchema;
10693
10766
  exports.setActiveAgentForConversation = setActiveAgentForConversation;
10694
10767
  exports.setActiveAgentForThread = setActiveAgentForThread;