Review Feature Access
Nucleic-Session: 85A6233A-F3F6-44B2-AD0B-261D49EE9C35 Co-authored-by: Nucleic <[email protected]>
This commit is contained in:
@@ -588,51 +588,45 @@ final class RemoteStore: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Stream a short, believable canned turn for a session: assistant prose, a tool call +
|
/// Stream a short, believable canned turn for a session: assistant prose, a tool call +
|
||||||
/// result, usage, and a finish — flipping the summary running → awaiting-input.
|
/// result, usage, and a finish — flipping the summary running → awaiting-input. Each step
|
||||||
|
/// re-checks demo mode and cancellation so `exitDemo()` stops it cleanly. Runs entirely on the
|
||||||
|
/// main actor (the store is `@MainActor`, and a `Task` in an isolated method inherits it).
|
||||||
private func demoRun(_ sessionID: SessionID, userText: String?) {
|
private func demoRun(_ sessionID: SessionID, userText: String?) {
|
||||||
if let userText, !userText.isEmpty {
|
if let userText, !userText.isEmpty {
|
||||||
demoAppend(sessionID, .userText(TextChunk(messageID: UUID().uuidString, text: userText, isPartial: false)))
|
demoAppend(sessionID, .userText(TextChunk(messageID: UUID().uuidString, text: userText, isPartial: false)))
|
||||||
}
|
}
|
||||||
demoUpdateSession(sessionID) { $0.demoCopy(status: .running, disposition: .some(nil)) }
|
demoUpdateSession(sessionID) { $0.demoCopy(status: .running, disposition: .some(nil)) }
|
||||||
let task = Task { [weak self] in
|
|
||||||
let toolID = UUID().uuidString
|
let toolID = UUID().uuidString
|
||||||
guard await self?.demoStep(sessionID, delayMs: 600, {
|
let task = Task { [weak self] in
|
||||||
$0.demoAppend(sessionID, .assistantText(TextChunk(
|
func pause(_ ms: Int) async -> Bool {
|
||||||
|
try? await Task.sleep(for: .milliseconds(ms))
|
||||||
|
return !Task.isCancelled && (self?.demoMode ?? false)
|
||||||
|
}
|
||||||
|
guard let self else { return }
|
||||||
|
guard await pause(600) else { return }
|
||||||
|
self.demoAppend(sessionID, .assistantText(TextChunk(
|
||||||
messageID: UUID().uuidString, text: "On it — let me take a look.", isPartial: false)))
|
messageID: UUID().uuidString, text: "On it — let me take a look.", isPartial: false)))
|
||||||
}) == true else { return }
|
guard await pause(700) else { return }
|
||||||
guard await self?.demoStep(sessionID, delayMs: 700, {
|
self.demoAppend(sessionID, .toolCallStarted(ToolCall(
|
||||||
$0.demoAppend(sessionID, .toolCallStarted(ToolCall(
|
|
||||||
toolCallID: toolID, name: "Bash", input: ["command": "npm test"])))
|
toolCallID: toolID, name: "Bash", input: ["command": "npm test"])))
|
||||||
}) == true else { return }
|
guard await pause(900) else { return }
|
||||||
guard await self?.demoStep(sessionID, delayMs: 900, {
|
self.demoAppend(sessionID, .toolResult(ToolResult(
|
||||||
$0.demoAppend(sessionID, .toolResult(ToolResult(
|
|
||||||
toolCallID: toolID, content: "42 passing\n0 failing", isError: false)))
|
toolCallID: toolID, content: "42 passing\n0 failing", isError: false)))
|
||||||
}) == true else { return }
|
guard await pause(700) else { return }
|
||||||
guard await self?.demoStep(sessionID, delayMs: 700, {
|
self.demoAppend(sessionID, .assistantText(TextChunk(
|
||||||
$0.demoAppend(sessionID, .assistantText(TextChunk(
|
|
||||||
messageID: UUID().uuidString,
|
messageID: UUID().uuidString,
|
||||||
text: "All green — tests pass and the change is in place. Anything else?",
|
text: "All green — tests pass and the change is in place. Anything else?",
|
||||||
isPartial: false)))
|
isPartial: false)))
|
||||||
$0.demoAppend(sessionID, .usage(Usage(
|
self.demoAppend(sessionID, .usage(Usage(
|
||||||
inputTokens: 12_400, outputTokens: 640, costUSD: 0.0088, contextInputTokens: 12_400)))
|
inputTokens: 12_400, outputTokens: 640, costUSD: 0.0088, contextInputTokens: 12_400)))
|
||||||
$0.demoAppend(sessionID, .runFinished(RunFinished(outcome: .completed, finalText: "Done.")))
|
self.demoAppend(sessionID, .runFinished(RunFinished(outcome: .completed, finalText: "Done.")))
|
||||||
}) == true else { return }
|
self.demoUpdateSession(sessionID) {
|
||||||
await self?.demoUpdateSession(sessionID) {
|
|
||||||
$0.demoCopy(status: .awaitingInput, disposition: .some(.completed))
|
$0.demoCopy(status: .awaitingInput, disposition: .some(.completed))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
demoTasks.append(task)
|
demoTasks.append(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One step of a simulated run: sleep, then (if still in demo and not cancelled) apply a
|
|
||||||
/// mutation on the main actor. Returns false to abort the remaining steps.
|
|
||||||
private func demoStep(_ sessionID: SessionID, delayMs: UInt64, _ body: @MainActor (RemoteStore) -> Void) async -> Bool {
|
|
||||||
try? await Task.sleep(for: .milliseconds(Int(delayMs)))
|
|
||||||
guard !Task.isCancelled, demoMode else { return false }
|
|
||||||
body(self)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private func demoStartChat(_ req: StartChatRequest) {
|
private func demoStartChat(_ req: StartChatRequest) {
|
||||||
let project = dashboard.projects.first { $0.id == req.projectID }
|
let project = dashboard.projects.first { $0.id == req.projectID }
|
||||||
let id = SessionID(rawValue: "demo-\(UUID().uuidString.prefix(8))")
|
let id = SessionID(rawValue: "demo-\(UUID().uuidString.prefix(8))")
|
||||||
|
|||||||
Reference in New Issue
Block a user