antpath 0.10.14 → 0.11.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 +201 -0
- package/README.md +16 -8
- package/dist/_shared/blueprint.d.ts +93 -108
- package/dist/_shared/blueprint.js +144 -78
- package/dist/_shared/cleanup-policy.d.ts +2 -2
- package/dist/_shared/cleanup-policy.js +2 -5
- package/dist/_shared/http.d.ts +2 -2
- package/dist/_shared/index.d.ts +7 -1
- package/dist/_shared/index.js +6 -1
- package/dist/_shared/mcp-proxy-url.d.ts +55 -0
- package/dist/_shared/mcp-proxy-url.js +65 -0
- package/dist/_shared/operations.d.ts +55 -8
- package/dist/_shared/operations.js +163 -20
- package/dist/_shared/provider-proxy-url.d.ts +64 -0
- package/dist/_shared/provider-proxy-url.js +73 -0
- package/dist/_shared/proxy-validation.d.ts +1 -1
- package/dist/_shared/proxy-validation.js +2 -2
- package/dist/_shared/run-unit.d.ts +23 -36
- package/dist/_shared/run-unit.js +30 -46
- package/dist/_shared/runner-event.d.ts +120 -0
- package/dist/_shared/runner-event.js +193 -0
- package/dist/_shared/runner-job.d.ts +159 -0
- package/dist/_shared/runner-job.js +54 -0
- package/dist/_shared/runtime-manifest.d.ts +191 -0
- package/dist/_shared/runtime-manifest.js +221 -0
- package/dist/_shared/runtime-types.d.ts +7 -16
- package/dist/_shared/sse.d.ts +74 -0
- package/dist/_shared/sse.js +0 -0
- package/dist/_shared/stable.d.ts +15 -10
- package/dist/_shared/stable.js +15 -10
- package/dist/_shared/submission.d.ts +199 -73
- package/dist/_shared/submission.js +409 -210
- package/dist/_shared/telemetry.d.ts +2 -2
- package/dist/_shared/telemetry.js +2 -2
- package/dist/_shared/template/index.d.ts +0 -1
- package/dist/_shared/template/index.js +0 -1
- package/dist/agents-md.d.ts +25 -67
- package/dist/agents-md.js +35 -121
- package/dist/agents-md.js.map +1 -1
- package/dist/asset-upload.d.ts +34 -0
- package/dist/asset-upload.js +34 -0
- package/dist/asset-upload.js.map +1 -1
- package/dist/blueprint.d.ts +3 -3
- package/dist/bundle.d.ts +2 -2
- package/dist/bundle.js +1 -1
- package/dist/cli.mjs +559 -105
- package/dist/cli.mjs.sha256 +1 -1
- package/dist/client.d.ts +53 -22
- package/dist/client.js +196 -130
- package/dist/client.js.map +1 -1
- package/dist/file.d.ts +28 -94
- package/dist/file.js +35 -175
- package/dist/file.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.d.ts +10 -2
- package/dist/mcp-server.js +17 -2
- package/dist/mcp-server.js.map +1 -1
- package/dist/skill.d.ts +44 -214
- package/dist/skill.js +50 -284
- package/dist/skill.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/docs/cleanup.md +1 -1
- package/docs/credentials.md +2 -2
- package/docs/events.md +8 -8
- package/docs/outputs.md +2 -0
- package/docs/quickstart.md +18 -2
- package/docs/skills.md +1 -3
- package/docs/templates.md +6 -5
- package/package.json +2 -1
- package/dist/_shared/secrets.d.ts +0 -7
- package/dist/_shared/secrets.js +0 -20
- package/dist/_shared/template/mapper.d.ts +0 -11
- package/dist/_shared/template/mapper.js +0 -70
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime manifest: the per-run, per-provider description of where
|
|
3
|
+
* antpath places things inside the agent container, plus the merged
|
|
4
|
+
* env-var bag delivered via `RUNTIME.env` / `RUNTIME.json`.
|
|
5
|
+
*
|
|
6
|
+
* Two consumers, one source of truth:
|
|
7
|
+
*
|
|
8
|
+
* 1. The dashboard BFF computes a manifest at submitRun-response
|
|
9
|
+
* time (from the validated submission + the chosen provider)
|
|
10
|
+
* and echoes it on the wire as `Run.runtimeManifest`. The SDK
|
|
11
|
+
* exposes it as `RunRef.runtimeManifest` so caller code (broll's
|
|
12
|
+
* dispatcher, anyone rendering catalog markdown pre-submission)
|
|
13
|
+
* can substitute path strings without guessing.
|
|
14
|
+
*
|
|
15
|
+
* 2. The worker uses the same builder + the same `renderRuntimeEnv`
|
|
16
|
+
* / `renderRuntimeJson` helpers to materialise the two RUNTIME
|
|
17
|
+
* files mounted into every session, so the in-container view
|
|
18
|
+
* and the SDK-side view are byte-for-byte the same set of
|
|
19
|
+
* keys/values.
|
|
20
|
+
*
|
|
21
|
+
* Manifest values are derived: the BFF and worker both compute them
|
|
22
|
+
* from the same input (provider + customer envVars). Nothing is
|
|
23
|
+
* persisted separately — the source of truth for the customer half
|
|
24
|
+
* remains `submission.environment.envVars` on the run row; the antpath
|
|
25
|
+
* half is constant for a given provider+SDK-version pair.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Set of providers whose runtime contract antpath models. Today only
|
|
29
|
+
* `"anthropic"` ships; the field is on the manifest so forward-compat
|
|
30
|
+
* consumers can branch on it without us having to silently change
|
|
31
|
+
* what `runtimeManifest` means when we add a second provider.
|
|
32
|
+
*/
|
|
33
|
+
export type RuntimeProvider = "anthropic";
|
|
34
|
+
/**
|
|
35
|
+
* The in-container paths the agent and skill code reference at
|
|
36
|
+
* runtime. All fields are absolute, all reflect Anthropic Managed
|
|
37
|
+
* Agents' session-mount rebase rule (every `mount_path` lands under
|
|
38
|
+
* `/mnt/session/uploads/` regardless of the leading slash) — see
|
|
39
|
+
* `references/architecture-decisions.md`.
|
|
40
|
+
*
|
|
41
|
+
* `skillsRoot` is the location of Skills API-registered bundles, which
|
|
42
|
+
* the runtime auto-discovers under `/workspace/skills/<name>/` —
|
|
43
|
+
* empirically a separate root from the session-resource mounts, NOT
|
|
44
|
+
* under `/mnt/session/uploads/`.
|
|
45
|
+
*/
|
|
46
|
+
export interface RuntimeManifest {
|
|
47
|
+
readonly provider: RuntimeProvider;
|
|
48
|
+
/** Where Skills-API-registered bundles auto-discover (Anthropic). */
|
|
49
|
+
readonly skillsRoot: string;
|
|
50
|
+
/** Parent dir of File mounts: `<filesRoot>/<f_id>/<rel-path>`. */
|
|
51
|
+
readonly filesRoot: string;
|
|
52
|
+
/** Parent dir of non-SKILL.md asset mounts: `<assetsRoot>/<skl_id>/<rel-path>`. */
|
|
53
|
+
readonly assetsRoot: string;
|
|
54
|
+
/** Absolute path the agent writes output files into for capture. */
|
|
55
|
+
readonly outputsRoot: string;
|
|
56
|
+
/** Absolute path of the in-container antpath CLI (invoke via `node`). */
|
|
57
|
+
readonly antpathCli: string;
|
|
58
|
+
/** Absolute path of the per-run proxy-endpoints manifest. */
|
|
59
|
+
readonly indexJson: string;
|
|
60
|
+
/** Absolute path of the always-mounted antpath runtime contract README. */
|
|
61
|
+
readonly readme: string;
|
|
62
|
+
/** Absolute path of the machine-readable manifest mirror. */
|
|
63
|
+
readonly runtimeJson: string;
|
|
64
|
+
/** Absolute path of the POSIX-shell-sourceable runtime env file. */
|
|
65
|
+
readonly runtimeEnv: string;
|
|
66
|
+
/**
|
|
67
|
+
* Merged env-var bag: antpath-set runtime keys (with reserved
|
|
68
|
+
* `ANTPATH_` prefix) plus customer-supplied `environment.envVars`.
|
|
69
|
+
* Both `RUNTIME.env` and `RUNTIME.json` are rendered from this
|
|
70
|
+
* exact map; `__KEY__` substitution in agent-facing markdown
|
|
71
|
+
* resolves against this exact map.
|
|
72
|
+
*/
|
|
73
|
+
readonly envVars: Readonly<Record<string, string>>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Anthropic Managed Agents container paths. Kept here so the BFF and
|
|
77
|
+
* the worker render identical values; the worker's `proxy-bootstrap`
|
|
78
|
+
* constants are validated against these by a regression test
|
|
79
|
+
* (`packages/shared/test/runtime-manifest.test.ts`).
|
|
80
|
+
*
|
|
81
|
+
* Path facts (each verified at least once by a live session, locked
|
|
82
|
+
* in `references/architecture-decisions.md`):
|
|
83
|
+
* - Session resources mount under `/mnt/session/uploads/` (rebase).
|
|
84
|
+
* - Skills API places bundles under `/workspace/skills/<name>/`
|
|
85
|
+
* — a SEPARATE root from session-resource mounts.
|
|
86
|
+
* - Files API mounts file_ids at the requested mount_path, also
|
|
87
|
+
* rebased — antpath threads them under `<filesRoot>/<f_id>/<rel>`.
|
|
88
|
+
* - Only `/mnt/session/outputs` files are auto-registered with the
|
|
89
|
+
* Files API for terminal-time capture.
|
|
90
|
+
*/
|
|
91
|
+
declare const ANTHROPIC_PATHS: Readonly<{
|
|
92
|
+
readonly skillsRoot: "/workspace/skills";
|
|
93
|
+
readonly filesRoot: "/mnt/session/uploads/antpath/files";
|
|
94
|
+
readonly assetsRoot: "/mnt/session/uploads/antpath/assets";
|
|
95
|
+
readonly outputsRoot: "/mnt/session/outputs";
|
|
96
|
+
readonly antpathCli: "/mnt/session/uploads/antpath/antpath";
|
|
97
|
+
readonly indexJson: "/mnt/session/uploads/antpath/index.json";
|
|
98
|
+
readonly readme: "/mnt/session/uploads/antpath/SKILLS.md";
|
|
99
|
+
readonly runtimeJson: "/mnt/session/uploads/antpath/RUNTIME.json";
|
|
100
|
+
readonly runtimeEnv: "/mnt/session/uploads/antpath/RUNTIME.env";
|
|
101
|
+
}>;
|
|
102
|
+
/**
|
|
103
|
+
* Container paths exposed for a given provider. Today only
|
|
104
|
+
* `"anthropic"` is recognised; calling with anything else throws so
|
|
105
|
+
* forward-compat surfaces the missing provider entry instead of
|
|
106
|
+
* silently emitting Anthropic paths.
|
|
107
|
+
*/
|
|
108
|
+
export declare function runtimePathsFor(provider: RuntimeProvider): typeof ANTHROPIC_PATHS;
|
|
109
|
+
export interface BuildRuntimeManifestInput {
|
|
110
|
+
readonly provider: RuntimeProvider;
|
|
111
|
+
/**
|
|
112
|
+
* Customer-supplied `environment.envVars` from the validated
|
|
113
|
+
* submission. Keys with the reserved `ANTPATH_` prefix are
|
|
114
|
+
* filtered out defensively — the strict submission parser already
|
|
115
|
+
* rejects them, but defence-in-depth means a malformed snapshot
|
|
116
|
+
* (or a future bypass) can't poison the manifest.
|
|
117
|
+
*/
|
|
118
|
+
readonly customerEnvVars?: Readonly<Record<string, string>> | undefined;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Build the runtime manifest for a single submission. Pure function:
|
|
122
|
+
* same input → same output → safe to call from the BFF response path
|
|
123
|
+
* and from the worker bootstrap path with identical results.
|
|
124
|
+
*/
|
|
125
|
+
export declare function buildRuntimeManifest(input: BuildRuntimeManifestInput): RuntimeManifest;
|
|
126
|
+
/**
|
|
127
|
+
* Render the RUNTIME.env file mounted into every session. POSIX-shell
|
|
128
|
+
* sourceable (`source /mnt/session/uploads/antpath/RUNTIME.env`).
|
|
129
|
+
* Values are double-quoted with `"`, `\`, `$`, and backtick escaped
|
|
130
|
+
* so any UTF-8 string survives a `source` invocation. Lines are LF
|
|
131
|
+
* (Unix), no trailing CR — the container is Linux regardless of
|
|
132
|
+
* caller platform.
|
|
133
|
+
*
|
|
134
|
+
* Output order: antpath keys first (in stable order from
|
|
135
|
+
* `buildRuntimeManifest`), then customer keys in insertion order.
|
|
136
|
+
* The same ordering is preserved in RUNTIME.json.
|
|
137
|
+
*/
|
|
138
|
+
export declare function renderRuntimeEnv(manifest: RuntimeManifest): string;
|
|
139
|
+
/**
|
|
140
|
+
* Render the RUNTIME.json file mounted into every session. Stable
|
|
141
|
+
* canonical JSON (2-space indent, key order matches the manifest)
|
|
142
|
+
* so the file is reviewable as a tracked artifact when captured into
|
|
143
|
+
* a run's output archive.
|
|
144
|
+
*/
|
|
145
|
+
export declare function renderRuntimeJson(manifest: RuntimeManifest): string;
|
|
146
|
+
/**
|
|
147
|
+
* Pattern matched by `substituteRuntimePlaceholders`. A placeholder is
|
|
148
|
+
* `__KEY__` where `KEY` matches POSIX shell key rules (uppercase, digits,
|
|
149
|
+
* underscores, starting with a letter or underscore). The literal form
|
|
150
|
+
* is deliberately conservative — no `{{ }}` templating, no expressions,
|
|
151
|
+
* no escape syntax. If a customer needs the literal string `__KEY__` in
|
|
152
|
+
* agent-facing markdown, they avoid the matching key in their envVars
|
|
153
|
+
* map.
|
|
154
|
+
*/
|
|
155
|
+
export declare const RUNTIME_PLACEHOLDER_PATTERN: RegExp;
|
|
156
|
+
/**
|
|
157
|
+
* Substitute `__KEY__` placeholders in agent-facing markdown against
|
|
158
|
+
* the manifest's envVars map. Fail-fast on unknown keys: the function
|
|
159
|
+
* throws `RuntimePlaceholderError` naming the offending key + filePath
|
|
160
|
+
* so the worker can surface a lint-style failure at materialization
|
|
161
|
+
* time, before the agent ever sees the file.
|
|
162
|
+
*
|
|
163
|
+
* Pure function; safe to call from the BFF, the worker materializer,
|
|
164
|
+
* or tests. The two callers in production are:
|
|
165
|
+
*
|
|
166
|
+
* - Worker materialization: rewrite SKILL.md / AGENTS.md / .md
|
|
167
|
+
* entries inside skill, file, and AgentsMd bundles before they
|
|
168
|
+
* mount or upload.
|
|
169
|
+
* - SDK / customer code: customers can apply the same helper in
|
|
170
|
+
* their dispatcher when they want to render templates locally
|
|
171
|
+
* before uploading. The merged envVars map is `runtimeManifest.envVars`.
|
|
172
|
+
*
|
|
173
|
+
* @param content The text to rewrite.
|
|
174
|
+
* @param envVars Map of allowed placeholder keys → values. Typically
|
|
175
|
+
* `runtimeManifest.envVars` from `buildRuntimeManifest`.
|
|
176
|
+
* @param filePath Optional path of the source file, included in the
|
|
177
|
+
* error message when a placeholder is unresolved.
|
|
178
|
+
* Helps the customer locate the offending line.
|
|
179
|
+
*/
|
|
180
|
+
export declare function substituteRuntimePlaceholders(content: string, envVars: Readonly<Record<string, string>>, filePath?: string): string;
|
|
181
|
+
/**
|
|
182
|
+
* Thrown by `substituteRuntimePlaceholders` when a `__KEY__` token in
|
|
183
|
+
* agent-facing markdown does not resolve against the merged env-var
|
|
184
|
+
* map. Surfaced at run materialization, before the run reaches the
|
|
185
|
+
* agent — the customer fixes the typo at the SDK call site, no
|
|
186
|
+
* tokens are spent on a misrouted run.
|
|
187
|
+
*/
|
|
188
|
+
export declare class RuntimePlaceholderError extends Error {
|
|
189
|
+
constructor(message: string);
|
|
190
|
+
}
|
|
191
|
+
export {};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime manifest: the per-run, per-provider description of where
|
|
3
|
+
* antpath places things inside the agent container, plus the merged
|
|
4
|
+
* env-var bag delivered via `RUNTIME.env` / `RUNTIME.json`.
|
|
5
|
+
*
|
|
6
|
+
* Two consumers, one source of truth:
|
|
7
|
+
*
|
|
8
|
+
* 1. The dashboard BFF computes a manifest at submitRun-response
|
|
9
|
+
* time (from the validated submission + the chosen provider)
|
|
10
|
+
* and echoes it on the wire as `Run.runtimeManifest`. The SDK
|
|
11
|
+
* exposes it as `RunRef.runtimeManifest` so caller code (broll's
|
|
12
|
+
* dispatcher, anyone rendering catalog markdown pre-submission)
|
|
13
|
+
* can substitute path strings without guessing.
|
|
14
|
+
*
|
|
15
|
+
* 2. The worker uses the same builder + the same `renderRuntimeEnv`
|
|
16
|
+
* / `renderRuntimeJson` helpers to materialise the two RUNTIME
|
|
17
|
+
* files mounted into every session, so the in-container view
|
|
18
|
+
* and the SDK-side view are byte-for-byte the same set of
|
|
19
|
+
* keys/values.
|
|
20
|
+
*
|
|
21
|
+
* Manifest values are derived: the BFF and worker both compute them
|
|
22
|
+
* from the same input (provider + customer envVars). Nothing is
|
|
23
|
+
* persisted separately — the source of truth for the customer half
|
|
24
|
+
* remains `submission.environment.envVars` on the run row; the antpath
|
|
25
|
+
* half is constant for a given provider+SDK-version pair.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Anthropic Managed Agents container paths. Kept here so the BFF and
|
|
29
|
+
* the worker render identical values; the worker's `proxy-bootstrap`
|
|
30
|
+
* constants are validated against these by a regression test
|
|
31
|
+
* (`packages/shared/test/runtime-manifest.test.ts`).
|
|
32
|
+
*
|
|
33
|
+
* Path facts (each verified at least once by a live session, locked
|
|
34
|
+
* in `references/architecture-decisions.md`):
|
|
35
|
+
* - Session resources mount under `/mnt/session/uploads/` (rebase).
|
|
36
|
+
* - Skills API places bundles under `/workspace/skills/<name>/`
|
|
37
|
+
* — a SEPARATE root from session-resource mounts.
|
|
38
|
+
* - Files API mounts file_ids at the requested mount_path, also
|
|
39
|
+
* rebased — antpath threads them under `<filesRoot>/<f_id>/<rel>`.
|
|
40
|
+
* - Only `/mnt/session/outputs` files are auto-registered with the
|
|
41
|
+
* Files API for terminal-time capture.
|
|
42
|
+
*/
|
|
43
|
+
const ANTHROPIC_PATHS = Object.freeze({
|
|
44
|
+
skillsRoot: "/workspace/skills",
|
|
45
|
+
filesRoot: "/mnt/session/uploads/antpath/files",
|
|
46
|
+
assetsRoot: "/mnt/session/uploads/antpath/assets",
|
|
47
|
+
outputsRoot: "/mnt/session/outputs",
|
|
48
|
+
antpathCli: "/mnt/session/uploads/antpath/antpath",
|
|
49
|
+
indexJson: "/mnt/session/uploads/antpath/index.json",
|
|
50
|
+
readme: "/mnt/session/uploads/antpath/SKILLS.md",
|
|
51
|
+
runtimeJson: "/mnt/session/uploads/antpath/RUNTIME.json",
|
|
52
|
+
runtimeEnv: "/mnt/session/uploads/antpath/RUNTIME.env"
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Container paths exposed for a given provider. Today only
|
|
56
|
+
* `"anthropic"` is recognised; calling with anything else throws so
|
|
57
|
+
* forward-compat surfaces the missing provider entry instead of
|
|
58
|
+
* silently emitting Anthropic paths.
|
|
59
|
+
*/
|
|
60
|
+
export function runtimePathsFor(provider) {
|
|
61
|
+
if (provider === "anthropic") {
|
|
62
|
+
return ANTHROPIC_PATHS;
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Unknown runtime provider: ${provider}`);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Reserved env-var prefix for antpath-set runtime keys. Mirrors the
|
|
68
|
+
* constant in `submission.ts`; duplicated here so this module is
|
|
69
|
+
* self-contained and can be tree-shaken by SDK consumers that don't
|
|
70
|
+
* need the submission parser.
|
|
71
|
+
*/
|
|
72
|
+
const ANTPATH_PREFIX = "ANTPATH_";
|
|
73
|
+
/**
|
|
74
|
+
* Build the runtime manifest for a single submission. Pure function:
|
|
75
|
+
* same input → same output → safe to call from the BFF response path
|
|
76
|
+
* and from the worker bootstrap path with identical results.
|
|
77
|
+
*/
|
|
78
|
+
export function buildRuntimeManifest(input) {
|
|
79
|
+
const paths = runtimePathsFor(input.provider);
|
|
80
|
+
const antpathEnvVars = {
|
|
81
|
+
ANTPATH_PROVIDER: input.provider,
|
|
82
|
+
ANTPATH_CLI: paths.antpathCli,
|
|
83
|
+
ANTPATH_OUTPUTS: paths.outputsRoot,
|
|
84
|
+
ANTPATH_SKILLS_ROOT: paths.skillsRoot,
|
|
85
|
+
ANTPATH_FILES_ROOT: paths.filesRoot,
|
|
86
|
+
ANTPATH_ASSETS_ROOT: paths.assetsRoot,
|
|
87
|
+
ANTPATH_INDEX_JSON: paths.indexJson,
|
|
88
|
+
ANTPATH_README: paths.readme,
|
|
89
|
+
ANTPATH_RUNTIME_JSON: paths.runtimeJson,
|
|
90
|
+
ANTPATH_RUNTIME_ENV: paths.runtimeEnv
|
|
91
|
+
};
|
|
92
|
+
const customerEnvVars = {};
|
|
93
|
+
for (const [key, value] of Object.entries(input.customerEnvVars ?? {})) {
|
|
94
|
+
if (key.startsWith(ANTPATH_PREFIX)) {
|
|
95
|
+
// Defensive filter; the strict parser rejects this at submit
|
|
96
|
+
// time. If a stored snapshot somehow carries a reserved key
|
|
97
|
+
// we drop it rather than letting it shadow our value.
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
customerEnvVars[key] = value;
|
|
101
|
+
}
|
|
102
|
+
const envVars = Object.freeze({ ...antpathEnvVars, ...customerEnvVars });
|
|
103
|
+
return Object.freeze({
|
|
104
|
+
provider: input.provider,
|
|
105
|
+
skillsRoot: paths.skillsRoot,
|
|
106
|
+
filesRoot: paths.filesRoot,
|
|
107
|
+
assetsRoot: paths.assetsRoot,
|
|
108
|
+
outputsRoot: paths.outputsRoot,
|
|
109
|
+
antpathCli: paths.antpathCli,
|
|
110
|
+
indexJson: paths.indexJson,
|
|
111
|
+
readme: paths.readme,
|
|
112
|
+
runtimeJson: paths.runtimeJson,
|
|
113
|
+
runtimeEnv: paths.runtimeEnv,
|
|
114
|
+
envVars
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Render the RUNTIME.env file mounted into every session. POSIX-shell
|
|
119
|
+
* sourceable (`source /mnt/session/uploads/antpath/RUNTIME.env`).
|
|
120
|
+
* Values are double-quoted with `"`, `\`, `$`, and backtick escaped
|
|
121
|
+
* so any UTF-8 string survives a `source` invocation. Lines are LF
|
|
122
|
+
* (Unix), no trailing CR — the container is Linux regardless of
|
|
123
|
+
* caller platform.
|
|
124
|
+
*
|
|
125
|
+
* Output order: antpath keys first (in stable order from
|
|
126
|
+
* `buildRuntimeManifest`), then customer keys in insertion order.
|
|
127
|
+
* The same ordering is preserved in RUNTIME.json.
|
|
128
|
+
*/
|
|
129
|
+
export function renderRuntimeEnv(manifest) {
|
|
130
|
+
const lines = [
|
|
131
|
+
"# antpath runtime environment (mounted at " + manifest.runtimeEnv + ")",
|
|
132
|
+
"# Generated per-run by the antpath worker; do not edit.",
|
|
133
|
+
"# Source from bash: `source " + manifest.runtimeEnv + "`",
|
|
134
|
+
""
|
|
135
|
+
];
|
|
136
|
+
for (const [key, value] of Object.entries(manifest.envVars)) {
|
|
137
|
+
lines.push(`${key}="${escapeForDoubleQuotedShell(value)}"`);
|
|
138
|
+
}
|
|
139
|
+
return lines.join("\n") + "\n";
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Render the RUNTIME.json file mounted into every session. Stable
|
|
143
|
+
* canonical JSON (2-space indent, key order matches the manifest)
|
|
144
|
+
* so the file is reviewable as a tracked artifact when captured into
|
|
145
|
+
* a run's output archive.
|
|
146
|
+
*/
|
|
147
|
+
export function renderRuntimeJson(manifest) {
|
|
148
|
+
// Manifest is already frozen with the desired key order — JSON.stringify
|
|
149
|
+
// preserves insertion order, so the file mirrors the wire shape.
|
|
150
|
+
return JSON.stringify(manifest, null, 2) + "\n";
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Escape a string for embedding inside a POSIX double-quoted shell
|
|
154
|
+
* literal. Only `\`, `"`, `$`, and backtick need escaping inside
|
|
155
|
+
* `"..."`; everything else (including single quotes, spaces, UTF-8)
|
|
156
|
+
* passes through verbatim. Newlines stay literal so multi-line
|
|
157
|
+
* values render across multiple lines in the file but are read back
|
|
158
|
+
* as a single value by `source`.
|
|
159
|
+
*/
|
|
160
|
+
function escapeForDoubleQuotedShell(value) {
|
|
161
|
+
return value.replace(/[\\"$`]/g, (ch) => `\\${ch}`);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Pattern matched by `substituteRuntimePlaceholders`. A placeholder is
|
|
165
|
+
* `__KEY__` where `KEY` matches POSIX shell key rules (uppercase, digits,
|
|
166
|
+
* underscores, starting with a letter or underscore). The literal form
|
|
167
|
+
* is deliberately conservative — no `{{ }}` templating, no expressions,
|
|
168
|
+
* no escape syntax. If a customer needs the literal string `__KEY__` in
|
|
169
|
+
* agent-facing markdown, they avoid the matching key in their envVars
|
|
170
|
+
* map.
|
|
171
|
+
*/
|
|
172
|
+
export const RUNTIME_PLACEHOLDER_PATTERN = /__([A-Z_][A-Z0-9_]*)__/g;
|
|
173
|
+
/**
|
|
174
|
+
* Substitute `__KEY__` placeholders in agent-facing markdown against
|
|
175
|
+
* the manifest's envVars map. Fail-fast on unknown keys: the function
|
|
176
|
+
* throws `RuntimePlaceholderError` naming the offending key + filePath
|
|
177
|
+
* so the worker can surface a lint-style failure at materialization
|
|
178
|
+
* time, before the agent ever sees the file.
|
|
179
|
+
*
|
|
180
|
+
* Pure function; safe to call from the BFF, the worker materializer,
|
|
181
|
+
* or tests. The two callers in production are:
|
|
182
|
+
*
|
|
183
|
+
* - Worker materialization: rewrite SKILL.md / AGENTS.md / .md
|
|
184
|
+
* entries inside skill, file, and AgentsMd bundles before they
|
|
185
|
+
* mount or upload.
|
|
186
|
+
* - SDK / customer code: customers can apply the same helper in
|
|
187
|
+
* their dispatcher when they want to render templates locally
|
|
188
|
+
* before uploading. The merged envVars map is `runtimeManifest.envVars`.
|
|
189
|
+
*
|
|
190
|
+
* @param content The text to rewrite.
|
|
191
|
+
* @param envVars Map of allowed placeholder keys → values. Typically
|
|
192
|
+
* `runtimeManifest.envVars` from `buildRuntimeManifest`.
|
|
193
|
+
* @param filePath Optional path of the source file, included in the
|
|
194
|
+
* error message when a placeholder is unresolved.
|
|
195
|
+
* Helps the customer locate the offending line.
|
|
196
|
+
*/
|
|
197
|
+
export function substituteRuntimePlaceholders(content, envVars, filePath) {
|
|
198
|
+
return content.replace(RUNTIME_PLACEHOLDER_PATTERN, (match, key) => {
|
|
199
|
+
if (key in envVars) {
|
|
200
|
+
return envVars[key];
|
|
201
|
+
}
|
|
202
|
+
const where = filePath ? ` (in ${filePath})` : "";
|
|
203
|
+
throw new RuntimePlaceholderError(`unresolved runtime placeholder ${match}${where}: key ${JSON.stringify(key)} ` +
|
|
204
|
+
`is not in environment.envVars or the antpath runtime keys. ` +
|
|
205
|
+
`Available keys: ${Object.keys(envVars).sort().join(", ")}`);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Thrown by `substituteRuntimePlaceholders` when a `__KEY__` token in
|
|
210
|
+
* agent-facing markdown does not resolve against the merged env-var
|
|
211
|
+
* map. Surfaced at run materialization, before the run reaches the
|
|
212
|
+
* agent — the customer fixes the typo at the SDK call site, no
|
|
213
|
+
* tokens are spent on a misrouted run.
|
|
214
|
+
*/
|
|
215
|
+
export class RuntimePlaceholderError extends Error {
|
|
216
|
+
constructor(message) {
|
|
217
|
+
super(message);
|
|
218
|
+
this.name = "RuntimePlaceholderError";
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=runtime-manifest.js.map
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type { JsonValue, PlatformInlineSecrets, PlatformProxyEndpoint } from "./submission.js";
|
|
2
1
|
/**
|
|
3
2
|
* Loose record describing a run as the dashboard BFF returns it. Concrete
|
|
4
3
|
* dashboard-managed fields appear in the index signature; the SDK and CLI
|
|
5
4
|
* may surface them without strong typing per-field.
|
|
5
|
+
*
|
|
6
|
+
* `runtimeManifest` is derived from the validated submission + the chosen
|
|
7
|
+
* provider on every read — see `runtime-manifest.ts`. It is `undefined`
|
|
8
|
+
* on responses from BFFs that predate Phase 2 of the runtime-environment
|
|
9
|
+
* rollout; SDK consumers MUST treat it as best-effort and not panic on
|
|
10
|
+
* its absence.
|
|
6
11
|
*/
|
|
7
12
|
export interface Run {
|
|
8
13
|
readonly id: string;
|
|
@@ -15,6 +20,7 @@ export interface Run {
|
|
|
15
20
|
readonly terminalAt?: string | null;
|
|
16
21
|
readonly errorMessage?: string | null;
|
|
17
22
|
readonly usage?: UsageSummary;
|
|
23
|
+
readonly runtimeManifest?: import("./runtime-manifest.js").RuntimeManifest;
|
|
18
24
|
readonly [key: string]: unknown;
|
|
19
25
|
}
|
|
20
26
|
export interface UsageSummary {
|
|
@@ -175,18 +181,3 @@ export interface FileRecord {
|
|
|
175
181
|
readonly deletedAt?: string | null;
|
|
176
182
|
readonly [key: string]: unknown;
|
|
177
183
|
}
|
|
178
|
-
/**
|
|
179
|
-
* Full submission as the SDK and CLI assemble it before posting. The
|
|
180
|
-
* `template` is the SDK-level ResolvedTemplate (or a JSON-encoded one);
|
|
181
|
-
* the SDK/CLI converts to PlatformTemplateSubmission via the mapper.
|
|
182
|
-
*/
|
|
183
|
-
export interface RunSubmissionInput {
|
|
184
|
-
readonly workspaceId: string;
|
|
185
|
-
readonly idempotencyKey?: string;
|
|
186
|
-
readonly variables?: Record<string, JsonValue>;
|
|
187
|
-
readonly secrets: PlatformInlineSecrets;
|
|
188
|
-
readonly proxyEndpoints?: readonly PlatformProxyEndpoint[];
|
|
189
|
-
readonly cleanup?: {
|
|
190
|
-
readonly session?: "retain" | "delete";
|
|
191
|
-
};
|
|
192
|
-
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tiny SSE (text/event-stream) parser used by the SDK / CLI to consume
|
|
3
|
+
* the dashboard's `/api/runs/:id/events/stream` endpoint without
|
|
4
|
+
* pulling in a DOM `EventSource` dependency. Node's `fetch` returns a
|
|
5
|
+
* web `ReadableStream<Uint8Array>` body; this parser turns that into
|
|
6
|
+
* an async iterable of `SseFrame`s.
|
|
7
|
+
*
|
|
8
|
+
* The wire grammar follows the WHATWG HTML spec § Server-sent events:
|
|
9
|
+
*
|
|
10
|
+
* - Lines are separated by `\n`, `\r`, or `\r\n`.
|
|
11
|
+
* - A `:` prefix marks a comment — ignored.
|
|
12
|
+
* - `field: value` (or `field:value`, with no space) — leading space
|
|
13
|
+
* after the colon is stripped.
|
|
14
|
+
* - Recognised fields: `event`, `data`, `id`, `retry`.
|
|
15
|
+
* - Multiple `data:` lines join with `\n`.
|
|
16
|
+
* - A blank line dispatches the current frame and resets the buffer.
|
|
17
|
+
* - `event:` defaults to `"message"` when absent.
|
|
18
|
+
*
|
|
19
|
+
* The parser is deliberately a free function so it can be unit-tested
|
|
20
|
+
* against synthesized chunk boundaries (one byte at a time, mid-frame,
|
|
21
|
+
* across UTF-8 multi-byte sequences) without spinning up a real
|
|
22
|
+
* connection.
|
|
23
|
+
*/
|
|
24
|
+
export interface SseFrame {
|
|
25
|
+
readonly id?: string;
|
|
26
|
+
readonly event: string;
|
|
27
|
+
readonly data: string;
|
|
28
|
+
readonly retry?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Stateful parser: feed in chunks (in any size), pull out completed
|
|
32
|
+
* frames. Designed for `for await` consumption — see `iterateSse`.
|
|
33
|
+
*/
|
|
34
|
+
export declare class SseParser {
|
|
35
|
+
#private;
|
|
36
|
+
/**
|
|
37
|
+
* Push a chunk of raw bytes through the parser. Returns any frames
|
|
38
|
+
* that completed during this chunk. Chunks may contain zero, one,
|
|
39
|
+
* or many frame boundaries — the parser handles partial trailing
|
|
40
|
+
* data internally.
|
|
41
|
+
*/
|
|
42
|
+
pushBytes(chunk: Uint8Array): readonly SseFrame[];
|
|
43
|
+
/**
|
|
44
|
+
* Push a text chunk directly. Used by the parser tests so they can
|
|
45
|
+
* exercise byte-boundary edge cases without manufacturing a
|
|
46
|
+
* `TextDecoder` round-trip.
|
|
47
|
+
*/
|
|
48
|
+
pushText(text: string): readonly SseFrame[];
|
|
49
|
+
/**
|
|
50
|
+
* Indicate end-of-stream. Returns any final frame that the dispatcher
|
|
51
|
+
* was holding when the stream closed mid-frame (no trailing blank
|
|
52
|
+
* line). The dispatcher pattern is: blank line dispatches; if the
|
|
53
|
+
* remote closes after a partial frame, that frame is dropped per the
|
|
54
|
+
* spec.
|
|
55
|
+
*/
|
|
56
|
+
flush(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Current "last event id" — the cursor the SSE spec instructs the
|
|
59
|
+
* client to replay on automatic reconnection. Callers use this to
|
|
60
|
+
* resume after a disconnect.
|
|
61
|
+
*/
|
|
62
|
+
get lastEventId(): string | undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Convert a web `ReadableStream<Uint8Array>` (the body of a fetch
|
|
66
|
+
* Response) into an async iterable of SSE frames. The stream is
|
|
67
|
+
* consumed exactly once; the caller is responsible for cancelling
|
|
68
|
+
* the underlying reader on abort.
|
|
69
|
+
*
|
|
70
|
+
* The reader is raced against the abort signal so a long-blocked
|
|
71
|
+
* server (no chunks for many seconds) still releases the loop
|
|
72
|
+
* promptly when the consumer aborts.
|
|
73
|
+
*/
|
|
74
|
+
export declare function iterateSse(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncIterable<SseFrame>;
|
|
Binary file
|
package/dist/_shared/stable.d.ts
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Canonical hosted antpath URL. Used as the default `baseUrl`
|
|
3
|
-
* SDK `AntpathClient` and the host-side CLI `--
|
|
2
|
+
* Canonical hosted antpath API plane URL. Used as the default `baseUrl`
|
|
3
|
+
* for the SDK `AntpathClient` and the host-side CLI `--antpath-url`
|
|
4
|
+
* flag.
|
|
4
5
|
*
|
|
5
|
-
* Pinned to
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Pinned to `api.antpath.ai` on purpose: the dashboard at
|
|
7
|
+
* `www.antpath.ai` is the human UX surface, while `api.antpath.ai`
|
|
8
|
+
* owns the runtime/API plane (run submission, provider proxy, MCP
|
|
9
|
+
* proxy, runner callbacks). Both the apex `antpath.ai` and `www.` host
|
|
10
|
+
* may issue redirects, and HTTP clients strip the `Authorization`
|
|
11
|
+
* header on cross-origin redirects (WHATWG Fetch §5.5) — hitting them
|
|
12
|
+
* would make authenticated calls land as 401s. Always go direct to
|
|
13
|
+
* the API plane.
|
|
10
14
|
*
|
|
11
15
|
* A single canonical default is not a "footnote mode" — it is the
|
|
12
16
|
* canonical product. Self-hosted deployments override via the
|
|
13
|
-
* explicit `baseUrl` / `--
|
|
17
|
+
* explicit `baseUrl` / `--antpath-url` parameter. The value lives in
|
|
14
18
|
* source (no env-var override) so the agent reading the SDK call site
|
|
15
19
|
* can see exactly where the call goes.
|
|
16
20
|
*
|
|
17
21
|
* See `references/development-principles.md` (Agent-first surface
|
|
18
|
-
* design, Concrete rule 3)
|
|
22
|
+
* design, Concrete rule 3) and
|
|
23
|
+
* `references/deepseek-runtime-mcp-plan.md` (API plane).
|
|
19
24
|
*/
|
|
20
|
-
export declare const ANTPATH_DEFAULT_BASE_URL = "https://
|
|
25
|
+
export declare const ANTPATH_DEFAULT_BASE_URL = "https://api.antpath.ai";
|
|
21
26
|
export declare function stableStringify(value: unknown): string;
|
|
22
27
|
export declare function sha256(value: unknown): string;
|
package/dist/_shared/stable.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
/**
|
|
3
|
-
* Canonical hosted antpath URL. Used as the default `baseUrl`
|
|
4
|
-
* SDK `AntpathClient` and the host-side CLI `--
|
|
3
|
+
* Canonical hosted antpath API plane URL. Used as the default `baseUrl`
|
|
4
|
+
* for the SDK `AntpathClient` and the host-side CLI `--antpath-url`
|
|
5
|
+
* flag.
|
|
5
6
|
*
|
|
6
|
-
* Pinned to
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Pinned to `api.antpath.ai` on purpose: the dashboard at
|
|
8
|
+
* `www.antpath.ai` is the human UX surface, while `api.antpath.ai`
|
|
9
|
+
* owns the runtime/API plane (run submission, provider proxy, MCP
|
|
10
|
+
* proxy, runner callbacks). Both the apex `antpath.ai` and `www.` host
|
|
11
|
+
* may issue redirects, and HTTP clients strip the `Authorization`
|
|
12
|
+
* header on cross-origin redirects (WHATWG Fetch §5.5) — hitting them
|
|
13
|
+
* would make authenticated calls land as 401s. Always go direct to
|
|
14
|
+
* the API plane.
|
|
11
15
|
*
|
|
12
16
|
* A single canonical default is not a "footnote mode" — it is the
|
|
13
17
|
* canonical product. Self-hosted deployments override via the
|
|
14
|
-
* explicit `baseUrl` / `--
|
|
18
|
+
* explicit `baseUrl` / `--antpath-url` parameter. The value lives in
|
|
15
19
|
* source (no env-var override) so the agent reading the SDK call site
|
|
16
20
|
* can see exactly where the call goes.
|
|
17
21
|
*
|
|
18
22
|
* See `references/development-principles.md` (Agent-first surface
|
|
19
|
-
* design, Concrete rule 3)
|
|
23
|
+
* design, Concrete rule 3) and
|
|
24
|
+
* `references/deepseek-runtime-mcp-plan.md` (API plane).
|
|
20
25
|
*/
|
|
21
|
-
export const ANTPATH_DEFAULT_BASE_URL = "https://
|
|
26
|
+
export const ANTPATH_DEFAULT_BASE_URL = "https://api.antpath.ai";
|
|
22
27
|
export function stableStringify(value) {
|
|
23
28
|
return JSON.stringify(sortValue(value));
|
|
24
29
|
}
|