@inkeep/agents-core 0.0.0-dev-20250930044500 → 0.0.0-dev-20250930181023

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
@@ -10406,14 +10406,31 @@ var NangoCredentialStore = class {
10406
10406
  if (!isSupportedAuthMode(type)) {
10407
10407
  return null;
10408
10408
  }
10409
+ const extractAccessTokenForBearerType = (tokenString) => {
10410
+ if (tokenString && typeof tokenString === "string") {
10411
+ try {
10412
+ const parsedToken = JSON.parse(tokenString);
10413
+ if (parsedToken.access_token && typeof parsedToken.access_token === "string") {
10414
+ return parsedToken.access_token;
10415
+ }
10416
+ } catch {
10417
+ }
10418
+ return tokenString;
10419
+ }
10420
+ return void 0;
10421
+ };
10409
10422
  switch (type) {
10410
10423
  case "API_KEY":
10411
10424
  return {
10412
- token: credentials.apiKey || credentials.api_key
10425
+ token: extractAccessTokenForBearerType(
10426
+ credentials.apiKey || credentials.api_key
10427
+ )
10413
10428
  };
10414
10429
  case "APP":
10415
10430
  return {
10416
- token: credentials.accessToken || credentials.access_token
10431
+ token: extractAccessTokenForBearerType(
10432
+ credentials.accessToken || credentials.access_token
10433
+ )
10417
10434
  };
10418
10435
  case "BASIC":
10419
10436
  return {
@@ -10424,7 +10441,7 @@ var NangoCredentialStore = class {
10424
10441
  return credentials.raw;
10425
10442
  case "JWT":
10426
10443
  return {
10427
- token: credentials.token
10444
+ token: extractAccessTokenForBearerType(credentials.token)
10428
10445
  };
10429
10446
  case "OAUTH1":
10430
10447
  return {
@@ -10433,12 +10450,12 @@ var NangoCredentialStore = class {
10433
10450
  };
10434
10451
  case "OAUTH2":
10435
10452
  return {
10436
- token: credentials.access_token,
10453
+ token: extractAccessTokenForBearerType(credentials.access_token),
10437
10454
  refresh_token: credentials.refresh_token
10438
10455
  };
10439
10456
  case "OAUTH2_CC":
10440
10457
  return {
10441
- token: credentials.token,
10458
+ token: extractAccessTokenForBearerType(credentials.token),
10442
10459
  client_certificate: credentials.client_certificate,
10443
10460
  client_id: credentials.client_id,
10444
10461
  client_private_key: credentials.client_private_key,
@@ -10464,6 +10481,104 @@ var NangoCredentialStore = class {
10464
10481
  }
10465
10482
  return result;
10466
10483
  }
10484
+ /**
10485
+ * Fetch a specific Nango integration
10486
+ */
10487
+ async fetchNangoIntegration(uniqueKey) {
10488
+ try {
10489
+ const response = await this.nangoClient.getIntegration(
10490
+ { uniqueKey },
10491
+ { include: ["credentials"] }
10492
+ );
10493
+ const integration = response.data;
10494
+ let areCredentialsSet = false;
10495
+ if (integration.credentials?.type === "OAUTH2" || integration.credentials?.type === "OAUTH1" || integration.credentials?.type === "TBA") {
10496
+ areCredentialsSet = !!(integration.credentials?.client_id && integration.credentials?.client_secret);
10497
+ } else if (integration.credentials?.type === "APP") {
10498
+ areCredentialsSet = !!(integration.credentials?.app_id && integration.credentials?.app_link);
10499
+ } else {
10500
+ areCredentialsSet = true;
10501
+ }
10502
+ const { credentials: _credentials, ...integrationWithoutCredentials } = integration;
10503
+ return {
10504
+ ...integrationWithoutCredentials,
10505
+ areCredentialsSet
10506
+ };
10507
+ } catch (error) {
10508
+ if (error && typeof error === "object" && "status" in error && error.status === 404) {
10509
+ return null;
10510
+ }
10511
+ console.error(`Failed to fetch integration ${uniqueKey}:`, error);
10512
+ return null;
10513
+ }
10514
+ }
10515
+ /**
10516
+ * Create an API key credential by setting up Nango integration and importing the connection
10517
+ */
10518
+ async createNangoApiKeyConnection({
10519
+ name,
10520
+ apiKeyToSet,
10521
+ metadata
10522
+ }) {
10523
+ const provider = "private-api-bearer";
10524
+ try {
10525
+ let integration;
10526
+ try {
10527
+ const response2 = await this.nangoClient.createIntegration({
10528
+ provider,
10529
+ unique_key: name,
10530
+ display_name: name
10531
+ });
10532
+ integration = response2.data;
10533
+ } catch (error) {
10534
+ const existingIntegration = await this.fetchNangoIntegration(name);
10535
+ if (existingIntegration) {
10536
+ integration = existingIntegration;
10537
+ } else {
10538
+ console.log(`Integration creation failed for unexpected reasons`, error);
10539
+ }
10540
+ }
10541
+ if (!integration) {
10542
+ throw new Error(`Integration '${name}' not found`);
10543
+ }
10544
+ const importConnectionUrl = `${process.env.NANGO_SERVER_URL || "https://api.nango.dev"}/connections`;
10545
+ const credentials = {
10546
+ type: "API_KEY",
10547
+ apiKey: apiKeyToSet
10548
+ };
10549
+ const body = {
10550
+ provider_config_key: integration.unique_key,
10551
+ connection_id: name,
10552
+ metadata,
10553
+ credentials
10554
+ };
10555
+ const response = await fetch(importConnectionUrl, {
10556
+ method: "POST",
10557
+ headers: {
10558
+ Authorization: `Bearer ${process.env.NANGO_SECRET_KEY}`,
10559
+ "Content-Type": "application/json"
10560
+ },
10561
+ body: JSON.stringify(body)
10562
+ });
10563
+ if (!response.ok) {
10564
+ throw new Error(
10565
+ `Failed to import connection: HTTP ${response.status} - ${response.statusText}`
10566
+ );
10567
+ }
10568
+ } catch (error) {
10569
+ console.error("Unexpected error creating API key credential:", error);
10570
+ logger11.error(
10571
+ {
10572
+ error: error instanceof Error ? error.message : "Unknown error",
10573
+ name
10574
+ },
10575
+ `Unexpected error creating API key credential '${name}'`
10576
+ );
10577
+ throw new Error(
10578
+ `Failed to create API key credential '${name}': ${error instanceof Error ? error.message : "Unknown error"}`
10579
+ );
10580
+ }
10581
+ }
10467
10582
  /**
10468
10583
  * Fetch credentials from Nango API using connection information
10469
10584
  * @param connectionId - The connection ID for the Nango connection
@@ -10553,8 +10668,12 @@ var NangoCredentialStore = class {
10553
10668
  /**
10554
10669
  * Set credentials - not supported for Nango (OAuth flow handles this)
10555
10670
  */
10556
- async set(_key, _value) {
10557
- throw new Error("Setting credentials not supported for Nango store - use OAuth flow instead");
10671
+ async set(key, value) {
10672
+ await this.createNangoApiKeyConnection({
10673
+ name: key,
10674
+ apiKeyToSet: value,
10675
+ metadata: {}
10676
+ });
10558
10677
  }
10559
10678
  /**
10560
10679
  * Check if credentials exist by attempting to fetch them
@@ -10648,7 +10767,16 @@ function createDefaultCredentialStores() {
10648
10767
  })
10649
10768
  );
10650
10769
  }
10651
- stores.push(createKeyChainStore("keychain-default"));
10770
+ if (process.env.ENABLE_KEYCHAIN_STORE === "true") {
10771
+ try {
10772
+ stores.push(createKeyChainStore("keychain-default"));
10773
+ } catch (error) {
10774
+ console.warn(
10775
+ "Failed to create keychain store:",
10776
+ error instanceof Error ? error.message : error
10777
+ );
10778
+ }
10779
+ }
10652
10780
  return stores;
10653
10781
  }
10654
10782
  var loadEnvironmentFiles = () => {
@@ -10968,7 +11096,6 @@ exports.createExternalAgentRelation = createExternalAgentRelation;
10968
11096
  exports.createFullGraphServerSide = createFullGraphServerSide;
10969
11097
  exports.createFullProjectServerSide = createFullProjectServerSide;
10970
11098
  exports.createInMemoryDatabaseClient = createInMemoryDatabaseClient;
10971
- exports.createKeyChainStore = createKeyChainStore;
10972
11099
  exports.createMessage = createMessage;
10973
11100
  exports.createNangoCredentialStore = createNangoCredentialStore;
10974
11101
  exports.createOrGetConversation = createOrGetConversation;
package/dist/index.d.cts CHANGED
@@ -452,35 +452,6 @@ declare class KeyChainStore implements CredentialStore {
452
452
  */
453
453
  clearAll(): Promise<number>;
454
454
  }
455
- /**
456
- * Factory function to create KeyChainStore
457
- * Provides consistent initialization and optional configuration
458
- *
459
- * ## Usage Recommendations for macOS Permission Handling
460
- *
461
- * 1. **First-time setup**: Inform users that they may see permission prompts
462
- * 2. **Error handling**: Check for `null` returns from `get()` operations
463
- * 3. **User guidance**: If credentials can't be retrieved, guide users to:
464
- * - Check Keychain Access app for denied permissions
465
- * - Re-run the application if they accidentally clicked "Deny"
466
- * 4. **Development**: Use a consistent `servicePrefix` to avoid permission prompt spam
467
- * 5. **Production**: Consider code-signing your distributed app for better permission prompts
468
- *
469
- * Example usage with permission handling:
470
- * ```typescript
471
- * const store = createKeyChainStore('my-app');
472
- *
473
- * // Always check for null when retrieving
474
- * const apiKey = await store.get('api-key');
475
- * if (!apiKey) {
476
- * console.log('API key not found or access denied');
477
- * // Guide user to check permissions or re-enter credentials
478
- * }
479
- * ```
480
- */
481
- declare function createKeyChainStore(id: string, options?: {
482
- servicePrefix?: string;
483
- }): KeyChainStore;
484
455
 
485
456
  /**
486
457
  * In-memory credential store implementation
@@ -536,6 +507,14 @@ declare class NangoCredentialStore implements CredentialStore {
536
507
  constructor(id: string, config: NangoConfig);
537
508
  private getAccessToken;
538
509
  private sanitizeMetadata;
510
+ /**
511
+ * Fetch a specific Nango integration
512
+ */
513
+ private fetchNangoIntegration;
514
+ /**
515
+ * Create an API key credential by setting up Nango integration and importing the connection
516
+ */
517
+ private createNangoApiKeyConnection;
539
518
  /**
540
519
  * Fetch credentials from Nango API using connection information
541
520
  * @param connectionId - The connection ID for the Nango connection
@@ -551,7 +530,7 @@ declare class NangoCredentialStore implements CredentialStore {
551
530
  /**
552
531
  * Set credentials - not supported for Nango (OAuth flow handles this)
553
532
  */
554
- set(_key: string, _value: string): Promise<void>;
533
+ set(key: string, value: string): Promise<void>;
555
534
  /**
556
535
  * Check if credentials exist by attempting to fetch them
557
536
  */
@@ -3906,4 +3885,4 @@ declare function setSpanWithError(span: Span, error: unknown, logger?: {
3906
3885
  */
3907
3886
  declare function getTracer(serviceName: string, serviceVersion?: string): Tracer;
3908
3887
 
3909
- export { AgentGraphInsert, AgentGraphUpdate, AgentInsert, AgentRelationInsert, AgentRelationUpdate, AgentScopeConfig, AgentSelect, AgentToolRelationUpdate, AgentUpdate, ApiKeyCreateResult, type ApiKeyGenerationResult, ApiKeyInsert, ApiKeySelect, ApiKeyUpdate, Artifact, ArtifactComponentInsert, ArtifactComponentSelect, ArtifactComponentUpdate, type CommonCreateErrorResponses, type CommonDeleteErrorResponses, type CommonGetErrorResponses, type CommonUpdateErrorResponses, ContextCache, ContextCacheInsert, ContextCacheSelect, ContextConfigBuilder, type ContextConfigBuilderOptions, ContextConfigInsert, ContextConfigSelect, ContextConfigUpdate, ContextFetchDefinition, ContextFetcher, type ContextResolutionOptions, type ContextResolutionResult, ContextResolver, type ContextResolverInterface, type ContextValidationError, type ContextValidationResult, ConversationHistoryConfig, ConversationInsert, ConversationMetadata, ConversationSelect, ConversationUpdate, CreateApiKeyParams, type CredentialContext, type CredentialData, CredentialReferenceApiInsert, CredentialReferenceInsert, CredentialReferenceSelect, CredentialReferenceUpdate, type CredentialReferenceWithTools, type CredentialResolverInput, CredentialStore, type CredentialStoreReference, CredentialStoreRegistry, CredentialStoreType, CredentialStuffer, DataComponentInsert, DataComponentSelect, DataComponentUpdate, type DatabaseClient, type DatabaseConfig, type DotPaths, ERROR_DOCS_BASE_URL, ErrorCode, type ErrorCodes, type ErrorResponse, ExecutionContext, ExternalAgentInsert, ExternalAgentRelationInsert, ExternalAgentSelect, ExternalAgentUpdate, type FetchResult, FullGraphDefinition, FullProjectDefinition, type GraphLogger, GraphScopeConfig, HTTP_REQUEST_PARTS, type HttpRequestPart, InMemoryCredentialStore, KeyChainStore, LedgerArtifactSelect, type LoggerFactoryConfig, MCPToolConfig, MCPTransportType, McpClient, type McpClientOptions, type McpSSEConfig, type McpServerConfig, type McpStreamableHttpConfig, McpTool, MessageContent, MessageInsert, MessageMetadata, MessageUpdate, MessageVisibility, NangoCredentialStore, type OAuthConfig, PaginationConfig, PaginationResult, type ParsedHttpRequest, PinoLogger, type PinoLoggerConfig, type ProblemDetails, ProjectInfo, ProjectInsert, type ProjectLogger, ProjectResourceCounts, ProjectScopeConfig, ProjectSelect, ProjectUpdate, type ResolvedContext, TaskInsert, TaskMetadataConfig, TaskSelect, type TemplateContext, TemplateEngine, type TemplateRenderOptions, ToolInsert, ToolMcpConfig, ToolSelect, ToolServerCapabilities, ToolUpdate, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createKeyChainStore, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, requestContextSchema, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertLedgerArtifact, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };
3888
+ export { AgentGraphInsert, AgentGraphUpdate, AgentInsert, AgentRelationInsert, AgentRelationUpdate, AgentScopeConfig, AgentSelect, AgentToolRelationUpdate, AgentUpdate, ApiKeyCreateResult, type ApiKeyGenerationResult, ApiKeyInsert, ApiKeySelect, ApiKeyUpdate, Artifact, ArtifactComponentInsert, ArtifactComponentSelect, ArtifactComponentUpdate, type CommonCreateErrorResponses, type CommonDeleteErrorResponses, type CommonGetErrorResponses, type CommonUpdateErrorResponses, ContextCache, ContextCacheInsert, ContextCacheSelect, ContextConfigBuilder, type ContextConfigBuilderOptions, ContextConfigInsert, ContextConfigSelect, ContextConfigUpdate, ContextFetchDefinition, ContextFetcher, type ContextResolutionOptions, type ContextResolutionResult, ContextResolver, type ContextResolverInterface, type ContextValidationError, type ContextValidationResult, ConversationHistoryConfig, ConversationInsert, ConversationMetadata, ConversationSelect, ConversationUpdate, CreateApiKeyParams, type CredentialContext, type CredentialData, CredentialReferenceApiInsert, CredentialReferenceInsert, CredentialReferenceSelect, CredentialReferenceUpdate, type CredentialReferenceWithTools, type CredentialResolverInput, CredentialStore, type CredentialStoreReference, CredentialStoreRegistry, CredentialStoreType, CredentialStuffer, DataComponentInsert, DataComponentSelect, DataComponentUpdate, type DatabaseClient, type DatabaseConfig, type DotPaths, ERROR_DOCS_BASE_URL, ErrorCode, type ErrorCodes, type ErrorResponse, ExecutionContext, ExternalAgentInsert, ExternalAgentRelationInsert, ExternalAgentSelect, ExternalAgentUpdate, type FetchResult, FullGraphDefinition, FullProjectDefinition, type GraphLogger, GraphScopeConfig, HTTP_REQUEST_PARTS, type HttpRequestPart, InMemoryCredentialStore, KeyChainStore, LedgerArtifactSelect, type LoggerFactoryConfig, MCPToolConfig, MCPTransportType, McpClient, type McpClientOptions, type McpSSEConfig, type McpServerConfig, type McpStreamableHttpConfig, McpTool, MessageContent, MessageInsert, MessageMetadata, MessageUpdate, MessageVisibility, NangoCredentialStore, type OAuthConfig, PaginationConfig, PaginationResult, type ParsedHttpRequest, PinoLogger, type PinoLoggerConfig, type ProblemDetails, ProjectInfo, ProjectInsert, type ProjectLogger, ProjectResourceCounts, ProjectScopeConfig, ProjectSelect, ProjectUpdate, type ResolvedContext, TaskInsert, TaskMetadataConfig, TaskSelect, type TemplateContext, TemplateEngine, type TemplateRenderOptions, ToolInsert, ToolMcpConfig, ToolSelect, ToolServerCapabilities, ToolUpdate, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, requestContextSchema, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertLedgerArtifact, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };
package/dist/index.d.ts CHANGED
@@ -452,35 +452,6 @@ declare class KeyChainStore implements CredentialStore {
452
452
  */
453
453
  clearAll(): Promise<number>;
454
454
  }
455
- /**
456
- * Factory function to create KeyChainStore
457
- * Provides consistent initialization and optional configuration
458
- *
459
- * ## Usage Recommendations for macOS Permission Handling
460
- *
461
- * 1. **First-time setup**: Inform users that they may see permission prompts
462
- * 2. **Error handling**: Check for `null` returns from `get()` operations
463
- * 3. **User guidance**: If credentials can't be retrieved, guide users to:
464
- * - Check Keychain Access app for denied permissions
465
- * - Re-run the application if they accidentally clicked "Deny"
466
- * 4. **Development**: Use a consistent `servicePrefix` to avoid permission prompt spam
467
- * 5. **Production**: Consider code-signing your distributed app for better permission prompts
468
- *
469
- * Example usage with permission handling:
470
- * ```typescript
471
- * const store = createKeyChainStore('my-app');
472
- *
473
- * // Always check for null when retrieving
474
- * const apiKey = await store.get('api-key');
475
- * if (!apiKey) {
476
- * console.log('API key not found or access denied');
477
- * // Guide user to check permissions or re-enter credentials
478
- * }
479
- * ```
480
- */
481
- declare function createKeyChainStore(id: string, options?: {
482
- servicePrefix?: string;
483
- }): KeyChainStore;
484
455
 
485
456
  /**
486
457
  * In-memory credential store implementation
@@ -536,6 +507,14 @@ declare class NangoCredentialStore implements CredentialStore {
536
507
  constructor(id: string, config: NangoConfig);
537
508
  private getAccessToken;
538
509
  private sanitizeMetadata;
510
+ /**
511
+ * Fetch a specific Nango integration
512
+ */
513
+ private fetchNangoIntegration;
514
+ /**
515
+ * Create an API key credential by setting up Nango integration and importing the connection
516
+ */
517
+ private createNangoApiKeyConnection;
539
518
  /**
540
519
  * Fetch credentials from Nango API using connection information
541
520
  * @param connectionId - The connection ID for the Nango connection
@@ -551,7 +530,7 @@ declare class NangoCredentialStore implements CredentialStore {
551
530
  /**
552
531
  * Set credentials - not supported for Nango (OAuth flow handles this)
553
532
  */
554
- set(_key: string, _value: string): Promise<void>;
533
+ set(key: string, value: string): Promise<void>;
555
534
  /**
556
535
  * Check if credentials exist by attempting to fetch them
557
536
  */
@@ -3906,4 +3885,4 @@ declare function setSpanWithError(span: Span, error: unknown, logger?: {
3906
3885
  */
3907
3886
  declare function getTracer(serviceName: string, serviceVersion?: string): Tracer;
3908
3887
 
3909
- export { AgentGraphInsert, AgentGraphUpdate, AgentInsert, AgentRelationInsert, AgentRelationUpdate, AgentScopeConfig, AgentSelect, AgentToolRelationUpdate, AgentUpdate, ApiKeyCreateResult, type ApiKeyGenerationResult, ApiKeyInsert, ApiKeySelect, ApiKeyUpdate, Artifact, ArtifactComponentInsert, ArtifactComponentSelect, ArtifactComponentUpdate, type CommonCreateErrorResponses, type CommonDeleteErrorResponses, type CommonGetErrorResponses, type CommonUpdateErrorResponses, ContextCache, ContextCacheInsert, ContextCacheSelect, ContextConfigBuilder, type ContextConfigBuilderOptions, ContextConfigInsert, ContextConfigSelect, ContextConfigUpdate, ContextFetchDefinition, ContextFetcher, type ContextResolutionOptions, type ContextResolutionResult, ContextResolver, type ContextResolverInterface, type ContextValidationError, type ContextValidationResult, ConversationHistoryConfig, ConversationInsert, ConversationMetadata, ConversationSelect, ConversationUpdate, CreateApiKeyParams, type CredentialContext, type CredentialData, CredentialReferenceApiInsert, CredentialReferenceInsert, CredentialReferenceSelect, CredentialReferenceUpdate, type CredentialReferenceWithTools, type CredentialResolverInput, CredentialStore, type CredentialStoreReference, CredentialStoreRegistry, CredentialStoreType, CredentialStuffer, DataComponentInsert, DataComponentSelect, DataComponentUpdate, type DatabaseClient, type DatabaseConfig, type DotPaths, ERROR_DOCS_BASE_URL, ErrorCode, type ErrorCodes, type ErrorResponse, ExecutionContext, ExternalAgentInsert, ExternalAgentRelationInsert, ExternalAgentSelect, ExternalAgentUpdate, type FetchResult, FullGraphDefinition, FullProjectDefinition, type GraphLogger, GraphScopeConfig, HTTP_REQUEST_PARTS, type HttpRequestPart, InMemoryCredentialStore, KeyChainStore, LedgerArtifactSelect, type LoggerFactoryConfig, MCPToolConfig, MCPTransportType, McpClient, type McpClientOptions, type McpSSEConfig, type McpServerConfig, type McpStreamableHttpConfig, McpTool, MessageContent, MessageInsert, MessageMetadata, MessageUpdate, MessageVisibility, NangoCredentialStore, type OAuthConfig, PaginationConfig, PaginationResult, type ParsedHttpRequest, PinoLogger, type PinoLoggerConfig, type ProblemDetails, ProjectInfo, ProjectInsert, type ProjectLogger, ProjectResourceCounts, ProjectScopeConfig, ProjectSelect, ProjectUpdate, type ResolvedContext, TaskInsert, TaskMetadataConfig, TaskSelect, type TemplateContext, TemplateEngine, type TemplateRenderOptions, ToolInsert, ToolMcpConfig, ToolSelect, ToolServerCapabilities, ToolUpdate, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createKeyChainStore, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, requestContextSchema, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertLedgerArtifact, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };
3888
+ export { AgentGraphInsert, AgentGraphUpdate, AgentInsert, AgentRelationInsert, AgentRelationUpdate, AgentScopeConfig, AgentSelect, AgentToolRelationUpdate, AgentUpdate, ApiKeyCreateResult, type ApiKeyGenerationResult, ApiKeyInsert, ApiKeySelect, ApiKeyUpdate, Artifact, ArtifactComponentInsert, ArtifactComponentSelect, ArtifactComponentUpdate, type CommonCreateErrorResponses, type CommonDeleteErrorResponses, type CommonGetErrorResponses, type CommonUpdateErrorResponses, ContextCache, ContextCacheInsert, ContextCacheSelect, ContextConfigBuilder, type ContextConfigBuilderOptions, ContextConfigInsert, ContextConfigSelect, ContextConfigUpdate, ContextFetchDefinition, ContextFetcher, type ContextResolutionOptions, type ContextResolutionResult, ContextResolver, type ContextResolverInterface, type ContextValidationError, type ContextValidationResult, ConversationHistoryConfig, ConversationInsert, ConversationMetadata, ConversationSelect, ConversationUpdate, CreateApiKeyParams, type CredentialContext, type CredentialData, CredentialReferenceApiInsert, CredentialReferenceInsert, CredentialReferenceSelect, CredentialReferenceUpdate, type CredentialReferenceWithTools, type CredentialResolverInput, CredentialStore, type CredentialStoreReference, CredentialStoreRegistry, CredentialStoreType, CredentialStuffer, DataComponentInsert, DataComponentSelect, DataComponentUpdate, type DatabaseClient, type DatabaseConfig, type DotPaths, ERROR_DOCS_BASE_URL, ErrorCode, type ErrorCodes, type ErrorResponse, ExecutionContext, ExternalAgentInsert, ExternalAgentRelationInsert, ExternalAgentSelect, ExternalAgentUpdate, type FetchResult, FullGraphDefinition, FullProjectDefinition, type GraphLogger, GraphScopeConfig, HTTP_REQUEST_PARTS, type HttpRequestPart, InMemoryCredentialStore, KeyChainStore, LedgerArtifactSelect, type LoggerFactoryConfig, MCPToolConfig, MCPTransportType, McpClient, type McpClientOptions, type McpSSEConfig, type McpServerConfig, type McpStreamableHttpConfig, McpTool, MessageContent, MessageInsert, MessageMetadata, MessageUpdate, MessageVisibility, NangoCredentialStore, type OAuthConfig, PaginationConfig, PaginationResult, type ParsedHttpRequest, PinoLogger, type PinoLoggerConfig, type ProblemDetails, ProjectInfo, ProjectInsert, type ProjectLogger, ProjectResourceCounts, ProjectScopeConfig, ProjectSelect, ProjectUpdate, type ResolvedContext, TaskInsert, TaskMetadataConfig, TaskSelect, type TemplateContext, TemplateEngine, type TemplateRenderOptions, ToolInsert, ToolMcpConfig, ToolSelect, ToolServerCapabilities, ToolUpdate, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, requestContextSchema, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertLedgerArtifact, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };
package/dist/index.js CHANGED
@@ -8667,14 +8667,31 @@ var NangoCredentialStore = class {
8667
8667
  if (!isSupportedAuthMode(type)) {
8668
8668
  return null;
8669
8669
  }
8670
+ const extractAccessTokenForBearerType = (tokenString) => {
8671
+ if (tokenString && typeof tokenString === "string") {
8672
+ try {
8673
+ const parsedToken = JSON.parse(tokenString);
8674
+ if (parsedToken.access_token && typeof parsedToken.access_token === "string") {
8675
+ return parsedToken.access_token;
8676
+ }
8677
+ } catch {
8678
+ }
8679
+ return tokenString;
8680
+ }
8681
+ return void 0;
8682
+ };
8670
8683
  switch (type) {
8671
8684
  case "API_KEY":
8672
8685
  return {
8673
- token: credentials.apiKey || credentials.api_key
8686
+ token: extractAccessTokenForBearerType(
8687
+ credentials.apiKey || credentials.api_key
8688
+ )
8674
8689
  };
8675
8690
  case "APP":
8676
8691
  return {
8677
- token: credentials.accessToken || credentials.access_token
8692
+ token: extractAccessTokenForBearerType(
8693
+ credentials.accessToken || credentials.access_token
8694
+ )
8678
8695
  };
8679
8696
  case "BASIC":
8680
8697
  return {
@@ -8685,7 +8702,7 @@ var NangoCredentialStore = class {
8685
8702
  return credentials.raw;
8686
8703
  case "JWT":
8687
8704
  return {
8688
- token: credentials.token
8705
+ token: extractAccessTokenForBearerType(credentials.token)
8689
8706
  };
8690
8707
  case "OAUTH1":
8691
8708
  return {
@@ -8694,12 +8711,12 @@ var NangoCredentialStore = class {
8694
8711
  };
8695
8712
  case "OAUTH2":
8696
8713
  return {
8697
- token: credentials.access_token,
8714
+ token: extractAccessTokenForBearerType(credentials.access_token),
8698
8715
  refresh_token: credentials.refresh_token
8699
8716
  };
8700
8717
  case "OAUTH2_CC":
8701
8718
  return {
8702
- token: credentials.token,
8719
+ token: extractAccessTokenForBearerType(credentials.token),
8703
8720
  client_certificate: credentials.client_certificate,
8704
8721
  client_id: credentials.client_id,
8705
8722
  client_private_key: credentials.client_private_key,
@@ -8725,6 +8742,104 @@ var NangoCredentialStore = class {
8725
8742
  }
8726
8743
  return result;
8727
8744
  }
8745
+ /**
8746
+ * Fetch a specific Nango integration
8747
+ */
8748
+ async fetchNangoIntegration(uniqueKey) {
8749
+ try {
8750
+ const response = await this.nangoClient.getIntegration(
8751
+ { uniqueKey },
8752
+ { include: ["credentials"] }
8753
+ );
8754
+ const integration = response.data;
8755
+ let areCredentialsSet = false;
8756
+ if (integration.credentials?.type === "OAUTH2" || integration.credentials?.type === "OAUTH1" || integration.credentials?.type === "TBA") {
8757
+ areCredentialsSet = !!(integration.credentials?.client_id && integration.credentials?.client_secret);
8758
+ } else if (integration.credentials?.type === "APP") {
8759
+ areCredentialsSet = !!(integration.credentials?.app_id && integration.credentials?.app_link);
8760
+ } else {
8761
+ areCredentialsSet = true;
8762
+ }
8763
+ const { credentials: _credentials, ...integrationWithoutCredentials } = integration;
8764
+ return {
8765
+ ...integrationWithoutCredentials,
8766
+ areCredentialsSet
8767
+ };
8768
+ } catch (error) {
8769
+ if (error && typeof error === "object" && "status" in error && error.status === 404) {
8770
+ return null;
8771
+ }
8772
+ console.error(`Failed to fetch integration ${uniqueKey}:`, error);
8773
+ return null;
8774
+ }
8775
+ }
8776
+ /**
8777
+ * Create an API key credential by setting up Nango integration and importing the connection
8778
+ */
8779
+ async createNangoApiKeyConnection({
8780
+ name,
8781
+ apiKeyToSet,
8782
+ metadata
8783
+ }) {
8784
+ const provider = "private-api-bearer";
8785
+ try {
8786
+ let integration;
8787
+ try {
8788
+ const response2 = await this.nangoClient.createIntegration({
8789
+ provider,
8790
+ unique_key: name,
8791
+ display_name: name
8792
+ });
8793
+ integration = response2.data;
8794
+ } catch (error) {
8795
+ const existingIntegration = await this.fetchNangoIntegration(name);
8796
+ if (existingIntegration) {
8797
+ integration = existingIntegration;
8798
+ } else {
8799
+ console.log(`Integration creation failed for unexpected reasons`, error);
8800
+ }
8801
+ }
8802
+ if (!integration) {
8803
+ throw new Error(`Integration '${name}' not found`);
8804
+ }
8805
+ const importConnectionUrl = `${process.env.NANGO_SERVER_URL || "https://api.nango.dev"}/connections`;
8806
+ const credentials = {
8807
+ type: "API_KEY",
8808
+ apiKey: apiKeyToSet
8809
+ };
8810
+ const body = {
8811
+ provider_config_key: integration.unique_key,
8812
+ connection_id: name,
8813
+ metadata,
8814
+ credentials
8815
+ };
8816
+ const response = await fetch(importConnectionUrl, {
8817
+ method: "POST",
8818
+ headers: {
8819
+ Authorization: `Bearer ${process.env.NANGO_SECRET_KEY}`,
8820
+ "Content-Type": "application/json"
8821
+ },
8822
+ body: JSON.stringify(body)
8823
+ });
8824
+ if (!response.ok) {
8825
+ throw new Error(
8826
+ `Failed to import connection: HTTP ${response.status} - ${response.statusText}`
8827
+ );
8828
+ }
8829
+ } catch (error) {
8830
+ console.error("Unexpected error creating API key credential:", error);
8831
+ logger11.error(
8832
+ {
8833
+ error: error instanceof Error ? error.message : "Unknown error",
8834
+ name
8835
+ },
8836
+ `Unexpected error creating API key credential '${name}'`
8837
+ );
8838
+ throw new Error(
8839
+ `Failed to create API key credential '${name}': ${error instanceof Error ? error.message : "Unknown error"}`
8840
+ );
8841
+ }
8842
+ }
8728
8843
  /**
8729
8844
  * Fetch credentials from Nango API using connection information
8730
8845
  * @param connectionId - The connection ID for the Nango connection
@@ -8814,8 +8929,12 @@ var NangoCredentialStore = class {
8814
8929
  /**
8815
8930
  * Set credentials - not supported for Nango (OAuth flow handles this)
8816
8931
  */
8817
- async set(_key, _value) {
8818
- throw new Error("Setting credentials not supported for Nango store - use OAuth flow instead");
8932
+ async set(key, value) {
8933
+ await this.createNangoApiKeyConnection({
8934
+ name: key,
8935
+ apiKeyToSet: value,
8936
+ metadata: {}
8937
+ });
8819
8938
  }
8820
8939
  /**
8821
8940
  * Check if credentials exist by attempting to fetch them
@@ -8909,7 +9028,16 @@ function createDefaultCredentialStores() {
8909
9028
  })
8910
9029
  );
8911
9030
  }
8912
- stores.push(createKeyChainStore("keychain-default"));
9031
+ if (process.env.ENABLE_KEYCHAIN_STORE === "true") {
9032
+ try {
9033
+ stores.push(createKeyChainStore("keychain-default"));
9034
+ } catch (error) {
9035
+ console.warn(
9036
+ "Failed to create keychain store:",
9037
+ error instanceof Error ? error.message : error
9038
+ );
9039
+ }
9040
+ }
8913
9041
  return stores;
8914
9042
  }
8915
9043
  var loadEnvironmentFiles = () => {
@@ -8962,4 +9090,4 @@ ${error.message}`
8962
9090
  };
8963
9091
  parseEnv();
8964
9092
 
8965
- export { ContextCache, ContextConfigBuilder, ContextFetcher, ContextResolver, CredentialStoreRegistry, CredentialStuffer, ERROR_DOCS_BASE_URL, ErrorCode, HTTP_REQUEST_PARTS, InMemoryCredentialStore, KeyChainStore, McpClient, NangoCredentialStore, PinoLogger, TemplateEngine, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createKeyChainStore, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, requestContextSchema, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertLedgerArtifact, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };
9093
+ export { ContextCache, ContextConfigBuilder, ContextFetcher, ContextResolver, CredentialStoreRegistry, CredentialStuffer, ERROR_DOCS_BASE_URL, ErrorCode, HTTP_REQUEST_PARTS, InMemoryCredentialStore, KeyChainStore, McpClient, NangoCredentialStore, PinoLogger, TemplateEngine, addLedgerArtifacts, addToolToAgent, associateArtifactComponentWithAgent, associateDataComponentWithAgent, cleanupTenantCache, clearContextConfigCache, clearConversationCache, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, contextConfig, contextValidationMiddleware, countApiKeys, countArtifactComponents, countArtifactComponentsForAgent, countContextConfigs, countCredentialReferences, countDataComponents, countExternalAgents, countLedgerArtifactsByTask, countMessagesByConversation, countProjects, createAgent, createAgentGraph, createAgentRelation, createAgentToolRelation, createApiError, createApiKey, createArtifactComponent, createContextConfig, createConversation, createCredentialReference, createDataComponent, createDatabaseClient, createDefaultCredentialStores, createExecutionContext, createExternalAgent, createExternalAgentRelation, createFullGraphServerSide, createFullProjectServerSide, createInMemoryDatabaseClient, createMessage, createNangoCredentialStore, createOrGetConversation, createProject, createTask, createTool, createValidatedDataAccess, dbResultToMcpTool, deleteAgent, deleteAgentArtifactComponentRelationByAgent, deleteAgentDataComponentRelationByAgent, deleteAgentGraph, deleteAgentRelation, deleteAgentRelationsByGraph, deleteAgentToolRelation, deleteAgentToolRelationByAgent, deleteApiKey, deleteArtifactComponent, deleteContextConfig, deleteConversation, deleteCredentialReference, deleteDataComponent, deleteExternalAgent, deleteFullGraph, deleteFullProject, deleteLedgerArtifactsByContext, deleteLedgerArtifactsByTask, deleteMessage, deleteProject, deleteTool, detectAuthenticationRequired, determineContextTrigger, discoverOAuthEndpoints, errorResponseSchema, errorSchemaFactory, externalAgentExists, externalAgentUrlExists, extractPublicId, fetchComponentRelationships, fetchDefinition, generateAndCreateApiKey, generateApiKey, getActiveAgentForConversation, getAgentById, getAgentGraphById, getAgentGraphWithDefaultAgent, getAgentRelationById, getAgentRelationByParams, getAgentRelations, getAgentRelationsByGraph, getAgentRelationsBySource, getAgentRelationsByTarget, getAgentToolRelationByAgent, getAgentToolRelationById, getAgentToolRelationByTool, getAgentsByIds, getAgentsForTool, getAgentsUsingArtifactComponent, getAgentsUsingDataComponent, getApiKeyById, getApiKeyByPublicId, getArtifactComponentById, getArtifactComponentsForAgent, getCacheEntry, getCachedValidator, getContextConfigById, getContextConfigCacheEntries, getContextConfigsByName, getConversation, getConversationCacheEntries, getConversationHistory, getCredentialReference, getCredentialReferenceById, getCredentialReferenceWithTools, getCredentialStoreLookupKeyFromRetrievalParams, getDataComponent, getDataComponentsForAgent, getExternalAgent, getExternalAgentByUrl, getExternalAgentRelations, getFullGraph, getFullGraphDefinition, getFullProject, getGraphAgentInfos, getLedgerArtifacts, getLedgerArtifactsByContext, getLogger, getMessageById, getMessagesByConversation, getMessagesByTask, getProject, getProjectResourceCounts, getRelatedAgentsForGraph, getRequestExecutionContext, getTask, getToolById, getToolsForAgent, getTracer, getVisibleMessages, graphHasArtifactComponents, handleApiError, handleContextConfigChange, handleContextResolution, hasApiKey, hasContextConfig, hasCredentialReference, hashApiKey, invalidateInvocationDefinitionsCache, invalidateRequestContextCache, isApiKeyExpired, isArtifactComponentAssociatedWithAgent, isDataComponentAssociatedWithAgent, isValidHttpRequest, listAgentGraphs, listAgentGraphsPaginated, listAgentRelations, listAgentToolRelations, listAgents, listAgentsPaginated, listApiKeys, listApiKeysPaginated, listArtifactComponents, listArtifactComponentsPaginated, listContextConfigs, listContextConfigsPaginated, listConversations, listCredentialReferences, listCredentialReferencesPaginated, listDataComponents, listDataComponentsPaginated, listExternalAgents, listExternalAgentsPaginated, listMessages, listProjects, listProjectsPaginated, listTaskIdsByContextId, listTools, loadEnvironmentFiles, loggerFactory, maskApiKey, problemDetailsSchema, projectExists, projectExistsInTable, projectHasResources, removeArtifactComponentFromAgent, removeDataComponentFromAgent, removeToolFromAgent, requestContextSchema, setActiveAgentForConversation, setActiveAgentForThread, setCacheEntry, setSpanWithError, updateAgent, updateAgentGraph, updateAgentRelation, updateAgentToolRelation, updateApiKey, updateApiKeyLastUsed, updateArtifactComponent, updateContextConfig, updateConversation, updateConversationActiveAgent, updateCredentialReference, updateDataComponent, updateExternalAgent, updateFullGraphServerSide, updateFullProjectServerSide, updateMessage, updateProject, updateTask, updateTool, upsertAgent, upsertAgentArtifactComponentRelation, upsertAgentDataComponentRelation, upsertAgentGraph, upsertAgentRelation, upsertAgentToolRelation, upsertArtifactComponent, upsertContextConfig, upsertCredentialReference, upsertDataComponent, upsertExternalAgent, upsertLedgerArtifact, upsertTool, validateAgainstJsonSchema, validateAndGetApiKey, validateApiKey, validateExternalAgent, validateHttpRequestHeaders, validateInternalAgent, validateProjectExists, validateRequestContext, validationHelper, withProjectValidation };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-core",
3
- "version": "0.0.0-dev-20250930044500",
3
+ "version": "0.0.0-dev-20250930181023",
4
4
  "description": "Agents Core contains the database schema, types, and validation schemas for Inkeep Agent Framework, along with core components.",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -57,13 +57,15 @@
57
57
  "find-up": "^7.0.0",
58
58
  "hono": "^4.9.7",
59
59
  "jmespath": "^0.16.0",
60
- "keytar": "^7.9.0",
61
60
  "nanoid": "^5.0.9",
62
61
  "pino": "^9.11.0",
63
62
  "pino-pretty": "^13.1.1",
64
63
  "ts-pattern": "^5.7.1",
65
64
  "zod": "^4.1.5"
66
65
  },
66
+ "optionalDependencies": {
67
+ "keytar": "^7.9.0"
68
+ },
67
69
  "devDependencies": {
68
70
  "@types/jmespath": "^0.15.2",
69
71
  "@types/node": "^20.11.24",