@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,349 @@
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 kind of one field: an integer, a word, a path, or one of a declared list. */
14
+ export type FieldKind = 'int' | 'word' | 'path' | {
15
+ readonly enum: readonly string[];
16
+ };
17
+ /** A map from each event name to its fields and their kinds. */
18
+ export type EventMap = Readonly<Record<string, Readonly<Record<string, FieldKind>>>>;
19
+ /** The context keys a child may bind, and their kinds. */
20
+ export type ContextSchema = Readonly<Record<string, FieldKind>>;
21
+ /** The value type of one kind: a number for `int`, the listed strings for an `enum`, a string otherwise. */
22
+ type Value<K extends FieldKind> = K extends 'int' ? number : K extends {
23
+ readonly enum: readonly (infer V)[];
24
+ } ? V : string;
25
+ /**
26
+ * The fields of one event, typed from its declaration. A declared field may be left out; a
27
+ * field that is not declared does not compile.
28
+ */
29
+ export type Fields<S extends Readonly<Record<string, FieldKind>>> = {
30
+ [K in keyof S]?: Value<S[K]>;
31
+ };
32
+ /** The values a child may bind, typed from a context schema. */
33
+ export type ContextValues<C extends ContextSchema> = Fields<C>;
34
+ /** The provider names a line may carry. Any other provider is written as `unknown`. */
35
+ export declare const PROVIDERS: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
36
+ /**
37
+ * The context keys a child may bind: `component` and `extension` as words, and `requestId`,
38
+ * which takes only letters, digits and dashes, at most 64 characters.
39
+ */
40
+ export declare const AGENTOS_CONTEXT: {
41
+ readonly component: "word";
42
+ readonly extension: "word";
43
+ readonly requestId: "word";
44
+ };
45
+ /**
46
+ * Every event AgentOS writes, with its fields. A field that names a provider, a state or a
47
+ * reason is an `enum`, never a free word, and an error is written as its `type` and `code`.
48
+ */
49
+ export declare const AGENTOS_EVENTS: {
50
+ readonly 'logging.level_unknown': {};
51
+ readonly 'agentos.untyped': {
52
+ readonly sourceLevel: {
53
+ readonly enum: readonly ["debug", "info", "warn", "error", "fatal"];
54
+ };
55
+ };
56
+ readonly console_line: {
57
+ readonly method: {
58
+ readonly enum: readonly ["debug", "info", "log", "warn", "error", "trace", "dir", "table", "assert", "count", "countReset", "time", "timeEnd", "timeLog", "group", "groupCollapsed", "groupEnd", "clear", "dirxml", "profile", "profileEnd", "timeStamp"];
59
+ };
60
+ readonly type: "word";
61
+ readonly code: "word";
62
+ };
63
+ readonly 'process.uncaught': {
64
+ readonly type: "word";
65
+ readonly code: "word";
66
+ };
67
+ readonly 'process.shutdown': {
68
+ readonly signal: {
69
+ readonly enum: readonly ["SIGTERM", "SIGINT"];
70
+ };
71
+ };
72
+ readonly 'http.request': {
73
+ readonly method: {
74
+ readonly enum: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE", "OTHER"];
75
+ };
76
+ readonly route: "path";
77
+ readonly status: "int";
78
+ readonly ms: "int";
79
+ readonly outcome: {
80
+ readonly enum: readonly ["ok", "aborted", "error"];
81
+ };
82
+ };
83
+ readonly 'http.handler_failed': {
84
+ readonly type: "word";
85
+ readonly code: "word";
86
+ };
87
+ readonly 'llm.provider_ready': {
88
+ readonly provider: {
89
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
90
+ };
91
+ readonly count: "int";
92
+ };
93
+ readonly 'llm.provider_stopped': {
94
+ readonly provider: {
95
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
96
+ };
97
+ };
98
+ readonly 'llm.provider_start_failed': {
99
+ readonly provider: {
100
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
101
+ };
102
+ readonly type: "word";
103
+ readonly code: "word";
104
+ };
105
+ readonly 'llm.default_changed': {
106
+ readonly provider: {
107
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
108
+ };
109
+ };
110
+ readonly 'llm.manager_state': {
111
+ readonly state: {
112
+ readonly enum: readonly ["reinitializing", "empty", "ready", "stopping", "stopped"];
113
+ };
114
+ readonly count: "int";
115
+ };
116
+ readonly 'llm.retry': {
117
+ readonly provider: {
118
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
119
+ };
120
+ readonly status: "int";
121
+ readonly attempt: "int";
122
+ readonly waitMs: "int";
123
+ };
124
+ readonly 'llm.stream_invalid': {
125
+ readonly provider: {
126
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
127
+ };
128
+ readonly bytes: "int";
129
+ readonly reason: {
130
+ readonly enum: readonly ["json", "shape", "framing", "mapping"];
131
+ };
132
+ };
133
+ readonly 'llm.stream_failed': {
134
+ readonly provider: {
135
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
136
+ };
137
+ readonly type: "word";
138
+ readonly code: "word";
139
+ };
140
+ readonly 'llm.stream_cancel_failed': {
141
+ readonly provider: {
142
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
143
+ };
144
+ readonly type: "word";
145
+ readonly code: "word";
146
+ };
147
+ readonly 'llm.models_refresh': {
148
+ readonly provider: {
149
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
150
+ };
151
+ };
152
+ readonly 'llm.models_failed': {
153
+ readonly provider: {
154
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
155
+ };
156
+ readonly type: "word";
157
+ readonly code: "word";
158
+ };
159
+ readonly 'llm.models_empty': {
160
+ readonly provider: {
161
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
162
+ };
163
+ };
164
+ readonly 'llm.key_pool_out': {
165
+ readonly provider: {
166
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
167
+ };
168
+ readonly count: "int";
169
+ };
170
+ readonly 'llm.option_ignored': {
171
+ readonly provider: {
172
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
173
+ };
174
+ readonly reason: {
175
+ readonly enum: readonly ["provider_sort", "cache_retention", "embedding_capability"];
176
+ };
177
+ };
178
+ readonly 'llm.output_mismatch': {
179
+ readonly provider: {
180
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
181
+ };
182
+ readonly reason: {
183
+ readonly enum: readonly ["tool_arguments", "text"];
184
+ };
185
+ };
186
+ readonly 'llm.output_empty': {
187
+ readonly provider: {
188
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
189
+ };
190
+ readonly count: "int";
191
+ };
192
+ readonly 'llm.format_fallback': {
193
+ readonly provider: {
194
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
195
+ };
196
+ readonly reason: {
197
+ readonly enum: readonly ["json_schema"];
198
+ };
199
+ };
200
+ readonly 'llm.response_format_failed': {
201
+ readonly provider: {
202
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
203
+ };
204
+ readonly type: "word";
205
+ readonly code: "word";
206
+ };
207
+ readonly 'llm.fallback_skipped': {
208
+ readonly reason: {
209
+ readonly enum: readonly ["duplicate", "excluded", "capability", "refusal", "refill", "unknown"];
210
+ };
211
+ readonly api: {
212
+ enum: readonly ["generateText", "streamText"];
213
+ };
214
+ readonly primaryProvider: {
215
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
216
+ };
217
+ readonly fallbackProvider: {
218
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
219
+ };
220
+ readonly attempt: "int";
221
+ };
222
+ readonly 'llm.fallback_circuit_open': {
223
+ readonly api: {
224
+ enum: readonly ["generateText", "streamText"];
225
+ };
226
+ readonly primaryProvider: {
227
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
228
+ };
229
+ readonly fallbackProvider: {
230
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
231
+ };
232
+ readonly attempt: "int";
233
+ };
234
+ readonly 'llm.fallback_fired': {
235
+ readonly type: "word";
236
+ readonly code: "word";
237
+ readonly api: {
238
+ enum: readonly ["generateText", "streamText"];
239
+ };
240
+ readonly primaryProvider: {
241
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
242
+ };
243
+ readonly fallbackProvider: {
244
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
245
+ };
246
+ readonly attempt: "int";
247
+ };
248
+ readonly 'llm.fallback_succeeded': {
249
+ readonly api: {
250
+ enum: readonly ["generateText", "streamText"];
251
+ };
252
+ readonly primaryProvider: {
253
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
254
+ };
255
+ readonly fallbackProvider: {
256
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
257
+ };
258
+ readonly attempt: "int";
259
+ };
260
+ readonly 'llm.fallback_failed_after_output': {
261
+ readonly api: {
262
+ enum: readonly ["generateText", "streamText"];
263
+ };
264
+ readonly primaryProvider: {
265
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
266
+ };
267
+ readonly fallbackProvider: {
268
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
269
+ };
270
+ readonly attempt: "int";
271
+ };
272
+ readonly 'llm.fallback_exhausted': {
273
+ readonly api: {
274
+ enum: readonly ["generateText", "streamText"];
275
+ };
276
+ readonly primaryProvider: {
277
+ enum: readonly ["openai", "openrouter", "anthropic", "gemini", "ollama", "requesty", "groq", "mistral", "together", "xai", "litellm", "minimax", "claude-code-cli", "gemini-cli", "unknown"];
278
+ };
279
+ readonly attempts: "int";
280
+ readonly type: "word";
281
+ readonly code: "word";
282
+ };
283
+ };
284
+ /** The type of {@link AGENTOS_EVENTS}, which `lazyLogger`'s handles are typed over. */
285
+ export type AgentOSEvents = typeof AGENTOS_EVENTS;
286
+ /** The values a child of an AgentOS handle may bind. */
287
+ export type AgentOSContext = ContextValues<typeof AGENTOS_CONTEXT>;
288
+ /**
289
+ * Whether a string has the shape of a credential. Segments are split at the start and end,
290
+ * `.`, `/`, `:`, `-` and whitespace, and the shapes are:
291
+ *
292
+ * - a key prefix (`sk-`, `sk_`, `pk_` or `rk_`) opening a segment;
293
+ * - the word `bearer`, in any case;
294
+ * - three base64url parts joined by dots (a JWT);
295
+ * - a whole segment of 20 or more letters, digits and underscores.
296
+ *
297
+ * @param value - The string to test.
298
+ * @returns `true` when the string must not reach a line.
299
+ */
300
+ export declare function credential(value: string): boolean;
301
+ /**
302
+ * Whether a value fits a field kind. A word or a path also fails when it has the shape of a
303
+ * credential, and the `requestId` context key takes only letters, digits and dashes. A word
304
+ * field named `type` also takes a class name ending in `Error` or `Exception`, and one named
305
+ * `code` an upper-case constant code such as `STREAM_PARSING_ERROR`, up to 64 characters and
306
+ * free of the other credential shapes, so that what {@link errorFields} writes passes.
307
+ *
308
+ * @param kind - The field's kind.
309
+ * @param value - The value, of any type, since JavaScript callers are checked too.
310
+ * @param key - The field's or the context key's name, which selects the `requestId`, `type` and `code` forms.
311
+ * @returns `true` when the value may be written.
312
+ */
313
+ export declare function valid(kind: FieldKind, value: unknown, key?: string): boolean;
314
+ /**
315
+ * A value as a word, or `unknown` when it is not a valid word.
316
+ *
317
+ * @param value - The value to write.
318
+ * @returns The value when it is a valid word, otherwise `'unknown'`.
319
+ */
320
+ export declare function safeWord(value: unknown): string;
321
+ /**
322
+ * The fields an error is written as: its type and its code, never its message or its stack.
323
+ * Either is `unknown` when it is not a valid word. A class name ending in `Error` or
324
+ * `Exception` and an upper-case constant code such as `STREAM_PARSING_ERROR` are kept at any
325
+ * length up to 64 characters, while a value with the shape of a credential is still `unknown`.
326
+ * Reading the error never throws: a property whose getter throws is written as `unknown`.
327
+ *
328
+ * @param error - The caught value.
329
+ * @returns `type`, the error's name (or the value's `typeof` when it is not an `Error`), and `code`, its `code` property.
330
+ *
331
+ * @example
332
+ * ```ts
333
+ * errorFields(Object.assign(new Error('text that is never written'), { code: 'ECONNRESET' }));
334
+ * // { type: 'Error', code: 'ECONNRESET' }
335
+ * ```
336
+ */
337
+ export declare function errorFields(error: unknown): {
338
+ type: string;
339
+ code: string;
340
+ };
341
+ /**
342
+ * A provider's name as one of {@link PROVIDERS}, or `unknown`.
343
+ *
344
+ * @param value - The provider name to write.
345
+ * @returns The name when it is listed, otherwise `'unknown'`.
346
+ */
347
+ export declare function providerName(value: unknown): (typeof PROVIDERS)[number];
348
+ export {};
349
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/core/logging/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,oFAAoF;AACpF,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,C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;;;;;;;;;;;;;;;;CAiCE,CAAC;AAE9B,uFAAuF;AACvF,MAAM,MAAM,aAAa,GAAG,OAAO,cAAc,CAAC;AAElD,wDAAwD;AACxD,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,OAAO,eAAe,CAAC,CAAC;AAEnE;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEjD;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,SAAK,GAAG,OAAO,CAQxE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAA+D;AAY/G;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAI1E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAEvE"}
@@ -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":[],"mapp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AC,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,KAAK,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAE7F,6FAA6F;AAC7F,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG,aAAa,GAAG,WAAW,GAAG,aAAa,CAAC;AAE1F,QAAA,MAAM,KAAK,eAA8C,CAAC;AAE1D,4DAA4D;AAC5D,qBAAa,kBAAmB,SAAQ,KAAK;IAG/B,QAAQ,CAAC,MAAM,EAAE,aAAa;IAF1C,QAAQ,CAAC,CAAC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