samagotchi 0.183.0 → 0.184.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 +40 -1
- data/docs/architecture.md +11 -10
- data/docs/bundles.md +1 -1
- data/docs/configuration.md +2 -1
- data/docs/internals/bridge.md +1 -1
- data/docs/internals/bundles.md +6 -2
- data/docs/internals/engine.md +2 -1
- data/docs/internals/participants.md +1 -1
- data/docs/internals/prompt-caching.md +8 -1
- data/docs/internals/remote-sessions.md +19 -3
- data/docs/internals/web-frontend.md +15 -10
- data/docs/internals/web-push.md +11 -0
- data/docs/internals/working-set.md +238 -6
- data/docs/mcp-server.md +5 -1
- data/docs/memory.md +2 -1
- data/docs/plugins.md +6 -6
- data/docs/scheduling.md +14 -0
- data/docs/sessions.md +1 -1
- data/docs/thin-clients.md +29 -10
- data/lib/samagotchi/bridge_client.rb +12 -4
- data/lib/samagotchi/bundle_command/check.rb +20 -2
- data/lib/samagotchi/bundle_manifest.rb +5 -1
- data/lib/samagotchi/bundles/mcp/http_client.rb +79 -54
- data/lib/samagotchi/bundles/mcp/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/self_map.md +7 -2
- data/lib/samagotchi/engine/session.rb +14 -6
- data/lib/samagotchi/engine/turn_helpers.rb +4 -3
- data/lib/samagotchi/mcp_server/http.rb +3 -3
- data/lib/samagotchi/mcp_server/protocol.rb +23 -4
- data/lib/samagotchi/mcp_server/stdio.rb +1 -0
- data/lib/samagotchi/mcp_server/tools.rb +2 -1
- data/lib/samagotchi/model_notes.rb +34 -12
- data/lib/samagotchi/prompt_files.rb +11 -4
- data/lib/samagotchi/prompt_layout.rb +88 -0
- data/lib/samagotchi/prompt_part.rb +82 -20
- data/lib/samagotchi/reply_wait.rb +6 -3
- data/lib/samagotchi/schedule_command.rb +18 -4
- data/lib/samagotchi/schedules.rb +40 -8
- data/lib/samagotchi/session_access/ask.rb +53 -12
- data/lib/samagotchi/session_access/exchange.rb +5 -2
- data/lib/samagotchi/session_access/local.rb +11 -2
- data/lib/samagotchi/session_inbox.rb +15 -0
- data/lib/samagotchi/session_manager/delivery.rb +8 -4
- data/lib/samagotchi/system_prompt.rb +196 -161
- data/lib/samagotchi/tools/memory.rb +11 -3
- data/lib/samagotchi/turn_stages/warmup.rb +2 -2
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +1 -2
- data/lib/samagotchi/web/ask_routes.rb +89 -19
- data/lib/samagotchi/web/mcp_route.rb +7 -4
- data/lib/samagotchi/web/public/delete_sheet.js +20 -18
- data/lib/samagotchi/web/public/removal_sheet_model.js +3 -4
- data/lib/samagotchi/web/public/running_tasks.js +0 -16
- data/lib/samagotchi/web/public/session_actions.js +0 -9
- data/lib/samagotchi/web/public/working_set_view.js +167 -21
- data/lib/samagotchi/web/public/ws_part_peek.js +277 -0
- data/lib/samagotchi/web/public/ws_peek.js +3 -1
- data/lib/samagotchi/web/public/ws_preview.css +30 -0
- data/lib/samagotchi/web/public/ws_reader.js +7 -3
- data/lib/samagotchi/web/public/ws_sections.js +37 -7
- data/lib/samagotchi/web/push/notifier.rb +33 -6
- data/lib/samagotchi/web/server.rb +1 -1
- data/lib/samagotchi/web/session_hub.rb +26 -4
- data/lib/samagotchi/web/working_set_routes.rb +93 -5
- data/lib/samagotchi/worker_link.rb +2 -2
- data/lib/samagotchi/working_set.rb +162 -90
- data/lib/samagotchi/working_set_locator.rb +221 -0
- data/lib/samagotchi/working_set_own_changes.rb +221 -0
- data/lib/samagotchi/working_set_part.rb +281 -0
- metadata +6 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "delegate"
|
|
4
|
+
require_relative "../bridge_client"
|
|
4
5
|
require_relative "../client_id"
|
|
5
6
|
require_relative "../reply_wait"
|
|
6
7
|
require_relative "../session"
|
|
@@ -25,9 +26,18 @@ module Samagotchi
|
|
|
25
26
|
# One ask answers within this many seconds from its request's start,
|
|
26
27
|
# whatever it waits for (a continue in flight, the Bridge of a worker
|
|
27
28
|
# starting, the wait's slice): a proxy or a Shortcut with a 60 s limit
|
|
28
|
-
# is safe.
|
|
29
|
-
#
|
|
29
|
+
# is safe. The post to a live worker draws on it too (#ask_bridge), but
|
|
30
|
+
# never under POST_FLOOR, so a call ends within about 44 s.
|
|
30
31
|
ASK_MAX_SECONDS = 35.0
|
|
32
|
+
# The shortest read a post to a live worker gets (#ask_bridge),
|
|
33
|
+
# however little of the deadline is left: a healthy but loaded worker
|
|
34
|
+
# still reads the message in time.
|
|
35
|
+
POST_FLOOR = 8.0
|
|
36
|
+
# The fewest seconds the post's body deadline leaves before its read
|
|
37
|
+
# times out (BridgeClient's deadline_margin): a worker that took the
|
|
38
|
+
# turn just in time still has that long to answer 202, so a 504 means
|
|
39
|
+
# it was not taken.
|
|
40
|
+
POST_MARGIN = 2.5
|
|
31
41
|
# A wait route answers within this many seconds (status timeout); the
|
|
32
42
|
# client asks again until its own --timeout. SessionAccessRoutes'
|
|
33
43
|
# (which includes this module) too.
|
|
@@ -35,6 +45,14 @@ module Samagotchi
|
|
|
35
45
|
# GET /api/info's feature: this chi web has the ask route, wait
|
|
36
46
|
# tokens, the answer's wait and the create's token.
|
|
37
47
|
ASK_FEATURE = "ask"
|
|
48
|
+
# A line a worker may run as a session command (#ask_request_id): a
|
|
49
|
+
# / name (Registry::UNKNOWN_COMMAND_WORD's shape, which every
|
|
50
|
+
# built-in a worker runs and a bundle's COMMAND_NAME fits) followed by
|
|
51
|
+
# whitespace or nothing, so "/Users/x/a.rb fails" is a message. A !
|
|
52
|
+
# line is the shell's.
|
|
53
|
+
COMMAND_SHAPE = %r{\A/[A-Za-z][A-Za-z0-9_-]*(?:\s|\z)}
|
|
54
|
+
# An ask's request_id: 1 to 128 printable ASCII characters.
|
|
55
|
+
REQUEST_ID = /\A[\x21-\x7e]{1,128}\z/
|
|
38
56
|
# The wait body's own fields, which a token replaces.
|
|
39
57
|
TOKEN_EXCLUDES = %w[cursor baseline turn queued ended_before owner_grace].freeze
|
|
40
58
|
|
|
@@ -62,15 +80,20 @@ module Samagotchi
|
|
|
62
80
|
|
|
63
81
|
private
|
|
64
82
|
|
|
65
|
-
# POST /api/sessions/:id/ask {prompt, timeout, queue, client_id
|
|
66
|
-
# message delivered (to a chain's newest link; a
|
|
67
|
-
# queues it as its own turn unless queue is false) and
|
|
68
|
-
# waited for, all within ASK_MAX_SECONDS.
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
73
|
-
# the
|
|
83
|
+
# POST /api/sessions/:id/ask {prompt, timeout, queue, client_id,
|
|
84
|
+
# request_id}: the message delivered (to a chain's newest link; a
|
|
85
|
+
# running session queues it as its own turn unless queue is false) and
|
|
86
|
+
# its answer waited for, all within ASK_MAX_SECONDS. A request_id (a
|
|
87
|
+
# message's, not a command's) names its turn: a retry whose turn the
|
|
88
|
+
# session knows waits on it again, nothing sent and no second history
|
|
89
|
+
# line (SessionAccess::Ask#call). 200 wait_result_json's fields +
|
|
90
|
+
# session_id (+ asked, the id given, when another link ran it; +
|
|
91
|
+
# token when the status is timeout: POST …/wait {token} goes on; +
|
|
92
|
+
# request_id when one was given); 200 {status: command} for a session
|
|
93
|
+
# command. 404 not_found, 400 ambiguous_id / invalid_ask, 409 busy /
|
|
94
|
+
# waiting / continuing / owned_by_tui / enqueued_id_conflict (the
|
|
95
|
+
# same request_id, another prompt), the turn route's delivery
|
|
96
|
+
# refusals, 503 server_stopping.
|
|
74
97
|
def handle_ask(req, id)
|
|
75
98
|
# One deadline from the request's start: the gate, the continue
|
|
76
99
|
# waits, the Bridge wait and the slice all draw on it.
|
|
@@ -82,7 +105,7 @@ module Samagotchi
|
|
|
82
105
|
gated = ask_gate(id, prompt, client_id)
|
|
83
106
|
return gated if gated
|
|
84
107
|
|
|
85
|
-
bridge = ->(sid) {
|
|
108
|
+
bridge = ->(sid) { ask_bridge(sid, deadline) }
|
|
86
109
|
access = AskAccess.new(session_access, manager: @manager, bridge: bridge, poll_interval: @wait_poll_interval)
|
|
87
110
|
stopping = -> { !@server_running.call }
|
|
88
111
|
exchange = SessionAccess::Exchange.new(access, continuing_wait: [SessionAccess::Exchange::CONTINUING_WAIT,
|
|
@@ -90,14 +113,15 @@ module Samagotchi
|
|
|
90
113
|
outcome = SessionAccess::Ask.new(access, exchange: exchange)
|
|
91
114
|
.call(id, prompt: prompt, client_id: client_id, cap: deadline - ask_clock,
|
|
92
115
|
cancelled: stopping, **options)
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
rebound = outcome.is_a?(SessionAccess::Ask::Reply) && outcome.rebound
|
|
117
|
+
record_history(body, prompt) unless outcome.is_a?(SessionAccess::Ask::Refused) || rebound
|
|
118
|
+
ask_response(id, outcome, request_id: options[:request_id])
|
|
95
119
|
rescue SessionManager::OwnedByTUI => e
|
|
96
120
|
owned_by_tui(e)
|
|
97
121
|
end
|
|
98
122
|
|
|
99
|
-
# The ask's body read: [prompt, client_id, {queue:, timeout
|
|
100
|
-
# [.., a 400 response].
|
|
123
|
+
# The ask's body read: [prompt, client_id, {queue:, timeout:,
|
|
124
|
+
# request_id:}, nil] or [.., a 400 response].
|
|
101
125
|
def ask_request(id, body)
|
|
102
126
|
return [nil, nil, nil, error_response(400, "missing_fields", "prompt is required")] unless body["prompt"].is_a?(String)
|
|
103
127
|
|
|
@@ -118,11 +142,36 @@ module Samagotchi
|
|
|
118
142
|
client_id = body["client_id"]
|
|
119
143
|
return [nil, nil, nil, error_response(400, "invalid_ask", "client_id is a string")] unless client_id.nil? || client_id.is_a?(String)
|
|
120
144
|
|
|
121
|
-
|
|
145
|
+
request_id, error = ask_request_id(body, prompt)
|
|
146
|
+
return [nil, nil, nil, error] if error
|
|
147
|
+
|
|
148
|
+
options = { queue: queue, timeout: [timeout, WAIT_MAX_SECONDS].min }
|
|
149
|
+
options[:request_id] = request_id if request_id
|
|
150
|
+
[prompt, ask_sender(client_id, prompt), options, nil]
|
|
122
151
|
rescue SessionInbox::NoteRejected => e
|
|
123
152
|
[nil, nil, nil, error_response(400, "invalid_prompt", e.message)]
|
|
124
153
|
end
|
|
125
154
|
|
|
155
|
+
# The body's request_id: [nil or it, nil] or [nil, a 400]. A session
|
|
156
|
+
# command never runs as a turn of that id (the Bridge's command path
|
|
157
|
+
# takes none), so a retry would run it again: refused. Any line the
|
|
158
|
+
# worker may run as one, by its shape (COMMAND_SHAPE): chi web can't
|
|
159
|
+
# see a bundle's commands, which only the worker's registry has.
|
|
160
|
+
def ask_request_id(body, prompt)
|
|
161
|
+
request_id = body["request_id"]
|
|
162
|
+
return [nil, nil] if request_id.nil?
|
|
163
|
+
unless request_id.is_a?(String) && REQUEST_ID.match?(request_id)
|
|
164
|
+
return [nil, error_response(400, "invalid_ask", "request_id is 1 to 128 printable ASCII characters")]
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
line = prompt.strip
|
|
168
|
+
if line.start_with?("!") || COMMAND_SHAPE.match?(line)
|
|
169
|
+
return [nil, error_response(400, "invalid_ask", "request_id is for messages, not session commands")]
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
[request_id, nil]
|
|
173
|
+
end
|
|
174
|
+
|
|
126
175
|
# Who asks: the owner (WEB_UNNAMED) unless the body names a sender
|
|
127
176
|
# (owner_sender's rule); a parent agent's /continue yes sent as
|
|
128
177
|
# cli:send goes in as cli:answer, as chi send sends it (the worker
|
|
@@ -151,8 +200,9 @@ module Samagotchi
|
|
|
151
200
|
nil
|
|
152
201
|
end
|
|
153
202
|
|
|
154
|
-
# The ask's answer for an Ask value
|
|
155
|
-
|
|
203
|
+
# The ask's answer for an Ask value (+request_id+ echoed when given:
|
|
204
|
+
# the client sees this chi web used it).
|
|
205
|
+
def ask_response(id, outcome, request_id: nil)
|
|
156
206
|
case outcome
|
|
157
207
|
when SessionAccess::Ask::Ran then json_response(200, { status: "command", session_id: outcome.session_id })
|
|
158
208
|
when SessionAccess::Ask::Refused then ask_refused(id, outcome)
|
|
@@ -163,6 +213,7 @@ module Samagotchi
|
|
|
163
213
|
json = wait_result_json(result, session_access.parent_strategy(outcome.session_id)).merge(session_id: outcome.session_id)
|
|
164
214
|
json[:asked] = outcome.asked if outcome.asked && outcome.asked != outcome.session_id
|
|
165
215
|
json[:token] = outcome.token if outcome.token
|
|
216
|
+
json[:request_id] = request_id if request_id
|
|
166
217
|
json_response(200, json)
|
|
167
218
|
end
|
|
168
219
|
end
|
|
@@ -283,6 +334,25 @@ module Samagotchi
|
|
|
283
334
|
|
|
284
335
|
def plain_exchange = SessionAccess::Exchange.new(session_access)
|
|
285
336
|
|
|
337
|
+
# The worker's Bridge client for an ask's delivery (App's
|
|
338
|
+
# live_bridge_client, drawn from +deadline+): a worker starting is
|
|
339
|
+
# waited for out of what is left, and the post's read is what is left
|
|
340
|
+
# after that but MIN_SLICE, within POST_FLOOR..READ_TIMEOUT. The
|
|
341
|
+
# client's body deadline is a share of that read (DEADLINE_SHARE, at
|
|
342
|
+
# least POST_MARGIN short of it), so
|
|
343
|
+
# a worker that reads the message late drops it (408
|
|
344
|
+
# deadline_passed) rather than run it after the call gave up.
|
|
345
|
+
# @param deadline [Numeric] ask_clock's seconds the call ends by
|
|
346
|
+
# @return [BridgeClient, nil] nil: no live worker in time
|
|
347
|
+
def ask_bridge(sid, deadline)
|
|
348
|
+
link = worker_link(sid)
|
|
349
|
+
link = await_worker_link(sid, timeout: [@bridge_wait_timeout.to_f, deadline - ask_clock].min.clamp(0.0..)) unless link.live?
|
|
350
|
+
return nil unless link.live?
|
|
351
|
+
|
|
352
|
+
read = (deadline - ask_clock - SessionAccess::Ask::MIN_SLICE).clamp(POST_FLOOR, BridgeClient::READ_TIMEOUT)
|
|
353
|
+
link.client(sid, host: App::DEFAULT_HOST, read_timeout: read, deadline_margin: POST_MARGIN)
|
|
354
|
+
end
|
|
355
|
+
|
|
286
356
|
# The ask's deadline clock (the Exchange's: monotonic seconds).
|
|
287
357
|
def ask_clock = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
288
358
|
|
|
@@ -20,7 +20,7 @@ module Samagotchi
|
|
|
20
20
|
# Bearer, so a host says it needs a token rather than look for OAuth.
|
|
21
21
|
# GET 405 (no stream), DELETE 200 (a legacy host closing its session).
|
|
22
22
|
# Included in App through SessionAccessRoutes; its helpers
|
|
23
|
-
# (request_body, session_access,
|
|
23
|
+
# (request_body, session_access, ask_bridge, ask_clock, error_response)
|
|
24
24
|
# and ivars (@manager, @hub, @wait_poll_interval, @server_running)
|
|
25
25
|
# answer. See docs/mcp-server.md.
|
|
26
26
|
module McpRoute
|
|
@@ -55,8 +55,11 @@ module Samagotchi
|
|
|
55
55
|
private
|
|
56
56
|
|
|
57
57
|
def handle_mcp(req)
|
|
58
|
+
# One deadline per POST (one call), as the ask's: the post to a
|
|
59
|
+
# live worker draws on it (AskRoutes#ask_bridge).
|
|
60
|
+
deadline = ask_clock + McpServer::Tools::CAP
|
|
58
61
|
body = request_body(req, BODY_LIMIT, what: "an MCP request")
|
|
59
|
-
McpServer::Http.new(mcp_protocol).call(req.env, body)
|
|
62
|
+
McpServer::Http.new(mcp_protocol(deadline)).call(req.env, body)
|
|
60
63
|
end
|
|
61
64
|
|
|
62
65
|
def handle_mcp_get(_req)
|
|
@@ -67,8 +70,8 @@ module Samagotchi
|
|
|
67
70
|
# Nothing is kept for a legacy session id: nothing to end.
|
|
68
71
|
def handle_mcp_delete(_req) = [200, { "Content-Length" => "0" }, []]
|
|
69
72
|
|
|
70
|
-
def mcp_protocol
|
|
71
|
-
bridge = ->(sid) {
|
|
73
|
+
def mcp_protocol(deadline)
|
|
74
|
+
bridge = ->(sid) { ask_bridge(sid, deadline) }
|
|
72
75
|
access = McpAccess.new(session_access, hub: @hub, manager: @manager, bridge: bridge, poll_interval: @wait_poll_interval)
|
|
73
76
|
stopping = -> { !@server_running.call }
|
|
74
77
|
exchange = ->(backend) { SessionAccess::Exchange.new(backend, cancelled: stopping) }
|
|
@@ -24,17 +24,9 @@
|
|
|
24
24
|
|
|
25
25
|
import { html, nothing, render } from "./vendor/lit-html.js";
|
|
26
26
|
import { createChipPopover, SHEET_TALL } from "./chip_popover.js";
|
|
27
|
-
import { archiveSheetModel, buttonWords, cantModel, choiceTail,
|
|
27
|
+
import { archiveSheetModel, buttonWords, cantModel, choiceTail, sessionSheetModel, sheetTitle,
|
|
28
28
|
stopTasksOptions, stopsFirst } from "./removal_sheet_model.js";
|
|
29
29
|
|
|
30
|
-
// The toast after a delete, for an older cached session_actions.js (0.182.0),
|
|
31
|
-
// which adds the stopped tasks to it itself: without them, so they aren't
|
|
32
|
-
// said twice. This session_actions.js imports removal_sheet_model.js'. Kept
|
|
33
|
-
// until the next release (web-frontend.md, removing an export).
|
|
34
|
-
export function deleteToast(which, result, plan, id) {
|
|
35
|
-
return modelToast(which, result, plan, id, { withTasks: false });
|
|
36
|
-
}
|
|
37
|
-
|
|
38
30
|
const short = (id) => String(id ?? "").slice(0, 8);
|
|
39
31
|
const count = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
40
32
|
|
|
@@ -218,13 +210,13 @@ export function refusalModel(refusal, previousId = null) {
|
|
|
218
210
|
return { title: "Not deleted", text: refusal?.message || "The delete was refused.", stop: null };
|
|
219
211
|
}
|
|
220
212
|
|
|
221
|
-
export function refusalTemplate(model, { back = false } = {}) {
|
|
213
|
+
export function refusalTemplate(model, { back = false, busy = false } = {}) {
|
|
222
214
|
return html`<div class="delete-sheet">${headTemplate(back)}
|
|
223
215
|
<div class="ds-title">${model.title}</div>
|
|
224
216
|
<div class="ds-sub">${model.text}</div>
|
|
225
217
|
${model.stop ? html`<div class="ds-choices"><button type="button" class="ds-choice primary" data-act="del:stop"
|
|
226
|
-
><span class="ds-label">${model.stop.label}</span><span class="ds-line dim">${model.stop.line}</span></button></div>` : nothing}
|
|
227
|
-
<div class="ds-acts"><button type="button" class="ds-cancel" data-act="del:cancel">${model.stop ? "Cancel" : "Close"}</button></div>
|
|
218
|
+
?disabled=${busy}><span class="ds-label">${busy ? "Stopping…" : model.stop.label}</span><span class="ds-line dim">${model.stop.line}</span></button></div>` : nothing}
|
|
219
|
+
<div class="ds-acts"><button type="button" class="ds-cancel" data-act="del:cancel" ?disabled=${busy}>${model.stop ? "Cancel" : "Close"}</button></div>
|
|
228
220
|
</div>`;
|
|
229
221
|
}
|
|
230
222
|
|
|
@@ -266,7 +258,8 @@ export function runDeleteFlow({ id, session, host, api, done, failed = () => {},
|
|
|
266
258
|
|
|
267
259
|
const list = () => (typeof sessions === "function" ? sessions() : sessions);
|
|
268
260
|
const showSheet = () => show(deleteSheetTemplate(model, { back, busy, notice, stopping, act: archive ? "archive" : "this" }));
|
|
269
|
-
const showRefusal = (
|
|
261
|
+
const showRefusal = (busyRefusal = false) =>
|
|
262
|
+
show(refusalTemplate(refusalModel(refusal, plan?.link?.previous_id), { back, busy: busyRefusal }));
|
|
270
263
|
// A plan that can't be read: why, in the sheet, and only Close.
|
|
271
264
|
const cant = (error) => {
|
|
272
265
|
busy = false;
|
|
@@ -307,8 +300,7 @@ export function runDeleteFlow({ id, session, host, api, done, failed = () => {},
|
|
|
307
300
|
return { tasks: choice.tasks, stops: choice.stops, digest: which === "chain" ? plan?.chain?.digest : plan?.link?.digest };
|
|
308
301
|
}
|
|
309
302
|
|
|
310
|
-
async function
|
|
311
|
-
if (busy || !live()) return;
|
|
303
|
+
async function sendDelete(which) {
|
|
312
304
|
const choice = chosen(which);
|
|
313
305
|
if (!choice) return;
|
|
314
306
|
busy = true;
|
|
@@ -347,6 +339,11 @@ export function runDeleteFlow({ id, session, host, api, done, failed = () => {},
|
|
|
347
339
|
}
|
|
348
340
|
}
|
|
349
341
|
|
|
342
|
+
async function run(which) {
|
|
343
|
+
if (busy || !live()) return;
|
|
344
|
+
await sendDelete(which);
|
|
345
|
+
}
|
|
346
|
+
|
|
350
347
|
// The sheet as it is now, with "changed; check again" on top: the plan
|
|
351
348
|
// read again (a delete), or the 409's own tasks (an archive's).
|
|
352
349
|
async function refreshPlan(error) {
|
|
@@ -378,20 +375,25 @@ export function runDeleteFlow({ id, session, host, api, done, failed = () => {},
|
|
|
378
375
|
if (busy || !live()) return;
|
|
379
376
|
const ids = refusal?.ids || [];
|
|
380
377
|
busy = true;
|
|
378
|
+
showRefusal(true);
|
|
381
379
|
for (const child of ids) {
|
|
382
380
|
let released = false;
|
|
383
381
|
try {
|
|
384
382
|
released = (await api.stopSession(child))?.released === true;
|
|
385
383
|
} catch (_) { released = false; }
|
|
386
384
|
if (!released) {
|
|
387
|
-
refusal = { reason: "still_stopping", message: `${short(child)}'s worker is still running; try again in a moment.`, ids };
|
|
388
385
|
busy = false;
|
|
386
|
+
const message = `${short(child)}'s worker is still running; try again in a moment.`;
|
|
387
|
+
if (!live()) {
|
|
388
|
+
failed(Object.assign(new Error(message), { code: "still_stopping", body: { ids } }));
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
refusal = { reason: "still_stopping", message, ids };
|
|
389
392
|
showRefusal();
|
|
390
393
|
return;
|
|
391
394
|
}
|
|
392
395
|
}
|
|
393
|
-
|
|
394
|
-
run("this");
|
|
396
|
+
await sendDelete("this");
|
|
395
397
|
}
|
|
396
398
|
|
|
397
399
|
return {
|
|
@@ -243,11 +243,10 @@ function stillRunning(result, choice) {
|
|
|
243
243
|
// stopped, what stays. +which+: "this" or "chain"; +result+: the route's
|
|
244
244
|
// 200; +plan+: the sheet's. +back+: a session to offer opening (the link
|
|
245
245
|
// that came back, else a delegate left running), or null; +sticky+ true for
|
|
246
|
-
// a chain delete that kept a link part-way.
|
|
247
|
-
// leaves the stopped tasks out (an older cached caller adds them itself).
|
|
246
|
+
// a chain delete that kept a link part-way.
|
|
248
247
|
// @return {text, back, sticky?}
|
|
249
|
-
export function deleteToast(which, result, plan, id
|
|
250
|
-
const tasks =
|
|
248
|
+
export function deleteToast(which, result, plan, id) {
|
|
249
|
+
const tasks = tasksStoppedSuffix(result);
|
|
251
250
|
const running = stillRunning(result, which === "chain" ? plan?.chain : plan?.link);
|
|
252
251
|
const keeps = running.length === 1
|
|
253
252
|
? ` · ${short(running[0])} keeps running`
|
|
@@ -47,22 +47,6 @@ function taskEntries(listing) {
|
|
|
47
47
|
(Array.isArray(listing?.[kind]) ? listing[kind] : []).map((task) => ({ task, kind })));
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
// The second confirm of a delete or an archive refused for background tasks
|
|
51
|
-
// still running (409 tasks_running): which, and whether to stop them and
|
|
52
|
-
// +verb+ ("delete" / "archive") the session. +listing+ is the 409's tasks.
|
|
53
|
-
// Unused since the delete sheet; kept while an older cached
|
|
54
|
-
// session_actions.js may import it (web-frontend.md); goes at the next
|
|
55
|
-
// release.
|
|
56
|
-
export function tasksConfirmText(id, listing, verb) {
|
|
57
|
-
const n = tasksCount(listing);
|
|
58
|
-
const one = n === 1;
|
|
59
|
-
return [
|
|
60
|
-
`Session ${String(id).slice(0, 8)} started ${n} background task${one ? "" : "s"} that ${one ? "is" : "are"} still running:`,
|
|
61
|
-
tasksLine(listing, id),
|
|
62
|
-
`Stop ${one ? "it" : "them"} and ${verb} the session?`,
|
|
63
|
-
].join("\n");
|
|
64
|
-
}
|
|
65
|
-
|
|
66
50
|
// What a delete's or an archive's toast adds for the tasks it stopped (its
|
|
67
51
|
// 200's tasks_stopped / tasks_not_stopped): " · stopped 2 background tasks",
|
|
68
52
|
// " · 1 not stopped: npm run dev"; "" when it stopped none.
|
|
@@ -75,11 +75,6 @@ export function createSessionActions({
|
|
|
75
75
|
notShown(host, `delete ${id.slice(0, 8)}`, error);
|
|
76
76
|
if (!eventsLive()) refresh();
|
|
77
77
|
},
|
|
78
|
-
// Kept for an older cached delete_sheet.js (0.182.0), which calls it
|
|
79
|
-
// for a session in no chain, its sheet closed (it was the browser's
|
|
80
|
-
// confirm): a reload brings the sheet. Goes at the next release.
|
|
81
|
-
plain: () => notShown(host, `delete ${id.slice(0, 8)}`,
|
|
82
|
-
{ message: "this page is out of date; reload it and delete again" }),
|
|
83
78
|
});
|
|
84
79
|
host.wire(flow);
|
|
85
80
|
}
|
|
@@ -325,10 +320,6 @@ export function createSessionActions({
|
|
|
325
320
|
if (!answer.ok) throw answer.error;
|
|
326
321
|
return answer.result;
|
|
327
322
|
},
|
|
328
|
-
// Kept for an older cached delete_sheet.js (0.182.0), which ignores
|
|
329
|
-
// +archive+ and reads a delete plan: the refusal, so it lands in
|
|
330
|
-
// +failed+ and says it. Goes at the next release.
|
|
331
|
-
deletePlan: () => Promise.reject(error),
|
|
332
323
|
},
|
|
333
324
|
done: (_which, result) => archived(id, true, result, undo),
|
|
334
325
|
failed: (failure) => notShown(host, `archive ${id.slice(0, 8)}`, failure),
|