@usepraxis/sdk 0.1.0 → 0.2.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/LICENSE +21 -0
- package/README.md +14 -2
- package/dist/index.cjs +89 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +86 -12
- package/dist/index.d.ts +86 -12
- package/dist/index.js +89 -19
- package/dist/index.js.map +1 -1
- package/package.json +17 -4
package/dist/index.d.cts
CHANGED
|
@@ -64,7 +64,10 @@ interface WalletChallenge {
|
|
|
64
64
|
}
|
|
65
65
|
interface SessionInfo {
|
|
66
66
|
authenticated: boolean;
|
|
67
|
+
/** The signed-in wallet (owner). Present whenever `authenticated` is true. */
|
|
67
68
|
walletAddress: Address;
|
|
69
|
+
/** Unix seconds at which the session expires (from `GET /auth/session`). */
|
|
70
|
+
expiresAt?: number;
|
|
68
71
|
}
|
|
69
72
|
interface TokenInfo {
|
|
70
73
|
symbol: string;
|
|
@@ -164,6 +167,11 @@ interface ResearchData {
|
|
|
164
167
|
metrics: ResearchMetric[];
|
|
165
168
|
summary: string;
|
|
166
169
|
}
|
|
170
|
+
interface PolicyChangeRow {
|
|
171
|
+
label: string;
|
|
172
|
+
from: string;
|
|
173
|
+
to: string;
|
|
174
|
+
}
|
|
167
175
|
type AgentBlock = {
|
|
168
176
|
type: "prose";
|
|
169
177
|
text: string;
|
|
@@ -179,6 +187,16 @@ type AgentBlock = {
|
|
|
179
187
|
type: "research";
|
|
180
188
|
text: string;
|
|
181
189
|
data: ResearchData;
|
|
190
|
+
} | {
|
|
191
|
+
type: "notice";
|
|
192
|
+
tone: "success" | "info";
|
|
193
|
+
text: string;
|
|
194
|
+
} | {
|
|
195
|
+
type: "policy_change";
|
|
196
|
+
text: string;
|
|
197
|
+
patch: PolicyUpdate;
|
|
198
|
+
changes: PolicyChangeRow[];
|
|
199
|
+
applied: boolean;
|
|
182
200
|
};
|
|
183
201
|
type UserMessage = {
|
|
184
202
|
id: string;
|
|
@@ -218,6 +236,14 @@ interface UnsignedOwnerTransaction {
|
|
|
218
236
|
blockhash: string;
|
|
219
237
|
lastValidBlockHeight: number;
|
|
220
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* An {@link UnsignedOwnerTransaction} after the owner wallet has signed it — the
|
|
241
|
+
* base64 `transaction` now carries the owner's signature. This is what you pass
|
|
242
|
+
* to {@link PraxisClient.submitOwnerTransaction}. Signing a Solana transaction
|
|
243
|
+
* requires a transaction-capable wallet (browser wallet adapter / `@solana/web3.js`);
|
|
244
|
+
* the SDK's `keypairSigner` only signs the sign-in *message*, not transactions.
|
|
245
|
+
*/
|
|
246
|
+
type SignedOwnerTransaction = UnsignedOwnerTransaction;
|
|
221
247
|
/** Typed owner action accepted by `POST /owner/build`. */
|
|
222
248
|
type OwnerAction = {
|
|
223
249
|
kind: "bootstrapPolicy";
|
|
@@ -252,8 +278,14 @@ interface PraxisClientOptions {
|
|
|
252
278
|
signer?: PraxisSigner;
|
|
253
279
|
/** Custom fetch (defaults to global fetch). Required in runtimes without one. */
|
|
254
280
|
fetch?: FetchLike;
|
|
255
|
-
/** Per-request timeout in ms (default 20_000). */
|
|
281
|
+
/** Per-request timeout in ms for reads/mutations (default 20_000). */
|
|
256
282
|
timeoutMs?: number;
|
|
283
|
+
/**
|
|
284
|
+
* Per-request timeout in ms for agent conversation turns (`send`/`ask`), which
|
|
285
|
+
* block on the full LLM round-trip (default 60_000). Effective value is never
|
|
286
|
+
* below `timeoutMs`.
|
|
287
|
+
*/
|
|
288
|
+
agentTimeoutMs?: number;
|
|
257
289
|
}
|
|
258
290
|
/** Result of {@link PraxisClient.ask} — the agent's reply, distilled. */
|
|
259
291
|
interface AskResult {
|
|
@@ -280,6 +312,7 @@ declare class PraxisClient {
|
|
|
280
312
|
private readonly signer?;
|
|
281
313
|
private readonly fetchImpl;
|
|
282
314
|
private readonly timeoutMs;
|
|
315
|
+
private readonly agentTimeoutMs;
|
|
283
316
|
/** Manual cookie jar — Node's fetch does not persist Set-Cookie across calls. */
|
|
284
317
|
private sessionCookie?;
|
|
285
318
|
constructor(options: PraxisClientOptions);
|
|
@@ -287,12 +320,20 @@ declare class PraxisClient {
|
|
|
287
320
|
get address(): string | undefined;
|
|
288
321
|
/**
|
|
289
322
|
* Run the wallet-ownership handshake: request a challenge, sign its message,
|
|
290
|
-
* verify it, and store the resulting session cookie.
|
|
323
|
+
* verify it, and store the resulting session cookie. Safe to call again to
|
|
324
|
+
* refresh the session (each call issues a new challenge + cookie).
|
|
291
325
|
*/
|
|
292
326
|
connect(): Promise<SessionInfo>;
|
|
293
|
-
/**
|
|
327
|
+
/**
|
|
328
|
+
* Current session, or `null` if not signed in. The endpoint answers `200`
|
|
329
|
+
* with `{ authenticated: false }` when signed out, so this normalizes both
|
|
330
|
+
* that shape and a `401` to `null`.
|
|
331
|
+
*/
|
|
294
332
|
session(): Promise<SessionInfo | null>;
|
|
295
|
-
/**
|
|
333
|
+
/**
|
|
334
|
+
* Clear the session (server-side cookie + local jar). Idempotent: if there is
|
|
335
|
+
* no active session, the local jar is still cleared and no error is thrown.
|
|
336
|
+
*/
|
|
296
337
|
logout(): Promise<void>;
|
|
297
338
|
/** Send a line to the agent. Creates a thread when `threadId` is omitted. */
|
|
298
339
|
send(text: string, threadId?: string | null): Promise<{
|
|
@@ -317,6 +358,12 @@ declare class PraxisClient {
|
|
|
317
358
|
isThinking(threadId: string): Promise<boolean>;
|
|
318
359
|
getVersion(): Promise<number>;
|
|
319
360
|
bootstrapPolicy(fundLamports?: BaseUnitString): Promise<void>;
|
|
361
|
+
/** Deposit SOL (lamports, base-unit string) from the owner into the vault. */
|
|
362
|
+
fundVault(amount: BaseUnitString): Promise<void>;
|
|
363
|
+
/** Withdraw SOL (lamports, base-unit string) from the vault to the owner. */
|
|
364
|
+
withdrawVault(amount: BaseUnitString): Promise<void>;
|
|
365
|
+
/** Tear the agent down — drain the vault and close the policy. Irreversible. */
|
|
366
|
+
deleteAgent(): Promise<void>;
|
|
320
367
|
updatePolicy(patch: PolicyUpdate): Promise<void>;
|
|
321
368
|
configureToken(config: TokenEnvelopeConfig): Promise<void>;
|
|
322
369
|
prepareTokenAccounts(recipientAddresses?: string[]): Promise<void>;
|
|
@@ -324,10 +371,15 @@ declare class PraxisClient {
|
|
|
324
371
|
rotateAgent(): Promise<void>;
|
|
325
372
|
addToAllowList(kind: AllowListKind, address: string): Promise<void>;
|
|
326
373
|
removeFromAllowList(kind: AllowListKind, address: string): Promise<void>;
|
|
327
|
-
/**
|
|
374
|
+
/**
|
|
375
|
+
* Build an unsigned owner transaction for the wallet to sign. The caller signs
|
|
376
|
+
* the returned base64 `transaction` with a transaction-capable wallet, then
|
|
377
|
+
* passes the result to {@link submitOwnerTransaction}. (The SDK's
|
|
378
|
+
* `keypairSigner` signs sign-in messages only, not transactions.)
|
|
379
|
+
*/
|
|
328
380
|
buildOwnerTransaction(action: OwnerAction): Promise<UnsignedOwnerTransaction>;
|
|
329
|
-
/** Submit a wallet-signed owner transaction. */
|
|
330
|
-
submitOwnerTransaction(signed:
|
|
381
|
+
/** Submit a wallet-signed owner transaction; resolves with its signature. */
|
|
382
|
+
submitOwnerTransaction(signed: SignedOwnerTransaction): Promise<{
|
|
331
383
|
sig: string;
|
|
332
384
|
}>;
|
|
333
385
|
private get;
|
|
@@ -345,14 +397,28 @@ declare class PraxisApiError extends Error {
|
|
|
345
397
|
readonly status: number;
|
|
346
398
|
/** The backend error class name, e.g. "PraxisAuthError", "PraxisRateLimitError". */
|
|
347
399
|
readonly type: string;
|
|
348
|
-
constructor(status: number, type: string, message: string
|
|
400
|
+
constructor(status: number, type: string, message: string, options?: {
|
|
401
|
+
cause?: unknown;
|
|
402
|
+
});
|
|
349
403
|
get isAuth(): boolean;
|
|
350
404
|
get isRateLimited(): boolean;
|
|
351
405
|
get isInput(): boolean;
|
|
406
|
+
/** Resource not found (404). */
|
|
407
|
+
get isNotFound(): boolean;
|
|
408
|
+
/** Server reported a configuration problem (503) — usually transient. */
|
|
409
|
+
get isConfig(): boolean;
|
|
410
|
+
/** The request timed out client-side before any HTTP response. */
|
|
411
|
+
get isTimeout(): boolean;
|
|
412
|
+
/** A connection-level failure (DNS, refused, TLS) before any HTTP response. */
|
|
413
|
+
get isNetwork(): boolean;
|
|
414
|
+
/** Any server-side failure (HTTP >= 500). */
|
|
415
|
+
get isServer(): boolean;
|
|
352
416
|
}
|
|
353
417
|
/** Thrown for SDK-side misconfiguration (no fetch, no signer, bad key, …). */
|
|
354
418
|
declare class PraxisConfigError extends Error {
|
|
355
|
-
constructor(message: string
|
|
419
|
+
constructor(message: string, options?: {
|
|
420
|
+
cause?: unknown;
|
|
421
|
+
});
|
|
356
422
|
}
|
|
357
423
|
|
|
358
424
|
/**
|
|
@@ -360,13 +426,21 @@ declare class PraxisConfigError extends Error {
|
|
|
360
426
|
* base units (lamports / token base units). These convert to/from `bigint` and
|
|
361
427
|
* human decimal amounts without floats.
|
|
362
428
|
*/
|
|
363
|
-
/**
|
|
429
|
+
/**
|
|
430
|
+
* Parse a base-unit string (or bigint) into a bigint. Rejects floats, hex, and
|
|
431
|
+
* other non-decimal-integer input so the SDK and server agree on what a valid
|
|
432
|
+
* base-unit string is (mirrors the server's `parseUnits`).
|
|
433
|
+
*/
|
|
364
434
|
declare function toBaseUnits(value: string | bigint): bigint;
|
|
365
|
-
/**
|
|
435
|
+
/**
|
|
436
|
+
* Serialize a bigint (or a whole, safe-integer number of base units) into a
|
|
437
|
+
* base-unit string. A non-integer or unsafe `number` throws rather than
|
|
438
|
+
* silently losing precision.
|
|
439
|
+
*/
|
|
366
440
|
declare function fromBaseUnits(value: bigint | number): string;
|
|
367
441
|
/** Convert a human decimal amount ("0.5") into base units for `decimals` places. */
|
|
368
442
|
declare function humanToBaseUnits(amount: string, decimals: number): string;
|
|
369
443
|
/** Convert base units into a human decimal string for `decimals` places. */
|
|
370
444
|
declare function baseUnitsToHuman(value: string | bigint, decimals: number): string;
|
|
371
445
|
|
|
372
|
-
export { ActionKind, type ActionProposal, type ActivityEntry, type Address, type AddressBookEntry, type AgentBlock, type AgentMessage, type AllowListKind, type AskResult, type BaseUnitString, type ClarifyOption, type FetchLike, type Message, type OwnerAction, type PolicyCheckResult, type PolicyUpdate, type PolicyView, PraxisApiError, PraxisClient, type PraxisClientOptions, PraxisConfigError, type PraxisSigner, type ProposalDetail, type ProposalState, RejectReason, type ResearchData, type ResearchMetric, type SecretKeyInput, type SessionInfo, type SwapDetail, type Thread, type TokenEnvelopeConfig, type TokenInfo, type TransferDetail, type UnsignedOwnerTransaction, type UserMessage, type WalletChallenge, baseUnitsToHuman, fromBaseUnits, humanToBaseUnits, keypairSigner, toBaseUnits };
|
|
446
|
+
export { ActionKind, type ActionProposal, type ActivityEntry, type Address, type AddressBookEntry, type AgentBlock, type AgentMessage, type AllowListKind, type AskResult, type BaseUnitString, type ClarifyOption, type FetchLike, type Message, type OwnerAction, type PolicyChangeRow, type PolicyCheckResult, type PolicyUpdate, type PolicyView, PraxisApiError, PraxisClient, type PraxisClientOptions, PraxisConfigError, type PraxisSigner, type ProposalDetail, type ProposalState, RejectReason, type ResearchData, type ResearchMetric, type SecretKeyInput, type SessionInfo, type SignedOwnerTransaction, type SwapDetail, type Thread, type TokenEnvelopeConfig, type TokenInfo, type TransferDetail, type UnsignedOwnerTransaction, type UserMessage, type WalletChallenge, baseUnitsToHuman, fromBaseUnits, humanToBaseUnits, keypairSigner, toBaseUnits };
|
package/dist/index.d.ts
CHANGED
|
@@ -64,7 +64,10 @@ interface WalletChallenge {
|
|
|
64
64
|
}
|
|
65
65
|
interface SessionInfo {
|
|
66
66
|
authenticated: boolean;
|
|
67
|
+
/** The signed-in wallet (owner). Present whenever `authenticated` is true. */
|
|
67
68
|
walletAddress: Address;
|
|
69
|
+
/** Unix seconds at which the session expires (from `GET /auth/session`). */
|
|
70
|
+
expiresAt?: number;
|
|
68
71
|
}
|
|
69
72
|
interface TokenInfo {
|
|
70
73
|
symbol: string;
|
|
@@ -164,6 +167,11 @@ interface ResearchData {
|
|
|
164
167
|
metrics: ResearchMetric[];
|
|
165
168
|
summary: string;
|
|
166
169
|
}
|
|
170
|
+
interface PolicyChangeRow {
|
|
171
|
+
label: string;
|
|
172
|
+
from: string;
|
|
173
|
+
to: string;
|
|
174
|
+
}
|
|
167
175
|
type AgentBlock = {
|
|
168
176
|
type: "prose";
|
|
169
177
|
text: string;
|
|
@@ -179,6 +187,16 @@ type AgentBlock = {
|
|
|
179
187
|
type: "research";
|
|
180
188
|
text: string;
|
|
181
189
|
data: ResearchData;
|
|
190
|
+
} | {
|
|
191
|
+
type: "notice";
|
|
192
|
+
tone: "success" | "info";
|
|
193
|
+
text: string;
|
|
194
|
+
} | {
|
|
195
|
+
type: "policy_change";
|
|
196
|
+
text: string;
|
|
197
|
+
patch: PolicyUpdate;
|
|
198
|
+
changes: PolicyChangeRow[];
|
|
199
|
+
applied: boolean;
|
|
182
200
|
};
|
|
183
201
|
type UserMessage = {
|
|
184
202
|
id: string;
|
|
@@ -218,6 +236,14 @@ interface UnsignedOwnerTransaction {
|
|
|
218
236
|
blockhash: string;
|
|
219
237
|
lastValidBlockHeight: number;
|
|
220
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* An {@link UnsignedOwnerTransaction} after the owner wallet has signed it — the
|
|
241
|
+
* base64 `transaction` now carries the owner's signature. This is what you pass
|
|
242
|
+
* to {@link PraxisClient.submitOwnerTransaction}. Signing a Solana transaction
|
|
243
|
+
* requires a transaction-capable wallet (browser wallet adapter / `@solana/web3.js`);
|
|
244
|
+
* the SDK's `keypairSigner` only signs the sign-in *message*, not transactions.
|
|
245
|
+
*/
|
|
246
|
+
type SignedOwnerTransaction = UnsignedOwnerTransaction;
|
|
221
247
|
/** Typed owner action accepted by `POST /owner/build`. */
|
|
222
248
|
type OwnerAction = {
|
|
223
249
|
kind: "bootstrapPolicy";
|
|
@@ -252,8 +278,14 @@ interface PraxisClientOptions {
|
|
|
252
278
|
signer?: PraxisSigner;
|
|
253
279
|
/** Custom fetch (defaults to global fetch). Required in runtimes without one. */
|
|
254
280
|
fetch?: FetchLike;
|
|
255
|
-
/** Per-request timeout in ms (default 20_000). */
|
|
281
|
+
/** Per-request timeout in ms for reads/mutations (default 20_000). */
|
|
256
282
|
timeoutMs?: number;
|
|
283
|
+
/**
|
|
284
|
+
* Per-request timeout in ms for agent conversation turns (`send`/`ask`), which
|
|
285
|
+
* block on the full LLM round-trip (default 60_000). Effective value is never
|
|
286
|
+
* below `timeoutMs`.
|
|
287
|
+
*/
|
|
288
|
+
agentTimeoutMs?: number;
|
|
257
289
|
}
|
|
258
290
|
/** Result of {@link PraxisClient.ask} — the agent's reply, distilled. */
|
|
259
291
|
interface AskResult {
|
|
@@ -280,6 +312,7 @@ declare class PraxisClient {
|
|
|
280
312
|
private readonly signer?;
|
|
281
313
|
private readonly fetchImpl;
|
|
282
314
|
private readonly timeoutMs;
|
|
315
|
+
private readonly agentTimeoutMs;
|
|
283
316
|
/** Manual cookie jar — Node's fetch does not persist Set-Cookie across calls. */
|
|
284
317
|
private sessionCookie?;
|
|
285
318
|
constructor(options: PraxisClientOptions);
|
|
@@ -287,12 +320,20 @@ declare class PraxisClient {
|
|
|
287
320
|
get address(): string | undefined;
|
|
288
321
|
/**
|
|
289
322
|
* Run the wallet-ownership handshake: request a challenge, sign its message,
|
|
290
|
-
* verify it, and store the resulting session cookie.
|
|
323
|
+
* verify it, and store the resulting session cookie. Safe to call again to
|
|
324
|
+
* refresh the session (each call issues a new challenge + cookie).
|
|
291
325
|
*/
|
|
292
326
|
connect(): Promise<SessionInfo>;
|
|
293
|
-
/**
|
|
327
|
+
/**
|
|
328
|
+
* Current session, or `null` if not signed in. The endpoint answers `200`
|
|
329
|
+
* with `{ authenticated: false }` when signed out, so this normalizes both
|
|
330
|
+
* that shape and a `401` to `null`.
|
|
331
|
+
*/
|
|
294
332
|
session(): Promise<SessionInfo | null>;
|
|
295
|
-
/**
|
|
333
|
+
/**
|
|
334
|
+
* Clear the session (server-side cookie + local jar). Idempotent: if there is
|
|
335
|
+
* no active session, the local jar is still cleared and no error is thrown.
|
|
336
|
+
*/
|
|
296
337
|
logout(): Promise<void>;
|
|
297
338
|
/** Send a line to the agent. Creates a thread when `threadId` is omitted. */
|
|
298
339
|
send(text: string, threadId?: string | null): Promise<{
|
|
@@ -317,6 +358,12 @@ declare class PraxisClient {
|
|
|
317
358
|
isThinking(threadId: string): Promise<boolean>;
|
|
318
359
|
getVersion(): Promise<number>;
|
|
319
360
|
bootstrapPolicy(fundLamports?: BaseUnitString): Promise<void>;
|
|
361
|
+
/** Deposit SOL (lamports, base-unit string) from the owner into the vault. */
|
|
362
|
+
fundVault(amount: BaseUnitString): Promise<void>;
|
|
363
|
+
/** Withdraw SOL (lamports, base-unit string) from the vault to the owner. */
|
|
364
|
+
withdrawVault(amount: BaseUnitString): Promise<void>;
|
|
365
|
+
/** Tear the agent down — drain the vault and close the policy. Irreversible. */
|
|
366
|
+
deleteAgent(): Promise<void>;
|
|
320
367
|
updatePolicy(patch: PolicyUpdate): Promise<void>;
|
|
321
368
|
configureToken(config: TokenEnvelopeConfig): Promise<void>;
|
|
322
369
|
prepareTokenAccounts(recipientAddresses?: string[]): Promise<void>;
|
|
@@ -324,10 +371,15 @@ declare class PraxisClient {
|
|
|
324
371
|
rotateAgent(): Promise<void>;
|
|
325
372
|
addToAllowList(kind: AllowListKind, address: string): Promise<void>;
|
|
326
373
|
removeFromAllowList(kind: AllowListKind, address: string): Promise<void>;
|
|
327
|
-
/**
|
|
374
|
+
/**
|
|
375
|
+
* Build an unsigned owner transaction for the wallet to sign. The caller signs
|
|
376
|
+
* the returned base64 `transaction` with a transaction-capable wallet, then
|
|
377
|
+
* passes the result to {@link submitOwnerTransaction}. (The SDK's
|
|
378
|
+
* `keypairSigner` signs sign-in messages only, not transactions.)
|
|
379
|
+
*/
|
|
328
380
|
buildOwnerTransaction(action: OwnerAction): Promise<UnsignedOwnerTransaction>;
|
|
329
|
-
/** Submit a wallet-signed owner transaction. */
|
|
330
|
-
submitOwnerTransaction(signed:
|
|
381
|
+
/** Submit a wallet-signed owner transaction; resolves with its signature. */
|
|
382
|
+
submitOwnerTransaction(signed: SignedOwnerTransaction): Promise<{
|
|
331
383
|
sig: string;
|
|
332
384
|
}>;
|
|
333
385
|
private get;
|
|
@@ -345,14 +397,28 @@ declare class PraxisApiError extends Error {
|
|
|
345
397
|
readonly status: number;
|
|
346
398
|
/** The backend error class name, e.g. "PraxisAuthError", "PraxisRateLimitError". */
|
|
347
399
|
readonly type: string;
|
|
348
|
-
constructor(status: number, type: string, message: string
|
|
400
|
+
constructor(status: number, type: string, message: string, options?: {
|
|
401
|
+
cause?: unknown;
|
|
402
|
+
});
|
|
349
403
|
get isAuth(): boolean;
|
|
350
404
|
get isRateLimited(): boolean;
|
|
351
405
|
get isInput(): boolean;
|
|
406
|
+
/** Resource not found (404). */
|
|
407
|
+
get isNotFound(): boolean;
|
|
408
|
+
/** Server reported a configuration problem (503) — usually transient. */
|
|
409
|
+
get isConfig(): boolean;
|
|
410
|
+
/** The request timed out client-side before any HTTP response. */
|
|
411
|
+
get isTimeout(): boolean;
|
|
412
|
+
/** A connection-level failure (DNS, refused, TLS) before any HTTP response. */
|
|
413
|
+
get isNetwork(): boolean;
|
|
414
|
+
/** Any server-side failure (HTTP >= 500). */
|
|
415
|
+
get isServer(): boolean;
|
|
352
416
|
}
|
|
353
417
|
/** Thrown for SDK-side misconfiguration (no fetch, no signer, bad key, …). */
|
|
354
418
|
declare class PraxisConfigError extends Error {
|
|
355
|
-
constructor(message: string
|
|
419
|
+
constructor(message: string, options?: {
|
|
420
|
+
cause?: unknown;
|
|
421
|
+
});
|
|
356
422
|
}
|
|
357
423
|
|
|
358
424
|
/**
|
|
@@ -360,13 +426,21 @@ declare class PraxisConfigError extends Error {
|
|
|
360
426
|
* base units (lamports / token base units). These convert to/from `bigint` and
|
|
361
427
|
* human decimal amounts without floats.
|
|
362
428
|
*/
|
|
363
|
-
/**
|
|
429
|
+
/**
|
|
430
|
+
* Parse a base-unit string (or bigint) into a bigint. Rejects floats, hex, and
|
|
431
|
+
* other non-decimal-integer input so the SDK and server agree on what a valid
|
|
432
|
+
* base-unit string is (mirrors the server's `parseUnits`).
|
|
433
|
+
*/
|
|
364
434
|
declare function toBaseUnits(value: string | bigint): bigint;
|
|
365
|
-
/**
|
|
435
|
+
/**
|
|
436
|
+
* Serialize a bigint (or a whole, safe-integer number of base units) into a
|
|
437
|
+
* base-unit string. A non-integer or unsafe `number` throws rather than
|
|
438
|
+
* silently losing precision.
|
|
439
|
+
*/
|
|
366
440
|
declare function fromBaseUnits(value: bigint | number): string;
|
|
367
441
|
/** Convert a human decimal amount ("0.5") into base units for `decimals` places. */
|
|
368
442
|
declare function humanToBaseUnits(amount: string, decimals: number): string;
|
|
369
443
|
/** Convert base units into a human decimal string for `decimals` places. */
|
|
370
444
|
declare function baseUnitsToHuman(value: string | bigint, decimals: number): string;
|
|
371
445
|
|
|
372
|
-
export { ActionKind, type ActionProposal, type ActivityEntry, type Address, type AddressBookEntry, type AgentBlock, type AgentMessage, type AllowListKind, type AskResult, type BaseUnitString, type ClarifyOption, type FetchLike, type Message, type OwnerAction, type PolicyCheckResult, type PolicyUpdate, type PolicyView, PraxisApiError, PraxisClient, type PraxisClientOptions, PraxisConfigError, type PraxisSigner, type ProposalDetail, type ProposalState, RejectReason, type ResearchData, type ResearchMetric, type SecretKeyInput, type SessionInfo, type SwapDetail, type Thread, type TokenEnvelopeConfig, type TokenInfo, type TransferDetail, type UnsignedOwnerTransaction, type UserMessage, type WalletChallenge, baseUnitsToHuman, fromBaseUnits, humanToBaseUnits, keypairSigner, toBaseUnits };
|
|
446
|
+
export { ActionKind, type ActionProposal, type ActivityEntry, type Address, type AddressBookEntry, type AgentBlock, type AgentMessage, type AllowListKind, type AskResult, type BaseUnitString, type ClarifyOption, type FetchLike, type Message, type OwnerAction, type PolicyChangeRow, type PolicyCheckResult, type PolicyUpdate, type PolicyView, PraxisApiError, PraxisClient, type PraxisClientOptions, PraxisConfigError, type PraxisSigner, type ProposalDetail, type ProposalState, RejectReason, type ResearchData, type ResearchMetric, type SecretKeyInput, type SessionInfo, type SignedOwnerTransaction, type SwapDetail, type Thread, type TokenEnvelopeConfig, type TokenInfo, type TransferDetail, type UnsignedOwnerTransaction, type UserMessage, type WalletChallenge, baseUnitsToHuman, fromBaseUnits, humanToBaseUnits, keypairSigner, toBaseUnits };
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,8 @@ var PraxisApiError = class _PraxisApiError extends Error {
|
|
|
8
8
|
status;
|
|
9
9
|
/** The backend error class name, e.g. "PraxisAuthError", "PraxisRateLimitError". */
|
|
10
10
|
type;
|
|
11
|
-
constructor(status, type, message) {
|
|
12
|
-
super(message);
|
|
11
|
+
constructor(status, type, message, options) {
|
|
12
|
+
super(message, options);
|
|
13
13
|
this.name = "PraxisApiError";
|
|
14
14
|
this.status = status;
|
|
15
15
|
this.type = type;
|
|
@@ -24,10 +24,30 @@ var PraxisApiError = class _PraxisApiError extends Error {
|
|
|
24
24
|
get isInput() {
|
|
25
25
|
return this.status === 400;
|
|
26
26
|
}
|
|
27
|
+
/** Resource not found (404). */
|
|
28
|
+
get isNotFound() {
|
|
29
|
+
return this.status === 404;
|
|
30
|
+
}
|
|
31
|
+
/** Server reported a configuration problem (503) — usually transient. */
|
|
32
|
+
get isConfig() {
|
|
33
|
+
return this.status === 503;
|
|
34
|
+
}
|
|
35
|
+
/** The request timed out client-side before any HTTP response. */
|
|
36
|
+
get isTimeout() {
|
|
37
|
+
return this.status === 0 && this.type === "TimeoutError";
|
|
38
|
+
}
|
|
39
|
+
/** A connection-level failure (DNS, refused, TLS) before any HTTP response. */
|
|
40
|
+
get isNetwork() {
|
|
41
|
+
return this.status === 0 && this.type === "NetworkError";
|
|
42
|
+
}
|
|
43
|
+
/** Any server-side failure (HTTP >= 500). */
|
|
44
|
+
get isServer() {
|
|
45
|
+
return this.status >= 500;
|
|
46
|
+
}
|
|
27
47
|
};
|
|
28
48
|
var PraxisConfigError = class _PraxisConfigError extends Error {
|
|
29
|
-
constructor(message) {
|
|
30
|
-
super(message);
|
|
49
|
+
constructor(message, options) {
|
|
50
|
+
super(message, options);
|
|
31
51
|
this.name = "PraxisConfigError";
|
|
32
52
|
Object.setPrototypeOf(this, _PraxisConfigError.prototype);
|
|
33
53
|
}
|
|
@@ -40,6 +60,7 @@ var PraxisClient = class {
|
|
|
40
60
|
signer;
|
|
41
61
|
fetchImpl;
|
|
42
62
|
timeoutMs;
|
|
63
|
+
agentTimeoutMs;
|
|
43
64
|
/** Manual cookie jar — Node's fetch does not persist Set-Cookie across calls. */
|
|
44
65
|
sessionCookie;
|
|
45
66
|
constructor(options) {
|
|
@@ -52,6 +73,7 @@ var PraxisClient = class {
|
|
|
52
73
|
}
|
|
53
74
|
this.fetchImpl = resolvedFetch;
|
|
54
75
|
this.timeoutMs = options.timeoutMs ?? 2e4;
|
|
76
|
+
this.agentTimeoutMs = Math.max(options.agentTimeoutMs ?? 6e4, this.timeoutMs);
|
|
55
77
|
}
|
|
56
78
|
// --- auth ----------------------------------------------------------------
|
|
57
79
|
/** The signer's wallet address, if a signer was provided. */
|
|
@@ -60,7 +82,8 @@ var PraxisClient = class {
|
|
|
60
82
|
}
|
|
61
83
|
/**
|
|
62
84
|
* Run the wallet-ownership handshake: request a challenge, sign its message,
|
|
63
|
-
* verify it, and store the resulting session cookie.
|
|
85
|
+
* verify it, and store the resulting session cookie. Safe to call again to
|
|
86
|
+
* refresh the session (each call issues a new challenge + cookie).
|
|
64
87
|
*/
|
|
65
88
|
async connect() {
|
|
66
89
|
if (!this.signer) {
|
|
@@ -76,24 +99,37 @@ var PraxisClient = class {
|
|
|
76
99
|
signature: bs582.encode(signature)
|
|
77
100
|
});
|
|
78
101
|
}
|
|
79
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Current session, or `null` if not signed in. The endpoint answers `200`
|
|
104
|
+
* with `{ authenticated: false }` when signed out, so this normalizes both
|
|
105
|
+
* that shape and a `401` to `null`.
|
|
106
|
+
*/
|
|
80
107
|
async session() {
|
|
81
108
|
try {
|
|
82
|
-
|
|
109
|
+
const info = await this.get("/auth/session");
|
|
110
|
+
return info && info.authenticated ? info : null;
|
|
83
111
|
} catch (error) {
|
|
84
112
|
if (error instanceof PraxisApiError && error.isAuth) return null;
|
|
85
113
|
throw error;
|
|
86
114
|
}
|
|
87
115
|
}
|
|
88
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* Clear the session (server-side cookie + local jar). Idempotent: if there is
|
|
118
|
+
* no active session, the local jar is still cleared and no error is thrown.
|
|
119
|
+
*/
|
|
89
120
|
async logout() {
|
|
90
|
-
|
|
91
|
-
|
|
121
|
+
try {
|
|
122
|
+
await this.request("DELETE", "/auth/session");
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (!(error instanceof PraxisApiError && error.isAuth)) throw error;
|
|
125
|
+
} finally {
|
|
126
|
+
this.sessionCookie = void 0;
|
|
127
|
+
}
|
|
92
128
|
}
|
|
93
129
|
// --- conversation --------------------------------------------------------
|
|
94
130
|
/** Send a line to the agent. Creates a thread when `threadId` is omitted. */
|
|
95
131
|
send(text, threadId = null) {
|
|
96
|
-
return this.post("/send", { text, threadId });
|
|
132
|
+
return this.post("/send", { text, threadId }, this.agentTimeoutMs);
|
|
97
133
|
}
|
|
98
134
|
/**
|
|
99
135
|
* Send a line and return the agent's reply in one call. The API resolves
|
|
@@ -148,6 +184,18 @@ var PraxisClient = class {
|
|
|
148
184
|
bootstrapPolicy(fundLamports) {
|
|
149
185
|
return this.post("/bootstrap-policy", fundLamports ? { fundLamports } : {});
|
|
150
186
|
}
|
|
187
|
+
/** Deposit SOL (lamports, base-unit string) from the owner into the vault. */
|
|
188
|
+
fundVault(amount) {
|
|
189
|
+
return this.post("/fund-vault", { amount });
|
|
190
|
+
}
|
|
191
|
+
/** Withdraw SOL (lamports, base-unit string) from the vault to the owner. */
|
|
192
|
+
withdrawVault(amount) {
|
|
193
|
+
return this.post("/withdraw-vault", { amount });
|
|
194
|
+
}
|
|
195
|
+
/** Tear the agent down — drain the vault and close the policy. Irreversible. */
|
|
196
|
+
deleteAgent() {
|
|
197
|
+
return this.post("/delete-agent", {});
|
|
198
|
+
}
|
|
151
199
|
updatePolicy(patch) {
|
|
152
200
|
return this.post("/update-policy", { patch });
|
|
153
201
|
}
|
|
@@ -170,11 +218,16 @@ var PraxisClient = class {
|
|
|
170
218
|
return this.post("/remove-from-allow-list", { kind, address });
|
|
171
219
|
}
|
|
172
220
|
// --- owner wallet-signed transaction path --------------------------------
|
|
173
|
-
/**
|
|
221
|
+
/**
|
|
222
|
+
* Build an unsigned owner transaction for the wallet to sign. The caller signs
|
|
223
|
+
* the returned base64 `transaction` with a transaction-capable wallet, then
|
|
224
|
+
* passes the result to {@link submitOwnerTransaction}. (The SDK's
|
|
225
|
+
* `keypairSigner` signs sign-in messages only, not transactions.)
|
|
226
|
+
*/
|
|
174
227
|
buildOwnerTransaction(action) {
|
|
175
228
|
return this.post("/owner/build", { action });
|
|
176
229
|
}
|
|
177
|
-
/** Submit a wallet-signed owner transaction. */
|
|
230
|
+
/** Submit a wallet-signed owner transaction; resolves with its signature. */
|
|
178
231
|
submitOwnerTransaction(signed) {
|
|
179
232
|
return this.post("/owner/submit", signed);
|
|
180
233
|
}
|
|
@@ -182,8 +235,8 @@ var PraxisClient = class {
|
|
|
182
235
|
get(path, query) {
|
|
183
236
|
return this.request("GET", path, { query });
|
|
184
237
|
}
|
|
185
|
-
post(path, body) {
|
|
186
|
-
return this.request("POST", path, { body });
|
|
238
|
+
post(path, body, timeoutMs) {
|
|
239
|
+
return this.request("POST", path, { body, timeoutMs });
|
|
187
240
|
}
|
|
188
241
|
async request(method, path, opts = {}) {
|
|
189
242
|
const url = new URL(this.baseUrl + API_PREFIX + path);
|
|
@@ -191,8 +244,9 @@ var PraxisClient = class {
|
|
|
191
244
|
const headers = { accept: "application/json" };
|
|
192
245
|
if (opts.body !== void 0) headers["content-type"] = "application/json";
|
|
193
246
|
if (this.sessionCookie) headers["cookie"] = this.sessionCookie;
|
|
247
|
+
const timeoutMs = opts.timeoutMs ?? this.timeoutMs;
|
|
194
248
|
const controller = new AbortController();
|
|
195
|
-
const timer = setTimeout(() => controller.abort(),
|
|
249
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
196
250
|
let res;
|
|
197
251
|
try {
|
|
198
252
|
res = await this.fetchImpl(url.toString(), {
|
|
@@ -205,9 +259,13 @@ var PraxisClient = class {
|
|
|
205
259
|
});
|
|
206
260
|
} catch (error) {
|
|
207
261
|
if (error instanceof Error && error.name === "AbortError") {
|
|
208
|
-
throw new PraxisApiError(0, "TimeoutError", `Praxis request timed out after ${
|
|
262
|
+
throw new PraxisApiError(0, "TimeoutError", `Praxis request timed out after ${timeoutMs}ms`, {
|
|
263
|
+
cause: error
|
|
264
|
+
});
|
|
209
265
|
}
|
|
210
|
-
throw error;
|
|
266
|
+
if (error instanceof PraxisApiError) throw error;
|
|
267
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
268
|
+
throw new PraxisApiError(0, "NetworkError", `Praxis request failed: ${detail}`, { cause: error });
|
|
211
269
|
} finally {
|
|
212
270
|
clearTimeout(timer);
|
|
213
271
|
}
|
|
@@ -269,6 +327,9 @@ function normalizeSecret(secret) {
|
|
|
269
327
|
throw new PraxisConfigError("secret key string must be base58-encoded");
|
|
270
328
|
}
|
|
271
329
|
} else if (Array.isArray(secret)) {
|
|
330
|
+
if (!secret.every((b) => Number.isInteger(b) && b >= 0 && b <= 255)) {
|
|
331
|
+
throw new PraxisConfigError("secret key array must contain only byte values (integers 0\u2013255)");
|
|
332
|
+
}
|
|
272
333
|
bytes = Uint8Array.from(secret);
|
|
273
334
|
} else {
|
|
274
335
|
bytes = secret;
|
|
@@ -282,10 +343,19 @@ function normalizeSecret(secret) {
|
|
|
282
343
|
}
|
|
283
344
|
|
|
284
345
|
// src/units.ts
|
|
346
|
+
var INTEGER_RE = /^-?\d+$/;
|
|
285
347
|
function toBaseUnits(value) {
|
|
286
|
-
|
|
348
|
+
if (typeof value === "bigint") return value;
|
|
349
|
+
const trimmed = value.trim();
|
|
350
|
+
if (!INTEGER_RE.test(trimmed)) {
|
|
351
|
+
throw new Error(`toBaseUnits: expected an integer base-unit string, got "${value}"`);
|
|
352
|
+
}
|
|
353
|
+
return BigInt(trimmed);
|
|
287
354
|
}
|
|
288
355
|
function fromBaseUnits(value) {
|
|
356
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
357
|
+
throw new Error(`fromBaseUnits: number must be a safe integer, got ${value}`);
|
|
358
|
+
}
|
|
289
359
|
return BigInt(value).toString();
|
|
290
360
|
}
|
|
291
361
|
function humanToBaseUnits(amount, decimals) {
|