@nevermined-io/payments 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/README.md +33 -0
  2. package/dist/a2a/clientRegistry.d.ts +10 -1
  3. package/dist/a2a/clientRegistry.d.ts.map +1 -1
  4. package/dist/a2a/clientRegistry.js +13 -4
  5. package/dist/a2a/clientRegistry.js.map +1 -1
  6. package/dist/a2a/paymentsClient.d.ts +60 -3
  7. package/dist/a2a/paymentsClient.d.ts.map +1 -1
  8. package/dist/a2a/paymentsClient.js +129 -8
  9. package/dist/a2a/paymentsClient.js.map +1 -1
  10. package/dist/a2a/paymentsRequestHandler.d.ts +5 -1
  11. package/dist/a2a/paymentsRequestHandler.d.ts.map +1 -1
  12. package/dist/a2a/paymentsRequestHandler.js +156 -13
  13. package/dist/a2a/paymentsRequestHandler.js.map +1 -1
  14. package/dist/a2a/types.d.ts +30 -0
  15. package/dist/a2a/types.d.ts.map +1 -1
  16. package/dist/a2a/types.js.map +1 -1
  17. package/dist/api/agents-api.d.ts +4 -3
  18. package/dist/api/agents-api.d.ts.map +1 -1
  19. package/dist/api/agents-api.js +7 -4
  20. package/dist/api/agents-api.js.map +1 -1
  21. package/dist/api/base-payments.d.ts +7 -2
  22. package/dist/api/base-payments.d.ts.map +1 -1
  23. package/dist/api/base-payments.js +15 -8
  24. package/dist/api/base-payments.js.map +1 -1
  25. package/dist/api/nvm-api.d.ts +5 -5
  26. package/dist/api/observability-api/types.d.ts +34 -6
  27. package/dist/api/observability-api/types.d.ts.map +1 -1
  28. package/dist/api/observability-api/types.js.map +1 -1
  29. package/dist/api/plans-api.d.ts +15 -12
  30. package/dist/api/plans-api.d.ts.map +1 -1
  31. package/dist/api/plans-api.js +17 -14
  32. package/dist/api/plans-api.js.map +1 -1
  33. package/dist/api/query-api.d.ts +1 -1
  34. package/dist/common/types.d.ts +175 -18
  35. package/dist/common/types.d.ts.map +1 -1
  36. package/dist/common/types.js.map +1 -1
  37. package/dist/index.d.ts +2 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/mcp/core/paywall.d.ts.map +1 -1
  42. package/dist/mcp/core/paywall.js +69 -8
  43. package/dist/mcp/core/paywall.js.map +1 -1
  44. package/dist/mcp/http/index.d.ts +1 -1
  45. package/dist/mcp/http/index.d.ts.map +1 -1
  46. package/dist/mcp/http/index.js +1 -1
  47. package/dist/mcp/http/index.js.map +1 -1
  48. package/dist/mcp/http/oauth-metadata.d.ts +32 -0
  49. package/dist/mcp/http/oauth-metadata.d.ts.map +1 -1
  50. package/dist/mcp/http/oauth-metadata.js +329 -34
  51. package/dist/mcp/http/oauth-metadata.js.map +1 -1
  52. package/dist/mcp/index.d.ts +4 -4
  53. package/dist/mcp/index.d.ts.map +1 -1
  54. package/dist/mcp/index.js +5 -5
  55. package/dist/mcp/index.js.map +1 -1
  56. package/dist/mcp/types/http.types.d.ts +38 -3
  57. package/dist/mcp/types/http.types.d.ts.map +1 -1
  58. package/dist/mcp/types/http.types.js.map +1 -1
  59. package/dist/mcp/types/paywall.types.d.ts +19 -3
  60. package/dist/mcp/types/paywall.types.d.ts.map +1 -1
  61. package/dist/mcp/types/paywall.types.js.map +1 -1
  62. package/dist/mpp/fetch.d.ts +8 -3
  63. package/dist/mpp/fetch.d.ts.map +1 -1
  64. package/dist/mpp/fetch.js +6 -0
  65. package/dist/mpp/fetch.js.map +1 -1
  66. package/dist/mpp/mpp-api.d.ts +11 -5
  67. package/dist/mpp/mpp-api.d.ts.map +1 -1
  68. package/dist/mpp/mpp-api.js +10 -3
  69. package/dist/mpp/mpp-api.js.map +1 -1
  70. package/dist/payments.d.ts.map +1 -1
  71. package/dist/x402/delegation-api.d.ts +5 -17
  72. package/dist/x402/delegation-api.d.ts.map +1 -1
  73. package/dist/x402/delegation-api.js +2 -2
  74. package/dist/x402/delegation-api.js.map +1 -1
  75. package/dist/x402/express/middleware.d.ts.map +1 -1
  76. package/dist/x402/express/middleware.js +98 -1
  77. package/dist/x402/express/middleware.js.map +1 -1
  78. package/dist/x402/facilitator-api.d.ts +90 -7
  79. package/dist/x402/facilitator-api.d.ts.map +1 -1
  80. package/dist/x402/facilitator-api.js +64 -3
  81. package/dist/x402/facilitator-api.js.map +1 -1
  82. package/dist/x402/index.d.ts +3 -2
  83. package/dist/x402/index.d.ts.map +1 -1
  84. package/dist/x402/index.js +1 -0
  85. package/dist/x402/index.js.map +1 -1
  86. package/dist/x402/token-request.d.ts +8 -0
  87. package/dist/x402/token-request.d.ts.map +1 -1
  88. package/dist/x402/token-request.js +101 -1
  89. package/dist/x402/token-request.js.map +1 -1
  90. package/dist/x402/token-version.d.ts +97 -0
  91. package/dist/x402/token-version.d.ts.map +1 -0
  92. package/dist/x402/token-version.js +127 -0
  93. package/dist/x402/token-version.js.map +1 -0
  94. package/dist/x402/token.d.ts +33 -2
  95. package/dist/x402/token.d.ts.map +1 -1
  96. package/dist/x402/token.js +47 -2
  97. package/dist/x402/token.js.map +1 -1
  98. package/package.json +22 -13
