@fireweaveai/server-sdk-cjs 0.0.0-reserve.0 → 0.0.0-stage

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.
Files changed (55) hide show
  1. package/README.md +2 -54
  2. package/package.json +4 -56
  3. package/LICENSE +0 -21
  4. package/dist/application/client.d.ts +0 -77
  5. package/dist/application/client.js +0 -144
  6. package/dist/application/mode.d.ts +0 -70
  7. package/dist/application/mode.js +0 -74
  8. package/dist/application/ports.d.ts +0 -94
  9. package/dist/application/ports.js +0 -2
  10. package/dist/application/runtime.d.ts +0 -101
  11. package/dist/application/runtime.js +0 -346
  12. package/dist/domain/context.d.ts +0 -67
  13. package/dist/domain/context.js +0 -90
  14. package/dist/domain/errors.d.ts +0 -45
  15. package/dist/domain/errors.js +0 -99
  16. package/dist/domain/target.d.ts +0 -2
  17. package/dist/domain/target.js +0 -2
  18. package/dist/domain/types.d.ts +0 -107
  19. package/dist/domain/types.js +0 -2
  20. package/dist/domain/validation.d.ts +0 -124
  21. package/dist/domain/validation.js +0 -355
  22. package/dist/index.d.ts +0 -34
  23. package/dist/index.js +0 -52
  24. package/dist/infrastructure/adapters/inmemory.d.ts +0 -77
  25. package/dist/infrastructure/adapters/inmemory.js +0 -151
  26. package/dist/infrastructure/adapters/local.d.ts +0 -108
  27. package/dist/infrastructure/adapters/local.js +0 -105
  28. package/dist/infrastructure/adapters/remote.d.ts +0 -74
  29. package/dist/infrastructure/adapters/remote.js +0 -373
  30. package/dist/infrastructure/hosts.d.ts +0 -18
  31. package/dist/infrastructure/hosts.js +0 -72
  32. package/dist/register-browser.d.ts +0 -1
  33. package/dist/register-browser.js +0 -7
  34. package/dist/register.d.ts +0 -1
  35. package/dist/register.js +0 -13
  36. package/dist/start/browser.d.ts +0 -12
  37. package/dist/start/browser.js +0 -36
  38. package/dist/start/build-info.d.ts +0 -2
  39. package/dist/start/build-info.js +0 -9
  40. package/dist/start/control-points.d.ts +0 -20
  41. package/dist/start/control-points.js +0 -59
  42. package/dist/start/env.d.ts +0 -11
  43. package/dist/start/env.js +0 -64
  44. package/dist/start/fw.d.ts +0 -29
  45. package/dist/start/fw.js +0 -76
  46. package/dist/start/index.d.ts +0 -23
  47. package/dist/start/index.js +0 -28
  48. package/dist/start/instance.d.ts +0 -17
  49. package/dist/start/instance.js +0 -56
  50. package/dist/start/names.d.ts +0 -22
  51. package/dist/start/names.js +0 -25
  52. package/dist/start/resolve.d.ts +0 -40
  53. package/dist/start/resolve.js +0 -139
  54. package/dist/start/state.d.ts +0 -96
  55. package/dist/start/state.js +0 -303
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_ALLOWED_HOSTS = void 0;
4
- exports.isLoopbackHostname = isLoopbackHostname;
5
- exports.assertHostAllowed = assertHostAllowed;
6
- /**
7
- * Backend host allowlist (SSRF guard).
8
- *
9
- * The allowlist is ON by default: when no explicit `allowedHosts` is
10
- * configured, only the canonical Fireweave hosts plus loopback are permitted,
11
- * so a typo'd or tampered `host` cannot be aimed at cloud metadata endpoints.
12
- * Custom / self-hosted deployments require an explicit `allowedHosts` entry;
13
- * `['*']` opts out entirely.
14
- *
15
- * Scheme policy: https is required for non-loopback hosts; plain http is
16
- * permitted on loopback only (the repo's test-server stub).
17
- */
18
- const errors_js_1 = require("../domain/errors.js");
19
- /**
20
- * Canonical default host allowlist.
21
- *
22
- * v3 replaced the third-party analytics hostnames this list used to carry
23
- * (ADR-0006) with Fireweave's own fw-server hostnames. The security property is
24
- * unchanged — an unconfigured allowlist still denies everything it does not name
25
- * — but the *contents* changed: code doing
26
- * `allowedHosts: [...DEFAULT_ALLOWED_HOSTS, …]` no longer reaches the former
27
- * vendor endpoints, which is the intent.
28
- */
29
- exports.DEFAULT_ALLOWED_HOSTS = Object.freeze([
30
- 'app-server.fireweave.ai',
31
- 'staging-app-server.fireweave.ai',
32
- 'localhost',
33
- '127.0.0.1',
34
- '::1',
35
- ]);
36
- /** True for loopback hostnames (http and test stubs are permitted here). */
37
- function isLoopbackHostname(hostname) {
38
- return (hostname === 'localhost' ||
39
- hostname === '127.0.0.1' ||
40
- hostname === '::1' ||
41
- hostname === '[::1]');
42
- }
43
- /**
44
- * Validate a backend host URL against the allowlist.
45
- * Throws FireweaveError('Configuration') — fixed message, no host echo.
46
- */
47
- function assertHostAllowed(host, allowedHosts) {
48
- let url;
49
- try {
50
- url = new URL(host);
51
- }
52
- catch {
53
- throw new errors_js_1.FireweaveError('Configuration');
54
- }
55
- if (url.protocol !== 'http:' && url.protocol !== 'https:') {
56
- throw new errors_js_1.FireweaveError('Configuration');
57
- }
58
- const loopback = isLoopbackHostname(url.hostname);
59
- if (url.protocol === 'http:' && !loopback) {
60
- // https required for anything that leaves the machine.
61
- throw new errors_js_1.FireweaveError('Configuration');
62
- }
63
- const list = allowedHosts !== undefined && allowedHosts.length > 0 ? allowedHosts : exports.DEFAULT_ALLOWED_HOSTS;
64
- if (list.includes('*'))
65
- return; // explicit opt-out
66
- const allowed = list.some((h) => url.hostname === h ||
67
- (h === 'localhost' && loopback) ||
68
- (h === '::1' && url.hostname === '[::1]'));
69
- if (!allowed) {
70
- throw new errors_js_1.FireweaveError('Configuration');
71
- }
72
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /** Browser build of @fireweaveai/server-sdk/register: fails loudly, never starts. */
4
- const index_js_1 = require("./index.js");
5
- throw new index_js_1.FireweaveError('Configuration', {
6
- message: '[fireweave] @fireweaveai/server-sdk/register is for server runtimes. Browser apps use @fireweaveai/web-sdk.',
7
- });
@@ -1 +0,0 @@
1
- export {};
package/dist/register.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * @fireweaveai/server-sdk/register: start FireWeave from the environment alone.
5
- *
6
- * import '@fireweaveai/server-sdk/register'; // first import of the entrypoint
7
- * node --import @fireweaveai/server-sdk/register app.js
8
- * bun --preload @fireweaveai/server-sdk/register app.ts
9
- *
10
- * Use src/fireweave/start.ts instead when you pass control points or other options.
11
- */
12
- const index_js_1 = require("./start/index.js");
13
- (0, index_js_1.start)();
@@ -1,12 +0,0 @@
1
- export declare function start(): void;
2
- export declare function defineControlPoints<T>(controlPoints: T): T;
3
- export declare function resetForTests(): Promise<void>;
4
- export declare const fw: Readonly<{
5
- controlPoints: {};
6
- identify: () => never;
7
- instanceKey: () => never;
8
- status: () => never;
9
- client: () => never;
10
- shutdown: () => never;
11
- }>;
12
- export { SDK_VERSION, SDK_CHANNEL } from './build-info.js';
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SDK_CHANNEL = exports.SDK_VERSION = exports.fw = void 0;
4
- exports.start = start;
5
- exports.defineControlPoints = defineControlPoints;
6
- exports.resetForTests = resetForTests;
7
- /**
8
- * Browser build of @fireweaveai/server-sdk/start (the "browser" export
9
- * condition). Server keys must never reach a bundle, so every entry point
10
- * fails loudly and names the right package.
11
- */
12
- const index_js_1 = require("../index.js");
13
- const serverOnly = () => new index_js_1.FireweaveError('Configuration', {
14
- message: '[fireweave] @fireweaveai/server-sdk/start is for server runtimes. Browser apps use @fireweaveai/web-sdk.',
15
- });
16
- function start() {
17
- throw serverOnly();
18
- }
19
- function defineControlPoints(controlPoints) {
20
- return controlPoints;
21
- }
22
- async function resetForTests() { }
23
- const fail = () => {
24
- throw serverOnly();
25
- };
26
- exports.fw = Object.freeze({
27
- controlPoints: new Proxy({}, { get: () => fail }),
28
- identify: fail,
29
- instanceKey: fail,
30
- status: fail,
31
- client: fail,
32
- shutdown: fail,
33
- });
34
- var build_info_js_1 = require("./build-info.js");
35
- Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return build_info_js_1.SDK_VERSION; } });
36
- Object.defineProperty(exports, "SDK_CHANNEL", { enumerable: true, get: function () { return build_info_js_1.SDK_CHANNEL; } });
@@ -1,2 +0,0 @@
1
- export declare const SDK_VERSION = "3.0.0";
2
- export declare const SDK_CHANNEL: 'staging' | 'production';
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SDK_CHANNEL = exports.SDK_VERSION = void 0;
4
- // GENERATED by tools/release/version.sh apply server — do not edit by hand.
5
- // The start profile reads SDK_CHANNEL to choose its default fw-server host
6
- // (docs/adr/0012-start-profile.md). test/unit/start-build-info.test.ts pins
7
- // SDK_VERSION to package.json, so a release that forgets to stamp fails CI.
8
- exports.SDK_VERSION = '3.0.0';
9
- exports.SDK_CHANNEL = 'production';
@@ -1,20 +0,0 @@
1
- export interface ControlPointDefinition {
2
- /** Value served in local mode. Ignored in remote mode. */
3
- readonly local: boolean;
4
- /** Optional note for humans and agents. Never sent anywhere. */
5
- readonly description?: string;
6
- }
7
- export type ControlPointMap = Readonly<Record<string, ControlPointDefinition>>;
8
- /** Validate a control-points object and return a frozen copy. Throws Configuration on a bad entry. */
9
- export declare function normalizeControlPoints(controlPoints: unknown): ControlPointMap;
10
- /**
11
- * Declare the app's control points. Returns its argument unchanged, typed, and
12
- * checks it at import time so a typo fails where it was made.
13
- *
14
- * export const controlPoints = defineControlPoints({
15
- * 'new-checkout': { local: true },
16
- * });
17
- */
18
- export declare function defineControlPoints<const T extends Record<string, ControlPointDefinition>>(controlPoints: T): T;
19
- /** The core local adapter's seed map. */
20
- export declare function toLocalControlPoints(controlPoints: ControlPointMap): Record<string, boolean>;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeControlPoints = normalizeControlPoints;
4
- exports.defineControlPoints = defineControlPoints;
5
- exports.toLocalControlPoints = toLocalControlPoints;
6
- /**
7
- * The control-points object: every control point the app reads, with the value
8
- * served in local mode. It lives in its own file
9
- * (src/fireweave/control-points.ts by default) and is passed as
10
- * start({ controlPoints }).
11
- *
12
- * It holds local values only. In remote mode fw-server and the rollout decide,
13
- * and call sites keep `false` as their default (RAMP-1), so this file can
14
- * never switch a feature on in production.
15
- */
16
- const index_js_1 = require("../index.js");
17
- const configError = (message) => new index_js_1.FireweaveError('Configuration', { message });
18
- /** Validate a control-points object and return a frozen copy. Throws Configuration on a bad entry. */
19
- function normalizeControlPoints(controlPoints) {
20
- if (controlPoints === undefined || controlPoints === null)
21
- return Object.freeze({});
22
- if (typeof controlPoints !== 'object' || Array.isArray(controlPoints)) {
23
- throw configError('[fireweave] start({ controlPoints }) must be an object of { key: { local: boolean } }.');
24
- }
25
- const out = {};
26
- for (const [key, entry] of Object.entries(controlPoints)) {
27
- const keyResult = (0, index_js_1.validateControlPointKey)(key);
28
- if (!keyResult.ok)
29
- throw configError(`[fireweave] controlPoints: '${key}' is not a valid control point key.`);
30
- if (typeof entry !== 'object' || entry === null || typeof entry.local !== 'boolean') {
31
- throw configError(`[fireweave] controlPoints['${key}'] must be { local: true } or { local: false }.`);
32
- }
33
- const { local, description } = entry;
34
- if (description !== undefined && typeof description !== 'string') {
35
- throw configError(`[fireweave] controlPoints['${key}'].description must be a string.`);
36
- }
37
- out[key] = Object.freeze(description === undefined ? { local } : { local, description });
38
- }
39
- return Object.freeze(out);
40
- }
41
- /**
42
- * Declare the app's control points. Returns its argument unchanged, typed, and
43
- * checks it at import time so a typo fails where it was made.
44
- *
45
- * export const controlPoints = defineControlPoints({
46
- * 'new-checkout': { local: true },
47
- * });
48
- */
49
- function defineControlPoints(controlPoints) {
50
- normalizeControlPoints(controlPoints);
51
- return controlPoints;
52
- }
53
- /** The core local adapter's seed map. */
54
- function toLocalControlPoints(controlPoints) {
55
- const out = {};
56
- for (const [key, entry] of Object.entries(controlPoints))
57
- out[key] = entry.local;
58
- return out;
59
- }
@@ -1,11 +0,0 @@
1
- /** Reads one variable. Returns undefined when unset, empty, or only whitespace. */
2
- export type EnvReader = (name: string) => string | undefined;
3
- /** Reader over an explicit bag (start({ env }) and tests). Only string values count. */
4
- export declare function envFromBag(bag: Readonly<Record<string, unknown>>): EnvReader;
5
- /** Reader over the running process: Deno.env first, then process.env. */
6
- export declare function processEnv(): EnvReader;
7
- /**
8
- * A reader that never throws, for values only needed to word a warning or an
9
- * error (for example the key a local start ignores).
10
- */
11
- export declare function quiet(read: EnvReader): EnvReader;
package/dist/start/env.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.envFromBag = envFromBag;
4
- exports.processEnv = processEnv;
5
- exports.quiet = quiet;
6
- /**
7
- * The ONLY place the SDK reads the process environment.
8
- *
9
- * The core SDK reads no environment variables (spec/modes.md). The start
10
- * profile is the documented exception (docs/adr/0012-start-profile.md), and
11
- * test/unit/runtime-portability.test.ts pins every env read to this file.
12
- *
13
- * Works on Node, Bun and Deno without importing a runtime module: Node and Bun
14
- * expose `process.env`; Deno exposes `Deno.env.get`, which throws when the
15
- * process lacks --allow-env. That refusal is reported, not swallowed, so a
16
- * Deno app never boots with a key it was not allowed to read.
17
- */
18
- const index_js_1 = require("../index.js");
19
- const clean = (value) => {
20
- if (typeof value !== 'string')
21
- return undefined;
22
- const trimmed = value.trim();
23
- return trimmed === '' ? undefined : trimmed;
24
- };
25
- /** Reader over an explicit bag (start({ env }) and tests). Only string values count. */
26
- function envFromBag(bag) {
27
- return (name) => clean(bag[name]);
28
- }
29
- /** Reader over the running process: Deno.env first, then process.env. */
30
- function processEnv() {
31
- const deno = globalThis.Deno;
32
- if (deno?.env !== undefined) {
33
- return (name) => {
34
- try {
35
- return clean(deno.env?.get(name));
36
- }
37
- catch (cause) {
38
- throw new index_js_1.FireweaveError('Configuration', {
39
- message: `[fireweave] Deno refused to read ${name}. Run with --allow-env=${name}, or pass the value to start() explicitly.`,
40
- cause,
41
- });
42
- }
43
- };
44
- }
45
- const proc = globalThis.process;
46
- const env = proc?.env;
47
- if (env === undefined)
48
- return () => undefined;
49
- return (name) => clean(env[name]);
50
- }
51
- /**
52
- * A reader that never throws, for values only needed to word a warning or an
53
- * error (for example the key a local start ignores).
54
- */
55
- function quiet(read) {
56
- return (name) => {
57
- try {
58
- return read(name);
59
- }
60
- catch {
61
- return undefined;
62
- }
63
- };
64
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * `fw`: the singleton accessor beside start(). Safe to import anywhere, in any
3
- * order. Every read awaits start and never throws: if start failed, reads
4
- * serve the caller's default (or an ERROR decision for the *Details forms).
5
- */
6
- import { type ControlPointsApi, type FireweaveClient, type JsonValue, type RegisterTargetResult, type TargetKind } from '../index.js';
7
- import { type FireweaveStatus } from './state.js';
8
- /** The same nine read methods as the core client's controlPoints. */
9
- export type ControlPoints = Pick<ControlPointsApi, 'evaluate' | 'getBooleanValue' | 'getStringValue' | 'getNumberValue' | 'getObjectValue' | 'getBooleanDetails' | 'getStringDetails' | 'getNumberDetails' | 'getObjectDetails'>;
10
- export interface IdentifyOptions {
11
- /** Defaults to 'user'. */
12
- readonly kind?: TargetKind;
13
- readonly signal?: AbortSignal;
14
- }
15
- export interface FireweaveStart {
16
- /** Read control points: `await fw.controlPoints.getBooleanValue('key', false, { targetingKey })`. */
17
- readonly controlPoints: ControlPoints;
18
- /** Register durable targeting facts at sign-in. Resolves { ok }, never throws. */
19
- identify(targetingKey: string, properties?: Record<string, JsonValue>, options?: IdentifyOptions): Promise<RegisterTargetResult>;
20
- /** Stable key for reads where the server is the subject (cron, boot). No disk writes. */
21
- instanceKey(): string;
22
- /** What start() decided: mode, channel, host, key source. Never includes the key. */
23
- status(): FireweaveStatus;
24
- /** The core client, for anything the facade does not cover. Rejects if start failed. */
25
- client(): Promise<FireweaveClient>;
26
- /** Flush and close. A later start() begins fresh. */
27
- shutdown(): Promise<void>;
28
- }
29
- export declare const fw: FireweaveStart;
package/dist/start/fw.js DELETED
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fw = void 0;
4
- /**
5
- * `fw`: the singleton accessor beside start(). Safe to import anywhere, in any
6
- * order. Every read awaits start and never throws: if start failed, reads
7
- * serve the caller's default (or an ERROR decision for the *Details forms).
8
- */
9
- const index_js_1 = require("../index.js");
10
- const state_js_1 = require("./state.js");
11
- const startFailure = () => (0, state_js_1.slot)().error ?? new index_js_1.FireweaveError('Configuration', { message: '[fireweave] FireWeave was not started.' });
12
- const errorDecision = (controlPointKey, defaultValue) => {
13
- const err = startFailure();
14
- return {
15
- controlPointKey,
16
- value: defaultValue,
17
- reason: 'ERROR',
18
- errorKind: err.kind,
19
- errorCode: err.openFeatureErrorCode,
20
- errorMessage: err.message,
21
- metadata: {},
22
- };
23
- };
24
- /** Local mode: a key missing from the control-points object gets its default, with one warning. */
25
- function noteLocalKey(controlPointKey) {
26
- const s = (0, state_js_1.slot)();
27
- const r = s.resolved;
28
- if (r?.mode !== 'local' || Object.prototype.hasOwnProperty.call(r.controlPoints, controlPointKey))
29
- return;
30
- (0, state_js_1.warnOnce)(s, `[fireweave:local] '${controlPointKey}' is not in your control points (src/fireweave/control-points.ts), so it gets its default. Add it there to try it locally.`);
31
- }
32
- async function read(controlPointKey, fallback, run) {
33
- const client = await (0, state_js_1.ensureClient)();
34
- if (client === undefined)
35
- return fallback();
36
- noteLocalKey(controlPointKey);
37
- return run(client);
38
- }
39
- const controlPoints = {
40
- evaluate: (controlPointKey, expectedType, defaultValue, context, options) => read(controlPointKey, () => errorDecision(controlPointKey, defaultValue), (c) => c.controlPoints.evaluate(controlPointKey, expectedType, defaultValue, context, options)),
41
- getBooleanValue: (controlPointKey, defaultValue, context) => read(controlPointKey, () => defaultValue, (c) => c.controlPoints.getBooleanValue(controlPointKey, defaultValue, context)),
42
- getStringValue: (controlPointKey, defaultValue, context) => read(controlPointKey, () => defaultValue, (c) => c.controlPoints.getStringValue(controlPointKey, defaultValue, context)),
43
- getNumberValue: (controlPointKey, defaultValue, context) => read(controlPointKey, () => defaultValue, (c) => c.controlPoints.getNumberValue(controlPointKey, defaultValue, context)),
44
- getObjectValue: (controlPointKey, defaultValue, context) => read(controlPointKey, () => defaultValue, (c) => c.controlPoints.getObjectValue(controlPointKey, defaultValue, context)),
45
- getBooleanDetails: (controlPointKey, defaultValue, context) => read(controlPointKey, () => errorDecision(controlPointKey, defaultValue), (c) => c.controlPoints.getBooleanDetails(controlPointKey, defaultValue, context)),
46
- getStringDetails: (controlPointKey, defaultValue, context) => read(controlPointKey, () => errorDecision(controlPointKey, defaultValue), (c) => c.controlPoints.getStringDetails(controlPointKey, defaultValue, context)),
47
- getNumberDetails: (controlPointKey, defaultValue, context) => read(controlPointKey, () => errorDecision(controlPointKey, defaultValue), (c) => c.controlPoints.getNumberDetails(controlPointKey, defaultValue, context)),
48
- getObjectDetails: (controlPointKey, defaultValue, context) => read(controlPointKey, () => errorDecision(controlPointKey, defaultValue), (c) => c.controlPoints.getObjectDetails(controlPointKey, defaultValue, context)),
49
- };
50
- exports.fw = Object.freeze({
51
- controlPoints: Object.freeze(controlPoints),
52
- async identify(targetingKey, properties, options = {}) {
53
- const client = await (0, state_js_1.ensureClient)();
54
- if (client === undefined)
55
- return { ok: false };
56
- try {
57
- return await client.registerTarget(targetingKey, {
58
- kind: options.kind ?? 'user',
59
- ...(properties !== undefined ? { properties } : {}),
60
- ...(options.signal !== undefined ? { signal: options.signal } : {}),
61
- });
62
- }
63
- catch {
64
- return { ok: false };
65
- }
66
- },
67
- instanceKey: () => (0, state_js_1.instanceKeyFor)(),
68
- status: () => (0, state_js_1.currentStatus)(),
69
- async client() {
70
- const client = await (0, state_js_1.ensureClient)();
71
- if (client === undefined)
72
- throw startFailure();
73
- return client;
74
- },
75
- shutdown: () => (0, state_js_1.shutdownSlot)(),
76
- });
@@ -1,23 +0,0 @@
1
- /**
2
- * @fireweaveai/server-sdk/start: FireWeave in one import (docs/adr/0012-start-profile.md).
3
- *
4
- * // src/fireweave/start.ts (imported first by your entrypoint)
5
- * import { start } from '@fireweaveai/server-sdk/start';
6
- * import { controlPoints } from './control-points';
7
- * start({ controlPoints });
8
- *
9
- * // anywhere
10
- * import { fw } from '@fireweaveai/server-sdk/start';
11
- * if (await fw.controlPoints.getBooleanValue('new-checkout', false, { targetingKey: user.id })) { … }
12
- *
13
- * This layer is built only on the package's public exports; the core
14
- * (initFireweave and everything in '.') is unchanged and still reads no env.
15
- */
16
- export { start, resetForTests } from './state.js';
17
- export type { StartOptions, StartState, FireweaveStatus } from './state.js';
18
- export { fw } from './fw.js';
19
- export type { FireweaveStart, ControlPoints, IdentifyOptions } from './fw.js';
20
- export { defineControlPoints } from './control-points.js';
21
- export type { ControlPointDefinition, ControlPointMap } from './control-points.js';
22
- export type { StartMode, SdkChannel } from './resolve.js';
23
- export { SDK_VERSION, SDK_CHANNEL } from './build-info.js';
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SDK_CHANNEL = exports.SDK_VERSION = exports.defineControlPoints = exports.fw = exports.resetForTests = exports.start = void 0;
4
- /**
5
- * @fireweaveai/server-sdk/start: FireWeave in one import (docs/adr/0012-start-profile.md).
6
- *
7
- * // src/fireweave/start.ts (imported first by your entrypoint)
8
- * import { start } from '@fireweaveai/server-sdk/start';
9
- * import { controlPoints } from './control-points';
10
- * start({ controlPoints });
11
- *
12
- * // anywhere
13
- * import { fw } from '@fireweaveai/server-sdk/start';
14
- * if (await fw.controlPoints.getBooleanValue('new-checkout', false, { targetingKey: user.id })) { … }
15
- *
16
- * This layer is built only on the package's public exports; the core
17
- * (initFireweave and everything in '.') is unchanged and still reads no env.
18
- */
19
- var state_js_1 = require("./state.js");
20
- Object.defineProperty(exports, "start", { enumerable: true, get: function () { return state_js_1.start; } });
21
- Object.defineProperty(exports, "resetForTests", { enumerable: true, get: function () { return state_js_1.resetForTests; } });
22
- var fw_js_1 = require("./fw.js");
23
- Object.defineProperty(exports, "fw", { enumerable: true, get: function () { return fw_js_1.fw; } });
24
- var control_points_js_1 = require("./control-points.js");
25
- Object.defineProperty(exports, "defineControlPoints", { enumerable: true, get: function () { return control_points_js_1.defineControlPoints; } });
26
- var build_info_js_1 = require("./build-info.js");
27
- Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return build_info_js_1.SDK_VERSION; } });
28
- Object.defineProperty(exports, "SDK_CHANNEL", { enumerable: true, get: function () { return build_info_js_1.SDK_CHANNEL; } });
@@ -1,17 +0,0 @@
1
- /**
2
- * fw.instanceKey(): a stable targeting key for reads where the server itself is
3
- * the subject (cron, migrations, boot-time decisions). Request reads still pass
4
- * the user's id.
5
- *
6
- * Sources, in order: start({ instanceId }), FIREWEAVE_INSTANCE_ID, then a hash
7
- * of the host name, then a random id for the life of the process. Nothing is
8
- * written to disk: in a container the file would not outlive the process anyway.
9
- */
10
- import type { EnvReader } from './env.js';
11
- export interface InstanceKey {
12
- readonly value: string;
13
- readonly source: 'option' | 'FIREWEAVE_INSTANCE_ID' | 'host' | 'random';
14
- }
15
- /** FNV-1a 64-bit, hex. Stable across runtimes; not a security hash. */
16
- export declare function fnv1a64(text: string): string;
17
- export declare function deriveInstanceKey(option: string | undefined, read: EnvReader): InstanceKey;
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fnv1a64 = fnv1a64;
4
- exports.deriveInstanceKey = deriveInstanceKey;
5
- const env_js_1 = require("./env.js");
6
- const names_js_1 = require("./names.js");
7
- /** FNV-1a 64-bit, hex. Stable across runtimes; not a security hash. */
8
- function fnv1a64(text) {
9
- let hash = 0xcbf29ce484222325n;
10
- const prime = 0x100000001b3n;
11
- for (const byte of new TextEncoder().encode(text)) {
12
- hash ^= BigInt(byte);
13
- hash = (hash * prime) & 0xffffffffffffffffn;
14
- }
15
- return hash.toString(16).padStart(16, '0');
16
- }
17
- /** Host name without importing a runtime module; undefined when the runtime will not say. */
18
- function hostName(read) {
19
- const fromEnv = (0, env_js_1.quiet)(read)('HOSTNAME');
20
- if (fromEnv !== undefined)
21
- return fromEnv;
22
- try {
23
- const deno = globalThis.Deno;
24
- if (typeof deno?.hostname === 'function')
25
- return deno.hostname();
26
- }
27
- catch {
28
- // Deno without --allow-sys=hostname: fall through.
29
- }
30
- try {
31
- const proc = globalThis.process;
32
- const os = proc?.getBuiltinModule?.('node:os');
33
- const name = os?.hostname?.();
34
- if (typeof name === 'string' && name !== '')
35
- return name;
36
- }
37
- catch {
38
- // Runtime without getBuiltinModule: fall through.
39
- }
40
- return undefined;
41
- }
42
- const randomId = () => {
43
- const c = globalThis.crypto;
44
- return c?.randomUUID?.() ?? `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
45
- };
46
- function deriveInstanceKey(option, read) {
47
- if (option !== undefined)
48
- return { value: option, source: 'option' };
49
- const fromEnv = (0, env_js_1.quiet)(read)(names_js_1.ENV.instanceId);
50
- if (fromEnv !== undefined)
51
- return { value: fromEnv, source: 'FIREWEAVE_INSTANCE_ID' };
52
- const host = hostName(read);
53
- if (host !== undefined)
54
- return { value: `inst_${fnv1a64(host)}`, source: 'host' };
55
- return { value: `inst_${randomId()}`, source: 'random' };
56
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Every name the start profile reads, in one place, so the README, the
3
- * initialise skill and the error messages cannot drift apart.
4
- */
5
- /** Env vars the start profile reads. Explicit start() options always win. */
6
- export declare const ENV: Readonly<{
7
- key: "FIREWEAVE_KEY";
8
- url: "FIREWEAVE_URL";
9
- environment: "FIREWEAVE_ENV";
10
- instanceId: "FIREWEAVE_INSTANCE_ID";
11
- }>;
12
- /** Fallback env-name sources for mode inference, after the environment option and FIREWEAVE_ENV. */
13
- export declare const ENVIRONMENT_FALLBACKS: readonly ["APP_ENV", "NODE_ENV"];
14
- /** Environment names that mean "local development" when no key is set. Case-insensitive. */
15
- export declare const DEV_ENVIRONMENTS: ReadonlySet<string>;
16
- /** fw-server host for each release channel of this package. */
17
- export declare const CHANNEL_URLS: Readonly<{
18
- production: "https://app-server.fireweave.ai";
19
- staging: "https://staging-app-server.fireweave.ai";
20
- }>;
21
- /** Hosts always allowed beside a custom endpoint, so local stacks keep working. */
22
- export declare const LOOPBACK_HOSTS: readonly string[];
@@ -1,25 +0,0 @@
1
- "use strict";
2
- /**
3
- * Every name the start profile reads, in one place, so the README, the
4
- * initialise skill and the error messages cannot drift apart.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.LOOPBACK_HOSTS = exports.CHANNEL_URLS = exports.DEV_ENVIRONMENTS = exports.ENVIRONMENT_FALLBACKS = exports.ENV = void 0;
8
- /** Env vars the start profile reads. Explicit start() options always win. */
9
- exports.ENV = Object.freeze({
10
- key: 'FIREWEAVE_KEY',
11
- url: 'FIREWEAVE_URL',
12
- environment: 'FIREWEAVE_ENV',
13
- instanceId: 'FIREWEAVE_INSTANCE_ID',
14
- });
15
- /** Fallback env-name sources for mode inference, after the environment option and FIREWEAVE_ENV. */
16
- exports.ENVIRONMENT_FALLBACKS = Object.freeze(['APP_ENV', 'NODE_ENV']);
17
- /** Environment names that mean "local development" when no key is set. Case-insensitive. */
18
- exports.DEV_ENVIRONMENTS = new Set(['development', 'dev', 'local', 'test']);
19
- /** fw-server host for each release channel of this package. */
20
- exports.CHANNEL_URLS = Object.freeze({
21
- production: 'https://app-server.fireweave.ai',
22
- staging: 'https://staging-app-server.fireweave.ai',
23
- });
24
- /** Hosts always allowed beside a custom endpoint, so local stacks keep working. */
25
- exports.LOOPBACK_HOSTS = Object.freeze(['localhost', '127.0.0.1', '::1']);
@@ -1,40 +0,0 @@
1
- import type { EnvReader } from './env.js';
2
- import { type ControlPointMap } from './control-points.js';
3
- export type StartMode = 'remote' | 'local';
4
- export type SdkChannel = 'staging' | 'production';
5
- export interface ResolveInput {
6
- readonly mode?: unknown;
7
- readonly environment?: unknown;
8
- readonly url?: unknown;
9
- readonly key?: unknown;
10
- readonly controlPoints?: unknown;
11
- }
12
- export interface BuildInfo {
13
- readonly version: string;
14
- readonly channel: SdkChannel;
15
- }
16
- export interface ResolvedStart {
17
- readonly mode: StartMode;
18
- /** Why this mode: the mode option, a present key, or the environment name. */
19
- readonly modeSource: 'option' | 'key' | 'environment';
20
- /** Remote only. */
21
- readonly url?: string;
22
- readonly urlSource?: string;
23
- readonly allowedHosts?: readonly string[];
24
- /** Remote only. Never logged or printed. */
25
- readonly key?: string;
26
- readonly keySource: string;
27
- /** Set when the environment name was consulted (no key, no mode option). */
28
- readonly environment?: string;
29
- readonly environmentSource?: string;
30
- readonly controlPoints: ControlPointMap;
31
- readonly channel: SdkChannel;
32
- readonly sdkVersion: string;
33
- /** Lines to log once each: ignored keys. */
34
- readonly warnings: readonly string[];
35
- }
36
- /**
37
- * Resolve start() options against the environment.
38
- * Throws FireweaveError('Configuration') naming the variable at fault.
39
- */
40
- export declare function resolveStart(input: ResolveInput, read: EnvReader, build: BuildInfo): ResolvedStart;