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
30 changes: 29 additions & 1 deletion packages/core/client/config-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export interface ConfigEntry {
path: string[];
schema: FormSchema;
omit?: string[];
editor?: "search-engines";
}
export interface ConfigGroup {
id: string;
label: string;
entries: ConfigEntry[];
fold?: boolean;
note?: string;
}
export interface ConfigCategory {
Expand Down Expand Up @@ -70,7 +72,7 @@ const definitions: CategoryDefinition[] = [
"记忆与上下文",
[
["context", "本轮上下文", ["ignoreSelfMessage", "contextInputBudgetTokens"]],
["l1", "近期对话与完整轮次", ["l1_memory"]],
["l1", "近期对话与完整轮次", ["l1_memory", "onebotHistory"]],
["core-memory", "核心记忆文件", ["coreMemoryPath"]],
["l2", "语义记忆检索", ["l2_memory"]],
["l3", "长期日记", ["l3_memory"]],
Expand Down Expand Up @@ -131,7 +133,14 @@ const definitions: CategoryDefinition[] = [
],
];

// Simple rows already have labels and controls in the native editor. A
// surrounding fold is useful for a feature with its own settings, such as L2
// memory or TypeSafe, but adds a second heading to standalone fields.
const directGroups = new Set(["scope", "context", "core-memory", "vision-input", "vision-prompt", "rendering", "execution", "other"]);

const projectedCoreFields = ["vision", "typing", "deliveryTimeoutMs"];
const configuredSearchFields = ["engines", "strategy", "selectedEngines", "engineOptions"];
const legacySearchFields = ["endpoint", "sources", "format"];

// Clone only schema structure, never mutate the live console registry or change
// defaults in the server validator. Omit both union branches, including hidden
Expand All @@ -158,6 +167,7 @@ export function createConfigLayout(schema: FormSchema, dynamicSchemas: Record<st
groups: groups.map(([id, label, names]) => ({
id,
label,
fold: !directGroups.has(id),
entries: names.flatMap((name) => {
const field = fields[name];
if (!field || field.meta?.hidden || used.has(name)) return [];
Expand All @@ -174,6 +184,24 @@ export function createConfigLayout(schema: FormSchema, dynamicSchemas: Record<st
extensionGroup.entries = [];
for (const [name, extensionSchema] of Object.entries(extensions)) {
if (extensionSchema.meta?.hidden) continue;
if (name === "search") {
const searchFields = collectConfigFields(extensionSchema);
// Old registry payloads still use the original editor.
if (searchFields.engineSelection && searchFields.selectedEngines) {
const searchConfig = config?.extra?.search;
const configured = searchConfig?.engineSelection === "configured";
const shown = configured && searchConfig?.enabled !== false;
const omitted = configured ? [...legacySearchFields, "selectedEngines"] : configuredSearchFields;
extensionGroup.entries.push({ path: ["extra", name], schema: omitSchemaFields(extensionSchema, omitted), omit: omitted });
if (shown)
extensionGroup.entries.push({
path: ["extra", name, "selectedEngines"],
schema: searchFields.selectedEngines,
editor: "search-engines",
});
continue;
}
}
if (name !== "core_util") {
extensionGroup.entries.push({ path: ["extra", name], schema: extensionSchema });
continue;
Expand Down
54 changes: 32 additions & 22 deletions packages/core/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Schema, store } from "@koishijs/client";
import { computed, defineComponent, h, ref, resolveComponent, shallowRef, watch } from "vue";

import { createConfigLayout, readConfigEntry, writeConfigEntry } from "./config-layout";
import type { ConfigEntry } from "./config-layout";
import type { ConfigEntry, ConfigGroup } from "./config-layout";
import { ModelGroups } from "./model-groups";
import { SearchEngineSelection } from "./search-engine-selection";

import "./section.css";

Expand Down Expand Up @@ -97,22 +98,33 @@ export const PurposeConfig = defineComponent({
const registry = store.schema?.["toolService.availableExtensions"];
return createConfigLayout(props.schema, registry ? { "toolService.availableExtensions": new Schema(registry) } : {}, draft.value);
});
const renderEntry = (entry: ConfigEntry, inline: boolean) =>
h(
const updateEntry = (entry: ConfigEntry, value: unknown) => {
if (props.disabled) return;
draft.value = writeConfigEntry(draft.value, entry, value);
emit("update:modelValue", draft.value);
};
const renderEntry = (entry: ConfigEntry, inline: boolean) => {
const modelValue = readConfigEntry(draft.value, entry);
if (entry.editor === "search-engines") {
return h(SearchEngineSelection, {
key: entry.path.join("."),
engines: draft.value?.extra?.search?.engines,
modelValue,
disabled: props.disabled,
"onUpdate:modelValue": (value: string[]) => updateEntry(entry, value),
});
}
return h(
resolveComponent("k-schema"),
{
key: entry.path.join("."),
schema: nativeSchema(entry, inline),
modelValue: readConfigEntry(draft.value, entry),
modelValue,
initial: readConfigEntry(props.initial, entry),
disabled: props.disabled,
prefix: `${props.prefix ?? ""}${entry.path.join(".")}.`,
extra: inline ? { foldable: false } : undefined,
"onUpdate:modelValue": (value) => {
if (props.disabled) return;
draft.value = writeConfigEntry(draft.value, entry, value);
emit("update:modelValue", draft.value);
},
"onUpdate:modelValue": (value) => updateEntry(entry, value),
},
{
title: () => [
Expand All @@ -121,6 +133,16 @@ export const PurposeConfig = defineComponent({
],
},
);
};
const renderGroup = (group: ConfigGroup) => {
const content = () => [
group.note ? h("p", { class: "yib-config-note" }, group.note) : null,
...group.entries.map((entry) => renderEntry(entry, group.fold !== false && group.entries.length === 1 && !entry.schema.meta?.role)),
];
return group.fold === false
? h("div", { key: group.id, class: "yib-config-direct" }, content())
: h(ConfigFold, { key: group.id, label: group.label, nested: true }, { default: content });
};
return () =>
h("div", { ...attrs, class: ["yib-config-layout", attrs.class] }, [
slots.menu ? h("details", { class: "yib-config-actions" }, [h("summary", "配置操作"), slots.menu()]) : null,
Expand All @@ -129,19 +151,7 @@ export const PurposeConfig = defineComponent({
ConfigFold,
{ key: category.id, label: category.label, expanded: index === 0 },
{
default: () =>
category.groups.map((group) =>
h(
ConfigFold,
{ key: group.id, label: group.label, nested: true },
{
default: () => [
group.note ? h("p", { class: "yib-config-note" }, group.note) : null,
...group.entries.map((entry) => renderEntry(entry, group.entries.length === 1 && !entry.schema.meta?.role)),
],
},
),
),
default: () => category.groups.map(renderGroup),
},
),
),
Expand Down
43 changes: 43 additions & 0 deletions packages/core/client/search-engine-selection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { defineComponent, h } from "vue";

export const SearchEngineSelection = defineComponent({
name: "YibSearchEngineSelection",
props: ["engines", "modelValue", "disabled"],
emits: ["update:modelValue"],
setup(props, { emit }) {
return () => {
const selected = new Set<string>(Array.isArray(props.modelValue) ? props.modelValue : []);
const choices = new Map<string, string>();
for (const engine of Array.isArray(props.engines) ? props.engines : []) {
if (typeof engine?.id !== "string" || !engine.id.trim()) continue;
choices.set(engine.id.trim(), typeof engine.backend === "string" ? engine.backend : "");
}
for (const id of selected) {
if (!choices.has(id)) choices.set(id, "未配置");
}
return h("fieldset", { class: "yib-search-engines", disabled: props.disabled }, [
h("legend", "选择参与搜索的引擎"),
choices.size
? h("p", { class: "yib-config-note" }, "无勾选时停用搜索。")
: h("p", { class: "yib-config-note" }, "请先添加搜索引擎并填写标识。"),
...Array.from(choices, ([id, label]) =>
h("label", { key: id }, [
h("input", {
type: "checkbox",
checked: selected.has(id),
onChange: (event: Event) => {
if (props.disabled) return;
const checked = (event.target as HTMLInputElement).checked;
const current = new Set<string>(Array.isArray(props.modelValue) ? props.modelValue : []);
if (checked) current.add(id);
else current.delete(id);
emit("update:modelValue", [...current]);
},
}),
h("span", label ? `${id}(${label})` : id),
]),
),
]);
};
},
});
21 changes: 20 additions & 1 deletion packages/core/client/section.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
.yib-config-body[hidden] {
display: none;
}
.yib-config-subgroup + .yib-config-subgroup {
.yib-config-body > :is(.yib-config-subgroup, .yib-config-direct) + .yib-config-subgroup,
.yib-config-body > .yib-config-subgroup + .yib-config-direct {
border-top: 1px solid var(--k-color-divider);
}
.yib-config-subgroup > .yib-config-heading {
Expand Down Expand Up @@ -155,3 +156,21 @@
.yib-model-group-note {
color: var(--k-text-light);
}

.yib-search-engines {
min-width: 0;
border: 1px solid var(--k-color-divider);
border-radius: 4px;
margin: 0.5rem 0;
padding: 0.5rem 0.75rem 0.75rem;
}
.yib-search-engines > p {
margin: 0 0 0.4rem;
}
.yib-search-engines > label {
display: flex;
align-items: center;
gap: 0.5rem;
min-height: 1.75rem;
overflow-wrap: anywhere;
}
6 changes: 5 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@
"./package.json": "./package.json"
},
"dependencies": {
"@ai-sdk/anthropic": "4.0.78",
"@ai-sdk/openai": "4.0.91",
"@miaowfish/gifwrap": "^0.10.1",
"ai": "7.0.137",
"gray-matter": "^4.0.3",
"jimp": "^1.6.0",
"jsonrepair": "^3.12.0",
"mustache": "^4.2.0",
"qface": "^1.4.1",
"semver": "^7.7.2",
"uuid": "^11.1.0"
"uuid": "^11.1.0",
"zod": "3.25.76"
},
"devDependencies": {
"@koishijs/client": "^5.30.11",
Expand Down
21 changes: 21 additions & 0 deletions packages/core/resources/licenses/ishiki-search.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Yes! We Are Bot!

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 17 additions & 6 deletions packages/core/src/agent/agent-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { matchContinuation, sameContinuation, type ContinuationMatch } from "./c
import { registerDecisionCommands } from "./decision-commands";
import { DecisionJournal } from "./decision-journal";
import { DecisionRecord, DecisionRecords, formatDecision, describeDecisionStage } from "./decision-record";
import { HeartbeatProcessor } from "./heartbeat-processor";
import { HeartbeatProcessor, type ReplyTurnOutcome } from "./heartbeat-processor";
import { isBotMention } from "./mention";
import { registerReplyCommands } from "./reply-commands";
import { ReplyControl, ReplyCategory, ReplyTarget, messageCategories, replyKey } from "./reply-control";
Expand Down Expand Up @@ -398,6 +398,7 @@ export class AgentCore extends YesImBotService<Config> {
this.activeTurns.set(channelCid, controller);
this.activeDecisionIds.set(channelCid, (stimulus as TracedStimulus).decisionId!);
let success = false;
const cycle: { status?: ReplyTurnOutcome } = {};
const valid = () =>
!controller.signal.aborted &&
this.stimulusCurrent(stimulus as TracedStimulus) &&
Expand Down Expand Up @@ -431,7 +432,11 @@ export class AgentCore extends YesImBotService<Config> {
const session = guardReplySession(stimulus.session);
// Release local scheduling on cancellation even if a remote
// implementation ignores abort. Its late promise stays observed.
return awaitReplyTurn(() => this.processor.runCycle({ ...stimulus, session }));
return awaitReplyTurn(() =>
this.processor.runCycle({ ...stimulus, session }, (status) => {
cycle.status = status;
}),
);
},
controller.signal,
(destination) => {
Expand Down Expand Up @@ -466,11 +471,17 @@ export class AgentCore extends YesImBotService<Config> {
/* prettier-ignore */
this.logger.debug(`已发送回复 · 意愿 ${willingnessBeforeReply.toFixed(2)} → ${willingnessAfterReply.toFixed(2)}`);
}
const completed = valid();
const completed = valid() && cycle.status !== "cancelled";
const failed = cycle.status === "failed" || cycle.status === "partial_delivery";
let reason: string | undefined;
if (!completed) reason = "invalid_generation";
else if (failed) reason = success ? "partial_delivery" : "model_decision_failed";
else if (cycle.status === "explicit_silence" || cycle.status === "empty_send") reason = cycle.status;
else if (!success) reason = "no_reply";
this.recordDecision(stimulus, {
stage: completed ? "completed" : "cancelled",
reason: !completed ? "invalid_generation" : success ? undefined : "no_reply",
success: success && completed,
stage: !completed ? "cancelled" : failed ? "failed" : "completed",
reason,
success: success && completed && !failed,
score: this.willing.getCurrentWillingness(
(stimulus as TracedStimulus).scoringTopic?.scoreKey ?? (stimulus as TracedStimulus).topic?.scoreKey ?? channelCid,
),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agent/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export const AgentBehaviorConfigSchema: Schema<AgentBehaviorConfig> = Schema.int
systemTemplate: Schema.string()
.default(SystemBaseTemplate)
.role("textarea", { rows: [2, 4] })
.description("系统提示词模板"),
.description("系统提示词模板。支持 model.name、model.id、model.group.name,以及 model.group.models 成员区段。"),
userTemplate: Schema.string()
.default(UserBaseTemplate)
.role("textarea", { rows: [2, 4] })
Expand Down
Loading
Loading