@vellumai/credential-executor 0.11.9 → 0.11.10-dev.202609090222.f16830b

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/Dockerfile CHANGED
@@ -27,7 +27,8 @@ COPY assistant/package.json ./assistant/
27
27
  COPY assistant/src/api/package.json ./assistant/src/api/
28
28
  COPY --parents packages/*/package.json ./
29
29
 
30
- RUN bun install --frozen-lockfile --ignore-scripts \
30
+ RUN --mount=type=cache,id=bun-install-cache,target=/root/.bun/install/cache \
31
+ bun install --frozen-lockfile --ignore-scripts \
31
32
  --filter='./credential-executor'
32
33
 
33
34
  # Runtime stage
@@ -50,7 +51,7 @@ RUN ln -sf /usr/local/bin/bun /usr/local/bin/bunx
50
51
  RUN groupadd --system --gid 1001 ces && \
51
52
  useradd --system --uid 1001 --gid ces --create-home ces
52
53
 
53
- COPY --from=builder --chown=ces:ces /app /app
54
+ COPY --link --from=builder --chown=1001:1001 /app /app
54
55
 
55
56
  # Copy source after installing dependencies for better layer caching.
56
57
  COPY --chown=ces:ces packages/service-contracts /app/packages/service-contracts
@@ -10,6 +10,7 @@
10
10
  "./conversation-handle": "./src/conversation-handle.ts",
11
11
  "./client-metadata": "./src/client-metadata.ts",
12
12
  "./credential-rpc": "./src/credential-rpc.ts",
13
+ "./desktop-presence": "./src/desktop-presence.ts",
13
14
  "./ingress": "./src/ingress.ts",
14
15
  "./no-response": "./src/no-response.ts",
15
16
  "./remote-web-pairing": "./src/remote-web-pairing.ts",
@@ -25,7 +26,8 @@
25
26
  "./error": "./src/error.ts",
26
27
  "./reactions": "./src/reactions.ts",
27
28
  "./guardian-requests": "./src/guardian-requests.ts",
28
- "./platform-credential": "./src/platform-credential.ts"
29
+ "./platform-credential": "./src/platform-credential.ts",
30
+ "./plan-credit": "./src/plan-credit.ts"
29
31
  },
30
32
  "scripts": {
31
33
  "typecheck": "bunx tsc --noEmit",
@@ -0,0 +1,51 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import {
4
+ extraCreditUsd,
5
+ planCreditUsedFraction,
6
+ usageGrantRatio,
7
+ } from "../plan-credit.js";
8
+
9
+ describe("usageGrantRatio", () => {
10
+ test("reads the used share and clamps to 0..1", () => {
11
+ expect(usageGrantRatio(20, 9.1)).toBeCloseTo(0.545);
12
+ expect(usageGrantRatio(20, 0)).toBe(1);
13
+ expect(usageGrantRatio(20, 25)).toBe(0);
14
+ });
15
+
16
+ test("has no reading without both figures or with nothing granted", () => {
17
+ expect(usageGrantRatio(null, 5)).toBeNull();
18
+ expect(usageGrantRatio(20, null)).toBeNull();
19
+ expect(usageGrantRatio(0, 0)).toBeNull();
20
+ });
21
+ });
22
+
23
+ describe("planCreditUsedFraction", () => {
24
+ test("prefers the ratio whatever the plan", () => {
25
+ expect(planCreditUsedFraction(20, 9.1, "base")).toBeCloseTo(0.545);
26
+ expect(planCreditUsedFraction(20, 9.1, null)).toBeCloseTo(0.545);
27
+ });
28
+
29
+ test("treats a Pro plan with nothing granted as fully spent", () => {
30
+ expect(planCreditUsedFraction(0, 0, "pro")).toBe(1);
31
+ expect(planCreditUsedFraction(0, null, "pro")).toBe(1);
32
+ });
33
+
34
+ test("gives a base or unknown plan with nothing granted no reading", () => {
35
+ expect(planCreditUsedFraction(0, 0, "base")).toBeNull();
36
+ expect(planCreditUsedFraction(0, 0, null)).toBeNull();
37
+ expect(planCreditUsedFraction(null, null, "pro")).toBeNull();
38
+ });
39
+ });
40
+
41
+ describe("extraCreditUsd", () => {
42
+ test("nets unused grant credit out of the balance to the cent", () => {
43
+ expect(extraCreditUsd(42.17, 9.1)).toBe(33.07);
44
+ expect(extraCreditUsd(34.65, 9.1)).toBe(25.55);
45
+ });
46
+
47
+ test("never goes below zero", () => {
48
+ expect(extraCreditUsd(5, 9.1)).toBe(0);
49
+ expect(extraCreditUsd(-2.5, 0)).toBe(0);
50
+ });
51
+ });
@@ -38,6 +38,8 @@ const FIXTURES: Record<string, string> = {
38
38
  "GitLab Token": `glpat-${filler(20)}`,
39
39
  "Stripe Secret Key": `sk_live_${filler(24)}`,
40
40
  "Stripe Restricted Key": `rk_live_${filler(24)}`,
41
+ "Link Access Token": `liwltoken_${filler(24)}`,
42
+ "Link Refresh Token": `liwlrefresh_${filler(24)}`,
41
43
  "Slack Bot Token": `xoxb-1234567890-1234567890-${filler(24)}`,
42
44
  "Slack User Token": `xoxp-1234567890-1234567890-1234567890-${"0123456789abcdef".repeat(2)}`,
43
45
  "Slack App Token": "xapp-1-abc123-4567-defghij890",
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The presence states a desktop client may report. Single runtime source for
3
+ * the daemon's stored type, the client route's wire enum, and the Electron
4
+ * presence monitor.
5
+ *
6
+ * Member order is load-bearing: the route feeds this tuple to `z.enum`, so
7
+ * reordering rewrites the generated `assistant/openapi.yaml`.
8
+ */
9
+ export const DESKTOP_PRESENCE_STATES = ["active", "idle", "away"] as const;
10
+
11
+ export type DesktopPresenceState = (typeof DESKTOP_PRESENCE_STATES)[number];
@@ -28,6 +28,7 @@ export * from "./rpc.js";
28
28
  export * from "./trust-rules.js";
