@tabai/sdk 0.2.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.
- package/LICENSE +23 -0
- package/README.md +401 -0
- package/bin/tab.mjs +23 -0
- package/dist/_shared/abi.d.ts +150 -0
- package/dist/_shared/abi.d.ts.map +1 -0
- package/dist/_shared/abi.js +197 -0
- package/dist/_shared/abi.js.map +1 -0
- package/dist/_shared/chains.d.ts +118 -0
- package/dist/_shared/chains.d.ts.map +1 -0
- package/dist/_shared/chains.js +89 -0
- package/dist/_shared/chains.js.map +1 -0
- package/dist/_shared/hex.d.ts +35 -0
- package/dist/_shared/hex.d.ts.map +1 -0
- package/dist/_shared/hex.js +40 -0
- package/dist/_shared/hex.js.map +1 -0
- package/dist/_shared/index.d.ts +14 -0
- package/dist/_shared/index.d.ts.map +1 -0
- package/dist/_shared/index.js +14 -0
- package/dist/_shared/index.js.map +1 -0
- package/dist/_shared/keccak256.d.ts +29 -0
- package/dist/_shared/keccak256.d.ts.map +1 -0
- package/dist/_shared/keccak256.js +145 -0
- package/dist/_shared/keccak256.js.map +1 -0
- package/dist/_shared/result.d.ts +78 -0
- package/dist/_shared/result.d.ts.map +1 -0
- package/dist/_shared/result.js +61 -0
- package/dist/_shared/result.js.map +1 -0
- package/dist/cli/client-config.d.ts +155 -0
- package/dist/cli/client-config.d.ts.map +1 -0
- package/dist/cli/client-config.js +382 -0
- package/dist/cli/client-config.js.map +1 -0
- package/dist/cli/connect.d.ts +76 -0
- package/dist/cli/connect.d.ts.map +1 -0
- package/dist/cli/connect.js +158 -0
- package/dist/cli/connect.js.map +1 -0
- package/dist/cli/doctor.d.ts +57 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +253 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +13 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/main.d.ts +45 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +371 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +37 -0
- package/dist/errors.js.map +1 -0
- package/dist/http/client-402.d.ts +243 -0
- package/dist/http/client-402.d.ts.map +1 -0
- package/dist/http/client-402.js +515 -0
- package/dist/http/client-402.js.map +1 -0
- package/dist/http/headers.d.ts +173 -0
- package/dist/http/headers.d.ts.map +1 -0
- package/dist/http/headers.js +284 -0
- package/dist/http/headers.js.map +1 -0
- package/dist/http/index.d.ts +15 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +15 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/metering-claim.d.ts +82 -0
- package/dist/http/metering-claim.d.ts.map +1 -0
- package/dist/http/metering-claim.js +99 -0
- package/dist/http/metering-claim.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +40 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +50 -0
- package/dist/logger.js.map +1 -0
- package/dist/mcp/assets.d.ts +31 -0
- package/dist/mcp/assets.d.ts.map +1 -0
- package/dist/mcp/assets.js +78 -0
- package/dist/mcp/assets.js.map +1 -0
- package/dist/mcp/index.d.ts +19 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +19 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/json-schema.d.ts +86 -0
- package/dist/mcp/json-schema.d.ts.map +1 -0
- package/dist/mcp/json-schema.js +215 -0
- package/dist/mcp/json-schema.js.map +1 -0
- package/dist/mcp/json.d.ts +43 -0
- package/dist/mcp/json.d.ts.map +1 -0
- package/dist/mcp/json.js +69 -0
- package/dist/mcp/json.js.map +1 -0
- package/dist/mcp/registry-client.d.ts +88 -0
- package/dist/mcp/registry-client.d.ts.map +1 -0
- package/dist/mcp/registry-client.js +158 -0
- package/dist/mcp/registry-client.js.map +1 -0
- package/dist/mcp/schemas.d.ts +82 -0
- package/dist/mcp/schemas.d.ts.map +1 -0
- package/dist/mcp/schemas.js +493 -0
- package/dist/mcp/schemas.js.map +1 -0
- package/dist/mcp/server.d.ts +97 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +285 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/settings.d.ts +90 -0
- package/dist/mcp/settings.d.ts.map +1 -0
- package/dist/mcp/settings.js +160 -0
- package/dist/mcp/settings.js.map +1 -0
- package/dist/mcp/toolset.d.ts +231 -0
- package/dist/mcp/toolset.d.ts.map +1 -0
- package/dist/mcp/toolset.js +760 -0
- package/dist/mcp/toolset.js.map +1 -0
- package/dist/payments/abi.d.ts +9 -0
- package/dist/payments/abi.d.ts.map +1 -0
- package/dist/payments/abi.js +17 -0
- package/dist/payments/abi.js.map +1 -0
- package/dist/payments/config.d.ts +199 -0
- package/dist/payments/config.d.ts.map +1 -0
- package/dist/payments/config.js +259 -0
- package/dist/payments/config.js.map +1 -0
- package/dist/payments/index.d.ts +13 -0
- package/dist/payments/index.d.ts.map +1 -0
- package/dist/payments/index.js +13 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/payments/kuru.d.ts +191 -0
- package/dist/payments/kuru.d.ts.map +1 -0
- package/dist/payments/kuru.js +377 -0
- package/dist/payments/kuru.js.map +1 -0
- package/dist/payments/monad.d.ts +69 -0
- package/dist/payments/monad.d.ts.map +1 -0
- package/dist/payments/monad.js +306 -0
- package/dist/payments/monad.js.map +1 -0
- package/dist/payments/permit2.d.ts +118 -0
- package/dist/payments/permit2.d.ts.map +1 -0
- package/dist/payments/permit2.js +366 -0
- package/dist/payments/permit2.js.map +1 -0
- package/dist/payments/registry.d.ts +119 -0
- package/dist/payments/registry.d.ts.map +1 -0
- package/dist/payments/registry.js +199 -0
- package/dist/payments/registry.js.map +1 -0
- package/dist/payments/strategy.d.ts +80 -0
- package/dist/payments/strategy.d.ts.map +1 -0
- package/dist/payments/strategy.js +103 -0
- package/dist/payments/strategy.js.map +1 -0
- package/dist/proxy/hooks.d.ts +90 -0
- package/dist/proxy/hooks.d.ts.map +1 -0
- package/dist/proxy/hooks.js +35 -0
- package/dist/proxy/hooks.js.map +1 -0
- package/dist/proxy/index.d.ts +9 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/index.js +9 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/proxy/proxy.d.ts +156 -0
- package/dist/proxy/proxy.d.ts.map +1 -0
- package/dist/proxy/proxy.js +366 -0
- package/dist/proxy/proxy.js.map +1 -0
- package/dist/server/adapters/express.d.ts +89 -0
- package/dist/server/adapters/express.d.ts.map +1 -0
- package/dist/server/adapters/express.js +215 -0
- package/dist/server/adapters/express.js.map +1 -0
- package/dist/server/adapters/hono.d.ts +52 -0
- package/dist/server/adapters/hono.d.ts.map +1 -0
- package/dist/server/adapters/hono.js +61 -0
- package/dist/server/adapters/hono.js.map +1 -0
- package/dist/server/adapters/next.d.ts +52 -0
- package/dist/server/adapters/next.d.ts.map +1 -0
- package/dist/server/adapters/next.js +56 -0
- package/dist/server/adapters/next.js.map +1 -0
- package/dist/server/index.d.ts +30 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +30 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/metering.d.ts +209 -0
- package/dist/server/metering.d.ts.map +1 -0
- package/dist/server/metering.js +365 -0
- package/dist/server/metering.js.map +1 -0
- package/dist/server/post-paid.d.ts +355 -0
- package/dist/server/post-paid.d.ts.map +1 -0
- package/dist/server/post-paid.js +512 -0
- package/dist/server/post-paid.js.map +1 -0
- package/dist/x402/client.d.ts +203 -0
- package/dist/x402/client.d.ts.map +1 -0
- package/dist/x402/client.js +337 -0
- package/dist/x402/client.js.map +1 -0
- package/dist/x402/hub.d.ts +79 -0
- package/dist/x402/hub.d.ts.map +1 -0
- package/dist/x402/hub.js +164 -0
- package/dist/x402/hub.js.map +1 -0
- package/dist/x402/index.d.ts +27 -0
- package/dist/x402/index.d.ts.map +1 -0
- package/dist/x402/index.js +27 -0
- package/dist/x402/index.js.map +1 -0
- package/dist/x402/proxy.d.ts +162 -0
- package/dist/x402/proxy.d.ts.map +1 -0
- package/dist/x402/proxy.js +198 -0
- package/dist/x402/proxy.js.map +1 -0
- package/dist/x402/server.d.ts +162 -0
- package/dist/x402/server.d.ts.map +1 -0
- package/dist/x402/server.js +306 -0
- package/dist/x402/server.js.map +1 -0
- package/dist/x402/wire.d.ts +104 -0
- package/dist/x402/wire.d.ts.map +1 -0
- package/dist/x402/wire.js +265 -0
- package/dist/x402/wire.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolset.js","sourceRoot":"","sources":["../../src/mcp/toolset.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAElE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAyC,MAAM,uBAAuB,CAAC;AAClG,OAAO,EAAE,aAAa,EAAe,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAyB,MAAM,yBAAyB,CAAC;AAExF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACxE,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,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC;QACnD,KAAK;KACN,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,EAAE;QAAE,OAAO,QAAQ,CAAC;IACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC7B,OAAO,IAAI,CACT,KAAK,CAAC,QAAQ,EACd,KAAK,CAAC,IAAI,EACV,GAAG,KAAK,CAAC,OAAO,yGAAyG,aAAa,CAAC,KAAK,CAAC,mCAAmC,EAChL,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,CAClG,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The four Tab tools, as functions.\n *\n * The MCP protocol wiring lives next door in `server.ts`. This file is the\n * behaviour, and it is separate so the tools can be exercised without a\n * transport: every test in `test/mcp-tools.test.mjs` calls these directly, which\n * is what lets task 16.3 validate every output against its declared schema\n * without standing a server up.\n *\n * ## Nothing here throws, including into the transport\n *\n * A tool that throws over stdio does not produce a bad answer, it produces no\n * answer: the MCP client sees a protocol error, the model sees nothing it can\n * reason about, and a long-running server can lose its transport to one\n * malformed argument. So every entry point below returns a value that validates\n * against the tool's declared output schema, on every path, including the paths\n * where the work failed. A failure is `error: { category, code, message }` in\n * the payload, and for `tab_call` and `tab_settle` it is `ok: false` beside it.\n *\n * `LIMIT_EXCEEDED` is the case that earns the discipline. An Agent out of\n * headroom is not an error in the Agent, the Service, or the call -- it is the\n * credit facility working. The tool answers `ok: false` with\n * `requiredBaseUnits` and `headroomBaseUnits` both filled in, so the model can\n * settle the difference and call again instead of retrying into the same wall.\n * (R21.5)\n *\n * ## Every input is validated against the schema that was published\n *\n * Not a hand-written check that resembles it. {@link applyJsonDefaults} fills in\n * the declared defaults and {@link validateJsonValue} enforces the same document\n * `tools/list` served, so a `limit` of 500 is refused with the same bound the\n * model was shown.\n *\n * Requirements: 21.5, 25.1, 25.2, 25.3, 25.4\n */\n\nimport type { Address, Bytes32, Result, TabError } from \"../_shared/index.js\";\nimport { isAddress, ok } from \"../_shared/index.js\";\nimport { decodeBytes32String, encodeBytes32String } from \"ethers\";\n\nimport { fail, notFoundError, tabError, upstreamError, validationError } from \"../errors.js\";\nimport { createTab402Client, type Tab402Fetch, type Tab402Response } from \"../http/client-402.js\";\nimport { defaultLogger, type Logger } from \"../logger.js\";\nimport type { ServiceHeaderRequest, TabServiceEntry } from \"../payments/config.js\";\nimport { loadTabConfig } from \"../payments/config.js\";\nimport { moduleStrategyRegistry, type StrategyRegistry } from \"../payments/registry.js\";\nimport type { AssetRef, PaymentStrategy, SettleRequest } from \"../payments/strategy.js\";\nimport { assetFacts, assetStringOf, formatAsset, parseAsset } from \"./assets.js\";\nimport { applyJsonDefaults, validateJsonValue } from \"./json-schema.js\";\nimport {\n asArray,\n asBoolean,\n asDigits,\n asDigitsOrNull,\n asNumber,\n asRecord,\n asString,\n asStringOrNull,\n field,\n isRecord,\n path as jsonPath,\n secondsToIso,\n} from \"./json.js\";\nimport { createRegistryReadClient, type RegistryFetch, type RegistryReadClient } from \"./registry-client.js\";\nimport { fetchHubManifest, type HubFetch } from \"../x402/hub.js\";\nimport {\n TAB_CALL_INPUT,\n TAB_DISCOVER_INPUT,\n TAB_SETTLE_INPUT,\n TAB_STATUS_INPUT,\n tabToolByName,\n} from \"./schemas.js\";\nimport type { TabMcpSettings } from \"./settings.js\";\n\n// ---------------------------------------------------------------- output types\n\n/** The error block every output can carry. */\nexport interface TabToolError {\n readonly category: TabError[\"category\"];\n readonly code: string;\n readonly message: string;\n readonly retryable: boolean;\n readonly requiredBaseUnits?: string;\n readonly headroomBaseUnits?: string;\n}\n\nexport interface DiscoveredAsset {\n readonly chainId: number;\n readonly address: string;\n readonly symbol: string | null;\n readonly decimals: number | null;\n readonly collectionAddress: string | null;\n readonly curatedAsset: boolean;\n}\n\nexport interface DiscoveredTool {\n readonly tool: string;\n readonly toolName: string | null;\n readonly asset: string;\n readonly priceBaseUnits: string;\n}\n\nexport interface DiscoveredBond {\n readonly asset: string;\n readonly stakedBaseUnits: string;\n readonly freeBaseUnits: string;\n}\n\nexport interface DiscoveredHubEndpoint {\n readonly endpoint: string;\n readonly name: string | null;\n readonly description: string | null;\n readonly priceType: string;\n readonly priceUsd: string | null;\n readonly priceBaseUnits: string | null;\n readonly networks: readonly string[];\n}\n\n/** The API Hub provider a Service fronts, with its endpoints as the Service's tools. */\nexport interface DiscoveredHub {\n readonly provider: string;\n readonly prefix: string;\n readonly endpoints: readonly DiscoveredHubEndpoint[];\n readonly total: number;\n /** Present when the manifest could not be read; `endpoints` is then empty. */\n readonly error?: TabToolError;\n}\n\nexport interface DiscoveredService {\n readonly serviceId: string;\n readonly name: string | null;\n readonly endpoint: string | null;\n readonly tier: \"curated\" | \"permissionless\" | \"unknown\";\n readonly settlementWindowSeconds: number;\n readonly assets: readonly DiscoveredAsset[];\n readonly tools: readonly DiscoveredTool[];\n readonly bonds: readonly DiscoveredBond[];\n readonly pendingChange: { readonly changeId: string; readonly kind: string | null; readonly etaIso: string | null } | null;\n readonly hub?: DiscoveredHub;\n}\n\nexport interface TabDiscoverOutput {\n readonly services: readonly DiscoveredService[];\n readonly error?: TabToolError;\n}\n\n/** The prepaid receipt a call carries when x402 paid for it instead of the Open Tab. */\nexport interface TabCallX402Block {\n readonly txHash: string;\n readonly network: string;\n readonly amountBaseUnits: string;\n readonly asset: string;\n readonly payTo: string;\n readonly payer: string;\n readonly explorerUrl: string | null;\n}\n\nexport interface TabCallOutput {\n readonly ok: boolean;\n readonly result?: unknown;\n readonly charge?: { readonly amountBaseUnits: string; readonly asset: string; readonly tool: string };\n readonly tab?: {\n readonly openTabBaseUnits: string;\n readonly headroomBaseUnits: string;\n readonly creditLimitBaseUnits?: string;\n readonly asset: string;\n readonly settlementDueIso?: string | null;\n };\n readonly x402?: TabCallX402Block;\n readonly error?: TabToolError;\n}\n\nexport interface TabStatusOutput {\n readonly agent: string;\n /**\n * The Monad block every figure here is as at, from the index that served them.\n *\n * A Settlement in a later block is not yet reflected; the index reaches it\n * within a few blocks. Null when the index has never ticked or the read failed.\n */\n readonly indexedBlock: number | null;\n readonly perAsset: readonly {\n readonly asset: string;\n readonly creditLimitBaseUnits: string | null;\n readonly openTabBaseUnits: string;\n readonly prepaidBaseUnits: string | null;\n readonly headroomBaseUnits: string | null;\n readonly delinquent: boolean;\n readonly tabs: readonly {\n readonly tabId: string | null;\n readonly serviceId: string;\n readonly openBaseUnits: string;\n readonly dueIso: string | null;\n }[];\n }[];\n readonly settlements?: readonly {\n readonly settlementId: string;\n readonly txHash: string;\n readonly serviceId: string;\n readonly asset: string;\n readonly amountBaseUnits: string;\n readonly appliedBaseUnits: string;\n readonly prepaidBaseUnits: string;\n readonly explorerUrl: string | null;\n }[];\n readonly error?: TabToolError;\n}\n\nexport interface TabSettleOutput {\n readonly ok: boolean;\n readonly dryRun: boolean;\n readonly txHash?: string | null;\n readonly chainId?: number | null;\n readonly amountBaseUnits: string;\n readonly settlementId?: string | null;\n readonly appliedBaseUnits?: string | null;\n readonly prepaidBaseUnits?: string | null;\n readonly explorerUrl?: string | null;\n readonly error?: TabToolError;\n}\n\n// ---------------------------------------------------------------- the toolset\n\nexport interface TabToolsetOptions {\n readonly settings: TabMcpSettings;\n /** Overrides the client built from `settings.registryUrl`. A test hands in a stub. */\n readonly registry?: RegistryReadClient;\n /** The `fetch` `tab_call` sends Service requests with. Defaults to the host's. */\n readonly fetchImpl?: Tab402Fetch<Tab402Response>;\n /**\n * The `fetch` the registry read client uses, when one is built from settings.\n *\n * Separate from {@link TabToolsetOptions.fetchImpl} because the two talk to\n * different things: one to a third party's Service, one to the read API. A\n * test that stubs a Service should not silently start answering registry\n * reads too.\n */\n readonly registryFetch?: RegistryFetch;\n /** The `fetch` `tab_discover` reads API Hub manifests with. Defaults to the host's. */\n readonly hubFetch?: HubFetch;\n /**\n * Where `tab_settle` resolves a strategy.\n *\n * Absent, the module-level registry is used, and `tab_settle` fills it from\n * `tab.config` the first time it is called. See {@link TabToolset.settle} for\n * why that load is deferred rather than done at startup.\n */\n readonly strategies?: StrategyRegistry;\n /** Where the deferred `tab.config` load walks from. Defaults to the working directory. */\n readonly cwd?: string;\n readonly logger?: Logger;\n readonly now?: () => number;\n /**\n * The environment the Asset table is read from: on Testnet `MOCK_USDC_ADDRESS`\n * names the token this deployment settles in. Defaults to the process\n * environment; a test passes its own so a machine's configuration cannot\n * change a result.\n */\n readonly env?: NodeJS.ProcessEnv;\n}\n\n/** The four tools, plus a dispatcher the MCP server calls by name. */\nexport interface TabToolset {\n discover(input: unknown): Promise<TabDiscoverOutput>;\n call(input: unknown): Promise<TabCallOutput>;\n status(input: unknown): Promise<TabStatusOutput>;\n settle(input: unknown): Promise<TabSettleOutput>;\n /** Dispatches by MCP tool name. `NOT_FOUND` for a name this package does not declare. */\n invoke(name: string, input: unknown): Promise<Result<unknown>>;\n}\n\nconst errorOf = (error: TabError): TabToolError => {\n const details = asRecord(error.details);\n const required = asDigitsOrNull(details[\"requiredBaseUnits\"]);\n const headroom = asDigitsOrNull(details[\"headroomBaseUnits\"]);\n return {\n category: error.category,\n code: error.code,\n message: error.message,\n retryable: error.retryable,\n ...(required === null ? {} : { requiredBaseUnits: required }),\n ...(headroom === null ? {} : { headroomBaseUnits: headroom }),\n };\n};\n\n/** Validates a tool input against the schema that was published for it. */\nfunction readInput<T>(toolName: string, raw: unknown): Result<T> {\n const declaration = tabToolByName(toolName);\n if (declaration === undefined) {\n return notFoundError(\"TOOL_UNKNOWN\", `\\`${toolName}\\` is not a tool this server declares`, {\n details: { tool: toolName },\n });\n }\n const supplied = raw === undefined || raw === null ? {} : raw;\n return validateJsonValue<T>(\n declaration.inputSchema,\n applyJsonDefaults(declaration.inputSchema, supplied),\n `${toolName} input`,\n \"INPUT_INVALID\",\n );\n}\n\n/** The ascii a 32-byte word decodes to, or null when it is not padded ascii. */\nfunction wordToName(word: string): string | null {\n try {\n const decoded = decodeBytes32String(word);\n return /^[\\x20-\\x7e]+$/.test(decoded) ? decoded : null;\n } catch {\n return null;\n }\n}\n\n/** A tool name as its 32-byte key: a hex word passes through, ascii is padded. */\nfunction toolKeyOf(tool: string): Result<Bytes32> {\n if (/^0x[a-fA-F0-9]{64}$/.test(tool)) return ok(tool.toLowerCase() as Bytes32);\n try {\n return ok(encodeBytes32String(tool).toLowerCase() as Bytes32);\n } catch {\n return validationError(\n \"TOOL_NAME_TOO_LONG\",\n `\\`${tool}\\` cannot be a tool key: a tool name is stored as 31 bytes of ascii, zero-padded, or given as a 32-byte hex word`,\n { details: { tool } },\n );\n }\n}\n\nconst ZERO_WORD = `0x${\"00\".repeat(32)}` as Bytes32;\n\nexport function createTabToolset(options: TabToolsetOptions): TabToolset {\n const settings = options.settings;\n const logger = options.logger ?? defaultLogger;\n const now = options.now ?? (() => Date.now());\n const env = options.env ?? process.env;\n const chainId = settings.chainId;\n\n /**\n * The strategy registry, filled from `tab.config` on first use.\n *\n * Deferred, and this is the one piece of laziness in the package that is not\n * an optimisation. Resolving a strategy entry runs consumer code: a factory in\n * a config file typically builds a signer, and a signer is built from a key.\n * Doing that at startup would mean `tab_discover`, `tab_status` and `tab\n * doctor` -- three surfaces whose whole claim is that they need no key --\n * loading one every time the server starts. So the load happens inside\n * `tab_settle`, the only tool that signs, at the moment it needs a strategy.\n *\n * Memoised, so a second Settlement does not re-import the config, and\n * registration is idempotent by strategy id in any case.\n */\n let loading: Promise<StrategyRegistry> | undefined;\n const strategiesFor = (): Promise<StrategyRegistry> => {\n if (options.strategies !== undefined) return Promise.resolve(options.strategies);\n loading ??= (async () => {\n const registry = moduleStrategyRegistry(logger);\n if (registry.list().length > 0) return registry;\n const loaded = await loadTabConfig({\n ...(options.cwd === undefined ? {} : { cwd: options.cwd }),\n registry,\n logger,\n });\n if (!loaded.ok) {\n logger.warn(\"tab.config could not be loaded, so no payment strategy is registered\", {\n code: loaded.error.code,\n message: loaded.error.message,\n });\n }\n return registry;\n })();\n return loading;\n };\n\n const directory = new Map<string, TabServiceEntry>(\n settings.services.map((entry) => [entry.serviceId.toLowerCase(), entry]),\n );\n\n /** The registry client, or the one failure that stands in for it. */\n const registryOf = (): Result<RegistryReadClient> => {\n if (options.registry !== undefined) return ok(options.registry);\n if (settings.registryUrl === undefined) {\n return upstreamError(\n \"REGISTRY_UNCONFIGURED\",\n \"no Tab registry read API is configured, so on-chain discovery and status cannot be read; set NEXT_PUBLIC_REGISTRY_API_URL, or registryUrl in tab.config\",\n );\n }\n return ok(\n createRegistryReadClient({\n baseUrl: settings.registryUrl,\n ...(options.registryFetch === undefined ? {} : { fetchImpl: options.registryFetch }),\n logger,\n }),\n );\n };\n\n // ------------------------------------------------------------- tab_discover\n\n const discover = async (raw: unknown): Promise<TabDiscoverOutput> => {\n const input = readInput<{ asset?: string; tier: string; search?: string; limit: number }>(\"tab_discover\", raw);\n if (!input.ok) return { services: [], error: errorOf(input.error) };\n\n let wanted: AssetRef | undefined;\n if (input.value.asset !== undefined) {\n const parsed = parseAsset(input.value.asset);\n if (!parsed.ok) return { services: [], error: errorOf(parsed.error) };\n wanted = parsed.value;\n }\n\n const registry = registryOf();\n if (!registry.ok) return { services: [], error: errorOf(registry.error) };\n\n // A filtered request has to over-fetch: the read API pages by registration\n // order and filters nothing, so asking for `limit` rows would return `limit`\n // rows before the filter and fewer after it.\n const filtered = wanted !== undefined || input.value.search !== undefined || input.value.tier !== \"any\";\n const body = await registry.value.services(filtered ? 200 : input.value.limit);\n if (!body.ok) return { services: [], error: errorOf(body.error) };\n\n const services = await Promise.all(\n asArray(field(body.value, \"services\"))\n .map((entry) => toDiscoveredService(entry, directory, chainId, env))\n .filter((service) => matches(service, input.value.tier, input.value.search, wanted))\n .slice(0, input.value.limit)\n .map((service) => withHub(service, directory.get(service.serviceId), options.hubFetch)),\n );\n\n return { services };\n };\n\n // ---------------------------------------------------------------- tab_call\n\n const call = async (raw: unknown): Promise<TabCallOutput> => {\n const input = readInput<{\n serviceId: string;\n tool: string;\n asset?: string;\n arguments?: Record<string, unknown>;\n timeoutMs: number;\n }>(\"tab_call\", raw);\n if (!input.ok) return { ok: false, error: errorOf(input.error) };\n\n if (settings.agent === undefined) return { ok: false, error: errorOf(agentUnconfigured()) };\n\n const serviceId = input.value.serviceId.toLowerCase();\n const entry = directory.get(serviceId);\n if (entry === undefined) {\n return {\n ok: false,\n error: errorOf(\n tabError(\n \"NOT_FOUND\",\n \"SERVICE_ENDPOINT_UNKNOWN\",\n `no endpoint is configured for Service ${serviceId}; the chain records no URL, so add it to the \\`services\\` list in tab.config`,\n { details: { serviceId, configured: [...directory.keys()].join(\", \") } },\n ),\n ),\n };\n }\n\n const toolKey = toolKeyOf(input.value.tool);\n if (!toolKey.ok) return { ok: false, error: errorOf(toolKey.error) };\n\n const client = createTab402Client({\n baseUrl: entry.endpoint,\n agent: settings.agent,\n // The credit decision is the Service's, and this tool reports it rather than\n // arguing with it. A repeat would meter the same call twice on the path where\n // the first attempt was declined, so the repeat is off.\n maxRetries: 0,\n logger,\n now,\n ...(options.fetchImpl === undefined ? {} : { fetchImpl: options.fetchImpl }),\n ...(settings.strategyId === undefined ? {} : { strategyId: settings.strategyId }),\n // The prepaid fallback, only when tab.config declared a signer factory. The\n // factory is called at the moment a refusal carries an x402 offer and not\n // before, which is what keeps this tool keyless on every other path.\n ...(settings.x402 === undefined ? {} : { x402: { signer: settings.x402, chainId: BigInt(chainId) } }),\n });\n\n // A Service meters its tools under `/meter/<tool>` off its published\n // endpoint, the shape the reference gateway serves and the Dashboard calls,\n // so the endpoint in the directory is the Service's root and `/hub/<prefix>`\n // sits beside the tools rather than under them.\n const url = `${entry.endpoint.replace(/\\/+$/, \"\")}/meter/${encodeURIComponent(input.value.tool)}`;\n\n const supplied = await serviceHeaders(entry, {\n method: \"POST\",\n url,\n tool: input.value.tool,\n agent: settings.agent,\n serviceId,\n });\n if (!supplied.ok) return { ok: false, error: errorOf(supplied.error) };\n\n const response = await client.fetch(url, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\", ...supplied.value },\n body: JSON.stringify(input.value.arguments ?? {}),\n signal: timeoutSignal(input.value.timeoutMs),\n });\n\n const charges = client.charges();\n const charge = charges.at(-1);\n const payment = client.payments().at(-1);\n const x402Block: TabCallX402Block | undefined =\n payment === undefined\n ? undefined\n : {\n txHash: payment.txHash,\n network: payment.network,\n amountBaseUnits: payment.amount.toString(10),\n asset: formatAsset(Number(payment.chainId), payment.asset),\n payTo: payment.payTo,\n payer: payment.payer,\n explorerUrl: explorerTx(settings.explorerUrl, payment.txHash),\n };\n const chargeBlock =\n charge === undefined\n ? undefined\n : {\n amountBaseUnits: charge.amount.toString(10),\n asset: formatAsset(charge.asset.chainId, charge.asset.address),\n tool: charge.tool,\n };\n const tabBlock =\n charge === undefined\n ? undefined\n : {\n openTabBaseUnits: charge.openTab.toString(10),\n headroomBaseUnits: charge.headroom.toString(10),\n asset: formatAsset(charge.asset.chainId, charge.asset.address),\n settlementDueIso: null,\n };\n\n if (!response.ok) {\n // A 402 that still stands is the headroom case, and it is the one failure\n // this tool restates rather than passes through: the model needs both\n // figures side by side to decide whether to settle. A standing 402 that\n // an x402 signer tried and failed to pay keeps the payment error instead,\n // because \"the facilitator refused the signature\" is the actionable fact.\n if (charge !== undefined && charge.outcome === \"declined\" && response.error.code === \"LIMIT_EXCEEDED\") {\n return {\n ok: false,\n ...(chargeBlock === undefined ? {} : { charge: chargeBlock }),\n ...(tabBlock === undefined ? {} : { tab: tabBlock }),\n error: {\n // `LIMIT` and not `CONFLICT`: the category maps to HTTP 402 everywhere\n // else in Tab, which is exactly what the Service answered.\n category: \"LIMIT\",\n code: \"LIMIT_EXCEEDED\",\n message: `this call needs ${charge.amount.toString(10)} base units and the Agent has ${charge.headroom.toString(10)} of headroom for the Asset; settle with tab_settle and call again`,\n retryable: false,\n requiredBaseUnits: charge.amount.toString(10),\n headroomBaseUnits: charge.headroom.toString(10),\n },\n };\n }\n return {\n ok: false,\n ...(chargeBlock === undefined ? {} : { charge: chargeBlock }),\n ...(tabBlock === undefined ? {} : { tab: tabBlock }),\n error: errorOf(response.error),\n };\n }\n\n const status = response.value.status;\n const body = await readBody(response.value);\n if (status < 200 || status >= 300) {\n return {\n ok: false,\n ...(chargeBlock === undefined ? {} : { charge: chargeBlock }),\n ...(tabBlock === undefined ? {} : { tab: tabBlock }),\n ...(x402Block === undefined ? {} : { x402: x402Block }),\n error: serviceRefusal(status, body, input.value.tool),\n };\n }\n\n const result = body;\n return {\n ok: true,\n result,\n // A prepaid call carries the credit refusal it was answered with, so the\n // model sees both what the tab could not cover and what paid for it.\n ...(chargeBlock === undefined ? {} : { charge: chargeBlock }),\n ...(tabBlock === undefined ? {} : { tab: tabBlock }),\n ...(x402Block === undefined ? {} : { x402: x402Block }),\n };\n };\n\n // -------------------------------------------------------------- tab_status\n\n const status = async (raw: unknown): Promise<TabStatusOutput> => {\n const input = readInput<{ agent?: string; asset?: string; historyLimit: number }>(\"tab_status\", raw);\n const agent = (input.ok ? input.value.agent : undefined) ?? settings.agent;\n const subject = agent ?? \"0x0000000000000000000000000000000000000000\";\n\n if (!input.ok) return { agent: subject, indexedBlock: null, perAsset: [], error: errorOf(input.error) };\n if (agent === undefined) {\n return { agent: subject, indexedBlock: null, perAsset: [], error: errorOf(agentUnconfigured()) };\n }\n\n let assetFilter: string | undefined;\n if (input.value.asset !== undefined) {\n const parsed = parseAsset(input.value.asset);\n if (!parsed.ok) return { agent: agent.toLowerCase(), indexedBlock: null, perAsset: [], error: errorOf(parsed.error) };\n assetFilter = parsed.value.address.toLowerCase();\n }\n\n const registry = registryOf();\n if (!registry.ok) return { agent: agent.toLowerCase(), indexedBlock: null, perAsset: [], error: errorOf(registry.error) };\n\n const body = await registry.value.agent(agent);\n if (!body.ok) return { agent: agent.toLowerCase(), indexedBlock: null, perAsset: [], error: errorOf(body.error) };\n\n // The block the index had read to when it answered. Stated, because a\n // Settlement the Agent sent a moment ago sits in a later block and an\n // answer that looked current while omitting it would be the misleading kind.\n const horizon = jsonPath(body.value, \"index\", \"lastBlock\");\n const indexedBlock = typeof horizon === \"number\" && Number.isInteger(horizon) && horizon >= 0 ? horizon : null;\n\n const perAsset = asArray(field(body.value, \"assets\"))\n .map((entry) => toPerAsset(entry, input.value.historyLimit, chainId))\n .filter((entry): entry is NonNullable<typeof entry> => entry !== null)\n .filter((entry) => assetFilter === undefined || entry.assetAddress === assetFilter)\n .map(({ assetAddress: _assetAddress, ...rest }) => rest);\n let settlements: TabStatusOutput[\"settlements\"] = [];\n if (input.value.historyLimit > 0) {\n const settled = await registry.value.settlements({\n agent,\n ...(assetFilter === undefined ? {} : { asset: assetFilter }),\n limit: input.value.historyLimit,\n });\n if (settled.ok) {\n settlements = asArray(field(settled.value, \"settlements\")).map((row) =>\n toSettlementRow(row, settings.explorerUrl, chainId),\n );\n } else {\n logger.warn(\"the settlement feed could not be read; status reports credit without history\", {\n code: settled.error.code,\n });\n }\n }\n return { agent: agent.toLowerCase(), indexedBlock, perAsset, settlements };\n };\n\n // -------------------------------------------------------------- tab_settle\n\n const settle = async (raw: unknown): Promise<TabSettleOutput> => {\n const input = readInput<{\n serviceId: string;\n asset: string;\n amountBaseUnits: string;\n strategyId?: string;\n dryRun: boolean;\n }>(\"tab_settle\", raw);\n if (!input.ok) return { ok: false, dryRun: false, amountBaseUnits: \"0\", error: errorOf(input.error) };\n const dryRun = input.value.dryRun;\n const amountBaseUnits = input.value.amountBaseUnits;\n const failure = (error: TabError): TabSettleOutput => ({\n ok: false,\n dryRun,\n amountBaseUnits,\n error: errorOf(error),\n });\n if (settings.agent === undefined) return failure(agentUnconfigured());\n const asset = parseAsset(input.value.asset, \"asset\", env);\n if (!asset.ok) return failure(asset.error);\n const amount = BigInt(amountBaseUnits);\n if (amount === 0n) {\n return failure(\n tabError(\"VALIDATION\", \"AMOUNT_ZERO\", \"a Settlement of zero base units moves nothing and proves nothing\"),\n );\n }\n // The strategy is resolved before the Service is read, because it is a local\n // lookup and the Service is a network read: an Agent with no strategy for the\n // Asset should be told that, not made to wait for a read it could not use.\n const strategy = resolveStrategy(\n await strategiesFor(),\n input.value.strategyId ?? settings.strategyId,\n asset.value,\n );\n if (!strategy.ok) return failure(strategy.error);\n const serviceId = input.value.serviceId.toLowerCase();\n const accepted = await serviceAcceptsAsset(registryOf(), serviceId, asset.value);\n if (!accepted.ok) return failure(accepted.error);\n const request: SettleRequest = {\n agent: settings.agent,\n serviceId: serviceId as Bytes32,\n asset: asset.value,\n amount,\n };\n if (dryRun) {\n const quote = await strategy.value.quote(request);\n if (!quote.ok) return failure(quote.error);\n return {\n ok: true,\n dryRun: true,\n txHash: null,\n chainId: Number(asset.value.chainId),\n amountBaseUnits,\n settlementId: null,\n appliedBaseUnits: null,\n prepaidBaseUnits: null,\n explorerUrl: null,\n };\n }\n const receipt = await strategy.value.settle(request);\n if (!receipt.ok) return failure(receipt.error);\n return {\n ok: true,\n dryRun: false,\n txHash: receipt.value.txHash,\n chainId: Number(receipt.value.chainId),\n amountBaseUnits: receipt.value.amount.toString(10),\n settlementId: receipt.value.settlementId,\n appliedBaseUnits: receipt.value.applied === null ? null : receipt.value.applied.toString(10),\n prepaidBaseUnits: receipt.value.toPrepaid === null ? null : receipt.value.toPrepaid.toString(10),\n explorerUrl: explorerTx(settings.explorerUrl, receipt.value.txHash),\n };\n };\n\n // -------------------------------------------------------------- dispatch\n\n const invoke = async (name: string, input: unknown): Promise<Result<unknown>> => {\n switch (name) {\n case \"tab_discover\":\n return ok(await discover(input));\n case \"tab_call\":\n return ok(await call(input));\n case \"tab_status\":\n return ok(await status(input));\n case \"tab_settle\":\n return ok(await settle(input));\n default:\n return notFoundError(\"TOOL_UNKNOWN\", `\\`${name}\\` is not a tool this server declares`, {\n details: { tool: name },\n });\n }\n };\n\n return { discover, call, status, settle, invoke };\n}\n\n// ---------------------------------------------------------------- mapping\n\n/**\n * The one setting no tool that touches a tab can proceed without.\n *\n * An Agent address, never a key. Deriving the address from a signing key would\n * mean this process holds one, and the whole point of the split is that\n * discovery, calling and status hold none.\n */\nconst agentUnconfigured = (): TabError =>\n tabError(\n \"VALIDATION\",\n \"AGENT_UNCONFIGURED\",\n \"no Agent address is configured, so there is no Open Tab to meter against; set `agent` in tab.config, or pass it to this tool where the schema allows it\",\n );\n\n/**\n * Names an Asset the index reports as a bare address.\n *\n * `TabBook` keys an Asset by token address alone, one ledger per address and no\n * chain column, while everything that crosses the MCP boundary is\n * `chainId:address`, because the SDK may be pointed at Mainnet or Testnet and a\n * bare address is ambiguous between the two. The chain id is the one the\n * settings resolved, which is the one the registry this toolset reads indexes.\n */\nconst assetStringFor = (address: string, chainId: number): string => formatAsset(chainId, address.toLowerCase());\n\n/** A transaction link on the configured explorer, or null for anything that is not a hash. */\nconst explorerTx = (explorerUrl: string, txHash: string): string | null =>\n /^0x[a-fA-F0-9]{64}$/.test(txHash) ? `${explorerUrl.replace(/\\/+$/, \"\")}/tx/${txHash}` : null;\n\nfunction toDiscoveredService(\n entry: unknown,\n directory: Map<string, TabServiceEntry>,\n chainId: number,\n env: NodeJS.ProcessEnv,\n): DiscoveredService {\n const serviceId = asString(field(entry, \"serviceId\"), \"\").toLowerCase();\n const configured = directory.get(serviceId);\n\n const assets: DiscoveredAsset[] = [];\n for (const accepted of asArray(field(entry, \"acceptedAssets\"))) {\n const address = asString(field(accepted, \"asset\"), \"\").toLowerCase();\n if (!isAddress(address)) continue;\n const collection = asStringOrNull(field(accepted, \"collection\"));\n const facts = assetFacts(chainId, address, env);\n assets.push({\n chainId,\n address,\n symbol: facts.symbol,\n decimals: facts.decimals,\n collectionAddress: collection === null ? null : collection.toLowerCase(),\n curatedAsset: facts.curatedAsset,\n });\n }\n\n const nameAsset = (address: string): string => formatAsset(chainId, address);\n\n const tools: DiscoveredTool[] = asArray(field(entry, \"prices\")).map((price) => {\n const tool = asString(field(price, \"tool\"), ZERO_WORD).toLowerCase();\n return {\n tool,\n toolName: wordToName(tool),\n asset: nameAsset(asString(field(price, \"asset\"), \"\")),\n priceBaseUnits: asDigits(field(price, \"baseUnits\"), \"0\"),\n };\n });\n\n const bonds: DiscoveredBond[] = asArray(field(entry, \"bond\")).map((bond) => ({\n asset: nameAsset(asString(field(bond, \"asset\"), \"\")),\n stakedBaseUnits: asDigits(field(bond, \"staked\"), \"0\"),\n freeBaseUnits: asDigits(field(bond, \"free\"), \"0\"),\n }));\n\n const pending = asArray(field(entry, \"pendingChanges\"))[0];\n const pendingChange =\n pending === undefined\n ? null\n : {\n changeId: asString(field(pending, \"changeId\"), ZERO_WORD).toLowerCase(),\n kind: asStringOrNull(field(pending, \"kindName\")),\n etaIso: asStringOrNull(field(pending, \"etaIso\")),\n };\n\n const tierName = asString(jsonPath(entry, \"tier\", \"name\"), \"\").toLowerCase();\n\n return {\n serviceId,\n name: configured?.name ?? wordToName(serviceId),\n endpoint: configured?.endpoint ?? null,\n tier: tierName === \"curated\" ? \"curated\" : tierName === \"permissionless\" ? \"permissionless\" : \"unknown\",\n settlementWindowSeconds: asNumber(jsonPath(entry, \"settlementWindowSeconds\", \"value\"), 0),\n assets,\n tools,\n bonds,\n pendingChange,\n };\n}\n\n/**\n * Attaches the fronted API Hub provider's endpoints to a discovered Service.\n *\n * A manifest that cannot be read is reported inside the `hub` block rather than\n * failing discovery: the Service is still real and its on-chain tools are still\n * listed, and the Hub's catalogue is an addition the chain does not carry.\n */\nasync function withHub(\n service: DiscoveredService,\n configured: TabServiceEntry | undefined,\n hubFetch: HubFetch | undefined,\n): Promise<DiscoveredService> {\n const hub = configured?.hub;\n if (hub === undefined) return service;\n const prefix = (hub.prefix ?? hub.provider).replace(/^\\/+|\\/+$/g, \"\");\n const manifest = await fetchHubManifest({\n provider: hub.provider,\n ...(hub.manifestUrl === undefined ? {} : { manifestUrl: hub.manifestUrl }),\n ...(hubFetch === undefined ? {} : { fetchImpl: hubFetch }),\n });\n if (!manifest.ok) {\n return { ...service, hub: { provider: hub.provider, prefix, endpoints: [], total: 0, error: errorOf(manifest.error) } };\n }\n return {\n ...service,\n hub: {\n provider: manifest.value.provider,\n prefix,\n endpoints: manifest.value.endpoints.map((endpoint) => ({\n endpoint: endpoint.endpoint,\n name: endpoint.name,\n description: endpoint.description,\n priceType: endpoint.priceType,\n priceUsd: endpoint.priceUsd,\n priceBaseUnits: endpoint.priceBaseUnits,\n networks: endpoint.networks,\n })),\n total: manifest.value.total,\n },\n };\n}\n\nfunction matches(\n service: DiscoveredService,\n tier: string,\n search: string | undefined,\n asset: AssetRef | undefined,\n): boolean {\n if (tier !== \"any\" && service.tier !== tier) return false;\n if (asset !== undefined) {\n const wanted = assetStringOf(asset);\n if (!service.assets.some((entry) => formatAsset(entry.chainId, entry.address) === wanted)) return false;\n }\n if (search !== undefined) {\n const needle = search.toLowerCase();\n const haystack = `${service.serviceId} ${service.name ?? \"\"}`.toLowerCase();\n if (!haystack.includes(needle)) return false;\n }\n return true;\n}\n\nfunction toPerAsset(\n entry: unknown,\n historyLimit: number,\n chainId: number,\n): (TabStatusOutput[\"perAsset\"][number] & { readonly assetAddress: string }) | null {\n const address = asString(field(entry, \"asset\"), \"\").toLowerCase();\n if (!isAddress(address)) return null;\n\n const openTab =\n asDigitsOrNull(jsonPath(entry, \"headroom\", \"openTab\")) ?? asDigits(jsonPath(entry, \"openTab\", \"observed\"), \"0\");\n\n const tabs = asArray(jsonPath(entry, \"openTab\", \"tabs\"))\n .slice(0, historyLimit)\n .map((tab) => {\n // The index keys a tab observation by Agent, Service and Asset, not by the\n // `TabBook` tabId, so the identity is often genuinely absent. Reporting the\n // zero word here would name a tab that does not exist.\n const tabId = asStringOrNull(field(tab, \"tabId\"));\n return {\n tabId: tabId !== null && /^0x[a-fA-F0-9]{64}$/.test(tabId) ? tabId.toLowerCase() : null,\n serviceId: asString(field(tab, \"serviceId\"), ZERO_WORD).toLowerCase(),\n openBaseUnits: asDigits(field(tab, \"openAfter\"), \"0\"),\n dueIso: null,\n };\n });\n\n return {\n assetAddress: address,\n asset: assetStringFor(address, chainId),\n creditLimitBaseUnits: asDigitsOrNull(jsonPath(entry, \"creditLimit\", \"value\")),\n openTabBaseUnits: openTab,\n prepaidBaseUnits: asDigitsOrNull(jsonPath(entry, \"settlements\", \"prepaidTotal\")),\n headroomBaseUnits: asDigitsOrNull(jsonPath(entry, \"headroom\", \"value\")),\n delinquent: asBoolean(jsonPath(entry, \"delinquency\", \"delinquent\"), false),\n tabs,\n };\n}\n\nfunction toSettlementRow(\n row: unknown,\n explorerUrl: string,\n chainId: number,\n): NonNullable<TabStatusOutput[\"settlements\"]>[number] {\n const txHash = asString(jsonPath(row, \"monad\", \"txHash\"), \"\");\n return {\n settlementId: asString(field(row, \"settlementId\"), ZERO_WORD).toLowerCase(),\n txHash: txHash.toLowerCase(),\n serviceId: asString(field(row, \"serviceId\"), ZERO_WORD).toLowerCase(),\n asset: formatAsset(chainId, asString(field(row, \"asset\"), \"\")),\n amountBaseUnits: asDigits(field(row, \"amount\"), \"0\"),\n appliedBaseUnits: asDigits(field(row, \"applied\"), \"0\"),\n prepaidBaseUnits: asDigits(field(row, \"toPrepaid\"), \"0\"),\n explorerUrl: explorerTx(explorerUrl, txHash),\n };\n}\n\nconst SERVICE_CATEGORIES: readonly TabError[\"category\"][] = [\n \"VALIDATION\",\n \"AUTHORISATION\",\n \"NOT_FOUND\",\n \"LIMIT\",\n \"CHAIN\",\n \"UPSTREAM\",\n \"CONFLICT\",\n \"UNAVAILABLE\",\n \"INTERNAL\",\n];\n\n/**\n * What a Service's refusal means, in this package's vocabulary.\n *\n * A Service that speaks Tab answers `{ error: { category, code, message } }` in\n * the same vocabulary, and that is passed through unchanged: a model told\n * `METERING_SIGNATURE_ABSENT` can act on it, where a flattened\n * \"the Service answered 403\" leaves it guessing. A Service that answers\n * something else has its status mapped, which is the most that can be said about\n * a body this package cannot read.\n */\nfunction serviceRefusal(status: number, body: unknown, tool: string): TabToolError {\n const declared = field(body, \"error\");\n if (isRecord(declared)) {\n const category = asString(declared[\"category\"], \"\");\n if ((SERVICE_CATEGORIES as readonly string[]).includes(category)) {\n return {\n category: category as TabError[\"category\"],\n code: asString(declared[\"code\"], \"SERVICE_REFUSED\"),\n message: asString(declared[\"message\"], `the Service answered ${status} for ${tool}`),\n retryable: asBoolean(declared[\"retryable\"], status >= 500),\n };\n }\n }\n const category: TabError[\"category\"] =\n status === 401 || status === 403\n ? \"AUTHORISATION\"\n : status === 402\n ? \"LIMIT\"\n : status === 404\n ? \"NOT_FOUND\"\n : status === 409\n ? \"CONFLICT\"\n : status === 408 || status === 429 || status === 503 || status === 504\n ? \"UNAVAILABLE\"\n : status >= 500\n ? \"UPSTREAM\"\n : \"VALIDATION\";\n return {\n category,\n code: \"SERVICE_REFUSED\",\n message: `the Service answered ${status} for ${tool}`,\n retryable: status >= 500 || status === 408 || status === 429,\n };\n}\n\n/**\n * The headers one Service requires for one call.\n *\n * A provider is consumer code, so it is called inside a `catch`: a config file\n * that throws becomes a failed tool call carrying the reason, not an unhandled\n * rejection that takes the transport with it.\n */\nasync function serviceHeaders(\n entry: TabServiceEntry,\n request: ServiceHeaderRequest,\n): Promise<Result<Readonly<Record<string, string>>>> {\n const declared = entry.headers;\n if (declared === undefined) return ok({});\n if (typeof declared !== \"function\") return ok(declared);\n try {\n return ok(await declared(request));\n } catch (error) {\n return fail(\n \"UPSTREAM\",\n \"SERVICE_HEADERS_FAILED\",\n `the header provider configured for Service ${request.serviceId} failed, so the call was not sent`,\n {\n details: { serviceId: request.serviceId },\n cause: { code: \"PROVIDER_THREW\", message: error instanceof Error ? error.message : String(error) },\n },\n );\n }\n}\n\n/** Reads the body of whatever the Service answered, without assuming a `Response`. */\nasync function readBody(response: Tab402Response): Promise<unknown> {\n const candidate = response as { json?: unknown; text?: unknown; body?: unknown };\n if (typeof candidate.json === \"function\") {\n try {\n return await (candidate.json as () => Promise<unknown>)();\n } catch {\n // fall through to text\n }\n }\n if (typeof candidate.text === \"function\") {\n try {\n return await (candidate.text as () => Promise<string>)();\n } catch {\n return null;\n }\n }\n return candidate.body ?? null;\n}\n\n/** An abort signal for one call, described structurally because there are no DOM types here. */\nfunction timeoutSignal(ms: number): unknown {\n const ctor = (globalThis as { AbortSignal?: { timeout?: (ms: number) => unknown } }).AbortSignal;\n return typeof ctor?.timeout === \"function\" ? ctor.timeout(ms) : undefined;\n}\n\n/**\n * Checks that the Service accepts the Asset before a transaction is built.\n *\n * `TabSettlement` would refuse it anyway, but a revert costs the Agent gas and\n * says less than this does. The registry read is keyless and one request.\n */\nasync function serviceAcceptsAsset(\n registry: Result<RegistryReadClient>,\n serviceId: string,\n asset: AssetRef,\n): Promise<Result<void>> {\n if (!registry.ok) return registry;\n const body = await registry.value.service(serviceId);\n if (!body.ok) return body;\n const wanted = asset.address.toLowerCase();\n for (const accepted of asArray(jsonPath(body.value, \"service\", \"acceptedAssets\"))) {\n if (asString(field(accepted, \"asset\"), \"\").toLowerCase() === wanted) return ok(undefined);\n }\n return notFoundError(\n \"ASSET_NOT_ACCEPTED\",\n `Service ${serviceId} does not accept ${assetStringOf(asset)}, so a Settlement in it would be refused`,\n { details: { serviceId, asset: assetStringOf(asset) } },\n );\n}\n\nfunction resolveStrategy(\n registry: StrategyRegistry,\n strategyId: string | undefined,\n asset: AssetRef,\n): Result<PaymentStrategy> {\n const resolved: Result<PaymentStrategy> = registry.resolve({\n ...(strategyId === undefined ? {} : { strategyId }),\n asset,\n });\n if (resolved.ok) return resolved;\n const cause = resolved.error;\n return fail(\n cause.category,\n cause.code,\n `${cause.message}; tab_settle signs with the Agent's own key through a payment strategy, so one must be registered for ${assetStringOf(asset)} before a Settlement can be built`,\n { details: { asset: assetStringOf(asset), ...(strategyId === undefined ? {} : { strategyId }) } },\n );\n}\n\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two ABIs the Monad strategy needs, in the human-readable form `ethers`
|
|
3
|
+
* parses. Kept minimal on purpose: only the functions this package calls and
|
|
4
|
+
* the one event it decodes.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ERC20_ABI: readonly ["function approve(address spender, uint256 amount) returns (bool)", "function allowance(address owner, address spender) view returns (uint256)", "function balanceOf(address owner) view returns (uint256)"];
|
|
7
|
+
/** `TabSettlement`, the one way an Open Tab is paid on Monad. */
|
|
8
|
+
export declare const TAB_SETTLEMENT_ABI: readonly ["function settle(bytes32 serviceId, address asset, uint128 amount) returns (bytes32 settlementId, uint128 applied, uint128 toPrepaid)", "function settleBatch((bytes32 serviceId, address asset, uint128 amount)[] instructions) returns (bytes32[] settlementIds)", "event Settled(bytes32 indexed settlementId, address indexed agent, bytes32 indexed serviceId, address asset, uint128 amount, uint128 applied, uint128 toPrepaid, address collection)"];
|
|
9
|
+
//# sourceMappingURL=abi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../../src/payments/abi.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,SAAS,wNAIZ,CAAC;AAEX,iEAAiE;AACjE,eAAO,MAAM,kBAAkB,wcAIrB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two ABIs the Monad strategy needs, in the human-readable form `ethers`
|
|
3
|
+
* parses. Kept minimal on purpose: only the functions this package calls and
|
|
4
|
+
* the one event it decodes.
|
|
5
|
+
*/
|
|
6
|
+
export const ERC20_ABI = [
|
|
7
|
+
"function approve(address spender, uint256 amount) returns (bool)",
|
|
8
|
+
"function allowance(address owner, address spender) view returns (uint256)",
|
|
9
|
+
"function balanceOf(address owner) view returns (uint256)",
|
|
10
|
+
];
|
|
11
|
+
/** `TabSettlement`, the one way an Open Tab is paid on Monad. */
|
|
12
|
+
export const TAB_SETTLEMENT_ABI = [
|
|
13
|
+
"function settle(bytes32 serviceId, address asset, uint128 amount) returns (bytes32 settlementId, uint128 applied, uint128 toPrepaid)",
|
|
14
|
+
"function settleBatch((bytes32 serviceId, address asset, uint128 amount)[] instructions) returns (bytes32[] settlementIds)",
|
|
15
|
+
"event Settled(bytes32 indexed settlementId, address indexed agent, bytes32 indexed serviceId, address asset, uint128 amount, uint128 applied, uint128 toPrepaid, address collection)",
|
|
16
|
+
];
|
|
17
|
+
//# sourceMappingURL=abi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abi.js","sourceRoot":"","sources":["../../src/payments/abi.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,kEAAkE;IAClE,2EAA2E;IAC3E,0DAA0D;CAClD,CAAC;AAEX,iEAAiE;AACjE,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,sIAAsI;IACtI,2HAA2H;IAC3H,sLAAsL;CAC9K,CAAC","sourcesContent":["/**\n * The two ABIs the Monad strategy needs, in the human-readable form `ethers`\n * parses. Kept minimal on purpose: only the functions this package calls and\n * the one event it decodes.\n */\n\nexport const ERC20_ABI = [\n \"function approve(address spender, uint256 amount) returns (bool)\",\n \"function allowance(address owner, address spender) view returns (uint256)\",\n \"function balanceOf(address owner) view returns (uint256)\",\n] as const;\n\n/** `TabSettlement`, the one way an Open Tab is paid on Monad. */\nexport const TAB_SETTLEMENT_ABI = [\n \"function settle(bytes32 serviceId, address asset, uint128 amount) returns (bytes32 settlementId, uint128 applied, uint128 toPrepaid)\",\n \"function settleBatch((bytes32 serviceId, address asset, uint128 amount)[] instructions) returns (bytes32[] settlementIds)\",\n \"event Settled(bytes32 indexed settlementId, address indexed agent, bytes32 indexed serviceId, address asset, uint128 amount, uint128 applied, uint128 toPrepaid, address collection)\",\n] as const;\n"]}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tab.config.ts` discovery: mechanism three of R23.6.
|
|
3
|
+
*
|
|
4
|
+
* Zero-code wiring. A consumer writes a config file naming strategies as module
|
|
5
|
+
* specifiers, and the strategies register themselves at startup with no
|
|
6
|
+
* application code involved at all:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* // tab.config.ts, at the consumer's project root
|
|
10
|
+
* import { defineTabConfig } from "@tabai/sdk";
|
|
11
|
+
* export default defineTabConfig({ strategies: ["@acme/tab-strategy-solana"] });
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* ## What an entry may be
|
|
15
|
+
*
|
|
16
|
+
* A module specifier, a strategy object, or a factory returning one. The
|
|
17
|
+
* specifier form is the point of the mechanism; the other two exist because a
|
|
18
|
+
* config file that can only name packages forces a consumer to publish one before
|
|
19
|
+
* they can try anything.
|
|
20
|
+
*
|
|
21
|
+
* ## Where a specifier resolves from
|
|
22
|
+
*
|
|
23
|
+
* From the **config file**, not from this package. `@acme/tab-strategy-solana` is
|
|
24
|
+
* the consumer's dependency and under pnpm it is not visible from inside
|
|
25
|
+
* `@tabai/sdk` at all, so resolving relative to this module would fail for the
|
|
26
|
+
* exact layout the workspace uses. `createRequire(configFileUrl)` resolves the
|
|
27
|
+
* way the consumer's own `import` would, and a bare specifier that resolution
|
|
28
|
+
* misses is retried as a plain dynamic import before the error is reported.
|
|
29
|
+
*
|
|
30
|
+
* ## The `.ts` config file and the host runtime
|
|
31
|
+
*
|
|
32
|
+
* This module imports the config file; it does not compile it. A `.ts` config
|
|
33
|
+
* loads under a runtime that strips types, `tsx`, `node --experimental-strip-types`,
|
|
34
|
+
* a bundler's dev server, and fails under one that does not. That failure comes
|
|
35
|
+
* back as a `Result` naming the file and the requirement rather than as a stack
|
|
36
|
+
* trace, and `tab.config.js` and `tab.config.mjs` are discovered too so a
|
|
37
|
+
* consumer with a plain Node process has a first-class option.
|
|
38
|
+
*
|
|
39
|
+
* Requirements: 23.6, 21.5
|
|
40
|
+
*/
|
|
41
|
+
import { type Result } from "../_shared/index.js";
|
|
42
|
+
import { type Logger } from "../logger.js";
|
|
43
|
+
import { type PaymentStrategy } from "./strategy.js";
|
|
44
|
+
import type { X402SignerFactory } from "../x402/client.js";
|
|
45
|
+
import { type StrategyRegistration, type StrategyRegistry } from "./registry.js";
|
|
46
|
+
/**
|
|
47
|
+
* A factory in a config file, so a strategy that needs a signer can be built lazily.
|
|
48
|
+
*
|
|
49
|
+
* Returning `undefined` is a supported answer and means "not available in this
|
|
50
|
+
* environment". That is what keeps every read on this rail keyless: the whole
|
|
51
|
+
* point of a factory rather than an object is that a config file can declare a
|
|
52
|
+
* strategy that only exists once a signing key does, and `tab_discover`,
|
|
53
|
+
* `tab_status` and `doctor` never need one. A declining factory is skipped, and
|
|
54
|
+
* the rest of the config - the Agent, the registry URL, the Service endpoints -
|
|
55
|
+
* is kept.
|
|
56
|
+
*/
|
|
57
|
+
export type PaymentStrategyFactory = () => PaymentStrategy | undefined | Promise<PaymentStrategy | undefined>;
|
|
58
|
+
/** A module specifier, a ready strategy, or a factory returning one. */
|
|
59
|
+
export type TabConfigStrategyEntry = string | PaymentStrategy | PaymentStrategyFactory;
|
|
60
|
+
/**
|
|
61
|
+
* One Service's off-chain coordinates.
|
|
62
|
+
*
|
|
63
|
+
* The chain records who operates a Service, what its tools cost and where it
|
|
64
|
+
* collects Settlements. It records no URL, deliberately: an endpoint moves, and
|
|
65
|
+
* a registry that pinned one would either go stale or need a write every time a
|
|
66
|
+
* Service redeployed. So the endpoint is configuration, and this is where a
|
|
67
|
+
* consumer states it.
|
|
68
|
+
*
|
|
69
|
+
* Without an entry here, `tab_discover` reports the Service with a null endpoint
|
|
70
|
+
* and `tab_call` refuses it by name rather than inventing a URL.
|
|
71
|
+
*/
|
|
72
|
+
export interface TabServiceEntry {
|
|
73
|
+
/** The Service's 32-byte registry key, as `tab_discover` reports it. */
|
|
74
|
+
readonly serviceId: string;
|
|
75
|
+
/** A label for a person. Defaults to the ascii the serviceId decodes to. */
|
|
76
|
+
readonly name?: string;
|
|
77
|
+
/** Absolute base URL `tab_call` sends requests to. */
|
|
78
|
+
readonly endpoint: string;
|
|
79
|
+
/**
|
|
80
|
+
* The API Hub provider this Service fronts, if it fronts one.
|
|
81
|
+
*
|
|
82
|
+
* With this set, `tab_discover` fetches the provider's manifest and lists its
|
|
83
|
+
* endpoints under the Service as the tools they are, each reachable through
|
|
84
|
+
* the Service's `/hub/<prefix>` mount and metered onto the Agent's Open Tab.
|
|
85
|
+
*/
|
|
86
|
+
readonly hub?: TabServiceHubEntry;
|
|
87
|
+
/**
|
|
88
|
+
* Headers sent with every call to this Service.
|
|
89
|
+
*
|
|
90
|
+
* A record for a Service that gates on something fixed, such as an API key. A
|
|
91
|
+
* function for one that gates on something per request: the reference metering
|
|
92
|
+
* gateway, for instance, requires a claim over the method, the path, the Agent
|
|
93
|
+
* and the tool, which no static header can satisfy. Tab defines neither scheme
|
|
94
|
+
* and validates neither -- this is the seam through which a Service's own
|
|
95
|
+
* access control stays the Service's own.
|
|
96
|
+
*
|
|
97
|
+
* Never a Tab credential. The Tab identity headers are added by the 402 client
|
|
98
|
+
* and nothing in Tab authenticates an Agent with a bearer token.
|
|
99
|
+
*/
|
|
100
|
+
readonly headers?: Readonly<Record<string, string>> | ServiceHeaderProvider;
|
|
101
|
+
}
|
|
102
|
+
/** An API Hub provider fronted by a Service. See {@link TabServiceEntry.hub}. */
|
|
103
|
+
export interface TabServiceHubEntry {
|
|
104
|
+
/** The Hub's provider slug, for example `weather-underground`. */
|
|
105
|
+
readonly provider: string;
|
|
106
|
+
/** The mount under the Service endpoint. Defaults to the provider slug, so `/hub/<provider>`. */
|
|
107
|
+
readonly prefix?: string;
|
|
108
|
+
/** Overrides the manifest URL, for a mirror or a test. */
|
|
109
|
+
readonly manifestUrl?: string;
|
|
110
|
+
}
|
|
111
|
+
/** Builds the per-request headers one Service requires. See {@link TabServiceEntry.headers}. */
|
|
112
|
+
export type ServiceHeaderProvider = (request: ServiceHeaderRequest) => Readonly<Record<string, string>> | Promise<Readonly<Record<string, string>>>;
|
|
113
|
+
/** What the provider is told about the call it is producing headers for. */
|
|
114
|
+
export interface ServiceHeaderRequest {
|
|
115
|
+
readonly method: string;
|
|
116
|
+
/** The absolute URL the request is going to. */
|
|
117
|
+
readonly url: string;
|
|
118
|
+
/** The tool name as the caller gave it, before it is packed into a 32-byte key. */
|
|
119
|
+
readonly tool: string;
|
|
120
|
+
/** The Agent the call is metered against. */
|
|
121
|
+
readonly agent: string;
|
|
122
|
+
readonly serviceId: string;
|
|
123
|
+
}
|
|
124
|
+
export interface TabConfig {
|
|
125
|
+
readonly strategies?: readonly TabConfigStrategyEntry[];
|
|
126
|
+
/**
|
|
127
|
+
* The Agent's Monad address: whose Open Tab a metered call lands on.
|
|
128
|
+
*
|
|
129
|
+
* An address and never a key. Nothing in this package derives an address from
|
|
130
|
+
* a private key, because doing so would mean a config file that holds one.
|
|
131
|
+
*/
|
|
132
|
+
readonly agent?: string;
|
|
133
|
+
/** Absolute base URL of the Tab registry read API, which serves discovery and status. */
|
|
134
|
+
readonly registryUrl?: string;
|
|
135
|
+
/** Where each Service can be reached. See {@link TabServiceEntry}. */
|
|
136
|
+
readonly services?: readonly TabServiceEntry[];
|
|
137
|
+
/**
|
|
138
|
+
* The x402 signer, for the prepaid fallback.
|
|
139
|
+
*
|
|
140
|
+
* A factory and only a factory, for the reason `strategies` holds factories:
|
|
141
|
+
* a signer is built from a key, and a config file must be loadable by the
|
|
142
|
+
* three surfaces that hold none. Nothing calls this until a Service has
|
|
143
|
+
* refused a call on credit and offered x402 for it, and a factory returning
|
|
144
|
+
* `undefined` declines, which leaves that refusal the `LIMIT_EXCEEDED` it was.
|
|
145
|
+
*/
|
|
146
|
+
readonly x402?: X402SignerFactory;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Types a config file's default export. Identity at runtime, its whole job is to
|
|
150
|
+
* make a typo in the config a compile error in the consumer's editor.
|
|
151
|
+
*/
|
|
152
|
+
export declare const defineTabConfig: (config: TabConfig) => TabConfig;
|
|
153
|
+
/**
|
|
154
|
+
* The file names discovery looks for, in order. `.ts` first because it is the
|
|
155
|
+
* documented form and the one that type-checks; the plain-JavaScript forms follow
|
|
156
|
+
* so a consumer whose runtime strips no types is not shut out.
|
|
157
|
+
*/
|
|
158
|
+
export declare const TAB_CONFIG_FILE_NAMES: readonly ["tab.config.ts", "tab.config.mts", "tab.config.mjs", "tab.config.js", "tab.config.cjs"];
|
|
159
|
+
export interface FindTabConfigOptions {
|
|
160
|
+
/** Where the walk starts. Defaults to the working directory. */
|
|
161
|
+
readonly cwd?: string;
|
|
162
|
+
readonly fileNames?: readonly string[];
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Walks from `cwd` towards the filesystem root and returns the first config file
|
|
166
|
+
* found, or `undefined` when there is none.
|
|
167
|
+
*
|
|
168
|
+
* Absence is not an error: the whole point of the mechanism is that a consumer
|
|
169
|
+
* who wants nothing from it writes nothing.
|
|
170
|
+
*/
|
|
171
|
+
export declare function findTabConfig(options?: FindTabConfigOptions): Result<string | undefined>;
|
|
172
|
+
export interface LoadTabConfigOptions extends FindTabConfigOptions {
|
|
173
|
+
/** An explicit config file. Absolute, or relative to `cwd`. Missing is an error. */
|
|
174
|
+
readonly configPath?: string;
|
|
175
|
+
/**
|
|
176
|
+
* Where the discovered strategies are registered. Omitted means the
|
|
177
|
+
* module-level registry, which is what makes the mechanism zero-code; `false`
|
|
178
|
+
* loads and validates without registering anything.
|
|
179
|
+
*/
|
|
180
|
+
readonly registry?: StrategyRegistry | false;
|
|
181
|
+
readonly logger?: Logger;
|
|
182
|
+
}
|
|
183
|
+
export interface LoadedTabConfig {
|
|
184
|
+
/** The file that was loaded, or `undefined` when none was found. */
|
|
185
|
+
readonly path: string | undefined;
|
|
186
|
+
readonly config: TabConfig;
|
|
187
|
+
readonly strategies: readonly PaymentStrategy[];
|
|
188
|
+
/** Empty when `registry` was `false`. */
|
|
189
|
+
readonly registrations: readonly StrategyRegistration[];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Loads a config file, resolves every strategy entry, and registers the result.
|
|
193
|
+
*
|
|
194
|
+
* Returns a `Result` for every failure, including a config file that throws on
|
|
195
|
+
* import: a consumer's config is consumer code, and this package does not turn
|
|
196
|
+
* their mistake into an unhandled rejection.
|
|
197
|
+
*/
|
|
198
|
+
export declare function loadTabConfig(options?: LoadTabConfigOptions): Promise<Result<LoadedTabConfig>>;
|
|
199
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/payments/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAMH,OAAO,EAA+B,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAiB,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAA2B,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACtB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;GAUG;AACH,MAAM,MAAM,sBAAsB,GAAG,MACjC,eAAe,GACf,SAAS,GACT,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;AAEzC,wEAAwE;AACxE,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,eAAe,GAAG,sBAAsB,CAAC;AAEvF;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,kBAAkB,CAAC;IAClC;;;;;;;;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