@trustthenverify/sdk 1.1.0 → 2.0.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/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export interface Agent {
28
28
  description?: string;
29
29
  contact?: string;
30
30
  trust_score?: number;
31
+ trust_tier?: number;
31
32
  capabilities?: string[];
32
33
  lightning_pubkey?: string;
33
34
  nostr_npub?: string;
@@ -35,6 +36,17 @@ export interface Agent {
35
36
  website?: string;
36
37
  created_at?: string;
37
38
  }
39
+ export interface PaginatedAgents {
40
+ agents: Agent[];
41
+ page: number;
42
+ limit: number;
43
+ total: number;
44
+ total_pages: number;
45
+ }
46
+ export interface ListAgentsOptions {
47
+ page?: number;
48
+ limit?: number;
49
+ }
38
50
  export interface RegisterResponse {
39
51
  agent_id: string;
40
52
  trust_score: number;
@@ -68,9 +80,25 @@ export declare class TrustClient {
68
80
  */
69
81
  getAgent(agentId: string): Promise<Agent | null>;
70
82
  /**
71
- * List all registered agents
83
+ * List registered agents (paginated)
84
+ */
85
+ listAgents(options?: ListAgentsOptions): Promise<PaginatedAgents>;
86
+ /**
87
+ * Update an agent's fields (requires auth secret = contact value)
72
88
  */
73
- listAgents(): Promise<Agent[]>;
89
+ updateAgent(agentId: string, updates: Partial<Pick<Agent, "description" | "capabilities" | "lightning_pubkey" | "x_handle" | "website" | "contact">>, authSecret: string): Promise<{
90
+ success: boolean;
91
+ message?: string;
92
+ error?: string;
93
+ }>;
94
+ /**
95
+ * Soft-delete an agent (requires auth secret = contact value)
96
+ */
97
+ deleteAgent(agentId: string, authSecret: string): Promise<{
98
+ success: boolean;
99
+ message?: string;
100
+ error?: string;
101
+ }>;
74
102
  /**
75
103
  * Register a new agent
76
104
  */
@@ -114,7 +142,17 @@ export declare const lookup: (agentId: string) => Promise<{
114
142
  } | null>;
115
143
  export declare const register: (name: string, contact: string, options?: Parameters<TrustClient["register"]>[2]) => Promise<RegisterResponse>;
116
144
  export declare const review: (agentId: string, rating: number, comment: string, options?: Parameters<TrustClient["review"]>[3]) => Promise<ReviewResponse>;
117
- export declare const listAgents: () => Promise<Agent[]>;
145
+ export declare const listAgents: (options?: ListAgentsOptions) => Promise<PaginatedAgents>;
146
+ export declare const updateAgent: (agentId: string, updates: Parameters<TrustClient["updateAgent"]>[1], authSecret: string) => Promise<{
147
+ success: boolean;
148
+ message?: string;
149
+ error?: string;
150
+ }>;
151
+ export declare const deleteAgent: (agentId: string, authSecret: string) => Promise<{
152
+ success: boolean;
153
+ message?: string;
154
+ error?: string;
155
+ }>;
118
156
  export declare const isTrusted: (agentId: string) => Promise<boolean>;
119
157
  export declare const badgeUrl: (agentId: string) => string;
120
158
  /**
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * https://trustthenverify.com
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.badgeUrl = exports.isTrusted = exports.listAgents = exports.review = exports.register = exports.lookup = exports.trust = exports.TrustClient = exports.TrustRegistryOfflineError = void 0;
9
+ exports.badgeUrl = exports.isTrusted = exports.deleteAgent = exports.updateAgent = exports.listAgents = exports.review = exports.register = exports.lookup = exports.trust = exports.TrustClient = exports.TrustRegistryOfflineError = void 0;
10
10
  exports.ensureRegistered = ensureRegistered;
11
11
  exports.checkBeforeTransaction = checkBeforeTransaction;
12
12
  class TrustRegistryOfflineError extends Error {
@@ -52,14 +52,50 @@ class TrustClient {
52
52
  return res.json();
53
53
  }
54
54
  /**
55
- * List all registered agents
55
+ * List registered agents (paginated)
56
56
  */
57
- async listAgents() {
58
- const res = await this.safeFetch(`${this.baseUrl}/registry/agents`);
57
+ async listAgents(options) {
58
+ const params = new URLSearchParams();
59
+ if (options?.page)
60
+ params.set("page", String(options.page));
61
+ if (options?.limit)
62
+ params.set("limit", String(options.limit));
63
+ const qs = params.toString();
64
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agents${qs ? `?${qs}` : ""}`);
59
65
  if (!res.ok)
60
- return [];
66
+ return { agents: [], page: 1, limit: 50, total: 0, total_pages: 0 };
61
67
  const data = await res.json();
62
- return data.agents || [];
68
+ return {
69
+ agents: data.agents || [],
70
+ page: data.page || 1,
71
+ limit: data.limit || 50,
72
+ total: data.total || 0,
73
+ total_pages: data.total_pages || 0,
74
+ };
75
+ }
76
+ /**
77
+ * Update an agent's fields (requires auth secret = contact value)
78
+ */
79
+ async updateAgent(agentId, updates, authSecret) {
80
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agent/${agentId}`, {
81
+ method: "PATCH",
82
+ headers: {
83
+ "Content-Type": "application/json",
84
+ "X-Agent-Secret": authSecret,
85
+ },
86
+ body: JSON.stringify(updates),
87
+ });
88
+ return res.json();
89
+ }
90
+ /**
91
+ * Soft-delete an agent (requires auth secret = contact value)
92
+ */
93
+ async deleteAgent(agentId, authSecret) {
94
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agent/${agentId}`, {
95
+ method: "DELETE",
96
+ headers: { "X-Agent-Secret": authSecret },
97
+ });
98
+ return res.json();
63
99
  }
64
100
  /**
65
101
  * Register a new agent
@@ -136,8 +172,12 @@ const register = (name, contact, options) => exports.trust.register(name, contac
136
172
  exports.register = register;
137
173
  const review = (agentId, rating, comment, options) => exports.trust.review(agentId, rating, comment, options);
138
174
  exports.review = review;
139
- const listAgents = () => exports.trust.listAgents();
175
+ const listAgents = (options) => exports.trust.listAgents(options);
140
176
  exports.listAgents = listAgents;
177
+ const updateAgent = (agentId, updates, authSecret) => exports.trust.updateAgent(agentId, updates, authSecret);
178
+ exports.updateAgent = updateAgent;
179
+ const deleteAgent = (agentId, authSecret) => exports.trust.deleteAgent(agentId, authSecret);
180
+ exports.deleteAgent = deleteAgent;
141
181
  const isTrusted = (agentId) => exports.trust.isTrusted(agentId);
142
182
  exports.isTrusted = isTrusted;
143
183
  const badgeUrl = (agentId) => exports.trust.badgeUrl(agentId);
@@ -156,19 +196,19 @@ exports.badgeUrl = badgeUrl;
156
196
  * });
157
197
  */
158
198
  async function ensureRegistered(options) {
159
- // Check if already registered by name
160
- const agents = await exports.trust.listAgents();
161
- const existing = agents.find(a => a.name.toLowerCase() === options.name.toLowerCase());
199
+ // Search by name instead of listing all agents
200
+ const result = await exports.trust.listAgents({ limit: 50 });
201
+ const existing = result.agents.find(a => a.name.toLowerCase() === options.name.toLowerCase());
162
202
  if (existing) {
163
203
  return existing.id;
164
204
  }
165
205
  // Register new agent
166
- const result = await exports.trust.register(options.name, options.contact || `sdk-auto-${Date.now()}`, {
206
+ const regResult = await exports.trust.register(options.name, options.contact || `sdk-auto-${Date.now()}`, {
167
207
  description: options.description,
168
208
  nostr_npub: options.npub,
169
209
  lightning_pubkey: options.lightning_pubkey,
170
210
  });
171
- return result.agent_id;
211
+ return regResult.agent_id;
172
212
  }
173
213
  /**
174
214
  * Check trust before transaction helper
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustthenverify/sdk",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "TypeScript SDK for the Trust Then Verify agent registry",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -31,6 +31,7 @@ export interface Agent {
31
31
  description?: string;
32
32
  contact?: string;
33
33
  trust_score?: number;
34
+ trust_tier?: number;
34
35
  capabilities?: string[];
35
36
  lightning_pubkey?: string;
36
37
  nostr_npub?: string;
@@ -39,6 +40,19 @@ export interface Agent {
39
40
  created_at?: string;
40
41
  }
41
42
 
43
+ export interface PaginatedAgents {
44
+ agents: Agent[];
45
+ page: number;
46
+ limit: number;
47
+ total: number;
48
+ total_pages: number;
49
+ }
50
+
51
+ export interface ListAgentsOptions {
52
+ page?: number;
53
+ limit?: number;
54
+ }
55
+
42
56
  export interface RegisterResponse {
43
57
  agent_id: string;
44
58
  trust_score: number;
@@ -102,13 +116,56 @@ export class TrustClient {
102
116
  }
103
117
 
104
118
  /**
105
- * List all registered agents
119
+ * List registered agents (paginated)
106
120
  */
107
- async listAgents(): Promise<Agent[]> {
108
- const res = await this.safeFetch(`${this.baseUrl}/registry/agents`);
109
- if (!res.ok) return [];
121
+ async listAgents(options?: ListAgentsOptions): Promise<PaginatedAgents> {
122
+ const params = new URLSearchParams();
123
+ if (options?.page) params.set("page", String(options.page));
124
+ if (options?.limit) params.set("limit", String(options.limit));
125
+ const qs = params.toString();
126
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agents${qs ? `?${qs}` : ""}`);
127
+ if (!res.ok) return { agents: [], page: 1, limit: 50, total: 0, total_pages: 0 };
110
128
  const data = await res.json();
111
- return data.agents || [];
129
+ return {
130
+ agents: data.agents || [],
131
+ page: data.page || 1,
132
+ limit: data.limit || 50,
133
+ total: data.total || 0,
134
+ total_pages: data.total_pages || 0,
135
+ };
136
+ }
137
+
138
+ /**
139
+ * Update an agent's fields (requires auth secret = contact value)
140
+ */
141
+ async updateAgent(
142
+ agentId: string,
143
+ updates: Partial<Pick<Agent, "description" | "capabilities" | "lightning_pubkey" | "x_handle" | "website" | "contact">>,
144
+ authSecret: string
145
+ ): Promise<{ success: boolean; message?: string; error?: string }> {
146
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agent/${agentId}`, {
147
+ method: "PATCH",
148
+ headers: {
149
+ "Content-Type": "application/json",
150
+ "X-Agent-Secret": authSecret,
151
+ },
152
+ body: JSON.stringify(updates),
153
+ });
154
+ return res.json();
155
+ }
156
+
157
+ /**
158
+ * Soft-delete an agent (requires auth secret = contact value)
159
+ */
160
+ async deleteAgent(
161
+ agentId: string,
162
+ authSecret: string
163
+ ): Promise<{ success: boolean; message?: string; error?: string }> {
164
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agent/${agentId}`, {
165
+ method: "DELETE",
166
+ headers: { "X-Agent-Secret": authSecret },
167
+ });
168
+ return res.json();
112
169
  }
113
170
 
114
171
  /**
@@ -205,7 +262,10 @@ export const register = (name: string, contact: string, options?: Parameters<Tru
205
262
  trust.register(name, contact, options);
206
263
  export const review = (agentId: string, rating: number, comment: string, options?: Parameters<TrustClient["review"]>[3]) =>
207
264
  trust.review(agentId, rating, comment, options);
208
- export const listAgents = () => trust.listAgents();
265
+ export const listAgents = (options?: ListAgentsOptions) => trust.listAgents(options);
266
+ export const updateAgent = (agentId: string, updates: Parameters<TrustClient["updateAgent"]>[1], authSecret: string) =>
267
+ trust.updateAgent(agentId, updates, authSecret);
268
+ export const deleteAgent = (agentId: string, authSecret: string) => trust.deleteAgent(agentId, authSecret);
209
269
  export const isTrusted = (agentId: string) => trust.isTrusted(agentId);
210
270
  export const badgeUrl = (agentId: string) => trust.badgeUrl(agentId);
211
271
 
@@ -229,16 +289,16 @@ export async function ensureRegistered(options: {
229
289
  lightning_pubkey?: string;
230
290
  description?: string;
231
291
  }): Promise<string> {
232
- // Check if already registered by name
233
- const agents = await trust.listAgents();
234
- const existing = agents.find(a => a.name.toLowerCase() === options.name.toLowerCase());
292
+ // Search by name instead of listing all agents
293
+ const result = await trust.listAgents({ limit: 50 });
294
+ const existing = result.agents.find(a => a.name.toLowerCase() === options.name.toLowerCase());
235
295
 
236
296
  if (existing) {
237
297
  return existing.id;
238
298
  }
239
299
 
240
300
  // Register new agent
241
- const result = await trust.register(
301
+ const regResult = await trust.register(
242
302
  options.name,
243
303
  options.contact || `sdk-auto-${Date.now()}`,
244
304
  {
@@ -248,7 +308,7 @@ export async function ensureRegistered(options: {
248
308
  }
249
309
  );
250
310
 
251
- return result.agent_id;
311
+ return regResult.agent_id;
252
312
  }
253
313
 
254
314
  /**