@ours.network/tg-connector 0.1.8-nightly.5 → 0.2.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/dist/mufl_code/{7BCB02D5A3ED41E957280186E93B0D32DD1EC65737991197924874D640459264.muflo → B41B515D572E12F3FC493AEFB07FB1489B82656FC20E80EAE9616BCBE2316187.muflo} +0 -0
- package/dist/mufl_code/core/a2a_capabilities.mm +17 -1
- package/dist/mufl_code/core/a2a_messaging.mm +122 -26
- package/dist/mufl_code/core/a2a_notification_integration.mm +144 -0
- package/dist/mufl_code/core/a2a_notifications.mm +39 -14
- package/dist/mufl_code/core/config.mufl +1 -0
- package/dist/mufl_code/core/tests/mig.mjs +53 -16
- package/dist/mufl_code/core/tests/mig_actor.mu +24 -1
- package/dist/mufl_code/core/tests/notif.mjs +66 -0
- package/dist/mufl_code/core/tests/notif_actor.mu +22 -30
- package/dist/mufl_code/core/tests/run_notif.sh +5 -3
- package/dist/mufl_code/core/tests/test.mjs +41 -0
- package/dist/mufl_code/core/tests/test_actor.mu +44 -0
- package/dist/mufl_code/core/version.mm +1 -1
- package/package.json +1 -1
|
Binary file
|
|
@@ -200,6 +200,13 @@ library a2a_capabilities loads libraries
|
|
|
200
200
|
// an app never wires capabilities, and the piggyback must degrade to
|
|
201
201
|
// "advertises nothing" there, never abort an invite/restore leg.
|
|
202
202
|
self_caps is str[] = [].
|
|
203
|
+
// Part C: transport routes stay in this low-level capability namespace,
|
|
204
|
+
// while the messaging layer owns contact state, encryption checks, retry,
|
|
205
|
+
// and migration subscription. Optional for backwards-compatible actors.
|
|
206
|
+
on_advertise is (any -> transaction::results::type) =
|
|
207
|
+
fn (_: any) -> transaction::results::type { return transaction::success []. }.
|
|
208
|
+
on_advertise_ack is (any -> transaction::results::type) =
|
|
209
|
+
fn (_: any) -> transaction::results::type { return transaction::success []. }.
|
|
203
210
|
}
|
|
204
211
|
|
|
205
212
|
// FAIL-FAST: $supported is the static list of capability ids this app
|
|
@@ -221,13 +228,17 @@ library a2a_capabilities loads libraries
|
|
|
221
228
|
// handlers (e.g. core.receipts.*). $supported keeps its declared-implies-
|
|
222
229
|
// implemented handler guard; $advertise is for ids that gate peer
|
|
223
230
|
// traffic shaping only and never route through dispatch.
|
|
224
|
-
$advertise -> advertise_list: str[]
|
|
231
|
+
$advertise -> advertise_list: str[]+,
|
|
232
|
+
$on_advertise -> advertise_cb: (any -> transaction::results::type)+,
|
|
233
|
+
$on_advertise_ack -> advertise_ack_cb: (any -> transaction::results::type)+
|
|
225
234
|
))
|
|
226
235
|
{
|
|
227
236
|
describe -> describe_cb.
|
|
228
237
|
handlers -> handler_map.
|
|
229
238
|
on_unknown -> fallback.
|
|
230
239
|
if authorizer_cb != NIL { authorizer -> authorizer_cb. }
|
|
240
|
+
if advertise_cb != NIL { on_advertise -> advertise_cb?. }
|
|
241
|
+
if advertise_ack_cb != NIL { on_advertise_ack -> advertise_ack_cb?. }
|
|
231
242
|
merged is str[] = [].
|
|
232
243
|
sc supported_caps -- ( -> cap) { merged (_count merged|) -> cap. }
|
|
233
244
|
if advertise_list != NIL
|
|
@@ -273,6 +284,11 @@ library a2a_capabilities loads libraries
|
|
|
273
284
|
if (self_advertises cap) != TRUE { self_caps (_count self_caps|) -> cap. }
|
|
274
285
|
}
|
|
275
286
|
|
|
287
|
+
// Thin, callback-routed wire transactions. a2a_capabilities intentionally
|
|
288
|
+
// owns no contact or retry state; consumers register the orchestration hooks.
|
|
289
|
+
trn advertise args: any { return on_advertise args. }
|
|
290
|
+
trn advertise_ack args: any { return on_advertise_ack args. }
|
|
291
|
+
|
|
276
292
|
// ---- manifest helpers -------------------------------------------------
|
|
277
293
|
fn has_capability (_:($manifest -> m: app_manifest_t, $cap -> cap: str)) -> bool
|
|
278
294
|
{
|
|
@@ -83,6 +83,8 @@ library a2a_messaging loads libraries
|
|
|
83
83
|
// core 0.10 (B1): stateless AD re-advertise pushed to pre-existing legacy contacts on
|
|
84
84
|
// upgrade, so an idle legacy pair learns both sides are now v2 and the migration FSM fires.
|
|
85
85
|
readvertise_ad_tx = "::a2a_messaging::readvertise_ad".
|
|
86
|
+
capability_advertise_tx = "::a2a_capabilities::advertise".
|
|
87
|
+
capability_advertise_ack_tx = "::a2a_capabilities::advertise_ack".
|
|
86
88
|
// core 0.9.0 boxed APP-E2E (Option B): app data over the MIGRATED session rides these named
|
|
87
89
|
// boxes ($targ = the e2e_signed_message). DISTINCT from legacy receive_message_tx so the wire
|
|
88
90
|
// separates e2e-carrying box from legacy box (an attacker cannot confuse them).
|
|
@@ -188,6 +190,9 @@ library a2a_messaging loads libraries
|
|
|
188
190
|
// guarded on import (pre-0.5 exports import unchanged).
|
|
189
191
|
contact_pv is (global_id ->> int) = (,).
|
|
190
192
|
contact_caps is (global_id ->> str[]) = (,).
|
|
193
|
+
// ACK-confirmed capability fingerprint per contact. A missing/stale entry
|
|
194
|
+
// is retried by reconcile_advertise; only the encrypted ACK advances it.
|
|
195
|
+
contact_advertised_caps is (global_id ->> str) = (,).
|
|
191
196
|
// core 0.8.0: monotonic E2E anti-downgrade pin (SPEC §4). Positive-evidence,
|
|
192
197
|
// set TRUE the first time a peer advertises core.e2e and NEVER cleared — it
|
|
193
198
|
// CANNOT be derived from contact_caps (which is last-seen-wins, so a later
|
|
@@ -499,6 +504,10 @@ library a2a_messaging loads libraries
|
|
|
499
504
|
// (peer, wire_id) on unknown < sent < delivered < read — duplicates
|
|
500
505
|
// and out-of-order arrivals collapse to no-ops.
|
|
501
506
|
on_receipt_received is (any -> transaction::action::type[]) = fn (_: any) -> transaction::action::type[] { return []. }
|
|
507
|
+
// Optional core middleware at the successful message-send choke point.
|
|
508
|
+
// Integration modules install it without coupling messaging to them.
|
|
509
|
+
// Default no-op preserves every existing consumer.
|
|
510
|
+
post_send_middleware is (any -> transaction::action::type[]) = fn (_: any) -> transaction::action::type[] { return []. }
|
|
502
511
|
}
|
|
503
512
|
|
|
504
513
|
init = fn (_:(
|
|
@@ -534,6 +543,13 @@ library a2a_messaging loads libraries
|
|
|
534
543
|
}).
|
|
535
544
|
}
|
|
536
545
|
|
|
546
|
+
// Separate from init so an integration importing a2a_messaging can install
|
|
547
|
+
// after the consumer has wired its ordinary storage hooks.
|
|
548
|
+
fn set_post_send_middleware (cb: (any -> transaction::action::type[])) -> nil
|
|
549
|
+
{
|
|
550
|
+
post_send_middleware -> cb.
|
|
551
|
+
}
|
|
552
|
+
|
|
537
553
|
// ---- shared action builders -------------------------------------------
|
|
538
554
|
// Signal the host to persist the packet. Only emitted at the end of a
|
|
539
555
|
// complete procedure — intermediate states (e.g. channel handshake) are
|
|
@@ -1706,6 +1722,7 @@ library a2a_messaging loads libraries
|
|
|
1706
1722
|
$name -> receive_e2e_message_tx,
|
|
1707
1723
|
$targ -> ( $e2e_envelope -> (eenv $e2e_envelope), $emsignature -> (eenv $emsignature) ) ) ].
|
|
1708
1724
|
sc on_message_sent ($target_id -> target_id, $text -> text, $date -> sent_date, $wire_id -> wire_id, $reply_to -> reply_to) -- ( -> a) { eacts (_count eacts|) -> a. }
|
|
1725
|
+
sc post_send_middleware ($target_id -> target_id, $text -> text, $date -> sent_date, $wire_id -> wire_id, $reply_to -> reply_to) -- ( -> a) { eacts (_count eacts|) -> a. }
|
|
1709
1726
|
sc monitor_copy_actions "out" target_id sent_date text -- ( -> a) { eacts (_count eacts|) -> a. }
|
|
1710
1727
|
// §4 observability: source $session_id from the ACTUAL envelope (NOT a re-read of
|
|
1711
1728
|
// active_session_id — that would make the #1867 "session_id==pin" assertion CIRCULAR;
|
|
@@ -1727,6 +1744,10 @@ library a2a_messaging loads libraries
|
|
|
1727
1744
|
{
|
|
1728
1745
|
actions (_count actions|) -> a.
|
|
1729
1746
|
}
|
|
1747
|
+
sc post_send_middleware ($target_id -> target_id, $text -> text, $date -> sent_date, $wire_id -> wire_id, $reply_to -> reply_to) -- ( -> a)
|
|
1748
|
+
{
|
|
1749
|
+
actions (_count actions|) -> a.
|
|
1750
|
+
}
|
|
1730
1751
|
// FORCED: emit the outbound monitoring copy as core code, after the app
|
|
1731
1752
|
// hook, so the app cannot suppress it (self-gates on monitoring_proxy).
|
|
1732
1753
|
sc monitor_copy_actions "out" target_id sent_date text -- ( -> a)
|
|
@@ -1838,6 +1859,9 @@ library a2a_messaging loads libraries
|
|
|
1838
1859
|
delete contacts target_id.
|
|
1839
1860
|
if peer_ads target_id != NIL { delete peer_ads target_id. }
|
|
1840
1861
|
if contact_roots target_id != NIL { delete contact_roots target_id. }
|
|
1862
|
+
if contact_pv target_id != NIL { delete contact_pv target_id. }
|
|
1863
|
+
if contact_caps target_id != NIL { delete contact_caps target_id. }
|
|
1864
|
+
if contact_advertised_caps target_id != NIL { delete contact_advertised_caps target_id. }
|
|
1841
1865
|
|
|
1842
1866
|
// Contact-restore stores too: an orphaned deferred queue would persist in
|
|
1843
1867
|
// every export and, on a later RE-ADD of the same peer, the boot/GC sweep
|
|
@@ -2296,10 +2320,20 @@ library a2a_messaging loads libraries
|
|
|
2296
2320
|
// can never be silently overwritten with a different keyset).
|
|
2297
2321
|
address_document::process_address_document peer_ad TRUE.
|
|
2298
2322
|
|
|
2299
|
-
|
|
2300
|
-
|
|
2323
|
+
peer_name is str = "".
|
|
2324
|
+
if (args $peer_name) != NIL { peer_name -> (args $peer_name) safe str. }
|
|
2325
|
+
|
|
2326
|
+
// Idempotent re-introduction: refresh the stored AD. A contact created from a
|
|
2327
|
+
// nameless/legacy introduction may still be labelled by its CID; in that one
|
|
2328
|
+
// case adopt the now-available peer label. Any better name (including an
|
|
2329
|
+
// explicit invite alias) remains authoritative and is never overwritten.
|
|
2301
2330
|
if (contacts peer_cid) != NIL
|
|
2302
2331
|
{
|
|
2332
|
+
existing = (contacts peer_cid)?.
|
|
2333
|
+
if peer_name != "" && (existing $name) == (_str peer_cid)
|
|
2334
|
+
{
|
|
2335
|
+
contacts peer_cid -> ($name -> peer_name, $container_id -> peer_cid).
|
|
2336
|
+
}
|
|
2303
2337
|
peer_ads peer_cid -> peer_ad.
|
|
2304
2338
|
return transaction::success [
|
|
2305
2339
|
_notify_agent ($event -> $reintroduced, $container_id -> peer_cid, $by_cp -> sender_id),
|
|
@@ -2308,8 +2342,6 @@ library a2a_messaging loads libraries
|
|
|
2308
2342
|
}
|
|
2309
2343
|
|
|
2310
2344
|
// New contact: register under the CP-supplied display name (cid as last resort).
|
|
2311
|
-
peer_name is str = "".
|
|
2312
|
-
if (args $peer_name) != NIL { peer_name -> (args $peer_name) safe str. }
|
|
2313
2345
|
contact_label is str = (peer_name == "" ?? (_str peer_cid) ; peer_name).
|
|
2314
2346
|
contacts peer_cid -> ($name -> contact_label, $container_id -> peer_cid).
|
|
2315
2347
|
peer_ads peer_cid -> peer_ad.
|
|
@@ -2942,6 +2974,10 @@ library a2a_messaging loads libraries
|
|
|
2942
2974
|
{
|
|
2943
2975
|
actions (_count actions|) -> a.
|
|
2944
2976
|
}
|
|
2977
|
+
sc post_send_middleware ($target_id -> target_id, $text -> (m $text), $date -> (m $date), $wire_id -> (m $wire_id), $reply_to -> (m $reply_to)) -- ( -> a)
|
|
2978
|
+
{
|
|
2979
|
+
actions (_count actions|) -> a.
|
|
2980
|
+
}
|
|
2945
2981
|
sc monitor_copy_actions "out" target_id (m $date) (m $text) -- ( -> a)
|
|
2946
2982
|
{
|
|
2947
2983
|
actions (_count actions|) -> a.
|
|
@@ -4217,41 +4253,95 @@ library a2a_messaging loads libraries
|
|
|
4217
4253
|
return s.
|
|
4218
4254
|
}
|
|
4219
4255
|
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
//
|
|
4228
|
-
//
|
|
4229
|
-
//
|
|
4230
|
-
//
|
|
4256
|
+
fn fingerprint_caps (caps: str[]) -> str
|
|
4257
|
+
{
|
|
4258
|
+
s is str = "".
|
|
4259
|
+
sc caps -- ( -> c) { s -> (s + c) + ",". }
|
|
4260
|
+
return s.
|
|
4261
|
+
}
|
|
4262
|
+
|
|
4263
|
+
// Generic capability snapshot receiver. Exact replacement is intentional:
|
|
4264
|
+
// removals must propagate. The E2E pin remains monotonic, so an advertised
|
|
4265
|
+
// removal cannot reopen plaintext routing. Duplicate snapshots still ACK,
|
|
4266
|
+
// which repairs a lost ACK without duplicating delta-side effects.
|
|
4267
|
+
fn handle_capability_advertise (args: any) -> transaction::results::type
|
|
4268
|
+
{
|
|
4269
|
+
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
|
|
4270
|
+
encrypted_channel::check_encrypted_or_abort().
|
|
4271
|
+
sender_id = current_transaction_info::get_external_envelope_or_abort() $from.
|
|
4272
|
+
if (contacts sender_id) == NIL { return transaction::success []. }
|
|
4273
|
+
caps is str[] = ((args $caps) safe (str[])).
|
|
4274
|
+
fp = (args $fingerprint) safe str.
|
|
4275
|
+
abort "Capability advertisement fingerprint mismatch." when fp != fingerprint_caps caps.
|
|
4276
|
+
pv = (args $pv) safe int.
|
|
4277
|
+
prev = contact_caps sender_id.
|
|
4278
|
+
prev_fp is str = "".
|
|
4279
|
+
if prev != NIL { prev_fp -> fingerprint_caps prev?. }
|
|
4280
|
+
contact_caps sender_id -> caps.
|
|
4281
|
+
contact_pv sender_id -> pv.
|
|
4282
|
+
note_e2e_seen sender_id caps.
|
|
4283
|
+
actions is transaction::action::type[] = [
|
|
4284
|
+
encrypted_channel::send_encrypted_tx sender_id (
|
|
4285
|
+
$name -> capability_advertise_ack_tx,
|
|
4286
|
+
$targ -> ($fingerprint -> fp)
|
|
4287
|
+
)
|
|
4288
|
+
].
|
|
4289
|
+
if prev_fp != fp
|
|
4290
|
+
{
|
|
4291
|
+
actions (_count actions|) -> _notify_agent (
|
|
4292
|
+
$event -> $peer_capabilities_changed, $cid -> sender_id,
|
|
4293
|
+
$previous_fingerprint -> prev_fp, $fingerprint -> fp, $caps -> caps
|
|
4294
|
+
).
|
|
4295
|
+
// DR migration is a subscriber/special-case of the generic delta:
|
|
4296
|
+
// all eligibility, election, born-DR and epoch gates remain inside
|
|
4297
|
+
// the existing trigger unchanged.
|
|
4298
|
+
sc mig_trigger_actions sender_id -- ( -> a) { actions (_count actions|) -> a. }
|
|
4299
|
+
}
|
|
4300
|
+
actions (_count actions|) -> _save_state NIL.
|
|
4301
|
+
return transaction::success actions.
|
|
4302
|
+
}
|
|
4303
|
+
|
|
4304
|
+
fn handle_capability_advertise_ack (args: any) -> transaction::results::type
|
|
4305
|
+
{
|
|
4306
|
+
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
|
|
4307
|
+
encrypted_channel::check_encrypted_or_abort().
|
|
4308
|
+
sender_id = current_transaction_info::get_external_envelope_or_abort() $from.
|
|
4309
|
+
if (contacts sender_id) == NIL { return transaction::success []. }
|
|
4310
|
+
fp = (args $fingerprint) safe str.
|
|
4311
|
+
// A stale/replayed ACK cannot suppress a newer capability snapshot.
|
|
4312
|
+
if fp != caps_fingerprint NIL { return transaction::success []. }
|
|
4313
|
+
contact_advertised_caps sender_id -> fp.
|
|
4314
|
+
return transaction::success [ _save_state NIL ].
|
|
4315
|
+
}
|
|
4316
|
+
|
|
4317
|
+
// Part C: the SINGLE generic capability re-advertise entrypoint. The app declares
|
|
4318
|
+
// capabilities once at init and calls this on boot/GC. A persisted global fingerprint
|
|
4319
|
+
// detects code-defined changes; a persisted per-contact ACK ledger prevents repeat sends
|
|
4320
|
+
// while retrying offline/lost-ACK contacts. On a global change, the legacy full-AD push
|
|
4321
|
+
// remains a migration bootstrap subscriber/special-case. E2E account/session recovery is
|
|
4322
|
+
// intentionally still the separate readvertise_e2e_recovery daemon sweep.
|
|
4231
4323
|
trn reconcile_advertise _
|
|
4232
4324
|
{
|
|
4233
4325
|
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
|
|
4234
|
-
b = my_identity_bundle_fields_fresh NIL.
|
|
4235
4326
|
cur_pv = a2a_versions::wire_version.
|
|
4236
4327
|
cur_fp = caps_fingerprint NIL.
|
|
4237
4328
|
changed is bool = (advertised_pv != cur_pv) || (cur_fp != advertised_caps).
|
|
4238
4329
|
actions is transaction::action::type[] = [].
|
|
4239
|
-
|
|
4330
|
+
cap_n is int = 0.
|
|
4240
4331
|
legacy_n is int = 0.
|
|
4241
|
-
//
|
|
4242
|
-
|
|
4332
|
+
// Per-contact ACK ledger: retry missing/stale peers on the next cadence,
|
|
4333
|
+
// but never re-spam a peer that confirmed this exact capability set.
|
|
4334
|
+
sc contacts -- (cid -> ) ?? ((contact_advertised_caps cid) != cur_fp)
|
|
4243
4335
|
{
|
|
4244
4336
|
actions (_count actions|) -> encrypted_channel::send_encrypted_tx cid (
|
|
4245
|
-
$name ->
|
|
4246
|
-
$targ -> (
|
|
4247
|
-
|
|
4248
|
-
$pv -> a2a_versions::wire_version,
|
|
4249
|
-
$caps -> (a2a_capabilities::self_cap_ids NIL) ) ).
|
|
4250
|
-
e2e_n -> e2e_n + 1.
|
|
4337
|
+
$name -> capability_advertise_tx,
|
|
4338
|
+
$targ -> ($pv -> cur_pv, $caps -> (a2a_capabilities::self_cap_ids NIL), $fingerprint -> cur_fp) ).
|
|
4339
|
+
cap_n -> cap_n + 1.
|
|
4251
4340
|
}
|
|
4252
4341
|
// ON CHANGE ONLY: the legacy upgrade push to pre-existing legacy contacts.
|
|
4253
4342
|
if changed
|
|
4254
4343
|
{
|
|
4344
|
+
b = my_identity_bundle_fields_fresh NIL.
|
|
4255
4345
|
sc contacts -- (cid -> ) ?? ((contact_e2e_epoch cid) == NIL && (contact_born_dr cid) != TRUE && (contact_migration cid) == NIL)
|
|
4256
4346
|
{
|
|
4257
4347
|
actions (_count actions|) -> encrypted_channel::send_encrypted_tx cid (
|
|
@@ -4265,7 +4355,10 @@ library a2a_messaging loads libraries
|
|
|
4265
4355
|
}
|
|
4266
4356
|
advertised_pv -> cur_pv.
|
|
4267
4357
|
advertised_caps -> cur_fp.
|
|
4268
|
-
actions (_count actions|) -> _return_data (
|
|
4358
|
+
actions (_count actions|) -> _return_data (
|
|
4359
|
+
$changed -> changed, $capability_advertised -> cap_n,
|
|
4360
|
+
$e2e_readvertised -> 0, $legacy_readvertised -> legacy_n
|
|
4361
|
+
).
|
|
4269
4362
|
actions (_count actions|) -> _save_state NIL.
|
|
4270
4363
|
return transaction::success actions.
|
|
4271
4364
|
}
|
|
@@ -4473,6 +4566,7 @@ library a2a_messaging loads libraries
|
|
|
4473
4566
|
$deferred_msgs -> deferred_msgs,
|
|
4474
4567
|
$contact_pv -> contact_pv,
|
|
4475
4568
|
$contact_caps -> contact_caps,
|
|
4569
|
+
$contact_advertised_caps -> contact_advertised_caps,
|
|
4476
4570
|
$contact_e2e_seen -> contact_e2e_seen,
|
|
4477
4571
|
$contact_born_dr -> contact_born_dr,
|
|
4478
4572
|
// core 0.9.0 migration FSM metadata — additive, all keyed by cid. Only
|
|
@@ -4709,6 +4803,8 @@ library a2a_messaging loads libraries
|
|
|
4709
4803
|
// re-advertises, which is exactly the desired post-upgrade behavior).
|
|
4710
4804
|
if (data $advertised_pv) != NIL { advertised_pv -> (data $advertised_pv) safe int. }
|
|
4711
4805
|
if (data $advertised_caps) != NIL { advertised_caps -> (data $advertised_caps) safe str. }
|
|
4806
|
+
if (data $contact_advertised_caps) != NIL
|
|
4807
|
+
{ contact_advertised_caps -> (data $contact_advertised_caps) safe (global_id ->> str). }
|
|
4712
4808
|
|
|
4713
4809
|
// Re-register every peer's keys so encrypted channels keep working after
|
|
4714
4810
|
// the upgrade — no handshake needed (my own keys are unchanged, and the
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Core-owned notification integration for ordinary message sends.
|
|
2
|
+
//
|
|
3
|
+
// Recipients hand each sender a scoped notify_address_t over their established
|
|
4
|
+
// encrypted channel. This library owns those opaque handouts, persists them,
|
|
5
|
+
// and installs the optional a2a_messaging successful-send middleware. Missing
|
|
6
|
+
// or deleted handouts are no-ops; notification delivery is fire-and-forget.
|
|
7
|
+
library a2a_notification_integration loads libraries
|
|
8
|
+
current_transaction_info,
|
|
9
|
+
encrypted_channel,
|
|
10
|
+
a2a_messaging,
|
|
11
|
+
a2a_notifications
|
|
12
|
+
uses transactions
|
|
13
|
+
{
|
|
14
|
+
receive_notify_address_tx = "::a2a_notification_integration::receive_notify_address".
|
|
15
|
+
|
|
16
|
+
// Peer cid -> validated serialized notify_address_t. Opaque serialized
|
|
17
|
+
// storage composes cleanly beside a2a_messaging::export_core_state.
|
|
18
|
+
received_notify_addresses is (global_id ->> bin) = (,).
|
|
19
|
+
|
|
20
|
+
metadef integration_state_t: (
|
|
21
|
+
$version -> int,
|
|
22
|
+
$received_notify_addresses -> (global_id ->> bin)
|
|
23
|
+
).
|
|
24
|
+
|
|
25
|
+
fn _save_state (_) = (transaction::action::return_data ($kind -> $save_state)).
|
|
26
|
+
|
|
27
|
+
// Relationship binding is checked at the handout boundary. The service
|
|
28
|
+
// later validates the token against its signed live exact-token store; the
|
|
29
|
+
// current protocol intentionally requires no sender<->service contact.
|
|
30
|
+
fn validate_address_for (recipient: global_id, blob: bin) -> a2a_notifications::notify_address_t
|
|
31
|
+
{
|
|
32
|
+
addr = a2a_notifications::decode_notify_address blob.
|
|
33
|
+
abort "Notify address token recipient does not match its sender." when (addr $token $c $recipient_cid) != recipient.
|
|
34
|
+
abort "Notify address token is not scoped to this sender." when (addr $token $c $scope) != _str (_get_container_id()).
|
|
35
|
+
return addr.
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Ordinary consumers are notification clients, not notification services.
|
|
39
|
+
// Install safe no-op service/UI callbacks here so they only need to init
|
|
40
|
+
// this integration. A service host may call a2a_notifications::init after
|
|
41
|
+
// this function to replace the defaults with durable/WebPush hooks.
|
|
42
|
+
init = fn (_:($_read_or_abort -> read: (bin->any)))
|
|
43
|
+
{
|
|
44
|
+
a2a_notifications::init (
|
|
45
|
+
$_read_or_abort -> read,
|
|
46
|
+
$on_notification_posted -> fn (_: any) -> transaction::action::type[] { return []. },
|
|
47
|
+
$on_notifications_marked_read -> fn (_: any) -> transaction::action::type[] { return []. },
|
|
48
|
+
$on_unregistered -> fn (_: any) -> transaction::action::type[] { return []. },
|
|
49
|
+
$on_notify_registration -> fn (_: any) -> transaction::action::type[] { return []. }
|
|
50
|
+
).
|
|
51
|
+
a2a_messaging::set_post_send_middleware (fn (arg: any) -> transaction::action::type[]
|
|
52
|
+
{
|
|
53
|
+
target_id = (arg $target_id) safe global_id.
|
|
54
|
+
address = received_notify_addresses target_id.
|
|
55
|
+
if address == NIL { return []. }
|
|
56
|
+
|
|
57
|
+
wire_id = (arg $wire_id) safe str.
|
|
58
|
+
// Built only from stringified global ids and wire ids, whose hex
|
|
59
|
+
// alphabets require no JSON escaping.
|
|
60
|
+
payload = "{\"v\":1,\"kind\":\"message\",\"sender\":\"" +
|
|
61
|
+
(_str (_get_container_id())) + "\",\"wire_id\":\"" + wire_id + "\"}".
|
|
62
|
+
return [ a2a_notifications::notification_send_action address? payload wire_id ].
|
|
63
|
+
}).
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fn handle_receive_notify_address (args: any) -> transaction::results::type
|
|
67
|
+
{
|
|
68
|
+
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
|
|
69
|
+
encrypted_channel::check_encrypted_or_abort ().
|
|
70
|
+
from = current_transaction_info::get_external_envelope_or_abort() $from.
|
|
71
|
+
|
|
72
|
+
if (args $address) == NIL
|
|
73
|
+
{
|
|
74
|
+
if (received_notify_addresses from) != NIL { delete received_notify_addresses from. }
|
|
75
|
+
return transaction::success [ _save_state NIL ].
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
blob = (args $address) safe bin.
|
|
79
|
+
validate_address_for from blob.
|
|
80
|
+
received_notify_addresses from -> blob.
|
|
81
|
+
return transaction::success [ _save_state NIL ].
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
trn receive_notify_address args: any
|
|
85
|
+
{
|
|
86
|
+
return handle_receive_notify_address args.
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Recipient-side distribution: build the sender-scoped handout from the
|
|
90
|
+
// notification client mirror and deliver it over the existing encrypted
|
|
91
|
+
// contact channel. Consumers retain only UI policy, not protocol state.
|
|
92
|
+
trn send_notify_address _:($service -> service_ref: str, $contact -> contact_ref: str)
|
|
93
|
+
{
|
|
94
|
+
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
|
|
95
|
+
target_id = a2a_messaging::resolve_contact contact_ref.
|
|
96
|
+
blob = a2a_notifications::build_notify_address service_ref contact_ref.
|
|
97
|
+
return encrypted_channel::execute_transaction target_id (fn (_) -> transaction::results::type {
|
|
98
|
+
return transaction::success [
|
|
99
|
+
encrypted_channel::send_encrypted_tx target_id (
|
|
100
|
+
$name -> receive_notify_address_tx,
|
|
101
|
+
$targ -> ($address -> blob)
|
|
102
|
+
),
|
|
103
|
+
transaction::action::return_data ($kind -> $data, $payload -> ($sent_to -> target_id)),
|
|
104
|
+
_save_state NIL
|
|
105
|
+
].
|
|
106
|
+
}).
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// NIL is the wire-level mute/removal signal and intentionally leaves the
|
|
110
|
+
// ordinary messaging relationship untouched.
|
|
111
|
+
trn delete_notify_address _:($contact -> contact_ref: str)
|
|
112
|
+
{
|
|
113
|
+
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
|
|
114
|
+
target_id = a2a_messaging::resolve_contact contact_ref.
|
|
115
|
+
return encrypted_channel::execute_transaction target_id (fn (_) -> transaction::results::type {
|
|
116
|
+
return transaction::success [
|
|
117
|
+
encrypted_channel::send_encrypted_tx target_id (
|
|
118
|
+
$name -> receive_notify_address_tx,
|
|
119
|
+
$targ -> ($address -> NIL)
|
|
120
|
+
),
|
|
121
|
+
transaction::action::return_data ($kind -> $data, $payload -> ($sent_to -> target_id)),
|
|
122
|
+
_save_state NIL
|
|
123
|
+
].
|
|
124
|
+
}).
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fn export_state (_) -> integration_state_t
|
|
128
|
+
{
|
|
129
|
+
return (
|
|
130
|
+
$version -> 1,
|
|
131
|
+
$received_notify_addresses -> received_notify_addresses
|
|
132
|
+
).
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
fn import_state (data: any) -> nil
|
|
136
|
+
{
|
|
137
|
+
abort "Unsupported notification integration state version." when ((data $version) safe int) != 1.
|
|
138
|
+
imported = (data $received_notify_addresses) safe (global_id ->> bin).
|
|
139
|
+
// Validate now so a corrupt local snapshot cannot turn a later accepted
|
|
140
|
+
// send_message into a middleware parse abort.
|
|
141
|
+
sc imported -- (peer -> blob) { validate_address_for peer blob. }
|
|
142
|
+
received_notify_addresses -> imported.
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -516,7 +516,7 @@ library a2a_notifications loads libraries
|
|
|
516
516
|
// my_notify_contact_tokens (i.e. a confirm after notify_issue_tokens has
|
|
517
517
|
// landed). Distribution is out of protocol — it rides ordinary
|
|
518
518
|
// send_message/send_file or the messenger's distribution engine.
|
|
519
|
-
|
|
519
|
+
fn build_notify_address (service_ref: str, contact_ref: str) -> bin
|
|
520
520
|
{
|
|
521
521
|
target_id = a2a_messaging::resolve_contact service_ref.
|
|
522
522
|
reg = my_notify_registrations target_id.
|
|
@@ -532,7 +532,13 @@ library a2a_notifications loads libraries
|
|
|
532
532
|
$service_name -> (reg? $service_name),
|
|
533
533
|
$token -> tok?
|
|
534
534
|
).
|
|
535
|
-
return
|
|
535
|
+
return _write addr.
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
trn readonly export_notify_address _:($service -> service_ref: str, $contact -> contact_ref: str)
|
|
539
|
+
{
|
|
540
|
+
blob = build_notify_address service_ref contact_ref.
|
|
541
|
+
return ($blob -> blob, $service_cid -> (_str (a2a_messaging::resolve_contact service_ref))).
|
|
536
542
|
}
|
|
537
543
|
|
|
538
544
|
// THE parallel of send_message, against a handout instead of a contact:
|
|
@@ -542,25 +548,44 @@ library a2a_notifications loads libraries
|
|
|
542
548
|
// the service; the token is the sole authorization) and deliberately NO
|
|
543
549
|
// monitoring copy (D-4: the forced-monitoring contract covers messages;
|
|
544
550
|
// notifications are wake-up signals). Fire-and-forget: no response leg.
|
|
545
|
-
|
|
551
|
+
// Parse and structurally validate a handout. The notification service is
|
|
552
|
+
// the final authorization authority (live token index + exact stored token
|
|
553
|
+
// + sender scope); a sender intentionally need not be its contact and thus
|
|
554
|
+
// does not necessarily possess service keys for local signature checking.
|
|
555
|
+
fn decode_notify_address (address_blob: bin) -> notify_address_t
|
|
546
556
|
{
|
|
547
|
-
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
|
|
548
|
-
|
|
549
557
|
addr = (_read_or_abort address_blob) safe notify_address_t.
|
|
550
558
|
abort "Unsupported notify address version." when (addr $version) != 1.
|
|
559
|
+
abort "Unsupported notify token version." when (addr $token $c $version) != 1.
|
|
560
|
+
abort "Notify address service does not match its token." when (addr $service_cid) != (addr $token $c $service_cid).
|
|
561
|
+
return addr.
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// Reusable fire-and-forget builder. The caller supplies wire_id so a post
|
|
565
|
+
// produced by send_message carries that message's actual stable id.
|
|
566
|
+
fn notification_send_action (address_blob: bin, payload: str, wire_id: str) -> transaction::action::type
|
|
567
|
+
{
|
|
568
|
+
addr = decode_notify_address address_blob.
|
|
551
569
|
abort "Notification payload exceeds " + (_str payload_max_bytes) + " bytes." when (_strlen payload) > payload_max_bytes.
|
|
570
|
+
return transaction::action::send (addr $service_cid) (
|
|
571
|
+
$name -> post_notification_tx,
|
|
572
|
+
$targ -> (
|
|
573
|
+
$token -> (addr $token),
|
|
574
|
+
$payload -> payload,
|
|
575
|
+
$wire_id -> wire_id,
|
|
576
|
+
$pv -> a2a_versions::wire_version
|
|
577
|
+
)
|
|
578
|
+
).
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
trn send_notification _:($address -> address_blob: bin, $payload -> payload: str)
|
|
582
|
+
{
|
|
583
|
+
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
|
|
552
584
|
|
|
553
585
|
wire_id = _str (_new_id "ours notification").
|
|
586
|
+
addr = decode_notify_address address_blob.
|
|
554
587
|
return transaction::success [
|
|
555
|
-
|
|
556
|
-
$name -> post_notification_tx,
|
|
557
|
-
$targ -> (
|
|
558
|
-
$token -> (addr $token),
|
|
559
|
-
$payload -> payload,
|
|
560
|
-
$wire_id -> wire_id,
|
|
561
|
-
$pv -> a2a_versions::wire_version
|
|
562
|
-
)
|
|
563
|
-
),
|
|
588
|
+
notification_send_action address_blob payload wire_id,
|
|
564
589
|
_return_data ($sent_to -> (addr $service_cid), $wire_id -> wire_id)
|
|
565
590
|
].
|
|
566
591
|
}
|
|
@@ -18,6 +18,7 @@ config script
|
|
|
18
18
|
$a2a_protocol -> #"a2a_protocol.mm",
|
|
19
19
|
$a2a_messaging -> #"a2a_messaging.mm",
|
|
20
20
|
$a2a_notifications -> #"a2a_notifications.mm",
|
|
21
|
+
$a2a_notification_integration -> #"a2a_notification_integration.mm",
|
|
21
22
|
$a2a_cluster -> #"a2a_cluster.mm",
|
|
22
23
|
$a2a_monitoring -> #"a2a_monitoring.mm",
|
|
23
24
|
$a2a_control -> #"a2a_control.mm"
|
|
@@ -670,32 +670,69 @@ async function main() {
|
|
|
670
670
|
const lSt2 = ro(lo, '::actor::qa_mig_state', { cid: hi.cid });
|
|
671
671
|
ok(sweep2.Reduce('initiated').Visualize() === '0' && lSt2.Reduce('phase').Visualize() === 'active' && hex(getBin(lSt2, 'epoch')) === epoch0, '★ C-path IDEMPOTENCY: a second sweep does NOT re-offer the ACTIVE contact (phase + epoch unchanged; the never-cleared contact_migration gate)'); }
|
|
672
672
|
|
|
673
|
-
// ═══ 2b
|
|
674
|
-
|
|
675
|
-
// core owns the re-advertise (replacing app-orchestrated readvertise_on_upgrade/e2e_recovery)
|
|
676
|
-
// and NOTICES a persisted wire-version/cap-set change to gate the legacy upgrade push.
|
|
677
|
-
console.log('=== mig: 2b reconcile_advertise — core-owned re-advertise + change detection ===');
|
|
673
|
+
// ═══ 2b GENERIC CAPABILITY RE-ADVERTISEMENT — persisted per-contact ACK state ═══
|
|
674
|
+
console.log('=== mig: 2b generic capability advertise/ack reconciliation ===');
|
|
678
675
|
{
|
|
679
|
-
|
|
676
|
+
let CA = await mkNode('mig-adv-A', 'CAA');
|
|
680
677
|
const CB = await mkNode('mig-adv-B', 'CBB'); await sleep(1000);
|
|
681
678
|
const cinv = await mutate(CA, '::a2a_messaging::generate_invite', { name: 'CBB' });
|
|
682
679
|
await mutate(CB, '::a2a_messaging::add_contact', { invite: binv(CB, Buffer.from(cinv.Reduce('invite').GetBinary())), name: 'CAA' });
|
|
683
680
|
await sleep(6000); // invite redeem round-trips (CA gains a contact)
|
|
684
681
|
|
|
685
|
-
//
|
|
682
|
+
// Stable-era baseline: both packets are already connected and ACK the old cap
|
|
683
|
+
// lists. Persist A, destroy the live packet, and restore the same identity.
|
|
684
|
+
await mutate(CA, '::actor::qa_init_caps', { advertise: ['core.e2e'] });
|
|
685
|
+
await mutate(CB, '::actor::qa_init_caps', { advertise: ['core.e2e', 'core.receipts.receive'] });
|
|
686
|
+
await mutate(CA, '::a2a_messaging::reconcile_advertise', {});
|
|
687
|
+
await mutate(CB, '::a2a_messaging::reconcile_advertise', {});
|
|
688
|
+
await sleep(2500);
|
|
689
|
+
const persistedA = Buffer.from(ro(CA, '::actor::export_state', {}).Serialize());
|
|
690
|
+
wrapper.packet_manager.remove_packet(CA.cid);
|
|
691
|
+
await sleep(300);
|
|
692
|
+
CA = await mkNode('mig-adv-A', 'CAA');
|
|
693
|
+
await mutate(CA, '::actor::import_state', CA.pw.packet.ParseValue(new Uint8Array(persistedA)));
|
|
694
|
+
await mutate(CA, '::a2a_messaging::commit_e2e_restore', {});
|
|
695
|
+
// "Upgraded code" defines A+notifications+receipts at one-time init.
|
|
696
|
+
await mutate(CA, '::actor::qa_init_caps', { advertise: ['core.e2e', 'core.notifications', 'core.receipts.emit'] });
|
|
697
|
+
|
|
698
|
+
// First reconcile sends a generic capability snapshot. The receiver replaces its
|
|
699
|
+
// cached list, ACKs the fingerprint, and the sender persists that per-contact ACK.
|
|
686
700
|
const r1 = await mutate(CA, '::a2a_messaging::reconcile_advertise', {});
|
|
687
|
-
ok(T(r1.Reduce('changed').Visualize()), '2b:
|
|
688
|
-
ok(+r1.Reduce('
|
|
689
|
-
|
|
690
|
-
|
|
701
|
+
ok(T(r1.Reduce('changed').Visualize()), '2b: persisted global fingerprint notices the code-defined capability list');
|
|
702
|
+
ok(+r1.Reduce('capability_advertised').Visualize() === 1, '2b: first reconcile sends one generic capability snapshot');
|
|
703
|
+
await sleep(2500);
|
|
704
|
+
const learned1 = ro(CB, '::actor::qa_cap_state', { cid: CA.cid });
|
|
705
|
+
ok(learned1.Reduce('caps').Visualize().includes('core.receipts.emit'), '2b: existing peer learns newly-added receipts capability without app traffic');
|
|
706
|
+
ok(learned1.Reduce('caps').Visualize().includes('core.notifications'), '2b: existing peer learns newly-added notifications capability without app traffic');
|
|
707
|
+
ok(T(ro(CA, '::actor::qa_receipt_gate', { cid: CB.cid }).Reduce('enabled').Visualize()), '2b: restored upgraded sender has its receipt gate enabled from reconciled peer capabilities');
|
|
708
|
+
const acked1 = ro(CA, '::actor::qa_cap_state', { cid: CB.cid });
|
|
709
|
+
ok(acked1.Reduce('confirmed').Visualize() === acked1.Reduce('current').Visualize(), '2b: ACK persists the peer-confirmed current fingerprint');
|
|
710
|
+
ok(T(acked1.Reduce('confirmed_persisted').Visualize()), '2b: per-contact ACK fingerprint is present in export_core_state');
|
|
711
|
+
|
|
712
|
+
// ACK-confirmed peers are not spammed on the next boot/cadence reconciliation.
|
|
691
713
|
const r2 = await mutate(CA, '::a2a_messaging::reconcile_advertise', {});
|
|
692
714
|
ok(!T(r2.Reduce('changed').Visualize()), '2b: second reconcile is idempotent (unchanged pv+caps → not changed)');
|
|
693
|
-
ok(+r2.Reduce('
|
|
694
|
-
|
|
695
|
-
//
|
|
696
|
-
|
|
715
|
+
ok(+r2.Reduce('capability_advertised').Visualize() === 0, '2b: ACK-confirmed contact is not re-spammed');
|
|
716
|
+
|
|
717
|
+
// Model a lost ACK/offline attempt by removing only the confirmed ledger entry:
|
|
718
|
+
// global previous-list state is still unchanged, but the per-contact retry must fire.
|
|
719
|
+
await mutate(CA, '::actor::qa_clear_cap_ack', { cid: CB.cid });
|
|
720
|
+
const retry = await mutate(CA, '::a2a_messaging::reconcile_advertise', {});
|
|
721
|
+
ok(!T(retry.Reduce('changed').Visualize()) && +retry.Reduce('capability_advertised').Visualize() === 1, '2b: missing per-contact ACK retries even when global fingerprint is unchanged');
|
|
722
|
+
await sleep(2500);
|
|
723
|
+
const retryDone = await mutate(CA, '::a2a_messaging::reconcile_advertise', {});
|
|
724
|
+
ok(+retryDone.Reduce('capability_advertised').Visualize() === 0, '2b: retry converges after ACK and does not re-spam');
|
|
725
|
+
|
|
726
|
+
// Removal is an exact replacement, not the old non-empty-only merge behavior.
|
|
727
|
+
// The monotonic E2E pin must survive even if a later snapshot removes core.e2e.
|
|
728
|
+
await mutate(CA, '::actor::qa_init_caps', { advertise: ['core.notifications'] });
|
|
697
729
|
const r3 = await mutate(CA, '::a2a_messaging::reconcile_advertise', {});
|
|
698
|
-
ok(T(r3.Reduce('changed').Visualize()), '2b:
|
|
730
|
+
ok(T(r3.Reduce('changed').Visualize()) && +r3.Reduce('capability_advertised').Visualize() === 1, '2b: changed capability set re-advertises exactly once');
|
|
731
|
+
await sleep(2500);
|
|
732
|
+
const learned2 = ro(CB, '::actor::qa_cap_state', { cid: CA.cid });
|
|
733
|
+
const caps2 = learned2.Reduce('caps').Visualize();
|
|
734
|
+
ok(caps2.includes('core.notifications') && !caps2.includes('core.receipts.emit') && !caps2.includes('core.e2e'), '2b: receiver exact-replaces additions and removals');
|
|
735
|
+
ok(T(learned2.Reduce('pinned').Visualize()), '2b: capability removal cannot clear the monotonic E2E downgrade pin');
|
|
699
736
|
}
|
|
700
737
|
|
|
701
738
|
// ═══ RELOAD PORT (design §3 acceptance) — page-reload DR message-loss, now GREEN ═══
|
|
@@ -265,7 +265,9 @@ application actor loads libraries
|
|
|
265
265
|
{ return ($version -> 1, $app_id -> "mig.actor", $name -> "actor", $description -> "", $monitoring_status -> "off", $capabilities -> (,)). },
|
|
266
266
|
$supported -> [], $handlers -> (,),
|
|
267
267
|
$on_unknown -> fn (_: any) -> transaction::action::type[] { return []. },
|
|
268
|
-
$authorizer -> NIL, $advertise -> adv
|
|
268
|
+
$authorizer -> NIL, $advertise -> adv,
|
|
269
|
+
$on_advertise -> a2a_messaging::handle_capability_advertise,
|
|
270
|
+
$on_advertise_ack -> a2a_messaging::handle_capability_advertise_ack ).
|
|
269
271
|
return transaction::success [ _return_data ($set -> TRUE) ].
|
|
270
272
|
}
|
|
271
273
|
trn qa_learn_peer _:($cid -> cid: global_id, $pv -> pv: int, $caps -> caps: str[])
|
|
@@ -274,6 +276,27 @@ application actor loads libraries
|
|
|
274
276
|
return transaction::success [ _return_data ($ok -> TRUE) ].
|
|
275
277
|
}
|
|
276
278
|
trn readonly qa_mig_should_trigger _:($cid -> cid: global_id) { return ($fire -> (a2a_messaging::mig_should_trigger cid)). }
|
|
279
|
+
trn readonly qa_cap_state _:($cid -> cid: global_id)
|
|
280
|
+
{
|
|
281
|
+
pc = a2a_messaging::contact_caps cid.
|
|
282
|
+
confirmed = a2a_messaging::contact_advertised_caps cid.
|
|
283
|
+
exported = (a2a_messaging::export_core_state NIL) $contact_advertised_caps cid.
|
|
284
|
+
return (
|
|
285
|
+
$caps -> (pc == NIL ?? [] ; pc?),
|
|
286
|
+
$confirmed -> (confirmed == NIL ?? "" ; confirmed?),
|
|
287
|
+
$confirmed_persisted -> (exported != NIL && exported? == (confirmed == NIL ?? "" ; confirmed?)),
|
|
288
|
+
$current -> (a2a_messaging::caps_fingerprint NIL),
|
|
289
|
+
$pinned -> (a2a_messaging::e2e_pinned cid)
|
|
290
|
+
).
|
|
291
|
+
}
|
|
292
|
+
trn qa_clear_cap_ack _:($cid -> cid: global_id)
|
|
293
|
+
{
|
|
294
|
+
if (a2a_messaging::contact_advertised_caps cid) != NIL
|
|
295
|
+
{ delete a2a_messaging::contact_advertised_caps cid. }
|
|
296
|
+
return transaction::success [ _return_data ($cleared -> TRUE) ].
|
|
297
|
+
}
|
|
298
|
+
trn readonly qa_receipt_gate _:($cid -> cid: global_id)
|
|
299
|
+
{ return ($enabled -> (a2a_messaging::receipt_gate cid)). }
|
|
277
300
|
|
|
278
301
|
// core 0.10 born-DR probe/override. A pair established through a real invite handshake presents a
|
|
279
302
|
// v2 (bundle-carrying) AD, so core marks it born-DR (contact_born_dr=TRUE) — correctly INELIGIBLE
|
|
@@ -88,6 +88,65 @@ async function main() {
|
|
|
88
88
|
ok(new RegExp(nbob.cid).test(n2s), `sender_cid recorded from the signed envelope`);
|
|
89
89
|
ok(/push\.example/.test(n2s.split('notif_log')[1] || ''), `hook received the recipient's current bindings`);
|
|
90
90
|
|
|
91
|
+
// ---------- NI1 core-owned handout + post-send middleware ----------
|
|
92
|
+
CUR = 'NI1-core-integration';
|
|
93
|
+
console.log('\n=== NI1 core-owned notification integration ===');
|
|
94
|
+
// Alice and Bob become ordinary messaging contacts. Alice's scoped handout
|
|
95
|
+
// above is already bound to (recipient=Alice, scope=Bob).
|
|
96
|
+
{
|
|
97
|
+
const im = await mutate(alice, '::a2a_messaging::generate_invite', { name: 'Bob' });
|
|
98
|
+
const iblob = Buffer.from(im.Reduce('invite').GetBinary());
|
|
99
|
+
await mutate(nbob, '::a2a_messaging::add_contact', { invite: binv(nbob, iblob), name: 'alice' });
|
|
100
|
+
await sleep(5000);
|
|
101
|
+
}
|
|
102
|
+
await mutate(alice, '::a2a_notification_integration::send_notify_address',
|
|
103
|
+
{ service: 'svc', contact: nbob.cid });
|
|
104
|
+
await sleep(2000);
|
|
105
|
+
ok(new RegExp(alice.cid).test(ro(nbob, '::actor::qa_notify_addr_store', undefined).Visualize()),
|
|
106
|
+
`new library route validates and stores Alice's handout on Bob`);
|
|
107
|
+
|
|
108
|
+
const ni1Before = nst(nsvc);
|
|
109
|
+
const ni1Sent = await mutate(nbob, '::a2a_messaging::send_message',
|
|
110
|
+
{ contact: alice.cid, text: 'core-notify-message' });
|
|
111
|
+
const ni1Wire = ni1Sent.Reduce('wire_id').Visualize();
|
|
112
|
+
await sleep(3000);
|
|
113
|
+
const ni1After = nst(nsvc);
|
|
114
|
+
ok(/core-notify-message/.test(ro(alice, '::actor::list_incoming_messages', undefined).Visualize()),
|
|
115
|
+
`ordinary message still reaches Alice`);
|
|
116
|
+
ok(ni1After !== ni1Before && ni1After.includes(ni1Wire),
|
|
117
|
+
`post-send middleware posts a notification carrying the actual message wire_id`);
|
|
118
|
+
ok(ni1After.includes(nbob.cid) && /kind.*message/.test(ni1After),
|
|
119
|
+
`notification payload carries sender metadata and kind=message`);
|
|
120
|
+
|
|
121
|
+
// A NIL handout is the mute/delete signal. It must suppress only the wake,
|
|
122
|
+
// never the accepted message.
|
|
123
|
+
await mutate(alice, '::a2a_notification_integration::delete_notify_address',
|
|
124
|
+
{ contact: nbob.cid });
|
|
125
|
+
await sleep(1500);
|
|
126
|
+
const ni1MutedBefore = nst(nsvc);
|
|
127
|
+
await mutate(nbob, '::a2a_messaging::send_message',
|
|
128
|
+
{ contact: alice.cid, text: 'muted-but-delivered' });
|
|
129
|
+
await sleep(3000);
|
|
130
|
+
ok(/muted-but-delivered/.test(ro(alice, '::actor::list_incoming_messages', undefined).Visualize()),
|
|
131
|
+
`address deletion does not affect message delivery`);
|
|
132
|
+
ok(nst(nsvc) === ni1MutedBefore, `address deletion suppresses the notification post`);
|
|
133
|
+
|
|
134
|
+
// Restore through the deployed ::actor::* compatibility shim and prove the
|
|
135
|
+
// same core-owned state/middleware path resumes.
|
|
136
|
+
await mutate(alice, '::actor::qa_send_notify_address',
|
|
137
|
+
{ target: nbob.cid, address: binv(alice, naddr), legacy: true });
|
|
138
|
+
await sleep(1500);
|
|
139
|
+
const ni1LegacyBefore = nst(nsvc);
|
|
140
|
+
const ni1LegacySent = await mutate(nbob, '::a2a_messaging::send_message',
|
|
141
|
+
{ contact: alice.cid, text: 'legacy-handout-message' });
|
|
142
|
+
const ni1LegacyWire = ni1LegacySent.Reduce('wire_id').Visualize();
|
|
143
|
+
await sleep(3000);
|
|
144
|
+
ok(nst(nsvc) !== ni1LegacyBefore && nst(nsvc).includes(ni1LegacyWire),
|
|
145
|
+
`legacy ::actor::receive_notify_address shim feeds the new middleware`);
|
|
146
|
+
const ni1Export = ro(nbob, '::actor::export_state', undefined).Visualize();
|
|
147
|
+
ok(/notify_integration/.test(ni1Export) && new RegExp(alice.cid).test(ni1Export),
|
|
148
|
+
`notification handout is included in the composed actor export`);
|
|
149
|
+
|
|
91
150
|
// ---------- N3 token rejection matrix + E9 (zero state change each) ----------
|
|
92
151
|
CUR = 'N3-rejections';
|
|
93
152
|
console.log('\n=== N3 rejection matrix ===');
|
|
@@ -105,6 +164,13 @@ async function main() {
|
|
|
105
164
|
await mutate(neve, '::a2a_messaging::add_contact', { invite: binv(neve, iblob), name: 'alice-target' });
|
|
106
165
|
await sleep(5000);
|
|
107
166
|
}
|
|
167
|
+
const neveRejectsBeforeBinding = neve.rejects.length;
|
|
168
|
+
await mutate(alice, '::actor::qa_send_notify_address',
|
|
169
|
+
{ target: neve.cid, address: binv(alice, naddr), legacy: false });
|
|
170
|
+
await sleep(2000);
|
|
171
|
+
ok(neve.rejects.slice(neveRejectsBeforeBinding).some((x) => /scoped to this sender/.test(x)) &&
|
|
172
|
+
!new RegExp(alice.cid).test(ro(neve, '::actor::qa_notify_addr_store', undefined).Visualize()),
|
|
173
|
+
`handout scoped to Bob is rejected when Alice sends it to Eve`);
|
|
108
174
|
const aBefore = nst(alice);
|
|
109
175
|
const aRejx = alice.rejects.length;
|
|
110
176
|
await mutate(neve, '::actor::qa_send_fake_confirm', { target: alice.cid });
|
|
@@ -35,6 +35,7 @@ application actor loads libraries
|
|
|
35
35
|
a2a_protocol,
|
|
36
36
|
a2a_messaging,
|
|
37
37
|
a2a_notifications,
|
|
38
|
+
a2a_notification_integration,
|
|
38
39
|
current_transaction_info,
|
|
39
40
|
protocol_container,
|
|
40
41
|
version
|
|
@@ -107,13 +108,9 @@ application actor loads libraries
|
|
|
107
108
|
unregs_log is any[] = [].
|
|
108
109
|
regconfirm_log is any[] = [].
|
|
109
110
|
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
// tests.
|
|
114
|
-
notify_addr_store is (global_id ->> bin) = (,).
|
|
115
|
-
notify_addr_recv_count is int = 0.
|
|
116
|
-
|
|
111
|
+
// The integration supplies ordinary client defaults; this dual-role
|
|
112
|
+
// test actor then overrides them with observable service/client hooks.
|
|
113
|
+
a2a_notification_integration::init ($_read_or_abort -> _read_or_abort).
|
|
117
114
|
a2a_notifications::init (
|
|
118
115
|
$_read_or_abort -> _read_or_abort,
|
|
119
116
|
$on_notification_posted -> fn (arg: any) -> transaction::action::type[]
|
|
@@ -150,12 +147,19 @@ application actor loads libraries
|
|
|
150
147
|
// core+notify round-trip lives here (test_actor keeps only the core half).
|
|
151
148
|
// The "both halves coexist in one blob and both restore" coverage (N7/N16)
|
|
152
149
|
// is asserted against these.
|
|
153
|
-
trn readonly export_state _ {
|
|
150
|
+
trn readonly export_state _ {
|
|
151
|
+
return (
|
|
152
|
+
$core -> (a2a_messaging::export_core_state NIL),
|
|
153
|
+
$notify -> (a2a_notifications::export_notify_state NIL),
|
|
154
|
+
$notify_integration -> (a2a_notification_integration::export_state NIL)
|
|
155
|
+
).
|
|
156
|
+
}
|
|
154
157
|
trn import_state data: any
|
|
155
158
|
{
|
|
156
159
|
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
|
|
157
160
|
a2a_messaging::import_core_state (data $core).
|
|
158
161
|
if (data $notify) != NIL { a2a_notifications::import_notify_state (data $notify). }
|
|
162
|
+
if (data $notify_integration) != NIL { a2a_notification_integration::import_state (data $notify_integration). }
|
|
159
163
|
return transaction::success [ _return_data ($imported -> TRUE), _save_state NIL ].
|
|
160
164
|
}
|
|
161
165
|
|
|
@@ -170,36 +174,24 @@ application actor loads libraries
|
|
|
170
174
|
|
|
171
175
|
// ================= NOTIFICATION TEST PROBES =================
|
|
172
176
|
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
// (byte-compat obligation). Feeds the control-plane engine rig (no driver
|
|
177
|
-
// in notif.mjs exercises it, but it is notification-plane surface).
|
|
178
|
-
trn receive_notify_address _:($address -> blob: bin)
|
|
179
|
-
{
|
|
180
|
-
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::external,).
|
|
181
|
-
encrypted_channel::check_encrypted_or_abort ().
|
|
182
|
-
|
|
183
|
-
from = current_transaction_info::get_external_envelope_or_abort() $from.
|
|
184
|
-
notify_addr_store from -> blob.
|
|
185
|
-
notify_addr_recv_count -> notify_addr_recv_count + 1.
|
|
186
|
-
return transaction::success [ _save_state NIL ].
|
|
187
|
-
}
|
|
177
|
+
// Deployed-peer compatibility shim: old senders still address ::actor::*;
|
|
178
|
+
// state and validation are owned by the integration library.
|
|
179
|
+
trn receive_notify_address args: any { return a2a_notification_integration::handle_receive_notify_address args. }
|
|
188
180
|
trn readonly qa_notify_addr_store _
|
|
189
181
|
{
|
|
190
|
-
return ($store ->
|
|
182
|
+
return ($store -> a2a_notification_integration::received_notify_addresses).
|
|
191
183
|
}
|
|
192
|
-
//
|
|
193
|
-
// shape
|
|
194
|
-
|
|
195
|
-
// send no ack).
|
|
196
|
-
trn qa_send_legacy_notify_address _:($target -> tgt: global_id, $address -> blob: bin)
|
|
184
|
+
// Send either the new library-routed handout or the deployed ::actor::*
|
|
185
|
+
// shape. Nullable address deletes the receiver's stored handout.
|
|
186
|
+
trn qa_send_notify_address _:($target -> tgt: global_id, $address -> blob: bin+, $legacy -> legacy: bool)
|
|
197
187
|
{
|
|
198
188
|
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
|
|
199
189
|
return encrypted_channel::execute_transaction tgt (fn (_) -> transaction::results::type {
|
|
190
|
+
tx_name is str = "::a2a_notification_integration::receive_notify_address".
|
|
191
|
+
if legacy { tx_name -> "::actor::receive_notify_address". }
|
|
200
192
|
return transaction::success [
|
|
201
193
|
encrypted_channel::send_encrypted_tx tgt (
|
|
202
|
-
$name ->
|
|
194
|
+
$name -> tx_name,
|
|
203
195
|
$targ -> ($address -> blob)
|
|
204
196
|
),
|
|
205
197
|
_return_data ($sent_to -> tgt)
|
|
@@ -13,9 +13,11 @@ STDLIB=${MUFL_STDLIB_OVERRIDE:-$AT/mufl_stdlib} # Phase-B: point at the adapt
|
|
|
13
13
|
SDK_NM=${OURS_SDK_NODE_MODULES:-/home/shakhvit/work/adapt/ours/ours-mcp/node_modules}
|
|
14
14
|
DEV_BROKER=${DEV_BROKER:-/home/shakhvit/work/adapt/ours/ours-mcp/scripts/dev-broker.mjs}
|
|
15
15
|
PORT=${PORT:-9798}
|
|
16
|
-
COMPILE
|
|
16
|
+
COMPILE=${MUFL_COMPILE_OVERRIDE:-$AT/build.linux.release/mufl-compile}
|
|
17
|
+
META=${MUFL_META_OVERRIDE:-$AT/meta}
|
|
18
|
+
TRANSACTIONS=${MUFL_TRANSACTIONS_OVERRIDE:-$AT/transactions}
|
|
17
19
|
|
|
18
|
-
for p in "$COMPILE" "$STDLIB" "$SDK_NM/@adapt-toolkit" "$DEV_BROKER"; do
|
|
20
|
+
for p in "$COMPILE" "$STDLIB" "$META" "$TRANSACTIONS" "$SDK_NM/@adapt-toolkit" "$DEV_BROKER"; do
|
|
19
21
|
[ -e "$p" ] || { echo "MISSING: $p (set ADAPT_TOOLKIT / OURS_SDK_NODE_MODULES / DEV_BROKER)"; exit 2; }
|
|
20
22
|
done
|
|
21
23
|
|
|
@@ -40,7 +42,7 @@ CFG
|
|
|
40
42
|
|
|
41
43
|
cd "$BUILD"
|
|
42
44
|
echo "compiling notif test actor against $CORE_DIR core…"
|
|
43
|
-
MUFL_STDLIB_PATH="$STDLIB" "$COMPILE" -mp "$
|
|
45
|
+
MUFL_STDLIB_PATH="$STDLIB" "$COMPILE" -mp "$META" -mp "$TRANSACTIONS" notif_actor.mu 2>&1 \
|
|
44
46
|
| grep -vE "Unused symbol|browser_attestation|identity_proof_document_impl" | tail -4
|
|
45
47
|
ls ./*.muflo >/dev/null 2>&1 || { echo "COMPILE FAILED"; exit 1; }
|
|
46
48
|
|
|
@@ -700,6 +700,47 @@ async function main() {
|
|
|
700
700
|
'RC10: expectation = unknown toward a pv-5 peer');
|
|
701
701
|
}
|
|
702
702
|
|
|
703
|
+
// ---------- CN contact naming after an AD introduction ----------
|
|
704
|
+
CUR = 'CN contact naming';
|
|
705
|
+
console.log('\n=== CN AD introduction adopts only a CID fallback name ===');
|
|
706
|
+
{
|
|
707
|
+
const N = mk('N'); const C = mk('C'); const P = mk('P');
|
|
708
|
+
await mkPacket(N, 'name-node-01');
|
|
709
|
+
await mkPacket(C, 'name-controller-02');
|
|
710
|
+
await mkPacket(P, 'name-peer-03');
|
|
711
|
+
await sleep(1200);
|
|
712
|
+
await setName(N, 'Node');
|
|
713
|
+
await setName(C, 'ControllerSelf');
|
|
714
|
+
await setName(P, 'PeerReal');
|
|
715
|
+
|
|
716
|
+
const ni = await mutate(N, '::a2a_messaging::generate_invite', { name: 'ControllerAlias' });
|
|
717
|
+
await mutate(C, '::a2a_messaging::add_contact',
|
|
718
|
+
{ invite: binv(C, Buffer.from(ni.Reduce('invite').GetBinary())), name: 'NodeAlias' });
|
|
719
|
+
await sleep(5000);
|
|
720
|
+
await mutate(N, '::actor::qa_init_connect', {});
|
|
721
|
+
await mutate(N, '::a2a_messaging::set_proxy_pending', { code: '123456', proxy: C.cid });
|
|
722
|
+
await mutate(N, '::a2a_messaging::verify_proxy_code', { code: '123456', sender: C.cid });
|
|
723
|
+
|
|
724
|
+
const pAd = adBlob(P);
|
|
725
|
+
await mutate(C, '::actor::qa_send_ingest_descriptor',
|
|
726
|
+
{ target: N.cid, peer_ad: binv(C, pAd), peer_name: '' });
|
|
727
|
+
await sleep(1800);
|
|
728
|
+
ok(new RegExp(`\"name\"->\"${P.cid}\"`).test(lc(N)),
|
|
729
|
+
'CN1: nameless introduction initially uses the peer CID fallback');
|
|
730
|
+
|
|
731
|
+
await mutate(C, '::actor::qa_send_ingest_descriptor',
|
|
732
|
+
{ target: N.cid, peer_ad: binv(C, pAd), peer_name: 'PeerReal' });
|
|
733
|
+
await sleep(1800);
|
|
734
|
+
ok(/"name"->"PeerReal"/.test(lc(N)),
|
|
735
|
+
'CN2: later AD introduction replaces the CID fallback with the real peer name');
|
|
736
|
+
|
|
737
|
+
await mutate(C, '::actor::qa_send_ingest_descriptor',
|
|
738
|
+
{ target: N.cid, peer_ad: binv(C, adBlob(C)), peer_name: 'ControllerSelf' });
|
|
739
|
+
await sleep(1800);
|
|
740
|
+
ok(/"name"->"ControllerAlias"/.test(lc(N)) && !/"name"->"ControllerSelf"/.test(lc(N)),
|
|
741
|
+
'CN3: an explicit invite name is preserved on re-introduction');
|
|
742
|
+
}
|
|
743
|
+
|
|
703
744
|
console.log('\n================ SCORECARD ================');
|
|
704
745
|
if (scorecard.length === 0) console.log('ALL TESTS PASSED');
|
|
705
746
|
else { console.log(`${scorecard.length} FAILURE(S):`); scorecard.forEach((s) => console.log(' ' + s)); }
|
|
@@ -438,6 +438,50 @@ application actor loads libraries
|
|
|
438
438
|
).
|
|
439
439
|
return transaction::success [ _return_data ($set -> TRUE) ].
|
|
440
440
|
}
|
|
441
|
+
|
|
442
|
+
// Contact-naming regression plumbing: advertise core.connect on the receiver,
|
|
443
|
+
// then let its already-bound CP relay a real signed peer AD + display label.
|
|
444
|
+
trn qa_init_connect _
|
|
445
|
+
{
|
|
446
|
+
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
|
|
447
|
+
hs is (str ->> (any -> transaction::action::type[])) = (,).
|
|
448
|
+
hs a2a_capabilities::cap_connect -> fn (_: any) -> transaction::action::type[] { return []. }.
|
|
449
|
+
a2a_capabilities::init (
|
|
450
|
+
$describe -> fn (_: any) -> a2a_capabilities::app_manifest_t
|
|
451
|
+
{
|
|
452
|
+
caps is (str ->> a2a_capabilities::capability_t) = (,).
|
|
453
|
+
caps a2a_capabilities::cap_connect -> (
|
|
454
|
+
$cap -> a2a_capabilities::cap_connect,
|
|
455
|
+
$version -> 1,
|
|
456
|
+
$params -> "",
|
|
457
|
+
$secrets -> (,)
|
|
458
|
+
).
|
|
459
|
+
return ($version -> 1, $app_id -> "test.actor", $name -> "actor",
|
|
460
|
+
$description -> "", $monitoring_status -> "off", $capabilities -> caps).
|
|
461
|
+
},
|
|
462
|
+
$supported -> [a2a_capabilities::cap_connect],
|
|
463
|
+
$handlers -> hs,
|
|
464
|
+
$on_unknown -> fn (_: any) -> transaction::action::type[] { return []. },
|
|
465
|
+
$authorizer -> NIL,
|
|
466
|
+
$advertise -> []
|
|
467
|
+
).
|
|
468
|
+
return transaction::success [ _return_data ($set -> TRUE) ].
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
trn qa_send_ingest_descriptor _:($target -> tgt: global_id, $peer_ad -> ad_blob: bin, $peer_name -> peer_name: str)
|
|
472
|
+
{
|
|
473
|
+
current_transaction_info::validate_origin_or_abort (transaction::envelope::origin::user,).
|
|
474
|
+
ad = (_read_or_abort ad_blob) safe address_document_types::t_address_document.
|
|
475
|
+
return encrypted_channel::execute_transaction tgt (fn (_) -> transaction::results::type {
|
|
476
|
+
return transaction::success [
|
|
477
|
+
encrypted_channel::send_encrypted_tx tgt (
|
|
478
|
+
$name -> "::a2a_messaging::ingest_connect_descriptor",
|
|
479
|
+
$targ -> ($peer_ad -> ad, $peer_name -> peer_name, $pv -> a2a_versions::wire_version)
|
|
480
|
+
),
|
|
481
|
+
_return_data ($sent -> TRUE)
|
|
482
|
+
].
|
|
483
|
+
}).
|
|
484
|
+
}
|
|
441
485
|
// Consumer read-path emission (the get/mark-read moment): appends the core
|
|
442
486
|
// read_receipt_actions for ids just transitioned unread->read.
|
|
443
487
|
trn qa_mark_read _:($contact -> cid: global_id, $wire_ids -> wids: str[])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ours.network/tg-connector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Bridge Telegram bots to ours proxy nodes — one ADAPT wrapper hosting N messenger packets, each connecting one Telegram bot to one ours node. Run `ours-tg-connector add_new_connection`.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "FSL-1.1-Apache-2.0",
|