@ghostspeak/sdk 1.4.1 → 1.5.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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _solana_addresses from '@solana/addresses';
2
2
  import { Address as Address$1 } from '@solana/addresses';
3
- import { ReadonlyUint8Array, Address, Encoder, Decoder, Codec, EncodedAccount, Account, MaybeEncodedAccount, MaybeAccount, fetchEncodedAccount, FetchAccountConfig, fetchEncodedAccounts, FetchAccountsConfig, Option, OptionOrNullable, GetDiscriminatedUnionVariant, GetDiscriminatedUnionVariantContent, SolanaError, SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, IAccountMeta, IInstruction, IInstructionWithData, IInstructionWithAccounts, WritableAccount, WritableSignerAccount, IAccountSignerMeta, ReadonlyAccount, TransactionSigner, ReadonlySignerAccount, Rpc, GetLatestBlockhashApi, SendTransactionApi, GetAccountInfoApi, SimulateTransactionApi, GetFeeForMessageApi, GetProgramAccountsApi, RpcSubscriptions, Signature, GetEpochInfoApi, GetSignatureStatusesApi, SignatureNotificationsApi, SlotNotificationsApi, TransactionMessage } from '@solana/kit';
3
+ import { ReadonlyUint8Array, Address, Encoder, Decoder, Codec, EncodedAccount, Account, MaybeEncodedAccount, MaybeAccount, fetchEncodedAccount, FetchAccountConfig, fetchEncodedAccounts, FetchAccountsConfig, Option, OptionOrNullable, GetDiscriminatedUnionVariant, GetDiscriminatedUnionVariantContent, SolanaError, SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, IAccountMeta, IInstruction, IInstructionWithData, IInstructionWithAccounts, WritableAccount, WritableSignerAccount, IAccountSignerMeta, ReadonlyAccount, TransactionSigner, ReadonlySignerAccount, Rpc, GetLatestBlockhashApi, SendTransactionApi, GetAccountInfoApi, SimulateTransactionApi, GetFeeForMessageApi, GetProgramAccountsApi, GetEpochInfoApi, GetSignatureStatusesApi, RpcSubscriptions, SignatureNotificationsApi, SlotNotificationsApi, Signature, TransactionMessage } from '@solana/kit';
4
4
  import { TransactionSigner as TransactionSigner$1 } from '@solana/signers';
5
5
  import { IInstruction as IInstruction$1 } from '@solana/instructions';
6
6
 
@@ -12255,12 +12255,14 @@ type ParsedVerifyAgentInstruction<TProgram extends string = typeof GHOSTSPEAK_MA
12255
12255
  declare function parseVerifyAgentInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedVerifyAgentInstruction<TProgram, TAccountMetas>;
12256
12256
 
12257
12257
  type RpcApi = Rpc<GetLatestBlockhashApi & SendTransactionApi & GetAccountInfoApi & SimulateTransactionApi & GetFeeForMessageApi & GetProgramAccountsApi>;
12258
+ type ExtendedRpcApi = RpcApi & Rpc<GetEpochInfoApi & GetSignatureStatusesApi>;
12259
+ type RpcSubscriptionApi = RpcSubscriptions<SignatureNotificationsApi & SlotNotificationsApi>;
12258
12260
  type Commitment = 'processed' | 'confirmed' | 'finalized';
12259
12261
 
