dpth 0.3.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 (54) hide show
  1. package/README.md +101 -148
  2. package/dist/adapter-sqlite.d.ts +17 -2
  3. package/dist/adapter-sqlite.d.ts.map +1 -1
  4. package/dist/adapter-sqlite.js +127 -16
  5. package/dist/adapter-sqlite.js.map +1 -1
  6. package/dist/dpth.d.ts +35 -2
  7. package/dist/dpth.d.ts.map +1 -1
  8. package/dist/dpth.js +157 -49
  9. package/dist/dpth.js.map +1 -1
  10. package/dist/entity.d.ts +1 -0
  11. package/dist/entity.d.ts.map +1 -1
  12. package/dist/entity.js +21 -5
  13. package/dist/entity.js.map +1 -1
  14. package/dist/errors.d.ts +43 -0
  15. package/dist/errors.d.ts.map +1 -0
  16. package/dist/errors.js +63 -0
  17. package/dist/errors.js.map +1 -0
  18. package/dist/experimental/agent-sdk.d.ts +157 -0
  19. package/dist/experimental/agent-sdk.d.ts.map +1 -0
  20. package/dist/experimental/agent-sdk.js +367 -0
  21. package/dist/experimental/agent-sdk.js.map +1 -0
  22. package/dist/experimental/economics.d.ts +203 -0
  23. package/dist/experimental/economics.d.ts.map +1 -0
  24. package/dist/experimental/economics.js +510 -0
  25. package/dist/experimental/economics.js.map +1 -0
  26. package/dist/experimental/fallback.d.ts +104 -0
  27. package/dist/experimental/fallback.d.ts.map +1 -0
  28. package/dist/experimental/fallback.js +359 -0
  29. package/dist/experimental/fallback.js.map +1 -0
  30. package/dist/experimental/federation.d.ts +224 -0
  31. package/dist/experimental/federation.d.ts.map +1 -0
  32. package/dist/experimental/federation.js +377 -0
  33. package/dist/experimental/federation.js.map +1 -0
  34. package/dist/experimental/index.d.ts +20 -0
  35. package/dist/experimental/index.d.ts.map +1 -0
  36. package/dist/experimental/index.js +20 -0
  37. package/dist/experimental/index.js.map +1 -0
  38. package/dist/index.d.ts +14 -14
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +13 -14
  41. package/dist/index.js.map +1 -1
  42. package/dist/storage.d.ts +10 -11
  43. package/dist/storage.d.ts.map +1 -1
  44. package/dist/storage.js +4 -11
  45. package/dist/storage.js.map +1 -1
  46. package/dist/types.d.ts +16 -1
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/types.js +11 -1
  49. package/dist/types.js.map +1 -1
  50. package/dist/util.d.ts +20 -0
  51. package/dist/util.d.ts.map +1 -0
  52. package/dist/util.js +28 -0
  53. package/dist/util.js.map +1 -0
  54. package/package.json +13 -25
