@jsm-mit/tigi-sharded-package 0.0.0-stage → 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.
Files changed (53) hide show
  1. package/README.md +128 -2
  2. package/declarations/coordinator/coordinator.did +661 -0
  3. package/declarations/coordinator/coordinator.did.d.ts +1016 -0
  4. package/declarations/coordinator/coordinator.did.js +430 -0
  5. package/declarations/core/core.did +486 -0
  6. package/declarations/core/core.did.d.ts +403 -0
  7. package/declarations/core/core.did.js +325 -0
  8. package/declarations/tigi-driver/tigi-driver.did +201 -0
  9. package/declarations/tigi-driver/tigi-driver.did.d.ts +165 -0
  10. package/declarations/tigi-driver/tigi-driver.did.js +117 -0
  11. package/declarations/tigi-simulator/tigi-simulator.did +300 -0
  12. package/declarations/tigi-simulator/tigi-simulator.did.d.ts +417 -0
  13. package/declarations/tigi-simulator/tigi-simulator.did.js +177 -0
  14. package/declarations/worker/worker.did +453 -0
  15. package/declarations/worker/worker.did.d.ts +399 -0
  16. package/declarations/worker/worker.did.js +348 -0
  17. package/dist/actors/profiles-actor.d.ts +41 -0
  18. package/dist/actors/profiles-actor.d.ts.map +1 -0
  19. package/dist/actors/profiles-actor.js +83 -0
  20. package/dist/actors/rides-actor.d.ts +227 -0
  21. package/dist/actors/rides-actor.d.ts.map +1 -0
  22. package/dist/actors/rides-actor.js +566 -0
  23. package/dist/actors/test-manager-actor.d.ts +37 -0
  24. package/dist/actors/test-manager-actor.d.ts.map +1 -0
  25. package/dist/actors/test-manager-actor.js +64 -0
  26. package/dist/chat.d.ts +51 -0
  27. package/dist/chat.d.ts.map +1 -0
  28. package/dist/chat.js +87 -0
  29. package/dist/geo.d.ts +18 -0
  30. package/dist/geo.d.ts.map +1 -0
  31. package/dist/geo.js +132 -0
  32. package/dist/group/canister-actor.d.ts +94 -0
  33. package/dist/group/canister-actor.d.ts.map +1 -0
  34. package/dist/group/canister-actor.js +182 -0
  35. package/dist/group/group.d.ts +63 -0
  36. package/dist/group/group.d.ts.map +1 -0
  37. package/dist/group/group.js +120 -0
  38. package/dist/group/prefixes.d.ts +14 -0
  39. package/dist/group/prefixes.d.ts.map +1 -0
  40. package/dist/group/prefixes.js +26 -0
  41. package/dist/group-entry.d.ts +3 -0
  42. package/dist/group-entry.d.ts.map +1 -0
  43. package/dist/group-entry.js +5 -0
  44. package/dist/index.d.ts +8 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +15 -0
  47. package/dist/interfaces.d.ts +168 -0
  48. package/dist/interfaces.d.ts.map +1 -0
  49. package/dist/interfaces.js +5 -0
  50. package/dist/mappers.d.ts +70 -0
  51. package/dist/mappers.d.ts.map +1 -0
  52. package/dist/mappers.js +169 -0
  53. package/package.json +63 -5
