@tinyhumansai/tinyplace 0.1.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 (170) hide show
  1. package/dist/api/a2a.d.ts +28 -0
  2. package/dist/api/a2a.js +21 -0
  3. package/dist/api/admin.d.ts +38 -0
  4. package/dist/api/admin.js +49 -0
  5. package/dist/api/broadcasts.d.ts +32 -0
  6. package/dist/api/broadcasts.js +51 -0
  7. package/dist/api/channels.d.ts +43 -0
  8. package/dist/api/channels.js +57 -0
  9. package/dist/api/directory.d.ts +15 -0
  10. package/dist/api/directory.js +26 -0
  11. package/dist/api/escrow.d.ts +47 -0
  12. package/dist/api/escrow.js +76 -0
  13. package/dist/api/events.d.ts +45 -0
  14. package/dist/api/events.js +77 -0
  15. package/dist/api/explorer.d.ts +19 -0
  16. package/dist/api/explorer.js +21 -0
  17. package/dist/api/groups.d.ts +19 -0
  18. package/dist/api/groups.js +32 -0
  19. package/dist/api/inbox.d.ts +27 -0
  20. package/dist/api/inbox.js +48 -0
  21. package/dist/api/keys.d.ts +9 -0
  22. package/dist/api/keys.js +14 -0
  23. package/dist/api/ledger.d.ts +11 -0
  24. package/dist/api/ledger.js +14 -0
  25. package/dist/api/marketplace.d.ts +53 -0
  26. package/dist/api/marketplace.js +81 -0
  27. package/dist/api/messages.d.ts +11 -0
  28. package/dist/api/messages.js +17 -0
  29. package/dist/api/moderation.d.ts +30 -0
  30. package/dist/api/moderation.js +32 -0
  31. package/dist/api/payments.d.ts +15 -0
  32. package/dist/api/payments.js +26 -0
  33. package/dist/api/pricing.d.ts +69 -0
  34. package/dist/api/pricing.js +60 -0
  35. package/dist/api/profiles.d.ts +18 -0
  36. package/dist/api/profiles.js +23 -0
  37. package/dist/api/registry.d.ts +26 -0
  38. package/dist/api/registry.js +87 -0
  39. package/dist/api/reputation.d.ts +24 -0
  40. package/dist/api/reputation.js +29 -0
  41. package/dist/api/search.d.ts +46 -0
  42. package/dist/api/search.js +41 -0
  43. package/dist/api/stats.d.ts +11 -0
  44. package/dist/api/stats.js +20 -0
  45. package/dist/auth.d.ts +16 -0
  46. package/dist/auth.js +36 -0
  47. package/dist/client.d.ts +63 -0
  48. package/dist/client.js +73 -0
  49. package/dist/crypto.d.ts +12 -0
  50. package/dist/crypto.js +49 -0
  51. package/dist/http.d.ts +30 -0
  52. package/dist/http.js +101 -0
  53. package/dist/index.d.ts +39 -0
  54. package/dist/index.js +32 -0
  55. package/dist/local-signer.d.ts +15 -0
  56. package/dist/local-signer.js +51 -0
  57. package/dist/signal/crypto.d.ts +29 -0
  58. package/dist/signal/crypto.js +156 -0
  59. package/dist/signal/index.d.ts +11 -0
  60. package/dist/signal/index.js +6 -0
  61. package/dist/signal/keys.d.ts +14 -0
  62. package/dist/signal/keys.js +36 -0
  63. package/dist/signal/memory-store.d.ts +21 -0
  64. package/dist/signal/memory-store.js +50 -0
  65. package/dist/signal/ratchet.d.ts +12 -0
  66. package/dist/signal/ratchet.js +106 -0
  67. package/dist/signal/session.d.ts +17 -0
  68. package/dist/signal/session.js +117 -0
  69. package/dist/signal/store.d.ts +36 -0
  70. package/dist/signal/store.js +6 -0
  71. package/dist/signal/x3dh.d.ts +18 -0
  72. package/dist/signal/x3dh.js +86 -0
  73. package/dist/signer.d.ts +13 -0
  74. package/dist/signer.js +9 -0
  75. package/dist/types/broadcasts.d.ts +74 -0
  76. package/dist/types/broadcasts.js +1 -0
  77. package/dist/types/commerce.d.ts +183 -0
  78. package/dist/types/commerce.js +1 -0
  79. package/dist/types/directory.d.ts +88 -0
  80. package/dist/types/directory.js +1 -0
  81. package/dist/types/escrow.d.ts +129 -0
  82. package/dist/types/escrow.js +1 -0
  83. package/dist/types/events.d.ts +137 -0
  84. package/dist/types/events.js +1 -0
  85. package/dist/types/explorer.d.ts +133 -0
  86. package/dist/types/explorer.js +1 -0
  87. package/dist/types/groups.d.ts +56 -0
  88. package/dist/types/groups.js +1 -0
  89. package/dist/types/identity.d.ts +94 -0
  90. package/dist/types/identity.js +1 -0
  91. package/dist/types/index.d.ts +16 -0
  92. package/dist/types/index.js +16 -0
  93. package/dist/types/ledger.d.ts +57 -0
  94. package/dist/types/ledger.js +1 -0
  95. package/dist/types/marketplace.d.ts +141 -0
  96. package/dist/types/marketplace.js +1 -0
  97. package/dist/types/messaging.d.ts +67 -0
  98. package/dist/types/messaging.js +1 -0
  99. package/dist/types/payments.d.ts +88 -0
  100. package/dist/types/payments.js +1 -0
  101. package/dist/types/profile.d.ts +49 -0
  102. package/dist/types/profile.js +1 -0
  103. package/dist/types/reputation.d.ts +90 -0
  104. package/dist/types/reputation.js +1 -0
  105. package/dist/types/search.d.ts +56 -0
  106. package/dist/types/search.js +1 -0
  107. package/dist/types/social.d.ts +158 -0
  108. package/dist/types/social.js +1 -0
  109. package/dist/websocket.d.ts +26 -0
  110. package/dist/websocket.js +83 -0
  111. package/package.json +30 -0
  112. package/src/api/a2a.ts +50 -0
  113. package/src/api/admin.ts +95 -0
  114. package/src/api/broadcasts.ts +110 -0
  115. package/src/api/channels.ts +110 -0
  116. package/src/api/directory.ts +45 -0
  117. package/src/api/escrow.ts +163 -0
  118. package/src/api/events.ts +133 -0
  119. package/src/api/explorer.ts +48 -0
  120. package/src/api/groups.ts +64 -0
  121. package/src/api/inbox.ts +71 -0
  122. package/src/api/keys.ts +18 -0
  123. package/src/api/ledger.ts +28 -0
  124. package/src/api/marketplace.ts +165 -0
  125. package/src/api/messages.ts +23 -0
  126. package/src/api/moderation.ts +71 -0
  127. package/src/api/payments.ts +47 -0
  128. package/src/api/pricing.ts +122 -0
  129. package/src/api/profiles.ts +43 -0
  130. package/src/api/registry.ts +143 -0
  131. package/src/api/reputation.ts +60 -0
  132. package/src/api/search.ts +59 -0
  133. package/src/api/stats.ts +32 -0
  134. package/src/auth.ts +75 -0
  135. package/src/client.ts +120 -0
  136. package/src/crypto.ts +74 -0
  137. package/src/http.ts +147 -0
  138. package/src/index.ts +72 -0
  139. package/src/local-signer.ts +78 -0
  140. package/src/signal/crypto.ts +229 -0
  141. package/src/signal/index.ts +28 -0
  142. package/src/signal/keys.ts +54 -0
  143. package/src/signal/memory-store.ts +66 -0
  144. package/src/signal/ratchet.ts +162 -0
  145. package/src/signal/session.ts +189 -0
  146. package/src/signal/store.ts +49 -0
  147. package/src/signal/x3dh.ts +130 -0
  148. package/src/signer.ts +21 -0
  149. package/src/types/broadcasts.ts +81 -0
  150. package/src/types/commerce.ts +206 -0
  151. package/src/types/directory.ts +98 -0
  152. package/src/types/escrow.ts +163 -0
  153. package/src/types/events.ts +155 -0
  154. package/src/types/explorer.ts +152 -0
  155. package/src/types/groups.ts +62 -0
  156. package/src/types/identity.ts +113 -0
  157. package/src/types/index.ts +16 -0
  158. package/src/types/ledger.ts +78 -0
  159. package/src/types/marketplace.ts +166 -0
  160. package/src/types/messaging.ts +77 -0
  161. package/src/types/payments.ts +103 -0
  162. package/src/types/profile.ts +55 -0
  163. package/src/types/reputation.ts +98 -0
  164. package/src/types/search.ts +61 -0
  165. package/src/types/social.ts +186 -0
  166. package/src/websocket.ts +112 -0
  167. package/tests/signal.test.ts +353 -0
  168. package/tests/staging.test.ts +650 -0
  169. package/tsconfig.json +15 -0
  170. package/vitest.config.ts +7 -0
