pico-engine 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +147 -0
  2. package/dist/RulesetRegistryLoaderFs.js +4 -7
  3. package/dist/auth/AuthService.js +537 -0
  4. package/dist/auth/index.js +8 -0
  5. package/dist/auth/webauthn.js +97 -0
  6. package/dist/cli.js +11 -0
  7. package/dist/index.js +83 -46
  8. package/dist/logging.js +36 -27
  9. package/dist/oauth/OAuthService.js +356 -0
  10. package/dist/oauth/acg.js +495 -0
  11. package/dist/oauth/channelEligibility.js +26 -0
  12. package/dist/oauth/errors.js +12 -0
  13. package/dist/oauth/index.js +21 -0
  14. package/dist/oauth/krlModule.js +27 -0
  15. package/dist/oauth/meshOAuth.js +43 -0
  16. package/dist/provisionRoot.js +80 -0
  17. package/dist/server.js +565 -17
  18. package/dist/utils/toFileUrl.js +1 -2
  19. package/krl/io.picolabs.did-o.krl +25 -5
  20. package/krl/io.picolabs.oauth.krl +48 -0
  21. package/krl/io.picolabs.pds.krl +344 -0
  22. package/krl/io.picolabs.pico-engine-ui.krl +43 -10
  23. package/krl/io.picolabs.wrangler.krl +21 -20
  24. package/package.json +29 -29
  25. package/public/pico-engine-ui.css +4 -4
  26. package/public/pico-engine-ui.js +50 -16
  27. package/public/pico-labs-logo.png +0 -0
  28. package/src/RulesetRegistryLoaderFs.ts +6 -10
  29. package/src/auth/AuthService.ts +755 -0
  30. package/src/auth/index.ts +17 -0
  31. package/src/auth/webauthn.ts +182 -0
  32. package/src/cli.ts +11 -0
  33. package/src/index.ts +123 -56
  34. package/src/logging.ts +36 -47
  35. package/src/oauth/OAuthService.ts +474 -0
  36. package/src/oauth/acg.ts +666 -0
  37. package/src/oauth/channelEligibility.ts +26 -0
  38. package/src/oauth/errors.ts +10 -0
  39. package/src/oauth/index.ts +14 -0
  40. package/src/oauth/krlModule.ts +31 -0
  41. package/src/oauth/meshOAuth.ts +50 -0
  42. package/src/provisionRoot.ts +97 -0
  43. package/src/server.ts +647 -17
@@ -24,9 +24,9 @@ DID-O V 1.0.0
24
24
  >>
25
25
  author "Rembrand Paul Pardo, Kekoapoaono Montalbo, Josh Mann"
26
26
 
27
- provides addRoute, routes, send, sendEvent, sendQuery, didMap, clearDidMap, didDocs, clearDidDocs, pendingRotations, clearPendingRotations, generate_invitation
27
+ provides addRoute, routes, send, sendEvent, sendQuery, didMap, clearDidMap, didDocs, clearDidDocs, pendingRotations, clearPendingRotations, generate_invitation, generate_message
28
28
 
29
- shares routes, addRoute, didDocs, clearDidDocs, didMap, clearDidMap, pendingRotations, clearPendingRotations, generate_invitation
29
+ shares routes, addRoute, didDocs, clearDidDocs, didMap, clearDidMap, pendingRotations, clearPendingRotations, generate_invitation, generate_message
30
30
 
31
31
  use module io.picolabs.wrangler alias wrangler
32
32
  }
@@ -139,11 +139,31 @@ DID-O V 1.0.0
139
139
 
140
140
  ///////////////////////////////////////////// MESSAGE CREATORS //////////////////////////////////////////////
141
141
 
142
+ /**
143
+ * Generates and returns a DIDComm v2 message with the given message.
144
+ * message is formatted as follows:
145
+ * {
146
+ * type: string,
147
+ * body: any,
148
+ * from?: string,
149
+ * to?: [string],
150
+ * thid?: string,
151
+ * pthid?: string,
152
+ * expires_time?: number,
153
+ * attachments?: [Attachment]
154
+ * }
155
+ *
156
+ * Refer to didcomm-node package for Attachment object specifics.
157
+ */
158
+ generate_message = function(message) {
159
+ dido:generateMessage(message)
160
+ }
161
+
142
162
  /**
143
163
  * Creates an invitation OOB URL that can be used to establish DID based relationships.
144
164
  * This automates the DID, channel, and message creation and encodes it into a base64 Out-of-Band URL.
145
165
  */
