@entrinsik/vite-plugin-informer 2.12.0 → 2.14.0-beta.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/README.md CHANGED
@@ -5,14 +5,18 @@ Vite plugin and deploy tool for Informer App development: a local dev server wir
5
5
  ## Quick start
6
6
 
7
7
  ```bash
8
+ npm install -g @entrinsik/informer-cli
9
+ inf login <your-informer-url> # once: the sign-in dev and deploy use
8
10
  npm create vite@latest my-app -- --template react
9
11
  cd my-app
10
12
  npm install -D @entrinsik/vite-plugin-informer
11
- npx informer-init # wires vite config, informer.yaml, .env, deploy scripts
12
- npm run dev # local dev against the Informer in .env
13
- npm run deploy # assemble + upload + deploy
13
+ npx informer-init # wires vite config, informer.yaml, deploy scripts
14
+ npm run dev # local dev against the server you signed in to
15
+ npm run deploy # assemble + upload + deploy (or: inf deploy, which asks first)
14
16
  ```
15
17
 
18
+ No `.env` is needed: with no credential in the environment or `.env`, the plugin asks the Informer CLI (`inf auth token`) for the signed-in server and a current token, and a dev server renews it as it runs. `INFORMER_URL` with `INFORMER_API_KEY` (or `INFORMER_USER` and `INFORMER_PASS`) in `.env` still work, and win when set; `INFORMER_URL` alone picks which of your sign-ins to use.
19
+
16
20
  `informer-init` leaves an existing `@entrinsik/vite-plugin-informer` entry alone, and writes one only when the dependency is missing — in which case it uses its own version (2.12.0 and later; before that it wrote `^1.0.0`). A project scaffolded earlier still carries `^1.0.0`, which resolves to 1.0.5 and predates everything below: bump it by hand.
17
21
 
18
22
  ## What a deploy ships
@@ -25,7 +29,7 @@ The assembler uploads your built frontend plus these source trees, matching how
25
29
  | `webhooks/` | Publicly callable webhook routes |
26
30
  | `tools/` | AI tools, private to the App's agents |
27
31
  | `mcp/` | Tools exposed over the App's MCP endpoint |
28
- | `channels/` | Live channel handlers: `join` / `joined` / `leave` and event-named handlers for `channel.send()`; `npm run dev` runs them locally, and the `channels:` block in `informer.yaml` declares relays only (each entry needs `on`) |
32
+ | `channels/` | Live channel handlers: `join` / `joined` / `leave` and event-named handlers for `channel.send()`, or a channel actor (`config.actor`: one live instance per channel, with `start` / `tick` / `stop` / `snapshot`); `npm run dev` runs both locally, and the `channels:` block in `informer.yaml` declares relays only (each entry needs `on`) |
29
33
  | `migrations/` | Workspace database migrations, run in order on deploy |
30
34
  | `embeddings/` | Declarative embedding use cases (see below) |
31
35
  | `lib/`, `shared/` | Modules importable by the trees above |
@@ -48,6 +52,8 @@ A server whose version isn't comparable (a `dev` build, or an `/about` behind a
48
52
 
49
53
  App Channels phase 2 (plugin ≥ 2.11.0: `channel.send()`, the `joined` export and event-named exports in `channels/` files, wildcard subscriptions, frame `seq` and replay, `connected`) needs a 2026.1.3 server that carries I5-13027. The version probe cannot tell such a server from an earlier 2026.1.3 build, so the deploy is not gated: an earlier build refuses a `channels/` file that exports `joined` or an event name, and accepts a `channels:` entry without `on` that a current server rejects. The dev server runs the phase 2 contract regardless; plugin 2.12.0 aligns its channel semantics with the server's (wildcard gating, replay expiry, and the per-user send budget), so on 2.11.0 the dev mirror has the phase 2 surface but not all of its behavior.
50
54
 
