@inkeep/agents-core 0.14.3 → 0.14.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.
@@ -115,7 +115,7 @@ var agentGraph = sqliteTable(
115
115
  var contextConfigs = sqliteTable(
116
116
  "context_configs",
117
117
  {
118
- ...projectScoped,
118
+ ...graphScoped,
119
119
  ...uiProperties,
120
120
  // Developer-defined Zod schema for validating incoming request context
121
121
  requestContextSchema: blob("request_context_schema", { mode: "json" }).$type(),
@@ -125,11 +125,11 @@ var contextConfigs = sqliteTable(
125
125
  ...timestamps
126
126
  },
127
127
  (table) => [
128
- primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
128
+ primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
129
129
  foreignKey({
130
- columns: [table.tenantId, table.projectId],
131
- foreignColumns: [projects.tenantId, projects.id],
132
- name: "context_configs_project_fk"
130
+ columns: [table.tenantId, table.projectId, table.graphId],
131
+ foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
132
+ name: "context_configs_graph_fk"
133
133
  }).onDelete("cascade")
134
134
  ]
135
135
  );
@@ -1,5 +1,5 @@
1
+ import { agents, agentRelations, agentGraph, tasks, taskRelations, tools, conversations, messages, contextCache, dataComponents, agentDataComponents, artifactComponents, agentArtifactComponents, externalAgents, apiKeys, credentialReferences, contextConfigs, agentToolRelations, ledgerArtifacts, projects } from './chunk-AHSEMW6N.js';
1
2
  import { VALID_RELATION_TYPES, MCPTransportType, TOOL_STATUS_VALUES, CredentialStoreType, MCPServerType } from './chunk-YFHT5M2R.js';
2
- import { agents, agentRelations, agentGraph, tasks, taskRelations, tools, conversations, messages, contextCache, dataComponents, agentDataComponents, artifactComponents, agentArtifactComponents, externalAgents, apiKeys, credentialReferences, contextConfigs, agentToolRelations, ledgerArtifacts, projects } from './chunk-KBRQN63H.js';
3
3
  import { z } from '@hono/zod-openapi';
4
4
  import { createSelectSchema, createInsertSchema } from 'drizzle-zod';
5
5
 
@@ -1,4 +1,4 @@
1
- import { FullGraphDefinitionSchema, resourceIdSchema, MAX_ID_LENGTH } from './chunk-AGEHLZUK.js';
1
+ import { FullGraphDefinitionSchema, resourceIdSchema, MAX_ID_LENGTH } from './chunk-C4PFKKRE.js';
2
2
 
3
3
  // src/validation/graphFull.ts
4
4
  function isInternalAgent(agent) {
@@ -93,7 +93,7 @@ var agentGraph = sqliteCore.sqliteTable(
93
93
  var contextConfigs = sqliteCore.sqliteTable(
94
94
  "context_configs",
95
95
  {
96
- ...projectScoped,
96
+ ...graphScoped,
97
97
  ...uiProperties,
98
98
  // Developer-defined Zod schema for validating incoming request context
99
99
  requestContextSchema: sqliteCore.blob("request_context_schema", { mode: "json" }).$type(),
@@ -103,11 +103,11 @@ var contextConfigs = sqliteCore.sqliteTable(
103
103
  ...timestamps
104
104
  },
105
105
  (table) => [
106
- sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
106
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
107
107
  sqliteCore.foreignKey({
108
- columns: [table.tenantId, table.projectId],
109
- foreignColumns: [projects.tenantId, projects.id],
110
- name: "context_configs_project_fk"
108
+ columns: [table.tenantId, table.projectId, table.graphId],
109
+ foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
110
+ name: "context_configs_graph_fk"
111
111
  }).onDelete("cascade")
112
112
  ]
113
113
  );
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { C as ConversationHistoryConfig, A as ApiKeyApiUpdateSchema, F as FullGraphAgentInsertSchema } from './utility-Cd0qsewS.cjs';
3
- export { d as AgentStopWhen, a as AgentStopWhenSchema, e as CredentialStoreType, c as GraphStopWhen, G as GraphStopWhenSchema, M as MCPTransportType, b as StopWhen, S as StopWhenSchema } from './utility-Cd0qsewS.cjs';
2
+ import { C as ConversationHistoryConfig, A as ApiKeyApiUpdateSchema, F as FullGraphAgentInsertSchema } from './utility-POey8vOB.cjs';
3
+ export { d as AgentStopWhen, a as AgentStopWhenSchema, e as CredentialStoreType, c as GraphStopWhen, G as GraphStopWhenSchema, M as MCPTransportType, b as StopWhen, S as StopWhenSchema } from './utility-POey8vOB.cjs';
4
4
  import 'drizzle-zod';
5
5
  import 'drizzle-orm/sqlite-core';
6
6
  import '@hono/zod-openapi';
@@ -67,8 +67,8 @@ declare const AgentApiInsertSchema: z.ZodObject<{
67
67
  canTransferTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
68
68
  canDelegateTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
69
  type: z.ZodOptional<z.ZodEnum<{
70
- internal: "internal";
71
70
  external: "external";
71
+ internal: "internal";
72
72
  }>>;
73
73
  }, z.core.$strip>;
74
74
  declare const ToolApiInsertSchema: z.ZodObject<{
@@ -168,13 +168,11 @@ declare const FullGraphDefinitionSchema: z.ZodObject<{
168
168
  description: z.ZodOptional<z.ZodString>;
169
169
  defaultAgentId: z.ZodOptional<z.ZodString>;
170
170
  agents: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
171
- id: z.ZodString;
172
171
  name: z.ZodString;
173
- description: z.ZodString;
174
- prompt: z.ZodString;
172
+ id: z.ZodString;
175
173
  createdAt: z.ZodOptional<z.ZodString>;
176
174
  updatedAt: z.ZodOptional<z.ZodString>;
177
- conversationHistoryConfig: z.ZodOptional<z.ZodNullable<z.ZodType<ConversationHistoryConfig, ConversationHistoryConfig, z.core.$ZodTypeInternals<ConversationHistoryConfig, ConversationHistoryConfig>>>>;
175
+ description: z.ZodString;
178
176
  models: z.ZodOptional<z.ZodObject<{
179
177
  base: z.ZodOptional<z.ZodObject<{
180
178
  model: z.ZodOptional<z.ZodString>;
@@ -198,6 +196,8 @@ declare const FullGraphDefinitionSchema: z.ZodObject<{
198
196
  }, {
199
197
  stepCountIs?: number | undefined;
200
198
  }>>>>;
199
+ prompt: z.ZodString;
200
+ conversationHistoryConfig: z.ZodOptional<z.ZodNullable<z.ZodType<ConversationHistoryConfig, ConversationHistoryConfig, z.core.$ZodTypeInternals<ConversationHistoryConfig, ConversationHistoryConfig>>>>;
201
201
  type: z.ZodLiteral<"internal">;
202
202
  canUse: z.ZodArray<z.ZodObject<{
203
203
  agentToolRelationId: z.ZodOptional<z.ZodString>;
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { C as ConversationHistoryConfig, A as ApiKeyApiUpdateSchema, F as FullGraphAgentInsertSchema } from './utility-Cd0qsewS.js';
3
- export { d as AgentStopWhen, a as AgentStopWhenSchema, e as CredentialStoreType, c as GraphStopWhen, G as GraphStopWhenSchema, M as MCPTransportType, b as StopWhen, S as StopWhenSchema } from './utility-Cd0qsewS.js';
2
+ import { C as ConversationHistoryConfig, A as ApiKeyApiUpdateSchema, F as FullGraphAgentInsertSchema } from './utility-POey8vOB.js';
3
+ export { d as AgentStopWhen, a as AgentStopWhenSchema, e as CredentialStoreType, c as GraphStopWhen, G as GraphStopWhenSchema, M as MCPTransportType, b as StopWhen, S as StopWhenSchema } from './utility-POey8vOB.js';
4
4
  import 'drizzle-zod';
5
5
  import 'drizzle-orm/sqlite-core';
6
6
  import '@hono/zod-openapi';
@@ -67,8 +67,8 @@ declare const AgentApiInsertSchema: z.ZodObject<{
67
67
  canTransferTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
68
68
  canDelegateTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
69
  type: z.ZodOptional<z.ZodEnum<{
70
- internal: "internal";
71
70
  external: "external";
71
+ internal: "internal";
72
72
  }>>;
73
73
  }, z.core.$strip>;
74
74
  declare const ToolApiInsertSchema: z.ZodObject<{
@@ -168,13 +168,11 @@ declare const FullGraphDefinitionSchema: z.ZodObject<{
168
168
  description: z.ZodOptional<z.ZodString>;
169
169
  defaultAgentId: z.ZodOptional<z.ZodString>;
170
170
  agents: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
171
- id: z.ZodString;
172
171
  name: z.ZodString;
173
- description: z.ZodString;
174
- prompt: z.ZodString;
172
+ id: z.ZodString;
175
173
  createdAt: z.ZodOptional<z.ZodString>;
176
174
  updatedAt: z.ZodOptional<z.ZodString>;
177
- conversationHistoryConfig: z.ZodOptional<z.ZodNullable<z.ZodType<ConversationHistoryConfig, ConversationHistoryConfig, z.core.$ZodTypeInternals<ConversationHistoryConfig, ConversationHistoryConfig>>>>;
175
+ description: z.ZodString;
178
176
  models: z.ZodOptional<z.ZodObject<{
179
177
  base: z.ZodOptional<z.ZodObject<{
180
178
  model: z.ZodOptional<z.ZodString>;
@@ -198,6 +196,8 @@ declare const FullGraphDefinitionSchema: z.ZodObject<{
198
196
  }, {
199
197
  stepCountIs?: number | undefined;
200
198
  }>>>>;
199
+ prompt: z.ZodString;
200
+ conversationHistoryConfig: z.ZodOptional<z.ZodNullable<z.ZodType<ConversationHistoryConfig, ConversationHistoryConfig, z.core.$ZodTypeInternals<ConversationHistoryConfig, ConversationHistoryConfig>>>>;
201
201
  type: z.ZodLiteral<"internal">;
202
202
  canUse: z.ZodArray<z.ZodObject<{
203
203
  agentToolRelationId: z.ZodOptional<z.ZodString>;
@@ -1,5 +1,5 @@
1
- import { FullGraphAgentInsertSchema } from './chunk-AGEHLZUK.js';
2
- export { AgentStopWhenSchema, GraphStopWhenSchema, StopWhenSchema } from './chunk-AGEHLZUK.js';
1
+ import { FullGraphAgentInsertSchema } from './chunk-C4PFKKRE.js';
2
+ export { AgentStopWhenSchema, GraphStopWhenSchema, StopWhenSchema } from './chunk-C4PFKKRE.js';
3
3
  import { CredentialStoreType } from './chunk-YFHT5M2R.js';
4
4
  export { CredentialStoreType, MCPTransportType } from './chunk-YFHT5M2R.js';
5
5
  import { z } from 'zod';
@@ -73,7 +73,7 @@ var agentGraph = sqliteCore.sqliteTable(
73
73
  var contextConfigs = sqliteCore.sqliteTable(
74
74
  "context_configs",
75
75
  {
76
- ...projectScoped,
76
+ ...graphScoped,
77
77
  ...uiProperties,
78
78
  // Developer-defined Zod schema for validating incoming request context
79
79
  requestContextSchema: sqliteCore.blob("request_context_schema", { mode: "json" }).$type(),
@@ -83,11 +83,11 @@ var contextConfigs = sqliteCore.sqliteTable(
83
83
  ...timestamps
84
84
  },
85
85
  (table) => [
86
- sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
86
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
87
87
  sqliteCore.foreignKey({
88
- columns: [table.tenantId, table.projectId],
89
- foreignColumns: [projects.tenantId, projects.id],
90
- name: "context_configs_project_fk"
88
+ columns: [table.tenantId, table.projectId, table.graphId],
89
+ foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
90
+ name: "context_configs_graph_fk"
91
91
  }).onDelete("cascade")
92
92
  ]
93
93
  );
@@ -1,7 +1,7 @@
1
1
  import 'drizzle-orm';
2
2
  import 'drizzle-orm/sqlite-core';
3
- import '../utility-Cd0qsewS.cjs';
4
- export { k as agentArtifactComponents, K as agentArtifactComponentsRelations, i as agentDataComponents, M as agentDataComponentsRelations, a as agentGraph, B as agentGraphRelations, e as agentRelations, O as agentRelationsRelations, m as agentToolRelations, E as agentToolRelationsRelations, d as agents, A as agentsRelations, r as apiKeys, D as apiKeysRelations, j as artifactComponents, J as artifactComponentsRelations, b as contextCache, z as contextCacheRelations, c as contextConfigs, y as contextConfigsRelations, n as conversations, H as conversationsRelations, u as credentialReferences, F as credentialReferencesRelations, h as dataComponents, L as dataComponentsRelations, f as externalAgents, C as externalAgentsRelations, q as ledgerArtifacts, N as ledgerArtifactsRelations, o as messages, I as messagesRelations, p as projects, w as projectsRelations, g as taskRelations, x as taskRelationsRelations, t as tasks, v as tasksRelations, l as tools, G as toolsRelations } from '../schema-DDUpvlcp.cjs';
3
+ import '../utility-POey8vOB.cjs';
4
+ export { k as agentArtifactComponents, K as agentArtifactComponentsRelations, i as agentDataComponents, M as agentDataComponentsRelations, a as agentGraph, B as agentGraphRelations, e as agentRelations, O as agentRelationsRelations, m as agentToolRelations, E as agentToolRelationsRelations, d as agents, A as agentsRelations, r as apiKeys, D as apiKeysRelations, j as artifactComponents, J as artifactComponentsRelations, b as contextCache, z as contextCacheRelations, c as contextConfigs, y as contextConfigsRelations, n as conversations, H as conversationsRelations, u as credentialReferences, F as credentialReferencesRelations, h as dataComponents, L as dataComponentsRelations, f as externalAgents, C as externalAgentsRelations, q as ledgerArtifacts, N as ledgerArtifactsRelations, o as messages, I as messagesRelations, p as projects, w as projectsRelations, g as taskRelations, x as taskRelationsRelations, t as tasks, v as tasksRelations, l as tools, G as toolsRelations } from '../schema-Cb-8k7aM.cjs';
5
5
  import 'zod';
6
6
  import 'drizzle-zod';
7
7
  import '@hono/zod-openapi';
@@ -1,7 +1,7 @@
1
1
  import 'drizzle-orm';
2
2
  import 'drizzle-orm/sqlite-core';
3
- import '../utility-Cd0qsewS.js';
4
- export { k as agentArtifactComponents, K as agentArtifactComponentsRelations, i as agentDataComponents, M as agentDataComponentsRelations, a as agentGraph, B as agentGraphRelations, e as agentRelations, O as agentRelationsRelations, m as agentToolRelations, E as agentToolRelationsRelations, d as agents, A as agentsRelations, r as apiKeys, D as apiKeysRelations, j as artifactComponents, J as artifactComponentsRelations, b as contextCache, z as contextCacheRelations, c as contextConfigs, y as contextConfigsRelations, n as conversations, H as conversationsRelations, u as credentialReferences, F as credentialReferencesRelations, h as dataComponents, L as dataComponentsRelations, f as externalAgents, C as externalAgentsRelations, q as ledgerArtifacts, N as ledgerArtifactsRelations, o as messages, I as messagesRelations, p as projects, w as projectsRelations, g as taskRelations, x as taskRelationsRelations, t as tasks, v as tasksRelations, l as tools, G as toolsRelations } from '../schema-BB_Q_YNK.js';
3
+ import '../utility-POey8vOB.js';
4
+ export { k as agentArtifactComponents, K as agentArtifactComponentsRelations, i as agentDataComponents, M as agentDataComponentsRelations, a as agentGraph, B as agentGraphRelations, e as agentRelations, O as agentRelationsRelations, m as agentToolRelations, E as agentToolRelationsRelations, d as agents, A as agentsRelations, r as apiKeys, D as apiKeysRelations, j as artifactComponents, J as artifactComponentsRelations, b as contextCache, z as contextCacheRelations, c as contextConfigs, y as contextConfigsRelations, n as conversations, H as conversationsRelations, u as credentialReferences, F as credentialReferencesRelations, h as dataComponents, L as dataComponentsRelations, f as externalAgents, C as externalAgentsRelations, q as ledgerArtifacts, N as ledgerArtifactsRelations, o as messages, I as messagesRelations, p as projects, w as projectsRelations, g as taskRelations, x as taskRelationsRelations, t as tasks, v as tasksRelations, l as tools, G as toolsRelations } from '../schema-CFoAzEjh.js';
5
5
  import 'zod';
6
6
  import 'drizzle-zod';
7
7
  import '@hono/zod-openapi';
package/dist/db/schema.js CHANGED
@@ -1 +1 @@
1
- export { agentArtifactComponents, agentArtifactComponentsRelations, agentDataComponents, agentDataComponentsRelations, agentGraph, agentGraphRelations, agentRelations, agentRelationsRelations, agentToolRelations, agentToolRelationsRelations, agents, agentsRelations, apiKeys, apiKeysRelations, artifactComponents, artifactComponentsRelations, contextCache, contextCacheRelations, contextConfigs, contextConfigsRelations, conversations, conversationsRelations, credentialReferences, credentialReferencesRelations, dataComponents, dataComponentsRelations, externalAgents, externalAgentsRelations, ledgerArtifacts, ledgerArtifactsRelations, messages, messagesRelations, projects, projectsRelations, taskRelations, taskRelationsRelations, tasks, tasksRelations, tools, toolsRelations } from '../chunk-KBRQN63H.js';
1
+ export { agentArtifactComponents, agentArtifactComponentsRelations, agentDataComponents, agentDataComponentsRelations, agentGraph, agentGraphRelations, agentRelations, agentRelationsRelations, agentToolRelations, agentToolRelationsRelations, agents, agentsRelations, apiKeys, apiKeysRelations, artifactComponents, artifactComponentsRelations, contextCache, contextCacheRelations, contextConfigs, contextConfigsRelations, conversations, conversationsRelations, credentialReferences, credentialReferencesRelations, dataComponents, dataComponentsRelations, externalAgents, externalAgentsRelations, ledgerArtifacts, ledgerArtifactsRelations, messages, messagesRelations, projects, projectsRelations, taskRelations, taskRelationsRelations, tasks, tasksRelations, tools, toolsRelations } from '../chunk-AHSEMW6N.js';
package/dist/index.cjs CHANGED
@@ -334,7 +334,7 @@ var agentGraph = sqliteCore.sqliteTable(
334
334
  var contextConfigs = sqliteCore.sqliteTable(
335
335
  "context_configs",
336
336
  {
337
- ...projectScoped,
337
+ ...graphScoped,
338
338
  ...uiProperties,
339
339
  // Developer-defined Zod schema for validating incoming request context
340
340
  requestContextSchema: sqliteCore.blob("request_context_schema", { mode: "json" }).$type(),
@@ -344,11 +344,11 @@ var contextConfigs = sqliteCore.sqliteTable(
344
344
  ...timestamps
345
345
  },
346
346
  (table) => [
347
- sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.id] }),
347
+ sqliteCore.primaryKey({ columns: [table.tenantId, table.projectId, table.graphId, table.id] }),
348
348
  sqliteCore.foreignKey({
349
- columns: [table.tenantId, table.projectId],
350
- foreignColumns: [projects.tenantId, projects.id],
351
- name: "context_configs_project_fk"
349
+ columns: [table.tenantId, table.projectId, table.graphId],
350
+ foreignColumns: [agentGraph.tenantId, agentGraph.projectId, agentGraph.id],
351
+ name: "context_configs_graph_fk"
352
352
  }).onDelete("cascade")
353
353
  ]
354
354
  );
@@ -1734,8 +1734,10 @@ var ContextConfigBuilder = class {
1734
1734
  __publicField(this, "baseURL");
1735
1735
  __publicField(this, "tenantId");
1736
1736
  __publicField(this, "projectId");
1737
+ __publicField(this, "graphId");
1737
1738
  this.tenantId = options.tenantId || "default";
1738
1739
  this.projectId = options.projectId || "default";
1740
+ this.graphId = options.graphId || "default";
1739
1741
  this.baseURL = process.env.INKEEP_AGENTS_MANAGE_API_URL || "http://localhost:3002";
1740
1742
  let requestContextSchema2;
1741
1743
  if (options.requestContextSchema) {
@@ -1789,9 +1791,10 @@ var ContextConfigBuilder = class {
1789
1791
  * Set the context (tenantId, projectId, baseURL) for this context config
1790
1792
  * Called by graph.setConfig() when the graph is configured
1791
1793
  */
1792
- setContext(tenantId, projectId, baseURL) {
1794
+ setContext(tenantId, projectId, graphId, baseURL) {
1793
1795
  this.tenantId = tenantId;
1794
1796
  this.projectId = projectId;
1797
+ this.graphId = graphId;
1795
1798
  if (baseURL) {
1796
1799
  this.baseURL = baseURL;
1797
1800
  }
@@ -1801,7 +1804,8 @@ var ContextConfigBuilder = class {
1801
1804
  {
1802
1805
  contextConfigId: this.config.id,
1803
1806
  tenantId: this.tenantId,
1804
- projectId: this.projectId
1807
+ projectId: this.projectId,
1808
+ graphId: this.graphId
1805
1809
  },
1806
1810
  "ContextConfig context updated"
1807
1811
  );
@@ -1814,6 +1818,7 @@ var ContextConfigBuilder = class {
1814
1818
  id: this.getId(),
1815
1819
  tenantId: this.tenantId,
1816
1820
  projectId: this.projectId,
1821
+ graphId: this.graphId,
1817
1822
  name: this.getName(),
1818
1823
  description: this.getDescription(),
1819
1824
  requestContextSchema: this.getRequestContextSchema(),
@@ -3143,6 +3148,7 @@ var createContextConfig = (db) => async (params) => {
3143
3148
  id,
3144
3149
  tenantId: params.tenantId,
3145
3150
  projectId: params.projectId,
3151
+ graphId: params.graphId,
3146
3152
  name: params.name,
3147
3153
  description: params.description,
3148
3154
  requestContextSchema: params.requestContextSchema ?? null,
@@ -5544,6 +5550,9 @@ var McpClient = class {
5544
5550
  { capabilities: opts.capabilities || {} }
5545
5551
  );
5546
5552
  }
5553
+ isConnected() {
5554
+ return this.connected;
5555
+ }
5547
5556
  async connect() {
5548
5557
  if (this.connected) return;
5549
5558
  await tsPattern.match(this.serverConfig).with({ type: MCPTransportType.streamableHttp }, (config) => this.connectHttp(config)).with({ type: MCPTransportType.sse }, (config) => this.connectSSE(config)).exhaustive();
@@ -10407,10 +10416,47 @@ var NangoCredentialStore = class {
10407
10416
  if (error && typeof error === "object" && "status" in error && error.status === 404) {
10408
10417
  return null;
10409
10418
  }
10410
- console.error(`Failed to fetch integration ${uniqueKey}:`, error);
10419
+ logger11.error(
10420
+ { error: error instanceof Error ? error.message : "Unknown error", uniqueKey },
10421
+ `Failed to fetch integration ${uniqueKey}`
10422
+ );
10411
10423
  return null;
10412
10424
  }
10413
10425
  }
10426
+ /**
10427
+ * Optimize OAuth token data to fit within Nango's 1024 character limit for apiKey field
10428
+ * Strategy: Remove unnecessary fields
10429
+ */
10430
+ optimizeOAuthTokenForNango(tokenData) {
10431
+ const parsed = JSON.parse(tokenData);
10432
+ const essential = {
10433
+ access_token: parsed.access_token,
10434
+ token_type: parsed.token_type,
10435
+ expires_in: parsed.expires_in,
10436
+ refresh_token: parsed.refresh_token
10437
+ };
10438
+ Object.keys(essential).forEach((key) => {
10439
+ if (essential[key] === void 0) {
10440
+ delete essential[key];
10441
+ }
10442
+ });
10443
+ const result = JSON.stringify(essential);
10444
+ if (result.length > 1024) {
10445
+ logger11.error(
10446
+ {
10447
+ originalLength: tokenData.length,
10448
+ essentialLength: result.length,
10449
+ accessTokenLength: parsed.access_token?.length || 0,
10450
+ refreshTokenLength: parsed.refresh_token?.length || 0
10451
+ },
10452
+ "OAuth token too large for Nango storage even after removing non-essential fields"
10453
+ );
10454
+ throw new Error(
10455
+ `OAuth token (${result.length} chars) exceeds Nango's 1024 character limit. Essential fields cannot be truncated without breaking functionality. Consider using keychain storage instead of Nango for this provider.`
10456
+ );
10457
+ }
10458
+ return result;
10459
+ }
10414
10460
  /**
10415
10461
  * Create an API key credential by setting up Nango integration and importing the connection
10416
10462
  */
@@ -10441,9 +10487,13 @@ var NangoCredentialStore = class {
10441
10487
  throw new Error(`Integration '${name}' not found`);
10442
10488
  }
10443
10489
  const importConnectionUrl = `${process.env.NANGO_SERVER_URL || "https://api.nango.dev"}/connections`;
10490
+ const optimizedApiKey = this.optimizeOAuthTokenForNango(apiKeyToSet);
10491
+ if (!optimizedApiKey) {
10492
+ throw new Error(`Failed to optimize OAuth token for Nango.`);
10493
+ }
10444
10494
  const credentials = {
10445
10495
  type: "API_KEY",
10446
- apiKey: apiKeyToSet
10496
+ apiKey: optimizedApiKey
10447
10497
  };
10448
10498
  const body = {
10449
10499
  provider_config_key: integration.unique_key,
@@ -10460,12 +10510,12 @@ var NangoCredentialStore = class {
10460
10510
  body: JSON.stringify(body)
10461
10511
  });
10462
10512
  if (!response.ok) {
10513
+ const errorText = await response.text();
10463
10514
  throw new Error(
10464
- `Failed to import connection: HTTP ${response.status} - ${response.statusText}`
10515
+ `Failed to import connection: HTTP ${response.status} - ${response.statusText}. Response: ${errorText}`
10465
10516
  );
10466
10517
  }
10467
10518
  } catch (error) {
10468
- console.error("Unexpected error creating API key credential:", error);
10469
10519
  logger11.error(
10470
10520
  {
10471
10521
  error: error instanceof Error ? error.message : "Unknown error",