@framers/agentos 0.15.71 → 0.15.72
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/.github/badges/tests.json +1 -1
- package/dist/api/generateText.d.ts.map +1 -1
- package/dist/api/generateText.js +28 -64
- package/dist/api/generateText.js.map +1 -1
- package/dist/api/runtime/responseFormatForProvider.d.ts +2 -3
- package/dist/api/runtime/responseFormatForProvider.d.ts.map +1 -1
- package/dist/api/runtime/responseFormatForProvider.js +2 -3
- package/dist/api/runtime/responseFormatForProvider.js.map +1 -1
- package/dist/api/server/AgentOSServer.d.ts +9 -0
- package/dist/api/server/AgentOSServer.d.ts.map +1 -1
- package/dist/api/server/AgentOSServer.js +92 -6
- package/dist/api/server/AgentOSServer.js.map +1 -1
- package/dist/api/streamText.d.ts.map +1 -1
- package/dist/api/streamText.js +26 -56
- package/dist/api/streamText.js.map +1 -1
- package/dist/core/llm/providers/AIModelProviderManager.d.ts +5 -5
- package/dist/core/llm/providers/AIModelProviderManager.d.ts.map +1 -1
- package/dist/core/llm/providers/AIModelProviderManager.js +11 -14
- package/dist/core/llm/providers/AIModelProviderManager.js.map +1 -1
- package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts +7 -6
- package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts.map +1 -1
- package/dist/core/llm/providers/implementations/OpenAIProvider.js +39 -54
- package/dist/core/llm/providers/implementations/OpenAIProvider.js.map +1 -1
- package/dist/core/llm/providers/implementations/OpenRouterProvider.d.ts.map +1 -1
- package/dist/core/llm/providers/implementations/OpenRouterProvider.js +20 -30
- package/dist/core/llm/providers/implementations/OpenRouterProvider.js.map +1 -1
- package/dist/core/logging/ILogger.d.ts +12 -0
- package/dist/core/logging/ILogger.d.ts.map +1 -1
- package/dist/core/logging/ILogger.js +5 -0
- package/dist/core/logging/ILogger.js.map +1 -1
- package/dist/core/logging/Logger.d.ts +52 -0
- package/dist/core/logging/Logger.d.ts.map +1 -0
- package/dist/core/logging/Logger.js +11 -0
- package/dist/core/logging/Logger.js.map +1 -0
- package/dist/core/logging/PinoLogger.d.ts +24 -2
- package/dist/core/logging/PinoLogger.d.ts.map +1 -1
- package/dist/core/logging/PinoLogger.js +39 -3
- package/dist/core/logging/PinoLogger.js.map +1 -1
- package/dist/core/logging/contentSafeTelemetry.d.ts +1 -1
- package/dist/core/logging/contentSafeTelemetry.d.ts.map +1 -1
- package/dist/core/logging/contentSafeTelemetry.js +1 -1
- package/dist/core/logging/contentSafeTelemetry.js.map +1 -1
- package/dist/core/logging/events.d.ts +349 -0
- package/dist/core/logging/events.d.ts.map +1 -0
- package/dist/core/logging/events.js +164 -0
- package/dist/core/logging/events.js.map +1 -0
- package/dist/core/logging/forward.d.ts +93 -0
- package/dist/core/logging/forward.d.ts.map +1 -0
- package/dist/core/logging/forward.js +167 -0
- package/dist/core/logging/forward.js.map +1 -0
- package/dist/core/logging/index.d.ts +8 -3
- package/dist/core/logging/index.d.ts.map +1 -1
- package/dist/core/logging/index.js +7 -3
- package/dist/core/logging/index.js.map +1 -1
- package/dist/core/logging/kit/allowList.d.ts +68 -0
- package/dist/core/logging/kit/allowList.d.ts.map +1 -0
- package/dist/core/logging/kit/allowList.js +219 -0
- package/dist/core/logging/kit/allowList.js.map +1 -0
- package/dist/core/logging/kit/burst.d.ts +38 -0
- package/dist/core/logging/kit/burst.d.ts.map +1 -0
- package/dist/core/logging/kit/burst.js +91 -0
- package/dist/core/logging/kit/burst.js.map +1 -0
- package/dist/core/logging/kit/consoleCapture.d.ts +47 -0
- package/dist/core/logging/kit/consoleCapture.d.ts.map +1 -0
- package/dist/core/logging/kit/consoleCapture.js +121 -0
- package/dist/core/logging/kit/consoleCapture.js.map +1 -0
- package/dist/core/logging/kit/index.d.ts +12 -0
- package/dist/core/logging/kit/index.d.ts.map +1 -0
- package/dist/core/logging/kit/index.js +12 -0
- package/dist/core/logging/kit/index.js.map +1 -0
- package/dist/core/logging/kit/processHandlers.d.ts +48 -0
- package/dist/core/logging/kit/processHandlers.d.ts.map +1 -0
- package/dist/core/logging/kit/processHandlers.js +77 -0
- package/dist/core/logging/kit/processHandlers.js.map +1 -0
- package/dist/core/logging/level.d.ts +33 -0
- package/dist/core/logging/level.d.ts.map +1 -0
- package/dist/core/logging/level.js +36 -0
- package/dist/core/logging/level.js.map +1 -0
- package/dist/core/logging/loggerFactory.d.ts +74 -15
- package/dist/core/logging/loggerFactory.d.ts.map +1 -1
- package/dist/core/logging/loggerFactory.js +138 -18
- package/dist/core/logging/loggerFactory.js.map +1 -1
- package/dist/core/logging/state.d.ts +77 -0
- package/dist/core/logging/state.d.ts.map +1 -0
- package/dist/core/logging/state.js +25 -0
- package/dist/core/logging/state.js.map +1 -0
- package/dist/core/utils/terminal.d.ts +22 -0
- package/dist/core/utils/terminal.d.ts.map +1 -0
- package/dist/core/utils/terminal.js +27 -0
- package/dist/core/utils/terminal.js.map +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Opt-in process handlers: the shutdown line and the process's last line.
|
|
3
|
+
*
|
|
4
|
+
* AgentOS never installs these. A host with handlers of its own calls the kit's `terminal()`
|
|
5
|
+
* from them instead.
|
|
6
|
+
*
|
|
7
|
+
* @module agentos/core/logging/kit/processHandlers
|
|
8
|
+
*/
|
|
9
|
+
import { errorFields } from '../events.js';
|
|
10
|
+
import { getLoggingState } from '../state.js';
|
|
11
|
+
/**
|
|
12
|
+
* Installs handlers for SIGTERM, SIGINT, uncaught exceptions and unhandled rejections.
|
|
13
|
+
*
|
|
14
|
+
* - On SIGTERM or SIGINT, the first signal writes `process.shutdown` with the signal, then
|
|
15
|
+
* calls `onShutdown`, which owns closing the host's servers and pools and ending the
|
|
16
|
+
* process. A later signal is ignored.
|
|
17
|
+
* - On an uncaught exception or an unhandled rejection, or when `onShutdown` fails, it writes
|
|
18
|
+
* `process.uncaught` with the error's type and code through `terminal()`, which bypasses the
|
|
19
|
+
* burst budget at `fatal`, then calls `onFatal`, which exits with status 1 unless the host
|
|
20
|
+
* gives its own.
|
|
21
|
+
*
|
|
22
|
+
* Installing is idempotent across every copy of AgentOS in the process: while the handlers are
|
|
23
|
+
* installed, a second call returns the first call's remover and installs nothing.
|
|
24
|
+
*
|
|
25
|
+
* @param kit - The kit the lines are written through.
|
|
26
|
+
* @param options - The host's callbacks.
|
|
27
|
+
* @param options.onShutdown - Called once, after the shutdown line, with the signal.
|
|
28
|
+
* @param options.onFatal - Called after the last line with the error; `process.exit(1)` unless given.
|
|
29
|
+
* @returns A function that removes every handler it installed.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* installProcessHandlers(kit, { onShutdown: async () => { await server.close(); process.exit(0); } });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function installProcessHandlers(kit, options) {
|
|
37
|
+
const state = getLoggingState();
|
|
38
|
+
if (state.removeProcessHandlers)
|
|
39
|
+
return state.removeProcessHandlers;
|
|
40
|
+
let ending = false;
|
|
41
|
+
const fatal = (error) => {
|
|
42
|
+
try {
|
|
43
|
+
kit.terminal('process.uncaught', errorFields(error));
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
(options.onFatal ?? (() => process.exit(1)))(error);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const shutdown = (signal) => {
|
|
50
|
+
if (ending)
|
|
51
|
+
return;
|
|
52
|
+
ending = true;
|
|
53
|
+
try {
|
|
54
|
+
kit.info('process.shutdown', { signal });
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
Promise.resolve().then(() => options.onShutdown(signal)).catch(fatal);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const term = () => shutdown('SIGTERM');
|
|
61
|
+
const interrupt = () => shutdown('SIGINT');
|
|
62
|
+
process.on('SIGTERM', term);
|
|
63
|
+
process.on('SIGINT', interrupt);
|
|
64
|
+
process.on('uncaughtException', fatal);
|
|
65
|
+
process.on('unhandledRejection', fatal);
|
|
66
|
+
const remove = () => {
|
|
67
|
+
process.off('SIGTERM', term);
|
|
68
|
+
process.off('SIGINT', interrupt);
|
|
69
|
+
process.off('uncaughtException', fatal);
|
|
70
|
+
process.off('unhandledRejection', fatal);
|
|
71
|
+
if (state.removeProcessHandlers === remove)
|
|
72
|
+
state.removeProcessHandlers = undefined;
|
|
73
|
+
};
|
|
74
|
+
state.removeProcessHandlers = remove;
|
|
75
|
+
return remove;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=processHandlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processHandlers.js","sourceRoot":"","sources":["../../../../src/core/logging/kit/processHandlers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAQ9C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAe,EAAE,OAGvD;IACC,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAChC,IAAI,KAAK,CAAC,qBAAqB;QAAE,OAAO,KAAK,CAAC,qBAAqB,CAAC;IACpE,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,EAAE;QAC/B,IAAI,CAAC;YAAC,GAAG,CAAC,QAAQ,CAAC,kBAAkB,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;QAAC,CAAC;gBACrD,CAAC;YAAC,CAAC,OAAO,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAAC,CAAC;IAClE,CAAC,CAAC;IACF,MAAM,QAAQ,GAAG,CAAC,MAA4B,EAAE,EAAE;QAChD,IAAI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|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The level of AgentOS's default logger, read from the environment.
|
|
3
|
+
*
|
|
4
|
+
* @module agentos/core/logging/level
|
|
5
|
+
*/
|
|
6
|
+
/** The level names pino takes, from the most verbose to the least, then `silent`. */
|
|
7
|
+
declare const LEVELS: readonly ["trace", "debug", "info", "warn", "error", "fatal", "silent"];
|
|
8
|
+
/**
|
|
9
|
+
* Reads the default logger's level from the environment.
|
|
10
|
+
*
|
|
11
|
+
* `AGENTOS_LOG_LEVEL` names the level, in any case. A value that is not a level name gives
|
|
12
|
+
* `info` with `unknown` set, and the caller writes one `logging.level_unknown` line, which
|
|
13
|
+
* never repeats the value. When `AGENTOS_LOG_LEVEL` is unset or names a level,
|
|
14
|
+
* `AGENTOS_DEBUG=1` or `AGENTOS_DEBUG=true` gives `debug`, as the providers' start-up checks
|
|
15
|
+
* read them. With neither set the level is `info`.
|
|
16
|
+
*
|
|
17
|
+
* @param env - The environment to read, usually `process.env`.
|
|
18
|
+
* @returns The level, and whether `AGENTOS_LOG_LEVEL` held a value that is not a level name.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* parseLogLevel({ AGENTOS_LOG_LEVEL: 'warn' }); // { level: 'warn', unknown: false }
|
|
23
|
+
* parseLogLevel({ AGENTOS_LOG_LEVEL: 'DEBUG' }); // { level: 'debug', unknown: false }
|
|
24
|
+
* parseLogLevel({ AGENTOS_LOG_LEVEL: 'loud' }); // { level: 'info', unknown: true }
|
|
25
|
+
* parseLogLevel({ AGENTOS_DEBUG: 'true' }); // { level: 'debug', unknown: false }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseLogLevel(env: Record<string, string | undefined>): {
|
|
29
|
+
level: (typeof LEVELS)[number];
|
|
30
|
+
unknown: boolean;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=level.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level.d.ts","sourceRoot":"","sources":["../../../src/core/logging/level.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qFAAqF;AACrF,QAAA,MAAM,MAAM,yEAA0E,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG;IACtE,KAAK,EAAE,CAAC,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;CAClD,CAKA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The level of AgentOS's default logger, read from the environment.
|
|
3
|
+
*
|
|
4
|
+
* @module agentos/core/logging/level
|
|
5
|
+
*/
|
|
6
|
+
/** The level names pino takes, from the most verbose to the least, then `silent`. */
|
|
7
|
+
const LEVELS = ['trace', 'debug', 'info', 'warn', 'error', 'fatal', 'silent'];
|
|
8
|
+
/**
|
|
9
|
+
* Reads the default logger's level from the environment.
|
|
10
|
+
*
|
|
11
|
+
* `AGENTOS_LOG_LEVEL` names the level, in any case. A value that is not a level name gives
|
|
12
|
+
* `info` with `unknown` set, and the caller writes one `logging.level_unknown` line, which
|
|
13
|
+
* never repeats the value. When `AGENTOS_LOG_LEVEL` is unset or names a level,
|
|
14
|
+
* `AGENTOS_DEBUG=1` or `AGENTOS_DEBUG=true` gives `debug`, as the providers' start-up checks
|
|
15
|
+
* read them. With neither set the level is `info`.
|
|
16
|
+
*
|
|
17
|
+
* @param env - The environment to read, usually `process.env`.
|
|
18
|
+
* @returns The level, and whether `AGENTOS_LOG_LEVEL` held a value that is not a level name.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* parseLogLevel({ AGENTOS_LOG_LEVEL: 'warn' }); // { level: 'warn', unknown: false }
|
|
23
|
+
* parseLogLevel({ AGENTOS_LOG_LEVEL: 'DEBUG' }); // { level: 'debug', unknown: false }
|
|
24
|
+
* parseLogLevel({ AGENTOS_LOG_LEVEL: 'loud' }); // { level: 'info', unknown: true }
|
|
25
|
+
* parseLogLevel({ AGENTOS_DEBUG: 'true' }); // { level: 'debug', unknown: false }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function parseLogLevel(env) {
|
|
29
|
+
const value = env.AGENTOS_LOG_LEVEL?.toLowerCase();
|
|
30
|
+
if (value && !LEVELS.includes(value))
|
|
31
|
+
return { level: 'info', unknown: true };
|
|
32
|
+
if (env.AGENTOS_DEBUG === '1' || env.AGENTOS_DEBUG === 'true')
|
|
33
|
+
return { level: 'debug', unknown: false };
|
|
34
|
+
return { level: (value || 'info'), unknown: false };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=level.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level.js","sourceRoot":"","sources":["../../../src/core/logging/level.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qFAAqF;AACrF,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,aAAa,CAAC,GAAuC;IAGnE,MAAM,KAAK,GAAG,GAAG,CAAC,iBAAiB,EAAE,WAAW,EAAE,CAAC;IACnD,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAgC,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACzG,IAAI,GAAG,CAAC,aAAa,KAAK,GAAG,IAAI,GAAG,CAAC,aAAa,KAAK,MAAM;QAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACzG,OAAO,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,MAAM,CAA4B,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACjF,CAAC"}
|
|
@@ -1,31 +1,90 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* @fileoverview How a host hands AgentOS its logger, the handles AgentOS writes through, and the
|
|
3
|
+
* guard that keeps every logger `createLogger` hands out inside content-safe telemetry.
|
|
4
|
+
*
|
|
5
|
+
* `setLogger` takes a pino-shaped logger, `setLoggerFactory` takes a factory of `ILogger`s,
|
|
6
|
+
* `setLogger(null)` silences AgentOS, and `resetLoggerFactory` returns to the default pino
|
|
7
|
+
* root, which is built on its first use. The last setter wins. `createLogger` calls the
|
|
8
|
+
* current factory at once and returns a guard over that factory's object: its calls reach the
|
|
9
|
+
* object until content-safe telemetry is enabled, and from then on each becomes one fixed
|
|
10
|
+
* event, even on a logger made earlier. `lazyLogger` returns a typed handle that reads the
|
|
11
|
+
* current target at each write, and so do its children; while content-safe telemetry is on,
|
|
12
|
+
* each of their lines is one fixed event as well.
|
|
13
|
+
*
|
|
14
|
+
* @module agentos/core/logging/loggerFactory
|
|
5
15
|
*/
|
|
6
16
|
import type { ILogger } from './ILogger.js';
|
|
17
|
+
import type { Logger, EventLogger } from './Logger.js';
|
|
18
|
+
import type { AgentOSEvents, AgentOSContext } from './events.js';
|
|
19
|
+
import { type LoggerFactory } from './state.js';
|
|
20
|
+
import { type ContentSafeLogComponent } from './contentSafeTelemetry.js';
|
|
21
|
+
export type { LoggerFactory } from './state.js';
|
|
7
22
|
/**
|
|
8
|
-
*
|
|
23
|
+
* Hands AgentOS a pino-shaped logger, or silences it with `null`. Lazy handles, whenever they
|
|
24
|
+
* were made, write to it from their next line; an object `createLogger` returned earlier keeps
|
|
25
|
+
* its target.
|
|
26
|
+
*
|
|
27
|
+
* @param logger - A logger with `debug`, `info`, `warn`, `error`, `fatal` and `child`, such as a pino logger or a pino child, or `null` to write nothing.
|
|
28
|
+
* @throws {TypeError} When one of those methods is missing, naming it.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import pino from 'pino';
|
|
33
|
+
* setLogger(pino());
|
|
34
|
+
* ```
|
|
9
35
|
*/
|
|
10
|
-
export
|
|
36
|
+
export declare function setLogger(logger: Logger | null): void;
|
|
11
37
|
/**
|
|
12
|
-
*
|
|
38
|
+
* Hands AgentOS a factory of `ILogger`s. `createLogger` calls it at once. A lazy handle calls
|
|
39
|
+
* it at each write with its component and context, and writes `(event, fields)` to the logger
|
|
40
|
+
* it returns.
|
|
13
41
|
*
|
|
14
|
-
* @param factory -
|
|
42
|
+
* @param factory - The factory.
|
|
15
43
|
*/
|
|
16
44
|
export declare function setLoggerFactory(factory: LoggerFactory): void;
|
|
17
|
-
/**
|
|
18
|
-
* Restores the default factory: children of a new root `PinoLogger` named `agentos`.
|
|
19
|
-
*/
|
|
45
|
+
/** Returns AgentOS to its default pino root, which is built again on its next use. */
|
|
20
46
|
export declare function resetLoggerFactory(): void;
|
|
21
47
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
48
|
+
* Returns a component's logger: a guard over the logger the current target gives. With a factory
|
|
49
|
+
* set, it calls the factory at once; otherwise it takes a child of the default root, or an
|
|
50
|
+
* adapter over the logger or the silence set now, and that logger keeps its target after a later
|
|
51
|
+
* setter. The guard's calls reach that logger, with the caller's arguments, until content-safe
|
|
52
|
+
* telemetry is enabled; from then on each call becomes one fixed event for the host's sink, even
|
|
53
|
+
* on a logger made earlier, and `child` returns the same logger. While the mode is on, the
|
|
54
|
+
* factory is not called and nothing is made.
|
|
25
55
|
*
|
|
26
|
-
* @param name - The component name.
|
|
27
|
-
* @param bindings -
|
|
56
|
+
* @param name - The component's name.
|
|
57
|
+
* @param bindings - Bindings for every line the logger writes.
|
|
28
58
|
* @returns The component's logger.
|
|
29
59
|
*/
|
|
30
60
|
export declare function createLogger(name: string, bindings?: Record<string, any>): ILogger;
|
|
61
|
+
/**
|
|
62
|
+
* Returns a typed handle that reads the current target at each write, so a handle made at
|
|
63
|
+
* import follows a later `setLogger` or `setLoggerFactory`; its children do the same. Its
|
|
64
|
+
* methods take only an event `AGENTOS_EVENTS` declares, with that event's fields.
|
|
65
|
+
*
|
|
66
|
+
* @param component - The component the lines come from.
|
|
67
|
+
* @param context - More context keys to bind, such as `extension`.
|
|
68
|
+
* @returns The handle.
|
|
69
|
+
* @throws {LogValidationError} Under `NODE_ENV=test`, when the component or the context breaks AgentOS's context schema; otherwise such a handle writes one `log_refused` line and then nothing.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const log = lazyLogger('OpenAIProvider');
|
|
74
|
+
* log.warn('llm.retry', { provider: 'openai', status: 429, attempt: 1, waitMs: 2000 });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function lazyLogger(component: string, context?: AgentOSContext): EventLogger<AgentOSEvents>;
|
|
78
|
+
/**
|
|
79
|
+
* The handle an AgentOS module writes through: a {@link lazyLogger} handle whose lines, while
|
|
80
|
+
* content-safe telemetry is on, each reach the sink as one fixed event naming the module, as
|
|
81
|
+
* the module's console lines do. An origin outside `CONTENT_SAFE_COMPONENTS` reads as
|
|
82
|
+
* `library`.
|
|
83
|
+
*
|
|
84
|
+
* @param component - The component the lines come from.
|
|
85
|
+
* @param origin - The module's fixed word in `CONTENT_SAFE_COMPONENTS`.
|
|
86
|
+
* @returns The handle.
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
export declare function moduleLogger(component: string, origin: ContentSafeLogComponent): EventLogger<AgentOSEvents>;
|
|
31
90
|
//# sourceMappingURL=loggerFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loggerFactory.d.ts","sourceRoot":"","sources":["../../../src/core/logging/loggerFactory.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loggerFactory.d.ts","sourceRoot":"","sources":["../../../src/core/logging/loggerFactory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAS,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,EAAmB,KAAK,aAAa,EAAe,MAAM,YAAY,CAAC;AAE9E,OAAO,EAAqD,KAAK,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAC5H,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAOrD;AAkCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAA6D;AAE3H,sFAAsF;AACtF,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AA4BD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAMlF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,WAAW,CAAC,aAAa,CAAC,CAEtG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,GAAG,WAAW,CAAC,aAAa,CAAC,CAE3G"}
|
|
@@ -1,10 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview How a host hands AgentOS its logger, the handles AgentOS writes through, and the
|
|
3
|
+
* guard that keeps every logger `createLogger` hands out inside content-safe telemetry.
|
|
4
|
+
*
|
|
5
|
+
* `setLogger` takes a pino-shaped logger, `setLoggerFactory` takes a factory of `ILogger`s,
|
|
6
|
+
* `setLogger(null)` silences AgentOS, and `resetLoggerFactory` returns to the default pino
|
|
7
|
+
* root, which is built on its first use. The last setter wins. `createLogger` calls the
|
|
8
|
+
* current factory at once and returns a guard over that factory's object: its calls reach the
|
|
9
|
+
* object until content-safe telemetry is enabled, and from then on each becomes one fixed
|
|
10
|
+
* event, even on a logger made earlier. `lazyLogger` returns a typed handle that reads the
|
|
11
|
+
* current target at each write, and so do its children; while content-safe telemetry is on,
|
|
12
|
+
* each of their lines is one fixed event as well.
|
|
13
|
+
*
|
|
14
|
+
* @module agentos/core/logging/loggerFactory
|
|
15
|
+
*/
|
|
16
|
+
import { AGENTOS_CONTEXT } from './events.js';
|
|
17
|
+
import { getLoggingState } from './state.js';
|
|
18
|
+
import { checkContext, defaultRoot, forward, isValidationError } from './forward.js';
|
|
2
19
|
import { emitContentSafeLog, isContentSafeTelemetryEnabled } from './contentSafeTelemetry.js';
|
|
3
|
-
|
|
4
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Hands AgentOS a pino-shaped logger, or silences it with `null`. Lazy handles, whenever they
|
|
22
|
+
* were made, write to it from their next line; an object `createLogger` returned earlier keeps
|
|
23
|
+
* its target.
|
|
24
|
+
*
|
|
25
|
+
* @param logger - A logger with `debug`, `info`, `warn`, `error`, `fatal` and `child`, such as a pino logger or a pino child, or `null` to write nothing.
|
|
26
|
+
* @throws {TypeError} When one of those methods is missing, naming it.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import pino from 'pino';
|
|
31
|
+
* setLogger(pino());
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function setLogger(logger) {
|
|
35
|
+
if (logger !== null) {
|
|
36
|
+
for (const name of ['debug', 'info', 'warn', 'error', 'fatal', 'child']) {
|
|
37
|
+
if (typeof logger?.[name] !== 'function')
|
|
38
|
+
throw new TypeError(`Logger.${name} must be a function`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
getLoggingState().target = logger === null ? { mode: 'silent' } : { mode: 'logger', logger };
|
|
42
|
+
}
|
|
5
43
|
/**
|
|
6
44
|
* Wraps `raw` so each call is checked against content-safe telemetry when it is made. While the mode is off, a call
|
|
7
|
-
* goes to `raw` with the caller's own arguments
|
|
45
|
+
* goes to `raw` with the caller's own arguments, a `fatal` call to `raw.error` when `raw` has no `fatal`; while it is
|
|
46
|
+
* on, it becomes one fixed event and `raw` is not called.
|
|
8
47
|
*/
|
|
9
48
|
function guarded(raw) {
|
|
10
49
|
const logger = {
|
|
@@ -24,6 +63,14 @@ function guarded(raw) {
|
|
|
24
63
|
if (!emitContentSafeLog('debug', 'logger_factory'))
|
|
25
64
|
raw?.debug?.(...args);
|
|
26
65
|
},
|
|
66
|
+
fatal(...args) {
|
|
67
|
+
if (emitContentSafeLog('error', 'logger_factory'))
|
|
68
|
+
return;
|
|
69
|
+
if (raw?.fatal)
|
|
70
|
+
raw.fatal(...args);
|
|
71
|
+
else
|
|
72
|
+
raw?.error(...args);
|
|
73
|
+
},
|
|
27
74
|
child(bindings) {
|
|
28
75
|
if (isContentSafeTelemetryEnabled())
|
|
29
76
|
return logger;
|
|
@@ -33,30 +80,103 @@ function guarded(raw) {
|
|
|
33
80
|
return logger;
|
|
34
81
|
}
|
|
35
82
|
/**
|
|
36
|
-
*
|
|
83
|
+
* Hands AgentOS a factory of `ILogger`s. `createLogger` calls it at once. A lazy handle calls
|
|
84
|
+
* it at each write with its component and context, and writes `(event, fields)` to the logger
|
|
85
|
+
* it returns.
|
|
37
86
|
*
|
|
38
|
-
* @param factory -
|
|
39
|
-
*/
|
|
40
|
-
export function setLoggerFactory(factory) { currentFactory = factory; }
|
|
41
|
-
/**
|
|
42
|
-
* Restores the default factory: children of a new root `PinoLogger` named `agentos`.
|
|
87
|
+
* @param factory - The factory.
|
|
43
88
|
*/
|
|
89
|
+
export function setLoggerFactory(factory) { getLoggingState().target = { mode: 'factory', factory }; }
|
|
90
|
+
/** Returns AgentOS to its default pino root, which is built again on its next use. */
|
|
44
91
|
export function resetLoggerFactory() {
|
|
45
|
-
|
|
46
|
-
|
|
92
|
+
const state = getLoggingState();
|
|
93
|
+
state.target = { mode: 'default' };
|
|
94
|
+
state.root = undefined;
|
|
95
|
+
}
|
|
96
|
+
// An ILogger over the target `target()` returns at each write. A child merges its bindings onto its parent's. With
|
|
97
|
+
// `strict` they are checked against AgentOS's context schema before the child is made: a child whose bindings fail
|
|
98
|
+
// writes one `log_refused` line and then nothing, and under NODE_ENV=test the failure is thrown instead. While
|
|
99
|
+
// content-safe telemetry is on, each line, a child's included, is one fixed event naming `origin`.
|
|
100
|
+
function adapter(target, bindings, strict, disabled = false, origin = 'library') {
|
|
101
|
+
const write = (level) => (event, fields = {}) => {
|
|
102
|
+
if (!disabled)
|
|
103
|
+
forward(target(), level, event, fields, bindings, strict, origin);
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
debug: write('debug'), info: write('info'), warn: write('warn'), error: write('error'), fatal: write('fatal'),
|
|
107
|
+
child(child) {
|
|
108
|
+
const merged = { ...bindings, ...child };
|
|
109
|
+
if (strict) {
|
|
110
|
+
try {
|
|
111
|
+
checkContext(AGENTOS_CONTEXT, merged);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
if (!isValidationError(error))
|
|
115
|
+
throw error;
|
|
116
|
+
if (process.env.NODE_ENV === 'test')
|
|
117
|
+
throw error;
|
|
118
|
+
forward(target(), 'warn', 'log_refused', { reason: 'bad_context' }, {}, false, origin);
|
|
119
|
+
return adapter(target, {}, strict, true, origin);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return adapter(target, merged, strict, disabled, origin);
|
|
123
|
+
},
|
|
124
|
+
};
|
|
47
125
|
}
|
|
48
126
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
127
|
+
* Returns a component's logger: a guard over the logger the current target gives. With a factory
|
|
128
|
+
* set, it calls the factory at once; otherwise it takes a child of the default root, or an
|
|
129
|
+
* adapter over the logger or the silence set now, and that logger keeps its target after a later
|
|
130
|
+
* setter. The guard's calls reach that logger, with the caller's arguments, until content-safe
|
|
131
|
+
* telemetry is enabled; from then on each call becomes one fixed event for the host's sink, even
|
|
132
|
+
* on a logger made earlier, and `child` returns the same logger. While the mode is on, the
|
|
133
|
+
* factory is not called and nothing is made.
|
|
52
134
|
*
|
|
53
|
-
* @param name - The component name.
|
|
54
|
-
* @param bindings -
|
|
135
|
+
* @param name - The component's name.
|
|
136
|
+
* @param bindings - Bindings for every line the logger writes.
|
|
55
137
|
* @returns The component's logger.
|
|
56
138
|
*/
|
|
57
139
|
export function createLogger(name, bindings) {
|
|
58
140
|
if (isContentSafeTelemetryEnabled())
|
|
59
141
|
return guarded();
|
|
60
|
-
|
|
142
|
+
const target = getLoggingState().target;
|
|
143
|
+
if (target.mode === 'factory')
|
|
144
|
+
return guarded(target.factory(name, bindings));
|
|
145
|
+
if (target.mode === 'default')
|
|
146
|
+
return guarded(defaultRoot().child({ component: name, ...bindings }));
|
|
147
|
+
return guarded(adapter(() => target, { component: name, ...bindings }, false));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Returns a typed handle that reads the current target at each write, so a handle made at
|
|
151
|
+
* import follows a later `setLogger` or `setLoggerFactory`; its children do the same. Its
|
|
152
|
+
* methods take only an event `AGENTOS_EVENTS` declares, with that event's fields.
|
|
153
|
+
*
|
|
154
|
+
* @param component - The component the lines come from.
|
|
155
|
+
* @param context - More context keys to bind, such as `extension`.
|
|
156
|
+
* @returns The handle.
|
|
157
|
+
* @throws {LogValidationError} Under `NODE_ENV=test`, when the component or the context breaks AgentOS's context schema; otherwise such a handle writes one `log_refused` line and then nothing.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const log = lazyLogger('OpenAIProvider');
|
|
162
|
+
* log.warn('llm.retry', { provider: 'openai', status: 429, attempt: 1, waitMs: 2000 });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export function lazyLogger(component, context = {}) {
|
|
166
|
+
return adapter(() => getLoggingState().target, {}, true).child({ component, ...context });
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The handle an AgentOS module writes through: a {@link lazyLogger} handle whose lines, while
|
|
170
|
+
* content-safe telemetry is on, each reach the sink as one fixed event naming the module, as
|
|
171
|
+
* the module's console lines do. An origin outside `CONTENT_SAFE_COMPONENTS` reads as
|
|
172
|
+
* `library`.
|
|
173
|
+
*
|
|
174
|
+
* @param component - The component the lines come from.
|
|
175
|
+
* @param origin - The module's fixed word in `CONTENT_SAFE_COMPONENTS`.
|
|
176
|
+
* @returns The handle.
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
export function moduleLogger(component, origin) {
|
|
180
|
+
return adapter(() => getLoggingState().target, {}, true, false, origin).child({ component });
|
|
61
181
|
}
|
|
62
182
|
//# sourceMappingURL=loggerFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loggerFactory.js","sourceRoot":"","sources":["../../../src/core/logging/loggerFactory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loggerFactory.js","sourceRoot":"","sources":["../../../src/core/logging/loggerFactory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAmC,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAgC,MAAM,2BAA2B,CAAC;AA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AAG,eAAe,EAAE,CAAC,MAAM,CAAC;IACxC,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9E,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC;IACrG,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;AACjF,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CAAC,SAAiB,EAAE,UAA0B,EAAE;IACxE,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,KAAM,CAAC,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAA+B,CAAC;AAC3H,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB,EAAE,MAA+B;IAC7E,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,KAAM,CAAC,EAAE,SAAS,EAAE,CAA+B,CAAC;AAC9H,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The one logging state every copy of AgentOS in a process shares.
|
|
3
|
+
*
|
|
4
|
+
* The state lives on `globalThis` under `Symbol.for('agentos.logging.state.v1')`, so a
|
|
5
|
+
* product and a pack's nested install of AgentOS obey one hand-over. The `v1` in the key
|
|
6
|
+
* changes only when the state's shape does.
|
|
7
|
+
*
|
|
8
|
+
* @module agentos/core/logging/state
|
|
9
|
+
*/
|
|
10
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
11
|
+
import type { ILogger } from './ILogger.js';
|
|
12
|
+
import type { Logger } from './Logger.js';
|
|
13
|
+
import type { PinoLogger } from './PinoLogger.js';
|
|
14
|
+
/** A host's factory: called with a component's name and its bindings, it returns that component's logger. */
|
|
15
|
+
export type LoggerFactory = (name: string, bindings?: Record<string, any>) => ILogger;
|
|
16
|
+
/**
|
|
17
|
+
* Where AgentOS's lines go: the lazy default root, a logger from `setLogger`, a factory from
|
|
18
|
+
* `setLoggerFactory`, or nowhere after `setLogger(null)`.
|
|
19
|
+
*/
|
|
20
|
+
export type Target = {
|
|
21
|
+
mode: 'default';
|
|
22
|
+
} | {
|
|
23
|
+
mode: 'silent';
|
|
24
|
+
} | {
|
|
25
|
+
mode: 'logger';
|
|
26
|
+
logger: Logger;
|
|
27
|
+
} | {
|
|
28
|
+
mode: 'factory';
|
|
29
|
+
factory: LoggerFactory;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* One burst budget for the current minute, kept for an event or a refusal reason and shared by
|
|
33
|
+
* every kit instance in the process.
|
|
34
|
+
*/
|
|
35
|
+
export interface Minute {
|
|
36
|
+
/** When the minute began, in milliseconds since the epoch. */
|
|
37
|
+
start: number;
|
|
38
|
+
/** Lines written in this minute. */
|
|
39
|
+
written: number;
|
|
40
|
+
/** Lines held back in this minute, reported in one line when the minute ends. */
|
|
41
|
+
held: number;
|
|
42
|
+
/** The smallest bound any kit asked for in this minute. */
|
|
43
|
+
limit: number;
|
|
44
|
+
/** The kit that opened the budget, whose writer reports the held lines. */
|
|
45
|
+
owner: symbol;
|
|
46
|
+
/** The event or the refusal reason the held-lines report names. */
|
|
47
|
+
name: string;
|
|
48
|
+
}
|
|
49
|
+
/** The process-wide logging state. */
|
|
50
|
+
export interface LoggingState {
|
|
51
|
+
/** Where lines go now. The last setter wins. */
|
|
52
|
+
target: Target;
|
|
53
|
+
/** The default pino root, built on its first use and dropped by `resetLoggerFactory`. */
|
|
54
|
+
root?: PinoLogger;
|
|
55
|
+
/** Whether the line about an unknown `AGENTOS_LOG_LEVEL` has been written; it is written once. */
|
|
56
|
+
levelWarned: boolean;
|
|
57
|
+
/** The current request's id, which the forwarding layer adds to each line's context. */
|
|
58
|
+
requests: AsyncLocalStorage<{
|
|
59
|
+
requestId: string;
|
|
60
|
+
}>;
|
|
61
|
+
/** The burst budgets of the current minute, by key. */
|
|
62
|
+
minutes: Map<string, Minute>;
|
|
63
|
+
/** Each open kit's writer for its held-lines reports. */
|
|
64
|
+
owners: Map<symbol, (name: string, n: number) => void>;
|
|
65
|
+
/** The unreferenced timer that reports held lines when a minute ends. */
|
|
66
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
67
|
+
/** Removes the installed process handlers, when a kit has installed them. */
|
|
68
|
+
removeProcessHandlers?: () => void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The process's logging state, created on the first call. Every copy of AgentOS in the
|
|
72
|
+
* process reads the same object.
|
|
73
|
+
*
|
|
74
|
+
* @returns The shared state.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getLoggingState(): LoggingState;
|
|
77
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/core/logging/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,6GAA6G;AAC7G,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM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;IAC7E,qBAAqB,CAAC,EAAE,MAAM,IAAI,CAAC;CACpC;AAGD;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAM9C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The one logging state every copy of AgentOS in a process shares.
|
|
3
|
+
*
|
|
4
|
+
* The state lives on `globalThis` under `Symbol.for('agentos.logging.state.v1')`, so a
|
|
5
|
+
* product and a pack's nested install of AgentOS obey one hand-over. The `v1` in the key
|
|
6
|
+
* changes only when the state's shape does.
|
|
7
|
+
*
|
|
8
|
+
* @module agentos/core/logging/state
|
|
9
|
+
*/
|
|
10
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
11
|
+
const KEY = Symbol.for('agentos.logging.state.v1');
|
|
12
|
+
/**
|
|
13
|
+
* The process's logging state, created on the first call. Every copy of AgentOS in the
|
|
14
|
+
* process reads the same object.
|
|
15
|
+
*
|
|
16
|
+
* @returns The shared state.
|
|
17
|
+
*/
|
|
18
|
+
export function getLoggingState() {
|
|
19
|
+
const holder = globalThis;
|
|
20
|
+
return holder[KEY] ?? (holder[KEY] = {
|
|
21
|
+
target: { mode: 'default' }, levelWarned: false,
|
|
22
|
+
requests: new AsyncLocalStorage(), minutes: new Map(), owners: new Map(),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/core/logging/state.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAoDrD,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,UAAiE,CAAC;IACjF,OAAO,MAAM,CAAC,GAAG,MAAV,MAAM,CAAC,GAAG,IAAM;QACrB,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,WAAW,EAAE,KAAK;QAC/C,QAAQ,EAAE,IAAI,iBAAiB,EAAE,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE;KACzE,EAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The one module allowed to write the standard streams directly.
|
|
3
|
+
*
|
|
4
|
+
* AgentOS's lines go through the logging hand-over; text meant for a person at a terminal, such
|
|
5
|
+
* as an interactive prompt or the frames-only stack the allow-list kit's console capture
|
|
6
|
+
* prints, goes through {@link terminal}.
|
|
7
|
+
*
|
|
8
|
+
* @module agentos/core/utils/terminal
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Writes text to standard output or standard error. A failing stream never reaches the caller.
|
|
12
|
+
*
|
|
13
|
+
* @param text - The text to write, as it should appear, with its own line ending.
|
|
14
|
+
* @param stream - The stream to write to, `stdout` unless given.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* terminal('Continue? [y/N] ');
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function terminal(text: string, stream?: 'stdout' | 'stderr'): void;
|
|
22
|
+
//# sourceMappingURL=terminal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../../src/core/utils/terminal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,QAAQ,GAAG,QAAmB,GAAG,IAAI,CAEnF"}
|