@aliou/pi-ts-aperture 0.1.0 → 0.2.1

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/README.md CHANGED
@@ -7,7 +7,7 @@ Aperture handles API key injection and request routing server-side. This extensi
7
7
  ## Setup
8
8
 
9
9
  ```bash
10
- pi install @aliou/pi-ts-aperture
10
+ pi install npm:@aliou/pi-ts-aperture
11
11
  ```
12
12
 
13
13
  Then run the setup wizard:
package/package.json CHANGED
@@ -1,18 +1,27 @@
1
1
  {
2
2
  "name": "@aliou/pi-ts-aperture",
3
3
  "description": "Route Pi LLM providers through Tailscale Aperture",
4
- "version": "0.1.0",
4
+ "version": "0.2.1",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "keywords": [
9
+ "pi-package",
10
+ "pi-extension",
11
+ "pi"
12
+ ],
5
13
  "repository": {
6
14
  "type": "git",
7
15
  "url": "https://github.com/aliou/pi-ts-aperture"
8
16
  },
9
- "keywords": [
10
- "pi-package"
11
- ],
12
17
  "publishConfig": {
13
18
  "access": "public",
14
19
  "provenance": true
15
20
  },
21
+ "files": [
22
+ "src",
23
+ "README.md"
24
+ ],
16
25
  "pi": {
17
26
  "extensions": [
18
27
  "./src/index.ts"
@@ -24,13 +33,25 @@
24
33
  },
25
34
  "peerDependencies": {
26
35
  "@mariozechner/pi-ai": ">=0.52.12",
27
- "@mariozechner/pi-coding-agent": ">=0.52.12"
36
+ "@mariozechner/pi-coding-agent": ">=0.52.12",
37
+ "@mariozechner/pi-tui": ">=0.51.0"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "@mariozechner/pi-coding-agent": {
41
+ "optional": true
42
+ },
43
+ "@mariozechner/pi-ai": {
44
+ "optional": true
45
+ },
46
+ "@mariozechner/pi-tui": {
47
+ "optional": true
48
+ }
28
49
  },
29
50
  "devDependencies": {
51
+ "@aliou/biome-plugins": "^0.3.2",
30
52
  "@biomejs/biome": "^2.3.13",
31
53
  "@changesets/cli": "^2.27.11",
32
54
  "@mariozechner/pi-coding-agent": "0.52.12",
33
- "@mariozechner/pi-tui": "0.52.12",
34
55
  "@sinclair/typebox": "^0.34.48",
35
56
  "@types/node": "^25.0.10",
36
57
  "husky": "^9.1.7",
@@ -40,6 +61,7 @@
40
61
  "typecheck": "tsc --noEmit",
41
62
  "lint": "biome check",
42
63
  "format": "biome check --write",
64
+ "check:lockfile": "pnpm install --frozen-lockfile --ignore-scripts",
43
65
  "changeset": "changeset",
44
66
  "version": "changeset version",
45
67
  "release": "pnpm changeset publish"
@@ -8,15 +8,15 @@
8
8
  */
9
9
 
10
10
  import { FuzzySelector } from "@aliou/pi-utils-settings";
11
- import { getProviders } from "@mariozechner/pi-ai";
12
11
  import type {
13
12
  ExtensionAPI,
14
13
  ExtensionContext,
15
14
  } from "@mariozechner/pi-coding-agent";
16
15
  import { getSettingsListTheme } from "@mariozechner/pi-coding-agent";
17
- import type { Component } from "@mariozechner/pi-tui";
16
+ import type { Component, TUI } from "@mariozechner/pi-tui";
18
17
  import { Input, Key, matchesKey } from "@mariozechner/pi-tui";
19
18
  import { configLoader } from "../config";
19
+ import { checkApertureHealth } from "../lib/health";
20
20
 
21
21
  function normalizeUrl(url: string): string {
22
22
  let result = url.trim();
@@ -27,6 +27,102 @@ function normalizeUrl(url: string): string {
27
27
  return result.replace(/\/v1\/?$/, "").replace(/\/+$/, "");
28
28
  }
29
29
 
30
+ const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
31
+
32
+ /**
33
+ * Shows a spinner while verifying the Aperture URL is reachable.
34
+ * Kicks off the health check on construction and resolves done(boolean)
35
+ * when the check completes.
36
+ */
37
+ class HealthCheckSpinner implements Component {
38
+ private theme: ReturnType<typeof getSettingsListTheme>;
39
+ private url: string;
40
+ private tui: TUI;
41
+ // true = healthy, false = failed (retry), undefined = cancelled
42
+ private done: (result: boolean | undefined) => void;
43
+ private frame = 0;
44
+ private timer: ReturnType<typeof setInterval>;
45
+ private result: { ok: boolean; error?: string } | null = null;
46
+
47
+ constructor(
48
+ theme: ReturnType<typeof getSettingsListTheme>,
49
+ url: string,
50
+ tui: TUI,
51
+ done: (result: boolean | undefined) => void,
52
+ ) {
53
+ this.theme = theme;
54
+ this.url = url;
55
+ this.tui = tui;
56
+ this.done = done;
57
+
58
+ // Animate spinner at ~80ms per frame.
59
+ this.timer = setInterval(() => {
60
+ this.frame = (this.frame + 1) % SPINNER_FRAMES.length;
61
+ this.tui.requestRender();
62
+ }, 80);
63
+
64
+ // Fire the check.
65
+ checkApertureHealth(url).then((res) => {
66
+ clearInterval(this.timer);
67
+ this.result = res;
68
+ this.tui.requestRender();
69
+
70
+ // On success, auto-advance after a brief pause.
71
+ // On failure, wait for user input (see handleInput).
72
+ if (res.ok) {
73
+ setTimeout(() => this.done(true), 600);
74
+ }
75
+ });
76
+ }
77
+
78
+ render(_width: number): string[] {
79
+ const lines: string[] = [];
80
+ lines.push(this.theme.label(" Aperture Setup", true));
81
+ lines.push("");
82
+
83
+ if (!this.result) {
84
+ const spinner = SPINNER_FRAMES[this.frame];
85
+ lines.push(
86
+ this.theme.hint(` ${spinner} Checking connection to ${this.url}...`),
87
+ );
88
+ } else if (this.result.ok) {
89
+ lines.push(this.theme.hint(` Connected to ${this.url}`));
90
+ } else {
91
+ lines.push(
92
+ this.theme.hint(` Could not reach ${this.url}: ${this.result.error}`),
93
+ );
94
+ lines.push("");
95
+ lines.push(
96
+ this.theme.hint(
97
+ " Make sure the URL is correct and you are connected to the tailnet.",
98
+ ),
99
+ );
100
+ lines.push("");
101
+ lines.push(this.theme.hint(" Enter: try another URL · Esc: cancel"));
102
+ }
103
+
104
+ lines.push("");
105
+ return lines;
106
+ }
107
+
108
+ invalidate() {}
109
+
110
+ handleInput(data: string) {
111
+ // Only handle input after a failed check.
112
+ if (!this.result || this.result.ok) return;
113
+
114
+ if (matchesKey(data, Key.enter)) {
115
+ this.done(false); // retry
116
+ } else if (matchesKey(data, Key.escape)) {
117
+ this.done(undefined); // cancel wizard
118
+ }
119
+ }
120
+
121
+ dispose() {
122
+ clearInterval(this.timer);
123
+ }
124
+ }
125
+
30
126
  /**
31
127
  * Simple input prompt component for the base URL step.
32
128
  */
@@ -171,17 +267,39 @@ export function registerSetupCommand(
171
267
  const config = configLoader.getConfig();
172
268
  const settingsTheme = getSettingsListTheme();
173
269
 
174
- // Step 1: base URL
175
- const baseUrl = await ctx.ui.custom<string | undefined>(
176
- (_tui, _theme, _kb, done) => {
177
- return new UrlPrompt(settingsTheme, config.baseUrl, done);
178
- },
179
- );
270
+ // Step 1: base URL + health check loop.
271
+ // On failure, loop back to the URL prompt so the user can retry.
272
+ let baseUrl: string | undefined;
273
+ while (true) {
274
+ baseUrl = await ctx.ui.custom<string | undefined>(
275
+ (_tui, _theme, _kb, done) => {
276
+ return new UrlPrompt(
277
+ settingsTheme,
278
+ baseUrl ?? config.baseUrl,
279
+ done,
280
+ );
281
+ },
282
+ );
283
+
284
+ if (!baseUrl) return;
285
+ const urlToCheck = baseUrl;
286
+
287
+ const result = await ctx.ui.custom<boolean | undefined>(
288
+ (tui, _theme, _kb, done) => {
289
+ return new HealthCheckSpinner(settingsTheme, urlToCheck, tui, done);
290
+ },
291
+ );
180
292
 
181
- if (!baseUrl) return;
293
+ if (result === true) break; // healthy, proceed
294
+ if (result === undefined) return; // cancelled
295
+ }
182
296
 
183
297
  // Step 2: select providers
184
- const knownProviders = getProviders();
298
+ // Use model registry so custom/extension providers are included.
299
+ const knownProviders = Array.from(
300
+ new Set(ctx.modelRegistry.getAll().map((model) => model.provider)),
301
+ ).sort((a, b) => a.localeCompare(b));
302
+
185
303
  const providers = await ctx.ui.custom<string[] | undefined>(
186
304
  (_tui, _theme, _kb, done) => {
187
305
  return new ProviderMultiSelect(
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Health check for the Aperture gateway.
3
+ *
4
+ * Hits GET <baseUrl>/v1/models to verify the gateway is reachable.
5
+ * Uses native fetch (no extra dependencies).
6
+ */
7
+
8
+ export interface HealthCheckResult {
9
+ ok: boolean;
10
+ error?: string;
11
+ }
12
+
13
+ export async function checkApertureHealth(
14
+ baseUrl: string,
15
+ ): Promise<HealthCheckResult> {
16
+ const url = `${baseUrl.replace(/\/+$/, "")}/v1/models`;
17
+ try {
18
+ const res = await fetch(url, {
19
+ method: "GET",
20
+ signal: AbortSignal.timeout(5000),
21
+ });
22
+ if (!res.ok) {
23
+ return { ok: false, error: `HTTP ${res.status} ${res.statusText}` };
24
+ }
25
+ return { ok: true };
26
+ } catch (e: unknown) {
27
+ const msg = e instanceof Error ? e.message : String(e);
28
+ return { ok: false, error: msg };
29
+ }
30
+ }
@@ -1,10 +0,0 @@
1
- {
2
- "$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3
- "changelog": "@changesets/cli/changelog",
4
- "commit": false,
5
- "fixed": [],
6
- "linked": [],
7
- "access": "public",
8
- "baseBranch": "main",
9
- "updateInternalDependencies": "patch"
10
- }
@@ -1,31 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
- pull_request:
8
-
9
- jobs:
10
- check:
11
- runs-on: ubuntu-latest
12
- steps:
13
- - name: Checkout
14
- uses: actions/checkout@v4
15
-
16
- - name: Setup Node
17
- uses: actions/setup-node@v4
18
- with:
19
- node-version: 22
20
-
21
- - name: Setup pnpm
22
- uses: pnpm/action-setup@v4
23
-
24
- - name: Install dependencies
25
- run: pnpm install --frozen-lockfile
26
-
27
- - name: Lint
28
- run: pnpm run lint
29
-
30
- - name: Typecheck
31
- run: pnpm run typecheck
@@ -1,86 +0,0 @@
1
- name: Publish
2
-
3
- on:
4
- workflow_run:
5
- workflows: ["CI"]
6
- types: [completed]
7
-
8
- concurrency:
9
- group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}
10
- cancel-in-progress: true
11
-
12
- jobs:
13
- publish:
14
- name: Publish
15
- if: >-
16
- github.event.workflow_run.conclusion == 'success' &&
17
- github.event.workflow_run.head_branch == 'main'
18
- runs-on: ubuntu-latest
19
- permissions:
20
- contents: write
21
- packages: write
22
- pull-requests: write
23
- id-token: write
24
-
25
- steps:
26
- - name: Checkout
27
- uses: actions/checkout@v4
28
- with:
29
- ref: ${{ github.event.workflow_run.head_sha }}
30
- fetch-depth: 0
31
-
32
- - name: Setup pnpm
33
- uses: pnpm/action-setup@v4
34
-
35
- - name: Setup Node.js
36
- uses: actions/setup-node@v4
37
- with:
38
- node-version: "22"
39
- registry-url: "https://registry.npmjs.org"
40
- scope: "@aliou"
41
- cache: "pnpm"
42
-
43
- - name: Upgrade npm for OIDC support
44
- run: npm install -g npm@latest
45
-
46
- - name: Install dependencies
47
- run: pnpm install --frozen-lockfile
48
-
49
- - name: Get release info
50
- id: release-info
51
- run: |
52
- pnpm changeset status --output=release.json 2>/dev/null || echo '{"releases":[]}' > release.json
53
- node <<NODE
54
- const fs = require('fs');
55
- const release = JSON.parse(fs.readFileSync('release.json', 'utf8'));
56
- const releases = release.releases?.filter(r => r.type !== 'none') || [];
57
-
58
- let title = 'Version Packages';
59
- let commit = 'Version Packages';
60
- if (releases.length === 1) {
61
- const { name, newVersion } = releases[0];
62
- title = 'Updating ' + name + ' to version ' + newVersion;
63
- commit = name + '@' + newVersion;
64
- } else if (releases.length > 1) {
65
- const summary = releases.map(r => r.name + '@' + r.newVersion).join(', ');
66
- title = 'Updating ' + summary;
67
- commit = summary;
68
- }
69
-
70
- fs.appendFileSync(process.env.GITHUB_OUTPUT, 'title=' + title + '\n');
71
- fs.appendFileSync(process.env.GITHUB_OUTPUT, 'commit=' + commit + '\n');
72
- NODE
73
- rm -f release.json
74
- continue-on-error: true
75
-
76
- - name: Create Release PR or Publish
77
- id: changesets
78
- uses: changesets/action@v1
79
- with:
80
- version: pnpm changeset version
81
- publish: pnpm changeset publish
82
- title: ${{ steps.release-info.outputs.title || 'Version Packages' }}
83
- commit: ${{ steps.release-info.outputs.commit || 'Version Packages' }}
84
- env:
85
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86
- NPM_CONFIG_PROVENANCE: true
package/AGENTS.md DELETED
@@ -1,29 +0,0 @@
1
- # pi-ts-aperture
2
-
3
- Pi extension that routes LLM providers through Tailscale Aperture.
4
-
5
- ## Structure
6
-
7
- - `src/index.ts` - Entry point. Loads config, registers providers, registers commands.
8
- - `src/config.ts` - Config schema (`ApertureConfig`, `ResolvedConfig`) and `ConfigLoader` instance.
9
- - `src/commands/setup.ts` - `/aperture:setup` interactive wizard (URL input + provider multi-select).
10
- - `src/commands/settings.ts` - `/aperture:settings` settings UI via `registerSettingsCommand`.
11
-
12
- ## Key decisions
13
-
14
- - Config is global-only (no per-project scope). Aperture is a network-level concern.
15
- - Provider list comes from `getProviders()` in `@mariozechner/pi-ai`, not hardcoded.
16
- - `apiKey` is set to `"-"` because Aperture ignores client-provided keys.
17
- - URLs are normalized on input: `http://` is prepended if missing, trailing `/v1` is stripped (appended at registration time).
18
-
19
- ## Dependencies
20
-
21
- - `@aliou/pi-utils-settings` - Config loader and settings command infrastructure.
22
- - `@mariozechner/pi-ai` - `getProviders()` for the known provider list.
23
- - `@mariozechner/pi-coding-agent` - Extension API, `getSettingsListTheme`.
24
- - `@mariozechner/pi-tui` - TUI components (`Input`, `Key`, `matchesKey`, `FuzzySelector`).
25
-
26
- ## Publishing
27
-
28
- - Manual publish for 0.0.1, then changesets + GitHub Actions for subsequent versions.
29
- - CI runs lint + typecheck on push/PR. Publish workflow triggers after CI succeeds on main.
package/CHANGELOG.md DELETED
@@ -1,15 +0,0 @@
1
- # @aliou/pi-ts-aperture
2
-
3
- ## 0.1.0
4
-
5
- ### Minor Changes
6
-
7
- - ebb9556: Initial release. Route Pi LLM providers through Tailscale Aperture.
8
-
9
- - `/aperture:setup` interactive wizard (base URL + provider multi-select)
10
- - `/aperture:settings` settings UI for updating configuration
11
- - Auto-registers selected providers with Aperture base URL on load
12
-
13
- ### Patch Changes
14
-
15
- - 7388139: Fix providers not taking effect immediately after setup/settings save. Register directly on modelRegistry and re-resolve the active model when it belongs to a reconfigured provider.
package/biome.json DELETED
@@ -1,30 +0,0 @@
1
- {
2
- "$schema": "https://biomejs.dev/schemas/2.4.2/schema.json",
3
- "vcs": {
4
- "enabled": true,
5
- "clientKind": "git",
6
- "useIgnoreFile": true
7
- },
8
- "files": {
9
- "includes": ["**/*.ts", "**/*.json"],
10
- "ignoreUnknown": true
11
- },
12
- "assist": {
13
- "actions": {
14
- "source": {
15
- "organizeImports": "on"
16
- }
17
- }
18
- },
19
- "linter": {
20
- "enabled": true,
21
- "rules": {
22
- "recommended": true
23
- }
24
- },
25
- "formatter": {
26
- "enabled": true,
27
- "indentStyle": "space",
28
- "indentWidth": 2
29
- }
30
- }
package/shell.nix DELETED
@@ -1,10 +0,0 @@
1
- {
2
- pkgs ? import <nixpkgs> { },
3
- }:
4
-
5
- pkgs.mkShell {
6
- buildInputs = with pkgs; [
7
- nodejs
8
- pnpm_10
9
- ];
10
- }
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "strict": true,
7
- "esModuleInterop": true,
8
- "skipLibCheck": true,
9
- "forceConsistentCasingInFileNames": true,
10
- "resolveJsonModule": true,
11
- "noEmit": true,
12
- "jsx": "react-jsx",
13
- "jsxImportSource": "@mariozechner/pi-tui"
14
- },
15
- "include": ["src/**/*"],
16
- "exclude": ["node_modules"]
17
- }