@deva-me/agent-sdk 0.2.0 → 0.4.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.
Files changed (78) hide show
  1. package/README.md +140 -19
  2. package/dist/cjs/agent.js +2 -0
  3. package/dist/cjs/agent.js.map +1 -1
  4. package/dist/cjs/auth.js +21 -3
  5. package/dist/cjs/auth.js.map +1 -1
  6. package/dist/cjs/client.js +131 -25
  7. package/dist/cjs/client.js.map +1 -1
  8. package/dist/cjs/deva-client.js +3 -0
  9. package/dist/cjs/deva-client.js.map +1 -1
  10. package/dist/cjs/errors.js +29 -1
  11. package/dist/cjs/errors.js.map +1 -1
  12. package/dist/cjs/resources/email.js +6 -3
  13. package/dist/cjs/resources/email.js.map +1 -1
  14. package/dist/cjs/resources/files.js +4 -10
  15. package/dist/cjs/resources/files.js.map +1 -1
  16. package/dist/cjs/resources/index.js +1 -0
  17. package/dist/cjs/resources/index.js.map +1 -1
  18. package/dist/cjs/resources/messaging.js +9 -3
  19. package/dist/cjs/resources/messaging.js.map +1 -1
  20. package/dist/cjs/resources/search.js +13 -9
  21. package/dist/cjs/resources/search.js.map +1 -1
  22. package/dist/cjs/resources/social.js +18 -24
  23. package/dist/cjs/resources/social.js.map +1 -1
  24. package/dist/cjs/resources/tools.js +168 -0
  25. package/dist/cjs/resources/tools.js.map +1 -0
  26. package/dist/cjs/resources/transcription.js +2 -6
  27. package/dist/cjs/resources/transcription.js.map +1 -1
  28. package/dist/cjs/resources/wallet.js +6 -13
  29. package/dist/cjs/resources/wallet.js.map +1 -1
  30. package/dist/cjs/x402.js +243 -16
  31. package/dist/cjs/x402.js.map +1 -1
  32. package/dist/esm/agent.js +2 -0
  33. package/dist/esm/agent.js.map +1 -1
  34. package/dist/esm/auth.js +21 -3
  35. package/dist/esm/auth.js.map +1 -1
  36. package/dist/esm/client.js +132 -26
  37. package/dist/esm/client.js.map +1 -1
  38. package/dist/esm/deva-client.js +3 -0
  39. package/dist/esm/deva-client.js.map +1 -1
  40. package/dist/esm/errors.js +26 -0
  41. package/dist/esm/errors.js.map +1 -1
  42. package/dist/esm/resources/email.js +6 -3
  43. package/dist/esm/resources/email.js.map +1 -1
  44. package/dist/esm/resources/files.js +4 -10
  45. package/dist/esm/resources/files.js.map +1 -1
  46. package/dist/esm/resources/index.js +1 -0
  47. package/dist/esm/resources/index.js.map +1 -1
  48. package/dist/esm/resources/messaging.js +9 -3
  49. package/dist/esm/resources/messaging.js.map +1 -1
  50. package/dist/esm/resources/search.js +13 -9
  51. package/dist/esm/resources/search.js.map +1 -1
  52. package/dist/esm/resources/social.js +18 -24
  53. package/dist/esm/resources/social.js.map +1 -1
  54. package/dist/esm/resources/tools.js +164 -0
  55. package/dist/esm/resources/tools.js.map +1 -0
  56. package/dist/esm/resources/transcription.js +2 -6
  57. package/dist/esm/resources/transcription.js.map +1 -1
  58. package/dist/esm/resources/wallet.js +6 -13
  59. package/dist/esm/resources/wallet.js.map +1 -1
  60. package/dist/esm/x402.js +234 -16
  61. package/dist/esm/x402.js.map +1 -1
  62. package/dist/types/agent.d.ts +1 -0
  63. package/dist/types/auth.d.ts +15 -2
  64. package/dist/types/client.d.ts +3 -0
  65. package/dist/types/deva-client.d.ts +2 -0
  66. package/dist/types/errors.d.ts +28 -0
  67. package/dist/types/resources/email.d.ts +8 -6
  68. package/dist/types/resources/files.d.ts +3 -5
  69. package/dist/types/resources/index.d.ts +1 -0
  70. package/dist/types/resources/messaging.d.ts +14 -4
  71. package/dist/types/resources/search.d.ts +27 -4
  72. package/dist/types/resources/social.d.ts +16 -15
  73. package/dist/types/resources/tools.d.ts +145 -0
  74. package/dist/types/resources/transcription.d.ts +4 -4
  75. package/dist/types/resources/wallet.d.ts +16 -6
  76. package/dist/types/types.d.ts +43 -0
  77. package/dist/types/x402.d.ts +27 -1
  78. package/package.json +5 -3
