@fireweaveai/server-sdk 2.3.1-staging.3 → 3.0.0-staging.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 +86 -123
- package/dist/application/client.d.ts +11 -25
- package/dist/application/client.d.ts.map +1 -1
- package/dist/application/client.js +20 -36
- package/dist/application/client.js.map +1 -1
- package/dist/application/ports.d.ts +3 -3
- package/dist/application/ports.d.ts.map +1 -1
- package/dist/application/runtime.d.ts +1 -1
- package/dist/application/runtime.d.ts.map +1 -1
- package/dist/application/runtime.js +23 -23
- package/dist/application/runtime.js.map +1 -1
- package/dist/domain/errors.d.ts +5 -2
- package/dist/domain/errors.d.ts.map +1 -1
- package/dist/domain/errors.js +40 -10
- package/dist/domain/errors.js.map +1 -1
- package/dist/domain/types.d.ts +4 -4
- package/dist/domain/types.d.ts.map +1 -1
- package/dist/domain/validation.d.ts +3 -3
- package/dist/domain/validation.js +6 -6
- package/dist/domain/validation.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/infrastructure/adapters/inmemory.d.ts +1 -1
- package/dist/infrastructure/adapters/inmemory.d.ts.map +1 -1
- package/dist/infrastructure/adapters/inmemory.js +3 -3
- package/dist/infrastructure/adapters/inmemory.js.map +1 -1
- package/dist/infrastructure/adapters/local.d.ts +3 -3
- package/dist/infrastructure/adapters/local.d.ts.map +1 -1
- package/dist/infrastructure/adapters/local.js +3 -3
- package/dist/infrastructure/adapters/local.js.map +1 -1
- package/dist/infrastructure/adapters/remote.d.ts +1 -1
- package/dist/infrastructure/adapters/remote.d.ts.map +1 -1
- package/dist/infrastructure/adapters/remote.js +23 -14
- package/dist/infrastructure/adapters/remote.js.map +1 -1
- package/dist/infrastructure/hosts.js +1 -1
- package/dist/register-browser.d.ts +2 -0
- package/dist/register-browser.d.ts.map +1 -0
- package/dist/register-browser.js +6 -0
- package/dist/register-browser.js.map +1 -0
- package/dist/register.d.ts +2 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +12 -0
- package/dist/register.js.map +1 -0
- package/dist/start/browser.d.ts +13 -0
- package/dist/start/browser.d.ts.map +1 -0
- package/dist/start/browser.js +29 -0
- package/dist/start/browser.js.map +1 -0
- package/dist/start/build-info.d.ts +3 -0
- package/dist/start/build-info.d.ts.map +1 -0
- package/dist/start/build-info.js +7 -0
- package/dist/start/build-info.js.map +1 -0
- package/dist/start/control-points.d.ts +21 -0
- package/dist/start/control-points.d.ts.map +1 -0
- package/dist/start/control-points.js +55 -0
- package/dist/start/control-points.js.map +1 -0
- package/dist/start/env.d.ts +12 -0
- package/dist/start/env.d.ts.map +1 -0
- package/dist/start/env.js +60 -0
- package/dist/start/env.js.map +1 -0
- package/dist/start/fw.d.ts +30 -0
- package/dist/start/fw.d.ts.map +1 -0
- package/dist/start/fw.js +74 -0
- package/dist/start/fw.js.map +1 -0
- package/dist/start/index.d.ts +24 -0
- package/dist/start/index.d.ts.map +1 -0
- package/dist/start/index.js +20 -0
- package/dist/start/index.js.map +1 -0
- package/dist/start/instance.d.ts +18 -0
- package/dist/start/instance.d.ts.map +1 -0
- package/dist/start/instance.js +53 -0
- package/dist/start/instance.js.map +1 -0
- package/dist/start/names.d.ts +33 -0
- package/dist/start/names.d.ts.map +1 -0
- package/dist/start/names.js +33 -0
- package/dist/start/names.js.map +1 -0
- package/dist/start/resolve.d.ts +41 -0
- package/dist/start/resolve.d.ts.map +1 -0
- package/dist/start/resolve.js +152 -0
- package/dist/start/resolve.js.map +1 -0
- package/dist/start/state.d.ts +97 -0
- package/dist/start/state.d.ts.map +1 -0
- package/dist/start/state.js +293 -0
- package/dist/start/state.js.map +1 -0
- package/package.json +12 -3
|
@@ -0,0 +1,24 @@
|
|
|
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';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/start/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACnF,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { fw } from './fw.js';
|
|
18
|
+
export { defineControlPoints } from './control-points.js';
|
|
19
|
+
export { SDK_VERSION, SDK_CHANNEL } from './build-info.js';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/start/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
|
18
|
+
//# sourceMappingURL=instance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../../src/start/instance.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAI1C,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,uBAAuB,GAAG,MAAM,GAAG,QAAQ,CAAC;CACzE;AAED,uEAAuE;AACvE,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ5C;AAmCD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,WAAW,CAO1F"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { quiet } from './env.js';
|
|
2
|
+
import { ENV } from './names.js';
|
|
3
|
+
/** FNV-1a 64-bit, hex. Stable across runtimes; not a security hash. */
|
|
4
|
+
export function fnv1a64(text) {
|
|
5
|
+
let hash = 0xcbf29ce484222325n;
|
|
6
|
+
const prime = 0x100000001b3n;
|
|
7
|
+
for (const byte of new TextEncoder().encode(text)) {
|
|
8
|
+
hash ^= BigInt(byte);
|
|
9
|
+
hash = (hash * prime) & 0xffffffffffffffffn;
|
|
10
|
+
}
|
|
11
|
+
return hash.toString(16).padStart(16, '0');
|
|
12
|
+
}
|
|
13
|
+
/** Host name without importing a runtime module; undefined when the runtime will not say. */
|
|
14
|
+
function hostName(read) {
|
|
15
|
+
const fromEnv = quiet(read)('HOSTNAME');
|
|
16
|
+
if (fromEnv !== undefined)
|
|
17
|
+
return fromEnv;
|
|
18
|
+
try {
|
|
19
|
+
const deno = globalThis.Deno;
|
|
20
|
+
if (typeof deno?.hostname === 'function')
|
|
21
|
+
return deno.hostname();
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Deno without --allow-sys=hostname: fall through.
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const proc = globalThis.process;
|
|
28
|
+
const os = proc?.getBuiltinModule?.('node:os');
|
|
29
|
+
const name = os?.hostname?.();
|
|
30
|
+
if (typeof name === 'string' && name !== '')
|
|
31
|
+
return name;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// Runtime without getBuiltinModule: fall through.
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const randomId = () => {
|
|
39
|
+
const c = globalThis.crypto;
|
|
40
|
+
return c?.randomUUID?.() ?? `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
41
|
+
};
|
|
42
|
+
export function deriveInstanceKey(option, read) {
|
|
43
|
+
if (option !== undefined)
|
|
44
|
+
return { value: option, source: 'option' };
|
|
45
|
+
const fromEnv = quiet(read)(ENV.instanceId);
|
|
46
|
+
if (fromEnv !== undefined)
|
|
47
|
+
return { value: fromEnv, source: 'FIREWEAVE_INSTANCE_ID' };
|
|
48
|
+
const host = hostName(read);
|
|
49
|
+
if (host !== undefined)
|
|
50
|
+
return { value: `inst_${fnv1a64(host)}`, source: 'host' };
|
|
51
|
+
return { value: `inst_${randomId()}`, source: 'random' };
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=instance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../../src/start/instance.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAOjC,uEAAuE;AACvE,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,IAAI,IAAI,GAAG,mBAAmB,CAAC;IAC/B,MAAM,KAAK,GAAG,cAAc,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAClD,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,mBAAmB,CAAC;IAC9C,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC;AASD,6FAA6F;AAC7F,SAAS,QAAQ,CAAC,IAAe;IAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC;IACxC,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,IAAI,GAAI,UAAkC,CAAC,IAAI,CAAC;QACtD,IAAI,OAAO,IAAI,EAAE,QAAQ,KAAK,UAAU;YAAE,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,mDAAmD;IACrD,CAAC;IACD,IAAI,CAA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O,EAAE,KAAK,EAAE,QAAQ,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
/**
|
|
13
|
+
* Legacy names written by the scaffolded harness. Read only when the
|
|
14
|
+
* replacement is unset, with one warning per name, for all of 2.x.
|
|
15
|
+
*/
|
|
16
|
+
export declare const LEGACY_ENV: Readonly<{
|
|
17
|
+
key: readonly ["FW_PROJECT_API_KEY"];
|
|
18
|
+
url: readonly ["FW_API_URL", "FW_ATTEST_URL"];
|
|
19
|
+
}>;
|
|
20
|
+
/** Fallback env-name sources for mode inference, after the environment option and FIREWEAVE_ENV. */
|
|
21
|
+
export declare const ENVIRONMENT_FALLBACKS: readonly ["APP_ENV", "NODE_ENV"];
|
|
22
|
+
/** Read only to explain a boot error: the harness's FW_ENV is no longer honoured. */
|
|
23
|
+
export declare const RETIRED_ENVIRONMENT_NAME = "FW_ENV";
|
|
24
|
+
/** Environment names that mean "local development" when no key is set. Case-insensitive. */
|
|
25
|
+
export declare const DEV_ENVIRONMENTS: ReadonlySet<string>;
|
|
26
|
+
/** fw-server host for each release channel of this package. */
|
|
27
|
+
export declare const CHANNEL_URLS: Readonly<{
|
|
28
|
+
production: "https://app-server.fireweave.ai";
|
|
29
|
+
staging: "https://staging-app-server.fireweave.ai";
|
|
30
|
+
}>;
|
|
31
|
+
/** Hosts always allowed beside a custom endpoint, so local stacks keep working. */
|
|
32
|
+
export declare const LOOPBACK_HOSTS: readonly string[];
|
|
33
|
+
//# sourceMappingURL=names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../src/start/names.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,GAAG;;;;;EAKd,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,UAAU;;;EAGrB,CAAC;AAEH,oGAAoG;AACpG,eAAO,MAAM,qBAAqB,kCAAkD,CAAC;AAErF,qFAAqF;AACrF,eAAO,MAAM,wBAAwB,WAAW,CAAC;AAEjD,4FAA4F;AAC5F,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAoD,CAAC;AAEtG,+DAA+D;AAC/D,eAAO,MAAM,YAAY;;;EAGvB,CAAC;AAEH,mFAAmF;AACnF,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAAqD,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 const ENV = Object.freeze({
|
|
7
|
+
key: 'FIREWEAVE_KEY',
|
|
8
|
+
url: 'FIREWEAVE_URL',
|
|
9
|
+
environment: 'FIREWEAVE_ENV',
|
|
10
|
+
instanceId: 'FIREWEAVE_INSTANCE_ID',
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Legacy names written by the scaffolded harness. Read only when the
|
|
14
|
+
* replacement is unset, with one warning per name, for all of 2.x.
|
|
15
|
+
*/
|
|
16
|
+
export const LEGACY_ENV = Object.freeze({
|
|
17
|
+
key: ['FW_PROJECT_API_KEY'],
|
|
18
|
+
url: ['FW_API_URL', 'FW_ATTEST_URL'],
|
|
19
|
+
});
|
|
20
|
+
/** Fallback env-name sources for mode inference, after the environment option and FIREWEAVE_ENV. */
|
|
21
|
+
export const ENVIRONMENT_FALLBACKS = Object.freeze(['APP_ENV', 'NODE_ENV']);
|
|
22
|
+
/** Read only to explain a boot error: the harness's FW_ENV is no longer honoured. */
|
|
23
|
+
export const RETIRED_ENVIRONMENT_NAME = 'FW_ENV';
|
|
24
|
+
/** Environment names that mean "local development" when no key is set. Case-insensitive. */
|
|
25
|
+
export const DEV_ENVIRONMENTS = new Set(['development', 'dev', 'local', 'test']);
|
|
26
|
+
/** fw-server host for each release channel of this package. */
|
|
27
|
+
export const CHANNEL_URLS = Object.freeze({
|
|
28
|
+
production: 'https://app-server.fireweave.ai',
|
|
29
|
+
staging: 'https://staging-app-server.fireweave.ai',
|
|
30
|
+
});
|
|
31
|
+
/** Hosts always allowed beside a custom endpoint, so local stacks keep working. */
|
|
32
|
+
export const LOOPBACK_HOSTS = Object.freeze(['localhost', '127.0.0.1', '::1']);
|
|
33
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","sourceRoot":"","sources":["../../src/start/names.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,eAAe;IACpB,WAAW,EAAE,eAAe;IAC5B,UAAU,EAAE,uBAAuB;CACpC,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IACtC,GAAG,EAAE,CAAC,oBAAoB,CAAU;IACpC,GAAG,EAAE,CAAC,YAAY,EAAE,eAAe,CAAU;CAC9C,CAAC,CAAC;AAEH,oGAAoG;AACpG,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,UAAU,CAAU,CAAC,CAAC;AAErF,qFAAqF;AACrF,MAAM,CAAC,MAAM,wBAAwB,GAAG,QAAQ,CAAC;AAEjD,4FAA4F;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtG,+DAA+D;AAC/D,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,UAAU,EAAE,iCAAiC;IAC7C,OAAO,EAAE,yCAAyC;CACnD,CAAC,CAAC;AAEH,mFAAmF;AACnF,MAAM,CAAC,MAAM,cAAc,GAAsB,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
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: legacy names, 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;
|
|
41
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/start/resolve.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAWnF,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAC3C,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,YAAY,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;CAC9B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,QAAQ,GAAG,KAAK,GAAG,aAAa,CAAC;IACtD,mBAAmB;IACnB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,4CAA4C;IAC5C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,eAAe,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAgID;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,aAAa,CA8ClG"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure start-profile resolver: options + env + build stamp in, one resolved
|
|
3
|
+
* config out. No I/O, no globals, no timers — every rule here is unit-tested
|
|
4
|
+
* through `resolveStart` alone.
|
|
5
|
+
*
|
|
6
|
+
* Precedence for every value: explicit start() option, then FIREWEAVE_* env,
|
|
7
|
+
* then the legacy FW_* name (one warning), then the default. Reads are lazy:
|
|
8
|
+
* a source is read only if every earlier source was unset, so an explicit
|
|
9
|
+
* option never touches the environment (which matters on Deno).
|
|
10
|
+
*/
|
|
11
|
+
import { FireweaveError, assertHostAllowed } from '../index.js';
|
|
12
|
+
import { quiet } from './env.js';
|
|
13
|
+
import { normalizeControlPoints } from './control-points.js';
|
|
14
|
+
import { CHANNEL_URLS, DEV_ENVIRONMENTS, ENV, ENVIRONMENT_FALLBACKS, LEGACY_ENV, LOOPBACK_HOSTS, RETIRED_ENVIRONMENT_NAME, } from './names.js';
|
|
15
|
+
const configError = (message) => new FireweaveError('Configuration', { message });
|
|
16
|
+
const optionString = (value, name) => {
|
|
17
|
+
if (value === undefined || value === null)
|
|
18
|
+
return undefined;
|
|
19
|
+
if (typeof value !== 'string')
|
|
20
|
+
throw configError(`[fireweave] start({ ${name} }) must be a string.`);
|
|
21
|
+
const trimmed = value.trim();
|
|
22
|
+
return trimmed === '' ? undefined : trimmed;
|
|
23
|
+
};
|
|
24
|
+
/** First non-empty of: the option, then each env name in order. */
|
|
25
|
+
function pick(option, optionName, names, legacy, read, warnings, replacement) {
|
|
26
|
+
if (option !== undefined)
|
|
27
|
+
return { value: option, source: `start({ ${optionName} })` };
|
|
28
|
+
for (const name of names) {
|
|
29
|
+
const value = read(name);
|
|
30
|
+
if (value !== undefined)
|
|
31
|
+
return { value, source: name };
|
|
32
|
+
}
|
|
33
|
+
for (const name of legacy) {
|
|
34
|
+
const value = read(name);
|
|
35
|
+
if (value !== undefined) {
|
|
36
|
+
warnings.push(`[fireweave] ${name} is a legacy name and will stop being read in 3.0.0. Rename it to ${replacement}; the value does not change.`);
|
|
37
|
+
return { value, source: name };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Key family check, before any request. Messages name the source, never the
|
|
44
|
+
* value. The redactor masks analytics-vendor prefixes, so the message says
|
|
45
|
+
* "analytics vendor key" instead of quoting one.
|
|
46
|
+
*/
|
|
47
|
+
function checkKeyFamily(key, source) {
|
|
48
|
+
if (key.startsWith('fw_public_')) {
|
|
49
|
+
throw configError(`[fireweave] The key from ${source} is a browser key (fw_public_…). Server apps need a project key (project-api-key_…) from Project settings, API keys.`);
|
|
50
|
+
}
|
|
51
|
+
if (/^ph[a-z]_/.test(key)) {
|
|
52
|
+
throw configError(`[fireweave] The key from ${source} is an analytics vendor key, not a FireWeave project key. Use the project key (project-api-key_…).`);
|
|
53
|
+
}
|
|
54
|
+
if (key.startsWith('fw_org_') || key.startsWith('cli_at_')) {
|
|
55
|
+
throw configError(`[fireweave] The key from ${source} is an organisation or CLI token, not a project key. Use the project key (project-api-key_…).`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function resolveUrl(input, read, build, warnings) {
|
|
59
|
+
const picked = pick(optionString(input.url, 'url'), 'url', [ENV.url], LEGACY_ENV.url, read, warnings, ENV.url);
|
|
60
|
+
if (picked === undefined) {
|
|
61
|
+
// The channel host is in DEFAULT_ALLOWED_HOSTS, so no custom allowlist.
|
|
62
|
+
return { url: CHANNEL_URLS[build.channel], urlSource: `SDK channel (${build.channel})` };
|
|
63
|
+
}
|
|
64
|
+
const url = picked.value.replace(/\/+$/, '');
|
|
65
|
+
let hostname;
|
|
66
|
+
try {
|
|
67
|
+
hostname = new URL(url).hostname;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw configError(`[fireweave] The endpoint from ${picked.source} is not a valid URL.`);
|
|
71
|
+
}
|
|
72
|
+
const allowedHosts = [hostname.replace(/^\[|\]$/g, ''), ...LOOPBACK_HOSTS];
|
|
73
|
+
try {
|
|
74
|
+
assertHostAllowed(url, allowedHosts);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
throw configError(`[fireweave] The endpoint from ${picked.source} must use https (http is allowed only for localhost).`);
|
|
78
|
+
}
|
|
79
|
+
return { url, urlSource: picked.source, allowedHosts };
|
|
80
|
+
}
|
|
81
|
+
function resolveKey(input, read, warnings) {
|
|
82
|
+
const picked = pick(optionString(input.key, 'key'), 'key', [ENV.key], LEGACY_ENV.key, read, warnings, ENV.key);
|
|
83
|
+
if (picked !== undefined)
|
|
84
|
+
checkKeyFamily(picked.value, picked.source);
|
|
85
|
+
return picked;
|
|
86
|
+
}
|
|
87
|
+
function resolveEnvironment(input, read) {
|
|
88
|
+
return pick(optionString(input.environment, 'environment'), 'environment', [ENV.environment, ...ENVIRONMENT_FALLBACKS], [], read, [], ENV.environment);
|
|
89
|
+
}
|
|
90
|
+
function noKeyError(env, read) {
|
|
91
|
+
const where = env === undefined
|
|
92
|
+
? 'no environment name is set (checked the environment option, FIREWEAVE_ENV, APP_ENV and NODE_ENV)'
|
|
93
|
+
: `the environment is '${env.value}' (from ${env.source}), which is not a development name`;
|
|
94
|
+
const retired = env === undefined && quiet(read)(RETIRED_ENVIRONMENT_NAME) !== undefined
|
|
95
|
+
? ` FW_ENV is no longer read; rename it to FIREWEAVE_ENV.`
|
|
96
|
+
: '';
|
|
97
|
+
return configError(`[fireweave] ${ENV.key} is not set and ${where}. Set ${ENV.key} to the project's server key, or for local development set FIREWEAVE_ENV=development or call start({ mode: 'local' }).${retired}`);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Resolve start() options against the environment.
|
|
101
|
+
* Throws FireweaveError('Configuration') naming the variable at fault.
|
|
102
|
+
*/
|
|
103
|
+
export function resolveStart(input, read, build) {
|
|
104
|
+
const warnings = [];
|
|
105
|
+
const controlPoints = normalizeControlPoints(input.controlPoints);
|
|
106
|
+
const base = { controlPoints, channel: build.channel, sdkVersion: build.version };
|
|
107
|
+
if (input.mode !== undefined && input.mode !== 'remote' && input.mode !== 'local') {
|
|
108
|
+
throw configError(`[fireweave] start({ mode }) must be 'remote' or 'local'.`);
|
|
109
|
+
}
|
|
110
|
+
if (input.mode === 'local') {
|
|
111
|
+
// The key is ignored. Look only to warn, and never fail on a refused read.
|
|
112
|
+
const ignored = resolveKeyQuietly(input, read);
|
|
113
|
+
if (ignored !== undefined) {
|
|
114
|
+
warnings.push(`[fireweave] start({ mode: 'local' }) ignores the key from ${ignored}; nothing is sent to fw-server.`);
|
|
115
|
+
}
|
|
116
|
+
return { ...base, mode: 'local', modeSource: 'option', keySource: 'none', warnings };
|
|
117
|
+
}
|
|
118
|
+
const key = resolveKey(input, read, warnings);
|
|
119
|
+
if (input.mode === 'remote') {
|
|
120
|
+
if (key === undefined) {
|
|
121
|
+
throw configError(`[fireweave] start({ mode: 'remote' }) needs a key. Set ${ENV.key} or pass start({ key }).`);
|
|
122
|
+
}
|
|
123
|
+
return { ...base, mode: 'remote', modeSource: 'option', ...resolveUrl(input, read, build, warnings), key: key.value, keySource: key.source, warnings };
|
|
124
|
+
}
|
|
125
|
+
if (key !== undefined) {
|
|
126
|
+
return { ...base, mode: 'remote', modeSource: 'key', ...resolveUrl(input, read, build, warnings), key: key.value, keySource: key.source, warnings };
|
|
127
|
+
}
|
|
128
|
+
const env = resolveEnvironment(input, read);
|
|
129
|
+
if (env !== undefined && DEV_ENVIRONMENTS.has(env.value.toLowerCase())) {
|
|
130
|
+
return {
|
|
131
|
+
...base,
|
|
132
|
+
mode: 'local',
|
|
133
|
+
modeSource: 'environment',
|
|
134
|
+
keySource: 'none',
|
|
135
|
+
environment: env.value,
|
|
136
|
+
environmentSource: env.source,
|
|
137
|
+
warnings,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
throw noKeyError(env, read);
|
|
141
|
+
}
|
|
142
|
+
function resolveKeyQuietly(input, read) {
|
|
143
|
+
if (typeof input.key === 'string' && input.key.trim() !== '')
|
|
144
|
+
return 'start({ key })';
|
|
145
|
+
const safe = quiet(read);
|
|
146
|
+
for (const name of [ENV.key, ...LEGACY_ENV.key]) {
|
|
147
|
+
if (safe(name) !== undefined)
|
|
148
|
+
return name;
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/start/res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AQ,EAAE,CAAC;IACtJ,CAAC;IAED,MAAM,GAAG,GAAG,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,IAAI,GAAG,KAAK,SAAS,IAAI,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QACvE,OAAO;YACL,GAAG,IAAI;YACP,IAAI,EAAE,OAAO;YACb,UAAU,EAAE,aAAa;YACzB,SAAS,EAAE,MAAM;YACjB,WAAW,EAAE,GAAG,CAAC,KAAK;YACtB,iBAAiB,EAAE,GAAG,CAAC,MAAM;YAC7B,QAAQ;SACT,CAAC;IACJ,CAAC;IACD,MAAM,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAmB,EAAE,IAAe;IAC7D,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,gBAAgB,CAAC;IACtF,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAChD,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;IAC5C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* start() and the process-wide singleton behind `fw`.
|
|
3
|
+
*
|
|
4
|
+
* One slot per process (or worker thread) at a Symbol.for key on globalThis,
|
|
5
|
+
* so two bundled copies of this package share one client. start() is
|
|
6
|
+
* synchronous: it resolves and validates everything up front, throws a
|
|
7
|
+
* Configuration error for bad config, then hands off to the unchanged core
|
|
8
|
+
* initFireweave(). Reads await readiness and never throw.
|
|
9
|
+
*
|
|
10
|
+
* A read that happens before any start() schedules an env-only start on the
|
|
11
|
+
* next macrotask. An ES module graph without top-level await evaluates in one
|
|
12
|
+
* job, so an entrypoint that imports ./fireweave/start first always wins.
|
|
13
|
+
*/
|
|
14
|
+
import { FireweaveError, type FireweaveClient, type FireweaveErrorKind, type FireweaveRemoteAdapterOptions } from '../index.js';
|
|
15
|
+
import { type EnvReader } from './env.js';
|
|
16
|
+
import { type ControlPointMap } from './control-points.js';
|
|
17
|
+
import { type InstanceKey } from './instance.js';
|
|
18
|
+
import { type ResolvedStart, type SdkChannel, type StartMode } from './resolve.js';
|
|
19
|
+
export interface StartOptions {
|
|
20
|
+
/** Control points and their local values; import from src/fireweave/control-points.ts. */
|
|
21
|
+
readonly controlPoints?: ControlPointMap;
|
|
22
|
+
/** Force a mode. Without it: a key means remote; no key means local only in a dev environment. */
|
|
23
|
+
readonly mode?: StartMode;
|
|
24
|
+
/** Environment name used to infer the mode, instead of FIREWEAVE_ENV, APP_ENV or NODE_ENV. */
|
|
25
|
+
readonly environment?: string;
|
|
26
|
+
/** fw-server URL. Default: FIREWEAVE_URL, else this SDK build's channel host. */
|
|
27
|
+
readonly url?: string;
|
|
28
|
+
/** Project key (project-api-key_…). Default: FIREWEAVE_KEY. */
|
|
29
|
+
readonly key?: string;
|
|
30
|
+
/** Stable id for this process in server-subject reads. Default: FIREWEAVE_INSTANCE_ID, else the host. */
|
|
31
|
+
readonly instanceId?: string;
|
|
32
|
+
/** Read these values instead of the process environment (tests, Workers bindings). */
|
|
33
|
+
readonly env?: Readonly<Record<string, unknown>>;
|
|
34
|
+
/** Where [fireweave] lines go. Default: console. Not part of the idempotency check. */
|
|
35
|
+
readonly log?: (line: string) => void;
|
|
36
|
+
/** Transport override for tests. Not part of the idempotency check. */
|
|
37
|
+
readonly fetch?: FireweaveRemoteAdapterOptions['fetch'];
|
|
38
|
+
}
|
|
39
|
+
export type StartState = 'unstarted' | 'starting' | 'ready' | 'failed' | 'shutdown';
|
|
40
|
+
export interface FireweaveStatus {
|
|
41
|
+
readonly state: StartState;
|
|
42
|
+
readonly mode?: StartMode;
|
|
43
|
+
readonly modeSource?: ResolvedStart['modeSource'];
|
|
44
|
+
readonly channel: SdkChannel;
|
|
45
|
+
readonly sdkVersion: string;
|
|
46
|
+
/** fw-server host name only: never a path or a credential. */
|
|
47
|
+
readonly host?: string;
|
|
48
|
+
readonly endpointSource?: string;
|
|
49
|
+
readonly keySource?: string;
|
|
50
|
+
readonly environment?: string;
|
|
51
|
+
readonly controlPointCount?: number;
|
|
52
|
+
/** Why start failed, when it did. Already redacted. */
|
|
53
|
+
readonly error?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The kind of the latest failed fw-server request (Authentication,
|
|
56
|
+
* Authorization, RateLimited, Network, Timeout or BackendUnavailable).
|
|
57
|
+
* Sticky: a later success does not clear it; a fresh start() does.
|
|
58
|
+
*/
|
|
59
|
+
readonly lastErrorKind?: FireweaveErrorKind;
|
|
60
|
+
}
|
|
61
|
+
interface Deferred<T> {
|
|
62
|
+
readonly promise: Promise<T>;
|
|
63
|
+
readonly resolve: (value: T | PromiseLike<T>) => void;
|
|
64
|
+
}
|
|
65
|
+
interface Slot {
|
|
66
|
+
readonly protocol: 1;
|
|
67
|
+
state: StartState;
|
|
68
|
+
signature?: string;
|
|
69
|
+
implicit: boolean;
|
|
70
|
+
resolved?: ResolvedStart;
|
|
71
|
+
ready: Deferred<FireweaveClient | undefined>;
|
|
72
|
+
client?: FireweaveClient | undefined;
|
|
73
|
+
error?: FireweaveError;
|
|
74
|
+
implicitScheduled: boolean;
|
|
75
|
+
read?: EnvReader;
|
|
76
|
+
instanceIdOption?: string;
|
|
77
|
+
instance?: InstanceKey;
|
|
78
|
+
log: (line: string) => void;
|
|
79
|
+
readonly warned: Set<string>;
|
|
80
|
+
lastErrorKind?: FireweaveErrorKind;
|
|
81
|
+
/** fw-server failure groups already logged; one line each for the life of the process. */
|
|
82
|
+
readonly diagnosed: Set<string>;
|
|
83
|
+
}
|
|
84
|
+
export declare function slot(): Slot;
|
|
85
|
+
export declare function warnOnce(s: Slot, line: string): void;
|
|
86
|
+
/** Start FireWeave for this process. Synchronous; call once, from src/fireweave/start.ts. */
|
|
87
|
+
export declare function start(options?: StartOptions): void;
|
|
88
|
+
export declare function startWith(options: StartOptions, implicit: boolean): void;
|
|
89
|
+
/** The client once start() settles; undefined when start failed. Schedules an implicit start if none ran. */
|
|
90
|
+
export declare function ensureClient(): Promise<FireweaveClient | undefined>;
|
|
91
|
+
export declare function currentStatus(): FireweaveStatus;
|
|
92
|
+
export declare function instanceKeyFor(): string;
|
|
93
|
+
export declare function shutdownSlot(): Promise<void>;
|
|
94
|
+
/** Test only: shut down and forget the singleton so the next start() begins fresh. */
|
|
95
|
+
export declare function resetForTests(): Promise<void>;
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/start/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,cAAc,EAId,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,6BAA6B,EAEnC,MAAM,aAAa,CAAC;AAErB,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAgB,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAEjG,MAAM,WAAW,YAAY;IAC3B,0FAA0F;IAC1F,QAAQ,CAAC,aAAa,CAAC,EAAE,eAAe,CAAC;IACzC,kGAAkG;IAClG,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B,8FAA8F;IAC9F,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