@songsid/agend 2.4.0-beta.23 → 2.4.0-beta.24

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 (152) hide show
  1. package/dist/agent-cli-instructions.md +4 -3
  2. package/dist/agent-cli.js +32 -2
  3. package/dist/agent-cli.js.map +1 -1
  4. package/dist/agent-file-read.js +2 -2
  5. package/dist/agent-file-read.js.map +1 -1
  6. package/dist/agent-whats-new.js +11 -1
  7. package/dist/agent-whats-new.js.map +1 -1
  8. package/dist/backend/claude-code.d.ts +15 -0
  9. package/dist/backend/claude-code.js +8 -3
  10. package/dist/backend/claude-code.js.map +1 -1
  11. package/dist/backend/claude-mcp-carry.d.ts +63 -0
  12. package/dist/backend/claude-mcp-carry.js +242 -0
  13. package/dist/backend/claude-mcp-carry.js.map +1 -0
  14. package/dist/build-provenance.json +1 -1
  15. package/dist/channel/mcp-tools.js +7 -6
  16. package/dist/channel/mcp-tools.js.map +1 -1
  17. package/dist/config-validator.js +6 -0
  18. package/dist/config-validator.js.map +1 -1
  19. package/dist/daemon.d.ts +11 -0
  20. package/dist/daemon.js +66 -15
  21. package/dist/daemon.js.map +1 -1
  22. package/dist/dashboard-permissions.d.ts +8 -0
  23. package/dist/dashboard-permissions.js +8 -0
  24. package/dist/dashboard-permissions.js.map +1 -1
  25. package/dist/delivery-outbox.d.ts +15 -1
  26. package/dist/delivery-outbox.js +60 -2
  27. package/dist/delivery-outbox.js.map +1 -1
  28. package/dist/fleet-manager.d.ts +14 -0
  29. package/dist/fleet-manager.js +67 -0
  30. package/dist/fleet-manager.js.map +1 -1
  31. package/dist/general-knowledge/skills/concepts/SKILL.md +22 -9
  32. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +6 -0
  33. package/dist/general-knowledge/skills/fleet-config/SKILL.md +3 -3
  34. package/dist/general-knowledge/skills/instance-lifecycle/SKILL.md +1 -1
  35. package/dist/general-knowledge/skills/task-board/SKILL.md +17 -0
  36. package/dist/general-knowledge/skills/web-appearance/SKILL.md +4 -0
  37. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +21 -3
  38. package/dist/hub/group-policy/resources.d.ts +1 -1
  39. package/dist/instance-lifecycle.d.ts +2 -0
  40. package/dist/instance-lifecycle.js +29 -1
  41. package/dist/instance-lifecycle.js.map +1 -1
  42. package/dist/locale.js +10 -0
  43. package/dist/locale.js.map +1 -1
  44. package/dist/needs-you-hub.d.ts +3 -0
  45. package/dist/needs-you-hub.js +31 -5
  46. package/dist/needs-you-hub.js.map +1 -1
  47. package/dist/needs-you.d.ts +14 -1
  48. package/dist/needs-you.js +5 -0
  49. package/dist/needs-you.js.map +1 -1
  50. package/dist/office-share-page.js +1 -1
  51. package/dist/office-share-page.js.map +1 -1
  52. package/dist/office-share.js +2 -1
  53. package/dist/office-share.js.map +1 -1
  54. package/dist/outbound-handlers.js +29 -6
  55. package/dist/outbound-handlers.js.map +1 -1
  56. package/dist/outbound-schemas.d.ts +3 -0
  57. package/dist/outbound-schemas.js +7 -5
  58. package/dist/outbound-schemas.js.map +1 -1
  59. package/dist/public-web-gateway.js +3 -0
  60. package/dist/public-web-gateway.js.map +1 -1
  61. package/dist/request-context-compatibility.d.ts +20 -0
  62. package/dist/request-context-compatibility.js +74 -0
  63. package/dist/request-context-compatibility.js.map +1 -0
  64. package/dist/request-context-protocol.d.ts +137 -0
  65. package/dist/request-context-protocol.js +38 -0
  66. package/dist/request-context-protocol.js.map +1 -0
  67. package/dist/request-context-store.d.ts +25 -0
  68. package/dist/request-context-store.js +137 -0
  69. package/dist/request-context-store.js.map +1 -0
  70. package/dist/scheduler/db.js +26 -0
  71. package/dist/scheduler/db.js.map +1 -1
  72. package/dist/scheduler/task-board-text.d.ts +2 -0
  73. package/dist/scheduler/task-board-text.js +12 -0
  74. package/dist/scheduler/task-board-text.js.map +1 -1
  75. package/dist/scheduler/task-board.d.ts +102 -2
  76. package/dist/scheduler/task-board.js +242 -24
  77. package/dist/scheduler/task-board.js.map +1 -1
  78. package/dist/scheduler/task-files.d.ts +80 -0
  79. package/dist/scheduler/task-files.js +357 -0
  80. package/dist/scheduler/task-files.js.map +1 -0
  81. package/dist/settings-api.d.ts +2 -0
  82. package/dist/settings-api.js +6 -1
  83. package/dist/settings-api.js.map +1 -1
  84. package/dist/settings-baseline.d.ts +1 -0
  85. package/dist/settings-baseline.js +1 -1
  86. package/dist/settings-baseline.js.map +1 -1
  87. package/dist/settings-effect.d.ts +2 -0
  88. package/dist/settings-effect.js +5 -1
  89. package/dist/settings-effect.js.map +1 -1
  90. package/dist/task-attach-client.d.ts +43 -0
  91. package/dist/task-attach-client.js +125 -0
  92. package/dist/task-attach-client.js.map +1 -0
  93. package/dist/task-board-tool.d.ts +12 -0
  94. package/dist/task-board-tool.js +107 -6
  95. package/dist/task-board-tool.js.map +1 -1
  96. package/dist/task-file-limits.d.ts +15 -0
  97. package/dist/task-file-limits.js +21 -0
  98. package/dist/task-file-limits.js.map +1 -0
  99. package/dist/tool-permissions.d.ts +32 -0
  100. package/dist/tool-permissions.js +63 -0
  101. package/dist/tool-permissions.js.map +1 -1
  102. package/dist/types.d.ts +6 -0
  103. package/dist/ui/agent-details-settings.js +7 -5
  104. package/dist/ui/agent-who-can-use-strings.js +125 -0
  105. package/dist/ui/agent-who-can-use.js +238 -0
  106. package/dist/ui/fleet-office-card.js +23 -5
  107. package/dist/ui/fleet-office-editor.js +5 -5
  108. package/dist/ui/fleet-office-pack.d.ts +10 -0
  109. package/dist/ui/fleet-office-pack.js +65 -2
  110. package/dist/ui/fleet-office-skin.js +42 -8
  111. package/dist/ui/fleet-office-store.js +33 -2
  112. package/dist/ui/fleet-office-vehicles.js +130 -0
  113. package/dist/ui/fleet-office-zones.js +5 -1
  114. package/dist/ui/fleet-office.js +112 -31
  115. package/dist/ui/fleet-task-activity.js +9 -82
  116. package/dist/ui/fleet-task-archive.js +111 -0
  117. package/dist/ui/fleet-task-card.js +6 -4
  118. package/dist/ui/fleet-task-common.js +2 -2
  119. package/dist/ui/fleet-task-edit.js +8 -1
  120. package/dist/ui/fleet-task-files.js +196 -0
  121. package/dist/ui/fleet-task-md.js +98 -0
  122. package/dist/ui/fleet-task-menu.js +1 -1
  123. package/dist/ui/fleet-task-stats.js +2 -2
  124. package/dist/ui/fleet-task-view.js +12 -8
  125. package/dist/ui/fleet-tasks.js +42 -18
  126. package/dist/ui/panel-details.js +3 -1
  127. package/dist/ui/panel-needs.js +3 -3
  128. package/dist/ui/panel-settings.js +15 -1
  129. package/dist/ui/settings-registry.js +1 -0
  130. package/dist/ui/settings-shared-strings.js +9 -0
  131. package/dist/ui/settings-shared.js +6 -1
  132. package/dist/ui/shared/app-i18n.js +2 -2
  133. package/dist/ui/shared/app-needs.js +8 -1
  134. package/dist/ui/shared/app.css +55 -3
  135. package/dist/ui/shared/chat-strings.js +4 -4
  136. package/dist/ui/shared/task-board.css +64 -0
  137. package/dist/web-api.d.ts +3 -0
  138. package/dist/web-api.js +97 -14
  139. package/dist/web-api.js.map +1 -1
  140. package/dist/web-office-acts.d.ts +16 -0
  141. package/dist/web-office-acts.js +27 -9
  142. package/dist/web-office-acts.js.map +1 -1
  143. package/dist/web-office-pack-read.js +1 -1
  144. package/dist/web-office-pack-read.js.map +1 -1
  145. package/dist/web-office-skins.d.ts +5 -3
  146. package/dist/web-office-skins.js +20 -16
  147. package/dist/web-office-skins.js.map +1 -1
  148. package/dist/web-settings-patch.d.ts +27 -0
  149. package/dist/web-settings-patch.js +67 -0
  150. package/dist/web-settings-patch.js.map +1 -1
  151. package/dist/workflow-templates/default.md +1 -0
  152. package/package.json +1 -1
