@lawreneliang/atel-sdk 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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +221 -0
  3. package/dist/anchor/base.d.ts +21 -0
  4. package/dist/anchor/base.js +26 -0
  5. package/dist/anchor/bsc.d.ts +20 -0
  6. package/dist/anchor/bsc.js +25 -0
  7. package/dist/anchor/evm.d.ts +67 -0
  8. package/dist/anchor/evm.js +176 -0
  9. package/dist/anchor/index.d.ts +173 -0
  10. package/dist/anchor/index.js +165 -0
  11. package/dist/anchor/mock.d.ts +43 -0
  12. package/dist/anchor/mock.js +100 -0
  13. package/dist/anchor/solana.d.ts +62 -0
  14. package/dist/anchor/solana.js +190 -0
  15. package/dist/gateway/index.d.ts +278 -0
  16. package/dist/gateway/index.js +520 -0
  17. package/dist/graph/index.d.ts +215 -0
  18. package/dist/graph/index.js +524 -0
  19. package/dist/identity/index.d.ts +114 -0
  20. package/dist/identity/index.js +178 -0
  21. package/dist/index.d.ts +14 -0
  22. package/dist/index.js +16 -0
  23. package/dist/orchestrator/index.d.ts +190 -0
  24. package/dist/orchestrator/index.js +297 -0
  25. package/dist/policy/index.d.ts +100 -0
  26. package/dist/policy/index.js +206 -0
  27. package/dist/proof/index.d.ts +220 -0
  28. package/dist/proof/index.js +541 -0
  29. package/dist/rollback/index.d.ts +76 -0
  30. package/dist/rollback/index.js +91 -0
  31. package/dist/schema/capability-schema.json +52 -0
  32. package/dist/schema/index.d.ts +128 -0
  33. package/dist/schema/index.js +163 -0
  34. package/dist/schema/task-schema.json +69 -0
  35. package/dist/score/index.d.ts +132 -0
  36. package/dist/score/index.js +202 -0
  37. package/dist/service/index.d.ts +34 -0
  38. package/dist/service/index.js +273 -0
  39. package/dist/service/server.d.ts +7 -0
  40. package/dist/service/server.js +22 -0
  41. package/dist/trace/index.d.ts +217 -0
  42. package/dist/trace/index.js +446 -0
  43. package/dist/trust/index.d.ts +84 -0
  44. package/dist/trust/index.js +107 -0
  45. package/dist/trust-sync/index.d.ts +30 -0
  46. package/dist/trust-sync/index.js +57 -0
  47. package/package.json +59 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Module: Trust Manager
