@sixb/app 0.2.5 → 0.2.7
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/agent/components/agent-threads.d.ts.map +1 -1
- package/dist/agent/components/composer-place.d.ts.map +1 -1
- package/dist/agent/components/computer-place.d.ts +24 -6
- package/dist/agent/components/computer-place.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/message-view.d.ts +13 -3
- package/dist/agent/components/message-view.d.ts.map +1 -1
- package/dist/agent/components/pending-messages.d.ts.map +1 -1
- package/dist/agent/components/sandbox-recovery.d.ts +8 -2
- package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
- package/dist/agent/components/transcript.d.ts +13 -0
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/conversation.d.ts +4 -0
- package/dist/agent/conversation.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts +5 -5
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/format.d.ts +7 -0
- package/dist/agent/format.d.ts.map +1 -1
- package/dist/agent/hooks/thread-queries.d.ts +1548 -0
- package/dist/agent/hooks/thread-queries.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +41 -2
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-lists.d.ts +80 -3
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-place.d.ts +49 -0
- package/dist/agent/hooks/use-thread-place.d.ts.map +1 -0
- package/dist/agent/i18n/en.d.ts +44 -6
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +76 -12
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/live-run.d.ts.map +1 -1
- package/dist/agent/model-selection.d.ts +3 -2
- package/dist/agent/model-selection.d.ts.map +1 -1
- package/dist/agent/moves.d.ts +40 -0
- package/dist/agent/moves.d.ts.map +1 -0
- package/dist/agent/thread-reader-state.d.ts +30 -0
- package/dist/agent/thread-reader-state.d.ts.map +1 -0
- package/dist/agent/types.d.ts +4 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/artifacts/live/session.d.ts.map +1 -1
- package/dist/artifacts/queries.d.ts.map +1 -1
- package/dist/artifacts/renderers/live-frame.d.ts.map +1 -1
- package/dist/{chunk-69qgh20f.js → chunk-1f4h75n3.js} +1 -1
- package/dist/{chunk-4fex83k2.js → chunk-7v9622qb.js} +2254 -739
- package/dist/{chunk-4fex83k2.js.map → chunk-7v9622qb.js.map} +29 -26
- package/dist/{chunk-5sgac68y.js → chunk-dntecmwb.js} +1 -1
- package/dist/{chunk-4wm09prf.js → chunk-qmka6aea.js} +1 -1
- package/dist/createCustomApp.d.ts +8 -1
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +3 -3
- package/dist/pages/console/data/accounts.d.ts +94 -0
- package/dist/pages/console/data/accounts.d.ts.map +1 -0
- package/dist/pages/console/data/connectors.d.ts.map +1 -1
- package/dist/pages/console/data/datasets.d.ts.map +1 -1
- package/dist/pages/console/data/live-updates.d.ts.map +1 -1
- package/dist/pages/console/data/messages.d.ts +46 -0
- package/dist/pages/console/data/messages.d.ts.map +1 -1
- package/dist/pages/console/data/pipelines.d.ts.map +1 -1
- package/dist/pages/console/data/projections.d.ts.map +1 -1
- package/dist/pages/console/data/sync-button.d.ts.map +1 -1
- package/dist/pages/console/data/syncs.d.ts.map +1 -1
- package/dist/pages/console/ontology/actions.d.ts.map +1 -1
- package/dist/pages/console/ontology/object-type.d.ts.map +1 -1
- package/dist/pages/console/ontology/object-types.d.ts.map +1 -1
- package/dist/pages/console/ontology/rules.d.ts.map +1 -1
- package/dist/pages/console/ontology/workflow.d.ts.map +1 -1
- package/dist/pages/console/ontology/workflows.d.ts.map +1 -1
- package/dist/pages/folders.d.ts +106 -0
- package/dist/pages/folders.d.ts.map +1 -0
- package/dist/pages/settings/usage/breakdown.d.ts.map +1 -1
- package/dist/pages/settings/usage/page.d.ts +4 -1
- package/dist/pages/settings/usage/page.d.ts.map +1 -1
- package/dist/pages/settings/usage/spend-model.d.ts +43 -19
- package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
- package/dist/pages.js +23453 -22656
- package/dist/pages.js.map +23 -21
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +40 -3
- package/dist/server.js.map +3 -3
- package/package.json +3 -3
- package/src/agent/agent-chat.tsx +2 -2
- package/src/agent/components/agent-threads.tsx +42 -2
- package/src/agent/components/composer-place.tsx +2 -7
- package/src/agent/components/computer-place.tsx +415 -70
- package/src/agent/components/conversation-panel.tsx +31 -26
- package/src/agent/components/message-view.tsx +418 -9
- package/src/agent/components/pending-messages.tsx +5 -1
- package/src/agent/components/sandbox-recovery.tsx +24 -6
- package/src/agent/components/transcript.tsx +136 -5
- package/src/agent/conversation.ts +16 -1
- package/src/agent/format.ts +52 -0
- package/src/agent/hooks/thread-queries.ts +75 -0
- package/src/agent/hooks/use-agent-conversation.ts +461 -112
- package/src/agent/hooks/use-thread-lists.ts +72 -7
- package/src/agent/hooks/use-thread-place.ts +239 -0
- package/src/agent/i18n/en.ts +69 -16
- package/src/agent/i18n/fr.ts +71 -19
- package/src/agent/live-run.ts +38 -0
- package/src/agent/model-selection.ts +3 -2
- package/src/agent/moves.ts +174 -0
- package/src/agent/thread-reader-state.ts +75 -0
- package/src/agent/types.ts +6 -0
- package/src/artifacts/live/session.ts +5 -0
- package/src/createCustomApp.ts +57 -3
- package/src/index.ts +4 -0
- package/src/pages/console/data/accounts.tsx +509 -0
- package/src/pages/console/data/connectors.tsx +67 -64
- package/src/pages/console/data/datasets.tsx +79 -68
- package/src/pages/console/data/live-updates.ts +2 -0
- package/src/pages/console/data/messages.ts +73 -0
- package/src/pages/console/data/pipelines.tsx +80 -69
- package/src/pages/console/data/projections.tsx +111 -82
- package/src/pages/console/data/sync-button.tsx +56 -16
- package/src/pages/console/data/syncs.tsx +121 -86
- package/src/pages/console/ontology/actions.tsx +51 -24
- package/src/pages/console/ontology/object-type.tsx +5 -1
- package/src/pages/console/ontology/object-types.tsx +41 -32
- package/src/pages/console/ontology/rules.tsx +48 -38
- package/src/pages/console/ontology/workflow.tsx +9 -3
- package/src/pages/console/ontology/workflows.tsx +55 -67
- package/src/pages/folders.tsx +335 -0
- package/src/pages/section-ui.tsx +1 -1
- package/src/pages/settings/usage/breakdown.tsx +5 -2
- package/src/pages/settings/usage/filter-menu.tsx +1 -1
- package/src/pages/settings/usage/page.tsx +32 -13
- package/src/pages/settings/usage/spend-chart.tsx +2 -2
- package/src/pages/settings/usage/spend-model.ts +118 -50
- package/src/server.ts +1 -0
- /package/dist/{chunk-69qgh20f.js.map → chunk-1f4h75n3.js.map} +0 -0
- /package/dist/{chunk-5sgac68y.js.map → chunk-dntecmwb.js.map} +0 -0
- /package/dist/{chunk-4wm09prf.js.map → chunk-qmka6aea.js.map} +0 -0
package/src/agent/live-run.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
AgentInboxReadMessage,
|
|
3
3
|
AgentRunFailure,
|
|
4
|
+
AgentRunStepsEvent,
|
|
4
5
|
AgentRunStreamEvent,
|
|
5
6
|
ModelUiChunk,
|
|
6
7
|
} from "@sixb/client"
|
|
@@ -118,6 +119,8 @@ function reduceEvent(state: LiveRunState, event: AgentRunStreamEvent): LiveRunSt
|
|
|
118
119
|
...state,
|
|
119
120
|
inboxReads: [...state.inboxReads, { at: state.parts.length, messages: event.messages }],
|
|
120
121
|
}
|
|
122
|
+
case "agent.ui.steps":
|
|
123
|
+
return applySteps(state, event)
|
|
121
124
|
case "agent.message.finalized":
|
|
122
125
|
return { ...state, finalizedMessageId: event.messageId }
|
|
123
126
|
case "agent.run.finished":
|
|
@@ -135,6 +138,41 @@ function reduceEvent(state: LiveRunState, event: AgentRunStreamEvent): LiveRunSt
|
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
140
|
|
|
141
|
+
/**
|
|
142
|
+
* The turn's finished steps, sent first to a reader who opened it late: they replace whatever it
|
|
143
|
+
* rebuilt so far, what it read included. What streams next belongs to a later step, even when that
|
|
144
|
+
* step's start was dropped from the stream, so it opens a step of its own.
|
|
145
|
+
*/
|
|
146
|
+
function applySteps(state: LiveRunState, steps: AgentRunStepsEvent): LiveRunState {
|
|
147
|
+
let next: LiveRunState = {
|
|
148
|
+
...state,
|
|
149
|
+
runId: steps.runId,
|
|
150
|
+
active: true,
|
|
151
|
+
parts: [],
|
|
152
|
+
partKeys: [],
|
|
153
|
+
inboxReads: [],
|
|
154
|
+
stepIndex: 0,
|
|
155
|
+
stepStart: 0,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Each read sits where the turn read it: after the parts its first `at` chunks built.
|
|
159
|
+
const addReads = (matches: (at: number) => boolean) => {
|
|
160
|
+
for (const read of steps.reads ?? []) {
|
|
161
|
+
if (!matches(read.at)) continue
|
|
162
|
+
const inboxRead = { at: next.parts.length, messages: read.messages }
|
|
163
|
+
next = { ...next, inboxReads: [...next.inboxReads, inboxRead] }
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
steps.chunks.forEach((chunk, index) => {
|
|
168
|
+
addReads((at) => at === index)
|
|
169
|
+
next = applyChunk(next, chunk)
|
|
170
|
+
})
|
|
171
|
+
addReads((at) => at >= steps.chunks.length)
|
|
172
|
+
|
|
173
|
+
return { ...next, stepIndex: next.stepIndex + 1, stepStart: next.parts.length }
|
|
174
|
+
}
|
|
175
|
+
|
|
138
176
|
type TextChunk = Extract<ModelUiChunk, { readonly type: "text-start" | "text-delta" | "text-end" }>
|
|
139
177
|
type ReasoningChunk = Extract<
|
|
140
178
|
ModelUiChunk,
|
|
@@ -21,8 +21,9 @@ export interface ResolvedModelSelection {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* With tiers,
|
|
25
|
-
* one every message runs on `standard`.
|
|
24
|
+
* With tiers, a conversation starts on Auto: a decision model picks each message's model, and
|
|
25
|
+
* without one every message runs on `standard`. A model chosen in any conversation becomes the one
|
|
26
|
+
* the next conversation starts on, and each conversation pins its own.
|
|
26
27
|
*/
|
|
27
28
|
export function hasTiers(models: readonly LanguageModel[]): boolean {
|
|
28
29
|
return models.some((model) => model.tier !== undefined)
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { folderName, shownFolder } from "./components/computer-place"
|
|
2
|
+
import type { AgentMessages } from "./i18n"
|
|
3
|
+
import type { AgentMessage, AgentRun, AgentThread } from "./types"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where a turn runs: the cloud, or a folder on one of its owner's computers. A computer's turn whose
|
|
7
|
+
* folder the reader isn't shown (someone else's conversation, or one from before folders were kept)
|
|
8
|
+
* is "a computer". The same places as the core's `runPlaceKey`, which tells the model of each move.
|
|
9
|
+
*/
|
|
10
|
+
type Place = "cloud" | "computer" | { readonly id: string; readonly folder: string }
|
|
11
|
+
|
|
12
|
+
function placeKey(place: Place): string {
|
|
13
|
+
return typeof place === "string" ? place : `computer:${place.id}:${place.folder}`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function samePlace(a: Place, b: Place): boolean {
|
|
17
|
+
return placeKey(a) === placeKey(b)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function runPlace(run: AgentRun): Place {
|
|
21
|
+
if (run.runsOn !== "computer") return "cloud"
|
|
22
|
+
return run.computer ?? "computer"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function threadPlace(thread: AgentThread): Place {
|
|
26
|
+
if (thread.runsOn !== "computer") return "cloud"
|
|
27
|
+
return thread.computer ? { id: thread.computer.id, folder: thread.computer.folder } : "computer"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A move in the transcript: what it says, and where it went. */
|
|
31
|
+
export interface TranscriptMove {
|
|
32
|
+
readonly label: string
|
|
33
|
+
readonly place: "cloud" | "computer"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** What the labels name places with, beyond what the runs hold. */
|
|
37
|
+
interface MoveNames {
|
|
38
|
+
readonly messages: AgentMessages["computer"]
|
|
39
|
+
/** Each computer's name, by id, where the reader knows it: runs keep only the id. */
|
|
40
|
+
readonly computerNames: ReadonlyMap<string, string>
|
|
41
|
+
/** Whose computer it is, for someone they shared it with, who isn't shown its folders. */
|
|
42
|
+
readonly ownerName: string | null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A folder by its name, on its computer when that's known. */
|
|
46
|
+
function folderPlace(names: MoveNames, place: { readonly id: string; readonly folder: string }) {
|
|
47
|
+
const computer = names.computerNames.get(place.id)
|
|
48
|
+
const folder = folderName(place.folder)
|
|
49
|
+
return computer ? names.messages.placeOn(folder, computer) : folder
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Where it went, and which files stay behind: `from` is unknown before any turn. */
|
|
53
|
+
function movedLabel(names: MoveNames, from: Place | undefined, to: Place): TranscriptMove {
|
|
54
|
+
const { messages } = names
|
|
55
|
+
|
|
56
|
+
if (to === "cloud") {
|
|
57
|
+
const left = typeof from === "object" ? folderName(from.folder) : null
|
|
58
|
+
return { label: messages.movedToCloud(left), place: "cloud" }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (to === "computer") {
|
|
62
|
+
const label =
|
|
63
|
+
from === "cloud" ? messages.movedToComputer(names.ownerName) : messages.movedElsewhere(null)
|
|
64
|
+
return { label, place: "computer" }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (from === "cloud") {
|
|
68
|
+
return { label: messages.movedToFolder(folderPlace(names, to)), place: "computer" }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Another folder on the same computer: by their names, or their paths where the names are alike.
|
|
72
|
+
if (typeof from === "object" && from.id === to.id) {
|
|
73
|
+
const alike = folderName(from.folder) === folderName(to.folder)
|
|
74
|
+
const shown = alike ? shownFolder : folderName
|
|
75
|
+
return {
|
|
76
|
+
label: messages.movedBetweenFolders(shown(to.folder), shown(from.folder)),
|
|
77
|
+
place: "computer",
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { label: messages.movedElsewhere(folderPlace(names, to)), place: "computer" }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Where a fork's first turn runs: a workspace of its own, apart from its source's. */
|
|
84
|
+
function continuedLabel(names: MoveNames, to: Place): TranscriptMove {
|
|
85
|
+
const { messages } = names
|
|
86
|
+
if (to === "cloud") return { label: messages.continuedIn(messages.cloudPlace), place: "cloud" }
|
|
87
|
+
if (to === "computer") {
|
|
88
|
+
return { label: messages.continuedOnComputer(names.ownerName), place: "computer" }
|
|
89
|
+
}
|
|
90
|
+
return { label: messages.continuedIn(folderPlace(names, to)), place: "computer" }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface TranscriptMoves {
|
|
94
|
+
/** The latest move, when no turn ran since: after the last message from before it. */
|
|
95
|
+
readonly moved: (TranscriptMove & { readonly afterMessageId: string }) | null
|
|
96
|
+
/** Every move, by the shown message it follows. */
|
|
97
|
+
readonly moves: ReadonlyMap<string, TranscriptMove>
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Every place the conversation moved to, in its transcript: where a turn runs elsewhere than the
|
|
102
|
+
* turn before it, and where it runs now when no turn ran since it moved. Moving back before a turn
|
|
103
|
+
* ran is no move: the workspace is the one the last turn worked in. A fork's first turn starts in a
|
|
104
|
+
* workspace of its own. The core tells the model the same (`detectMovedMessages`).
|
|
105
|
+
*/
|
|
106
|
+
export function transcriptMoves(
|
|
107
|
+
input: MoveNames & {
|
|
108
|
+
readonly thread: AgentThread | null
|
|
109
|
+
/** Oldest first. */
|
|
110
|
+
readonly savedMessages: readonly AgentMessage[]
|
|
111
|
+
/** The saved messages the transcript draws: a marker follows one of them. */
|
|
112
|
+
readonly shownIds: ReadonlySet<string>
|
|
113
|
+
/** Newest first, as the conversation reads them. */
|
|
114
|
+
readonly runs: readonly AgentRun[]
|
|
115
|
+
}
|
|
116
|
+
): TranscriptMoves {
|
|
117
|
+
const { thread, savedMessages, shownIds, runs } = input
|
|
118
|
+
|
|
119
|
+
// A retried turn runs again for the same message: its latest run is where it went.
|
|
120
|
+
const placeByTrigger = new Map<string, Place>()
|
|
121
|
+
for (const run of [...runs].reverse()) {
|
|
122
|
+
if (run.kind === "conversation") placeByTrigger.set(run.triggerMessageId, runPlace(run))
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const moves = new Map<string, TranscriptMove>()
|
|
126
|
+
let previous: Place | undefined
|
|
127
|
+
let lastShownId: string | null = null
|
|
128
|
+
// A fork's copies keep the time they were written, before the fork was: they ran in its source,
|
|
129
|
+
// so its first turn here starts elsewhere. A message written here with no run, such as one
|
|
130
|
+
// steering a turn, decides nothing.
|
|
131
|
+
let forked = false
|
|
132
|
+
|
|
133
|
+
for (const saved of savedMessages) {
|
|
134
|
+
const place = saved.role === "user" ? placeByTrigger.get(saved.id) : undefined
|
|
135
|
+
const copied = thread !== null && saved.createdAt < thread.createdAt
|
|
136
|
+
if (saved.role === "user" && copied && previous === undefined) forked = true
|
|
137
|
+
|
|
138
|
+
if (place !== undefined) {
|
|
139
|
+
const move =
|
|
140
|
+
previous === undefined
|
|
141
|
+
? forked && continuedLabel(input, place)
|
|
142
|
+
: !samePlace(previous, place) && movedLabel(input, previous, place)
|
|
143
|
+
if (move && lastShownId !== null) moves.set(lastShownId, move)
|
|
144
|
+
previous = place
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (shownIds.has(saved.id)) lastShownId = saved.id
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!thread) return { moved: null, moves }
|
|
151
|
+
|
|
152
|
+
// Where it runs now, if no turn ran there yet: after the last message from before the move, or
|
|
153
|
+
// a fork's last copy.
|
|
154
|
+
const current = threadPlace(thread)
|
|
155
|
+
const move =
|
|
156
|
+
previous === undefined
|
|
157
|
+
? forked && continuedLabel(input, current)
|
|
158
|
+
: thread.movedAt !== undefined &&
|
|
159
|
+
!samePlace(previous, current) &&
|
|
160
|
+
movedLabel(input, previous, current)
|
|
161
|
+
if (!move) return { moved: null, moves }
|
|
162
|
+
|
|
163
|
+
// A fork keeps its source's latest move, which can predate some of its copies: its marker
|
|
164
|
+
// follows the last copy. A move's follows the last message from before it.
|
|
165
|
+
const movedAt = previous === undefined ? undefined : thread.movedAt
|
|
166
|
+
const afterMessageId = movedAt
|
|
167
|
+
? savedMessages.filter((saved) => saved.createdAt <= movedAt && shownIds.has(saved.id)).at(-1)
|
|
168
|
+
?.id
|
|
169
|
+
: lastShownId
|
|
170
|
+
if (!afterMessageId) return { moved: null, moves }
|
|
171
|
+
|
|
172
|
+
moves.set(afterMessageId, move)
|
|
173
|
+
return { moved: { ...move, afterMessageId }, moves }
|
|
174
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { CurrentUser } from "../session"
|
|
2
|
+
import { CONTEXT_LIMIT_EXCEEDED } from "./run-presentation"
|
|
3
|
+
import { samePrincipal, userPrincipal } from "./sharing"
|
|
4
|
+
import type { AgentThread } from "./types"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What a session asks of the person reading it. The words are the app's; the facts are the
|
|
8
|
+
* server's: a call waiting on them, a turn in flight, and what arrived since they last looked.
|
|
9
|
+
*/
|
|
10
|
+
export type AgentThreadState = "needs-you" | "working" | "finished" | "idle"
|
|
11
|
+
|
|
12
|
+
type ThreadStateSources = Pick<AgentThread, "activeRunId" | "lastRun" | "read">
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The state of a session for one reader, in this order:
|
|
16
|
+
*
|
|
17
|
+
* - `needs-you`: a call waits on their approval, or a turn they asked for ended short since they
|
|
18
|
+
* last looked, and they can run it again.
|
|
19
|
+
* - `working`: a turn runs.
|
|
20
|
+
* - `finished`: something arrived since they last looked: an answer, someone's message, or
|
|
21
|
+
* another person's turn that ended short.
|
|
22
|
+
* - `idle`: nothing did.
|
|
23
|
+
*
|
|
24
|
+
* Looking, which marking the thread read records, settles a turn that ended short as it settles
|
|
25
|
+
* the messages before it: Done clears both. Without a place in the thread (an observer, or a
|
|
26
|
+
* project without sign-in) only approvals and running turns show.
|
|
27
|
+
*
|
|
28
|
+
* `waiting` is a pending approval of theirs in this thread, from `agent.approvals.list()`.
|
|
29
|
+
*/
|
|
30
|
+
export function agentThreadState(
|
|
31
|
+
thread: ThreadStateSources,
|
|
32
|
+
reader: { readonly waiting: boolean; readonly user: CurrentUser | null }
|
|
33
|
+
): AgentThreadState {
|
|
34
|
+
const endedShort = unseenShortTurn(thread)
|
|
35
|
+
|
|
36
|
+
if (reader.waiting) return "needs-you"
|
|
37
|
+
if (endedShort && canRunAgain(endedShort, reader.user)) return "needs-you"
|
|
38
|
+
if (thread.activeRunId !== null) return "working"
|
|
39
|
+
if (endedShort || (thread.read?.unread ?? 0) > 0) return "finished"
|
|
40
|
+
return "idle"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type LastRun = NonNullable<AgentThread["lastRun"]>
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The newest turn, when it stopped before its answer and the reader has not looked since. The
|
|
47
|
+
* server says the same of a run (`agentRunEndedShort`) when it names who asked for it.
|
|
48
|
+
*/
|
|
49
|
+
function unseenShortTurn(thread: ThreadStateSources): LastRun | null {
|
|
50
|
+
const { lastRun, read } = thread
|
|
51
|
+
if (!lastRun || !read) return null
|
|
52
|
+
|
|
53
|
+
const endedShort =
|
|
54
|
+
lastRun.status === "failed" ||
|
|
55
|
+
lastRun.finishReason === "timeout" ||
|
|
56
|
+
lastRun.finishReason === "interrupted"
|
|
57
|
+
if (!endedShort) return null
|
|
58
|
+
|
|
59
|
+
const seen =
|
|
60
|
+
read.readAt !== undefined &&
|
|
61
|
+
(lastRun.completedAt === undefined ||
|
|
62
|
+
Date.parse(read.readAt) >= Date.parse(lastRun.completedAt))
|
|
63
|
+
|
|
64
|
+
return seen ? null : lastRun
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Whether the transcript offers this reader Continue or Retry: only whoever asked for the turn
|
|
69
|
+
* runs it again, and never a conversation too long for its model, which would fail the same way.
|
|
70
|
+
*/
|
|
71
|
+
function canRunAgain(lastRun: LastRun, user: CurrentUser | null): boolean {
|
|
72
|
+
if (lastRun.errorCode === CONTEXT_LIMIT_EXCEEDED) return false
|
|
73
|
+
|
|
74
|
+
return samePrincipal(lastRun.requestedBy, userPrincipal(user))
|
|
75
|
+
}
|
package/src/agent/types.ts
CHANGED
|
@@ -20,6 +20,12 @@ export type Agent = GetAgentResponse
|
|
|
20
20
|
|
|
21
21
|
export type AgentThread = ListAgentThreadsResponse["threads"][number]
|
|
22
22
|
|
|
23
|
+
/** How far the reader's place in a thread has reached, and what is new to them. */
|
|
24
|
+
export type AgentThreadRead = NonNullable<AgentThread["read"]>
|
|
25
|
+
|
|
26
|
+
/** A thread's newest run: enough to offer Continue or Retry without reading it. */
|
|
27
|
+
export type AgentThreadLastRun = NonNullable<AgentThread["lastRun"]>
|
|
28
|
+
|
|
23
29
|
/** What a new conversation's sandbox is made from, as the project's sandbox declares its params. */
|
|
24
30
|
export type AgentThreadSandboxParams = NonNullable<CreateAgentThreadData["body"]["sandbox"]>
|
|
25
31
|
|
|
@@ -222,6 +222,10 @@ export class LiveArtifact {
|
|
|
222
222
|
connected(): void {
|
|
223
223
|
if (this.state.left) return
|
|
224
224
|
this.joined = false
|
|
225
|
+
const others = [...this.awareness.getStates().keys()].filter(
|
|
226
|
+
(client) => client !== this.doc.clientID
|
|
227
|
+
)
|
|
228
|
+
awarenessProtocol.removeAwarenessStates(this.awareness, others, FROM_SERVER)
|
|
225
229
|
this.send({ type: "join", artifactId: this.artifactId })
|
|
226
230
|
this.update({ connection: "online" })
|
|
227
231
|
}
|
|
@@ -515,6 +519,7 @@ function openLiveSocket(handlers: Parameters<LiveSocketFactory>[0]): ArtifactLiv
|
|
|
515
519
|
onMessage: handlers.onMessage,
|
|
516
520
|
onStateChange: (state) => {
|
|
517
521
|
if (state.connected || !connected) return
|
|
522
|
+
if (!state.reconnecting && !state.error) return
|
|
518
523
|
connected = false
|
|
519
524
|
handlers.onClosed()
|
|
520
525
|
},
|
package/src/createCustomApp.ts
CHANGED
|
@@ -64,12 +64,20 @@ export interface CustomAppStartOptions {
|
|
|
64
64
|
authEnabled?: boolean
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
export interface CustomAppStopOptions {
|
|
68
|
+
/**
|
|
69
|
+
* How long in-flight requests may take to finish before remaining connections are closed.
|
|
70
|
+
* Defaults to 5 seconds; `0` closes them at once.
|
|
71
|
+
*/
|
|
72
|
+
readonly timeoutMs?: number
|
|
73
|
+
}
|
|
74
|
+
|
|
67
75
|
export interface CustomAppServer {
|
|
68
76
|
host: string
|
|
69
77
|
/** The port it listens on: the one it bound when asked for port 0. */
|
|
70
78
|
port: number
|
|
71
79
|
url: string
|
|
72
|
-
stop(): Promise<void>
|
|
80
|
+
stop(options?: CustomAppStopOptions): Promise<void>
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
export interface CustomAppDevServer extends CustomAppServer {
|
|
@@ -692,14 +700,60 @@ export async function createCustomApp(options: CreateCustomAppOptions): Promise<
|
|
|
692
700
|
host,
|
|
693
701
|
port: boundPort,
|
|
694
702
|
url: `http://${displayHost}:${boundPort}`,
|
|
695
|
-
async stop() {
|
|
696
|
-
server.
|
|
703
|
+
async stop(stopOptions: CustomAppStopOptions = {}) {
|
|
704
|
+
await stopBunAppServer(server, stopOptions.timeoutMs)
|
|
697
705
|
},
|
|
698
706
|
}
|
|
699
707
|
},
|
|
700
708
|
}
|
|
701
709
|
}
|
|
702
710
|
|
|
711
|
+
const DEFAULT_APP_STOP_TIMEOUT_MS = 5_000
|
|
712
|
+
|
|
713
|
+
async function stopBunAppServer(
|
|
714
|
+
server: ReturnType<typeof Bun.serve>,
|
|
715
|
+
timeoutMs: number = DEFAULT_APP_STOP_TIMEOUT_MS
|
|
716
|
+
): Promise<void> {
|
|
717
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) {
|
|
718
|
+
throw new Error("[SixbCustomApp] Stop timeout must be a non-negative finite number.")
|
|
719
|
+
}
|
|
720
|
+
if (timeoutMs <= 0) {
|
|
721
|
+
await server.stop(true)
|
|
722
|
+
return
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
const draining = server.stop(false)
|
|
726
|
+
const deadline = Date.now() + timeoutMs
|
|
727
|
+
let settled = false
|
|
728
|
+
void draining.then(
|
|
729
|
+
() => {
|
|
730
|
+
settled = true
|
|
731
|
+
},
|
|
732
|
+
() => {
|
|
733
|
+
settled = true
|
|
734
|
+
}
|
|
735
|
+
)
|
|
736
|
+
|
|
737
|
+
while (!settled && (server.pendingRequests > 0 || server.pendingWebSockets > 0)) {
|
|
738
|
+
const remaining = deadline - Date.now()
|
|
739
|
+
if (remaining <= 0) break
|
|
740
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
741
|
+
try {
|
|
742
|
+
await Promise.race([
|
|
743
|
+
draining,
|
|
744
|
+
new Promise<void>((resolve) => {
|
|
745
|
+
timer = setTimeout(resolve, Math.min(remaining, 25))
|
|
746
|
+
}),
|
|
747
|
+
])
|
|
748
|
+
} finally {
|
|
749
|
+
if (timer !== undefined) clearTimeout(timer)
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
await server.stop(true)
|
|
754
|
+
await draining
|
|
755
|
+
}
|
|
756
|
+
|
|
703
757
|
async function pathExists(path: string): Promise<boolean> {
|
|
704
758
|
try {
|
|
705
759
|
await access(path)
|
package/src/index.ts
CHANGED
|
@@ -77,10 +77,12 @@ export type {
|
|
|
77
77
|
AgentConversationTurn,
|
|
78
78
|
AgentFileSource,
|
|
79
79
|
} from "./agent/conversation"
|
|
80
|
+
export { usePrefetchAgentThread } from "./agent/hooks/thread-queries"
|
|
80
81
|
export {
|
|
81
82
|
type AgentConversation,
|
|
82
83
|
type AgentConversationMessagesError,
|
|
83
84
|
type AgentConversationSendError,
|
|
85
|
+
type AgentMessageEditDraft,
|
|
84
86
|
type ConversationComposerProps,
|
|
85
87
|
type UseAgentConversationInput,
|
|
86
88
|
useAgentConversation,
|
|
@@ -103,6 +105,8 @@ export type {
|
|
|
103
105
|
AgentRun,
|
|
104
106
|
AgentThread,
|
|
105
107
|
AgentThreadContext,
|
|
108
|
+
AgentThreadLastRun,
|
|
109
|
+
AgentThreadRead,
|
|
106
110
|
AgentThreadSandboxParams,
|
|
107
111
|
LanguageModel,
|
|
108
112
|
} from "./agent/types"
|