@springbrand/agent-runtime 0.2.0-alpha.18 → 0.2.0-alpha.20
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/package.json +1 -1
- package/src/adapter/cloudflare/sandbox/adapter.ts +20 -5
- package/src/adapter/cloudflare/universal-agent/preparation.ts +32 -5
- package/src/db/schema.ts +10 -0
- package/src/db/submission.repo.ts +44 -1
- package/src/index.ts +3 -1
- package/src/kernel/bindings.ts +22 -13
- package/src/kernel/recoverable-chat-agent.ts +37 -11
- package/src/kernel/submission-lifecycle.ts +53 -10
- package/src/kernel/tool-surface.ts +41 -0
- package/src/layers/context/budget/gate.ts +57 -11
- package/src/lib/prompt.ts +32 -15
- package/src/pi/message/projection.ts +22 -4
- package/src/pi/runtime-adapter/execution.ts +115 -9
- package/src/pi/runtime-adapter/transcript.ts +7 -2
- package/src/pi/tool/compiler.ts +9 -5
- package/src/pi/tool/core-host.ts +102 -13
- package/src/pi/tool/core.ts +209 -61
- package/src/pi/tool/schedule.ts +3 -1
- package/src/pi/tool/skill.ts +88 -1
- package/src/pi/tool/workspace-sandbox.ts +136 -4
- package/src/runtime-assembler.ts +32 -8
- package/src/runtime.ts +251 -44
- package/src/skills/index.ts +14 -0
- package/src/skills/springbrand-worker-website/index.ts +73 -0
- package/src/tool-registry.ts +15 -32
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export const SPRINGBRAND_WORKER_WEBSITE_SKILL = {
|
|
2
|
+
name: "springbrand-worker-website",
|
|
3
|
+
description:
|
|
4
|
+
"Use when an Agent creates, restructures, previews, verifies, or deploys a Website in a SpringBrand Workspace; provide the complete Cloudflare Worker project layout, asset conventions, and browser validation workflow.",
|
|
5
|
+
body: [
|
|
6
|
+
"# SpringBrand Worker Website",
|
|
7
|
+
"",
|
|
8
|
+
"Keep the Website in one stable project directory under `/creations/<website-name>/`. Treat that directory as the complete deployable Website project, not as a directory containing only one HTML file.",
|
|
9
|
+
"",
|
|
10
|
+
"## Recommended layout",
|
|
11
|
+
"",
|
|
12
|
+
"When creating a new Website and no existing project structure needs to be preserved, prefer:",
|
|
13
|
+
"",
|
|
14
|
+
"```text",
|
|
15
|
+
"/creations/<website-name>/",
|
|
16
|
+
"├── wrangler.json",
|
|
17
|
+
"├── package.json",
|
|
18
|
+
"├── src/",
|
|
19
|
+
"│ ├── worker.ts",
|
|
20
|
+
"│ ├── routes/",
|
|
21
|
+
"│ ├── lib/",
|
|
22
|
+
"│ └── client/",
|
|
23
|
+
"└── public/",
|
|
24
|
+
" ├── index.html",
|
|
25
|
+
" ├── about/",
|
|
26
|
+
" │ └── index.html",
|
|
27
|
+
" ├── products/",
|
|
28
|
+
" │ └── index.html",
|
|
29
|
+
" ├── assets/",
|
|
30
|
+
" │ ├── css/",
|
|
31
|
+
" │ ├── js/",
|
|
32
|
+
" │ ├── images/",
|
|
33
|
+
" │ ├── fonts/",
|
|
34
|
+
" │ └── icons/",
|
|
35
|
+
" ├── data/",
|
|
36
|
+
" ├── favicon.ico",
|
|
37
|
+
" ├── robots.txt",
|
|
38
|
+
" └── manifest.webmanifest",
|
|
39
|
+
"```",
|
|
40
|
+
"",
|
|
41
|
+
"This is a recommended default, not a required layout. Preserve an existing valid framework or project convention such as `dist/`, `build/`, another Worker entry path, or another static asset directory, and configure Wrangler accordingly.",
|
|
42
|
+
"",
|
|
43
|
+
"## Project rules",
|
|
44
|
+
"",
|
|
45
|
+
"- Keep Worker configuration, package metadata, and build configuration at the Website project root.",
|
|
46
|
+
"- Keep Worker code, routes, application logic, and editable source files under `src/`.",
|
|
47
|
+
"- Keep browser-accessible, deployment-ready static files under `public/`.",
|
|
48
|
+
"- Use `public/index.html` as the recommended home page. Put additional pages under clear routes such as `public/about/index.html` and `public/products/index.html`.",
|
|
49
|
+
"- Put stylesheets, browser scripts, images, fonts, icons, and other static resources under the corresponding `public/assets/` subdirectory.",
|
|
50
|
+
"- Put publicly accessible static data under `public/data/` when needed.",
|
|
51
|
+
"- Keep every file required to build and deploy the Website inside its project directory.",
|
|
52
|
+
"- Do not duplicate the same entry page at both the project root and `public/`.",
|
|
53
|
+
"- Do not place secrets, temporary files, logs, raw tool output, or unprocessed attachments inside the Website project.",
|
|
54
|
+
"",
|
|
55
|
+
"## Worker and browser requirements",
|
|
56
|
+
"",
|
|
57
|
+
"- Configure Wrangler `main` to point to the actual Worker source file.",
|
|
58
|
+
"- Export `class App extends DurableObject` from that module when the Website uses the SpringBrand App Facet.",
|
|
59
|
+
"- Configure `assets.directory` to point to the actual browser asset directory, preferably `public/`.",
|
|
60
|
+
"- Use `./` or `../` for local Website files, never a root-relative Workspace path, so preview and deployed URL prefixes both work.",
|
|
61
|
+
"- Load CSS from HTML instead of importing it from browser JavaScript.",
|
|
62
|
+
"- Without a build step, load browser-native third-party ESM through a full pinned HTTPS URL or an import map to a pinned CORS-enabled CDN.",
|
|
63
|
+
"- With a build step, produce deployment-ready assets before preview instead of depending on a development server.",
|
|
64
|
+
"",
|
|
65
|
+
"## Workflow",
|
|
66
|
+
"",
|
|
67
|
+
"1. Inspect the existing Website directory before changing it and preserve valid conventions.",
|
|
68
|
+
"2. Create or update the complete project rather than only an entry HTML file.",
|
|
69
|
+
"3. Build when the project requires a build step.",
|
|
70
|
+
"4. Preview the Website through the available Workspace or Space capability.",
|
|
71
|
+
"5. When `browser_execute` is available, check runtime errors, failed resources, CSP violations, responsive layout, clipping, overlap, and visual hierarchy. Capture a screenshot when visual appearance matters, fix discovered problems, and verify once more.",
|
|
72
|
+
].join("\n"),
|
|
73
|
+
};
|
package/src/tool-registry.ts
CHANGED
|
@@ -1,51 +1,34 @@
|
|
|
1
|
-
import type { ExecutionLevel } from "./lib/execution-level";
|
|
2
1
|
import type {
|
|
3
|
-
|
|
2
|
+
RuntimeCodeExecutionFactory,
|
|
4
3
|
RuntimeMemoryPort,
|
|
5
4
|
RuntimeSubagentPort,
|
|
6
5
|
WorkspacePort,
|
|
7
6
|
} from "./kernel/bindings";
|
|
8
7
|
import type { RuntimeExtensionConfig } from "./kernel/extensions";
|
|
9
8
|
import type { RuntimeDegradation } from "./kernel/degradation";
|
|
9
|
+
import type {
|
|
10
|
+
ToolContext,
|
|
11
|
+
ToolRegistry,
|
|
12
|
+
ToolSpec,
|
|
13
|
+
} from "./kernel/tool-surface";
|
|
10
14
|
import type { PiToolCandidate } from "./pi/tool/compiler";
|
|
11
15
|
import { validateToolArguments } from "@earendil-works/pi-ai";
|
|
12
16
|
|
|
17
|
+
// Tool Surface 的形状类型住在 `kernel/tool-surface.ts`:bindings 也要用它们,放在这里
|
|
18
|
+
// 会让 `bindings → tool-registry → bindings` 成环。这里继续导出是为了保持调用方不变。
|
|
19
|
+
export type {
|
|
20
|
+
RuntimeCodeExecutionFactory,
|
|
21
|
+
ToolContext,
|
|
22
|
+
ToolRegistry,
|
|
23
|
+
ToolSpec,
|
|
24
|
+
};
|
|
25
|
+
|
|
13
26
|
/** Tool Surface 筛选策略(不含 Manifest deny 列表)。 */
|
|
14
27
|
export interface ToolSurfaceSelectionPolicy {
|
|
15
28
|
readonly allowsTool?: (name: string) => boolean;
|
|
16
29
|
readonly allowsExtension?: (extension: RuntimeExtensionConfig) => boolean;
|
|
17
30
|
}
|
|
18
31
|
|
|
19
|
-
/** 模型调用 Tool 时传给 `execute` 的上下文。 */
|
|
20
|
-
export interface ToolContext {
|
|
21
|
-
readonly toolCallId: string;
|
|
22
|
-
readonly signal: AbortSignal;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Definition 作者声明的一个 Tool。 */
|
|
26
|
-
export interface ToolSpec extends Partial<
|
|
27
|
-
Omit<PiToolCandidate, "tool" | "requiredExecutionLevel">
|
|
28
|
-
> {
|
|
29
|
-
readonly label: string;
|
|
30
|
-
readonly description: string;
|
|
31
|
-
readonly parameters: unknown;
|
|
32
|
-
readonly requiredExecutionLevel: ExecutionLevel;
|
|
33
|
-
/** Require a fresh human decision for every call, regardless of execution level. */
|
|
34
|
-
readonly alwaysRequiresApproval?: boolean;
|
|
35
|
-
readonly execute: (
|
|
36
|
-
input: unknown,
|
|
37
|
-
ctx: ToolContext,
|
|
38
|
-
) => Promise<unknown>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** 一次装配声明的全部 Tool,键即模型可见的工具名。 */
|
|
42
|
-
export type ToolRegistry = Record<string, ToolSpec>;
|
|
43
|
-
|
|
44
|
-
/** 延迟到最终 Tool Surface 完成后再创建 Code Mode 执行能力。 */
|
|
45
|
-
export interface RuntimeCodeExecutionFactory {
|
|
46
|
-
create(tools: ToolRegistry): RuntimeCodeExecutionPort;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
32
|
export function emptyToolRegistry(): ToolRegistry {
|
|
50
33
|
return {};
|
|
51
34
|
}
|