@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,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,Q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AAE,GAAG,MAAM,EAAE,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;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"}
@@ -0,0 +1,219 @@
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 { AGENTOS_CONTEXT, AGENTOS_EVENTS, errorFields, safeWord, valid } from '../events.js';
18
+ import { checkContext, checkFields, isValidationError, LogValidationError, sinkCall } from '../forward.js';
19
+ import { admit, burstOwner, closeOwner } from './burst.js';
20
+ const own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
21
+ // Whether two field kinds are the same: the same word, or enums of the same values in any order.
22
+ function sameKind(a, b) {
23
+ if (typeof a === 'string' || typeof b === 'string')
24
+ return a === b;
25
+ if (!a || !b || !Array.isArray(a.enum) || !Array.isArray(b.enum))
26
+ return false;
27
+ return a.enum.length === b.enum.length && a.enum.every(value => b.enum.includes(value));
28
+ }
29
+ // Whether two event declarations name the same fields with the same kinds.
30
+ function sameFields(a, b) {
31
+ const keys = Object.keys(a);
32
+ return keys.length === Object.keys(b).length && keys.every(key => own(b, key) && sameKind(a[key], b[key]));
33
+ }
34
+ /**
35
+ * Creates an allow-list logger over a product's event map. AgentOS's own events are always
36
+ * declared; the product's map adds its own and those of the packs it uses, and may name one of
37
+ * AgentOS's events again only with the same fields. No process listener is installed by
38
+ * importing or creating a kit.
39
+ *
40
+ * @param options - The kit's settings.
41
+ * @param options.logger - The pino logger, or pino child, the kit writes through.
42
+ * @param options.events - The product's event map.
43
+ * @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.
44
+ * @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.
45
+ * @returns The kit, typed over AgentOS's events and the product's map, so it also takes the
46
+ * `console_line` and `process.*` lines `captureConsole` and `installProcessHandlers` write.
47
+ * @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.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import pino from 'pino';
52
+ * const kit = createAllowListLogger({ logger: pino(), events: { 'job.done': { ms: 'int' } } });
53
+ * kit.info('job.done', { ms: 120 });
54
+ * setLogger(kit.asLogger());
55
+ * ```
56
+ */
57
+ export function createAllowListLogger(options) {
58
+ const events = { ...AGENTOS_EVENTS, ...options.events };
59
+ // AgentOS's own lines carry its context keys, so a host's keys extend them and may name one again only with its kind.
60
+ for (const [key, kind] of Object.entries(options.context ?? {})) {
61
+ if (own(AGENTOS_CONTEXT, key) && !sameKind(kind, AGENTOS_CONTEXT[key]))
62
+ throw new TypeError('context key redeclared with another kind');
63
+ }
64
+ const schema = { ...AGENTOS_CONTEXT, ...options.context };
65
+ const limit = options.burst ?? 30;
66
+ if (!Number.isInteger(limit) || limit < 1)
67
+ throw new TypeError('burst must be a positive integer');
68
+ // The refusal and held-lines records are the kit's own, so a product map can neither declare nor overwrite them.
69
+ // An AgentOS event the product's map names again keeps AgentOS's fields, so AgentOS's own lines are never refused.
70
+ for (const [name, fields] of Object.entries(events)) {
71
+ if (own(AGENTOS_EVENTS, name) && !sameFields(fields, AGENTOS_EVENTS[name]))
72
+ throw new TypeError('event redeclared with other fields');
73
+ if (name === 'log_refused' || name === 'log_held' || !/^[A-Za-z0-9_.:-]{1,64}$/.test(name))
74
+ throw new TypeError('invalid event declaration');
75
+ for (const key of Object.keys(fields))
76
+ if (own(schema, key) || key === 'event' || key === 'level' || key === 'time')
77
+ throw new TypeError('reserved field declaration');
78
+ }
79
+ let closed = false;
80
+ const raw = (level, fields) => { if (!closed)
81
+ sinkCall(() => options.logger[level](fields)); };
82
+ const owner = burstOwner((name, n) => raw('info', { event: 'log_held', name, n }));
83
+ function refuse(reason, event) {
84
+ if (process.env.NODE_ENV === 'test')
85
+ throw new LogValidationError(reason);
86
+ if (admit(owner, `reason:${reason}`, reason, limit))
87
+ raw('warn', { event: 'log_refused', reason, ...(event && own(events, event) ? { name: event } : {}) });
88
+ }
89
+ // One logger over `bindings`. A child whose bindings fail the context schema writes one refusal and is then
90
+ // disabled, so it writes nothing.
91
+ function make(bindings, disabled = false) {
92
+ function write(level, event, fields = {}, adapter = false) {
93
+ if (closed || disabled)
94
+ return;
95
+ if (adapter && !own(events, event)) {
96
+ if (admit(owner, 'event:agentos.untyped', 'agentos.untyped', limit))
97
+ raw(level, { event: 'agentos.untyped', ...(bindings.component ? { component: bindings.component } : {}), sourceLevel: level });
98
+ return;
99
+ }
100
+ try {
101
+ checkContext(schema, bindings);
102
+ checkFields(events, schema, event, fields);
103
+ }
104
+ catch (error) {
105
+ if (isValidationError(error)) {
106
+ refuse(error.reason, event);
107
+ return;
108
+ }
109
+ throw error;
110
+ }
111
+ if (admit(owner, `event:${event}`, event, limit))
112
+ raw(level, { ...bindings, ...fields, event });
113
+ }
114
+ function child(next) {
115
+ const merged = { ...bindings, ...next };
116
+ try {
117
+ checkContext(schema, merged);
118
+ }
119
+ catch (error) {
120
+ if (isValidationError(error)) {
121
+ refuse('bad_context');
122
+ return make({}, true);
123
+ }
124
+ throw error;
125
+ }
126
+ return make(merged, disabled);
127
+ }
128
+ const api = {
129
+ debug: (event, fields) => write('debug', event, fields),
130
+ info: (event, fields) => write('info', event, fields),
131
+ warn: (event, fields) => write('warn', event, fields),
132
+ error: (event, fields) => write('error', event, fields),
133
+ fatal: (event, fields) => write('fatal', event, fields),
134
+ child,
135
+ terminal(event, fields = {}) {
136
+ if (closed || disabled)
137
+ return;
138
+ // Terminal never routes an unsafe value into a refusal or echoes it.
139
+ const safe = {};
140
+ const shape = events[event];
141
+ if (shape) {
142
+ for (const [key, value] of Object.entries(fields)) {
143
+ try {
144
+ checkFields(events, schema, event, { [key]: value });
145
+ safe[key] = value;
146
+ }
147
+ catch { /* Omit an invalid terminal field. */ }
148
+ }
149
+ raw('fatal', { ...bindings, ...safe, event });
150
+ }
151
+ else
152
+ raw('fatal', { event: 'process.uncaught', ...errorFields(undefined) });
153
+ },
154
+ close() { if (!closed) {
155
+ closeOwner(owner);
156
+ closed = true;
157
+ } },
158
+ // The pino-shaped form. A host's line arrives as one object holding its event, its context and its fields;
159
+ // a message alone has no event, so it is written as agentos.untyped. A refusal another layer forwards is
160
+ // written again as this kit's own, from its reason and declared name alone.
161
+ asLogger() {
162
+ const method = (level) => ((obj) => {
163
+ if (closed || disabled)
164
+ return;
165
+ if (typeof obj === 'string') {
166
+ write(level, '', {}, true);
167
+ return;
168
+ }
169
+ if (obj === null) {
170
+ write(level, '', {}, true);
171
+ return;
172
+ }
173
+ const input = obj;
174
+ const event = typeof input.event === 'string' ? input.event : '';
175
+ if (event === 'log_refused') {
176
+ const reasons = ['unknown_event', 'unknown_key', 'bad_value', 'bad_context'];
177
+ const reason = reasons.includes(input.reason) ? input.reason : 'bad_value';
178
+ refuse(reason, typeof input.name === 'string' && own(events, input.name) ? input.name : undefined);
179
+ return;
180
+ }
181
+ if (!own(events, event)) {
182
+ const component = valid('word', input.component) ? input.component : bindings.component;
183
+ if (admit(owner, 'event:agentos.untyped', 'agentos.untyped', limit)) {
184
+ raw(level, { event: 'agentos.untyped', ...(component ? { component } : {}), sourceLevel: level });
185
+ }
186
+ return;
187
+ }
188
+ const context = { ...bindings };
189
+ const fields = {};
190
+ for (const [key, value] of Object.entries(input)) {
191
+ if (key === 'event')
192
+ continue;
193
+ if (own(schema, key))
194
+ context[key] = value;
195
+ else
196
+ fields[key] = value;
197
+ }
198
+ try {
199
+ checkContext(schema, context);
200
+ }
201
+ catch (error) {
202
+ if (isValidationError(error)) {
203
+ refuse('bad_context', event);
204
+ return;
205
+ }
206
+ throw error;
207
+ }
208
+ make(context)[level](event, fields);
209
+ });
210
+ return { debug: method('debug'), info: method('info'), warn: method('warn'), error: method('error'), fatal: method('fatal'), child: next => child(next).asLogger() };
211
+ },
212
+ };
213
+ return api;
214
+ }
215
+ // The map the kit checks against always holds AgentOS's own events, so its type does too.
216
+ return make({});
217
+ }
218
+ export { safeWord };
219
+ //# sourceMappingURL=allowList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allowList.js","sourceRoot":"","sources":["../../../../src/core/logging/kit/allowList.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAsF,MAAM,cAAc,CAAC;AACjL,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,QAAQ,EAAsB,MAAM,eAAe,CAAC;AAC/H,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAqB3D,MAAM,GAAG,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAE7F,iGAAiG;AACjG,SAAS,QAAQ,CAAC,CAAY,EAAE,CAAY;IAC1C,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACnE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/E,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,CA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IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;YACvK,CAAC;SACF,CAAC;QACF,OAAO,GAA4B,CAAC;IACtC,CAAC;IACD,0FAA0F;IAC1F,OAAO,IAAI,CAAC,EAAE,CAA8E,CAAC;AAC/F,CAAC;AACD,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,38 @@
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
+ /**
14
+ * Registers a kit as an owner of burst budgets.
15
+ *
16
+ * @param emit - Writes the kit's `log_held` line: the event or refusal reason held, and how many lines were held.
17
+ * @returns The owner's key, which {@link admit} and {@link closeOwner} take.
18
+ */
19
+ export declare function burstOwner(emit: (name: string, n: number) => void): symbol;
20
+ /**
21
+ * Counts one line against its minute's budget. A budget's bound is the smallest any kit asked
22
+ * for in that minute.
23
+ *
24
+ * @param owner - The kit writing the line; a minute it opens reports its held lines through it.
25
+ * @param key - The budget's key, built from a declared event's name or a fixed refusal reason, so the keys are finite.
26
+ * @param name - The event's name or the refusal reason, as the `log_held` line gives it.
27
+ * @param limit - The kit's bound on lines a minute.
28
+ * @returns `true` when the line may be written, `false` when it is held.
29
+ */
30
+ export declare function admit(owner: symbol, key: string, name: string, limit: number): boolean;
31
+ /**
32
+ * Removes a kit from the owners. A minute it opened still reports through a kit that remains
33
+ * open; when no kit remains, the counters and the timer are cleared.
34
+ *
35
+ * @param owner - The key {@link burstOwner} returned.
36
+ */
37
+ export declare function closeOwner(owner: symbol): void;
38
+ //# sourceMappingURL=burst.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"burst.d.ts","sourceRoot":"","sources":["../../../../src/core/logging/kit/burst.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA6BH;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,CAE1E;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAOtF;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAI9C"}