@framers/agentos 0.15.71 → 0.15.73

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 (95) 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/responseFormatForProvider.d.ts +2 -3
  6. package/dist/api/runtime/responseFormatForProvider.d.ts.map +1 -1
  7. package/dist/api/runtime/responseFormatForProvider.js +2 -3
  8. package/dist/api/runtime/responseFormatForProvider.js.map +1 -1
  9. package/dist/api/server/AgentOSServer.d.ts +9 -0
  10. package/dist/api/server/AgentOSServer.d.ts.map +1 -1
  11. package/dist/api/server/AgentOSServer.js +92 -6
  12. package/dist/api/server/AgentOSServer.js.map +1 -1
  13. package/dist/api/streamText.d.ts.map +1 -1
  14. package/dist/api/streamText.js +26 -56
  15. package/dist/api/streamText.js.map +1 -1
  16. package/dist/core/llm/providers/AIModelProviderManager.d.ts +5 -5
  17. package/dist/core/llm/providers/AIModelProviderManager.d.ts.map +1 -1
  18. package/dist/core/llm/providers/AIModelProviderManager.js +11 -14
  19. package/dist/core/llm/providers/AIModelProviderManager.js.map +1 -1
  20. package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts +7 -6
  21. package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts.map +1 -1
  22. package/dist/core/llm/providers/implementations/OpenAIProvider.js +39 -54
  23. package/dist/core/llm/providers/implementations/OpenAIProvider.js.map +1 -1
  24. package/dist/core/llm/providers/implementations/OpenRouterProvider.d.ts.map +1 -1
  25. package/dist/core/llm/providers/implementations/OpenRouterProvider.js +20 -30
  26. package/dist/core/llm/providers/implementations/OpenRouterProvider.js.map +1 -1
  27. package/dist/core/logging/ILogger.d.ts +12 -0
  28. package/dist/core/logging/ILogger.d.ts.map +1 -1
  29. package/dist/core/logging/ILogger.js +5 -0
  30. package/dist/core/logging/ILogger.js.map +1 -1
  31. package/dist/core/logging/Logger.d.ts +52 -0
  32. package/dist/core/logging/Logger.d.ts.map +1 -0
  33. package/dist/core/logging/Logger.js +11 -0
  34. package/dist/core/logging/Logger.js.map +1 -0
  35. package/dist/core/logging/PinoLogger.d.ts +24 -2
  36. package/dist/core/logging/PinoLogger.d.ts.map +1 -1
  37. package/dist/core/logging/PinoLogger.js +39 -3
  38. package/dist/core/logging/PinoLogger.js.map +1 -1
  39. package/dist/core/logging/contentSafeTelemetry.d.ts +1 -1
  40. package/dist/core/logging/contentSafeTelemetry.d.ts.map +1 -1
  41. package/dist/core/logging/contentSafeTelemetry.js +1 -1
  42. package/dist/core/logging/contentSafeTelemetry.js.map +1 -1
  43. package/dist/core/logging/events.d.ts +349 -0
  44. package/dist/core/logging/events.d.ts.map +1 -0
  45. package/dist/core/logging/events.js +164 -0
  46. package/dist/core/logging/events.js.map +1 -0
  47. package/dist/core/logging/forward.d.ts +93 -0
  48. package/dist/core/logging/forward.d.ts.map +1 -0
  49. package/dist/core/logging/forward.js +167 -0
  50. package/dist/core/logging/forward.js.map +1 -0
  51. package/dist/core/logging/index.d.ts +8 -3
  52. package/dist/core/logging/index.d.ts.map +1 -1
  53. package/dist/core/logging/index.js +7 -3
  54. package/dist/core/logging/index.js.map +1 -1
  55. package/dist/core/logging/kit/allowList.d.ts +68 -0
  56. package/dist/core/logging/kit/allowList.d.ts.map +1 -0
  57. package/dist/core/logging/kit/allowList.js +219 -0
  58. package/dist/core/logging/kit/allowList.js.map +1 -0
  59. package/dist/core/logging/kit/burst.d.ts +38 -0
  60. package/dist/core/logging/kit/burst.d.ts.map +1 -0
  61. package/dist/core/logging/kit/burst.js +91 -0
  62. package/dist/core/logging/kit/burst.js.map +1 -0
  63. package/dist/core/logging/kit/consoleCapture.d.ts +47 -0
  64. package/dist/core/logging/kit/consoleCapture.d.ts.map +1 -0
  65. package/dist/core/logging/kit/consoleCapture.js +121 -0
  66. package/dist/core/logging/kit/consoleCapture.js.map +1 -0
  67. package/dist/core/logging/kit/index.d.ts +12 -0
  68. package/dist/core/logging/kit/index.d.ts.map +1 -0
  69. package/dist/core/logging/kit/index.js +12 -0
  70. package/dist/core/logging/kit/index.js.map +1 -0
  71. package/dist/core/logging/kit/processHandlers.d.ts +48 -0
  72. package/dist/core/logging/kit/processHandlers.d.ts.map +1 -0
  73. package/dist/core/logging/kit/processHandlers.js +77 -0
  74. package/dist/core/logging/kit/processHandlers.js.map +1 -0
  75. package/dist/core/logging/level.d.ts +33 -0
  76. package/dist/core/logging/level.d.ts.map +1 -0
  77. package/dist/core/logging/level.js +36 -0
  78. package/dist/core/logging/level.js.map +1 -0
  79. package/dist/core/logging/loggerFactory.d.ts +74 -15
  80. package/dist/core/logging/loggerFactory.d.ts.map +1 -1
  81. package/dist/core/logging/loggerFactory.js +138 -18
  82. package/dist/core/logging/loggerFactory.js.map +1 -1
  83. package/dist/core/logging/state.d.ts +77 -0
  84. package/dist/core/logging/state.d.ts.map +1 -0
  85. package/dist/core/logging/state.js +25 -0
  86. package/dist/core/logging/state.js.map +1 -0
  87. package/dist/core/utils/terminal.d.ts +22 -0
  88. package/dist/core/utils/terminal.d.ts.map +1 -0
  89. package/dist/core/utils/terminal.js +27 -0
  90. package/dist/core/utils/terminal.js.map +1 -0
  91. package/dist/io/voice-pipeline/providers/OpenAIRealtimeTTS.d.ts +23 -4
  92. package/dist/io/voice-pipeline/providers/OpenAIRealtimeTTS.d.ts.map +1 -1
  93. package/dist/io/voice-pipeline/providers/OpenAIRealtimeTTS.js +296 -71
  94. package/dist/io/voice-pipeline/providers/OpenAIRealtimeTTS.js.map +1 -1
  95. package/package.json +6 -1