package/README.md CHANGED
@@ -1,3 +1,129 @@
1
- # Temporary Holding Version
1
+ # @jsm-mit/tigi-sharded-package
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The one package of the Tigi network group: it takes the coordinator's id and hides the
4
+ coordinator, the core and the workers — for a consumer the group is one canister. It also
5
+ carries the rider's few driver-canister endpoints (U-14: `getRide`, `cancelRide`,
6
+ `getLicence`), built from `protocol/tigi-driver.did`, so the consumer never sees a driver
7
+ canister's id.
8
+
9
+ Status: the rider's side (night 1, U-42); 0.2.0 (stage 2a, U-43) adds the rider's own
10
+ rating and WHERE the chat with a driver is. Version 0.1.0 was the first to publish.
11
+
12
+ ## The rider
13
+
14
+ ```ts
15
+ import { ProfilesActor, RidesActor, TestManagerActor, REQUEST_POLL_MS } from "@jsm-mit/tigi-sharded-package";
16
+
17
+ const profiles = new ProfilesActor(coordinatorId, identity, { host });
18
+ await profiles.setMyProfileAsyncUnsafe("Ala"); // C-2: once, before the first request
19
+
20
+ const rides = new RidesActor(coordinatorId, identity, { host });
21
+ const request = await rides.requestRideAsyncUnsafe({ pickup, destination });
22
+ localStorage.setItem("tigi-request", request.token); // rides.resumeRequest(token) after a reload
23
+
24
+ const snapshot = await request.getAsyncUnsafe(); // every REQUEST_POLL_MS (1 s)
25
+ // snapshot.phase: searching | waitingForDriver ("Zamawiam…", a second or two) | accepted | closed
26
+ // snapshot.offers: a FIXED list (U-42) — by first arrival, new ones at the end, nothing
27
+ // re-sorted; an offer that left keeps its entry with `gone` (rejected | driverNotFree |
28
+ // taken | closed): draw a grey row of the same height there
29
+ await request.rejectOfferAsyncUnsafe(offer.offerId); // ✕ → gone "rejected"; the next nearest driver
30
+ await request.refreshOfferAsyncUnsafe(offer.offerId); // a stale (grey) offer asks again
31
+ await request.chooseOfferAsyncUnsafe(offer.offerId); // ordered (= the ride, accepted at once) | busy | offerExpired
32
+ // | driverNotFree ("Kierowca jest już zajęty") | closed
33
+ await request.giveUpAsyncUnsafe();
34
+ // After "Kierowca anulował kurs" (ride status cancelledByDriver): "Szukaj ponownie" —
35
+ const again = await request.searchAgainAsyncUnsafe(); // a new request, the same pickup and destination
36
+
37
+ const ride = await request.getRideAsyncUnsafe(); // from the driver canister, every RIDE_POLL_MS (2 s)
38
+ await request.cancelRideAsyncUnsafe(); // before inProgress, once
39
+ await request.getLicenceAsyncUnsafe(); // from accepted to the end of the ride
40
+ await request.rateDriverAsyncUnsafe(5); // after completed, once
41
+
42
+ const page = await profiles.getMyRidesAsyncUnsafe(); // the history in the core, 20 a page
43
+ const mine = await profiles.getMyRatingAsyncUnsafe(); // PF-4: { average: 4.87, count, sum } | undefined ("Brak ocen")
44
+ await rides.getPastRideAsyncUnsafe(page.rides[0].rideRef); // its details from the driver canister
45
+ ```
46
+
47
+ What the package does for the network (zgloszenie-i-oferty.md):
48
+
49
+ - the request goes to every worker whose area reaches 3 km around the pickup (ZO-1), found
50
+ with the coordinator's prefix map (kept 30 s; a worker's `NOT_MY_AREA` makes it ask again);
51
+ - 15 s without an offer → 6 km, in the same and in new workers (ZO-8), inside `getAsyncUnsafe`;
52
+ - one choice at a time over all the workers (ZO-14); after an acceptance,
53
+ `closeRequest otherOfferChosen` in the other workers (ZO-15);
54
+ - a stopped canister (an upgrade, IC0508/IC0509) is waited out for about a minute.
55
+
56
+ Errors: `CanisterError` (with `errorKey`; `refusalKeyOf(err)` gives the worker's refusal:
57
+ `ALREADY_OPEN`, `NOT_MY_AREA`, `FULL`, `CLOSED`, `ORDERING`, `DRIVER_NOT_FREE`,
58
+ `NOT_COMPLETED`, `EXPIRED`, `BLOCKED`), `CallRefusedAtInspectionStage`,
59
+ `CriticalCanisterError`.
60
+
61
+ ## For the fronts: the chat (U-43)
62
+
63
+ One chat room per DRIVER in `chat-sharded` (not per ride): its recipient is the owner of
64
+ the driver canister, and every Tigi account may open a chat there (the chat asks the Tigi
65
+ coordinator WHERE the accounts are and the core `isUser`). The core makes the rooms through
66
+ the coordinator; this package only says WHERE — the fronts send and read messages with
67
+ `@jsm-mit/chat-sharded-package` themselves (this package does not wrap the chat).
68
+
69
+ ```ts
70
+ import { ChatPlacesActor, driverRoomId } from "@jsm-mit/tigi-sharded-package";
71
+ import { ChatsActor, MessagesActor } from "@jsm-mit/chat-sharded-package";
72
+
73
+ // The rider (PR-25): from `accepted` to the end of the ride.
74
+ const place = await request.getChatPlaceAsyncUnsafe(); // { chatCoordinatorId, projectId, roomId } | undefined
75
+ if (place) {
76
+ const chats = new ChatsActor(place.chatCoordinatorId, identity, { host });
77
+ const chat = await chats.openChatAsyncUnsafe({ projectId: place.projectId, roomId: place.roomId, customerName: profile.name });
78
+ // … MessagesActor(place.chatCoordinatorId, identity).postAsyncUnsafe / pollNewMessagesAsyncUnsafe
79
+ }
80
+
81
+ // The driver (FK-20): the room of their own canister; they are its recipient.
82
+ const driverPlace = await new ChatPlacesActor(coordinatorId, identity, { host }).getDriverChatPlaceAsyncUnsafe(myDriverCanisterId);
83
+ // list the chats of driverPlace.roomId (ChatsActor.getMyChatsAsyncUnsafe({ projectId, roomId }))
84
+ // and show only the current rider's chat
85
+ ```
86
+
87
+ - `undefined` = no chat in this environment yet (no chat config in the core) or a
88
+ simulated driver (no chat in MVP).
89
+ - The room id is deterministic: `driverRoomId(canister)` = `drv-<canister id>` (the
90
+ core's `ChatRoomFunctions.driverRoomId`).
91
+ - The rider needs a Tigi profile (`setMyProfileAsyncUnsafe`) — without one the chat
92
+ refuses to open it (`CanisterError`, `NotAuthorized`).
93
+ - One chat per (room, rider, recipients): the rider has one chat with a driver over all
94
+ their rides. A demo pool canister taken over by another tester gets that tester as
95
+ the recipient; the chats with the previous tester stay with them.
96
+ - The room may appear a few seconds after the driver's canister (the core's outbox);
97
+ `openChatAsyncUnsafe` answers `NotFound` until then — try again.
98
+
99
+ The Test Manager (stage and the test modes): `TestManagerActor.hasSimulatedDriversAsyncUnsafe`,
100
+ `spawnDriversAsyncUnsafe` (12 drivers), `setSpeedUpAsyncUnsafe(request, 10)` before choosing.
101
+ Offers of the simulator have `simulated: true`.
102
+
103
+ ## Scripts
104
+
105
+ ```
106
+ npm run build # tsc (src → dist) and the type-check of the tests
107
+ npm run test-unit # no replica needed
108
+ npm run test-drivers # (a) 5 real driver canisters, driver-bots, route-stub
109
+ npm run test-simulator # (b) the simulator, 20 requests, 20 rides
110
+ npm run test-split # (c) an area split during traffic
111
+ npm run test-smoke # one whole ride with the simulator (run by publish-public)
112
+ npm run publish-public # human-run: publish from master (see below)
113
+ npm run sync-declarations # after a change of a .did (`… protocol` for the protocol and the simulator only)
114
+ ```
115
+
116
+ The end-to-end suites run on the LOCAL replica only (`scripts/run-tests-local.sh`): a fresh
117
+ group, local cycles, the driver and simulator wasms of `../../tigi-driver-rust` (built
118
+ there, never changed). Logs and measurements go to `/tmp/claude-1000/tigi/`
119
+ (`TEST_LOG_DIR`).
120
+
121
+ ## Publishing
122
+
123
+ Human-run only: bump `version` in `package.json` by hand (do not commit it), then
124
+ `npm run publish-public` on `master`. The script refuses unless this repo and
125
+ `../../tigi-driver-rust` are both on a clean `master` equal to `origin/master`, the version is
126
+ new on npm, the declarations match the current builds (core, worker, coordinator, protocol,
127
+ simulator) and the smoke test passes on the LOCAL replica (`dfx start` first). It stamps
128
+ `tigiSharded.commit` and `tigiDriverRust.commit` into `package.json`, publishes, then commits
129
+ "Version bump to <version>" and pushes.