cortico 0.1.0 → 0.1.1

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.
Files changed (63) hide show
  1. package/README.md +4 -11
  2. package/package.json +1 -3
  3. package/src/bot.ts +1 -1
  4. package/src/core/README.md +0 -4
  5. package/src/core/types.ts +1 -1
  6. package/src/core/util.ts +2 -1
  7. package/src/deploy.ts +8 -6
  8. package/src/providers/README.md +4 -5
  9. package/src/providers/base.ts +1 -1
  10. package/src/providers/configuration.ts +2 -1
  11. package/src/providers/console/settings.ts +8 -10
  12. package/src/providers/llamacpp/console/runtime-panel.ts +73 -32
  13. package/src/providers/llamacpp/console/server.ts +1 -20
  14. package/src/providers/llamacpp/index.ts +0 -2
  15. package/src/providers/llamacpp/options.ts +0 -2
  16. package/src/providers/llamacpp/strings.ts +6 -6
  17. package/src/providers/openai-responses-compat/index.ts +0 -3
  18. package/src/web/README.md +1 -5
  19. package/src/web/client/console-pages/builtins/llm-settings/panel.ts +35 -41
  20. package/src/web/client/console-pages/builtins/llm-settings/strings.ts +4 -4
  21. package/src/web/client/console-pages/host.ts +2 -2
  22. package/src/web/client/features/core/strings.ts +2 -2
  23. package/src/web/client/features/feature.ts +1 -1
  24. package/src/web/client/features/live/index.ts +8 -1
  25. package/src/web/client/features/live/onboarding.ts +4 -1
  26. package/src/web/client/features/live/strings.ts +11 -11
  27. package/src/web/client/features/live/timeline.ts +2 -1
  28. package/src/web/client/features/settings/general.ts +1 -0
  29. package/src/web/client/features/settings/index.ts +1 -0
  30. package/src/web/client/features/worlds/index.ts +1 -0
  31. package/src/web/client/shell/index.ts +27 -47
  32. package/src/web/client/shell/strings.ts +0 -22
  33. package/src/web/client/ui/icons.ts +5 -0
  34. package/src/web/console-pages.ts +1 -1
  35. package/src/web/public/styles.css +21 -8
  36. package/src/web/server.ts +11 -3
  37. package/src/web/shared/client-panel.ts +1 -1
  38. package/src/web/shared/console-protocol.ts +2 -1
  39. package/src/worlds/minecraft/README.md +61 -11
  40. package/src/worlds/minecraft/cell-facts.ts +226 -0
  41. package/src/worlds/minecraft/chests.ts +5 -0
  42. package/src/worlds/minecraft/containers.ts +325 -0
  43. package/src/worlds/minecraft/entity-facts.ts +31 -5
  44. package/src/worlds/minecraft/executor.ts +283 -10348
  45. package/src/worlds/minecraft/inventory.ts +268 -0
  46. package/src/worlds/minecraft/melee.ts +419 -0
  47. package/src/worlds/minecraft/placed-ledger.ts +152 -0
  48. package/src/worlds/minecraft/placement.ts +1038 -0
  49. package/src/worlds/minecraft/receipt.ts +340 -0
  50. package/src/worlds/minecraft/skill-context.ts +358 -0
  51. package/src/worlds/minecraft/skills-build.ts +1169 -0
  52. package/src/worlds/minecraft/skills-container.ts +1343 -0
  53. package/src/worlds/minecraft/skills-craft.ts +333 -0
  54. package/src/worlds/minecraft/skills-dig.ts +624 -0
  55. package/src/worlds/minecraft/skills-gather.ts +1230 -0
  56. package/src/worlds/minecraft/skills-interact.ts +1559 -0
  57. package/src/worlds/minecraft/tools.ts +331 -0
  58. package/src/worlds/minecraft/travel.ts +763 -0
  59. package/src/worlds/minecraft/until.ts +75 -0
  60. package/src/worlds/terminal/world.ts +8 -5
  61. package/src/providers/console/config.ts +0 -21
  62. package/src/providers/llamacpp/config.ts +0 -36
  63. package/src/providers/openai-responses-compat/config.ts +0 -20
