From a01b1c69d561fa84514f33ee9f64d675156769ae Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Fri, 19 Sep 2025 17:34:05 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`dev`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @MiaowFISH. * https://github.com/YesWeAreBot/YesImBot/pull/157#issuecomment-3312943624 The following files were modified: * `packages/core/src/agent/heartbeat-processor.ts` * `packages/core/src/config/migrations.ts` * `packages/core/src/services/extension/decorators.ts` --- .../core/src/agent/heartbeat-processor.ts | 9 ++++ packages/core/src/config/migrations.ts | 45 +++++++++++++++++++ .../core/src/services/extension/decorators.ts | 14 ++++-- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/packages/core/src/agent/heartbeat-processor.ts b/packages/core/src/agent/heartbeat-processor.ts index f9186b1a..80508c33 100644 --- a/packages/core/src/agent/heartbeat-processor.ts +++ b/packages/core/src/agent/heartbeat-processor.ts @@ -470,6 +470,15 @@ export class HeartbeatProcessor { } } +/** + * Convert a value to a string suitable for templates. + * + * If `obj` is already a string it is returned unchanged; otherwise the value + * is serialized with `JSON.stringify`. + * + * @param obj - Value to convert (string or any JSON-serializable value) + * @returns A string representation of `obj` + */ function _toString(obj) { if (typeof obj === "string") return obj; return JSON.stringify(obj); diff --git a/packages/core/src/config/migrations.ts b/packages/core/src/config/migrations.ts index 70645185..d3dc7a27 100644 --- a/packages/core/src/config/migrations.ts +++ b/packages/core/src/config/migrations.ts @@ -4,6 +4,20 @@ import semver from "semver"; import { ConfigV201 } from "./versions/v201"; import { ModelAbility, ModelDescriptor } from "@/services"; +/** + * Migrate a v1 configuration object to the v2.0.0 configuration shape. + * + * Produces a new config with version "2.0.0" by: + * - copying top-level service sections (modelService, assetService, promptService, system), + * - flattening nested agentBehavior fields (arousal, willingness, vision, prompt) into the top level, + * - setting `enableVision` from `vision?.enabled`, + * - carrying selected agentBehavior flags (streamAction, heartbeat, newMessageStrategy, deferredProcessingTime), + * - flattening capabilities (history, memory, tools) into the top level, + * - mapping `assetEndpoint` from `assetService.endpoint`. + * + * @param configV1 - The original configuration in the 1.0.0 shape to migrate. + * @returns A config object shaped as v2.0.0 (omitting `enableTelemetry` and `sentryDsn`). + */ function migrateV1ToV200(configV1: ConfigV1): Omit { const { modelService, agentBehavior, capabilities, assetService, promptService, system } = configV1; @@ -39,6 +53,12 @@ function migrateV1ToV200(configV1: ConfigV1): Omit = new (...args: any[]) => T; /** - * @Extension 类装饰器 - * 将一个普通类转换为功能完备、可被 Koishi 直接加载的工具扩展插件。 - * @param metadata 扩展包的元数据对象 + * Class decorator that turns a plain class into a Koishi-loadable tool extension. + * + * The decorator wraps the target class to perform automatic runtime registration with the tool + * management service: it binds per-instance tool `execute` methods, registers the extension + * on the Koishi `ready` event (using the instance config `enabled` flag), and unregisters it + * on `dispose`. It also attaches the provided metadata to the wrapped prototype, preserves a + * static `Config` if present, sets the wrapped class name to `metadata.name`, and ensures the + * wrapped class declares the tool and logger services in its `inject` metadata. + * + * @param metadata - Extension package metadata used for registration (provides the extension name and related info) + * @returns A class decorator that produces a wrapped extension class compatible with Koishi's tool service */ export function Extension(metadata: ExtensionMetadata): ClassDecorator { //@ts-ignore