@motebit/protocol 0.7.0 → 1.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.
Files changed (72) hide show
  1. package/LICENSE +198 -18
  2. package/NOTICE +19 -0
  3. package/README.md +37 -5
  4. package/dist/agent-settlement-anchor.d.ts +102 -0
  5. package/dist/agent-settlement-anchor.d.ts.map +1 -0
  6. package/dist/agent-settlement-anchor.js +18 -0
  7. package/dist/agent-settlement-anchor.js.map +1 -0
  8. package/dist/computer-use.d.ts +312 -0
  9. package/dist/computer-use.d.ts.map +1 -0
  10. package/dist/computer-use.js +86 -0
  11. package/dist/computer-use.js.map +1 -0
  12. package/dist/credential-anchor.d.ts +101 -0
  13. package/dist/credential-anchor.d.ts.map +1 -0
  14. package/dist/credential-anchor.js +9 -0
  15. package/dist/credential-anchor.js.map +1 -0
  16. package/dist/crypto-suite.d.ts +100 -0
  17. package/dist/crypto-suite.d.ts.map +1 -0
  18. package/dist/crypto-suite.js +93 -0
  19. package/dist/crypto-suite.js.map +1 -0
  20. package/dist/discovery.d.ts +87 -0
  21. package/dist/discovery.d.ts.map +1 -0
  22. package/dist/discovery.js +9 -0
  23. package/dist/discovery.js.map +1 -0
  24. package/dist/dispute.d.ts +176 -0
  25. package/dist/dispute.d.ts.map +1 -0
  26. package/dist/dispute.js +9 -0
  27. package/dist/dispute.js.map +1 -0
  28. package/dist/goal-lifecycle.d.ts +129 -0
  29. package/dist/goal-lifecycle.d.ts.map +1 -0
  30. package/dist/goal-lifecycle.js +29 -0
  31. package/dist/goal-lifecycle.js.map +1 -0
  32. package/dist/graph.d.ts +50 -0
  33. package/dist/graph.d.ts.map +1 -0
  34. package/dist/graph.js +95 -0
  35. package/dist/graph.js.map +1 -0
  36. package/dist/index.d.ts +790 -3
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +37 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/memory-events.d.ts +140 -0
  41. package/dist/memory-events.d.ts.map +1 -0
  42. package/dist/memory-events.js +29 -0
  43. package/dist/memory-events.js.map +1 -0
  44. package/dist/migration.d.ts +180 -0
  45. package/dist/migration.d.ts.map +1 -0
  46. package/dist/migration.js +9 -0
  47. package/dist/migration.js.map +1 -0
  48. package/dist/plan-lifecycle.d.ts +147 -0
  49. package/dist/plan-lifecycle.d.ts.map +1 -0
  50. package/dist/plan-lifecycle.js +36 -0
  51. package/dist/plan-lifecycle.js.map +1 -0
  52. package/dist/semiring.d.ts +104 -0
  53. package/dist/semiring.d.ts.map +1 -0
  54. package/dist/semiring.js +187 -0
  55. package/dist/semiring.js.map +1 -0
  56. package/dist/settlement-mode.d.ts +68 -0
  57. package/dist/settlement-mode.d.ts.map +1 -0
  58. package/dist/settlement-mode.js +8 -0
  59. package/dist/settlement-mode.js.map +1 -0
  60. package/dist/tool-mode.d.ts +46 -0
  61. package/dist/tool-mode.d.ts.map +1 -0
  62. package/dist/tool-mode.js +50 -0
  63. package/dist/tool-mode.js.map +1 -0
  64. package/dist/traversal.d.ts +60 -0
  65. package/dist/traversal.d.ts.map +1 -0
  66. package/dist/traversal.js +183 -0
  67. package/dist/traversal.js.map +1 -0
  68. package/dist/trust-algebra.d.ts +34 -0
  69. package/dist/trust-algebra.d.ts.map +1 -0
  70. package/dist/trust-algebra.js +58 -0
  71. package/dist/trust-algebra.js.map +1 -0
  72. package/package.json +13 -9
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Tool cost-tier taxonomy.
3
+ *
4
+ * Every `ToolDefinition` declares one of these modes. The motebit's
5
+ * tool registry sorts the list by tier, so when the model scans its
6
+ * available tools it sees structured / cheap options first and the
7
+ * pixel-level fallback last. Cost tiers (hybrid engine doctrine):
8
+ *
9
+ * - **api** — structured, semantically rich, KB round-trip.
10
+ * MCP tools, web_search, read_url, memory ops, file I/O, goals.
11
+ * The default for any tool that moves text or structured data.
12
+ *
13
+ * - **ax** — accessibility-tree extraction: DOM, AX API, reader
14
+ * shapes. Structured but lossy (visual context discarded). Used
15
+ * when the target surface exposes a hierarchy the motebit can
16
+ * read without screen capture. Today: the web Reader / virtual
17
+ * browser path. Tomorrow: macOS AXUIElement traversal for native
18
+ * apps.
19
+ *
20
+ * - **pixels** — screen capture + synthetic input. Works on every
21
+ * app (legacy software, games, custom UI) but costs ~30k tokens
22
+ * per observation even downscaled and crosses a whole-screen
23
+ * privacy surface. The universal fallback — reserved for
24
+ * surfaces that have no API and no accessibility tree.
25
+ *
26
+ * `ToolMode` is a closed string-literal union, following the `SuiteId`
27
+ * registry pattern. Adding a tier is additive (new entry + new
28
+ * priority arm in the registry sort). Removing one is a wire-format
29
+ * break — third parties declare `mode` in their tool definitions and
30
+ * that claim is stable.
31
+ */
32
+ /**
33
+ * All declared modes in priority order (cheapest first). Consumers
34
+ * that need to rank or enumerate tool modes iterate this array rather
35
+ * than hard-coding the order.
36
+ */
37
+ export const TOOL_MODES = ["api", "ax", "pixels"];
38
+ /**
39
+ * Priority index of a declared mode (0 = cheapest). Tools without a
40
+ * `mode` declaration sort to the end (`TOOL_MODES.length`) — they are
41
+ * neither rejected nor prioritized, just deprioritized relative to
42
+ * explicit tiers.
43
+ */
44
+ export function toolModePriority(mode) {
45
+ if (mode === undefined)
46
+ return TOOL_MODES.length;
47
+ const idx = TOOL_MODES.indexOf(mode);
48
+ return idx === -1 ? TOOL_MODES.length : idx;
49
+ }
50
+ //# sourceMappingURL=tool-mode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-mode.js","sourceRoot":"","sources":["../src/tool-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAU,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAA0B;IACzD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,UAAU,CAAC,MAAM,CAAC;IACjD,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Generic graph traversal over arbitrary semirings.
3
+ *
4
+ * The core insight: shortest path, most-trusted path, cheapest path,
5
+ * most reliable path, and reachability are ALL the same algorithm.
6
+ * The semiring determines the answer.
7
+ *
8
+ * Bellman-Ford generalized: relax edges using ⊕ (choice) and ⊗ (composition).
9
+ * Floyd-Warshall generalized: all-pairs transitive closure.
10
+ *
11
+ * These are the only two traversal algorithms the system needs.
12
+ * Every routing query is a semiring instantiation of one of them.
13
+ */
14
+ import type { WeightedDigraph } from "./graph.js";
15
+ /**
16
+ * Single-source optimal paths via generalized Bellman-Ford.
17
+ *
18
+ * Returns a map from each reachable node to the optimal semiring value
19
+ * of the best path from `source` to that node.
20
+ *
21
+ * - Over TrustSemiring: most trusted delegation chain from source
22
+ * - Over CostSemiring: cheapest pipeline from source
23
+ * - Over BooleanSemiring: reachable set from source
24
+ * - Over product semiring: all of the above simultaneously
25
+ *
26
+ * Complexity: O(V × E) — safe for graphs with negative-weight analogs
27
+ * (semirings where ⊕ is not monotone). For monotone semirings
28
+ * (trust, cost), could be optimized to Dijkstra-like O((V+E) log V).
29
+ */
30
+ export declare function optimalPaths<T>(graph: WeightedDigraph<T>, source: string): Map<string, T>;
31
+ /**
32
+ * Optimal path between two specific nodes.
33
+ * Convenience wrapper around optimalPaths.
34
+ */
35
+ export declare function optimalPath<T>(graph: WeightedDigraph<T>, source: string, target: string): T;
36
+ /**
37
+ * All-pairs transitive closure via generalized Floyd-Warshall.
38
+ *
39
+ * Computes the optimal semiring value between every pair of nodes.
40
+ * Returns a nested map: closure.get(from)?.get(to) → optimal value.
41
+ *
42
+ * Use cases:
43
+ * - Pre-compute all trust relationships in a network
44
+ * - Find all cheapest routes for capacity planning
45
+ * - Detect isolated subgraphs (boolean semiring)
46
+ *
47
+ * Complexity: O(V³). Use optimalPaths for single-source queries on large graphs.
48
+ */
49
+ export declare function transitiveClosure<T>(graph: WeightedDigraph<T>): Map<string, Map<string, T>>;
50
+ /**
51
+ * Reconstruct the actual optimal path (sequence of node IDs).
52
+ *
53
+ * Returns null if no path exists (value equals semiring zero).
54
+ * Runs a modified Bellman-Ford that tracks predecessors.
55
+ */
56
+ export declare function optimalPathTrace<T>(graph: WeightedDigraph<T>, source: string, target: string): {
57
+ value: T;
58
+ path: string[];
59
+ } | null;
60
+ //# sourceMappingURL=traversal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traversal.d.ts","sourceRoot":"","sources":["../src/traversal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAsCzF;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,CAE3F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CA6C3F;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,EACzB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,IAAI,CAiDrC"}
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Generic graph traversal over arbitrary semirings.
3
+ *
4
+ * The core insight: shortest path, most-trusted path, cheapest path,
5
+ * most reliable path, and reachability are ALL the same algorithm.
6
+ * The semiring determines the answer.
7
+ *
8
+ * Bellman-Ford generalized: relax edges using ⊕ (choice) and ⊗ (composition).
9
+ * Floyd-Warshall generalized: all-pairs transitive closure.
10
+ *
11
+ * These are the only two traversal algorithms the system needs.
12
+ * Every routing query is a semiring instantiation of one of them.
13
+ */
14
+ /**
15
+ * Single-source optimal paths via generalized Bellman-Ford.
16
+ *
17
+ * Returns a map from each reachable node to the optimal semiring value
18
+ * of the best path from `source` to that node.
19
+ *
20
+ * - Over TrustSemiring: most trusted delegation chain from source
21
+ * - Over CostSemiring: cheapest pipeline from source
22
+ * - Over BooleanSemiring: reachable set from source
23
+ * - Over product semiring: all of the above simultaneously
24
+ *
25
+ * Complexity: O(V × E) — safe for graphs with negative-weight analogs
26
+ * (semirings where ⊕ is not monotone). For monotone semirings
27
+ * (trust, cost), could be optimized to Dijkstra-like O((V+E) log V).
28
+ */
29
+ export function optimalPaths(graph, source) {
30
+ const sr = graph.sr;
31
+ const srEq = sr.eq;
32
+ const eq = (a, b) => (srEq ? srEq(a, b) : a === b);
33
+ const dist = new Map();
34
+ // Initialize: source = 1 (identity), everything else = 0 (worst)
35
+ for (const node of graph.nodes()) {
36
+ dist.set(node, sr.zero);
37
+ }
38
+ dist.set(source, sr.one);
39
+ const nodes = [...graph.nodes()];
40
+ const nodeCount = nodes.length;
41
+ // Relax all edges V-1 times
42
+ for (let i = 0; i < nodeCount - 1; i++) {
43
+ let changed = false;
44
+ for (const node of nodes) {
45
+ const dNode = dist.get(node);
46
+ // Skip unreachable nodes — mul(zero, w) = zero (annihilation), so no update possible
47
+ if (eq(dNode, sr.zero))
48
+ continue;
49
+ for (const [neighbor, weight] of graph.neighbors(node)) {
50
+ // New candidate: path-to-node ⊗ edge-weight
51
+ const candidate = sr.mul(dNode, weight);
52
+ const current = dist.get(neighbor);
53
+ const combined = sr.add(current, candidate);
54
+ // Only update if the value actually changed
55
+ if (!eq(combined, current)) {
56
+ dist.set(neighbor, combined);
57
+ changed = true;
58
+ }
59
+ }
60
+ }
61
+ if (!changed)
62
+ break; // Early termination — converged
63
+ }
64
+ return dist;
65
+ }
66
+ /**
67
+ * Optimal path between two specific nodes.
68
+ * Convenience wrapper around optimalPaths.
69
+ */
70
+ export function optimalPath(graph, source, target) {
71
+ return optimalPaths(graph, source).get(target) ?? graph.sr.zero;
72
+ }
73
+ /**
74
+ * All-pairs transitive closure via generalized Floyd-Warshall.
75
+ *
76
+ * Computes the optimal semiring value between every pair of nodes.
77
+ * Returns a nested map: closure.get(from)?.get(to) → optimal value.
78
+ *
79
+ * Use cases:
80
+ * - Pre-compute all trust relationships in a network
81
+ * - Find all cheapest routes for capacity planning
82
+ * - Detect isolated subgraphs (boolean semiring)
83
+ *
84
+ * Complexity: O(V³). Use optimalPaths for single-source queries on large graphs.
85
+ */
86
+ export function transitiveClosure(graph) {
87
+ const sr = graph.sr;
88
+ const nodes = [...graph.nodes()];
89
+ const n = nodes.length;
90
+ const idx = new Map();
91
+ for (let i = 0; i < n; i++)
92
+ idx.set(nodes[i], i);
93
+ // Initialize distance matrix
94
+ const dist = [];
95
+ for (let i = 0; i < n; i++) {
96
+ dist.push([]);
97
+ for (let j = 0; j < n; j++) {
98
+ dist[i].push(i === j ? sr.one : sr.zero);
99
+ }
100
+ }
101
+ // Load edges
102
+ for (const node of nodes) {
103
+ const i = idx.get(node);
104
+ for (const [neighbor, weight] of graph.neighbors(node)) {
105
+ const j = idx.get(neighbor);
106
+ dist[i][j] = sr.add(dist[i][j], weight);
107
+ }
108
+ }
109
+ // Floyd-Warshall relaxation
110
+ for (let k = 0; k < n; k++) {
111
+ for (let i = 0; i < n; i++) {
112
+ for (let j = 0; j < n; j++) {
113
+ const through_k = sr.mul(dist[i][k], dist[k][j]);
114
+ dist[i][j] = sr.add(dist[i][j], through_k);
115
+ }
116
+ }
117
+ }
118
+ // Convert to nested map
119
+ const result = new Map();
120
+ for (let i = 0; i < n; i++) {
121
+ const row = new Map();
122
+ for (let j = 0; j < n; j++) {
123
+ row.set(nodes[j], dist[i][j]);
124
+ }
125
+ result.set(nodes[i], row);
126
+ }
127
+ return result;
128
+ }
129
+ /**
130
+ * Reconstruct the actual optimal path (sequence of node IDs).
131
+ *
132
+ * Returns null if no path exists (value equals semiring zero).
133
+ * Runs a modified Bellman-Ford that tracks predecessors.
134
+ */
135
+ export function optimalPathTrace(graph, source, target) {
136
+ const sr = graph.sr;
137
+ const dist = new Map();
138
+ const pred = new Map();
139
+ for (const node of graph.nodes()) {
140
+ dist.set(node, sr.zero);
141
+ pred.set(node, null);
142
+ }
143
+ dist.set(source, sr.one);
144
+ const nodes = [...graph.nodes()];
145
+ const srEq = sr.eq;
146
+ const eq = (a, b) => (srEq ? srEq(a, b) : a === b);
147
+ for (let i = 0; i < nodes.length - 1; i++) {
148
+ let changed = false;
149
+ for (const node of nodes) {
150
+ const dNode = dist.get(node);
151
+ if (eq(dNode, sr.zero))
152
+ continue;
153
+ for (const [neighbor, weight] of graph.neighbors(node)) {
154
+ const candidate = sr.mul(dNode, weight);
155
+ const current = dist.get(neighbor);
156
+ const combined = sr.add(current, candidate);
157
+ if (!eq(combined, current)) {
158
+ dist.set(neighbor, combined);
159
+ pred.set(neighbor, node);
160
+ changed = true;
161
+ }
162
+ }
163
+ }
164
+ if (!changed)
165
+ break;
166
+ }
167
+ const value = dist.get(target) ?? sr.zero;
168
+ if (value === sr.zero && source !== target)
169
+ return null;
170
+ // Reconstruct path
171
+ const path = [];
172
+ let current = target;
173
+ const visited = new Set();
174
+ while (current != null && !visited.has(current)) {
175
+ visited.add(current);
176
+ path.unshift(current);
177
+ current = pred.get(current) ?? null;
178
+ }
179
+ if (path[0] !== source)
180
+ return null;
181
+ return { value, path };
182
+ }
183
+ //# sourceMappingURL=traversal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traversal.js","sourceRoot":"","sources":["../src/traversal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAAI,KAAyB,EAAE,MAAc;IACvE,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;IACpB,MAAM,IAAI,GAAG,EAAE,CAAC,EAAE,CAAC;IACnB,MAAM,EAAE,GAAG,CAAC,CAAI,EAAE,CAAI,EAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAa,CAAC;IAElC,iEAAiE;IACjE,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IAEzB,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACjC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;IAE/B,4BAA4B;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;YAC9B,qFA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EAAE,SAAS,CAAC,CAAC;gBAC5C,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;oBAC3B,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;oBAC7B,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;oBACzB,OAAO,GAAG,IAAI,CAAC;gBACjB,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,CAAC,OAAO;YAAE,MAAM;IACtB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC;IAC1C,IAAI,KAAK,KAAK,EAAE,CAAC,IAAI,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAExD,mBAAmB;IACnB,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,OAAO,GAA8B,MAAM,CAAC;IAChD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,OAAO,OAAO,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAChD,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;IACtC,CAAC;IAED,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Trust algebra: concrete semiring operations for agent trust scoring.
3
+ *
4
+ * (TrustScores, max, ×, 0, 1) — standard algebraic path problem.
5
+ * Multiplicative discount for serial chains, max for parallel paths.
6
+ *
7
+ * These are protocol-level primitives: any compatible implementation
8
+ * must compute trust the same way for interoperable routing.
9
+ */
10
+ import type { TrustTransitionThresholds, AgentTrustLevel } from "./index.js";
11
+ /**
12
+ * Canonical AgentTrustLevel → [0,1] mapping (single source of truth).
13
+ *
14
+ * Uses string literals instead of enum computed keys to avoid circular
15
+ * initialization between trust-algebra.ts ↔ index.ts. The values match
16
+ * AgentTrustLevel enum values exactly.
17
+ */
18
+ export declare const TRUST_LEVEL_SCORES: Record<string, number>;
19
+ /** Convert a trust level to its numeric score. */
20
+ export declare function trustLevelToScore(level: AgentTrustLevel | string): number;
21
+ /** Semiring zero — annihilator for ⊗, identity for ⊕. */
22
+ export declare const TRUST_ZERO = 0;
23
+ /** Semiring one — identity for ⊗. */
24
+ export declare const TRUST_ONE = 1;
25
+ /** ⊕: parallel paths — pick the best route. */
26
+ export declare function trustAdd(a: number, b: number): number;
27
+ /** ⊗: serial chain — discount per hop. */
28
+ export declare function trustMultiply(a: number, b: number): number;
29
+ /** Fold a chain of trust scores with ⊗. Empty chain → 1.0 (identity). */
30
+ export declare function composeTrustChain(scores: number[]): number;
31
+ /** Fold parallel route scores with ⊕. No routes → 0.0 (identity). */
32
+ export declare function joinParallelRoutes(scores: number[]): number;
33
+ export declare const DEFAULT_TRUST_THRESHOLDS: TrustTransitionThresholds;
34
+ //# sourceMappingURL=trust-algebra.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust-algebra.d.ts","sourceRoot":"","sources":["../src/trust-algebra.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI7E;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAMrD,CAAC;AAEF,kDAAkD;AAClD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,GAAG,MAAM,CAEzE;AAED,yDAAyD;AACzD,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B,qCAAqC;AACrC,eAAO,MAAM,SAAS,IAAI,CAAC;AAE3B,+CAA+C;AAC/C,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,0CAA0C;AAC1C,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAE1D;AAED,qEAAqE;AACrE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAE3D;AAID,eAAO,MAAM,wBAAwB,EAAE,yBAOtC,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Trust algebra: concrete semiring operations for agent trust scoring.
3
+ *
4
+ * (TrustScores, max, ×, 0, 1) — standard algebraic path problem.
5
+ * Multiplicative discount for serial chains, max for parallel paths.
6
+ *
7
+ * These are protocol-level primitives: any compatible implementation
8
+ * must compute trust the same way for interoperable routing.
9
+ */
10
+ // ── Trust Semiring Algebra ──────────────────────────────────────────
11
+ /**
12
+ * Canonical AgentTrustLevel → [0,1] mapping (single source of truth).
13
+ *
14
+ * Uses string literals instead of enum computed keys to avoid circular
15
+ * initialization between trust-algebra.ts ↔ index.ts. The values match
16
+ * AgentTrustLevel enum values exactly.
17
+ */
18
+ export const TRUST_LEVEL_SCORES = {
19
+ unknown: 0.1,
20
+ first_contact: 0.3,
21
+ verified: 0.6,
22
+ trusted: 0.9,
23
+ blocked: 0.0,
24
+ };
25
+ /** Convert a trust level to its numeric score. */
26
+ export function trustLevelToScore(level) {
27
+ return TRUST_LEVEL_SCORES[level] ?? 0.1;
28
+ }
29
+ /** Semiring zero — annihilator for ⊗, identity for ⊕. */
30
+ export const TRUST_ZERO = 0;
31
+ /** Semiring one — identity for ⊗. */
32
+ export const TRUST_ONE = 1;
33
+ /** ⊕: parallel paths — pick the best route. */
34
+ export function trustAdd(a, b) {
35
+ return Math.max(a, b);
36
+ }
37
+ /** ⊗: serial chain — discount per hop. */
38
+ export function trustMultiply(a, b) {
39
+ return a * b;
40
+ }
41
+ /** Fold a chain of trust scores with ⊗. Empty chain → 1.0 (identity). */
42
+ export function composeTrustChain(scores) {
43
+ return scores.reduce(trustMultiply, TRUST_ONE);
44
+ }
45
+ /** Fold parallel route scores with ⊕. No routes → 0.0 (identity). */
46
+ export function joinParallelRoutes(scores) {
47
+ return scores.reduce(trustAdd, TRUST_ZERO);
48
+ }
49
+ // ── Default Thresholds ─────────────────────────────────────────────
50
+ export const DEFAULT_TRUST_THRESHOLDS = {
51
+ promoteToVerified_minTasks: 5,
52
+ promoteToVerified_minRate: 0.8,
53
+ promoteToTrusted_minTasks: 20,
54
+ promoteToTrusted_minRate: 0.9,
55
+ demote_belowRate: 0.5,
56
+ demote_minTasks: 3,
57
+ };
58
+ //# sourceMappingURL=trust-algebra.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust-algebra.js","sourceRoot":"","sources":["../src/trust-algebra.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,uEAAuE;AAEvE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA2B;IACxD,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,GAAG;IAClB,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,GAAG;CACb,CAAC;AAEF,kDAAkD;AAClD,MAAM,UAAU,iBAAiB,CAAC,KAA+B;IAC/D,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC;AAC1C,CAAC;AAED,yDAAyD;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AAE5B,qCAAqC;AACrC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAE3B,+CAA+C;AAC/C,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,aAAa,CAAC,CAAS,EAAE,CAAS;IAChD,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,iBAAiB,CAAC,MAAgB;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;AACjD,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,kBAAkB,CAAC,MAAgB;IACjD,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED,sEAAsE;AAEtE,MAAM,CAAC,MAAM,wBAAwB,GAA8B;IACjE,0BAA0B,EAAE,CAAC;IAC7B,yBAAyB,EAAE,GAAG;IAC9B,yBAAyB,EAAE,EAAE;IAC7B,wBAAwB,EAAE,GAAG;IAC7B,gBAAgB,EAAE,GAAG;IACrB,eAAe,EAAE,CAAC;CACnB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@motebit/protocol",
3
- "version": "0.7.0",
4
- "description": "Motebit network protocol types — identity, receipts, credentials, settlement, trust algebra. MIT, zero dependencies.",
3
+ "version": "1.0.0",
4
+ "description": "Motebit protocol — identity, receipts, credentials, delegation, settlement, and trust algebra for sovereign AI agents. Types, semirings, routing primitives. Apache-2.0, zero dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -12,15 +12,16 @@
12
12
  }
