@percher/core 1.7.0 → 2.0.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/dist/commands/claim.d.ts.map +1 -1
- package/dist/commands/claim.js +5 -8
- package/dist/commands/claim.js.map +1 -1
- package/dist/commands/diagnose.d.ts +7 -6
- package/dist/commands/diagnose.d.ts.map +1 -1
- package/dist/commands/diagnose.js +5 -4
- package/dist/commands/diagnose.js.map +1 -1
- package/dist/commands/doctor-access.d.ts +4 -0
- package/dist/commands/doctor-access.d.ts.map +1 -0
- package/dist/commands/doctor-access.js +32 -0
- package/dist/commands/doctor-access.js.map +1 -0
- package/dist/commands/doctor-build.d.ts +60 -0
- package/dist/commands/doctor-build.d.ts.map +1 -0
- package/dist/commands/doctor-build.js +470 -0
- package/dist/commands/doctor-build.js.map +1 -0
- package/dist/commands/doctor-evidence.d.ts +67 -0
- package/dist/commands/doctor-evidence.d.ts.map +1 -0
- package/dist/commands/doctor-evidence.js +102 -0
- package/dist/commands/doctor-evidence.js.map +1 -0
- package/dist/commands/doctor-observations.d.ts +19 -0
- package/dist/commands/doctor-observations.d.ts.map +1 -0
- package/dist/commands/doctor-observations.js +166 -0
- package/dist/commands/doctor-observations.js.map +1 -0
- package/dist/commands/doctor-route.d.ts +10 -0
- package/dist/commands/doctor-route.d.ts.map +1 -0
- package/dist/commands/doctor-route.js +104 -0
- package/dist/commands/doctor-route.js.map +1 -0
- package/dist/commands/doctor-runtime.d.ts +41 -0
- package/dist/commands/doctor-runtime.d.ts.map +1 -0
- package/dist/commands/doctor-runtime.js +276 -0
- package/dist/commands/doctor-runtime.js.map +1 -0
- package/dist/commands/doctor-state.d.ts +36 -0
- package/dist/commands/doctor-state.d.ts.map +1 -0
- package/dist/commands/doctor-state.js +671 -0
- package/dist/commands/doctor-state.js.map +1 -0
- package/dist/commands/doctor.d.ts +98 -13
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +217 -374
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/env-scan.d.ts +1 -1
- package/dist/commands/env-scan.js +2 -2
- package/dist/commands/env-scan.js.map +1 -1
- package/dist/commands/preview-branch.d.ts +2 -0
- package/dist/commands/preview-branch.d.ts.map +1 -1
- package/dist/commands/preview-branch.js +1 -0
- package/dist/commands/preview-branch.js.map +1 -1
- package/dist/commands/publish-anonymous.d.ts +3 -0
- package/dist/commands/publish-anonymous.d.ts.map +1 -1
- package/dist/commands/publish-anonymous.js +6 -3
- package/dist/commands/publish-anonymous.js.map +1 -1
- package/dist/commands/publish-api-error.d.ts.map +1 -1
- package/dist/commands/publish-api-error.js +4 -1
- package/dist/commands/publish-api-error.js.map +1 -1
- package/dist/commands/publish-failure.d.ts +17 -0
- package/dist/commands/publish-failure.d.ts.map +1 -1
- package/dist/commands/publish-failure.js +30 -8
- package/dist/commands/publish-failure.js.map +1 -1
- package/dist/commands/publish-needs-login.d.ts +2 -2
- package/dist/commands/publish-needs-login.d.ts.map +1 -1
- package/dist/commands/publish-needs-login.js +4 -15
- package/dist/commands/publish-needs-login.js.map +1 -1
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +22 -20
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/restore.d.ts.map +1 -1
- package/dist/commands/restore.js +29 -2
- package/dist/commands/restore.js.map +1 -1
- package/dist/commands/wait-deploy.d.ts +1 -1
- package/dist/commands/wait-deploy.d.ts.map +1 -1
- package/dist/doctor.d.ts +2 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +2 -0
- package/dist/doctor.js.map +1 -0
- package/dist/error-classifier.d.ts +1 -1
- package/dist/error-classifier.d.ts.map +1 -1
- package/dist/error-classifier.js +15 -15
- package/dist/error-classifier.js.map +1 -1
- package/dist/index.d.ts +3 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/log-excerpt.d.ts +12 -0
- package/dist/log-excerpt.d.ts.map +1 -0
- package/dist/log-excerpt.js +88 -0
- package/dist/log-excerpt.js.map +1 -0
- package/dist/network-budget-recovery.d.ts +16 -0
- package/dist/network-budget-recovery.d.ts.map +1 -0
- package/dist/network-budget-recovery.js +32 -0
- package/dist/network-budget-recovery.js.map +1 -0
- package/dist/plans.d.ts +35 -0
- package/dist/plans.d.ts.map +1 -1
- package/dist/plans.js +20 -0
- package/dist/plans.js.map +1 -1
- package/dist/recovery.d.ts +9 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +39 -15
- package/dist/recovery.js.map +1 -1
- package/dist/security-deployment-failure.d.ts.map +1 -1
- package/dist/security-deployment-failure.js +2 -1
- package/dist/security-deployment-failure.js.map +1 -1
- package/dist/static-docker.d.ts +1 -1
- package/dist/static-docker.js +3 -3
- package/dist/structured-error-codes.d.ts +6 -1
- package/dist/structured-error-codes.d.ts.map +1 -1
- package/dist/structured-error-codes.js +51 -0
- package/dist/structured-error-codes.js.map +1 -1
- package/dist/templates/ai-files/claude-md.d.ts.map +1 -1
- package/dist/templates/ai-files/claude-md.js +8 -1
- package/dist/templates/ai-files/claude-md.js.map +1 -1
- package/dist/templates/ai-files/cursor-percher-mdc.d.ts.map +1 -1
- package/dist/templates/ai-files/cursor-percher-mdc.js +5 -1
- package/dist/templates/ai-files/cursor-percher-mdc.js.map +1 -1
- package/dist/validation/blocked-names.d.ts +2 -0
- package/dist/validation/blocked-names.d.ts.map +1 -1
- package/dist/validation/blocked-names.js +30 -1
- package/dist/validation/blocked-names.js.map +1 -1
- package/package.json +10 -5
- package/templates/astro/Dockerfile +2 -2
- package/templates/capsule/Dockerfile +2 -5
- package/templates/eleventy/Dockerfile +2 -2
- package/templates/hugo/Dockerfile +2 -2
- package/templates/preact/Dockerfile +2 -2
- package/templates/solid/Dockerfile +2 -2
- package/templates/vite-react/Dockerfile +2 -2
- package/templates/vite-vue/Dockerfile +2 -2
- package/dist/commands/admin-legacy-audit.d.ts +0 -40
- package/dist/commands/admin-legacy-audit.d.ts.map +0 -1
- package/dist/commands/admin-legacy-audit.js +0 -57
- package/dist/commands/admin-legacy-audit.js.map +0 -1
- package/dist/commands/admin-legacy-inventory.d.ts +0 -27
- package/dist/commands/admin-legacy-inventory.d.ts.map +0 -1
- package/dist/commands/admin-legacy-inventory.js +0 -37
- package/dist/commands/admin-legacy-inventory.js.map +0 -1
- package/dist/commands/admin-migrate-networks.d.ts +0 -15
- package/dist/commands/admin-migrate-networks.d.ts.map +0 -1
- package/dist/commands/admin-migrate-networks.js +0 -15
- package/dist/commands/admin-migrate-networks.js.map +0 -1
- package/dist/commands/admin-reconcile-routes.d.ts +0 -18
- package/dist/commands/admin-reconcile-routes.d.ts.map +0 -1
- package/dist/commands/admin-reconcile-routes.js +0 -22
- package/dist/commands/admin-reconcile-routes.js.map +0 -1
- package/templates/capsule/src/lib/ai-client.ts +0 -193
- package/templates/capsule/src/lib/ai.ts +0 -15
|
@@ -19,8 +19,8 @@ RUN bun -e 'const fs=require("node:fs"),path=require("node:path");const root=fs.
|
|
|
19
19
|
# runtime carries no shell, package manager, or file capabilities and listens
|
|
20
20
|
# on the unprivileged port :8080.
|
|
21
21
|
FROM golang:1.26.11-alpine3.23@sha256:23f198931d4bd83b4f5a613bd75656257ae8bf832dcbc2db80e1050b5219ca2a AS caddy-source
|
|
22
|
-
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.
|
|
23
|
-
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.
|
|
22
|
+
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.9 \
|
|
23
|
+
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.9 /src \
|
|
24
24
|
&& chmod -R u+w /src
|
|
25
25
|
WORKDIR /src
|
|
26
26
|
RUN go get github.com/go-jose/go-jose/v4@v4.1.7 github.com/go-chi/chi/v5@v5.5.0 github.com/klauspost/compress@v1.20.2 \
|
|
@@ -13,8 +13,8 @@ RUN hugo --minify
|
|
|
13
13
|
# runtime carries no shell, package manager, or file capabilities and listens
|
|
14
14
|
# on the unprivileged port :8080.
|
|
15
15
|
FROM golang:1.26.11-alpine3.23@sha256:23f198931d4bd83b4f5a613bd75656257ae8bf832dcbc2db80e1050b5219ca2a AS caddy-source
|
|
16
|
-
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.
|
|
17
|
-
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.
|
|
16
|
+
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.9 \
|
|
17
|
+
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.9 /src \
|
|
18
18
|
&& chmod -R u+w /src
|
|
19
19
|
WORKDIR /src
|
|
20
20
|
RUN go get github.com/go-jose/go-jose/v4@v4.1.7 github.com/go-chi/chi/v5@v5.5.0 github.com/klauspost/compress@v1.20.2 \
|
|
@@ -19,8 +19,8 @@ RUN bun -e 'const fs=require("node:fs"),path=require("node:path");const root=fs.
|
|
|
19
19
|
# runtime carries no shell, package manager, or file capabilities and listens
|
|
20
20
|
# on the unprivileged port :8080.
|
|
21
21
|
FROM golang:1.26.11-alpine3.23@sha256:23f198931d4bd83b4f5a613bd75656257ae8bf832dcbc2db80e1050b5219ca2a AS caddy-source
|
|
22
|
-
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.
|
|
23
|
-
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.
|
|
22
|
+
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.9 \
|
|
23
|
+
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.9 /src \
|
|
24
24
|
&& chmod -R u+w /src
|
|
25
25
|
WORKDIR /src
|
|
26
26
|
RUN go get github.com/go-jose/go-jose/v4@v4.1.7 github.com/go-chi/chi/v5@v5.5.0 github.com/klauspost/compress@v1.20.2 \
|
|
@@ -19,8 +19,8 @@ RUN bun -e 'const fs=require("node:fs"),path=require("node:path");const root=fs.
|
|
|
19
19
|
# runtime carries no shell, package manager, or file capabilities and listens
|
|
20
20
|
# on the unprivileged port :8080.
|
|
21
21
|
FROM golang:1.26.11-alpine3.23@sha256:23f198931d4bd83b4f5a613bd75656257ae8bf832dcbc2db80e1050b5219ca2a AS caddy-source
|
|
22
|
-
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.
|
|
23
|
-
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.
|
|
22
|
+
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.9 \
|
|
23
|
+
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.9 /src \
|
|
24
24
|
&& chmod -R u+w /src
|
|
25
25
|
WORKDIR /src
|
|
26
26
|
RUN go get github.com/go-jose/go-jose/v4@v4.1.7 github.com/go-chi/chi/v5@v5.5.0 github.com/klauspost/compress@v1.20.2 \
|
|
@@ -19,8 +19,8 @@ RUN bun -e 'const fs=require("node:fs"),path=require("node:path");const root=fs.
|
|
|
19
19
|
# runtime carries no shell, package manager, or file capabilities and listens
|
|
20
20
|
# on the unprivileged port :8080.
|
|
21
21
|
FROM golang:1.26.11-alpine3.23@sha256:23f198931d4bd83b4f5a613bd75656257ae8bf832dcbc2db80e1050b5219ca2a AS caddy-source
|
|
22
|
-
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.
|
|
23
|
-
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.
|
|
22
|
+
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.9 \
|
|
23
|
+
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.9 /src \
|
|
24
24
|
&& chmod -R u+w /src
|
|
25
25
|
WORKDIR /src
|
|
26
26
|
RUN go get github.com/go-jose/go-jose/v4@v4.1.7 github.com/go-chi/chi/v5@v5.5.0 github.com/klauspost/compress@v1.20.2 \
|
|
@@ -19,8 +19,8 @@ RUN bun -e 'const fs=require("node:fs"),path=require("node:path");const root=fs.
|
|
|
19
19
|
# runtime carries no shell, package manager, or file capabilities and listens
|
|
20
20
|
# on the unprivileged port :8080.
|
|
21
21
|
FROM golang:1.26.11-alpine3.23@sha256:23f198931d4bd83b4f5a613bd75656257ae8bf832dcbc2db80e1050b5219ca2a AS caddy-source
|
|
22
|
-
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.
|
|
23
|
-
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.
|
|
22
|
+
RUN go mod download github.com/caddyserver/caddy/v2@v2.11.9 \
|
|
23
|
+
&& cp -R /go/pkg/mod/github.com/caddyserver/caddy/v2@v2.11.9 /src \
|
|
24
24
|
&& chmod -R u+w /src
|
|
25
25
|
WORKDIR /src
|
|
26
26
|
RUN go get github.com/go-jose/go-jose/v4@v4.1.7 github.com/go-chi/chi/v5@v5.5.0 github.com/klauspost/compress@v1.20.2 \
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { AdminLegacyAuditResult } from "@percher/client";
|
|
2
|
-
import type { Context } from "../context.js";
|
|
3
|
-
/**
|
|
4
|
-
* `percher admin legacy-audit` — the zero-legacy audit (§11).
|
|
5
|
-
*
|
|
6
|
-
* A thin wrapper, exactly like the inventory one beside it: the server is the
|
|
7
|
-
* authority on every verdict and nothing here re-derives a term.
|
|
8
|
-
*/
|
|
9
|
-
export declare function adminLegacyAudit(ctx: Context): Promise<AdminLegacyAuditResult>;
|
|
10
|
-
/**
|
|
11
|
-
* The terms this CLI release knows the audit is a conjunction of.
|
|
12
|
-
*
|
|
13
|
-
* A duplicate of the API's list, and deliberately so — the client package
|
|
14
|
-
* cannot import from the API, and the alternative (trusting whatever list
|
|
15
|
-
* arrives) is what this constant exists to catch. It is a FLOOR, not an
|
|
16
|
-
* allowlist: a future API that adds a ninth term still has that term
|
|
17
|
-
* evaluated below, because the check is "every term present is measured and
|
|
18
|
-
* ok" AND "none of the terms I know about is missing". Only the second half
|
|
19
|
-
* needs a local list, and only to stop a SHORTER conjunction reading greener.
|
|
20
|
-
*/
|
|
21
|
-
export declare const LEGACY_AUDIT_REQUIRED_CONJUNCTS: readonly ["evidence_complete", "counters_zero", "desired_live_apps_present", "volumes_attributed", "scans_complete", "runtime_evidence_complete", "security_attestation_complete", "launch_gate_ready"];
|
|
22
|
-
/**
|
|
23
|
-
* Whether the audit is green, decided here rather than taken on trust.
|
|
24
|
-
*
|
|
25
|
-
* THREE independent conditions, and none of them is redundant:
|
|
26
|
-
*
|
|
27
|
-
* 1. `zeroLegacy === true` STRICTLY. An API that predates this endpoint, a
|
|
28
|
-
* proxy that returned something else, or a body with the field missing
|
|
29
|
-
* all deserialise to `undefined`, and `undefined` is not `true`.
|
|
30
|
-
* 2. Every term present is `measured` AND `ok`. A server that computed a
|
|
31
|
-
* verdict from terms it could not measure does not get an exit 0 out of
|
|
32
|
-
* this CLI, whatever it put in `zeroLegacy`.
|
|
33
|
-
* 3. Every term this release knows is required is actually present. Without
|
|
34
|
-
* it, condition 2 is vacuously true over an empty list — a conjunction
|
|
35
|
-
* that quietly stopped evaluating a term would read as the cleanest
|
|
36
|
-
* possible fleet, which is the exact shape of failure this whole
|
|
37
|
-
* programme is a response to.
|
|
38
|
-
*/
|
|
39
|
-
export declare function legacyAuditIsGreen(result: AdminLegacyAuditResult): boolean;
|
|
40
|
-
//# sourceMappingURL=admin-legacy-audit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admin-legacy-audit.d.ts","sourceRoot":"","sources":["../../src/commands/admin-legacy-audit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAEpF;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,+BAA+B,YAC1C,mBAAmB,EACnB,eAAe,EACf,2BAA2B,EAC3B,oBAAoB,EACpB,gBAAgB,EAChB,2BAA2B,EAC3B,+BAA+B,EAC/B,mBAAmB,CACX,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAM1E"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `percher admin legacy-audit` — the zero-legacy audit (§11).
|
|
3
|
-
*
|
|
4
|
-
* A thin wrapper, exactly like the inventory one beside it: the server is the
|
|
5
|
-
* authority on every verdict and nothing here re-derives a term.
|
|
6
|
-
*/
|
|
7
|
-
export async function adminLegacyAudit(ctx) {
|
|
8
|
-
return ctx.client.platform.adminLegacyAudit();
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* The terms this CLI release knows the audit is a conjunction of.
|
|
12
|
-
*
|
|
13
|
-
* A duplicate of the API's list, and deliberately so — the client package
|
|
14
|
-
* cannot import from the API, and the alternative (trusting whatever list
|
|
15
|
-
* arrives) is what this constant exists to catch. It is a FLOOR, not an
|
|
16
|
-
* allowlist: a future API that adds a ninth term still has that term
|
|
17
|
-
* evaluated below, because the check is "every term present is measured and
|
|
18
|
-
* ok" AND "none of the terms I know about is missing". Only the second half
|
|
19
|
-
* needs a local list, and only to stop a SHORTER conjunction reading greener.
|
|
20
|
-
*/
|
|
21
|
-
export const LEGACY_AUDIT_REQUIRED_CONJUNCTS = [
|
|
22
|
-
"evidence_complete",
|
|
23
|
-
"counters_zero",
|
|
24
|
-
"desired_live_apps_present",
|
|
25
|
-
"volumes_attributed",
|
|
26
|
-
"scans_complete",
|
|
27
|
-
"runtime_evidence_complete",
|
|
28
|
-
"security_attestation_complete",
|
|
29
|
-
"launch_gate_ready",
|
|
30
|
-
];
|
|
31
|
-
/**
|
|
32
|
-
* Whether the audit is green, decided here rather than taken on trust.
|
|
33
|
-
*
|
|
34
|
-
* THREE independent conditions, and none of them is redundant:
|
|
35
|
-
*
|
|
36
|
-
* 1. `zeroLegacy === true` STRICTLY. An API that predates this endpoint, a
|
|
37
|
-
* proxy that returned something else, or a body with the field missing
|
|
38
|
-
* all deserialise to `undefined`, and `undefined` is not `true`.
|
|
39
|
-
* 2. Every term present is `measured` AND `ok`. A server that computed a
|
|
40
|
-
* verdict from terms it could not measure does not get an exit 0 out of
|
|
41
|
-
* this CLI, whatever it put in `zeroLegacy`.
|
|
42
|
-
* 3. Every term this release knows is required is actually present. Without
|
|
43
|
-
* it, condition 2 is vacuously true over an empty list — a conjunction
|
|
44
|
-
* that quietly stopped evaluating a term would read as the cleanest
|
|
45
|
-
* possible fleet, which is the exact shape of failure this whole
|
|
46
|
-
* programme is a response to.
|
|
47
|
-
*/
|
|
48
|
-
export function legacyAuditIsGreen(result) {
|
|
49
|
-
if (result.zeroLegacy !== true)
|
|
50
|
-
return false;
|
|
51
|
-
const terms = Array.isArray(result.conjuncts) ? result.conjuncts : [];
|
|
52
|
-
const present = new Set(terms.map((term) => term.name));
|
|
53
|
-
if (LEGACY_AUDIT_REQUIRED_CONJUNCTS.some((name) => !present.has(name)))
|
|
54
|
-
return false;
|
|
55
|
-
return terms.every((term) => term.measured === true && term.ok === true);
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=admin-legacy-audit.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admin-legacy-audit.js","sourceRoot":"","sources":["../../src/commands/admin-legacy-audit.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAY;IACjD,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;AAChD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,mBAAmB;IACnB,eAAe;IACf,2BAA2B;IAC3B,oBAAoB;IACpB,gBAAgB;IAChB,2BAA2B;IAC3B,+BAA+B;IAC/B,mBAAmB;CACX,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAA8B;IAC/D,IAAI,MAAM,CAAC,UAAU,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC7C,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACxD,IAAI,+BAA+B,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrF,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { AdminLegacyInventoryResult } from "@percher/client";
|
|
2
|
-
import type { Context } from "../context.js";
|
|
3
|
-
/**
|
|
4
|
-
* `percher admin legacy-inventory` — the authoritative fleet inventory.
|
|
5
|
-
*
|
|
6
|
-
* A thin wrapper so the CLI, tests and any future tooling read the counters
|
|
7
|
-
* through one place. The server is the authority on the shape and on every
|
|
8
|
-
* verdict inside it; nothing here re-derives a class.
|
|
9
|
-
*/
|
|
10
|
-
export declare function adminLegacyInventory(ctx: Context): Promise<AdminLegacyInventoryResult>;
|
|
11
|
-
/**
|
|
12
|
-
* Whether the inventory is red.
|
|
13
|
-
*
|
|
14
|
-
* TWO independent conditions, and the second is the one that gets forgotten:
|
|
15
|
-
* a fleet with `unknownGenerationCount === 0` is only green if the evidence
|
|
16
|
-
* behind that zero was COMPLETE. An inventory that could not read half the
|
|
17
|
-
* daemon reports few legacy resources precisely because it saw few resources,
|
|
18
|
-
* so `complete === false` is red on its own and the CLI exits non-zero for it.
|
|
19
|
-
*/
|
|
20
|
-
export declare function legacyInventoryIsRed(result: AdminLegacyInventoryResult): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Whether every legacy counter has reached zero. Distinct from the red check:
|
|
23
|
-
* a fleet can be fully attributed and completely measured (not red) while
|
|
24
|
-
* still carrying legacy runtimes to migrate.
|
|
25
|
-
*/
|
|
26
|
-
export declare function legacyInventoryIsZeroLegacy(result: AdminLegacyInventoryResult): boolean;
|
|
27
|
-
//# sourceMappingURL=admin-legacy-inventory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admin-legacy-inventory.d.ts","sourceRoot":"","sources":["../../src/commands/admin-legacy-inventory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAE5F;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAEhF;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAUvF"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `percher admin legacy-inventory` — the authoritative fleet inventory.
|
|
3
|
-
*
|
|
4
|
-
* A thin wrapper so the CLI, tests and any future tooling read the counters
|
|
5
|
-
* through one place. The server is the authority on the shape and on every
|
|
6
|
-
* verdict inside it; nothing here re-derives a class.
|
|
7
|
-
*/
|
|
8
|
-
export async function adminLegacyInventory(ctx) {
|
|
9
|
-
return ctx.client.platform.adminLegacyInventory();
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Whether the inventory is red.
|
|
13
|
-
*
|
|
14
|
-
* TWO independent conditions, and the second is the one that gets forgotten:
|
|
15
|
-
* a fleet with `unknownGenerationCount === 0` is only green if the evidence
|
|
16
|
-
* behind that zero was COMPLETE. An inventory that could not read half the
|
|
17
|
-
* daemon reports few legacy resources precisely because it saw few resources,
|
|
18
|
-
* so `complete === false` is red on its own and the CLI exits non-zero for it.
|
|
19
|
-
*/
|
|
20
|
-
export function legacyInventoryIsRed(result) {
|
|
21
|
-
return !result.complete || result.counters.unknownGenerationCount > 0;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Whether every legacy counter has reached zero. Distinct from the red check:
|
|
25
|
-
* a fleet can be fully attributed and completely measured (not red) while
|
|
26
|
-
* still carrying legacy runtimes to migrate.
|
|
27
|
-
*/
|
|
28
|
-
export function legacyInventoryIsZeroLegacy(result) {
|
|
29
|
-
const c = result.counters;
|
|
30
|
-
return (result.complete &&
|
|
31
|
-
c.legacyRuntimeCount === 0 &&
|
|
32
|
-
c.legacyPocketBaseSidecarCount === 0 &&
|
|
33
|
-
c.legacyTopologyCount === 0 &&
|
|
34
|
-
c.incompatibleRollbackImageCount === 0 &&
|
|
35
|
-
c.unknownGenerationCount === 0);
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=admin-legacy-inventory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admin-legacy-inventory.js","sourceRoot":"","sources":["../../src/commands/admin-legacy-inventory.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,GAAY;IACrD,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,EAAE,CAAC;AACpD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAkC;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,sBAAsB,GAAG,CAAC,CAAC;AACxE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAAkC;IAC5E,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;IAC1B,OAAO,CACL,MAAM,CAAC,QAAQ;QACf,CAAC,CAAC,kBAAkB,KAAK,CAAC;QAC1B,CAAC,CAAC,4BAA4B,KAAK,CAAC;QACpC,CAAC,CAAC,mBAAmB,KAAK,CAAC;QAC3B,CAAC,CAAC,8BAA8B,KAAK,CAAC;QACtC,CAAC,CAAC,sBAAsB,KAAK,CAAC,CAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { AdminMigrateNetworksResult } from "@percher/client";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import type { Context } from "../context.js";
|
|
4
|
-
export declare const adminMigrateNetworksInputSchema: z.ZodObject<{
|
|
5
|
-
appIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
6
|
-
limit: z.ZodOptional<z.ZodNumber>;
|
|
7
|
-
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
-
direction: z.ZodOptional<z.ZodEnum<{
|
|
9
|
-
"to-per-app": "to-per-app";
|
|
10
|
-
"to-shared": "to-shared";
|
|
11
|
-
}>>;
|
|
12
|
-
}, z.core.$strip>;
|
|
13
|
-
export type AdminMigrateNetworksInput = z.infer<typeof adminMigrateNetworksInputSchema>;
|
|
14
|
-
export declare function adminMigrateNetworks(ctx: Context, input: AdminMigrateNetworksInput): Promise<AdminMigrateNetworksResult>;
|
|
15
|
-
//# sourceMappingURL=admin-migrate-networks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admin-migrate-networks.d.ts","sourceRoot":"","sources":["../../src/commands/admin-migrate-networks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,eAAO,MAAM,+BAA+B;;;;;;;;iBAS1C,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAExF,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,0BAA0B,CAAC,CAErC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export const adminMigrateNetworksInputSchema = z.object({
|
|
3
|
-
appIds: z
|
|
4
|
-
.array(z.string().regex(/^app_[0-9a-z]{20}$/))
|
|
5
|
-
.min(1)
|
|
6
|
-
.max(20)
|
|
7
|
-
.optional(),
|
|
8
|
-
limit: z.number().int().min(1).max(20).optional(),
|
|
9
|
-
dryRun: z.boolean().optional(),
|
|
10
|
-
direction: z.enum(["to-per-app", "to-shared"]).optional(),
|
|
11
|
-
});
|
|
12
|
-
export async function adminMigrateNetworks(ctx, input) {
|
|
13
|
-
return ctx.client.platform.adminMigrateNetworks(adminMigrateNetworksInputSchema.parse(input));
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=admin-migrate-networks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admin-migrate-networks.js","sourceRoot":"","sources":["../../src/commands/admin-migrate-networks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC,MAAM,CAAC;IACtD,MAAM,EAAE,CAAC;SACN,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;SAC7C,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,EAAE,CAAC;SACP,QAAQ,EAAE;IACb,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;IACjD,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC9B,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC1D,CAAC,CAAC;AAIH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAY,EACZ,KAAgC;IAEhC,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,+BAA+B,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AAChG,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AdminReconcileRoutesResult } from "@percher/client";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import type { Context } from "../context.js";
|
|
4
|
-
/**
|
|
5
|
-
* FUTURE18 Fas 4 — `percher admin reconcile-routes` command. Thin
|
|
6
|
-
* wrapper around the client's `adminReconcileRoutes` so the CLI,
|
|
7
|
-
* tests, and any future tooling go through one schema. Server is the
|
|
8
|
-
* authority on the result shape (`AdminReconcileRoutesResult`); we
|
|
9
|
-
* just narrow the input.
|
|
10
|
-
*/
|
|
11
|
-
export declare const adminReconcileRoutesInputSchema: z.ZodObject<{
|
|
12
|
-
appName: z.ZodOptional<z.ZodString>;
|
|
13
|
-
appId: z.ZodOptional<z.ZodString>;
|
|
14
|
-
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
-
}, z.core.$strip>;
|
|
16
|
-
export type AdminReconcileRoutesInput = z.infer<typeof adminReconcileRoutesInputSchema>;
|
|
17
|
-
export declare function adminReconcileRoutes(ctx: Context, input: AdminReconcileRoutesInput): Promise<AdminReconcileRoutesResult>;
|
|
18
|
-
//# sourceMappingURL=admin-reconcile-routes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admin-reconcile-routes.d.ts","sourceRoot":"","sources":["../../src/commands/admin-reconcile-routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B;;;;iBAQxC,CAAC;AAEL,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAExF,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,0BAA0B,CAAC,CAGrC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* FUTURE18 Fas 4 — `percher admin reconcile-routes` command. Thin
|
|
4
|
-
* wrapper around the client's `adminReconcileRoutes` so the CLI,
|
|
5
|
-
* tests, and any future tooling go through one schema. Server is the
|
|
6
|
-
* authority on the result shape (`AdminReconcileRoutesResult`); we
|
|
7
|
-
* just narrow the input.
|
|
8
|
-
*/
|
|
9
|
-
export const adminReconcileRoutesInputSchema = z
|
|
10
|
-
.object({
|
|
11
|
-
appName: z.string().optional(),
|
|
12
|
-
appId: z.string().optional(),
|
|
13
|
-
dryRun: z.boolean().optional(),
|
|
14
|
-
})
|
|
15
|
-
.refine((v) => !(v.appName && v.appId), {
|
|
16
|
-
message: "Pass either --app or --app-id, not both — they're mutually exclusive.",
|
|
17
|
-
});
|
|
18
|
-
export async function adminReconcileRoutes(ctx, input) {
|
|
19
|
-
const parsed = adminReconcileRoutesInputSchema.parse(input);
|
|
20
|
-
return ctx.client.platform.adminReconcileRoutes(parsed);
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=admin-reconcile-routes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"admin-reconcile-routes.js","sourceRoot":"","sources":["../../src/commands/admin-reconcile-routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC;KAC7C,MAAM,CAAC;IACN,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC;KACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE;IACtC,OAAO,EAAE,uEAAuE;CACjF,CAAC,CAAC;AAIL,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAY,EACZ,KAAgC;IAEhC,MAAM,MAAM,GAAG,+BAA+B,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
export type ManagedInferenceOptions = {
|
|
2
|
-
model?: string;
|
|
3
|
-
maxTokens?: number;
|
|
4
|
-
signal?: AbortSignal;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export class ManagedInferenceError extends Error {
|
|
8
|
-
constructor(
|
|
9
|
-
message: string,
|
|
10
|
-
readonly status?: number,
|
|
11
|
-
readonly code?: string,
|
|
12
|
-
readonly retryAt?: string,
|
|
13
|
-
) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = "ManagedInferenceError";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function createManagedInferenceClient(config: {
|
|
20
|
-
endpoint?: string;
|
|
21
|
-
getSession: () => { valid: boolean; token: string };
|
|
22
|
-
fetch?: typeof globalThis.fetch;
|
|
23
|
-
}) {
|
|
24
|
-
const fetcher = config.fetch ?? globalThis.fetch;
|
|
25
|
-
|
|
26
|
-
function isConfigured(): boolean {
|
|
27
|
-
return Boolean(config.endpoint);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function assertReady(): string {
|
|
31
|
-
if (!config.endpoint) {
|
|
32
|
-
throw new ManagedInferenceError(
|
|
33
|
-
"Managed inference is not available for this deployment.",
|
|
34
|
-
503,
|
|
35
|
-
"INFERENCE_DISABLED",
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
const session = config.getSession();
|
|
39
|
-
if (!session.valid || !session.token) {
|
|
40
|
-
throw new ManagedInferenceError("Sign in to use AI.", 401, "INFERENCE_AUTH_REQUIRED");
|
|
41
|
-
}
|
|
42
|
-
return session.token;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function safeError(response: Response): Promise<ManagedInferenceError> {
|
|
46
|
-
let code: string | undefined;
|
|
47
|
-
let resetAt: string | undefined;
|
|
48
|
-
try {
|
|
49
|
-
const body = (await response.json()) as {
|
|
50
|
-
error?: { code?: unknown; resetAt?: unknown; retryAfterSec?: unknown };
|
|
51
|
-
};
|
|
52
|
-
if (typeof body.error?.code === "string") code = body.error.code;
|
|
53
|
-
if (typeof body.error?.resetAt === "string") resetAt = body.error.resetAt;
|
|
54
|
-
if (!resetAt && typeof body.error?.retryAfterSec === "number") {
|
|
55
|
-
resetAt = new Date(Date.now() + body.error.retryAfterSec * 1000).toISOString();
|
|
56
|
-
}
|
|
57
|
-
} catch {
|
|
58
|
-
// Never show raw upstream/proxy response bodies to capsule users.
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (response.status === 401) {
|
|
62
|
-
return new ManagedInferenceError("Your session expired. Sign in again.", 401, code);
|
|
63
|
-
}
|
|
64
|
-
if (response.status === 403) {
|
|
65
|
-
return new ManagedInferenceError(
|
|
66
|
-
"Managed inference is not included for this app's plan.",
|
|
67
|
-
403,
|
|
68
|
-
code,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
if (response.status === 429) {
|
|
72
|
-
return new ManagedInferenceError(
|
|
73
|
-
resetAt ? `AI usage is limited until ${resetAt}.` : "AI usage is temporarily limited.",
|
|
74
|
-
429,
|
|
75
|
-
code,
|
|
76
|
-
resetAt,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
if (response.status === 503) {
|
|
80
|
-
return new ManagedInferenceError(
|
|
81
|
-
"Managed inference is currently unavailable.",
|
|
82
|
-
503,
|
|
83
|
-
code ?? "INFERENCE_DISABLED",
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
return new ManagedInferenceError(
|
|
87
|
-
"The AI request could not be completed. Try again.",
|
|
88
|
-
response.status,
|
|
89
|
-
code,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function request(prompt: string, opts: ManagedInferenceOptions, stream: boolean) {
|
|
94
|
-
// Validate configuration/auth before the network-error wrapper so a local
|
|
95
|
-
// disabled or signed-out state keeps its precise user-facing error.
|
|
96
|
-
const authorization = `Bearer ${assertReady()}`;
|
|
97
|
-
let response: Response;
|
|
98
|
-
try {
|
|
99
|
-
response = await fetcher(config.endpoint!, {
|
|
100
|
-
method: "POST",
|
|
101
|
-
headers: {
|
|
102
|
-
"content-type": "application/json",
|
|
103
|
-
authorization,
|
|
104
|
-
},
|
|
105
|
-
body: JSON.stringify({
|
|
106
|
-
model: opts.model,
|
|
107
|
-
max_tokens: opts.maxTokens ?? 512,
|
|
108
|
-
messages: [{ role: "user", content: prompt }],
|
|
109
|
-
...(stream ? { stream: true } : {}),
|
|
110
|
-
}),
|
|
111
|
-
signal: opts.signal,
|
|
112
|
-
});
|
|
113
|
-
} catch (error) {
|
|
114
|
-
if (opts.signal?.aborted) throw error;
|
|
115
|
-
throw new ManagedInferenceError("Managed inference could not be reached. Try again.");
|
|
116
|
-
}
|
|
117
|
-
if (!response.ok) throw await safeError(response);
|
|
118
|
-
return response;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function complete(
|
|
122
|
-
prompt: string,
|
|
123
|
-
opts: ManagedInferenceOptions = {},
|
|
124
|
-
): Promise<string> {
|
|
125
|
-
const response = await request(prompt, opts, false);
|
|
126
|
-
const data = (await response.json()) as {
|
|
127
|
-
choices?: Array<{ message?: { content?: unknown } }>;
|
|
128
|
-
};
|
|
129
|
-
const content = data.choices?.[0]?.message?.content;
|
|
130
|
-
if (typeof content !== "string") {
|
|
131
|
-
throw new ManagedInferenceError("The AI provider returned an invalid response.");
|
|
132
|
-
}
|
|
133
|
-
return content;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async function streamComplete(
|
|
137
|
-
prompt: string,
|
|
138
|
-
onToken: (delta: string) => void,
|
|
139
|
-
opts: ManagedInferenceOptions = {},
|
|
140
|
-
): Promise<string> {
|
|
141
|
-
const response = await request(prompt, opts, true);
|
|
142
|
-
if (!response.body) throw new ManagedInferenceError("The AI stream could not be opened.");
|
|
143
|
-
|
|
144
|
-
const reader = response.body.getReader();
|
|
145
|
-
const decoder = new TextDecoder();
|
|
146
|
-
let buffer = "";
|
|
147
|
-
let full = "";
|
|
148
|
-
let sawDone = false;
|
|
149
|
-
try {
|
|
150
|
-
for (;;) {
|
|
151
|
-
const { done, value } = await reader.read();
|
|
152
|
-
if (done) break;
|
|
153
|
-
buffer += decoder.decode(value, { stream: true }).replaceAll("\r\n", "\n");
|
|
154
|
-
let separator = buffer.indexOf("\n\n");
|
|
155
|
-
while (separator !== -1) {
|
|
156
|
-
const event = buffer.slice(0, separator);
|
|
157
|
-
buffer = buffer.slice(separator + 2);
|
|
158
|
-
separator = buffer.indexOf("\n\n");
|
|
159
|
-
const payload = event
|
|
160
|
-
.split("\n")
|
|
161
|
-
.filter((line) => line.startsWith("data:"))
|
|
162
|
-
.map((line) => line.slice(5).trimStart())
|
|
163
|
-
.join("\n")
|
|
164
|
-
.trim();
|
|
165
|
-
if (!payload) continue;
|
|
166
|
-
if (payload === "[DONE]") {
|
|
167
|
-
sawDone = true;
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
try {
|
|
171
|
-
const chunk = JSON.parse(payload) as {
|
|
172
|
-
choices?: Array<{ delta?: { content?: unknown } }>;
|
|
173
|
-
};
|
|
174
|
-
const delta = chunk.choices?.[0]?.delta?.content;
|
|
175
|
-
if (typeof delta === "string" && delta) {
|
|
176
|
-
full += delta;
|
|
177
|
-
onToken(delta);
|
|
178
|
-
}
|
|
179
|
-
} catch {
|
|
180
|
-
// Ignore SSE comments/keep-alives and malformed non-data events.
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (!sawDone) throw new ManagedInferenceError("The AI stream ended unexpectedly.");
|
|
185
|
-
return full;
|
|
186
|
-
} finally {
|
|
187
|
-
if (opts.signal?.aborted) await reader.cancel().catch(() => undefined);
|
|
188
|
-
reader.releaseLock();
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return { isConfigured, complete, streamComplete };
|
|
193
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { createManagedInferenceClient } from "./ai-client";
|
|
2
|
-
import { pb } from "./db";
|
|
3
|
-
|
|
4
|
-
// This is a public URL, never a provider credential. Percher injects it only
|
|
5
|
-
// when the shared server-side feature gate is operational.
|
|
6
|
-
const client = createManagedInferenceClient({
|
|
7
|
-
endpoint: import.meta.env.VITE_PERCHER_AI_URL as string | undefined,
|
|
8
|
-
getSession: () => ({ valid: pb.authStore.isValid, token: pb.authStore.token }),
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
export { ManagedInferenceError } from "./ai-client";
|
|
12
|
-
export type { ManagedInferenceOptions } from "./ai-client";
|
|
13
|
-
export const isManagedInferenceConfigured = client.isConfigured;
|
|
14
|
-
export const complete = client.complete;
|
|
15
|
-
export const streamComplete = client.streamComplete;
|