@deepmaid/maid-logger 0.1.0-alpha.1 → 0.1.0-alpha.3
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/lib/index.d.ts +97 -65
- package/lib/index.js +60 -1
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+cosmokit@1.
|
|
1
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+cosmokit@1.9.0/node_modules/@deepseek-ai/cosmokit/lib/types/misc.d.ts
|
|
2
2
|
/** String/symbol keyed dictionary type. */
|
|
3
3
|
type Dict<T = any, K extends string | symbol = string> = { [key in K]: T; };
|
|
4
4
|
/** Wrap a value in `Promise`, preserving the resolved type of existing promises. */
|
|
@@ -83,7 +83,7 @@ declare namespace StandardSchemaV1 {
|
|
|
83
83
|
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
84
84
|
}
|
|
85
85
|
//#endregion
|
|
86
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.
|
|
86
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0_@deepseek-ai+cordis-plugin-include@1.1.0_@deepseek-ai+cordis-plugin-loader@1.1.0/node_modules/@deepseek-ai/cordis/lib/types/utils.d.ts
|
|
87
87
|
/** Ordered collection of disposable values with O(1) deletion by value. */
|
|
88
88
|
declare class DisposableList<T extends WeakKey> {
|
|
89
89
|
private sn;
|
|
@@ -98,6 +98,7 @@ declare class DisposableList<T extends WeakKey> {
|
|
|
98
98
|
/** Shared symbols used to avoid public property-name collisions. */
|
|
99
99
|
declare const symbols: {
|
|
100
100
|
shadow: symbol;
|
|
101
|
+
caller: symbol;
|
|
101
102
|
receiver: symbol;
|
|
102
103
|
original: symbol;
|
|
103
104
|
metadata: symbol;
|
|
@@ -116,7 +117,7 @@ declare const symbols: {
|
|
|
116
117
|
resolveConfig: typeof Service.resolveConfig;
|
|
117
118
|
};
|
|
118
119
|
//#endregion
|
|
119
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.
|
|
120
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0_@deepseek-ai+cordis-plugin-include@1.1.0_@deepseek-ai+cordis-plugin-loader@1.1.0/node_modules/@deepseek-ai/cordis/lib/types/registry.d.ts
|
|
120
121
|
/**
|
|
121
122
|
* Service dependency declaration accepted by plugins and the `@Inject`
|
|
122
123
|
* decorator.
|
|
@@ -308,7 +309,7 @@ declare class RegistryService {
|
|
|
308
309
|
plugin(plugin: Plugin, config?: any, getOuterStack?: () => string[]): Fiber & PromiseLike<Fiber>;
|
|
309
310
|
}
|
|
310
311
|
//#endregion
|
|
311
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.
|
|
312
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0_@deepseek-ai+cordis-plugin-include@1.1.0_@deepseek-ai+cordis-plugin-loader@1.1.0/node_modules/@deepseek-ai/cordis/lib/types/reflect.d.ts
|
|
312
313
|
declare module './context.ts' {
|
|
313
314
|
interface Context {
|
|
314
315
|
/**
|
|
@@ -395,14 +396,21 @@ declare namespace Property {
|
|
|
395
396
|
}
|
|
396
397
|
/** Concrete service implementation record stored in the root reflect service. */
|
|
397
398
|
interface Impl {
|
|
399
|
+
/** Unique identity of this provision. */
|
|
400
|
+
uid: number;
|
|
398
401
|
/** The service name. */
|
|
399
402
|
name: string;
|
|
400
|
-
/** The
|
|
401
|
-
|
|
403
|
+
/** The providing context, including its service isolation. */
|
|
404
|
+
ctx: Context;
|
|
405
|
+
/** Fibers retaining this implementation until their teardown finishes. */
|
|
406
|
+
dependents: Set<Fiber>;
|
|
407
|
+
/** Wake a provision disposer after its final dependent unloads. */
|
|
408
|
+
release?: () => void;
|
|
402
409
|
/** The current service value. */
|
|
403
410
|
value?: any;
|
|
404
411
|
/** Optional availability predicate consulted before dependents may load. */
|
|
405
412
|
check?: () => boolean;
|
|
413
|
+
isolate: symbol;
|
|
406
414
|
}
|
|
407
415
|
/**
|
|
408
416
|
* Reflection and service-resolution layer installed as `ctx.reflect`.
|
|
@@ -418,6 +426,7 @@ declare class ReflectService {
|
|
|
418
426
|
store: Dict<Impl, symbol>;
|
|
419
427
|
/** Declared context properties (services and accessors), by name. */
|
|
420
428
|
props: Dict<Property>;
|
|
429
|
+
private _implCounter;
|
|
421
430
|
constructor(ctx: Context);
|
|
422
431
|
/**
|
|
423
432
|
* Read a service from the store without the inject requirement.
|
|
@@ -455,9 +464,8 @@ declare class ReflectService {
|
|
|
455
464
|
*
|
|
456
465
|
* @param names — the service names that changed.
|
|
457
466
|
* @param filter — restricts notification to matching isolation scopes.
|
|
458
|
-
* @returns the fibers whose dependency state was refreshed.
|
|
459
467
|
*/
|
|
460
|
-
notify(names: string[], filter?: (ctx: Context, name: string) => boolean):
|
|
468
|
+
notify(names: string[], filter?: (ctx: Context, name: string) => boolean): void;
|
|
461
469
|
/**
|
|
462
470
|
* Define a computed context property backed by get/set hooks.
|
|
463
471
|
*
|
|
@@ -492,7 +500,7 @@ declare class ReflectService {
|
|
|
492
500
|
bind<T extends Function>(callback: T): T;
|
|
493
501
|
}
|
|
494
502
|
//#endregion
|
|
495
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.
|
|
503
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0_@deepseek-ai+cordis-plugin-include@1.1.0_@deepseek-ai+cordis-plugin-loader@1.1.0/node_modules/@deepseek-ai/cordis/lib/types/fiber.d.ts
|
|
496
504
|
declare module './context.ts' {
|
|
497
505
|
interface Context extends Pick<Fiber, 'effect'> {
|
|
498
506
|
/** The fiber (plugin runtime instance) that owns this context. */
|
|
@@ -545,7 +553,7 @@ declare const enum FiberState {
|
|
|
545
553
|
/**
|
|
546
554
|
* Runtime instance of one plugin application.
|
|
547
555
|
*
|
|
548
|
-
* A fiber tracks dependency state,
|
|
556
|
+
* A fiber tracks dependency state, raw and effective config, lifecycle effects, and
|
|
549
557
|
* cleanup for the plugin context returned by `ctx.plugin()`.
|
|
550
558
|
*/
|
|
551
559
|
declare class Fiber {
|
|
@@ -556,24 +564,28 @@ declare class Fiber {
|
|
|
556
564
|
uid: number | null;
|
|
557
565
|
/** The context this fiber's plugin runs in (extends the parent context). */
|
|
558
566
|
readonly ctx: Context;
|
|
559
|
-
/**
|
|
567
|
+
/** Raw plugin input retained for the next activation. */
|
|
560
568
|
config: any;
|
|
561
|
-
/** The raw plugin config, re-resolved before each activation. */
|
|
562
|
-
_config: any;
|
|
563
569
|
/** Current lifecycle state; transitions emit `internal/status`. */
|
|
564
570
|
state: FiberState;
|
|
565
571
|
/** Dispose this fiber: unload the plugin, then settle once cleanup finished. */
|
|
566
572
|
readonly dispose: () => Promise<void>;
|
|
567
|
-
/**
|
|
568
|
-
|
|
573
|
+
/** Required implementations retained through dependent teardown. */
|
|
574
|
+
committed: Readonly<Dict<Impl>> | undefined;
|
|
575
|
+
/** Service implementations owned by this fiber, including isolated provisions. */
|
|
576
|
+
readonly provisions: Set<Impl>;
|
|
569
577
|
/** The in-flight load/unload transition, if one is currently running. */
|
|
570
578
|
inertia: Promise<void> | undefined;
|
|
571
579
|
readonly _hooks: Dict<DisposableList<Function>>;
|
|
572
580
|
readonly _disposables: DisposableList<Disposable<any>>;
|
|
573
581
|
protected context: Context;
|
|
574
582
|
private _error;
|
|
583
|
+
private _revision;
|
|
584
|
+
private _configRevision;
|
|
585
|
+
private _effectiveConfig;
|
|
575
586
|
private _runner;
|
|
576
587
|
private _store;
|
|
588
|
+
private _release;
|
|
577
589
|
/**
|
|
578
590
|
* Create a fiber. Plugin authors normally obtain fibers from `ctx.plugin()`
|
|
579
591
|
* rather than constructing them directly.
|
|
@@ -622,7 +634,25 @@ declare class Fiber {
|
|
|
622
634
|
_checkImpl(name: string): boolean | undefined;
|
|
623
635
|
_refresh(): void;
|
|
624
636
|
private _setEpoch;
|
|
625
|
-
|
|
637
|
+
/** Raw input retained for the next activation, without evaluating expressions or validating it. */
|
|
638
|
+
get rawConfig(): unknown;
|
|
639
|
+
/** Retain raw input without changing the running config or triggering an update. */
|
|
640
|
+
set rawConfig(config: unknown);
|
|
641
|
+
/**
|
|
642
|
+
* The object passed to plugin activation or the latest successful update that retained the instance.
|
|
643
|
+
* Candidate resolution does not publish it; volatile updates retain its references.
|
|
644
|
+
* Undefined before activation and readable after unload; callers requiring a live instance check `state`.
|
|
645
|
+
*/
|
|
646
|
+
get effectiveConfig(): unknown;
|
|
647
|
+
/**
|
|
648
|
+
* Evaluate and validate a candidate using this fiber's `internal/config` hooks and runtime schema.
|
|
649
|
+
* Does not publish the result, replace raw input, or commit running volatile references.
|
|
650
|
+
* Required injections must be available when a hook uses them.
|
|
651
|
+
* @param config Raw candidate input.
|
|
652
|
+
* @returns The candidate's resolved config, retaining the schema's result identity.
|
|
653
|
+
* @throws {ValidationError} when the runtime schema rejects the candidate; hook errors propagate.
|
|
654
|
+
*/
|
|
655
|
+
resolveConfig(config: unknown): unknown;
|
|
626
656
|
private _reload;
|
|
627
657
|
private _unload;
|
|
628
658
|
/**
|
|
@@ -640,20 +670,16 @@ declare class Fiber {
|
|
|
640
670
|
*/
|
|
641
671
|
restart(): Promise<void>;
|
|
642
672
|
/**
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
* @param config — the new raw config; validated before anything restarts.
|
|
649
|
-
* @param noSave — hint for persistence hooks not to write the change back.
|
|
650
|
-
* @returns nothing; the restart runs behind the `internal/update` waterfall.
|
|
651
|
-
* @throws {ValidationError} when the new config fails validation.
|
|
673
|
+
* Resolve a candidate, retain its raw config and apply it through the update waterfall.
|
|
674
|
+
* @param config Raw config; pending fibers defer resolution until activation.
|
|
675
|
+
* @param noSave Suppress the persistence notification when true.
|
|
676
|
+
* @returns The awaited update/restart result, or undefined when a synchronous listener handles it.
|
|
677
|
+
* @throws {ValidationError} when an active fiber's candidate is invalid.
|
|
652
678
|
*/
|
|
653
|
-
update(config: any, noSave?: boolean): void
|
|
679
|
+
update(config: any, noSave?: boolean): Awaitable<void>;
|
|
654
680
|
}
|
|
655
681
|
//#endregion
|
|
656
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.
|
|
682
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0_@deepseek-ai+cordis-plugin-include@1.1.0_@deepseek-ai+cordis-plugin-loader@1.1.0/node_modules/@deepseek-ai/cordis/lib/types/events.d.ts
|
|
657
683
|
/** Extract the parameter tuple from a function type. */
|
|
658
684
|
type Parameters<F> = F extends ((...args: infer P) => any) ? P : never;
|
|
659
685
|
/** Extract the return type from a function type. */
|
|
@@ -765,12 +791,13 @@ declare class EventsService {
|
|
|
765
791
|
private ctx;
|
|
766
792
|
_hooks: Record<keyof any, Hook[]>;
|
|
767
793
|
constructor(ctx: Context);
|
|
794
|
+
private _resolve;
|
|
768
795
|
/**
|
|
769
|
-
* Resolve
|
|
770
|
-
*
|
|
771
|
-
* @param
|
|
772
|
-
* @
|
|
773
|
-
*
|
|
796
|
+
* Resolve bound callbacks using the event's context filter.
|
|
797
|
+
* @param type Dispatch mode reported to observers.
|
|
798
|
+
* @param args Dispatch arguments, consumed through the event name.
|
|
799
|
+
* @returns Matching callbacks bound to the dispatch receiver.
|
|
800
|
+
* DSH retains callback enumeration for per-listener error containment.
|
|
774
801
|
*/
|
|
775
802
|
dispatch(type: string, args: any[]): ((...args: any[]) => any)[];
|
|
776
803
|
/**
|
|
@@ -811,24 +838,8 @@ declare class EventsService {
|
|
|
811
838
|
* @returns the outermost listener's return value.
|
|
812
839
|
*/
|
|
813
840
|
waterfall(...args: any[]): any;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
*
|
|
817
|
-
* @param label — effect label shown in fiber diagnostics.
|
|
818
|
-
* @param hooks — the listener list for one event.
|
|
819
|
-
* @param callback — the listener to store.
|
|
820
|
-
* @param options — placement and filtering options.
|
|
821
|
-
* @returns a disposer that unregisters the listener.
|
|
822
|
-
*/
|
|
823
|
-
register(label: string, hooks: Hook[], callback: any, options: EventOptions): () => void;
|
|
824
|
-
/**
|
|
825
|
-
* Remove a stored listener record.
|
|
826
|
-
*
|
|
827
|
-
* @param hooks — the listener list for one event.
|
|
828
|
-
* @param callback — the listener to remove.
|
|
829
|
-
* @returns `true` if the listener was found and removed.
|
|
830
|
-
*/
|
|
831
|
-
unregister(hooks: Hook[], callback: any): true | undefined;
|
|
841
|
+
private register;
|
|
842
|
+
private unregister;
|
|
832
843
|
/**
|
|
833
844
|
* Register an event listener owned by the current fiber.
|
|
834
845
|
*
|
|
@@ -849,7 +860,7 @@ declare class EventsService {
|
|
|
849
860
|
* @param options — listener options; a boolean is shorthand for `prepend`.
|
|
850
861
|
* @returns a disposer removing the listener; `true` if it was still registered.
|
|
851
862
|
*/
|
|
852
|
-
once(name: string, listener: (...args: any) => any, options?: boolean | EventOptions): any;
|
|
863
|
+
once(name: string | symbol, listener: (...args: any) => any, options?: boolean | EventOptions): any;
|
|
853
864
|
}
|
|
854
865
|
/**
|
|
855
866
|
* Built-in framework events used by core services and extension points.
|
|
@@ -860,20 +871,34 @@ declare class EventsService {
|
|
|
860
871
|
* diagnostics before public events are delivered.
|
|
861
872
|
*/
|
|
862
873
|
interface Events {
|
|
874
|
+
[key: symbol]: (...args: any[]) => any;
|
|
863
875
|
/** A plugin fiber was created or its uid was cleared on disposal. */
|
|
864
876
|
'internal/plugin'(fiber: Fiber): void;
|
|
865
877
|
/** A fiber changed lifecycle state; receives the fiber and its previous state. */
|
|
866
878
|
'internal/status'(fiber: Fiber, oldValue: FiberState): void;
|
|
879
|
+
/** A service binding was refreshed in the matching isolation scope. */
|
|
880
|
+
'internal/service'(this: Context, name: string, value: any): void;
|
|
867
881
|
/**
|
|
868
|
-
*
|
|
869
|
-
* @param
|
|
882
|
+
* Apply resolved config; omitting `next()` keeps the current instance.
|
|
883
|
+
* @param resolvedConfig - the evaluated and validated candidate.
|
|
884
|
+
* @param next - restarts the fiber and waits for its lifecycle work.
|
|
870
885
|
* @mode waterfall
|
|
871
886
|
*/
|
|
872
|
-
'internal/
|
|
873
|
-
/**
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
887
|
+
'internal/update'(this: Fiber, resolvedConfig: any, next: () => Awaitable<void>): Awaitable<void>;
|
|
888
|
+
/**
|
|
889
|
+
* Persist original config from a programmatic update, before its lifecycle transition.
|
|
890
|
+
* @param fiber - the updated fiber.
|
|
891
|
+
* @param originalConfig - the raw candidate; omitted when update uses noSave.
|
|
892
|
+
* @mode emit
|
|
893
|
+
*/
|
|
894
|
+
'internal/commit'(fiber: Fiber, originalConfig: any): void;
|
|
895
|
+
/**
|
|
896
|
+
* Resolve plugin config after injections are active; candidate resolution does not publish it.
|
|
897
|
+
* @param fiber - the fiber whose candidate is being resolved.
|
|
898
|
+
* @param next - obtains the raw candidate from inner listeners.
|
|
899
|
+
* @mode waterfall
|
|
900
|
+
*/
|
|
901
|
+
'internal/config'(fiber: Fiber, next: () => any): any;
|
|
877
902
|
/** Waterfall: a service is being read through the context proxy. */
|
|
878
903
|
'internal/get'(ctx: Context, name: string, error: Error, next: () => any): any;
|
|
879
904
|
/** Waterfall: a service is being written through the context proxy. */
|
|
@@ -881,10 +906,10 @@ interface Events {
|
|
|
881
906
|
/** Bail: a listener is being registered; a non-null result replaces registration. */
|
|
882
907
|
'internal/listener'(this: Context, name: string, listener: any, prepend: boolean): void;
|
|
883
908
|
/** An event is being dispatched to listeners (fired for non-internal events only). */
|
|
884
|
-
'internal/dispatch'(mode: DispatchMode, name: string, args: any[], thisArg: any): void;
|
|
909
|
+
'internal/dispatch'(mode: DispatchMode, name: string | symbol, args: any[], thisArg: any): void;
|
|
885
910
|
}
|
|
886
911
|
//#endregion
|
|
887
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.
|
|
912
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0_@deepseek-ai+cordis-plugin-include@1.1.0_@deepseek-ai+cordis-plugin-loader@1.1.0/node_modules/@deepseek-ai/cordis/lib/types/logger.d.ts
|
|
888
913
|
declare module './context.ts' {
|
|
889
914
|
interface Intercept {
|
|
890
915
|
logger: LoggerService.Intercept;
|
|
@@ -972,7 +997,7 @@ declare class LoggerService {
|
|
|
972
997
|
[symbols.invoke](name?: string): Logger;
|
|
973
998
|
}
|
|
974
999
|
//#endregion
|
|
975
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.
|
|
1000
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0_@deepseek-ai+cordis-plugin-include@1.1.0_@deepseek-ai+cordis-plugin-loader@1.1.0/node_modules/@deepseek-ai/cordis/lib/types/context.d.ts
|
|
976
1001
|
/**
|
|
977
1002
|
* Public shape of a Cordis context.
|
|
978
1003
|
*
|
|
@@ -988,7 +1013,7 @@ interface Context {
|
|
|
988
1013
|
/** The root context of the application (every child context shares it). @experimental */
|
|
989
1014
|
root: this;
|
|
990
1015
|
/** Base URL used to resolve relative plugin/module specifiers, if the runtime sets one. */
|
|
991
|
-
baseUrl?: string;
|
|
1016
|
+
baseUrl?: string | undefined;
|
|
992
1017
|
/** The event bus. Its methods are also mixed onto `ctx` (`ctx.on`, `ctx.emit`, ...). */
|
|
993
1018
|
events: EventsService;
|
|
994
1019
|
/** The logging service. Call `ctx.logger(name)` for a named logger. */
|
|
@@ -1067,7 +1092,7 @@ declare class Context {
|
|
|
1067
1092
|
intercept(name: string, config: any): this;
|
|
1068
1093
|
}
|
|
1069
1094
|
//#endregion
|
|
1070
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.
|
|
1095
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+cordis@4.1.0_@deepseek-ai+cordis-plugin-include@1.1.0_@deepseek-ai+cordis-plugin-loader@1.1.0/node_modules/@deepseek-ai/cordis/lib/types/service.d.ts
|
|
1071
1096
|
/**
|
|
1072
1097
|
* Base class for services that expose a named API on `ctx`.
|
|
1073
1098
|
*
|
|
@@ -1122,6 +1147,13 @@ declare abstract class Service<out T = never> {
|
|
|
1122
1147
|
}
|
|
1123
1148
|
//#endregion
|
|
1124
1149
|
//#region src/index.d.ts
|
|
1125
|
-
|
|
1150
|
+
interface MaidLoggerConfig {
|
|
1151
|
+
/** M3e §5:运行时缓存探针(默认 disabled——零监听零日志零 Session 写入)。 */
|
|
1152
|
+
cacheProbe?: {
|
|
1153
|
+
enabled?: boolean;
|
|
1154
|
+
reportFile?: string;
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
declare const apply: (ctx: Context, config?: MaidLoggerConfig) => (() => Promise<void>);
|
|
1126
1158
|
//#endregion
|
|
1127
|
-
export { apply };
|
|
1159
|
+
export { MaidLoggerConfig, apply };
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
//#region src/cache-probe.ts
|
|
3
|
+
/** 签名 = sha256(systemText + tools 序列化);user/assistant 消息不参与。 */
|
|
4
|
+
function defaultHash(input) {
|
|
5
|
+
return createHash("sha256").update(input).digest("hex").slice(0, 16);
|
|
6
|
+
}
|
|
7
|
+
/** 稳定序列化(键排序,数组保序)。 */
|
|
8
|
+
function stableStringify(value) {
|
|
9
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
10
|
+
if (typeof value === "object" && value !== null) return `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stableStringify(value[k])}`).join(",")}}`;
|
|
11
|
+
return JSON.stringify(value) ?? "null";
|
|
12
|
+
}
|
|
13
|
+
function createCacheProbe(options) {
|
|
14
|
+
const warn = options.warn ?? (() => {});
|
|
15
|
+
const hash = options.hash ?? defaultHash;
|
|
16
|
+
const report = options.reportSink ?? (() => {});
|
|
17
|
+
if (!options.enabled) return { observe: () => {} };
|
|
18
|
+
const lastSignature = /* @__PURE__ */ new Map();
|
|
19
|
+
let stopped = false;
|
|
20
|
+
return { observe(g) {
|
|
21
|
+
if (stopped) return;
|
|
22
|
+
const sessionId = g.sessionId;
|
|
23
|
+
if (sessionId === void 0 || sessionId === "") return;
|
|
24
|
+
if (g.purpose !== void 0) return;
|
|
25
|
+
try {
|
|
26
|
+
const systemText = (g.system ?? "") + (g.messages ?? []).filter((m) => m.role === "system").map((m) => typeof m.content === "string" ? m.content : stableStringify(m.content)).join("\n");
|
|
27
|
+
const signature = hash(`${systemText}\x00${stableStringify(g.tools ?? [])}`);
|
|
28
|
+
const prev = lastSignature.get(sessionId);
|
|
29
|
+
lastSignature.set(sessionId, signature);
|
|
30
|
+
if (prev !== void 0 && prev !== signature) {
|
|
31
|
+
const line = JSON.stringify({
|
|
32
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
33
|
+
sessionId,
|
|
34
|
+
prev,
|
|
35
|
+
current: signature,
|
|
36
|
+
event: "cache-suspect"
|
|
37
|
+
});
|
|
38
|
+
warn(`maid-logger cache-probe: cache-suspect session=${sessionId} prev=${prev} current=${signature}`);
|
|
39
|
+
report(line);
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
stopped = true;
|
|
43
|
+
warn(`maid-logger cache-probe: 探针自停(签名计算异常:${error.message}),后续请求不再对账`);
|
|
44
|
+
}
|
|
45
|
+
} };
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
1
48
|
//#region src/index.ts
|
|
2
49
|
const TAG = {
|
|
3
50
|
error: "E",
|
|
@@ -14,7 +61,7 @@ const safeText = (a) => {
|
|
|
14
61
|
return String(a);
|
|
15
62
|
}
|
|
16
63
|
};
|
|
17
|
-
const apply = (ctx) => {
|
|
64
|
+
const apply = (ctx, config) => {
|
|
18
65
|
ctx.logger.exporter({
|
|
19
66
|
levels: { default: 3 },
|
|
20
67
|
export(message) {
|
|
@@ -29,6 +76,18 @@ const apply = (ctx) => {
|
|
|
29
76
|
} catch {}
|
|
30
77
|
}
|
|
31
78
|
});
|
|
79
|
+
const probeConfig = config?.cacheProbe;
|
|
80
|
+
if (probeConfig?.enabled === true) {
|
|
81
|
+
const probe = createCacheProbe({
|
|
82
|
+
enabled: true,
|
|
83
|
+
warn: (m) => ctx.logger("maid-logger").warn(m),
|
|
84
|
+
...probeConfig.reportFile !== void 0 ? { reportFile: probeConfig.reportFile } : {}
|
|
85
|
+
});
|
|
86
|
+
ctx.on("llm/stream", ((options, next) => {
|
|
87
|
+
probe.observe(options);
|
|
88
|
+
return next();
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
32
91
|
return async () => {};
|
|
33
92
|
};
|
|
34
93
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepmaid/maid-logger",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@deepseek-ai/cordis": "4.0
|
|
31
|
+
"@deepseek-ai/cordis": "4.1.0",
|
|
32
32
|
"tsdown": "0.22.14",
|
|
33
33
|
"typescript": "6.0.3"
|
|
34
34
|
},
|