@re-cinq/floor-pipeline 0.5.6 → 0.6.1
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 +51 -4
- package/dist/agent-config-schema.d.ts +46 -0
- package/dist/agent-config-schema.js +45 -0
- package/dist/cli.js +30 -10
- package/dist/collection/agent-file.d.ts +36 -0
- package/dist/collection/agent-file.js +41 -0
- package/dist/collection/agents.d.ts +29 -0
- package/dist/collection/agents.js +54 -0
- package/dist/collection/apply.d.ts +8 -0
- package/dist/collection/apply.js +27 -0
- package/dist/collection/collection.d.ts +17 -0
- package/dist/collection/collection.js +28 -0
- package/dist/collection/enforce.d.ts +1 -0
- package/dist/collection/enforce.js +6 -0
- package/dist/collection/environment.d.ts +6 -0
- package/dist/collection/environment.js +28 -0
- package/dist/collection/graph-rules.d.ts +7 -0
- package/dist/collection/graph-rules.js +102 -0
- package/dist/collection/lint-directory.d.ts +32 -0
- package/dist/collection/lint-directory.js +67 -0
- package/dist/collection/lint-rules.d.ts +5 -0
- package/dist/collection/lint-rules.js +115 -0
- package/dist/collection/lint-shape.d.ts +89 -0
- package/dist/collection/lint-shape.js +99 -0
- package/dist/collection/lint-supply.d.ts +20 -0
- package/dist/collection/lint-supply.js +99 -0
- package/dist/collection/paths.d.ts +18 -0
- package/dist/collection/paths.js +28 -0
- package/dist/collection/pipelines.d.ts +8 -0
- package/dist/collection/pipelines.js +56 -0
- package/dist/collection/refusal.d.ts +11 -0
- package/dist/collection/refusal.js +11 -0
- package/dist/file.d.ts +2 -2
- package/dist/file.js +22 -9
- package/dist/floor-given.d.ts +2 -0
- package/dist/floor-given.js +8 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +12 -2
- package/dist/shape.d.ts +4 -0
- package/dist/shape.js +2 -0
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -8,14 +8,17 @@ The tool speaks the HTTP API of a [floor](https://github.com/re-cinq/floor) and
|
|
|
8
8
|
npm install @re-cinq/floor-pipeline # the command is floor-pipeline
|
|
9
9
|
|
|
10
10
|
export FLOOR_SERVICE_TOKEN=...
|
|
11
|
+
export FLOOR_API_URL=http://localhost:8180
|
|
11
12
|
|
|
12
|
-
floor-pipeline export code-review
|
|
13
|
-
floor-pipeline export --all --dir backup/
|
|
14
|
-
floor-pipeline import code-review.yaml
|
|
15
|
-
floor-pipeline migrate pipelines/
|
|
13
|
+
floor-pipeline export code-review > code-review.yaml
|
|
14
|
+
floor-pipeline export --all --dir backup/
|
|
15
|
+
floor-pipeline import code-review.yaml
|
|
16
|
+
floor-pipeline migrate pipelines/
|
|
16
17
|
floor-pipeline migrate pipelines/ --floor http://floor-api:8080 --wait-ready 180
|
|
17
18
|
```
|
|
18
19
|
|
|
20
|
+
`--floor <url>` names the floor for one call and wins over `FLOOR_API_URL`, the name a station's worker reads too.
|
|
21
|
+
|
|
19
22
|
| command | what it does |
|
|
20
23
|
|---|---|
|
|
21
24
|
| `export <line>` | writes the line's latest version, and what it names, as one file |
|
|
@@ -90,6 +93,50 @@ schedules:
|
|
|
90
93
|
| The program behind a service station | wherever it runs. The file declares the station; the program that posts a review is lore's |
|
|
91
94
|
| Runs, visits, their records and costs | in the floor's database. This is a backup of what a floor is told to do, and not of what it did |
|
|
92
95
|
|
|
96
|
+
## A collection
|
|
97
|
+
|
|
98
|
+
A collection is a folder of lines. Each line has its own folder, with its pipeline and its agents. An agent is a markdown file: the frontmatter holds its settings, and the body is its prompt. A file named `<agent>.extra.md` adds to the prompt of an agent the host already ships.
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
code-review/
|
|
102
|
+
assembly-line.yaml
|
|
103
|
+
agents/
|
|
104
|
+
reviewer.md
|
|
105
|
+
reviewer.extra.md
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`lint` checks a collection without a floor and without a token. A key that belongs to the host is named in the collection's `floor-collection.yaml` (`host_keys: [execution_mode]`), or with `--host-key`, as often as needed; `lint` and `apply` use both.
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
floor-pipeline lint collection/ --host-key execution_mode
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`lint` asks the same questions the floor asks of a line, through [`@re-cinq/floor-assembly-lines`](../assembly-lines/README.md). `unseeded-need` is a need that is neither a line argument or file nor produced on every path into its node, and its message gives one path that arrives without it. `unsupplied-input` is a `{name}` in an agent's prompt that the station does not give: a value need is read as `{name}`, a file or git need and a produce with a path as `{name_path}`, and the floor gives `{run_id}`, `{line_id}`, `{node_id}`, and for a retry or a fan-out branch `{previous_error}`, `{previous_failures}` and `{item}`. A station with a git need is also given `{git_credential}` and `{git_credential_url}`. A prompt's `{name}` is made of letters, digits, `_`, `.` and `-`, and starts with a letter or `_`, so a JSON object in a prompt is never read as one.
|
|
115
|
+
|
|
116
|
+
A collection may extend an agent the host ships with an `.extra.md` file, or name a shipped agent without defining it. Without the host's catalog `lint` refuses both. `--shipped <dir>` names a directory in the same layout, whose lines and agents are the shipped ones.
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
floor-pipeline lint collection/ --shipped shipped/ --host-key execution_mode
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
A refused file prints one line and the exit code is 1. A call with no directory prints the usage and the exit code is 2.
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
code-review/assembly-line.yml: a collection does not read this path: a line folder holds assembly-line.yaml, agents/<agent>.md and agents/<agent>.extra.md
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
A clean collection prints a summary and the exit code is 0.
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
collection ok: 1 agents, 1 pipelines, 0 extensions
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`apply` puts a collection to a floor: its agents, then each line with its stations. `${NAME}` in its files is filled from the environment. When a file is refused, nothing is put.
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
floor-pipeline apply collection/
|
|
138
|
+
```
|
|
139
|
+
|
|
93
140
|
## Migrations
|
|
94
141
|
|
|
95
142
|
`migrate` is for seeding a floor at deploy, and for changing it after. It runs a folder's files in the order of their names, each once.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const agentConfigSchema: z.ZodObject<{
|
|
3
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
4
|
+
skills_source: z.ZodOptional<z.ZodURL>;
|
|
5
|
+
mcp_servers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
transport: z.ZodEnum<{
|
|
8
|
+
http: "http";
|
|
9
|
+
sse: "sse";
|
|
10
|
+
stdio: "stdio";
|
|
11
|
+
}>;
|
|
12
|
+
command: z.ZodOptional<z.ZodString>;
|
|
13
|
+
args: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
14
|
+
url: z.ZodOptional<z.ZodURL>;
|
|
15
|
+
headers_secret: z.ZodOptional<z.ZodString>;
|
|
16
|
+
headers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
ref: z.ZodString;
|
|
19
|
+
}, z.core.$strip>>>;
|
|
20
|
+
env: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
21
|
+
name: z.ZodString;
|
|
22
|
+
ref: z.ZodString;
|
|
23
|
+
}, z.core.$strip>>>;
|
|
24
|
+
}, z.core.$strip>>>;
|
|
25
|
+
disallowed_tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
26
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
27
|
+
permission_mode: z.ZodOptional<z.ZodEnum<{
|
|
28
|
+
auto: "auto";
|
|
29
|
+
bypass: "bypass";
|
|
30
|
+
}>>;
|
|
31
|
+
max_turns: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
model_secret_key: z.ZodOptional<z.ZodString>;
|
|
33
|
+
pod_resources: z.ZodOptional<z.ZodObject<{
|
|
34
|
+
requests: z.ZodOptional<z.ZodObject<{
|
|
35
|
+
cpu: z.ZodOptional<z.ZodString>;
|
|
36
|
+
memory: z.ZodOptional<z.ZodString>;
|
|
37
|
+
"ephemeral-storage": z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strict>>;
|
|
39
|
+
limits: z.ZodOptional<z.ZodObject<{
|
|
40
|
+
cpu: z.ZodOptional<z.ZodString>;
|
|
41
|
+
memory: z.ZodOptional<z.ZodString>;
|
|
42
|
+
"ephemeral-storage": z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strict>>;
|
|
44
|
+
}, z.core.$strict>>;
|
|
45
|
+
}, z.core.$loose>;
|
|
46
|
+
export type AgentConfig = z.infer<typeof agentConfigSchema>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The schema of an agent definition's `config`, under the names docs/entities/agent-definition.md gives them, which are lore's own. Pure zod, so the browser can import it.
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// A header or env var the server needs, valued from the key `ref` of the cluster's agent-secrets.
|
|
4
|
+
const secretRef = z.object({
|
|
5
|
+
name: z.string().min(1).describe("The name of the header or environment variable."),
|
|
6
|
+
ref: z.string().min(1).describe("The key of the cluster's `agent-secrets` that holds its value."),
|
|
7
|
+
});
|
|
8
|
+
// One of the two ways to reach a server, never neither: a process the pod starts, or an address it calls.
|
|
9
|
+
const mcpServer = z
|
|
10
|
+
.object({
|
|
11
|
+
name: z.string().min(1).describe("The name the agent knows the server by."),
|
|
12
|
+
transport: z.enum(["stdio", "http", "sse"]).describe("How the server is reached. `stdio` is a process the pod starts. `http` and `sse` are an address it calls."),
|
|
13
|
+
command: z.string().min(1).describe("`stdio` only, and required there. The command that starts the server.").optional(),
|
|
14
|
+
args: z.array(z.string()).describe("`stdio` only. The command's arguments.").optional(),
|
|
15
|
+
url: z.url().describe("`http` and `sse` only, and required there. The server's address.").optional(),
|
|
16
|
+
headers_secret: z.string().min(1).describe("The key of `agent-secrets` that holds one whole header line, such as `Authorization: Bearer <token>`.").optional(),
|
|
17
|
+
headers: z.array(secretRef).describe("`http` and `sse` only. Headers sent to the server, each valued from `agent-secrets`.").optional(),
|
|
18
|
+
env: z.array(secretRef).describe("`stdio` only. Environment variables of the server's process, each valued from `agent-secrets`.").optional(),
|
|
19
|
+
})
|
|
20
|
+
.refine((server) => (server.transport === "stdio" ? Boolean(server.command) : Boolean(server.url)), {
|
|
21
|
+
message: "a stdio server needs a command, any other a url",
|
|
22
|
+
});
|
|
23
|
+
const KUBERNETES_QUANTITY = /^\d+(\.\d+)?(m|k|M|G|T|Ki|Mi|Gi|Ti)?$/;
|
|
24
|
+
const quantity = z.string().regex(KUBERNETES_QUANTITY, "a Kubernetes quantity such as 250m, 1, 512Mi or 2Gi");
|
|
25
|
+
const resourceQuantities = z.strictObject({
|
|
26
|
+
cpu: quantity.describe("A Kubernetes quantity, such as `500m`.").optional(),
|
|
27
|
+
memory: quantity.describe("A Kubernetes quantity, such as `2Gi`.").optional(),
|
|
28
|
+
"ephemeral-storage": quantity.describe("A Kubernetes quantity, such as `6Gi`.").optional(),
|
|
29
|
+
});
|
|
30
|
+
const podResources = z.strictObject({
|
|
31
|
+
requests: resourceQuantities.describe("What the pod asks for.").optional(),
|
|
32
|
+
limits: resourceQuantities.describe("What the pod may not exceed.").optional(),
|
|
33
|
+
});
|
|
34
|
+
export const agentConfigSchema = z.looseObject({
|
|
35
|
+
skills: z.array(z.string()).describe("Names of the skills the agent is given.").optional(),
|
|
36
|
+
skills_source: z.url().describe("Where the pod fetches each named skill and the agent's settings. Defaults to the floor's own `/skills`, which serves no skills.").optional(),
|
|
37
|
+
mcp_servers: z.array(mcpServer).describe("The MCP servers the agent can call.").optional(),
|
|
38
|
+
disallowed_tools: z.array(z.string()).describe("Tools the agent may not use.").optional(),
|
|
39
|
+
env: z.record(z.string(), z.string()).describe("Environment variables of the agent, as plain values.").optional(),
|
|
40
|
+
permission_mode: z.enum(["auto", "bypass"]).describe("How the agent asks before it acts. Defaults to `bypass`.").optional(),
|
|
41
|
+
max_turns: z.number().int().positive().describe("The most turns the agent takes in one visit.").optional(),
|
|
42
|
+
model_secret_key: z.string().min(1).describe("The key of `agent-secrets` that holds the model's API key.").optional(),
|
|
43
|
+
pod_resources: podResources.describe("The resources of the agent's container. With none, the cluster's default applies.").optional(),
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=agent-config-schema.js.map
|
package/dist/cli.js
CHANGED
|
@@ -5,32 +5,45 @@ import { join } from "node:path";
|
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
6
|
import { exportPipeline, lineIds } from "./export.js";
|
|
7
7
|
import { readPipelineFile, writePipelineFile } from "./file.js";
|
|
8
|
+
import { floorGiven } from "./floor-given.js";
|
|
8
9
|
import { importPipeline } from "./import.js";
|
|
9
10
|
import { migrate } from "./migrate.js";
|
|
11
|
+
import { applyCollection } from "./collection/apply.js";
|
|
12
|
+
import { lintCommand, readCollectionDirectory } from "./collection/lint-directory.js";
|
|
10
13
|
import { waitUntilReady } from "./ready.js";
|
|
11
14
|
import { fileOf, pipelineOf } from "./shape.js";
|
|
12
15
|
const USAGE = `floor-pipeline <what to do> --floor <url> with FLOOR_SERVICE_TOKEN
|
|
16
|
+
--floor may be left out when FLOOR_API_URL names the floor
|
|
13
17
|
|
|
14
18
|
export <line> one pipeline, written to standard output, or to --out <file>
|
|
15
19
|
export --all --dir <dir> every pipeline, one file each, named after its line: a backup
|
|
16
20
|
import <file>... puts each file to the floor. The same file twice changes nothing
|
|
17
21
|
migrate <dir> the folder's files in the order of their names, each once.
|
|
18
22
|
The floor remembers which ran
|
|
23
|
+
apply <dir> puts a collection to the floor: its agents, then each line with its stations.
|
|
24
|
+
\${NAME} in its files is filled from this environment. Nothing is put
|
|
25
|
+
when a file is refused
|
|
26
|
+
lint <dir> checks a collection: one folder a line, with its assembly-line.yaml and agents/.
|
|
27
|
+
Needs no floor and no token. A key the host owns is named with --host-key <name>,
|
|
28
|
+
as often as needed. The agents and lines the host ships are a directory in the
|
|
29
|
+
same layout, named with --shipped <dir>. Exits 2 when no directory is given
|
|
19
30
|
|
|
20
31
|
--wait-ready <seconds> first waits up to that long for the floor's /readyz to answer 200,
|
|
21
32
|
for a job that starts with the floor`;
|
|
22
|
-
const OPTIONS = { floor: { type: "string" }, out: { type: "string" }, dir: { type: "string" }, all: { type: "boolean" }, "wait-ready": { type: "string" } };
|
|
33
|
+
const OPTIONS = { floor: { type: "string" }, out: { type: "string" }, dir: { type: "string" }, all: { type: "boolean" }, "wait-ready": { type: "string" }, "host-key": { type: "string", multiple: true }, shipped: { type: "string" } };
|
|
23
34
|
function given() {
|
|
24
35
|
return parseArgs({ options: OPTIONS, allowPositionals: true });
|
|
25
36
|
}
|
|
26
37
|
async function main() {
|
|
27
38
|
const told = given();
|
|
28
39
|
const [command = ""] = told.positionals;
|
|
29
|
-
|
|
40
|
+
if (command === "lint")
|
|
41
|
+
return linted(told);
|
|
42
|
+
const commands = { export: exported, import: imported, migrate: migrated, apply: applied };
|
|
30
43
|
const run = commands[command];
|
|
31
44
|
if (!run)
|
|
32
45
|
throw new Error(USAGE);
|
|
33
|
-
const floor =
|
|
46
|
+
const floor = floorGiven(told.values.floor, process.env, USAGE);
|
|
34
47
|
await waitedFor(floor, told.values["wait-ready"]);
|
|
35
48
|
await run(floor, told);
|
|
36
49
|
}
|
|
@@ -42,13 +55,6 @@ async function waitedFor(floor, waitReady) {
|
|
|
42
55
|
throw new Error(`--wait-ready is a number of seconds above 0, and not "${waitReady}"`);
|
|
43
56
|
await waitUntilReady({ floorUrl: floor.url, seconds });
|
|
44
57
|
}
|
|
45
|
-
function floorOf(told) {
|
|
46
|
-
const token = process.env.FLOOR_SERVICE_TOKEN;
|
|
47
|
-
const url = told.values.floor;
|
|
48
|
-
if (!url || !token)
|
|
49
|
-
throw new Error(`a floor is named with --floor, and reached with FLOOR_SERVICE_TOKEN\n\n${USAGE}`);
|
|
50
|
-
return { url: url.replace(/\/$/, ""), token };
|
|
51
|
-
}
|
|
52
58
|
async function exported(floor, told) {
|
|
53
59
|
const [, line] = told.positionals;
|
|
54
60
|
if (told.values.all)
|
|
@@ -84,6 +90,20 @@ async function migrated(floor, told) {
|
|
|
84
90
|
const all = await migrate(floor, files);
|
|
85
91
|
all.forEach((each) => (each.ran ? said(each.name, each.put) : console.log(`${each.name}: ran before`)));
|
|
86
92
|
}
|
|
93
|
+
async function applied(floor, told) {
|
|
94
|
+
const [, dir] = told.positionals;
|
|
95
|
+
if (!dir)
|
|
96
|
+
throw new Error(USAGE);
|
|
97
|
+
const overlay = await readCollectionDirectory(dir, { hostKeys: told.values["host-key"] ?? [], env: process.env });
|
|
98
|
+
const refusals = overlay.refused.map(({ path, reason }) => `${path}: ${reason}`);
|
|
99
|
+
if (refusals.length > 0)
|
|
100
|
+
throw new Error(refusals.join("\n"));
|
|
101
|
+
said(dir, await applyCollection(floor, overlay));
|
|
102
|
+
}
|
|
103
|
+
async function linted(told) {
|
|
104
|
+
const [, directory] = told.positionals;
|
|
105
|
+
process.exitCode = await lintCommand({ directory, hostKeys: told.values["host-key"] ?? [], shippedDirectory: told.values.shipped }, USAGE, { out: console.log, err: console.error });
|
|
106
|
+
}
|
|
87
107
|
function said(file, put) {
|
|
88
108
|
console.log(`${file}:`);
|
|
89
109
|
put.forEach((each) => console.log(` ${each.kind}/${each.id}: ${each.changed ? "changed" : "as it was"}`));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Strict, unlike the stored config: a misspelled key in a file is a bug to fail on, not a field to carry. What `config` may hold is the floor's to say, when the agent is put. */
|
|
3
|
+
export declare const agentFrontmatterSchema: z.ZodObject<{
|
|
4
|
+
model: z.ZodOptional<z.ZodString>;
|
|
5
|
+
image: z.ZodOptional<z.ZodString>;
|
|
6
|
+
timeout_minutes: z.ZodOptional<z.ZodNumber>;
|
|
7
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
8
|
+
prices: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
9
|
+
input_per_million: z.ZodNumber;
|
|
10
|
+
output_per_million: z.ZodNumber;
|
|
11
|
+
cache_read_per_million: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
cache_write_per_million: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
}, z.core.$strict>>>;
|
|
14
|
+
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
type Frontmatter = z.infer<typeof agentFrontmatterSchema>;
|
|
17
|
+
export interface ParsedAgentFile {
|
|
18
|
+
name: string;
|
|
19
|
+
frontmatter: Frontmatter;
|
|
20
|
+
/** As written, host keys included: the validated copy reorders config's keys, and the floor is handed the file's order. */
|
|
21
|
+
written: Record<string, unknown>;
|
|
22
|
+
prompt: string | null;
|
|
23
|
+
}
|
|
24
|
+
/** The settings block of an agent definition, as a pipeline file holds it. */
|
|
25
|
+
export type AgentFileSettings = Pick<Frontmatter, "model" | "image" | "timeout_minutes" | "tags" | "prices" | "config"> & {
|
|
26
|
+
prompt: string | null;
|
|
27
|
+
};
|
|
28
|
+
/** The agents a host ships, by name, their settings as the files write them. */
|
|
29
|
+
export type ShippedAgents = ReadonlyMap<string, AgentFileSettings>;
|
|
30
|
+
/** The prompt of each agent a pipeline can name. */
|
|
31
|
+
export type AgentPrompts = ReadonlyMap<string, string | null>;
|
|
32
|
+
/** A key in `hostKeys` is the host's own: accepted with any value, kept in `written`, and never in the settings. */
|
|
33
|
+
export declare function readAgentFile(name: string, text: string, hostKeys?: readonly string[]): ParsedAgentFile;
|
|
34
|
+
/** The keys a pipeline file's `settings` held, in the file's order. A key the file leaves out stays out. */
|
|
35
|
+
export declare function floorSettingsOf(file: ParsedAgentFile): AgentFileSettings;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// One agent file: `<name>.md`, its frontmatter the agent's settings, its body its prompt.
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { enforce } from "./enforce.js";
|
|
5
|
+
const perMillion = z.number();
|
|
6
|
+
const price = z.strictObject({
|
|
7
|
+
input_per_million: perMillion.describe("US dollars for a million input tokens."),
|
|
8
|
+
output_per_million: perMillion.describe("US dollars for a million output tokens."),
|
|
9
|
+
cache_read_per_million: perMillion.describe("US dollars for a million tokens read from the cache. The input price when not stated.").optional(),
|
|
10
|
+
cache_write_per_million: perMillion.describe("US dollars for a million tokens written to the cache. The input price when not stated.").optional(),
|
|
11
|
+
});
|
|
12
|
+
/** Strict, unlike the stored config: a misspelled key in a file is a bug to fail on, not a field to carry. What `config` may hold is the floor's to say, when the agent is put. */
|
|
13
|
+
export const agentFrontmatterSchema = z.strictObject({
|
|
14
|
+
model: z.string().describe("The model the agent runs on.").optional(),
|
|
15
|
+
image: z.string().describe("The container image the agent runs in. Required in a file that defines an agent.").optional(),
|
|
16
|
+
timeout_minutes: z.number().int().positive().describe("How long a visit may run, in minutes. Required in a file that defines an agent.").optional(),
|
|
17
|
+
tags: z.array(z.string()).describe("Which cluster agents may run it. A cluster agent claims a visit only when it offers every tag.").optional(),
|
|
18
|
+
prices: z.record(z.string(), price).describe("Model name to what it costs, for a model that reports tokens and no cost.").optional(),
|
|
19
|
+
config: z.record(z.string(), z.unknown()).describe("Settings for the agent's pod. A key the floor does not know is kept and not acted on.").optional(),
|
|
20
|
+
});
|
|
21
|
+
const FRONTMATTER = /^---\n([\s\S]*?)\n---(?:\n|$)/;
|
|
22
|
+
/** A key in `hostKeys` is the host's own: accepted with any value, kept in `written`, and never in the settings. */
|
|
23
|
+
export function readAgentFile(name, text, hostKeys = []) {
|
|
24
|
+
const match = FRONTMATTER.exec(text);
|
|
25
|
+
enforce(match, `${name}.md: missing the --- frontmatter block`);
|
|
26
|
+
const written = (parseYaml(match[1]) ?? {});
|
|
27
|
+
const body = text.slice(match[0].length);
|
|
28
|
+
return { name, frontmatter: validated(name, written, hostKeys), written, prompt: body === "" ? null : body };
|
|
29
|
+
}
|
|
30
|
+
function validated(name, written, hostKeys) {
|
|
31
|
+
const own = Object.fromEntries(Object.entries(written).filter(([key]) => !hostKeys.includes(key)));
|
|
32
|
+
const parsed = agentFrontmatterSchema.safeParse(own);
|
|
33
|
+
enforce(parsed.success, `${name}.md: ${parsed.success ? "" : z.prettifyError(parsed.error)}`);
|
|
34
|
+
return parsed.data;
|
|
35
|
+
}
|
|
36
|
+
const SETTINGS_KEYS = new Set(["model", "image", "timeout_minutes", "tags", "prices", "config"]);
|
|
37
|
+
/** The keys a pipeline file's `settings` held, in the file's order. A key the file leaves out stays out. */
|
|
38
|
+
export function floorSettingsOf(file) {
|
|
39
|
+
return { ...Object.fromEntries(Object.entries(file.written).filter(([key]) => SETTINGS_KEYS.has(key))), prompt: file.prompt };
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=agent-file.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type AgentFileSettings, type ShippedAgents } from "./agent-file.js";
|
|
2
|
+
import { type Environment } from "./environment.js";
|
|
3
|
+
import { type CollectionFile } from "./paths.js";
|
|
4
|
+
import { type Refusal } from "./refusal.js";
|
|
5
|
+
export interface ShippedCatalog {
|
|
6
|
+
/** The names of the pipelines the host ships. */
|
|
7
|
+
pipelines: readonly string[];
|
|
8
|
+
/** The shipped agents, their settings as the md files write them (environment not yet filled in). */
|
|
9
|
+
agents: ShippedAgents;
|
|
10
|
+
}
|
|
11
|
+
export interface CollectionOverlayInput {
|
|
12
|
+
files: readonly CollectionFile[];
|
|
13
|
+
shipped: ShippedCatalog;
|
|
14
|
+
env: Environment;
|
|
15
|
+
/** Frontmatter keys that are the host's own: accepted in an agent file, and never in its settings. */
|
|
16
|
+
hostKeys?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
export type AgentSource = "collection-new" | "replaced" | "extended";
|
|
19
|
+
export interface OverlayAgent {
|
|
20
|
+
settings: AgentFileSettings;
|
|
21
|
+
source: AgentSource;
|
|
22
|
+
}
|
|
23
|
+
/** The agents the collection sets, the first file to name an agent winning. */
|
|
24
|
+
export declare function agentsOverlay(input: CollectionOverlayInput): {
|
|
25
|
+
agents: Map<string, OverlayAgent>;
|
|
26
|
+
refused: Refusal[];
|
|
27
|
+
};
|
|
28
|
+
/** A shipped agent's prompt with the collection's extension appended. */
|
|
29
|
+
export declare function extendedPrompt(base: string, extra: string): string;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// The agents a collection sets: a full definition replaces or adds one, an extension appends to a shipped agent's prompt.
|
|
2
|
+
import { floorSettingsOf, readAgentFile } from "./agent-file.js";
|
|
3
|
+
import { settingsWithEnvironment } from "./environment.js";
|
|
4
|
+
import { enforce } from "./enforce.js";
|
|
5
|
+
import { agentFileOf } from "./paths.js";
|
|
6
|
+
import { attempt } from "./refusal.js";
|
|
7
|
+
const REQUIRED_SETTINGS = ["image", "timeout_minutes", "prompt"];
|
|
8
|
+
/** The agents the collection sets, the first file to name an agent winning. */
|
|
9
|
+
export function agentsOverlay(input) {
|
|
10
|
+
const agents = new Map();
|
|
11
|
+
const setBy = new Map();
|
|
12
|
+
const refused = [];
|
|
13
|
+
for (const file of agentFilesOf(input.files)) {
|
|
14
|
+
const result = attempt(file.path, () => agentOf(file, input, setBy));
|
|
15
|
+
if ("refusal" in result) {
|
|
16
|
+
refused.push(result.refusal);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
agents.set(file.agent, result.made);
|
|
20
|
+
setBy.set(file.agent, file.path);
|
|
21
|
+
}
|
|
22
|
+
return { agents, refused };
|
|
23
|
+
}
|
|
24
|
+
/** A shipped agent's prompt with the collection's extension appended. */
|
|
25
|
+
export function extendedPrompt(base, extra) {
|
|
26
|
+
return `${base}\n\n${extra}`;
|
|
27
|
+
}
|
|
28
|
+
function agentFilesOf(files) {
|
|
29
|
+
const agentFiles = [...files]
|
|
30
|
+
.sort((left, right) => left.path.localeCompare(right.path))
|
|
31
|
+
.flatMap((file) => {
|
|
32
|
+
const named = agentFileOf(file.path);
|
|
33
|
+
return named ? [{ ...file, ...named }] : [];
|
|
34
|
+
});
|
|
35
|
+
// A full definition goes first, so an extension of the same agent is the one refused.
|
|
36
|
+
return [...agentFiles.filter((file) => !file.isExtension), ...agentFiles.filter((file) => file.isExtension)];
|
|
37
|
+
}
|
|
38
|
+
function agentOf(file, { shipped, env, hostKeys }, setBy) {
|
|
39
|
+
const base = shipped.agents.get(file.agent);
|
|
40
|
+
enforce(!setBy.has(file.agent), `${file.agent} is already set by ${setBy.get(file.agent)}`);
|
|
41
|
+
return file.isExtension ? extendedAgent(file, base, env) : definedAgent(file, base, env, hostKeys);
|
|
42
|
+
}
|
|
43
|
+
function extendedAgent(file, base, env) {
|
|
44
|
+
enforce(base, `an extension needs a shipped agent, and nothing ships ${file.agent}`);
|
|
45
|
+
return { source: "extended", settings: settingsWithEnvironment({ ...base, prompt: extendedPrompt(base.prompt ?? "", file.text) }, env) };
|
|
46
|
+
}
|
|
47
|
+
function definedAgent(file, base, env, hostKeys) {
|
|
48
|
+
const settings = floorSettingsOf(readAgentFile(file.agent, file.text, hostKeys));
|
|
49
|
+
for (const field of REQUIRED_SETTINGS) {
|
|
50
|
+
enforce(settings[field], `${file.agent} has no ${field}, and a full agent definition needs a prompt, an image and timeout_minutes`);
|
|
51
|
+
}
|
|
52
|
+
return { source: base ? "replaced" : "collection-new", settings: settingsWithEnvironment(settings, env) };
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Floor } from "../floor.js";
|
|
2
|
+
import { type Put } from "../import.js";
|
|
3
|
+
import { type Fields, type Named } from "../shape.js";
|
|
4
|
+
import type { OverlayAgent } from "./agents.js";
|
|
5
|
+
import type { CollectionOverlay } from "./collection.js";
|
|
6
|
+
export declare function applyCollection(floor: Floor, overlay: Pick<CollectionOverlay, "agents" | "pipelines">): Promise<Put[]>;
|
|
7
|
+
/** Each agent's settings as the floor spells them, over what the floor holds for it: a collection sets an agent's settings, and a repository's variant is not its to take away. */
|
|
8
|
+
export declare function agentDefinitionsOf(agents: ReadonlyMap<string, OverlayAgent>, held: ReadonlyMap<string, Fields>): Named[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// A collection, put to a floor: its agents first, then each line with its stations, since the floor refuses a station naming an agent it does not have. Putting the same collection twice changes nothing.
|
|
2
|
+
import { asked } from "../floor.js";
|
|
3
|
+
import { importPipeline } from "../import.js";
|
|
4
|
+
import { pipelineOf } from "../shape.js";
|
|
5
|
+
const NOTHING_ELSE = { files: {}, stations: [], schedules: [], archive: { lines: [], stations: [], agentDefinitions: [], schedules: [] } };
|
|
6
|
+
export async function applyCollection(floor, overlay) {
|
|
7
|
+
const agentDefinitions = agentDefinitionsOf(overlay.agents, await heldDefinitions(floor, [...overlay.agents.keys()]));
|
|
8
|
+
const agents = await importPipeline(floor, { ...NOTHING_ELSE, agentDefinitions });
|
|
9
|
+
const lines = [];
|
|
10
|
+
// One after another, in the order of their folders: a line may name a station an earlier folder defines.
|
|
11
|
+
for (const pipeline of overlay.pipelines)
|
|
12
|
+
lines.push(...(await importPipeline(floor, withoutAgents(pipeline))));
|
|
13
|
+
return [...agents, ...lines];
|
|
14
|
+
}
|
|
15
|
+
/** Each agent's settings as the floor spells them, over what the floor holds for it: a collection sets an agent's settings, and a repository's variant is not its to take away. */
|
|
16
|
+
export function agentDefinitionsOf(agents, held) {
|
|
17
|
+
const written = Object.fromEntries([...agents].map(([name, agent]) => [name, { settings: agent.settings }]));
|
|
18
|
+
return pipelineOf({ agent_definitions: written }).agentDefinitions.map(({ id, body }) => ({ id, body: { ...held.get(id), settings: body.settings } }));
|
|
19
|
+
}
|
|
20
|
+
function withoutAgents(pipeline) {
|
|
21
|
+
return { ...pipeline, agentDefinitions: [] };
|
|
22
|
+
}
|
|
23
|
+
async function heldDefinitions(floor, names) {
|
|
24
|
+
const rows = await Promise.all(names.map(async (name) => asked(floor, { method: "GET", path: `/agent-definitions/${name}` })));
|
|
25
|
+
return new Map(names.flatMap((name, index) => (rows[index] ? [[name, rows[index].body]] : [])));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Pipeline } from "../shape.js";
|
|
2
|
+
import { type CollectionOverlayInput, type OverlayAgent } from "./agents.js";
|
|
3
|
+
import type { Refusal } from "./refusal.js";
|
|
4
|
+
export type { AgentSource, CollectionOverlayInput, OverlayAgent, ShippedCatalog } from "./agents.js";
|
|
5
|
+
export type { CollectionFile } from "./paths.js";
|
|
6
|
+
export type { Refusal } from "./refusal.js";
|
|
7
|
+
export interface CollectionOverlay {
|
|
8
|
+
agents: Map<string, OverlayAgent>;
|
|
9
|
+
pipelines: Pipeline[];
|
|
10
|
+
counts: {
|
|
11
|
+
agents: number;
|
|
12
|
+
pipelines: number;
|
|
13
|
+
extensions: number;
|
|
14
|
+
};
|
|
15
|
+
refused: Refusal[];
|
|
16
|
+
}
|
|
17
|
+
export declare function collectionOverlay(input: CollectionOverlayInput): CollectionOverlay;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { agentsOverlay } from "./agents.js";
|
|
2
|
+
import { pipelinesOverlay } from "./pipelines.js";
|
|
3
|
+
import { isReadPath } from "./paths.js";
|
|
4
|
+
export function collectionOverlay(input) {
|
|
5
|
+
const agentsSet = agentsOverlay(input);
|
|
6
|
+
const pipelinesSet = pipelinesOverlay(input, agentsSet.agents);
|
|
7
|
+
const { agents } = agentsSet;
|
|
8
|
+
const { pipelines } = pipelinesSet;
|
|
9
|
+
return {
|
|
10
|
+
agents,
|
|
11
|
+
pipelines,
|
|
12
|
+
refused: byPath([...agentsSet.refused, ...pipelinesSet.refused, ...unreadPathsOf(input)]),
|
|
13
|
+
counts: { agents: agents.size, pipelines: pipelines.length, extensions: extensionsIn(agents) },
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function extensionsIn(agents) {
|
|
17
|
+
return [...agents.values()].filter((agent) => agent.source === "extended").length;
|
|
18
|
+
}
|
|
19
|
+
const UNREAD_PATH = "a collection does not read this path: a line folder holds assembly-line.yaml, agents/<agent>.md and agents/<agent>.extra.md";
|
|
20
|
+
/** A file in a line folder that would be skipped in silence: a misspelt name must show, not quietly do nothing. */
|
|
21
|
+
function unreadPathsOf({ files }) {
|
|
22
|
+
const unread = files.filter((file) => !isReadPath(file.path));
|
|
23
|
+
return unread.map((file) => ({ path: file.path, reason: UNREAD_PATH }));
|
|
24
|
+
}
|
|
25
|
+
function byPath(refused) {
|
|
26
|
+
return refused.sort((left, right) => left.path.localeCompare(right.path));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function enforce(condition: unknown, message: string): asserts condition;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AgentFileSettings } from "./agent-file.js";
|
|
2
|
+
export type Environment = Record<string, string | undefined>;
|
|
3
|
+
/** The names a text asks for, each once, in the order they first appear. */
|
|
4
|
+
export declare function placeholdersIn(text: string): string[];
|
|
5
|
+
export declare function withEnvironment(yamlText: string, env: Environment): string;
|
|
6
|
+
export declare function settingsWithEnvironment(settings: unknown, env: Environment): AgentFileSettings;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Fills `${NAME}` placeholders from an environment: into a pipeline's text and an agent's settings, never into a prompt.
|
|
2
|
+
import { enforce } from "./enforce.js";
|
|
3
|
+
const PLACEHOLDER = /\$\{([A-Z][A-Z0-9_]*)\}/g;
|
|
4
|
+
/** The names a text asks for, each once, in the order they first appear. */
|
|
5
|
+
export function placeholdersIn(text) {
|
|
6
|
+
return [...new Set([...text.matchAll(PLACEHOLDER)].map((match) => match[1]))];
|
|
7
|
+
}
|
|
8
|
+
export function withEnvironment(yamlText, env) {
|
|
9
|
+
return yamlText.replace(PLACEHOLDER, (placeholder, name) => {
|
|
10
|
+
const value = env[name];
|
|
11
|
+
enforce(value, `${name} is not set, and a pipeline names it`);
|
|
12
|
+
return value;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function settingsWithEnvironment(settings, env) {
|
|
16
|
+
const { prompt, ...rest } = settings;
|
|
17
|
+
return { ...filledIn(rest, env), prompt };
|
|
18
|
+
}
|
|
19
|
+
function filledIn(value, env) {
|
|
20
|
+
if (typeof value === "string")
|
|
21
|
+
return withEnvironment(value, env);
|
|
22
|
+
if (Array.isArray(value))
|
|
23
|
+
return value.map((element) => filledIn(element, env));
|
|
24
|
+
if (!value || typeof value !== "object")
|
|
25
|
+
return value;
|
|
26
|
+
return Object.fromEntries(Object.entries(value).map(([key, field]) => [key, filledIn(field, env)]));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Checked, type Node, type PipelineProblem, type Station } from "./lint-shape.js";
|
|
2
|
+
export declare function ambiguousEdges(checked: Checked): PipelineProblem[];
|
|
3
|
+
export declare function unroutedOutcomes(checked: Checked, node: Node, station: Station): PipelineProblem[];
|
|
4
|
+
export declare function undeclaredOutcomes(checked: Checked): PipelineProblem[];
|
|
5
|
+
export declare function danglingEdges(checked: Checked): PipelineProblem[];
|
|
6
|
+
export declare function deadEnds(checked: Checked): PipelineProblem[];
|
|
7
|
+
export declare function unreachableNodes(checked: Checked): PipelineProblem[];
|