Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"unicorn/no-null": "off",
"eslint/no-underscore-dangle": "off",
"typescript/no-this-alias": "off",
"vitest/require-top-level-describe": "off"
"vitest/require-top-level-describe": "off",
"typescript/no-unnecessary-type-parameters": "off"
},
"env": {
"builtin": true,
Expand Down
15 changes: 0 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./di": {
"import": "./dist/di.js",
"types": "./dist/di.d.ts"
},
"./simple-suite": {
"import": "./dist/simple-suite.js",
"types": "./dist/simple-suite.d.ts"
},
"./package.json": "./package.json"
},
"publishConfig": {
"access": "public",
"provenance": true
Expand Down
57 changes: 0 additions & 57 deletions skill/example (simple-suite)/AlertDispatch.ts

This file was deleted.

52 changes: 0 additions & 52 deletions skill/example (simple-suite)/CoreLogging.ts

This file was deleted.

24 changes: 0 additions & 24 deletions skill/example (simple-suite)/index.ts

This file was deleted.

29 changes: 0 additions & 29 deletions skill/example (simple-suite)/main.ts

This file was deleted.

36 changes: 17 additions & 19 deletions skill/example/AlertDispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,35 @@
* AlertDispatch: Handles validation and transmission of alerts
*/

import type { BaseArgs } from './BaseModule.ts';
import { BaseModule } from './BaseModule.ts';
import CoreLogging from './CoreLogging.ts';
import type { Hook } from 'synthkernel';
import type { LogEntry, Level } from './CoreLogging.ts';

export default class AlertDispatch extends BaseModule {
private readonly logging: CoreLogging;
export default class AlertDispatch {
private readonly unsub: () => void;

constructor(...args: BaseArgs) {
super(...args);
this.logging = this.container.get(CoreLogging);
this.unsub = this.logging.onOverflow.subscribe((log) =>
constructor(
private readonly ctx: {
log: (level: Level, msg: string) => void;
onLogOverflow: Hook<[LogEntry]>;
},
) {
this.unsub = ctx.onLogOverflow.subscribe((log) =>
this.dispatchAlert(`Log overflow: ${JSON.stringify(log)}`),
);
}

dispatchAlert = async (message: string): Promise<boolean> => {
this.logging.log('INFO', `Attempted dispatch: "${message}"`);
this.ctx.log('INFO', `Attempted dispatch: "${message}"`);
const { minMessageLength, maxMessageLength } = this.options;
if (message.length < minMessageLength) {
this.logging.log(
this.ctx.log(
'ERROR',
`Validation failed: message too short (min: ${minMessageLength})`,
);
return false;
}
if (message.length > maxMessageLength) {
this.logging.log(
'ERROR',
`Validation failed: message too long (max: ${maxMessageLength})`,
);
this.ctx.log('ERROR', `Validation failed: message too long (max: ${maxMessageLength})`);
return false;
}

Expand All @@ -41,19 +39,19 @@ export default class AlertDispatch extends BaseModule {
};

private readonly connectAlertService = async (alert: string) => {
this.logging.log('INFO', `Dispatched: "${alert}"`);
this.ctx.log('INFO', `Dispatched: "${alert}"`);
// Simulate async connection to alerting service, like an email API
await new Promise((resolve) => setTimeout(resolve, 10));
};

onDispose() {
this.unsub();
this.logging.log('INFO', 'AlertDispatch disposed');
this.ctx.log('INFO', 'AlertDispatch disposed');
}
onStart() {
this.logging.log('INFO', 'AlertDispatch initialized');
this.ctx.log('INFO', 'AlertDispatch initialized');
}
augmentation = { dispatchAlert: this.dispatchAlert };
root = { dispatchAlert: this.dispatchAlert };
declare options: {
minMessageLength: number;
maxMessageLength: number;
Expand Down
20 changes: 0 additions & 20 deletions skill/example/BaseModule.ts

This file was deleted.

14 changes: 7 additions & 7 deletions skill/example/CoreLogging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@

import { hook } from 'synthkernel';
import type { BaseOptions } from './index.ts';
import { BaseModule } from './BaseModule.ts';

// Helper to enforce hierarchy
const LEVELS = { DEBUG: 0, ERROR: 3, INFO: 1, WARN: 2 } as const;
type Level = keyof typeof LEVELS;
export type Level = keyof typeof LEVELS;

type LogEntry = {
export type LogEntry = {
timestamp: number;
level: string;
message: string;
};

export default class CoreLogging extends BaseModule {
export default class CoreLogging {
private logs: Array<LogEntry> = [];
onOverflow = hook<[LogEntry]>(); // A hook to notify when log overflow occurs for other modules to subscribe to
private readonly onOverflow = hook<[LogEntry]>(); // A hook to notify when log overflow occurs for other modules to subscribe to
declare options: {
logLevel: Level;
maxLogs?: number;
} & BaseOptions;

log = (level: Level, message: string) => {
private readonly log = (level: Level, message: string) => {
const currentLevel = LEVELS[level];
const minLevel = LEVELS[this.options.logLevel] ?? 0;
if (currentLevel < minLevel) return; // Skip logging if below threshold
Expand All @@ -49,8 +48,9 @@ export default class CoreLogging extends BaseModule {
this.logs = [];
this.onOverflow.dispose();
}
augmentation = {
root = {
log: this.log,
logs: this.logs,
onLogOverflow: this.onOverflow,
};
}
Loading