13
13
  },
14
14
  "files": [
15
- "dist/index.js",
16
- "dist/index.js.map",
17
- "dist/index.d.ts",
18
- "dist/index.d.ts.map",
15
+ "dist/**/*.js",
16
+ "dist/**/*.js.map",
17
+ "dist/**/*.d.ts",
18
+ "dist/**/*.d.ts.map",
19
19
  "LICENSE",
20
+ "NOTICE",
20
21
  "README.md"
21
22
  ],
22
23
  "sideEffects": false,
23
- "license": "MIT",
24
+ "license": "Apache-2.0",
24
25
  "keywords": [
25
26
  "motebit",
26
27
  "protocol",
@@ -48,17 +49,20 @@
48
49
  "devDependencies": {
49
50
  "@types/node": "^22.0.0",
50
51
  "typescript": "^5.6.0",
52
+ "fast-check": "^4.6.0",
51
53
  "vitest": "^2.1.0"
52
54
  },
53
55
  "engines": {
54
- "node": ">=18"
56
+ "node": ">=20"
55
57
  },
56
58
  "scripts": {
57
59
  "build": "tsc -b",
58
60
  "test": "vitest run",
59
61
  "test:coverage": "vitest run --coverage",
60
62
  "typecheck": "tsc --noEmit",
61
- "lint": "eslint src/",
63
+ "lint": "eslint --parser-options=project:tsconfig.eslint.json src/",
64
+ "lint:pack": "publint --strict && attw --pack --profile esm-only",
65
+ "api:extract": "api-extractor run --local",
62
66
  "clean": "rm -rf dist .turbo *.tsbuildinfo"
63
67
  }
64
68
  }