@sixb/agent 0.2.4 → 0.2.6
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/README.md +2 -2
- package/dist/agent-prompt.d.ts +13 -3
- package/dist/agent-prompt.d.ts.map +1 -1
- package/dist/artifacts/layout-check/layout-check.d.ts +21 -24
- package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -1
- package/dist/artifacts/publish-tool.d.ts.map +1 -1
- package/dist/background-commands.d.ts +2 -2
- package/dist/context-compaction.d.ts.map +1 -1
- package/dist/conversation-messages.d.ts +1 -1
- package/dist/conversation-messages.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11082 -9281
- package/dist/index.js.map +37 -33
- package/dist/login-shell.d.ts +18 -2
- package/dist/login-shell.d.ts.map +1 -1
- package/dist/model-adapters.d.ts +5 -2
- package/dist/model-adapters.d.ts.map +1 -1
- package/dist/model-lines.d.ts +1 -0
- package/dist/model-lines.d.ts.map +1 -1
- package/dist/run-agent-turn.d.ts +3 -14
- package/dist/run-agent-turn.d.ts.map +1 -1
- package/dist/run-conversation-turn.d.ts.map +1 -1
- package/dist/run-environment.d.ts.map +1 -1
- package/dist/run-sandbox.d.ts +11 -1
- package/dist/run-sandbox.d.ts.map +1 -1
- package/dist/run-subagent.d.ts.map +1 -1
- package/dist/sandbox-api-context.d.ts.map +1 -1
- package/dist/search-script.d.ts +7 -0
- package/dist/search-script.d.ts.map +1 -0
- package/dist/skills/built-in.d.ts.map +1 -1
- package/dist/subagent-tools.d.ts +11 -1
- package/dist/subagent-tools.d.ts.map +1 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/glob.d.ts +41 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/grep.d.ts +64 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/model-spec.d.ts.map +1 -1
- package/dist/tools/sandbox-search.d.ts +26 -0
- package/dist/tools/sandbox-search.d.ts.map +1 -0
- package/dist/tools/search/command.d.ts +15 -0
- package/dist/tools/search/command.d.ts.map +1 -0
- package/dist/tools/search/gitignore.d.ts +28 -0
- package/dist/tools/search/gitignore.d.ts.map +1 -0
- package/dist/tools/search/glob.d.ts +15 -0
- package/dist/tools/search/glob.d.ts.map +1 -0
- package/dist/tools/search/main.d.ts +2 -0
- package/dist/tools/search/main.d.ts.map +1 -0
- package/dist/tools/search/match.d.ts +30 -0
- package/dist/tools/search/match.d.ts.map +1 -0
- package/dist/tools/search/pattern.d.ts +19 -0
- package/dist/tools/search/pattern.d.ts.map +1 -0
- package/dist/tools/search/read.d.ts +62 -0
- package/dist/tools/search/read.d.ts.map +1 -0
- package/dist/tools/search/request.d.ts +80 -0
- package/dist/tools/search/request.d.ts.map +1 -0
- package/dist/tools/search/search.d.ts +4 -0
- package/dist/tools/search/search.d.ts.map +1 -0
- package/dist/tools/search/walk.d.ts +43 -0
- package/dist/tools/search/walk.d.ts.map +1 -0
- package/dist/tools/tool-outputs.d.ts.map +1 -1
- package/dist/turn-inbox.d.ts +75 -0
- package/dist/turn-inbox.d.ts.map +1 -0
- package/package.json +7 -5
- package/src/agent-prompt.ts +63 -28
- package/src/agent-runtime/preflight.ts +1 -0
- package/src/artifacts/layout-check/check.cjs +176 -95
- package/src/artifacts/layout-check/layout-check.ts +118 -76
- package/src/artifacts/publish-tool.ts +48 -99
- package/src/background-commands.ts +8 -6
- package/src/context-compaction.ts +1 -0
- package/src/conversation-messages.ts +11 -4
- package/src/generated/search.mjs +985 -0
- package/src/index.ts +0 -1
- package/src/login-shell.ts +30 -3
- package/src/model-adapters.ts +23 -4
- package/src/model-lines.ts +1 -1
- package/src/run-agent-turn.ts +85 -129
- package/src/run-conversation-turn.ts +15 -6
- package/src/run-environment.ts +42 -11
- package/src/run-sandbox.ts +60 -1
- package/src/run-subagent.ts +9 -2
- package/src/sandbox-api-context.ts +10 -1
- package/src/search-script-assets.d.ts +5 -0
- package/src/search-script.ts +9 -0
- package/src/skills/built-in.ts +16 -0
- package/src/skills/sixb-artifacts/SKILL.md +7 -7
- package/src/skills/sixb-artifacts/canvas.md +3 -2
- package/src/skills/sixb-artifacts/document.md +92 -5
- package/src/skills/sixb-artifacts/examples/document/service-proposal/design.css +114 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/document.html +159 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/images/fieldwise.svg +1 -0
- package/src/skills/sixb-artifacts/examples/document/service-proposal/images/harbor-pine.svg +1 -0
- package/src/skills/sixb-artifacts/queries.md +2 -1
- package/src/subagent-tools.ts +23 -5
- package/src/tools/bash.ts +9 -10
- package/src/tools/glob.ts +124 -0
- package/src/tools/grep.ts +190 -0
- package/src/tools/model-spec.ts +4 -0
- package/src/tools/sandbox-search.ts +219 -0
- package/src/tools/search/command.ts +116 -0
- package/src/tools/search/gitignore.ts +101 -0
- package/src/tools/search/glob.ts +90 -0
- package/src/tools/search/main.ts +9 -0
- package/src/tools/search/match.ts +278 -0
- package/src/tools/search/pattern.ts +178 -0
- package/src/tools/search/read.ts +237 -0
- package/src/tools/search/request.ts +101 -0
- package/src/tools/search/search.ts +297 -0
- package/src/tools/search/walk.ts +145 -0
- package/src/tools/tool-outputs.ts +7 -2
- package/src/turn-inbox.ts +283 -0
- package/dist/artifacts/board-previews.d.ts +0 -41
- package/dist/artifacts/board-previews.d.ts.map +0 -1
- package/src/artifacts/board-previews.ts +0 -218
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer"
|
|
2
|
+
import { type Dirent, lstatSync, readdirSync, readFileSync, statSync } from "node:fs"
|
|
3
|
+
import { type IgnoreFile, isIgnored, parseGitignore } from "./gitignore"
|
|
4
|
+
|
|
5
|
+
export interface WalkOptions {
|
|
6
|
+
/** The folder to walk: a real, absolute path. */
|
|
7
|
+
readonly root: string
|
|
8
|
+
/** The `.gitignore` files of the folders above the root that apply, outermost first. */
|
|
9
|
+
readonly ignoreFiles: readonly IgnoreFile[]
|
|
10
|
+
/** Enter folders and list files whose name starts with `.`. */
|
|
11
|
+
readonly hidden: boolean
|
|
12
|
+
readonly nodeModules: boolean
|
|
13
|
+
/** Real, absolute paths of folders never entered: the run's context directory. */
|
|
14
|
+
readonly skipFolders: ReadonlySet<string>
|
|
15
|
+
/** Whether a folder, relative to the root, may hold what the search looks for. */
|
|
16
|
+
readonly mayContain?: (relativeFolder: string) => boolean
|
|
17
|
+
/** The time, in epoch milliseconds, at which the walk stops. */
|
|
18
|
+
readonly deadline: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface WalkedFile {
|
|
22
|
+
readonly path: string
|
|
23
|
+
/** From the root, with `/`. */
|
|
24
|
+
readonly relative: string
|
|
25
|
+
/** A link to a file: listed, but its target may be anywhere. */
|
|
26
|
+
readonly symlink: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The files under a folder, in byte order of their paths, so that the first results of a capped
|
|
31
|
+
* search are the same on every run. `.git`, hidden entries and `node_modules` unless asked for,
|
|
32
|
+
* what `.gitignore` files exclude, and unreadable entries are skipped. Links to folders are not
|
|
33
|
+
* followed. Past its deadline, the walk stops and says it is {@link incomplete}.
|
|
34
|
+
*/
|
|
35
|
+
export class FileWalk {
|
|
36
|
+
#incomplete = false
|
|
37
|
+
|
|
38
|
+
constructor(private readonly options: WalkOptions) {}
|
|
39
|
+
|
|
40
|
+
get incomplete(): boolean {
|
|
41
|
+
return this.#incomplete
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
*files(): Generator<WalkedFile> {
|
|
45
|
+
yield* this.#folder(this.options.root, "", this.options.ignoreFiles)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
*#folder(
|
|
49
|
+
folder: string,
|
|
50
|
+
relativeFolder: string,
|
|
51
|
+
ignoreFiles: readonly IgnoreFile[]
|
|
52
|
+
): Generator<WalkedFile> {
|
|
53
|
+
if (this.#pastDeadline()) return
|
|
54
|
+
|
|
55
|
+
let entries: Dirent[]
|
|
56
|
+
try {
|
|
57
|
+
entries = readdirSync(folder, { withFileTypes: true })
|
|
58
|
+
} catch {
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const own = entries.some((entry) => entry.name === ".gitignore")
|
|
63
|
+
? readIgnoreFile(folder)
|
|
64
|
+
: undefined
|
|
65
|
+
const applying = own ? [...ignoreFiles, own] : ignoreFiles
|
|
66
|
+
|
|
67
|
+
for (const entry of sortedEntries(entries)) {
|
|
68
|
+
if (this.#incomplete) return
|
|
69
|
+
|
|
70
|
+
const { name } = entry
|
|
71
|
+
if (name === ".git") continue
|
|
72
|
+
if (!this.options.hidden && name.startsWith(".")) continue
|
|
73
|
+
|
|
74
|
+
const path = childPath(folder, name)
|
|
75
|
+
const relative = relativeFolder ? `${relativeFolder}/${name}` : name
|
|
76
|
+
|
|
77
|
+
if (entry.isDirectory()) {
|
|
78
|
+
if (name === "node_modules" && !this.options.nodeModules) continue
|
|
79
|
+
if (this.options.skipFolders.has(path)) continue
|
|
80
|
+
if (isIgnored(applying, path, true)) continue
|
|
81
|
+
if (this.options.mayContain && !this.options.mayContain(relative)) continue
|
|
82
|
+
|
|
83
|
+
yield* this.#folder(path, relative, applying)
|
|
84
|
+
continue
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const symlink = entry.isSymbolicLink()
|
|
88
|
+
if (!entry.isFile() && !(symlink && isLinkToFile(path))) continue
|
|
89
|
+
if (isIgnored(applying, path, false)) continue
|
|
90
|
+
if (this.#pastDeadline()) return
|
|
91
|
+
|
|
92
|
+
yield { path, relative, symlink }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#pastDeadline(): boolean {
|
|
97
|
+
if (Date.now() >= this.options.deadline) this.#incomplete = true
|
|
98
|
+
return this.#incomplete
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Past this size, an ignore file is not read. */
|
|
103
|
+
const IGNORE_FILE_BYTES = 1024 * 1024
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A folder's `.gitignore`, or another ignore file applying from it, when it is a regular file it
|
|
107
|
+
* can read. A link is not followed, as git does not, and a device or a FIFO is never opened.
|
|
108
|
+
*/
|
|
109
|
+
export function readIgnoreFile(folder: string, name = ".gitignore"): IgnoreFile | undefined {
|
|
110
|
+
try {
|
|
111
|
+
const path = childPath(folder, name)
|
|
112
|
+
const stats = lstatSync(path)
|
|
113
|
+
if (!stats.isFile() || stats.size > IGNORE_FILE_BYTES) return undefined
|
|
114
|
+
|
|
115
|
+
return { folder, rules: parseGitignore(readFileSync(path, "utf8")) }
|
|
116
|
+
} catch {
|
|
117
|
+
return undefined
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Entries in the order their paths sort in, byte by byte: a folder as its name and a `/`, so that
|
|
123
|
+
* `a.txt` comes before `a/b.txt` as it does in a sorted list of paths.
|
|
124
|
+
*/
|
|
125
|
+
function sortedEntries(entries: readonly Dirent[]): Dirent[] {
|
|
126
|
+
return entries
|
|
127
|
+
.map((entry) => ({
|
|
128
|
+
entry,
|
|
129
|
+
key: Buffer.from(entry.isDirectory() ? `${entry.name}/` : entry.name),
|
|
130
|
+
}))
|
|
131
|
+
.sort((left, right) => Buffer.compare(left.key, right.key))
|
|
132
|
+
.map(({ entry }) => entry)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function childPath(folder: string, name: string): string {
|
|
136
|
+
return folder.endsWith("/") ? `${folder}${name}` : `${folder}/${name}`
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function isLinkToFile(path: string): boolean {
|
|
140
|
+
try {
|
|
141
|
+
return statSync(path).isFile()
|
|
142
|
+
} catch {
|
|
143
|
+
return false
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -22,6 +22,8 @@ import type { AgentMessageRecord } from "@sixb/core/storage"
|
|
|
22
22
|
import { listSandboxFiles } from "../sandbox-files"
|
|
23
23
|
import { type AgentSandboxHandle, contextPath } from "../sandbox-handle"
|
|
24
24
|
import { BASH_TOOL_SPEC, keptCommandOutput } from "./bash"
|
|
25
|
+
import { GLOB_TOOL_SPEC } from "./glob"
|
|
26
|
+
import { GREP_TOOL_SPEC } from "./grep"
|
|
25
27
|
import { READ_TOOL_SPEC } from "./read"
|
|
26
28
|
import { AgentFileBudget } from "./tool-files"
|
|
27
29
|
import { LEGACY_VIEW_FILE_TOOL } from "./view-file"
|
|
@@ -65,11 +67,14 @@ const LISTED_OUTPUTS_MAX_FILES = 1_000
|
|
|
65
67
|
const LIST_TIMEOUT_MS = 30_000
|
|
66
68
|
|
|
67
69
|
/**
|
|
68
|
-
* Never saved here: the readers page through files themselves, and `
|
|
69
|
-
*
|
|
70
|
+
* Never saved here: the readers page through files themselves, `glob` and `grep` cap what they
|
|
71
|
+
* return and show it as text a saved JSON would not be, and `web_fetch` saves its page itself
|
|
72
|
+
* ({@link ToolOutputFiles.store}).
|
|
70
73
|
*/
|
|
71
74
|
const UNSAVED_TOOLS: ReadonlySet<string> = new Set([
|
|
72
75
|
READ_TOOL_SPEC.name,
|
|
76
|
+
GLOB_TOOL_SPEC.name,
|
|
77
|
+
GREP_TOOL_SPEC.name,
|
|
73
78
|
LEGACY_VIEW_FILE_TOOL,
|
|
74
79
|
WEB_FETCH_TOOL_SPEC.name,
|
|
75
80
|
])
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type { AgentMessagePart, AgentStepRequestSize } from "@sixb/core"
|
|
2
|
+
import {
|
|
3
|
+
AGENT_MESSAGE_CONTENT_VERSION,
|
|
4
|
+
type AgentRunSession,
|
|
5
|
+
createAgentMessageId,
|
|
6
|
+
type PausableModelLoopResult,
|
|
7
|
+
toModelMessages,
|
|
8
|
+
} from "@sixb/core/internal/agents"
|
|
9
|
+
import type { ModelAssistantPart, ModelMessage, ModelStep } from "@sixb/core/models"
|
|
10
|
+
import type {
|
|
11
|
+
AgentInboxItemRecord,
|
|
12
|
+
AgentMessageRecord,
|
|
13
|
+
AppendAgentMessageInput,
|
|
14
|
+
ConversationAgentRunRecord,
|
|
15
|
+
Principal,
|
|
16
|
+
} from "@sixb/core/storage"
|
|
17
|
+
import { renderCurrentTime, type SentSettings } from "./agent-prompt"
|
|
18
|
+
import { type ConversationReaders, conversationAuthors } from "./message-authors"
|
|
19
|
+
import {
|
|
20
|
+
type AgentToolOutputFileOf,
|
|
21
|
+
agentTraceFromModelSteps,
|
|
22
|
+
agentTraceFromPartialModelLoop,
|
|
23
|
+
} from "./model-adapters"
|
|
24
|
+
|
|
25
|
+
/** A steer the turn read at one of its step boundaries: which step, and what it read. */
|
|
26
|
+
export interface TurnInboxDelivery {
|
|
27
|
+
/** The step the messages came after: its own count of the steps the turn completed. */
|
|
28
|
+
readonly afterSteps: number
|
|
29
|
+
readonly items: readonly AgentInboxItemRecord[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** What a steer's message is projected from: the thread as the turn started, and who reads it. */
|
|
33
|
+
interface TurnInboxContext {
|
|
34
|
+
readonly retainedMessages: readonly AgentMessageRecord[]
|
|
35
|
+
readonly conversation?: ConversationReaders
|
|
36
|
+
readonly project: SentSettings
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A turn's mid-run steers, drained from its session's inbox at step boundaries.
|
|
41
|
+
*
|
|
42
|
+
* Every item a turn reads is claimed by its run and its step, so a step that reads twice reads
|
|
43
|
+
* once, and a turn that never writes one releases it (see AgentRunSession.finish). The messages
|
|
44
|
+
* here are what the model read: its history plus the steer, projected the way the next turn's
|
|
45
|
+
* replay of `agent_messages` projects it, so both send the same bytes.
|
|
46
|
+
*/
|
|
47
|
+
export class TurnInbox {
|
|
48
|
+
readonly #deliveries: TurnInboxDelivery[] = []
|
|
49
|
+
#read: AgentInboxItemRecord[] = []
|
|
50
|
+
readonly #context: TurnInboxContext
|
|
51
|
+
|
|
52
|
+
constructor(
|
|
53
|
+
private readonly session: AgentRunSession,
|
|
54
|
+
context: TurnInboxContext
|
|
55
|
+
) {
|
|
56
|
+
this.#context = context
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What the turn read, in order. */
|
|
60
|
+
get deliveries(): readonly TurnInboxDelivery[] {
|
|
61
|
+
return this.#deliveries
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The messages the model reads after `afterSteps` steps; none when nothing waits. `afterAnswer`
|
|
66
|
+
* marks a read that came as the model answered, which the next request follows with one more
|
|
67
|
+
* step.
|
|
68
|
+
*/
|
|
69
|
+
async take(
|
|
70
|
+
afterSteps: number,
|
|
71
|
+
options: { readonly afterAnswer?: boolean } = {}
|
|
72
|
+
): Promise<readonly ModelMessage[]> {
|
|
73
|
+
const items = await this.session.inbox.takeSteers({
|
|
74
|
+
stepIndex: afterSteps,
|
|
75
|
+
...(options.afterAnswer ? { afterAnswer: true } : {}),
|
|
76
|
+
})
|
|
77
|
+
if (items.length === 0) return []
|
|
78
|
+
|
|
79
|
+
this.#deliveries.push({ afterSteps, items })
|
|
80
|
+
this.#read = [...this.#read, ...items]
|
|
81
|
+
return steerModelMessages(items, this.#context, this.#read)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A steer's parts as one user message, projected as a later turn replays it. A steer carries text
|
|
87
|
+
* and context only: storage refuses a file, whose text a later turn derives from the attachments it
|
|
88
|
+
* prepares, so the bytes could not be the same.
|
|
89
|
+
*/
|
|
90
|
+
function steerModelMessages(
|
|
91
|
+
items: readonly AgentInboxItemRecord[],
|
|
92
|
+
context: TurnInboxContext,
|
|
93
|
+
read: readonly AgentInboxItemRecord[]
|
|
94
|
+
): readonly ModelMessage[] {
|
|
95
|
+
// Who wrote them, as the thread reads once they are saved: the turn appends each steer to the
|
|
96
|
+
// conversation a later turn replays, so the same authors close the same messages.
|
|
97
|
+
const authors = context.conversation
|
|
98
|
+
? conversationAuthors({
|
|
99
|
+
conversation: context.conversation,
|
|
100
|
+
messages: [...context.retainedMessages, ...read.map(savedRecord)],
|
|
101
|
+
}).byMessageId
|
|
102
|
+
: undefined
|
|
103
|
+
|
|
104
|
+
const closing = new Map<string, string>()
|
|
105
|
+
for (const item of items) {
|
|
106
|
+
const sent = renderCurrentTime(item.createdAt, {
|
|
107
|
+
timeZone: item.timeZone ?? context.project.timeZone,
|
|
108
|
+
locale: item.locale ?? context.project.locale,
|
|
109
|
+
})
|
|
110
|
+
closing.set(item.messageId, [sent, authors?.get(item.messageId)].filter(Boolean).join("\n"))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return toModelMessages(
|
|
114
|
+
items.map((item) => ({ id: item.messageId, role: "user" as const, parts: item.parts })),
|
|
115
|
+
{ userMessageSuffix: (message) => (message.id ? closing.get(message.id) : undefined) }
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A steer as the conversation holds it once the turn appends it: what its authors read from. */
|
|
120
|
+
function savedRecord(item: AgentInboxItemRecord): AgentMessageRecord {
|
|
121
|
+
return {
|
|
122
|
+
id: item.messageId,
|
|
123
|
+
projectId: item.projectId,
|
|
124
|
+
threadId: item.threadId,
|
|
125
|
+
runId: null,
|
|
126
|
+
role: "user",
|
|
127
|
+
authorPrincipal: item.authorPrincipal,
|
|
128
|
+
seq: 0,
|
|
129
|
+
parts: item.parts,
|
|
130
|
+
contentVersion: AGENT_MESSAGE_CONTENT_VERSION,
|
|
131
|
+
createdAt: item.createdAt,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Slice the steps a turn completed, or the part of one it did not, around the steers it read, as
|
|
137
|
+
* `agent_messages` rows: one assistant message up to each delivery, the steer as its own user
|
|
138
|
+
* message, then the rest. A steer no step followed — the turn stopped before answering it — is
|
|
139
|
+
* left out, so finishing without its message releases it back to the thread's inbox.
|
|
140
|
+
*/
|
|
141
|
+
export function turnWorkMessages(input: {
|
|
142
|
+
readonly steps: readonly ModelStep[]
|
|
143
|
+
/** What an aborted step streamed: the one step `steps` does not hold whole. */
|
|
144
|
+
readonly partialContent?: readonly ModelAssistantPart[]
|
|
145
|
+
readonly aborted?: boolean
|
|
146
|
+
readonly run: ConversationAgentRunRecord
|
|
147
|
+
readonly deliveries: readonly TurnInboxDelivery[]
|
|
148
|
+
/** The first step whose request the context guard reduced: it and those after it are marked. */
|
|
149
|
+
readonly reducedFromStep?: number
|
|
150
|
+
readonly stepRequests: readonly (AgentStepRequestSize | undefined)[]
|
|
151
|
+
readonly outputFileOf?: AgentToolOutputFileOf
|
|
152
|
+
readonly authorPrincipal?: Principal
|
|
153
|
+
}): readonly AppendAgentMessageInput[] {
|
|
154
|
+
const { steps, run, deliveries, reducedFromStep, stepRequests, outputFileOf } = input
|
|
155
|
+
const details = { threadId: run.threadId, runId: run.id }
|
|
156
|
+
const messages: AppendAgentMessageInput[] = []
|
|
157
|
+
|
|
158
|
+
const pushSteps = (parts: readonly AgentMessagePart[], from: number, to: number) => {
|
|
159
|
+
const marked = recordStepRequests(
|
|
160
|
+
markReducedSteps(parts, reducedFromStep === undefined ? undefined : reducedFromStep - from),
|
|
161
|
+
stepRequests.slice(from, to)
|
|
162
|
+
)
|
|
163
|
+
if (!marked.some((part) => part.type !== "step-start")) return
|
|
164
|
+
|
|
165
|
+
messages.push({
|
|
166
|
+
id: createAgentMessageId(),
|
|
167
|
+
projectId: run.projectId,
|
|
168
|
+
threadId: run.threadId,
|
|
169
|
+
runId: run.id,
|
|
170
|
+
role: "assistant",
|
|
171
|
+
parts: marked,
|
|
172
|
+
...(input.authorPrincipal === undefined ? {} : { authorPrincipal: input.authorPrincipal }),
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// A delivery no step followed reads unread: the turn stopped before the model answered it.
|
|
177
|
+
const answered = (delivery: TurnInboxDelivery) => {
|
|
178
|
+
if (steps.length > delivery.afterSteps) return true
|
|
179
|
+
return input.aborted === true && (input.partialContent?.length ?? 0) > 0
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
let from = 0
|
|
183
|
+
for (const delivery of deliveries) {
|
|
184
|
+
pushSteps(
|
|
185
|
+
agentTraceFromModelSteps(steps.slice(from, delivery.afterSteps), details, outputFileOf),
|
|
186
|
+
from,
|
|
187
|
+
delivery.afterSteps
|
|
188
|
+
)
|
|
189
|
+
from = delivery.afterSteps
|
|
190
|
+
if (!answered(delivery)) break
|
|
191
|
+
|
|
192
|
+
for (const item of delivery.items) {
|
|
193
|
+
messages.push(savedSteer(item))
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const rest = steps.slice(from)
|
|
198
|
+
pushSteps(
|
|
199
|
+
input.aborted === true
|
|
200
|
+
? agentTraceFromPartialModelLoop(rest, input.partialContent ?? [], details, outputFileOf)
|
|
201
|
+
: agentTraceFromModelSteps(rest, details, outputFileOf),
|
|
202
|
+
from,
|
|
203
|
+
stepRequests.length
|
|
204
|
+
)
|
|
205
|
+
return messages
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The rows a turn finishes with, for the model loop it just ran. */
|
|
209
|
+
export function turnResultMessages(
|
|
210
|
+
result: PausableModelLoopResult,
|
|
211
|
+
input: Omit<Parameters<typeof turnWorkMessages>[0], "steps" | "partialContent" | "aborted">
|
|
212
|
+
): readonly AppendAgentMessageInput[] {
|
|
213
|
+
return result.status === "aborted"
|
|
214
|
+
? turnWorkMessages({
|
|
215
|
+
...input,
|
|
216
|
+
steps: result.steps,
|
|
217
|
+
partialContent: result.partialContent,
|
|
218
|
+
aborted: true,
|
|
219
|
+
})
|
|
220
|
+
: turnWorkMessages({ ...input, steps: result.steps })
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* A steer as the thread keeps it: a user message of no run, authored by whoever sent it, with the
|
|
225
|
+
* time zone and locale its `<sixb_current_time>` was rendered in.
|
|
226
|
+
*/
|
|
227
|
+
function savedSteer(item: AgentInboxItemRecord): AppendAgentMessageInput {
|
|
228
|
+
const metadata =
|
|
229
|
+
item.timeZone === undefined && item.locale === undefined
|
|
230
|
+
? undefined
|
|
231
|
+
: {
|
|
232
|
+
...(item.timeZone === undefined ? {} : { timeZone: item.timeZone }),
|
|
233
|
+
...(item.locale === undefined ? {} : { locale: item.locale }),
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
id: item.messageId,
|
|
237
|
+
projectId: item.projectId,
|
|
238
|
+
threadId: item.threadId,
|
|
239
|
+
runId: null,
|
|
240
|
+
role: "user",
|
|
241
|
+
parts: item.parts,
|
|
242
|
+
authorPrincipal: item.authorPrincipal,
|
|
243
|
+
createdAt: item.createdAt,
|
|
244
|
+
...(metadata === undefined ? {} : { metadata }),
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Mark each step from `fromStep` on as answering a request the turn reduced, for the next turn's
|
|
250
|
+
* estimate not to go by what those calls read.
|
|
251
|
+
*/
|
|
252
|
+
export function markReducedSteps(
|
|
253
|
+
parts: readonly AgentMessagePart[],
|
|
254
|
+
fromStep: number | undefined
|
|
255
|
+
): readonly AgentMessagePart[] {
|
|
256
|
+
if (fromStep === undefined) return parts
|
|
257
|
+
|
|
258
|
+
let step = -1
|
|
259
|
+
return parts.map((part) => {
|
|
260
|
+
if (part.type !== "step-start") return part
|
|
261
|
+
|
|
262
|
+
step += 1
|
|
263
|
+
return step >= fromStep ? { type: "step-start", reducedRequest: true } : part
|
|
264
|
+
})
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Record on each step-start what its request carried, by step: the next turn's context meter
|
|
269
|
+
* reads the system prompt and tools the latest one sent.
|
|
270
|
+
*/
|
|
271
|
+
export function recordStepRequests(
|
|
272
|
+
parts: readonly AgentMessagePart[],
|
|
273
|
+
requests: readonly (AgentStepRequestSize | undefined)[]
|
|
274
|
+
): readonly AgentMessagePart[] {
|
|
275
|
+
let step = -1
|
|
276
|
+
return parts.map((part) => {
|
|
277
|
+
if (part.type !== "step-start") return part
|
|
278
|
+
|
|
279
|
+
step += 1
|
|
280
|
+
const request = requests[step]
|
|
281
|
+
return request ? { ...part, request } : part
|
|
282
|
+
})
|
|
283
|
+
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { BlobStorage, Sandbox } from "@sixb/core";
|
|
2
|
-
import type { AgentRunMissingPreview } from "@sixb/core/internal/agents";
|
|
3
|
-
import { type BoardPreviewInput, type MissingBoardPreview, type RefusedBoardPreview } from "@sixb/core/internal/artifacts/publish";
|
|
4
|
-
import type { ArtifactVersionRecord } from "@sixb/core/storage";
|
|
5
|
-
import type { AgentSandboxHandle } from "../sandbox-handle";
|
|
6
|
-
import { type CheckedPreview, type CheckedQuery } from "./layout-check/layout-check";
|
|
7
|
-
/** The pictures read and stored, and those that were not, with why. */
|
|
8
|
-
export interface CheckedPreviews {
|
|
9
|
-
readonly previews: readonly BoardPreviewInput[];
|
|
10
|
-
readonly dropped: readonly RefusedBoardPreview[];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* The pictures the check took that `missing` asks for, read out of the sandbox a batch at a time
|
|
14
|
-
* and each stored in `blobStorage`. A picture the check did not take is left out: the worker
|
|
15
|
-
* renders it later. Each stands alone: one too large or that cannot be read or stored is dropped,
|
|
16
|
-
* and returned with why, and the others are kept.
|
|
17
|
-
*/
|
|
18
|
-
export declare function storeCheckedPreviews(input: {
|
|
19
|
-
readonly handle: AgentSandboxHandle;
|
|
20
|
-
readonly checked: readonly CheckedPreview[];
|
|
21
|
-
readonly missing: readonly AgentRunMissingPreview[];
|
|
22
|
-
readonly blobStorage: Pick<BlobStorage, "put">;
|
|
23
|
-
readonly signal: AbortSignal;
|
|
24
|
-
}): Promise<CheckedPreviews>;
|
|
25
|
-
/**
|
|
26
|
-
* Renders the pictures a stored canvas version's boards miss, in `sandbox`, a blank one created
|
|
27
|
-
* for it: the version's files are written there, each missing board is opened in every mode it
|
|
28
|
-
* misses, and the pictures are stored in `blobStorage`. What the boards' queries return, `queries`
|
|
29
|
-
* holds as the version's publisher read them. Without them a board that reads a query is not
|
|
30
|
-
* pictured: it would show its queries rejecting, which no reader sees. A sandbox without the
|
|
31
|
-
* agent image's browser renders nothing.
|
|
32
|
-
*/
|
|
33
|
-
export declare function renderBoardPreviews(input: {
|
|
34
|
-
readonly sandbox: Sandbox;
|
|
35
|
-
readonly version: ArtifactVersionRecord;
|
|
36
|
-
readonly missing: readonly MissingBoardPreview[];
|
|
37
|
-
readonly blobStorage: Pick<BlobStorage, "put" | "open" | "stat">;
|
|
38
|
-
readonly queries?: Readonly<Record<string, CheckedQuery>>;
|
|
39
|
-
readonly signal: AbortSignal;
|
|
40
|
-
}): Promise<CheckedPreviews>;
|
|
41
|
-
//# sourceMappingURL=board-previews.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"board-previews.d.ts","sourceRoot":"","sources":["../../src/artifacts/board-previews.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACxE,OAAO,EAGL,KAAK,iBAAiB,EAEtB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAG/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,YAAY,EAAe,MAAM,6BAA6B,CAAA;AAiBjG,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAA;IAC/C,QAAQ,CAAC,OAAO,EAAE,SAAS,mBAAmB,EAAE,CAAA;CACjD;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE;IAChD,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;IACnC,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;IAC3C,QAAQ,CAAC,OAAO,EAAE,SAAS,sBAAsB,EAAE,CAAA;IACnD,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;IAC9C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B,GAAG,OAAO,CAAC,eAAe,CAAC,CAwD3B;AAqBD;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAA;IACvC,QAAQ,CAAC,OAAO,EAAE,SAAS,mBAAmB,EAAE,CAAA;IAChD,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC,CAAA;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAA;IACzD,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAC7B,GAAG,OAAO,CAAC,eAAe,CAAC,CAmD3B"}
|