146
- generate_invitation = function() {
166
+ generate_invitation = function(label) {
147
167
  DIDdoc = dido:generateDID(true)
148
168
  new_did = DIDdoc{"id"}
149
169
  invitation = dido:generateMessage({
@@ -152,7 +172,7 @@ DID-O V 1.0.0
152
172
  "body": {
153
173
  "goal_code": "exchange-did",
154
174
  "goal": "ExchangeDid",
155
- "label": "PicoInvite",
175
+ "label": label || "PicoInvite",
156
176
  "accept": [
157
177
  "didcomm/v2"
158
178
  ]
@@ -322,4 +342,4 @@ DID-O - V 1.0.0
322
342
  | ,.' `---'
323
343
  '_ ,--`
324
344
  `---'
325
- */
345
+ */
@@ -0,0 +1,48 @@
1
+ ruleset io.picolabs.oauth {
2
+ meta {
3
+ name "OAuth Mesh"
4
+ description <<
5
+ Optional mesh-level OAuth. Install on the root pico to require Bearer tokens on external /sky/*
6
+ for this mesh, and to hold per-mesh OAuth configuration (apps, consent policy, defaults).
7
+ Webhook Client Credentials (per channel) and app Authorization Code grants coexist here.
8
+ Not installed by default.
9
+
10
+ use module io.picolabs.oauth alias oauth
11
+ >>
12
+ author "PICOLABS"
13
+
14
+ provides meshEnabled, meshRequiresOAuth,
15
+ channelStatus, createChannelSecret, revokeChannelSecret, revokeTokens
16
+
17
+ shares meshEnabled, meshRequiresOAuth,
18
+ channelStatus, createChannelSecret, revokeChannelSecret, revokeTokens
19
+ }
20
+
21
+ global {
22
+ /** True when this ruleset is installed on the pico (mesh OAuth opt-in marker). */
23
+ meshEnabled = function() {
24
+ true
25
+ }
26
+
27
+ /** True when external /sky/* for eci requires a Bearer token (mesh lock or oauth-webhook tag). */
28
+ meshRequiresOAuth = function(eci) {
29
+ oauth:meshRequiresOAuth(eci)
30
+ }
31
+
32
+ channelStatus = function(eci) {
33
+ oauth:channelStatus(eci)
34
+ }
35
+
36
+ createChannelSecret = function(eci) {
37
+ oauth:createChannelSecret(eci)
38
+ }
39
+
40
+ revokeChannelSecret = function(eci) {
41
+ oauth:revokeChannelSecret(eci)
42
+ }
43
+
44
+ revokeTokens = function(eci) {
45
+ oauth:revokeTokens(eci)
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,344 @@
1
+ ruleset io.picolabs.pds {
2
+ meta {
3
+ name "PDS"
4
+ description <<
5
+ Pico Data Services (PDS), a common data base structure for all rulesets to use.
6
+ >>
7
+ author "PICOLABS"
8
+
9
+ use module io.picolabs.wrangler alias wrangler
10
+
11
+ logging on
12
+
13
+ provides items, get_keys,
14
+ profile,
15
+ settings, get_config_value, get_setting_data_value, config_value, settings_names,
16
+ getChannelEci
17
+
18
+ shares items, get_keys,
19
+ profile,
20
+ settings, get_config_value, get_setting_data_value, config_value, settings_names,
21
+ getChannelEci
22
+
23
+ }
24
+
25
+
26
+ // --------------------------------------------
27
+ // PDS entity variables (io.picolabs.pds RS scope only)
28
+ //
29
+ // ent:profile — this pico's display identity
30
+ // {
31
+ // "name": "",
32
+ // "description": "",
33
+ // "photo": "<url or data: URI>",
34
+ // "_created": "20260609T120000+0000", // set on first update
35
+ // "_modified": "20260609T153000+0000", // set on every update
36
+ // "email": "", // optional
37
+ // "phone": "" // optional
38
+ // }
39
+ //
40
+ // ent:general — namespaced app/domain data
41
+ // "<namespace>": {
42
+ // "<key>": <value>,
43
+ // ...
44
+ // }
45
+ // Path: ent:general{[namespace, key]} or ent:general{namespace} for whole namespace map
46
+ //
47
+ // ent:settings — per-ruleset configuration, keyed by RID
48
+ // "<rulesetRID>": {
49
+ // "name": "<display name>",
50
+ // "rid": "<rulesetRID>",
51
+ // "data": { "<configKey>": <value>, ... },
52
+ // "schema": []
53
+ // }
54
+ // Path: ent:settings{[rulesetRID, "data", configKey]} for config_value()
55
+ //
56
+ // --------------------------------------------
57
+
58
+
59
+ global {
60
+
61
+ // Default avatar: embedded SVG (no external URL dependency)
62
+ defaultUnknownPhoto = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2NCA2NCI+PHJlY3Qgd2lkdGg9IjY0IiBoZWlnaHQ9IjY0IiBmaWxsPSIjZWNlZmYxIi8+PGNpcmNsZSBjeD0iMzIiIGN5PSIyMiIgcj0iMTEiIGZpbGw9IiM3ODkwOWMiLz48ZWxsaXBzZSBjeD0iMzIiIGN5PSI1NCIgcng9IjE4IiByeT0iMTQiIGZpbGw9IiM3ODkwOWMiLz48L3N2Zz4="
63
+
64
+ items = function (namespace, key){
65
+ item = function(namespace, keyvalue) {
66
+ ent:general{[namespace, keyvalue]}
67
+ };
68
+
69
+ multipleItems = function(namespace) {
70
+ ent:general{namespace}
71
+ };
72
+ payload = (key.isnull()) => (namespace.isnull() => ent:general | multipleItems(namespace)) | item(namespace, key);
73
+ status = namespace.isnull() => "failed" | "success";
74
+ {
75
+ "status" : status,
76
+ "general" : payload
77
+ };
78
+ }
79
+
80
+ get_keys = function(namespace) {
81
+ ent:general{namespace}.keys()
82
+ }
83
+
84
+ profile = function(key){
85
+ get_profile = function(k) {
86
+ ent:profile{k};
87
+ };
88
+ get_all_profile = function() {
89
+ ent:profile;
90
+ };
91
+ payload = (key.isnull()) => get_all_profile() | get_profile(key);
92
+ {
93
+ "status" : "success",
94
+ "profile" : payload
95
+ };
96
+ };
97
+
98
+ settings_names = function() {
99
+ ent:settings.keys().map(function(setRID) {
100
+ setName = ent:settings{[setRID, "name"]};
101
+ {
102
+ "setRID": setRID,
103
+ "setName": setName
104
+ }
105
+ })
106
+ };
107
+
108
+ settings = function(Rid, Key, detail){
109
+ get_setting_all = function() {
110
+ ent:settings
111
+ };
112
+ get_setting = function(rid) {
113
+ ent:settings{rid}
114
+ };
115
+ get_setting_value = function(rid, varible) {
116
+ ent:settings{[rid, varible]}
117
+ };
118
+ get_data_value = function(rid, dataKey) {
119
+ ent:settings{[rid, "data", dataKey]}
120
+ };
121
+ pick = function() {
122
+ Rid.isnull() => get_setting_all()
123
+ | Key.isnull() => get_setting(Rid)
124
+ | detail.isnull() => get_setting_value(Rid, Key)
125
+ | get_data_value(Rid, detail)
126
+ };
127
+ {
128
+ "status" : "success",
129
+ "settings" : pick()
130
+ };
131
+ }
132
+
133
+ setting_data = function(setRID) {
134
+ ent:settings{[setRID, "data"]}
135
+ };
136
+
137
+ setting_schema = function(setRID) {
138
+ ent:settings{[setRID, "schema"]}
139
+ };
140
+
141
+ setting_data_value = function(setRID, setKey) {
142
+ ent:settings{[setRID, "data", setKey]}
143
+ };
144
+
145
+ get_setting_data_value = function(setRID, setKey) {
146
+ setting_data_value(setRID, setKey)
147
+ }
148
+
149
+ config_value = function(setKey) {
150
+ setRID = meta:callingRID();
151
+ ent:settings{[setRID, "data", setKey]}
152
+ };
153
+
154
+ get_config_value = function(setKey) {
155
+ config_value(setKey)
156
+ }
157
+
158
+ getChannelEci = function() {
159
+ ent:pds_channel_eci
160
+ }
161
+
162
+ defaultProfile = {
163
+ "name": "",
164
+ "description": "",
165
+ "photo": defaultUnknownPhoto
166
+ };
167
+
168
+ }//End Global
169
+ // Rules
170
+
171
+ //------------------------------- ent: general
172
+
173
+ rule add_item {
174
+ select when pds new_data_available
175
+ pre {
176
+ namespace = event:attr("namespace").defaultsTo("", "no namespace");
177
+ keyvalue = event:attr("key").defaultsTo("", "no key");
178
+ value = event:attr("value").defaultsTo("", "no value");
179
+ }
180
+ noop()
181
+ always {
182
+ ent:general{[namespace, keyvalue]} := value;
183
+ raise pds event "data_added"
184
+ attributes {"namespace": namespace, "keyvalue": keyvalue}
185
+ }
186
+ }
187
+
188
+ rule update_item {
189
+ select when pds updated_data_available
190
+ foreach(event:attr("value") || {}) setting(avalue, akey)
191
+ pre {
192
+ namespace = event:attr("namespace").defaultsTo("", "no namespace");
193
+ keyvalue = event:attr("key").defaultsTo("", "no key");
194
+ }
195
+ noop()
196
+ always {
197
+ ent:general{[namespace, keyvalue, akey]} := avalue;
198
+ raise pds event "data_updated"
199
+ attributes {"namespace": namespace, "keyvalue": keyvalue};
200
+ }
201
+ }
202
+
203
+ rule remove_item {
204
+ select when pds remove_old_data
205
+ pre{
206
+ namespace = event:attr("namespace").defaultsTo("", "no namespace");
207
+ keyvalue = event:attr("key").defaultsTo("", "no key");
208
+ }
209
+ noop()
210
+ always {
211
+ clear ent:general{[namespace, keyvalue]};
212
+ raise pds event "data_deleted"
213
+ attributes {"namespace": namespace, "keyvalue": keyvalue}
214
+ }
215
+ }
216
+
217
+ rule remove_namespace {
218
+ select when pds remove_namespace
219
+ pre{
220
+ namespace = event:attr("namespace").defaultsTo("", "no namespace");
221
+ }
222
+ noop()
223
+ always {
224
+ clear ent:general{namespace};
225
+ raise pds event "namespace_deleted"
226
+ attributes {"namespace": namespace}
227
+ }
228
+ }
229
+
230
+ rule itemed_mapped {
231
+ select when pds map_item
232
+ pre{
233
+ namespace = event:attr("namespace").defaultsTo("", "no namespace");
234
+ mapvalues = event:attr("mapvalues").defaultsTo("", "no mapvalues").decode();
235
+ }
236
+ noop()
237
+ always {
238
+ ent:general{namespace} := mapvalues;
239
+ raise pds event "new_map_added"
240
+ attributes {"namespace": namespace, "mapvalues": mapvalues};
241
+ }
242
+ }
243
+
244
+ rule update_profile {
245
+ select when pds updated_profile
246
+ pre {
247
+ newProfile = event:attrs.defaultsTo({}, "no attrs");
248
+ created = function(){
249
+ time:strftime(time:now(), "%Y%m%dT%H%M%S%z", {"tz":"UTC"});
250
+ };
251
+
252
+ buildProfile = function(newProfile){
253
+ profile = ent:profile || defaultProfile;
254
+ keepOrSet = function(key) {
255
+ newProfile{key}.isnull() => profile{key} | newProfile{key}
256
+ };
257
+ newProfile
258
+ .put(["name"], keepOrSet("name"))
259
+ .put(["description"], keepOrSet("description"))
260
+ .put(["photo"], keepOrSet("photo"))
261
+ .put(["email"], keepOrSet("email"))
262
+ .put(["phone"], keepOrSet("phone"))
263
+ .put(["_created"], (profile{"_created"} || created()))
264
+ .put(["_modified"], time:strftime(time:now(), "%Y%m%dT%H%M%S%z", {"tz":"UTC"}))
265
+ };
266
+ newly_constructed_profile = (newProfile.keys().length() > 0) =>
267
+ buildProfile(newProfile) |
268
+ "nothing to update";
269
+
270
+ }
271
+ if newly_constructed_profile != "nothing to update" then
272
+ noop()
273
+ fired {
274
+ ent:profile := newly_constructed_profile;
275
+ raise pds event "profile_updated" attributes newProfile.put(["_status"], "success");
276
+ }
277
+ else {
278
+ raise pds event "profile_updated" attributes newProfile.put(["_status"], "failure");
279
+ }
280
+ }
281
+
282
+ rule settings_added {
283
+ select when pds add_settings
284
+ pre {
285
+ set_name = event:attr("name").defaultsTo(0, "no Name");
286
+ set_rid = event:attr("keyed_rid").defaultsTo(0, "no keyed_rid");
287
+ set_schema = event:attr("schema").defaultsTo(0, "no Schema");
288
+ set_attr = event:attr("data_key").defaultsTo(0, "no setAttr");
289
+ set_value = event:attr("value").defaultsTo(0, "no Value");
290
+
291
+ }
292
+ noop()
293
+ always {
294
+ ent:settings{[set_rid, "name"]} := set_name;
295
+ ent:settings{[set_rid, "rid"]} := set_rid;
296
+ ent:settings{[set_rid, "schema"]} := set_schema if set_schema;
297
+ ent:settings{[set_rid, "data", set_attr]} := set_value if set_attr;
298
+ raise pds event "settings_added" attributes event:attrs;
299
+ }
300
+ }
301
+
302
+ rule create_pds_channel {
303
+ select when wrangler ruleset_installed where event:attr("rids") >< ctx:rid
304
+ pre {
305
+ channelName = "pds"
306
+ eventPolicy = {"allow": [{"domain": "pds", "name": "*"}], "deny": []}
307
+ queryPolicy = {"allow": [{"rid": "io.picolabs.pds", "name": "*"}], "deny": []}
308
+ existing_channels = wrangler:channels()
309
+ pds_channel = existing_channels.filter(function(chan) {
310
+ chan{"name"} == channelName
311
+ })
312
+ channel_exists = pds_channel.length() > 0
313
+ }
314
+ if not channel_exists then
315
+ wrangler:createChannel([channelName], eventPolicy, queryPolicy) setting(channel)
316
+ fired {
317
+ ent:pds_channel_eci := channel_exists => pds_channel.head(){"id"} | channel{"id"}
318
+ }
319
+ }
320
+
321
+ rule seed_profile_name {
322
+ select when wrangler ruleset_installed where event:attr("rids") >< ctx:rid
323
+ pre {
324
+ wrangler_name = wrangler:myself(){"name"}
325
+ existing_name = ent:profile{"name"}
326
+ needs_seed = wrangler_name && (existing_name.isnull() || existing_name == "")
327
+ }
328
+ if needs_seed then noop()
329
+ fired {
330
+ raise pds event "updated_profile" attributes {"name": wrangler_name}
331
+ }
332
+ }
333
+
334
+ rule clearPDS {
335
+ select when pds clear_all_data
336
+ noop()
337
+ always {
338
+ clear ent:general;
339
+ clear ent:profile;
340
+ clear ent:settings;
341
+ }
342
+ }
343
+
344
+ }
@@ -12,9 +12,16 @@ ruleset io.picolabs.pico-engine-ui {
12
12
  .map(function(c){c["id"]})
13
13
  .head()
14
14
  }
15
- getOtherUiECI = function(eci){
16
- thisPico = ctx:channels.any(function(c){c{"id"}==eci})
17
- return (eci && not thisPico) => ctx:query(eci, ctx:rid, "uiECI") | null
15
+ // Cached UI channel ECIs for parent/child links. Populated at child creation
16
+ // and backfilled on engine started. box()/pico() read these maps only — no
17
+ // cross-pico ctx:query — to avoid deadlocks (#493).
18
+ uiEciForChild = function(familyEci){
19
+ ent:child_ui_ecis{familyEci}
20
+ }
21
+ childUiEcis = function(){
22
+ ctx:children
23
+ .map(uiEciForChild)
24
+ .filter(function(eci){eci})
18
25
  }
19
26
  testingECI = function(){
20
27
  return ent:testingECI
@@ -25,8 +32,8 @@ ruleset io.picolabs.pico-engine-ui {
25
32
  box = function(){
26
33
  return {
27
34
  "eci": uiECI(),
28
- "parent": getOtherUiECI(ctx:parent),
29
- "children": ctx:children.map(getOtherUiECI),
35
+ "parent": ent:parent_ui_eci,
36
+ "children": childUiEcis(),
30
37
  "name": name(),
31
38
  "backgroundColor": ent:backgroundColor || "#87cefa",
32
39
  "x": ent:x || 100,
@@ -38,8 +45,8 @@ ruleset io.picolabs.pico-engine-ui {
38
45
  pico = function(){
39
46
  return {
40
47
  "eci": uiECI(),
41
- "parent": getOtherUiECI(ctx:parent),
42
- "children": ctx:children.map(getOtherUiECI),
48
+ "parent": ent:parent_ui_eci,
49
+ "children": childUiEcis(),
43
50
  "channels": ctx:channels,
44
51
  "rulesets": ctx:rulesets
45
52
  }
@@ -176,6 +183,33 @@ ruleset io.picolabs.pico-engine-ui {
176
183
  ent:height := event:attrs{"height"}.as("Number") if event:attrs{"height"}
177
184
  ent:name := event:attrs{"name"}.as("String") if event:attrs{"name"}
178
185
  ent:backgroundColor := event:attrs{"backgroundColor"}.validateColor() if event:attrs{"backgroundColor"}
186
+ ent:parent_ui_eci := event:attrs{"parentUiEci"} if event:attrs{"parentUiEci"}
187
+ }
188
+ }
189
+ rule remember_child_ui_eci {
190
+ select when wrangler new_child_created
191
+ pre {
192
+ uiEci = event:attr("uiEci")
193
+ familyEci = event:attr("eci")
194
+ }
195
+ if uiEci && familyEci then noop()
196
+ always {
197
+ ent:child_ui_ecis{[familyEci]} := uiEci
198
+ }
199
+ }
200
+ rule backfill_child_ui_eci {
201
+ select when engine started
202
+ foreach ctx:children setting(familyEci)
203
+ if ent:child_ui_ecis{familyEci}.isnull() then noop()
204
+ always {
205
+ ent:child_ui_ecis{[familyEci]} := ctx:query(familyEci, ctx:rid, "uiECI")
206
+ }
207
+ }
208
+ rule backfill_parent_ui_eci {
209
+ select when engine started
210
+ if ctx:parent && ent:parent_ui_eci.isnull() then noop()
211
+ always {
212
+ ent:parent_ui_eci := ctx:query(ctx:parent, ctx:rid, "uiECI")
179
213
  }
180
214
  }
181
215
  rule new {
@@ -196,9 +230,8 @@ ruleset io.picolabs.pico-engine-ui {
196
230
  pre {
197
231
  delUiEci = event:attrs{"eci"}
198
232
  delEci = ctx:children
199
- .filter(function(eci){
200
- other = getOtherUiECI(eci)
201
- return other == delUiEci
233
+ .filter(function(familyEci){
234
+ ent:child_ui_ecis{familyEci} == delUiEci
202
235
  })
203
236
  .head()
204
237
  }
@@ -68,10 +68,10 @@ ruleset io.picolabs.wrangler {
68
68
  Note this must include protocol (http:// or https://) being used and port number if not 80.
69
69
  For example "http://localhost:8080", which also is the default.
70
70
  _path - The sub path of the url which does not include mod or func.
71
- For example "/sky/cloud/", which also is the default.
71
+ For example "/sky/query/", which also is the default.
72
72
  _root_url - The entire url except eci, mod, func.
73
73
  For example, dependent on _host and _path is
74
- "http://localhost:8080/sky/cloud/", which also is the default.
74
+ "http://localhost:8080/sky/query/", which also is the default.
75
75
  picoQuery on success (if status code of request is 200) returns results of the called function.
76
76
  picoQuery on failure (if status code of request is not 200) returns a Map of error information which contains;
77
77
  error - general error message.
@@ -88,7 +88,7 @@ ruleset io.picolabs.wrangler {
88
88
  buildWebHook = function(eci, mod, func, _host, _path, _root_url) {
89
89
  createRootUrl = function (_host,_path){
90
90
  host = _host || meta:host;
91
- path = _path || "/sky/cloud/";
91
+ path = _path || "/sky/query/";
92
92
  root_url = host+path;
93
93
  root_url
94
94
  };
@@ -118,7 +118,7 @@ ruleset io.picolabs.wrangler {
118
118
  }
119
119
 
120
120
  skyQuery = function(eci, mod, func, params,_host,_path,_root_url) { // path must start with "/"", _host must include protocol(http:// or https://)
121
- //.../sky/cloud/<eci>/<rid>/<name>?name0=value0&...&namen=valuen
121
+ //.../sky/query/<eci>/<rid>/<name>?name0=value0&...&namen=valuen
122
122
  thisPico = ctx:channels.any(function(c){c{"id"}==eci})
123
123
  web_hook = buildWebHook(eci, mod, func, _host, _path, _root_url)
124
124
 
@@ -145,8 +145,8 @@ ruleset io.picolabs.wrangler {
145
145
  web_hook = buildWebHook(eci, mod, func, _host, _path, _root_url)
146
146
 
147
147
  response = thisPico => QUERY_SELF_INVALID_HTTP_MAP |
148
- thisHost => processQueryResponse(ctx:query(eci, mod, func, {}.put(params))) |
149
148
  isDid => dido:prepareQuery(eci, {"rid": mod, "name": func, "args": params}) |
149
+ thisHost => processQueryResponse(ctx:query(eci, mod, func, {}.put(params))) |
150
150
  processHTTPResponse(http:get(web_hook, {}.put(params)))
151
151
 
152
152
  response
@@ -360,6 +360,10 @@ ruleset io.picolabs.wrangler {
360
360
  "config":the_ruleset.get("config")
361
361
  }
362
362
  }
363
+ parentUiEci = ctx:channels
364
+ .filter(function(c){c["tags"].sort().join(",") == "engine,ui"})
365
+ .map(function(c){c["id"]})
366
+ .head()
363
367
  }
364
368
  every {
365
369
  ctx:newPico(rulesets=[
@@ -385,13 +389,14 @@ ruleset io.picolabs.wrangler {
385
389
  name="box",
386
390
  attrs={
387
391
  "name": name,
388
- "backgroundColor": backgroundColor
392
+ "backgroundColor": backgroundColor,
393
+ "parentUiEci": parentUiEci
389
394
  }
390
395
  )
391
396
  }
392
397
  fired {
393
398
  raise wrangler event "new_child_created"
394
- attributes event:attrs.put({"eci":newEci})
399
+ attributes event:attrs.put({"eci":newEci, "uiEci": newUiECI})
395
400
  }
396
401
  }
397
402
 
@@ -401,25 +406,21 @@ ruleset io.picolabs.wrangler {
401
406
  rule initialize_child_after_creation {
402
407
  select when wrangler pico_created
403
408
  pre {
404
- subscription_ruleset_url = function(){
405
- subscription_rid = "io.picolabs.subscription"
409
+ sibling_ruleset_url = function(rid){
406
410
  parts = ctx:rid_url.split("/")
407
- parts.splice(parts.length()-1,1,subscription_rid+".krl").join("/")
411
+ parts.splice(parts.length()-1,1,rid+".krl").join("/")
408
412
  }
409
- subs_url = subscription_ruleset_url()
410
-
411
- did_o_ruleset_url = function(){
412
- did_o_rid = "io.picolabs.did-o"
413
- parts = ctx:rid_url.split("/")
414
- parts.splice(parts.length()-1,1,did_o_rid+".krl").join("/")
415
- }
416
- did_o_url = did_o_ruleset_url()
413
+ subs_url = sibling_ruleset_url("io.picolabs.subscription")
414
+ did_o_url = sibling_ruleset_url("io.picolabs.did-o")
415
+ pds_url = sibling_ruleset_url("io.picolabs.pds")
417
416
  }
418
417
  fired {
419
418
  raise wrangler event "install_ruleset_request"
420
- attributes {"url":subs_url}
419
+ attributes {"url": pds_url}
420
+ raise wrangler event "install_ruleset_request"
421
+ attributes {"url": subs_url}
421
422
  raise wrangler event "install_ruleset_request"
422
- attributes {"url":did_o_url}
423
+ attributes {"url": did_o_url}
423
424
  ent:parent_eci := ctx:parent
424
425
  ent:name := event:attr("name")
425
426
  ent:id := ctx:picoId