@framers/agentos 0.15.70 → 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.
Files changed (103) hide show
  1. package/.github/badges/tests.json +1 -1
  2. package/dist/api/generateText.d.ts.map +1 -1
  3. package/dist/api/generateText.js +28 -64
  4. package/dist/api/generateText.js.map +1 -1
  5. package/dist/api/runtime/ExternalToolResultHandler.d.ts.map +1 -1
  6. package/dist/api/runtime/ExternalToolResultHandler.js +9 -2
  7. package/dist/api/runtime/ExternalToolResultHandler.js.map +1 -1
  8. package/dist/api/runtime/responseFormatForProvider.d.ts +2 -3
  9. package/dist/api/runtime/responseFormatForProvider.d.ts.map +1 -1
  10. package/dist/api/runtime/responseFormatForProvider.js +2 -3
  11. package/dist/api/runtime/responseFormatForProvider.js.map +1 -1
  12. package/dist/api/server/AgentOSServer.d.ts +9 -0
  13. package/dist/api/server/AgentOSServer.d.ts.map +1 -1
  14. package/dist/api/server/AgentOSServer.js +92 -6
  15. package/dist/api/server/AgentOSServer.js.map +1 -1
  16. package/dist/api/streamText.d.ts.map +1 -1
  17. package/dist/api/streamText.js +26 -56
  18. package/dist/api/streamText.js.map +1 -1
  19. package/dist/api/types/AgentOSInput.d.ts +6 -0
  20. package/dist/api/types/AgentOSInput.d.ts.map +1 -1
  21. package/dist/cognition/substrate/GMI.d.ts +12 -0
  22. package/dist/cognition/substrate/GMI.d.ts.map +1 -1
  23. package/dist/cognition/substrate/GMI.js +71 -11
  24. package/dist/cognition/substrate/GMI.js.map +1 -1
  25. package/dist/cognition/substrate/IGMI.d.ts +8 -0
  26. package/dist/cognition/substrate/IGMI.d.ts.map +1 -1
  27. package/dist/cognition/substrate/IGMI.js.map +1 -1
  28. package/dist/core/llm/providers/AIModelProviderManager.d.ts +5 -5
  29. package/dist/core/llm/providers/AIModelProviderManager.d.ts.map +1 -1
  30. package/dist/core/llm/providers/AIModelProviderManager.js +11 -14
  31. package/dist/core/llm/providers/AIModelProviderManager.js.map +1 -1
  32. package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts +7 -6
  33. package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts.map +1 -1
  34. package/dist/core/llm/providers/implementations/OpenAIProvider.js +39 -54
  35. package/dist/core/llm/providers/implementations/OpenAIProvider.js.map +1 -1
  36. package/dist/core/llm/providers/implementations/OpenRouterProvider.d.ts.map +1 -1
  37. package/dist/core/llm/providers/implementations/OpenRouterProvider.js +20 -30
  38. package/dist/core/llm/providers/implementations/OpenRouterProvider.js.map +1 -1
  39. package/dist/core/logging/ILogger.d.ts +12 -0
  40. package/dist/core/logging/ILogger.d.ts.map +1 -1
  41. package/dist/core/logging/ILogger.js +5 -0
  42. package/dist/core/logging/ILogger.js.map +1 -1
  43. package/dist/core/logging/Logger.d.ts +52 -0
  44. package/dist/core/logging/Logger.d.ts.map +1 -0
  45. package/dist/core/logging/Logger.js +11 -0
  46. package/dist/core/logging/Logger.js.map +1 -0
  47. package/dist/core/logging/PinoLogger.d.ts +24 -2
  48. package/dist/core/logging/PinoLogger.d.ts.map +1 -1
  49. package/dist/core/logging/PinoLogger.js +39 -3
  50. package/dist/core/logging/PinoLogger.js.map +1 -1
  51. package/dist/core/logging/contentSafeTelemetry.d.ts +1 -1
  52. package/dist/core/logging/contentSafeTelemetry.d.ts.map +1 -1
  53. package/dist/core/logging/contentSafeTelemetry.js +1 -1
  54. package/dist/core/logging/contentSafeTelemetry.js.map +1 -1
  55. package/dist/core/logging/events.d.ts +349 -0
  56. package/dist/core/logging/events.d.ts.map +1 -0
  57. package/dist/core/logging/events.js +164 -0
  58. package/dist/core/logging/events.js.map +1 -0
  59. package/dist/core/logging/forward.d.ts +93 -0
  60. package/dist/core/logging/forward.d.ts.map +1 -0
  61. package/dist/core/logging/forward.js +167 -0
  62. package/dist/core/logging/forward.js.map +1 -0
  63. package/dist/core/logging/index.d.ts +8 -3
  64. package/dist/core/logging/index.d.ts.map +1 -1
  65. package/dist/core/logging/index.js +7 -3
  66. package/dist/core/logging/index.js.map +1 -1
  67. package/dist/core/logging/kit/allowList.d.ts +68 -0
  68. package/dist/core/logging/kit/allowList.d.ts.map +1 -0
  69. package/dist/core/logging/kit/allowList.js +219 -0
  70. package/dist/core/logging/kit/allowList.js.map +1 -0
  71. package/dist/core/logging/kit/burst.d.ts +38 -0
  72. package/dist/core/logging/kit/burst.d.ts.map +1 -0
  73. package/dist/core/logging/kit/burst.js +91 -0
  74. package/dist/core/logging/kit/burst.js.map +1 -0
  75. package/dist/core/logging/kit/consoleCapture.d.ts +47 -0
  76. package/dist/core/logging/kit/consoleCapture.d.ts.map +1 -0
  77. package/dist/core/logging/kit/consoleCapture.js +121 -0
  78. package/dist/core/logging/kit/consoleCapture.js.map +1 -0
  79. package/dist/core/logging/kit/index.d.ts +12 -0
  80. package/dist/core/logging/kit/index.d.ts.map +1 -0
  81. package/dist/core/logging/kit/index.js +12 -0
  82. package/dist/core/logging/kit/index.js.map +1 -0
  83. package/dist/core/logging/kit/processHandlers.d.ts +48 -0
  84. package/dist/core/logging/kit/processHandlers.d.ts.map +1 -0
  85. package/dist/core/logging/kit/processHandlers.js +77 -0
  86. package/dist/core/logging/kit/processHandlers.js.map +1 -0
  87. package/dist/core/logging/level.d.ts +33 -0
  88. package/dist/core/logging/level.d.ts.map +1 -0
  89. package/dist/core/logging/level.js +36 -0
  90. package/dist/core/logging/level.js.map +1 -0
  91. package/dist/core/logging/loggerFactory.d.ts +74 -15
  92. package/dist/core/logging/loggerFactory.d.ts.map +1 -1
  93. package/dist/core/logging/loggerFactory.js +138 -18
  94. package/dist/core/logging/loggerFactory.js.map +1 -1
  95. package/dist/core/logging/state.d.ts +77 -0
  96. package/dist/core/logging/state.d.ts.map +1 -0
  97. package/dist/core/logging/state.js +25 -0
  98. package/dist/core/logging/state.js.map +1 -0
  99. package/dist/core/utils/terminal.d.ts +22 -0
  100. package/dist/core/utils/terminal.d.ts.map +1 -0
  101. package/dist/core/utils/terminal.js +27 -0
  102. package/dist/core/utils/terminal.js.map +1 -0
  103. package/package.json +6 -1
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @fileoverview The burst budgets every allow-list kit in the process shares.
3
+ *
4
+ * Each declared event, and each refusal reason, writes the first `limit` lines of a minute;
5
+ * the rest are held, and once the minute has turned one `log_held` line gives the name and
6
+ * the count held. The budgets live in the process-wide logging state, so every kit instance,
7
+ * child, adapter and lazy handle that writes through a kit counts against the same minute.
8
+ * The timer that reports held lines is unreferenced, so it never holds the process open, and
9
+ * closing the last kit clears it with the counters.
10
+ *
11
+ * @module agentos/core/logging/kit/burst
12
+ */
13
+ import { getLoggingState } from '../state.js';
14
+ // Ends every minute that has turned and reports what it held through the writer of the kit that opened it, or,
15
+ // when that kit has closed, through any kit still open.
16
+ function flush() {
17
+ const state = getLoggingState();
18
+ const now = Date.now();
19
+ for (const [key, minute] of state.minutes) {
20
+ if (now - minute.start < 60000)
21
+ continue;
22
+ state.minutes.delete(key);
23
+ const emit = state.owners.get(minute.owner) ?? state.owners.values().next().value;
24
+ if (minute.held)
25
+ emit?.(minute.name, minute.held);
26
+ }
27
+ }
28
+ // Keeps one unreferenced timer for the earliest minute that holds lines, and none when no minute holds any or no
29
+ // kit is open to report it.
30
+ function schedule() {
31
+ const state = getLoggingState();
32
+ if (state.timer)
33
+ clearTimeout(state.timer);
34
+ state.timer = undefined;
35
+ const ends = [...state.minutes.values()].filter(m => m.held > 0).map(m => m.start + 60000);
36
+ if (!ends.length || !state.owners.size)
37
+ return;
38
+ const delay = Math.min(60000, Math.max(0, Math.min(...ends) - Date.now()));
39
+ state.timer = setTimeout(() => { state.timer = undefined; flush(); schedule(); }, delay);
40
+ state.timer.unref();
41
+ }
42
+ /**
43
+ * Registers a kit as an owner of burst budgets.
44
+ *
45
+ * @param emit - Writes the kit's `log_held` line: the event or refusal reason held, and how many lines were held.
46
+ * @returns The owner's key, which {@link admit} and {@link closeOwner} take.
47
+ */
48
+ export function burstOwner(emit) {
49
+ const owner = Symbol();
50
+ getLoggingState().owners.set(owner, emit);
51
+ return owner;
52
+ }
53
+ /**
54
+ * Counts one line against its minute's budget. A budget's bound is the smallest any kit asked
55
+ * for in that minute.
56
+ *
57
+ * @param owner - The kit writing the line; a minute it opens reports its held lines through it.
58
+ * @param key - The budget's key, built from a declared event's name or a fixed refusal reason, so the keys are finite.
59
+ * @param name - The event's name or the refusal reason, as the `log_held` line gives it.
60
+ * @param limit - The kit's bound on lines a minute.
61
+ * @returns `true` when the line may be written, `false` when it is held.
62
+ */
63
+ export function admit(owner, key, name, limit) {
64
+ const state = getLoggingState();
65
+ flush();
66
+ const minute = state.minutes.get(key) ?? { start: Date.now(), written: 0, held: 0, limit, owner, name };
67
+ minute.limit = Math.min(minute.limit, limit);
68
+ state.minutes.set(key, minute);
69
+ if (minute.written < minute.limit) {
70
+ minute.written++;
71
+ schedule();
72
+ return true;
73
+ }
74
+ minute.held++;
75
+ schedule();
76
+ return false;
77
+ }
78
+ /**
79
+ * Removes a kit from the owners. A minute it opened still reports through a kit that remains
80
+ * open; when no kit remains, the counters and the timer are cleared.
81
+ *
82
+ * @param owner - The key {@link burstOwner} returned.
83
+ */
84
+ export function closeOwner(owner) {
85
+ const state = getLoggingState();
86
+ state.owners.delete(owner);
87
+ if (!state.owners.size)
88
+ state.minutes.clear();
89
+ schedule();
90
+ }
91
+ //# sourceMappingURL=burst.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"burst.js","sourceRoot":"","sources":["../../../../src/core/logging/kit/burst.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,+GAA+G;AAC/G,wDAAwD;AACxD,SAAS,KAAK;IACZ,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAAC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACxD,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,E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AC,KAAa;IACtC,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI;QAAE,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC9C,QAAQ,EAAE,CAAC;AACb,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @fileoverview Console capture: each console call becomes one content-free `console_line`
3
+ * event.
4
+ *
5
+ * The event carries the console method and, when one of the values is an error, its type and
6
+ * code. The text is never written. For an error, the frames of its stack after the exact
7
+ * opening (its name, `: ` and its message) go to standard error through the terminal writer,
8
+ * so an operator sees where it was thrown; a stack that opens any other way gives no frames,
9
+ * since a value inside a message could be shaped like a frame. Only lines with a frame's form
10
+ * (`at ` after the indent) are written, at most 50, and a line over 512 characters or holding
11
+ * a control or direction character is left out, so a stack set by hand cannot put text or
12
+ * terminal sequences on standard error. An error whose properties throw when read gives the
13
+ * event with `unknown` fields and no frames, and the console call does not throw.
14
+ *
15
+ * @module agentos/core/logging/kit/consoleCapture
16
+ */
17
+ /**
18
+ * What console capture writes through: the `warn` method of an allow-list kit whose map
19
+ * declares AgentOS's `console_line` event.
20
+ */
21
+ export interface ConsoleKit {
22
+ warn(event: 'console_line', fields: {
23
+ method: (typeof METHODS)[number];
24
+ type?: string;
25
+ code?: string;
26
+ }): void;
27
+ }
28
+ declare const METHODS: readonly ["debug", "info", "log", "warn", "error", "trace", "dir", "table", "assert", "count", "countReset", "time", "timeEnd", "timeLog", "group", "groupCollapsed", "groupEnd", "clear", "dirxml", "profile", "profileEnd", "timeStamp"];
29
+ /**
30
+ * Replaces each console method with one that writes a `console_line` event through the kit.
31
+ * Capturing is idempotent across every copy of AgentOS in the process: a second call returns
32
+ * the first call's restore function and changes nothing. A console call made while a captured
33
+ * call is being written is dropped.
34
+ *
35
+ * @param kit - The kit the events are written through.
36
+ * @returns A function that puts the original console methods back.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const restore = captureConsole(kit);
41
+ * console.error(new Error('text that is never written')); // one console_line line: method, type, code
42
+ * restore();
43
+ * ```
44
+ */
45
+ export declare function captureConsole(kit: ConsoleKit): () => void;
46
+ export {};
47
+ //# sourceMappingURL=consoleCapture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consoleCapture.d.ts","sourceRoot":"","sources":["../../../../src/core/logging/kit/consoleCapture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH;;;GAGG;AACH,MAAM,WAAW,UAAU;IAAG,IAAI,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE;QAAE,MAAM,EAAE,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE;AAC7I,QAAA,MAAM,OAAO,4OAA6O,CAAC;AA6C3P;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,IAAI,CAyB1D"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * @fileoverview Console capture: each console call becomes one content-free `console_line`
3
+ * event.
4
+ *
5
+ * The event carries the console method and, when one of the values is an error, its type and
6
+ * code. The text is never written. For an error, the frames of its stack after the exact
7
+ * opening (its name, `: ` and its message) go to standard error through the terminal writer,
8
+ * so an operator sees where it was thrown; a stack that opens any other way gives no frames,
9
+ * since a value inside a message could be shaped like a frame. Only lines with a frame's form
10
+ * (`at ` after the indent) are written, at most 50, and a line over 512 characters or holding
11
+ * a control or direction character is left out, so a stack set by hand cannot put text or
12
+ * terminal sequences on standard error. An error whose properties throw when read gives the
13
+ * event with `unknown` fields and no frames, and the console call does not throw.
14
+ *
15
+ * @module agentos/core/logging/kit/consoleCapture
16
+ */
17
+ import { errorFields } from '../events.js';
18
+ import { terminal } from '../../utils/terminal.js';
19
+ const METHODS = ['debug', 'info', 'log', 'warn', 'error', 'trace', 'dir', 'table', 'assert', 'count', 'countReset', 'time', 'timeEnd', 'timeLog', 'group', 'groupCollapsed', 'groupEnd', 'clear', 'dirxml', 'profile', 'profileEnd', 'timeStamp'];
20
+ // The restore function of the capture in place, shared by every copy of AgentOS in the process.
21
+ const KEY = Symbol.for('agentos.logging.console.v1');
22
+ // A frame line, and the bounds on the frames written.
23
+ const FRAME = /^ +at \S/;
24
+ const MAX_FRAMES = 50;
25
+ const MAX_FRAME_LENGTH = 512;
26
+ // Whether a line holds a C0 or C1 control, DEL, or a direction mark or override. A loop, not a regular
27
+ // expression, since eslint's no-control-regex refuses control characters in one.
28
+ function unsafe(line) {
29
+ for (let index = 0; index < line.length; index += 1) {
30
+ const code = line.charCodeAt(index);
31
+ if (code < 0x20 || (code >= 0x7f && code <= 0x9f) || code === 0x200e || code === 0x200f
32
+ || (code >= 0x202a && code <= 0x202e) || (code >= 0x2066 && code <= 0x2069))
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+ // The first value that is an error; a value whose prototype throws when read is passed over.
38
+ function firstError(values) {
39
+ for (const value of values) {
40
+ try {
41
+ if (value instanceof Error)
42
+ return value;
43
+ }
44
+ catch { /* Not an error that can be read. */ }
45
+ }
46
+ return undefined;
47
+ }
48
+ // The frame lines of an error's stack after its exact opening, bounded, or '' when there are none or reading fails.
49
+ function framesOf(error) {
50
+ try {
51
+ const stack = error.stack;
52
+ if (typeof stack !== 'string')
53
+ return '';
54
+ const message = error.message;
55
+ for (const name of [error.name, 'Error']) {
56
+ const opening = `${name}: ${message}\n`;
57
+ if (!stack.startsWith(opening))
58
+ continue;
59
+ const lines = stack.slice(opening.length).split('\n')
60
+ .filter(line => line.length <= MAX_FRAME_LENGTH && FRAME.test(line) && !unsafe(line))
61
+ .slice(0, MAX_FRAMES);
62
+ return lines.length ? `${lines.join('\n')}\n` : '';
63
+ }
64
+ return '';
65
+ }
66
+ catch {
67
+ return '';
68
+ }
69
+ }
70
+ /**
71
+ * Replaces each console method with one that writes a `console_line` event through the kit.
72
+ * Capturing is idempotent across every copy of AgentOS in the process: a second call returns
73
+ * the first call's restore function and changes nothing. A console call made while a captured
74
+ * call is being written is dropped.
75
+ *
76
+ * @param kit - The kit the events are written through.
77
+ * @returns A function that puts the original console methods back.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const restore = captureConsole(kit);
82
+ * console.error(new Error('text that is never written')); // one console_line line: method, type, code
83
+ * restore();
84
+ * ```
85
+ */
86
+ export function captureConsole(kit) {
87
+ const holder = globalThis;
88
+ if (holder[KEY])
89
+ return holder[KEY];
90
+ const target = console;
91
+ const originals = new Map();
92
+ let writing = false;
93
+ for (const method of METHODS) {
94
+ if (typeof target[method] !== 'function')
95
+ continue;
96
+ originals.set(method, target[method]);
97
+ target[method] = (...values) => {
98
+ if (writing)
99
+ return;
100
+ writing = true;
101
+ try {
102
+ const error = firstError(values);
103
+ kit.warn('console_line', { method, ...(error ? errorFields(error) : {}) });
104
+ const frames = error ? framesOf(error) : '';
105
+ if (frames)
106
+ terminal(frames, 'stderr');
107
+ }
108
+ finally {
109
+ writing = false;
110
+ }
111
+ };
112
+ }
113
+ const restore = () => {
114
+ for (const [method, original] of originals)
115
+ target[method] = original;
116
+ delete holder[KEY];
117
+ };
118
+ holder[KEY] = restore;
119
+ return restore;
120
+ }
121
+ //# sourceMappingURL=consoleCapture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consoleCapture.js","sourceRoot":"","sources":["../../../../src/core/logging/kit/consoleCapture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAOnD,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO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 +1,12 @@
1
+ /**
2
+ * @fileoverview The allow-list kit: a typed logger over a product's event map with fixed
3
+ * refusal reasons and burst budgets shared across the process, console capture, and opt-in
4
+ * process handlers.
5
+ *
6
+ * @module agentos/core/logging/kit
7
+ */
8
+ export { createAllowListLogger, type AllowListLogger } from './allowList.js';
9
+ export { captureConsole } from './consoleCapture.js';
10
+ export { installProcessHandlers } from './processHandlers.js';
11
+ export { LogValidationError } from '../forward.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/logging/kit/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,qBAAqB,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileoverview The allow-list kit: a typed logger over a product's event map with fixed
3
+ * refusal reasons and burst budgets shared across the process, console capture, and opt-in
4
+ * process handlers.
5
+ *
6
+ * @module agentos/core/logging/kit
7
+ */
8
+ export { createAllowListLogger } from './allowList.js';
9
+ export { captureConsole } from './consoleCapture.js';
10
+ export { installProcessHandlers } from './processHandlers.js';
11
+ export { LogValidationError } from '../forward.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/logging/kit/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,qBAAqB,EAAwB,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,48 @@
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
+ /** What the process handlers write through: an allow-list kit whose map declares AgentOS's process events. */
10
+ export interface ProcessKit {
11
+ info(event: 'process.shutdown', fields: {
12
+ signal: 'SIGTERM' | 'SIGINT';
13
+ }): void;
14
+ terminal(event: 'process.uncaught', fields: {
15
+ type: string;
16
+ code: string;
17
+ }): void;
18
+ }
19
+ /**
20
+ * Installs handlers for SIGTERM, SIGINT, uncaught exceptions and unhandled rejections.
21
+ *
22
+ * - On SIGTERM or SIGINT, the first signal writes `process.shutdown` with the signal, then
23
+ * calls `onShutdown`, which owns closing the host's servers and pools and ending the
24
+ * process. A later signal is ignored.
25
+ * - On an uncaught exception or an unhandled rejection, or when `onShutdown` fails, it writes
26
+ * `process.uncaught` with the error's type and code through `terminal()`, which bypasses the
27
+ * burst budget at `fatal`, then calls `onFatal`, which exits with status 1 unless the host
28
+ * gives its own.
29
+ *
30
+ * Installing is idempotent across every copy of AgentOS in the process: while the handlers are
31
+ * installed, a second call returns the first call's remover and installs nothing.
32
+ *
33
+ * @param kit - The kit the lines are written through.
34
+ * @param options - The host's callbacks.
35
+ * @param options.onShutdown - Called once, after the shutdown line, with the signal.
36
+ * @param options.onFatal - Called after the last line with the error; `process.exit(1)` unless given.
37
+ * @returns A function that removes every handler it installed.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * installProcessHandlers(kit, { onShutdown: async () => { await server.close(); process.exit(0); } });
42
+ * ```
43
+ */
44
+ export declare function installProcessHandlers(kit: ProcessKit, options: {
45
+ onShutdown: (signal: 'SIGTERM' | 'SIGINT') => void | Promise<void>;
46
+ onFatal?: (error: unknown) => void;
47
+ }): () => void;
48
+ //# sourceMappingURL=processHandlers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processHandlers.d.ts","sourceRoot":"","sources":["../../../../src/core/logging/kit/processHandlers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,8GAA8G;AAC9G,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE;QAAE,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAA;KAAE,GAAG,IAAI,CAAC;IAChF,QAAQ,CAAC,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACnF;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE;IAC/D,UAAU,EAAE,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,GAAG,MAAM,IAAI,CAuBb"}
@@ -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
+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AS,CAAC,CAAC;IAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC7D,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC/D,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;QAClF,IAAI,KAAK,CAAC,qBAAqB,KAAK,MAAM;YAAE,KAAK,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACtF,CAAC,CAAC;IACF,KAAK,CAAC,qBAAqB,GAAG,MAAM,CAAC;IAAC,OAAO,MAAM,CAAC;AACtD,CAAC"}
@@ -0,0 +1,33 @@
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 The process-wide logger factory behind `createLogger`, and the guard that keeps every logger it
3
- * hands out, including one made before content-safe telemetry was enabled, inside that mode.
4
- * @module agentos/logging/loggerFactory
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
- * Makes the logger `createLogger` delegates to, from a component name and optional bindings.
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 type LoggerFactory = (name: string, bindings?: Record<string, any>) => ILogger;
36
+ export declare function setLogger(logger: Logger | null): void;
11
37
  /**
12
- * Sets the factory that later `createLogger` calls delegate to.
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 - Makes the logger for a component name and optional bindings.
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
- * A logger for one component. Its calls go to the logger the current factory makes, with the caller's arguments,
23
- * until content-safe telemetry is enabled; from then on each call becomes one fixed event for the host's sink, even
24
- * on a logger created earlier. While the mode is on, the factory is not called and `child` returns the same logger.
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 - Fields every record of the logger carries.
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