@motebit/protocol 0.8.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 +17 -2
- package/dist/credential-anchor.d.ts.map +1 -1
- package/dist/credential-anchor.js +3 -2
- package/dist/credential-anchor.js.map +1 -1
- 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/index.d.ts +692 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -2
- 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 +16 -0
- package/dist/semiring.d.ts.map +1 -1
- package/dist/semiring.js +21 -0
- package/dist/semiring.js.map +1 -1
- 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/package.json +8 -5
- package/dist/__tests__/branded-ids.test.d.ts +0 -2
- package/dist/__tests__/branded-ids.test.d.ts.map +0 -1
- package/dist/__tests__/branded-ids.test.js +0 -70
- package/dist/__tests__/branded-ids.test.js.map +0 -1
- package/dist/__tests__/semiring-laws.test.d.ts +0 -25
- package/dist/__tests__/semiring-laws.test.d.ts.map +0 -1
- package/dist/__tests__/semiring-laws.test.js +0 -231
- package/dist/__tests__/semiring-laws.test.js.map +0 -1
- package/dist/__tests__/semiring.test.d.ts +0 -2
- package/dist/__tests__/semiring.test.d.ts.map +0 -1
- package/dist/__tests__/semiring.test.js +0 -201
- package/dist/__tests__/semiring.test.js.map +0 -1
- package/dist/__tests__/traversal.test.d.ts +0 -2
- package/dist/__tests__/traversal.test.d.ts.map +0 -1
- package/dist/__tests__/traversal.test.js +0 -331
- package/dist/__tests__/traversal.test.js.map +0 -1
- package/dist/__tests__/trust-algebra.test.d.ts +0 -2
- package/dist/__tests__/trust-algebra.test.d.ts.map +0 -1
- package/dist/__tests__/trust-algebra.test.js +0 -105
- package/dist/__tests__/trust-algebra.test.js.map +0 -1
|
@@ -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,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Q,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,QAAQ,CAAC,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"}
|
package/dist/semiring.d.ts
CHANGED
|
@@ -62,6 +62,22 @@ export declare const ReliabilitySemiring: Semiring<number>;
|
|
|
62
62
|
export declare const RegulatoryRiskSemiring: Semiring<number>;
|
|
63
63
|
/** (∨, ∧, false, true) — can agent A reach agent B? */
|
|
64
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>;
|
|
65
81
|
/**
|
|
66
82
|
* Product semiring: optimize multiple concerns simultaneously.
|
|
67
83
|
*
|
package/dist/semiring.d.ts.map
CHANGED
|
@@ -1 +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,CAAC,MAAM,CAK5C,CAAC;AAEF,4EAA4E;AAC5E,e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;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE;KACvE,CAAC,IAAI,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/B,GAAG,QAAQ,CAAC,CAAC,CAAC,CAwCd;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EACjC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACjB,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EACf,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAChB,QAAQ,CAAC,CAAC,CAAC,CAUb"}
|
package/dist/semiring.js
CHANGED
|
@@ -78,6 +78,27 @@ export const BooleanSemiring = {
|
|
|
78
78
|
add: (a, b) => a || b,
|
|
79
79
|
mul: (a, b) => a && b,
|
|
80
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
|
+
};
|
|
81
102
|
// ── Semiring Combinators ────────────────────────────────────────────
|
|
82
103
|
/**
|
|
83
104
|
* Product semiring: optimize multiple concerns simultaneously.
|
package/dist/semiring.js.map
CHANGED
|
@@ -1 +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;AAEF,wEAAwE;AACxE,MAAM,CAAC,MAAM,eAAe,GAAqB;IAC/C,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;AAEF,4E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G,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"}
|
|
@@ -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"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@motebit/protocol",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Motebit
|
|
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",
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
"dist/**/*.d.ts",
|
|
18
18
|
"dist/**/*.d.ts.map",
|
|
19
19
|
"LICENSE",
|
|
20
|
+
"NOTICE",
|
|
20
21
|
"README.md"
|
|
21
22
|
],
|
|
22
23
|
"sideEffects": false,
|
|
23
|
-
"license": "
|
|
24
|
+
"license": "Apache-2.0",
|
|
24
25
|
"keywords": [
|
|
25
26
|
"motebit",
|
|
26
27
|
"protocol",
|
|
@@ -52,14 +53,16 @@
|
|
|
52
53
|
"vitest": "^2.1.0"
|
|
53
54
|
},
|
|
54
55
|
"engines": {
|
|
55
|
-
"node": ">=
|
|
56
|
+
"node": ">=20"
|
|
56
57
|
},
|
|
57
58
|
"scripts": {
|
|
58
59
|
"build": "tsc -b",
|
|
59
60
|
"test": "vitest run",
|
|
60
61
|
"test:coverage": "vitest run --coverage",
|
|
61
62
|
"typecheck": "tsc --noEmit",
|
|
62
|
-
"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",
|
|
63
66
|
"clean": "rm -rf dist .turbo *.tsbuildinfo"
|
|
64
67
|
}
|
|
65
68
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"branded-ids.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/branded-ids.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, expectTypeOf } from "vitest";
|
|
2
|
-
import { asMotebitId, asDeviceId, asNodeId, asGoalId, asEventId, asConversationId, asPlanId, asAllocationId, asSettlementId, asListingId, asProposalId, } from "../index.js";
|
|
3
|
-
describe("Branded ID types", () => {
|
|
4
|
-
it("string is assignable to branded type (backward compat)", () => {
|
|
5
|
-
expectTypeOf().toMatchTypeOf();
|
|
6
|
-
expectTypeOf().toMatchTypeOf();
|
|
7
|
-
expectTypeOf().toMatchTypeOf();
|
|
8
|
-
expectTypeOf().toMatchTypeOf();
|
|
9
|
-
});
|
|
10
|
-
it("branded type is assignable to string (for SQL, JSON)", () => {
|
|
11
|
-
expectTypeOf().toMatchTypeOf();
|
|
12
|
-
expectTypeOf().toMatchTypeOf();
|
|
13
|
-
});
|
|
14
|
-
it("branded types are NOT cross-assignable (catches the bug)", () => {
|
|
15
|
-
expectTypeOf().not.toMatchTypeOf();
|
|
16
|
-
expectTypeOf().not.toMatchTypeOf();
|
|
17
|
-
expectTypeOf().not.toMatchTypeOf();
|
|
18
|
-
expectTypeOf().not.toMatchTypeOf();
|
|
19
|
-
expectTypeOf().not.toMatchTypeOf();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe("Branded ID branding functions", () => {
|
|
23
|
-
it("asMotebitId brands a string as MotebitId", () => {
|
|
24
|
-
const id = asMotebitId("test-motebit-id");
|
|
25
|
-
expect(id).toBe("test-motebit-id");
|
|
26
|
-
// Runtime value is a plain string
|
|
27
|
-
expect(typeof id).toBe("string");
|
|
28
|
-
});
|
|
29
|
-
it("asDeviceId brands a string as DeviceId", () => {
|
|
30
|
-
const id = asDeviceId("dev-001");
|
|
31
|
-
expect(id).toBe("dev-001");
|
|
32
|
-
});
|
|
33
|
-
it("asNodeId brands a string as NodeId", () => {
|
|
34
|
-
const id = asNodeId("node-abc");
|
|
35
|
-
expect(id).toBe("node-abc");
|
|
36
|
-
});
|
|
37
|
-
it("asGoalId brands a string as GoalId", () => {
|
|
38
|
-
const id = asGoalId("goal-xyz");
|
|
39
|
-
expect(id).toBe("goal-xyz");
|
|
40
|
-
});
|
|
41
|
-
it("asEventId brands a string as EventId", () => {
|
|
42
|
-
const id = asEventId("evt-123");
|
|
43
|
-
expect(id).toBe("evt-123");
|
|
44
|
-
});
|
|
45
|
-
it("asConversationId brands a string as ConversationId", () => {
|
|
46
|
-
const id = asConversationId("conv-456");
|
|
47
|
-
expect(id).toBe("conv-456");
|
|
48
|
-
});
|
|
49
|
-
it("asPlanId brands a string as PlanId", () => {
|
|
50
|
-
const id = asPlanId("plan-789");
|
|
51
|
-
expect(id).toBe("plan-789");
|
|
52
|
-
});
|
|
53
|
-
it("asAllocationId brands a string as AllocationId", () => {
|
|
54
|
-
const id = asAllocationId("alloc-001");
|
|
55
|
-
expect(id).toBe("alloc-001");
|
|
56
|
-
});
|
|
57
|
-
it("asSettlementId brands a string as SettlementId", () => {
|
|
58
|
-
const id = asSettlementId("settle-002");
|
|
59
|
-
expect(id).toBe("settle-002");
|
|
60
|
-
});
|
|
61
|
-
it("asListingId brands a string as ListingId", () => {
|
|
62
|
-
const id = asListingId("list-003");
|
|
63
|
-
expect(id).toBe("list-003");
|
|
64
|
-
});
|
|
65
|
-
it("asProposalId brands a string as ProposalId", () => {
|
|
66
|
-
const id = asProposalId("prop-004");
|
|
67
|
-
expect(id).toBe("prop-004");
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
//# sourceMappingURL=branded-ids.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"branded-ids.test.js","sourceRoot":"","sources":["../../src/__tests__/branded-ids.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE5D,OAAO,EACL,WAAW,EACX,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,wDAAwD,EAAE,GAAG,E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AC,YAAY,CAAC,CAAC;QACxC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,EAAE,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;QACnC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;QACpD,MAAM,EAAE,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;QACpC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Property-based tests for semiring laws using fast-check.
|
|
3
|
-
*
|
|
4
|
-
* These verify the algebraic invariants that every algorithm in the
|
|
5
|
-
* semiring package depends on — associativity, commutativity, identity,
|
|
6
|
-
* annihilation, distributivity — over thousands of random inputs rather
|
|
7
|
-
* than a handful of hand-picked examples.
|
|
8
|
-
*
|
|
9
|
-
* ### Determinism
|
|
10
|
-
*
|
|
11
|
-
* Fast-check defaults to a time-based seed, which means two CI runs
|
|
12
|
-
* can draw different inputs and expose different edge cases. That
|
|
13
|
-
* turns property tests into nondeterministic flakes under parallel
|
|
14
|
-
* monorepo execution — one of the 103 tests in this file fired
|
|
15
|
-
* intermittently during the pre-push hook. Fixed by pinning a seed:
|
|
16
|
-
* every run now draws the same input sequence, so a passing run is a
|
|
17
|
-
* reproducible guarantee, and a failing run is a bisectable
|
|
18
|
-
* counterexample instead of a ghost.
|
|
19
|
-
*
|
|
20
|
-
* If a new law fails locally but passes the fixed-seed CI run, bump
|
|
21
|
-
* `FC_NUM_RUNS` to explore more inputs, or switch the seed temporarily
|
|
22
|
-
* to confirm the counterexample isn't a cherry-pick.
|
|
23
|
-
*/
|
|
24
|
-
export {};
|
|
25
|
-
//# sourceMappingURL=semiring-laws.test.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"semiring-laws.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/semiring-laws.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG"}
|