@@ -0,0 +1,164 @@
1
+ /**
2
+ * @fileoverview AgentOS's events and context keys, declared once as data, and the checks a
3
+ * value passes before it reaches a line.
4
+ *
5
+ * Each event maps its fields to one of four kinds: `int` (an integer), `word` (letters,
6
+ * digits and `_ . : -`, at most 64 characters), `path` (a word that may also hold `/`, at
7
+ * most 128 characters) or an `enum` (one of a declared list). A word or a path with the shape
8
+ * of a credential is refused. Nothing a person wrote, a model answered or a tool was given is
9
+ * ever a field; a length or a count may be.
10
+ *
11
+ * @module agentos/core/logging/events
12
+ */
13
+ /** The provider names a line may carry. Any other provider is written as `unknown`. */
14
+ export const PROVIDERS = ['openai', 'openrouter', 'anthropic', 'gemini', 'ollama', 'requesty', 'groq', 'mistral', 'together', 'xai', 'litellm', 'minimax', 'claude-code-cli', 'gemini-cli', 'unknown'];
15
+ const provider = { enum: PROVIDERS };
16
+ const api = { enum: ['generateText', 'streamText'] };
17
+ // The fields every fallback event of generateText and streamText shares.
18
+ const fallback = { api, primaryProvider: provider, fallbackProvider: provider, attempt: 'int' };
19
+ /**
20
+ * The context keys a child may bind: `component` and `extension` as words, and `requestId`,
21
+ * which takes only letters, digits and dashes, at most 64 characters.
22
+ */
23
+ export const AGENTOS_CONTEXT = { component: 'word', extension: 'word', requestId: 'word' };
24
+ /**
25
+ * Every event AgentOS writes, with its fields. A field that names a provider, a state or a
26
+ * reason is an `enum`, never a free word, and an error is written as its `type` and `code`.
27
+ */
28
+ export const AGENTOS_EVENTS = {
29
+ 'logging.level_unknown': {},
30
+ 'agentos.untyped': { sourceLevel: { enum: ['debug', 'info', 'warn', 'error', 'fatal'] } },
31
+ 'console_line': { method: { enum: ['debug', 'info', 'log', 'warn', 'error', 'trace', 'dir', 'table', 'assert', 'count', 'countReset', 'time', 'timeEnd', 'timeLog', 'group', 'groupCollapsed', 'groupEnd', 'clear', 'dirxml', 'profile', 'profileEnd', 'timeStamp'] }, type: 'word', code: 'word' },
32
+ 'process.uncaught': { type: 'word', code: 'word' },
33
+ 'process.shutdown': { signal: { enum: ['SIGTERM', 'SIGINT'] } },
34
+ 'http.request': { method: { enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS', 'CONNECT', 'TRACE', 'OTHER'] }, route: 'path', status: 'int', ms: 'int', outcome: { enum: ['ok', 'aborted', 'error'] } },
35
+ 'http.handler_failed': { type: 'word', code: 'word' },
36
+ 'llm.provider_ready': { provider, count: 'int' },
37
+ 'llm.provider_stopped': { provider },
38
+ 'llm.provider_start_failed': { provider, type: 'word', code: 'word' },
39
+ 'llm.default_changed': { provider },
40
+ 'llm.manager_state': { state: { enum: ['reinitializing', 'empty', 'ready', 'stopping', 'stopped'] }, count: 'int' },
41
+ 'llm.retry': { provider, status: 'int', attempt: 'int', waitMs: 'int' },
42
+ 'llm.stream_invalid': { provider, bytes: 'int', reason: { enum: ['json', 'shape', 'framing', 'mapping'] } },
43
+ 'llm.stream_failed': { provider, type: 'word', code: 'word' },
44
+ 'llm.stream_cancel_failed': { provider, type: 'word', code: 'word' },
45
+ 'llm.models_refresh': { provider },
46
+ 'llm.models_failed': { provider, type: 'word', code: 'word' },
47
+ 'llm.models_empty': { provider },
48
+ // Every key of a pool of several is out of rotation at start: the provider starts without its model listing.
49
+ 'llm.key_pool_out': { provider, count: 'int' },
50
+ 'llm.option_ignored': { provider, reason: { enum: ['provider_sort', 'cache_retention', 'embedding_capability'] } },
51
+ 'llm.output_mismatch': { provider, reason: { enum: ['tool_arguments', 'text'] } },
52
+ 'llm.output_empty': { provider, count: 'int' },
53
+ 'llm.format_fallback': { provider, reason: { enum: ['json_schema'] } },
54
+ 'llm.response_format_failed': { provider, type: 'word', code: 'word' },
55
+ 'llm.fallback_skipped': { ...fallback, reason: { enum: ['duplicate', 'excluded', 'capability', 'refusal', 'refill', 'unknown'] } },
56
+ 'llm.fallback_circuit_open': fallback,
57
+ 'llm.fallback_fired': { ...fallback, type: 'word', code: 'word' },
58
+ 'llm.fallback_succeeded': fallback,
59
+ 'llm.fallback_failed_after_output': fallback,
60
+ 'llm.fallback_exhausted': { api, primaryProvider: provider, attempts: 'int', type: 'word', code: 'word' },
61
+ };
62
+ /**
63
+ * Whether a string has the shape of a credential. Segments are split at the start and end,
64
+ * `.`, `/`, `:`, `-` and whitespace, and the shapes are:
65
+ *
66
+ * - a key prefix (`sk-`, `sk_`, `pk_` or `rk_`) opening a segment;
67
+ * - the word `bearer`, in any case;
68
+ * - three base64url parts joined by dots (a JWT);
69
+ * - a whole segment of 20 or more letters, digits and underscores.
70
+ *
71
+ * @param value - The string to test.
72
+ * @returns `true` when the string must not reach a line.
73
+ */
74
+ export function credential(value) {
75
+ return keyShape(value) || /(?:^|[./:\s-])[A-Za-z0-9_]{20,}(?:$|[./:\s-])/.test(value);
76
+ }
77
+ // The credential shapes other than a long segment: a key prefix, the word bearer, or a JWT.
78
+ function keyShape(value) {
79
+ return /(?:^|[./:\s-])(?:sk[-_]|pk_|rk_)/i.test(value) || /bearer/i.test(value)
80
+ || /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value);
81
+ }
82
+ // A class name ending in Error or Exception, and an upper-case constant code of two or more parts joined by
83
+ // underscores, each part at most 16 characters. Either may be 20 characters or more, which the long-segment
84
+ // credential rule alone would refuse; the other credential shapes still refuse them.
85
+ const CLASS_NAME = /^[A-Z][A-Za-z0-9]{0,54}(?:Error|Exception)$/;
86
+ const CONSTANT_CODE = /^[A-Z][A-Z0-9]{0,15}(?:_[A-Z0-9]{1,16})+$/;
87
+ /**
88
+ * Whether a value fits a field kind. A word or a path also fails when it has the shape of a
89
+ * credential, and the `requestId` context key takes only letters, digits and dashes. A word
90
+ * field named `type` also takes a class name ending in `Error` or `Exception`, and one named
91
+ * `code` an upper-case constant code such as `STREAM_PARSING_ERROR`, up to 64 characters and
92
+ * free of the other credential shapes, so that what {@link errorFields} writes passes.
93
+ *
94
+ * @param kind - The field's kind.
95
+ * @param value - The value, of any type, since JavaScript callers are checked too.
96
+ * @param key - The field's or the context key's name, which selects the `requestId`, `type` and `code` forms.
97
+ * @returns `true` when the value may be written.
98
+ */
99
+ export function valid(kind, value, key = '') {
100
+ if (kind === 'int')
101
+ return typeof value === 'number' && Number.isInteger(value);
102
+ if (typeof value !== 'string')
103
+ return false;
104
+ if (typeof kind === 'object')
105
+ return kind.enum.includes(value);
106
+ if (kind === 'word' && value.length <= 64 && ((key === 'type' && CLASS_NAME.test(value)) || (key === 'code' && CONSTANT_CODE.test(value))))
107
+ return !keyShape(value);
108
+ if (credential(value))
109
+ return false;
110
+ if (key === 'requestId')
111
+ return /^[A-Za-z0-9-]{1,64}$/.test(value);
112
+ return kind === 'path' ? /^[A-Za-z0-9_.:/-]{1,128}$/.test(value) : /^[A-Za-z0-9_.:-]{1,64}$/.test(value);
113
+ }
114
+ /**
115
+ * A value as a word, or `unknown` when it is not a valid word.
116
+ *
117
+ * @param value - The value to write.
118
+ * @returns The value when it is a valid word, otherwise `'unknown'`.
119
+ */
120
+ export function safeWord(value) { return valid('word', value) ? value : 'unknown'; }
121
+ // A value read from a caught error, or undefined when reading it throws.
122
+ function read(get) {
123
+ try {
124
+ return get();
125
+ }
126
+ catch {
127
+ return undefined;
128
+ }
129
+ }
130
+ // A value as the word field named `key`, or `unknown` when it does not fit.
131
+ function fieldWord(value, key) {
132
+ return valid('word', value, key) ? value : 'unknown';
133
+ }
134
+ /**
135
+ * The fields an error is written as: its type and its code, never its message or its stack.
136
+ * Either is `unknown` when it is not a valid word. A class name ending in `Error` or
137
+ * `Exception` and an upper-case constant code such as `STREAM_PARSING_ERROR` are kept at any
138
+ * length up to 64 characters, while a value with the shape of a credential is still `unknown`.
139
+ * Reading the error never throws: a property whose getter throws is written as `unknown`.
140
+ *
141
+ * @param error - The caught value.
142
+ * @returns `type`, the error's name (or the value's `typeof` when it is not an `Error`), and `code`, its `code` property.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * errorFields(Object.assign(new Error('text that is never written'), { code: 'ECONNRESET' }));
147
+ * // { type: 'Error', code: 'ECONNRESET' }
148
+ * ```
149
+ */
150
+ export function errorFields(error) {
151
+ const type = read(() => (error instanceof Error ? error.name : typeof error));
152
+ const code = read(() => (typeof error === 'object' && error !== null ? error.code : undefined));
153
+ return { type: fieldWord(type, 'type'), code: fieldWord(code, 'code') };
154
+ }
155
+ /**
156
+ * A provider's name as one of {@link PROVIDERS}, or `unknown`.
157
+ *
158
+ * @param value - The provider name to write.
159
+ * @returns The name when it is listed, otherwise `'unknown'`.
160
+ */
161
+ export function providerName(value) {
162
+ return PROVIDERS.includes(value) ? value : 'unknown';
163
+ }
164
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/core/logging/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAuBH,uFAAuF;AACvF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS,CAAU,CAAC;AAChN,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;AACrC,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,CAAC,cAAc,EAAE,YAAY,CAAU,EAAE,CAAC;AAC9D,yEAAyE;AACzE,MAAM,QAAQ,GAAG,EAAE,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAW,CAAC;AAEzG;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAW,CAAC;AAEpG;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,uBAAuB,EAAE,EAAE;IAC3B,iBAAiB,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE;IACzF,cAAc,EAAE,EAAE,MAAM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,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAe,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;IAC9E,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAE,KAAiC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7H,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;AAC1E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,SAAS,CAAC,QAAQ,CAAC,KAAmC,CAAC,CAAC,CAAC,CAAC,KAAmC,CAAC,CAAC,CAAC,SAAS,CAAC;AACnH,CAAC"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @fileoverview Turns an event, its context and the current request's id into the call the
3
+ * current target takes, and keeps a failing sink away from the caller.
4
+ *
5
+ * A sink that throws never reaches the caller. A failed check is a `LogValidationError`:
6
+ * under `NODE_ENV=test` it is thrown, so a test that writes a bad field fails, and otherwise
7
+ * it becomes one `log_refused` line with a fixed reason and no key or value.
8
+ *
9
+ * @module agentos/core/logging/forward
10
+ */
11
+ import type { Level } from './Logger.js';
12
+ import type { Target } from './state.js';
13
+ import { type ContextSchema, type EventMap } from './events.js';
14
+ import { PinoLogger } from './PinoLogger.js';
15
+ import { type ContentSafeLogComponent } from './contentSafeTelemetry.js';
16
+ /** Why a line was refused. A refusal line carries the reason, never the key or the value. */
17
+ export type RefusalReason = 'unknown_event' | 'unknown_key' | 'bad_value' | 'bad_context';
18
+ declare const ERROR: unique symbol;
19
+ /** A line that failed its event, field or context check. */
20
+ export declare class LogValidationError extends Error {
21
+ readonly reason: RefusalReason;
22
+ readonly [ERROR] = true;
23
+ /** @param reason - Why the line was refused. */
24
+ constructor(reason: RefusalReason);
25
+ }
26
+ /**
27
+ * Whether a value is a {@link LogValidationError}, including one thrown by another copy of
28
+ * AgentOS in the process.
29
+ *
30
+ * @param error - The caught value.
31
+ * @returns `true` for a validation error from any copy of the package.
32
+ */
33
+ export declare function isValidationError(error: unknown): error is LogValidationError;
34
+ /**
35
+ * Runs one write to a sink and swallows what it throws, except a validation error under
36
+ * `NODE_ENV=test`, which reaches the test.
37
+ *
38
+ * @param write - The write to run.
39
+ */
40
+ export declare function sinkCall(write: () => void): void;
41
+ /**
42
+ * Checks bindings against a context schema.
43
+ *
44
+ * @param schema - The keys a child may bind, and their kinds.
45
+ * @param bindings - The bindings to check.
46
+ * @throws {LogValidationError} With `bad_context` when a key is not in the schema or its value breaks its kind.
47
+ */
48
+ export declare function checkContext(schema: ContextSchema, bindings: Record<string, unknown>): void;
49
+ /**
50
+ * Checks an event and its fields against an event map.
51
+ *
52
+ * @param events - The declared events.
53
+ * @param context - The context schema, whose keys a field cannot set.
54
+ * @param event - The event's name.
55
+ * @param fields - The event's fields.
56
+ * @throws {LogValidationError} With `unknown_event` for an undeclared event, `unknown_key` for an undeclared field or a context key, and `bad_value` for a value that breaks its kind.
57
+ */
58
+ export declare function checkFields(events: EventMap, context: ContextSchema, event: string, fields: Record<string, unknown>): void;
59
+ /**
60
+ * The default pino root, built on its first use at the level the environment names. When
61
+ * `AGENTOS_LOG_LEVEL` holds a value that is not a level name, the first build in the process
62
+ * writes one `logging.level_unknown` line, which never repeats the value.
63
+ *
64
+ * @returns The shared root.
65
+ */
66
+ export declare function defaultRoot(): PinoLogger;
67
+ /**
68
+ * Writes one line to a target.
69
+ *
70
+ * The line's context is the handle's bindings plus the current request's id. With `strict`
71
+ * the context, the event and its fields are checked against `AGENTOS_CONTEXT` and
72
+ * `AGENTOS_EVENTS`, the map a strict handle is typed over, so an event it does not declare,
73
+ * which only a JavaScript caller or a cast can write, is refused as `unknown_event`. A failed
74
+ * check is thrown under `NODE_ENV=test` and otherwise written as `log_refused`.
75
+ *
76
+ * A logger gets `logger[level]({ ...context, ...fields, event })`, with no message, and the
77
+ * default root writes the same object. A factory's logger gets `(event, fields)`: at `error`
78
+ * when it has no `fatal`, and not at all at `debug` when it has no `debug`. A silent target
79
+ * gets nothing. While content-safe telemetry is on, any other target gets nothing either: the
80
+ * line becomes one fixed event for the host's sink (a `fatal` line at `error`) naming `origin`,
81
+ * before any check, and nothing of it is read.
82
+ *
83
+ * @param target - Where the line goes.
84
+ * @param level - The line's level.
85
+ * @param event - The event's name.
86
+ * @param fields - The event's fields.
87
+ * @param context - The handle's bindings.
88
+ * @param strict - Whether to check the context and the fields; `createLogger`'s adapters pass `false`.
89
+ * @param origin - The fixed module word the content-safe event names; `library` for a handle no AgentOS module owns.
90
+ */
91
+ export declare function forward(target: Target, level: Level, event: string, fields: Record<string, unknown>, context: Record<string, any>, strict?: boolean, origin?: ContentSafeLogComponent): void;
92
+ export {};
93
+ //# sourceMappingURL=forward.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forward.d.ts","sourceRoot":"","sources":["../../../src/core/logging/forward.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAA0C,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAsB,K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,167 @@
1
+ /**
2
+ * @fileoverview Turns an event, its context and the current request's id into the call the
3
+ * current target takes, and keeps a failing sink away from the caller.
4
+ *
5
+ * A sink that throws never reaches the caller. A failed check is a `LogValidationError`:
6
+ * under `NODE_ENV=test` it is thrown, so a test that writes a bad field fails, and otherwise
7
+ * it becomes one `log_refused` line with a fixed reason and no key or value.
8
+ *
9
+ * @module agentos/core/logging/forward
10
+ */
11
+ var _a;
12
+ import { getLoggingState } from './state.js';
13
+ import { AGENTOS_CONTEXT, AGENTOS_EVENTS, valid } from './events.js';
14
+ import { PinoLogger } from './PinoLogger.js';
15
+ import { parseLogLevel } from './level.js';
16
+ import { emitContentSafeLog } from './contentSafeTelemetry.js';
17
+ // Marks a validation error so that another copy of the package recognises it, where instanceof fails.
18
+ const ERROR = Symbol.for('agentos.logging.validation.v1');
19
+ /** A line that failed its event, field or context check. */
20
+ export class LogValidationError extends Error {
21
+ /** @param reason - Why the line was refused. */
22
+ constructor(reason) {
23
+ super(reason);
24
+ this.reason = reason;
25
+ this[_a] = true;
26
+ this.name = 'LogValidationError';
27
+ }
28
+ }
29
+ _a = ERROR;
30
+ /**
31
+ * Whether a value is a {@link LogValidationError}, including one thrown by another copy of
32
+ * AgentOS in the process.
33
+ *
34
+ * @param error - The caught value.
35
+ * @returns `true` for a validation error from any copy of the package.
36
+ */
37
+ export function isValidationError(error) {
38
+ return typeof error === 'object' && error !== null && error[ERROR] === true;
39
+ }
40
+ /**
41
+ * Runs one write to a sink and swallows what it throws, except a validation error under
42
+ * `NODE_ENV=test`, which reaches the test.
43
+ *
44
+ * @param write - The write to run.
45
+ */
46
+ export function sinkCall(write) {
47
+ try {
48
+ write();
49
+ }
50
+ catch (error) {
51
+ if (process.env.NODE_ENV === 'test' && isValidationError(error))
52
+ throw error;
53
+ }
54
+ }
55
+ /**
56
+ * Checks bindings against a context schema.
57
+ *
58
+ * @param schema - The keys a child may bind, and their kinds.
59
+ * @param bindings - The bindings to check.
60
+ * @throws {LogValidationError} With `bad_context` when a key is not in the schema or its value breaks its kind.
61
+ */
62
+ export function checkContext(schema, bindings) {
63
+ for (const [key, value] of Object.entries(bindings)) {
64
+ if (!Object.prototype.hasOwnProperty.call(schema, key) || !valid(schema[key], value, key))
65
+ throw new LogValidationError('bad_context');
66
+ }
67
+ }
68
+ /**
69
+ * Checks an event and its fields against an event map.
70
+ *
71
+ * @param events - The declared events.
72
+ * @param context - The context schema, whose keys a field cannot set.
73
+ * @param event - The event's name.
74
+ * @param fields - The event's fields.
75
+ * @throws {LogValidationError} With `unknown_event` for an undeclared event, `unknown_key` for an undeclared field or a context key, and `bad_value` for a value that breaks its kind.
76
+ */
77
+ export function checkFields(events, context, event, fields) {
78
+ if (!Object.prototype.hasOwnProperty.call(events, event))
79
+ throw new LogValidationError('unknown_event');
80
+ for (const [key, value] of Object.entries(fields)) {
81
+ if (Object.prototype.hasOwnProperty.call(context, key) || !Object.prototype.hasOwnProperty.call(events[event], key))
82
+ throw new LogValidationError('unknown_key');
83
+ if (!valid(events[event][key], value, key))
84
+ throw new LogValidationError('bad_value');
85
+ }
86
+ }
87
+ /**
88
+ * The default pino root, built on its first use at the level the environment names. When
89
+ * `AGENTOS_LOG_LEVEL` holds a value that is not a level name, the first build in the process
90
+ * writes one `logging.level_unknown` line, which never repeats the value.
91
+ *
92
+ * @returns The shared root.
93
+ */
94
+ export function defaultRoot() {
95
+ const state = getLoggingState();
96
+ if (!state.root) {
97
+ const parsed = parseLogLevel(process.env);
98
+ state.root = new PinoLogger({ name: 'agentos', level: parsed.level });
99
+ if (parsed.unknown && !state.levelWarned) {
100
+ state.levelWarned = true;
101
+ sinkCall(() => state.root.writeEvent('warn', 'logging.level_unknown', {}));
102
+ }
103
+ }
104
+ return state.root;
105
+ }
106
+ /**
107
+ * Writes one line to a target.
108
+ *
109
+ * The line's context is the handle's bindings plus the current request's id. With `strict`
110
+ * the context, the event and its fields are checked against `AGENTOS_CONTEXT` and
111
+ * `AGENTOS_EVENTS`, the map a strict handle is typed over, so an event it does not declare,
112
+ * which only a JavaScript caller or a cast can write, is refused as `unknown_event`. A failed
113
+ * check is thrown under `NODE_ENV=test` and otherwise written as `log_refused`.
114
+ *
115
+ * A logger gets `logger[level]({ ...context, ...fields, event })`, with no message, and the
116
+ * default root writes the same object. A factory's logger gets `(event, fields)`: at `error`
117
+ * when it has no `fatal`, and not at all at `debug` when it has no `debug`. A silent target
118
+ * gets nothing. While content-safe telemetry is on, any other target gets nothing either: the
119
+ * line becomes one fixed event for the host's sink (a `fatal` line at `error`) naming `origin`,
120
+ * before any check, and nothing of it is read.
121
+ *
122
+ * @param target - Where the line goes.
123
+ * @param level - The line's level.
124
+ * @param event - The event's name.
125
+ * @param fields - The event's fields.
126
+ * @param context - The handle's bindings.
127
+ * @param strict - Whether to check the context and the fields; `createLogger`'s adapters pass `false`.
128
+ * @param origin - The fixed module word the content-safe event names; `library` for a handle no AgentOS module owns.
129
+ */
130
+ export function forward(target, level, event, fields, context, strict = true, origin = 'library') {
131
+ if (target.mode === 'silent')
132
+ return;
133
+ if (emitContentSafeLog(level === 'fatal' ? 'error' : level, origin))
134
+ return;
135
+ const requestId = getLoggingState().requests.getStore()?.requestId;
136
+ // Annotated: a spread keeps an index signature only when every part has one, so the inferred type would lose
137
+ // the context's keys (component among them).
138
+ const merged = { ...context, ...(requestId ? { requestId } : {}) };
139
+ if (strict) {
140
+ try {
141
+ checkContext(AGENTOS_CONTEXT, merged);
142
+ checkFields(AGENTOS_EVENTS, AGENTOS_CONTEXT, event, fields);
143
+ }
144
+ catch (error) {
145
+ if (!isValidationError(error))
146
+ return;
147
+ if (process.env.NODE_ENV === 'test')
148
+ throw error;
149
+ forward(target, 'warn', 'log_refused', { reason: error.reason, ...(Object.prototype.hasOwnProperty.call(AGENTOS_EVENTS, event) ? { name: event } : {}) }, {}, false, origin);
150
+ return;
151
+ }
152
+ }
153
+ sinkCall(() => {
154
+ if (target.mode === 'logger') {
155
+ target.logger[level]({ ...merged, ...fields, event });
156
+ return;
157
+ }
158
+ if (target.mode === 'default') {
159
+ defaultRoot().writeEvent(level, event, { ...merged, ...fields });
160
+ return;
161
+ }
162
+ const log = target.factory(String(merged.component ?? 'agentos'), merged);
163
+ const method = level === 'fatal' ? log.fatal ?? log.error : log[level];
164
+ method?.call(log, event, fields);
165
+ });
166
+ }
167
+ //# sourceMappingURL=forward.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forward.js","sourceRoot":"","sources":["../../../src/core/logging/forward.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;;AAIH,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,KAAK,EAAqC,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAgC,MAAM,2BAA2B,CAAC;AAI7F,sGAAsG;AACtG,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAE1D,4DAA4D;AAC5D,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAE3C,gDAAgD;IAChD,YAAqB,MAAqB;QAAI,KAAK,CAAC,MAAM,CAAC,CAAC;QAAvC,WAAM,GAAN,MAAM,CAAe;QAFjC,QAAO,GAAG,IAAI,CAAC;QAEqC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IAAC,CAAC;CACjG;KAHW,KAAK;AAKjB;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAK,KAAiC,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;AAC3G,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAiB;IACxC,IAAI,CAAC;QAAC,KAAK,EAAE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AAC;QAC5G,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,IAAI,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;QAC1E,MAAM,MAAM,GAAG,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACvE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,10 +1,15 @@
1
1
  /**
2
- * Logging infrastructure: the `ILogger` contract, `createLogger` and its factory, `PinoLogger`, and content-safe
3
- * server telemetry.
2
+ * Logging infrastructure: the `ILogger` contract, `createLogger` and its factory, the hand-over of a host's pino
3
+ * logger (`setLogger`) with the typed event handles AgentOS writes through (`lazyLogger`), AgentOS's events and
4
+ * context keys as data, `PinoLogger`, and content-safe server telemetry. The allow-list kit is its own entry,
5
+ * `@framers/agentos/logging/kit`.
4
6
  * @module agentos/logging
5
7
  */
6
8
  export * from './ILogger.js';
7
- export * from './loggerFactory.js';
9
+ export { setLogger, setLoggerFactory, resetLoggerFactory, createLogger, lazyLogger, type LoggerFactory, } from './loggerFactory.js';
10
+ export type { Logger, LogMethod, Level, EventLogger, EventMethod } from './Logger.js';
11
+ export { AGENTOS_EVENTS, AGENTOS_CONTEXT, PROVIDERS, type AgentOSEvents, type AgentOSContext, type EventMap, type ContextSchema, type FieldKind, type Fields, type ContextValues, } from './events.js';
12
+ export { LogValidationError, type RefusalReason } from './forward.js';
8
13
  export { PinoLogger } from './PinoLogger.js';
9
14
  export { enableContentSafeTelemetry, isContentSafeTelemetryEnabled, CONTENT_SAFE_COMPONENTS, type ContentSafeLogLevel, type ContentSafeLogEvent, type ContentSafeLogSink, type ContentSafeLogComponent, type ContentSafeTelemetryOptions, } from './contentSafeTelemetry.js';
10
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/logging/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,0BAA0B,EAAE,6BAA6B,EAAE,uBAAuB,EAClF,KAAK,mBAAmB,EAAE,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAC3E,KAAK,uBAAuB,EAAE,KAAK,2BAA2B,GAC/D,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/logging/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,cAAc,CAAC;AAC7B,OAAO,EACL,SAAS,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,aAAa,GAC9F,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EACL,cAAc,EAAE,eAAe,EAAE,SAAS,EAC1C,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,GAC5H,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,0BAA0B,EAAE,6BAA6B,EAAE,uBAAuB,EAClF,KAAK,mBAAmB,EAAE,KAAK,mBAAmB,EAAE,KAAK,kBAAkB,EAC3E,KAAK,uBAAuB,EAAE,KAAK,2BAA2B,GAC/D,MAAM,2BAA2B,CAAC"}
@@ -1,10 +1,14 @@
1
1
  /**
2
- * Logging infrastructure: the `ILogger` contract, `createLogger` and its factory, `PinoLogger`, and content-safe
3
- * server telemetry.
2
+ * Logging infrastructure: the `ILogger` contract, `createLogger` and its factory, the hand-over of a host's pino
3
+ * logger (`setLogger`) with the typed event handles AgentOS writes through (`lazyLogger`), AgentOS's events and
4
+ * context keys as data, `PinoLogger`, and content-safe server telemetry. The allow-list kit is its own entry,
5
+ * `@framers/agentos/logging/kit`.
4
6
  * @module agentos/logging
5
7
  */
6
8
  export * from './ILogger.js';
7
- export * from './loggerFactory.js';
9
+ export { setLogger, setLoggerFactory, resetLoggerFactory, createLogger, lazyLogger, } from './loggerFactory.js';
10
+ export { AGENTOS_EVENTS, AGENTOS_CONTEXT, PROVIDERS, } from './events.js';
11
+ export { LogValidationError } from './forward.js';
8
12
  export { PinoLogger } from './PinoLogger.js';
9
13
  export { enableContentSafeTelemetry, isContentSafeTelemetryEnabled, CONTENT_SAFE_COMPONENTS, } from './contentSafeTelemetry.js';
10
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/logging/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,0BAA0B,EAAE,6BAA6B,EAAE,uBAAuB,GAGnF,MAAM,2BAA2B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/logging/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,cAAc,CAAC;AAC7B,OAAO,EACL,SAAS,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,GAC1E,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,cAAc,EAAE,eAAe,EAAE,SAAS,GAE3C,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAsB,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,0BAA0B,EAAE,6BAA6B,EAAE,uBAAuB,GAGnF,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @fileoverview The allow-list logger: a typed logger over a product's event map that writes
3
+ * only declared events with fields of their declared kinds.
4
+ *
5
+ * A line the product writes through the kit is refused when its event is undeclared, or when a
6
+ * field or the context breaks its kind. A refusal is written as `log_refused` at `warn` with a
7
+ * fixed reason (`unknown_event`, `unknown_key`, `bad_value` or `bad_context`), plus the
8
+ * event's name only when the event is declared, and never the key or the value; under
9
+ * `NODE_ENV=test` it is thrown as a `LogValidationError` instead. A line that reaches the
10
+ * kit's pino-shaped form, `asLogger()`, with an undeclared event is written as
11
+ * `agentos.untyped` with only its component and its level, so a sentence from code that has
12
+ * not moved to events never reaches the log. Every line counts against the burst budgets the
13
+ * process shares.
14
+ *
15
+ * @module agentos/core/logging/kit/allowList
16
+ */
17
+ import type { EventLogger, Logger } from '../Logger.js';
18
+ import { AGENTOS_CONTEXT, safeWord, type AgentOSEvents, type ContextSchema, type EventMap, type Fields } from '../events.js';
19
+ /**
20
+ * The logger {@link createAllowListLogger} returns: an `EventLogger` over the product's event
21
+ * map, plus three methods.
22
+ *
23
+ * - `asLogger()` returns the pino-shaped form that `setLogger` takes.
24
+ * - `terminal(event, fields)` writes the process's last line at `fatal`. It bypasses the burst
25
+ * budget and never refuses: a field that breaks its kind is left out, and an undeclared
26
+ * event is written as `process.uncaught`.
27
+ * - `close()` stops the kit writing. Closing a child closes the kit it came from; closing the
28
+ * last open kit in the process clears the shared counters and their timer.
29
+ *
30
+ * @typeParam E - The product's event map.
31
+ * @typeParam C - The context schema.
32
+ */
33
+ export type AllowListLogger<E extends EventMap, C extends ContextSchema> = EventLogger<E, C> & {
34
+ asLogger(): Logger;
35
+ terminal<K extends keyof E & string>(event: K, fields?: Fields<E[K]>): void;
36
+ close(): void;
37
+ };
38
+ /**
39
+ * Creates an allow-list logger over a product's event map. AgentOS's own events are always
40
+ * declared; the product's map adds its own and those of the packs it uses, and may name one of
41
+ * AgentOS's events again only with the same fields. No process listener is installed by
42
+ * importing or creating a kit.
43
+ *
44
+ * @param options - The kit's settings.
45
+ * @param options.logger - The pino logger, or pino child, the kit writes through.
46
+ * @param options.events - The product's event map.
47
+ * @param options.context - The context keys a child may bind beyond AgentOS's own, which stay in the schema because AgentOS's lines carry them.
48
+ * @param options.burst - Lines a minute for each event and each refusal reason, 30 unless set. Every kit in the process shares the budgets, at the smallest bound asked for.
49
+ * @returns The kit, typed over AgentOS's events and the product's map, so it also takes the
50
+ * `console_line` and `process.*` lines `captureConsole` and `installProcessHandlers` write.
51
+ * @throws {TypeError} When `burst` is not a positive integer, an event's name is not a word of at most 64 characters or is `log_refused` or `log_held`, an event declares a context key, `event`, `level` or `time` as a field, the product's map declares one of AgentOS's events with other fields than AgentOS gives it, or `context` gives one of AgentOS's context keys another kind.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import pino from 'pino';
56
+ * const kit = createAllowListLogger({ logger: pino(), events: { 'job.done': { ms: 'int' } } });
57
+ * kit.info('job.done', { ms: 120 });
58
+ * setLogger(kit.asLogger());
59
+ * ```
60
+ */
61
+ export declare function createAllowListLogger<E extends EventMap, C extends ContextSchema = typeof AGENTOS_CONTEXT>(options: {
62
+ logger: Logger;
63
+ events: E;
64
+ context?: C;
65
+ burst?: number;
66
+ }): AllowListLogger<E & AgentOSEvents, C & typeof AGENTOS_CONTEXT>;
67
+ export { safeWord };
68
+ //# sourceMappingURL=allowList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allowList.d.ts","sourceRoot":"","sources":["../../../../src/core/logging/kit/allowList.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,EAAa,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,eAAe,EAA+B,QAAQ,EAAS,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAkB,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAIjL;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,aAAa,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;IAC7F,QAAQ,IAAI,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC5E,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAgBF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,aAAa,GAAG,OAAO,eAAe,EAAE,OAAO,EAAE;IACnH,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACxD,GAAG,eAAe,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC,GAAG,OAAO,eAAe,CAAC,CAqGjE;AACD,OAAO,EAAE,QAAQ,EAAE,CAAC"}