@agenttool/sdk 0.2.1 → 0.2.2

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/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 { Trace, StoreTraceOptions, SearchTracesOptions, TraceSearchResult, TraceChain } from "./traces.js";
14
15
  export type { CreateWalletOptions, ExecuteResult, Memory, ScrapeResult, SearchMemoryOptions, SearchResponse, SearchResult, StoreOptions, UsageStats, VerifyResult, Wallet, } 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenttool/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "TypeScript SDK for agenttool.dev — memory and tools for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",