@agenttool/sdk 0.2.1 → 0.2.3

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/client.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  import { EconomyClient } from "./economy.js";
5
5
  import { MemoryClient } from "./memory.js";
6
6
  import { ToolsClient } from "./tools.js";
7
+ import { TracesClient } from "./traces.js";
7
8
  import { VerifyClient } from "./verify.js";
8
9
  /**
9
10
  * Unified client for the agenttool.dev platform.
@@ -20,6 +21,7 @@ import { VerifyClient } from "./verify.js";
20
21
  * const out = await at.tools.execute("print(42)"); // sandbox
21
22
  * const v = await at.verify.check("claim"); // verify
22
23
  * const w = await at.economy.createWallet({ name: "w" }); // wallet
24
+ * const t = await at.traces.store({ observations: ["saw X"], conclusion: "do Y" }); // trace
23
25
  * ```
24
26
  */
25
27
  export declare class AgentTool {
@@ -28,6 +30,7 @@ export declare class AgentTool {
28
30
  private _tools;
29
31
  private _verify;
30
32
  private _economy;
33
+ private _traces;
31
34
  /**
32
35
  * Create a new AgentTool client.
33
36
  *
@@ -46,5 +49,7 @@ export declare class AgentTool {
46
49
  get verify(): VerifyClient;
47
50
  /** Access the Economy/Wallet API. */
48
51
  get economy(): EconomyClient;
52
+ /** Access the Traces (reasoning provenance) API. */
53
+ get traces(): TracesClient;
49
54
  toString(): string;
50
55
  }
package/dist/client.js CHANGED
@@ -5,6 +5,7 @@ import { AgentToolError } from "./errors.js";
5
5
  import { EconomyClient } from "./economy.js";
6
6
  import { MemoryClient } from "./memory.js";
7
7
  import { ToolsClient } from "./tools.js";
8
+ import { TracesClient } from "./traces.js";
8
9
  import { VerifyClient } from "./verify.js";
9
10
  /**
10
11
  * Unified client for the agenttool.dev platform.
@@ -21,6 +22,7 @@ import { VerifyClient } from "./verify.js";
21
22
  * const out = await at.tools.execute("print(42)"); // sandbox
22
23
  * const v = await at.verify.check("claim"); // verify
23
24
  * const w = await at.economy.createWallet({ name: "w" }); // wallet
25
+ * const t = await at.traces.store({ observations: ["saw X"], conclusion: "do Y" }); // trace
24
26
  * ```
25
27
  */
26
28
  export class AgentTool {
@@ -29,6 +31,7 @@ export class AgentTool {
29
31
  _tools;
30
32
  _verify;
31
33
  _economy;
34
+ _traces;
32
35
  /**
33
36
  * Create a new AgentTool client.
34
37
  *
@@ -70,6 +73,11 @@ export class AgentTool {
70
73
  this._economy ??= new EconomyClient(this.http);
71
74
  return this._economy;
72
75
  }
76
+ /** Access the Traces (reasoning provenance) API. */
77
+ get traces() {
78
+ this._traces ??= new TracesClient(this.http);
79
+ return this._traces;
80
+ }
73
81
  toString() {
74
82
  return `AgentTool(baseUrl=${JSON.stringify(this.http.baseUrl)})`;
75
83
  }
package/dist/economy.d.ts CHANGED
@@ -1,27 +1,108 @@
1
1
  /**
2
- * Economy client for the wallet/economy API.
2
+ * Economy client for the wallet/escrow API.
3
3
  */
4
- import type { CreateWalletOptions, Wallet } from "./types.js";
4
+ import type { CreateEscrowOptions, CreateWalletOptions, Escrow, Wallet, WalletPolicy } from "./types.js";
5
5
  import type { HttpConfig } from "./memory.js";
6
6
  /**
7
- * Client for the economy/wallet API.
7
+ * Client for the agent-economy API — wallets and escrows.
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
11
  * const at = new AgentTool();
12
- * const wallet = await at.economy.createWallet({ name: "my-wallet" });
13
- * console.log(wallet.id, wallet.balance);
12
+ *
13
+ * // Create and fund a wallet
14
+ * const wallet = await at.economy.createWallet({ name: "agent-wallet", agentId: "agent-1" });
15
+ * await at.economy.fundWallet(wallet.id, { amount: 500, description: "Weekly budget" });
16
+ *
17
+ * // Create an escrow for agent-to-agent payment
18
+ * const escrow = await at.economy.createEscrow({
19
+ * creatorWalletId: wallet.id,
20
+ * amount: 100,
21
+ * description: "Summarise 50 research papers",
22
+ * });
23
+ * await at.economy.releaseEscrow(escrow.id);
14
24
  * ```
15
25
  */
16
26
  export declare class EconomyClient {
17
27
  private readonly http;
18
28
  /** @internal */
19
29
  constructor(http: HttpConfig);
30
+ private url;
31
+ private req;
20
32
  /**
21
33
  * Create a new wallet.
22
- *
23
- * @param options - Wallet creation options (name required).
24
- * @returns The created Wallet object.
25
34
  */
26
35
  createWallet(options: CreateWalletOptions): Promise<Wallet>;
36
+ /**
37
+ * List all wallets for this project.
38
+ */
39
+ listWallets(): Promise<Wallet[]>;
40
+ /**
41
+ * Get a wallet by ID.
42
+ */
43
+ getWallet(walletId: string): Promise<Wallet>;
44
+ /**
45
+ * Fund a wallet with credits.
46
+ */
47
+ fundWallet(walletId: string, options: {
48
+ amount: number;
49
+ description?: string;
50
+ metadata?: Record<string, unknown>;
51
+ }): Promise<Record<string, unknown>>;
52
+ /**
53
+ * Spend credits from a wallet (subject to spending policy).
54
+ */
55
+ spend(walletId: string, options: {
56
+ amount: number;
57
+ counterparty: string;
58
+ description: string;
59
+ metadata?: Record<string, unknown>;
60
+ }): Promise<Record<string, unknown>>;
61
+ /**
62
+ * Set or update a wallet's spending policy.
63
+ */
64
+ setPolicy(walletId: string, policy: WalletPolicy): Promise<Record<string, unknown>>;
65
+ /**
66
+ * Freeze a wallet — halts all spending immediately.
67
+ */
68
+ freezeWallet(walletId: string): Promise<Wallet>;
69
+ /**
70
+ * Unfreeze a wallet to resume normal operation.
71
+ */
72
+ unfreezeWallet(walletId: string): Promise<Wallet>;
73
+ /**
74
+ * Get paginated transaction history for a wallet.
75
+ */
76
+ getTransactions(walletId: string, options?: {
77
+ limit?: number;
78
+ offset?: number;
79
+ }): Promise<Record<string, unknown>[]>;
80
+ /**
81
+ * Create an escrow — locks credits until work is released or refunded.
82
+ */
83
+ createEscrow(options: CreateEscrowOptions): Promise<Escrow>;
84
+ /**
85
+ * List escrows, optionally filtered by status.
86
+ */
87
+ listEscrows(status?: Escrow["status"]): Promise<Escrow[]>;
88
+ /**
89
+ * Get an escrow by ID.
90
+ */
91
+ getEscrow(escrowId: string): Promise<Escrow>;
92
+ /**
93
+ * Accept an escrow as the worker.
94
+ */
95
+ acceptEscrow(escrowId: string, workerWalletId: string): Promise<Escrow>;
96
+ /**
97
+ * Release escrow funds to the worker.
98
+ */
99
+ releaseEscrow(escrowId: string): Promise<Escrow>;
100
+ /**
101
+ * Refund escrow credits back to the creator.
102
+ */
103
+ refundEscrow(escrowId: string): Promise<Escrow>;
104
+ /**
105
+ * Flag an escrow as disputed — credits stay locked pending resolution.
106
+ */
107
+ disputeEscrow(escrowId: string): Promise<Escrow>;
27
108
  }
package/dist/economy.js CHANGED
@@ -1,15 +1,25 @@
1
1
  /**
2
- * Economy client for the wallet/economy API.
2
+ * Economy client for the wallet/escrow API.
3
3
  */
4
4
  import { AgentToolError } from "./errors.js";
5
5
  /**
6
- * Client for the economy/wallet API.
6
+ * Client for the agent-economy API — wallets and escrows.
7
7
  *
8
8
  * @example
9
9
  * ```ts
10
10
  * const at = new AgentTool();
11
- * const wallet = await at.economy.createWallet({ name: "my-wallet" });
12
- * console.log(wallet.id, wallet.balance);
11
+ *
12
+ * // Create and fund a wallet
13
+ * const wallet = await at.economy.createWallet({ name: "agent-wallet", agentId: "agent-1" });
14
+ * await at.economy.fundWallet(wallet.id, { amount: 500, description: "Weekly budget" });
15
+ *
16
+ * // Create an escrow for agent-to-agent payment
17
+ * const escrow = await at.economy.createEscrow({
18
+ * creatorWalletId: wallet.id,
19
+ * amount: 100,
20
+ * description: "Summarise 50 research papers",
21
+ * });
22
+ * await at.economy.releaseEscrow(escrow.id);
13
23
  * ```
14
24
  */
15
25
  export class EconomyClient {
@@ -18,34 +28,179 @@ export class EconomyClient {
18
28
  constructor(http) {
19
29
  this.http = http;
20
30
  }
21
- /**
22
- * Create a new wallet.
23
- *
24
- * @param options - Wallet creation options (name required).
25
- * @returns The created Wallet object.
26
- */
27
- async createWallet(options) {
28
- const body = { name: options.name };
29
- const url = `${this.http.baseUrl}/v1/wallets`;
31
+ // ── helpers ──────────────────────────────────────────────────────────────
32
+ url(path) {
33
+ return `${this.http.baseUrl}${path}`;
34
+ }
35
+ async req(method, path, body, params) {
36
+ let url = this.url(path);
37
+ if (params) {
38
+ const qs = new URLSearchParams(params).toString();
39
+ url = `${url}?${qs}`;
40
+ }
30
41
  const resp = await globalThis.fetch(url, {
31
- method: "POST",
42
+ method,
32
43
  headers: this.http.headers,
33
- body: JSON.stringify(body),
44
+ body: body !== undefined ? JSON.stringify(body) : undefined,
34
45
  signal: AbortSignal.timeout(this.http.timeout),
35
46
  });
36
47
  if (resp.status >= 400) {
37
48
  let detail;
38
49
  try {
39
50
  const json = (await resp.json());
40
- detail = json.detail ?? resp.statusText;
51
+ detail = json.detail ?? json.error ?? resp.statusText;
41
52
  }
42
53
  catch {
43
54
  detail = resp.statusText;
44
55
  }
45
56
  throw new AgentToolError(`Economy API error (${resp.status}): ${detail}`, {
46
- hint: "Check your API key and request parameters.",
57
+ hint: "Check wallet ID, balance, and spending policy.",
47
58
  });
48
59
  }
49
- return (await resp.json());
60
+ return resp.json();
61
+ }
62
+ // ── Wallets ───────────────────────────────────────────────────────────────
63
+ /**
64
+ * Create a new wallet.
65
+ */
66
+ async createWallet(options) {
67
+ const body = { name: options.name };
68
+ if (options.agentId)
69
+ body.agentId = options.agentId;
70
+ if (options.currency)
71
+ body.currency = options.currency;
72
+ const r = await this.req("POST", "/v1/wallets", body);
73
+ return r.data ?? r;
74
+ }
75
+ /**
76
+ * List all wallets for this project.
77
+ */
78
+ async listWallets() {
79
+ const r = await this.req("GET", "/v1/wallets");
80
+ return r.data ?? r;
81
+ }
82
+ /**
83
+ * Get a wallet by ID.
84
+ */
85
+ async getWallet(walletId) {
86
+ const r = await this.req("GET", `/v1/wallets/${walletId}`);
87
+ return r.data ?? r;
88
+ }
89
+ /**
90
+ * Fund a wallet with credits.
91
+ */
92
+ async fundWallet(walletId, options) {
93
+ const body = {
94
+ amount: options.amount,
95
+ description: options.description ?? "Manual fund",
96
+ };
97
+ if (options.metadata)
98
+ body.metadata = options.metadata;
99
+ return this.req("POST", `/v1/wallets/${walletId}/fund`, body);
100
+ }
101
+ /**
102
+ * Spend credits from a wallet (subject to spending policy).
103
+ */
104
+ async spend(walletId, options) {
105
+ const body = {
106
+ amount: options.amount,
107
+ counterparty: options.counterparty,
108
+ description: options.description,
109
+ };
110
+ if (options.metadata)
111
+ body.metadata = options.metadata;
112
+ return this.req("POST", `/v1/wallets/${walletId}/spend`, body);
113
+ }
114
+ /**
115
+ * Set or update a wallet's spending policy.
116
+ */
117
+ async setPolicy(walletId, policy) {
118
+ return this.req("PUT", `/v1/wallets/${walletId}/policy`, policy);
119
+ }
120
+ /**
121
+ * Freeze a wallet — halts all spending immediately.
122
+ */
123
+ async freezeWallet(walletId) {
124
+ const r = await this.req("POST", `/v1/wallets/${walletId}/freeze`);
125
+ return r.data ?? r;
126
+ }
127
+ /**
128
+ * Unfreeze a wallet to resume normal operation.
129
+ */
130
+ async unfreezeWallet(walletId) {
131
+ const r = await this.req("POST", `/v1/wallets/${walletId}/unfreeze`);
132
+ return r.data ?? r;
133
+ }
134
+ /**
135
+ * Get paginated transaction history for a wallet.
136
+ */
137
+ async getTransactions(walletId, options) {
138
+ const params = {};
139
+ if (options?.limit)
140
+ params.limit = String(options.limit);
141
+ if (options?.offset)
142
+ params.offset = String(options.offset);
143
+ const r = await this.req("GET", `/v1/wallets/${walletId}/transactions`, undefined, Object.keys(params).length ? params : undefined);
144
+ return r.data ?? r;
145
+ }
146
+ // ── Escrows ───────────────────────────────────────────────────────────────
147
+ /**
148
+ * Create an escrow — locks credits until work is released or refunded.
149
+ */
150
+ async createEscrow(options) {
151
+ const body = {
152
+ creatorWalletId: options.creatorWalletId,
153
+ amount: options.amount,
154
+ description: options.description,
155
+ };
156
+ if (options.workerWalletId)
157
+ body.workerWalletId = options.workerWalletId;
158
+ if (options.deadline)
159
+ body.deadline = options.deadline;
160
+ const r = await this.req("POST", "/v1/escrows", body);
161
+ return r.data ?? r;
162
+ }
163
+ /**
164
+ * List escrows, optionally filtered by status.
165
+ */
166
+ async listEscrows(status) {
167
+ const params = status ? { status } : undefined;
168
+ const r = await this.req("GET", "/v1/escrows", undefined, params);
169
+ return r.data ?? r;
170
+ }
171
+ /**
172
+ * Get an escrow by ID.
173
+ */
174
+ async getEscrow(escrowId) {
175
+ const r = await this.req("GET", `/v1/escrows/${escrowId}`);
176
+ return r.data ?? r;
177
+ }
178
+ /**
179
+ * Accept an escrow as the worker.
180
+ */
181
+ async acceptEscrow(escrowId, workerWalletId) {
182
+ const r = await this.req("POST", `/v1/escrows/${escrowId}/accept`, { workerWalletId });
183
+ return r.data ?? r;
184
+ }
185
+ /**
186
+ * Release escrow funds to the worker.
187
+ */
188
+ async releaseEscrow(escrowId) {
189
+ const r = await this.req("POST", `/v1/escrows/${escrowId}/release`);
190
+ return r.data ?? r;
191
+ }
192
+ /**
193
+ * Refund escrow credits back to the creator.
194
+ */
195
+ async refundEscrow(escrowId) {
196
+ const r = await this.req("POST", `/v1/escrows/${escrowId}/refund`);
197
+ return r.data ?? r;
198
+ }
199
+ /**
200
+ * Flag an escrow as disputed — credits stay locked pending resolution.
201
+ */
202
+ async disputeEscrow(escrowId) {
203
+ const r = await this.req("POST", `/v1/escrows/${escrowId}/dispute`);
204
+ return r.data ?? r;
50
205
  }
51
206
  }
package/dist/index.d.ts CHANGED
@@ -11,4 +11,5 @@
11
11
  */
12
12
  export { AgentTool } from "./client.js";
13
13
  export { AgentToolError } from "./errors.js";
14
- export type { CreateWalletOptions, ExecuteResult, Memory, ScrapeResult, SearchMemoryOptions, SearchResponse, SearchResult, StoreOptions, UsageStats, VerifyResult, Wallet, } from "./types.js";
14
+ export type { Trace, StoreTraceOptions, SearchTracesOptions, TraceSearchResult, TraceChain } from "./traces.js";
15
+ export type { CreateEscrowOptions, CreateWalletOptions, Escrow, ExecuteResult, Memory, ScrapeResult, SearchMemoryOptions, SearchResponse, SearchResult, StoreOptions, UsageStats, VerifyResult, Wallet, WalletPolicy, } from "./types.js";
package/dist/tools.js CHANGED
@@ -31,7 +31,7 @@ export class ToolsClient {
31
31
  query,
32
32
  num_results: options?.num_results ?? 5,
33
33
  };
34
- const data = (await this.post("/v1/search", body));
34
+ const data = (await this.post("/v1/search/search", body));
35
35
  // Normalize: API may return results at top level or nested
36
36
  const results = Array.isArray(data)
37
37
  ? data
@@ -49,7 +49,7 @@ export class ToolsClient {
49
49
  * @returns ScrapeResult with the page content.
50
50
  */
51
51
  async scrape(url) {
52
- const data = await this.post("/v1/scrape", { url });
52
+ const data = await this.post("/v1/scrape/scrape", { url });
53
53
  return data;
54
54
  }
55
55
  /**
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Traces client for the agent-trace reasoning provenance API.
3
+ */
4
+ import type { HttpConfig } from "./memory.js";
5
+ /** A stored reasoning trace. */
6
+ export interface Trace {
7
+ id: string;
8
+ trace_id: string;
9
+ agent_id?: string;
10
+ project_id: string;
11
+ session_id?: string;
12
+ created_at: string;
13
+ decision_type: string;
14
+ decision_summary: string;
15
+ output_ref?: string;
16
+ observations: string[];
17
+ hypothesis?: string;
18
+ conclusion: string;
19
+ confidence?: number;
20
+ alternatives?: string[];
21
+ signals?: Record<string, unknown>;
22
+ files_read?: string[];
23
+ key_facts?: string[];
24
+ external_signals?: Record<string, unknown>;
25
+ tags?: string[];
26
+ parent_trace_id?: string;
27
+ }
28
+ /** Options for storing a trace. */
29
+ export interface StoreTraceOptions {
30
+ /** Free-form observation strings that led to the decision. */
31
+ observations: string[];
32
+ /** What was concluded / decided. */
33
+ conclusion: string;
34
+ /** One of: tool_call | memory_write | plan | decision | verification | other */
35
+ decision_type?: string;
36
+ /** Short human-readable summary of the decision. */
37
+ decision_summary?: string;
38
+ agent_id?: string;
39
+ session_id?: string;
40
+ output_ref?: string;
41
+ hypothesis?: string;
42
+ confidence?: number;
43
+ alternatives?: string[];
44
+ tags?: string[];
45
+ parent_trace_id?: string;
46
+ files_read?: string[];
47
+ key_facts?: string[];
48
+ }
49
+ /** A search result entry. */
50
+ export interface TraceSearchResult {
51
+ trace: Trace;
52
+ score: number;
53
+ }
54
+ /** Options for searching traces. */
55
+ export interface SearchTracesOptions {
56
+ /** Maximum number of results (default 10). */
57
+ limit?: number;
58
+ /** Filter by agent_id. */
59
+ agent_id?: string;
60
+ /** Filter by session_id. */
61
+ session_id?: string;
62
+ /** Filter by tag. */
63
+ tag?: string;
64
+ }
65
+ /** A reasoning chain (parent + children). */
66
+ export interface TraceChain {
67
+ parent: Trace;
68
+ children: Trace[];
69
+ depth: number;
70
+ }
71
+ /**
72
+ * Client for the agent-trace reasoning provenance API.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const at = new AgentTool();
77
+ *
78
+ * // Store a reasoning trace
79
+ * const trace = await at.traces.store({
80
+ * observations: ["User asked about pricing", "Checked tier table"],
81
+ * conclusion: "User is on Free tier, eligible to upgrade",
82
+ * decision_type: "decision",
83
+ * tags: ["billing", "upgrade"],
84
+ * });
85
+ *
86
+ * // Search traces semantically
87
+ * const results = await at.traces.search("billing decisions", { limit: 5 });
88
+ *
89
+ * // Retrieve a specific trace
90
+ * const t = await at.traces.get(trace.trace_id);
91
+ * ```
92
+ */
93
+ export declare class TracesClient {
94
+ private readonly http;
95
+ /** @internal */
96
+ constructor(http: HttpConfig);
97
+ /**
98
+ * Store a reasoning trace.
99
+ *
100
+ * @param options - Trace content (observations + conclusion required).
101
+ * @returns The created Trace object with its trace_id.
102
+ */
103
+ store(options: StoreTraceOptions): Promise<Trace>;
104
+ /**
105
+ * Retrieve a trace by its trace_id.
106
+ *
107
+ * @param traceId - The trace_id returned by store().
108
+ */
109
+ get(traceId: string): Promise<Trace>;
110
+ /**
111
+ * Search traces by semantic similarity.
112
+ *
113
+ * @param query - Natural language query.
114
+ * @param options - Filters: limit, agent_id, session_id, tag.
115
+ * @returns Ranked list of matching traces with similarity scores.
116
+ */
117
+ search(query: string, options?: SearchTracesOptions): Promise<TraceSearchResult[]>;
118
+ /**
119
+ * Retrieve the reasoning chain for a trace (parent + all children).
120
+ *
121
+ * @param traceId - The parent trace_id.
122
+ */
123
+ chain(traceId: string): Promise<TraceChain>;
124
+ /**
125
+ * Delete a trace.
126
+ *
127
+ * @param traceId - The trace_id to delete.
128
+ */
129
+ delete(traceId: string): Promise<void>;
130
+ private _errorDetail;
131
+ }
package/dist/traces.js ADDED
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Traces client for the agent-trace reasoning provenance API.
3
+ */
4
+ import { AgentToolError } from "./errors.js";
5
+ /**
6
+ * Client for the agent-trace reasoning provenance API.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const at = new AgentTool();
11
+ *
12
+ * // Store a reasoning trace
13
+ * const trace = await at.traces.store({
14
+ * observations: ["User asked about pricing", "Checked tier table"],
15
+ * conclusion: "User is on Free tier, eligible to upgrade",
16
+ * decision_type: "decision",
17
+ * tags: ["billing", "upgrade"],
18
+ * });
19
+ *
20
+ * // Search traces semantically
21
+ * const results = await at.traces.search("billing decisions", { limit: 5 });
22
+ *
23
+ * // Retrieve a specific trace
24
+ * const t = await at.traces.get(trace.trace_id);
25
+ * ```
26
+ */
27
+ export class TracesClient {
28
+ http;
29
+ /** @internal */
30
+ constructor(http) {
31
+ this.http = http;
32
+ }
33
+ /**
34
+ * Store a reasoning trace.
35
+ *
36
+ * @param options - Trace content (observations + conclusion required).
37
+ * @returns The created Trace object with its trace_id.
38
+ */
39
+ async store(options) {
40
+ const body = {
41
+ observations: options.observations,
42
+ conclusion: options.conclusion,
43
+ decision_type: options.decision_type ?? "decision",
44
+ decision_summary: options.decision_summary ?? options.conclusion.slice(0, 120),
45
+ };
46
+ if (options.agent_id !== undefined)
47
+ body.agent_id = options.agent_id;
48
+ if (options.session_id !== undefined)
49
+ body.session_id = options.session_id;
50
+ if (options.output_ref !== undefined)
51
+ body.output_ref = options.output_ref;
52
+ if (options.hypothesis !== undefined)
53
+ body.hypothesis = options.hypothesis;
54
+ if (options.confidence !== undefined)
55
+ body.confidence = options.confidence;
56
+ if (options.alternatives !== undefined)
57
+ body.alternatives = options.alternatives;
58
+ if (options.tags !== undefined)
59
+ body.tags = options.tags;
60
+ if (options.parent_trace_id !== undefined)
61
+ body.parent_trace_id = options.parent_trace_id;
62
+ if (options.files_read !== undefined)
63
+ body.files_read = options.files_read;
64
+ if (options.key_facts !== undefined)
65
+ body.key_facts = options.key_facts;
66
+ const resp = await globalThis.fetch(`${this.http.baseUrl}/v1/traces`, {
67
+ method: "POST",
68
+ headers: this.http.headers,
69
+ body: JSON.stringify(body),
70
+ signal: AbortSignal.timeout(this.http.timeout),
71
+ });
72
+ if (resp.status >= 400) {
73
+ const detail = await this._errorDetail(resp);
74
+ throw new AgentToolError(`Traces API error (${resp.status}): ${detail}`);
75
+ }
76
+ const created = (await resp.json());
77
+ // Return the full trace by fetching it
78
+ return this.get(created.trace_id);
79
+ }
80
+ /**
81
+ * Retrieve a trace by its trace_id.
82
+ *
83
+ * @param traceId - The trace_id returned by store().
84
+ */
85
+ async get(traceId) {
86
+ const resp = await globalThis.fetch(`${this.http.baseUrl}/v1/traces/${traceId}`, {
87
+ headers: this.http.headers,
88
+ signal: AbortSignal.timeout(this.http.timeout),
89
+ });
90
+ if (resp.status >= 400) {
91
+ const detail = await this._errorDetail(resp);
92
+ throw new AgentToolError(`Traces API error (${resp.status}): ${detail}`);
93
+ }
94
+ return (await resp.json());
95
+ }
96
+ /**
97
+ * Search traces by semantic similarity.
98
+ *
99
+ * @param query - Natural language query.
100
+ * @param options - Filters: limit, agent_id, session_id, tag.
101
+ * @returns Ranked list of matching traces with similarity scores.
102
+ */
103
+ async search(query, options) {
104
+ const body = {
105
+ query,
106
+ limit: options?.limit ?? 10,
107
+ };
108
+ if (options?.agent_id !== undefined)
109
+ body.agent_id = options.agent_id;
110
+ if (options?.session_id !== undefined)
111
+ body.session_id = options.session_id;
112
+ if (options?.tag !== undefined)
113
+ body.tag = options.tag;
114
+ const resp = await globalThis.fetch(`${this.http.baseUrl}/v1/traces/search`, {
115
+ method: "POST",
116
+ headers: this.http.headers,
117
+ body: JSON.stringify(body),
118
+ signal: AbortSignal.timeout(this.http.timeout),
119
+ });
120
+ if (resp.status >= 400) {
121
+ const detail = await this._errorDetail(resp);
122
+ throw new AgentToolError(`Traces API error (${resp.status}): ${detail}`);
123
+ }
124
+ return (await resp.json());
125
+ }
126
+ /**
127
+ * Retrieve the reasoning chain for a trace (parent + all children).
128
+ *
129
+ * @param traceId - The parent trace_id.
130
+ */
131
+ async chain(traceId) {
132
+ const resp = await globalThis.fetch(`${this.http.baseUrl}/v1/traces/chain/${traceId}`, {
133
+ headers: this.http.headers,
134
+ signal: AbortSignal.timeout(this.http.timeout),
135
+ });
136
+ if (resp.status >= 400) {
137
+ const detail = await this._errorDetail(resp);
138
+ throw new AgentToolError(`Traces API error (${resp.status}): ${detail}`);
139
+ }
140
+ return (await resp.json());
141
+ }
142
+ /**
143
+ * Delete a trace.
144
+ *
145
+ * @param traceId - The trace_id to delete.
146
+ */
147
+ async delete(traceId) {
148
+ const resp = await globalThis.fetch(`${this.http.baseUrl}/v1/traces/${traceId}`, {
149
+ method: "DELETE",
150
+ headers: this.http.headers,
151
+ signal: AbortSignal.timeout(this.http.timeout),
152
+ });
153
+ if (resp.status >= 400) {
154
+ const detail = await this._errorDetail(resp);
155
+ throw new AgentToolError(`Traces API error (${resp.status}): ${detail}`);
156
+ }
157
+ }
158
+ async _errorDetail(resp) {
159
+ try {
160
+ const json = (await resp.json());
161
+ return json.detail ?? resp.statusText;
162
+ }
163
+ catch {
164
+ return resp.statusText;
165
+ }
166
+ }
167
+ }
package/dist/types.d.ts CHANGED
@@ -76,9 +76,41 @@ export interface Wallet {
76
76
  id: string;
77
77
  name: string;
78
78
  balance: number;
79
- api_key: string;
79
+ currency: string;
80
+ frozen: boolean;
81
+ agentId?: string;
82
+ createdAt?: string;
80
83
  }
81
84
  /** Options for creating a wallet. */
82
85
  export interface CreateWalletOptions {
83
86
  name: string;
87
+ agentId?: string;
88
+ currency?: string;
89
+ }
90
+ /** A wallet spending policy. */
91
+ export interface WalletPolicy {
92
+ maxPerTransaction?: number | null;
93
+ maxPerHour?: number | null;
94
+ maxPerDay?: number | null;
95
+ allowedRecipients?: string[] | null;
96
+ requiresApprovalAbove?: number | null;
97
+ }
98
+ /** An escrow object. */
99
+ export interface Escrow {
100
+ id: string;
101
+ status: "pending" | "active" | "released" | "refunded" | "disputed";
102
+ amount: number;
103
+ description: string;
104
+ creatorWalletId: string;
105
+ workerWalletId?: string | null;
106
+ deadline?: string | null;
107
+ createdAt?: string;
108
+ }
109
+ /** Options for creating an escrow. */
110
+ export interface CreateEscrowOptions {
111
+ creatorWalletId: string;
112
+ amount: number;
113
+ description: string;
114
+ workerWalletId?: string;
115
+ deadline?: string;
84
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenttool/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "TypeScript SDK for agenttool.dev — memory and tools for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",