antpath 0.10.15 → 0.11.4

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.
Files changed (75) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +16 -8
  3. package/dist/_shared/blueprint.d.ts +93 -108
  4. package/dist/_shared/blueprint.js +144 -78
  5. package/dist/_shared/cleanup-policy.d.ts +2 -2
  6. package/dist/_shared/cleanup-policy.js +2 -5
  7. package/dist/_shared/http.d.ts +2 -2
  8. package/dist/_shared/index.d.ts +5 -1
  9. package/dist/_shared/index.js +5 -1
  10. package/dist/_shared/mcp-proxy-url.d.ts +55 -0
  11. package/dist/_shared/mcp-proxy-url.js +65 -0
  12. package/dist/_shared/operations.d.ts +7 -8
  13. package/dist/_shared/operations.js +14 -20
  14. package/dist/_shared/provider-proxy-url.d.ts +64 -0
  15. package/dist/_shared/provider-proxy-url.js +73 -0
  16. package/dist/_shared/proxy-validation.d.ts +1 -1
  17. package/dist/_shared/proxy-validation.js +2 -2
  18. package/dist/_shared/run-unit.d.ts +23 -36
  19. package/dist/_shared/run-unit.js +30 -46
  20. package/dist/_shared/runner-event.d.ts +120 -0
  21. package/dist/_shared/runner-event.js +193 -0
  22. package/dist/_shared/runner-job.d.ts +159 -0
  23. package/dist/_shared/runner-job.js +54 -0
  24. package/dist/_shared/runtime-manifest.d.ts +191 -0
  25. package/dist/_shared/runtime-manifest.js +221 -0
  26. package/dist/_shared/runtime-types.d.ts +7 -16
  27. package/dist/_shared/stable.d.ts +15 -10
  28. package/dist/_shared/stable.js +15 -10
  29. package/dist/_shared/submission.d.ts +221 -73
  30. package/dist/_shared/submission.js +442 -212
  31. package/dist/_shared/telemetry.d.ts +2 -2
  32. package/dist/_shared/telemetry.js +2 -2
  33. package/dist/_shared/template/index.d.ts +0 -1
  34. package/dist/_shared/template/index.js +0 -1
  35. package/dist/agents-md.d.ts +25 -67
  36. package/dist/agents-md.js +35 -121
  37. package/dist/agents-md.js.map +1 -1
  38. package/dist/asset-upload.d.ts +34 -0
  39. package/dist/asset-upload.js +34 -0
  40. package/dist/asset-upload.js.map +1 -1
  41. package/dist/blueprint.d.ts +3 -3
  42. package/dist/bundle.d.ts +2 -2
  43. package/dist/bundle.js +1 -1
  44. package/dist/cli.mjs +191 -100
  45. package/dist/cli.mjs.sha256 +1 -1
  46. package/dist/client.d.ts +56 -19
  47. package/dist/client.js +147 -125
  48. package/dist/client.js.map +1 -1
  49. package/dist/file.d.ts +28 -94
  50. package/dist/file.js +35 -175
  51. package/dist/file.js.map +1 -1
  52. package/dist/index.d.ts +5 -5
  53. package/dist/index.js +4 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/mcp-server.d.ts +10 -2
  56. package/dist/mcp-server.js +17 -2
  57. package/dist/mcp-server.js.map +1 -1
  58. package/dist/skill.d.ts +44 -214
  59. package/dist/skill.js +50 -284
  60. package/dist/skill.js.map +1 -1
  61. package/dist/version.d.ts +1 -1
  62. package/dist/version.js +1 -1
  63. package/dist/version.js.map +1 -1
  64. package/docs/cleanup.md +1 -1
  65. package/docs/credentials.md +2 -2
  66. package/docs/events.md +8 -8
  67. package/docs/outputs.md +2 -0
  68. package/docs/quickstart.md +18 -2
  69. package/docs/skills.md +1 -3
  70. package/docs/templates.md +6 -5
  71. package/package.json +3 -2
  72. package/dist/_shared/secrets.d.ts +0 -7
  73. package/dist/_shared/secrets.js +0 -20
  74. package/dist/_shared/template/mapper.d.ts +0 -11
  75. package/dist/_shared/template/mapper.js +0 -70
@@ -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
- }
@@ -1,22 +1,27 @@
1
1
  /**
2
- * Canonical hosted antpath URL. Used as the default `baseUrl` for the
3
- * SDK `AntpathClient` and the host-side CLI `--dashboard-url` flag.
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 the `www.` host on purpose: the apex `antpath.ai` issues a
6
- * 307 redirect to `https://www.antpath.ai`, and HTTP clients strip the
7
- * `Authorization` header on cross-origin redirects (WHATWG Fetch §5.5).
8
- * Hitting the apex would make every authenticated call from a default
9
- * client land as a 401 `authentication required`. Always go direct.
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` / `--dashboard-url` parameter. The value lives in
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://www.antpath.ai";
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;
@@ -1,24 +1,29 @@
1
1
  import { createHash } from "node:crypto";
2
2
  /**
3
- * Canonical hosted antpath URL. Used as the default `baseUrl` for the
4
- * SDK `AntpathClient` and the host-side CLI `--dashboard-url` flag.
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 the `www.` host on purpose: the apex `antpath.ai` issues a
7
- * 307 redirect to `https://www.antpath.ai`, and HTTP clients strip the
8
- * `Authorization` header on cross-origin redirects (WHATWG Fetch §5.5).
9
- * Hitting the apex would make every authenticated call from a default
10
- * client land as a 401 `authentication required`. Always go direct.
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` / `--dashboard-url` parameter. The value lives in
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://www.antpath.ai";
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
  }