12260
12262
  interface GhostSpeakConfig$1 {
12261
12263
  programId?: Address$1;
12262
- rpc: RpcApi;
12263
- rpcSubscriptions?: RpcSubscriptions<any>;
12264
+ rpc: ExtendedRpcApi;
12265
+ rpcSubscriptions?: RpcSubscriptionApi;
12264
12266
  commitment?: Commitment;
12265
12267
  transactionTimeout?: number;
12266
12268
  defaultFeePayer?: Address$1;
@@ -12306,11 +12308,11 @@ declare abstract class BaseInstructions {
12306
12308
  /**
12307
12309
  * Get the RPC client
12308
12310
  */
12309
- protected get rpc(): Rpc<GetLatestBlockhashApi & SendTransactionApi & GetAccountInfoApi & SimulateTransactionApi & GetFeeForMessageApi & GetProgramAccountsApi & GetEpochInfoApi & GetSignatureStatusesApi>;
12311
+ protected get rpc(): ExtendedRpcApi;
12310
12312
  /**
12311
12313
  * Get the RPC subscriptions client
12312
12314
  */
12313
- protected get rpcSubscriptions(): RpcSubscriptions<SignatureNotificationsApi & SlotNotificationsApi> | undefined;
12315
+ protected get rpcSubscriptions(): RpcSubscriptionApi | undefined;
12314
12316
  /**
12315
12317
  * Get the program ID
12316
12318
  */
@@ -13888,7 +13890,7 @@ declare class GhostSpeakClient$1 {
13888
13890
  /**
13889
13891
  * Create a new GhostSpeak client instance
13890
13892
  */
13891
- static create(rpc: RpcApi, programId?: Address$1): GhostSpeakClient$1;
13893
+ static create(rpc: ExtendedRpcApi, programId?: Address$1): GhostSpeakClient$1;
13892
13894
  /**
13893
13895
  * Register a new AI agent
13894
13896
  */
package/dist/index.js CHANGED
@@ -21602,10 +21602,6 @@ var BaseInstructions = class {
21602
21602
  */
21603
21603
  async sendTransactionWithDetails(instructions, signers) {
21604
21604
  try {
21605
- console.log(`\u{1F4E4} Sending REAL transaction with ${instructions.length} instructions`);
21606
- console.log(`\u{1F510} Using ${signers.length} signers`);
21607
- console.log(`\u{1F4CD} Program ID: ${this.programId}`);
21608
- console.log(`\u{1F310} Commitment: ${this.commitment}`);
21609
21605
  for (let i = 0; i < instructions.length; i++) {
21610
21606
  const instruction = instructions[i];
21611
21607
  if (!instruction) {
@@ -21620,48 +21616,57 @@ var BaseInstructions = class {
21620
21616
  if (!Array.isArray(instruction.accounts)) {
21621
21617
  throw new Error(`Instruction at index ${i} accounts is not an array`);
21622
21618
  }
21623
- console.log(`\u2705 Instruction ${i}: ${instruction.accounts.length} accounts, program: ${instruction.programAddress}`);
21624
21619
  }
21625
- console.log("\u{1F517} Fetching latest blockhash...");
21626
21620
  const { value: latestBlockhash } = await this.rpc.getLatestBlockhash().send();
21627
- console.log(`\u2705 Got blockhash: ${latestBlockhash.blockhash}`);
21628
- console.log("\u{1F3D7}\uFE0F Building transaction message...");
21629
21621
  const transactionMessage = await pipe(
21630
21622
  createTransactionMessage({ version: 0 }),
21631
21623
  (tx) => setTransactionMessageFeePayerSigner(signers[0], tx),
21632
21624
  (tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
21633
21625
  (tx) => appendTransactionMessageInstructions(instructions, tx)
21634
21626
  );
21635
- console.log("\u2705 Transaction message built");
21636
- console.log("\u270D\uFE0F Signing transaction...");
21637
21627
  const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);
21638
- console.log("\u2705 Transaction signed");
21639
- console.log("\u{1F4E1} Sending transaction to blockchain...");
21640
21628
  let result;
21641
21629
  let signature;
21642
21630
  if (!this.rpcSubscriptions) {
21643
- console.log("\u26A0\uFE0F No RPC subscriptions available, using polling for confirmation...");
21644
21631
  const transactionSignature = await this.rpc.sendTransaction(signedTransaction, {
21645
21632
  skipPreflight: false,
21646
21633
  preflightCommitment: this.commitment
21647
21634
  }).send();
21648
- console.log(`\u{1F4E4} Transaction sent: ${transactionSignature}`);
21649
21635
  let confirmed = false;
21650
21636
  let attempts = 0;
21651
21637
  const maxAttempts = 30;
21638
+ const baseDelay = 1e3;
21639
+ let currentDelay = baseDelay;
21652
21640
  while (!confirmed && attempts < maxAttempts) {
21653
- const status = await this.rpc.getSignatureStatuses([transactionSignature]).send();
21654
- if (status.value[0] && status.value[0].confirmationStatus === this.commitment) {
21655
- confirmed = true;
21656
- console.log("\u2705 Transaction confirmed!");
21657
- } else {
21641
+ try {
21642
+ const status = await this.rpc.getSignatureStatuses([transactionSignature]).send();
21643
+ if (status.value[0]) {
21644
+ const confirmationStatus = status.value[0].confirmationStatus;
21645
+ const err = status.value[0].err;
21646
+ if (err) {
21647
+ throw new Error(`Transaction failed: ${JSON.stringify(err)}`);
21648
+ }
21649
+ if (confirmationStatus === this.commitment || this.commitment === "confirmed" && confirmationStatus === "finalized") {
21650
+ confirmed = true;
21651
+ console.log("\u2705 Transaction confirmed!");
21652
+ break;
21653
+ }
21654
+ }
21658
21655
  attempts++;
21659
21656
  console.log(`\u23F3 Waiting for confirmation... (${attempts}/${maxAttempts})`);
21660
- await new Promise((resolve) => setTimeout(resolve, 1e3));
21657
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
21658
+ currentDelay = Math.min(currentDelay * 1.5, 5e3);
21659
+ } catch (statusError) {
21660
+ if (statusError.message?.includes("Transaction failed")) {
21661
+ throw statusError;
21662
+ }
21663
+ attempts++;
21664
+ console.warn(`\u26A0\uFE0F Status check failed (${attempts}/${maxAttempts}): ${statusError.message}`);
21665
+ await new Promise((resolve) => setTimeout(resolve, currentDelay * 2));
21661
21666
  }
21662
21667
  }
21663
21668
  if (!confirmed) {
21664
- throw new Error("Transaction confirmation timeout");
21669
+ throw new Error(`Transaction confirmation timeout after ${maxAttempts} attempts. Signature: ${transactionSignature}`);
21665
21670
  }
21666
21671
  signature = transactionSignature;
21667
21672
  } else {
@@ -21670,7 +21675,18 @@ var BaseInstructions = class {
21670
21675
  commitment: this.commitment,
21671
21676
  skipPreflight: false
21672
21677
  });
21673
- signature = result?.signature || Object.values(signedTransaction.signatures || {})[0] || "unknown_signature";
21678
+ if (result && typeof result === "object" && "signature" in result) {
21679
+ signature = result.signature;
21680
+ } else if (signedTransaction.signatures && typeof signedTransaction.signatures === "object") {
21681
+ const signatures = Object.values(signedTransaction.signatures);
21682
+ if (signatures.length > 0 && typeof signatures[0] === "string") {
21683
+ signature = signatures[0];
21684
+ } else {
21685
+ throw new Error("Unable to extract transaction signature");
21686
+ }
21687
+ } else {
21688
+ throw new Error("Transaction result missing signature");
21689
+ }
21674
21690
  }
21675
21691
  const cluster = this.config.cluster || (this.config.rpcEndpoint ? detectClusterFromEndpoint(this.config.rpcEndpoint) : "devnet");
21676
21692
  const transactionResult = createTransactionResult(
@@ -21814,7 +21830,7 @@ var AgentInstructions = class extends BaseInstructions {
21814
21830
  const signature = await this.sendTransaction([instruction], [signer]);
21815
21831
  return signature;
21816
21832
  } catch (error) {
21817
- console.error("\u274C Failed to create register instruction:", error);
21833
+ console.error("\u274C Failed to register agent:", error);
21818
21834
  throw error;
21819
21835
  }
21820
21836
  }