koishi-plugin-chatluna-studio 1.0.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/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/index.js +45313 -0
- package/dist/style.css +1 -0
- package/lib/chatluna/error.d.ts +15 -0
- package/lib/chatluna/runtime.d.ts +25 -0
- package/lib/chatluna/session-tracker.d.ts +98 -0
- package/lib/chatluna/usage.d.ts +46 -0
- package/lib/console-contract.d.ts +61 -0
- package/lib/console.d.ts +39 -0
- package/lib/evidence-kind.d.ts +61 -0
- package/lib/evidence-preview-text.d.ts +13 -0
- package/lib/index.d.ts +42 -0
- package/lib/index.js +4579 -0
- package/lib/model-evidence/index.d.ts +15 -0
- package/lib/model-evidence/metrics.d.ts +11 -0
- package/lib/model-evidence/request.d.ts +7 -0
- package/lib/model-evidence/response.d.ts +7 -0
- package/lib/model-evidence/shared.d.ts +37 -0
- package/lib/model-evidence/transport.d.ts +13 -0
- package/lib/model-evidence/types.d.ts +104 -0
- package/lib/model-evidence/usage.d.ts +10 -0
- package/lib/model-request-collector.d.ts +32 -0
- package/lib/model-request-trajectory.d.ts +21 -0
- package/lib/model-request-variables.d.ts +16 -0
- package/lib/model-request.d.ts +158 -0
- package/lib/persistence.d.ts +85 -0
- package/lib/presets/evidence-match.d.ts +9 -0
- package/lib/presets/index.d.ts +6 -0
- package/lib/presets/repository.d.ts +86 -0
- package/lib/presets/runtime-correlation.d.ts +16 -0
- package/lib/presets/service.d.ts +69 -0
- package/lib/presets/source-document.d.ts +2 -0
- package/lib/presets/types.d.ts +63 -0
- package/lib/record-store.d.ts +85 -0
- package/lib/types.d.ts +270 -0
- package/package.json +110 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 证据种类:模型请求证据的最细一档分类,以及它在两种排版语境下的展示标签。
|
|
3
|
+
*
|
|
4
|
+
* 分类与标签由本 module 独占。轨迹账本的种类列、证据种类过滤开关、请求组成图的图例与分段、
|
|
5
|
+
* 分析导航的分组标题全部从这里取值;任何一侧再自己列一张标签表,同一种证据就会在同屏出现两种说法。
|
|
6
|
+
*
|
|
7
|
+
* 本 module 是浏览器安全的纯 module:不依赖 Node、Koishi、Vue 或 DOM,
|
|
8
|
+
* 因此服务端轨迹派生与客户端视图共用同一实现,与共享模型证据投影同一形状。
|
|
9
|
+
* 它只描述「一条证据属于哪一类、这一类怎么显示」,不描述任何证据数据、DOM、排序或交互状态。
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* 基础证据种类,取最细一档,与领域词汇表的证据词条一一对应。
|
|
13
|
+
*
|
|
14
|
+
* 请求边界不在其中:它是「一次模型请求从这里开始」的结构标记而不是证据,
|
|
15
|
+
* 隐藏全部证据种类后仍要能看出有哪些请求,因此它的标签留在轨迹账本这一侧。
|
|
16
|
+
*/
|
|
17
|
+
export type StudioEvidenceKind = 'system' | 'user' | 'assistant' | 'variable' | 'tool-definition' | 'tool-call' | 'tool-result' | 'response';
|
|
18
|
+
/**
|
|
19
|
+
* 具名聚合:多档粒度都从基础种类派生。
|
|
20
|
+
*
|
|
21
|
+
* - `tool-interaction`:请求组成图使用。它按字符占比统计,而工具调用与工具结果在请求消息里成对出现,合并统计才有意义。
|
|
22
|
+
* - `tool`:分析导航使用。分组标题下要挂多个条目,因此三种工具证据收在一个分组里。
|
|
23
|
+
*/
|
|
24
|
+
export type StudioEvidenceAggregateId = 'tool-interaction' | 'tool';
|
|
25
|
+
/** 展示标签的两个变体,按排版语境区分,成对声明因此不会各自漂移。 */
|
|
26
|
+
export interface StudioEvidenceLabels {
|
|
27
|
+
/** 徽标语境:有背景色、内边距与固定高度的种类标记,全大写。 */
|
|
28
|
+
badge: string;
|
|
29
|
+
/** 标题与图例语境:分组标题、轨道图例,词首大写。 */
|
|
30
|
+
title: string;
|
|
31
|
+
}
|
|
32
|
+
declare const EVIDENCE_AGGREGATE_MEMBERS: {
|
|
33
|
+
'tool-interaction': readonly ["tool-call", "tool-result"];
|
|
34
|
+
tool: readonly ["tool-definition", "tool-call", "tool-result"];
|
|
35
|
+
};
|
|
36
|
+
/** 基础证据种类的全集,按视图里从上到下、从左到右的既有阅读顺序声明。 */
|
|
37
|
+
export declare const STUDIO_EVIDENCE_KINDS: readonly StudioEvidenceKind[];
|
|
38
|
+
export declare const STUDIO_EVIDENCE_AGGREGATE_IDS: readonly StudioEvidenceAggregateId[];
|
|
39
|
+
/** 某个聚合的成员种类,用于让「取子集还是取聚合」在类型上也是显式选择。 */
|
|
40
|
+
export type StudioEvidenceAggregateMemberKind<Id extends StudioEvidenceAggregateId> = typeof EVIDENCE_AGGREGATE_MEMBERS[Id][number];
|
|
41
|
+
export interface StudioEvidenceAggregate<Id extends StudioEvidenceAggregateId = StudioEvidenceAggregateId> {
|
|
42
|
+
id: Id;
|
|
43
|
+
members: readonly StudioEvidenceAggregateMemberKind<Id>[];
|
|
44
|
+
labels: StudioEvidenceLabels;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 取展示标签。基础种类与聚合走同一个入口,因此视图不必自己判断某个取值是不是聚合,
|
|
48
|
+
* 取标签也只需要一个参数。
|
|
49
|
+
*/
|
|
50
|
+
export declare function studioEvidenceLabels(id: StudioEvidenceKind | StudioEvidenceAggregateId): StudioEvidenceLabels;
|
|
51
|
+
/** 取具名聚合。成员显式声明,因此「组成图把工具调用与工具结果算作一类」是可断言的事实。 */
|
|
52
|
+
export declare function studioEvidenceAggregate<Id extends StudioEvidenceAggregateId>(id: Id): StudioEvidenceAggregate<Id>;
|
|
53
|
+
export declare function isStudioEvidenceAggregateMember<Id extends StudioEvidenceAggregateId>(aggregate: Id, kind: StudioEvidenceKind): kind is StudioEvidenceAggregateMemberKind<Id>;
|
|
54
|
+
/**
|
|
55
|
+
* 请求组成图的种类:四种基础证据种类加工具交互聚合。
|
|
56
|
+
*
|
|
57
|
+
* 工具定义不参与聚合——它是请求前缀里的能力目录,按字符占比独立成轨;
|
|
58
|
+
* 模型请求变量投影到 User 轨道,模型响应不进请求体统计,因此两者都不在这一档里。
|
|
59
|
+
*/
|
|
60
|
+
export type StudioEvidenceCompositionKind = Exclude<StudioEvidenceKind, 'variable' | 'response' | StudioEvidenceAggregateMemberKind<'tool-interaction'>> | 'tool-interaction';
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 证据预览文本的空白归一化。
|
|
3
|
+
*
|
|
4
|
+
* 轨迹账本行和分析导航条目都只显示一两百字的预览,但它们的输入是原始请求消息,
|
|
5
|
+
* 单条动辄几十 KB。对整段文本跑一次 `\s+` 归一化,是这两条读取路径里最贵的一步,
|
|
6
|
+
* 而结果的 99% 会被立刻丢掉。
|
|
7
|
+
*
|
|
8
|
+
* 这里只归一化足够产出预览的前缀,并在空白折叠让前缀不够长时继续扩大扫描范围。
|
|
9
|
+
* 空白折叠是就地、保序的变换,因此前缀的归一化结果一定是整段归一化结果的前缀:
|
|
10
|
+
* 返回值长度超过 `minLength` 时,它与整段归一化结果的前 `minLength` 个字符一致;
|
|
11
|
+
* 没超过时两者完全相同。调用方按自己的规则截断。
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeEvidencePreviewText(value: string, minLength: number): string;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
import type { StudioAppearance, StudioPersistenceMode } from './types';
|
|
3
|
+
export * from './console';
|
|
4
|
+
export * from './console-contract';
|
|
5
|
+
export * from './chatluna/error';
|
|
6
|
+
export * from './chatluna/session-tracker';
|
|
7
|
+
export * from './chatluna/usage';
|
|
8
|
+
export * from './evidence-kind';
|
|
9
|
+
export * from './model-evidence';
|
|
10
|
+
export * from './model-request';
|
|
11
|
+
export * from './model-request-collector';
|
|
12
|
+
export * from './model-request-trajectory';
|
|
13
|
+
export * from './model-request-variables';
|
|
14
|
+
export * from './persistence';
|
|
15
|
+
export * from './presets';
|
|
16
|
+
export * from './record-store';
|
|
17
|
+
export * from './types';
|
|
18
|
+
export declare const name = "chatluna-studio";
|
|
19
|
+
export declare const usage = "\n\u5728 Koishi \u63A7\u5236\u53F0\u91CC\u67E5\u770B ChatLuna \u7684\u771F\u5B9E\u6A21\u578B\u8BF7\u6C42\uFF0C\u5E76\u76F4\u63A5\u7F16\u8F91 ChatLuna \u4E0E chatluna-character \u7684\u9884\u8BBE\u6587\u4EF6\u3002\n\n- \u6A21\u578B\u8BF7\u6C42\u9875\u9762\u8BB0\u5F55\u6BCF\u6B21\u771F\u5B9E\u5BF9\u8BDD\u89E6\u53D1\u7684\u6A21\u578B\u8C03\u7528\uFF1A\u8BF7\u6C42\u4F53\u3001\u54CD\u5E94\u539F\u6587\u3001\u7528\u91CF\u3001\u8F68\u8FF9\u4E0E\u9884\u8BBE\u53D8\u91CF\u5C55\u5F00\u3002\n- \u9884\u8BBE\u9875\u9762\u76F4\u63A5\u8BFB\u5199`data/chathub/presets`\u4E0E`data/chathub/character/presets`\u4E0B\u7684 YAML \u6587\u4EF6\uFF0C\u4FDD\u5B58\u540E\u7531 ChatLuna \u81EA\u5DF1\u70ED\u91CD\u8F7D\u3002\n- \u70B9\u51FB\u9884\u8BBE\u91CC\u7684\u8868\u8FBE\u5F0F\u53EF\u4EE5\u8DF3\u5230\u5B83\u5728\u771F\u5B9E\u6A21\u578B\u8BF7\u6C42\u4E2D\u7684\u5C55\u5F00\u4F4D\u7F6E\uFF0C\u9700\u8981\u5148\u6709\u4E00\u6B21\u7528\u5230\u8BE5\u9884\u8BBE\u7684\u6210\u529F\u8BF7\u6C42\u3002\n\n\u6A21\u578B\u8BF7\u6C42\u7684\u91C7\u96C6\u5728 ChatLuna \u7684 fetch \u8FB9\u754C\u5B8C\u6210\uFF0C\u56E0\u6B64\u9700\u8981\u4E0E ChatLuna \u88C5\u5728\u540C\u4E00\u4E2A Koishi \u5B9E\u4F8B\u91CC\u3002\n";
|
|
20
|
+
/**
|
|
21
|
+
* `chatluna_usage` 刻意不出现在这里。
|
|
22
|
+
*
|
|
23
|
+
* chatluna-usage 的用量服务是 Console `DataService`,Cordis 里的真实服务名是
|
|
24
|
+
* `console.services.chatluna_usage`,根上下文永远没有 `chatluna_usage`。把它写进 `inject.optional`
|
|
25
|
+
* 或 `koishi.service.optional`,只会让插件配置页一直显示「可选服务: chatluna_usage (未加载)」——即使
|
|
26
|
+
* 用量插件已启用、用量也读得到。用量按服务名现取(见 `findChatLunaUsage`),不进 `inject`。
|
|
27
|
+
*/
|
|
28
|
+
export declare const inject: {
|
|
29
|
+
required: string[];
|
|
30
|
+
optional: string[];
|
|
31
|
+
};
|
|
32
|
+
export interface Config extends StudioAppearance {
|
|
33
|
+
persistenceMode: StudioPersistenceMode;
|
|
34
|
+
modelRequestRecordLimit: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const Config: Schema<Config>;
|
|
37
|
+
declare module 'koishi' {
|
|
38
|
+
interface Events {
|
|
39
|
+
'chatluna/model-usage'(payload: import('./chatluna/usage').ChatLunaModelUsageEvent): void;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export declare function apply(ctx: Context, config: Config): void;
|