@sellable/install 0.1.794 → 0.1.796

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.
@@ -0,0 +1,84 @@
1
+ // Shared by the control plane and the runtime. A custom Runs API is only a
2
+ // requested destination here; the runtime must also match a trusted connection.
3
+ export const ENDPOINT_MODEL_SELECTION_ALLOWLIST = Object.freeze({
4
+ openrouter: Object.freeze([
5
+ "anthropic/claude-opus-5.5",
6
+ "anthropic/claude-sonnet-5.5",
7
+ ]),
8
+ });
9
+ export const ENDPOINT_MODEL_REASONING_EFFORTS = Object.freeze([
10
+ "low",
11
+ "medium",
12
+ "high",
13
+ "xhigh",
14
+ ]);
15
+
16
+ export function normalizeRunsApiBaseUrl(value) {
17
+ if (
18
+ typeof value !== "string" ||
19
+ value.length > 1_024 ||
20
+ value !== value.trim()
21
+ )
22
+ return null;
23
+ try {
24
+ const url = new URL(value);
25
+ if (
26
+ url.username ||
27
+ url.password ||
28
+ url.search ||
29
+ url.hash ||
30
+ /[\\\s]/.test(value) ||
31
+ (url.protocol !== "https:" &&
32
+ !(
33
+ url.protocol === "http:" &&
34
+ ["127.0.0.1", "[::1]"].includes(url.hostname)
35
+ ))
36
+ )
37
+ return null;
38
+ return `${url.origin}${url.pathname.replace(/\/$/, "")}`;
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+
44
+ export function compileEndpointModelSelection(value) {
45
+ if (value === undefined || value === null) return null;
46
+ if (typeof value !== "object" || Array.isArray(value)) return "invalid";
47
+ const custom = Object.hasOwn(value, "runsApiBaseUrl");
48
+ if (
49
+ Object.keys(value).sort().join(",") !==
50
+ (custom
51
+ ? "model,provider,reasoningEffort,runsApiBaseUrl"
52
+ : "model,provider,reasoningEffort")
53
+ )
54
+ return "invalid";
55
+ const { provider, model, reasoningEffort } = value;
56
+ if (
57
+ typeof provider !== "string" ||
58
+ typeof model !== "string" ||
59
+ !ENDPOINT_MODEL_REASONING_EFFORTS.includes(reasoningEffort)
60
+ )
61
+ return "invalid";
62
+ if (
63
+ !custom &&
64
+ (!Object.hasOwn(ENDPOINT_MODEL_SELECTION_ALLOWLIST, provider) ||
65
+ !ENDPOINT_MODEL_SELECTION_ALLOWLIST[provider].includes(model))
66
+ )
67
+ return "invalid";
68
+ const runsApiBaseUrl = custom
69
+ ? normalizeRunsApiBaseUrl(value.runsApiBaseUrl)
70
+ : null;
71
+ if (
72
+ custom &&
73
+ (!runsApiBaseUrl ||
74
+ !/^[a-z][a-z0-9_-]{0,63}$/.test(provider) ||
75
+ !/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,199}$/.test(model))
76
+ )
77
+ return "invalid";
78
+ return Object.freeze({
79
+ provider,
80
+ model,
81
+ reasoningEffort,
82
+ ...(custom ? { runsApiBaseUrl } : {}),
83
+ });
84
+ }
@@ -7,6 +7,11 @@ import {
7
7
  writeFileSync,
8
8
  } from "node:fs";
9
9
  import { dirname, isAbsolute } from "node:path";
10
+ import {
11
+ compileEndpointModelSelection,
12
+ normalizeRunsApiBaseUrl,
13
+ } from "./endpoint-model-selection.mjs";
14
+ export { ENDPOINT_MODEL_SELECTION_ALLOWLIST } from "./endpoint-model-selection.mjs";
10
15
 
11
16
  const LOOPBACK_ORIGIN = "http://127.0.0.1:8642";
12
17
  const RUN_ID = /^run_[a-f0-9]{32}$/;
@@ -206,37 +211,12 @@ function canonicalHistory(value) {
206
211
  return result;
207
212
  }
208
213
 
209
- // The models a caller may name for one endpoint run. The server checks the
210
- // same list before it hands the run over; the runtime checks it again here so
211
- // a run can never reach Hermes with a model that was not reviewed.
212
- export const ENDPOINT_MODEL_SELECTION_ALLOWLIST = Object.freeze({
213
- openrouter: Object.freeze([
214
- "anthropic/claude-opus-5.5",
215
- "anthropic/claude-sonnet-5.5",
216
- ]),
217
- });
218
- const ENDPOINT_MODEL_REASONING_EFFORTS = Object.freeze([
219
- "low",
220
- "medium",
221
- "high",
222
- "xhigh",
223
- ]);
224
-
225
214
  export function validateEndpointModelSelection(value) {
226
- if (
227
- !exactObject(value) ||
228
- Object.keys(value).sort().join(",") !== "model,provider,reasoningEffort" ||
229
- !Object.hasOwn(ENDPOINT_MODEL_SELECTION_ALLOWLIST, value.provider) ||
230
- !ENDPOINT_MODEL_SELECTION_ALLOWLIST[value.provider].includes(value.model) ||
231
- !ENDPOINT_MODEL_REASONING_EFFORTS.includes(value.reasoningEffort)
232
- ) {
215
+ const compiled = compileEndpointModelSelection(value);
216
+ if (!compiled || compiled === "invalid") {
233
217
  throw new Error("hermes_runs_model_selection_rejected");
234
218
  }
235
- return Object.freeze({
236
- provider: value.provider,
237
- model: value.model,
238
- reasoningEffort: value.reasoningEffort,
239
- });
219
+ return compiled;
240
220
  }
241
221
 
242
222
  export function validateOpenerOutputContract(value) {
@@ -606,12 +586,19 @@ function submitNotAdmitted(response, value) {
606
586
  export function createHermesRunsClient(options = {}) {
607
587
  const {
608
588
  apiKeyFile,
589
+ baseUrl = LOOPBACK_ORIGIN,
590
+ scopeHeaders = {},
609
591
  fixture,
610
592
  fetchImpl = fetch,
611
593
  timeoutMs = 20_000,
612
594
  } = options;
613
595
  assertFixture(fixture);
596
+ const origin = normalizeRunsApiBaseUrl(baseUrl);
614
597
  if (
598
+ !origin ||
599
+ !exactObject(scopeHeaders) ||
600
+ Object.keys(scopeHeaders).some(key => !["x-sellable-workspace-id", "x-sellable-agent-id"].includes(key)) ||
601
+ Object.values(scopeHeaders).some(value => typeof value !== "string" || !/^[A-Za-z0-9_-]{1,128}$/.test(value)) ||
615
602
  typeof fetchImpl !== "function" ||
616
603
  !Number.isSafeInteger(timeoutMs) ||
617
604
  timeoutMs < 100 ||
@@ -624,9 +611,11 @@ export function createHermesRunsClient(options = {}) {
624
611
  if (!path.startsWith("/v1/runs")) {
625
612
  throw new Error("hermes_runs_path_rejected");
626
613
  }
627
- return fetchImpl(`${LOOPBACK_ORIGIN}${path}`, {
614
+ return fetchImpl(`${origin}${path}`, {
628
615
  ...init,
616
+ redirect: "error",
629
617
  headers: {
618
+ ...scopeHeaders,
630
619
  authorization: `Bearer ${apiKey}`,
631
620
  ...(init.body === undefined
632
621
  ? {}
@@ -0,0 +1,27 @@
1
+ export const RUNS_API_CONNECTIONS_ENV: "SELLABLE_AGENT_RUNS_API_CONNECTIONS_JSON";
2
+ export type RunsApiConnection = Readonly<{
3
+ runtimeId: string;
4
+ workspaceId: string;
5
+ agentId: string;
6
+ baseUrl: string;
7
+ apiKeyFile: string;
8
+ endpointIds: string[];
9
+ workKinds: Array<"STANDARD" | "OPENER" | "REPLY" | "FOLLOW_UP">;
10
+ models: Array<{
11
+ provider: string;
12
+ model: string;
13
+ reasoningEfforts: string[];
14
+ }>;
15
+ localRoot?: string;
16
+ toolEndpointIds?: string[];
17
+ }>;
18
+ export function parseRunsApiConnections(raw: unknown): RunsApiConnection[];
19
+ export function runsApiConnectionsForRuntime(
20
+ raw: unknown,
21
+ runtime: {
22
+ runtimeId: string;
23
+ workspaceId: string;
24
+ agentId: string;
25
+ }
26
+ ): RunsApiConnection[];
27
+ export function createConfiguredRunsClient(options: any): any;
@@ -0,0 +1,228 @@
1
+ import { createHash } from "node:crypto";
2
+ import {
3
+ compileEndpointModelSelection,
4
+ normalizeRunsApiBaseUrl,
5
+ } from "./endpoint-model-selection.mjs";
6
+ import { createHermesRunsClient } from "./hermes-runs-client.mjs";
7
+
8
+ export const RUNS_API_CONNECTIONS_ENV =
9
+ "SELLABLE_AGENT_RUNS_API_CONNECTIONS_JSON";
10
+ const id = (value) =>
11
+ typeof value === "string" && /^[A-Za-z0-9_.:-]{1,128}$/.test(value);
12
+ const record = (value) =>
13
+ value && typeof value === "object" && !Array.isArray(value);
14
+ const stable = (value) =>
15
+ Array.isArray(value)
16
+ ? `[${value.map(stable).join(",")}]`
17
+ : record(value)
18
+ ? `{${Object.keys(value)
19
+ .sort()
20
+ .map((key) => `${JSON.stringify(key)}:${stable(value[key])}`)
21
+ .join(",")}}`
22
+ : JSON.stringify(value);
23
+ const fail = () => {
24
+ throw new Error("runs_api_connection_configuration_rejected");
25
+ };
26
+
27
+ // Only the control plane's machine configuration supplies this registry. It
28
+ // contains credential file references, never credentials or request input.
29
+ export function parseRunsApiConnections(raw) {
30
+ if (raw === undefined || raw === "") return [];
31
+ if (typeof raw !== "string" || Buffer.byteLength(raw) > 64 * 1024) fail();
32
+ let entries;
33
+ try {
34
+ entries = JSON.parse(raw);
35
+ } catch {
36
+ fail();
37
+ }
38
+ if (!Array.isArray(entries) || entries.length > 32) fail();
39
+ const seen = new Set();
40
+ return entries.map((entry) => {
41
+ if (
42
+ !record(entry) ||
43
+ Object.keys(entry).some(
44
+ (key) =>
45
+ ![
46
+ "runtimeId",
47
+ "workspaceId",
48
+ "agentId",
49
+ "baseUrl",
50
+ "apiKeyFile",
51
+ "endpointIds",
52
+ "workKinds",
53
+ "models",
54
+ "localRoot",
55
+ "toolEndpointIds",
56
+ ].includes(key)
57
+ ) ||
58
+ ![entry.runtimeId, entry.workspaceId, entry.agentId].every(id) ||
59
+ typeof entry.apiKeyFile !== "string" ||
60
+ !/^\/(?:opt\/data|run\/secrets)\/[A-Za-z0-9_./-]{1,250}$/.test(
61
+ entry.apiKeyFile
62
+ ) ||
63
+ entry.apiKeyFile
64
+ .split("/")
65
+ .some((part) => part === "." || part === "..") ||
66
+ !Array.isArray(entry.endpointIds) ||
67
+ !entry.endpointIds.length ||
68
+ entry.endpointIds.length > 64 ||
69
+ !entry.endpointIds.every(id) ||
70
+ !Array.isArray(entry.workKinds) ||
71
+ !entry.workKinds.length ||
72
+ !entry.workKinds.every((kind) =>
73
+ ["STANDARD", "OPENER", "REPLY", "FOLLOW_UP"].includes(kind)
74
+ ) ||
75
+ !Array.isArray(entry.models) ||
76
+ !entry.models.length ||
77
+ entry.models.length > 16
78
+ )
79
+ fail();
80
+ const baseUrl = normalizeRunsApiBaseUrl(entry.baseUrl);
81
+ if (!baseUrl) fail();
82
+ const identity = `${entry.runtimeId}:${baseUrl}`;
83
+ if (seen.has(identity)) fail();
84
+ seen.add(identity);
85
+ const models = entry.models.map((model) => {
86
+ if (
87
+ !record(model) ||
88
+ Object.keys(model).sort().join(",") !==
89
+ "model,provider,reasoningEfforts" ||
90
+ !Array.isArray(model.reasoningEfforts) ||
91
+ !model.reasoningEfforts.length ||
92
+ model.reasoningEfforts.some(
93
+ (reasoningEffort) =>
94
+ compileEndpointModelSelection({
95
+ provider: model.provider,
96
+ model: model.model,
97
+ reasoningEffort,
98
+ runsApiBaseUrl: baseUrl,
99
+ }) === "invalid"
100
+ )
101
+ )
102
+ fail();
103
+ return { ...model, reasoningEfforts: [...model.reasoningEfforts] };
104
+ });
105
+ if (entry.localRoot !== undefined) {
106
+ const url = new URL(baseUrl);
107
+ if (
108
+ typeof entry.localRoot !== "string" ||
109
+ !/^\/opt\/data\/[A-Za-z0-9_-]{1,80}$/.test(entry.localRoot) ||
110
+ entry.apiKeyFile !== `${entry.localRoot}/api-key` ||
111
+ url.hostname !== "127.0.0.1" ||
112
+ url.protocol !== "http:" ||
113
+ url.pathname !== "/" ||
114
+ !url.port ||
115
+ Number(url.port) < 1024 ||
116
+ models.some(
117
+ (model) =>
118
+ model.provider !== "claude-code" ||
119
+ !/^claude-[a-z0-9-]{1,100}$/.test(model.model) ||
120
+ model.reasoningEfforts.some(
121
+ (effort) => !["low", "medium", "high"].includes(effort)
122
+ )
123
+ )
124
+ )
125
+ fail();
126
+ }
127
+ // Runs on these endpoints get their own allowed tools from the image-owned
128
+ // service; every other run stays tool-free.
129
+ if (
130
+ entry.toolEndpointIds !== undefined &&
131
+ (entry.localRoot === undefined ||
132
+ !Array.isArray(entry.toolEndpointIds) ||
133
+ !entry.toolEndpointIds.length ||
134
+ new Set(entry.toolEndpointIds).size !== entry.toolEndpointIds.length ||
135
+ entry.toolEndpointIds.some(
136
+ (value) => !entry.endpointIds.includes(value)
137
+ ))
138
+ )
139
+ fail();
140
+ return Object.freeze({
141
+ ...entry,
142
+ baseUrl,
143
+ models,
144
+ endpointIds: [...entry.endpointIds],
145
+ workKinds: [...entry.workKinds],
146
+ ...(entry.toolEndpointIds === undefined
147
+ ? {}
148
+ : { toolEndpointIds: [...entry.toolEndpointIds] }),
149
+ });
150
+ });
151
+ }
152
+
153
+ export function runsApiConnectionsForRuntime(raw, runtime) {
154
+ return parseRunsApiConnections(raw).filter(
155
+ (connection) =>
156
+ connection.runtimeId === runtime.runtimeId &&
157
+ connection.workspaceId === runtime.workspaceId &&
158
+ connection.agentId === runtime.agentId
159
+ );
160
+ }
161
+
162
+ /** @param {any} options */
163
+ export function createConfiguredRunsClient({
164
+ apiKeyFile,
165
+ claim,
166
+ env = process.env,
167
+ clientFactory = createHermesRunsClient,
168
+ }) {
169
+ const selection = claim?.run?.modelSelection;
170
+ if (!selection?.runsApiBaseUrl) return clientFactory({ apiKeyFile });
171
+ const model = compileEndpointModelSelection(selection);
172
+ if (!model || model === "invalid") throw new Error("runs_api_model_rejected");
173
+ const connection = runsApiConnectionsForRuntime(
174
+ env[RUNS_API_CONNECTIONS_ENV],
175
+ {
176
+ runtimeId: claim.runtime?.runtimeId,
177
+ workspaceId: claim.attempt?.workspaceId,
178
+ agentId: claim.attempt?.agentId,
179
+ }
180
+ ).find((value) => value.baseUrl === model.runsApiBaseUrl);
181
+ const workKind = claim.run.productExecution?.workKind ?? "STANDARD";
182
+ if (
183
+ !connection ||
184
+ env.SELLABLE_RUNTIME_ID !== connection.runtimeId ||
185
+ !connection.endpointIds.includes(claim.attempt.endpointId) ||
186
+ !connection.workKinds.includes(workKind) ||
187
+ !connection.models.some(
188
+ (allowed) =>
189
+ allowed.provider === model.provider &&
190
+ allowed.model === model.model &&
191
+ allowed.reasoningEfforts.includes(model.reasoningEffort)
192
+ )
193
+ )
194
+ throw new Error("runs_api_connection_not_authorized");
195
+ // This client instance retains one destination and one credential for the
196
+ // entire attempt, including stream/status/stop, even if settings later change.
197
+ const client = clientFactory({
198
+ baseUrl: connection.baseUrl,
199
+ apiKeyFile: connection.apiKeyFile,
200
+ scopeHeaders: {
201
+ "x-sellable-workspace-id": connection.workspaceId,
202
+ "x-sellable-agent-id": connection.agentId,
203
+ },
204
+ });
205
+ return Object.freeze({
206
+ ...client,
207
+ submit(compiled, options) {
208
+ // Public semantic endpoints have a published schema but no product tuple.
209
+ // Preserve that existing contract when calling a custom Runs service.
210
+ const schema = claim.revision?.outputSchema;
211
+ if (compiled.outputContract || !schema?.properties?.proposal)
212
+ return client.submit(compiled, options);
213
+ return client.submit(
214
+ {
215
+ ...compiled,
216
+ outputContract: {
217
+ schemaVersion: "sellable-opener-output-contract/v1",
218
+ schema,
219
+ nativeProposalSchemaDigest: createHash("sha256")
220
+ .update(stable(schema.properties.proposal))
221
+ .digest("hex"),
222
+ },
223
+ },
224
+ options
225
+ );
226
+ },
227
+ });
228
+ }
@@ -38,7 +38,7 @@ import { installAgentHostServices } from "./service-installer.mjs";
38
38
  const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
39
39
  const VERSION = "sellable-agent-host-bootstrap/v1";
40
40
  const RECEIPT_VERSION = "sellable-agent-host-registration/v1";
41
- const INSTALLER_PACKAGE = "@sellable/install@0.1.794";
41
+ const INSTALLER_PACKAGE = "@sellable/install@0.1.796";
42
42
  const MCP_PACKAGE = "@sellable/mcp@0.1.957";
43
43
  const HERMES_VERSION = "0.18.0";
44
44
  const SHA256 = /^[a-f0-9]{64}$/;
@@ -1546,7 +1546,7 @@ export function compileClaimToProfileDesired(activeClaim, config) {
1546
1546
  ]) ||
1547
1547
  pinned.hermesCli !== "hermes" ||
1548
1548
  pinned.hermesVersion !== "0.18.0" ||
1549
- pinned.installerPackage !== "@sellable/install@0.1.794" ||
1549
+ pinned.installerPackage !== "@sellable/install@0.1.796" ||
1550
1550
  pinned.mcpPackage !== "@sellable/mcp@0.1.957" ||
1551
1551
  !Array.isArray(policy.toolInclude) ||
1552
1552
  policy.toolInclude.length === 0 ||
@@ -312,7 +312,7 @@ function validateDesired(desired) {
312
312
  desired.serviceCredentialGeneration < 1 ||
313
313
  desired.hermesCli !== "hermes" ||
314
314
  desired.hermesVersion !== "0.18.0" ||
315
- desired.installerPackage !== "@sellable/install@0.1.794" ||
315
+ desired.installerPackage !== "@sellable/install@0.1.796" ||
316
316
  desired.mcpPackage !== "@sellable/mcp@0.1.957" ||
317
317
  !Array.isArray(desired.toolInclude) ||
318
318
  desired.toolInclude.length === 0 ||
@@ -25,7 +25,7 @@ import { fileURLToPath } from "node:url";
25
25
  import { deriveContainedProfileId } from "./profile-materializer.mjs";
26
26
 
27
27
  export const PROVISIONING_ACTION = "PROVISION_HERMES_PROFILE";
28
- export const PINNED_INSTALL_PACKAGE = "@sellable/install@0.1.794";
28
+ export const PINNED_INSTALL_PACKAGE = "@sellable/install@0.1.796";
29
29
  export const PINNED_MCP_PACKAGE = "@sellable/mcp@0.1.957";
30
30
  const PINNED_INSTALL_VERSION = PINNED_INSTALL_PACKAGE.slice(
31
31
  PINNED_INSTALL_PACKAGE.lastIndexOf("@") + 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sellable/install",
3
- "version": "0.1.794",
3
+ "version": "0.1.796",
4
4
  "type": "module",
5
5
  "description": "One-command installer for Sellable MCP in Claude Code, Codex, and Hermes",
6
6
  "bin": {