3
+ *
4
+ * Unified trust management combining TrustScoreClient and TrustGraph.
5
+ * Provides a single entry point for submitting execution results and
6
+ * querying comprehensive trust information.
7
+ */
8
+ import { TrustScoreClient, type ExecutionSummary, type ScoreReport } from '../score/index.js';
9
+ import { TrustGraph, type TrustResult } from '../graph/index.js';
10
+ /** Extended execution summary that includes issuer for graph updates */
11
+ export interface TrustSubmission extends ExecutionSummary {
12
+ /** DID of the agent that delegated the task (issuer) */
13
+ issuer: string;
14
+ /** Scene/category for graph classification (defaults to task_type) */
15
+ scene?: string;
16
+ /** Max cost of the task (used for weight calculation) */
17
+ max_cost?: number;
18
+ /** Number of similar tasks previously executed (for novelty) */
19
+ similar_task_count?: number;
20
+ }
21
+ /** Comprehensive trust query result */
22
+ export interface ComprehensiveTrust {
23
+ /** Trust score from the graph (0–1 range, composite) */
24
+ graphTrust: TrustResult;
25
+ /** Score report from the score client (0–100 range) */
26
+ scoreReport: ScoreReport;
27
+ /** Combined trust score (normalized 0–1) */
28
+ combinedScore: number;
29
+ }
30
+ /**
31
+ * Unified trust manager that coordinates TrustScoreClient and TrustGraph.
32
+ *
33
+ * Provides:
34
+ * - `submitResult()` — updates both score and graph in one call
35
+ * - `queryTrust()` — returns comprehensive trust combining both systems
36
+ */
37
+ export declare class TrustManager {
38
+ /** The underlying score client */
39
+ readonly scoreClient: TrustScoreClient;
40
+ /** The underlying trust graph */
41
+ readonly graph: TrustGraph;
42
+ constructor(options?: {
43
+ scoreClient?: TrustScoreClient;
44
+ graph?: TrustGraph;
45
+ });
46
+ /**
47
+ * Submit an execution result, updating both the score client and trust graph.
48
+ *
49
+ * @param submission - The execution result with issuer information.
50
+ */
51
+ submitResult(submission: TrustSubmission): void;
52
+ /**
53
+ * Query comprehensive trust between two agents for a given scene.
54
+ *
55
+ * Combines graph-based trust (composite) with score-based reputation
56
+ * into a single normalized score.
57
+ *
58
+ * @param from - The querying agent's DID.
59
+ * @param to - The target agent's DID.
60
+ * @param scene - The scene/category to query trust for.
61
+ * @returns Comprehensive trust information.
62
+ */
63
+ queryTrust(from: string, to: string, scene: string): ComprehensiveTrust;
64
+ /**
65
+ * Get the score report for a specific agent.
66
+ *
67
+ * @param agentId - The agent's DID.
68
+ * @returns The score report.
69
+ */
70
+ getAgentScore(agentId: string): ScoreReport;
71
+ /**
72
+ * Get the graph trust between two agents.
73
+ *
74
+ * @param from - Source agent DID.
75
+ * @param to - Target agent DID.
76
+ * @param scene - Scene/category.
77
+ * @returns Trust result from the graph.
78
+ */
79
+ getGraphTrust(from: string, to: string, scene: string): TrustResult;
80
+ /**
81
+ * Estimate max_cost from risk level for weight calculation.
82
+ */
83
+ private _estimateCost;
84
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Module: Trust Manager
3
+ *
4
+ * Unified trust management combining TrustScoreClient and TrustGraph.
5
+ * Provides a single entry point for submitting execution results and
6
+ * querying comprehensive trust information.
7
+ */
8
+ import { TrustScoreClient, } from '../score/index.js';
9
+ import { TrustGraph, calculateTaskWeight, } from '../graph/index.js';
10
+ // ─── TrustManager ────────────────────────────────────────────────
11
+ /**
12
+ * Unified trust manager that coordinates TrustScoreClient and TrustGraph.
13
+ *
14
+ * Provides:
15
+ * - `submitResult()` — updates both score and graph in one call
16
+ * - `queryTrust()` — returns comprehensive trust combining both systems
17
+ */
18
+ export class TrustManager {
19
+ /** The underlying score client */
20
+ scoreClient;
21
+ /** The underlying trust graph */
22
+ graph;
23
+ constructor(options) {
24
+ this.scoreClient = options?.scoreClient ?? new TrustScoreClient();
25
+ this.graph = options?.graph ?? new TrustGraph();
26
+ }
27
+ /**
28
+ * Submit an execution result, updating both the score client and trust graph.
29
+ *
30
+ * @param submission - The execution result with issuer information.
31
+ */
32
+ submitResult(submission) {
33
+ // 1. Submit to TrustScoreClient
34
+ this.scoreClient.submitExecutionSummary(submission);
35
+ // 2. Calculate task weight for graph
36
+ const taskWeight = calculateTaskWeight({
37
+ tool_calls: submission.tool_calls,
38
+ duration_ms: submission.duration_ms,
39
+ max_cost: submission.max_cost ?? this._estimateCost(submission.risk_level),
40
+ risk_level: submission.risk_level,
41
+ similar_task_count: submission.similar_task_count ?? 0,
42
+ });
43
+ // 3. Update TrustGraph
44
+ this.graph.recordInteraction({
45
+ from: submission.issuer,
46
+ to: submission.executor,
47
+ scene: submission.scene ?? submission.task_type,
48
+ success: submission.success,
49
+ task_weight: taskWeight,
50
+ duration_ms: submission.duration_ms,
51
+ });
52
+ }
53
+ /**
54
+ * Query comprehensive trust between two agents for a given scene.
55
+ *
56
+ * Combines graph-based trust (composite) with score-based reputation
57
+ * into a single normalized score.
58
+ *
59
+ * @param from - The querying agent's DID.
60
+ * @param to - The target agent's DID.
61
+ * @param scene - The scene/category to query trust for.
62
+ * @returns Comprehensive trust information.
63
+ */
64
+ queryTrust(from, to, scene) {
65
+ const graphTrust = this.graph.compositeTrust(from, to, scene);
66
+ const scoreReport = this.scoreClient.getAgentScore(to);
67
+ // Combine: 60% graph trust + 40% normalized score
68
+ const normalizedScore = scoreReport.trust_score / 100;
69
+ const combinedScore = 0.6 * graphTrust.trust_score + 0.4 * normalizedScore;
70
+ return {
71
+ graphTrust,
72
+ scoreReport,
73
+ combinedScore,
74
+ };
75
+ }
76
+ /**
77
+ * Get the score report for a specific agent.
78
+ *
79
+ * @param agentId - The agent's DID.
80
+ * @returns The score report.
81
+ */
82
+ getAgentScore(agentId) {
83
+ return this.scoreClient.getAgentScore(agentId);
84
+ }
85
+ /**
86
+ * Get the graph trust between two agents.
87
+ *
88
+ * @param from - Source agent DID.
89
+ * @param to - Target agent DID.
90
+ * @param scene - Scene/category.
91
+ * @returns Trust result from the graph.
92
+ */
93
+ getGraphTrust(from, to, scene) {
94
+ return this.graph.compositeTrust(from, to, scene);
95
+ }
96
+ /**
97
+ * Estimate max_cost from risk level for weight calculation.
98
+ */
99
+ _estimateCost(riskLevel) {
100
+ switch (riskLevel) {
101
+ case 'critical': return 10;
102
+ case 'high': return 5;
103
+ case 'medium': return 2;
104
+ default: return 1;
105
+ }
106
+ }
107
+ }
@@ -0,0 +1,30 @@
1
+ import type { TrustSubmission } from '../trust/index.js';
2
+ export interface TrustSyncResult {
3
+ synced: boolean;
4
+ reference?: string;
5
+ detail?: string;
6
+ }
7
+ export interface TrustSyncAdapter {
8
+ submit(submission: TrustSubmission): Promise<TrustSyncResult>;
9
+ }
10
+ export interface HttpTrustSyncAdapterOptions {
11
+ /** Base URL of TrustScoreService, e.g. http://localhost:3100 */
12
+ baseUrl: string;
13
+ /** Request timeout in milliseconds */
14
+ timeoutMs?: number;
15
+ /** Optional bearer token */
16
+ bearerToken?: string;
17
+ }
18
+ /**
19
+ * Default network trust sync adapter for self-hosted TrustScoreService.
20
+ *
21
+ * Sends execution summary to:
22
+ * POST {baseUrl}/api/v1/summary
23
+ */
24
+ export declare class HttpTrustSyncAdapter implements TrustSyncAdapter {
25
+ private readonly baseUrl;
26
+ private readonly timeoutMs;
27
+ private readonly bearerToken?;
28
+ constructor(options: HttpTrustSyncAdapterOptions);
29
+ submit(submission: TrustSubmission): Promise<TrustSyncResult>;
30
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Default network trust sync adapter for self-hosted TrustScoreService.
3
+ *
4
+ * Sends execution summary to:
5
+ * POST {baseUrl}/api/v1/summary
6
+ */
7
+ export class HttpTrustSyncAdapter {
8
+ baseUrl;
9
+ timeoutMs;
10
+ bearerToken;
11
+ constructor(options) {
12
+ this.baseUrl = options.baseUrl.replace(/\/+$/, '');
13
+ this.timeoutMs = options.timeoutMs ?? 10_000;
14
+ this.bearerToken = options.bearerToken;
15
+ }
16
+ async submit(submission) {
17
+ const controller = new AbortController();
18
+ const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
19
+ const headers = {
20
+ 'Content-Type': 'application/json',
21
+ };
22
+ if (this.bearerToken) {
23
+ headers.Authorization = `Bearer ${this.bearerToken}`;
24
+ }
25
+ try {
26
+ const response = await fetch(`${this.baseUrl}/api/v1/summary`, {
27
+ method: 'POST',
28
+ headers,
29
+ body: JSON.stringify(submission),
30
+ signal: controller.signal,
31
+ });
32
+ if (!response.ok) {
33
+ const text = await response.text();
34
+ return {
35
+ synced: false,
36
+ detail: `HTTP ${response.status}: ${text || response.statusText}`,
37
+ };
38
+ }
39
+ const body = await response.json();
40
+ return {
41
+ synced: true,
42
+ reference: body.agent_id ?? submission.executor,
43
+ detail: body.last_updated ? `updated_at=${body.last_updated}` : 'ok',
44
+ };
45
+ }
46
+ catch (err) {
47
+ const message = err instanceof Error ? err.message : String(err);
48
+ return {
49
+ synced: false,
50
+ detail: message,
51
+ };
52
+ }
53
+ finally {
54
+ clearTimeout(timeout);
55
+ }
56
+ }
57
+ }
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@lawreneliang/atel-sdk",
3
+ "version": "0.1.0",
4
+ "description": "ATEL Protocol SDK - Agent Trust & Economics Layer",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "clean": "rm -rf dist",
25
+ "test": "vitest --run",
26
+ "test:perf": "vitest --run tests/performance.test.ts",
27
+ "wallets:generate": "tsx scripts/generate-test-wallets.ts",
28
+ "run:cluster": "tsx scripts/agent-cluster-runner.ts",
29
+ "acceptance:deploy": "tsx scripts/deploy-acceptance.ts",
30
+ "doctor": "tsx scripts/doctor.ts",
31
+ "quickstart:local": "tsx demo/quickstart-local.ts",
32
+ "quickstart:network": "tsx demo/quickstart-network.ts",
33
+ "demo:real": "tsx demo/real-api-demo.ts",
34
+ "smoke:anchor": "tsx scripts/testnet-anchor-smoke.ts",
35
+ "serve": "tsx src/service/server.ts",
36
+ "prepublishOnly": "npm run clean && npm run build && npm test"
37
+ },
38
+ "dependencies": {
39
+ "@solana/web3.js": "^1.98.4",
40
+ "ajv": "^8.17.1",
41
+ "ajv-formats": "^3.0.1",
42
+ "bs58": "^6.0.0",
43
+ "ethers": "^6.16.0",
44
+ "express": "^5.2.1",
45
+ "tweetnacl": "^1.0.3",
46
+ "uuid": "^11.1.0"
47
+ },
48
+ "devDependencies": {
49
+ "@types/express": "^5.0.6",
50
+ "@types/node": "^25.2.3",
51
+ "@types/supertest": "^6.0.3",
52
+ "@types/uuid": "^10.0.0",
53
+ "supertest": "^7.2.2",
54
+ "tsx": "^4.21.0",
55
+ "typescript": "^5.7.0",
56
+ "vitest": "^3.2.4"
57
+ },
58
+ "license": "MIT"
59
+ }