@klarkxy/dsh-plugin-kit 0.6.1 → 0.8.0
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/README.md +1 -1
- package/docs/README.zh-CN.md +1 -1
- package/lib/auxiliary-model-client.d.ts +4 -1
- package/lib/auxiliary-model-client.js +72 -33
- package/lib/auxiliary-model-client.js.map +1 -1
- package/lib/auxiliary-model.js +26 -2
- package/lib/auxiliary-model.js.map +1 -1
- package/lib/cli-media.js +1 -1
- package/lib/cli-process.d.ts +2 -0
- package/lib/cli-process.js +36 -2
- package/lib/cli-process.js.map +1 -1
- package/lib/client-logger.d.ts +19 -0
- package/lib/client-logger.js +153 -0
- package/lib/client-logger.js.map +1 -0
- package/lib/client-utils.d.ts +2 -1
- package/lib/client-utils.js +9 -3
- package/lib/client-utils.js.map +1 -1
- package/lib/domain.d.ts +12 -4
- package/lib/domain.js +32 -6
- package/lib/domain.js.map +1 -1
- package/lib/host-rpc.d.ts +2 -0
- package/lib/host-rpc.js +71 -2
- package/lib/host-rpc.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +2 -1
- package/lib/llm-call.d.ts +5 -1
- package/lib/llm-call.js +79 -46
- package/lib/llm-call.js.map +1 -1
- package/lib/log-shared.d.ts +2 -0
- package/lib/log-shared.js +169 -0
- package/lib/log-shared.js.map +1 -0
- package/lib/log-shared2.d.ts +72 -0
- package/lib/logger.d.ts +87 -0
- package/lib/logger.js +572 -0
- package/lib/logger.js.map +1 -0
- package/lib/model-picker.d.ts +34 -0
- package/lib/model-picker.js +96 -0
- package/lib/model-picker.js.map +1 -0
- package/lib/official-ui.d.ts +1 -1
- package/lib/official-ui.js +3 -1
- package/lib/official-ui.js.map +1 -1
- package/lib/zod.js +79 -79
- package/lib/zod.js.map +1 -1
- package/package.json +34 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-shared.js","names":[],"sources":["../src/log-shared.ts"],"sourcesContent":["export type PluginLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fault'\n\nexport const PLUGIN_LOG_LEVELS: readonly PluginLogLevel[] = ['debug', 'info', 'warn', 'error', 'fault']\nexport const DEFAULT_PLUGIN_LOG_LEVEL: PluginLogLevel = 'info'\nexport const PLUGIN_LOG_MAX_MESSAGE_CHARS = 16_000\nexport const PLUGIN_LOG_MAX_CONTEXT_CHARS = 8_000\n\nexport type PluginLogScalar = string | number | boolean | null\nexport type PluginLogContext = Record<string, PluginLogScalar | undefined>\n\nexport interface PluginLogInput {\n level: PluginLogLevel\n event: string\n message: string\n context?: PluginLogContext\n error?: unknown\n}\n\nexport interface PluginLogError {\n name: string\n message: string\n stack?: string\n code?: string\n}\n\nexport interface PluginLogEntry {\n version: 1\n at: string\n level: PluginLogLevel\n source: string\n surface: 'host' | 'client'\n profile?: string\n event: string\n message: string\n pid?: number\n context?: Record<string, PluginLogScalar>\n error?: PluginLogError\n}\n\nexport interface PluginLogger {\n readonly source: string\n readonly file: string | null\n readonly lastWriteError: string | null\n debug(event: string, message: string, context?: PluginLogContext): boolean\n info(event: string, message: string, context?: PluginLogContext): boolean\n warn(event: string, message: string, error?: unknown, context?: PluginLogContext): boolean\n error(event: string, message: string, error?: unknown, context?: PluginLogContext): boolean\n fault(event: string, message: string, error?: unknown, context?: PluginLogContext): boolean\n write(input: PluginLogInput): boolean\n child(context: PluginLogContext): PluginLogger\n}\n\nconst SOURCE_RE = /^[a-z][a-z0-9-]{0,63}$/\nconst EVENT_RE = /^[a-z][a-z0-9._-]{0,127}$/\nconst CONTEXT_KEY_RE = /^[a-zA-Z][a-zA-Z0-9._-]{0,63}$/\nconst SECRET_KEY_RE = /(?:api[_-]?key|access[_-]?token|refresh[_-]?token|bearer|authorization|cookie|set[_-]?cookie|nonce|credential|private[_-]?key|password|secret|app[_-]?secret|client[_-]?secret|z_c0|d_c0)$/i\n\nconst CHAT_PAYLOAD_RE =\n /\"role\"\\s*:\\s*\"(?:system|user|assistant|tool)\"|\"(?:messages|content|prompt|input_text|input_image|image_url)\"\\s*:\\s*[\\[{\"']/i\nconst CREDENTIAL_BODY_RE =\n /-----BEGIN (?:RSA |EC |OPENSSH |PRIVATE )?PRIVATE KEY-----|\"type\"\\s*:\\s*\"service_account\"|credentials\\.json|\\.dsh[/\\\\](?:credentials|auth)/i\nconst AUTH_HEADER_RE = /\\b(Authorization|Proxy-Authorization|Cookie|Set-Cookie)\\s*:\\s*[^\\r\\n]*/gi\nconst BEARER_RE = /\\bBearer\\s+[A-Za-z0-9._\\-+=/]{8,}/g\nconst SECRET_FIELD_RE =\n /([\"']?(?:api[_-]?key|access[_-]?token|refresh[_-]?token|token|bearer|authorization|cookie|set-cookie|nonce|credential|private[_-]?key|password|secret|app[_-]?secret|client[_-]?secret|password|z_c0|d_c0)[\"']?\\s*[:=]\\s*)(?:\"(?:\\\\.|[^\"\\\\])*\"|'(?:\\\\.|[^'\\\\])*'|[^\\s,&;}]+)/gi\nconst SECRET_QUERY_RE =\n /([?&](?:token|api[_-]?key|key|secret|password|bootstrap|code|sig|signature|credential|password)=)[^\\s&#\"']+/gi\nconst URL_CREDENTIAL_RE = /\\b(https?:\\/\\/)[^\\s/:@]+:[^\\s/@]+@/gi\nconst BOOTSTRAP_RE = /\\/bootstrap\\/[^\\s\"'?&#]+/gi\nconst KNOWN_TOKEN_RE = /\\b(?:sk-[A-Za-z0-9_-]{10,}|gh[pousr]_[A-Za-z0-9_]{16,}|github_pat_[A-Za-z0-9_]{20,}|tvly-[A-Za-z0-9_-]{10,}|AKIA[0-9A-Z]{16})\\b/g\nconst PATH_RE = /(?:[A-Za-z]:\\\\|\\\\\\\\)[^\\s\"'`<>|]+|(?:\\/(?:home|Users|tmp|var|root)\\/|~\\/)[^\\s\"'`<>|]+/g\n\nexport function isPluginLogLevel(value: unknown): value is PluginLogLevel {\n return typeof value === 'string' && (PLUGIN_LOG_LEVELS as readonly string[]).includes(value)\n}\n\nexport function pluginLogLevelEnabled(level: PluginLogLevel, minimum: PluginLogLevel): boolean {\n return PLUGIN_LOG_LEVELS.indexOf(level) >= PLUGIN_LOG_LEVELS.indexOf(minimum)\n}\n\nexport function normalizePluginLogSource(raw: string): string {\n const stripped = String(raw || '').trim().replace(/^@[^/]+\\//, '').toLowerCase()\n .replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '')\n const prefixed = /^[a-z]/.test(stripped) ? stripped : `p-${stripped}`\n const bounded = prefixed.slice(0, 64).replace(/-+$/g, '')\n return SOURCE_RE.test(bounded) ? bounded : 'dsh-plugin'\n}\n\nexport function normalizePluginLogEvent(raw: string): string {\n const cleaned = String(raw || '').trim().toLowerCase()\n .replace(/[^a-z0-9._-]+/g, '-').replace(/^[^a-z]+/, '').slice(0, 128)\n return EVENT_RE.test(cleaned) ? cleaned : 'plugin.event'\n}\n\n/**\n * Parse a level specification like `debug` or `dsh-zhihu=debug,dsh-dot:warn,info`.\n * Source-specific rules win over a bare fallback level.\n */\nexport function parsePluginLogLevel(\n spec: string | undefined | null,\n source?: string,\n fallback: PluginLogLevel = DEFAULT_PLUGIN_LOG_LEVEL,\n): PluginLogLevel {\n if (!spec || typeof spec !== 'string') return fallback\n const normalizedSource = source ? normalizePluginLogSource(source) : undefined\n let wildcard: PluginLogLevel | undefined\n for (const token of spec.split(',').map(part => part.trim()).filter(Boolean)) {\n const lowered = token.toLowerCase()\n if (isPluginLogLevel(lowered)) {\n wildcard = lowered\n continue\n }\n const match = /^([^=:]+)[=:]([a-z]+)$/i.exec(token)\n if (!match) continue\n const target = match[1]!.trim()\n const candidate = match[2]!.trim().toLowerCase()\n if (!isPluginLogLevel(candidate)) continue\n if (target === '*') {\n wildcard = candidate\n continue\n }\n if (normalizedSource && normalizePluginLogSource(target) === normalizedSource) {\n return candidate\n }\n }\n return wildcard ?? fallback\n}\n\nexport function sanitizePluginLogText(text: string, maxChars = PLUGIN_LOG_MAX_MESSAGE_CHARS): string {\n if (!text) return ''\n if (CREDENTIAL_BODY_RE.test(text)) return '[omitted credential material]'\n if (CHAT_PAYLOAD_RE.test(text)) return '[omitted chat payload]'\n const redacted = text\n .replace(AUTH_HEADER_RE, '$1: [redacted]')\n .replace(BEARER_RE, 'Bearer [redacted]')\n .replace(SECRET_FIELD_RE, (full, prefix: string) => {\n const value = full.slice(prefix.length)\n if (value.startsWith('\"')) return `${prefix}\"[redacted]\"`\n if (value.startsWith(\"'\")) return `${prefix}'[redacted]'`\n return `${prefix}[redacted]`\n })\n .replace(SECRET_QUERY_RE, '$1[redacted]')\n .replace(URL_CREDENTIAL_RE, '$1[redacted]@')\n .replace(BOOTSTRAP_RE, '/bootstrap/[redacted]')\n .replace(KNOWN_TOKEN_RE, '[redacted]')\n .replace(PATH_RE, '[path]')\n return truncateLogText(redacted, maxChars)\n}\n\nexport function sanitizePluginLogContext(\n input: PluginLogContext | undefined,\n): Record<string, PluginLogScalar> | undefined {\n if (!input) return undefined\n const output: Record<string, PluginLogScalar> = {}\n for (const [key, value] of Object.entries(input).slice(0, 32)) {\n if (value === undefined || !CONTEXT_KEY_RE.test(key)) continue\n if (typeof value === 'number' && !Number.isFinite(value)) continue\n if (SECRET_KEY_RE.test(key)) {\n output[key] = '[redacted]'\n continue\n }\n output[key] = typeof value === 'string' ? sanitizePluginLogText(value, 1_000) : value\n }\n if (!Object.keys(output).length) return undefined\n const encoded = JSON.stringify(output)\n if (encoded.length <= PLUGIN_LOG_MAX_CONTEXT_CHARS) return output\n return { omitted: true, reason: 'Diagnostic context exceeded its size limit.' }\n}\n\nexport function sanitizePluginLogError(error: unknown): PluginLogError | undefined {\n if (error === undefined) return undefined\n const row = error && typeof error === 'object'\n ? error as { name?: unknown; message?: unknown; stack?: unknown; code?: unknown }\n : {}\n const rawMessage = typeof row.message === 'string' ? row.message : String(error)\n const result: PluginLogError = {\n name: typeof row.name === 'string' && row.name.trim() ? truncateLogText(row.name.trim(), 100) : 'Error',\n message: sanitizePluginLogText(rawMessage) || 'Unknown error',\n }\n if (typeof row.stack === 'string' && row.stack.trim()) {\n result.stack = sanitizePluginLogText(row.stack, 24_000)\n }\n if (typeof row.code === 'string' && /^[A-Za-z0-9_./:-]{1,100}$/.test(row.code)) {\n result.code = row.code\n } else if (typeof row.code === 'number' && Number.isFinite(row.code)) {\n result.code = String(row.code)\n }\n return result\n}\n\nexport function mergePluginLogContext(\n base: PluginLogContext | undefined,\n extra: PluginLogContext | undefined,\n): PluginLogContext | undefined {\n if (!base) return extra\n if (!extra) return base\n return { ...base, ...extra }\n}\n\nexport function buildPluginLogEntry(\n input: PluginLogInput,\n meta: {\n at: Date\n source: string\n surface: 'host' | 'client'\n profile?: string\n pid?: number\n correlation?: PluginLogContext\n },\n): PluginLogEntry {\n const entry: PluginLogEntry = {\n version: 1,\n at: meta.at.toISOString(),\n level: isPluginLogLevel(input.level) ? input.level : 'info',\n source: normalizePluginLogSource(meta.source),\n surface: meta.surface,\n ...(meta.profile ? { profile: meta.profile } : {}),\n event: normalizePluginLogEvent(input.event),\n message: sanitizePluginLogText(input.message || 'No diagnostic message was provided.', PLUGIN_LOG_MAX_MESSAGE_CHARS),\n ...(meta.pid !== undefined ? { pid: meta.pid } : {}),\n }\n const context = sanitizePluginLogContext(mergePluginLogContext(meta.correlation, input.context))\n if (context) entry.context = context\n const error = sanitizePluginLogError(input.error)\n if (error) entry.error = error\n return entry\n}\n\nexport function createChildPluginLogger(parent: PluginLogger, bound: PluginLogContext): PluginLogger {\n return {\n get source() { return parent.source },\n get file() { return parent.file },\n get lastWriteError() { return parent.lastWriteError },\n debug: (event, message, context) => parent.debug(event, message, mergePluginLogContext(bound, context)),\n info: (event, message, context) => parent.info(event, message, mergePluginLogContext(bound, context)),\n warn: (event, message, error, context) => parent.warn(event, message, error, mergePluginLogContext(bound, context)),\n error: (event, message, error, context) => parent.error(event, message, error, mergePluginLogContext(bound, context)),\n fault: (event, message, error, context) => parent.fault(event, message, error, mergePluginLogContext(bound, context)),\n write: input => parent.write({ ...input, context: mergePluginLogContext(bound, input.context) }),\n child: next => createChildPluginLogger(parent, mergePluginLogContext(bound, next) ?? {}),\n }\n}\n\nexport function truncateLogText(text: string, maxChars: number): string {\n if (text.length <= maxChars) return text\n const marker = '[truncated]\\n'\n if (maxChars <= marker.length) return text.slice(0, Math.max(0, maxChars))\n return `${marker}${text.slice(-(maxChars - marker.length))}`\n}\n"],"mappings":";AAEA,MAAa,oBAA+C;CAAC;CAAS;CAAQ;CAAQ;CAAS;AAAO;AACtG,MAAa,2BAA2C;AACxD,MAAa,+BAA+B;AAC5C,MAAa,+BAA+B;AA+C5C,MAAM,YAAY;AAClB,MAAM,WAAW;AACjB,MAAM,iBAAiB;AACvB,MAAM,gBAAgB;AAEtB,MAAM,kBACJ;AACF,MAAM,qBACJ;AACF,MAAM,iBAAiB;AACvB,MAAM,YAAY;AAClB,MAAM,kBACJ;AACF,MAAM,kBACJ;AACF,MAAM,oBAAoB;AAC1B,MAAM,eAAe;AACrB,MAAM,iBAAiB;AACvB,MAAM,UAAU;AAEhB,SAAgB,iBAAiB,OAAyC;CACxE,OAAO,OAAO,UAAU,YAAa,kBAAwC,SAAS,KAAK;AAC7F;AAEA,SAAgB,sBAAsB,OAAuB,SAAkC;CAC7F,OAAO,kBAAkB,QAAQ,KAAK,KAAK,kBAAkB,QAAQ,OAAO;AAC9E;AAEA,SAAgB,yBAAyB,KAAqB;CAC5D,MAAM,WAAW,OAAO,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,aAAa,EAAE,CAAC,CAAC,YAAY,CAAC,CAC7E,QAAQ,gBAAgB,GAAG,CAAC,CAAC,QAAQ,YAAY,EAAE;CAEtD,MAAM,WADW,SAAS,KAAK,QAAQ,IAAI,WAAW,KAAK,WAAA,CAClC,MAAM,GAAG,EAAE,CAAC,CAAC,QAAQ,QAAQ,EAAE;CACxD,OAAO,UAAU,KAAK,OAAO,IAAI,UAAU;AAC7C;AAEA,SAAgB,wBAAwB,KAAqB;CAC3D,MAAM,UAAU,OAAO,OAAO,EAAE,C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,iBAAiB;GAAE,OAAO,OAAO;EAAe;EACpD,QAAQ,OAAO,SAAS,YAAY,OAAO,MAAM,OAAO,SAAS,sBAAsB,OAAO,OAAO,CAAC;EACtG,OAAO,OAAO,SAAS,YAAY,OAAO,KAAK,OAAO,SAAS,sBAAsB,OAAO,OAAO,CAAC;EACpG,OAAO,OAAO,SAAS,OAAO,YAAY,OAAO,KAAK,OAAO,SAAS,OAAO,sBAAsB,OAAO,OAAO,CAAC;EAClH,QAAQ,OAAO,SAAS,OAAO,YAAY,OAAO,MAAM,OAAO,SAAS,OAAO,sBAAsB,OAAO,OAAO,CAAC;EACpH,QAAQ,OAAO,SAAS,OAAO,YAAY,OAAO,MAAM,OAAO,SAAS,OAAO,sBAAsB,OAAO,OAAO,CAAC;EACpH,QAAO,UAAS,OAAO,MAAM;GAAE,GAAG;GAAO,SAAS,sBAAsB,OAAO,MAAM,OAAO;EAAE,CAAC;EAC/F,QAAO,SAAQ,wBAAwB,QAAQ,sBAAsB,OAAO,IAAI,KAAK,CAAC,CAAC;CACzF;AACF;AAEA,SAAgB,gBAAgB,MAAc,UAA0B;CACtE,IAAI,KAAK,UAAU,UAAU,OAAO;CACpC,MAAM,SAAS;CACf,IAAI,YAAY,IAAe,OAAO,KAAK,MAAM,GAAG,KAAK,IAAI,GAAG,QAAQ,CAAC;CACzE,OAAO,GAAG,SAAS,KAAK,MAAM,EAAE,WAAW,GAAc;AAC3D"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//#region src/log-shared.d.ts
|
|
2
|
+
type PluginLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fault';
|
|
3
|
+
declare const PLUGIN_LOG_LEVELS: readonly PluginLogLevel[];
|
|
4
|
+
declare const DEFAULT_PLUGIN_LOG_LEVEL: PluginLogLevel;
|
|
5
|
+
declare const PLUGIN_LOG_MAX_MESSAGE_CHARS = 16000;
|
|
6
|
+
declare const PLUGIN_LOG_MAX_CONTEXT_CHARS = 8000;
|
|
7
|
+
type PluginLogScalar = string | number | boolean | null;
|
|
8
|
+
type PluginLogContext = Record<string, PluginLogScalar | undefined>;
|
|
9
|
+
interface PluginLogInput {
|
|
10
|
+
level: PluginLogLevel;
|
|
11
|
+
event: string;
|
|
12
|
+
message: string;
|
|
13
|
+
context?: PluginLogContext;
|
|
14
|
+
error?: unknown;
|
|
15
|
+
}
|
|
16
|
+
interface PluginLogError {
|
|
17
|
+
name: string;
|
|
18
|
+
message: string;
|
|
19
|
+
stack?: string;
|
|
20
|
+
code?: string;
|
|
21
|
+
}
|
|
22
|
+
interface PluginLogEntry {
|
|
23
|
+
version: 1;
|
|
24
|
+
at: string;
|
|
25
|
+
level: PluginLogLevel;
|
|
26
|
+
source: string;
|
|
27
|
+
surface: 'host' | 'client';
|
|
28
|
+
profile?: string;
|
|
29
|
+
event: string;
|
|
30
|
+
message: string;
|
|
31
|
+
pid?: number;
|
|
32
|
+
context?: Record<string, PluginLogScalar>;
|
|
33
|
+
error?: PluginLogError;
|
|
34
|
+
}
|
|
35
|
+
interface PluginLogger {
|
|
36
|
+
readonly source: string;
|
|
37
|
+
readonly file: string | null;
|
|
38
|
+
readonly lastWriteError: string | null;
|
|
39
|
+
debug(event: string, message: string, context?: PluginLogContext): boolean;
|
|
40
|
+
info(event: string, message: string, context?: PluginLogContext): boolean;
|
|
41
|
+
warn(event: string, message: string, error?: unknown, context?: PluginLogContext): boolean;
|
|
42
|
+
error(event: string, message: string, error?: unknown, context?: PluginLogContext): boolean;
|
|
43
|
+
fault(event: string, message: string, error?: unknown, context?: PluginLogContext): boolean;
|
|
44
|
+
write(input: PluginLogInput): boolean;
|
|
45
|
+
child(context: PluginLogContext): PluginLogger;
|
|
46
|
+
}
|
|
47
|
+
declare function isPluginLogLevel(value: unknown): value is PluginLogLevel;
|
|
48
|
+
declare function pluginLogLevelEnabled(level: PluginLogLevel, minimum: PluginLogLevel): boolean;
|
|
49
|
+
declare function normalizePluginLogSource(raw: string): string;
|
|
50
|
+
declare function normalizePluginLogEvent(raw: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Parse a level specification like `debug` or `dsh-zhihu=debug,dsh-dot:warn,info`.
|
|
53
|
+
* Source-specific rules win over a bare fallback level.
|
|
54
|
+
*/
|
|
55
|
+
declare function parsePluginLogLevel(spec: string | undefined | null, source?: string, fallback?: PluginLogLevel): PluginLogLevel;
|
|
56
|
+
declare function sanitizePluginLogText(text: string, maxChars?: number): string;
|
|
57
|
+
declare function sanitizePluginLogContext(input: PluginLogContext | undefined): Record<string, PluginLogScalar> | undefined;
|
|
58
|
+
declare function sanitizePluginLogError(error: unknown): PluginLogError | undefined;
|
|
59
|
+
declare function mergePluginLogContext(base: PluginLogContext | undefined, extra: PluginLogContext | undefined): PluginLogContext | undefined;
|
|
60
|
+
declare function buildPluginLogEntry(input: PluginLogInput, meta: {
|
|
61
|
+
at: Date;
|
|
62
|
+
source: string;
|
|
63
|
+
surface: 'host' | 'client';
|
|
64
|
+
profile?: string;
|
|
65
|
+
pid?: number;
|
|
66
|
+
correlation?: PluginLogContext;
|
|
67
|
+
}): PluginLogEntry;
|
|
68
|
+
declare function createChildPluginLogger(parent: PluginLogger, bound: PluginLogContext): PluginLogger;
|
|
69
|
+
declare function truncateLogText(text: string, maxChars: number): string;
|
|
70
|
+
//#endregion
|
|
71
|
+
export { truncateLogText as C, sanitizePluginLogText as S, normalizePluginLogSource as _, PluginLogContext as a, sanitizePluginLogContext as b, PluginLogInput as c, PluginLogger as d, buildPluginLogEntry as f, normalizePluginLogEvent as g, mergePluginLogContext as h, PLUGIN_LOG_MAX_MESSAGE_CHARS as i, PluginLogLevel as l, isPluginLogLevel as m, PLUGIN_LOG_LEVELS as n, PluginLogEntry as o, createChildPluginLogger as p, PLUGIN_LOG_MAX_CONTEXT_CHARS as r, PluginLogError as s, DEFAULT_PLUGIN_LOG_LEVEL as t, PluginLogScalar as u, parsePluginLogLevel as v, sanitizePluginLogError as x, pluginLogLevelEnabled as y };
|
|
72
|
+
//# sourceMappingURL=log-shared2.d.ts.map
|
package/lib/logger.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { C as truncateLogText, S as sanitizePluginLogText, _ as normalizePluginLogSource, a as PluginLogContext, b as sanitizePluginLogContext, c as PluginLogInput, d as PluginLogger, f as buildPluginLogEntry, g as normalizePluginLogEvent, h as mergePluginLogContext, i as PLUGIN_LOG_MAX_MESSAGE_CHARS, l as PluginLogLevel, m as isPluginLogLevel, n as PLUGIN_LOG_LEVELS, o as PluginLogEntry, p as createChildPluginLogger, r as PLUGIN_LOG_MAX_CONTEXT_CHARS, s as PluginLogError, t as DEFAULT_PLUGIN_LOG_LEVEL, u as PluginLogScalar, v as parsePluginLogLevel, x as sanitizePluginLogError, y as pluginLogLevelEnabled } from "./log-shared2.js";
|
|
2
|
+
//#region src/logger.d.ts
|
|
3
|
+
declare const PLUGIN_LOG_MAX_AGE_MS: number;
|
|
4
|
+
declare const PLUGIN_LOG_MAX_FILE_BYTES: number;
|
|
5
|
+
declare const PLUGIN_LOG_MAX_ARCHIVE_BYTES: number;
|
|
6
|
+
declare const PLUGIN_LOG_RECENT_LIMIT = 200;
|
|
7
|
+
interface RotatingPluginLoggerOptions {
|
|
8
|
+
directory?: string;
|
|
9
|
+
home?: string;
|
|
10
|
+
profile?: string;
|
|
11
|
+
minimumLevel?: PluginLogLevel;
|
|
12
|
+
env?: NodeJS.ProcessEnv;
|
|
13
|
+
now?: () => Date;
|
|
14
|
+
pid?: number;
|
|
15
|
+
maxFileBytes?: number;
|
|
16
|
+
maxArchiveBytes?: number;
|
|
17
|
+
maxAgeMs?: number;
|
|
18
|
+
recentLimit?: number;
|
|
19
|
+
forwardHostWarnError?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface InstallPluginLoggerOptions extends RotatingPluginLoggerOptions {
|
|
22
|
+
loadedContext?: PluginLogContext;
|
|
23
|
+
}
|
|
24
|
+
declare function safeProfileName(profile: string | undefined | null): string;
|
|
25
|
+
declare function pluginLogDirectory(home: string, profile?: string): string;
|
|
26
|
+
declare function resolveHostLogTarget(ctx: unknown, options?: Pick<RotatingPluginLoggerOptions, 'directory' | 'home' | 'profile' | 'env'>): {
|
|
27
|
+
directory: string | null;
|
|
28
|
+
anchor: string | null;
|
|
29
|
+
profile?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Synchronous, append-only rotating JSONL logger modeled on DSH Spaces
|
|
33
|
+
* diagnostics: 7-day or 100 MiB active rotation, 7-day / 100 MiB archive
|
|
34
|
+
* retention, secret and path redaction, and non-throwing write resilience.
|
|
35
|
+
*/
|
|
36
|
+
declare class RotatingPluginLogger implements PluginLogger {
|
|
37
|
+
readonly source: string;
|
|
38
|
+
readonly file: string | null;
|
|
39
|
+
private lastError;
|
|
40
|
+
private size;
|
|
41
|
+
private openedAt;
|
|
42
|
+
private initialized;
|
|
43
|
+
private writing;
|
|
44
|
+
private sequence;
|
|
45
|
+
private loggedWriteFailure;
|
|
46
|
+
private readonly recent;
|
|
47
|
+
private readonly directory;
|
|
48
|
+
private readonly anchor;
|
|
49
|
+
private readonly profile;
|
|
50
|
+
private readonly minimum;
|
|
51
|
+
private readonly now;
|
|
52
|
+
private readonly pid;
|
|
53
|
+
private readonly maxFileBytes;
|
|
54
|
+
private readonly maxArchiveBytes;
|
|
55
|
+
private readonly maxAgeMs;
|
|
56
|
+
private readonly recentLimit;
|
|
57
|
+
constructor(source: string, options?: RotatingPluginLoggerOptions & {
|
|
58
|
+
anchor?: string | null;
|
|
59
|
+
});
|
|
60
|
+
get lastWriteError(): string | null;
|
|
61
|
+
recentEntries(limit?: number): PluginLogEntry[];
|
|
62
|
+
debug(event: string, message: string, context?: PluginLogContext): boolean;
|
|
63
|
+
info(event: string, message: string, context?: PluginLogContext): boolean;
|
|
64
|
+
warn(event: string, message: string, error?: unknown, context?: PluginLogContext): boolean;
|
|
65
|
+
error(event: string, message: string, error?: unknown, context?: PluginLogContext): boolean;
|
|
66
|
+
fault(event: string, message: string, error?: unknown, context?: PluginLogContext): boolean;
|
|
67
|
+
child(context: PluginLogContext): PluginLogger;
|
|
68
|
+
write(input: PluginLogInput): boolean;
|
|
69
|
+
private pushRecent;
|
|
70
|
+
private prepare;
|
|
71
|
+
private rotate;
|
|
72
|
+
private rotateStaleActive;
|
|
73
|
+
private prune;
|
|
74
|
+
private openManagedDirectory;
|
|
75
|
+
private regularFile;
|
|
76
|
+
}
|
|
77
|
+
declare function createPluginLogger(ctxOrSource: unknown, maybeSource?: string | RotatingPluginLoggerOptions, maybeOptions?: RotatingPluginLoggerOptions): PluginLogger;
|
|
78
|
+
declare function installPluginLogger(ctx: unknown, source: string, options?: InstallPluginLoggerOptions): PluginLogger;
|
|
79
|
+
declare function nextPluginOperationId(prefix?: string): string;
|
|
80
|
+
declare function currentPluginLogContext(): PluginLogContext | undefined;
|
|
81
|
+
declare function withPluginLogContext<T>(context: PluginLogContext, action: () => T): T;
|
|
82
|
+
declare function pluginLogStep<T>(logger: PluginLogger, step: string, context: PluginLogContext | undefined, action: () => Promise<T>, completedLevel?: PluginLogLevel): Promise<T>;
|
|
83
|
+
declare function pluginLogSyncStep<T>(logger: PluginLogger, step: string, context: PluginLogContext | undefined, action: () => T, completedLevel?: PluginLogLevel): T;
|
|
84
|
+
declare function readPluginLogTail(file: string, maxBytes?: number): string;
|
|
85
|
+
//#endregion
|
|
86
|
+
export { DEFAULT_PLUGIN_LOG_LEVEL, InstallPluginLoggerOptions, PLUGIN_LOG_LEVELS, PLUGIN_LOG_MAX_AGE_MS, PLUGIN_LOG_MAX_ARCHIVE_BYTES, PLUGIN_LOG_MAX_CONTEXT_CHARS, PLUGIN_LOG_MAX_FILE_BYTES, PLUGIN_LOG_MAX_MESSAGE_CHARS, PLUGIN_LOG_RECENT_LIMIT, PluginLogContext, PluginLogEntry, PluginLogError, PluginLogInput, PluginLogLevel, PluginLogScalar, PluginLogger, RotatingPluginLogger, RotatingPluginLoggerOptions, buildPluginLogEntry, createChildPluginLogger, createPluginLogger, currentPluginLogContext, installPluginLogger, isPluginLogLevel, mergePluginLogContext, nextPluginOperationId, normalizePluginLogEvent, normalizePluginLogSource, parsePluginLogLevel, pluginLogDirectory, pluginLogLevelEnabled, pluginLogStep, pluginLogSyncStep, readPluginLogTail, resolveHostLogTarget, safeProfileName, sanitizePluginLogContext, sanitizePluginLogError, sanitizePluginLogText, truncateLogText, withPluginLogContext };
|
|
87
|
+
//# sourceMappingURL=logger.d.ts.map
|