samagotchi 0.170.0 → 0.172.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +61 -1
- data/bin/chi +6 -4
- data/docs/architecture.md +26 -9
- data/docs/bundles.md +4 -21
- data/docs/cli.md +81 -97
- data/docs/configuration.md +12 -14
- data/docs/context.md +5 -6
- data/docs/guardrails.md +57 -96
- data/docs/hooks.md +3 -4
- data/docs/internals/attached-context.md +6 -7
- data/docs/internals/background-tasks.md +4 -3
- data/docs/internals/block-renderers.md +2 -2
- data/docs/internals/bridge.md +34 -7
- data/docs/internals/context-telemetry.md +13 -1
- data/docs/internals/engine.md +25 -13
- data/docs/internals/inline-widgets.md +1 -1
- data/docs/internals/objectives.md +4 -6
- data/docs/internals/participants.md +340 -249
- data/docs/internals/prompt-caching.md +4 -5
- data/docs/internals/web-frontend.md +185 -35
- data/docs/internals/working-set.md +71 -5
- data/docs/memory.md +1 -1
- data/docs/plugins.md +2 -16
- data/docs/releasing.md +2 -1
- data/docs/scheduling.md +1 -1
- data/docs/sessions.md +17 -48
- data/docs/sub-agent.md +2 -2
- data/docs/system-one.md +2 -2
- data/docs/testing.md +56 -7
- data/lib/samagotchi/bridge/card_store.rb +1 -0
- data/lib/samagotchi/bridge/sse_writer.rb +1 -0
- data/lib/samagotchi/bridge/turn_accumulator.rb +8 -5
- data/lib/samagotchi/bridge.rb +64 -20
- data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
- data/lib/samagotchi/bundle_command/test_run.rb +1 -0
- data/lib/samagotchi/bundle_command/try/run.rb +1 -0
- data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
- data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
- data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
- data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
- data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
- data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
- data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +126 -67
- data/lib/samagotchi/command_intake.rb +15 -3
- data/lib/samagotchi/compat.rb +6 -1
- data/lib/samagotchi/context_candidate_choice.rb +1 -3
- data/lib/samagotchi/context_candidates.rb +3 -4
- data/lib/samagotchi/continue_offer.rb +9 -2
- data/lib/samagotchi/delivery.rb +36 -12
- data/lib/samagotchi/empty_answer_error.rb +5 -0
- data/lib/samagotchi/engine/cards.rb +3 -0
- data/lib/samagotchi/engine/context_judge.rb +5 -3
- data/lib/samagotchi/engine/events.rb +4 -0
- data/lib/samagotchi/engine/hooks.rb +3 -0
- data/lib/samagotchi/engine/messages.rb +5 -0
- data/lib/samagotchi/engine/model_settings.rb +2 -0
- data/lib/samagotchi/engine/models.rb +10 -0
- data/lib/samagotchi/engine/objectives.rb +6 -0
- data/lib/samagotchi/engine/participants.rb +18 -14
- data/lib/samagotchi/engine/plugins.rb +8 -0
- data/lib/samagotchi/engine/questions.rb +3 -0
- data/lib/samagotchi/engine/recap.rb +1 -0
- data/lib/samagotchi/engine/session.rb +4 -0
- data/lib/samagotchi/engine/side_requests.rb +9 -0
- data/lib/samagotchi/engine/steering.rb +2 -0
- data/lib/samagotchi/engine/toolkit.rb +5 -0
- data/lib/samagotchi/engine/turn_end.rb +7 -0
- data/lib/samagotchi/engine/turn_helpers.rb +8 -0
- data/lib/samagotchi/engine/verify.rb +2 -0
- data/lib/samagotchi/engine.rb +8 -3
- data/lib/samagotchi/event_fanout.rb +22 -1
- data/lib/samagotchi/grants.rb +33 -22
- data/lib/samagotchi/guardrail_wiring.rb +23 -18
- data/lib/samagotchi/guardrails/approval_use.rb +59 -0
- data/lib/samagotchi/guardrails/approvals.rb +9 -11
- data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
- data/lib/samagotchi/guardrails/gate.rb +10 -5
- data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
- data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
- data/lib/samagotchi/guardrails/review_paths.rb +2 -3
- data/lib/samagotchi/guardrails.rb +1 -1
- data/lib/samagotchi/image_store.rb +51 -12
- data/lib/samagotchi/kernel_loop.rb +7 -1
- data/lib/samagotchi/llm/stray_tool_call.rb +7 -4
- data/lib/samagotchi/llm_context_stale.rb +4 -1
- data/lib/samagotchi/llm_context_strategy.rb +2 -0
- data/lib/samagotchi/objectives.rb +1 -4
- data/lib/samagotchi/objectives_audit.rb +1 -1
- data/lib/samagotchi/objectives_track.rb +1 -1
- data/lib/samagotchi/owner_prompt.rb +3 -6
- data/lib/samagotchi/parent_report.rb +1 -0
- data/lib/samagotchi/participant_messages.rb +48 -4
- data/lib/samagotchi/participant_revise.rb +61 -0
- data/lib/samagotchi/participant_turn_mode.rb +50 -0
- data/lib/samagotchi/participant_uploads.rb +98 -0
- data/lib/samagotchi/participants.rb +21 -12
- data/lib/samagotchi/participants_watch.rb +2 -2
- data/lib/samagotchi/plugin/api.rb +2 -2
- data/lib/samagotchi/plugin/attached_context.rb +1 -1
- data/lib/samagotchi/plugin/context.rb +0 -4
- data/lib/samagotchi/plugin/sessions.rb +1 -25
- data/lib/samagotchi/reply_wait/poll.rb +5 -1
- data/lib/samagotchi/revise_anchor.rb +9 -0
- data/lib/samagotchi/run_options.rb +2 -3
- data/lib/samagotchi/send_command.rb +15 -10
- data/lib/samagotchi/session.rb +0 -3
- data/lib/samagotchi/session_access/contract.rb +1 -10
- data/lib/samagotchi/session_access/local.rb +10 -23
- data/lib/samagotchi/session_access/remote.rb +9 -20
- data/lib/samagotchi/session_access.rb +12 -16
- data/lib/samagotchi/session_chain.rb +4 -6
- data/lib/samagotchi/session_commands.rb +6 -3
- data/lib/samagotchi/session_continue.rb +1 -2
- data/lib/samagotchi/session_inbox.rb +20 -12
- data/lib/samagotchi/session_manager/delivery.rb +32 -5
- data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
- data/lib/samagotchi/session_manager/listing.rb +5 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/session_manager/worker_command.rb +9 -0
- data/lib/samagotchi/session_participants.rb +12 -8
- data/lib/samagotchi/session_review.rb +5 -7
- data/lib/samagotchi/session_stores.rb +3 -1
- data/lib/samagotchi/share_command.rb +10 -12
- data/lib/samagotchi/share_terms.rb +41 -0
- data/lib/samagotchi/steer.rb +8 -14
- data/lib/samagotchi/system_prompt.rb +16 -25
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
- data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
- data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
- data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
- data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
- data/lib/samagotchi/terminal_ui.rb +1 -2
- data/lib/samagotchi/testing/sessions.rb +2 -10
- data/lib/samagotchi/tool_runner.rb +42 -9
- data/lib/samagotchi/toolkit.rb +4 -22
- data/lib/samagotchi/toolkit_suggest.rb +3 -3
- data/lib/samagotchi/tools/deferred_tools.rb +1 -0
- data/lib/samagotchi/tools/execute.rb +11 -45
- data/lib/samagotchi/tools/leftovers.rb +122 -0
- data/lib/samagotchi/tools/memory.rb +88 -25
- data/lib/samagotchi/tools/task_get.rb +1 -0
- data/lib/samagotchi/tools/task_list.rb +3 -2
- data/lib/samagotchi/tools/task_record.rb +6 -4
- data/lib/samagotchi/tools/task_runtime.rb +199 -20
- data/lib/samagotchi/tools/task_wait.rb +4 -3
- data/lib/samagotchi/turn_anchors.rb +0 -3
- data/lib/samagotchi/turn_context.rb +1 -1
- data/lib/samagotchi/turn_origin.rb +1 -1
- data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
- data/lib/samagotchi/turn_stages/objectives.rb +2 -2
- data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
- data/lib/samagotchi/turn_stages/verify_anchors.rb +13 -1
- data/lib/samagotchi/update_hint.rb +3 -1
- data/lib/samagotchi/verify_anchor.rb +6 -0
- data/lib/samagotchi/verify_fresh.rb +1 -1
- data/lib/samagotchi/verify_fresh_origin.rb +13 -11
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +45 -82
- data/lib/samagotchi/web/participant_access.rb +139 -40
- data/lib/samagotchi/web/participant_images.rb +185 -0
- data/lib/samagotchi/web/participant_review.rb +22 -142
- data/lib/samagotchi/web/participant_show.rb +241 -0
- data/lib/samagotchi/web/participant_stream_filter.rb +25 -2
- data/lib/samagotchi/web/participant_view.rb +334 -27
- data/lib/samagotchi/web/participants_admin.rb +21 -40
- data/lib/samagotchi/web/public/annotate_bar.css +1 -2
- data/lib/samagotchi/web/public/annotate_bar.js +1 -2
- data/lib/samagotchi/web/public/app.js +126 -132
- data/lib/samagotchi/web/public/block_host.js +7 -4
- data/lib/samagotchi/web/public/bubbles.js +9 -1
- data/lib/samagotchi/web/public/cards_offscreen.js +69 -0
- data/lib/samagotchi/web/public/chip_popover.js +5 -4
- data/lib/samagotchi/web/public/claim_link.js +4 -4
- data/lib/samagotchi/web/public/composer.css +4 -6
- data/lib/samagotchi/web/public/composer_mode.js +11 -6
- data/lib/samagotchi/web/public/composer_mount.js +4 -4
- data/lib/samagotchi/web/public/ctx.js +12 -3
- data/lib/samagotchi/web/public/data.js +2 -10
- data/lib/samagotchi/web/public/delivery_line.js +49 -63
- data/lib/samagotchi/web/public/history_shape.js +5 -1
- data/lib/samagotchi/web/public/images.js +7 -1
- data/lib/samagotchi/web/public/index.html +50 -34
- data/lib/samagotchi/web/public/info_bar_model.js +2 -1
- data/lib/samagotchi/web/public/live_turn.js +1 -1
- data/lib/samagotchi/web/public/markdown_place.js +5 -4
- data/lib/samagotchi/web/public/owner_claim.js +5 -5
- data/lib/samagotchi/web/public/owner_verify.js +0 -2
- data/lib/samagotchi/web/public/participant_bar.js +107 -0
- data/lib/samagotchi/web/public/participant_main.js +289 -0
- data/lib/samagotchi/web/public/participant_model.js +5 -292
- data/lib/samagotchi/web/public/participant_names.js +17 -8
- data/lib/samagotchi/web/public/participant_revise.js +66 -0
- data/lib/samagotchi/web/public/participants_panel.js +32 -74
- data/lib/samagotchi/web/public/question_cards.js +14 -3
- data/lib/samagotchi/web/public/refs.js +53 -36
- data/lib/samagotchi/web/public/reload_check.js +70 -14
- data/lib/samagotchi/web/public/revise_stack.js +21 -10
- data/lib/samagotchi/web/public/send_turn.js +28 -29
- data/lib/samagotchi/web/public/session_actions.js +4 -45
- data/lib/samagotchi/web/public/session_fields.js +1 -2
- data/lib/samagotchi/web/public/session_state.js +12 -7
- data/lib/samagotchi/web/public/session_sync.js +9 -2
- data/lib/samagotchi/web/public/session_view.js +14 -5
- data/lib/samagotchi/web/public/settings_panel.js +4 -18
- data/lib/samagotchi/web/public/stage_answer.js +56 -0
- data/lib/samagotchi/web/public/stage_asking.js +7 -5
- data/lib/samagotchi/web/public/stage_cloud.js +93 -0
- data/lib/samagotchi/web/public/stage_dom.js +100 -0
- data/lib/samagotchi/web/public/stage_handoff.js +154 -0
- data/lib/samagotchi/web/public/stage_owner_wait.js +35 -0
- data/lib/samagotchi/web/public/stage_pager.js +59 -0
- data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
- data/lib/samagotchi/web/public/stage_view.js +103 -410
- data/lib/samagotchi/web/public/stage_waiting.js +74 -6
- data/lib/samagotchi/web/public/start_page.js +12 -33
- data/lib/samagotchi/web/public/start_settings.js +24 -78
- data/lib/samagotchi/web/public/start_toolkit.js +6 -10
- data/lib/samagotchi/web/public/storage.js +22 -0
- data/lib/samagotchi/web/public/stream_handlers.js +3 -10
- data/lib/samagotchi/web/public/tokens.css +1 -1
- data/lib/samagotchi/web/public/turn_block.js +2 -5
- data/lib/samagotchi/web/public/turn_events.js +30 -12
- data/lib/samagotchi/web/public/turn_html.js +9 -2
- data/lib/samagotchi/web/public/turn_pieces.js +3 -4
- data/lib/samagotchi/web/public/turn_range.js +1 -2
- data/lib/samagotchi/web/public/verify_target.js +2 -4
- data/lib/samagotchi/web/public/viewer.js +59 -0
- data/lib/samagotchi/web/public/viewer_self.js +59 -0
- data/lib/samagotchi/web/public/working_set.js +11 -5
- data/lib/samagotchi/web/public/working_set_view.js +53 -8
- data/lib/samagotchi/web/public/ws_cards.js +89 -0
- data/lib/samagotchi/web/public/ws_peek.js +106 -0
- data/lib/samagotchi/web/public/ws_preview.css +126 -0
- data/lib/samagotchi/web/public/ws_reader.js +319 -0
- data/lib/samagotchi/web/public/ws_timeline.js +200 -0
- data/lib/samagotchi/web/public/ws_way_in.js +25 -0
- data/lib/samagotchi/web/qr.rb +1 -1
- data/lib/samagotchi/web/session_control.rb +42 -15
- data/lib/samagotchi/web/session_create.rb +6 -72
- data/lib/samagotchi/web/session_show.rb +75 -28
- data/lib/samagotchi/web/session_summary.rb +1 -4
- data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
- data/lib/samagotchi/web/viewer.rb +70 -0
- data/lib/samagotchi/web/working_set_routes.rb +132 -0
- data/lib/samagotchi/worker.rb +35 -28
- data/lib/samagotchi/worker_inbound.rb +4 -3
- data/lib/samagotchi/worker_link.rb +17 -0
- data/lib/samagotchi/working_set.rb +322 -11
- metadata +32 -13
- data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
- data/lib/samagotchi/participant_mode.rb +0 -86
- data/lib/samagotchi/review_apply.rb +0 -131
- data/lib/samagotchi/review_command.rb +0 -123
- data/lib/samagotchi/review_start.rb +0 -196
- data/lib/samagotchi/web/public/participant.html +0 -218
- data/lib/samagotchi/web/public/participant.js +0 -719
- data/lib/samagotchi/web/public/participant_annotate.js +0 -76
- data/lib/samagotchi/web/public/review_apply.js +0 -34
- data/lib/samagotchi/web/public/review_history.js +0 -72
- data/lib/samagotchi/web/public/review_start.js +0 -55
- data/lib/samagotchi/web/public/tools_overview.js +0 -42
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// The main page for a participant (an invited person's link): what is
|
|
2
|
+
// theirs on the owner's page, wired from app.js in a few lines. The
|
|
3
|
+
// owner's page never makes it (app.js: viewer.kind() is "participant").
|
|
4
|
+
//
|
|
5
|
+
// - The grant's session (<body data-session>) is the page's one session,
|
|
6
|
+
// whatever the hash says; no start page, no list.
|
|
7
|
+
// - Who they are (viewer_self.js), from each show's `viewer`: their own
|
|
8
|
+
// turns and prompts, the owner's labelled "owner".
|
|
9
|
+
// - The top row's name and the link's end, the bottom row in the bar's
|
|
10
|
+
// place, the closed composer (participant_bar.js).
|
|
11
|
+
// - The running turn: whose it is (turn_started's author and `mine`), so
|
|
12
|
+
// Stop turn shows on their own only and the delivery line says where a
|
|
13
|
+
// message goes; and whether it waits for the owner (question_requested
|
|
14
|
+
// / continue_offered's `kind`; stage_owner_wait.js draws it).
|
|
15
|
+
// - Their usage and limit, read again from the show at each turn's end
|
|
16
|
+
// (the light re-reads carry no viewer).
|
|
17
|
+
// - A link that ended mid-session (a 401 from chi web): the composer gives
|
|
18
|
+
// way to the server's sentence, instead of the owner's signed-out banner.
|
|
19
|
+
//
|
|
20
|
+
// See docs/internals/web-frontend.md (The participant's page).
|
|
21
|
+
import { render } from "./vendor/lit-html.js";
|
|
22
|
+
import { setViewerSelf } from "./viewer_self.js";
|
|
23
|
+
import { authorColor, participantAuthor } from "./participant_model.js";
|
|
24
|
+
import { barItems, barTemplate, CLOSING_CODES, closedLine, closedTemplate, whoTemplate } from "./participant_bar.js";
|
|
25
|
+
|
|
26
|
+
// The worker features a participant's composer reads: their message goes
|
|
27
|
+
// into their own running turn at its next step (Delivery::OWN_TURN_STEER_FEATURE).
|
|
28
|
+
export const PARTICIPANT_STEER = "participant_steer";
|
|
29
|
+
// A 401 whose words the page couldn't read (an auth proxy's own answer).
|
|
30
|
+
export const LINK_ENDED = "this link no longer opens the session";
|
|
31
|
+
|
|
32
|
+
// The events that end a turn: whose turn it was and its wait go, and the
|
|
33
|
+
// viewer is read again (their spend moved).
|
|
34
|
+
const TURN_ENDS = ["turn_completed", "turn_canceled", "turn_failed"];
|
|
35
|
+
// The owner's question, approval or Continue offer, and their answers:
|
|
36
|
+
// chi web sends a participant the kind alone, never a card's content.
|
|
37
|
+
const WAITS = ["question_requested", "continue_offered"];
|
|
38
|
+
const WAIT_ENDS = ["question_answered", "question_cancelled", "continue_resolved"];
|
|
39
|
+
|
|
40
|
+
// @param body the page's <body> (data-session, data-session-title)
|
|
41
|
+
// @param topBar #topBar: the logo, title, their name, the link's end
|
|
42
|
+
// @param infoBar #infoBar: the bottom row takes its place
|
|
43
|
+
// @param composer #composer: given way to the closed line
|
|
44
|
+
// @param store the session store (store.current: ctxPct, timing, workerFeatures)
|
|
45
|
+
// @param running() a turn runs (liveTurn.running)
|
|
46
|
+
// @param stage the stage view (turnDom): redraw()
|
|
47
|
+
// @param read(id) the session's show (data.js getSession)
|
|
48
|
+
// @param probe(id) a fetch Response of the session's brief read, whose 401 carries the ended link's words
|
|
49
|
+
// @param onClosed() the composer closed or opened again (the Revise buttons follow)
|
|
50
|
+
export function createParticipantMain({ body, topBar, infoBar, composer, store, running, stage, read, onClosed = () => {},
|
|
51
|
+
probe = (id) => fetch(`/api/sessions/${encodeURIComponent(id)}?brief=1`, { headers: { Accept: "application/json" } }) }) {
|
|
52
|
+
const sessionId = body.dataset.session || null;
|
|
53
|
+
let viewer = null;
|
|
54
|
+
// The running turn's author: {author, name, mine}; null between turns.
|
|
55
|
+
let turnBy = null;
|
|
56
|
+
// What the running turn waits for the owner on (a kind), or null.
|
|
57
|
+
let waitKind = null;
|
|
58
|
+
// The last generation's speed ({decode_tps, source}).
|
|
59
|
+
let speed = null;
|
|
60
|
+
// A refusal that closed the composer ({code, text}).
|
|
61
|
+
let refusal = null;
|
|
62
|
+
let reading = null;
|
|
63
|
+
// A second turn ended while a re-read was out: one more after it.
|
|
64
|
+
let readAgain = false;
|
|
65
|
+
// What the last show said the session waits for the owner on: a reload
|
|
66
|
+
// or a resync mid-wait gets no question event (no cards for them), only
|
|
67
|
+
// this; the replay's turn_started keeps it.
|
|
68
|
+
let showWait = null;
|
|
69
|
+
// Live turn starts so far: a re-read begun before one is stale about the wait.
|
|
70
|
+
let starts = 0;
|
|
71
|
+
// The session's title as the last show read it (chi web's participant title).
|
|
72
|
+
let title = null;
|
|
73
|
+
|
|
74
|
+
// The top row: a plain logo (not the owner's new-session button), their
|
|
75
|
+
// name and the link's end after the title.
|
|
76
|
+
const logo = document.createElement("span");
|
|
77
|
+
logo.className = "brand plain-brand";
|
|
78
|
+
logo.textContent = "chi";
|
|
79
|
+
topBar.prepend(logo);
|
|
80
|
+
const who = document.createElement("span");
|
|
81
|
+
who.id = "participantWho";
|
|
82
|
+
topBar.querySelector("#sessionTitleRow")?.after(who);
|
|
83
|
+
// The bottom row, in the owner's info line's place.
|
|
84
|
+
const row = document.createElement("div");
|
|
85
|
+
row.id = "participantBar";
|
|
86
|
+
infoBar.prepend(row);
|
|
87
|
+
infoBar.querySelector("#infoText")?.setAttribute("hidden", "");
|
|
88
|
+
const closed = document.createElement("div");
|
|
89
|
+
closed.id = "participantClosed";
|
|
90
|
+
closed.hidden = true;
|
|
91
|
+
composer.after(closed);
|
|
92
|
+
body.classList.add("participant-view");
|
|
93
|
+
|
|
94
|
+
const redraw = () => store.touch("infoBar");
|
|
95
|
+
|
|
96
|
+
function drawTop() {
|
|
97
|
+
const color = viewer?.id ? authorColor(participantAuthor(viewer.id)) : null;
|
|
98
|
+
render(whoTemplate({ name: viewer?.name, endsAt: viewer?.usage?.expires_at, color }), who);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function drawClosed() {
|
|
102
|
+
const line = closedLine({ capReached: !!viewer?.cap_reached, usage: viewer?.usage, refusal });
|
|
103
|
+
const flips = closed.hidden === !!line;
|
|
104
|
+
closed.hidden = !line;
|
|
105
|
+
composer.hidden = !!line;
|
|
106
|
+
body.classList.toggle("participant-closed", !!line);
|
|
107
|
+
if (line) {
|
|
108
|
+
closed.dataset.kind = line.kind;
|
|
109
|
+
render(closedTemplate(line), closed);
|
|
110
|
+
}
|
|
111
|
+
if (flips) onClosed();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// A show's viewer: who they are, their usage, whether the session waits.
|
|
115
|
+
// +fresh+ false: a re-read a turn started after (its wait is stale).
|
|
116
|
+
function shown(next, { fresh = true } = {}) {
|
|
117
|
+
if (!next || next.kind !== "participant") return;
|
|
118
|
+
viewer = next;
|
|
119
|
+
setViewerSelf(next);
|
|
120
|
+
// A session the owner started again (it runs, or was read not stopped)
|
|
121
|
+
// takes the stopped line back.
|
|
122
|
+
if (refusal?.code === "session_stopped" && !next.session_stopped) refusal = null;
|
|
123
|
+
if (fresh) {
|
|
124
|
+
showWait = next.waiting_for_owner || null;
|
|
125
|
+
if (running()) waitKind = showWait;
|
|
126
|
+
}
|
|
127
|
+
drawTop();
|
|
128
|
+
drawClosed();
|
|
129
|
+
stage.redraw?.();
|
|
130
|
+
redraw();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The viewer again from the show (its usage moved, or its cap).
|
|
134
|
+
async function reread() {
|
|
135
|
+
if (!sessionId) return null;
|
|
136
|
+
if (reading) {
|
|
137
|
+
readAgain = true;
|
|
138
|
+
return reading;
|
|
139
|
+
}
|
|
140
|
+
const at = starts;
|
|
141
|
+
reading = read(sessionId).then((data) => {
|
|
142
|
+
if (typeof data?.session?.title === "string" && data.session.title) title = data.session.title;
|
|
143
|
+
shown(data?.viewer, { fresh: at === starts });
|
|
144
|
+
}, () => {}).finally(() => {
|
|
145
|
+
reading = null;
|
|
146
|
+
if (readAgain) {
|
|
147
|
+
readAgain = false;
|
|
148
|
+
reread();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return reading;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function started(data) {
|
|
155
|
+
turnBy = { author: data?.author || null, name: data?.author_name || null, mine: !!data?.mine };
|
|
156
|
+
// A replayed start (a load or resync mid-turn) is the turn the show read:
|
|
157
|
+
// its wait stands. A live one starts unwaited.
|
|
158
|
+
if (data?.replayed) waitKind = showWait;
|
|
159
|
+
else {
|
|
160
|
+
starts += 1;
|
|
161
|
+
waitKind = null;
|
|
162
|
+
showWait = null;
|
|
163
|
+
}
|
|
164
|
+
if (refusal?.code === "session_stopped") {
|
|
165
|
+
refusal = null;
|
|
166
|
+
drawClosed();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// The stream's handlers (stream_handlers.js) with a participant's own
|
|
171
|
+
// reading of the events chi web sends them bare or cut down.
|
|
172
|
+
function wrapHandlers(handlers) {
|
|
173
|
+
const wrapped = { ...handlers };
|
|
174
|
+
wrapped.turn_started = (data) => {
|
|
175
|
+
started(data);
|
|
176
|
+
handlers.turn_started?.(data);
|
|
177
|
+
stage.redraw?.();
|
|
178
|
+
};
|
|
179
|
+
for (const type of TURN_ENDS) {
|
|
180
|
+
wrapped[type] = (data) => {
|
|
181
|
+
waitKind = null;
|
|
182
|
+
if (!data?.replayed) showWait = null;
|
|
183
|
+
const out = handlers[type]?.(data);
|
|
184
|
+
turnBy = null;
|
|
185
|
+
reread();
|
|
186
|
+
redraw();
|
|
187
|
+
return out;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// No card: the stage's waiting look says for what kind of thing.
|
|
191
|
+
for (const type of WAITS) {
|
|
192
|
+
wrapped[type] = (data) => {
|
|
193
|
+
waitKind = data?.kind || "question";
|
|
194
|
+
stage.redraw?.();
|
|
195
|
+
redraw();
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
for (const type of WAIT_ENDS) {
|
|
199
|
+
wrapped[type] = (data) => {
|
|
200
|
+
waitKind = null;
|
|
201
|
+
if (!data?.replayed) showWait = null;
|
|
202
|
+
stage.redraw?.();
|
|
203
|
+
redraw();
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
wrapped.generation_completed = (data) => {
|
|
207
|
+
if (data?.speed && Number.isFinite(Number(data.speed.decode_tps))) speed = data.speed;
|
|
208
|
+
return handlers.generation_completed?.(data);
|
|
209
|
+
};
|
|
210
|
+
return wrapped;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function lastSpeed() {
|
|
214
|
+
if (speed) return speed;
|
|
215
|
+
const records = store.current.timing?.turnRecords || [];
|
|
216
|
+
const last = [...records].reverse().find((r) => Number(r.decode_tps) > 0);
|
|
217
|
+
return last ? { decode_tps: last.decode_tps, source: last.tps_source } : null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function drawBar() {
|
|
221
|
+
const isRunning = running();
|
|
222
|
+
const status = isRunning ? (waitKind ? "waiting" : "running") : "idle";
|
|
223
|
+
const startedAt = Date.parse(store.current.timing?.activeTurn?.started_at || "");
|
|
224
|
+
const turnMs = isRunning && Number.isFinite(startedAt) ? Math.max(0, Date.now() - startedAt) : null;
|
|
225
|
+
render(barTemplate(barItems({
|
|
226
|
+
status, ctxPct: store.current.ctxPct, windowSource: store.current.ctxWindowSource, speed: lastSpeed(), turnMs,
|
|
227
|
+
usage: viewer?.usage, mode: viewer?.mode,
|
|
228
|
+
})), row);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// A refused send (send_turn.js): the codes that close the composer
|
|
232
|
+
// close it (the cap: from the show read again); @return whether it was one.
|
|
233
|
+
function refused(error) {
|
|
234
|
+
const code = error?.code;
|
|
235
|
+
if (!CLOSING_CODES.includes(code)) return false;
|
|
236
|
+
if (code === "cap_reached") {
|
|
237
|
+
viewer = viewer ? { ...viewer, cap_reached: true } : viewer;
|
|
238
|
+
drawClosed();
|
|
239
|
+
reread();
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
refusal = { code, text: error.body?.detail || error.message };
|
|
243
|
+
drawClosed();
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// chi web refused the page's credential (data.js onAuthLost): their link
|
|
248
|
+
// ended. The server's sentence: a refused send's own (refused), else the
|
|
249
|
+
// 401 of a brief read.
|
|
250
|
+
let ended = false;
|
|
251
|
+
async function linkEnded() {
|
|
252
|
+
if (ended) return;
|
|
253
|
+
ended = true;
|
|
254
|
+
let found = null;
|
|
255
|
+
try {
|
|
256
|
+
const res = await probe(sessionId);
|
|
257
|
+
const answer = await res.json();
|
|
258
|
+
if (res.status === 401 && answer?.detail) found = { code: answer.error || "token_revoked", text: answer.detail };
|
|
259
|
+
} catch (_) { /* unreachable or not JSON: the words below */ }
|
|
260
|
+
if (refusal?.code?.startsWith("token_")) return;
|
|
261
|
+
refusal = found || { code: "token_revoked", text: LINK_ENDED };
|
|
262
|
+
drawClosed();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
sessionId,
|
|
267
|
+
shown,
|
|
268
|
+
wrapHandlers,
|
|
269
|
+
drawBar,
|
|
270
|
+
refused,
|
|
271
|
+
linkEnded,
|
|
272
|
+
// The session title the top row shows: the one chi web gave the page.
|
|
273
|
+
title: () => title || body.dataset.sessionTitle || "",
|
|
274
|
+
// Whether their composer is closed (no Revise then: participant_revise.js).
|
|
275
|
+
closed: () => !closed.hidden,
|
|
276
|
+
// Stop turn: on their own turn only.
|
|
277
|
+
canCancel: () => !!turnBy?.mine,
|
|
278
|
+
// What the stage's waiting look says, while a turn runs.
|
|
279
|
+
ownerWait: () => (running() ? waitKind : null),
|
|
280
|
+
// The delivery line's input (delivery_line.js viewerTurn): whose turn
|
|
281
|
+
// runs, and whether a message goes into it (their own, on a worker that
|
|
282
|
+
// takes it).
|
|
283
|
+
deliveryTurn: () => ({
|
|
284
|
+
own: !!turnBy?.mine,
|
|
285
|
+
steer: !!turnBy?.mine && (store.current.workerFeatures || []).includes(PARTICIPANT_STEER),
|
|
286
|
+
by: turnBy?.author && !turnBy.mine ? turnBy.name || "another participant" : null,
|
|
287
|
+
}),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import { fullTime, gapText } from "./format.js";
|
|
1
|
+
// A participant's author and colour, pure: the one place the web spells a
|
|
2
|
+
// participant's author ("p:<grant id>"), shared by the badges on their
|
|
3
|
+
// prompts (participant_names.js), the owner's participants panel, the
|
|
4
|
+
// question cards, notifications and the viewer's own identity
|
|
5
|
+
// (viewer_self.js).
|
|
7
6
|
|
|
8
7
|
// A participant's author: "p:" and its grant id, as the server writes it
|
|
9
8
|
// (Steer.author_for / PARTICIPANT_PREFIX): the one place the web spells it.
|
|
@@ -25,289 +24,3 @@ export function authorSlot(author) {
|
|
|
25
24
|
export function authorColor(author) {
|
|
26
25
|
return isParticipantAuthor(author) ? `var(--author-${authorSlot(author)})` : "var(--author-owner)";
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
// Who wrote a user message or started a turn, as the page names them.
|
|
30
|
-
export function authorLabel(item) {
|
|
31
|
-
if (item?.mine) return "You";
|
|
32
|
-
if (isParticipantAuthor(item?.author)) return item.author_name || "A participant";
|
|
33
|
-
if (item?.automatic) return "Automatic";
|
|
34
|
-
return "Owner";
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// "read docs/plan.md", or the tool's name alone.
|
|
38
|
-
export function toolLine(row) {
|
|
39
|
-
return row?.path ? `${row.tool} ${row.path}` : String(row?.tool || "tool");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// The conversation with each run of text-less tool steps (a reply that
|
|
43
|
-
// only called tools) folded into the next reply's rows, or one row group
|
|
44
|
-
// when no reply follows: one "3 tools: …" line instead of three.
|
|
45
|
-
// A folded run with no reply after it keeps its last step's time (at).
|
|
46
|
-
export function withToolSteps(messages) {
|
|
47
|
-
const out = [];
|
|
48
|
-
let pending = [];
|
|
49
|
-
let pendingAt = null;
|
|
50
|
-
const flush = () => out.push({ role: "assistant", content: "", tools: pending, ...(pendingAt ? { at: pendingAt } : {}) });
|
|
51
|
-
for (const message of messages) {
|
|
52
|
-
const toolOnly = message.role === "assistant" && !String(message.content || "").trim() && message.tools?.length;
|
|
53
|
-
if (toolOnly) {
|
|
54
|
-
pending = pending.concat(message.tools);
|
|
55
|
-
pendingAt = message.at || pendingAt;
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (pending.length) {
|
|
59
|
-
if (message.role === "assistant") {
|
|
60
|
-
out.push({ ...message, tools: pending.concat(message.tools || []) });
|
|
61
|
-
pending = [];
|
|
62
|
-
pendingAt = null;
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
flush();
|
|
66
|
-
pending = [];
|
|
67
|
-
pendingAt = null;
|
|
68
|
-
}
|
|
69
|
-
out.push(message);
|
|
70
|
-
}
|
|
71
|
-
if (pending.length) flush();
|
|
72
|
-
return out;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// The thread's gap dividers (format.js gapText, the owner's page's words):
|
|
76
|
-
// before each message, and before the turn in progress (+currentAt+, its
|
|
77
|
-
// turn_started's at), the divider's text or null. A gap is marked only
|
|
78
|
-
// where a person's message or a turn starts, measured from the last
|
|
79
|
-
// message's time before it: never inside a turn's work.
|
|
80
|
-
export function threadGaps(messages, { currentAt = null, now = Date.now() } = {}) {
|
|
81
|
-
let last = null;
|
|
82
|
-
const before = (messages || []).map((message) => {
|
|
83
|
-
const text = message?.role === "user" && last && message.at ? gapText(last, message.at, now) : null;
|
|
84
|
-
if (message?.at) last = message.at;
|
|
85
|
-
return text;
|
|
86
|
-
});
|
|
87
|
-
return { before, current: last && currentAt ? gapText(last, currentAt, now) : null };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// The server's words (ParticipantMessages, a relay's detail) as the page
|
|
91
|
-
// shows them: a sentence, never reworded; null with none.
|
|
92
|
-
export function sentence(detail) {
|
|
93
|
-
const text = typeof detail === "string" ? detail.trim() : "";
|
|
94
|
-
if (!text) return null;
|
|
95
|
-
return `${text[0].toUpperCase()}${text.slice(1)}${/[.!?…]$/.test(text) ? "" : "."}`;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// A comment refused (POST …/turn), in words: the server's detail, else
|
|
99
|
-
// the status.
|
|
100
|
-
export function refusalText(status, body) {
|
|
101
|
-
const said = sentence(body?.detail);
|
|
102
|
-
if (said) return said;
|
|
103
|
-
if (status === 0) return "Not sent: can't reach the session. Send it again.";
|
|
104
|
-
return `Not sent (HTTP ${status}).`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// A queued comment not taken back (POST …/dequeue): the server's detail,
|
|
108
|
-
// else a turn that already started (the Bridge's 409, no detail), else the
|
|
109
|
-
// status.
|
|
110
|
-
export function dequeueText(status, body) {
|
|
111
|
-
const said = sentence(body?.detail);
|
|
112
|
-
if (said) return said;
|
|
113
|
-
if (body?.error === "already_started") return "Not taken back: it already started.";
|
|
114
|
-
if (status === 0) return "Not taken back: can't reach the session.";
|
|
115
|
-
return `Not taken back (HTTP ${status}).`;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// A 401 from chi web: the link ended, revoked or expired, in the server's
|
|
119
|
-
// words; with none (no session in the link), where to get a new one.
|
|
120
|
-
export function endedText(body) {
|
|
121
|
-
return sentence(body?.detail) || "Ask the session's owner for a new link.";
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Whether a review read that failed is read again: chi web unreachable
|
|
125
|
-
// (status 0) or a 5xx (a worker starting, a proxy); a 404 (gone) or
|
|
126
|
-
// another 4xx is final, a 401 the ended page.
|
|
127
|
-
export function retries(status) {
|
|
128
|
-
return status === 0 || status >= 500;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// The wait before the next read of the review after +failures+ failed in
|
|
132
|
-
// a row: 3 s, doubling, at most 30 s.
|
|
133
|
-
export function retryDelay(failures) {
|
|
134
|
-
return Math.min(3000 * 2 ** Math.max(0, failures), 30000);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// The seq of a stream cursor `<seq>-<epoch>` (or a plain seq); null for none.
|
|
138
|
-
export function cursorSeq(eventId) {
|
|
139
|
-
const m = /^(\d+)/.exec(String(eventId || ""));
|
|
140
|
-
return m ? Number(m[1]) : null;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// The filtered stream's URL: from the review data's cursor, `<seq>-<epoch>`
|
|
144
|
-
// as the owner's page sends it (another worker answers it with a reset,
|
|
145
|
-
// which the page re-reads at), or (read with no worker) joining with a
|
|
146
|
-
// snapshot, which arrives as a bare marker the page re-reads at, never as
|
|
147
|
-
// a replay of old turns. The owner's participant view asks for the
|
|
148
|
-
// participant filter (?as=participant).
|
|
149
|
-
export function streamURL(sessionId, eventId, { owner = false } = {}) {
|
|
150
|
-
const params = new URLSearchParams();
|
|
151
|
-
if (cursorSeq(eventId) !== null) params.set("from_seq", String(eventId));
|
|
152
|
-
else params.set("snapshot", "1");
|
|
153
|
-
if (owner) params.set("as", "participant");
|
|
154
|
-
const query = params.toString();
|
|
155
|
-
return `/api/sessions/${encodeURIComponent(sessionId)}/stream${query ? `?${query}` : ""}`;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// The events after which the page reads its review data again: a turn's
|
|
159
|
-
// start or end, the queue, the owner's question, a snapshot or reset.
|
|
160
|
-
const RELOAD = new Set(["turn_started", "turn_completed", "turn_canceled", "turn_failed", "turn_enqueued", "turn_dequeued",
|
|
161
|
-
"input_merged", "question_requested", "question_answered", "question_cancelled", "continue_offered",
|
|
162
|
-
"continue_resolved", "snapshot", "reset"]);
|
|
163
|
-
export function reloads(type) {
|
|
164
|
-
return RELOAD.has(type);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// The events after which the live turn drawn is no longer the running one
|
|
168
|
-
// (it ended, another started, the stream started over): the page draws no
|
|
169
|
-
// live event until its re-read, whose stream replays the ones after it.
|
|
170
|
-
const TURN_BOUNDARY = new Set(["turn_started", "turn_completed", "turn_canceled", "turn_failed", "snapshot", "reset"]);
|
|
171
|
-
export function endsLiveTurn(type) {
|
|
172
|
-
return TURN_BOUNDARY.has(type);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// The live turn between reloads: its text by step (a restarted step's
|
|
176
|
-
// text is void) and its tool rows. Returns the new live state.
|
|
177
|
-
export function liveFrom(current) {
|
|
178
|
-
return {
|
|
179
|
-
texts: current?.text ? { 0: current.text } : {},
|
|
180
|
-
tools: Array.isArray(current?.tools) ? current.tools.map((row) => ({ ...row })) : [],
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function applyLive(live, event) {
|
|
185
|
-
const next = { texts: { ...live.texts }, tools: live.tools.slice() };
|
|
186
|
-
const step = Number.isInteger(event?.iteration) ? event.iteration : 0;
|
|
187
|
-
switch (event?.type) {
|
|
188
|
-
case "generation_chunk":
|
|
189
|
-
next.texts[step] = (next.texts[step] || "") + String(event.text || "");
|
|
190
|
-
break;
|
|
191
|
-
case "generation_retrying":
|
|
192
|
-
if (event.restarted) delete next.texts[step];
|
|
193
|
-
break;
|
|
194
|
-
case "tool_call_started":
|
|
195
|
-
next.tools.push({ tool: event.tool, ...(event.path ? { path: event.path } : {}), status: "running",
|
|
196
|
-
iteration: event.iteration, call_index: event.call_index });
|
|
197
|
-
break;
|
|
198
|
-
case "tool_call_completed": {
|
|
199
|
-
const at = next.tools.findLastIndex((row) => row.iteration === event.iteration && row.call_index === event.call_index);
|
|
200
|
-
if (at >= 0) next.tools[at] = { ...next.tools[at], status: event.status || "ok" };
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
default:
|
|
204
|
-
return live;
|
|
205
|
-
}
|
|
206
|
-
return next;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// The live turn's reply text so far, its steps in order.
|
|
210
|
-
export function liveText(live) {
|
|
211
|
-
return Object.keys(live.texts).map(Number).sort((a, b) => a - b).map((k) => live.texts[k]).join("");
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// The Plan view's subject: the one picked by path when it is still there,
|
|
215
|
-
// else the first; null with no subjects (not a review session).
|
|
216
|
-
export function pickSubject(subjects, path) {
|
|
217
|
-
const list = Array.isArray(subjects) ? subjects : [];
|
|
218
|
-
return list.find((s) => s.path === path) || list[0] || null;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// What the Plan view shows for a subject: rendered markdown, plain text,
|
|
222
|
-
// or why it can't (gone, or no longer a project file a participant may
|
|
223
|
-
// read); +note+ when the text is cut.
|
|
224
|
-
export function subjectBody(subject) {
|
|
225
|
-
if (!subject) return { kind: "none" };
|
|
226
|
-
if (subject.missing) return { kind: "missing", text: `${subject.path} can't be shown: it is gone, or no longer a project file you may read.` };
|
|
227
|
-
const note = subject.truncated ? "Only the start of this file is shown: it is long." : null;
|
|
228
|
-
return subject.html ? { kind: "html", html: subject.html, note } : { kind: "text", text: subject.text || "", note };
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Whether the subjects differ from what the Plan view drew (a re-read at
|
|
232
|
-
// a turn boundary redraws it only then, keeping its scroll).
|
|
233
|
-
export function subjectsKey(subjects) {
|
|
234
|
-
return JSON.stringify((subjects || []).map((s) => [s.path, s.missing ? null : s.text, !!s.truncated]));
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Which view a narrow screen shows: "thread" by default, "plan" only when
|
|
238
|
-
// there is a subject to show.
|
|
239
|
-
export function narrowView(wanted, subjects) {
|
|
240
|
-
return wanted === "plan" && (subjects || []).length ? "plan" : "thread";
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// A participant's usage row (the review data's viewer.usage: the fields
|
|
244
|
-
// their grant's exposure shows, ParticipantExposure): one short item per
|
|
245
|
-
// field it has, each {key, text, title, level}; level "" / "warn" (most of
|
|
246
|
-
// the cap spent, the queue full) / "over" (the cap reached). Only the
|
|
247
|
-
// participant's own figures ever arrive; a field the level doesn't show is
|
|
248
|
-
// absent and draws nothing. [] with no usage (the owner's view).
|
|
249
|
-
export const USAGE_WARN = 0.8;
|
|
250
|
-
const MINUTE_MS = 60 * 1000;
|
|
251
|
-
const HOUR_MS = 60 * MINUTE_MS;
|
|
252
|
-
const DAY_MS = 24 * HOUR_MS;
|
|
253
|
-
const dollars = (n) => `$${(Number(n) || 0).toFixed(2)}`;
|
|
254
|
-
const isNum = (n) => typeof n === "number" && Number.isFinite(n);
|
|
255
|
-
|
|
256
|
-
// "6 d left", "5 h left", "12 min left", "ended"; "" for no or bad input.
|
|
257
|
-
export function leftText(iso, now = Date.now()) {
|
|
258
|
-
const at = Date.parse(iso || "");
|
|
259
|
-
if (!Number.isFinite(at)) return "";
|
|
260
|
-
const left = at - now;
|
|
261
|
-
if (left <= 0) return "ended";
|
|
262
|
-
if (left >= 2 * DAY_MS) return `${Math.round(left / DAY_MS)} d left`;
|
|
263
|
-
if (left >= 2 * HOUR_MS) return `${Math.floor(left / HOUR_MS)} h left`;
|
|
264
|
-
return `${Math.max(1, Math.floor(left / MINUTE_MS))} min left`;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// What the page says a participant's turn does, by the session's mode
|
|
268
|
-
// (viewer.mode: ParticipantMode.live on the server): a review turn only
|
|
269
|
-
// reads; a pair turn (a working session's) acts with the session's tools
|
|
270
|
-
// under the owner's guardrails. +tag+ is a message's: its own stamp
|
|
271
|
-
// (participant_mode), a message without one a review's.
|
|
272
|
-
export const MODE_COPY = {
|
|
273
|
-
review: {
|
|
274
|
-
note: "You can comment and ask; the model answers in a turn that can only read. The owner sees everything.",
|
|
275
|
-
hint: "The model answers in a read-only turn; the owner sees everything.",
|
|
276
|
-
tag: "review",
|
|
277
|
-
},
|
|
278
|
-
pair: {
|
|
279
|
-
note: "You can ask the model to work in this session: your turns use its tools, writes included, under the owner's "
|
|
280
|
-
+ "guardrails, and what needs approval goes to the owner. The owner sees everything.",
|
|
281
|
-
hint: "The model works in this session; the owner approves what needs it and sees everything.",
|
|
282
|
-
tag: "pair",
|
|
283
|
-
},
|
|
284
|
-
};
|
|
285
|
-
export const modeCopy = (mode) => MODE_COPY[mode] || MODE_COPY.review;
|
|
286
|
-
|
|
287
|
-
export function usageItems(usage, now = Date.now()) {
|
|
288
|
-
if (!usage || typeof usage !== "object") return [];
|
|
289
|
-
const items = [];
|
|
290
|
-
if (isNum(usage.spent)) {
|
|
291
|
-
const cap = isNum(usage.cap) ? usage.cap : null;
|
|
292
|
-
const share = cap ? usage.spent / cap : 0;
|
|
293
|
-
const level = cap === null ? "" : usage.spent >= cap ? "over" : share >= USAGE_WARN ? "warn" : "";
|
|
294
|
-
items.push({ key: "spent", text: cap === null ? `${dollars(usage.spent)} spent` : `${dollars(usage.spent)} of ${dollars(cap)} cap`,
|
|
295
|
-
title: cap === null ? "What your comments have cost the owner so far"
|
|
296
|
-
: `What your comments have cost the owner so far, of the ${dollars(cap)} cap they set`, level });
|
|
297
|
-
}
|
|
298
|
-
if (isNum(usage.queued) && isNum(usage.queue_limit)) {
|
|
299
|
-
items.push({ key: "queued", text: `${usage.queued}/${usage.queue_limit} queued`,
|
|
300
|
-
title: `Your comments waiting for their turn: up to ${usage.queue_limit} can wait behind a running one`,
|
|
301
|
-
level: usage.queued >= usage.queue_limit ? "warn" : "" });
|
|
302
|
-
}
|
|
303
|
-
const left = leftText(usage.expires_at, now);
|
|
304
|
-
if (left) {
|
|
305
|
-
const day = Date.parse(usage.expires_at) - now < DAY_MS;
|
|
306
|
-
items.push({ key: "expires_at", text: left === "ended" ? "link ended" : `link: ${left}`,
|
|
307
|
-
title: `Your link ends ${fullTime(usage.expires_at)}`, level: day ? "warn" : "" });
|
|
308
|
-
}
|
|
309
|
-
if (typeof usage.model === "string" && usage.model) {
|
|
310
|
-
items.push({ key: "model", text: usage.model, title: "The model answering in this session", level: "" });
|
|
311
|
-
}
|
|
312
|
-
return items;
|
|
313
|
-
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// badge drawn before the list came, with neither, says UNNAMED until
|
|
6
6
|
// nameUnnamedBadges names it.
|
|
7
7
|
import { authorColor, isParticipantAuthor, participantAuthor } from "./participant_model.js";
|
|
8
|
+
import { viewerSelf } from "./viewer_self.js";
|
|
8
9
|
|
|
9
10
|
export const UNNAMED = "a participant";
|
|
10
11
|
|
|
@@ -34,14 +35,22 @@ export function authorBadge(author, name = null, mode = null) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
// A badge's text and tooltip (turn_html.js userBubbleTemplate), by the
|
|
37
|
-
// turn's mode: a
|
|
38
|
-
//
|
|
39
|
-
//
|
|
38
|
+
// turn's mode: a participant's turn acts with the session's tools (pair,
|
|
39
|
+
// and a live prompt whose mode isn't known yet: a queued one, until
|
|
40
|
+
// setBadgeMode); a saved turn stamped "review", or saved with no stamp (an
|
|
41
|
+
// older chi's, as Steer reads it), could only read: the history render
|
|
42
|
+
// passes READ_ONLY for an unstamped one (turn_block.js). PAIR is the stamp
|
|
43
|
+
// ParticipantTurnMode::PAIR_MODE writes; the page only reads it.
|
|
40
44
|
export const PAIR = "pair";
|
|
41
|
-
export const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
export const READ_ONLY = "review";
|
|
46
|
+
// A participant looking (viewer_self.js) reads their turn by its name alone.
|
|
47
|
+
export const authorBadgeText = (name, mode = null) => {
|
|
48
|
+
if (mode === READ_ONLY) return `${name} · read-only`;
|
|
49
|
+
return viewerSelf() ? name : `${name} · pair`;
|
|
50
|
+
};
|
|
51
|
+
export const authorBadgeTitle = (name, mode = null) => (mode === READ_ONLY
|
|
52
|
+
? `A turn from ${name}, a participant, under an older chi: it could only read`
|
|
53
|
+
: `A turn from ${name}, a participant: it acted with this session's tools, its asks came to you`);
|
|
45
54
|
|
|
46
55
|
// The badge on +bubble+ (a prompt drawn before its turn started) takes the
|
|
47
56
|
// turn's +mode+ once turn_started names it.
|
|
@@ -50,7 +59,7 @@ export function setBadgeMode(bubble, mode) {
|
|
|
50
59
|
if (!badge || !mode) return;
|
|
51
60
|
bubble.dataset.participantMode = mode;
|
|
52
61
|
if (badge.dataset.unnamed) return;
|
|
53
|
-
const name = participantName(bubble.dataset.author) || badge.textContent.replace(/ · (
|
|
62
|
+
const name = participantName(bubble.dataset.author) || badge.textContent.replace(/ · (read-only|pair)$/, "");
|
|
54
63
|
badge.textContent = authorBadgeText(name, mode);
|
|
55
64
|
badge.title = authorBadgeTitle(name, mode);
|
|
56
65
|
}
|