@ottocode/ai-sdk 0.1.3 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ottocode/ai-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
package/src/auth.ts CHANGED
@@ -9,8 +9,8 @@ export interface WalletContext {
9
9
  privateKeyBytes: Uint8Array;
10
10
  }
11
11
 
12
- export function createWalletContext(auth: SetuAuth): WalletContext {
13
- const privateKeyBytes = bs58.decode(auth.privateKey);
12
+ export function createWalletContext(auth: Required<SetuAuth>): WalletContext {
13
+ const privateKeyBytes = bs58.decode(auth.privateKey!);
14
14
  const keypair = Keypair.fromSecretKey(privateKeyBytes);
15
15
  const walletAddress = keypair.publicKey.toBase58();
16
16
  return { keypair, walletAddress, privateKeyBytes };
@@ -32,7 +32,8 @@ export function buildWalletHeaders(ctx: WalletContext): Record<string, string> {
32
32
  };
33
33
  }
34
34
 
35
- export function getPublicKeyFromPrivate(privateKey: string): string | null {
35
+ export function getPublicKeyFromPrivate(privateKey?: string): string | null {
36
+ if (!privateKey) return null;
36
37
  try {
37
38
  const privateKeyBytes = bs58.decode(privateKey);
38
39
  const keypair = Keypair.fromSecretKey(privateKeyBytes);
package/src/balance.ts CHANGED
@@ -13,11 +13,11 @@ function trimTrailingSlash(url: string) {
13
13
  }
14
14
 
15
15
  export async function fetchBalance(
16
- auth: SetuAuth,
16
+ auth: Required<SetuAuth>,
17
17
  baseURL?: string,
18
18
  ): Promise<BalanceResponse | null> {
19
19
  try {
20
- const privateKeyBytes = bs58.decode(auth.privateKey);
20
+ const privateKeyBytes = bs58.decode(auth.privateKey!);
21
21
  const keypair = Keypair.fromSecretKey(privateKeyBytes);
22
22
  const walletAddress = keypair.publicKey.toBase58();
23
23
  const url = trimTrailingSlash(baseURL ?? DEFAULT_BASE_URL);
@@ -60,11 +60,11 @@ export async function fetchBalance(
60
60
  }
61
61
 
62
62
  export async function fetchWalletUsdcBalance(
63
- auth: SetuAuth,
63
+ auth: Required<SetuAuth>,
64
64
  network: 'mainnet' | 'devnet' = 'mainnet',
65
65
  ): Promise<WalletUsdcBalance | null> {
66
66
  try {
67
- const privateKeyBytes = bs58.decode(auth.privateKey);
67
+ const privateKeyBytes = bs58.decode(auth.privateKey!);
68
68
  const keypair = Keypair.fromSecretKey(privateKeyBytes);
69
69
  const walletAddress = keypair.publicKey.toBase58();
70
70
  const rpcUrl = network === 'devnet' ? 'https://api.devnet.solana.com' : DEFAULT_RPC_URL;
package/src/setu.ts CHANGED
@@ -27,7 +27,12 @@ export interface SetuInstance {
27
27
 
28
28
  export function createSetu(config: SetuConfig): SetuInstance {
29
29
  const baseURL = trimTrailingSlash(config.baseURL ?? DEFAULT_BASE_URL);
30
- const wallet = createWalletContext(config.auth);
30
+ const privateKey = config.auth.privateKey || process.env.SETU_PRIVATE_KEY;
31
+ if (!privateKey) {
32
+ throw new Error('Setu: privateKey is required. Pass it via config.auth.privateKey or set SETU_PRIVATE_KEY env variable.');
33
+ }
34
+ const resolvedAuth = { ...config.auth, privateKey };
35
+ const wallet = createWalletContext(resolvedAuth);
31
36
  const registry = new ProviderRegistry(config.providers, config.modelMap);
32
37
 
33
38
  const setuFetch = createSetuFetch({
@@ -74,14 +79,14 @@ export function createSetu(config: SetuConfig): SetuInstance {
74
79
  },
75
80
 
76
81
  async balance() {
77
- return fetchBalance(config.auth, baseURL);
82
+ return fetchBalance(resolvedAuth, baseURL);
78
83
  },
79
84
 
80
85
  async walletBalance(network?: 'mainnet' | 'devnet') {
81
- return fetchWalletUsdcBalance(config.auth, network);
86
+ return fetchWalletUsdcBalance(resolvedAuth, network);
82
87
  },
83
88
 
84
- walletAddress: getPublicKeyFromPrivate(config.auth.privateKey),
89
+ walletAddress: getPublicKeyFromPrivate(resolvedAuth.privateKey),
85
90
 
86
91
  registry,
87
92
  };
package/src/types.ts CHANGED
@@ -21,7 +21,7 @@ export interface ProviderConfig {
21
21
  }
22
22
 
23
23
  export interface SetuAuth {
24
- privateKey: string;
24
+ privateKey?: string;
25
25
  }
26
26
 
27
27
  export interface BalanceUpdate {