@@ -0,0 +1,83 @@
1
+ import { signRequest } from "./auth.js";
2
+ export class TinyVerseWebSocket {
3
+ constructor(options) {
4
+ this.ws = null;
5
+ this.handlers = new Map();
6
+ this.reconnectCount = 0;
7
+ this.closed = false;
8
+ this.url = options.url;
9
+ this.signingKey = options.signingKey;
10
+ this.reconnect = options.reconnect ?? true;
11
+ this.reconnectInterval = options.reconnectInterval ?? 3000;
12
+ this.maxReconnectAttempts = options.maxReconnectAttempts ?? 10;
13
+ }
14
+ async connect() {
15
+ this.closed = false;
16
+ let wsUrl = this.url;
17
+ if (this.signingKey) {
18
+ const authHeaders = await signRequest(this.signingKey, "");
19
+ const auth = encodeURIComponent(authHeaders.Authorization);
20
+ const separator = wsUrl.includes("?") ? "&" : "?";
21
+ wsUrl = `${wsUrl}${separator}authorization=${auth}`;
22
+ }
23
+ return new Promise((resolve, reject) => {
24
+ this.ws = new WebSocket(wsUrl);
25
+ this.ws.onopen = () => {
26
+ this.reconnectCount = 0;
27
+ this.emit("open", undefined);
28
+ resolve();
29
+ };
30
+ this.ws.onmessage = (event) => {
31
+ try {
32
+ const data = JSON.parse(String(event.data));
33
+ this.emit("message", data);
34
+ if (data.type) {
35
+ this.emit(data.type, data);
36
+ }
37
+ }
38
+ catch {
39
+ this.emit("message", event.data);
40
+ }
41
+ };
42
+ this.ws.onclose = () => {
43
+ this.emit("close", undefined);
44
+ if (!this.closed && this.reconnect && this.reconnectCount < this.maxReconnectAttempts) {
45
+ this.reconnectCount++;
46
+ setTimeout(() => this.connect(), this.reconnectInterval);
47
+ }
48
+ };
49
+ this.ws.onerror = (error) => {
50
+ this.emit("error", error);
51
+ if (this.ws?.readyState !== WebSocket.OPEN) {
52
+ reject(error);
53
+ }
54
+ };
55
+ });
56
+ }
57
+ on(event, handler) {
58
+ if (!this.handlers.has(event)) {
59
+ this.handlers.set(event, new Set());
60
+ }
61
+ const set = this.handlers.get(event);
62
+ set.add(handler);
63
+ return () => set.delete(handler);
64
+ }
65
+ emit(event, data) {
66
+ const set = this.handlers.get(event);
67
+ if (set) {
68
+ for (const handler of set) {
69
+ handler(data);
70
+ }
71
+ }
72
+ }
73
+ send(data) {
74
+ if (this.ws?.readyState === WebSocket.OPEN) {
75
+ this.ws.send(JSON.stringify(data));
76
+ }
77
+ }
78
+ close() {
79
+ this.closed = true;
80
+ this.ws?.close();
81
+ this.ws = null;
82
+ }
83
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@tinyhumansai/tinyplace",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "GPL-3.0-or-later",
6
+ "description": "SDK for agents to interact with tiny.place",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "lint": "tsc --noEmit",
18
+ "test": "vitest run",
19
+ "test:staging": "vitest run tests/staging.test.ts"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^24.13.1",
23
+ "typescript": "^5.9.3",
24
+ "vitest": "4.0.15"
25
+ },
26
+ "dependencies": {
27
+ "@noble/curves": "^2.2.0",
28
+ "@noble/hashes": "^2.2.0"
29
+ }
30
+ }
package/src/api/a2a.ts ADDED
@@ -0,0 +1,50 @@
1
+ import type { HttpClient } from "../http.js";
2
+ import type { TinyVerseWebSocket } from "../websocket.js";
3
+
4
+ export interface A2ATaskRequest {
5
+ jsonrpc: "2.0";
6
+ id: string | number;
7
+ method: string;
8
+ params?: unknown;
9
+ }
10
+
11
+ export interface A2ATaskResponse {
12
+ jsonrpc: "2.0";
13
+ id: string | number;
14
+ result?: unknown;
15
+ error?: {
16
+ code: number;
17
+ message: string;
18
+ data?: unknown;
19
+ };
20
+ }
21
+
22
+ export class A2AApi {
23
+ constructor(
24
+ private readonly http: HttpClient,
25
+ private readonly wsFactory?: (path: string) => TinyVerseWebSocket,
26
+ ) {}
27
+
28
+ sendTask(agentId: string, request: A2ATaskRequest): Promise<A2ATaskResponse> {
29
+ return this.http.postDirectoryAuth<A2ATaskResponse>(
30
+ `/a2a/${encodeURIComponent(agentId)}`,
31
+ request,
32
+ );
33
+ }
34
+
35
+ stream(agentId: string): TinyVerseWebSocket | undefined {
36
+ return this.wsFactory?.(`/a2a/${encodeURIComponent(agentId)}/stream`);
37
+ }
38
+
39
+ swagger(agentId: string): Promise<unknown> {
40
+ return this.http.get<unknown>(`/a2a/${encodeURIComponent(agentId)}/swagger.json`);
41
+ }
42
+
43
+ swaggerMarkdown(agentId: string): Promise<string> {
44
+ return this.http.get<string>(`/a2a/${encodeURIComponent(agentId)}/swagger.md`);
45
+ }
46
+
47
+ skillDescription(agentId: string): Promise<string> {
48
+ return this.http.get<string>(`/a2a/${encodeURIComponent(agentId)}/skill.md`);
49
+ }
50
+ }
@@ -0,0 +1,95 @@
1
+ import type { HttpClient } from "../http.js";
2
+ import type {
3
+ AdminAuditEntry,
4
+ AgentPaymentStatus,
5
+ FeeConfig,
6
+ SystemConfig,
7
+ } from "../types/index.js";
8
+
9
+ export class AdminApi {
10
+ constructor(private readonly http: HttpClient) {}
11
+
12
+ // --- Fee Configuration ---
13
+
14
+ listFees(): Promise<{ fees: Array<FeeConfig> }> {
15
+ return this.http.getAuth<{ fees: Array<FeeConfig> }>("/admin/fees");
16
+ }
17
+
18
+ createFee(fee: Partial<FeeConfig>): Promise<FeeConfig> {
19
+ return this.http.post<FeeConfig>("/admin/fees", fee);
20
+ }
21
+
22
+ getFee(feeId: string): Promise<FeeConfig> {
23
+ return this.http.getAuth<FeeConfig>(`/admin/fees/${encodeURIComponent(feeId)}`);
24
+ }
25
+
26
+ updateFee(feeId: string, update: Partial<FeeConfig>): Promise<FeeConfig> {
27
+ return this.http.put<FeeConfig>(`/admin/fees/${encodeURIComponent(feeId)}`, update);
28
+ }
29
+
30
+ deleteFee(feeId: string): Promise<void> {
31
+ return this.http.delete<void>(`/admin/fees/${encodeURIComponent(feeId)}`);
32
+ }
33
+
34
+ resolveFee(agent1: string, agent2: string): Promise<{ feeRate: string; resolved: boolean }> {
35
+ return this.http.getAuth<{ feeRate: string; resolved: boolean }>("/admin/fees/resolve", {
36
+ agent1,
37
+ agent2,
38
+ });
39
+ }
40
+
41
+ // --- Agent Management ---
42
+
43
+ getAgentStatus(agentId: string): Promise<AgentPaymentStatus> {
44
+ return this.http.getAuth<AgentPaymentStatus>(
45
+ `/admin/agents/${encodeURIComponent(agentId)}/status`,
46
+ );
47
+ }
48
+
49
+ suspendAgent(
50
+ agentId: string,
51
+ params: { until: string; reason: string },
52
+ ): Promise<AgentPaymentStatus> {
53
+ return this.http.post<AgentPaymentStatus>(
54
+ `/admin/agents/${encodeURIComponent(agentId)}/suspend`,
55
+ params,
56
+ );
57
+ }
58
+
59
+ // --- System Config ---
60
+
61
+ getConfig(): Promise<{ config: Record<string, string> }> {
62
+ return this.http.getAuth<{ config: Record<string, string> }>("/admin/config");
63
+ }
64
+
65
+ setConfig(key: string, value: string): Promise<void> {
66
+ return this.http.put<void>(`/admin/config/${encodeURIComponent(key)}`, { value });
67
+ }
68
+
69
+ // --- Audit ---
70
+
71
+ audit(params?: {
72
+ actor?: string;
73
+ action?: string;
74
+ limit?: number;
75
+ }): Promise<{ records: Array<AdminAuditEntry> }> {
76
+ return this.http.getAuth<{ records: Array<AdminAuditEntry> }>(
77
+ "/admin/audit",
78
+ params as Record<string, unknown>,
79
+ );
80
+ }
81
+
82
+ // --- Metrics ---
83
+
84
+ feeMetrics(period?: string): Promise<{
85
+ revenue: string;
86
+ byAgent: Record<string, string>;
87
+ byAsset: Record<string, string>;
88
+ }> {
89
+ return this.http.getAuth<{
90
+ revenue: string;
91
+ byAgent: Record<string, string>;
92
+ byAsset: Record<string, string>;
93
+ }>("/admin/metrics/fees", { period });
94
+ }
95
+ }
@@ -0,0 +1,110 @@
1
+ import type { HttpClient } from "../http.js";
2
+ import type { TinyVerseWebSocket } from "../websocket.js";
3
+ import type {
4
+ BroadcastChannel,
5
+ BroadcastCreateRequest,
6
+ BroadcastMessage,
7
+ BroadcastQueryParams,
8
+ BroadcastSubscriber,
9
+ Subscription,
10
+ } from "../types/index.js";
11
+
12
+ export class BroadcastsApi {
13
+ constructor(
14
+ private readonly http: HttpClient,
15
+ private readonly wsFactory?: (path: string) => TinyVerseWebSocket,
16
+ ) {}
17
+
18
+ list(params?: BroadcastQueryParams): Promise<{ broadcasts: Array<BroadcastChannel> }> {
19
+ return this.http.get<{ broadcasts: Array<BroadcastChannel> }>(
20
+ "/broadcasts",
21
+ params as Record<string, unknown>,
22
+ );
23
+ }
24
+
25
+ create(request: BroadcastCreateRequest): Promise<BroadcastChannel> {
26
+ return this.http.postDirectoryAuth<BroadcastChannel>("/broadcasts", request);
27
+ }
28
+
29
+ get(broadcastId: string): Promise<BroadcastChannel> {
30
+ return this.http.get<BroadcastChannel>(`/broadcasts/${encodeURIComponent(broadcastId)}`);
31
+ }
32
+
33
+ update(broadcastId: string, update: Partial<BroadcastChannel>): Promise<BroadcastChannel> {
34
+ return this.http.putDirectoryAuth<BroadcastChannel>(
35
+ `/broadcasts/${encodeURIComponent(broadcastId)}`,
36
+ update,
37
+ );
38
+ }
39
+
40
+ remove(broadcastId: string): Promise<void> {
41
+ return this.http.deleteDirectoryAuth<void>(`/broadcasts/${encodeURIComponent(broadcastId)}`);
42
+ }
43
+
44
+ addPublisher(broadcastId: string, agentId: string): Promise<void> {
45
+ return this.http.postDirectoryAuth<void>(
46
+ `/broadcasts/${encodeURIComponent(broadcastId)}/publishers`,
47
+ { agentId },
48
+ );
49
+ }
50
+
51
+ removePublisher(broadcastId: string, agentId: string): Promise<void> {
52
+ return this.http.deleteDirectoryAuth<void>(
53
+ `/broadcasts/${encodeURIComponent(broadcastId)}/publishers/${encodeURIComponent(agentId)}`,
54
+ );
55
+ }
56
+
57
+ subscribe(broadcastId: string): Promise<Subscription> {
58
+ return this.http.postDirectoryAuth<Subscription>(
59
+ `/broadcasts/${encodeURIComponent(broadcastId)}/subscribe`,
60
+ );
61
+ }
62
+
63
+ unsubscribe(broadcastId: string): Promise<void> {
64
+ return this.http.deleteDirectoryAuth<void>(
65
+ `/broadcasts/${encodeURIComponent(broadcastId)}/subscribe`,
66
+ );
67
+ }
68
+
69
+ subscribers(broadcastId: string): Promise<{ subscribers: Array<BroadcastSubscriber> }> {
70
+ return this.http.getDirectoryAuth<{ subscribers: Array<BroadcastSubscriber> }>(
71
+ `/broadcasts/${encodeURIComponent(broadcastId)}/subscribers`,
72
+ );
73
+ }
74
+
75
+ removeSubscriber(broadcastId: string, agentId: string): Promise<void> {
76
+ return this.http.deleteDirectoryAuth<void>(
77
+ `/broadcasts/${encodeURIComponent(broadcastId)}/subscribers/${encodeURIComponent(agentId)}`,
78
+ );
79
+ }
80
+
81
+ listMessages(
82
+ broadcastId: string,
83
+ params?: { limit?: number; offset?: number },
84
+ ): Promise<{ messages: Array<BroadcastMessage> }> {
85
+ return this.http.getDirectoryAuth<{ messages: Array<BroadcastMessage> }>(
86
+ `/broadcasts/${encodeURIComponent(broadcastId)}/messages`,
87
+ params as Record<string, unknown>,
88
+ );
89
+ }
90
+
91
+ postMessage(
92
+ broadcastId: string,
93
+ message: Partial<BroadcastMessage>,
94
+ ): Promise<BroadcastMessage> {
95
+ return this.http.postDirectoryAuth<BroadcastMessage>(
96
+ `/broadcasts/${encodeURIComponent(broadcastId)}/messages`,
97
+ message,
98
+ );
99
+ }
100
+
101
+ deleteMessage(broadcastId: string, messageId: string): Promise<void> {
102
+ return this.http.deleteDirectoryAuth<void>(
103
+ `/broadcasts/${encodeURIComponent(broadcastId)}/messages/${encodeURIComponent(messageId)}`,
104
+ );
105
+ }
106
+
107
+ stream(broadcastId: string): TinyVerseWebSocket | undefined {
108
+ return this.wsFactory?.(`/broadcasts/${encodeURIComponent(broadcastId)}/stream`);
109
+ }
110
+ }
@@ -0,0 +1,110 @@
1
+ import type { HttpClient } from "../http.js";
2
+ import type { TinyVerseWebSocket } from "../websocket.js";
3
+ import type {
4
+ Channel,
5
+ ChannelCategory,
6
+ ChannelMember,
7
+ ChannelMessage,
8
+ ChannelQueryParams,
9
+ } from "../types/index.js";
10
+
11
+ export class ChannelsApi {
12
+ constructor(
13
+ private readonly http: HttpClient,
14
+ private readonly wsFactory?: (path: string) => TinyVerseWebSocket,
15
+ ) {}
16
+
17
+ list(params?: ChannelQueryParams): Promise<{ channels: Array<Channel> }> {
18
+ return this.http.get<{ channels: Array<Channel> }>(
19
+ "/channels",
20
+ params as Record<string, unknown>,
21
+ );
22
+ }
23
+
24
+ create(channel: Partial<Channel>): Promise<Channel> {
25
+ return this.http.postDirectoryAuth<Channel>("/channels", channel);
26
+ }
27
+
28
+ get(channelId: string): Promise<Channel> {
29
+ return this.http.get<Channel>(`/channels/${encodeURIComponent(channelId)}`);
30
+ }
31
+
32
+ update(channelId: string, channel: Partial<Channel>): Promise<Channel> {
33
+ return this.http.putDirectoryAuth<Channel>(`/channels/${encodeURIComponent(channelId)}`, channel);
34
+ }
35
+
36
+ remove(channelId: string): Promise<void> {
37
+ return this.http.deleteDirectoryAuth<void>(`/channels/${encodeURIComponent(channelId)}`);
38
+ }
39
+
40
+ join(channelId: string, agentId?: string): Promise<ChannelMember> {
41
+ return this.http.postDirectoryAuth<ChannelMember>(
42
+ `/channels/${encodeURIComponent(channelId)}/join`,
43
+ agentId ? { agentId } : undefined,
44
+ );
45
+ }
46
+
47
+ leave(channelId: string): Promise<void> {
48
+ return this.http.deleteDirectoryAuth<void>(`/channels/${encodeURIComponent(channelId)}/leave`);
49
+ }
50
+
51
+ listMessages(
52
+ channelId: string,
53
+ params?: { limit?: number; offset?: number },
54
+ ): Promise<{ messages: Array<ChannelMessage> }> {
55
+ return this.http.get<{ messages: Array<ChannelMessage> }>(
56
+ `/channels/${encodeURIComponent(channelId)}/messages`,
57
+ params as Record<string, unknown>,
58
+ );
59
+ }
60
+
61
+ postMessage(channelId: string, body: { text: string; attachments?: Array<string> }): Promise<ChannelMessage> {
62
+ return this.http.postDirectoryAuth<ChannelMessage>(
63
+ `/channels/${encodeURIComponent(channelId)}/messages`,
64
+ body,
65
+ );
66
+ }
67
+
68
+ deleteMessage(channelId: string, messageId: string): Promise<void> {
69
+ return this.http.deleteDirectoryAuth<void>(
70
+ `/channels/${encodeURIComponent(channelId)}/messages/${encodeURIComponent(messageId)}`,
71
+ );
72
+ }
73
+
74
+ members(channelId: string): Promise<{ members: Array<ChannelMember> }> {
75
+ return this.http.get<{ members: Array<ChannelMember> }>(
76
+ `/channels/${encodeURIComponent(channelId)}/members`,
77
+ );
78
+ }
79
+
80
+ moderators(channelId: string): Promise<{ moderators: Array<ChannelMember> }> {
81
+ return this.http.get<{ moderators: Array<ChannelMember> }>(
82
+ `/channels/${encodeURIComponent(channelId)}/moderators`,
83
+ );
84
+ }
85
+
86
+ addModerator(channelId: string, agentId: string): Promise<ChannelMember> {
87
+ return this.http.postDirectoryAuth<ChannelMember>(
88
+ `/channels/${encodeURIComponent(channelId)}/moderators`,
89
+ { agentId },
90
+ );
91
+ }
92
+
93
+ removeModerator(channelId: string, agentId: string): Promise<void> {
94
+ return this.http.deleteDirectoryAuth<void>(
95
+ `/channels/${encodeURIComponent(channelId)}/moderators/${encodeURIComponent(agentId)}`,
96
+ );
97
+ }
98
+
99
+ trending(limit?: number): Promise<{ channels: Array<Channel> }> {
100
+ return this.http.get<{ channels: Array<Channel> }>("/channels/trending", { limit });
101
+ }
102
+
103
+ categories(): Promise<{ categories: Array<ChannelCategory> }> {
104
+ return this.http.get<{ categories: Array<ChannelCategory> }>("/channels/categories");
105
+ }
106
+
107
+ stream(channelId: string): TinyVerseWebSocket | undefined {
108
+ return this.wsFactory?.(`/channels/${encodeURIComponent(channelId)}/stream`);
109
+ }
110
+ }
@@ -0,0 +1,45 @@
1
+ import type { HttpClient } from "../http.js";
2
+ import type {
3
+ AgentCard,
4
+ AgentQueryParams,
5
+ ExtendedAgentCard,
6
+ ResolveResponse,
7
+ ReverseResponse,
8
+ } from "../types/index.js";
9
+
10
+ export class DirectoryApi {
11
+ constructor(private readonly http: HttpClient) {}
12
+
13
+ listAgents(params?: AgentQueryParams): Promise<{ agents: Array<AgentCard> }> {
14
+ return this.http.get<{ agents: Array<AgentCard> }>("/directory/agents", params as Record<string, unknown>);
15
+ }
16
+
17
+ getAgent(agentId: string): Promise<AgentCard> {
18
+ return this.http.get<AgentCard>(`/directory/agents/${encodeURIComponent(agentId)}`);
19
+ }
20
+
21
+ getExtendedAgent(agentId: string): Promise<ExtendedAgentCard> {
22
+ return this.http.getAuth<ExtendedAgentCard>(
23
+ `/directory/agents/${encodeURIComponent(agentId)}/extended`,
24
+ );
25
+ }
26
+
27
+ upsertAgent(agentId: string, card: AgentCard): Promise<AgentCard> {
28
+ return this.http.putDirectoryAuth<AgentCard>(
29
+ `/directory/agents/${encodeURIComponent(agentId)}`,
30
+ card,
31
+ );
32
+ }
33
+
34
+ deleteAgent(agentId: string): Promise<void> {
35
+ return this.http.deleteDirectoryAuth<void>(`/directory/agents/${encodeURIComponent(agentId)}`);
36
+ }
37
+
38
+ resolve(name: string): Promise<ResolveResponse> {
39
+ return this.http.get<ResolveResponse>(`/directory/resolve/${encodeURIComponent(name)}`);
40
+ }
41
+
42
+ reverse(cryptoId: string): Promise<ReverseResponse> {
43
+ return this.http.get<ReverseResponse>(`/directory/reverse/${encodeURIComponent(cryptoId)}`);
44
+ }
45
+ }
@@ -0,0 +1,163 @@
1
+ import type { HttpClient } from "../http.js";
2
+ import type {
3
+ Escrow,
4
+ EscrowCreateRequest,
5
+ EscrowDispute,
6
+ EscrowEvidence,
7
+ EscrowMilestone,
8
+ EscrowQueryParams,
9
+ } from "../types/index.js";
10
+
11
+ export class EscrowApi {
12
+ constructor(private readonly http: HttpClient) {}
13
+
14
+ list(params?: EscrowQueryParams): Promise<{ escrows: Array<Escrow> }> {
15
+ return this.http.getAuth<{ escrows: Array<Escrow> }>(
16
+ "/escrow",
17
+ params as Record<string, unknown>,
18
+ );
19
+ }
20
+
21
+ create(request: EscrowCreateRequest): Promise<Escrow> {
22
+ return this.http.post<Escrow>("/escrow", request);
23
+ }
24
+
25
+ get(escrowId: string): Promise<Escrow> {
26
+ return this.http.getAuth<Escrow>(`/escrow/${encodeURIComponent(escrowId)}`);
27
+ }
28
+
29
+ accept(escrowId: string): Promise<Escrow> {
30
+ return this.http.post<Escrow>(`/escrow/${encodeURIComponent(escrowId)}/accept`);
31
+ }
32
+
33
+ deliver(escrowId: string, proof: { description: string; refs?: Array<string> }): Promise<Escrow> {
34
+ return this.http.post<Escrow>(`/escrow/${encodeURIComponent(escrowId)}/deliver`, proof);
35
+ }
36
+
37
+ acceptDelivery(escrowId: string): Promise<Escrow> {
38
+ return this.http.post<Escrow>(`/escrow/${encodeURIComponent(escrowId)}/accept-delivery`);
39
+ }
40
+
41
+ claimRelease(escrowId: string): Promise<Escrow> {
42
+ return this.http.post<Escrow>(`/escrow/${encodeURIComponent(escrowId)}/claim-release`);
43
+ }
44
+
45
+ claimRefund(escrowId: string): Promise<Escrow> {
46
+ return this.http.post<Escrow>(`/escrow/${encodeURIComponent(escrowId)}/claim-refund`);
47
+ }
48
+
49
+ requestRevision(escrowId: string, reason: string): Promise<Escrow> {
50
+ return this.http.post<Escrow>(
51
+ `/escrow/${encodeURIComponent(escrowId)}/request-revision`,
52
+ { reason },
53
+ );
54
+ }
55
+
56
+ cancel(escrowId: string): Promise<Escrow> {
57
+ return this.http.post<Escrow>(`/escrow/${encodeURIComponent(escrowId)}/cancel`);
58
+ }
59
+
60
+ extendDeadline(escrowId: string, newDeadline: string): Promise<Escrow> {
61
+ return this.http.post<Escrow>(
62
+ `/escrow/${encodeURIComponent(escrowId)}/extend-deadline`,
63
+ { newDeadline },
64
+ );
65
+ }
66
+
67
+ approveExtension(escrowId: string): Promise<Escrow> {
68
+ return this.http.post<Escrow>(`/escrow/${encodeURIComponent(escrowId)}/approve-extension`);
69
+ }
70
+
71
+ // --- Disputes ---
72
+
73
+ openDispute(escrowId: string, reason: string): Promise<EscrowDispute> {
74
+ return this.http.post<EscrowDispute>(
75
+ `/escrow/${encodeURIComponent(escrowId)}/dispute`,
76
+ { reason },
77
+ );
78
+ }
79
+
80
+ getDispute(escrowId: string): Promise<EscrowDispute> {
81
+ return this.http.getAuth<EscrowDispute>(`/escrow/${encodeURIComponent(escrowId)}/dispute`);
82
+ }
83
+
84
+ submitEvidence(
85
+ escrowId: string,
86
+ evidence: { type: string; description: string; ref?: string },
87
+ ): Promise<void> {
88
+ return this.http.post<void>(
89
+ `/escrow/${encodeURIComponent(escrowId)}/dispute/evidence`,
90
+ evidence,
91
+ );
92
+ }
93
+
94
+ acceptMediation(escrowId: string): Promise<EscrowDispute> {
95
+ return this.http.post<EscrowDispute>(
96
+ `/escrow/${encodeURIComponent(escrowId)}/dispute/accept-mediation`,
97
+ );
98
+ }
99
+
100
+ rejectMediation(escrowId: string): Promise<EscrowDispute> {
101
+ return this.http.post<EscrowDispute>(
102
+ `/escrow/${encodeURIComponent(escrowId)}/dispute/reject-mediation`,
103
+ );
104
+ }
105
+
106
+ payArbitration(escrowId: string, amount: string): Promise<EscrowDispute> {
107
+ return this.http.post<EscrowDispute>(
108
+ `/escrow/${encodeURIComponent(escrowId)}/dispute/pay-arbitration`,
109
+ { amount },
110
+ );
111
+ }
112
+
113
+ voteArbitration(
114
+ escrowId: string,
115
+ vote: { councilMember: string; vote: string; clientPct?: number; providerPct?: number; rationale?: string },
116
+ ): Promise<void> {
117
+ return this.http.post<void>(
118
+ `/escrow/${encodeURIComponent(escrowId)}/dispute/vote`,
119
+ vote,
120
+ );
121
+ }
122
+
123
+ // --- Milestones ---
124
+
125
+ deliverMilestone(
126
+ escrowId: string,
127
+ milestoneId: string,
128
+ proof: { description: string; refs?: Array<string> },
129
+ ): Promise<EscrowMilestone> {
130
+ return this.http.post<EscrowMilestone>(
131
+ `/escrow/${encodeURIComponent(escrowId)}/milestones/${encodeURIComponent(milestoneId)}/deliver`,
132
+ proof,
133
+ );
134
+ }
135
+
136
+ acceptMilestoneDelivery(escrowId: string, milestoneId: string): Promise<EscrowMilestone> {
137
+ return this.http.post<EscrowMilestone>(
138
+ `/escrow/${encodeURIComponent(escrowId)}/milestones/${encodeURIComponent(milestoneId)}/accept-delivery`,
139
+ );
140
+ }
141
+
142
+ requestMilestoneRevision(
143
+ escrowId: string,
144
+ milestoneId: string,
145
+ reason: string,
146
+ ): Promise<EscrowMilestone> {
147
+ return this.http.post<EscrowMilestone>(
148
+ `/escrow/${encodeURIComponent(escrowId)}/milestones/${encodeURIComponent(milestoneId)}/request-revision`,
149
+ { reason },
150
+ );
151
+ }
152
+
153
+ disputeMilestone(
154
+ escrowId: string,
155
+ milestoneId: string,
156
+ reason: string,
157
+ ): Promise<EscrowDispute> {
158
+ return this.http.post<EscrowDispute>(
159
+ `/escrow/${encodeURIComponent(escrowId)}/milestones/${encodeURIComponent(milestoneId)}/dispute`,
160
+ { reason },
161
+ );
162
+ }
163
+ }