29
29
  export * from "./ingress.js";
30
30
  export * from "./no-response.js";
31
+ export * from "./plan-credit.js";
31
32
  export * from "./platform-credential.js";
32
33
  export * from "./remote-web-pairing.js";
33
34
  export * from "./twilio-ingress.js";
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Plan-credit derivations shared by the assistant runtime's `platform credits`
3
+ * route and the web client's usage meter, so both read the billing summary's
4
+ * grant figures the same way and can never quote different readings.
5
+ */
6
+
7
+ export type BillingPlanId = "base" | "pro";
8
+
9
+ function clamp01(value: number): number {
10
+ if (!Number.isFinite(value) || value < 0) {
11
+ return 0;
12
+ }
13
+ return value > 1 ? 1 : value;
14
+ }
15
+
16
+ /**
17
+ * How much of the usage credit an account was granted it has already used:
18
+ * the granted total less what is still unused, over that total. The initial
19
+ * $5 grant burns 0 to 100% as it is spent, and a further grant grows the total
20
+ * so the bar drops back. Null when nothing was ever granted, or when the
21
+ * platform reports neither figure, which has no honest reading rather than a
22
+ * full or empty bar.
23
+ */
24
+ export function usageGrantRatio(
25
+ totalUsd: number | null,
26
+ availableUsd: number | null,
27
+ ): number | null {
28
+ if (totalUsd == null || availableUsd == null || totalUsd <= 0) {
29
+ return null;
30
+ }
31
+ return clamp01((totalUsd - availableUsd) / totalUsd);
32
+ }
33
+
34
+ /**
35
+ * The plan-credit reading with the plan's fallback applied. The grant figures
36
+ * count only unexpired grants, so a Pro subscription whose grants total
37
+ * nothing has used or expired everything it was granted (a full bar, with
38
+ * nothing scheduled to refill it), while a base plan in that position was
39
+ * never granted anything (no reading). An unknown plan gets the ratio when
40
+ * the figures allow one and no fallback otherwise.
41
+ */
42
+ export function planCreditUsedFraction(
43
+ totalUsd: number | null,
44
+ availableUsd: number | null,
45
+ planId: BillingPlanId | null,
46
+ ): number | null {
47
+ const ratio = usageGrantRatio(totalUsd, availableUsd);
48
+ if (ratio != null) {
49
+ return ratio;
50
+ }
51
+ if (planId === "pro" && totalUsd != null && totalUsd <= 0) {
52
+ return 1;
53
+ }
54
+ return null;
55
+ }
56
+
57
+ /**
58
+ * Credit bought or earned on top of the plan-included grants: the balance less
59
+ * whatever is still unused on those grants, never below zero, to the cent.
60
+ */
61
+ export function extraCreditUsd(
62
+ balanceUsd: number,
63
+ availableUsd: number,
64
+ ): number {
65
+ return Math.round(Math.max(0, balanceUsd - availableUsd) * 100) / 100;
66
+ }
@@ -143,6 +143,13 @@ export const PREFIX_PATTERNS: SecretPrefixPattern[] = [
143
143
  // -- Stripe --
144
144
  { label: "Stripe Secret Key", regex: /sk_live_[A-Za-z0-9]{24,}/ },
145
145
  { label: "Stripe Restricted Key", regex: /rk_live_[A-Za-z0-9]{24,}/ },
146
+ // Link (Stripe's wallet) issues prefixed OAuth tokens rather than opaque
147
+ // ones, and its own docs tell users to export the access token as
148
+ // LINK_ACCESS_TOKEN to drive link-cli, so these do get pasted by hand. A
149
+ // leaked one can spend from the wallet. The `lwlpk_` client id is public
150
+ // (it ships in the CLI bundle) and is deliberately not matched here.
151
+ { label: "Link Access Token", regex: /liwltoken_[A-Za-z0-9]{16,}/ },
152
+ { label: "Link Refresh Token", regex: /liwlrefresh_[A-Za-z0-9]{16,}/ },
146
153
 
147
154
  // -- Slack --
148
155
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/credential-executor",
3
- "version": "0.11.9",
3
+ "version": "0.11.10-dev.202609090222.f16830b",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {