@vellumai/credential-executor 0.11.5 → 0.11.6-dev.202608252309.48526e7

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.
@@ -2,7 +2,12 @@ import { describe, expect, test } from "bun:test";
2
2
 
3
3
  import {
4
4
  normalizeHttpPublicBaseUrl,
5
+ normalizeHttpPublicBaseUrlWithoutTrailingSlash,
5
6
  normalizePublicBaseUrl,
7
+ parseRecordedAssistantId,
8
+ parseTunnelRecord,
9
+ trimmedNonEmptyString,
10
+ TUNNEL_PROVIDERS,
6
11
  velayHostForPlatformHost,
7
12
  } from "../ingress.js";
8
13
  import {
@@ -85,6 +90,35 @@ describe("normalizeHttpPublicBaseUrl", () => {
85
90
  });
86
91
  });
87
92
 
93
+ describe("normalizeHttpPublicBaseUrlWithoutTrailingSlash", () => {
94
+ test("drops the root path its sibling always emits", () => {
95
+ expect(
96
+ normalizeHttpPublicBaseUrlWithoutTrailingSlash("https://x.test"),
97
+ ).toBe("https://x.test");
98
+ expect(
99
+ normalizeHttpPublicBaseUrlWithoutTrailingSlash("https://x.test/"),
100
+ ).toBe("https://x.test");
101
+ expect(
102
+ normalizeHttpPublicBaseUrlWithoutTrailingSlash(" https://x.test/api/// "),
103
+ ).toBe("https://x.test/api");
104
+ });
105
+
106
+ test("rejects everything its sibling rejects", () => {
107
+ for (const value of [
108
+ "",
109
+ " ",
110
+ "notaurl",
111
+ "ftp://x.test",
112
+ "https://x.test?a=b",
113
+ 42,
114
+ ]) {
115
+ expect(
116
+ normalizeHttpPublicBaseUrlWithoutTrailingSlash(value),
117
+ ).toBeUndefined();
118
+ }
119
+ });
120
+ });
121
+
88
122
  describe("Twilio ingress helpers", () => {
89
123
  test("resolves public base URL with fallback", () => {
90
124
  expect(
@@ -123,3 +157,87 @@ describe("Twilio ingress helpers", () => {
123
157
  });
124
158
  });
125
159
  });
160
+
161
+ describe("parseTunnelRecord", () => {
162
+ const TUNNEL_URL = "https://assistant-1.example.ts.net";
163
+
164
+ test("accepts every provider in the registry", () => {
165
+ for (const provider of TUNNEL_PROVIDERS) {
166
+ expect(
167
+ parseTunnelRecord({ provider, publicBaseUrl: TUNNEL_URL }),
168
+ ).toEqual({ provider, publicBaseUrl: TUNNEL_URL });
169
+ }
170
+ });
171
+
172
+ test("returns the URL in the shape its own validator produces", () => {
173
+ // Padding and trailing slashes are normalized away rather than handed
174
+ // back, so readers never re-normalize what they were given.
175
+ for (const publicBaseUrl of [
176
+ ` ${TUNNEL_URL} `,
177
+ `${TUNNEL_URL}/`,
178
+ `${TUNNEL_URL}///`,
179
+ ]) {
180
+ expect(
181
+ parseTunnelRecord({ provider: "ngrok", publicBaseUrl }),
182
+ ).toEqual({ provider: "ngrok", publicBaseUrl: TUNNEL_URL });
183
+ }
184
+ });
185
+
186
+ test("rejects values that are not a record", () => {
187
+ for (const value of [undefined, null, "nonsense", 42, []]) {
188
+ expect(parseTunnelRecord(value)).toBeNull();
189
+ }
190
+ });
191
+
192
+ test("rejects a record missing either field", () => {
193
+ expect(parseTunnelRecord({ provider: "ngrok" })).toBeNull();
194
+ expect(parseTunnelRecord({ publicBaseUrl: TUNNEL_URL })).toBeNull();
195
+ });
196
+
197
+ test("rejects a provider outside the registry", () => {
198
+ // Readers render the provider into a `vellum tunnel --provider <name>`
199
+ // command, so a hand-edited config must not reach a terminal.
200
+ for (const provider of ["wireguard", "; rm -rf /", "", 42]) {
201
+ expect(
202
+ parseTunnelRecord({ provider, publicBaseUrl: TUNNEL_URL }),
203
+ ).toBeNull();
204
+ }
205
+ });
206
+
207
+ test("rejects a URL that is not absolute HTTP(S)", () => {
208
+ for (const publicBaseUrl of [
209
+ "",
210
+ " ",
211
+ "not-a-url",
212
+ "example.ts.net",
213
+ "ftp://x.test",
214
+ "https://one.ngrok.app?token=x",
215
+ 42,
216
+ ]) {
217
+ expect(
218
+ parseTunnelRecord({ provider: "ngrok", publicBaseUrl }),
219
+ ).toBeNull();
220
+ }
221
+ });
222
+ });
223
+
224
+ describe("trimmedNonEmptyString", () => {
225
+ test("trims and rejects blank or non-string values", () => {
226
+ expect(trimmedNonEmptyString(" assistant-1 ")).toBe("assistant-1");
227
+ for (const value of ["", " ", undefined, null, 42]) {
228
+ expect(trimmedNonEmptyString(value)).toBeUndefined();
229
+ }
230
+ });
231
+ });
232
+
233
+ describe("parseRecordedAssistantId", () => {
234
+ test("trims a recorded id", () => {
235
+ expect(parseRecordedAssistantId(" assistant-1 ")).toBe("assistant-1");
236
+ });
237
+
238
+ test("rejects blank and non-string values", () => {
239
+ for (const value of ["", " ", undefined, null, 42]) {
240
+ expect(parseRecordedAssistantId(value)).toBeNull();
241
+ }
242
+ });
243
+ });
@@ -48,3 +48,106 @@ export function normalizeHttpPublicBaseUrl(value: unknown): string | undefined {
48
48
  return undefined;
49
49
  }
50
50
  }
