pico-engine 1.6.2 → 1.8.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/README.md +117 -14
- package/dist/RulesetRegistryLoaderFs.js +24 -8
- package/dist/auth/cookies.js +32 -0
- package/dist/auth/index.js +6 -1
- package/dist/bundledKrl.js +129 -11
- package/dist/channelIdentityPolicy.js +22 -0
- package/dist/cli.js +105 -46
- package/dist/engineConfig.js +280 -0
- package/dist/identity/IdentityService.js +90 -0
- package/dist/identity/crossPico.js +106 -30
- package/dist/identity/didoModule.js +80 -18
- package/dist/identity/establishSubscription.js +2 -2
- package/dist/identity/identityPortable.js +92 -0
- package/dist/identity/index.js +10 -1
- package/dist/identity/localPeerReconcile.js +65 -0
- package/dist/identity/peerDid4.js +175 -0
- package/dist/identity/peerDid4Create.js +90 -0
- package/dist/identity/portableExportPrepare.js +196 -0
- package/dist/identity/portableMove.js +87 -0
- package/dist/identity/skyIntro.js +10 -4
- package/dist/identity/skyProtocol.js +26 -1
- package/dist/identity/skyRotation.js +121 -0
- package/dist/identity/store.js +5 -1
- package/dist/identity/subscriptionEntSync.js +72 -0
- package/dist/identity/veramoDidComm.js +41 -2
- package/dist/identity/webvh.js +4 -2
- package/dist/identity/webvhRelocation.js +115 -0
- package/dist/index.js +127 -34
- package/dist/levelDb.js +102 -0
- package/dist/logging.js +47 -8
- package/dist/oauth/OAuthService.js +12 -5
- package/dist/oauth/channelEligibility.js +7 -1
- package/dist/oauth/index.js +3 -1
- package/dist/policyConfigFromJson.js +112 -0
- package/dist/runMcp.js +27 -0
- package/dist/server.js +95 -24
- package/dist/subtreeWrangler.js +180 -0
- package/dist/uiChannelPolicies.js +16 -0
- package/krl/io.picolabs.oauth.krl +51 -5
- package/krl/io.picolabs.pds.krl +131 -10
- package/krl/io.picolabs.pico-engine-ui.krl +219 -22
- package/krl/io.picolabs.portable_subtree.krl +97 -0
- package/krl/io.picolabs.subscription.krl +226 -72
- package/krl/io.picolabs.wrangler.krl +300 -58
- package/mcp/devResources.js +118 -0
- package/mcp/devTools.js +351 -0
- package/mcp/engineClient.js +133 -0
- package/mcp/meshHttp.js +137 -0
- package/mcp/meshTools.js +189 -0
- package/mcp/runStdio.js +34 -0
- package/mcp/schemaToZod.js +56 -0
- package/package.json +22 -8
- package/public/docs/_sidebar.md +2 -1
- package/public/docs/llms-full.txt +479 -0
- package/public/docs/llms.txt +37 -0
- package/public/docs/openapi.yaml +78 -0
- package/public/docs/pico-engine.md +235 -4
- package/public/docs/pico-overview.md +117 -0
- package/public/docs/pico.md +3 -1
- package/public/docs/rulesets/README.md +25 -0
- package/public/docs/rulesets/io.picolabs.oauth.md +71 -0
- package/public/docs/rulesets/io.picolabs.pds.md +327 -0
- package/public/docs/rulesets/io.picolabs.pico-engine-ui.md +65 -0
- package/public/docs/rulesets/io.picolabs.portable_subtree.md +94 -0
- package/public/docs/rulesets/io.picolabs.subscription.md +398 -0
- package/public/docs/rulesets/io.picolabs.wrangler.md +471 -0
- package/public/pico-engine-ui.css +1 -1
- package/public/pico-engine-ui.js +28 -26
- package/src/RulesetRegistryLoaderFs.ts +43 -11
- package/src/auth/cookies.ts +34 -0
- package/src/auth/index.ts +7 -0
- package/src/bundledKrl.ts +150 -12
- package/src/channelIdentityPolicy.ts +29 -0
- package/src/cli.ts +98 -40
- package/src/engineConfig.ts +345 -0
- package/src/identity/IdentityService.ts +189 -1
- package/src/identity/crossPico.ts +161 -41
- package/src/identity/didoModule.ts +140 -23
- package/src/identity/establishSubscription.ts +2 -2
- package/src/identity/identityPortable.ts +153 -0
- package/src/identity/index.ts +14 -0
- package/src/identity/localPeerReconcile.ts +97 -0
- package/src/identity/peerDid4.ts +197 -0
- package/src/identity/peerDid4Create.ts +121 -0
- package/src/identity/portableExportPrepare.ts +302 -0
- package/src/identity/portableMove.ts +193 -0
- package/src/identity/skyIntro.ts +16 -12
- package/src/identity/skyProtocol.ts +46 -0
- package/src/identity/skyRotation.ts +211 -0
- package/src/identity/store.ts +5 -1
- package/src/identity/subscriptionEntSync.ts +97 -0
- package/src/identity/veramoDidComm.ts +52 -2
- package/src/identity/webvh.ts +4 -4
- package/src/identity/webvhRelocation.ts +167 -0
- package/src/index.ts +179 -39
- package/src/levelDb.ts +122 -0
- package/src/logging.ts +63 -11
- package/src/oauth/OAuthService.ts +20 -6
- package/src/oauth/channelEligibility.ts +9 -0
- package/src/oauth/index.ts +7 -1
- package/src/policyConfigFromJson.ts +131 -0
- package/src/runMcp.ts +30 -0
- package/src/server.ts +133 -27
- package/src/subtreeWrangler.ts +278 -0
- package/src/uiChannelPolicies.ts +16 -0
- package/krl/io.picolabs.did-o.krl +0 -349
- package/krl/test/didtestdid.krl +0 -78
|
@@ -2,9 +2,10 @@ ruleset io.picolabs.subscription {
|
|
|
2
2
|
meta {
|
|
3
3
|
name "subscription "
|
|
4
4
|
description <<
|
|
5
|
-
Tx/Rx
|
|
5
|
+
Pico-to-pico relationships (Tx/Rx). User-facing term: relationship.
|
|
6
|
+
Ruleset RID io.picolabs.subscription is stable; prefer module alias relationship.
|
|
6
7
|
>>
|
|
7
|
-
author "
|
|
8
|
+
author "Picolabs"
|
|
8
9
|
use module io.picolabs.wrangler alias wrangler
|
|
9
10
|
provides established, outbound, inbound, wellKnown_Rx, autoAcceptConfig, queryOnSub
|
|
10
11
|
shares established, outbound, inbound, wellKnown_Rx, autoAcceptConfig, queryOnSub
|
|
@@ -12,42 +13,7 @@ ruleset io.picolabs.subscription {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
global{
|
|
15
|
-
|
|
16
|
-
.put("queries",__testing.get("queries").map(function(q){
|
|
17
|
-
q.delete("args")
|
|
18
|
-
}))
|
|
19
|
-
.put("events",[
|
|
20
|
-
{ "domain": "wrangler", "name": "subscription",
|
|
21
|
-
"attrs": [ "wellKnown_Tx","Rx_role","Tx_role","name","channel_type","Tx_host","password"] },
|
|
22
|
-
{ "domain": "wrangler", "name": "subscription",
|
|
23
|
-
"attrs": [ "wellKnown_Tx","Rx_role","Tx_role","name","channel_type","password"] },
|
|
24
|
-
{ "domain": "wrangler", "name": "subscription",
|
|
25
|
-
"attrs": [ "wellKnown_Tx","password"] },
|
|
26
|
-
{ "domain": "wrangler", "name": "subscription",
|
|
27
|
-
"attrs": [ "wellKnown_Tx"] },
|
|
28
|
-
{ "domain": "wrangler", "name": "relationship",
|
|
29
|
-
"attrs": [ "wellKnown_Tx","Rx_role","Tx_role","name","channel_type","Tx_host","password","layer2","target_did"] },
|
|
30
|
-
{ "domain": "wrangler", "name": "pending_subscription_approval",
|
|
31
|
-
"attrs": [ "Id" ] },
|
|
32
|
-
{ "domain": "wrangler", "name": "pending_relationship_approval",
|
|
33
|
-
"attrs": [ "Id" ] },
|
|
34
|
-
{ "domain": "wrangler", "name": "subscription_cancellation",
|
|
35
|
-
"attrs": [ "Id" ] },
|
|
36
|
-
{ "domain": "wrangler", "name": "relationship_cancellation",
|
|
37
|
-
"attrs": [ "Id" ] },
|
|
38
|
-
{ "domain": "wrangler", "name": "inbound_rejection",
|
|
39
|
-
"attrs": [ "Id" ] },
|
|
40
|
-
{ "domain": "wrangler", "name": "inbound_relationship_rejection",
|
|
41
|
-
"attrs": [ "Id" ] },
|
|
42
|
-
{ "domain": "wrangler", "name": "outbound_cancellation",
|
|
43
|
-
"attrs": [ "Id" ] },
|
|
44
|
-
{ "domain": "wrangler", "name": "outbound_relationship_cancellation",
|
|
45
|
-
"attrs": [ "Id" ] },
|
|
46
|
-
{ "domain": "wrangler", "name": "autoAcceptConfigUpdate",
|
|
47
|
-
"attrs": [ "configName", "password", "regexMap","delete" ] },
|
|
48
|
-
{ "domain": "wrangler", "name": "intent_to_delete",
|
|
49
|
-
"attrs": [ "Id" ] },
|
|
50
|
-
])
|
|
16
|
+
|
|
51
17
|
/*
|
|
52
18
|
ent:inbound [
|
|
53
19
|
{
|
|
@@ -99,6 +65,12 @@ ent:established [
|
|
|
99
65
|
"allow": [{"rid": ctx:rid, "name": "wellKnown_Rx"}],
|
|
100
66
|
"deny": []
|
|
101
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Auto-accept rules for incoming relationship requests, keyed by config name.
|
|
70
|
+
* A request is accepted automatically when any config's entries match: each
|
|
71
|
+
* entry maps an attr name to a list of regexes tested against that attr.
|
|
72
|
+
* @returns Map "{ <configName>: { configName, password, entries: { <attr>: [regex, …] } } }"
|
|
73
|
+
*/
|
|
102
74
|
autoAcceptConfig = function(){
|
|
103
75
|
ent:autoAcceptConfig.defaultsTo({})
|
|
104
76
|
}
|
|
@@ -109,13 +81,43 @@ ent:established [
|
|
|
109
81
|
doesntExist || passwordMatched
|
|
110
82
|
}
|
|
111
83
|
|
|
112
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Established relationships, optionally only those whose field `key` equals
|
|
86
|
+
* `value` (e.g. key "Tx_role", value "manifold_thing"). Each has Id, Rx (this
|
|
87
|
+
* pico's channel), Tx (the other pico's channel), roles, name, and, for Layer 2
|
|
88
|
+
* relationships, layer2 and the peer DIDs.
|
|
89
|
+
* @param key String "field to filter on, e.g. Id, Tx_role, Rx_role"
|
|
90
|
+
* @param value Any "value the field must equal"
|
|
91
|
+
* @returns Array
|
|
92
|
+
* @example "all" {}
|
|
93
|
+
* @example "by role" { "key": "Tx_role", "value": "<their role>" }
|
|
94
|
+
*/
|
|
95
|
+
established = function(key = null, value = null){
|
|
113
96
|
filterOn(ent:established, key, value)
|
|
114
97
|
}
|
|
115
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Relationship requests this pico has sent that are still waiting for the other
|
|
100
|
+
* side to approve. Optional filter as for established().
|
|
101
|
+
* @param key String "field to filter on"
|
|
102
|
+
* @param value Any "value the field must equal"
|
|
103
|
+
* @returns Array
|
|
104
|
+
* @example "all" {}
|
|
105
|
+
* @example "by id" { "key": "Id", "value": "<relationship id>" }
|
|
106
|
+
*/
|
|
107
|
+
outbound = function(key = null, value = null){//Tx_Pending
|
|
116
108
|
filterOn(ent:outbound, key, value)
|
|
117
109
|
}
|
|
118
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Relationship requests other picos have sent to this one that are waiting for
|
|
112
|
+
* approval (approve with wrangler:pending_relationship_approval). Optional filter
|
|
113
|
+
* as for established().
|
|
114
|
+
* @param key String "field to filter on"
|
|
115
|
+
* @param value Any "value the field must equal"
|
|
116
|
+
* @returns Array
|
|
117
|
+
* @example "all" {}
|
|
118
|
+
* @example "by id" { "key": "Id", "value": "<relationship id>" }
|
|
119
|
+
*/
|
|
120
|
+
inbound = function(key = null, value = null){//Rx_Pending
|
|
119
121
|
filterOn(ent:inbound, key, value)
|
|
120
122
|
}
|
|
121
123
|
|
|
@@ -126,27 +128,24 @@ ent:established [
|
|
|
126
128
|
|| ent:outbound.defaultsTo([]).length() > 0
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
@param [key], key in the map to filter on
|
|
132
|
-
@param [value], the value at the given key to filter on
|
|
133
|
-
@return an array of maps that contain the given key/value pair (if provided) from the array, defaulting to the original array if the key/value pair was not provided
|
|
134
|
-
*/
|
|
131
|
+
// The maps in array whose field key equals value. Returns the whole array
|
|
132
|
+
// (or [] if array is null) when key or value is not given.
|
|
135
133
|
filterOn = function(array, key, value){
|
|
136
134
|
defaultedArray = array.defaultsTo([]);
|
|
137
135
|
(key && value) => defaultedArray.filter(function(bus){ bus{key} == value}) | defaultedArray
|
|
138
136
|
}
|
|
139
137
|
|
|
138
|
+
/**
|
|
139
|
+
* This pico's well-known channel: the one other picos send relationship requests
|
|
140
|
+
* to (give its id as wellKnown_Tx when requesting a relationship with this pico).
|
|
141
|
+
* @returns Map "the channel, including its id"
|
|
142
|
+
*/
|
|
140
143
|
wellKnown_Rx = function(){
|
|
141
144
|
tags = ["wellKnown_Rx","Tx_Rx"]
|
|
142
145
|
return wrangler:channels(tags).head()
|
|
143
146
|
}
|
|
144
147
|
|
|
145
|
-
|
|
146
|
-
@param buses, an array of subscriptions
|
|
147
|
-
@param Id, a subscription id
|
|
148
|
-
@return the index of the subscription in the array with the given id. -1 if it does not exist
|
|
149
|
-
*/
|
|
148
|
+
// Index of the relationship with this Id in buses, or -1 if none has it.
|
|
150
149
|
indexOfId = function(buses, Id) {
|
|
151
150
|
buses.map(function(bus){
|
|
152
151
|
bus{"Id"}
|
|
@@ -161,8 +160,15 @@ ent:established [
|
|
|
161
160
|
}
|
|
162
161
|
|
|
163
162
|
/**
|
|
164
|
-
* Query a function on
|
|
165
|
-
* Layer 2
|
|
163
|
+
* Query a function on the pico at the other end of an established relationship.
|
|
164
|
+
* Layer 2 relationships go over DIDComm (or verified local dispatch); legacy ones
|
|
165
|
+
* query the other pico's Tx channel. Null if no relationship has that id.
|
|
166
|
+
* @param subId String "relationship id"
|
|
167
|
+
* @param rid String "ruleset id on the other pico"
|
|
168
|
+
* @param name String "shared function to call"
|
|
169
|
+
* @param args Map "arguments for the function"
|
|
170
|
+
* @returns Any "the function's result"
|
|
171
|
+
* @example "other pico's name" { "subId": "<relationship id>", "rid": "io.picolabs.wrangler", "name": "name" }
|
|
166
172
|
*/
|
|
167
173
|
queryOnSub = function(subId, rid, name, args) {
|
|
168
174
|
bus = established("Id", subId).head()
|
|
@@ -183,8 +189,11 @@ ent:established [
|
|
|
183
189
|
} | {};
|
|
184
190
|
_roles = event:attr("Tx_host") => // add possible host
|
|
185
191
|
roles.put(["Tx_host"] , host) | roles;
|
|
186
|
-
event:attr("Id") => // add subscription identifier
|
|
187
|
-
_roles.put(["Id"], event:attr("Id")) | _roles.put(["Id"], random:uuid())
|
|
192
|
+
withId = event:attr("Id") => // add subscription identifier
|
|
193
|
+
_roles.put(["Id"], event:attr("Id")) | _roles.put(["Id"], random:uuid());
|
|
194
|
+
// Manifold (and other apps) pass registry keys on wrangler:subscription; keep them on the bus.
|
|
195
|
+
picoID = event:attr("picoID");
|
|
196
|
+
picoID.isnull() == false && picoID != "" => withId.put("picoID", picoID) | withId
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
doesConfigMatch = function(config) {
|
|
@@ -242,11 +251,17 @@ ent:established [
|
|
|
242
251
|
|
|
243
252
|
rule cleanup_subscriptions {
|
|
244
253
|
select when wrangler rulesets_need_to_cleanup
|
|
254
|
+
or wrangler cleanup_relationships
|
|
245
255
|
always {
|
|
246
256
|
raise wrangler event "cancel_subscriptions" attributes event:attrs
|
|
247
257
|
}
|
|
248
258
|
}
|
|
249
259
|
|
|
260
|
+
/**
|
|
261
|
+
* Cancel every relationship this pico has: established ones are cancelled,
|
|
262
|
+
* inbound requests rejected, and outbound requests withdrawn, notifying the other
|
|
263
|
+
* picos. Used before deleting a pico.
|
|
264
|
+
*/
|
|
250
265
|
rule cancel_all_subscriptions {
|
|
251
266
|
select when wrangler cancel_subscriptions
|
|
252
267
|
pre {
|
|
@@ -319,6 +334,30 @@ ent:established [
|
|
|
319
334
|
//START OF A SUBSCRIPTION'S CREATION
|
|
320
335
|
//For the following comments, consider picoA sending the request to picoB
|
|
321
336
|
|
|
337
|
+
/**
|
|
338
|
+
* Request a relationship with another pico. Legacy (default): give the other
|
|
339
|
+
* pico's well-known channel as wellKnown_Tx. Layer 2: set layer2 true and give the
|
|
340
|
+
* other pico's DID as target_did; the request goes over DIDComm. The request is
|
|
341
|
+
* recorded in outbound() until the other side approves (or auto-accepts), then
|
|
342
|
+
* moves to established() and wrangler:subscription_added is raised. A request to
|
|
343
|
+
* this pico itself, or one missing wellKnown_Tx / target_did, raises
|
|
344
|
+
* self_relationship_failure, wellKnown_Tx_format_failure, or
|
|
345
|
+
* target_did_format_failure instead.
|
|
346
|
+
* @attr wellKnown_Tx String optional "legacy: the other pico's well-known channel id (its wellKnown_Rx)"
|
|
347
|
+
* @attr layer2 Boolean optional "true for a DID-based Layer 2 relationship"
|
|
348
|
+
* @attr target_did String optional "Layer 2: the other pico's DID"
|
|
349
|
+
* @attr name String optional "relationship name (random word if omitted)"
|
|
350
|
+
* @attr Rx_role String optional "this pico's role in the relationship"
|
|
351
|
+
* @attr Tx_role String optional "the other pico's role"
|
|
352
|
+
* @attr channel_type String optional "channel type for the new channel (default Tx_Rx)"
|
|
353
|
+
* @attr Tx_host String optional "legacy: the other pico's engine URL, if on a different engine"
|
|
354
|
+
* @attr password String optional "for the other pico's auto-accept config"
|
|
355
|
+
* @example "same engine" { "wellKnown_Tx": "<eci>" }
|
|
356
|
+
* @example "same engine, with roles" { "wellKnown_Tx": "<eci>", "name": "<name>", "Rx_role": "<my role>", "Tx_role": "<their role>" }
|
|
357
|
+
* @example "another engine" { "wellKnown_Tx": "<eci>", "Tx_host": "https://other.example" }
|
|
358
|
+
* @example "auto-accept password" { "wellKnown_Tx": "<eci>", "password": "<password>" }
|
|
359
|
+
* @example "Layer 2" { "layer2": true, "target_did": "<did>" }
|
|
360
|
+
*/
|
|
322
361
|
rule createRxBus {
|
|
323
362
|
select when wrangler subscription
|
|
324
363
|
or wrangler relationship
|
|
@@ -328,7 +367,7 @@ ent:established [
|
|
|
328
367
|
channel_type = event:attr("channel_type").defaultsTo("Tx_Rx","Tx_Rx channel_type used.")
|
|
329
368
|
pending_entry = pending_entry().put(["wellKnown_Tx"],event:attr("wellKnown_Tx"))
|
|
330
369
|
}
|
|
331
|
-
if not layer2 && pending_entry{"wellKnown_Tx"} then // check if we have someone to send a request to
|
|
370
|
+
if not layer2 && pending_entry{"wellKnown_Tx"} && pending_entry{"wellKnown_Tx"} != wellKnown_Rx(){"id"} then // check if we have someone to send a request to
|
|
332
371
|
ctx:newChannel([channel_name,channel_type],allow_all_eventPolicy,allow_all_queryPolicy) setting(channel); // create Rx
|
|
333
372
|
fired {
|
|
334
373
|
newBus = pending_entry.put({ "Rx" : channel{"id"} });
|
|
@@ -342,9 +381,24 @@ ent:established [
|
|
|
342
381
|
raise wrangler event "subscription_request_needed"
|
|
343
382
|
attributes event:attrs.put(fullNewBus);
|
|
344
383
|
raise wrangler event "outbound_pending_subscription_added" attributes event:attrs.put(fullNewBus)// API event
|
|
384
|
+
raise wrangler event "outbound_pending_relationship_added" attributes event:attrs.put(fullNewBus)// API event
|
|
345
385
|
}
|
|
346
386
|
}//end createMySubscription rule
|
|
347
387
|
|
|
388
|
+
// `where` binds to the event it follows, so each alternative needs its own;
|
|
389
|
+
// with one trailing `where`, every wrangler:subscription matched unguarded.
|
|
390
|
+
rule createRxBusLegacySelfFailure {
|
|
391
|
+
select when wrangler subscription
|
|
392
|
+
where not event:attr("layer2") == true
|
|
393
|
+
&& event:attr("wellKnown_Tx") == wellKnown_Rx(){"id"}
|
|
394
|
+
or wrangler relationship
|
|
395
|
+
where not event:attr("layer2") == true
|
|
396
|
+
&& event:attr("wellKnown_Tx") == wellKnown_Rx(){"id"}
|
|
397
|
+
fired {
|
|
398
|
+
raise wrangler event "self_relationship_failure" attributes event:attrs
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
348
402
|
rule createRxBusLegacyFailure {
|
|
349
403
|
select when wrangler subscription
|
|
350
404
|
or wrangler relationship
|
|
@@ -370,7 +424,7 @@ ent:established [
|
|
|
370
424
|
.put(["target_did"], target_did)
|
|
371
425
|
.put(["layer2"], true)
|
|
372
426
|
}
|
|
373
|
-
if layer2 && target_did then
|
|
427
|
+
if layer2 && target_did && target_did != wrangler:myDid() then
|
|
374
428
|
ctx:newChannel([channel_name,channel_type],allow_all_eventPolicy,allow_all_queryPolicy) setting(channel)
|
|
375
429
|
fired {
|
|
376
430
|
newBus = pending_entry.put({ "Rx" : channel{"id"} })
|
|
@@ -382,6 +436,19 @@ ent:established [
|
|
|
382
436
|
ent:outbound := outbound().append(fullNewBus)
|
|
383
437
|
raise wrangler event "subscription_request_needed" attributes event:attrs.put(fullNewBus)
|
|
384
438
|
raise wrangler event "outbound_pending_subscription_added" attributes event:attrs.put(fullNewBus)
|
|
439
|
+
raise wrangler event "outbound_pending_relationship_added" attributes event:attrs.put(fullNewBus)
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
rule createRxBusLayer2SelfFailure {
|
|
444
|
+
select when wrangler subscription
|
|
445
|
+
where event:attr("layer2") == true
|
|
446
|
+
&& event:attr("target_did") == wrangler:myDid()
|
|
447
|
+
or wrangler relationship
|
|
448
|
+
where event:attr("layer2") == true
|
|
449
|
+
&& event:attr("target_did") == wrangler:myDid()
|
|
450
|
+
fired {
|
|
451
|
+
raise wrangler event "self_relationship_failure" attributes event:attrs
|
|
385
452
|
}
|
|
386
453
|
}
|
|
387
454
|
|
|
@@ -425,7 +492,7 @@ ent:established [
|
|
|
425
492
|
pre {
|
|
426
493
|
layer2 = event:attr("layer2") == true
|
|
427
494
|
target = event:attr("target_did")
|
|
428
|
-
sent = layer2 && target => dido:sendSkyIntro({
|
|
495
|
+
sent = layer2 && target && target != wrangler:myDid() => dido:sendSkyIntro({
|
|
429
496
|
"subscriptionId": event:attr("Id"),
|
|
430
497
|
"targetDid": target,
|
|
431
498
|
"name": event:attr("name").defaultsTo(event:attr("channel_name")),
|
|
@@ -452,6 +519,7 @@ ent:established [
|
|
|
452
519
|
fired {
|
|
453
520
|
ent:inbound := inbound().append(pending_entry)
|
|
454
521
|
raise wrangler event "inbound_pending_subscription_added" attributes event:attrs
|
|
522
|
+
raise wrangler event "inbound_pending_relationship_added" attributes event:attrs
|
|
455
523
|
}
|
|
456
524
|
else {
|
|
457
525
|
raise wrangler event "no_Tx_did_failure" attributes event:attrs
|
|
@@ -473,6 +541,7 @@ ent:established [
|
|
|
473
541
|
});
|
|
474
542
|
ent:inbound := inbound().append( newBus );
|
|
475
543
|
raise wrangler event "inbound_pending_subscription_added" attributes event:attrs.put(["Rx"], Rx); // API event
|
|
544
|
+
raise wrangler event "inbound_pending_relationship_added" attributes event:attrs.put(["Rx"], Rx); // API event
|
|
476
545
|
}
|
|
477
546
|
else {
|
|
478
547
|
raise wrangler event "no_Tx_failure" attributes event:attrs // API event
|
|
@@ -489,9 +558,19 @@ ent:established [
|
|
|
489
558
|
if bus{"layer2"} == true then noop()
|
|
490
559
|
fired {
|
|
491
560
|
raise wrangler event "inbound_pending_subscription_approved" attributes event:attrs.put("Id", bus{"Id"}).put(["bus"],bus)
|
|
561
|
+
raise wrangler event "inbound_pending_relationship_approved" attributes event:attrs.put("Id", bus{"Id"}).put(["bus"],bus)
|
|
492
562
|
}
|
|
493
563
|
}
|
|
494
564
|
|
|
565
|
+
/**
|
|
566
|
+
* Approve a pending inbound relationship request (one listed in inbound()). The
|
|
567
|
+
* requesting pico is notified, and both sides raise wrangler:subscription_added
|
|
568
|
+
* once it is established. Works for legacy and Layer 2 requests.
|
|
569
|
+
* @attr Id String optional "relationship id; or identify it by Rx or Tx instead"
|
|
570
|
+
* @attr Rx String optional "this pico's channel for the relationship"
|
|
571
|
+
* @attr Tx String optional "the other pico's channel for the relationship"
|
|
572
|
+
* @example "by id" { "Id": "<relationship id>" }
|
|
573
|
+
*/
|
|
495
574
|
rule approveInboundPendingSubscription {
|
|
496
575
|
select when wrangler pending_subscription_approval
|
|
497
576
|
or wrangler pending_relationship_approval
|
|
@@ -509,6 +588,7 @@ ent:established [
|
|
|
509
588
|
}, bus{"Tx_host"})
|
|
510
589
|
fired {
|
|
511
590
|
raise wrangler event "inbound_pending_subscription_approved" attributes event:attrs.put("Id", bus{"Id"}).put(["bus"],bus)
|
|
591
|
+
raise wrangler event "inbound_pending_relationship_approved" attributes event:attrs.put("Id", bus{"Id"}).put(["bus"],bus)
|
|
512
592
|
}
|
|
513
593
|
}
|
|
514
594
|
|
|
@@ -528,11 +608,13 @@ ent:established [
|
|
|
528
608
|
ent:established := established().append(updated)
|
|
529
609
|
ent:outbound := buses.splice(index, 1)
|
|
530
610
|
raise wrangler event "subscription_added" attributes event:attrs.put(["bus"], updated)
|
|
611
|
+
raise wrangler event "relationship_added" attributes event:attrs.put(["bus"], updated)
|
|
531
612
|
}
|
|
532
613
|
}
|
|
533
614
|
|
|
534
615
|
rule addOutboundSubscription {
|
|
535
616
|
select when wrangler outbound_pending_subscription_approved
|
|
617
|
+
or wrangler outbound_pending_relationship_approved
|
|
536
618
|
pre{
|
|
537
619
|
outbound = outbound()
|
|
538
620
|
bus = findBus(outbound).put({"Tx" : event:attr("Tx"),
|
|
@@ -547,11 +629,13 @@ ent:established [
|
|
|
547
629
|
ent:established := established().append(bus);
|
|
548
630
|
ent:outbound := outbound.splice(index,1);
|
|
549
631
|
raise wrangler event "subscription_added" attributes event:attrs.put(["bus"], bus) // API event
|
|
632
|
+
raise wrangler event "relationship_added" attributes event:attrs.put(["bus"], bus) // API event
|
|
550
633
|
}
|
|
551
634
|
}
|
|
552
635
|
|
|
553
636
|
rule addInboundSubscription {
|
|
554
637
|
select when wrangler inbound_pending_subscription_approved
|
|
638
|
+
or wrangler inbound_pending_relationship_approved
|
|
555
639
|
pre{
|
|
556
640
|
inbound = inbound()
|
|
557
641
|
index = indexOfId(inbound,event:attr("Id"))
|
|
@@ -563,12 +647,14 @@ ent:established [
|
|
|
563
647
|
ent:established := established().append( event:attr("bus") );
|
|
564
648
|
ent:inbound := inbound.splice(index,1);
|
|
565
649
|
raise wrangler event "subscription_added" attributes event:attrs // API event
|
|
650
|
+
raise wrangler event "relationship_added" attributes event:attrs // API event
|
|
566
651
|
}
|
|
567
652
|
}
|
|
568
653
|
|
|
569
654
|
// Layer 2 (1.6+): provision did:peer + internal Rx identity when bus.layer2 is set.
|
|
570
655
|
rule establish_layer2_subscription_identity {
|
|
571
656
|
select when wrangler subscription_added
|
|
657
|
+
or wrangler relationship_added
|
|
572
658
|
pre {
|
|
573
659
|
bus = event:attr("bus").defaultsTo({})
|
|
574
660
|
layer2_identity = bus{"layer2"} == true => dido:establishSubscription(bus) | null
|
|
@@ -601,6 +687,16 @@ ent:established [
|
|
|
601
687
|
}
|
|
602
688
|
}
|
|
603
689
|
|
|
690
|
+
/**
|
|
691
|
+
* End an established relationship. It is removed on both picos, and the other
|
|
692
|
+
* pico is notified (over DIDComm for Layer 2). wrangler:subscription_removed is
|
|
693
|
+
* raised when done.
|
|
694
|
+
* @attr Id String optional "relationship id; or identify it by Rx or Tx instead"
|
|
695
|
+
* @attr Rx String optional "this pico's channel for the relationship"
|
|
696
|
+
* @attr Tx String optional "the other pico's channel for the relationship"
|
|
697
|
+
* @example "by id" { "Id": "<relationship id>" }
|
|
698
|
+
* @example "by this pico's channel" { "Rx": "<eci>" }
|
|
699
|
+
*/
|
|
604
700
|
rule cancelEstablished {
|
|
605
701
|
select when wrangler subscription_cancellation
|
|
606
702
|
or wrangler relationship_cancellation
|
|
@@ -636,6 +732,7 @@ ent:established [
|
|
|
636
732
|
fired {
|
|
637
733
|
ent:established := buses.splice(index,1);
|
|
638
734
|
raise wrangler event "subscription_removed" attributes event:attrs.put({ "bus" : bus }) // API event
|
|
735
|
+
raise wrangler event "relationship_removed" attributes event:attrs.put({ "bus" : bus }) // API event
|
|
639
736
|
}
|
|
640
737
|
}
|
|
641
738
|
|
|
@@ -656,6 +753,14 @@ ent:established [
|
|
|
656
753
|
}
|
|
657
754
|
}
|
|
658
755
|
|
|
756
|
+
/**
|
|
757
|
+
* Reject a pending inbound relationship request (one listed in inbound()). The
|
|
758
|
+
* requesting pico is notified and removes it from its outbound().
|
|
759
|
+
* @attr Id String optional "relationship id; or identify it by Rx or Tx instead"
|
|
760
|
+
* @attr Rx String optional "this pico's channel for the relationship"
|
|
761
|
+
* @attr Tx String optional "the other pico's channel for the relationship"
|
|
762
|
+
* @example "by id" { "Id": "<relationship id>" }
|
|
763
|
+
*/
|
|
659
764
|
rule cancelInbound {
|
|
660
765
|
select when wrangler inbound_rejection
|
|
661
766
|
or wrangler inbound_relationship_rejection
|
|
@@ -689,6 +794,7 @@ ent:established [
|
|
|
689
794
|
fired {
|
|
690
795
|
ent:inbound := buses.splice(index,1);
|
|
691
796
|
raise wrangler event "inbound_subscription_cancelled" attributes event:attrs.put({ "bus" : bus }) // API event
|
|
797
|
+
raise wrangler event "inbound_relationship_cancelled" attributes event:attrs.put({ "bus" : bus }) // API event
|
|
692
798
|
}
|
|
693
799
|
}
|
|
694
800
|
|
|
@@ -709,6 +815,15 @@ ent:established [
|
|
|
709
815
|
}
|
|
710
816
|
}
|
|
711
817
|
|
|
818
|
+
/**
|
|
819
|
+
* Withdraw a relationship request this pico sent that hasn't been approved yet
|
|
820
|
+
* (one listed in outbound()). The other pico is notified and removes it from its
|
|
821
|
+
* inbound().
|
|
822
|
+
* @attr Id String optional "relationship id; or identify it by Rx or Tx instead"
|
|
823
|
+
* @attr Rx String optional "this pico's channel for the relationship"
|
|
824
|
+
* @attr Tx String optional "the other pico's channel for the relationship"
|
|
825
|
+
* @example "by id" { "Id": "<relationship id>" }
|
|
826
|
+
*/
|
|
712
827
|
rule cancelOutbound {
|
|
713
828
|
select when wrangler outbound_cancellation
|
|
714
829
|
or wrangler outbound_relationship_cancellation
|
|
@@ -743,11 +858,27 @@ ent:established [
|
|
|
743
858
|
fired {
|
|
744
859
|
ent:outbound := buses.splice(index,1);
|
|
745
860
|
raise wrangler event "outbound_subscription_cancelled" attributes event:attrs.put({ "bus" : bus }) // API event
|
|
861
|
+
raise wrangler event "outbound_relationship_cancelled" attributes event:attrs.put({ "bus" : bus }) // API event
|
|
746
862
|
}
|
|
747
863
|
}
|
|
748
864
|
|
|
865
|
+
/**
|
|
866
|
+
* Send an event to the picos at the other end of established relationships,
|
|
867
|
+
* selected by relationship id and/or by role. Each match receives the event on
|
|
868
|
+
* its channel (over DIDComm for Layer 2). If nothing matches, or domain or type is
|
|
869
|
+
* missing, raises wrangler:failed_to_send_event_to_relationship instead.
|
|
870
|
+
* @attr domain String "domain of the event to send"
|
|
871
|
+
* @attr type String "type of the event to send"
|
|
872
|
+
* @attr attrs Map optional "attributes of the event to send"
|
|
873
|
+
* @attr subID String optional "send on this relationship"
|
|
874
|
+
* @attr Tx_role String optional "send on every relationship where the other pico has this role"
|
|
875
|
+
* @attr Rx_role String optional "send on every relationship where this pico has this role"
|
|
876
|
+
* @example "one relationship" { "subID": "<relationship id>", "domain": "<domain>", "type": "<type>", "attrs": {} }
|
|
877
|
+
* @example "everyone with a role" { "Tx_role": "<their role>", "domain": "<domain>", "type": "<type>", "attrs": {} }
|
|
878
|
+
*/
|
|
749
879
|
rule sendEventToSubCheck {
|
|
750
880
|
select when wrangler send_event_on_subs
|
|
881
|
+
or wrangler send_event_on_relationships
|
|
751
882
|
pre {
|
|
752
883
|
subID = event:attr("subID")
|
|
753
884
|
Tx_role = event:attr("Tx_role")
|
|
@@ -767,9 +898,29 @@ ent:established [
|
|
|
767
898
|
"domainGiven":event:attr("domain").as("Boolean"),
|
|
768
899
|
"typeGiven":event:attr("type").as("Boolean"),
|
|
769
900
|
})
|
|
901
|
+
raise wrangler event "failed_to_send_event_to_relationship" attributes event:attrs.put({
|
|
902
|
+
"foundSubsToSendTo":subs.length() > 0,
|
|
903
|
+
"domainGiven":event:attr("domain").as("Boolean"),
|
|
904
|
+
"typeGiven":event:attr("type").as("Boolean"),
|
|
905
|
+
})
|
|
770
906
|
}
|
|
771
907
|
}
|
|
772
908
|
|
|
909
|
+
rule apply_webvh_peer_rotation {
|
|
910
|
+
select when wrangler webvh_peer_rotated
|
|
911
|
+
always {
|
|
912
|
+
subId = event:attr("Id")
|
|
913
|
+
newDid = event:attr("new_webvh_did")
|
|
914
|
+
ent:established := established().map(function(b){
|
|
915
|
+
b{"Id"} == subId => b
|
|
916
|
+
.put(["Tx_host"], event:attr("new_tx_host"))
|
|
917
|
+
.put(["Tx_did"], newDid)
|
|
918
|
+
.put(["layer2"], true)
|
|
919
|
+
| b
|
|
920
|
+
})
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
773
924
|
rule send_event_to_subs {
|
|
774
925
|
select when wrangler send_event_to_subs
|
|
775
926
|
foreach event:attr("subs") setting (sub)
|
|
@@ -789,6 +940,7 @@ ent:established [
|
|
|
789
940
|
|
|
790
941
|
rule autoAccept {
|
|
791
942
|
select when wrangler inbound_pending_subscription_added
|
|
943
|
+
or wrangler inbound_pending_relationship_added
|
|
792
944
|
pre{
|
|
793
945
|
/*
|
|
794
946
|
autoAcceptConfig{
|
|
@@ -811,24 +963,26 @@ ent:established [
|
|
|
811
963
|
if matches then noop()
|
|
812
964
|
fired {
|
|
813
965
|
raise wrangler event "pending_subscription_approval" attributes event:attrs;
|
|
966
|
+
raise wrangler event "pending_relationship_approval" attributes event:attrs;
|
|
814
967
|
raise wrangler event "auto_accepted_subscription_request" attributes event:attrs; //API event
|
|
968
|
+
raise wrangler event "auto_accepted_relationship_request" attributes event:attrs; //API event
|
|
815
969
|
}// else ...
|
|
816
970
|
}
|
|
817
971
|
|
|
818
972
|
/**
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
*
|
|
973
|
+
* Add, replace, or delete an auto-accept config. An incoming relationship request
|
|
974
|
+
* is approved automatically when, for any config, one of its entries matches:
|
|
975
|
+
* an entry maps an attr name to a list of regexes, and matches when the request's
|
|
976
|
+
* attr matches any of them. Give the whole config as config, or its parts as
|
|
977
|
+
* configName, regexMap, and password. Raises wrangler:auto_accept_config_updated,
|
|
978
|
+
* or autoAcceptConfigUpdate_failure when there is no config name.
|
|
979
|
+
* @attr configName String optional "name of the config to set or delete"
|
|
980
|
+
* @attr regexMap String optional "the entries, JSON-encoded: { <attr>: [regex, …] }"
|
|
981
|
+
* @attr config Map optional "the whole config instead: { configName, password, entries }"
|
|
982
|
+
* @attr password String optional "stored with the config; not currently checked"
|
|
983
|
+
* @attr delete Boolean optional "true to delete the named config"
|
|
984
|
+
* @example "accept a role" { "config": { "configName": "<name>", "entries": { "Tx_role": ["^<role>$"] } } }
|
|
985
|
+
* @example "delete" { "configName": "<name>", "delete": true }
|
|
832
986
|
*/
|
|
833
987
|
rule autoAcceptConfigUpdate {
|
|
834
988
|
select when wrangler autoAcceptConfigUpdate
|