Skip to content

Commit 05a163a

Browse files
Copilot0xrinegade
andcommitted
Align TypeScript SDK API semantics with Rust SDK
Co-authored-by: 0xrinegade <[email protected]>
1 parent edf2c5b commit 05a163a

File tree

6 files changed

+692
-11
lines changed

6 files changed

+692
-11
lines changed

sdk/typescript/src/agent.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,80 @@ export class AgentAPI {
227227
}
228228
}
229229

230+
/**
231+
* Update agent status (matches Rust SDK)
232+
*/
233+
async updateAgentStatus(agentId: string, status: AgentStatus): Promise<TransactionResult> {
234+
Validator.validateAgentId(agentId);
235+
236+
try {
237+
const program = this.client.getAgentRegistryProgram();
238+
const provider = this.client.getProvider();
239+
240+
// Derive PDA for agent account
241+
const [agentPda] = PublicKey.findProgramAddressSync(
242+
[
243+
Buffer.from(CONSTANTS.AGENT_REGISTRY_PDA_SEED),
244+
Buffer.from(agentId),
245+
provider.wallet.publicKey.toBuffer(),
246+
],
247+
program.programId
248+
);
249+
250+
const updateStatusInstruction = await program.methods
251+
.updateAgentStatus(status)
252+
.accounts({
253+
agentAccount: agentPda,
254+
owner: provider.wallet.publicKey,
255+
})
256+
.instruction();
257+
258+
const transaction = new Transaction().add(updateStatusInstruction);
259+
return await this.client.sendAndConfirmTransaction(transaction);
260+
} catch (error) {
261+
throw new RegistryError(
262+
`Failed to update agent status: ${error instanceof Error ? error.message : 'Unknown error'}`,
263+
undefined,
264+
undefined,
265+
error instanceof Error ? error : undefined
266+
);
267+
}
268+
}
269+
270+
/**
271+
* Get agent by ID (matches Rust SDK signature with explicit owner)
272+
*/
273+
async getAgentByOwner(owner: PublicKey, agentId: string): Promise<AgentRegistryEntry | null> {
274+
Validator.validateAgentId(agentId);
275+
276+
try {
277+
const program = this.client.getAgentRegistryProgram();
278+
279+
// Derive PDA for agent account
280+
const [agentPda] = PublicKey.findProgramAddressSync(
281+
[
282+
Buffer.from(CONSTANTS.AGENT_REGISTRY_PDA_SEED),
283+
Buffer.from(agentId),
284+
owner.toBuffer(),
285+
],
286+
program.programId
287+
);
288+
289+
try {
290+
const account = await (program.account as any).agentRegistryEntryV1.fetch(agentPda);
291+
return this.parseAgentAccount(account, agentPda);
292+
} catch (error) {
293+
// Return null if account not found (matches Rust SDK Option<T> pattern)
294+
return null;
295+
}
296+
} catch (error) {
297+
throw new AccountError(
298+
`Failed to get agent '${agentId}' for owner '${owner.toBase58()}': ${error instanceof Error ? error.message : 'Unknown error'}`,
299+
error instanceof Error ? error : undefined
300+
);
301+
}
302+
}
303+
230304
/**
231305
* Get agent by ID
232306
*/

0 commit comments

Comments
 (0)