@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.
- package/LICENSE +198 -18
- package/NOTICE +19 -0
- package/README.md +37 -5
- package/dist/agent-settlement-anchor.d.ts +102 -0
- package/dist/agent-settlement-anchor.d.ts.map +1 -0
- package/dist/agent-settlement-anchor.js +18 -0
- package/dist/agent-settlement-anchor.js.map +1 -0
- package/dist/computer-use.d.ts +312 -0
- package/dist/computer-use.d.ts.map +1 -0
- package/dist/computer-use.js +86 -0
- package/dist/computer-use.js.map +1 -0
- package/dist/credential-anchor.d.ts +101 -0
- package/dist/credential-anchor.d.ts.map +1 -0
- package/dist/credential-anchor.js +9 -0
- package/dist/credential-anchor.js.map +1 -0
- package/dist/crypto-suite.d.ts +100 -0
- package/dist/crypto-suite.d.ts.map +1 -0
- package/dist/crypto-suite.js +93 -0
- package/dist/crypto-suite.js.map +1 -0
- package/dist/discovery.d.ts +87 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +9 -0
- package/dist/discovery.js.map +1 -0
- package/dist/dispute.d.ts +176 -0
- package/dist/dispute.d.ts.map +1 -0
- package/dist/dispute.js +9 -0
- package/dist/dispute.js.map +1 -0
- package/dist/goal-lifecycle.d.ts +129 -0
- package/dist/goal-lifecycle.d.ts.map +1 -0
- package/dist/goal-lifecycle.js +29 -0
- package/dist/goal-lifecycle.js.map +1 -0
- package/dist/graph.d.ts +50 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +95 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +790 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-events.d.ts +140 -0
- package/dist/memory-events.d.ts.map +1 -0
- package/dist/memory-events.js +29 -0
- package/dist/memory-events.js.map +1 -0
- package/dist/migration.d.ts +180 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +9 -0
- package/dist/migration.js.map +1 -0
- package/dist/plan-lifecycle.d.ts +147 -0
- package/dist/plan-lifecycle.d.ts.map +1 -0
- package/dist/plan-lifecycle.js +36 -0
- package/dist/plan-lifecycle.js.map +1 -0
- package/dist/semiring.d.ts +104 -0
- package/dist/semiring.d.ts.map +1 -0
- package/dist/semiring.js +187 -0
- package/dist/semiring.js.map +1 -0
- package/dist/settlement-mode.d.ts +68 -0
- package/dist/settlement-mode.d.ts.map +1 -0
- package/dist/settlement-mode.js +8 -0
- package/dist/settlement-mode.js.map +1 -0
- package/dist/tool-mode.d.ts +46 -0
- package/dist/tool-mode.d.ts.map +1 -0
- package/dist/tool-mode.js +50 -0
- package/dist/tool-mode.js.map +1 -0
- package/dist/traversal.d.ts +60 -0
- package/dist/traversal.d.ts.map +1 -0
- package/dist/traversal.js +183 -0
- package/dist/traversal.js.map +1 -0
- package/dist/trust-algebra.d.ts +34 -0
- package/dist/trust-algebra.d.ts.map +1 -0
- package/dist/trust-algebra.js +58 -0
- package/dist/trust-algebra.js.map +1 -0
- package/package.json +13 -9
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan-lifecycle event payload types — wire format for `plan-lifecycle-v1.md`.
|
|
3
|
+
*
|
|
4
|
+
* A plan is the execution backbone for a goal: an ordered list of steps,
|
|
5
|
+
* each with its own description, status, and tool-call accounting. Plans
|
|
6
|
+
* are created and advanced by `@motebit/runtime`'s plan-execution
|
|
7
|
+
* orchestrator; events are emitted at every state transition so the event
|
|
8
|
+
* log captures an append-only audit trail of every plan run.
|
|
9
|
+
*
|
|
10
|
+
* Because plans cross device boundaries (multi-device sync replays plan
|
|
11
|
+
* history) and delegation boundaries (when a step is delegated, the
|
|
12
|
+
* delegator logs the delegation; the worker logs its own plan events
|
|
13
|
+
* against its own motebit_id and the result returns via
|
|
14
|
+
* `AgentTaskCompleted`), the payload of every plan-lifecycle event must be
|
|
15
|
+
* pinned as a wire-format type so a non-TypeScript implementer validates
|
|
16
|
+
* payloads against the committed JSON Schema rather than TypeScript's
|
|
17
|
+
* structural view.
|
|
18
|
+
*
|
|
19
|
+
* Seven event types cover the full lifecycle:
|
|
20
|
+
* 1. `plan_created` — plan materialized with N steps
|
|
21
|
+
* 2. `plan_step_started` — step N entered running state
|
|
22
|
+
* 3. `plan_step_completed` — step N reached terminal success
|
|
23
|
+
* 4. `plan_step_failed` — step N reached terminal failure
|
|
24
|
+
* 5. `plan_step_delegated` — step N handed off to a remote agent
|
|
25
|
+
* 6. `plan_completed` — every step finished; plan is done
|
|
26
|
+
* 7. `plan_failed` — plan terminated before completion
|
|
27
|
+
*
|
|
28
|
+
* Every type named here is referenced by a `### X.Y — Name` section under a
|
|
29
|
+
* `#### Wire format (foundation law)` block in `spec/plan-lifecycle-v1.md`,
|
|
30
|
+
* so `check-spec-coverage` (invariant #9) keeps the spec and types in
|
|
31
|
+
* lockstep. Implementing package declaration lives in
|
|
32
|
+
* `packages/runtime/package.json`'s `motebit.implements` array, enforced by
|
|
33
|
+
* `check-spec-impl-coverage` (invariant #31).
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Emitted when `@motebit/runtime`'s plan engine materializes a plan from
|
|
37
|
+
* a goal or a direct prompt. Each step has its own lifecycle events; this
|
|
38
|
+
* event records the top-level plan identity and step count.
|
|
39
|
+
*/
|
|
40
|
+
export interface PlanCreatedPayload {
|
|
41
|
+
/** Stable identifier of the plan. UUID v4 at creation. */
|
|
42
|
+
readonly plan_id: string;
|
|
43
|
+
/** Human-readable title summarizing the plan's goal. */
|
|
44
|
+
readonly title: string;
|
|
45
|
+
/** Total number of steps the plan was materialized with. */
|
|
46
|
+
readonly total_steps: number;
|
|
47
|
+
/** Owning goal when the plan was created in service of a scheduled or on-demand goal. */
|
|
48
|
+
readonly goal_id?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Emitted when a plan step transitions from `pending` to `running`. The
|
|
52
|
+
* step has been chosen and the runtime is about to invoke the
|
|
53
|
+
* corresponding tool or agent call.
|
|
54
|
+
*/
|
|
55
|
+
export interface PlanStepStartedPayload {
|
|
56
|
+
readonly plan_id: string;
|
|
57
|
+
/** Stable identifier of this step. UUID v4, unique within the plan. */
|
|
58
|
+
readonly step_id: string;
|
|
59
|
+
/** Zero-based position of the step within its plan. */
|
|
60
|
+
readonly ordinal: number;
|
|
61
|
+
/** Human-readable description of what this step does. */
|
|
62
|
+
readonly description: string;
|
|
63
|
+
readonly goal_id?: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Emitted when a plan step completes successfully. Carries the tool-call
|
|
67
|
+
* count so consumers can reconstruct execution cost without replaying
|
|
68
|
+
* every `tool_used` event. When the step was delegated, `task_id`
|
|
69
|
+
* carries the delegation identifier so the terminal event joins
|
|
70
|
+
* payload-directly to its `plan_step_delegated` predecessor — receivers
|
|
71
|
+
* do not have to maintain a separate task→step index.
|
|
72
|
+
*/
|
|
73
|
+
export interface PlanStepCompletedPayload {
|
|
74
|
+
readonly plan_id: string;
|
|
75
|
+
readonly step_id: string;
|
|
76
|
+
readonly ordinal: number;
|
|
77
|
+
/** Number of tool calls the step performed. */
|
|
78
|
+
readonly tool_calls_made: number;
|
|
79
|
+
/** Delegation task id. Present iff this step was delegated (§3.7). */
|
|
80
|
+
readonly task_id?: string;
|
|
81
|
+
readonly goal_id?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Emitted when a plan step terminates in failure. Carries a free-text
|
|
85
|
+
* error message; consumers MUST NOT parse it semantically. Receivers MAY
|
|
86
|
+
* correlate `error` with surrounding `tool_used` events or with a receipt
|
|
87
|
+
* from a delegated step, but the error string itself is implementation-
|
|
88
|
+
* detail rationale.
|
|
89
|
+
*/
|
|
90
|
+
export interface PlanStepFailedPayload {
|
|
91
|
+
readonly plan_id: string;
|
|
92
|
+
readonly step_id: string;
|
|
93
|
+
readonly ordinal: number;
|
|
94
|
+
/** Error message from the failing step. */
|
|
95
|
+
readonly error: string;
|
|
96
|
+
/** Delegation task id. Present iff this step was delegated (§3.7). */
|
|
97
|
+
readonly task_id?: string;
|
|
98
|
+
readonly goal_id?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Emitted when a plan step is handed off to a remote agent via
|
|
102
|
+
* delegation. The delegator logs this event and then waits for the
|
|
103
|
+
* corresponding `AgentTaskCompleted` / `AgentTaskFailed` event to resume
|
|
104
|
+
* the plan. The `task_id` is the delegation's relay-issued id; the
|
|
105
|
+
* `routing_choice` (when present) carries the routing provenance picked
|
|
106
|
+
* by the semiring so downstream audit can reconstruct why this agent was
|
|
107
|
+
* chosen.
|
|
108
|
+
*/
|
|
109
|
+
export interface PlanStepDelegatedPayload {
|
|
110
|
+
readonly plan_id: string;
|
|
111
|
+
readonly step_id: string;
|
|
112
|
+
readonly ordinal: number;
|
|
113
|
+
/** Relay-issued task identifier. Matches the subsequent `AgentTaskCompleted.task_id`. */
|
|
114
|
+
readonly task_id: string;
|
|
115
|
+
/**
|
|
116
|
+
* Routing provenance picked by the semiring. Opaque to this spec; the
|
|
117
|
+
* motebit semiring module defines the field set. Consumers MAY read
|
|
118
|
+
* known fields (trust score, latency estimate) but MUST tolerate
|
|
119
|
+
* additional fields for forward compatibility.
|
|
120
|
+
*/
|
|
121
|
+
readonly routing_choice?: Record<string, unknown>;
|
|
122
|
+
readonly goal_id?: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Emitted when every step in a plan has reached a terminal state and the
|
|
126
|
+
* plan itself is considered done. A plan completes when all its steps
|
|
127
|
+
* completed or when the plan engine decided to stop short (e.g. the goal
|
|
128
|
+
* was achieved before the final step). Either way, `plan_completed`
|
|
129
|
+
* signals the plan record is closed.
|
|
130
|
+
*/
|
|
131
|
+
export interface PlanCompletedPayload {
|
|
132
|
+
readonly plan_id: string;
|
|
133
|
+
readonly goal_id?: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Emitted when a plan terminates before completion — a step failed and
|
|
137
|
+
* the plan engine could not recover, the plan was cancelled, or a policy
|
|
138
|
+
* gate rejected further execution. The `reason` string is free-text
|
|
139
|
+
* rationale for the failure.
|
|
140
|
+
*/
|
|
141
|
+
export interface PlanFailedPayload {
|
|
142
|
+
readonly plan_id: string;
|
|
143
|
+
/** Free-text failure rationale. Consumers MUST NOT parse it semantically. */
|
|
144
|
+
readonly reason: string;
|
|
145
|
+
readonly goal_id?: string;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=plan-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-lifecycle.d.ts","sourceRoot":"","sources":["../src/plan-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wDAAwD;IACxD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,yFAAyF;IACzF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE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C,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plan-lifecycle event payload types — wire format for `plan-lifecycle-v1.md`.
|
|
3
|
+
*
|
|
4
|
+
* A plan is the execution backbone for a goal: an ordered list of steps,
|
|
5
|
+
* each with its own description, status, and tool-call accounting. Plans
|
|
6
|
+
* are created and advanced by `@motebit/runtime`'s plan-execution
|
|
7
|
+
* orchestrator; events are emitted at every state transition so the event
|
|
8
|
+
* log captures an append-only audit trail of every plan run.
|
|
9
|
+
*
|
|
10
|
+
* Because plans cross device boundaries (multi-device sync replays plan
|
|
11
|
+
* history) and delegation boundaries (when a step is delegated, the
|
|
12
|
+
* delegator logs the delegation; the worker logs its own plan events
|
|
13
|
+
* against its own motebit_id and the result returns via
|
|
14
|
+
* `AgentTaskCompleted`), the payload of every plan-lifecycle event must be
|
|
15
|
+
* pinned as a wire-format type so a non-TypeScript implementer validates
|
|
16
|
+
* payloads against the committed JSON Schema rather than TypeScript's
|
|
17
|
+
* structural view.
|
|
18
|
+
*
|
|
19
|
+
* Seven event types cover the full lifecycle:
|
|
20
|
+
* 1. `plan_created` — plan materialized with N steps
|
|
21
|
+
* 2. `plan_step_started` — step N entered running state
|
|
22
|
+
* 3. `plan_step_completed` — step N reached terminal success
|
|
23
|
+
* 4. `plan_step_failed` — step N reached terminal failure
|
|
24
|
+
* 5. `plan_step_delegated` — step N handed off to a remote agent
|
|
25
|
+
* 6. `plan_completed` — every step finished; plan is done
|
|
26
|
+
* 7. `plan_failed` — plan terminated before completion
|
|
27
|
+
*
|
|
28
|
+
* Every type named here is referenced by a `### X.Y — Name` section under a
|
|
29
|
+
* `#### Wire format (foundation law)` block in `spec/plan-lifecycle-v1.md`,
|
|
30
|
+
* so `check-spec-coverage` (invariant #9) keeps the spec and types in
|
|
31
|
+
* lockstep. Implementing package declaration lives in
|
|
32
|
+
* `packages/runtime/package.json`'s `motebit.implements` array, enforced by
|
|
33
|
+
* `check-spec-impl-coverage` (invariant #31).
|
|
34
|
+
*/
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=plan-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-lifecycle.js","sourceRoot":"","sources":["../src/plan-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semiring — the algebraic foundation for agent network computation.
|
|
3
|
+
*
|
|
4
|
+
* A semiring (S, ⊕, ⊗, 0, 1) satisfies:
|
|
5
|
+
* (S, ⊕, 0) — commutative monoid (aggregation of parallel alternatives)
|
|
6
|
+
* (S, ⊗, 1) — monoid (sequential composition)
|
|
7
|
+
* ⊗ distributes over ⊕: a ⊗ (b ⊕ c) = (a ⊗ b) ⊕ (a ⊗ c)
|
|
8
|
+
* 0 annihilates: a ⊗ 0 = 0 ⊗ a = 0
|
|
9
|
+
*
|
|
10
|
+
* Different semirings model different routing concerns over the same graph:
|
|
11
|
+
* Trust: (max, ×, 0, 1) → most trusted delegation chain
|
|
12
|
+
* Cost: (min, +, ∞, 0) → cheapest agent pipeline
|
|
13
|
+
* Latency: (min, +, ∞, 0) → fastest sequential path
|
|
14
|
+
* Bottleneck: (max, min, 0, 1) → widest bottleneck path (capacity)
|
|
15
|
+
* Reliability: (max, ×, 0, 1) → most reliable chain
|
|
16
|
+
* Boolean: (∨, ∧, ⊥, ⊤) → reachability
|
|
17
|
+
*
|
|
18
|
+
* One graph. One algorithm. Swap the semiring. Different answer.
|
|
19
|
+
*/
|
|
20
|
+
export interface Semiring<T> {
|
|
21
|
+
/** Additive identity. The "worst" or "impossible" value. */
|
|
22
|
+
readonly zero: T;
|
|
23
|
+
/** Multiplicative identity. Passthrough / no-op edge. */
|
|
24
|
+
readonly one: T;
|
|
25
|
+
/** ⊕: aggregate parallel alternatives (commutative, associative). */
|
|
26
|
+
add(a: T, b: T): T;
|
|
27
|
+
/** ⊗: compose sequential edges (associative). */
|
|
28
|
+
mul(a: T, b: T): T;
|
|
29
|
+
/**
|
|
30
|
+
* Value equality. Used by graph traversal for convergence detection.
|
|
31
|
+
* Defaults to `===` when absent — correct for primitive semirings (number, boolean).
|
|
32
|
+
* Required for compound semirings (record, product, annotated) where `add()`
|
|
33
|
+
* returns a new object even when the value is semantically unchanged.
|
|
34
|
+
*
|
|
35
|
+
* Declared as a property (not method) so extracting it doesn't trigger
|
|
36
|
+
* unbound-method lint — semiring objects are plain data, never class instances.
|
|
37
|
+
*/
|
|
38
|
+
readonly eq?: ((a: T, b: T) => boolean) | undefined;
|
|
39
|
+
}
|
|
40
|
+
/** (max, ×, 0, 1) — most trusted delegation chain through the network. */
|
|
41
|
+
export declare const TrustSemiring: Semiring<number>;
|
|
42
|
+
/**
|
|
43
|
+
* (min, +, ∞, 0) — cheapest path through the agent network.
|
|
44
|
+
* Tropical semiring. Same algebra as Dijkstra / Bellman-Ford.
|
|
45
|
+
*/
|
|
46
|
+
export declare const CostSemiring: Semiring<number>;
|
|
47
|
+
/** (min, +, ∞, 0) — fastest sequential path (sum of edge latencies). */
|
|
48
|
+
export declare const LatencySemiring: Semiring<number>;
|
|
49
|
+
/** (max, min, 0, ∞) — widest bottleneck path (capacity-limited routing). */
|
|
50
|
+
export declare const BottleneckSemiring: Semiring<number>;
|
|
51
|
+
/** (max, ×, 0, 1) — most reliable chain (probability product). */
|
|
52
|
+
export declare const ReliabilitySemiring: Semiring<number>;
|
|
53
|
+
/**
|
|
54
|
+
* (min, +, ∞, 0) — lowest regulatory risk path.
|
|
55
|
+
* Risk accumulates along delegation chains (additive composition),
|
|
56
|
+
* parallel alternatives pick the lowest-risk route (min choice).
|
|
57
|
+
*
|
|
58
|
+
* Edge weights represent risk scores: 0 = no risk, ∞ = impossible.
|
|
59
|
+
* Jurisdictional data handling, compliance requirements, audit depth —
|
|
60
|
+
* all accumulate when one agent delegates to another.
|
|
61
|
+
*/
|
|
62
|
+
export declare const RegulatoryRiskSemiring: Semiring<number>;
|
|
63
|
+
/** (∨, ∧, false, true) — can agent A reach agent B? */
|
|
64
|
+
export declare const BooleanSemiring: Semiring<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* (max, +, -∞, 0) — numerically stable max-product via log-space.
|
|
67
|
+
*
|
|
68
|
+
* Multiplying many small probabilities or confidences (each < 1) in
|
|
69
|
+
* linear space underflows fast: twenty 0.1-confidence edges collapse
|
|
70
|
+
* to 10⁻²⁰, which starts losing precision before then and hits
|
|
71
|
+
* denormals by 50. In log space the product becomes a sum; max stays
|
|
72
|
+
* max. Isomorphic to `ReliabilitySemiring` via x ↦ log(x), but callers
|
|
73
|
+
* skip the intermediate floats and stay stable over deep chains.
|
|
74
|
+
*
|
|
75
|
+
* Used by memory-graph's `recallConfidentChain` lens — most-confident
|
|
76
|
+
* reasoning chain through the memory graph. Also valid as the Viterbi
|
|
77
|
+
* recurrence semiring on DAG-structured trellises (when HMM-shape
|
|
78
|
+
* inference joins the codebase as a separate primitive).
|
|
79
|
+
*/
|
|
80
|
+
export declare const MaxProductLogSemiring: Semiring<number>;
|
|
81
|
+
/**
|
|
82
|
+
* Product semiring: optimize multiple concerns simultaneously.
|
|
83
|
+
*
|
|
84
|
+
* (A × B, ⊕_A × ⊕_B, ⊗_A × ⊗_B, (0_A, 0_B), (1_A, 1_B))
|
|
85
|
+
*
|
|
86
|
+
* One graph traversal computes trust × cost × latency in a single pass.
|
|
87
|
+
*/
|
|
88
|
+
export declare function productSemiring<A, B>(sa: Semiring<A>, sb: Semiring<B>): Semiring<readonly [A, B]>;
|
|
89
|
+
/**
|
|
90
|
+
* Lift a scalar semiring into a named-fields record semiring.
|
|
91
|
+
* Useful when you want labeled dimensions instead of nested tuples.
|
|
92
|
+
*
|
|
93
|
+
* const Multi = recordSemiring({ trust: TrustSemiring, cost: CostSemiring });
|
|
94
|
+
* // Semiring<{ trust: number; cost: number }>
|
|
95
|
+
*/
|
|
96
|
+
export declare function recordSemiring<R extends Record<string, unknown>>(fields: {
|
|
97
|
+
[K in keyof R]: Semiring<R[K]>;
|
|
98
|
+
}): Semiring<R>;
|
|
99
|
+
/**
|
|
100
|
+
* Map a semiring through an isomorphism.
|
|
101
|
+
* Useful for wrapping/unwrapping branded types or unit conversions.
|
|
102
|
+
*/
|
|
103
|
+
export declare function mappedSemiring<T, U>(base: Semiring<T>, to: (t: T) => U, from: (u: U) => T): Semiring<U>;
|
|
104
|
+
//# sourceMappingURL=semiring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semiring.d.ts","sourceRoot":"","sources":["../src/semiring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,yDAAyD;IACzD,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAChB,qEAAqE;IACrE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACnB,iDAAiD;IACjD,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACnB;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;CACrD;AAID,0EAA0E;AAC1E,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAK1C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAKzC,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,eAAe,EAAE,QAAQ,CA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|
|
3
|
+
*
|
|
4
|
+
* A semiring (S, ⊕, ⊗, 0, 1) satisfies:
|
|
5
|
+
* (S, ⊕, 0) — commutative monoid (aggregation of parallel alternatives)
|
|
6
|
+
* (S, ⊗, 1) — monoid (sequential composition)
|
|
7
|
+
* ⊗ distributes over ⊕: a ⊗ (b ⊕ c) = (a ⊗ b) ⊕ (a ⊗ c)
|
|
8
|
+
* 0 annihilates: a ⊗ 0 = 0 ⊗ a = 0
|
|
9
|
+
*
|
|
10
|
+
* Different semirings model different routing concerns over the same graph:
|
|
11
|
+
* Trust: (max, ×, 0, 1) → most trusted delegation chain
|
|
12
|
+
* Cost: (min, +, ∞, 0) → cheapest agent pipeline
|
|
13
|
+
* Latency: (min, +, ∞, 0) → fastest sequential path
|
|
14
|
+
* Bottleneck: (max, min, 0, 1) → widest bottleneck path (capacity)
|
|
15
|
+
* Reliability: (max, ×, 0, 1) → most reliable chain
|
|
16
|
+
* Boolean: (∨, ∧, ⊥, ⊤) → reachability
|
|
17
|
+
*
|
|
18
|
+
* One graph. One algorithm. Swap the semiring. Different answer.
|
|
19
|
+
*/
|
|
20
|
+
// ── Concrete Semirings ──────────────────────────────────────────────
|
|
21
|
+
/** (max, ×, 0, 1) — most trusted delegation chain through the network. */
|
|
22
|
+
export const TrustSemiring = {
|
|
23
|
+
zero: 0,
|
|
24
|
+
one: 1,
|
|
25
|
+
add: (a, b) => Math.max(a, b),
|
|
26
|
+
mul: (a, b) => a * b,
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* (min, +, ∞, 0) — cheapest path through the agent network.
|
|
30
|
+
* Tropical semiring. Same algebra as Dijkstra / Bellman-Ford.
|
|
31
|
+
*/
|
|
32
|
+
export const CostSemiring = {
|
|
33
|
+
zero: Infinity,
|
|
34
|
+
one: 0,
|
|
35
|
+
add: (a, b) => Math.min(a, b),
|
|
36
|
+
mul: (a, b) => a + b,
|
|
37
|
+
};
|
|
38
|
+
/** (min, +, ∞, 0) — fastest sequential path (sum of edge latencies). */
|
|
39
|
+
export const LatencySemiring = {
|
|
40
|
+
zero: Infinity,
|
|
41
|
+
one: 0,
|
|
42
|
+
add: (a, b) => Math.min(a, b),
|
|
43
|
+
mul: (a, b) => a + b,
|
|
44
|
+
};
|
|
45
|
+
/** (max, min, 0, ∞) — widest bottleneck path (capacity-limited routing). */
|
|
46
|
+
export const BottleneckSemiring = {
|
|
47
|
+
zero: 0,
|
|
48
|
+
one: Infinity,
|
|
49
|
+
add: (a, b) => Math.max(a, b),
|
|
50
|
+
mul: (a, b) => Math.min(a, b),
|
|
51
|
+
};
|
|
52
|
+
/** (max, ×, 0, 1) — most reliable chain (probability product). */
|
|
53
|
+
export const ReliabilitySemiring = {
|
|
54
|
+
zero: 0,
|
|
55
|
+
one: 1,
|
|
56
|
+
add: (a, b) => Math.max(a, b),
|
|
57
|
+
mul: (a, b) => a * b,
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* (min, +, ∞, 0) — lowest regulatory risk path.
|
|
61
|
+
* Risk accumulates along delegation chains (additive composition),
|
|
62
|
+
* parallel alternatives pick the lowest-risk route (min choice).
|
|
63
|
+
*
|
|
64
|
+
* Edge weights represent risk scores: 0 = no risk, ∞ = impossible.
|
|
65
|
+
* Jurisdictional data handling, compliance requirements, audit depth —
|
|
66
|
+
* all accumulate when one agent delegates to another.
|
|
67
|
+
*/
|
|
68
|
+
export const RegulatoryRiskSemiring = {
|
|
69
|
+
zero: Infinity,
|
|
70
|
+
one: 0,
|
|
71
|
+
add: (a, b) => Math.min(a, b),
|
|
72
|
+
mul: (a, b) => a + b,
|
|
73
|
+
};
|
|
74
|
+
/** (∨, ∧, false, true) — can agent A reach agent B? */
|
|
75
|
+
export const BooleanSemiring = {
|
|
76
|
+
zero: false,
|
|
77
|
+
one: true,
|
|
78
|
+
add: (a, b) => a || b,
|
|
79
|
+
mul: (a, b) => a && b,
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* (max, +, -∞, 0) — numerically stable max-product via log-space.
|
|
83
|
+
*
|
|
84
|
+
* Multiplying many small probabilities or confidences (each < 1) in
|
|
85
|
+
* linear space underflows fast: twenty 0.1-confidence edges collapse
|
|
86
|
+
* to 10⁻²⁰, which starts losing precision before then and hits
|
|
87
|
+
* denormals by 50. In log space the product becomes a sum; max stays
|
|
88
|
+
* max. Isomorphic to `ReliabilitySemiring` via x ↦ log(x), but callers
|
|
89
|
+
* skip the intermediate floats and stay stable over deep chains.
|
|
90
|
+
*
|
|
91
|
+
* Used by memory-graph's `recallConfidentChain` lens — most-confident
|
|
92
|
+
* reasoning chain through the memory graph. Also valid as the Viterbi
|
|
93
|
+
* recurrence semiring on DAG-structured trellises (when HMM-shape
|
|
94
|
+
* inference joins the codebase as a separate primitive).
|
|
95
|
+
*/
|
|
96
|
+
export const MaxProductLogSemiring = {
|
|
97
|
+
zero: -Infinity,
|
|
98
|
+
one: 0,
|
|
99
|
+
add: (a, b) => Math.max(a, b),
|
|
100
|
+
mul: (a, b) => a + b,
|
|
101
|
+
};
|
|
102
|
+
// ── Semiring Combinators ────────────────────────────────────────────
|
|
103
|
+
/**
|
|
104
|
+
* Product semiring: optimize multiple concerns simultaneously.
|
|
105
|
+
*
|
|
106
|
+
* (A × B, ⊕_A × ⊕_B, ⊗_A × ⊗_B, (0_A, 0_B), (1_A, 1_B))
|
|
107
|
+
*
|
|
108
|
+
* One graph traversal computes trust × cost × latency in a single pass.
|
|
109
|
+
*/
|
|
110
|
+
export function productSemiring(sa, sb) {
|
|
111
|
+
const saEq = sa.eq;
|
|
112
|
+
const sbEq = sb.eq;
|
|
113
|
+
const eqA = (a, b) => (saEq ? saEq(a, b) : a === b);
|
|
114
|
+
const eqB = (a, b) => (sbEq ? sbEq(a, b) : a === b);
|
|
115
|
+
return {
|
|
116
|
+
zero: [sa.zero, sb.zero],
|
|
117
|
+
one: [sa.one, sb.one],
|
|
118
|
+
add: (x, y) => [sa.add(x[0], y[0]), sb.add(x[1], y[1])],
|
|
119
|
+
mul: (x, y) => [sa.mul(x[0], y[0]), sb.mul(x[1], y[1])],
|
|
120
|
+
eq: (x, y) => eqA(x[0], y[0]) && eqB(x[1], y[1]),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Lift a scalar semiring into a named-fields record semiring.
|
|
125
|
+
* Useful when you want labeled dimensions instead of nested tuples.
|
|
126
|
+
*
|
|
127
|
+
* const Multi = recordSemiring({ trust: TrustSemiring, cost: CostSemiring });
|
|
128
|
+
* // Semiring<{ trust: number; cost: number }>
|
|
129
|
+
*/
|
|
130
|
+
export function recordSemiring(fields) {
|
|
131
|
+
const keys = Object.keys(fields);
|
|
132
|
+
const zero = {};
|
|
133
|
+
const one = {};
|
|
134
|
+
const eqs = {};
|
|
135
|
+
for (const k of keys) {
|
|
136
|
+
const f = fields[k];
|
|
137
|
+
zero[k] = f.zero;
|
|
138
|
+
one[k] = f.one;
|
|
139
|
+
const fEq = f.eq;
|
|
140
|
+
eqs[k] = fEq
|
|
141
|
+
? (a, b) => fEq(a, b)
|
|
142
|
+
: (a, b) => a === b;
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
zero,
|
|
146
|
+
one,
|
|
147
|
+
add(a, b) {
|
|
148
|
+
const r = {};
|
|
149
|
+
for (const k of keys) {
|
|
150
|
+
const f = fields[k];
|
|
151
|
+
r[k] = f.add(a[k], b[k]);
|
|
152
|
+
}
|
|
153
|
+
return r;
|
|
154
|
+
},
|
|
155
|
+
mul(a, b) {
|
|
156
|
+
const r = {};
|
|
157
|
+
for (const k of keys) {
|
|
158
|
+
const f = fields[k];
|
|
159
|
+
r[k] = f.mul(a[k], b[k]);
|
|
160
|
+
}
|
|
161
|
+
return r;
|
|
162
|
+
},
|
|
163
|
+
eq(a, b) {
|
|
164
|
+
for (const k of keys) {
|
|
165
|
+
if (!eqs[k](a[k], b[k]))
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Map a semiring through an isomorphism.
|
|
174
|
+
* Useful for wrapping/unwrapping branded types or unit conversions.
|
|
175
|
+
*/
|
|
176
|
+
export function mappedSemiring(base, to, from) {
|
|
177
|
+
const bEq = base.eq;
|
|
178
|
+
const baseEq = (a, b) => (bEq ? bEq(a, b) : a === b);
|
|
179
|
+
return {
|
|
180
|
+
zero: to(base.zero),
|
|
181
|
+
one: to(base.one),
|
|
182
|
+
add: (a, b) => to(base.add(from(a), from(b))),
|
|
183
|
+
mul: (a, b) => to(base.mul(from(a), from(b))),
|
|
184
|
+
eq: (a, b) => baseEq(from(a), from(b)),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=semiring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semiring.js","sourceRoot":"","sources":["../src/semiring.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAuBH,uEAAuE;AAEvE,0EAA0E;AAC1E,MAAM,CAAC,MAAM,aAAa,GAAqB;IAC7C,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7B,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAqB;IAC5C,IAAI,EAAE,QAAQ;IACd,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7B,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC;CACrB,CAAC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xC,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAiB,EACjB,EAAe,EACf,IAAiB;IAEjB,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC;IACpB,MAAM,MAAM,GAAG,CAAC,CAAI,EAAE,CAAI,EAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACpE,OAAO;QACL,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;QACnB,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QACjB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;KACvC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settlement mode types — relay-mediated vs peer-to-peer settlement.
|
|
3
|
+
*
|
|
4
|
+
* Permissive floor (Apache-2.0): these types define the interoperable format
|
|
5
|
+
* for settlement mode selection and payment proof verification.
|
|
6
|
+
*/
|
|
7
|
+
/** How money moves for a task: through the relay's virtual accounts, or directly onchain. */
|
|
8
|
+
export type SettlementMode = "relay" | "p2p";
|
|
9
|
+
/**
|
|
10
|
+
* Proof of direct onchain payment from delegator to worker.
|
|
11
|
+
* Submitted by the delegator at task submission time.
|
|
12
|
+
*/
|
|
13
|
+
export interface P2pPaymentProof {
|
|
14
|
+
/** Onchain transaction signature (Solana base58, 87-88 chars). */
|
|
15
|
+
tx_hash: string;
|
|
16
|
+
/** Chain identifier (e.g., "solana"). */
|
|
17
|
+
chain: string;
|
|
18
|
+
/** CAIP-2 network identifier. */
|
|
19
|
+
network: string;
|
|
20
|
+
/** Worker's declared settlement address (base58 for Solana). */
|
|
21
|
+
to_address: string;
|
|
22
|
+
/** Exact payment amount in micro-units (USDC 6 decimals). Must match expected amount. */
|
|
23
|
+
amount_micro: number;
|
|
24
|
+
}
|
|
25
|
+
/** Verification status of an onchain payment proof. */
|
|
26
|
+
export type PaymentVerificationStatus = "pending" | "verified" | "failed";
|
|
27
|
+
/**
|
|
28
|
+
* Relay-signed attestation of an agent's available balance.
|
|
29
|
+
*
|
|
30
|
+
* Workers verify this before starting expensive p2p tasks where
|
|
31
|
+
* the relay doesn't escrow. Short TTL (5 minutes) prevents stale attestations.
|
|
32
|
+
*
|
|
33
|
+
* Verification: strip `signature`, canonicalJson the rest, Ed25519 verify
|
|
34
|
+
* against the relay's public key (from /.well-known/motebit.json).
|
|
35
|
+
*/
|
|
36
|
+
export interface SolvencyProof {
|
|
37
|
+
/** The agent whose balance is attested. */
|
|
38
|
+
motebit_id: string;
|
|
39
|
+
/** Available balance in micro-units (after dispute holds). */
|
|
40
|
+
balance_available: number;
|
|
41
|
+
/** The amount the requester asked about. */
|
|
42
|
+
amount_requested: number;
|
|
43
|
+
/** Whether balance_available >= amount_requested. */
|
|
44
|
+
sufficient: boolean;
|
|
45
|
+
/** Relay that issued this proof. */
|
|
46
|
+
relay_id: string;
|
|
47
|
+
/** When the proof was generated (ms since epoch). */
|
|
48
|
+
attested_at: number;
|
|
49
|
+
/** When the proof expires (ms since epoch). attested_at + 300_000. */
|
|
50
|
+
expires_at: number;
|
|
51
|
+
/** Ed25519 signature over canonical JSON of all other fields. */
|
|
52
|
+
signature: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Result of policy-based settlement mode evaluation.
|
|
56
|
+
*
|
|
57
|
+
* The eligibility check considers: mutual opt-in, trust level,
|
|
58
|
+
* interaction history, active disputes, and declared settlement capabilities.
|
|
59
|
+
*/
|
|
60
|
+
export interface SettlementEligibility {
|
|
61
|
+
/** Whether p2p settlement is allowed for this pair + task. */
|
|
62
|
+
allowed: boolean;
|
|
63
|
+
/** Selected settlement mode. */
|
|
64
|
+
mode: SettlementMode;
|
|
65
|
+
/** Human-readable reason for the decision. */
|
|
66
|
+
reason: string;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=settlement-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settlement-mode.d.ts","sourceRoot":"","sources":["../src/settlement-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,6FAA6F;AAC7F,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,KAAK,CAAC;AAI7C;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAC;IACnB,yFAAyF;IACzF,YAAY,EAAE,MAAM,CAAC;CACtB;AAID,uDAAuD;AACvD,MAAM,MAAM,yBAAyB,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;AAI1E;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,4CAA4C;IAC5C,gBAAgB,EAAE,MAAM,CAAC;IACzB,qDAAqD;IACrD,UAAU,EAAE,OAAO,CAAC;IACpB,oCAAoC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;CACnB;AAID;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,8DAA8D;IAC9D,OAAO,EAAE,OAAO,CAAC;IACjB,gCAAgC;IAChC,IAAI,EAAE,cAAc,CAAC;IACrB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settlement mode types — relay-mediated vs peer-to-peer settlement.
|
|
3
|
+
*
|
|
4
|
+
* Permissive floor (Apache-2.0): these types define the interoperable format
|
|
5
|
+
* for settlement mode selection and payment proof verification.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=settlement-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settlement-mode.js","sourceRoot":"","sources":["../src/settlement-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
export type ToolMode = "api" | "ax" | "pixels";
|
|
33
|
+
/**
|
|
34
|
+
* All declared modes in priority order (cheapest first). Consumers
|
|
35
|
+
* that need to rank or enumerate tool modes iterate this array rather
|
|
36
|
+
* than hard-coding the order.
|
|
37
|
+
*/
|
|
38
|
+
export declare const TOOL_MODES: readonly ["api", "ax", "pixels"];
|
|
39
|
+
/**
|
|
40
|
+
* Priority index of a declared mode (0 = cheapest). Tools without a
|
|
41
|
+
* `mode` declaration sort to the end (`TOOL_MODES.length`) — they are
|
|
42
|
+
* neither rejected nor prioritized, just deprioritized relative to
|
|
43
|
+
* explicit tiers.
|
|
44
|
+
*/
|
|
45
|
+
export declare function toolModePriority(mode: ToolMode | undefined): number;
|
|
46
|
+
//# sourceMappingURL=tool-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-mode.d.ts","sourceRoot":"","sources":["../src/tool-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,IAAI,GAAG,QAAQ,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,UAAU,kCAAmC,CAAC;AAE3D;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,CAInE"}
|