@sixb/agent 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/abort.d.ts +6 -0
- package/dist/abort.d.ts.map +1 -0
- package/dist/agent-prompt.d.ts +120 -0
- package/dist/agent-prompt.d.ts.map +1 -0
- package/dist/agent-runtime/errors.d.ts +13 -0
- package/dist/agent-runtime/errors.d.ts.map +1 -0
- package/dist/agent-runtime/preflight.d.ts +18 -0
- package/dist/agent-runtime/preflight.d.ts.map +1 -0
- package/dist/agent-runtime/profile.d.ts +14 -0
- package/dist/agent-runtime/profile.d.ts.map +1 -0
- package/dist/artifacts/layout-check/layout-check.d.ts +87 -0
- package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -0
- package/dist/artifacts/materialize.d.ts +115 -0
- package/dist/artifacts/materialize.d.ts.map +1 -0
- package/dist/artifacts/publish-tool.d.ts +86 -0
- package/dist/artifacts/publish-tool.d.ts.map +1 -0
- package/dist/ask-parent-tool.d.ts +36 -0
- package/dist/ask-parent-tool.d.ts.map +1 -0
- package/dist/attachments.d.ts +68 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/child-files.d.ts +96 -0
- package/dist/child-files.d.ts.map +1 -0
- package/dist/child-questions.d.ts +24 -0
- package/dist/child-questions.d.ts.map +1 -0
- package/dist/computer-runner.d.ts +65 -0
- package/dist/computer-runner.d.ts.map +1 -0
- package/dist/context-budget.d.ts +28 -0
- package/dist/context-budget.d.ts.map +1 -0
- package/dist/context-compaction.d.ts +48 -0
- package/dist/context-compaction.d.ts.map +1 -0
- package/dist/conversation-memory.d.ts +21 -0
- package/dist/conversation-memory.d.ts.map +1 -0
- package/dist/errors.d.ts +46 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/execution-plan.d.ts +34 -0
- package/dist/execution-plan.d.ts.map +1 -0
- package/dist/failure.d.ts +14 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/family-mailbox.d.ts +60 -0
- package/dist/family-mailbox.d.ts.map +1 -0
- package/dist/file-ref.d.ts +6 -0
- package/dist/file-ref.d.ts.map +1 -0
- package/dist/image-attachments.d.ts +34 -0
- package/dist/image-attachments.d.ts.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12168 -0
- package/dist/index.js.map +65 -0
- package/dist/message-authors.d.ts +34 -0
- package/dist/message-authors.d.ts.map +1 -0
- package/dist/message-times.d.ts +8 -0
- package/dist/message-times.d.ts.map +1 -0
- package/dist/model-adapters.d.ts +55 -0
- package/dist/model-adapters.d.ts.map +1 -0
- package/dist/model-lines.d.ts +16 -0
- package/dist/model-lines.d.ts.map +1 -0
- package/dist/requester.d.ts +15 -0
- package/dist/requester.d.ts.map +1 -0
- package/dist/run-agent-turn.d.ts +63 -0
- package/dist/run-agent-turn.d.ts.map +1 -0
- package/dist/run-child.d.ts +77 -0
- package/dist/run-child.d.ts.map +1 -0
- package/dist/run-conversation-turn.d.ts +42 -0
- package/dist/run-conversation-turn.d.ts.map +1 -0
- package/dist/run-credential.d.ts +22 -0
- package/dist/run-credential.d.ts.map +1 -0
- package/dist/run-environment.d.ts +115 -0
- package/dist/run-environment.d.ts.map +1 -0
- package/dist/run-fate.d.ts +15 -0
- package/dist/run-fate.d.ts.map +1 -0
- package/dist/run-sandbox.d.ts +60 -0
- package/dist/run-sandbox.d.ts.map +1 -0
- package/dist/run-subagent.d.ts +51 -0
- package/dist/run-subagent.d.ts.map +1 -0
- package/dist/run-workflow-agent-node.d.ts +41 -0
- package/dist/run-workflow-agent-node.d.ts.map +1 -0
- package/dist/sandbox-api-context.d.ts +34 -0
- package/dist/sandbox-api-context.d.ts.map +1 -0
- package/dist/sandbox-file-registry.d.ts +9 -0
- package/dist/sandbox-file-registry.d.ts.map +1 -0
- package/dist/sandbox-files.d.ts +71 -0
- package/dist/sandbox-files.d.ts.map +1 -0
- package/dist/sandbox-handle.d.ts +15 -0
- package/dist/sandbox-handle.d.ts.map +1 -0
- package/dist/sandbox-readiness.d.ts +8 -0
- package/dist/sandbox-readiness.d.ts.map +1 -0
- package/dist/skills/built-in.d.ts +15 -0
- package/dist/skills/built-in.d.ts.map +1 -0
- package/dist/subagent-continuation.d.ts +27 -0
- package/dist/subagent-continuation.d.ts.map +1 -0
- package/dist/subagent-inbox.d.ts +53 -0
- package/dist/subagent-inbox.d.ts.map +1 -0
- package/dist/subagent-tools.d.ts +282 -0
- package/dist/subagent-tools.d.ts.map +1 -0
- package/dist/thread-context.d.ts +12 -0
- package/dist/thread-context.d.ts.map +1 -0
- package/dist/tools/attachments.d.ts +11 -0
- package/dist/tools/attachments.d.ts.map +1 -0
- package/dist/tools/bash.d.ts +60 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/model-spec.d.ts +4 -0
- package/dist/tools/model-spec.d.ts.map +1 -0
- package/dist/tools/read.d.ts +43 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/result-media.d.ts +22 -0
- package/dist/tools/result-media.d.ts.map +1 -0
- package/dist/tools/result-output.d.ts +18 -0
- package/dist/tools/result-output.d.ts.map +1 -0
- package/dist/tools/tool-files.d.ts +59 -0
- package/dist/tools/tool-files.d.ts.map +1 -0
- package/dist/tools/view-file.d.ts +40 -0
- package/dist/tools/view-file.d.ts.map +1 -0
- package/dist/tsconfig.json +5 -0
- package/dist/turn-runtime.d.ts +19 -0
- package/dist/turn-runtime.d.ts.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/workflow-input-attachments.d.ts +18 -0
- package/dist/workflow-input-attachments.d.ts.map +1 -0
- package/package.json +59 -4
- package/src/abort.ts +40 -0
- package/src/agent-prompt.ts +758 -0
- package/src/agent-runtime/errors.ts +44 -0
- package/src/agent-runtime/preflight.ts +314 -0
- package/src/agent-runtime/profile.ts +23 -0
- package/src/artifacts/layout-check/check.cjs +478 -0
- package/src/artifacts/layout-check/layout-check.ts +460 -0
- package/src/artifacts/materialize.ts +380 -0
- package/src/artifacts/publish-tool.ts +700 -0
- package/src/ask-parent-tool.ts +100 -0
- package/src/attachments.ts +850 -0
- package/src/child-files.ts +540 -0
- package/src/child-questions.ts +42 -0
- package/src/computer-runner.ts +284 -0
- package/src/context-budget.ts +161 -0
- package/src/context-compaction.ts +529 -0
- package/src/conversation-memory.ts +45 -0
- package/src/errors.ts +85 -0
- package/src/execution-plan.ts +50 -0
- package/src/failure.ts +71 -0
- package/src/family-mailbox.ts +189 -0
- package/src/file-ref.ts +18 -0
- package/src/image-attachments.ts +322 -0
- package/src/index.ts +54 -0
- package/src/message-authors.ts +77 -0
- package/src/message-times.ts +21 -0
- package/src/model-adapters.ts +227 -0
- package/src/model-lines.ts +28 -0
- package/src/requester.ts +21 -0
- package/src/run-agent-turn.ts +347 -0
- package/src/run-child.ts +319 -0
- package/src/run-conversation-turn.ts +257 -0
- package/src/run-credential.ts +55 -0
- package/src/run-environment.ts +769 -0
- package/src/run-fate.ts +51 -0
- package/src/run-sandbox.ts +63 -0
- package/src/run-subagent.ts +347 -0
- package/src/run-workflow-agent-node.ts +270 -0
- package/src/sandbox-api-context.ts +234 -0
- package/src/sandbox-file-registry.ts +26 -0
- package/src/sandbox-files.ts +326 -0
- package/src/sandbox-handle.ts +19 -0
- package/src/sandbox-readiness.ts +22 -0
- package/src/skills/built-in.ts +183 -0
- package/src/skills/sixb-artifacts/SKILL.md +95 -0
- package/src/skills/sixb-artifacts/canvas.md +104 -0
- package/src/skills/sixb-artifacts/document.md +63 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/first-job.html +42 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/region.html +29 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/shared.css +35 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/welcome.html +31 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/canvas.json +107 -0
- package/src/skills/sixb-artifacts/examples/canvas/retro/canvas.json +158 -0
- package/src/skills/sixb-artifacts/examples/document/incident-report/document.md +35 -0
- package/src/skills/sixb-artifacts/examples/document/operations-review/document.md +41 -0
- package/src/skills/sixb-artifacts/examples/document/operations-review/figures/restorations.svg +1 -0
- package/src/skills/sixb-artifacts/examples/page/collections-desk/index.html +169 -0
- package/src/skills/sixb-artifacts/examples/page/collections-desk/queries/overdue.json +13 -0
- package/src/skills/sixb-artifacts/examples/page/dispatch-board/data/dispatch.json +234 -0
- package/src/skills/sixb-artifacts/examples/page/dispatch-board/index.html +245 -0
- package/src/skills/sixb-artifacts/examples/page/fleet-planner/data/plan.json +53 -0
- package/src/skills/sixb-artifacts/examples/page/fleet-planner/index.html +462 -0
- package/src/skills/sixb-artifacts/examples/page/service-explorer/data/service.json +276 -0
- package/src/skills/sixb-artifacts/examples/page/service-explorer/index.html +549 -0
- package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/queries/overdue.json +13 -0
- package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/workbook.json +30 -0
- package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Inventory.csv +13 -0
- package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Spend.csv +6 -0
- package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/workbook.json +47 -0
- package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Quarters.csv +5 -0
- package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Regions.csv +5 -0
- package/src/skills/sixb-artifacts/examples/sheet/service-metrics/workbook.json +78 -0
- package/src/skills/sixb-artifacts/examples/slides/launch-plan/index.html +63 -0
- package/src/skills/sixb-artifacts/examples/slides/q3-review/index.html +133 -0
- package/src/skills/sixb-artifacts/file.md +17 -0
- package/src/skills/sixb-artifacts/page.md +215 -0
- package/src/skills/sixb-artifacts/queries.md +66 -0
- package/src/skills/sixb-artifacts/references.md +68 -0
- package/src/skills/sixb-artifacts/sheet.md +223 -0
- package/src/skills/sixb-artifacts/slides.md +137 -0
- package/src/skills/sixb-memory/SKILL.md +68 -0
- package/src/skills/text-assets.d.ts +25 -0
- package/src/subagent-continuation.ts +51 -0
- package/src/subagent-inbox.ts +101 -0
- package/src/subagent-tools.ts +1609 -0
- package/src/thread-context.ts +25 -0
- package/src/tools/attachments.ts +28 -0
- package/src/tools/bash.ts +217 -0
- package/src/tools/model-spec.ts +22 -0
- package/src/tools/read.ts +262 -0
- package/src/tools/result-media.ts +147 -0
- package/src/tools/result-output.ts +44 -0
- package/src/tools/tool-files.ts +204 -0
- package/src/tools/view-file.ts +155 -0
- package/src/turn-runtime.ts +33 -0
- package/src/types.ts +79 -0
- package/src/workflow-input-attachments.ts +140 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { posix } from "node:path"
|
|
2
|
+
import type { FileRef } from "@sixb/core"
|
|
3
|
+
import { isFileRef } from "@sixb/core"
|
|
4
|
+
import type { AgentRunFileStore } from "@sixb/core/internal/agents"
|
|
5
|
+
import type { WorkflowIOSnapshot } from "@sixb/core/internal/workflows"
|
|
6
|
+
import { waitForAbort } from "./abort"
|
|
7
|
+
import type { PreparedAgentAttachmentContext } from "./attachments"
|
|
8
|
+
|
|
9
|
+
const MAX_WORKFLOW_ATTACHMENT_BYTES = 25 * 1024 * 1024
|
|
10
|
+
const MAX_WORKFLOW_ATTACHMENTS_TOTAL_BYTES = 100 * 1024 * 1024
|
|
11
|
+
|
|
12
|
+
/** Materialize nested FileRefs from a workflow input into the headless task sandbox. */
|
|
13
|
+
export async function prepareWorkflowInputAttachments(input: {
|
|
14
|
+
readonly input: WorkflowIOSnapshot
|
|
15
|
+
readonly blobStorage: AgentRunFileStore
|
|
16
|
+
/** Where the run's files go: the input's files are materialized in it. */
|
|
17
|
+
readonly contextDirectory: string
|
|
18
|
+
readonly signal?: AbortSignal
|
|
19
|
+
}): Promise<PreparedAgentAttachmentContext> {
|
|
20
|
+
const refs = workflowInputFileRefs(input.input)
|
|
21
|
+
const sandboxFiles: PreparedAgentAttachmentContext["sandboxFiles"] extends readonly (infer T)[]
|
|
22
|
+
? T[]
|
|
23
|
+
: never = []
|
|
24
|
+
const manifest: Array<Record<string, unknown>> = []
|
|
25
|
+
let totalBytes = 0
|
|
26
|
+
|
|
27
|
+
for (const [index, item] of refs.entries()) {
|
|
28
|
+
input.signal?.throwIfAborted()
|
|
29
|
+
const stat = await waitForAbort(input.blobStorage.stat(item.fileRef.blobId), input.signal)
|
|
30
|
+
if (
|
|
31
|
+
!stat ||
|
|
32
|
+
stat.digest !== item.fileRef.digest ||
|
|
33
|
+
stat.sizeBytes !== item.fileRef.sizeBytes ||
|
|
34
|
+
stat.sizeBytes > MAX_WORKFLOW_ATTACHMENT_BYTES ||
|
|
35
|
+
totalBytes + stat.sizeBytes > MAX_WORKFLOW_ATTACHMENTS_TOTAL_BYTES
|
|
36
|
+
) {
|
|
37
|
+
manifest.push({ key: item.path, path: item.path, fileRef: item.fileRef, materialized: false })
|
|
38
|
+
continue
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const bytes = await readAllBytes(
|
|
42
|
+
await waitForAbort(input.blobStorage.open(item.fileRef.blobId), input.signal),
|
|
43
|
+
stat.sizeBytes,
|
|
44
|
+
input.signal
|
|
45
|
+
)
|
|
46
|
+
const fileName = safeFileName(item.fileRef.fileName ?? `${item.fileRef.blobId}.bin`)
|
|
47
|
+
const sandboxPath = posix.join(
|
|
48
|
+
input.contextDirectory,
|
|
49
|
+
"attachments/workflow-input",
|
|
50
|
+
`${index}-${fileName}`
|
|
51
|
+
)
|
|
52
|
+
sandboxFiles.push({ key: item.path, path: sandboxPath, bytes, fileRef: item.fileRef })
|
|
53
|
+
totalBytes += bytes.byteLength
|
|
54
|
+
manifest.push({
|
|
55
|
+
key: item.path,
|
|
56
|
+
path: item.path,
|
|
57
|
+
fileRef: item.fileRef,
|
|
58
|
+
materialized: true,
|
|
59
|
+
sandboxPath,
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
entries: [],
|
|
65
|
+
promptTextByPartKey: new Map(),
|
|
66
|
+
modelFileDataByPartKey: new Map(),
|
|
67
|
+
sandboxFiles,
|
|
68
|
+
manifestJson: JSON.stringify({ attachments: manifest }, null, 2),
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Every FileRef in a workflow input, keyed by its path such as `input.documents[0]`. */
|
|
73
|
+
export function workflowInputFileRefs(
|
|
74
|
+
input: WorkflowIOSnapshot
|
|
75
|
+
): readonly { readonly path: string; readonly fileRef: FileRef }[] {
|
|
76
|
+
const refs: Array<{ readonly path: string; readonly fileRef: FileRef }> = []
|
|
77
|
+
collectFileRefs(input, "input", refs)
|
|
78
|
+
return refs
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function collectFileRefs(
|
|
82
|
+
value: unknown,
|
|
83
|
+
path: string,
|
|
84
|
+
output: Array<{ readonly path: string; readonly fileRef: FileRef }>
|
|
85
|
+
): void {
|
|
86
|
+
if (isFileRef(value)) {
|
|
87
|
+
output.push({ path, fileRef: value })
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(value)) {
|
|
91
|
+
value.forEach((entry, index) => {
|
|
92
|
+
collectFileRefs(entry, `${path}[${index}]`, output)
|
|
93
|
+
})
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
if (typeof value === "object" && value !== null) {
|
|
97
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
98
|
+
collectFileRefs(entry, `${path}.${key}`, output)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function readAllBytes(
|
|
104
|
+
stream: ReadableStream<Uint8Array>,
|
|
105
|
+
expectedSize: number,
|
|
106
|
+
signal?: AbortSignal
|
|
107
|
+
): Promise<Uint8Array> {
|
|
108
|
+
const bytes = new Uint8Array(expectedSize)
|
|
109
|
+
const reader = stream.getReader()
|
|
110
|
+
let offset = 0
|
|
111
|
+
const cancelOnAbort = () => {
|
|
112
|
+
void reader.cancel(signal?.reason)
|
|
113
|
+
}
|
|
114
|
+
signal?.addEventListener("abort", cancelOnAbort, { once: true })
|
|
115
|
+
try {
|
|
116
|
+
for (;;) {
|
|
117
|
+
const { done, value } = await reader.read()
|
|
118
|
+
signal?.throwIfAborted()
|
|
119
|
+
if (done) break
|
|
120
|
+
if (offset + value.byteLength > expectedSize) {
|
|
121
|
+
throw new Error("Blob size changed while reading.")
|
|
122
|
+
}
|
|
123
|
+
bytes.set(value, offset)
|
|
124
|
+
offset += value.byteLength
|
|
125
|
+
}
|
|
126
|
+
} finally {
|
|
127
|
+
signal?.removeEventListener("abort", cancelOnAbort)
|
|
128
|
+
reader.releaseLock()
|
|
129
|
+
}
|
|
130
|
+
if (offset !== expectedSize) throw new Error("Blob size changed while reading.")
|
|
131
|
+
return bytes
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function safeFileName(value: string): string {
|
|
135
|
+
const name = value
|
|
136
|
+
.split(/[\\/]/)
|
|
137
|
+
.at(-1)
|
|
138
|
+
?.replace(/[^A-Za-z0-9._-]/g, "_")
|
|
139
|
+
return name || "attachment.bin"
|
|
140
|
+
}
|