@@ -1 +1 @@
1
- {"version":3,"file":"agents-api.js","sourceRoot":"","sources":["../../src/api/agents-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAIL,iBAAiB,GAKlB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAsB,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AACnG,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,cAAc,CAAA;AAIrB;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,eAAe;IAC5C;;;;;OAKG;IACH,MAAM,CAA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AC,OAAO,CAAC,CAAA;QACvD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,aAAa,CAAC,WAAW,CAC7B,kCAAkC,EAClC,MAAM,aAAa,CAAC,QAAQ,CAAC,CAC9B,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { safeParseJson } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport {\n AgentAPIAttributes,\n AgentMetadata,\n NvmAPIResult,\n PaginationOptions,\n PaymentOptions,\n PlanCreditsConfig,\n PlanMetadata,\n PlanPriceConfig,\n} from '../common/types.js'\nimport { BasePaymentsAPI, PublicationOptions, resolvePublicationHeaders } from './base-payments.js'\nimport {\n API_URL_ADD_PLAN_AGENT,\n API_URL_GET_AGENT,\n API_URL_GET_AGENTS,\n API_URL_GET_AGENT_PLANS,\n API_URL_REGISTER_AGENT,\n API_URL_REGISTER_AGENTS_AND_PLAN,\n API_URL_REMOVE_PLAN_AGENT,\n API_URL_UPDATE_AGENT,\n} from './nvm-api.js'\n\nexport type { PublicationOptions } from './base-payments.js'\n\n/**\n * The AgentsAPI class provides methods to register and interact with AI Agents on Nevermined.\n */\nexport class AgentsAPI extends BasePaymentsAPI {\n /**\n * This method is used to create a singleton instance of the AgentsAPI class.\n *\n * @param options - The options to initialize the payments class.\n * @returns The instance of the AgentsAPI class.\n */\n static getInstance(options: PaymentOptions): AgentsAPI {\n return new AgentsAPI(options)\n }\n\n /**\n *\n * It registers a new AI Agent on Nevermined.\n * The agent must be associated to one or multiple Payment Plans. Users that are subscribers of a payment plan can query the agent.\n * Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.\n * When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.\n *\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/register-agent\n *\n * @param agentMetadata - @see {@link AgentMetadata}\n * @param agentApi - @see {@link AgentAPIAttributes}\n * @param paymentPlans - the list of payment plans giving access to the agent.\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My AI Payments Agent', tags: ['test'] }\n * const agentApi = { endpoints: [{ 'POST': 'https://example.com/api/v1/agents/:agentId/tasks' }] }\n * const paymentPlans = [planId]\n *\n * const { agentId } = await payments.agents.registerAgent(agentMetadata, agentApi, paymentPlans)\n * ```\n *\n * @returns The unique identifier of the newly created agent (Agent Id).\n */\n public async registerAgent(\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n paymentPlans: string[],\n publicationOptions?: PublicationOptions,\n ): Promise<{ agentId: string }> {\n const body = {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n plans: paymentPlans,\n }\n\n const options = this.getBackendHTTPOptions(\n 'POST',\n body,\n resolvePublicationHeaders(publicationOptions),\n )\n const url = new URL(API_URL_REGISTER_AGENT, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to register agent', await safeParseJson(response))\n }\n const agentData = await response.json()\n return { agentId: agentData.data.agentId }\n }\n\n /**\n *\n * It registers a new AI Agent and a Payment Plan associated to this new agent.\n * Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.\n * When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.\n *\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/register-agent\n *\n * @param agentMetadata - @see {@link AgentMetadata}\n * @param agentApi - @see {@link AgentAPIAttributes}\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My AI Payments Agent', tags: ['test'] }\n * const agentApi { endpoints: [{ 'POST': 'https://example.com/api/v1/agents/:agentId/tasks' }] }\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { agentId, planId } = await payments.agents.registerAgentAndPlan(\n * agentMetadata,\n * agentApi,\n * cryptoPriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the newly created agent (agentId).\n * @returns The unique identifier of the newly created plan (planId).\n */\n public async registerAgentAndPlan(\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n accessLimit?: 'credits' | 'time',\n publicationOptions?: PublicationOptions,\n ): Promise<{\n agentId: string\n planId: string\n txHash: string\n }> {\n if (accessLimit && !['credits', 'time'].includes(accessLimit)) {\n throw new PaymentsError(\n 'Invalid access limit',\n 'accessLimit must be either \"credits\" or \"time\"',\n )\n }\n if (!accessLimit) {\n accessLimit = creditsConfig.durationSecs > 0n ? 'time' : 'credits'\n }\n const body = {\n plan: {\n metadataAttributes: planMetadata,\n priceConfig: priceConfig,\n creditsConfig: creditsConfig,\n accessLimit,\n },\n agent: {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n },\n }\n const options = this.getBackendHTTPOptions(\n 'POST',\n body,\n resolvePublicationHeaders(publicationOptions),\n )\n const url = new URL(API_URL_REGISTER_AGENTS_AND_PLAN, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend(\n 'Unable to register agent & plan',\n await safeParseJson(response),\n )\n }\n const result = await response.json()\n return {\n agentId: result.data.agentId,\n planId: result.data.planId,\n txHash: result.txHash,\n }\n }\n\n /**\n * Gets the metadata for a given Agent identifier.\n *\n * @param agentId - The unique identifier of the agent.\n * @returns A promise that resolves to the agent's metadata.\n * @throws PaymentsError if the agent is not found.\n *\n * @example\n * ```\n * const plan = payments.agents.getAgent(agentId)\n * ```\n */\n public async getAgent(agentId: string) {\n const url = new URL(API_URL_GET_AGENT.replace(':agentId', agentId), this.environment.backend)\n const response = await fetch(url, this.getPublicHTTPOptions('GET'))\n if (!response.ok) {\n throw PaymentsError.fromBackend('Agent not found', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Updates the metadata and API attributes of an existing AI Agent.\n *\n * @param agentId - The unique identifier of the agent.\n * @param agentMetadata - The new metadata attributes for the agent.\n * @param agentApi - The new API attributes for the agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if the agent is not found or if the update fails.\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My Updated Agent', tags: ['test'] }\n * const agentApi = { endpoints: [{ 'POST': 'https://nevermined.app/api/v1/agents/:agentId/tasks' }] }\n *\n * await payments.agents.updateAgentMetadata(agentId, agentMetadata, agentApi)\n * ```\n */\n public async updateAgentMetadata(\n agentId: string,\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n ): Promise<NvmAPIResult> {\n const body = {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n }\n const url = new URL(API_URL_UPDATE_AGENT.replace(':agentId', agentId), this.environment.backend)\n const options = this.getBackendHTTPOptions('PUT', body)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Error updating agent', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Gets the list of plans that can be ordered to get access to an agent.\n *\n * @param agentId - The unique identifier of the agent.\n * @param pagination - Optional pagination options to control the number of results returned.p\n * @returns A promise that resolves to the list of all different plans giving access to the agent.\n * @throws PaymentsError if the agent is not found.\n *\n * @example\n * ```\n * const result = payments.agents.getAgentPlans(planId)\n * // {\n * // total: 10,\n * // page: 1,\n * // offset: 5,\n * // plans: [ ..]\n * // }\n * ```\n */\n public async getAgentPlans(agentId: string, pagination = new PaginationOptions()) {\n const query =\n API_URL_GET_AGENT_PLANS.replace(':agentId', agentId) + '?' + pagination.asQueryParams()\n const url = new URL(query, this.environment.backend)\n const response = await fetch(url, this.getPublicHTTPOptions('GET'))\n if (!response.ok) {\n throw PaymentsError.fromBackend('Agent not found', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Lists the AI agents **you** published (the authenticated caller's own\n * agents). This is account management, not a marketplace search — it never\n * returns other users' agents.\n *\n * @param page - The page number to retrieve.\n * @param offset - The number of items per page.\n * @param sortBy - The field to sort the results by.\n * @param sortOrder - The order in which to sort the results.\n * @param orgId - Optional organization id. When set, returns every agent in\n * that organization (requires active membership) instead of the caller's.\n * @returns A promise that resolves to the paginated list of your agents.\n */\n public async getAgents(\n page = 1,\n offset = 100,\n sortBy = 'created',\n sortOrder: 'asc' | 'desc' = 'desc',\n orgId?: string,\n ): Promise<{ total: number; page: number; offset: number; agents: any[] }> {\n const url = new URL(API_URL_GET_AGENTS, this.environment.backend)\n url.searchParams.set('page', page.toString())\n url.searchParams.set('offset', offset.toString())\n url.searchParams.set('sortBy', sortBy)\n url.searchParams.set('sortOrder', sortOrder)\n if (orgId) url.searchParams.set('orgId', orgId)\n const response = await fetch(url, this.getBackendHTTPOptions('GET'))\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to get agents', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Adds an existing Payment Plan to an AI Agent.\n * After this operation, users with access to the Payment Plan will be able to access the AI Agent.\n *\n * @remarks\n * Only the owner of the Payment Plan can call this method.\n *\n * @param planId - The unique identifier of the Payment Plan.\n * @param agentId - The unique identifier of the AI Agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to add the plan to the agent.\n *\n * @example\n * ```\n * const result = await payments.agents.addPlanToAgent(planId, agentId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async addPlanToAgent(planId: string, agentId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('POST')\n const endpoint = API_URL_ADD_PLAN_AGENT.replace(':planId', planId).replace(':agentId', agentId)\n const url = new URL(endpoint, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to add plan to agent', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Removes a Payment Plan from an AI Agent.\n * After this operation, users with access to the Payment Plan will no longer be able to access the AI Agent.\n *\n * @remarks\n * Only the owner of the Payment Plan can call this method.\n *\n * @param planId - The unique identifier of the Payment Plan.\n * @param agentId - The unique identifier of the AI Agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to remove the plan from the agent.\n *\n * @example\n * ```\n * const result = await payments.agents.removePlanFromAgent(planId, agentId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async removePlanFromAgent(planId: string, agentId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('DELETE')\n const endpoint = API_URL_REMOVE_PLAN_AGENT.replace(':planId', planId).replace(\n ':agentId',\n agentId,\n )\n const url = new URL(endpoint, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend(\n 'Unable to remove plan from agent',\n await safeParseJson(response),\n )\n }\n\n return response.json()\n }\n}\n"]}
1
+ {"version":3,"file":"agents-api.js","sourceRoot":"","sources":["../../src/api/agents-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAC3D,OAAO,EAIL,iBAAiB,GAKlB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAsB,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AACnG,O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,qBAAqB,CAAC,QAAQ,CAAC,CAAA;QACpD,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,OAAO,CAC3E,UAAU,EACV,OAAO,CACR,CAAA;QACD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QACvD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,aAAa,CAAC,WAAW,CAC7B,kCAAkC,EAClC,MAAM,aAAa,CAAC,QAAQ,CAAC,CAC9B,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF","sourcesContent":["import { safeParseJson } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport {\n AgentAPIAttributes,\n AgentMetadata,\n NvmAPIResult,\n PaginationOptions,\n PaymentOptions,\n PlanCreditsConfig,\n PlanMetadata,\n PlanPriceConfig,\n} from '../common/types.js'\nimport { BasePaymentsAPI, PublicationOptions, resolvePublicationHeaders } from './base-payments.js'\nimport {\n API_URL_ADD_PLAN_AGENT,\n API_URL_GET_AGENT,\n API_URL_GET_AGENTS,\n API_URL_GET_AGENT_PLANS,\n API_URL_REGISTER_AGENT,\n API_URL_REGISTER_AGENTS_AND_PLAN,\n API_URL_REMOVE_PLAN_AGENT,\n API_URL_UPDATE_AGENT,\n} from './nvm-api.js'\n\nexport type { PublicationOptions } from './base-payments.js'\n\n/**\n * The AgentsAPI class provides methods to register and interact with AI Agents on Nevermined.\n */\nexport class AgentsAPI extends BasePaymentsAPI {\n /**\n * This method is used to create a singleton instance of the AgentsAPI class.\n *\n * @param options - The options to initialize the payments class.\n * @returns The instance of the AgentsAPI class.\n */\n static getInstance(options: PaymentOptions): AgentsAPI {\n return new AgentsAPI(options)\n }\n\n /**\n *\n * It registers a new AI Agent on Nevermined.\n * The agent must be associated to one or multiple Payment Plans. Users that are subscribers of a payment plan can query the agent.\n * Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.\n * When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.\n *\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/register-agent\n *\n * @param agentMetadata - @see {@link AgentMetadata}\n * @param agentApi - @see {@link AgentAPIAttributes}\n * @param paymentPlans - the list of payment plans giving access to the agent.\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My AI Payments Agent', tags: ['test'] }\n * const agentApi = { endpoints: [{ 'POST': 'https://example.com/api/v1/agents/:agentId/tasks' }] }\n * const paymentPlans = [planId]\n *\n * const { agentId } = await payments.agents.registerAgent(agentMetadata, agentApi, paymentPlans)\n * ```\n *\n * @returns The unique identifier of the newly created agent (Agent Id).\n */\n public async registerAgent(\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n paymentPlans: string[],\n publicationOptions?: PublicationOptions,\n ): Promise<{ agentId: string }> {\n const body = {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n plans: paymentPlans,\n }\n\n const options = this.getBackendHTTPOptions(\n 'POST',\n body,\n resolvePublicationHeaders(publicationOptions),\n )\n const url = new URL(API_URL_REGISTER_AGENT, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to register agent', await safeParseJson(response))\n }\n const agentData = await response.json()\n return { agentId: agentData.data.agentId }\n }\n\n /**\n *\n * It registers a new AI Agent and a Payment Plan associated to this new agent.\n * Depending on the Payment Plan and the configuration of the agent, the usage of the agent/service will consume credits.\n * When the plan expires (because the time is over or the credits are consumed), the user needs to renew the plan to continue using the agent.\n *\n * @remarks This method is oriented to AI Builders\n * @remarks To call this method, the NVM API Key must have publication permissions\n *\n * @see https://nevermined.ai/docs/tutorials/builders/register-agent\n *\n * @param agentMetadata - @see {@link AgentMetadata}\n * @param agentApi - @see {@link AgentAPIAttributes}\n * @param planMetadata - @see {@link PlanMetadata}\n * @param priceConfig - @see {@link PlanPriceConfig}\n * @param creditsConfig - @see {@link PlanCreditsConfig}\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My AI Payments Agent', tags: ['test'] }\n * const agentApi { endpoints: [{ 'POST': 'https://example.com/api/v1/agents/:agentId/tasks' }] }\n * const cryptoPriceConfig = getNativeTokenPriceConfig(100n, builderAddress)\n * const 1dayDurationPlan = getExpirableDurationConfig(ONE_DAY_DURATION)\n * const { agentId, planId } = await payments.agents.registerAgentAndPlan(\n * agentMetadata,\n * agentApi,\n * cryptoPriceConfig,\n * 1dayDurationPlan\n * )\n * ```\n *\n * @returns The unique identifier of the newly created agent (agentId).\n * @returns The unique identifier of the newly created plan (planId).\n */\n public async registerAgentAndPlan(\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n planMetadata: PlanMetadata,\n priceConfig: PlanPriceConfig,\n creditsConfig: PlanCreditsConfig,\n accessLimit?: 'credits' | 'time',\n publicationOptions?: PublicationOptions,\n ): Promise<{\n agentId: string\n planId: string\n txHash: string\n }> {\n if (accessLimit && !['credits', 'time'].includes(accessLimit)) {\n throw new PaymentsError(\n 'Invalid access limit',\n 'accessLimit must be either \"credits\" or \"time\"',\n )\n }\n if (!accessLimit) {\n accessLimit = creditsConfig.durationSecs > 0n ? 'time' : 'credits'\n }\n const body = {\n plan: {\n metadataAttributes: planMetadata,\n priceConfig: priceConfig,\n creditsConfig: creditsConfig,\n accessLimit,\n },\n agent: {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n },\n }\n const options = this.getBackendHTTPOptions(\n 'POST',\n body,\n resolvePublicationHeaders(publicationOptions),\n )\n const url = new URL(API_URL_REGISTER_AGENTS_AND_PLAN, this.environment.backend)\n\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend(\n 'Unable to register agent & plan',\n await safeParseJson(response),\n )\n }\n const result = await response.json()\n return {\n agentId: result.data.agentId,\n planId: result.data.planId,\n txHash: result.txHash,\n }\n }\n\n /**\n * Gets the metadata for a given Agent identifier.\n *\n * @param agentId - The unique identifier of the agent.\n * @returns A promise that resolves to the agent's metadata.\n * @throws PaymentsError if the agent is not found.\n *\n * @example\n * ```\n * const plan = payments.agents.getAgent(agentId)\n * ```\n */\n public async getAgent(agentId: string) {\n const url = new URL(API_URL_GET_AGENT.replace(':agentId', agentId), this.environment.backend)\n const response = await fetch(url, this.getPublicHTTPOptions('GET'))\n if (!response.ok) {\n throw PaymentsError.fromBackend('Agent not found', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Updates the metadata and API attributes of an existing AI Agent.\n *\n * @param agentId - The unique identifier of the agent.\n * @param agentMetadata - The new metadata attributes for the agent.\n * @param agentApi - The new API attributes for the agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if the agent is not found or if the update fails.\n *\n * @example\n * ```\n * const agentMetadata = { name: 'My Updated Agent', tags: ['test'] }\n * const agentApi = { endpoints: [{ 'POST': 'https://nevermined.app/api/v1/agents/:agentId/tasks' }] }\n *\n * await payments.agents.updateAgentMetadata(agentId, agentMetadata, agentApi)\n * ```\n */\n public async updateAgentMetadata(\n agentId: string,\n agentMetadata: AgentMetadata,\n agentApi: AgentAPIAttributes,\n ): Promise<NvmAPIResult> {\n const body = {\n metadataAttributes: agentMetadata,\n agentApiAttributes: agentApi,\n }\n const url = new URL(API_URL_UPDATE_AGENT.replace(':agentId', agentId), this.environment.backend)\n const options = this.getBackendHTTPOptions('PUT', body)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Error updating agent', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Gets the list of plans that can be ordered to get access to an agent.\n *\n * @param agentId - The unique identifier of the agent.\n * @param pagination - Optional pagination options. Accepts a plain object\n * (`{ page, offset, sortBy, sortOrder }`) or a `PaginationOptions` instance.\n * @returns A promise that resolves to the list of all different plans giving access to the agent.\n * @throws PaymentsError if the agent is not found.\n *\n * @example\n * ```\n * const result = payments.agents.getAgentPlans(agentId, { page: 1, offset: 10 })\n * // {\n * // total: 10,\n * // page: 1,\n * // offset: 5,\n * // plans: [ ..]\n * // }\n * ```\n */\n public async getAgentPlans(agentId: string, pagination: Partial<PaginationOptions> = {}) {\n const query =\n API_URL_GET_AGENT_PLANS.replace(':agentId', agentId) +\n '?' +\n new PaginationOptions(pagination).asQueryParams()\n const url = new URL(query, this.environment.backend)\n const response = await fetch(url, this.getPublicHTTPOptions('GET'))\n if (!response.ok) {\n throw PaymentsError.fromBackend('Agent not found', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Lists the AI agents **you** published (the authenticated caller's own\n * agents). This is account management, not a marketplace search — it never\n * returns other users' agents.\n *\n * @param page - The page number to retrieve.\n * @param offset - The number of items per page.\n * @param sortBy - The field to sort the results by.\n * @param sortOrder - The order in which to sort the results.\n * @param orgId - Optional organization id. When set, returns every agent in\n * that organization (requires active membership) instead of the caller's.\n * @returns A promise that resolves to the paginated list of your agents.\n */\n public async getAgents(\n page = 1,\n offset = 100,\n sortBy = 'created',\n sortOrder: 'asc' | 'desc' = 'desc',\n orgId?: string,\n ): Promise<{ total: number; page: number; offset: number; agents: any[] }> {\n const url = new URL(API_URL_GET_AGENTS, this.environment.backend)\n url.searchParams.set('page', page.toString())\n url.searchParams.set('offset', offset.toString())\n url.searchParams.set('sortBy', sortBy)\n url.searchParams.set('sortOrder', sortOrder)\n if (orgId) url.searchParams.set('orgId', orgId)\n const response = await fetch(url, this.getBackendHTTPOptions('GET'))\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to get agents', await safeParseJson(response))\n }\n return response.json()\n }\n\n /**\n * Adds an existing Payment Plan to an AI Agent.\n * After this operation, users with access to the Payment Plan will be able to access the AI Agent.\n *\n * @remarks\n * Only the owner of the Payment Plan can call this method.\n *\n * @param planId - The unique identifier of the Payment Plan.\n * @param agentId - The unique identifier of the AI Agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to add the plan to the agent.\n *\n * @example\n * ```\n * const result = await payments.agents.addPlanToAgent(planId, agentId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async addPlanToAgent(planId: string, agentId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('POST')\n const endpoint = API_URL_ADD_PLAN_AGENT.replace(':planId', planId).replace(':agentId', agentId)\n const url = new URL(endpoint, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend('Unable to add plan to agent', await safeParseJson(response))\n }\n\n return response.json()\n }\n\n /**\n * Removes a Payment Plan from an AI Agent.\n * After this operation, users with access to the Payment Plan will no longer be able to access the AI Agent.\n *\n * @remarks\n * Only the owner of the Payment Plan can call this method.\n *\n * @param planId - The unique identifier of the Payment Plan.\n * @param agentId - The unique identifier of the AI Agent.\n * @returns @see {@link NvmAPIResult} A promise that resolves indicating if the operation was successful.\n * @throws PaymentsError if unable to remove the plan from the agent.\n *\n * @example\n * ```\n * const result = await payments.agents.removePlanFromAgent(planId, agentId)\n * // {\n * // txHash: '0x8d29d5769e832a35e53f80cd4e8890d941c50a09c33dbd975533debc894f2535',\n * // success: true\n * // }\n * ```\n */\n public async removePlanFromAgent(planId: string, agentId: string): Promise<NvmAPIResult> {\n const options = this.getBackendHTTPOptions('DELETE')\n const endpoint = API_URL_REMOVE_PLAN_AGENT.replace(':planId', planId).replace(\n ':agentId',\n agentId,\n )\n const url = new URL(endpoint, this.environment.backend)\n const response = await fetch(url, options)\n if (!response.ok) {\n throw PaymentsError.fromBackend(\n 'Unable to remove plan from agent',\n await safeParseJson(response),\n )\n }\n\n return response.json()\n }\n}\n"]}
@@ -56,8 +56,13 @@ export declare abstract class BasePaymentsAPI {
56
56
  * (`<prefix>:<jwt>`); the key wins whenever its prefix is recognized. The
57
57
  * deprecated `environment` option is still honored as a fallback when the
58
58
  * key has no recognized prefix (e.g. local/custom dev), and ultimately
59
- * defaults to `custom`. Passing `environment` emits a one-time deprecation
60
- * warning.
59
+ * defaults to `custom`.
60
+ *
61
+ * The deprecation warning fires only when a passed `environment` is actually
62
+ * overridden by the key prefix (i.e. silently ignored). When it matches the
63
+ * derived environment, or is the fallback that's actually used, it's harmless
64
+ * — documented snippets still pass a matching `environment`, so nagging every
65
+ * new integration would be pure noise (#431).
61
66
  */
62
67
  private resolveEnvironmentName;
63
68
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"base-payments.d.ts","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,EACL,eAAe,EACf,eAAe,EAGhB,MAAM,oBAAoB,CAAA;AAM3B;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,qBAAqB,CAAA;AAUvD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAKpC;AAED;;;GAGG;AACH,8BAAsB,eAAe;IACnC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,MAAM,EAAE,aAAa,CAAA;IAC/B,SAAS,CAAC,WAAW,EAAE,eAAe,CAAA;IACtC,SAAS,CAAC,eAAe,EAAE,eAAe,CAAA;IAC1C,SAAS,CAAC,SAAS,EAAE,MAAM,CAAA;IAC3B,SAAS,CAAC,KAA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I7D;;;;;;;;;OASG;IACH,SAAS,CAAC,qBAAqB,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,GAAG,EACV,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IA4BvC;;;;;;;;OAQG;IACH,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG;gBAE7C,MAAM;iBACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;eACxB,MAAM;;CAgBlB"}
@@ -73,20 +73,27 @@ export class BasePaymentsAPI {
73
73
  * (`<prefix>:<jwt>`); the key wins whenever its prefix is recognized. The
74
74
  * deprecated `environment` option is still honored as a fallback when the
75
75
  * key has no recognized prefix (e.g. local/custom dev), and ultimately
76
- * defaults to `custom`. Passing `environment` emits a one-time deprecation
77
- * warning.
76
+ * defaults to `custom`.
77
+ *
78
+ * The deprecation warning fires only when a passed `environment` is actually
79
+ * overridden by the key prefix (i.e. silently ignored). When it matches the
80
+ * derived environment, or is the fallback that's actually used, it's harmless
81
+ * — documented snippets still pass a matching `environment`, so nagging every
82
+ * new integration would be pure noise (#431).
78
83
  */
79
84
  resolveEnvironmentName(options) {
80
85
  const fromKey = getEnvironmentFromApiKey(options.nvmApiKey);
81
- if (options.environment && !environmentOptionDeprecationWarned) {
86
+ const resolved = fromKey ?? options.environment ?? 'custom';
87
+ if (options.environment &&
88
+ options.environment !== resolved &&
89
+ !environmentOptionDeprecationWarned) {
82
90
  environmentOptionDeprecationWarned = true;
83
- const override = fromKey && fromKey !== options.environment
84
- ? ` It is ignored in favor of the environment derived from the API key ('${fromKey}').`
85
- : '';
86
91
  console.warn("[DEPRECATED] The 'environment' option is deprecated; the environment is now derived " +
87
- `from the NVM API key prefix.${override} Remove the 'environment' option to silence this warning.`);
92
+ `from the NVM API key prefix. Your value ('${options.environment}') is ignored in favor of ` +
93
+ `the environment derived from the API key ('${resolved}'). Remove the 'environment' option ` +
94
+ 'to silence this warning.');
88
95
  }
89
- return fromKey ?? options.environment ?? 'custom';
96
+ return resolved;
90
97
  }
91
98
  /**
92
99
  * Parses the NVM API Key to extract the account address.
@@ -1 +1 @@
1
- {"version":3,"file":"base-payments.js","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,EAGL,YAAY,EACZ,wBAAwB,GACzB,MAAM,oBAAoB,CAAA;AAE3B,8EAA8E;AAC9E,8EAA8E;AAC9E,IAAI,kCAAkC,GAAG,KAAK,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAA;AAEvD;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAS,CAAC,qBAAqB,CAAC,CAAC,CAAA;AAiBtE;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAA4B;IAE5B,IAAI,OAAO,EAAE,cAAc,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC,cAAc,EAAE,CAAA;IAC5D,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAkBnC,YAAY,OAAuB;QAF5B,sBAAiB,GAAG,IAAI,CAAA;QAG7B,uEAAuE;QACvE,qEAAqE;QACrE,iEAAiE;QACjE,gEAAgE;QAChE,mEAAmE;QACnE,2BAA2B;QAC3B,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YAC/C,MAAM,IAAI,aAAa,CACrB,WAA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js'\nimport { jsonReplacer } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { PaymentOptions, PaymentScheme } from '../common/types.js'\nimport {\n EnvironmentInfo,\n EnvironmentName,\n Environments,\n getEnvironmentFromApiKey,\n} from '../environments.js'\n\n// Emit the `environment` deprecation notice at most once per process to avoid\n// log spam when many sub-API instances are constructed from the same options.\nlet environmentOptionDeprecationWarned = false\n\n/**\n * Header used by the Nevermined backend to resolve the active organization\n * context for an authenticated request. Resolution priority is:\n * path `:orgId` &gt; this header &gt; API-key tag &gt; fallback membership &gt; personal.\n * See `apps/api/src/common/guards/current-org-context.guard.ts` in nvm-monorepo.\n */\nexport const CURRENT_ORG_ID_HEADER = 'X-Current-Org-Id'\n\n/**\n * Set of header names that callers can pass to `getBackendHTTPOptions` via\n * `extraHeaders`. Anything outside this set is dropped silently so a stray\n * `Authorization` or `Content-Type` override can't clobber the SDK's\n * transport security headers.\n */\nconst ALLOWED_EXTRA_HEADERS = new Set<string>([CURRENT_ORG_ID_HEADER])\n\n/**\n * Options accepted by publication methods (`registerAgent`,\n * `registerAgentAndPlan`, `registerPlan`, …) that want to override the\n * active organization workspace for a single call.\n */\nexport type PublicationOptions = {\n /**\n * Organization id (e.g. `org-…`) to publish into. When set, the SDK\n * sends an `X-Current-Org-Id` header for this call only — the caller's\n * instance-level pin (set via `Payments.setOrganizationId`) is not\n * affected.\n */\n organizationId?: string\n}\n\n/**\n * Builds the `extraHeaders` argument for `getBackendHTTPOptions` from\n * publication options. Returns `undefined` when no override is requested\n * so existing callers receive identical request shapes.\n */\nexport function resolvePublicationHeaders(\n options?: PublicationOptions,\n): Record<string, string> | undefined {\n if (options?.organizationId) {\n return { [CURRENT_ORG_ID_HEADER]: options.organizationId }\n }\n return undefined\n}\n\n/**\n * Base class extended by all Payments API classes.\n * It provides common functionality such as parsing the NVM API Key and getting the account address.\n */\nexport abstract class BasePaymentsAPI {\n protected nvmApiKey: string\n protected scheme: PaymentScheme\n protected environment: EnvironmentInfo\n protected environmentName: EnvironmentName\n protected returnUrl: string\n protected appId?: string\n /**\n * Backend API version (MAJOR.MINOR) pinned by this instance, set from\n * `options.version`. When unset, every request defaults to\n * {@link LOCKED_API_VERSION}.\n */\n protected version?: string\n protected accountAddress: string\n protected heliconeApiKey: string\n protected currentOrganizationId: string | null\n public isBrowserInstance = true\n\n constructor(options: PaymentOptions) {\n // Type-level narrowing of PaymentScheme to 'nvm' won't protect callers\n // pinned to an older .d.ts that still has 'visa' in the union — they\n // would silently fall through to the standard pipeline and hit a\n // misleading 'Invalid NVM API Key' from parseNvmApiKey when the\n // legacy Visa path tolerated a non-JWT key. Reject up front with a\n // clear migration message.\n if (options.scheme && options.scheme !== 'nvm') {\n throw new PaymentsError(\n `scheme '${options.scheme}' is no longer supported. Visa is now exposed as provider:'visa' on createDelegation; construct Payments without a scheme override.`,\n )\n }\n this.nvmApiKey = options.nvmApiKey\n this.scheme = options.scheme || 'nvm'\n this.returnUrl = options.returnUrl || ''\n this.environmentName = this.resolveEnvironmentName(options)\n this.environment = Environments[this.environmentName]\n this.appId = options.appId\n // `version` is the backend API pin (MAJOR.MINOR) sent verbatim as\n // Nevermined-Version. Fail fast on a malformed value rather than shipping\n // an invalid header (e.g. an SDK package version '1.0.0', 'v1.1', or '')\n // that the backend rejects with 400 on every call.\n if (options.version !== undefined && !/^\\d+\\.\\d+$/.test(options.version)) {\n throw new PaymentsError(\n `Invalid 'version' option '${options.version}': expected a backend API version as MAJOR.MINOR (e.g. '1.1'). Omit it to use the SDK's default pin.`,\n )\n }\n this.version = options.version\n this.currentOrganizationId = options.organizationId ?? null\n\n const { accountAddress, heliconeApiKey } = this.parseNvmApiKey()\n this.accountAddress = accountAddress\n this.heliconeApiKey = heliconeApiKey\n }\n\n /**\n * Resolves the active environment for this instance.\n *\n * The environment is derived from the NVM API key prefix\n * (`<prefix>:<jwt>`); the key wins whenever its prefix is recognized. The\n * deprecated `environment` option is still honored as a fallback when the\n * key has no recognized prefix (e.g. local/custom dev), and ultimately\n * defaults to `custom`. Passing `environment` emits a one-time deprecation\n * warning.\n */\n private resolveEnvironmentName(options: PaymentOptions): EnvironmentName {\n const fromKey = getEnvironmentFromApiKey(options.nvmApiKey)\n\n if (options.environment && !environmentOptionDeprecationWarned) {\n environmentOptionDeprecationWarned = true\n const override =\n fromKey && fromKey !== options.environment\n ? ` It is ignored in favor of the environment derived from the API key ('${fromKey}').`\n : ''\n console.warn(\n \"[DEPRECATED] The 'environment' option is deprecated; the environment is now derived \" +\n `from the NVM API key prefix.${override} Remove the 'environment' option to silence this warning.`,\n )\n }\n\n return fromKey ?? options.environment ?? 'custom'\n }\n\n /**\n * Parses the NVM API Key to extract the account address.\n * @throws PaymentsError if the API key is invalid.\n */\n protected parseNvmApiKey(): { accountAddress: string; heliconeApiKey: string } {\n try {\n if (!this.nvmApiKey) {\n throw new PaymentsError('NVM API Key is required')\n }\n const jwt = decodeJwt(this.nvmApiKey)\n const accountAddress = jwt.sub as string\n const heliconeApiKey = jwt.o11y as string\n return { accountAddress, heliconeApiKey }\n } catch (error) {\n throw new PaymentsError('Invalid NVM API Key')\n }\n }\n\n /**\n * Returns the environment name used to initialize the Payments instance.\n * @returns The environment name (e.g. 'sandbox', 'live')\n */\n public getEnvironmentName(): EnvironmentName {\n return this.environmentName\n }\n\n /**\n * It returns the account address associated with the NVM API Key used to initialize the Payments Library instance.\n * @returns The account address extracted from the NVM API Key\n */\n public getAccountAddress(): string | undefined {\n return this.accountAddress\n }\n\n /**\n * Returns the current organization context applied to every authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * `null` means \"no pinned workspace\" — the backend falls back to the\n * caller's API-key tag or most-recent active membership.\n */\n public getOrganizationId(): string | null {\n return this.currentOrganizationId\n }\n\n /**\n * Sets the organization context applied to every subsequent authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * Pass `null` to clear the pin and fall back to the backend default.\n *\n * @param organizationId - Org ID (e.g. `org-…`) or `null` to clear.\n */\n public setOrganizationId(organizationId: string | null): void {\n this.currentOrganizationId = organizationId\n }\n\n /**\n * Returns the HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @param extraHeaders - Optional per-call header overrides. Use\n * `{ 'X-Current-Org-Id': orgId }` to target a specific workspace for\n * one call without mutating the instance-level pin.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(\n method: string,\n body?: any,\n extraHeaders?: Record<string, string>,\n ) {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n }\n if (this.currentOrganizationId) {\n headers[CURRENT_ORG_ID_HEADER] = this.currentOrganizationId\n }\n if (extraHeaders) {\n // Allowlist callers' header overrides so a passed-in `Authorization`\n // or `Content-Type` can't clobber the SDK's transport security\n // headers. Today only `X-Current-Org-Id` is allowed through.\n for (const [name, value] of Object.entries(extraHeaders)) {\n if (ALLOWED_EXTRA_HEADERS.has(name)) {\n headers[name] = value\n }\n }\n }\n return {\n method,\n headers,\n ...(body && { body: JSON.stringify(body, jsonReplacer) }),\n }\n }\n\n /**\n * Get HTTP options for public backend requests (no authorization header).\n * Converts body keys from snake_case to camelCase for consistency.\n *\n * @param method - HTTP method\n * @param body - Optional request body (keys will be converted to camelCase)\n * @returns HTTP options object\n * @internal\n */\n protected getPublicHTTPOptions(method: string, body?: any) {\n const options: {\n method: string\n headers: Record<string, string>\n body?: string\n } = {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n },\n }\n\n if (body) {\n options.body = JSON.stringify(body, jsonReplacer)\n }\n\n return options\n }\n}\n"]}
1
+ {"version":3,"file":"base-payments.js","sourceRoot":"","sources":["../../src/api/base-payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAChC,OAAO,EAAE,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;QACD,IAAI,YAAY,EAAE,CAAC;YACjB,qEAAqE;YACrE,+DAA+D;YAC/D,6DAA6D;YAC7D,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;gBACzD,IAAI,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACpC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;gBACvB,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO;YACL,MAAM;YACN,OAAO;YACP,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC;SAC1D,CAAA;IACH,CAAC;IAED;;;;;;;;OAQG;IACO,oBAAoB,CAAC,MAAc,EAAE,IAAU;QACvD,MAAM,OAAO,GAIT;YACF,MAAM;YACN,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,cAAc,EAAE,kBAAkB;gBAClC,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,OAAO,IAAI,kBAAkB;aACzD;SACF,CAAA;QAED,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACnD,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { decodeJwt } from 'jose'\nimport { API_VERSION_HEADER, LOCKED_API_VERSION } from '../common/api-version.js'\nimport { jsonReplacer } from '../common/helper.js'\nimport { PaymentsError } from '../common/payments.error.js'\nimport { PaymentOptions, PaymentScheme } from '../common/types.js'\nimport {\n EnvironmentInfo,\n EnvironmentName,\n Environments,\n getEnvironmentFromApiKey,\n} from '../environments.js'\n\n// Emit the `environment` deprecation notice at most once per process to avoid\n// log spam when many sub-API instances are constructed from the same options.\nlet environmentOptionDeprecationWarned = false\n\n/**\n * Header used by the Nevermined backend to resolve the active organization\n * context for an authenticated request. Resolution priority is:\n * path `:orgId` &gt; this header &gt; API-key tag &gt; fallback membership &gt; personal.\n * See `apps/api/src/common/guards/current-org-context.guard.ts` in nvm-monorepo.\n */\nexport const CURRENT_ORG_ID_HEADER = 'X-Current-Org-Id'\n\n/**\n * Set of header names that callers can pass to `getBackendHTTPOptions` via\n * `extraHeaders`. Anything outside this set is dropped silently so a stray\n * `Authorization` or `Content-Type` override can't clobber the SDK's\n * transport security headers.\n */\nconst ALLOWED_EXTRA_HEADERS = new Set<string>([CURRENT_ORG_ID_HEADER])\n\n/**\n * Options accepted by publication methods (`registerAgent`,\n * `registerAgentAndPlan`, `registerPlan`, …) that want to override the\n * active organization workspace for a single call.\n */\nexport type PublicationOptions = {\n /**\n * Organization id (e.g. `org-…`) to publish into. When set, the SDK\n * sends an `X-Current-Org-Id` header for this call only — the caller's\n * instance-level pin (set via `Payments.setOrganizationId`) is not\n * affected.\n */\n organizationId?: string\n}\n\n/**\n * Builds the `extraHeaders` argument for `getBackendHTTPOptions` from\n * publication options. Returns `undefined` when no override is requested\n * so existing callers receive identical request shapes.\n */\nexport function resolvePublicationHeaders(\n options?: PublicationOptions,\n): Record<string, string> | undefined {\n if (options?.organizationId) {\n return { [CURRENT_ORG_ID_HEADER]: options.organizationId }\n }\n return undefined\n}\n\n/**\n * Base class extended by all Payments API classes.\n * It provides common functionality such as parsing the NVM API Key and getting the account address.\n */\nexport abstract class BasePaymentsAPI {\n protected nvmApiKey: string\n protected scheme: PaymentScheme\n protected environment: EnvironmentInfo\n protected environmentName: EnvironmentName\n protected returnUrl: string\n protected appId?: string\n /**\n * Backend API version (MAJOR.MINOR) pinned by this instance, set from\n * `options.version`. When unset, every request defaults to\n * {@link LOCKED_API_VERSION}.\n */\n protected version?: string\n protected accountAddress: string\n protected heliconeApiKey: string\n protected currentOrganizationId: string | null\n public isBrowserInstance = true\n\n constructor(options: PaymentOptions) {\n // Type-level narrowing of PaymentScheme to 'nvm' won't protect callers\n // pinned to an older .d.ts that still has 'visa' in the union — they\n // would silently fall through to the standard pipeline and hit a\n // misleading 'Invalid NVM API Key' from parseNvmApiKey when the\n // legacy Visa path tolerated a non-JWT key. Reject up front with a\n // clear migration message.\n if (options.scheme && options.scheme !== 'nvm') {\n throw new PaymentsError(\n `scheme '${options.scheme}' is no longer supported. Visa is now exposed as provider:'visa' on createDelegation; construct Payments without a scheme override.`,\n )\n }\n this.nvmApiKey = options.nvmApiKey\n this.scheme = options.scheme || 'nvm'\n this.returnUrl = options.returnUrl || ''\n this.environmentName = this.resolveEnvironmentName(options)\n this.environment = Environments[this.environmentName]\n this.appId = options.appId\n // `version` is the backend API pin (MAJOR.MINOR) sent verbatim as\n // Nevermined-Version. Fail fast on a malformed value rather than shipping\n // an invalid header (e.g. an SDK package version '1.0.0', 'v1.1', or '')\n // that the backend rejects with 400 on every call.\n if (options.version !== undefined && !/^\\d+\\.\\d+$/.test(options.version)) {\n throw new PaymentsError(\n `Invalid 'version' option '${options.version}': expected a backend API version as MAJOR.MINOR (e.g. '1.1'). Omit it to use the SDK's default pin.`,\n )\n }\n this.version = options.version\n this.currentOrganizationId = options.organizationId ?? null\n\n const { accountAddress, heliconeApiKey } = this.parseNvmApiKey()\n this.accountAddress = accountAddress\n this.heliconeApiKey = heliconeApiKey\n }\n\n /**\n * Resolves the active environment for this instance.\n *\n * The environment is derived from the NVM API key prefix\n * (`<prefix>:<jwt>`); the key wins whenever its prefix is recognized. The\n * deprecated `environment` option is still honored as a fallback when the\n * key has no recognized prefix (e.g. local/custom dev), and ultimately\n * defaults to `custom`.\n *\n * The deprecation warning fires only when a passed `environment` is actually\n * overridden by the key prefix (i.e. silently ignored). When it matches the\n * derived environment, or is the fallback that's actually used, it's harmless\n * — documented snippets still pass a matching `environment`, so nagging every\n * new integration would be pure noise (#431).\n */\n private resolveEnvironmentName(options: PaymentOptions): EnvironmentName {\n const fromKey = getEnvironmentFromApiKey(options.nvmApiKey)\n const resolved = fromKey ?? options.environment ?? 'custom'\n\n if (\n options.environment &&\n options.environment !== resolved &&\n !environmentOptionDeprecationWarned\n ) {\n environmentOptionDeprecationWarned = true\n console.warn(\n \"[DEPRECATED] The 'environment' option is deprecated; the environment is now derived \" +\n `from the NVM API key prefix. Your value ('${options.environment}') is ignored in favor of ` +\n `the environment derived from the API key ('${resolved}'). Remove the 'environment' option ` +\n 'to silence this warning.',\n )\n }\n\n return resolved\n }\n\n /**\n * Parses the NVM API Key to extract the account address.\n * @throws PaymentsError if the API key is invalid.\n */\n protected parseNvmApiKey(): { accountAddress: string; heliconeApiKey: string } {\n try {\n if (!this.nvmApiKey) {\n throw new PaymentsError('NVM API Key is required')\n }\n const jwt = decodeJwt(this.nvmApiKey)\n const accountAddress = jwt.sub as string\n const heliconeApiKey = jwt.o11y as string\n return { accountAddress, heliconeApiKey }\n } catch (error) {\n throw new PaymentsError('Invalid NVM API Key')\n }\n }\n\n /**\n * Returns the environment name used to initialize the Payments instance.\n * @returns The environment name (e.g. 'sandbox', 'live')\n */\n public getEnvironmentName(): EnvironmentName {\n return this.environmentName\n }\n\n /**\n * It returns the account address associated with the NVM API Key used to initialize the Payments Library instance.\n * @returns The account address extracted from the NVM API Key\n */\n public getAccountAddress(): string | undefined {\n return this.accountAddress\n }\n\n /**\n * Returns the current organization context applied to every authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * `null` means \"no pinned workspace\" — the backend falls back to the\n * caller's API-key tag or most-recent active membership.\n */\n public getOrganizationId(): string | null {\n return this.currentOrganizationId\n }\n\n /**\n * Sets the organization context applied to every subsequent authenticated\n * backend request via the `X-Current-Org-Id` header.\n *\n * Pass `null` to clear the pin and fall back to the backend default.\n *\n * @param organizationId - Org ID (e.g. `org-…`) or `null` to clear.\n */\n public setOrganizationId(organizationId: string | null): void {\n this.currentOrganizationId = organizationId\n }\n\n /**\n * Returns the HTTP options required to query the backend.\n * @param method - HTTP method.\n * @param body - Optional request body.\n * @param extraHeaders - Optional per-call header overrides. Use\n * `{ 'X-Current-Org-Id': orgId }` to target a specific workspace for\n * one call without mutating the instance-level pin.\n * @returns HTTP options object.\n * @internal\n */\n protected getBackendHTTPOptions(\n method: string,\n body?: any,\n extraHeaders?: Record<string, string>,\n ) {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.nvmApiKey}`,\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n }\n if (this.currentOrganizationId) {\n headers[CURRENT_ORG_ID_HEADER] = this.currentOrganizationId\n }\n if (extraHeaders) {\n // Allowlist callers' header overrides so a passed-in `Authorization`\n // or `Content-Type` can't clobber the SDK's transport security\n // headers. Today only `X-Current-Org-Id` is allowed through.\n for (const [name, value] of Object.entries(extraHeaders)) {\n if (ALLOWED_EXTRA_HEADERS.has(name)) {\n headers[name] = value\n }\n }\n }\n return {\n method,\n headers,\n ...(body && { body: JSON.stringify(body, jsonReplacer) }),\n }\n }\n\n /**\n * Get HTTP options for public backend requests (no authorization header).\n * Converts body keys from snake_case to camelCase for consistency.\n *\n * @param method - HTTP method\n * @param body - Optional request body (keys will be converted to camelCase)\n * @returns HTTP options object\n * @internal\n */\n protected getPublicHTTPOptions(method: string, body?: any) {\n const options: {\n method: string\n headers: Record<string, string>\n body?: string\n } = {\n method,\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n [API_VERSION_HEADER]: this.version ?? LOCKED_API_VERSION,\n },\n }\n\n if (body) {\n options.body = JSON.stringify(body, jsonReplacer)\n }\n\n return options\n }\n}\n"]}
@@ -72,10 +72,10 @@ export declare abstract class AbstractHTTPClient {
72
72
  }, accessToken?: string): {
73
73
  Authorization?: string | undefined;
74
74
  };
75
- request(method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', url: string, data?: any, reqOptions?: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}>>;
76
- get(url: string, reqOptions?: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}>>;
77
- post(url: string, data: any, reqOptions: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}>>;
78
- put(url: string, data: any, reqOptions: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}>>;
79
- delete(url: string, data: any, reqOptions: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}>>;
75
+ request(method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', url: string, data?: any, reqOptions?: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}, any>>;
76
+ get(url: string, reqOptions?: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}, any>>;
77
+ post(url: string, data: any, reqOptions: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}, any>>;
78
+ put(url: string, data: any, reqOptions: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}, any>>;
79
+ delete(url: string, data: any, reqOptions: HTTPRequestOptions): Promise<import("axios").AxiosResponse<any, any, {}, any>>;
80
80
  }
81
81
  //# sourceMappingURL=nvm-api.d.ts.map
@@ -1,12 +1,36 @@
1
1
  import type OpenAI from 'openai';
2
2
  import type Together from 'together-ai';
3
- import type * as ChainsModule from 'langchain/chains';
4
- import type * as AgentsModule from 'langchain/agents';
5
- import type * as ToolsModule from 'langchain/tools';
6
3
  import type * as anthropic from '@anthropic-ai/sdk';
7
4
  import type * as cohere from 'cohere-ai';
8
5
  import type * as bedrock from '@aws-sdk/client-bedrock-runtime';
9
6
  import type * as google_aiplatform from '@google-cloud/aiplatform';
7
+ /**
8
+ * A LangChain entry-point module handed over by the caller.
9
+ *
10
+ * On the resolved `@traceloop/node-server-sdk` (0.26.0) nothing reads a member
11
+ * of it. `observability-api.ts` forwards the bag to
12
+ * `traceloop.initialize({ instrumentModules })` behind an `as any`, and there
13
+ * the field is declared `langchain?: boolean` and never consulted —
14
+ * `instrumentModules?.langchain` appears nowhere in its `dist/` — because
15
+ * LangChain is instrumented unconditionally by hooking
16
+ * `@langchain/core/callbacks/manager`.
17
+ *
18
+ * That was not always so. traceloop 0.14 declared five module fields
19
+ * (`chainsModule`, `agentsModule`, `toolsModule`, `runnablesModule`,
20
+ * `vectorStoreModule`) and passed them to `manuallyInstrument`; #158 took three
21
+ * of them, and they went inert with the 0.26 bump in #312. They stay for source
22
+ * compatibility with callers written against that contract.
23
+ *
24
+ * Typing the three as `typeof import('langchain/chains')` and friends therefore
25
+ * bought no checking, and cost twice. It pinned this SDK's build to one
26
+ * LangChain layout — v1 moved the legacy chains and agents entry points out, so
27
+ * those subpaths stopped resolving and a dev-only bump failed with TS2307
28
+ * (#317) — and, because declaration emit keeps those imports in the published
29
+ * `types.d.ts` while `langchain` is neither a dependency nor a peer, it broke
30
+ * the typecheck of any consumer building with `skipLibCheck: false` unless they
31
+ * happened to have a 0.3-layout `langchain` installed.
32
+ */
33
+ export type LangChainModule = Record<string, unknown>;
10
34
  export type AsyncLoggerProviders = {
11
35
  openAI?: typeof OpenAI;
12
36
  anthropic?: typeof anthropic;
@@ -14,10 +38,14 @@ export type AsyncLoggerProviders = {
14
38
  bedrock?: typeof bedrock;
15
39
  google_aiplatform?: typeof google_aiplatform;
16
40
  together?: typeof Together;
41
+ /**
42
+ * Inert on the resolved traceloop (0.26.0), which instruments LangChain
43
+ * unconditionally and ignores these modules. See {@link LangChainModule}.
44
+ */
17
45
  langchain?: {
18
- chainsModule?: typeof ChainsModule;
19
- agentsModule?: typeof AgentsModule;
20
- toolsModule?: typeof ToolsModule;
46
+ chainsModule?: LangChainModule;
47
+ agentsModule?: LangChainModule;
48
+ toolsModule?: LangChainModule;
21
49
  };
22
50
  };
23
51
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/api/observability-api/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,KAAK,QAAQ,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,KAAK,YAAY,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,kCAAkC,EAAE,MAAM,CAAA;IAC1C,mCAAmC,EAAE,MAAM,CAAA;IAC3C,yBAAyB,EAAE,MAAM,CAAA;IACjC,iCAAiC,EAAE,MAAM,CAAA;IACzC,iCAAiC,EAAE,MAAM,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,yBAAyB,GAAG,gBAAgB,CAAA;AAEjF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,EAAE;QACb,OAAO,EAAE,MAAM,CAAA;QACf,cAAc,EAAE,sBAAsB,CAAA;KACvC,CAAA;CACF,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,sBAAsB,CAAA;CACvC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/observability-api/types.ts"],"names":[],"mappings":"","sourcesContent":["import type OpenAI from 'openai'\nimport type Together from 'together-ai'\nimport type * as ChainsModule from 'langchain/chains'\nimport type * as AgentsModule from 'langchain/agents'\nimport type * as ToolsModule from 'langchain/tools'\nimport type * as anthropic from '@anthropic-ai/sdk'\nimport type * as cohere from 'cohere-ai'\nimport type * as bedrock from '@aws-sdk/client-bedrock-runtime'\nimport type * as google_aiplatform from '@google-cloud/aiplatform'\n\nexport type AsyncLoggerProviders = {\n openAI?: typeof OpenAI\n anthropic?: typeof anthropic\n cohere?: typeof cohere\n bedrock?: typeof bedrock\n google_aiplatform?: typeof google_aiplatform\n together?: typeof Together\n langchain?: {\n chainsModule?: typeof ChainsModule\n agentsModule?: typeof AgentsModule\n toolsModule?: typeof ToolsModule\n }\n}\n\n/**\n * Configuration for creating a Helicone payload\n */\nexport interface HeliconePayloadConfig {\n model: string\n inputData: Record<string, any>\n temperature?: number\n top_p?: number\n frequency_penalty?: number\n presence_penalty?: number\n n?: number\n stream?: boolean\n}\n\n/**\n * Configuration for creating a Helicone response\n */\nexport interface HeliconeResponseConfig {\n idPrefix: string\n model: string\n resultData: any\n usage: {\n prompt_tokens: number\n completion_tokens: number\n total_tokens: number\n prompt_tokens_details?: {\n cached_tokens: number\n audio_tokens: number\n }\n completion_tokens_details?: {\n reasoning_tokens: number\n audio_tokens: number\n accepted_prediction_tokens: number\n rejected_prediction_tokens: number\n }\n }\n systemFingerprint?: string\n}\n\nexport type CustomProperties = Record<string, string>\n\nexport type NeverminedHeliconeHeaders = {\n 'Helicone-Auth': string\n 'Helicone-Property-accountaddress': string\n 'Helicone-Property-consumeraddress': string\n 'Helicone-Property-agentid': string\n 'Helicone-Property-planid': string\n 'Helicone-Property-plantype': string\n 'Helicone-Property-planname': string\n 'Helicone-Property-agentname': string\n 'Helicone-Property-agentrequestid': string\n 'Helicone-Property-pricepercredit': string\n 'Helicone-Property-environmentname': string\n 'Helicone-Property-batch': string\n 'Helicone-Property-ismarginbased': string\n 'Helicone-Property-marginpercent': string\n}\n\nexport type DefaultHeliconeHeaders = NeverminedHeliconeHeaders & CustomProperties\n\nexport type ChatOpenAIConfiguration = {\n model: string\n apiKey: string\n configuration: {\n baseURL: string\n defaultHeaders: DefaultHeliconeHeaders\n }\n}\n\nexport type OpenAIConfiguration = {\n apiKey: string\n baseURL: string\n defaultHeaders: DefaultHeliconeHeaders\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/observability-api/types.ts"],"names":[],"mappings":"","sourcesContent":["import type OpenAI from 'openai'\nimport type Together from 'together-ai'\nimport type * as anthropic from '@anthropic-ai/sdk'\nimport type * as cohere from 'cohere-ai'\nimport type * as bedrock from '@aws-sdk/client-bedrock-runtime'\nimport type * as google_aiplatform from '@google-cloud/aiplatform'\n\n/**\n * A LangChain entry-point module handed over by the caller.\n *\n * On the resolved `@traceloop/node-server-sdk` (0.26.0) nothing reads a member\n * of it. `observability-api.ts` forwards the bag to\n * `traceloop.initialize({ instrumentModules })` behind an `as any`, and there\n * the field is declared `langchain?: boolean` and never consulted —\n * `instrumentModules?.langchain` appears nowhere in its `dist/` — because\n * LangChain is instrumented unconditionally by hooking\n * `@langchain/core/callbacks/manager`.\n *\n * That was not always so. traceloop 0.14 declared five module fields\n * (`chainsModule`, `agentsModule`, `toolsModule`, `runnablesModule`,\n * `vectorStoreModule`) and passed them to `manuallyInstrument`; #158 took three\n * of them, and they went inert with the 0.26 bump in #312. They stay for source\n * compatibility with callers written against that contract.\n *\n * Typing the three as `typeof import('langchain/chains')` and friends therefore\n * bought no checking, and cost twice. It pinned this SDK's build to one\n * LangChain layout — v1 moved the legacy chains and agents entry points out, so\n * those subpaths stopped resolving and a dev-only bump failed with TS2307\n * (#317) — and, because declaration emit keeps those imports in the published\n * `types.d.ts` while `langchain` is neither a dependency nor a peer, it broke\n * the typecheck of any consumer building with `skipLibCheck: false` unless they\n * happened to have a 0.3-layout `langchain` installed.\n */\nexport type LangChainModule = Record<string, unknown>\n\nexport type AsyncLoggerProviders = {\n openAI?: typeof OpenAI\n anthropic?: typeof anthropic\n cohere?: typeof cohere\n bedrock?: typeof bedrock\n google_aiplatform?: typeof google_aiplatform\n together?: typeof Together\n /**\n * Inert on the resolved traceloop (0.26.0), which instruments LangChain\n * unconditionally and ignores these modules. See {@link LangChainModule}.\n */\n langchain?: {\n chainsModule?: LangChainModule\n agentsModule?: LangChainModule\n toolsModule?: LangChainModule\n }\n}\n\n/**\n * Configuration for creating a Helicone payload\n */\nexport interface HeliconePayloadConfig {\n model: string\n inputData: Record<string, any>\n temperature?: number\n top_p?: number\n frequency_penalty?: number\n presence_penalty?: number\n n?: number\n stream?: boolean\n}\n\n/**\n * Configuration for creating a Helicone response\n */\nexport interface HeliconeResponseConfig {\n idPrefix: string\n model: string\n resultData: any\n usage: {\n prompt_tokens: number\n completion_tokens: number\n total_tokens: number\n prompt_tokens_details?: {\n cached_tokens: number\n audio_tokens: number\n }\n completion_tokens_details?: {\n reasoning_tokens: number\n audio_tokens: number\n accepted_prediction_tokens: number\n rejected_prediction_tokens: number\n }\n }\n systemFingerprint?: string\n}\n\nexport type CustomProperties = Record<string, string>\n\nexport type NeverminedHeliconeHeaders = {\n 'Helicone-Auth': string\n 'Helicone-Property-accountaddress': string\n 'Helicone-Property-consumeraddress': string\n 'Helicone-Property-agentid': string\n 'Helicone-Property-planid': string\n 'Helicone-Property-plantype': string\n 'Helicone-Property-planname': string\n 'Helicone-Property-agentname': string\n 'Helicone-Property-agentrequestid': string\n 'Helicone-Property-pricepercredit': string\n 'Helicone-Property-environmentname': string\n 'Helicone-Property-batch': string\n 'Helicone-Property-ismarginbased': string\n 'Helicone-Property-marginpercent': string\n}\n\nexport type DefaultHeliconeHeaders = NeverminedHeliconeHeaders & CustomProperties\n\nexport type ChatOpenAIConfiguration = {\n model: string\n apiKey: string\n configuration: {\n baseURL: string\n defaultHeaders: DefaultHeliconeHeaders\n }\n}\n\nexport type OpenAIConfiguration = {\n apiKey: string\n baseURL: string\n defaultHeaders: DefaultHeliconeHeaders\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Address, Currency, NvmAPIResult, PaginationOptions, PaymentOptions, PlanBalance, PlanCreditsConfig, PlanRedemptionType, PlanMetadata, PlanPriceConfig, StripeCheckoutResult } from '../common/types.js';
1
+ import { Address, Currency, NvmAPIResult, PaginationOptions, PaymentOptions, PlanBalance, PlanCreditsConfig, PlanRedemptionType, PlanMetadata, PlanPriceConfig, StripePaymentIntent } from '../common/types.js';
2
2
  import { BasePaymentsAPI, PublicationOptions } from './base-payments.js';
3
3
  /**
4
4
  * The PlansAPI class provides methods to register and interact with payment plans on Nevermined.
@@ -325,13 +325,14 @@ export declare class PlansAPI extends BasePaymentsAPI {
325
325
  * All the agents returned can be accessed by the users that are subscribed to the Payment Plan.
326
326
  *
327
327
  * @param planId - The unique identifier of the plan.
328
- * @param pagination - Optional pagination options to control the number of results returned.
328
+ * @param pagination - Optional pagination options. Accepts a plain object
329
+ * (`{ page, offset, sortBy, sortOrder }`) or a `PaginationOptions` instance.
329
330
  * @returns A promise that resolves to the list of agents associated with the plan.
330
331
  * @throws PaymentsError if the plan is not found.
331
332
  *
332
333
  * @example
333
334
  * ```
334
- * const result = payments.plans.getAgentsAssociatedToAPlan(planId)
335
+ * const result = payments.plans.getAgentsAssociatedToAPlan(planId, { page: 1, offset: 10 })
335
336
  * // {
336
337
  * // total: 10,
337
338
  * // page: 1,
@@ -340,7 +341,7 @@ export declare class PlansAPI extends BasePaymentsAPI {
340
341
  * // }
341
342
  * ```
342
343
  */
343
- getAgentsAssociatedToAPlan(planId: string, pagination?: PaginationOptions): Promise<any>;
344
+ getAgentsAssociatedToAPlan(planId: string, pagination?: Partial<PaginationOptions>): Promise<any>;
344
345
  /**
345
346
  * Gets the balance of an account for a Payment Plan.
346
347
  *
@@ -384,25 +385,27 @@ export declare class PlansAPI extends BasePaymentsAPI {
384
385
  */
385
386
  orderPlan(planId: string): Promise<NvmAPIResult>;
386
387
  /**
387
- * Initiates the purchase of a Plan requiring the payment in Fiat. This method will return a URL where the user can complete the payment.
388
+ * Initiates the purchase of a Plan requiring the payment in Fiat. This method creates a
389
+ * Stripe PaymentIntent for the plan's price and returns it.
388
390
  *
389
391
  * @remarks
390
- * The payment is completed using a credit card in a external website (Stripe).
392
+ * The payment is completed by confirming the PaymentIntent client-side with Stripe.js and
393
+ * its `client_secret`.
391
394
  * @remarks
392
- * This method is only valid for plans with price in Fiat.
395
+ * This method is only valid for plans priced in Fiat through Stripe.
393
396
  *
394
397
  * @param planId - The unique identifier of the plan.
395
- * @returns A promise that resolves indicating the URL to complete the payment.
398
+ * @returns A promise that resolves to the Stripe PaymentIntent created for the plan.
396
399
  * @throws PaymentsError if unable to order the plan.
397
400
  *
398
401
  * @example
399
402
  * ```
400
- * const result = await payments.plans.orderFiatPlan(planId)
403
+ * const paymentIntent = await payments.plans.orderFiatPlan(planId)
404
+ * // paymentIntent.id -> 'pi_…'
405
+ * // paymentIntent.client_secret -> confirm with Stripe.js
401
406
  * ```
402
407
  */
403
- orderFiatPlan(planId: string): Promise<{
404
- result: StripeCheckoutResult;
405
- }>;
408
+ orderFiatPlan(planId: string): Promise<StripePaymentIntent>;
406
409
  /**
407
410
  * Mints credits for a given Payment Plan and transfers them to a receiver.
408
411
  *
@@ -1 +1 @@
1
- {"version":3,"file":"plans-api.d.ts","sourceRoot":"","sources":["../../src/api/plans-api.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EACP,QAAQ,EAER,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,oBAAoB,EACrB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAA6B,MAAM,oBAAoB,CAAA;AAenG;;GAEG;AACH,qBAAa,QAAS,SAAQ,eAAe;IAC3C,OAAO,CAAC,YAAY,CAAc;gBAEtB,OAAO,EAAE,cAAc;IAInC,oBAAoB;IACpB;;;;;;;;;;;OAWG;IACI,kBAAkB,CACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,EACjB,QAAQ,GAAE,QAAQ,GAAG,MAAqB,GACzC,eAAe;IAIlB;;OAEG;IACU,wBAAwB,CACnC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,EACjB,YAAY,GAAE,OAAqB,GAClC,OAAO,CAAC,eAAe,CAAC;IAK3B;;OAEG;IACI,0BAA0B,IAAI,iBAAiB;IAItD;;;;;;;OAOG;IACI,oBAAoB,CACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,EACjB,YAAY,CAAC,EAAE,OAAO,GACrB,eAAe;IAIlB;;;;;;;OAOG;IACI,mBAAmB,CACxB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,OAAO,GAChB,eAAe;IAIlB;;;;;;;OAOG;IACI,kBAAkB,CAC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AAe,EAAE,OAAO,EACxB,eAAe,SAAK,GACnB,OAAO,CAAC,YAAY,CAAC;CAczB"}
@@ -416,13 +416,14 @@ export class PlansAPI extends BasePaymentsAPI {
416
416
  * All the agents returned can be accessed by the users that are subscribed to the Payment Plan.
417
417
  *
418
418
  * @param planId - The unique identifier of the plan.
419
- * @param pagination - Optional pagination options to control the number of results returned.
419
+ * @param pagination - Optional pagination options. Accepts a plain object
420
+ * (`{ page, offset, sortBy, sortOrder }`) or a `PaginationOptions` instance.
420
421
  * @returns A promise that resolves to the list of agents associated with the plan.
421
422
  * @throws PaymentsError if the plan is not found.
422
423
  *
423
424
  * @example
424
425
  * ```
425
- * const result = payments.plans.getAgentsAssociatedToAPlan(planId)
426
+ * const result = payments.plans.getAgentsAssociatedToAPlan(planId, { page: 1, offset: 10 })
426
427
  * // {
427
428
  * // total: 10,
428
429
  * // page: 1,
@@ -431,8 +432,10 @@ export class PlansAPI extends BasePaymentsAPI {
431
432
  * // }
432
433
  * ```
433
434
  */
434
- async getAgentsAssociatedToAPlan(planId, pagination = new PaginationOptions()) {
435
- const query = API_URL_GET_PLAN_AGENTS.replace(':planId', planId) + '?' + pagination.asQueryParams();
435
+ async getAgentsAssociatedToAPlan(planId, pagination = {}) {
436
+ const query = API_URL_GET_PLAN_AGENTS.replace(':planId', planId) +
437
+ '?' +
438
+ new PaginationOptions(pagination).asQueryParams();
436
439
  const url = new URL(query, this.environment.backend);
437
440
  const response = await fetch(url, this.getPublicHTTPOptions('GET'));
438
441
  if (!response.ok) {
@@ -505,28 +508,28 @@ export class PlansAPI extends BasePaymentsAPI {
505
508
  return response.json();
506
509
  }
507
510
  /**
508
- * Initiates the purchase of a Plan requiring the payment in Fiat. This method will return a URL where the user can complete the payment.
511
+ * Initiates the purchase of a Plan requiring the payment in Fiat. This method creates a
512
+ * Stripe PaymentIntent for the plan's price and returns it.
509
513
  *
510
514
  * @remarks
511
- * The payment is completed using a credit card in a external website (Stripe).
515
+ * The payment is completed by confirming the PaymentIntent client-side with Stripe.js and
516
+ * its `client_secret`.
512
517
  * @remarks
513
- * This method is only valid for plans with price in Fiat.
518
+ * This method is only valid for plans priced in Fiat through Stripe.
514
519
  *
515
520
  * @param planId - The unique identifier of the plan.
516
- * @returns A promise that resolves indicating the URL to complete the payment.
521
+ * @returns A promise that resolves to the Stripe PaymentIntent created for the plan.
517
522
  * @throws PaymentsError if unable to order the plan.
518
523
  *
519
524
  * @example
520
525
  * ```
521
- * const result = await payments.plans.orderFiatPlan(planId)
526
+ * const paymentIntent = await payments.plans.orderFiatPlan(planId)
527
+ * // paymentIntent.id -> 'pi_…'
528
+ * // paymentIntent.client_secret -> confirm with Stripe.js
522
529
  * ```
523
530
  */
524
531
  async orderFiatPlan(planId) {
525
- const body = {
526
- sessionType: 'embedded',
527
- planId,
528
- };
529
- const options = this.getBackendHTTPOptions('POST', body);
532
+ const options = this.getBackendHTTPOptions('POST', { planId });
530
533
  const url = new URL(API_URL_STRIPE_CHECKOUT, this.environment.backend);
531
534
  const response = await fetch(url, options);
532
535
  if (!response.ok) {