@@ -0,0 +1,75 @@
1
+ /**
2
+ * 早停名单:find 与 tunnel 声明的 `until`,把类别名摊成方块 id,一路上撞见就收工。
3
+ *
4
+ * 只认名单与判定,收不收工由技能自己决定。
5
+ */
6
+ import type { Bot } from 'mineflayer';
7
+ import { UNTIL_CATEGORIES } from './skills.ts';
8
+ import { matchBlockIds } from './travel.ts';
9
+ import { canSeeBlockAt } from './terrain.ts';
10
+ import { zhName } from './names.ts';
11
+
12
+ /**
13
+ * `until` 的早停名单 → 方块 id 集合。
14
+ *
15
+ * `#类别` 先探一次 registry 的 tag 数据面(本仓库钉住的版本没有这一面,留着是为了
16
+ * 将来有了就自动走过去),取不到落到 `UNTIL_CATEGORIES` 那几个内置类别。
17
+ * 认不出的名字不抛错 —— 早停是这一单的副条件,它认不出来不该把整步判死;
18
+ * 认不出哪几个由回执点名(静默吃掉参数是这条链上最贵的一类失败)。
19
+ */
20
+ export function untilBlockIds(bot: Bot, until: readonly string[]): { ids: number[]; unknown: string[] } {
21
+ const byName = bot.registry.blocksByName as Record<string, { id: number; name: string }>;
22
+ const tags = (bot.registry as unknown as { blockTags?: Record<string, string[]> }).blockTags;
23
+ const ids = new Set<number>();
24
+ const unknown: string[] = [];
25
+ for (const raw of until) {
26
+ const name = raw.replace(/^minecraft:/, '');
27
+ if (name.startsWith('#')) {
28
+ const bare = name.slice(1);
29
+ const tagged = tags?.[bare] ?? tags?.[`minecraft:${bare}`] ?? null;
30
+ if (tagged) {
31
+ for (const n of tagged) {
32
+ const b = byName[n.replace(/^minecraft:/, '')];
33
+ if (b) ids.add(b.id);
34
+ }
35
+ continue;
36
+ }
37
+ const pred = UNTIL_CATEGORIES[bare];
38
+ if (!pred) { unknown.push(name); continue; }
39
+ for (const b of Object.values(byName)) if (pred(b.name)) ids.add(b.id);
40
+ continue;
41
+ }
42
+ const matched = matchBlockIds(bot, name);
43
+ if (matched.length === 0) { unknown.push(name); continue; }
44
+ for (const id of matched) ids.add(id);
45
+ }
46
+ return { ids: [...ids], unknown };
47
+ }
48
+
49
+ /** `until` 命中的那一格 */
50
+ export interface UntilHit { x: number; y: number; z: number; what: string }
51
+
52
+ /**
53
+ * 周身有没有碰到早停名单里的东西。
54
+ *
55
+ * `visible` = 只认看得见的:行军途中用这一档(与 find 自己的感知规则同源)。
56
+ * 挖通道那一档不设视线闸 —— 铲子下去露出来的那一面本来就贴着脸,视线判据在坑里没意义。
57
+ */
58
+ export function untilHit(bot: Bot, ids: readonly number[], radius: number, visible: boolean): UntilHit | null {
59
+ if (ids.length === 0) return null;
60
+ const found = bot.findBlocks({ matching: [...ids], maxDistance: radius, count: 16 });
61
+ const p = found.find((q) => !visible || canSeeBlockAt(bot, q));
62
+ if (!p) return null;
63
+ return { x: p.x, y: p.y, z: p.z, what: zhName(bot.blockAt(p)?.name ?? 'unknown') };
64
+ }
65
+
66
+ /** 行军途中每走完一段扫一次早停的半径(格) */
67
+ export const UNTIL_TRAVEL_RADIUS = 16;
68
+ /** 挖通道每挖完一格扫一次早停的半径(格):坑壁上露出来的那一圈 */
69
+ export const UNTIL_DIG_RADIUS = 4;
70
+
71
+ /** 认不出的早停名字那一句;全认得出返回空串 */
72
+ export function untilUnknownNote(unknown: readonly string[]): string {
73
+ return unknown.length > 0 ? `(until 里的 ${unknown.join('、')} 认不出来,这几样没算进去)` : '';
74
+ }
75
+
@@ -74,7 +74,8 @@ const MODEL_TEXT = {
74
74
  selfLine: (time: string, text: string) => `[${time}] you: ${text}`,
75
75
  inviteLine: (time: string, name: string, label: string, spokenBefore: boolean) =>
76
76
  `[${time}] ${name} pressed the "${label}" button on the terminal.`
77
- + (spokenBefore ? '' : ' No speech is recorded in the retained terminal history.'),
77
+ + (spokenBefore ? '' : ' Nothing has been said here before.')
78
+ + ' You may say hello and introduce yourself.',
78
79
  imageFallback: (from: string, i: number, total: number) => `image ${i}/${total} from ${from}`,
79
80
  deliveredTo: (delivered: number, names: string[]) =>
80
81
  `Sent to the chat channel on the console's "Terminal" page; ${delivered} connection${delivered === 1 ? '' : 's'} online right now`
@@ -251,6 +252,8 @@ interface TerminalWorldOptions {
251
252
 
252
253
  const NAME_MAX = 32;
253
254
  const TEXT_MAX = 4000;
255
+ /** 按钮标签进事件正文前的长度上限。 */
256
+ const LABEL_MAX = 40;
254
257
 
255
258
  /** 一条消息最多带几张图,单张解码后的字节上限。与面板侧的上限一致。 */
256
259
  const IMAGES_MAX = 8;
@@ -606,8 +609,8 @@ export class TerminalWorld implements World {
606
609
  this.sendJson(client.peer, { type: 'sys', text: t.botNotConnected });
607
610
  return;
608
611
  }
609
- // 事件引用单行标签;没有标签时不产生事件。
610
- const label = typeof msg.label === 'string' ? msg.label.replace(/\s+/g, ' ').trim() : '';
612
+ // 标签逐字进事件正文,所以压成一行并截断;没有标签就没有可引用的事实,这一帧作废。
613
+ const label = typeof msg.label === 'string' ? msg.label.replace(/\s+/g, ' ').trim().slice(0, LABEL_MAX) : '';
611
614
  if (!label) return;
612
615
  const host = this.host;
613
616
  host.pushEvent(
@@ -628,11 +631,11 @@ export class TerminalWorld implements World {
628
631
  this.sendJson(client.peer, { type: 'sys', text: t.unknownType(String(msg.type)) });
629
632
  }
630
633
 
631
- /** 已保存的终端事件中是否有发言。 */
634
+ /** 这个终端上有没有人说过话。末尾几十条够判断:这颗按钮只在事件库还空着时露面。 */
632
635
  private spokenBefore(): boolean {
633
636
  if (!this.host) return false;
634
637
  return this.host.store
635
- .range({ source: this.id })
638
+ .range({ source: this.id, limit: 50 })
636
639
  .some((e) => e.type === 'terminal.message' || e.type === 'terminal.self');
637
640
  }
638
641
 
@@ -1,21 +0,0 @@
1
- import type { ConfigGroup } from '../../core/config-schema.ts';
2
- import type { LLMProviderEntry } from '../../core/types.ts';
3
- import type { Language } from '../../core/language.ts';
4
- import { text } from './strings.ts';
5
-
6
- export function connectionGroup(name: string, entry: LLMProviderEntry, language: Language): ConfigGroup {
7
- const S = text(language);
8
- const prefix = `providers.${name}.`;
9
- return {
10
- id: `llm.${entry.kind}.${name}.connection`,
11
- owner: `provider:${entry.kind}`,
12
- schema: {
13
- type: 'object', title: name, description: S.connectionDescription,
14
- properties: {
15
- [`${prefix}baseUrl`]: { type: 'string', title: S.baseUrl, 'x-hot': true },
16
- [`${prefix}secret`]: { type: 'string', title: S.secret, description: S.secretDescription, 'x-hot': true },
17
- [`${prefix}multimodal`]: { type: 'boolean', title: S.multimodal, 'x-hot': true },
18
- },
19
- },
20
- };
21
- }
@@ -1,36 +0,0 @@
1
- import type { ConfigGroup, ConfigProperty } from '../../core/config-schema.ts';
2
- import type { Language } from '../../core/language.ts';
3
- import type { LLMProviderEntry } from '../../core/types.ts';
4
- import { backendChoices, llamacppOptions } from './options.ts';
5
- import { panel } from './strings.ts';
6
-
7
- export function runtimeConfig(name: string, entry: LLMProviderEntry, language: Language): ConfigGroup[] {
8
- if (!llamacppOptions(entry).runtime) return [];
9
- const S = panel[language];
10
- const group = (id: string, title: string, properties: Record<string, ConfigProperty>): ConfigGroup => ({
11
- id: `llm.llamacpp.${name}.${id}`,
12
- owner: 'provider:llamacpp',
13
- schema: {
14
- type: 'object', title,
15
- properties: Object.fromEntries(Object.entries(properties).map(([path, property]) => [
16
- `providers.${name}.options.${path}`, { ...property, 'x-hot': true },
17
- ])),
18
- },
19
- });
20
- return [
21
- group('runtime', S.runtimeSection, {
22
- 'runtime.release': { type: 'string', title: S.release, description: S.releaseHint },
23
- 'runtime.backend': { type: 'string', title: S.backend, enum: backendChoices() },
24
- 'runtime.runtimeDir': {
25
- type: 'string', title: S.runtimeDir, description: S.runtimeDirHint, 'x-path': { kind: 'directory' },
26
- },
27
- }),
28
- group('launch', S.launchSection, {
29
- 'launch.contextSize': { type: 'integer', title: S.contextSize, minimum: 1, description: S.launchSectionDesc },
30
- 'launch.nGpuLayers': { type: 'integer', title: S.nGpuLayers, minimum: 0 },
31
- 'launch.parallel': { type: 'integer', title: S.parallel, minimum: 1 },
32
- 'launch.extraArgs': { type: 'string', title: S.extraArgs, description: S.extraArgsHint },
33
- autoStart: { type: 'boolean', title: S.autoStart },
34
- }),
35
- ];
36
- }
@@ -1,20 +0,0 @@
1
- import type { ConfigGroup } from '../../core/config-schema.ts';
2
- import type { LLMProviderEntry } from '../../core/types.ts';
3
- import type { Language } from '../../core/language.ts';
4
- import { text } from './strings.ts';
5
-
6
- export function protocolConfig(name: string, entry: LLMProviderEntry, language: Language): ConfigGroup[] {
7
- const S = text(language);
8
- return [{
9
- id: `llm.${entry.kind}.${name}.protocol`,
10
- owner: `provider:${entry.kind}`,
11
- schema: {
12
- type: 'object', title: name,
13
- properties: {
14
- [`providers.${name}.options.endpointPath`]: {
15
- type: 'string', title: S.endpointPath, description: S.endpointPathDescription, 'x-hot': true,
16
- },
17
- },
18
- },
19
- }];
20
- }