51
+
52
+ /**
53
+ * The same validation as `normalizeHttpPublicBaseUrl`, minus the root path it
54
+ * always emits (`https://x` becomes `https://x/`). Callers that append a path
55
+ * or persist the result want this shape, so they neither join through a double
56
+ * slash nor re-strip what the normalizer just added.
57
+ */
58
+ export function normalizeHttpPublicBaseUrlWithoutTrailingSlash(
59
+ value: unknown,
60
+ ): string | undefined {
61
+ return normalizePublicBaseUrl(normalizeHttpPublicBaseUrl(value));
62
+ }
63
+
64
+ /**
65
+ * A trimmed string, or undefined when the value is not a non-blank string.
66
+ *
67
+ * Exported because the identity check in the daemon's tunnel probe compares an
68
+ * id recorded here against one an edge serves, and the two sides have to trim
69
+ * alike: a padded served id must read as a match, not as a different
70
+ * assistant.
71
+ */
72
+ export function trimmedNonEmptyString(value: unknown): string | undefined {
73
+ if (typeof value !== "string") {
74
+ return undefined;
75
+ }
76
+ const trimmed = value.trim();
77
+ return trimmed.length > 0 ? trimmed : undefined;
78
+ }
79
+
80
+ // Records `vellum tunnel` leaves in the workspace config's `ingress` section.
81
+ // The CLI writes them and the daemon reads them, and the two are separate
82
+ // build units that cannot import each other, so the key names, the provider
83
+ // allowlist, and the validation all live here rather than in a copy on each
84
+ // side.
85
+
86
+ /** Key under `ingress` holding the tunnel that most recently ran. */
87
+ export const INGRESS_LAST_TUNNEL_KEY = "lastTunnel";
88
+
89
+ /**
90
+ * Key under `ingress` holding a tunnel published for device pairing alone.
91
+ *
92
+ * A tailnet-only tunnel started while webhook integrations are configured
93
+ * cannot carry their callbacks, so it leaves `publicBaseUrl` (the callback
94
+ * base) as it is and records itself here. Readers that answer the pairing card
95
+ * prefer this address over `publicBaseUrl`; teardown drops the key.
96
+ */
97
+ export const INGRESS_PAIRING_TUNNEL_KEY = "pairingTunnel";
98
+
99
+ /** Key under `ingress` holding the assistant id that tunnel fronted. */
100
+ export const INGRESS_ASSISTANT_ID_KEY = "assistantId";
101
+
102
+ /**
103
+ * The local tunnel providers the CLI can start, in the order they are offered.
104
+ * `vellum tunnel`'s accepted `--provider` values and the persisted-record
105
+ * validation below both derive from it.
106
+ */
107
+ export const TUNNEL_PROVIDERS = ["ngrok", "cloudflare", "tailscale"] as const;
108
+
109
+ export type TunnelProviderName = (typeof TUNNEL_PROVIDERS)[number];
110
+
111
+ /** A recorded tunnel, kept after teardown so UIs can name the command to restart. */
112
+ export interface TunnelRecord {
113
+ provider: TunnelProviderName;
114
+ publicBaseUrl: string;
115
+ }
116
+
117
+ function isTunnelProviderName(value: unknown): value is TunnelProviderName {
118
+ return (
119
+ typeof value === "string" &&
120
+ (TUNNEL_PROVIDERS as readonly string[]).includes(value)
121
+ );
122
+ }
123
+
124
+ /**
125
+ * Parse an `ingress.lastTunnel` or `ingress.pairingTunnel` value, or null when
126
+ * it is absent or malformed.
127
+ *
128
+ * A hand-edited config must not hand callers an unusable address or a provider
129
+ * name no command accepts: the provider is checked against the allowlist
130
+ * because readers render it into a restart command, and the URL faces the same
131
+ * absolute HTTP(S) constraint as every other public base URL. The URL comes
132
+ * back in the shape the validator produced, so readers never re-normalize it.
133
+ */
134
+ export function parseTunnelRecord(value: unknown): TunnelRecord | null {
135
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
136
+ return null;
137
+ }
138
+ const { provider, publicBaseUrl } = value as Record<string, unknown>;
139
+ if (!isTunnelProviderName(provider)) {
140
+ return null;
141
+ }
142
+ const normalized =
143
+ normalizeHttpPublicBaseUrlWithoutTrailingSlash(publicBaseUrl);
144
+ if (normalized === undefined) {
145
+ return null;
146
+ }
147
+ return { provider, publicBaseUrl: normalized };
148
+ }
149
+
150
+ /** Parse an `ingress.assistantId` value, or null when it is absent or blank. */
151
+ export function parseRecordedAssistantId(value: unknown): string | null {
152
+ return trimmedNonEmptyString(value) ?? null;
153
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/credential-executor",
3
- "version": "0.11.5",
3
+ "version": "0.11.6-dev.202608252309.48526e7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {