@xrkseek/harness 0.4.8 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@xrkseek/cordis/LICENSE +21 -0
- package/node_modules/@xrkseek/cordis/README.md +14 -0
- package/node_modules/@xrkseek/cordis/bin.js +16 -0
- package/node_modules/@xrkseek/cordis/lib/index.js +1828 -0
- package/node_modules/@xrkseek/cordis/lib/types/context.d.ts +101 -0
- package/node_modules/@xrkseek/cordis/lib/types/context.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/lib/types/events.d.ts +240 -0
- package/node_modules/@xrkseek/cordis/lib/types/events.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/lib/types/fiber.d.ts +202 -0
- package/node_modules/@xrkseek/cordis/lib/types/fiber.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/lib/types/index.d.ts +15 -0
- package/node_modules/@xrkseek/cordis/lib/types/index.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/lib/types/logger.d.ts +105 -0
- package/node_modules/@xrkseek/cordis/lib/types/logger.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/lib/types/reflect.d.ts +186 -0
- package/node_modules/@xrkseek/cordis/lib/types/reflect.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/lib/types/registry.d.ts +201 -0
- package/node_modules/@xrkseek/cordis/lib/types/registry.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/lib/types/service.d.ts +55 -0
- package/node_modules/@xrkseek/cordis/lib/types/service.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/lib/types/utils.d.ts +62 -0
- package/node_modules/@xrkseek/cordis/lib/types/utils.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/package.json +49 -0
- package/node_modules/@xrkseek/cordis/src/context.d.ts +101 -0
- package/node_modules/@xrkseek/cordis/src/context.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/src/context.js +99 -0
- package/node_modules/@xrkseek/cordis/src/context.js.map +1 -0
- package/node_modules/@xrkseek/cordis/src/context.ts +146 -0
- package/node_modules/@xrkseek/cordis/src/events.d.ts +240 -0
- package/node_modules/@xrkseek/cordis/src/events.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/src/events.js +199 -0
- package/node_modules/@xrkseek/cordis/src/events.js.map +1 -0
- package/node_modules/@xrkseek/cordis/src/events.ts +352 -0
- package/node_modules/@xrkseek/cordis/src/fiber.d.ts +202 -0
- package/node_modules/@xrkseek/cordis/src/fiber.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/src/fiber.js +677 -0
- package/node_modules/@xrkseek/cordis/src/fiber.js.map +1 -0
- package/node_modules/@xrkseek/cordis/src/fiber.ts +754 -0
- package/node_modules/@xrkseek/cordis/src/index.d.ts +15 -0
- package/node_modules/@xrkseek/cordis/src/index.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/src/index.js +15 -0
- package/node_modules/@xrkseek/cordis/src/index.js.map +1 -0
- package/node_modules/@xrkseek/cordis/src/index.ts +14 -0
- package/node_modules/@xrkseek/cordis/src/logger.d.ts +105 -0
- package/node_modules/@xrkseek/cordis/src/logger.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/src/logger.js +193 -0
- package/node_modules/@xrkseek/cordis/src/logger.js.map +1 -0
- package/node_modules/@xrkseek/cordis/src/logger.ts +270 -0
- package/node_modules/@xrkseek/cordis/src/reflect.d.ts +186 -0
- package/node_modules/@xrkseek/cordis/src/reflect.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/src/reflect.js +311 -0
- package/node_modules/@xrkseek/cordis/src/reflect.js.map +1 -0
- package/node_modules/@xrkseek/cordis/src/reflect.ts +418 -0
- package/node_modules/@xrkseek/cordis/src/registry.d.ts +201 -0
- package/node_modules/@xrkseek/cordis/src/registry.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/src/registry.js +218 -0
- package/node_modules/@xrkseek/cordis/src/registry.js.map +1 -0
- package/node_modules/@xrkseek/cordis/src/registry.ts +337 -0
- package/node_modules/@xrkseek/cordis/src/service.d.ts +55 -0
- package/node_modules/@xrkseek/cordis/src/service.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/src/service.js +113 -0
- package/node_modules/@xrkseek/cordis/src/service.js.map +1 -0
- package/node_modules/@xrkseek/cordis/src/service.ts +115 -0
- package/node_modules/@xrkseek/cordis/src/utils.d.ts +62 -0
- package/node_modules/@xrkseek/cordis/src/utils.d.ts.map +1 -0
- package/node_modules/@xrkseek/cordis/src/utils.js +271 -0
- package/node_modules/@xrkseek/cordis/src/utils.js.map +1 -0
- package/node_modules/@xrkseek/cordis/src/utils.ts +287 -0
- package/node_modules/@xrkseek/core-agent-loop/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/core-agent-loop/dist/index.js +39 -68
- package/node_modules/@xrkseek/core-agent-loop/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/core-session/dist/compaction.d.ts +4 -3
- package/node_modules/@xrkseek/core-session/dist/compaction.d.ts.map +1 -1
- package/node_modules/@xrkseek/core-session/dist/compaction.js.map +1 -1
- package/node_modules/@xrkseek/core-tools/dist/subagent-prompt.d.ts.map +1 -1
- package/node_modules/@xrkseek/core-tools/dist/subagent-prompt.js +2 -1
- package/node_modules/@xrkseek/core-tools/dist/subagent-prompt.js.map +1 -1
- package/node_modules/@xrkseek/exec-image-gen/README.md +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/catalog.d.ts +16 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/catalog.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/catalog.js +152 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/catalog.js.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/deepinfra-http.d.ts +9 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/deepinfra-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/deepinfra-http.js +21 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/deepinfra-http.js.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/fal-http.d.ts +16 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/fal-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/fal-http.js +189 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/fal-http.js.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/index.d.ts +10 -5
- package/node_modules/@xrkseek/exec-image-gen/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/index.js +174 -18
- package/node_modules/@xrkseek/exec-image-gen/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/krea-http.d.ts +16 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/krea-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/krea-http.js +144 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/krea-http.js.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/meta-ai-http.d.ts +9 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/meta-ai-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/meta-ai-http.js +21 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/meta-ai-http.js.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/openai-http.d.ts +4 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/openai-http.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/openai-http.js +7 -5
- package/node_modules/@xrkseek/exec-image-gen/dist/openai-http.js.map +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/openrouter-http.d.ts +14 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/openrouter-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/openrouter-http.js +117 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/openrouter-http.js.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/tools.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/tools.js +43 -6
- package/node_modules/@xrkseek/exec-image-gen/dist/tools.js.map +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/types.d.ts +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/types.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/types.js.map +1 -1
- package/node_modules/@xrkseek/exec-image-gen/dist/xai-http.d.ts +16 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/xai-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/xai-http.js +137 -0
- package/node_modules/@xrkseek/exec-image-gen/dist/xai-http.js.map +1 -0
- package/node_modules/@xrkseek/exec-memory/dist/consolidate-pipeline.d.ts +52 -0
- package/node_modules/@xrkseek/exec-memory/dist/consolidate-pipeline.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-memory/dist/consolidate-pipeline.js +216 -0
- package/node_modules/@xrkseek/exec-memory/dist/consolidate-pipeline.js.map +1 -0
- package/node_modules/@xrkseek/exec-memory/dist/index.d.ts +1 -0
- package/node_modules/@xrkseek/exec-memory/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-memory/dist/index.js +1 -0
- package/node_modules/@xrkseek/exec-memory/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/exec-memory/dist/tools.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-memory/dist/tools.js +20 -7
- package/node_modules/@xrkseek/exec-memory/dist/tools.js.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/README.md +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/catalog.d.ts +14 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/catalog.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/catalog.js +99 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/catalog.js.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/deepinfra-http.d.ts +9 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/deepinfra-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/deepinfra-http.js +17 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/deepinfra-http.js.map +1 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/fal-http.d.ts +14 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/fal-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/fal-http.js +342 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/fal-http.js.map +1 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/index.d.ts +8 -6
- package/node_modules/@xrkseek/exec-video-gen/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/index.js +122 -19
- package/node_modules/@xrkseek/exec-video-gen/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/openai-http.d.ts +4 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/openai-http.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/openai-http.js +21 -15
- package/node_modules/@xrkseek/exec-video-gen/dist/openai-http.js.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/openrouter-http.d.ts +9 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/openrouter-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/openrouter-http.js +18 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/openrouter-http.js.map +1 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/tools.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/tools.js +26 -6
- package/node_modules/@xrkseek/exec-video-gen/dist/tools.js.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/types.d.ts +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/types.d.ts.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/types.js.map +1 -1
- package/node_modules/@xrkseek/exec-video-gen/dist/xai-http.d.ts +18 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/xai-http.d.ts.map +1 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/xai-http.js +263 -0
- package/node_modules/@xrkseek/exec-video-gen/dist/xai-http.js.map +1 -0
- package/node_modules/@xrkseek/preset-harness/dist/preset.d.ts.map +1 -1
- package/node_modules/@xrkseek/preset-harness/dist/preset.js +12 -3
- package/node_modules/@xrkseek/preset-harness/dist/preset.js.map +1 -1
- package/node_modules/@xrkseek/preset-harness/dist/tsconfig.tsbuildinfo +1 -1
- package/node_modules/@xrkseek/preset-minimal/dist/tsconfig.tsbuildinfo +1 -1
- package/node_modules/@xrkseek/preset-server/dist/tsconfig.tsbuildinfo +1 -1
- package/node_modules/@xrkseek/server-face/dist/agent-team-graph.d.ts +31 -0
- package/node_modules/@xrkseek/server-face/dist/agent-team-graph.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/agent-team-graph.js +125 -1
- package/node_modules/@xrkseek/server-face/dist/agent-team-graph.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/context.d.ts +19 -1
- package/node_modules/@xrkseek/server-face/dist/context.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/index.d.ts +3 -3
- package/node_modules/@xrkseek/server-face/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/index.js +1 -1
- package/node_modules/@xrkseek/server-face/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/mcp-oauth.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/mcp-oauth.js +25 -3
- package/node_modules/@xrkseek/server-face/dist/mcp-oauth.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/ralph-tool.d.ts +2 -0
- package/node_modules/@xrkseek/server-face/dist/ralph-tool.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/ralph-tool.js +11 -5
- package/node_modules/@xrkseek/server-face/dist/ralph-tool.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/runtime.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/runtime.js +1 -0
- package/node_modules/@xrkseek/server-face/dist/runtime.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/session-status.d.ts +16 -0
- package/node_modules/@xrkseek/server-face/dist/session-status.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/session-status.js +44 -5
- package/node_modules/@xrkseek/server-face/dist/session-status.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/settings-credentials.d.ts +9 -0
- package/node_modules/@xrkseek/server-face/dist/settings-credentials.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/settings-credentials.js +50 -0
- package/node_modules/@xrkseek/server-face/dist/settings-credentials.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/settings-document.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/settings-document.js +40 -0
- package/node_modules/@xrkseek/server-face/dist/settings-document.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/settings-schemas.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/settings-schemas.js +20 -4
- package/node_modules/@xrkseek/server-face/dist/settings-schemas.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/subagent-tools.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/subagent-tools.js +191 -0
- package/node_modules/@xrkseek/server-face/dist/subagent-tools.js.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/wire/rpc-error.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-face/dist/wire/rpc-error.js +8 -0
- package/node_modules/@xrkseek/server-face/dist/wire/rpc-error.js.map +1 -1
- package/node_modules/@xrkseek/server-host/dist/index.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-host/dist/index.js +140 -24
- package/node_modules/@xrkseek/server-host/dist/index.js.map +1 -1
- package/node_modules/@xrkseek/server-host/dist/sidebar-face-bridge.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-host/dist/sidebar-face-bridge.js +6 -0
- package/node_modules/@xrkseek/server-host/dist/sidebar-face-bridge.js.map +1 -1
- package/node_modules/@xrkseek/server-host/dist/workflow-engine-mount.d.ts +40 -0
- package/node_modules/@xrkseek/server-host/dist/workflow-engine-mount.d.ts.map +1 -0
- package/node_modules/@xrkseek/server-host/dist/workflow-engine-mount.js +162 -0
- package/node_modules/@xrkseek/server-host/dist/workflow-engine-mount.js.map +1 -0
- package/node_modules/@xrkseek/server-host/package.json +2 -0
- package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-adapter.d.ts.map +1 -1
- package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-adapter.js +20 -0
- package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-adapter.js.map +1 -1
- package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-face-bridge.d.ts +10 -2
- package/node_modules/@xrkseek/server-http/dist/sidebar/sidebar-face-bridge.d.ts.map +1 -1
- package/node_modules/@xrkseek/xrk-workflow/README.i18n.yaml +6 -0
- package/node_modules/@xrkseek/xrk-workflow/README.md +73 -0
- package/node_modules/@xrkseek/xrk-workflow/README.zh.md +72 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/index.d.ts +177 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/index.js +730 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/index.js.map +1 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/invariant.d.ts +13 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/invariant.js +118 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/invariant.js.map +1 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/runtime-types.d.ts +45 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/runtime-types.js +9 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/runtime-types.js.map +1 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/types.d.ts +118 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/types.js +16 -0
- package/node_modules/@xrkseek/xrk-workflow/lib/types/types.js.map +1 -0
- package/node_modules/@xrkseek/xrk-workflow/package.json +51 -0
- package/package.json +5 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Core context type and root context implementation. */
|
|
2
|
+
export * from './context.ts';
|
|
3
|
+
/** Event bus, dispatch modes, and event augmentation types. */
|
|
4
|
+
export * from './events.ts';
|
|
5
|
+
/** Plugin fiber lifecycle, effects, and config validation helpers. */
|
|
6
|
+
export * from './fiber.ts';
|
|
7
|
+
/** Logger facade, logger service, message, exporter, and formatting types. */
|
|
8
|
+
export * from './logger.ts';
|
|
9
|
+
/** Plugin registry, dependency injection, and plugin entrypoint types. */
|
|
10
|
+
export * from './registry.ts';
|
|
11
|
+
/** Base service class and service lifecycle symbols. */
|
|
12
|
+
export * from './service.ts';
|
|
13
|
+
/** Shared internal helpers used by context, services, and plugin fibers. */
|
|
14
|
+
export * from './utils.ts';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,cAAc,cAAc,CAAA;AAC5B,+DAA+D;AAC/D,cAAc,aAAa,CAAA;AAC3B,sEAAsE;AACtE,cAAc,YAAY,CAAA;AAC1B,8EAA8E;AAC9E,cAAc,aAAa,CAAA;AAC3B,0EAA0E;AAC1E,cAAc,eAAe,CAAA;AAC7B,wDAAwD;AACxD,cAAc,cAAc,CAAA;AAC5B,4EAA4E;AAC5E,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Core context type and root context implementation. */
|
|
2
|
+
export * from "./context.js";
|
|
3
|
+
/** Event bus, dispatch modes, and event augmentation types. */
|
|
4
|
+
export * from "./events.js";
|
|
5
|
+
/** Plugin fiber lifecycle, effects, and config validation helpers. */
|
|
6
|
+
export * from "./fiber.js";
|
|
7
|
+
/** Logger facade, logger service, message, exporter, and formatting types. */
|
|
8
|
+
export * from "./logger.js";
|
|
9
|
+
/** Plugin registry, dependency injection, and plugin entrypoint types. */
|
|
10
|
+
export * from "./registry.js";
|
|
11
|
+
/** Base service class and service lifecycle symbols. */
|
|
12
|
+
export * from "./service.js";
|
|
13
|
+
/** Shared internal helpers used by context, services, and plugin fibers. */
|
|
14
|
+
export * from "./utils.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,cAAc,cAAc,CAAA;AAC5B,+DAA+D;AAC/D,cAAc,aAAa,CAAA;AAC3B,sEAAsE;AACtE,cAAc,YAAY,CAAA;AAC1B,8EAA8E;AAC9E,cAAc,aAAa,CAAA;AAC3B,0EAA0E;AAC1E,cAAc,eAAe,CAAA;AAC7B,wDAAwD;AACxD,cAAc,cAAc,CAAA;AAC5B,4EAA4E;AAC5E,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Core context type and root context implementation. */
|
|
2
|
+
export * from './context.ts'
|
|
3
|
+
/** Event bus, dispatch modes, and event augmentation types. */
|
|
4
|
+
export * from './events.ts'
|
|
5
|
+
/** Plugin fiber lifecycle, effects, and config validation helpers. */
|
|
6
|
+
export * from './fiber.ts'
|
|
7
|
+
/** Logger facade, logger service, message, exporter, and formatting types. */
|
|
8
|
+
export * from './logger.ts'
|
|
9
|
+
/** Plugin registry, dependency injection, and plugin entrypoint types. */
|
|
10
|
+
export * from './registry.ts'
|
|
11
|
+
/** Base service class and service lifecycle symbols. */
|
|
12
|
+
export * from './service.ts'
|
|
13
|
+
/** Shared internal helpers used by context, services, and plugin fibers. */
|
|
14
|
+
export * from './utils.ts'
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Context } from './context.ts';
|
|
2
|
+
import { Fiber } from './fiber.ts';
|
|
3
|
+
import { symbols } from './utils.ts';
|
|
4
|
+
declare module './context.ts' {
|
|
5
|
+
interface Intercept {
|
|
6
|
+
logger: LoggerService.Intercept;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/** Logger method name and severity category. */
|
|
10
|
+
export type LoggerType = 'error' | 'info' | 'warn' | 'debug';
|
|
11
|
+
/** Callable shape for one logger severity method. */
|
|
12
|
+
export type LoggerMethod = (format: any, ...param: any[]) => void;
|
|
13
|
+
/** Formatter used to resolve a printf-style placeholder. */
|
|
14
|
+
export type Formatter = (value: any, exporter: Exporter, message: Message) => any;
|
|
15
|
+
/** Numeric severity used when exporters decide whether to emit a message. */
|
|
16
|
+
export declare const enum LoggerLevel {
|
|
17
|
+
ERROR = 0,
|
|
18
|
+
INFO = 1,
|
|
19
|
+
WARN = 2,
|
|
20
|
+
DEBUG = 3
|
|
21
|
+
}
|
|
22
|
+
/** Structured log record delivered to exporters. */
|
|
23
|
+
export interface Message {
|
|
24
|
+
sn: number;
|
|
25
|
+
ts: number;
|
|
26
|
+
name: string;
|
|
27
|
+
type: LoggerType;
|
|
28
|
+
level: number;
|
|
29
|
+
args: any[];
|
|
30
|
+
fiber?: WeakRef<Fiber>;
|
|
31
|
+
}
|
|
32
|
+
/** Sink that receives structured log messages. */
|
|
33
|
+
export interface Exporter {
|
|
34
|
+
colors?: number | false;
|
|
35
|
+
maxLength?: number;
|
|
36
|
+
levels?: Record<string, number>;
|
|
37
|
+
formatters?: Record<string, Formatter>;
|
|
38
|
+
export(message: Message): void;
|
|
39
|
+
}
|
|
40
|
+
/** Built-in placeholder formatters used by `Logger.format()`. */
|
|
41
|
+
export declare const defaultFormatters: Record<string, Formatter>;
|
|
42
|
+
/** Options used when creating a named logger facade. */
|
|
43
|
+
export interface LoggerOptions {
|
|
44
|
+
/** The logger name shown with each message. */
|
|
45
|
+
name: string;
|
|
46
|
+
/** Message fields merged into every record from this logger. */
|
|
47
|
+
meta?: Partial<Message>;
|
|
48
|
+
/** Default maximum level exported when an exporter has no own threshold. */
|
|
49
|
+
level?: number;
|
|
50
|
+
}
|
|
51
|
+
/** Logger facade identity, inherited message metadata, and optional minimum level. */
|
|
52
|
+
export interface Logger extends LoggerOptions {
|
|
53
|
+
}
|
|
54
|
+
/** Logger facade severity methods. */
|
|
55
|
+
export interface Logger extends Record<LoggerType, LoggerMethod> {
|
|
56
|
+
}
|
|
57
|
+
/** Logger facade for one named subsystem. */
|
|
58
|
+
export declare class Logger {
|
|
59
|
+
private service;
|
|
60
|
+
static color(exporter: Exporter, code: number, value: any, decoration?: string): string;
|
|
61
|
+
static code(name: string, level?: false | number): number | undefined;
|
|
62
|
+
static format(exporter: Exporter, message: Message): string;
|
|
63
|
+
constructor(options: LoggerOptions, service: LoggerService);
|
|
64
|
+
private _method;
|
|
65
|
+
}
|
|
66
|
+
/** ANSI 16-color palette indexes used for logger name coloring. */
|
|
67
|
+
export declare const c16: number[];
|
|
68
|
+
/** ANSI 256-color palette indexes used for logger name coloring. */
|
|
69
|
+
export declare const c256: number[];
|
|
70
|
+
/** Logger service configuration merged from context intercepts. */
|
|
71
|
+
export declare namespace LoggerService {
|
|
72
|
+
interface Intercept {
|
|
73
|
+
name?: string;
|
|
74
|
+
level?: number;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Callable `ctx.logger` service shape. */
|
|
78
|
+
export interface LoggerService extends Record<LoggerType, LoggerMethod> {
|
|
79
|
+
(name?: string): Logger;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Built-in logging service.
|
|
83
|
+
*
|
|
84
|
+
* Call `ctx.logger()` to create a named logger, or call `ctx.logger.info()`
|
|
85
|
+
* directly to log with the current fiber-derived name.
|
|
86
|
+
*/
|
|
87
|
+
export declare class LoggerService {
|
|
88
|
+
bufferSize: number;
|
|
89
|
+
buffer: Message[];
|
|
90
|
+
ctx: Context;
|
|
91
|
+
_snMessage: number;
|
|
92
|
+
_snExporter: number;
|
|
93
|
+
exporters: Map<number, Exporter>;
|
|
94
|
+
constructor(ctx: Context);
|
|
95
|
+
/**
|
|
96
|
+
* Register an exporter and dispose it with the current fiber.
|
|
97
|
+
*
|
|
98
|
+
* @param exporter — the sink that receives structured log messages.
|
|
99
|
+
* @returns a disposer that removes the exporter.
|
|
100
|
+
*/
|
|
101
|
+
exporter(exporter: Exporter): import("@xrkseek/cordis").Disposable<Promise<void>>;
|
|
102
|
+
private _resolveConfig;
|
|
103
|
+
[symbols.invoke](name?: string): Logger;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAiC,OAAO,EAAgB,MAAM,YAAY,CAAA;AAEjF,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,SAAS;QACjB,MAAM,EAAE,aAAa,CAAC,SAAS,CAAA;KAChC;CACF;AAED,gDAAgD;AAChD,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAE5D,qDAAqD;AACrD,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;AAEjE,4DAA4D;AAC5D,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,KAAK,GAAG,CAAA;AAEjF,6EAA6E;AAC7E,0BAAkB,WAAW;IAC3B,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACV;AAED,oDAAoD;AACpD,MAAM,WAA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AE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM;IAUhD,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM;gBAkC/C,OAAO,EAAE,aAAa,EAAU,OAAO,EAAE,aAAa;IAQlE,OAAO,CAAC,OAAO;CAqBhB;AAED,mEAAmE;AACnE,eAAO,MAAM,GAAG,UAAqB,CAAA;AACrC,oEAAoE;AACpE,eAAO,MAAM,IAAI,UAMhB,CAAA;AAED,mEAAmE;AACnE,yBAAiB,aAAa,CAAC;IAC7B,UAAiB,SAAS;QACxB,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,KAAK,CAAC,EAAE,MAAM,CAAA;KACf;CACF;AAED,2CAA2C;AAC3C,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC;IACrE,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACxB;AAED;;;;;GAKG;AACH,qBAAa,aAAa;IACxB,UAAU,SAAO;IACjB,MAAM,EAAE,OAAO,EAAE,CAAK;IACtB,GAAG,EAAG,OAAO,CAAA;IAEb,UAAU,SAAI;IACd,WAAW,SAAI;IACf,SAAS,wBAA8B;gBAE3B,GAAG,EAAE,OAAO;IAuBxB;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ;IAO3B,OAAO,CAAC,cAAc;IAYtB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;CAmBxC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { defineProperty, hyphenate } from '@xrkseek/cosmokit';
|
|
2
|
+
import { createCallable, joinPrototype, symbols } from "./utils.js";
|
|
3
|
+
/** Numeric severity used when exporters decide whether to emit a message. */
|
|
4
|
+
export var LoggerLevel;
|
|
5
|
+
(function (LoggerLevel) {
|
|
6
|
+
LoggerLevel[LoggerLevel["ERROR"] = 0] = "ERROR";
|
|
7
|
+
LoggerLevel[LoggerLevel["INFO"] = 1] = "INFO";
|
|
8
|
+
LoggerLevel[LoggerLevel["WARN"] = 2] = "WARN";
|
|
9
|
+
LoggerLevel[LoggerLevel["DEBUG"] = 3] = "DEBUG";
|
|
10
|
+
})(LoggerLevel || (LoggerLevel = {}));
|
|
11
|
+
/** Built-in placeholder formatters used by `Logger.format()`. */
|
|
12
|
+
export const defaultFormatters = {
|
|
13
|
+
s: (value) => String(value),
|
|
14
|
+
d: (value) => Math.trunc(Number(value)),
|
|
15
|
+
i: (value) => Math.trunc(Number(value)),
|
|
16
|
+
f: (value) => Number(value),
|
|
17
|
+
o: (value) => JSON.stringify(value),
|
|
18
|
+
O: (value) => JSON.stringify(value),
|
|
19
|
+
c: () => '',
|
|
20
|
+
C: (value, exporter, message) => {
|
|
21
|
+
return Logger.color(exporter, Logger.code(message.name, exporter.colors), value);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
function isAggregateError(error) {
|
|
25
|
+
return error instanceof Error && Array.isArray(error['errors']);
|
|
26
|
+
}
|
|
27
|
+
/** Logger facade for one named subsystem. */
|
|
28
|
+
export class Logger {
|
|
29
|
+
service;
|
|
30
|
+
static color(exporter, code, value, decoration = '') {
|
|
31
|
+
if (!exporter.colors)
|
|
32
|
+
return '' + value;
|
|
33
|
+
return `\u001b[3${code < 8 ? code : '8;5;' + code}${exporter.colors >= 2 ? decoration : ''}m${value}\u001b[0m`;
|
|
34
|
+
}
|
|
35
|
+
static code(name, level) {
|
|
36
|
+
let hash = 0;
|
|
37
|
+
for (let i = 0; i < name.length; i++) {
|
|
38
|
+
hash = ((hash << 3) - hash) + name.charCodeAt(i) + 13;
|
|
39
|
+
hash |= 0;
|
|
40
|
+
}
|
|
41
|
+
const colors = !level ? [] : level >= 2 ? c256 : c16;
|
|
42
|
+
return colors[Math.abs(hash) % colors.length];
|
|
43
|
+
}
|
|
44
|
+
static format(exporter, message) {
|
|
45
|
+
const args = message.args.slice();
|
|
46
|
+
if (args[0] instanceof Error) {
|
|
47
|
+
args[0] = args[0].stack || args[0].message;
|
|
48
|
+
args.unshift('%s');
|
|
49
|
+
}
|
|
50
|
+
else if (typeof args[0] !== 'string') {
|
|
51
|
+
args.unshift('%o');
|
|
52
|
+
}
|
|
53
|
+
let format = args.shift();
|
|
54
|
+
format = format.replace(/%([a-zA-Z%])/g, (match, char) => {
|
|
55
|
+
if (match === '%%')
|
|
56
|
+
return '%';
|
|
57
|
+
const formatter = exporter.formatters?.[char] ?? defaultFormatters[char];
|
|
58
|
+
if (typeof formatter === 'function') {
|
|
59
|
+
const value = args.shift();
|
|
60
|
+
return formatter(value, exporter, message);
|
|
61
|
+
}
|
|
62
|
+
return match;
|
|
63
|
+
});
|
|
64
|
+
const oFormatter = exporter.formatters?.o ?? defaultFormatters.o;
|
|
65
|
+
for (let arg of args) {
|
|
66
|
+
if (typeof arg === 'object' && arg) {
|
|
67
|
+
arg = oFormatter(arg, exporter, message);
|
|
68
|
+
}
|
|
69
|
+
format += ' ' + arg;
|
|
70
|
+
}
|
|
71
|
+
const { maxLength = 10240 } = exporter;
|
|
72
|
+
return format.split(/\r?\n/g).map(line => {
|
|
73
|
+
return line.slice(0, maxLength) + (line.length > maxLength ? '...' : '');
|
|
74
|
+
}).join('\n');
|
|
75
|
+
}
|
|
76
|
+
constructor(options, service) {
|
|
77
|
+
this.service = service;
|
|
78
|
+
Object.assign(this, options);
|
|
79
|
+
this.error = this._method('error', LoggerLevel.ERROR);
|
|
80
|
+
this.info = this._method('info', LoggerLevel.INFO);
|
|
81
|
+
this.warn = this._method('warn', LoggerLevel.WARN);
|
|
82
|
+
this.debug = this._method('debug', LoggerLevel.DEBUG);
|
|
83
|
+
}
|
|
84
|
+
_method(type, level) {
|
|
85
|
+
return (...args) => {
|
|
86
|
+
if (args.length === 1 && args[0] instanceof Error) {
|
|
87
|
+
if (args[0].cause) {
|
|
88
|
+
this[type](args[0].cause);
|
|
89
|
+
}
|
|
90
|
+
else if (isAggregateError(args[0])) {
|
|
91
|
+
args[0].errors.forEach(error => this[type](error));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const sn = ++this.service._snMessage;
|
|
96
|
+
const ts = Date.now();
|
|
97
|
+
for (const exporter of this.service.exporters.values()) {
|
|
98
|
+
const targetLevel = exporter.levels?.[this.name] ?? exporter.levels?.default ?? this.level ?? LoggerLevel.INFO;
|
|
99
|
+
if (targetLevel < level)
|
|
100
|
+
continue;
|
|
101
|
+
const message = { sn, ts, type, level, name: this.name, ...this.meta, args };
|
|
102
|
+
exporter.export(message);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** ANSI 16-color palette indexes used for logger name coloring. */
|
|
108
|
+
export const c16 = [6, 2, 3, 4, 5, 1];
|
|
109
|
+
/** ANSI 256-color palette indexes used for logger name coloring. */
|
|
110
|
+
export const c256 = [
|
|
111
|
+
20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62,
|
|
112
|
+
63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113,
|
|
113
|
+
129, 134, 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168,
|
|
114
|
+
169, 170, 171, 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200,
|
|
115
|
+
201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, 220, 221,
|
|
116
|
+
];
|
|
117
|
+
/**
|
|
118
|
+
* Built-in logging service.
|
|
119
|
+
*
|
|
120
|
+
* Call `ctx.logger()` to create a named logger, or call `ctx.logger.info()`
|
|
121
|
+
* directly to log with the current fiber-derived name.
|
|
122
|
+
*/
|
|
123
|
+
export class LoggerService {
|
|
124
|
+
bufferSize = 1000;
|
|
125
|
+
buffer = [];
|
|
126
|
+
ctx;
|
|
127
|
+
_snMessage = 0;
|
|
128
|
+
_snExporter = 0;
|
|
129
|
+
exporters = new Map();
|
|
130
|
+
constructor(ctx) {
|
|
131
|
+
const tracker = {
|
|
132
|
+
property: 'ctx',
|
|
133
|
+
noShadow: true,
|
|
134
|
+
};
|
|
135
|
+
const self = createCallable('logger', joinPrototype(Object.getPrototypeOf(this), Function.prototype), tracker);
|
|
136
|
+
Object.assign(self, this);
|
|
137
|
+
self.ctx = ctx;
|
|
138
|
+
defineProperty(self, symbols.tracker, tracker);
|
|
139
|
+
self.exporter({
|
|
140
|
+
colors: 3,
|
|
141
|
+
export: (message) => {
|
|
142
|
+
self.buffer.push(message);
|
|
143
|
+
if (self.buffer.length > self.bufferSize) {
|
|
144
|
+
self.buffer = self.buffer.slice(-self.bufferSize);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
return self;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Register an exporter and dispose it with the current fiber.
|
|
152
|
+
*
|
|
153
|
+
* @param exporter — the sink that receives structured log messages.
|
|
154
|
+
* @returns a disposer that removes the exporter.
|
|
155
|
+
*/
|
|
156
|
+
exporter(exporter) {
|
|
157
|
+
return this.ctx.effect(() => {
|
|
158
|
+
this.exporters.set(++this._snExporter, exporter);
|
|
159
|
+
return () => this.exporters.delete(this._snExporter);
|
|
160
|
+
}, 'ctx.logger.exporter()');
|
|
161
|
+
}
|
|
162
|
+
_resolveConfig() {
|
|
163
|
+
let intercept = this.ctx[symbols.intercept];
|
|
164
|
+
const configs = [];
|
|
165
|
+
while ('logger' in intercept) {
|
|
166
|
+
if (Object.hasOwn(intercept, 'logger')) {
|
|
167
|
+
configs.unshift(intercept['logger']);
|
|
168
|
+
}
|
|
169
|
+
intercept = Object.getPrototypeOf(intercept);
|
|
170
|
+
}
|
|
171
|
+
return Object.assign({}, ...configs);
|
|
172
|
+
}
|
|
173
|
+
[symbols.invoke](name) {
|
|
174
|
+
const config = this._resolveConfig();
|
|
175
|
+
const fiber = (this.ctx[symbols.shadow] ?? this.ctx).fiber;
|
|
176
|
+
name ??= config.name;
|
|
177
|
+
name ??= hyphenate(fiber.name);
|
|
178
|
+
return new Logger({
|
|
179
|
+
name,
|
|
180
|
+
level: config.level,
|
|
181
|
+
meta: { fiber: new WeakRef(fiber) },
|
|
182
|
+
}, this);
|
|
183
|
+
}
|
|
184
|
+
static {
|
|
185
|
+
for (const type of ['error', 'info', 'warn', 'debug']) {
|
|
186
|
+
;
|
|
187
|
+
LoggerService.prototype[type] = function (...args) {
|
|
188
|
+
return this()[type](...args);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAG7D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,OAAO,EAAgB,MAAM,YAAY,CAAA;AAiBjF,6EAA6E;AAC7E,MAAM,CAAN,IAAkB,WAKjB;AALD,WAAkB,WAAW;IAC3B,+CAAS,CAAA;IACT,6CAAQ,CAAA;IACR,6CAAQ,CAAA;IACR,+CAAS,CAAA;AACX,CAAC,EALiB,WAAW,KAAX,WAAW,QAK5B;AAsBD,iEAAiE;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAA8B;IAC1D,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3B,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAA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,CAAC,KAAK,CAAC,EAAE;SACpC,EAAE,IAAI,CAAC,CAAA;IACV,CAAC;IAED;QACE,KAAK,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAU,EAAE,CAAC;YAC/D,CAAC;YAAC,aAAa,CAAC,SAAiB,CAAC,IAAI,CAAC,GAAG,UAA+B,GAAG,IAAW;gBACrF,OAAQ,IAAY,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;YACvC,CAAC,CAAA;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { defineProperty, hyphenate } from '@xrkseek/cosmokit'
|
|
2
|
+
import { Context } from './context.ts'
|
|
3
|
+
import { Fiber } from './fiber.ts'
|
|
4
|
+
import { createCallable, joinPrototype, symbols, type Tracker } from './utils.ts'
|
|
5
|
+
|
|
6
|
+
declare module './context.ts' {
|
|
7
|
+
interface Intercept {
|
|
8
|
+
logger: LoggerService.Intercept
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Logger method name and severity category. */
|
|
13
|
+
export type LoggerType = 'error' | 'info' | 'warn' | 'debug'
|
|
14
|
+
|
|
15
|
+
/** Callable shape for one logger severity method. */
|
|
16
|
+
export type LoggerMethod = (format: any, ...param: any[]) => void
|
|
17
|
+
|
|
18
|
+
/** Formatter used to resolve a printf-style placeholder. */
|
|
19
|
+
export type Formatter = (value: any, exporter: Exporter, message: Message) => any
|
|
20
|
+
|
|
21
|
+
/** Numeric severity used when exporters decide whether to emit a message. */
|
|
22
|
+
export const enum LoggerLevel {
|
|
23
|
+
ERROR = 0,
|
|
24
|
+
INFO = 1,
|
|
25
|
+
WARN = 2,
|
|
26
|
+
DEBUG = 3,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Structured log record delivered to exporters. */
|
|
30
|
+
export interface Message {
|
|
31
|
+
sn: number
|
|
32
|
+
ts: number
|
|
33
|
+
name: string
|
|
34
|
+
type: LoggerType
|
|
35
|
+
level: number
|
|
36
|
+
args: any[]
|
|
37
|
+
fiber?: WeakRef<Fiber>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Sink that receives structured log messages. */
|
|
41
|
+
export interface Exporter {
|
|
42
|
+
colors?: number | false
|
|
43
|
+
maxLength?: number
|
|
44
|
+
levels?: Record<string, number>
|
|
45
|
+
formatters?: Record<string, Formatter>
|
|
46
|
+
export(message: Message): void
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Built-in placeholder formatters used by `Logger.format()`. */
|
|
50
|
+
export const defaultFormatters: Record<string, Formatter> = {
|
|
51
|
+
s: (value) => String(value),
|
|
52
|
+
d: (value) => Math.trunc(Number(value)),
|
|
53
|
+
i: (value) => Math.trunc(Number(value)),
|
|
54
|
+
f: (value) => Number(value),
|
|
55
|
+
o: (value) => JSON.stringify(value),
|
|
56
|
+
O: (value) => JSON.stringify(value),
|
|
57
|
+
c: () => '',
|
|
58
|
+
C: (value, exporter, message) => {
|
|
59
|
+
return Logger.color(exporter, Logger.code(message.name, exporter.colors), value)
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Options used when creating a named logger facade. */
|
|
64
|
+
export interface LoggerOptions {
|
|
65
|
+
/** The logger name shown with each message. */
|
|
66
|
+
name: string
|
|
67
|
+
/** Message fields merged into every record from this logger. */
|
|
68
|
+
meta?: Partial<Message>
|
|
69
|
+
/** Default maximum level exported when an exporter has no own threshold. */
|
|
70
|
+
level?: number
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Logger facade identity, inherited message metadata, and optional minimum level. */
|
|
74
|
+
export interface Logger extends LoggerOptions {}
|
|
75
|
+
/** Logger facade severity methods. */
|
|
76
|
+
export interface Logger extends Record<LoggerType, LoggerMethod> {}
|
|
77
|
+
|
|
78
|
+
function isAggregateError(error: any): error is Error & { errors: Error[] } {
|
|
79
|
+
return error instanceof Error && Array.isArray(error['errors'])
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Logger facade for one named subsystem. */
|
|
83
|
+
export class Logger {
|
|
84
|
+
static color(exporter: Exporter, code: number, value: any, decoration = '') {
|
|
85
|
+
if (!exporter.colors) return '' + value
|
|
86
|
+
return `\u001b[3${code < 8 ? code : '8;5;' + code}${exporter.colors >= 2 ? decoration : ''}m${value}\u001b[0m`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static code(name: string, level?: false | number) {
|
|
90
|
+
let hash = 0
|
|
91
|
+
for (let i = 0; i < name.length; i++) {
|
|
92
|
+
hash = ((hash << 3) - hash) + name.charCodeAt(i) + 13
|
|
93
|
+
hash |= 0
|
|
94
|
+
}
|
|
95
|
+
const colors = !level ? [] : level >= 2 ? c256 : c16
|
|
96
|
+
return colors[Math.abs(hash) % colors.length]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static format(exporter: Exporter, message: Message): string {
|
|
100
|
+
const args = message.args.slice()
|
|
101
|
+
if (args[0] instanceof Error) {
|
|
102
|
+
args[0] = args[0].stack || args[0].message
|
|
103
|
+
args.unshift('%s')
|
|
104
|
+
} else if (typeof args[0] !== 'string') {
|
|
105
|
+
args.unshift('%o')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let format: string = args.shift()
|
|
109
|
+
format = format.replace(/%([a-zA-Z%])/g, (match, char) => {
|
|
110
|
+
if (match === '%%') return '%'
|
|
111
|
+
const formatter = exporter.formatters?.[char] ?? defaultFormatters[char]
|
|
112
|
+
if (typeof formatter === 'function') {
|
|
113
|
+
const value = args.shift()
|
|
114
|
+
return formatter(value, exporter, message)
|
|
115
|
+
}
|
|
116
|
+
return match
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
const oFormatter = exporter.formatters?.o ?? defaultFormatters.o
|
|
120
|
+
for (let arg of args) {
|
|
121
|
+
if (typeof arg === 'object' && arg) {
|
|
122
|
+
arg = oFormatter(arg, exporter, message)
|
|
123
|
+
}
|
|
124
|
+
format += ' ' + arg
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const { maxLength = 10240 } = exporter
|
|
128
|
+
return format.split(/\r?\n/g).map(line => {
|
|
129
|
+
return line.slice(0, maxLength) + (line.length > maxLength ? '...' : '')
|
|
130
|
+
}).join('\n')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
constructor(options: LoggerOptions, private service: LoggerService) {
|
|
134
|
+
Object.assign(this, options)
|
|
135
|
+
this.error = this._method('error', LoggerLevel.ERROR)
|
|
136
|
+
this.info = this._method('info', LoggerLevel.INFO)
|
|
137
|
+
this.warn = this._method('warn', LoggerLevel.WARN)
|
|
138
|
+
this.debug = this._method('debug', LoggerLevel.DEBUG)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private _method(type: LoggerType, level: number): LoggerMethod {
|
|
142
|
+
return (...args: any[]) => {
|
|
143
|
+
if (args.length === 1 && args[0] instanceof Error) {
|
|
144
|
+
if (args[0].cause) {
|
|
145
|
+
this[type](args[0].cause)
|
|
146
|
+
} else if (isAggregateError(args[0])) {
|
|
147
|
+
args[0].errors.forEach(error => this[type](error))
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const sn = ++this.service._snMessage
|
|
153
|
+
const ts = Date.now()
|
|
154
|
+
for (const exporter of this.service.exporters.values()) {
|
|
155
|
+
const targetLevel = exporter.levels?.[this.name] ?? exporter.levels?.default ?? this.level ?? LoggerLevel.INFO
|
|
156
|
+
if (targetLevel < level) continue
|
|
157
|
+
const message: Message = { sn, ts, type, level, name: this.name, ...this.meta, args }
|
|
158
|
+
exporter.export(message)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** ANSI 16-color palette indexes used for logger name coloring. */
|
|
165
|
+
export const c16 = [6, 2, 3, 4, 5, 1]
|
|
166
|
+
/** ANSI 256-color palette indexes used for logger name coloring. */
|
|
167
|
+
export const c256 = [
|
|
168
|
+
20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62,
|
|
169
|
+
63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113,
|
|
170
|
+
129, 134, 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168,
|
|
171
|
+
169, 170, 171, 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200,
|
|
172
|
+
201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, 220, 221,
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
/** Logger service configuration merged from context intercepts. */
|
|
176
|
+
export namespace LoggerService {
|
|
177
|
+
export interface Intercept {
|
|
178
|
+
name?: string
|
|
179
|
+
level?: number
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Callable `ctx.logger` service shape. */
|
|
184
|
+
export interface LoggerService extends Record<LoggerType, LoggerMethod> {
|
|
185
|
+
(name?: string): Logger
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Built-in logging service.
|
|
190
|
+
*
|
|
191
|
+
* Call `ctx.logger()` to create a named logger, or call `ctx.logger.info()`
|
|
192
|
+
* directly to log with the current fiber-derived name.
|
|
193
|
+
*/
|
|
194
|
+
export class LoggerService {
|
|
195
|
+
bufferSize = 1000
|
|
196
|
+
buffer: Message[] = []
|
|
197
|
+
ctx!: Context
|
|
198
|
+
|
|
199
|
+
_snMessage = 0
|
|
200
|
+
_snExporter = 0
|
|
201
|
+
exporters = new Map<number, Exporter>()
|
|
202
|
+
|
|
203
|
+
constructor(ctx: Context) {
|
|
204
|
+
const tracker: Tracker = {
|
|
205
|
+
property: 'ctx',
|
|
206
|
+
noShadow: true,
|
|
207
|
+
}
|
|
208
|
+
const self = createCallable('logger', joinPrototype(Object.getPrototypeOf(this), Function.prototype), tracker) as unknown as LoggerService
|
|
209
|
+
Object.assign(self, this)
|
|
210
|
+
self.ctx = ctx
|
|
211
|
+
defineProperty(self, symbols.tracker, tracker)
|
|
212
|
+
|
|
213
|
+
self.exporter({
|
|
214
|
+
colors: 3,
|
|
215
|
+
export: (message) => {
|
|
216
|
+
self.buffer.push(message)
|
|
217
|
+
if (self.buffer.length > self.bufferSize) {
|
|
218
|
+
self.buffer = self.buffer.slice(-self.bufferSize)
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
return self
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Register an exporter and dispose it with the current fiber.
|
|
228
|
+
*
|
|
229
|
+
* @param exporter — the sink that receives structured log messages.
|
|
230
|
+
* @returns a disposer that removes the exporter.
|
|
231
|
+
*/
|
|
232
|
+
exporter(exporter: Exporter) {
|
|
233
|
+
return this.ctx.effect(() => {
|
|
234
|
+
this.exporters.set(++this._snExporter, exporter)
|
|
235
|
+
return () => this.exporters.delete(this._snExporter)
|
|
236
|
+
}, 'ctx.logger.exporter()')
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private _resolveConfig(): LoggerService.Intercept {
|
|
240
|
+
let intercept = this.ctx[symbols.intercept]
|
|
241
|
+
const configs: LoggerService.Intercept[] = []
|
|
242
|
+
while ('logger' in intercept) {
|
|
243
|
+
if (Object.hasOwn(intercept, 'logger')) {
|
|
244
|
+
configs.unshift(intercept['logger'])
|
|
245
|
+
}
|
|
246
|
+
intercept = Object.getPrototypeOf(intercept)
|
|
247
|
+
}
|
|
248
|
+
return Object.assign({}, ...configs)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
[symbols.invoke](name?: string): Logger {
|
|
252
|
+
const config = this._resolveConfig()
|
|
253
|
+
const fiber = ((this.ctx as any)[symbols.shadow] ?? this.ctx).fiber
|
|
254
|
+
name ??= config.name
|
|
255
|
+
name ??= hyphenate(fiber.name)
|
|
256
|
+
return new Logger({
|
|
257
|
+
name,
|
|
258
|
+
level: config.level,
|
|
259
|
+
meta: { fiber: new WeakRef(fiber) },
|
|
260
|
+
}, this)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static {
|
|
264
|
+
for (const type of ['error', 'info', 'warn', 'debug'] as const) {
|
|
265
|
+
;(LoggerService.prototype as any)[type] = function (this: LoggerService, ...args: any[]) {
|
|
266
|
+
return (this as any)()[type](...args)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|