package/dist/errors.js ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * dpth — Error Classes
3
+ *
4
+ * Custom errors with codes for programmatic handling.
5
+ * Every error includes a descriptive message explaining what went wrong
6
+ * and what to do about it.
7
+ */
8
+ export class DpthError extends Error {
9
+ code;
10
+ constructor(code, message) {
11
+ super(message);
12
+ this.name = 'DpthError';
13
+ this.code = code;
14
+ }
15
+ }
16
+ /**
17
+ * Thrown when required arguments are missing or invalid.
18
+ */
19
+ export class ValidationError extends DpthError {
20
+ constructor(message) {
21
+ super('VALIDATION_ERROR', message);
22
+ this.name = 'ValidationError';
23
+ }
24
+ }
25
+ /**
26
+ * Thrown when an entity is not found.
27
+ */
28
+ export class EntityNotFoundError extends DpthError {
29
+ entityId;
30
+ constructor(entityId) {
31
+ super('ENTITY_NOT_FOUND', `Entity '${entityId}' not found`);
32
+ this.name = 'EntityNotFoundError';
33
+ this.entityId = entityId;
34
+ }
35
+ }
36
+ /**
37
+ * Thrown when a storage operation fails.
38
+ */
39
+ export class StorageError extends DpthError {
40
+ constructor(message) {
41
+ super('STORAGE_ERROR', message);
42
+ this.name = 'StorageError';
43
+ }
44
+ }
45
+ /**
46
+ * Thrown when insufficient data exists for an operation.
47
+ */
48
+ export class InsufficientDataError extends DpthError {
49
+ constructor(message) {
50
+ super('INSUFFICIENT_DATA', message);
51
+ this.name = 'InsufficientDataError';
52
+ }
53
+ }
54
+ /**
55
+ * Thrown when a feature requires a capability the current adapter doesn't support.
56
+ */
57
+ export class AdapterCapabilityError extends DpthError {
58
+ constructor(feature, requirement) {
59
+ super('ADAPTER_CAPABILITY', `${feature} requires ${requirement}`);
60
+ this.name = 'AdapterCapabilityError';
61
+ }
62
+ }
63
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClB,IAAI,CAAS;IAE7B,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAChC,QAAQ,CAAS;IAEjC,YAAY,QAAgB;QAC1B,KAAK,CAAC,kBAAkB,EAAE,WAAW,QAAQ,aAAa,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,SAAS;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,SAAS;IACnD,YAAY,OAAe,EAAE,WAAmB;QAC9C,KAAK,CAAC,oBAAoB,EAAE,GAAG,OAAO,aAAa,WAAW,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * dpth.io Agent SDK
3
+ *
4
+ * Simple client for agents to participate in the dpth.io network.
5
+ * Handles registration, heartbeat, task claiming, and result submission.
6
+ *
7
+ * Usage:
8
+ * const agent = new DpthAgent({
9
+ * name: 'my-agent',
10
+ * apiUrl: 'https://fathom.gib.lol/api/dpth',
11
+ * capabilities: { storageCapacityMb: 1000, cpuCores: 4, ... }
12
+ * });
13
+ *
14
+ * await agent.register();
15
+ * await agent.startWorking();
16
+ */
17
+ export interface AgentCapabilities {
18
+ storageCapacityMb: number;
19
+ cpuCores: number;
20
+ hasGpu: boolean;
21
+ gpuVramMb?: number;
22
+ taskTypes: ('embed' | 'correlate' | 'extract' | 'analyze' | 'inference')[];
23
+ }
24
+ export interface AgentConfig {
25
+ name: string;
26
+ apiUrl: string;
27
+ capabilities: AgentCapabilities;
28
+ /** Private key for signing (generated if not provided) */
29
+ privateKey?: string;
30
+ /** Polling interval in ms (default: 5000) */
31
+ pollIntervalMs?: number;
32
+ /** Task handlers by type */
33
+ handlers?: Partial<Record<string, TaskHandler>>;
34
+ }
35
+ export interface Task {
36
+ id: string;
37
+ type: string;
38
+ priority: string;
39
+ input: {
40
+ cid?: string;
41
+ data?: unknown;
42
+ params?: Record<string, unknown>;
43
+ };
44
+ deadline?: string;
45
+ }
46
+ export type TaskHandler = (task: Task) => Promise<TaskResult>;
47
+ export interface TaskResult {
48
+ success: boolean;
49
+ output?: {
50
+ cid?: string;
51
+ data?: unknown;
52
+ };
53
+ error?: string;
54
+ }
55
+ export declare class DpthAgent {
56
+ private config;
57
+ private agentId;
58
+ private publicKey;
59
+ private privateKey;
60
+ private running;
61
+ private pollTimeout;
62
+ constructor(config: AgentConfig);
63
+ private derivePublicKey;
64
+ /**
65
+ * Get a header-safe version of the public key (base64, no PEM wrapping)
66
+ */
67
+ private getHeaderSafeKey;
68
+ private fetch;
69
+ /**
70
+ * Register this agent with the network
71
+ */
72
+ register(): Promise<void>;
73
+ /**
74
+ * Deregister from the network
75
+ */
76
+ deregister(): Promise<void>;
77
+ /**
78
+ * Fetch available tasks
79
+ */
80
+ getTasks(limit?: number): Promise<Task[]>;
81
+ /**
82
+ * Claim a task for processing
83
+ */
84
+ claimTask(taskId: string): Promise<Task>;
85
+ /**
86
+ * Complete a task with results
87
+ */
88
+ completeTask(taskId: string, result: TaskResult): Promise<void>;
89
+ /**
90
+ * Store a chunk, returns CID
91
+ */
92
+ storeChunk(data: unknown): Promise<string>;
93
+ /**
94
+ * Retrieve a chunk by CID
95
+ */
96
+ getChunk(cid: string): Promise<unknown>;
97
+ /**
98
+ * Get pending storage proof challenges for this agent
99
+ */
100
+ getPendingChallenges(): Promise<Array<{
101
+ id: string;
102
+ cid: string;
103
+ nonce: string;
104
+ expiresAt: string;
105
+ }>>;
106
+ /**
107
+ * Submit a storage proof response
108
+ * @param challengeId The challenge ID
109
+ * @param proof SHA256(chunk_data + nonce)
110
+ */
111
+ submitProof(challengeId: string, proof: string): Promise<{
112
+ valid: boolean;
113
+ stats: {
114
+ successRate: number;
115
+ };
116
+ }>;
117
+ /**
118
+ * Generate a proof for a chunk + nonce
119
+ * (Agents should use this to compute proofs from their local storage)
120
+ */
121
+ static computeProof(chunkData: string, nonce: string): string;
122
+ /**
123
+ * Start the work loop — continuously poll for and process tasks
124
+ */
125
+ startWorking(): Promise<void>;
126
+ /**
127
+ * Stop the work loop
128
+ */
129
+ stopWorking(): void;
130
+ private pollLoop;
131
+ private processTask;
132
+ /**
133
+ * Get the agent's public key (for verification)
134
+ */
135
+ getPublicKey(): string;
136
+ /**
137
+ * Get the agent's ID (after registration)
138
+ */
139
+ getAgentId(): string | null;
140
+ /**
141
+ * Check if agent is registered
142
+ */
143
+ isRegistered(): boolean;
144
+ /**
145
+ * Check if work loop is running
146
+ */
147
+ isWorking(): boolean;
148
+ }
149
+ /**
150
+ * Default embedding handler using OpenAI-compatible API
151
+ */
152
+ export declare function createEmbedHandler(apiKey: string, model?: string): TaskHandler;
153
+ /**
154
+ * Default extraction handler (simple regex-based)
155
+ */
156
+ export declare function createExtractHandler(): TaskHandler;
157
+ //# sourceMappingURL=agent-sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-sdk.d.ts","sourceRoot":"","sources":["../../src/experimental/agent-sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,CAAC,OAAO,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC;CAC5E;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,iBAAiB,CAAC;IAChC,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KA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OAAO,CAAC,MAAM,CAAC;IAchD;;OAEG;IACG,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU7C;;OAEG;IACG,oBAAoB,IAAI,OAAO,CAAC,KAAK,CAAC;QAC1C,EAAE,EAAE,MAAM,CAAC;QACX,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;IAWH;;;;OAIG;IACG,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAC7D,KAAK,EAAE,OAAO,CAAC;QACf,KAAK,EAAE;YAAE,WAAW,EAAE,MAAM,CAAA;SAAE,CAAC;KAChC,CAAC;IAkBF;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAY7D;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAYnC;;OAEG;IACH,WAAW,IAAI,IAAI;YASL,QAAQ;YAsBR,WAAW;IAkCzB;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,UAAU,IAAI,MAAM,GAAG,IAAI;IAI3B;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;OAEG;IACH,SAAS,IAAI,OAAO;CAGrB;AAID;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAA2B,GAAG,WAAW,CA4BhG;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,WAAW,CAqBlD"}
@@ -0,0 +1,367 @@
1
+ /**
2
+ * dpth.io Agent SDK
3
+ *
4
+ * Simple client for agents to participate in the dpth.io network.
5
+ * Handles registration, heartbeat, task claiming, and result submission.
6
+ *
7
+ * Usage:
8
+ * const agent = new DpthAgent({
9
+ * name: 'my-agent',
10
+ * apiUrl: 'https://fathom.gib.lol/api/dpth',
11
+ * capabilities: { storageCapacityMb: 1000, cpuCores: 4, ... }
12
+ * });
13
+ *
14
+ * await agent.register();
15
+ * await agent.startWorking();
16
+ */
17
+ import { createHash, generateKeyPairSync } from 'crypto';
18
+ // ─── Agent Class ─────────────────────────────────────
19
+ export class DpthAgent {
20
+ config;
21
+ agentId = null;
22
+ publicKey;
23
+ privateKey;
24
+ running = false;
25
+ pollTimeout = null;
26
+ constructor(config) {
27
+ // Generate key pair if not provided
28
+ if (config.privateKey) {
29
+ this.privateKey = config.privateKey;
30
+ // Derive public key from private
31
+ this.publicKey = this.derivePublicKey(config.privateKey);
32
+ }
33
+ else {
34
+ const { publicKey, privateKey } = generateKeyPairSync('ed25519');
35
+ this.privateKey = privateKey.export({ type: 'pkcs8', format: 'pem' });
36
+ this.publicKey = publicKey.export({ type: 'spki', format: 'pem' });
37
+ }
38
+ this.config = {
39
+ ...config,
40
+ privateKey: this.privateKey,
41
+ pollIntervalMs: config.pollIntervalMs || 5000,
42
+ handlers: config.handlers || {},
43
+ };
44
+ }
45
+ derivePublicKey(privateKeyPem) {
46
+ // For ed25519, derive a compact public key identifier
47
+ const hash = createHash('sha256').update(privateKeyPem).digest('hex');
48
+ return `dpth:pub:${hash.slice(0, 32)}`;
49
+ }
50
+ /**
51
+ * Get a header-safe version of the public key (base64, no PEM wrapping)
52
+ */
53
+ getHeaderSafeKey() {
54
+ // Strip PEM headers and newlines for HTTP header compatibility
55
+ return this.publicKey
56
+ .replace(/-----BEGIN.*?-----/g, '')
57
+ .replace(/-----END.*?-----/g, '')
58
+ .replace(/\n/g, '')
59
+ .trim();
60
+ }
61
+ // ─── API Methods ─────────────────────────────────
62
+ async fetch(path, options) {
63
+ const url = `${this.config.apiUrl}${path}`;
64
+ const response = await fetch(url, {
65
+ ...options,
66
+ headers: {
67
+ 'Content-Type': 'application/json',
68
+ 'X-Agent-Id': this.agentId || '',
69
+ 'X-Public-Key': this.getHeaderSafeKey(),
70
+ ...options?.headers,
71
+ },
72
+ });
73
+ return response;
74
+ }
75
+ /**
76
+ * Register this agent with the network
77
+ */
78
+ async register() {
79
+ const response = await this.fetch('/agents', {
80
+ method: 'POST',
81
+ body: JSON.stringify({
82
+ name: this.config.name,
83
+ publicKey: this.publicKey,
84
+ capabilities: this.config.capabilities,
85
+ }),
86
+ });
87
+ if (!response.ok) {
88
+ const error = await response.json();
89
+ throw new Error(`Registration failed: ${error.error || response.statusText}`);
90
+ }
91
+ const result = await response.json();
92
+ this.agentId = result.agent.id;
93
+ console.log(`[dpth] Agent registered: ${this.agentId}`);
94
+ }
95
+ /**
96
+ * Deregister from the network
97
+ */
98
+ async deregister() {
99
+ if (!this.agentId)
100
+ return;
101
+ await this.fetch(`/agents?id=${this.agentId}`, {
102
+ method: 'DELETE',
103
+ });
104
+ this.agentId = null;
105
+ console.log('[dpth] Agent deregistered');
106
+ }
107
+ /**
108
+ * Fetch available tasks
109
+ */
110
+ async getTasks(limit = 10) {
111
+ const types = this.config.capabilities.taskTypes.join(',');
112
+ const response = await this.fetch(`/tasks?limit=${limit}&type=${types}`);
113
+ if (!response.ok) {
114
+ throw new Error('Failed to fetch tasks');
115
+ }
116
+ const result = await response.json();
117
+ return result.tasks;
118
+ }
119
+ /**
120
+ * Claim a task for processing
121
+ */
122
+ async claimTask(taskId) {
123
+ const response = await this.fetch('/tasks?action=claim', {
124
+ method: 'POST',
125
+ body: JSON.stringify({
126
+ taskId,
127
+ agentId: this.agentId,
128
+ }),
129
+ });
130
+ if (!response.ok) {
131
+ const error = await response.json();
132
+ throw new Error(`Failed to claim task: ${error.error}`);
133
+ }
134
+ const result = await response.json();
135
+ return result.task;
136
+ }
137
+ /**
138
+ * Complete a task with results
139
+ */
140
+ async completeTask(taskId, result) {
141
+ const response = await this.fetch('/tasks?action=complete', {
142
+ method: 'POST',
143
+ body: JSON.stringify({
144
+ taskId,
145
+ agentId: this.agentId,
146
+ success: result.success,
147
+ output: result.output,
148
+ }),
149
+ });
150
+ if (!response.ok) {
151
+ throw new Error('Failed to complete task');
152
+ }
153
+ }
154
+ /**
155
+ * Store a chunk, returns CID
156
+ */
157
+ async storeChunk(data) {
158
+ const response = await this.fetch('/storage', {
159
+ method: 'POST',
160
+ body: JSON.stringify(data),
161
+ });
162
+ if (!response.ok) {
163
+ throw new Error('Failed to store chunk');
164
+ }
165
+ const result = await response.json();
166
+ return result.cid;
167
+ }
168
+ /**
169
+ * Retrieve a chunk by CID
170
+ */
171
+ async getChunk(cid) {
172
+ const response = await this.fetch(`/storage?cid=${cid}`);
173
+ if (!response.ok) {
174
+ throw new Error('Chunk not found');
175
+ }
176
+ return response.json();
177
+ }
178
+ /**
179
+ * Get pending storage proof challenges for this agent
180
+ */
181
+ async getPendingChallenges() {
182
+ const response = await this.fetch('/proofs?pending');
183
+ if (!response.ok) {
184
+ throw new Error('Failed to get pending challenges');
185
+ }
186
+ const result = await response.json();
187
+ return result.pending.filter((c) => c.agentId === this.agentId);
188
+ }
189
+ /**
190
+ * Submit a storage proof response
191
+ * @param challengeId The challenge ID
192
+ * @param proof SHA256(chunk_data + nonce)
193
+ */
194
+ async submitProof(challengeId, proof) {
195
+ const response = await this.fetch('/proofs?action=respond', {
196
+ method: 'POST',
197
+ body: JSON.stringify({
198
+ challengeId,
199
+ agentId: this.agentId,
200
+ proof,
201
+ }),
202
+ });
203
+ if (!response.ok) {
204
+ const error = await response.json();
205
+ throw new Error(`Proof submission failed: ${error.error}`);
206
+ }
207
+ return response.json();
208
+ }
209
+ /**
210
+ * Generate a proof for a chunk + nonce
211
+ * (Agents should use this to compute proofs from their local storage)
212
+ */
213
+ static computeProof(chunkData, nonce) {
214
+ // In browser/Node environments, use Web Crypto or Node crypto
215
+ // This is a placeholder - agents implement their own
216
+ const encoder = new TextEncoder();
217
+ const data = encoder.encode(chunkData + nonce);
218
+ // Note: Real implementation needs async crypto
219
+ // This is just to show the interface
220
+ throw new Error('Implement with crypto.subtle.digest or createHash');
221
+ }
222
+ // ─── Worker Loop ─────────────────────────────────
223
+ /**
224
+ * Start the work loop — continuously poll for and process tasks
225
+ */
226
+ async startWorking() {
227
+ if (this.running)
228
+ return;
229
+ if (!this.agentId) {
230
+ await this.register();
231
+ }
232
+ this.running = true;
233
+ console.log('[dpth] Starting work loop');
234
+ this.pollLoop();
235
+ }
236
+ /**
237
+ * Stop the work loop
238
+ */
239
+ stopWorking() {
240
+ this.running = false;
241
+ if (this.pollTimeout) {
242
+ clearTimeout(this.pollTimeout);
243
+ this.pollTimeout = null;
244
+ }
245
+ console.log('[dpth] Stopped work loop');
246
+ }
247
+ async pollLoop() {
248
+ if (!this.running)
249
+ return;
250
+ try {
251
+ // Fetch available tasks
252
+ const tasks = await this.getTasks(1);
253
+ if (tasks.length > 0) {
254
+ const task = tasks[0];
255
+ await this.processTask(task);
256
+ }
257
+ }
258
+ catch (error) {
259
+ console.error('[dpth] Error in poll loop:', error);
260
+ }
261
+ // Schedule next poll
262
+ this.pollTimeout = setTimeout(() => this.pollLoop(), this.config.pollIntervalMs);
263
+ }
264
+ async processTask(task) {
265
+ console.log(`[dpth] Processing task ${task.id} (${task.type})`);
266
+ try {
267
+ // Claim the task
268
+ const claimed = await this.claimTask(task.id);
269
+ // Get handler for task type
270
+ const handler = this.config.handlers[task.type];
271
+ if (!handler) {
272
+ throw new Error(`No handler for task type: ${task.type}`);
273
+ }
274
+ // Execute handler
275
+ const result = await handler(claimed);
276
+ // Complete the task
277
+ await this.completeTask(task.id, result);
278
+ console.log(`[dpth] Completed task ${task.id}`);
279
+ }
280
+ catch (error) {
281
+ console.error(`[dpth] Task ${task.id} failed:`, error);
282
+ // Report failure
283
+ await this.completeTask(task.id, {
284
+ success: false,
285
+ error: error instanceof Error ? error.message : 'Unknown error',
286
+ });
287
+ }
288
+ }
289
+ // ─── Utilities ───────────────────────────────────
290
+ /**
291
+ * Get the agent's public key (for verification)
292
+ */
293
+ getPublicKey() {
294
+ return this.publicKey;
295
+ }
296
+ /**
297
+ * Get the agent's ID (after registration)
298
+ */
299
+ getAgentId() {
300
+ return this.agentId;
301
+ }
302
+ /**
303
+ * Check if agent is registered
304
+ */
305
+ isRegistered() {
306
+ return this.agentId !== null;
307
+ }
308
+ /**
309
+ * Check if work loop is running
310
+ */
311
+ isWorking() {
312
+ return this.running;
313
+ }
314
+ }
315
+ // ─── Built-in Task Handlers ──────────────────────────
316
+ /**
317
+ * Default embedding handler using OpenAI-compatible API
318
+ */
319
+ export function createEmbedHandler(apiKey, model = 'text-embedding-3-small') {
320
+ return async (task) => {
321
+ const text = task.input.data;
322
+ const response = await fetch('https://api.openai.com/v1/embeddings', {
323
+ method: 'POST',
324
+ headers: {
325
+ 'Authorization': `Bearer ${apiKey}`,
326
+ 'Content-Type': 'application/json',
327
+ },
328
+ body: JSON.stringify({
329
+ model,
330
+ input: text,
331
+ }),
332
+ });
333
+ if (!response.ok) {
334
+ throw new Error(`Embedding API failed: ${response.statusText}`);
335
+ }
336
+ const result = await response.json();
337
+ return {
338
+ success: true,
339
+ output: {
340
+ data: result.data[0].embedding,
341
+ },
342
+ };
343
+ };
344
+ }
345
+ /**
346
+ * Default extraction handler (simple regex-based)
347
+ */
348
+ export function createExtractHandler() {
349
+ return async (task) => {
350
+ const text = task.input.data;
351
+ // Simple email extraction
352
+ const emails = text.match(/[\w.-]+@[\w.-]+\.\w+/g) || [];
353
+ // Simple number extraction
354
+ const numbers = text.match(/\$?[\d,]+\.?\d*/g) || [];
355
+ return {
356
+ success: true,
357
+ output: {
358
+ data: {
359
+ emails,
360
+ numbers,
361
+ length: text.length,
362
+ },
363
+ },
364
+ };
365
+ };
366
+ }
367
+ //# sourceMappingURL=agent-sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-sdk.js","sourceRoot":"","sources":["../../src/experimental/agent-sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAgB,MAAM,QAAQ,CAAC;AA+CvE,wDAAwD;AAExD,MAA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