@@ -62,3 +62,31 @@ export declare function classifyError(data: NormalizedErrorData): DevaError;
62
62
  export declare function errorFromResponse(status: number, body: unknown): DevaError;
63
63
  /** Normalizes unknown exceptions into DevaError instances. */
64
64
  export declare function normalizeError(error: unknown): DevaError;
65
+ /** A task-scoped tool budget refused a run before its paid POST. */
66
+ export declare class BudgetExceededError extends DevaError {
67
+ readonly reason: "maxUsd" | "maxRuns" | "unknownEstimate";
68
+ readonly budget: {
69
+ maxUsd: number;
70
+ maxRuns: number;
71
+ };
72
+ readonly usage: {
73
+ spentUsd: number;
74
+ reservedUsd: number;
75
+ runs: number;
76
+ };
77
+ readonly estimatedUsd?: number | undefined;
78
+ constructor(reason: "maxUsd" | "maxRuns" | "unknownEstimate", budget: {
79
+ maxUsd: number;
80
+ maxRuns: number;
81
+ }, usage: {
82
+ spentUsd: number;
83
+ reservedUsd: number;
84
+ runs: number;
85
+ }, estimatedUsd?: number | undefined);
86
+ }
87
+ /** Waiting timed out; the remote run may still be executing. */
88
+ export declare class ToolRunTimeoutError extends DevaError {
89
+ readonly runId: string;
90
+ readonly timeoutMs: number;
91
+ constructor(runId: string, timeoutMs: number);
92
+ }
@@ -2,21 +2,23 @@ import { DevaHttpClient } from "../client.js";
2
2
  export interface SendEmailRequest {
3
3
  to: string | string[];
4
4
  subject: string;
5
- body: string;
6
- cc?: string[];
7
- bcc?: string[];
5
+ /** @deprecated Use body_text. */
6
+ body?: string;
7
+ body_text?: string;
8
+ body_html?: string;
8
9
  reply_to?: string;
9
10
  [key: string]: unknown;
10
11
  }
11
12
  export interface SendEmailResponse {
12
- id?: string;
13
- status?: string;
13
+ success: boolean;
14
+ message_id: string;
15
+ karma_cost: number;
14
16
  [key: string]: unknown;
15
17
  }
16
18
  /** Outbound email operations. */
17
19
  export declare class EmailResource {
18
20
  private readonly client;
19
21
  constructor(client: DevaHttpClient);
20
- /** Sends an email via `POST /v1/agents/email/send`. */
22
+ /** Sends an email via `POST /v1/comms/email/send`. */
21
23
  send(payload: SendEmailRequest): Promise<SendEmailResponse>;
22
24
  }
@@ -40,7 +40,7 @@ export interface DownloadFileResponse {
40
40
  contentType: string | null;
41
41
  etag: string | null;
42
42
  }