55
+ Channel actors (plugin ≥ 2.13.0: `config.actor` files, `request.member`, `__INFORMER__.serverNow()`) need a server that reports `platform.capabilities.channelActors`; on one that does not, the same file runs as an ordinary channel handler, one fresh module per message. Under `npm run dev` each concrete channel gets its own module instance, calls run one at a time, `tick()` runs on a timer, and the actor stops `idleMs` after its last page leaves. `snapshot()` is kept in memory, so editing a file under `channels/`, `shared/`, `lib/` or `server/` restarts the running actors on the new code from their snapshots with the same pages subscribed: a game in progress survives the edit. The server's cluster, leases, billing and broadcast limits have no dev counterpart.
56
+
51
57
  Feature-detect at runtime with optional chaining, since `platform` is absent entirely before 2026.1.3:
52
58
 
53
59
  ```javascript
package/bin/deploy.js CHANGED
@@ -4,9 +4,12 @@ import { readFile, writeFile } from 'node:fs/promises';
4
4
  import { resolve } from 'node:path';
5
5
  import { deploy } from '../src/deploy.js';
6
6
  import { loadEnv, parseModeArg } from '../src/env.js';
7
+ import { useSignedIn } from '../src/signed-in.js';
7
8
 
8
9
  const mode = parseModeArg(process.argv);
9
10
  loadEnv({ mode });
11
+ // No credential in the environment or .env: use the inf CLI's sign-in
12
+ await useSignedIn(process.env);
10
13
 
11
14
  const baseUrl = process.env.INFORMER_URL;
12
15
  const apiKey = process.env.INFORMER_API_KEY;
@@ -14,13 +17,10 @@ const user = process.env.INFORMER_USER;
14
17
  const pass = process.env.INFORMER_PASS;
15
18
 
16
19
  if (!baseUrl || (!apiKey && (!user || !pass))) {
17
- console.error('Missing required environment variables.');
18
- console.error('Create a .env file with:');
19
- console.error(' INFORMER_URL=http://localhost:3000');
20
- console.error(' INFORMER_API_KEY=your-api-key');
21
- console.error('Or use basic auth:');
22
- console.error(' INFORMER_USER=admin');
23
- console.error(' INFORMER_PASS=yourpassword');
20
+ console.error('Not signed in to an Informer server.');
21
+ console.error('Sign in once with the Informer CLI (npm install -g @entrinsik/informer-cli):');
22
+ console.error(' inf login <your-informer-url>');
23
+ console.error('Or set INFORMER_URL with INFORMER_API_KEY (or INFORMER_USER and INFORMER_PASS) in .env.');
24
24
  process.exit(1);
25
25
  }
26
26
 
@@ -82,5 +82,8 @@ try {
82
82
  }
83
83
  } catch (err) {
84
84
  console.error('Deploy failed:', err.message);
85
+ // The server's own message carries the recovery instruction; err.message is
86
+ // only the status line.
87
+ if (err.detail) console.error(err.detail);
85
88
  process.exit(1);
86
89
  }
package/bin/init.js CHANGED
@@ -208,14 +208,17 @@ async function init() {
208
208
  // 7. Update vite.config
209
209
  await updateViteConfig();
210
210
 
211
- // 8. Create .env.example
212
- const envExample = `# Informer connection settings
213
- INFORMER_URL=http://localhost:3000
214
-
215
- # Option 1: API Key (recommended)
216
- INFORMER_API_KEY=your-api-key
217
-
218
- # Option 2: Basic auth
211
+ // 8. Create .env.example. No .env: the Informer CLI's sign-in (inf login)
212
+ // is the credential, and a placeholder key would stand in its way
213
+ const envExample = `# Nothing here is required. Sign in once with the Informer CLI:
214
+ # npm install -g @entrinsik/informer-cli
215
+ # inf login <your-informer-url>
216
+ # and npm run dev / npm run deploy use that sign-in (inf deploy does too).
217
+ #
218
+ # To use another server or credential instead, copy this file to .env and set:
219
+ # INFORMER_URL=http://localhost:3000
220
+ # INFORMER_API_KEY=your-api-key
221
+ # or basic auth:
219
222
  # INFORMER_USER=admin
220
223
  # INFORMER_PASS=yourpassword
221
224
  `;