@@ -0,0 +1,125 @@
1
+ // M-3734 (#4459, the user's 2X): the words of an agent page's "Who can use" (agent-who-can-use.js). Their own module and
2
+ // namespace: a tab that still holds an older strings module gets these too (upgrade skew). The guest levels, the people
3
+ // search and the sign-in state keep Settings → Guests' own words (settings.*), so both places say the same thing.
4
+ import { register, t } from "/assets/app-i18n.js";
5
+
6
+ register("agentWhoCanUse", {
7
+ en: {
8
+ tab: "Who can use",
9
+ lead: "Who can chat with this agent on the web as a guest, and who may ask it on the Hub.",
10
+ adminsNote: "Fleet admins can always use every agent. Who can talk to the bot in Discord or Telegram is the bot's own setting (its allowed users) and isn't changed here.",
11
+ agentLabel: "{0} ({1})",
12
+ guestsTitle: "Web guests",
13
+ guestsLead: "People you let sign in to this dashboard as guests. It's the same list as Settings → Guests: a change made in either place shows in both.",
14
+ openGuests: "Open Settings → Guests",
15
+ guestsOff: "Guest sign-in is off, so no one below can sign in until it's turned on in Settings → Guests.",
16
+ notAdmin: "Only a fleet admin can see and change who can use this agent.",
17
+ notGrantable: "Guests can't be given this agent.",
18
+ none: "No guest can use this agent.",
19
+ derived: "Right now guests can use the agents they've talked to in chat. Nothing is chosen per agent yet, so this list can't be changed.",
20
+ convertHint: "“Start from today's guests” saves that access as each guest's own choices: everyone keeps exactly the agents they can use now, nothing more. After that, a guest can use this agent only if you add them here or in Settings → Guests. Saving it needs a fleet admin's confirmation, like adding someone.",
21
+ derivedList: "Can use it today:",
22
+ convert: "Start from today's guests",
23
+ convertTitle: "Choose who can use each agent?",
24
+ convertConfirm: "Each guest keeps exactly the agents they can use now. After this, a guest can use an agent only when you add them to it. Saving it needs a fleet admin's confirmation.",
25
+ levelAll: "{0}'s level (Chat or Trusted) applies to all {1} agents they can use, not only this one.",
26
+ changed: "This person's access changed since this list was read, so nothing was saved. The list is up to date now: check it and try again.",
27
+ changedAll: "Guests' access changed since this list was read, so nothing was saved. The list is up to date now: check it and try again.",
28
+ alsoUses: "Can also use: {0}",
29
+ level: "Level",
30
+ remove: "Remove",
31
+ removeTitle: "Remove {0}?",
32
+ removeConfirm: "{0} will no longer be able to use {1}.",
33
+ removeLast: "{0} will no longer be able to use {1}. It's the only agent they can use, so their guest access ends and they're signed out.",
34
+ add: "Add a person",
35
+ addHint: "People who have messaged one of your agents in Discord or Telegram. Fleet admins aren't listed: they can already use every agent.",
36
+ addMissing: "Not in the list? Ask them to send any of your agents a message once, then look again.",
37
+ addConfirm: "Adding someone, or making them Trusted, needs a fleet admin's confirmation. Signed in here as an admin, you can confirm it yourself on the confirm card at the top of this page (Apply now, or your authenticator code if you require one). Otherwise an admin presses Confirm on the card in General.",
38
+ searchLabel: "Search people who have messaged your agents",
39
+ noPeople: "No one matches. A person must have messaged one of your agents first.",
40
+ trustedHint: "Trusted can also watch these agents' screens (read-only) and search their chats. The screen shows everything the agent's terminal does: other people's messages to it, commands and their output, which can include secrets. Chat and search stay limited to what this person may see.",
41
+ addOne: "Add",
42
+ searchShort: "Search by name",
43
+ adding: "Adding…",
44
+ waiting: "Sent for confirmation: confirm it on the card at the top of this page (or in General). It applies once confirmed.",
45
+ saved: "Saved.",
46
+ saveFailed: "Couldn't save: {0}",
47
+ refused: "AgEnD can't give this person access: {0}",
48
+ unknown: "The change isn't confirmed. Check the list before trying again.",
49
+ hubTitle: "Hub",
50
+ hubLead: "Who may ask this agent on the Hub (people or directory groups, each until a date you choose) is set on the Hub itself.",
51
+ hubWhere: "“Choose who may ask on the Hub” opens the Hub's own page. That page opens only on the internal network: it won't open outside the internal network (for example, at home).",
52
+ hubChoose: "Choose who may ask on the Hub",
53
+ hubSettings: "Open Settings → Hub",
54
+ hubNone: "This Fleet isn't connected to a Hub.",
55
+ hubNotPaired: "This Fleet isn't connected to its Hub right now.",
56
+ hubOffline: "This Fleet can't reach its Hub right now. The Hub page may still open where the Hub can be reached.",
57
+ hubNotShared: "This agent isn't shared on the Hub, so no one there can ask it. Share it in Settings → Hub first.",
58
+ hubPending: "Sharing this agent is waiting for confirmation.",
59
+ hubLapsed: "This agent's share needs renewing: use Share again in Settings → Hub.",
60
+ hubRefused: "The Hub refused this agent's share. See Settings → Hub.",
61
+ hubFrozen: "This agent's share is paused on the Hub.",
62
+ hubShared: "Shared on the Hub.",
63
+ hubLoadFailed: "Couldn't read this agent's Hub sharing.",
64
+ },
65
+ "zh-TW": {
66
+ tab: "誰能用",
67
+ lead: "誰能以訪客身分在網頁上和這個 Agent 聊天,以及誰可以在 Hub 上問它。",
68
+ adminsNote: "Fleet 管理員一律可以使用每個 Agent。誰能在 Discord 或 Telegram 和機器人對話是機器人本身的設定(允許的使用者),這裡不會改動。",
69
+ agentLabel: "{0}({1})",
70
+ guestsTitle: "網頁訪客",
71
+ guestsLead: "你允許以訪客身分登入這個儀表板的人。和「設定 → 訪客」是同一份清單:在任一處修改,兩邊都會看到。",
72
+ openGuests: "開啟「設定 → 訪客」",
73
+ guestsOff: "訪客登入目前關閉,下面的人都要等到在「設定 → 訪客」開啟後才能登入。",
74
+ notAdmin: "只有 Fleet 管理員可以查看和修改誰能用這個 Agent。",
75
+ notGrantable: "這個 Agent 無法開放給訪客。",
76
+ none: "目前沒有訪客可以使用這個 Agent。",
77
+ derived: "目前訪客可以使用他們在聊天中互動過的 Agent。還沒有逐一選擇,所以這份名單無法修改。",
78
+ convertHint: "按「從現有訪客開始」會把這些存取存成每位訪客自己的授權:每個人都只保留他們現在能用的 Agent,不會多。之後,訪客只有在你從這裡或「設定 → 訪客」加入後,才能使用這個 Agent。儲存前需要 Fleet 管理員確認,和新增人員一樣。",
79
+ derivedList: "目前能用的人:",
80
+ convert: "從現有訪客開始",
81
+ convertTitle: "要改成逐一選擇誰能用每個 Agent 嗎?",
82
+ convertConfirm: "每位訪客都保留他們現在能用的 Agent。之後,訪客只有在你把他們加進某個 Agent 時才能使用它。儲存前需要 Fleet 管理員確認。",
83
+ levelAll: "{0} 的等級(聊天或信任)套用到他們能用的全部 {1} 個 Agent,不只這一個。",
84
+ changed: "這個人的權限在讀取清單後有變動,所以沒有儲存。清單已更新:請確認後再試一次。",
85
+ changedAll: "訪客的權限在讀取清單後有變動,所以沒有儲存。清單已更新:請確認後再試一次。",
86
+ alsoUses: "也可以用:{0}",
87
+ level: "等級",
88
+ remove: "移除",
89
+ removeTitle: "要移除 {0} 嗎?",
90
+ removeConfirm: "{0} 將無法再使用 {1}。",
91
+ removeLast: "{0} 將無法再使用 {1}。這是他們唯一能用的 Agent,所以他們的訪客權限會結束並被登出。",
92
+ add: "新增人員",
93
+ addHint: "在 Discord 或 Telegram 傳過訊息給你任一個 Agent 的人。Fleet 管理員不會列出,因為他們本來就能用每個 Agent。",
94
+ addMissing: "名單裡沒有?請對方先傳一則訊息給你任一個 Agent,再回來看。",
95
+ addConfirm: "新增人員或改為「信任」需要 Fleet 管理員確認。你在這裡以管理員身分登入時,可以在本頁上方的確認卡自己確認(按「立即套用」,或輸入驗證器 App 的 6 位數驗證碼);否則由管理員在 General 的確認卡上按「確認」。",
96
+ searchLabel: "搜尋傳過訊息給你的 Agent 的人",
97
+ noPeople: "沒有符合的人。對方必須先傳過訊息給你的某個 Agent。",
98
+ trustedHint: "信任另外可以:觀看這些 Agent 的畫面(唯讀),以及搜尋它們的聊天。畫面會顯示 Agent 終端上的一切:別人傳給它的訊息、指令和它們的輸出,其中可能有機密。聊天和搜尋仍只限這個人看得到的內容。",
99
+ addOne: "新增",
100
+ searchShort: "以名稱搜尋",
101
+ adding: "新增中…",
102
+ waiting: "已送出確認:請在本頁上方的確認卡(或 General)確認,確認後才會套用。",
103
+ saved: "已儲存。",
104
+ saveFailed: "無法儲存:{0}",
105
+ refused: "AgEnD 無法開放權限給這個人:{0}",
106
+ unknown: "尚未確認變更,請先檢查清單再試一次。",
107
+ hubTitle: "Hub",
108
+ hubLead: "誰可以在 Hub 上問這個 Agent(人或目錄群組,各自有你選的到期日)是在 Hub 上設定的。",
109
+ hubWhere: "「到 Hub 選擇誰可以問」會開啟 Hub 自己的頁面。這個頁面只在內部網路內打得開,在內部網路以外(例如在家)打不開。",
110
+ hubChoose: "到 Hub 選擇誰可以問",
111
+ hubSettings: "開啟「設定 → Hub」",
112
+ hubNone: "這個 Fleet 沒有連接 Hub。",
113
+ hubNotPaired: "這個 Fleet 目前沒有連上它的 Hub。",
114
+ hubOffline: "這個 Fleet 目前連不到它的 Hub。在連得到 Hub 的地方,Hub 頁面可能仍然打得開。",
115
+ hubNotShared: "這個 Agent 沒有在 Hub 上分享,所以 Hub 上沒有人能問它。請先在「設定 → Hub」分享它。",
116
+ hubPending: "分享這個 Agent 正在等待確認。",
117
+ hubLapsed: "這個 Agent 的分享需要更新:請在「設定 → Hub」按「重新分享」。",
118
+ hubRefused: "Hub 拒絕了這個 Agent 的分享。請看「設定 → Hub」。",
119
+ hubFrozen: "這個 Agent 的分享在 Hub 上已暫停。",
120
+ hubShared: "已在 Hub 上分享。",
121
+ hubLoadFailed: "無法讀取這個 Agent 在 Hub 上的分享狀態。",
122
+ },
123
+ });
124
+
125
+ export const wc = (k, ...v) => t(`agentWhoCanUse.${k}`, ...v);
@@ -0,0 +1,238 @@
1
+ // M-3734 (#4459, the user's 2X): an agent page's "Who can use" (agent-details-settings.js, category "access"). One place
2
+ // that lists and edits the two existing records of who can use this agent — no third permission model:
3
+ // - Web guests: web.guests.grants (Settings → Guests' own data, read with GET /api/settings/guests). Each change writes one
4
+ // person's whole grant with PUT /api/settings/fleet/web { guests: { grants: { <account>: grant | null } } } — the same
5
+ // write as Settings → Guests' Save, through the same Settings confirmation: adding a person or an agent, or making them
6
+ // Trusted, waits for a fleet admin (202, followed by settings-confirm.js); taking away applies at once. Each write is made
7
+ // from the grant this page shows and carries it as `if_grants` (Prism #4461 P2): the server refuses it (409) when that
8
+ // grant changed since — checked as it is admitted and again as it applies after a confirmation — so a change made
9
+ // meanwhile in Settings → Guests is never written over, and Remove's question is about exactly what is written.
10
+ // While the fleet still uses #1920's derived access (no grants saved), the list is read-only, and "Start from today's
11
+ // guests" saves each guest's current reach as a grant (Settings → Guests' own button, one write here, `if_grants: "unset"`):
12
+ // the server takes it only while it is exactly each guest's derived access then (Prism #4461 R1) — never access narrowed since.
13
+ // - Hub: who may ask is kept only on the Hub (its grants: people or AD groups, each with an expiry); the Fleet never reads
14
+ // or writes it. This says whether the agent is shared and links to the Hub page that chooses who may ask
15
+ // (`?agent=<exposureId>&grant=1`, as Settings → Hub does) — on the Hub's own address, so only where the Hub is reachable.
16
+ // Discord / Telegram allowed_users is the whole bot's setting and stays as it is. Its own reads and writes (like
17
+ // Permissions, contact-permissions.js) — never staged with the page's settings Save. The server decides who may see or
18
+ // change anything: a session that isn't a fleet admin's gets 403 and is told so.
19
+ import { html, useEffect, useRef, useState } from "/assets/app-html.js";
20
+ import { t } from "/assets/app-i18n.js";
21
+ import { Skeleton } from "/assets/ui-states.js";
22
+ import { toast } from "/assets/ui-toast.js";
23
+ import { confirmDialog } from "/assets/ui-confirm.js";
24
+ import { settingsPath } from "/assets/app-route.js";
25
+ import { api, confirmedWrite } from "./settings-confirm.js";
26
+ import "./settings-strings.js";
27
+ import { hubClient, hubMarks, safeWebOrigin } from "./hub-client.js";
28
+ import { wc } from "./agent-who-can-use-strings.js";
29
+
30
+ const tn = (k, ...v) => t(`settings.${k}`, ...v);
31
+ const PLATFORMS = { discord: "Discord", telegram: "Telegram" };
32
+ const accountKey = (g) => `${g.adapterId}:${g.userId}`;
33
+ const levelOf = (g) => (g && g.level === "trusted" ? "trusted" : "chat");
34
+ /** A grant as written: chat is the default level, never written (settings-guests.js grantOf). */
35
+ export const grantOf = (v) => ({ ...(v.name ? { name: v.name } : {}), instances: [...v.instances], ...(v.level === "trusted" ? { level: "trusted" } : {}) });
36
+ const GUESTS_URL = "/api/settings/guests";
37
+ const WRITE_URL = "/api/settings/fleet/web";
38
+
39
+ /**
40
+ * The people this page lists for `name`, from the guests overview: with grants saved, each one whose grant names it (`editable`);
41
+ * before that (#1920's derived access), each guest who can use it today, read-only.
42
+ */
43
+ export function whoCanUse(overview, name) {
44
+ const guests = (overview && Array.isArray(overview.guests) && overview.guests) || [];
45
+ if (overview && overview.explicit) return guests.filter((g) => g.grant && Array.isArray(g.grant.instances) && g.grant.instances.includes(name));
46
+ return guests.filter((g) => Array.isArray(g.scope) && g.scope.includes(name));
47
+ }
48
+ /** Whether a guest may be given `name` at all: one of fleet.yaml's instances, or a ClassicBot room (#2667). */
49
+ export const grantable = (overview, name) => !!overview && ((overview.instances || []).includes(name) || (overview.rooms || []).some((r) => r.name === name));
50
+ /** Each guest's current reach as a grant — Settings → Guests' "Start from today's guests". */
51
+ export function todaysGrants(overview) {
52
+ const out = {};
53
+ for (const g of (overview && overview.guests) || []) if (Array.isArray(g.scope) && g.scope.length) out[accountKey(g)] = { ...(g.name ? { name: g.name } : {}), instances: [...g.scope] };
54
+ return out;
55
+ }
56
+ /**
57
+ * One person's grant after a change on this page, from the grant saved now (null: none): "add" adds `name` (a new grant
58
+ * when there is none, at the Chat level), "remove" takes it away (no agent left: the grant goes, null), "level" sets it.
59
+ */
60
+ export function nextGrant(saved, name, change, extra = {}) {
61
+ const base = saved ? grantOf(saved) : { ...(extra.name ? { name: extra.name } : {}), instances: [] };
62
+ if (change === "add") return base.instances.includes(name) ? base : { ...base, instances: [...base.instances, name] };
63
+ if (change === "remove") { const instances = base.instances.filter((n) => n !== name); return instances.length ? { ...base, instances } : null; }
64
+ if (change === "level") return saved ? grantOf({ ...base, level: extra.level === "trusted" ? "trusted" : undefined }) : null;
65
+ return base;
66
+ }
67
+ const roomName = (overview, n) => { const r = ((overview && overview.rooms) || []).find((x) => x.name === n); return (r && r.display_name) || n; };
68
+
69
+ export function WhoCanUsePanel({ name, display }) {
70
+ // The agent as people know it — its display name, with the name the page heading uses beside it when they differ.
71
+ const shown = display && display !== name ? wc("agentLabel", display, name) : name;
72
+ return html`<div class="ap-who">
73
+ <p class="note ap-who-admins">${wc("adminsNote")}</p>
74
+ <${GuestsCard} name=${name} shown=${shown} />
75
+ <${HubCard} name=${name} />
76
+ </div>`;
77
+ }
78
+
79
+ function GuestsCard({ name, shown }) {
80
+ const [overview, setOverview] = useState(null), [state, setState] = useState("loading"); // loading | ready | denied | failed
81
+ const [people, setPeople] = useState(null), [query, setQuery] = useState("");
82
+ const [busy, setBusy] = useState(null), [msg, setMsg] = useState(null);
83
+ const live = useRef(true), seq = useRef(0);
84
+ const read = async () => {
85
+ const n = ++seq.current;
86
+ let r = null;
87
+ try { r = await api(GUESTS_URL); } catch { r = null; }
88
+ if (!live.current || n !== seq.current) return null;
89
+ if (r && r.ok && r.body) { setOverview(r.body); setState("ready"); return r.body; }
90
+ setState(r && (r.status === 401 || r.status === 403) ? "denied" : "failed");
91
+ return null;
92
+ };
93
+ const readPeople = async () => {
94
+ let r = null;
95
+ try { r = await api(`${GUESTS_URL}/people`); } catch { r = null; }
96
+ if (live.current) setPeople(r && r.ok && r.body && Array.isArray(r.body.people) ? r.body.people : []);
97
+ };
98
+ useEffect(() => {
99
+ live.current = true; void read();
100
+ const onShow = () => { if (document.visibilityState === "visible") void read(); };
101
+ document.addEventListener("visibilitychange", onShow);
102
+ return () => { live.current = false; seq.current++; document.removeEventListener("visibilitychange", onShow); };
103
+ }, [name]);
104
+
105
+ /** One write of Settings → Guests' own shape; `body` is the guests patch. Says how it went. */
106
+ const write = async (key, guests) => {
107
+ setBusy(key); setMsg(null);
108
+ try {
109
+ const r = await confirmedWrite(WRITE_URL, { method: "PUT", body: { guests }, resendable: true, label: wc("guestsTitle"),
110
+ onPending: () => { if (live.current) setMsg({ waiting: true }); } });
111
+ if (!live.current) return;
112
+ if (r.ok) { setMsg(null); toast(wc("saved")); }
113
+ else if (r.ambiguous) setMsg({ error: wc("unknown") });
114
+ else if (r.status === 409 && r.body && (r.body.key === "guest_grant_changed" || r.body.error === "guest_grant_changed")) setMsg({ error: wc(key === "--convert" ? "changedAll" : "changed") });
115
+ else if (r.body && r.body.key === "guest_grant_refused") setMsg({ error: wc("refused", r.body.error || "") });
116
+ else setMsg({ error: wc("saveFailed", (r.body && r.body.error) || r.status) });
117
+ } catch { if (live.current) setMsg({ error: wc("unknown") }); }
118
+ finally { if (live.current) { setBusy(null); await read(); } }
119
+ };
120
+ /** One person's change, made from their grant as this page shows it (`shown`: null, none), on condition it is still that. */
121
+ const change = async (key, shownGrant, kind, extra) => {
122
+ if (busy || !overview || !overview.explicit) return;
123
+ const next = nextGrant(shownGrant, name, kind, extra);
124
+ await write(key, { grants: { [key]: next }, if_grants: { [key]: shownGrant ? grantOf(shownGrant) : null } });
125
+ };
126
+ const shownGrantOf = (key) => { const g = ((overview && overview.guests) || []).find((x) => accountKey(x) === key); return (g && g.grant) || null; };
127
+ const remove = async (g) => {
128
+ // Asked about the grant shown, and written only if it is still that one (if_grants): the warning is about what is written.
129
+ const last = !!g.grant && g.grant.instances.length === 1;
130
+ const yes = await confirmDialog({ title: wc("removeTitle", g.name), message: wc(last ? "removeLast" : "removeConfirm", g.name, shown), confirmLabel: wc("remove"), danger: true });
131
+ if (yes) await change(accountKey(g), g.grant, "remove");
132
+ };
133
+ const convert = async () => {
134
+ if (!overview || overview.explicit) return;
135
+ const yes = await confirmDialog({ title: wc("convertTitle"), message: wc("convertConfirm"), confirmLabel: wc("convert") });
136
+ if (!yes) return;
137
+ await write("--convert", { grants: todaysGrants(overview), if_grants: "unset" });
138
+ };
139
+
140
+ const head = html`<h3>${wc("guestsTitle")}</h3><p class="note">${wc("guestsLead")}</p>
141
+ <div class="field-row"><a class="btn btn-sm ap-who-go" href=${`${settingsPath("access")}#guests`}>${wc("openGuests")}</a></div>`;
142
+ if (state === "loading") return html`<section class="card ap-who-guests" id="who-guests">${head}<${Skeleton} variant="rows" lines=${3} /></section>`;
143
+ if (state === "denied") return html`<section class="card ap-who-guests" id="who-guests">${head}<p class="note" role="status">${wc("notAdmin")}</p></section>`;
144
+ if (state === "failed") return html`<section class="card ap-who-guests" id="who-guests">${head}<p class="note" role="status">${tn("guestsLoadFailed")} <button type="button" class="btn btn-sm" onClick=${read}>${t("app.retry")}</button></p></section>`;
145
+ if (!grantable(overview, name)) return html`<section class="card ap-who-guests" id="who-guests">${head}<p class="note">${wc("notGrantable")}</p></section>`;
146
+
147
+ const rows = whoCanUse(overview, name);
148
+ const explicit = !!overview.explicit;
149
+ const listed = new Set(rows.map(accountKey));
150
+ const q = query.trim().toLowerCase();
151
+ const candidates = (people || []).filter((p) => !listed.has(accountKey(p)))
152
+ .filter((p) => !q || [p.name, p.username, p.userId].some((x) => typeof x === "string" && x.toLowerCase().includes(q))).slice(0, 8);
153
+ const others = (g) => (g.grant ? g.grant.instances : g.scope || []).filter((n) => n !== name).map((n) => roomName(overview, n));
154
+ const row = (g) => {
155
+ const key = accountKey(g), levelId = `who-level-${key.replace(/[^A-Za-z0-9_-]/g, "_")}`, level = levelOf(g.grant), on = g.sessions || g.devices, mine = busy === key, also = others(g);
156
+ return html`<li key=${key} class="ap-who-row" data-account=${key}>
157
+ <span class="ap-who-av" aria-hidden="true">${(g.name || "?").slice(0, 1).toUpperCase()}</span>
158
+ <div class="ap-who-id"><strong>${g.name || g.userId}</strong> <span class="note">${PLATFORMS[g.platform] || g.platform || ""}</span>
159
+ <div class="note ap-who-state">${on ? tn("grantsSignedIn", g.devices || g.sessions) : tn("grantsNotSignedIn")}${also.length ? html` · ${wc("alsoUses", also.join(", "))}` : null}</div></div>
160
+ ${explicit ? html`<div class="ap-who-actions">
161
+ <span class="note ap-who-level-label" id=${levelId}>${wc("level")}</span>
162
+ <div class="seg-inline" role="group" aria-labelledby=${levelId}>${["chat", "trusted"].map((l) => html`<button key=${l} type="button"
163
+ class=${`btn btn-sm${level === l ? " btn-primary" : ""}`} aria-pressed=${level === l ? "true" : "false"} data-level=${l} disabled=${!!busy}
164
+ onClick=${() => { if (level !== l) void change(key, g.grant, "level", { level: l }); }}>${tn(l === "trusted" ? "grantsLevelTrusted" : "grantsLevelChat")}</button>`)}</div>
165
+ <button type="button" class="btn btn-sm btn-danger ap-who-remove" disabled=${!!busy} aria-busy=${mine ? "true" : undefined} onClick=${() => remove(g)}>${wc("remove")}</button>
166
+ </div>${also.length ? html`<p class="note ap-who-level-all">${wc("levelAll", g.name, also.length + 1)}</p>` : null}` : html`<span class="note ap-who-level">${tn(level === "trusted" ? "grantsLevelTrusted" : "grantsLevelChat")}</span>`}
167
+ </li>`;
168
+ };
169
+ return html`<section class="card ap-who-guests" id="who-guests">${head}
170
+ ${!overview.enabled ? html`<p class="note ap-who-off" role="note">${wc("guestsOff")}</p>` : null}
171
+ ${!explicit ? html`<div class="ap-who-derived"><p class="note">${wc("derived")}</p><p class="note">${wc("convertHint")}</p>
172
+ <button type="button" class="btn btn-sm" id="whoConvert" disabled=${!!busy} onClick=${convert}>${wc("convert")}</button></div>` : null}
173
+ ${!explicit && rows.length ? html`<p class="note">${wc("derivedList")}</p>` : null}
174
+ ${rows.length ? html`<ul class="ap-who-list">${rows.map(row)}</ul>` : html`<p class="note" id="whoNone">${wc("none")}</p>`}
175
+ ${rows.some((g) => levelOf(g.grant) === "trusted") ? html`<p class="note ap-who-trusted">${wc("trustedHint")}</p>` : null}
176
+ ${explicit ? html`<details class="ap-who-add" onToggle=${(e) => { if (e.target.open && people === null) void readPeople(); }}><summary>${wc("add")}</summary>
177
+ <p class="note">${wc("addHint")} ${wc("addMissing")}</p>
178
+ <p class="note ap-who-confirm-note">${wc("addConfirm")}</p>
179
+ <input type="search" class="input" id="whoSearch" value=${query} aria-label=${wc("searchLabel")} placeholder=${wc("searchShort")} onInput=${(e) => setQuery(e.target.value)} />
180
+ ${people === null ? html`<${Skeleton} variant="rows" lines=${2} />` : !candidates.length ? html`<p class="note" id="whoNoPeople">${wc("noPeople")}</p>`
181
+ : html`<ul class="ap-who-list ap-who-pick">${candidates.map((p) => { const key = accountKey(p); return html`<li key=${key} class="ap-who-row" data-account=${key}>
182
+ <span class="ap-who-av" aria-hidden="true">${(p.name || "?").slice(0, 1).toUpperCase()}</span>
183
+ <div class="ap-who-id"><strong>${p.name}</strong> <span class="note">${PLATFORMS[p.platform] || p.platform}${p.username ? ` · @${p.username}` : ""}</span></div>
184
+ <div class="ap-who-actions"><button type="button" class="btn btn-sm" disabled=${!!busy} onClick=${() => change(key, shownGrantOf(key), "add", { name: p.name })}>${busy === key ? wc("adding") : wc("addOne")}</button></div></li>`; })}</ul>`}
185
+ </details>` : null}
186
+ ${msg && msg.waiting ? html`<p class="note ap-who-msg" role="status">${wc("waiting")}</p>` : null}
187
+ ${msg && msg.error ? html`<p class="note err ap-who-msg" role="alert">${msg.error}</p>` : null}
188
+ </section>`;
189
+ }
190
+
191
+ /** The Hub's part: this agent's share, as Settings → Hub reads it, and the way to the Hub page that chooses who may ask. */
192
+ export function hubState(marks, pairing, rows, name) {
193
+ if (!marks || !marks.member) return { kind: "none" };
194
+ if (!pairing) return { kind: "loading" };
195
+ if (pairing.state !== "paired") return { kind: "notPaired" };
196
+ if (!rows) return { kind: "loading" };
197
+ const row = rows.find((r) => r && r.agent === name);
198
+ const origin = safeWebOrigin(pairing), offline = pairing.link === "offline";
199
+ const link = row && origin && /^[a-f0-9-]{36}$/.test(row.exposureId || "") ? `${origin}/ui/hub/exposures?agent=${encodeURIComponent(row.exposureId)}&grant=1` : null;
200
+ if (!row) return { kind: "notShared", offline };
201
+ if (row.pending) return { kind: "pending", offline };
202
+ if (row.state === "frozen") return { kind: "frozen", offline };
203
+ if (row.state !== "published") return { kind: "notShared", offline };
204
+ if (row.reason === "hub_refused") return { kind: "refused", offline };
205
+ if (row.reason === "republish_required" || row.reason === "share_lapsed") return { kind: "lapsed", offline, link };
206
+ return { kind: "shared", offline, link };
207
+ }
208
+ const HUB_WORDS = { none: "hubNone", notPaired: "hubNotPaired", notShared: "hubNotShared", pending: "hubPending", frozen: "hubFrozen", refused: "hubRefused", lapsed: "hubLapsed", shared: "hubShared", failed: "hubLoadFailed" };
209
+
210
+ function HubCard({ name }) {
211
+ const marks = hubMarks();
212
+ const [pairing, setPairing] = useState(null), [rows, setRows] = useState(null), [failed, setFailed] = useState(false);
213
+ const live = useRef(true);
214
+ const read = async () => {
215
+ if (!marks.member) return;
216
+ setFailed(false);
217
+ try {
218
+ const client = hubClient();
219
+ const p = await client.pairing();
220
+ if (!live.current) return;
221
+ setPairing(p);
222
+ if (p && p.state === "paired") { const r = await client.exposures(); if (live.current) setRows(Array.isArray(r) ? r : []); }
223
+ } catch { if (live.current) setFailed(true); }
224
+ };
225
+ useEffect(() => { live.current = true; void read(); return () => { live.current = false; }; }, [name]);
226
+ const s = failed ? { kind: "failed" } : hubState(marks, pairing, rows, name);
227
+ return html`<section class="card ap-who-hub" id="who-hub" data-hub-state=${s.kind}><h3>${wc("hubTitle")}</h3>
228
+ <p class="note">${wc("hubLead")}</p>
229
+ ${s.kind === "loading" ? html`<${Skeleton} variant="rows" lines=${1} />` : html`<p class="ap-who-hub-state" role="status">${wc(HUB_WORDS[s.kind])}</p>`}
230
+ ${s.offline ? html`<p class="note">${wc("hubOffline")}</p>` : null}
231
+ ${s.kind === "failed" ? html`<button type="button" class="btn btn-sm" onClick=${read}>${t("app.retry")}</button>` : null}
232
+ ${s.link ? html`<p class="note ap-who-hub-where">${wc("hubWhere")}</p>` : null}
233
+ <div class="field-row">
234
+ ${s.link ? html`<a class="btn btn-sm btn-primary" id="whoHubChoose" href=${s.link} target="_blank" rel="noopener noreferrer">${wc("hubChoose")}<span aria-hidden="true"> ↗</span></a>` : null}
235
+ ${s.kind !== "loading" ? html`<a class="btn btn-sm" href=${settingsPath("hub")}>${wc("hubSettings")}</a>` : null}
236
+ </div>
237
+ </section>`;
238
+ }
@@ -24,19 +24,20 @@ import { backendLabel, modelText, namesOf } from "/assets/instance-nav.js";
24
24
  import { badgeText, fixedOf, tierOf, titleOf, tokens, xpOf } from "./fleet-office-levels.js";
