@sixb/agent 0.2.3 → 0.2.5
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 +3 -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 +26 -44
- package/dist/artifacts/publish-tool.d.ts.map +1 -1
- package/dist/ask-tool.d.ts +62 -0
- package/dist/ask-tool.d.ts.map +1 -0
- package/dist/attachments.d.ts +1 -1
- package/dist/attachments.d.ts.map +1 -1
- package/dist/background-commands.d.ts +3 -3
- package/dist/background-commands.d.ts.map +1 -1
- package/dist/background-notices.d.ts.map +1 -1
- package/dist/child-files.d.ts +1 -1
- package/dist/child-questions.d.ts +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10457 -7971
- package/dist/index.js.map +46 -38
- 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 +4 -1
- package/dist/run-environment.d.ts.map +1 -1
- package/dist/run-subagent.d.ts +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 +20 -1
- package/dist/subagent-tools.d.ts.map +1 -1
- package/dist/tools/background.d.ts +50 -18
- package/dist/tools/background.d.ts.map +1 -1
- package/dist/tools/bash.d.ts +1 -0
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/edit-text.d.ts +22 -0
- package/dist/tools/edit-text.d.ts.map +1 -0
- package/dist/tools/edit.d.ts +54 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/file-writes.d.ts +52 -0
- package/dist/tools/file-writes.d.ts.map +1 -0
- 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/read.d.ts +16 -3
- package/dist/tools/read.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/tools/view-file.d.ts +20 -23
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools/web-fetch/tool.d.ts +1 -0
- package/dist/tools/web-fetch/tool.d.ts.map +1 -1
- package/dist/tools/web-search.d.ts +1 -0
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/write.d.ts +36 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/turn-inbox.d.ts +75 -0
- package/dist/turn-inbox.d.ts.map +1 -0
- package/package.json +6 -4
- package/src/agent-prompt.ts +10 -9
- 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 +123 -192
- package/src/ask-tool.ts +223 -0
- package/src/attachments.ts +7 -6
- package/src/background-commands.ts +5 -5
- package/src/background-notices.ts +5 -12
- package/src/child-files.ts +1 -1
- package/src/child-questions.ts +1 -1
- package/src/context-compaction.ts +4 -1
- package/src/generated/search.mjs +985 -0
- package/src/index.ts +1 -2
- package/src/run-agent-turn.ts +99 -133
- package/src/run-child.ts +1 -1
- package/src/run-conversation-turn.ts +8 -5
- package/src/run-environment.ts +40 -21
- package/src/run-subagent.ts +4 -4
- package/src/sandbox-api-context.ts +3 -0
- 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 +13 -13
- package/src/skills/sixb-artifacts/canvas.md +5 -4
- 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/page.md +2 -2
- package/src/skills/sixb-artifacts/queries.md +2 -1
- package/src/skills/sixb-artifacts/slides.md +2 -2
- package/src/subagent-tools.ts +115 -81
- package/src/tools/background.ts +227 -67
- package/src/tools/bash.ts +2 -1
- package/src/tools/edit-text.ts +241 -0
- package/src/tools/edit.ts +166 -0
- package/src/tools/file-writes.ts +270 -0
- package/src/tools/glob.ts +124 -0
- package/src/tools/grep.ts +190 -0
- package/src/tools/model-spec.ts +13 -13
- package/src/tools/read.ts +75 -9
- 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 +9 -4
- package/src/tools/view-file.ts +78 -80
- package/src/tools/web-fetch/tool.ts +2 -1
- package/src/tools/web-search.ts +1 -0
- package/src/tools/write.ts +95 -0
- 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/dist/ask-parent-tool.d.ts +0 -36
- package/dist/ask-parent-tool.d.ts.map +0 -1
- package/src/artifacts/board-previews.ts +0 -218
- package/src/ask-parent-tool.ts +0 -100
package/src/tools/web-search.ts
CHANGED
|
@@ -15,6 +15,7 @@ const MAX_QUERY_CHARACTERS = 2_000
|
|
|
15
15
|
|
|
16
16
|
export const WEB_SEARCH_TOOL_SPEC = {
|
|
17
17
|
name: "web_search",
|
|
18
|
+
strict: true,
|
|
18
19
|
description:
|
|
19
20
|
"Search the web for current or external information. Returns up to 8 results, each a title, URL, date and snippet.",
|
|
20
21
|
inputSchema: {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { JsonObject, JsonValue, ModelTool } from "@sixb/core/models"
|
|
2
|
+
import { agentToolErrorText } from "../model-adapters"
|
|
3
|
+
import type { AgentSandboxHandle } from "../sandbox-handle"
|
|
4
|
+
import { assertReadAsIs, objectInput, pathInput } from "./edit"
|
|
5
|
+
import {
|
|
6
|
+
commitSandboxFile,
|
|
7
|
+
type FileReadLedger,
|
|
8
|
+
loadSandboxFile,
|
|
9
|
+
MAX_EDITED_FILE_BYTES,
|
|
10
|
+
publicError,
|
|
11
|
+
} from "./file-writes"
|
|
12
|
+
|
|
13
|
+
export const WRITE_TOOL_SPEC = {
|
|
14
|
+
name: "write",
|
|
15
|
+
strict: true,
|
|
16
|
+
description:
|
|
17
|
+
"Create a file, or replace one whole; missing parent directories are created. Replacing an existing file needs a read of it first. To change part of a file, use edit.",
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: "object",
|
|
20
|
+
properties: {
|
|
21
|
+
path: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description:
|
|
24
|
+
"Path relative to the working directory, or an absolute path in the run's context directory.",
|
|
25
|
+
},
|
|
26
|
+
content: { type: "string", description: "The file's whole new contents." },
|
|
27
|
+
},
|
|
28
|
+
required: ["path", "content"],
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
} satisfies JsonObject,
|
|
31
|
+
} as const
|
|
32
|
+
|
|
33
|
+
export interface WriteToolInput {
|
|
34
|
+
readonly path: string
|
|
35
|
+
readonly content: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface WriteToolOutput {
|
|
39
|
+
readonly path: string
|
|
40
|
+
/** True when the file did not exist before. */
|
|
41
|
+
readonly created: boolean
|
|
42
|
+
readonly lines: number
|
|
43
|
+
readonly bytes: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createWriteTool(
|
|
47
|
+
resolveSandbox: () => Promise<AgentSandboxHandle>,
|
|
48
|
+
ledger: FileReadLedger
|
|
49
|
+
): ModelTool<WriteToolInput> {
|
|
50
|
+
return {
|
|
51
|
+
...WRITE_TOOL_SPEC,
|
|
52
|
+
parseInput: parseWriteInput,
|
|
53
|
+
async execute(input, { signal }): Promise<JsonValue> {
|
|
54
|
+
const bytes = new TextEncoder().encode(input.content)
|
|
55
|
+
if (bytes.byteLength > MAX_EDITED_FILE_BYTES) {
|
|
56
|
+
throw publicError(
|
|
57
|
+
"write",
|
|
58
|
+
`content is larger than ${MAX_EDITED_FILE_BYTES / 1024 / 1024} MiB: write it with bash.`
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
const handle = await resolveSandbox()
|
|
62
|
+
const loaded = await loadSandboxFile(handle, { path: input.path, tool: "write", signal })
|
|
63
|
+
if (loaded.kind === "file") assertReadAsIs(ledger, loaded, input.path, "write")
|
|
64
|
+
|
|
65
|
+
const written = await commitSandboxFile(handle, {
|
|
66
|
+
path: loaded.kind === "file" ? loaded.realPath : input.path,
|
|
67
|
+
expected: loaded.kind === "file" ? loaded.fingerprint : "missing",
|
|
68
|
+
bytes,
|
|
69
|
+
tool: "write",
|
|
70
|
+
signal,
|
|
71
|
+
})
|
|
72
|
+
ledger.record(written.realPath, written.fingerprint)
|
|
73
|
+
return {
|
|
74
|
+
path: input.path,
|
|
75
|
+
created: loaded.kind === "missing",
|
|
76
|
+
lines: lineCount(input.content),
|
|
77
|
+
bytes: bytes.byteLength,
|
|
78
|
+
} satisfies WriteToolOutput
|
|
79
|
+
},
|
|
80
|
+
errorText: agentToolErrorText,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function lineCount(content: string): number {
|
|
85
|
+
if (content === "") return 0
|
|
86
|
+
const newlines = content.split("\n").length - 1
|
|
87
|
+
return content.endsWith("\n") ? newlines : newlines + 1
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function parseWriteInput(value: unknown): WriteToolInput {
|
|
91
|
+
const input = objectInput(value, "write", ["path", "content"])
|
|
92
|
+
const path = pathInput(input.path, "write")
|
|
93
|
+
if (typeof input.content !== "string") throw publicError("write", "content must be a string.")
|
|
94
|
+
return { path, content: input.content }
|
|
95
|
+
}
|
|
@@ -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"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { type AgentMessage } from "@sixb/core";
|
|
2
|
-
import { type ModelTool } from "@sixb/core/models";
|
|
3
|
-
import type { SubagentInbox } from "./subagent-inbox";
|
|
4
|
-
export interface AskParentInput {
|
|
5
|
-
readonly question: string;
|
|
6
|
-
}
|
|
7
|
-
/** What `ask_parent` answers: the parent's answer, or that it comes in a later turn. */
|
|
8
|
-
export type AskParentOutput = {
|
|
9
|
-
readonly answer: string;
|
|
10
|
-
}
|
|
11
|
-
/** `question`: its id, which the answer of a later turn replies to. */
|
|
12
|
-
| {
|
|
13
|
-
readonly status: "deferred";
|
|
14
|
-
readonly question: string;
|
|
15
|
-
readonly note: string;
|
|
16
|
-
}
|
|
17
|
-
/** It paused on a held call too: only a decision continues it, without an answer. */
|
|
18
|
-
| {
|
|
19
|
-
readonly status: "unanswered";
|
|
20
|
-
readonly question: string;
|
|
21
|
-
readonly note: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* What a question deferred in the step that held a call reads as once the child continues: the
|
|
25
|
-
* decision continues it, and no answer comes with it. Only a continuation reads it, as the child
|
|
26
|
-
* paused right after that step, so what its thread keeps may say so without changing a byte the
|
|
27
|
-
* model already read.
|
|
28
|
-
*/
|
|
29
|
-
export declare function unansweredQuestion<TMessage extends Pick<AgentMessage, "parts">>(messages: readonly TMessage[]): readonly TMessage[];
|
|
30
|
-
/**
|
|
31
|
-
* A child's question to its parent, which it waits for within its step. Its parent answers with
|
|
32
|
-
* `message_agent`; when its turn ends first, the child pauses on the question and a later turn
|
|
33
|
-
* continues it with the answer.
|
|
34
|
-
*/
|
|
35
|
-
export declare function createAskParentTool(inbox: SubagentInbox): ModelTool<AskParentInput>;
|
|
36
|
-
//# sourceMappingURL=ask-parent-tool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ask-parent-tool.d.ts","sourceRoot":"","sources":["../src/ask-parent-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAwB,MAAM,YAAY,CAAA;AACpE,OAAO,EAAiC,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAEjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAED,wFAAwF;AACxF,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE;AAC7B,uEAAuE;GACrE;IAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AACnF,qFAAqF;GACnF;IAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AASvF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,EAC7E,QAAQ,EAAE,SAAS,QAAQ,EAAE,GAC5B,SAAS,QAAQ,EAAE,CAiBrB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,CAAC,cAAc,CAAC,CA+BnF"}
|