@@ -226,13 +229,6 @@ INFORMER_API_KEY=your-api-key
226
229
  console.log('Created .env.example');
227
230
  }
228
231
 
229
- // Also create .env if it doesn't exist
230
- const envPath = resolve(cwd, '.env');
231
- if (!await exists(envPath)) {
232
- await writeFile(envPath, envExample);
233
- console.log('Created .env (update with your credentials)');
234
- }
235
-
236
232
  // 9. Create informer.yaml if it doesn't exist
237
233
  const informerYamlPath = resolve(cwd, 'informer.yaml');
238
234
  if (!await exists(informerYamlPath)) {
@@ -283,7 +279,7 @@ export default defineConfig({
283
279
  }
284
280
 
285
281
  // Check if plugin is already added
286
- if (configContent.includes('vite-plugin-informer') || configContent.includes("informer()")) {
282
+ if (configContent.includes('vite-plugin-informer') || configContent.includes('informer()')) {
287
283
  console.log('Informer plugin already in vite config');
288
284
  return;
289
285
  }
package/bin/workspace.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import { resolve, basename } from 'node:path';
5
5
  import { createClient } from '../src/client.js';
6
+ import { useSignedIn } from '../src/signed-in.js';
6
7
  import { loadEnv, envWritePath, localEnvValue, parseModeArg } from '../src/env.js';
7
8
  import { init, migrate, reset } from '../src/workspace.js';
8
9
 
@@ -26,14 +27,16 @@ if (!command || !['init', 'migrate', 'reset'].includes(command)) {
26
27
  process.exit(1);
27
28
  }
28
29
 
30
+ // No credential in the environment or .env: use the inf CLI's sign-in
31
+ await useSignedIn(process.env);
29
32
  const baseUrl = process.env.INFORMER_URL;
30
33
  const apiKey = process.env.INFORMER_API_KEY;
31
34
  const user = process.env.INFORMER_USER;
32
35
  const pass = process.env.INFORMER_PASS;
33
36
 
34
37
  if (!baseUrl || (!apiKey && (!user || !pass))) {
35
- console.error('Missing required environment variables.');
36
- console.error('Set INFORMER_URL and either INFORMER_API_KEY or INFORMER_USER/INFORMER_PASS in .env');
38
+ console.error('Not signed in to an Informer server. Run inf login <your-informer-url>,');
39
+ console.error('or set INFORMER_URL with INFORMER_API_KEY (or INFORMER_USER and INFORMER_PASS) in .env.');
37
40
  process.exit(1);
38
41
  }
39
42
 
package/index.d.ts CHANGED
@@ -2,12 +2,14 @@ import type { Plugin } from 'vite';
2
2
 
3
3
  /**
4
4
  * Dev-only binding for a `target: app` or `target: pack` dependency slot.
5
- * Points `request()` at the target app in dev. For app slots it overrides the
6
- * manifest `defaultBinding` when both are present; for pack slots it is the
7
- * only way to bind — the marketplace pin has no install to resolve against in
8
- * dev, so point it at your locally-installed copy of the pack's app.
5
+ * Points `request()` and `url()` at the target app in dev. For app slots it
6
+ * overrides the manifest `defaultBinding` when both are present; for pack
7
+ * slots it is the only way to bind — the marketplace pin has no install to
8
+ * resolve against in dev, so point it at your locally-installed copy of the
9
+ * pack's app.
9
10
  *
10
- * - `app` — the target app (`owner:slug` or UUID). Powers `request()`.
11
+ * - `app` — the target app (`owner:slug` or UUID). Powers `request()`, and
12
+ * names the app `url()` links into (on `INFORMER_URL`).
11
13
  *
12
14
  * A bare string is shorthand for `{ app }`.
13
15
  */
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@entrinsik/vite-plugin-informer",
3
- "version": "2.12.0",
3
+ "version": "2.14.0-beta.0",
4
4
  "description": "Vite plugin and deploy tool for Informer App development",
5
5
  "scripts": {
6
- "test": "node --test"
6
+ "test": "node --test",
7
+ "lint": "eslint ."
7
8
  },
8
9
  "repository": {
9
10
  "type": "git",
10
11
  "url": "https://github.com/entrinsik-org/i5.git",
11
- "directory": "packages/vite-plugin-informer"
12
+ "directory": "packages-standalone/vite-plugin-informer"
12
13
  },
13
14
  "author": "Entrinsik Inc.",
14
15
  "license": "UNLICENSED",
@@ -46,5 +47,10 @@
46
47
  "dependencies": {
47
48
  "dotenv": "16.6.1",
48
49
  "yaml": "^2.7.0"
50
+ },
51
+ "devDependencies": {
52
+ "@eslint/js": "9.22.0",
53
+ "eslint": "9.22.0",
54
+ "globals": "15.15.0"
49
55
  }
50
56
  }
package/src/agent-dev.js CHANGED
@@ -157,6 +157,8 @@ async function readSSE(response) {
157
157
  * @returns {Function} Connect middleware
158
158
  */
159
159
  export function createAgentMiddleware(viteServer, { serverOrigin, authHeader, devWorkspaceId, projectRoot, devBindings, appToken, channels = createDevChannels(), platform = devPlatform(), appId = null }) {
160
+ // a string, or a function answering the current header (renewed from the CLI's sign-in)
161
+ const header = () => (typeof authHeader === 'function' ? authHeader() : authHeader);
160
162
 
161
163
  // query() — proxies to the workspace _sql endpoint (same as server-routes.js)
162
164
  async function query(sql, params) {
@@ -166,7 +168,7 @@ export function createAgentMiddleware(viteServer, { serverOrigin, authHeader, de
166
168
 
167
169
  const resp = await globalThis.fetch(`${serverOrigin}/api/datasources/${devWorkspaceId}/_sql`, {
168
170
  method: 'POST',
169
- headers: { 'Content-Type': 'application/json', Authorization: authHeader },
171
+ headers: { 'Content-Type': 'application/json', Authorization: header() },
170
172
  body: JSON.stringify({ sql, params: params || [] })
171
173
  });
172
174
 
@@ -221,7 +223,7 @@ export function createAgentMiddleware(viteServer, { serverOrigin, authHeader, de
221
223
  const embed = createDevEmbed({ platform, apiFetch, appId });
222
224
 
223
225
  async function apiFetch(path, opts = {}) {
224
- return await fetchAs(authHeader, path, opts);
226
+ return await fetchAs(header(), path, opts);
225
227
  }
226
228
 
227
229
  // Cross-app request() hits the target's /view/_/ dispatch, which accepts only
@@ -229,11 +231,11 @@ export function createAgentMiddleware(viteServer, { serverOrigin, authHeader, de
229
231
  // INFORMER_API_KEY Bearer is reused; under basic auth INFORMER_APP_TOKEN is
230
232
  // required. appFetch stamps x-informer-app-depth:1 for the one-hop guard.
231
233
  // See server-routes.js.
232
- const appAuth = appToken
234
+ const appAuth = () => (appToken
233
235
  ? `Bearer ${appToken}`
234
- : (authHeader && authHeader.startsWith('Bearer ') ? authHeader : null);
235
- const appFetch = appAuth
236
- ? async (path, opts = {}) => await fetchAs(appAuth, path, { ...opts, headers: { ...(opts.headers || {}), 'x-informer-app-depth': '1' } })
236
+ : (header() && header().startsWith('Bearer ') ? header() : null));
237
+ const appFetch = appAuth()
238
+ ? async (path, opts = {}) => await fetchAs(appAuth(), path, { ...opts, headers: { ...(opts.headers || {}), 'x-informer-app-depth': '1' } })
237
239
  : null;
238
240
 
239
241
  // notify/email — delivery is a console-logged no-op in dev, but required-field
@@ -325,7 +327,7 @@ export function createAgentMiddleware(viteServer, { serverOrigin, authHeader, de
325
327
  // `context.<slot>.<method>(...)` and `env` work locally and match
326
328
  // the prod sandbox bag. The manifest is already in hand.
327
329
  const deps = manifestBlock(yaml, 'dependencies');
328
- const context = buildDevContext({ deps, apiFetch, devBindings, appFetch });
330
+ const context = buildDevContext({ deps, apiFetch, devBindings, appFetch, serverOrigin });
329
331
  const env = manifestBlock(yaml, 'env');
330
332
 
331
333
  // emit() writes no app_event row in dev, but still relays a
@@ -401,7 +403,7 @@ export function createAgentMiddleware(viteServer, { serverOrigin, authHeader, de
401
403
  // Call the AI model
402
404
  const chatResp = await globalThis.fetch(`${serverOrigin}/api/models/${model}/_chat`, {
403
405
  method: 'POST',
404
- headers: { 'Content-Type': 'application/json', Authorization: authHeader },
406
+ headers: { 'Content-Type': 'application/json', Authorization: header() },
405
407
  body: JSON.stringify({
406
408
  messages,
407
409
  system: instructions,
package/src/assemble.js CHANGED
@@ -25,8 +25,9 @@ const ROOT_CONFIG_FILES = ['informer.yaml', 'data-access.yaml', 'API.md', 'READM
25
25
  // channels/ holds live-channel join/leave handlers (App Channels); the server
26
26
  // scans and bundles it like server/ and webhooks/. `embeddings` holds the pump
27
27
  // use-case files: server-side like server/, so they ship with the library and
28
- // the platform can scan them.
29
- const SOURCE_DIRS = ['migrations', 'tools', 'mcp', 'server', 'webhooks', 'channels', 'embeddings', 'lib', 'shared'];
28
+ // the platform can scan them. `cli` holds the commands the installed Informer
29
+ // CLI runs, scanned and bundled like mcp/.
30
+ const SOURCE_DIRS = ['migrations', 'tools', 'mcp', 'cli', 'server', 'webhooks', 'channels', 'embeddings', 'lib', 'shared'];
30
31
 
31
32
  // Entries never worth shipping in an app's server-side library: OS/editor
32
33
  // dotfiles (.DS_Store, .env), nested dependency trees, and test files. Applied
package/src/client.js CHANGED
@@ -2,6 +2,26 @@
2
2
  * Informer API client using native fetch with Basic auth.
3
3
  */
4
4
 
5
+ /**
6
+ * The server's own explanation, dug out of an error body.
7
+ *
8
+ * Boom replies carry the useful sentence in `message`, and for a refused deploy
9
+ * that sentence is the whole value of the response — it names the call that
10
+ * unblocks the app. A bare status line leaves the author with nothing to act on.
11
+ *
12
+ * @param {string} body - raw response body
13
+ * @returns {string} the server's message, or '' when the body says nothing
14
+ */
15
+ function errorDetail(body) {
16
+ if (!body) return '';
17
+ try {
18
+ const parsed = JSON.parse(body);
19
+ return parsed.message || parsed.error || '';
20
+ } catch {
21
+ return String(body).trim().slice(0, 500);
22
+ }
23
+ }
24
+
5
25
  class InformerApiError extends Error {
6
26
  constructor(status, statusText, body, url) {
7
27
  super(`Informer API ${status} ${statusText}${url ? ` (${url})` : ''}`);
@@ -9,6 +29,7 @@ class InformerApiError extends Error {
9
29
  this.status = status;
10
30
  this.statusText = statusText;
11
31
  this.body = body;
32
+ this.detail = errorDetail(body);
12
33
  this.url = url;
13
34
  }
14
35
  }
@@ -63,7 +84,7 @@ export function createClient({ baseUrl, apiKey, user, pass }) {
63
84
  * Upload a file using chunked Flow.js protocol, then assemble into an entity's library.
64
85
  * @param {{ entityPath?: string, reportId?: string, path: string, buffer: Buffer, filename: string }} opts
65
86
  */
66
- async function uploadChunked({ entityPath, reportId, path, buffer, filename }) {
87
+ async function uploadChunked({ entityPath, reportId, path, buffer, filename, stagingLibraryId }) {
67
88
  const basePath = entityPath || `reports/${reportId}`;
68
89
  const totalChunks = Math.ceil(buffer.length / CHUNK_SIZE);
69
90
  const uploadId = `publish-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
@@ -98,14 +119,19 @@ export function createClient({ baseUrl, apiKey, user, pass }) {
98
119
  }
99
120
  }
100
121
 
101
- // Assemble chunks into a file in the entity's library at the specified path
122
+ // Assemble chunks into a file in the entity's library at the specified
123
+ // path. `stagingLibraryId` claims the in-flight deploy — without it the
124
+ // server refuses the write rather than folding it into someone else's
125
+ // build (see deploy-target.js).
102
126
  await request('POST', `${basePath}/_upload`, {
103
127
  uploadId,
104
- path
128
+ path,
129
+ ...(stagingLibraryId ? { stagingLibraryId } : {})
105
130
  });
106
131
  }
107
132
 
108
133
  return {
134
+ baseUrl: origin,
109
135
  get: (path) => request('GET', path),
110
136
  post: (path, body) => request('POST', path, body),
111
137
  put: (path, body) => request('PUT', path, body),
package/src/compat.js CHANGED
@@ -22,6 +22,8 @@ export const FEATURE_FLOORS = Object.freeze({
22
22
  channels: '2026.1.3',
23
23
  // The embedding pump: embeddings/ use cases and embed() on the handler bag.
24
24
  embeddings: '2026.1.3',
25
+ // App CLI commands: cli/ handlers the installed Informer CLI runs.
26
+ cli: '2026.1.4',
25
27
  // Staged uploads/downloads: the uploads/downloads services, /view/_uploads
26
28
  // and /view/_downloads, and __INFORMER__.upload() in the page.
27
29
  streams: '2026.1.3',
@@ -50,7 +52,8 @@ export const FEATURE_FLOORS = Object.freeze({
50
52
  */
51
53
  export const GATED_SOURCE_DIRS = Object.freeze([
52
54
  Object.freeze({ dir: 'channels', feature: 'channels', holds: 'channel join/leave handlers' }),
53
- Object.freeze({ dir: 'embeddings', feature: 'embeddings', holds: 'embedding pump handlers (and the workspace SQL in them)' })
55
+ Object.freeze({ dir: 'embeddings', feature: 'embeddings', holds: 'embedding pump handlers (and the workspace SQL in them)' }),
56
+ Object.freeze({ dir: 'cli', feature: 'cli', holds: 'CLI command handlers' })
54
57
  ]);
55
58
 
56
59
  /**
@@ -179,10 +182,11 @@ export function planDeploy({ server, files, manifest }) {
179
182
  const where = server.version ? `Informer ${server.version}` : 'this Informer';
180
183
 
181
184
  if (server.unknown) {
185
+ const atRisk = GATED_SOURCE_DIRS.map(d => `${d.dir}/ (before ${FEATURE_FLOORS[d.feature]})`).join(', ');
182
186
  warnings.push(
183
187
  `Could not read a comparable version from ${server.version ? `"${server.version}"` : 'GET /api/about'}. `
184
- + 'Deploying everything on the assumption the server is current — if it is older than 2026.1.3, '
185
- + `${GATED_SOURCE_DIRS.map(d => `${d.dir}/`).join(' and ')} will be readable from the App's view URL.`
188
+ + 'Deploying everything on the assumption the server is current. On an older server these trees '
189
+ + `would be readable from the App's view URL: ${atRisk}.`
186
190
  );
187
191
  }
188
192