25
25
  import { CARD_ROWS, CARD_SECTIONS, contrastRatio, relativeLuminance } from "./fleet-office-pack.js";
26
26
  import { nineSlice } from "./fleet-office-dialogue.js";
27
+ import { RENAME_LEN } from "./fleet-office-store.js";
27
28
 
28
29
  register("ocard", {
29
30
  en: {
30
31
  card: "{0}'s card", level: "Lv {0}", work: "{0} work tokens", estimated: "estimated", toNext: "{0} to Lv {1}", office: "Office", model: "Model", backend: "Backend",
31
32
  today: "Today", todayN: "{0} work tokens · {1} requests", firstSeen: "First seen", day: "Day {0}", now: "Now", nowLabel: "Now: ", find: "Find in office", chat: "Chat", pat: "Pat", feed: "Feed", tell: "Tell {0} (with their next message)", tellNote: "Off: only you see it. On: a line like “[Office] <your name> patted your head ×3” rides the next message they get anyway — it never wakes them.",
32
33
  chatWindow: "Open {0}’s chat in a new window",
33
- close: "Close", xp: "Progress to Lv {0}",
34
+ close: "Close", xp: "Progress to Lv {0}", rename: "Rename (only you see it)", renameField: "Name you see",
34
35
  },
35
36
  "zh-TW": {
36
37
  card: "{0} 的名片", level: "Lv {0}", work: "{0} 工作 token", estimated: "估算", toNext: "再 {0} 到 Lv {1}", office: "辦公室", model: "模型", backend: "後端",
37
38
  today: "今天", todayN: "{0} 工作 token · {1} 次請求", firstSeen: "首次出現", day: "第 {0} 天", now: "現在", nowLabel: "現在:", find: "在辦公室找它", chat: "聊天", pat: "摸頭", feed: "餵點心", tell: "讓 {0} 知道(隨下一則訊息)", tellNote: "關閉:只有你看得到。開啟:下一則本來就會送給它的訊息會附上一行,例如「[Office] <你的名字> patted your head ×3」,不會叫醒它。",
38
39
  chatWindow: "在新視窗開啟 {0} 的聊天",
39
- close: "關閉", xp: "升到 Lv {0} 的進度",
40
+ close: "關閉", xp: "升到 Lv {0} 的進度", rename: "改名(只有你看得到)", renameField: "你看到的名字",
40
41
  },
41
42
  });
