@chipi-stack/backend 14.14.0 → 14.15.1

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.
@@ -26,10 +26,12 @@ declare class ChipiClient {
26
26
  params?: Record<string, any>;
27
27
  bearerToken?: string;
28
28
  }): Promise<T>;
29
- post<T>({ endpoint, bearerToken, body, }: {
29
+ post<T>({ endpoint, bearerToken, body, headers, }: {
30
30
  endpoint: string;
31
31
  bearerToken: string;
32
32
  body?: Record<string, any>;
33
+ /** Extra request headers, e.g. `X-PAYMENT`. Cannot override auth or content type. */
34
+ headers?: Record<string, string>;
33
35
  }): Promise<T>;
34
36
  put<T>({ endpoint, bearerToken, body, }: {
35
37
  endpoint: string;
@@ -26,10 +26,12 @@ declare class ChipiClient {
26
26
  params?: Record<string, any>;
27
27
  bearerToken?: string;
28
28
  }): Promise<T>;
29
- post<T>({ endpoint, bearerToken, body, }: {
29
+ post<T>({ endpoint, bearerToken, body, headers, }: {
30
30
  endpoint: string;
31
31
  bearerToken: string;
32
32
  body?: Record<string, any>;
33
+ /** Extra request headers, e.g. `X-PAYMENT`. Cannot override auth or content type. */
34
+ headers?: Record<string, string>;
33
35
  }): Promise<T>;
34
36
  put<T>({ endpoint, bearerToken, body, }: {
35
37
  endpoint: string;
package/dist/index.d.mts CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as _chipi_stack_types from '@chipi-stack/types';
2
- import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, SetupSessionParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, SetSpendingPolicyParams, GetSpendingPolicyParams, SpendingPolicyData, RemoveSpendingPolicyParams, Currency, AiSignalsParams, AiSignals, ThinkParams, ThinkResponse, AiExecuteParams, AiExecuteResponse, AiChatParams, AiChatResponse, AiPricesParams, AiPrices, AiModelsResponse, ThinkDecision, PaymasterAdapter, PaymasterAccount, X402FacilitatorConfig, NonceStore, PaymentPayload, VerifyResponse, SettleResponse, ChipiSDKConfig, ExecuteTransactionParams, SignTypedDataParams, SignTypedDataResult, TransferParams, ApproveParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, TransactionStatusResponse, PrepareWalletUpgradeParams, PrepareWalletUpgradeResponse, ExecuteWalletUpgradeParams, ExecuteWalletUpgradeResponse, ChipiServerSDKConfig, ChipiBrowserSDKConfig, SessionConfig, Call as Call$1, SpendingPolicyConfig, X402ClientConfig, PaymentRequirement, X402PaymentConfig, ShhhSignerKind } from '@chipi-stack/types';
2
+ import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, SetupSessionParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, SetSpendingPolicyParams, GetSpendingPolicyParams, SpendingPolicyData, RemoveSpendingPolicyParams, Currency, AiSignalsParams, AiSignals, ThinkParams, ThinkOptions, ThinkResponse, AiExecuteParams, AiExecuteResponse, AiChatParams, AiChatResponse, AiPricesParams, AiPrices, AiModelsResponse, ThinkDecision, PaymasterAdapter, PaymasterAccount, X402FacilitatorConfig, NonceStore, PaymentPayload, VerifyResponse, SettleResponse, ChipiSDKConfig, ExecuteTransactionParams, SignTypedDataParams, SignTypedDataResult, TransferParams, ApproveParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, TransactionStatusResponse, PrepareWalletUpgradeParams, PrepareWalletUpgradeResponse, ExecuteWalletUpgradeParams, ExecuteWalletUpgradeResponse, ChipiServerSDKConfig, ChipiBrowserSDKConfig, SessionConfig, Call as Call$1, SpendingPolicyConfig, X402ClientConfig, PaymentRequirement, X402PaymentConfig, ShhhSignerKind } from '@chipi-stack/types';
3
3
  export * from '@chipi-stack/types';
4
4
  export { Chain, ChainToken, Currency } from '@chipi-stack/types';
5
- import { C as ChipiWallets } from './wallets-CYCLyyXY.mjs';
6
- export { E as ExecuteMigrateResponse, M as MigrateChipiWalletToShhhParams, a as MigrationOutcome, P as PrepareMigrateResponse, m as migrateChipiWalletToShhh } from './wallets-CYCLyyXY.mjs';
5
+ import { C as ChipiWallets } from './wallets-CX42j3eN.mjs';
6
+ export { E as ExecuteMigrateResponse, M as MigrateChipiWalletToShhhParams, a as MigrationOutcome, P as PrepareMigrateResponse, m as migrateChipiWalletToShhh } from './wallets-CX42j3eN.mjs';
7
7
  import { ChipiTransactions } from './transactions.mjs';
8
8
  import { ChipiSkuPurchases } from './skuPurchases.mjs';
9
9
  import { ChipiSkus } from './skus.mjs';
10
- import { C as ChipiClient } from './client-CqD_yGH0.mjs';
10
+ import { C as ChipiClient } from './client-D6SDBu5p.mjs';
11
11
  import { Call, ProviderInterface, Account } from 'starknet';
12
12
 
13
13
  /**
@@ -626,7 +626,11 @@ declare function isThinkDecision(decision: unknown): decision is ThinkDecision;
626
626
  declare class ChipiAi {
627
627
  private client;
628
628
  private apiSecretKey?;
629
- constructor(client: ChipiClient, apiSecretKey?: string | undefined);
629
+ /** Needed only to pay think calls with `payWithSession`. */
630
+ private sessions?;
631
+ constructor(client: ChipiClient, apiSecretKey?: string | undefined,
632
+ /** Needed only to pay think calls with `payWithSession`. */
633
+ sessions?: ChipiSessions | undefined);
630
634
  private secret;
631
635
  /**
632
636
  * `GET /v1/ai/signals`: technical signals per token, market sentiment and
@@ -639,8 +643,37 @@ declare class ChipiAi {
639
643
  *
640
644
  * The decision is advice, not an order: check it with `isThinkDecision` and
641
645
  * enforce your own limits before executing anything.
646
+ *
647
+ * **Paying per call (x402).** With `payWithSession`, a 402 that carries a
648
+ * session-transfer offer (credits short, x402 on) is paid with the agent's
649
+ * session key: a USDC `transfer` to the offer's `payTo`, then the same call
650
+ * again with `X-PAYMENT`. The price must be at most `maxAmount`, `model`
651
+ * must be payable and the input within `maxPromptBytes`, all checked before
652
+ * paying. The wallet must be a wallet of the organization that owns the
653
+ * `sk_`: the first request names it in `X-PAYER`, and when the API answers
654
+ * that a payment from it would be refused, nothing is paid
655
+ * (`X402_PAYER_NOT_IN_ORG`). The session must whitelist `transfer` and cap
656
+ * USDC. A payment that was made but not served is reported in
657
+ * `error.details.xPayment`; pass it back as `options.xPayment` to retry
658
+ * without paying again.
659
+ *
660
+ * @example
661
+ * ```typescript
662
+ * const res = await sdk.ai.think(
663
+ * { portfolio, model: "haiku" },
664
+ * { payWithSession: { encryptKey, wallet, session, maxAmount: 20_000n } } // $0.02 at most
665
+ * );
666
+ * res.x402Payment; // set when the call was paid over x402
667
+ * ```
668
+ */
669
+ think(params: ThinkParams, options?: ThinkOptions): Promise<ThinkResponse>;
670
+ private postThink;
671
+ /**
672
+ * Pay one think call with a session-key USDC transfer, then send it again
673
+ * with `X-PAYMENT`. Every check that can refuse the call runs before the
674
+ * transfer; the transfer counts only once its receipt shows the USDC moved.
642
675
  */
643
- think(params: ThinkParams): Promise<ThinkResponse>;
676
+ private payAndThink;
644
677
  /**
645
678
  * `POST /v1/ai/execute`: unsigned AVNU swap calls (approve + swap) for
646
679
  * `walletAddress`. Nothing is submitted; sign the calls with a session key
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import * as _chipi_stack_types from '@chipi-stack/types';
2
- import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, SetupSessionParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, SetSpendingPolicyParams, GetSpendingPolicyParams, SpendingPolicyData, RemoveSpendingPolicyParams, Currency, AiSignalsParams, AiSignals, ThinkParams, ThinkResponse, AiExecuteParams, AiExecuteResponse, AiChatParams, AiChatResponse, AiPricesParams, AiPrices, AiModelsResponse, ThinkDecision, PaymasterAdapter, PaymasterAccount, X402FacilitatorConfig, NonceStore, PaymentPayload, VerifyResponse, SettleResponse, ChipiSDKConfig, ExecuteTransactionParams, SignTypedDataParams, SignTypedDataResult, TransferParams, ApproveParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, TransactionStatusResponse, PrepareWalletUpgradeParams, PrepareWalletUpgradeResponse, ExecuteWalletUpgradeParams, ExecuteWalletUpgradeResponse, ChipiServerSDKConfig, ChipiBrowserSDKConfig, SessionConfig, Call as Call$1, SpendingPolicyConfig, X402ClientConfig, PaymentRequirement, X402PaymentConfig, ShhhSignerKind } from '@chipi-stack/types';
2
+ import { CreateSessionKeyParams, SessionKeyData, AddSessionKeyParams, SetupSessionParams, RevokeSessionKeyParams, GetSessionDataParams, SessionDataResponse, ExecuteWithSessionParams, SetSpendingPolicyParams, GetSpendingPolicyParams, SpendingPolicyData, RemoveSpendingPolicyParams, Currency, AiSignalsParams, AiSignals, ThinkParams, ThinkOptions, ThinkResponse, AiExecuteParams, AiExecuteResponse, AiChatParams, AiChatResponse, AiPricesParams, AiPrices, AiModelsResponse, ThinkDecision, PaymasterAdapter, PaymasterAccount, X402FacilitatorConfig, NonceStore, PaymentPayload, VerifyResponse, SettleResponse, ChipiSDKConfig, ExecuteTransactionParams, SignTypedDataParams, SignTypedDataResult, TransferParams, ApproveParams, CallAnyContractParams, CreateWalletParams, CreateWalletResponse, RecordSendTransactionParams, Transaction, GetTransactionListQuery, PaginatedResponse, GetWalletParams, GetTokenBalanceParams, GetTokenBalanceResponse, CreateSkuPurchaseParams, GetSkuListQuery, Sku, TransactionStatusResponse, PrepareWalletUpgradeParams, PrepareWalletUpgradeResponse, ExecuteWalletUpgradeParams, ExecuteWalletUpgradeResponse, ChipiServerSDKConfig, ChipiBrowserSDKConfig, SessionConfig, Call as Call$1, SpendingPolicyConfig, X402ClientConfig, PaymentRequirement, X402PaymentConfig, ShhhSignerKind } from '@chipi-stack/types';
3
3
  export * from '@chipi-stack/types';
4
4
  export { Chain, ChainToken, Currency } from '@chipi-stack/types';
5
- import { C as ChipiWallets } from './wallets-DxKnh21Q.js';
6
- export { E as ExecuteMigrateResponse, M as MigrateChipiWalletToShhhParams, a as MigrationOutcome, P as PrepareMigrateResponse, m as migrateChipiWalletToShhh } from './wallets-DxKnh21Q.js';
5
+ import { C as ChipiWallets } from './wallets-C541u9mn.js';
6
+ export { E as ExecuteMigrateResponse, M as MigrateChipiWalletToShhhParams, a as MigrationOutcome, P as PrepareMigrateResponse, m as migrateChipiWalletToShhh } from './wallets-C541u9mn.js';
7
7
  import { ChipiTransactions } from './transactions.js';
8
8
  import { ChipiSkuPurchases } from './skuPurchases.js';
9
9
  import { ChipiSkus } from './skus.js';
10
- import { C as ChipiClient } from './client-CqD_yGH0.js';
10
+ import { C as ChipiClient } from './client-D6SDBu5p.js';
11
11
  import { Call, ProviderInterface, Account } from 'starknet';
12
12
 
13
13
  /**
@@ -626,7 +626,11 @@ declare function isThinkDecision(decision: unknown): decision is ThinkDecision;
626
626
  declare class ChipiAi {
627
627
  private client;
628
628
  private apiSecretKey?;
629
- constructor(client: ChipiClient, apiSecretKey?: string | undefined);
629
+ /** Needed only to pay think calls with `payWithSession`. */
630
+ private sessions?;
631
+ constructor(client: ChipiClient, apiSecretKey?: string | undefined,
632
+ /** Needed only to pay think calls with `payWithSession`. */
633
+ sessions?: ChipiSessions | undefined);
630
634
  private secret;
631
635
  /**
632
636
  * `GET /v1/ai/signals`: technical signals per token, market sentiment and
@@ -639,8 +643,37 @@ declare class ChipiAi {
639
643
  *
640
644
  * The decision is advice, not an order: check it with `isThinkDecision` and
641
645
  * enforce your own limits before executing anything.
646
+ *
647
+ * **Paying per call (x402).** With `payWithSession`, a 402 that carries a
648
+ * session-transfer offer (credits short, x402 on) is paid with the agent's
649
+ * session key: a USDC `transfer` to the offer's `payTo`, then the same call
650
+ * again with `X-PAYMENT`. The price must be at most `maxAmount`, `model`
651
+ * must be payable and the input within `maxPromptBytes`, all checked before
652
+ * paying. The wallet must be a wallet of the organization that owns the
653
+ * `sk_`: the first request names it in `X-PAYER`, and when the API answers
654
+ * that a payment from it would be refused, nothing is paid
655
+ * (`X402_PAYER_NOT_IN_ORG`). The session must whitelist `transfer` and cap
656
+ * USDC. A payment that was made but not served is reported in
657
+ * `error.details.xPayment`; pass it back as `options.xPayment` to retry
658
+ * without paying again.
659
+ *
660
+ * @example
661
+ * ```typescript
662
+ * const res = await sdk.ai.think(
663
+ * { portfolio, model: "haiku" },
664
+ * { payWithSession: { encryptKey, wallet, session, maxAmount: 20_000n } } // $0.02 at most
665
+ * );
666
+ * res.x402Payment; // set when the call was paid over x402
667
+ * ```
668
+ */
669
+ think(params: ThinkParams, options?: ThinkOptions): Promise<ThinkResponse>;
670
+ private postThink;
671
+ /**
672
+ * Pay one think call with a session-key USDC transfer, then send it again
673
+ * with `X-PAYMENT`. Every check that can refuse the call runs before the
674
+ * transfer; the transfer counts only once its receipt shows the USDC moved.
642
675
  */
643
- think(params: ThinkParams): Promise<ThinkResponse>;
676
+ private payAndThink;
644
677
  /**
645
678
  * `POST /v1/ai/execute`: unsigned AVNU swap calls (approve + swap) for
646
679
  * `walletAddress`. Nothing is submitted; sign the calls with a session key