43
- /** File upload/download/list/delete and presigned URL workflows. */
43
+ /** File upload/download/list/delete operations. */
44
44
  export declare class FilesResource {
45
45
  private readonly client;
46
46
  constructor(client: DevaHttpClient);
@@ -54,8 +54,6 @@ export declare class FilesResource {
54
54
  list(input?: ListFilesRequest): Promise<ListFilesResponse>;
55
55
  /** Deletes a file via `DELETE /v1/agents/files/{path}`. */
56
56
  delete(path: string): Promise<DeleteFileResponse>;
57
- /**
58
- * Creates a presigned upload/download URL. Expected endpoint: `POST /v1/agents/files/presign`.
59
- */
60
- presign(payload: PresignFileRequest): Promise<PresignFileResponse>;
57
+ /** @deprecated Not supported by the live API. Use upload() or download(). */
58
+ presign(_payload: PresignFileRequest): Promise<PresignFileResponse>;
61
59
  }
@@ -12,3 +12,4 @@ export * from "./social.js";
12
12
  export * from "./transcription.js";
13
13
  export * from "./vision.js";
14
14
  export * from "./wallet.js";
15
+ export * from "./tools.js";
@@ -1,21 +1,31 @@
1
1
  import { DevaHttpClient } from "../client.js";
2
2
  export interface SendMessageRequest {
3
3
  to: string;
4
- content: string;
5
- channel?: "agent" | "user";
4
+ /** Legacy alias for body. */
5
+ content?: string;
6
+ body?: string;
7
+ thread_id?: string;
6
8
  subject?: string;
7
9
  metadata?: Record<string, unknown>;
8
10
  [key: string]: unknown;
9
11
  }
10
12
  export interface SendMessageResponse {
11
13
  id?: string;
12
- status?: string;
14
+ status?: "unread" | "read" | "deleted";
15
+ thread_id: string;
16
+ from: string;
17
+ to: string;
18
+ body: string;
19
+ subject: string | null;
20
+ sent_at: string;
21
+ read_at: string | null;
22
+ metadata: Record<string, unknown>;
13
23
  [key: string]: unknown;
14
24
  }
15
25
  /** Agent/user messaging APIs. */
16
26
  export declare class MessagingResource {
17
27
  private readonly client;
18
28
  constructor(client: DevaHttpClient);
19
- /** Sends a message via `POST /v1/agents/messaging/send`. */
29
+ /** Sends a message via `POST /v1/agents/messages/send`. */
20
30
  send(payload: SendMessageRequest): Promise<SendMessageResponse>;
21
31
  }
@@ -18,22 +18,45 @@ export interface WebSearchResponse {
18
18
  }
19
19
  export interface XSearchRequest {
20
20
  query: string;
21
+ count?: number;
22
+ search_type?: "Latest" | "Top";
23
+ source?: "anyapi" | "monid" | "rapidapi";
24
+ max_price?: number;
25
+ /** @deprecated Use count. */
21
26
  max_results?: number;
22
27
  [key: string]: unknown;
23
28
  }
24
29
  export interface XTweet {
25
30
  id?: string;
26
31
  text?: string;
27
- author_username?: string;
32
+ author?: {
33
+ id?: string | null;
34
+ username?: string | null;
35
+ name?: string | null;
36
+ };
37
+ metrics?: {
38
+ likes?: number | null;
39
+ retweets?: number | null;
40
+ replies?: number | null;
41
+ views?: number | null;
42
+ };
28
43
  created_at?: string;
29
44
  [key: string]: unknown;
30
45
  }
31
46
  export interface XSearchResponse {
32
- results?: XTweet[];
47
+ success: boolean;
48
+ tweets: XTweet[];
49
+ total: number;
50
+ credits_cost: number;
51
+ query?: string;
52
+ search_type?: string;
53
+ username?: string;
33
54
  [key: string]: unknown;
34
55
  }
35
56
  export interface XUserTweetsRequest {
36
57
  username: string;
58
+ count?: number;
59
+ /** @deprecated Use count. */
37
60
  limit?: number;
38
61
  }
39
62
  /** Web and X/Twitter resource search APIs. */
@@ -42,8 +65,8 @@ export declare class SearchResource {
42
65
  constructor(client: DevaHttpClient);
43
66
  /** Performs web search via Perplexity Sonar (5 ₭ per search). `POST /v1/agents/resources/search`. */
44
67
  web(payload: WebSearchRequest): Promise<WebSearchResponse>;
45
- /** Performs X/Twitter search (15 ₭ per search). `POST /v1/agents/resources/x/search`. */
68
+ /** Performs X/Twitter search (15 ₭ per search). `POST /v1/tools/x/search`. */
46
69
  x(payload: XSearchRequest): Promise<XSearchResponse>;
47
- /** Fetches tweets for a specific X user (15 ₭ per request). `GET /v1/agents/resources/x/user/{username}/tweets`. */
70
+ /** Fetches user tweets via POST /v1/tools/x/user-tweets. */
48
71
  xUserTweets(input: XUserTweetsRequest): Promise<XSearchResponse>;
49
72
  }
@@ -1,5 +1,4 @@
1
1
  import { DevaHttpClient } from "../client.js";
2
- import type { PaginatedRequest, PaginatedResponse } from "../types.js";
3
2
  export interface SocialPostAuthor {
4
3
  id?: string;
5
4
  username?: string;
@@ -10,7 +9,7 @@ export interface SocialPostAuthor {
10
9
  export interface SocialPost {
11
10
  id: string;
12
11
  content?: string;
13
- author?: SocialPostAuthor;
12
+ author?: SocialPostAuthor | string;
14
13
  created_at?: string;
15
14
  updated_at?: string;
16
15
  reactions?: Record<string, number>;
@@ -19,12 +18,12 @@ export interface SocialPost {
19
18
  }
20
19
  export interface CreatePostRequest {
21
20
  content: string;
22
- media_urls?: string[];
23
- metadata?: Record<string, unknown>;
21
+ in_reply_to?: string;
24
22
  [key: string]: unknown;
25
23
  }
26
- export interface FeedRequest extends PaginatedRequest {
27
- scope?: "following" | "global";
24
+ export interface FeedRequest {
25
+ limit?: number;
26
+ include_untrusted?: boolean;
28
27
  }
29
28
  export interface ReactToPostRequest {
30
29
  /** Reaction value — any emoji or text string (e.g. "like", "❤️", "🔥"). Send null to remove. */
@@ -32,23 +31,25 @@ export interface ReactToPostRequest {
32
31
  }
33
32
  export interface AddCommentRequest {
34
33
  content: string;
35
- parent_comment_id?: string;
36
34
  }
37
- export type FeedResponse = PaginatedResponse<SocialPost>;
35
+ export interface FeedResponse {
36
+ success: boolean;
37
+ posts: SocialPost[];
38
+ }
38
39
  /** Social posting, feed, reactions, and comments. */
39
40
  export declare class SocialResource {
40
41
  private readonly client;
41
42
  constructor(client: DevaHttpClient);
42
- /** Creates a social post via `POST /v1/social/posts`. */
43
+ /** Creates a social post via `POST /v1/agents/posts`. */
43
44
  createPost(payload: CreatePostRequest): Promise<SocialPost>;
44
- /** Lists the social feed via `GET /v1/social/feed`. */
45
+ /** Lists the social feed via `GET /v1/agents/feed`. */
45
46
  getFeed(input?: FeedRequest): Promise<FeedResponse>;
46
- /** Fetches a single post by id via `GET /v1/social/posts/{id}`. */
47
+ /** Fetches a single post by id via `GET /v1/agents/posts/{id}`. */
47
48
  getPost(postId: string): Promise<SocialPost>;
48
- /** Adds or updates a reaction on a post via `POST /v1/social/posts/{id}/react`. */
49
+ /** Adds or updates a reaction on a post via `PUT /v1/agents/posts/{id}/react`. */
49
50
  react(postId: string, payload: ReactToPostRequest): Promise<Record<string, unknown>>;
50
- /** Removes the current reaction on a post via `DELETE /v1/social/posts/{id}/react`. */
51
+ /** Removes a reaction using PUT with a null reaction. */
51
52
  removeReaction(postId: string): Promise<Record<string, unknown>>;
52
- /** Adds a comment to a post via `POST /v1/social/posts/{id}/comment`. */
53
- comment(postId: string, payload: AddCommentRequest): Promise<Record<string, unknown>>;
53
+ /** Creates a reply via POST /v1/agents/posts. */
54
+ comment(postId: string, payload: AddCommentRequest): Promise<SocialPost>;
54
55
  }
@@ -0,0 +1,145 @@
1
+ import { DevaHttpClient } from "../client.js";
2
+ import type { JsonObject } from "../types.js";
3
+ export interface ToolCatalogEntry {
4
+ provider: string;
5
+ slug: string;
6
+ name: string;
7
+ description: string | null;
8
+ categories: string[];
9
+ pricing_summary: string;
10
+ unit_price_usd: number | null;
11
+ payable_with: string[];
12
+ run_kind: "SYNC" | "ASYNC";
13
+ provider_tool_id: string;
14
+ provider_native_id: string | null;
15
+ popularity: number;
16
+ pricing: JsonObject;
17
+ pricing_model: "FREE" | "PER_RESULT" | "PER_EVENT" | null;
18
+ min_cap_usd: number | null;
19
+ relevance_score: number | null;
20
+ burn_rate: JsonObject | null;
21
+ }
22
+ export interface ToolsDiscoverRequest {
23
+ q?: string;
24
+ category?: string;
25
+ provider?: string;
26
+ status?: string;
27
+ cursor?: string;
28
+ limit?: number;
29
+ min_score?: number;
30
+ }
31
+ export interface ToolsDiscoverResponse {
32
+ items: ToolCatalogEntry[];
33
+ total: number;
34
+ next_cursor: string | null;
35
+ next: Record<string, string> | null;
36
+ }
37
+ export interface ToolSpec {
38
+ slug: string;
39
+ provider: string;
40
+ input_schema: JsonObject;
41
+ output_hint: string | null;
42
+ pricing: JsonObject;
43
+ defaults: JsonObject;
44
+ caps: JsonObject;
45
+ build: JsonObject | null;
46
+ min_cap_usd: number | null;
47
+ next: Record<string, string> | null;
48
+ }
49
+ export interface ToolRunInput {
50
+ params?: JsonObject;
51
+ maxTotalChargeUsd?: number;
52
+ }
53
+ export interface ToolCostEstimate {
54
+ amount_usd: number | null;
55
+ amount_credits: number | null;
56
+ deterministic: boolean;
57
+ cap_usd: number | null;
58
+ breakdown: JsonObject;
59
+ basis: string;
60
+ sample_size: number | null;
61
+ cap_credits: number | null;
62
+ min_charge_usd: number | null;
63
+ min_cap_usd: number | null;
64
+ next: Record<string, string> | null;
65
+ }
66
+ export interface ToolRunResponse {
67
+ status: string;
68
+ charged: boolean;
69
+ credits_charged: number;
70
+ actual_cost_usd: number | null;
71
+ run_id: string | null;
72
+ output: JsonObject | null;
73
+ message: string | null;
74
+ }
75
+ export interface ToolRunStartResponse {
76
+ run_id: string;
77
+ status: string;
78
+ poll: string;
79
+ max_total_charge_credits: number | null;
80
+ next: Record<string, string> | null;
81
+ }
82
+ export interface ToolRunStatusResponse {
83
+ status: string;
84
+ run_id: string;
85
+ credits_charged: number | null;
86
+ actual_cost_usd: number | null;
87
+ items: unknown[] | null;
88
+ dataset_id: string | null;
89
+ result_count: number | null;
90
+ usage_breakdown: JsonObject | null;
91
+ max_total_charge_credits: number | null;
92
+ cap_hit: boolean | null;
93
+ message: string | null;
94
+ next: Record<string, string> | null;
95
+ }
96
+ export interface ToolWaitOptions {
97
+ timeoutMs?: number;
98
+ pollMs?: number;
99
+ }
100
+ export interface ToolBudget {
101
+ maxUsd: number;
102
+ maxRuns: number;
103
+ }
104
+ export interface ToolBudgetUsage {
105
+ spentUsd: number;
106
+ reservedUsd: number;
107
+ runs: number;
108
+ }
109
+ /** Provider-independent tool discovery and execution. */
110
+ export declare class ToolsResource {
111
+ protected readonly client: DevaHttpClient;
112
+ constructor(client: DevaHttpClient);
113
+ discover(input?: ToolsDiscoverRequest): Promise<ToolsDiscoverResponse>;
114
+ inspect(slug: string): Promise<ToolSpec>;
115
+ estimate(slug: string, input?: ToolRunInput): Promise<ToolCostEstimate>;
116
+ /** Starts one run. Paid POSTs are never automatically retried, including on 402. */
117
+ run(slug: string, input?: ToolRunInput): Promise<ToolRunResponse | ToolRunStartResponse>;
118
+ getRun(runId: string, options?: {
119
+ timeoutMs?: number;
120
+ }): Promise<ToolRunStatusResponse>;
121
+ /** Poll until terminal; timeout does not cancel the remote run. */
122
+ waitForRun(runId: string, { timeoutMs, pollMs }?: ToolWaitOptions): Promise<ToolRunStatusResponse>;
123
+ /** Creates an independent, in-memory task budget. Zero means no runs/spend allowed. */
124
+ withBudget(budget: ToolBudget): BudgetedToolsResource;
125
+ }
126
+ /**
127
+ * Task budget inspired by monid-ai/activegraph-monid's budget_guard behavior:
128
+ * count attempted calls, account for actual cost when completed. Independently implemented.
129
+ */
130
+ export declare class BudgetedToolsResource extends ToolsResource {
131
+ private readonly budget;
132
+ private spent;
133
+ private runs;
134
+ private readonly reservations;
135
+ private readonly pending;
136
+ private gate;
137
+ constructor(client: DevaHttpClient, budget: ToolBudget);
138
+ private reserved;
139
+ get usage(): ToolBudgetUsage;
140
+ run(slug: string, input?: ToolRunInput): Promise<ToolRunResponse | ToolRunStartResponse>;
141
+ getRun(runId: string, options?: {
142
+ timeoutMs?: number;
143
+ }): Promise<ToolRunStatusResponse>;
144
+ private settle;
145
+ }
@@ -3,13 +3,13 @@ export interface TranscriptionRequest {
3
3
  file: Blob | ArrayBuffer | Uint8Array;
4
4
  filename?: string;
5
5
  language?: string;
6
- model?: string;
7
- prompt?: string;
8
6
  }
9
7
  export interface TranscriptionResponse {
10
8
  text?: string;
11
9
  language?: string;
12
- duration?: number;
10
+ duration_seconds?: number;
11
+ credits_cost?: number;
12
+ provider?: string;
13
13
  [key: string]: unknown;
14
14
  }
15
15
  /** Audio transcription API using multipart upload. */
@@ -17,7 +17,7 @@ export declare class TranscriptionResource {
17
17
  private readonly client;
18
18
  constructor(client: DevaHttpClient);
19
19
  /**
20
- * Transcribes audio via `POST /v1/ai/audio/transcriptions`.
20
+ * Transcribes audio via `POST /v1/ai/transcribe`.
21
21
  */
22
22
  create(payload: TranscriptionRequest): Promise<TranscriptionResponse>;
23
23
  }
@@ -1,9 +1,19 @@
1
1
  import { DevaHttpClient } from "../client.js";
2
2
  import type { PaginatedRequest, PaginatedResponse } from "../types.js";
3
3
  export interface WalletBalance {
4
- karma?: number;
5
- available?: number;
6
- pending?: number;
4
+ success: boolean;
5
+ unit: "credits" | "usd" | "karma";
6
+ subject: {
7
+ type: string;
8
+ agent_id?: string | null;
9
+ user_id?: string | null;
10
+ owner_user_id?: string | null;
11
+ };
12
+ agent_balance: Record<"bronze" | "silver" | "gold" | "purchased_silver" | "purchased_gold" | "sdk_subscription" | "sdk_earned" | "sdk_top_up" | "total", number>;
13
+ total_spendable?: number | null;
14
+ owner_budget_enabled: boolean;
15
+ owner_budget_remaining?: number | null;
16
+ owner_daily_allowance_remaining?: number | null;
7
17
  [key: string]: unknown;
8
18
  }
9
19
  export interface WalletTransaction {
@@ -22,8 +32,8 @@ export type WalletTransactionsResponse = PaginatedResponse<WalletTransaction>;
22
32
  export declare class WalletResource {
23
33
  private readonly client;
24
34
  constructor(client: DevaHttpClient);
25
- /** Reads wallet balance via `GET /v1/agents/wallet/balance`. */
35
+ /** Reads wallet balance via `GET /v1/agents/balance`. */
26
36
  balance(): Promise<WalletBalance>;
27
- /** Lists wallet transactions via `GET /v1/agents/wallet/transactions`. */
28
- transactions(input?: WalletTransactionsRequest): Promise<WalletTransactionsResponse>;
37
+ /** @deprecated Not supported by the live API; rejects without a network request. */
38
+ transactions(_input?: WalletTransactionsRequest): Promise<WalletTransactionsResponse>;
29
39
  }
@@ -16,10 +16,25 @@ export interface DevaClientOptions {
16
16
  export interface X402Options {
17
17
  enabled?: boolean;
18
18
  maxRetries?: number;
19
+ /** Custom deployments only; requires walletPayPath and autoPayPolicy. */
19
20
  walletAutoPay?: boolean;
21
+ /** Explicit custom payment endpoint; the live API has no default wallet pay route. */
20
22
  walletPayPath?: string;
23
+ autoPayPolicy?: X402AutoPayPolicy;
21
24
  payer?: X402Payer;
22
25
  }
26
+ export interface X402AutoPayPolicy {
27
+ /** Maximum amount the SDK may pay for one SDK request, in the same units as the challenge amount. */
28
+ maxAmount: string | number;
29
+ /** Maximum cumulative amount this client instance may auto-pay, in the same units as the challenge amount. */
30
+ maxCumulativeAmount: string | number;
31
+ /** Networks the caller has approved for auto-pay challenges. Compared case-insensitively. */
32
+ allowedNetworks: readonly string[];
33
+ /** Payees the caller has approved for auto-pay challenges. Compared exactly after trimming. */
34
+ allowedPayees: readonly string[];
35
+ /** Challenge schemes the caller has approved. Defaults to ["exact"]. Compared case-insensitively. */
36
+ allowedSchemes?: readonly string[];
37
+ }
23
38
  export interface RequestOptions {
24
39
  method: HttpMethod;
25
40
  path: string;
@@ -29,12 +44,24 @@ export interface RequestOptions {
29
44
  requiresAuth?: boolean;
30
45
  timeoutMs?: number;
31
46
  retryOn402?: boolean;
47
+ /** Disable transport retries for requests that must not be replayed. */
48
+ retry?: boolean;
32
49
  }
33
50
  export interface RegisterAgentInput {
34
51
  /** Unique agent name: 3-30 chars, alphanumeric + underscore (`^[a-zA-Z0-9_]+$`), not a reserved word. */
35
52
  name: string;
36
53
  /** What the agent does: 10-500 characters. Required by the API. */
37
54
  description: string;
55
+ /**
56
+ * Stable random caller-generated identifier (32-128 chars, `[A-Za-z0-9_-]`), e.g. from
57
+ * `openssl rand -hex 32`.
58
+ * Optional, but without it a lost API key can never be recovered. Retrying register
59
+ * with the same name + client_id while unclaimed returns 200 and a new key.
60
+ *
61
+ * Secret recovery credential: whoever holds name + client_id can replace the key of
62
+ * an unclaimed agent. Generate it once, store it securely, never commit or share it.
63
+ */
64
+ client_id?: string;
38
65
  [key: string]: unknown;
39
66
  }
40
67
  export interface RegisteredAgent {
@@ -51,6 +78,10 @@ export interface RegisterAgentOutput {
51
78
  success?: boolean;
52
79
  agent: RegisteredAgent;
53
80
  important?: string;
81
+ /** False when registered without a `client_id` (the registration cannot be recovered). */
82
+ recoverable?: boolean;
83
+ /** Next steps: `discover_url`, `claim_url`, `hint`, and `warning` when not recoverable. */
84
+ next?: Record<string, string> | null;
54
85
  [key: string]: unknown;
55
86
  }
56
87
  export interface PaginatedRequest {
@@ -80,12 +111,24 @@ export interface X402Challenge {
80
111
  token?: string;
81
112
  challenge_id?: string;
82
113
  expires_at?: string;
114
+ request_hash?: string;
115
+ request_method?: string;
116
+ request_path?: string;
117
+ request_url?: string;
118
+ body_sha256?: string;
83
119
  raw?: unknown;
84
120
  }
85
121
  export interface X402PaymentContext {
86
122
  path: string;
123
+ url?: string;
87
124
  method: HttpMethod;
88
125
  status: number;
126
+ bodySha256?: string;
127
+ bodyHashAlgorithm?: "sha-256";
128
+ requestHash?: string;
129
+ requestHashAlgorithm?: "sha-256";
130
+ autoPayAttempt?: number;
131
+ autoPaySpent?: string;
89
132
  responseHeaders: Headers;
90
133
  }
91
134
  export interface X402PaymentResult {
@@ -1,8 +1,34 @@
1
- import type { X402Challenge, X402Payer } from "./types.js";
1
+ import type { X402AutoPayPolicy, X402Challenge, X402PaymentContext, X402Payer } from "./types.js";
2
+ export interface X402Amount {
3
+ units: bigint;
4
+ scale: number;
5
+ }
6
+ export interface NormalizedX402AutoPayPolicy {
7
+ maxAmount: X402Amount;
8
+ maxCumulativeAmount: X402Amount;
9
+ allowedNetworks: ReadonlySet<string>;
10
+ allowedPayees: ReadonlySet<string>;
11
+ allowedSchemes: ReadonlySet<string>;
12
+ }
13
+ export interface X402AutoPayValidationResult {
14
+ allowed: boolean;
15
+ amount?: X402Amount;
16
+ replayKey?: string;
17
+ reason?: string;
18
+ }
2
19
  /**
3
20
  * Extracts x402 challenge details from response headers and response body.
4
21
  */
5
22
  export declare function parseX402Challenge(response: Response, payload?: unknown): X402Challenge | undefined;
23
+ export declare function parseX402Amount(value: string | number | undefined): X402Amount | undefined;
24
+ export declare function compareX402Amounts(left: X402Amount, right: X402Amount): number;
25
+ export declare function addX402Amounts(left: X402Amount, right: X402Amount): X402Amount;
26
+ export declare function subtractX402Amounts(left: X402Amount, right: X402Amount): X402Amount;
27
+ export declare function zeroX402Amount(): X402Amount;
28
+ export declare function formatX402Amount(amount: X402Amount): string;
29
+ export declare function normalizeX402AutoPayPolicy(policy: X402AutoPayPolicy | undefined): NormalizedX402AutoPayPolicy;
30
+ export declare function getX402ChallengeReplayKey(challenge: X402Challenge): string | undefined;
31
+ export declare function validateX402AutoPay(challenge: X402Challenge, context: X402PaymentContext, policy: NormalizedX402AutoPayPolicy, requestSpent: X402Amount, cumulativeSpent: X402Amount, paidChallengeKeys: ReadonlySet<string>): X402AutoPayValidationResult;
6
32
  /**
7
33
  * Creates a built-in wallet-backed x402 payer that calls a Deva wallet pay endpoint.
8
34
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deva-me/agent-sdk",
3
- "version": "0.2.0",
4
- "description": "TypeScript SDK for the Deva Agent Resources API — LLM chat, KV, social, email, and more for autonomous agents (not the \"Login with Deva\" web SDK)",
3
+ "version": "0.4.0",
4
+ "description": "TypeScript SDK for the Deva Agent Resources API \u2014 LLM chat, KV, social, email, and more for autonomous agents (not the \"Login with Deva\" web SDK)",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/Deva-me-AI/deva-agent-sdk.git"
@@ -35,7 +35,9 @@
35
35
  "build:cjs": "tsc -p tsconfig.cjs.json && node -e \"require('fs').writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' }))\"",
36
36
  "clean": "rm -rf dist",
37
37
  "prepublishOnly": "npm run clean && npm run build",
38
- "test": "npm run build && node --experimental-strip-types --test 'test/*.test.ts'"
38
+ "test": "npm run build && node --experimental-strip-types --test 'test/*.test.ts'",
39
+ "typecheck": "tsc -p tsconfig.esm.json --noEmit && tsc -p tsconfig.cjs.json --noEmit",
40
+ "lint": "tsc -p tsconfig.esm.json --noEmit --noUnusedLocals --noUnusedParameters --noFallthroughCasesInSwitch"
39
41
  },
40
42
  "devDependencies": {
41
43
  "typescript": "^5.7.3"