42
43
  const tc = (k, ...v) => t(`ocard.${k}`, ...v);
@@ -334,7 +335,24 @@ function drawPortraitAvatar(cv, im, W) {
334
335
  * M-3533 R2b: `photo` (src) the agent's identity-card picture (a Hub room's), drawn as the pack portrait is, in place of
335
336
  * the figure once it loads; the figure while it loads or when it fails.
336
337
  */
337
- export function OfficeCard({ model: m, avatar, sheet, place, onChat, onFind, onClose, onReact = null, tell = null, packCard = null, picture = null, portrait = null, packScale = 2, action = null, photo = null }) {
338
+ /**
339
+ * The card's name, and with `rename` ({ value, save }) a pencil beside it: a field for the name this browser shows
340
+ * (Enter or leaving it keeps it, Escape does not; empty gives back their own).
341
+ */
342
+ function CardName({ name, rename }) {
343
+ const [editing, setEditing] = useState(false);
344
+ const field = useRef(null);
345
+ // Filled once, as the field appears: a `value` prop would put the name back over what is typed at each redraw.
346
+ useLayoutEffect(() => { if (editing && field.current) { field.current.value = (rename && rename.value) || name; field.current.focus(); field.current.select(); } }, [editing]);
347
+ if (!rename) return html`<strong class="oo-card-name">${name}</strong>`;
348
+ const done = (keep) => { if (!editing) return; setEditing(false); if (keep && field.current) rename.save(field.current.value.trim()); };
349
+ if (editing) return html`<input ref=${field} class="oo-card-rename" maxlength=${RENAME_LEN} aria-label=${tc("renameField")}
350
+ onKeyDown=${(e) => { if (e.key === "Enter") { e.preventDefault(); done(true); } else if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); done(false); } }} onBlur=${() => done(true)} />`;
351
+ return html`<span class="oo-card-name-row"><strong class="oo-card-name">${name}</strong><button type="button" class="icon-btn oo-card-rename-btn"
352
+ aria-label=${tc("rename")} title=${tc("rename")} onClick=${() => setEditing(true)}>✎</button></span>`;
353
+ }
354
+
355
+ export function OfficeCard({ model: m, avatar, sheet, place, onChat, onFind, onClose, onReact = null, tell = null, rename = null, packCard = null, picture = null, portrait = null, packScale = 2, action = null, photo = null }) {
338
356
  // `action`: one, or a list (M-3565: a Hub room's "@ it" and "Chat with it one-to-one"); the first is the primary button.
339
357
  const actions = Array.isArray(action) ? action.filter(Boolean) : action ? [action] : [];
340
358
  const actionButtons = actions.map((a, i) => html`<button key=${i} type="button" class=${`btn btn-sm ${i === 0 ? "btn-primary " : ""}oo-card-action`} title=${a.title || undefined} aria-label=${a.title || undefined} onClick=${a.run}>${a.label}</button>`);
@@ -449,7 +467,7 @@ export function OfficeCard({ model: m, avatar, sheet, place, onChat, onFind, onC
449
467
  <div class="oo-card-avatar"><canvas ref=${canvas} width="56" height="56" aria-hidden="true"></canvas>
450
468
  ${m.badge ? html`<span class=${`oo-badge tier-${m.badge.tier}${m.badge.mark ? " mark" : ""}`} aria-hidden="true">${m.badge.mark ? "" : m.badge.text}</span>` : null}</div>
451
469
  <div class="oo-card-names">
452
- <strong class="oo-card-name">${m.name}</strong>
470
+ <${CardName} name=${m.name} rename=${rename} />
453
471
  ${m.instance ? html`<div class="oo-card-instance mono" title=${m.instance}>${m.instance}</div>` : null}
454
472
  <div class="oo-card-state">${m.stateLine}</div>
455
473
  </div>
@@ -493,7 +511,7 @@ export function OfficeCard({ model: m, avatar, sheet, place, onChat, onFind, onC
493
511
  <div class="oo-card-avatar"><canvas ref=${canvas} width=${avatarPx} height=${avatarPx} aria-hidden="true"></canvas>
494
512
  ${m.badge && !hide.has("badge") ? html`<span class=${`oo-badge tier-${m.badge.tier}${m.badge.mark ? " mark" : ""}`} aria-hidden="true">${m.badge.mark ? "" : m.badge.text}</span>` : null}</div>
495
513
  <div class="oo-card-names">
496
- <strong class="oo-card-name">${m.name}</strong>
514
+ <${CardName} name=${m.name} rename=${rename} />
497
515
  ${!hide.has("instance") && m.instance ? html`<div class="oo-card-instance mono" title=${m.instance}>${m.instance}</div>` : null}
498
516
  <div class="oo-card-state">${stateLine}</div>
499
517
  </div>
@@ -3,7 +3,7 @@
3
3
  // whole teams or one instance at a time, or #2752 nobody: its style's NPCs only) and deletes one — then saves the whole list with the rev it read
4
4
  // (PUT /ui/offices; a change made meanwhile is a 409: read again, nothing overwritten). A stored office's layout (seats,
5
5
  // paths) and its layout overrides (Edit layout, fleet-office-layout.js) are kept as they are. Skin packs (#2513): the
6
- // packs the host keeps are styles to choose; an admin uploads one here (its manifest.json and its PNGs, picked together
6
+ // packs the host keeps are styles to choose; an admin uploads one here (its manifest.json and its PNG or WebP pictures, picked together
7
7
  // or as a folder — sent at once, checked by the host, which keeps it whole) or deletes one; #2692: which agents may change
8
8
  // packs, whether their changes need the admin's yes, those waiting for it, and the newest log entries. Never offered to a guest,
9
9
  // the public link or a read-only session (the host refuses them too).
@@ -30,7 +30,7 @@ register("orge", {
30
30
  failed: "The offices were not saved ({0}).", layoutKept: "Its seats and paths are kept.",
31
31
  stayInArea: "Idle people stay in their own area", stayInAreaNote: "They stroll only within the area they sit in and never go to sit in another area.",
32
32
  styleUnknown: "{0} (not available here: drawn as Desks)",
33
- packs: "Skin packs", packsLead: "Styles drawn from an artist's pictures. Pick a pack's manifest.json and all its PNG files together (or its folder).",
33
+ packs: "Skin packs", packsLead: "Styles drawn from an artist's pictures. Pick a pack's manifest.json and all its PNG or WebP files together (or its folder).",
34
34
  packsNone: "No skin packs yet.", upload: "Upload a skin pack", uploadFolder: "Upload a folder", uploading: "Uploading…", uploaded: "Skin pack “{0}” uploaded.",
35
35
  uploadFailed: "The skin pack was not uploaded: {0}", noManifest: "no manifest.json among the files", badManifest: "manifest.json is not JSON",
36
36
  removePack: "Delete {0}", removedPack: "Skin pack “{0}” deleted.", removeFailed: "The skin pack was not deleted ({0}).",
@@ -54,7 +54,7 @@ register("orge", {
54
54
  failed: "辦公室沒有儲存({0})。", layoutKept: "它的座位與路徑會保留。",
55
55
  stayInArea: "待命只在自己的區域走動", stayInAreaNote: "待命的人只在自己座位所在的區域裡走動,不會到其他區域去坐。",
56
56
  styleUnknown: "{0}(這裡沒有:以辦公桌顯示)",
57
- packs: "外觀包", packsLead: "用畫師的圖片畫出的風格。請把外觀包的 manifest.json 和所有 PNG 檔一起選取(或選整個資料夾)。",
57
+ packs: "外觀包", packsLead: "用畫師的圖片畫出的風格。請把外觀包的 manifest.json 和所有 PNG 或 WebP 檔一起選取(或選整個資料夾)。",
58
58
  packsNone: "還沒有外觀包。", upload: "上傳外觀包", uploadFolder: "上傳資料夾", uploading: "上傳中…", uploaded: "已上傳外觀包「{0}」。",
59
59
  uploadFailed: "外觀包沒有上傳:{0}", noManifest: "檔案中沒有 manifest.json", badManifest: "manifest.json 不是 JSON",
60
60
  removePack: "刪除 {0}", removedPack: "已刪除外觀包「{0}」。", removeFailed: "外觀包沒有刪除({0})。",
@@ -91,7 +91,7 @@ export async function packUpload(files) {
91
91
  try { manifest = JSON.parse(await man.file.text()); } catch { return { error: te("badManifest") }; }
92
92
  const out = {};
93
93
  for (const x of named) {
94
- if (x === man || !/\.png$/i.test(x.name)) continue;
94
+ if (x === man || !/\.(png|webp)$/i.test(x.name)) continue;
95
95
  out[x.name] = base64Of(new Uint8Array(await x.file.arrayBuffer()));
96
96
  }
97
97
  return { body: { manifest, files: out } };
@@ -126,7 +126,7 @@ function Packs({ packs, store }) {
126
126
  <span>${pk.name}</span>${pk.name !== pk.id ? html` <span class="muted mono">${pk.id}</span>` : null}
127
127
  <button type="button" class="btn btn-sm btn-danger oe-pack-remove" onClick=${() => remove(pk)} aria-label=${te("removePack", pk.name)}>${te("remove")}</button></li>`)}</ul>`
128
128
  : html`<p class="note" id="oePacksNone">${te("packsNone")}</p>`}
129
- <label class="btn btn-sm oe-upload">${te("upload")}<input type="file" class="sr-only oe-upload-files" multiple accept=".json,.png,application/json,image/png" onChange=${send} /></label>
129
+ <label class="btn btn-sm oe-upload">${te("upload")}<input type="file" class="sr-only oe-upload-files" multiple accept=".json,.png,.webp,application/json,image/png,image/webp" onChange=${send} /></label>
130
130
  <label class="btn btn-sm oe-upload">${te("uploadFolder")}<input type="file" class="sr-only oe-upload-dir" webkitdirectory="" multiple onChange=${send} /></label>
131
131
  ${msg ? html`<p class="note oe-pack-msg" role="status">${msg}</p>` : null}
132
132
  </fieldset>`;
@@ -50,6 +50,8 @@ export interface CheckedPack {
50
50
  idleVisits?: Array<{ area: string; weight: number; minSeconds: number; maxSeconds: number }>;
51
51
  /** M-3432 (#4255): optional custom snacks the viewer may drag-to-feed or place on the floor. */
52
52
  snacks?: PackSnack[];
53
+ /** A train on a loop of track (fleet-office-vehicles.js); agents ride by office_set `ride`. */
54
+ vehicles?: PackVehicle[];
53
55
  }
54
56
  /** M-3432 (#4255): one custom snack item from a pack's `snacks` list. */
55
57
  export interface PackSnack {
@@ -149,3 +151,11 @@ export function overridesBetween(pack: CheckedPack, edited: CheckedPack): Layout
149
151
  export function poseStrip(set: Record<string, PackStrip> | null | undefined, pose: string, heading?: { dx: number; dy: number } | null): { strip: PackStrip; mirror: boolean } | null;
150
152
  export function walkStrip(f: { walk?: Record<string, PackStrip> | null; walking?: boolean; heading?: { dx: number; dy: number } | null } | null | undefined): { strip: PackStrip; mirror: boolean } | null;
151
153
  export function stripBox(st: PackStrip, x: number, y: number, mirror?: boolean): { x: number; y: number; w: number; h: number };
154
+
155
+ /** A pack's vehicle, checked: round its closed `path` at `speed` units a second, waiting at each stop; riders sit at `seats`. */
156
+ export interface PackVehicle {
157
+ id: string; label?: string; sprite: PackStrip | null; sprites?: Partial<Record<"right" | "left" | "up" | "down", PackStrip>>;
158
+ fronts?: Partial<Record<"right" | "left" | "up" | "down", PackStrip>>;
159
+ path: PackPoint[]; speed: number; stops: Array<{ at: number; seconds: number; platform: PackPoint }>; seats: Array<{ dx: number; dy: number }>;
160
+ }
161
+ export const VEHICLE_LIMITS: { vehicles: number; path: number; stops: number; seats: number; minSpeed: number; maxSpeed: number; defaultSpeed: number; maxSeconds: number; defaultSeconds: number; offset: number };
@@ -693,6 +693,63 @@ function snackLabelOf(v, at) {
693
693
  return out;
694
694
  }
695
695
 
696
+ /**
697
+ * A pack's `vehicles` (a train on a loop of track): each runs round its closed `path` (logical points; the last joins
698
+ * the first) at `speed` logical units a second, and waits `seconds` at each of its `stops` (a path point's index, with
699
+ * the `platform` point people board from). `seats`: where riders sit, offsets from the vehicle's anchor as drawn
700
+ * heading right (`dx` along the car, `dy` across it; fleet-office-vehicles.js seatAt places them for each heading).
701
+ * `sprite` (its picture heading right; mirrored going left), or `sprites` by heading (`right`, `left`, `up`, `down`),
702
+ * each a strip; `fronts` the same by heading, drawn over the riders (the car's front edge hiding their lower half). Who
703
+ * rides is the agents' own choice (office_set `ride`), not the pack's.
704
+ */
705
+ export const VEHICLE_LIMITS = { vehicles: 4, path: 64, stops: 8, seats: 16, minSpeed: 5, maxSpeed: 600, defaultSpeed: 80, maxSeconds: 600, defaultSeconds: 8, offset: 2000 };
706
+ const HEADINGS = ["right", "left", "up", "down"];
707
+ function vehiclesOf(v, scale) {
708
+ if (v === undefined) return [];
709
+ const seen = new Set();
710
+ return list(v, VEHICLE_LIMITS.vehicles, "vehicles").map((x, i) => {
711
+ const at = `vehicles[${i}]`;
712
+ obj(x, at); keys(x, ["id", "label", "sprite", "sprites", "fronts", "path", "speed", "stops", "seats"], at);
713
+ if (!nameOk(x.id) || seen.has(x.id)) throw new Refused(`${at}.id`, "a new name of letters, digits, _ or - (not an inherited one)");
714
+ seen.add(x.id);
715
+ if (x.label !== undefined && (typeof x.label !== "string" || !x.label.trim() || [...x.label].length > LIMIT.line || /[\u0000-\u001f\u007f]/.test(x.label))) throw new Refused(`${at}.label`, `1–${LIMIT.line} characters`);
716
+ if (x.sprite === undefined && x.sprites === undefined) throw new Refused(at, "a sprite, or sprites by heading");
717
+ let sprites = null;
718
+ if (x.sprites !== undefined) {
719
+ obj(x.sprites, `${at}.sprites`); keys(x.sprites, HEADINGS, `${at}.sprites`);
720
+ sprites = {};
721
+ for (const h of HEADINGS) if (x.sprites[h] !== undefined) sprites[h] = checkStrip(x.sprites[h], `${at}.sprites.${h}`, scale);
722
+ if (!Object.keys(sprites).length) throw new Refused(`${at}.sprites`, "at least one heading");
723
+ }
724
+ let fronts = null;
725
+ if (x.fronts !== undefined) {
726
+ obj(x.fronts, `${at}.fronts`); keys(x.fronts, HEADINGS, `${at}.fronts`);
727
+ fronts = {};
728
+ for (const h of HEADINGS) if (x.fronts[h] !== undefined) fronts[h] = checkStrip(x.fronts[h], `${at}.fronts.${h}`, scale);
729
+ }
730
+ const path = list(x.path, VEHICLE_LIMITS.path, `${at}.path`).map((p, j) => point(p, `${at}.path[${j}]`));
731
+ if (path.length < 3) throw new Refused(`${at}.path`, "at least 3 points (a loop)");
732
+ const speed = x.speed === undefined ? VEHICLE_LIMITS.defaultSpeed : num(x.speed, VEHICLE_LIMITS.minSpeed, VEHICLE_LIMITS.maxSpeed, `${at}.speed`);
733
+ const taken = new Set();
734
+ const stops = list(x.stops ?? [], VEHICLE_LIMITS.stops, `${at}.stops`).map((s, j) => {
735
+ const here = `${at}.stops[${j}]`;
736
+ obj(s, here); keys(s, ["at", "seconds", "platform"], here);
737
+ const k = int(s.at, 0, path.length - 1, `${here}.at`);
738
+ if (taken.has(k)) throw new Refused(`${here}.at`, "a path point no other stop has");
739
+ taken.add(k);
740
+ return { at: k, seconds: s.seconds === undefined ? VEHICLE_LIMITS.defaultSeconds : num(s.seconds, 1, VEHICLE_LIMITS.maxSeconds, `${here}.seconds`), platform: point(s.platform, `${here}.platform`) };
741
+ });
742
+ const seats = list(x.seats ?? [], VEHICLE_LIMITS.seats, `${at}.seats`).map((s, j) => {
743
+ const here = `${at}.seats[${j}]`;
744
+ obj(s, here); keys(s, ["dx", "dy"], here);
745
+ return { dx: num(s.dx ?? 0, -VEHICLE_LIMITS.offset, VEHICLE_LIMITS.offset, `${here}.dx`), dy: num(s.dy ?? 0, -VEHICLE_LIMITS.offset, VEHICLE_LIMITS.offset, `${here}.dy`) };
746
+ });
747
+ if (seats.length && !stops.length) throw new Refused(`${at}.stops`, "at least one stop, for its seats to be boarded");
748
+ return { id: x.id, ...(x.label !== undefined ? { label: x.label.trim() } : {}), sprite: x.sprite === undefined ? null : checkStrip(x.sprite, `${at}.sprite`, scale),
749
+ ...(sprites ? { sprites } : {}), ...(fronts && Object.keys(fronts).length ? { fronts } : {}), path, speed, stops, seats };
750
+ });
751
+ }
752
+
696
753
  /** M-3432 (#4255): a pack's optional `snacks` list — 1–12 snack items with sprites, optional eat overlay, and attraction radius. */
697
754
  function snacksOf(v, scale) {
698
755
  if (v === undefined) return [];
@@ -742,7 +799,7 @@ export function checkLevels(v) {
742
799
  export function checkSkinPack(x, { kept = false } = {}) {
743
800
  try {
744
801
  obj(x, "pack");
745
- keys(x, ["format", "id", "scale", "canvas", "background", "foreground", "matte", "areas", "stateZones", "door", "mailDrop", "waypoints", "edges", "straight", "furniture", "characters", "byInstance", "props", "bubbles", "bubblesByInstance", "room", "desk", "levels", "portraits", "dialogBox", "idleVisits", "snacks", "card"], "pack");
802
+ keys(x, ["format", "id", "scale", "canvas", "background", "foreground", "matte", "areas", "stateZones", "door", "mailDrop", "waypoints", "edges", "straight", "furniture", "characters", "byInstance", "props", "bubbles", "bubblesByInstance", "room", "desk", "levels", "portraits", "dialogBox", "idleVisits", "snacks", "card", "vehicles"], "pack");
746
803
  if (x.format !== 1) throw new Refused("format", "1");
747
804
  if (typeof x.id !== "string" || !ID.test(x.id)) throw new Refused("id", "1–40 letters, digits, _ or -");
748
805
  if (BUILT_IN.has(x.id) || (!kept && RESERVED.has(x.id))) throw new Refused("id", "a built-in skin's id");
@@ -850,6 +907,7 @@ export function checkSkinPack(x, { kept = false } = {}) {
850
907
  const levels = levelsOf(x.levels);
851
908
  const portraits = portraitsOf(x.portraits, fids), dialogBox = dialogBoxOf(x.dialogBox), card = cardOf(x.card);
852
909
  const snacks = snacksOf(x.snacks, scale);
910
+ const vehicles = vehiclesOf(x.vehicles, scale);
853
911
  const room = x.room === undefined ? {} : obj(x.room, "room"), desk = x.desk === undefined ? {} : obj(x.desk, "desk");
854
912
  keys(room, ["floor", "wall"], "room"); keys(desk, ["back", "front", "lit"], "desk");
855
913
  const opt = (v, at) => (v === undefined ? undefined : src(v, at));
@@ -863,7 +921,7 @@ export function checkSkinPack(x, { kept = false } = {}) {
863
921
  room: { floor: opt(room.floor, "room.floor"), wall: opt(room.wall, "room.wall") }, desk: { back: opt(desk.back, "desk.back"), front: opt(desk.front, "desk.front"), lit: opt(desk.lit, "desk.lit") },
864
922
  ...(levels ? { levels } : {}), ...(idleVisits.length ? { idleVisits } : {}),
865
923
  ...(portraits ? { portraits } : {}), ...(dialogBox ? { dialogBox } : {}),
866
- ...(snacks.length ? { snacks } : {}), ...(card ? { card } : {}),
924
+ ...(snacks.length ? { snacks } : {}), ...(card ? { card } : {}), ...(vehicles.length ? { vehicles } : {}),
867
925
  } };
868
926
  } catch (err) {
869
927
  if (err instanceof Refused) return { ok: false, error: err.message };
@@ -908,6 +966,11 @@ export function packStrips(pack) {
908
966
  if (sn.sprite) out.push({ at: `snacks.${sn.id}.sprite`, strip: sn.sprite });
909
967
  if (sn.eat) out.push({ at: `snacks.${sn.id}.eat`, strip: sn.eat });
910
968
  }
969
+ for (const v of pack.vehicles || []) {
970
+ if (v.sprite) out.push({ at: `vehicles.${v.id}.sprite`, strip: v.sprite });
971
+ for (const [h, st] of Object.entries(v.sprites || {})) out.push({ at: `vehicles.${v.id}.sprites.${h}`, strip: st });
972
+ for (const [h, st] of Object.entries(v.fronts || {})) out.push({ at: `vehicles.${v.id}.fronts.${h}`, strip: st });
973
+ }
911
974
  return out;
912
975
  }
913
976