@ghostspeak/sdk 1.4.2 → 1.5.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.
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
  */
@@ -12367,7 +12369,7 @@ declare class AgentInstructions extends BaseInstructions {
12367
12369
  /**
12368
12370
  * Register a new AI agent
12369
12371
  */
12370
- register(signer: KeyPairSigner, agentAddress: Address$1, userRegistryAddress: Address$1, params: AgentRegistrationParams): Promise<string>;
12372
+ register(signer: KeyPairSigner, params: AgentRegistrationParams): Promise<string>;
12371
12373
  /**
12372
12374
  * Update an existing agent
12373
12375
  */
@@ -13888,11 +13890,11 @@ 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
  */
13895
- registerAgent(signer: KeyPairSigner, agentAddress: Address$1, userRegistryAddress: Address$1, params: AgentRegistrationParams): Promise<string>;
13897
+ registerAgent(signer: KeyPairSigner, params: AgentRegistrationParams): Promise<string>;
13896
13898
  /**
13897
13899
  * Get agent account information
13898
13900
  */
package/dist/index.js CHANGED
@@ -21073,7 +21073,7 @@ async function deriveA2AMessagePda(programId, session, sessionCreatedAt) {
21073
21073
  });
21074
21074
  return address2;
21075
21075
  }
21076
- async function deriveUserRegistryPda(programId) {
21076
+ async function deriveUserRegistryPda(programId, signer) {
21077
21077
  const [address2] = await getProgramDerivedAddress({
21078
21078
  programAddress: programId,
21079
21079
  seeds: [
@@ -21091,8 +21091,9 @@ async function deriveUserRegistryPda(programId) {
21091
21091
  116,
21092
21092
  114,
21093
21093
  121
21094
- ]))
21094
+ ])),
21095
21095
  // 'user_registry'
21096
+ getAddressEncoder().encode(signer)
21096
21097
  ]
21097
21098
  });
21098
21099
  return address2;
@@ -21635,19 +21636,38 @@ var BaseInstructions = class {
21635
21636
  let confirmed = false;
21636
21637
  let attempts = 0;
21637
21638
  const maxAttempts = 30;
21639
+ const baseDelay = 1e3;
21640
+ let currentDelay = baseDelay;
21638
21641
  while (!confirmed && attempts < maxAttempts) {
21639
- const status = await this.rpc.getSignatureStatuses([transactionSignature]).send();
21640
- if (status.value[0] && status.value[0].confirmationStatus === this.commitment) {
21641
- confirmed = true;
21642
- console.log("\u2705 Transaction confirmed!");
21643
- } else {
21642
+ try {
21643
+ const status = await this.rpc.getSignatureStatuses([transactionSignature]).send();
21644
+ if (status.value[0]) {
21645
+ const confirmationStatus = status.value[0].confirmationStatus;
21646
+ const err = status.value[0].err;
21647
+ if (err) {
21648
+ throw new Error(`Transaction failed: ${JSON.stringify(err)}`);
21649
+ }
21650
+ if (confirmationStatus === this.commitment || this.commitment === "confirmed" && confirmationStatus === "finalized") {
21651
+ confirmed = true;
21652
+ console.log("\u2705 Transaction confirmed!");
21653
+ break;
21654
+ }
21655
+ }
21644
21656
  attempts++;
21645
21657
  console.log(`\u23F3 Waiting for confirmation... (${attempts}/${maxAttempts})`);
21646
- await new Promise((resolve) => setTimeout(resolve, 1e3));
21658
+ await new Promise((resolve) => setTimeout(resolve, currentDelay));
21659
+ currentDelay = Math.min(currentDelay * 1.5, 5e3);
21660
+ } catch (statusError) {
21661
+ if (statusError.message?.includes("Transaction failed")) {
21662
+ throw statusError;
21663
+ }
21664
+ attempts++;
21665
+ console.warn(`\u26A0\uFE0F Status check failed (${attempts}/${maxAttempts}): ${statusError.message}`);
21666
+ await new Promise((resolve) => setTimeout(resolve, currentDelay * 2));
21647
21667
  }
21648
21668
  }
21649
21669
  if (!confirmed) {
21650
- throw new Error("Transaction confirmation timeout");
21670
+ throw new Error(`Transaction confirmation timeout after ${maxAttempts} attempts. Signature: ${transactionSignature}`);
21651
21671
  }
21652
21672
  signature = transactionSignature;
21653
21673
  } else {
@@ -21656,7 +21676,18 @@ var BaseInstructions = class {
21656
21676
  commitment: this.commitment,
21657
21677
  skipPreflight: false
21658
21678
  });
21659
- signature = result?.signature || Object.values(signedTransaction.signatures || {})[0] || "unknown_signature";
21679
+ if (result && typeof result === "object" && "signature" in result) {
21680
+ signature = result.signature;
21681
+ } else if (signedTransaction.signatures && typeof signedTransaction.signatures === "object") {
21682
+ const signatures = Object.values(signedTransaction.signatures);
21683
+ if (signatures.length > 0 && typeof signatures[0] === "string") {
21684
+ signature = signatures[0];
21685
+ } else {
21686
+ throw new Error("Unable to extract transaction signature");
21687
+ }
21688
+ } else {
21689
+ throw new Error("Transaction result missing signature");
21690
+ }
21660
21691
  }
21661
21692
  const cluster = this.config.cluster || (this.config.rpcEndpoint ? detectClusterFromEndpoint(this.config.rpcEndpoint) : "devnet");
21662
21693
  const transactionResult = createTransactionResult(
@@ -21785,17 +21816,15 @@ var AgentInstructions = class extends BaseInstructions {
21785
21816
  /**
21786
21817
  * Register a new AI agent
21787
21818
  */
21788
- async register(signer, agentAddress, userRegistryAddress, params) {
21819
+ async register(signer, params) {
21789
21820
  const agentType = typeof params.agentType === "number" && !isNaN(params.agentType) ? params.agentType : 1;
21790
21821
  try {
21791
- const instruction = getRegisterAgentInstruction({
21792
- agentAccount: agentAddress,
21793
- userRegistry: userRegistryAddress,
21822
+ const instruction = await getRegisterAgentInstructionAsync({
21794
21823
  signer,
21795
21824
  agentType,
21796
21825
  metadataUri: params.metadataUri,
21797
21826
  agentId: params.agentId
21798
- });
21827
+ }, { programAddress: this.programId });
21799
21828
  this.logInstructionDetails(instruction);
21800
21829
  const signature = await this.sendTransaction([instruction], [signer]);
21801
21830
  return signature;
@@ -24973,8 +25002,8 @@ var GhostSpeakClient = class _GhostSpeakClient {
24973
25002
  /**
24974
25003
  * Register a new AI agent
24975
25004
  */
24976
- async registerAgent(signer, agentAddress, userRegistryAddress, params) {
24977
- return this.agent.register(signer, agentAddress, userRegistryAddress, params);
25005
+ async registerAgent(signer, params) {
25006
+ return this.agent.register(signer, params);
24978
25007
  }
24979
25008
  /**
24980
25009
  * Get agent account information