@chainingintention/pi-web-cn 2.202611.2 → 2.202611.4
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/dist/client/assets/{PiWebApp-Dur6Wi62.js → PiWebApp-rG0WhMEa.js} +863 -863
- package/dist/client/assets/{SettingsDialog-SOljSiee.js → SettingsDialog-D6czghzo.js} +1 -1
- package/dist/client/assets/{external-DjGXa4ZP.js → external-DZQ-GM9O.js} +1 -1
- package/dist/client/assets/{index-CInvlJKI.js → index-C8SnDkf4.js} +2 -2
- package/dist/client/assets/{main-CWcn0Deu.js → main-T8PgowZ_.js} +2 -2
- package/dist/client/assets/requiredTerminalPlugin-DrXvpLs1.js +3 -0
- package/dist/client/index.html +1 -1
- package/dist/pi-web-plugins/custom-ui-codex/codex.css +0 -2
- package/dist/pi-web-plugins/custom-ui-codex/fileIcons.js +30 -28
- package/dist/pi-web-plugins/custom-ui-codex/pi-web-plugin.js +3 -3
- package/dist/pi-web-plugins/files/browser/pi-web-plugin.js +6 -5
- package/dist/pi-web-plugins/zh-cn/bundled.json +1 -0
- package/dist/pi-web-plugins/zh-cn/catalogs.json +7 -0
- package/dist/server/managementAgents.js +5 -4
- package/dist/server/managementAgents.js.map +1 -1
- package/dist/server/managementAgentsRoutes.js +1 -1
- package/dist/server/managementAgentsRoutes.js.map +1 -1
- package/dist/server/normalAuth.js +3 -0
- package/dist/server/normalAuth.js.map +1 -1
- package/dist/server/piWebPluginCatalog.js +13 -5
- package/dist/server/piWebPluginCatalog.js.map +1 -1
- package/dist/server/sessions/sessionContentSearch.js +10 -6
- package/dist/server/sessions/sessionContentSearch.js.map +1 -1
- package/dist/shared/pluginApiTypes.d.ts +3 -1
- package/docs/plugins.md +5 -5
- package/package.json +1 -1
- package/dist/client/assets/requiredTerminalPlugin-B-0wkiKe.js +0 -3
package/docs/plugins.md
CHANGED
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
- **Pi 扩展**定制代理的工具、命令、钩子、模型提供器及会话行为。
|
|
43
43
|
- **PI WEB 插件**定制 Web 应用及工作区集成。
|
|
44
44
|
|
|
45
|
-
一个包可包含上述三种定制。安装包与启用 PI WEB 插件是独立操作;禁用插件不会移除包里的 Pi
|
|
45
|
+
一个包可包含上述三种定制。安装包与启用 PI WEB 插件是独立操作;禁用插件不会移除包里的 Pi 扩展、技能或提示词。同一物理包通过多个来源别名配置时只发现一次并保留首个来源;不同安装即使共享插件 ID 仍按冲突处理。
|
|
46
46
|
|
|
47
47
|
代理行为放在 Pi 扩展中,Web UI 放在 PI WEB 插件中。需要两者协作时一起发布,通过已托管会话的连接通信。
|
|
48
48
|
|
|
@@ -279,7 +279,7 @@ mkdir -p ~/.pi-web/plugins
|
|
|
279
279
|
ln -s /path/to/plugin-folder ~/.pi-web/plugins/my-plugin
|
|
280
280
|
```
|
|
281
281
|
|
|
282
|
-
设置 `PI_WEB_DATA_DIR` 时改用 `$PI_WEB_DATA_DIR/plugins`。无需重建 PI WEB,但包必须包含编译后的 JavaScript
|
|
282
|
+
设置 `PI_WEB_DATA_DIR` 时改用 `$PI_WEB_DATA_DIR/plugins`。无需重建 PI WEB,但包必须包含编译后的 JavaScript;宿主不编译任意已安装插件源码。未打包的浏览器模块须使用可解析的相对导入并带 `.js` 扩展名,渲染使用宿主提供的 `html`/`svg`,不要依赖未解析的裸运行时导入(如 `lit`);已打包的导入同样可用。
|
|
283
283
|
|
|
284
284
|
<a id="remote-machines"></a>
|
|
285
285
|
## 远端机器
|
|
@@ -305,15 +305,15 @@ ln -s /path/to/plugin-folder ~/.pi-web/plugins/my-plugin
|
|
|
305
305
|
<a id="managed-agents-review"></a>
|
|
306
306
|
### 管理工作区指令
|
|
307
307
|
|
|
308
|
-
管理嵌入的文件工具栏提供 `AGENTS.md`
|
|
308
|
+
管理嵌入的文件工具栏提供 `AGENTS.md` 二级菜单。待确认表示工作区文件内容与授权当前模板不同,与模板/本地文件时间戳或旧“不覆盖”决定无关;时间戳元数据只用于显示。存在待确认内容时,入口按钮右上角圆点脉冲提示,减少动态效果时为静态。每个模板指纹首次检出不一致会自动打开既有复核弹窗并说明原因;弹窗实际展示后,显式 acknowledge 只记录已阅、不改文件。关闭菜单或按 Escape 不构成覆盖或不覆盖决定。
|
|
309
309
|
|
|
310
|
-
|
|
310
|
+
“覆盖并备份”先将当前工作区的原文件保存到 `.pi-web/agents-backups/`,再写入授权项目提供的模板;“不覆盖”保留文件并记录该模板已阅,但内容仍不同,圆点继续显示,之后仍可手动覆盖并备份。已阅按工作区保存在现有状态中并兼容既有 v1 记录。同一模板指纹在已阅后若文件再次变化,圆点恢复但不自动弹窗;模板正文、修订或 `updatedAt` 变化会产生新指纹,不一致时可再次自动弹出一次。当前签名上下文中的模板是唯一来源;未刷新上下文时,不承诺检测远端平台侧模板变化。
|
|
311
311
|
|
|
312
312
|
确认针对当前机器、项目和工作区,切换工作区不会将旧请求结果应用到新位置。网关重新验证管理身份与工作区授权;浏览器不能指定模板正文、任意路径或备份位置。确认期间文件或模板已变化时,返回冲突而不覆盖,需重新查看后决定。缺少文件时的首次创建仍沿用项目初始化规则;已有文件不因项目解析或会话初始化自动替换。
|
|
313
313
|
|
|
314
314
|
指令确认只处理不超过 **1 MiB** 的普通文件,拒绝文件或相关托管目录的符号链接。备份保留原有 `AGENTS.<timestamp>.<fingerprint>[suffix].md` 命名,不覆盖历史备份。POSIX 平台确认覆盖时保留原文件访问权限,目标缺失时以 `0600` 创建;备份也以 `0600` 创建,仅文件所有者(服务账号)可读写。Windows 访问控制仍由系统 ACL 决定,不以 POSIX 权限位承诺隔离。
|
|
315
315
|
|
|
316
|
-
公开工作区文件能力的可选 `files.managedAgents` 提供 `status(options?)` 与 `decide({ action: "overwrite" | "keep", revision })`。`status` 返回不可用状态 `{ available: false }`,或带 `available: true`、`pending`、不透明 `revision`、文件修改时间 `modifiedAt`、平台模板更新时间 `templateModifiedAt` 和 `templateRevision` 的快照;两个时间字段可为 `null
|
|
316
|
+
公开工作区文件能力的可选 `files.managedAgents` 提供 `status(options?)` 与 `decide({ action: "overwrite" | "keep" | "acknowledge", revision })`。`status` 返回不可用状态 `{ available: false }`,或带 `available: true`、`pending`、不透明 `revision`、文件修改时间 `modifiedAt`、平台模板更新时间 `templateModifiedAt` 和 `templateRevision` 的快照;两个时间字段可为 `null`。新宿主还会成对提供可选 `promptPending` 与不透明 `promptRevision`;缺失时只提供手动复核,不发送 acknowledge 请求。`revision` 仍是完整快照 CAS 标识,不是稳定模板身份。`decide` 必须提交所查看快照的 `revision`,返回决定后的状态。普通模式及旧宿主可省略此能力,插件应按能力是否存在展示入口,而不是自行拼接私有请求。
|
|
317
317
|
|
|
318
318
|
### 工作区任务
|
|
319
319
|
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{_ as e,a as t,d as n,h as r,i,l as a,m as o,o as s,p as c,r as l,u,v as d}from"./themePreference-BBiJxLjs.js";var f=/(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;function ee(e){let t={};return e.replace(f,e=>{let n=e.length;switch(e[0]){case`G`:t.era=n===4?`long`:n===5?`narrow`:`short`;break;case`y`:t.year=n===2?`2-digit`:`numeric`;break;case`Y`:case`u`:case`U`:case`r`:throw RangeError("`Y/u/U/r` (year) patterns are not supported, use `y` instead");case`q`:case`Q`:throw RangeError("`q/Q` (quarter) patterns are not supported");case`M`:case`L`:t.month=[`numeric`,`2-digit`,`short`,`long`,`narrow`][n-1];break;case`w`:case`W`:throw RangeError("`w/W` (week) patterns are not supported");case`d`:t.day=[`numeric`,`2-digit`][n-1];break;case`D`:case`F`:case`g`:throw RangeError("`D/F/g` (day) patterns are not supported, use `d` instead");case`E`:t.weekday=n===4?`long`:n===5?`narrow`:`short`;break;case`e`:if(n<4)throw RangeError("`e..eee` (weekday) patterns are not supported");t.weekday=[`short`,`long`,`narrow`,`short`][n-3];break;case`c`:if(n<4)throw RangeError("`c..ccc` (weekday) patterns are not supported");t.weekday=[`short`,`long`,`narrow`,`short`][n-3];break;case`a`:t.hour12=!0;break;case`b`:case`B`:throw RangeError("`b/B` (period) patterns are not supported, use `a` instead");case`h`:t.hourCycle=`h12`,t.hour=[`numeric`,`2-digit`][n-1];break;case`H`:t.hourCycle=`h23`,t.hour=[`numeric`,`2-digit`][n-1];break;case`K`:t.hourCycle=`h11`,t.hour=[`numeric`,`2-digit`][n-1];break;case`k`:t.hourCycle=`h24`,t.hour=[`numeric`,`2-digit`][n-1];break;case`j`:case`J`:case`C`:throw RangeError("`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead");case`m`:t.minute=[`numeric`,`2-digit`][n-1];break;case`s`:t.second=[`numeric`,`2-digit`][n-1];break;case`S`:case`A`:throw RangeError("`S/A` (second) patterns are not supported, use `s` instead");case`z`:t.timeZoneName=n<4?`short`:`long`;break;case`Z`:case`O`:case`v`:case`V`:case`X`:case`x`:throw RangeError("`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead")}return``}),t}var te=/[\t-\r \x85\u200E\u200F\u2028\u2029]/i;function ne(e){if(e.length===0)throw Error(`Number skeleton cannot be empty`);let t=e.split(te).filter(e=>e.length>0),n=[];for(let e of t){let t=e.split(`/`);if(t.length===0)throw Error(`Invalid number skeleton`);let[r,...i]=t;for(let e of i)if(e.length===0)throw Error(`Invalid number skeleton`);n.push({stem:r,options:i})}return n}function re(e){return e.replace(/^(.*?)-/,``)}var ie=/^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g,ae=/^(@+)?(\+|#+)?[rs]?$/g,oe=/(\*)(0+)|(#+)(0+)|(0+)/g,se=/^(0+)$/;function ce(e){let t={};return e[e.length-1]===`r`?t.roundingPriority=`morePrecision`:e[e.length-1]===`s`&&(t.roundingPriority=`lessPrecision`),e.replace(ae,function(e,n,r){return typeof r==`string`?r===`+`?t.minimumSignificantDigits=n.length:n[0]===`#`?t.maximumSignificantDigits=n.length:(t.minimumSignificantDigits=n.length,t.maximumSignificantDigits=n.length+(typeof r==`string`?r.length:0)):(t.minimumSignificantDigits=n.length,t.maximumSignificantDigits=n.length),``}),t}function le(e){switch(e){case`sign-auto`:return{signDisplay:`auto`};case`sign-accounting`:case`()`:return{currencySign:`accounting`};case`sign-always`:case`+!`:return{signDisplay:`always`};case`sign-accounting-always`:case`()!`:return{signDisplay:`always`,currencySign:`accounting`};case`sign-except-zero`:case`+?`:return{signDisplay:`exceptZero`};case`sign-accounting-except-zero`:case`()?`:return{signDisplay:`exceptZero`,currencySign:`accounting`};case`sign-never`:case`+_`:return{signDisplay:`never`}}}function ue(e){let t;if(e[0]===`E`&&e[1]===`E`?(t={notation:`engineering`},e=e.slice(2)):e[0]===`E`&&(t={notation:`scientific`},e=e.slice(1)),t){let n=e.slice(0,2);if(n===`+!`?(t.signDisplay=`always`,e=e.slice(2)):n===`+?`&&(t.signDisplay=`exceptZero`,e=e.slice(2)),!se.test(e))throw Error(`Malformed concise eng/scientific notation`);t.minimumIntegerDigits=e.length}return t}function de(e){return le(e)||{}}function fe(e){let t={};for(let n of e){switch(n.stem){case`percent`:case`%`:t.style=`percent`;continue;case`%x100`:t.style=`percent`,t.scale=100;continue;case`currency`:t.style=`currency`,t.currency=n.options[0];continue;case`group-off`:case`,_`:t.useGrouping=!1;continue;case`precision-integer`:case`.`:t.maximumFractionDigits=0;continue;case`measure-unit`:case`unit`:t.style=`unit`,t.unit=re(n.options[0]);continue;case`compact-short`:case`K`:t.notation=`compact`,t.compactDisplay=`short`;continue;case`compact-long`:case`KK`:t.notation=`compact`,t.compactDisplay=`long`;continue;case`scientific`:t={...t,notation:`scientific`,...n.options.reduce((e,t)=>({...e,...de(t)}),{})};continue;case`engineering`:t={...t,notation:`engineering`,...n.options.reduce((e,t)=>({...e,...de(t)}),{})};continue;case`notation-simple`:t.notation=`standard`;continue;case`unit-width-narrow`:t.currencyDisplay=`narrowSymbol`,t.unitDisplay=`narrow`;continue;case`unit-width-short`:t.currencyDisplay=`code`,t.unitDisplay=`short`;continue;case`unit-width-full-name`:t.currencyDisplay=`name`,t.unitDisplay=`long`;continue;case`unit-width-iso-code`:t.currencyDisplay=`symbol`;continue;case`scale`:t.scale=parseFloat(n.options[0]);continue;case`rounding-mode-floor`:t.roundingMode=`floor`;continue;case`rounding-mode-ceiling`:t.roundingMode=`ceil`;continue;case`rounding-mode-down`:t.roundingMode=`trunc`;continue;case`rounding-mode-up`:t.roundingMode=`expand`;continue;case`rounding-mode-half-even`:t.roundingMode=`halfEven`;continue;case`rounding-mode-half-down`:t.roundingMode=`halfTrunc`;continue;case`rounding-mode-half-up`:t.roundingMode=`halfExpand`;continue;case`integer-width`:if(n.options.length>1)throw RangeError(`integer-width stems only accept a single optional option`);n.options[0].replace(oe,function(e,n,r,i,a,o){if(n)t.minimumIntegerDigits=r.length;else if(i&&a)throw Error(`We currently do not support maximum integer digits`);else if(o)throw Error(`We currently do not support exact integer digits`);return``});continue}if(se.test(n.stem)){t.minimumIntegerDigits=n.stem.length;continue}if(ie.test(n.stem)){if(n.options.length>1)throw RangeError(`Fraction-precision stems only accept a single optional option`);n.stem.replace(ie,function(e,n,r,i,a,o){return r===`*`?t.minimumFractionDigits=n.length:i&&i[0]===`#`?t.maximumFractionDigits=i.length:a&&o?(t.minimumFractionDigits=a.length,t.maximumFractionDigits=a.length+o.length):(t.minimumFractionDigits=n.length,t.maximumFractionDigits=n.length),``});let e=n.options[0];e===`w`?t={...t,trailingZeroDisplay:`stripIfInteger`}:e&&(t={...t,...ce(e)});continue}if(ae.test(n.stem)){t={...t,...ce(n.stem)};continue}let e=le(n.stem);e&&(t={...t,...e});let r=ue(n.stem);r&&(t={...t,...r})}return t}var pe=function(e){return e[e.EXPECT_ARGUMENT_CLOSING_BRACE=1]=`EXPECT_ARGUMENT_CLOSING_BRACE`,e[e.EMPTY_ARGUMENT=2]=`EMPTY_ARGUMENT`,e[e.MALFORMED_ARGUMENT=3]=`MALFORMED_ARGUMENT`,e[e.EXPECT_ARGUMENT_TYPE=4]=`EXPECT_ARGUMENT_TYPE`,e[e.INVALID_ARGUMENT_TYPE=5]=`INVALID_ARGUMENT_TYPE`,e[e.EXPECT_ARGUMENT_STYLE=6]=`EXPECT_ARGUMENT_STYLE`,e[e.INVALID_NUMBER_SKELETON=7]=`INVALID_NUMBER_SKELETON`,e[e.INVALID_DATE_TIME_SKELETON=8]=`INVALID_DATE_TIME_SKELETON`,e[e.EXPECT_NUMBER_SKELETON=9]=`EXPECT_NUMBER_SKELETON`,e[e.EXPECT_DATE_TIME_SKELETON=10]=`EXPECT_DATE_TIME_SKELETON`,e[e.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE=11]=`UNCLOSED_QUOTE_IN_ARGUMENT_STYLE`,e[e.EXPECT_SELECT_ARGUMENT_OPTIONS=12]=`EXPECT_SELECT_ARGUMENT_OPTIONS`,e[e.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE=13]=`EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE`,e[e.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE=14]=`INVALID_PLURAL_ARGUMENT_OFFSET_VALUE`,e[e.EXPECT_SELECT_ARGUMENT_SELECTOR=15]=`EXPECT_SELECT_ARGUMENT_SELECTOR`,e[e.EXPECT_PLURAL_ARGUMENT_SELECTOR=16]=`EXPECT_PLURAL_ARGUMENT_SELECTOR`,e[e.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT=17]=`EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT`,e[e.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT=18]=`EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT`,e[e.INVALID_PLURAL_ARGUMENT_SELECTOR=19]=`INVALID_PLURAL_ARGUMENT_SELECTOR`,e[e.DUPLICATE_PLURAL_ARGUMENT_SELECTOR=20]=`DUPLICATE_PLURAL_ARGUMENT_SELECTOR`,e[e.DUPLICATE_SELECT_ARGUMENT_SELECTOR=21]=`DUPLICATE_SELECT_ARGUMENT_SELECTOR`,e[e.MISSING_OTHER_CLAUSE=22]=`MISSING_OTHER_CLAUSE`,e[e.INVALID_TAG=23]=`INVALID_TAG`,e[e.INVALID_TAG_NAME=25]=`INVALID_TAG_NAME`,e[e.UNMATCHED_CLOSING_TAG=26]=`UNMATCHED_CLOSING_TAG`,e[e.UNCLOSED_TAG=27]=`UNCLOSED_TAG`,e}({}),p=function(e){return e[e.literal=0]=`literal`,e[e.argument=1]=`argument`,e[e.number=2]=`number`,e[e.date=3]=`date`,e[e.time=4]=`time`,e[e.select=5]=`select`,e[e.plural=6]=`plural`,e[e.pound=7]=`pound`,e[e.tag=8]=`tag`,e}({});function me(e){return e.type===0}function he(e){return e.type===1}function ge(e){return e.type===2}function _e(e){return e.type===3}function ve(e){return e.type===4}function ye(e){return e.type===5}function be(e){return e.type===6}function xe(e){return e.type===7}function Se(e){return e.type===8}function Ce(e){return!!(e&&typeof e==`object`&&e.type===0)}function we(e){return!!(e&&typeof e==`object`&&e.type===1)}var Te=/[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/,Ee=/([^\t-\r -\/:-@\[-\^`\{-~\x85\xA0-\xA7\xA9\xAB\xAC\xAE\xB0\xB1\xB6\xBB\xBF\xD7\xF7\u1680\u2000-\u200A\u2010-\u2029\u202F-\u203E\u2041-\u2053\u2055-\u205F\u2190-\u245F\u2500-\u2775\u2794-\u2BFF\u2E00-\u2E7F\u3000-\u3003\u3008-\u3020\u3030\uFD3E\uFD3F\uFE45\uFE46]*)/g,m={"001":[`H`,`h`],419:[`h`,`H`,`hB`,`hb`],AC:[`H`,`h`,`hb`,`hB`],AD:[`H`,`hB`],AE:[`h`,`hB`,`hb`,`H`],AF:[`H`,`hb`,`hB`,`h`],AG:[`h`,`hb`,`H`,`hB`],AI:[`H`,`h`,`hb`,`hB`],AL:[`h`,`H`,`hB`],AM:[`H`,`hB`],AO:[`H`,`hB`],AR:[`h`,`H`,`hB`,`hb`],AS:[`h`,`H`],AT:[`H`,`hB`],AU:[`h`,`hb`,`H`,`hB`],AW:[`H`,`hB`],AX:[`H`],AZ:[`H`,`hB`,`h`],BA:[`H`,`hB`,`h`],BB:[`h`,`hb`,`H`,`hB`],BD:[`h`,`hB`,`H`],BE:[`H`,`hB`],BF:[`H`,`hB`],BG:[`H`,`hB`,`h`],BH:[`h`,`hB`,`hb`,`H`],BI:[`H`,`h`],BJ:[`H`,`hB`],BL:[`H`,`hB`],BM:[`h`,`hb`,`H`,`hB`],BN:[`hb`,`hB`,`h`,`H`],BO:[`h`,`H`,`hB`,`hb`],BQ:[`H`],BR:[`H`,`hB`],BS:[`h`,`hb`,`H`,`hB`],BT:[`h`,`H`],BW:[`H`,`h`,`hb`,`hB`],BY:[`H`,`h`],BZ:[`H`,`h`,`hb`,`hB`],CA:[`h`,`hb`,`H`,`hB`],CC:[`H`,`h`,`hb`,`hB`],CD:[`hB`,`H`],CF:[`H`,`h`,`hB`],CG:[`H`,`hB`],CH:[`H`,`hB`,`h`],CI:[`H`,`hB`],CK:[`H`,`h`,`hb`,`hB`],CL:[`h`,`H`,`hB`,`hb`],CM:[`H`,`h`,`hB`],CN:[`H`,`hB`,`hb`,`h`],CO:[`h`,`H`,`hB`,`hb`],CP:[`H`],CR:[`h`,`H`,`hB`,`hb`],CU:[`h`,`H`,`hB`,`hb`],CV:[`H`,`hB`],CW:[`H`,`hB`],CX:[`H`,`h`,`hb`,`hB`],CY:[`h`,`H`,`hb`,`hB`],CZ:[`H`],DE:[`H`,`hB`],DG:[`H`,`h`,`hb`,`hB`],DJ:[`h`,`H`],DK:[`H`],DM:[`h`,`hb`,`H`,`hB`],DO:[`h`,`H`,`hB`,`hb`],DZ:[`h`,`hB`,`hb`,`H`],EA:[`H`,`h`,`hB`,`hb`],EC:[`h`,`H`,`hB`,`hb`],EE:[`H`,`hB`],EG:[`h`,`hB`,`hb`,`H`],EH:[`h`,`hB`,`hb`,`H`],ER:[`h`,`H`],ES:[`H`,`hB`,`h`,`hb`],ET:[`hB`,`hb`,`h`,`H`],FI:[`H`],FJ:[`h`,`hb`,`H`,`hB`],FK:[`H`,`h`,`hb`,`hB`],FM:[`h`,`hb`,`H`,`hB`],FO:[`H`,`h`],FR:[`H`,`hB`],GA:[`H`,`hB`],GB:[`H`,`h`,`hb`,`hB`],GD:[`h`,`hb`,`H`,`hB`],GE:[`H`,`hB`,`h`],GF:[`H`,`hB`],GG:[`H`,`h`,`hb`,`hB`],GH:[`h`,`H`],GI:[`H`,`h`,`hb`,`hB`],GL:[`H`,`h`],GM:[`h`,`hb`,`H`,`hB`],GN:[`H`,`hB`],GP:[`H`,`hB`],GQ:[`H`,`hB`,`h`,`hb`],GR:[`h`,`H`,`hb`,`hB`],GS:[`H`,`h`,`hb`,`hB`],GT:[`h`,`H`,`hB`,`hb`],GU:[`h`,`hb`,`H`,`hB`],GW:[`H`,`hB`],GY:[`h`,`hb`,`H`,`hB`],HK:[`h`,`hB`,`hb`,`H`],HN:[`h`,`H`,`hB`,`hb`],HR:[`H`,`hB`],HU:[`H`,`h`],IC:[`H`,`h`,`hB`,`hb`],ID:[`H`],IE:[`H`,`h`,`hb`,`hB`],IL:[`H`,`hB`],IM:[`H`,`h`,`hb`,`hB`],IN:[`h`,`H`],IO:[`H`,`h`,`hb`,`hB`],IQ:[`h`,`hB`,`hb`,`H`],IR:[`hB`,`H`],IS:[`H`],IT:[`H`,`hB`],JE:[`H`,`h`,`hb`,`hB`],JM:[`h`,`hb`,`H`,`hB`],JO:[`h`,`hB`,`hb`,`H`],JP:[`H`,`K`,`h`],KE:[`hB`,`hb`,`H`,`h`],KG:[`H`,`h`,`hB`,`hb`],KH:[`hB`,`h`,`H`,`hb`],KI:[`h`,`hb`,`H`,`hB`],KM:[`H`,`h`,`hB`,`hb`],KN:[`h`,`hb`,`H`,`hB`],KP:[`h`,`H`,`hB`,`hb`],KR:[`h`,`H`,`hB`,`hb`],KW:[`h`,`hB`,`hb`,`H`],KY:[`h`,`hb`,`H`,`hB`],KZ:[`H`,`hB`],LA:[`H`,`hb`,`hB`,`h`],LB:[`h`,`hB`,`hb`,`H`],LC:[`h`,`hb`,`H`,`hB`],LI:[`H`,`hB`,`h`],LK:[`H`,`h`,`hB`,`hb`],LR:[`h`,`hb`,`H`,`hB`],LS:[`h`,`H`],LT:[`H`,`h`,`hb`,`hB`],LU:[`H`,`h`,`hB`],LV:[`H`,`hB`,`hb`,`h`],LY:[`h`,`hB`,`hb`,`H`],MA:[`H`,`h`,`hB`,`hb`],MC:[`H`,`hB`],MD:[`H`,`hB`],ME:[`H`,`hB`,`h`],MF:[`H`,`hB`],MG:[`H`,`h`],MH:[`h`,`hb`,`H`,`hB`],MK:[`H`,`h`,`hb`,`hB`],ML:[`H`],MM:[`hB`,`hb`,`H`,`h`],MN:[`H`,`h`,`hb`,`hB`],MO:[`h`,`hB`,`hb`,`H`],MP:[`h`,`hb`,`H`,`hB`],MQ:[`H`,`hB`],MR:[`h`,`hB`,`hb`,`H`],MS:[`H`,`h`,`hb`,`hB`],MT:[`H`,`h`],MU:[`H`,`h`],MV:[`H`,`h`],MW:[`h`,`hb`,`H`,`hB`],MX:[`h`,`H`,`hB`,`hb`],MY:[`hb`,`hB`,`h`,`H`],MZ:[`H`,`hB`],NA:[`h`,`H`,`hB`,`hb`],NC:[`H`,`hB`],NE:[`H`],NF:[`H`,`h`,`hb`,`hB`],NG:[`H`,`h`,`hb`,`hB`],NI:[`h`,`H`,`hB`,`hb`],NL:[`H`,`hB`],NO:[`H`,`h`],NP:[`H`,`h`,`hB`],NR:[`H`,`h`,`hb`,`hB`],NU:[`H`,`h`,`hb`,`hB`],NZ:[`h`,`hb`,`H`,`hB`],OM:[`h`,`hB`,`hb`,`H`],PA:[`h`,`H`,`hB`,`hb`],PE:[`h`,`H`,`hB`,`hb`],PF:[`H`,`h`,`hB`],PG:[`h`,`H`],PH:[`h`,`hB`,`hb`,`H`],PK:[`h`,`hB`,`H`],PL:[`H`,`h`],PM:[`H`,`hB`],PN:[`H`,`h`,`hb`,`hB`],PR:[`h`,`H`,`hB`,`hb`],PS:[`h`,`hB`,`hb`,`H`],PT:[`H`,`hB`],PW:[`h`,`H`],PY:[`h`,`H`,`hB`,`hb`],QA:[`h`,`hB`,`hb`,`H`],RE:[`H`,`hB`],RO:[`H`,`hB`],RS:[`H`,`hB`,`h`],RU:[`H`],RW:[`H`,`h`],SA:[`h`,`hB`,`hb`,`H`],SB:[`h`,`hb`,`H`,`hB`],SC:[`H`,`h`,`hB`],SD:[`h`,`hB`,`hb`,`H`],SE:[`H`],SG:[`h`,`hb`,`H`,`hB`],SH:[`H`,`h`,`hb`,`hB`],SI:[`H`,`hB`],SJ:[`H`],SK:[`H`],SL:[`h`,`hb`,`H`,`hB`],SM:[`H`,`h`,`hB`],SN:[`H`,`h`,`hB`],SO:[`h`,`H`],SR:[`H`,`hB`],SS:[`h`,`hb`,`H`,`hB`],ST:[`H`,`hB`],SV:[`h`,`H`,`hB`,`hb`],SX:[`H`,`h`,`hb`,`hB`],SY:[`h`,`hB`,`hb`,`H`],SZ:[`h`,`hb`,`H`,`hB`],TA:[`H`,`h`,`hb`,`hB`],TC:[`h`,`hb`,`H`,`hB`],TD:[`h`,`H`,`hB`],TF:[`H`,`h`,`hB`],TG:[`H`,`hB`],TH:[`H`,`h`],TJ:[`H`,`h`],TL:[`H`,`hB`,`hb`,`h`],TM:[`H`,`h`],TN:[`h`,`hB`,`hb`,`H`],TO:[`h`,`H`],TR:[`H`,`hB`],TT:[`h`,`hb`,`H`,`hB`],TW:[`hB`,`hb`,`h`,`H`],TZ:[`hB`,`hb`,`H`,`h`],UA:[`H`,`hB`,`h`],UG:[`hB`,`hb`,`H`,`h`],UM:[`h`,`hb`,`H`,`hB`],US:[`h`,`hb`,`H`,`hB`],UY:[`h`,`H`,`hB`,`hb`],UZ:[`H`,`hB`,`h`],VA:[`H`,`h`,`hB`],VC:[`h`,`hb`,`H`,`hB`],VE:[`h`,`H`,`hB`,`hb`],VG:[`h`,`hb`,`H`,`hB`],VI:[`h`,`hb`,`H`,`hB`],VN:[`H`,`h`],VU:[`h`,`H`],WF:[`H`,`hB`],WS:[`h`,`H`],XK:[`H`,`hB`,`h`],YE:[`h`,`hB`,`hb`,`H`],YT:[`H`,`hB`],ZA:[`H`,`h`,`hb`,`hB`],ZM:[`h`,`hb`,`H`,`hB`],ZW:[`H`,`h`],"af-ZA":[`H`,`h`,`hB`,`hb`],"ar-001":[`h`,`hB`,`hb`,`H`],"ca-ES":[`H`,`h`,`hB`],"en-001":[`h`,`hb`,`H`,`hB`],"en-HK":[`h`,`hb`,`H`,`hB`],"en-IL":[`H`,`h`,`hb`,`hB`],"en-MY":[`h`,`hb`,`H`,`hB`],"es-BR":[`H`,`h`,`hB`,`hb`],"es-ES":[`H`,`h`,`hB`,`hb`],"es-GQ":[`H`,`h`,`hB`,`hb`],"fr-CA":[`H`,`h`,`hB`],"gl-ES":[`H`,`h`,`hB`],"gu-IN":[`hB`,`hb`,`h`,`H`],"hi-IN":[`hB`,`h`,`H`],"it-CH":[`H`,`h`,`hB`],"it-IT":[`H`,`h`,`hB`],"kn-IN":[`hB`,`h`,`H`],"ku-SY":[`H`,`hB`],"ml-IN":[`hB`,`h`,`H`],"mr-IN":[`hB`,`hb`,`h`,`H`],"pa-IN":[`hB`,`hb`,`h`,`H`],"ta-IN":[`hB`,`h`,`hb`,`H`],"te-IN":[`hB`,`h`,`H`],"zu-ZA":[`H`,`hB`,`hb`,`h`]};function De(e,t){let n=``;for(let r=0;r<e.length;r++){let i=e.charAt(r);if(i===`j`){let a=0;for(;r+1<e.length&&e.charAt(r+1)===i;)a++,r++;let o=1+(a&1),s=a<2?1:3+(a>>1),c=Oe(t);for((c==`H`||c==`k`)&&(s=0);s-->0;)n+=`a`;for(;o-->0;)n=c+n}else n+=i===`J`?`H`:i}return n}function Oe(e){let t=e.hourCycle;if(t===void 0){let n=e;t=n.getHourCycles?.()[0]??n.hourCycles?.[0]}if(t)switch(t){case`h24`:return`k`;case`h23`:return`H`;case`h12`:return`h`;case`h11`:return`K`;default:throw Error(`Invalid hourCycle`)}let n=e.language,r;return n!==`root`&&(r=e.maximize().region),(m[`${n}-${r}`]||m[r||``]||m[n||``]||m[`${n}-001`]||m[`001`])[0].charAt(0)}var ke=RegExp(`^${Te.source}*`),Ae=RegExp(`${Te.source}*$`);function h(e,t){return{start:e,end:t}}var je=!!Object.fromEntries,Me=!!String.prototype.trimStart,Ne=!!String.prototype.trimEnd,Pe=je?Object.fromEntries:function(e){let t={};for(let[n,r]of e)t[n]=r;return t},Fe=Me?function(e){return e.trimStart()}:function(e){return e.replace(ke,``)},Ie=Ne?function(e){return e.trimEnd()}:function(e){return e.replace(Ae,``)},Le=Re();function Re(){try{let e=RegExp(`([^\\p{White_Space}\\p{Pattern_Syntax}]*)`,`yu`);if(e.exec(`a `)?.[1]===`a`)return e}catch{}return Ee}function ze(e,t){return Le.lastIndex=t,Le.exec(e)[1]??``}function Be(e){if(e.length===0)return null;let t=1,n=1;for(let r=0;r<e.length;){let i=e.charCodeAt(r);switch(i){case 35:case 39:case 60:case 123:case 125:return null}if(i===10)t++,n=1,r++;else if(n++,i>=55296&&i<=56319&&r+1<e.length){let t=e.charCodeAt(r+1);r+=t>=56320&&t<=57343?2:1}else r++}return{offset:e.length,line:t,column:n}}var Ve=class{constructor(e,t={}){this.message=e,this.position={offset:0,line:1,column:1},this.ignoreTag=!!t.ignoreTag,this.locale=t.locale,this.requiresOtherClause=!!t.requiresOtherClause,this.shouldParseSkeletons=!!t.shouldParseSkeletons}parse(){if(this.offset()!==0)throw Error(`parser can only be used once`);if(this.message.length>0){let e=this.message.charCodeAt(0);if(e!==35&&e!==39&&e!==60&&e!==123&&e!==125){let e=Be(this.message);if(e){let t=this.clonePosition();return this.position=e,{val:[{type:0,value:this.message,location:h(t,this.clonePosition())}],err:null}}}}return this.parseMessage(0,``,!1)}parseMessage(e,t,n){let r=[];for(;!this.isEOF();){let i=this.char();if(i===123){let t=this.parseArgument(e,n);if(t.err)return t;r.push(t.val)}else if(i===125&&e>0)break;else if(i===35&&(t===`plural`||t===`selectordinal`)){let e=this.clonePosition();this.bump(),r.push({type:7,location:h(e,this.clonePosition())})}else if(i===60&&!this.ignoreTag&&this.peek()===47){if(n)break;return this.error(26,h(this.clonePosition(),this.clonePosition()))}else if(i===60&&!this.ignoreTag&&He(this.peek()||0)){let n=this.parseTag(e,t);if(n.err)return n;r.push(n.val)}else{let n=this.parseLiteral(e,t);if(n.err)return n;r.push(n.val)}}return{val:r,err:null}}parseTag(e,t){let n=this.clonePosition();this.bump();let r=this.parseTagName();if(this.bumpSpace(),this.bumpIf(`/>`))return{val:{type:0,value:`<${r}/>`,location:h(n,this.clonePosition())},err:null};if(this.bumpIf(`>`)){let i=this.parseMessage(e+1,t,!0);if(i.err)return i;let a=i.val,o=this.clonePosition();if(this.bumpIf(`</`)){if(this.isEOF()||!He(this.char()))return this.error(23,h(o,this.clonePosition()));let e=this.clonePosition();return r===this.parseTagName()?(this.bumpSpace(),this.bumpIf(`>`)?{val:{type:8,value:r,children:a,location:h(n,this.clonePosition())},err:null}:this.error(23,h(o,this.clonePosition()))):this.error(26,h(e,this.clonePosition()))}return this.error(27,h(n,this.clonePosition()))}return this.error(23,h(n,this.clonePosition()))}parseTagName(){let e=this.offset();for(this.bump();!this.isEOF()&&We(this.char());)this.bump();return this.message.slice(e,this.offset())}parseLiteral(e,t){let n=this.clonePosition(),r=``;for(;;){let n=this.tryParseQuote(t);if(n){r+=n;continue}let i=this.tryParseUnquoted(e,t);if(i){r+=i;continue}let a=this.tryParseLeftAngleBracket();if(a)r+=a;else break}let i=h(n,this.clonePosition());return{val:{type:0,value:r,location:i},err:null}}tryParseLeftAngleBracket(){return!this.isEOF()&&this.char()===60&&(this.ignoreTag||!Ue(this.peek()||0))?(this.bump(),`<`):null}tryParseQuote(e){if(this.isEOF()||this.char()!==39)return null;switch(this.peek()){case 39:return this.bump(),this.bump(),`'`;case 123:case 60:case 62:case 125:break;case 35:if(e===`plural`||e===`selectordinal`)break;return null;default:return null}this.bump();let t=[this.char()];for(this.bump();!this.isEOF();){let e=this.char();if(e===39){if(this.peek()===39)t.push(39),this.bump();else{this.bump();break}}else t.push(e);this.bump()}return String.fromCodePoint(...t)}tryParseUnquoted(e,t){if(this.isEOF())return null;let n=this.char();return n===60||n===123||n===35&&(t===`plural`||t===`selectordinal`)||n===125&&e>0?null:(this.bump(),String.fromCodePoint(n))}parseArgument(e,t){let n=this.clonePosition();if(this.bump(),this.bumpSpace(),this.isEOF())return this.error(1,h(n,this.clonePosition()));if(this.char()===125)return this.bump(),this.error(2,h(n,this.clonePosition()));let r=this.parseIdentifierIfPossible().value;if(!r)return this.error(3,h(n,this.clonePosition()));if(this.bumpSpace(),this.isEOF())return this.error(1,h(n,this.clonePosition()));switch(this.char()){case 125:return this.bump(),{val:{type:1,value:r,location:h(n,this.clonePosition())},err:null};case 44:return this.bump(),this.bumpSpace(),this.isEOF()?this.error(1,h(n,this.clonePosition())):this.parseArgumentOptions(e,t,r,n);default:return this.error(3,h(n,this.clonePosition()))}}parseIdentifierIfPossible(){let e=this.clonePosition(),t=this.offset(),n=ze(this.message,t),r=t+n.length;return this.bumpTo(r),{value:n,location:h(e,this.clonePosition())}}parseArgumentOptions(e,t,n,r){let i=this.clonePosition(),a=this.parseIdentifierIfPossible().value,o=this.clonePosition();switch(a){case``:return this.error(4,h(i,o));case`number`:case`date`:case`time`:{this.bumpSpace();let e=null;if(this.bumpIf(`,`)){this.bumpSpace();let t=this.clonePosition(),n=this.parseSimpleArgStyleIfPossible();if(n.err)return n;let r=Ie(n.val);if(r.length===0)return this.error(6,h(this.clonePosition(),this.clonePosition()));e={style:r,styleLocation:h(t,this.clonePosition())}}let t=this.tryParseArgumentClose(r);if(t.err)return t;let i=h(r,this.clonePosition());if(e&&e.style.startsWith(`::`)){let t=Fe(e.style.slice(2));if(a===`number`){let r=this.parseNumberSkeletonFromString(t,e.styleLocation);return r.err?r:{val:{type:2,value:n,location:i,style:r.val},err:null}}{if(t.length===0)return this.error(10,i);let r=t;this.locale&&(r=De(t,this.locale));let o={type:1,pattern:r,location:e.styleLocation,parsedOptions:this.shouldParseSkeletons?ee(r):{}};return{val:{type:a===`date`?3:4,value:n,location:i,style:o},err:null}}}return{val:{type:a===`number`?2:a===`date`?3:4,value:n,location:i,style:e?.style??null},err:null}}case`plural`:case`selectordinal`:case`select`:{let i=this.clonePosition();if(this.bumpSpace(),!this.bumpIf(`,`))return this.error(12,h(i,{...i}));this.bumpSpace();let o=this.parseIdentifierIfPossible(),s=0;if(a!==`select`&&o.value===`offset`){if(!this.bumpIf(`:`))return this.error(13,h(this.clonePosition(),this.clonePosition()));this.bumpSpace();let e=this.tryParseDecimalInteger(13,14);if(e.err)return e;this.bumpSpace(),o=this.parseIdentifierIfPossible(),s=e.val}let c=this.tryParsePluralOrSelectOptions(e,a,t,o);if(c.err)return c;let l=this.tryParseArgumentClose(r);if(l.err)return l;let u=h(r,this.clonePosition());return a===`select`?{val:{type:5,value:n,options:Pe(c.val),location:u},err:null}:{val:{type:6,value:n,options:Pe(c.val),offset:s,pluralType:a===`plural`?`cardinal`:`ordinal`,location:u},err:null}}default:return this.error(5,h(i,o))}}tryParseArgumentClose(e){return this.isEOF()||this.char()!==125?this.error(1,h(e,this.clonePosition())):(this.bump(),{val:!0,err:null})}parseSimpleArgStyleIfPossible(){let e=0,t=this.clonePosition();for(;!this.isEOF();)switch(this.char()){case 39:{this.bump();let e=this.clonePosition();if(!this.bumpUntil(`'`))return this.error(11,h(e,this.clonePosition()));this.bump();break}case 123:e+=1,this.bump();break;case 125:if(e>0)--e;else return{val:this.message.slice(t.offset,this.offset()),err:null};break;default:this.bump()}return{val:this.message.slice(t.offset,this.offset()),err:null}}parseNumberSkeletonFromString(e,t){let n=[];try{n=ne(e)}catch{return this.error(7,t)}return{val:{type:0,tokens:n,location:t,parsedOptions:this.shouldParseSkeletons?fe(n):{}},err:null}}tryParsePluralOrSelectOptions(e,t,n,r){let i=!1,a=[],o=new Set,{value:s,location:c}=r;for(;;){if(s.length===0){let e=this.clonePosition();if(t!==`select`&&this.bumpIf(`=`)){let t=this.tryParseDecimalInteger(16,19);if(t.err)return t;c=h(e,this.clonePosition()),s=this.message.slice(e.offset,this.offset())}else break}if(o.has(s))return this.error(t===`select`?21:20,c);s===`other`&&(i=!0),this.bumpSpace();let r=this.clonePosition();if(!this.bumpIf(`{`))return this.error(t===`select`?17:18,h(this.clonePosition(),this.clonePosition()));let l=this.parseMessage(e+1,t,n);if(l.err)return l;let u=this.tryParseArgumentClose(r);if(u.err)return u;a.push([s,{value:l.val,location:h(r,this.clonePosition())}]),o.add(s),this.bumpSpace(),{value:s,location:c}=this.parseIdentifierIfPossible()}return a.length===0?this.error(t===`select`?15:16,h(this.clonePosition(),this.clonePosition())):this.requiresOtherClause&&!i?this.error(22,h(this.clonePosition(),this.clonePosition())):{val:a,err:null}}tryParseDecimalInteger(e,t){let n=1,r=this.clonePosition();this.bumpIf(`+`)||this.bumpIf(`-`)&&(n=-1);let i=!1,a=0;for(;!this.isEOF();){let e=this.char();if(e>=48&&e<=57)i=!0,a=a*10+(e-48),this.bump();else break}let o=h(r,this.clonePosition());return i?(a*=n,Number.isSafeInteger(a)?{val:a,err:null}:this.error(t,o)):this.error(e,o)}offset(){return this.position.offset}isEOF(){return this.offset()===this.message.length}clonePosition(){return{offset:this.position.offset,line:this.position.line,column:this.position.column}}char(){let e=this.position.offset;if(e>=this.message.length)throw Error(`out of bound`);let t=this.message.codePointAt(e);if(t===void 0)throw Error(`Offset ${e} is at invalid UTF-16 code unit boundary`);return t}error(e,t){return{val:null,err:{kind:e,message:this.message,location:t}}}bump(){if(this.isEOF())return;let e=this.char();e===10?(this.position.line+=1,this.position.column=1,this.position.offset+=1):(this.position.column+=1,this.position.offset+=e<65536?1:2)}bumpIf(e){let t=this.offset();if(this.message.slice(t,t+e.length)===e){for(let t=0;t<e.length;t++)this.bump();return!0}return!1}bumpUntil(e){let t=this.offset(),n=this.message.indexOf(e,t);return n>=0?(this.bumpTo(n),!0):(this.bumpTo(this.message.length),!1)}bumpTo(e){if(this.offset()>e)throw Error(`targetOffset ${e} must be greater than or equal to the current offset ${this.offset()}`);for(e=Math.min(e,this.message.length);;){let t=this.offset();if(t===e)break;if(t>e)throw Error(`targetOffset ${e} is at invalid UTF-16 code unit boundary`);if(this.bump(),this.isEOF())break}}bumpSpace(){for(;!this.isEOF()&&Ge(this.char());)this.bump()}peek(){if(this.isEOF())return null;let e=this.char(),t=this.offset();return this.message.charCodeAt(t+(e>=65536?2:1))??null}};function He(e){return e>=97&&e<=122||e>=65&&e<=90}function Ue(e){return He(e)||e===47}function We(e){return e===45||e===46||e>=48&&e<=57||e===95||e>=97&&e<=122||e>=65&&e<=90||e==183||e>=192&&e<=214||e>=216&&e<=246||e>=248&&e<=893||e>=895&&e<=8191||e>=8204&&e<=8205||e>=8255&&e<=8256||e>=8304&&e<=8591||e>=11264&&e<=12271||e>=12289&&e<=55295||e>=63744&&e<=64975||e>=65008&&e<=65533||e>=65536&&e<=983039}function Ge(e){return e>=9&&e<=13||e===32||e===133||e>=8206&&e<=8207||e===8232||e===8233}function Ke(e){e.forEach(e=>{if(delete e.location,ye(e)||be(e))for(let t in e.options)delete e.options[t].location,Ke(e.options[t].value);else ge(e)&&Ce(e.style)||(_e(e)||ve(e))&&we(e.style)?delete e.style.location:Se(e)&&Ke(e.children)})}function qe(e,t={}){t={shouldParseSkeletons:!0,requiresOtherClause:!0,...t};let n=new Ve(e,t).parse();if(n.err){let e=SyntaxError(pe[n.err.kind]);throw e.location=n.err.location,e.originalMessage=n.err.message,e}return t?.captureLocation||Ke(n.val),n.val}function Je(e,t){let n=t&&t.cache?t.cache:it,r=t&&t.serializer?t.serializer:nt;return(t&&t.strategy?t.strategy:$e)(e,{cache:n,serializer:r})}function Ye(e){return e==null||typeof e==`number`||typeof e==`boolean`}function Xe(e,t,n,r){let i=Ye(r)?r:n(r),a=t.get(i);return a===void 0&&(a=e.call(this,r),t.set(i,a)),a}function Ze(e,t,n){let r=Array.prototype.slice.call(arguments,3),i=n(r),a=t.get(i);return a===void 0&&(a=e.apply(this,r),t.set(i,a)),a}function Qe(e,t,n,r,i){return n.bind(t,e,r,i)}function $e(e,t){let n=e.length===1?Xe:Ze;return Qe(e,this,n,t.cache.create(),t.serializer)}function et(e,t){return Qe(e,this,Ze,t.cache.create(),t.serializer)}function tt(e,t){return Qe(e,this,Xe,t.cache.create(),t.serializer)}var nt=function(){return JSON.stringify(arguments)},rt=class{constructor(){this.cache=Object.create(null)}get(e){return this.cache[e]}set(e,t){this.cache[e]=t}},it={create:function(){return new rt}},at={variadic:et,monadic:tt},ot=class extends Error{constructor(e,t,n){super(e),this.code=t,this.originalMessage=n}toString(){return`[formatjs Error: ${this.code}] ${this.message}`}},st=class extends ot{constructor(e,t,n,r){super(`Invalid values for "${e}": "${t}". Options are "${Object.keys(n).join(`", "`)}"`,`INVALID_VALUE`,r)}},ct=class extends ot{constructor(e,t,n){super(`Value for "${e}" must be of type ${t}`,`INVALID_VALUE`,n)}},lt=class extends ot{constructor(e,t){super(`The intl string context variable "${e}" was not provided to the string "${t}"`,`MISSING_VALUE`,t)}};function ut(e){return e.length<2?e:e.reduce((e,t)=>{let n=e[e.length-1];return!n||n.type!==0||t.type!==0?e.push(t):n.value+=t.value,e},[])}function dt(e){return typeof e==`function`}function ft(e,t,n,r,i,a,o){if(e.length===1&&me(e[0]))return[{type:0,value:e[0].value}];let s=[];for(let c of e){if(me(c)){s.push({type:0,value:c.value});continue}if(xe(c)){typeof a==`number`&&s.push({type:0,value:n.getNumberFormat(t).format(a)});continue}let{value:e}=c;if(!(i&&e in i))throw new lt(e,o);let l=i[e];if(he(c))l&&typeof l!=`string`&&typeof l!=`number`&&typeof l!=`bigint`||(l=typeof l==`string`||typeof l==`number`||typeof l==`bigint`?String(l):``),s.push({type:typeof l==`string`?0:1,value:l});else if(_e(c)){let e=typeof c.style==`string`?r.date[c.style]:we(c.style)?c.style.parsedOptions:void 0;s.push({type:0,value:n.getDateTimeFormat(t,e).format(l)})}else if(ve(c)){let e=typeof c.style==`string`?r.time[c.style]:we(c.style)?c.style.parsedOptions:r.time.medium;s.push({type:0,value:n.getDateTimeFormat(t,e).format(l)})}else if(ge(c)){let e=typeof c.style==`string`?r.number[c.style]:Ce(c.style)?c.style.parsedOptions:void 0;if(e&&e.scale){let t=e.scale||1;if(typeof l==`bigint`){if(!Number.isInteger(t))throw TypeError(`Cannot apply fractional scale ${t} to bigint value. Scale must be an integer when formatting bigint.`);l*=BigInt(t)}else l*=t}s.push({type:0,value:n.getNumberFormat(t,e).format(l)})}else{if(Se(c)){let{children:e,value:l}=c,u=i[l];if(!dt(u))throw new ct(l,`function`,o);let d=u(ft(e,t,n,r,i,a).map(e=>e.value));Array.isArray(d)||(d=[d]),s.push(...d.map(e=>({type:typeof e==`string`?0:1,value:e})))}if(ye(c)){let e=l,a=(Object.prototype.hasOwnProperty.call(c.options,e)?c.options[e]:void 0)||c.options.other;if(!a)throw new st(c.value,l,Object.keys(c.options),o);s.push(...ft(a.value,t,n,r,i))}else if(be(c)){let e=`=${l}`,a=Object.prototype.hasOwnProperty.call(c.options,e)?c.options[e]:void 0;if(!a){if(!Intl.PluralRules)throw new ot(`Intl.PluralRules is not available in this environment.
|
|
2
|
-
Try polyfilling it using "@formatjs/intl-pluralrules"
|
|
3
|
-
`,`MISSING_INTL_API`,o);let e=typeof l==`bigint`?Number(l):l,r=n.getPluralRules(t,{type:c.pluralType}).select(e-(c.offset||0));a=(Object.prototype.hasOwnProperty.call(c.options,r)?c.options[r]:void 0)||c.options.other}if(!a)throw new st(c.value,l,Object.keys(c.options),o);let u=typeof l==`bigint`?Number(l):l;s.push(...ft(a.value,t,n,r,i,u-(c.offset||0)))}}}return ut(s)}function pt(e,t){return t?{...e,...t,...Object.keys(e).reduce((n,r)=>(n[r]={...e[r],...t[r]},n),{})}:e}function mt(e,t){return t?Object.keys(e).reduce((n,r)=>(n[r]=pt(e[r],t[r]),n),{...e}):e}function ht(e){return{create(){return{get(t){return e[t]},set(t,n){e[t]=n}}}}}function gt(e={number:{},dateTime:{},pluralRules:{}}){return{getNumberFormat:Je((...e)=>new Intl.NumberFormat(...e),{cache:ht(e.number),strategy:at.variadic}),getDateTimeFormat:Je((...e)=>new Intl.DateTimeFormat(...e),{cache:ht(e.dateTime),strategy:at.variadic}),getPluralRules:Je((...e)=>new Intl.PluralRules(...e),{cache:ht(e.pluralRules),strategy:at.variadic})}}var _t=class e{constructor(t,n=e.defaultLocale,r,i){if(this.formatterCache={number:{},dateTime:{},pluralRules:{}},this.format=(e=>{let t=this.formatToParts(e);if(t.length===1)return t[0].value;let n=t.reduce((e,t)=>(!e.length||t.type!==0||typeof e[e.length-1]!=`string`?e.push(t.value):e[e.length-1]+=t.value,e),[]);return n.length<=1?n[0]||``:n}),this.formatToParts=(e=>ft(this.ast,this.locales,this.formatters,this.formats,e,void 0,this.message)),this.resolvedOptions=()=>({locale:this.resolvedLocale?.toString()||Intl.NumberFormat.supportedLocalesOf(this.locales)[0]}),this.getAst=()=>this.ast,this.locales=n,this.resolvedLocale=e.resolveLocale(n),typeof t==`string`){if(this.message=t,!e.__parse)throw TypeError("IntlMessageFormat.__parse must be set to process `message` of type `string`");let{...n}=i||{};this.ast=e.__parse(t,{...n,locale:this.resolvedLocale})}else this.ast=t;if(!Array.isArray(this.ast))throw TypeError(`A message must be provided as a String or AST.`);this.formats=mt(e.formats,r),this.formatters=i&&i.formatters||gt(this.formatterCache)}static{this.memoizedDefaultLocale=null}static get defaultLocale(){return e.memoizedDefaultLocale||=new Intl.NumberFormat().resolvedOptions().locale,e.memoizedDefaultLocale}static{this.resolveLocale=e=>{if(Intl.Locale===void 0)return;let t=Intl.NumberFormat.supportedLocalesOf(e);return t.length>0?new Intl.Locale(t[0]):new Intl.Locale(typeof e==`string`?e:e[0])}}static{this.__parse=qe}static{this.formats={number:{integer:{maximumFractionDigits:0},currency:{style:`currency`},percent:{style:`percent`}},date:{short:{month:`numeric`,day:`numeric`,year:`2-digit`},medium:{month:`short`,day:`numeric`,year:`numeric`},long:{month:`long`,day:`numeric`,year:`numeric`},full:{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`}},time:{short:{hour:`numeric`,minute:`numeric`},medium:{hour:`numeric`,minute:`numeric`,second:`numeric`},long:{hour:`numeric`,minute:`numeric`,second:`numeric`,timeZoneName:`short`},full:{hour:`numeric`,minute:`numeric`,second:`numeric`,timeZoneName:`short`}}}}};function vt(e,t=new Set){for(let n of e){if(n.type===p.literal||n.type===p.pound)continue;let e=n.type===p.plural||n.type===p.number?`number`:n.type===p.date||n.type===p.time?`date`:String(n.type);if(t.add(`${n.value}:${e}`),n.type===p.tag&&vt(n.children,t),n.type===p.select||n.type===p.plural)for(let e of Object.values(n.options))vt(e.value,t)}return[...t].sort()}function yt(e,t){let n=[];for(let[r,i]of Object.entries(t)){let t=e[r];if(!t)n.push(`${r}: unknown message`);else try{if(typeof i!=`string`)throw Error(`Expected an ICU string`);let e=vt(qe(t.message)),a=vt(qe(i));JSON.stringify(e)!==JSON.stringify(a)&&n.push(`${r}: arguments/tags differ (expected ${e.join(`, `)}; got ${a.join(`, `)})`)}catch(e){n.push(`${r}: ${String(e)}`)}}return n}function bt(e){let t=[];for(let[n,r]of Object.entries(e)){r.description.trim()||t.push(`${n}: missing translator description`);try{qe(r.message)}catch(e){t.push(`${n}: ${String(e)}`)}}return t}var xt={a:`á`,e:`ë`,i:`ï`,o:`ö`,u:`ü`,A:`Á`,E:`Ë`,I:`Ï`,O:`Ö`,U:`Ü`};function St(e,t){return e.map(e=>{if(e.type===p.literal){if(!e.value.trim())return e;let n=e.value.replace(/[aeiouAEIOU]/g,e=>xt[e]??e);return{...e,value:t?`\u202e${n}\u202c`:`[${n}${`~`.repeat(Math.ceil(n.length*.3))}]`}}return e.type===p.tag?{...e,children:St(e.children,t)}:e.type===p.plural||e.type===p.select?{...e,options:Object.fromEntries(Object.entries(e.options).map(([e,n])=>[e,{...n,value:St(n.value,t)}]))}:e})}var Ct=5e3;function wt(e,t){let n,r=()=>void 0,i=new Promise(e=>{r=e}),a=!0,o=(i,o)=>{a&&(a=!1,clearTimeout(s),n=i,o!==void 0&&t({code:`load`,message:`Could not load ${e.id} (${e.locale}/${e.namespace})`,cause:o}),r())},s=setTimeout(()=>{o({},Error(`Catalog loading exceeded 5 seconds; using fallback messages`))},Ct);return Promise.resolve().then(()=>a?e.load():void 0).then(n=>{if(!a)return;if(typeof n!=`object`||!n||Array.isArray(n))throw TypeError(`Expected a translation catalog object`);let r=[];for(let[i,a]of Object.entries(n))typeof a==`string`?r.push([i,a]):t({code:`invalid`,message:`${e.id}: ${i}: expected an ICU string`});o(Object.fromEntries(r))}).catch(e=>{o({},e)}),{ready:i,get catalog(){return n},dispose(){a&&(a=!1,clearTimeout(s),r())}}}function Tt(e,t){return{message:e,description:t}}var Et=[`language`,`formatLocale`,`timeZone`,`hourCycle`];function Dt(e){let t=Intl.getCanonicalLocales(e)[0];if(t===void 0)throw RangeError(`A locale is required`);return t}function Ot(e){let t=new Intl.Locale(e).baseName.split(`-`),n=[];for(;t.length;)n.unshift(t.join(`-`)),t.pop();return n}function g(e){if(typeof e!=`object`||!e||!(`language`in e)||typeof e.language!=`string`||!(`formatLocale`in e)||typeof e.formatLocale!=`string`)throw TypeError(`Expected language and formatLocale`);let t=Dt(e.language),n=Dt(e.formatLocale),r=`hourCycle`in e?e.hourCycle:void 0,i=`timeZone`in e?e.timeZone:void 0;if(r!==void 0&&r!==`h11`&&r!==`h12`&&r!==`h23`&&r!==`h24`)throw RangeError(`Invalid hour cycle`);if(i!==void 0&&typeof i!=`string`)throw TypeError(`Expected a time-zone name`);let a=i===void 0?void 0:new Intl.DateTimeFormat(n,{timeZone:i}).resolvedOptions().timeZone;return{language:t,formatLocale:n,...a===void 0?{}:{timeZone:a},...r===void 0?{}:{hourCycle:r}}}function kt(e){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`Expected localization overrides`);let t=g({language:`en`,formatLocale:`en`,...e});return{...`language`in e?{language:t.language}:{},...`formatLocale`in e?{formatLocale:t.formatLocale}:{},...t.timeZone===void 0?{}:{timeZone:t.timeZone},...t.hourCycle===void 0?{}:{hourCycle:t.hourCycle}}}function At(e){return`getTextInfo`in e&&typeof e.getTextInfo==`function`}function jt(e){if(e===`ar-XB`)return`rtl`;let t=new Intl.Locale(e),n=At(t)?t.getTextInfo():`textInfo`in t?t.textInfo:void 0;return typeof n==`object`&&n&&`direction`in n&&n.direction===`rtl`?`rtl`:`ltr`}var Mt=class{constructor(e={}){this.defaults={language:`en`,formatLocale:`en`},this.policy={},this.sources=new Map,this.contributions=new Map,this.listeners=new Set,this.formats=new Map,this.reported=new Set,this.preferencesRevision=0,this.pending=Promise.resolve(),this.resolvedLanguage=`en`,this.current=g(e.preferences??this.defaults),this.overrides=e.preferences===void 0?{}:{...this.current},this.development=e.development??!1,this.diagnostic=e.diagnostic??(e=>{console.warn(`[i18n:${e.code}] ${e.message}`,e.cause??``)}),this.assertLanguage(this.current.language)}get preferences(){return{...this.current}}get preferenceOverrides(){return{...this.overrides}}get preferenceDefaults(){return{...this.defaults}}get preferencePolicy(){return{enforcedFields:{...this.policy.enforcedFields},sources:{...this.policy.sources}}}preferenceSettingPolicy(e){let t=this.policy.enforcedFields?.[e];return{locked:t!==void 0,enforcedBy:t,source:this.policy.sources?.[e]}}resolvePreferences(e,t,n){let r={...e,...t};for(let t of Et)n.enforcedFields?.[t]!==void 0&&(Reflect.deleteProperty(r,t),Object.assign(r,{[t]:e[t]}));return g(r)}get preferenceRevision(){return this.preferencesRevision}get language(){return this.isPseudo?this.current.language:this.resolvedLanguage}get direction(){return jt(this.language)}get ready(){return this.pending}get availableLanguages(){return[...new Set([`en`,...[...this.contributions.values()].map(e=>e.locale)])].filter(e=>e!==`en-XA`&&e!==`ar-XB`).sort()}get isPseudo(){return this.current.language===`en-XA`||this.current.language===`ar-XB`}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(){this.formats.clear();for(let e of this.listeners)e()}report(e,t,n){let r=`${e}:${t}`;this.reported.has(r)||(this.reported.add(r),this.diagnostic({code:e,message:t,...n===void 0?{}:{cause:n}}))}assertLanguage(e){if(!this.development&&(e===`en-XA`||e===`ar-XB`))throw RangeError(`Pseudo-localization is available only in development`)}setPreferences(e){let t=g(e);return this.assertLanguage(t.language),this.setPreferenceOverrides(t)}setPreferenceDefaults(e,t=this.policy){let n=g(e),r=this.resolvePreferences(n,this.overrides,t);return this.assertLanguage(n.language),this.assertLanguage(r.language),this.defaults=n,this.policy={enforcedFields:{...t.enforcedFields},sources:{...t.sources}},this.current=r,this.refresh(),this.pending}setPreferenceOverrides(e){let t=kt(e);for(let e of Et)this.policy.enforcedFields?.[e]!==void 0&&(Reflect.deleteProperty(t,e),this.overrides[e]!==void 0&&Object.assign(t,{[e]:this.overrides[e]}));let n=this.resolvePreferences(this.defaults,t,this.policy);return this.assertLanguage(n.language),this.overrides=t,this.current=n,this.preferencesRevision++,this.refresh(),this.pending}registerMessages(e,t){if(!e||this.sources.has(e))throw Error(`Duplicate or empty message namespace: ${e}`);return this.messageHandle(e,this.addSource(e,t))}acquireMessages(e,t){let n=this.addSource(e,t);return{messages:this.messageHandle(e,n),release:()=>{if(!n.active)return;n.active=!1,n.selected.clear();let t=this.sources.get(e);t?.delete(n),t?.size===0&&this.sources.delete(e),this.refresh()}}}addSource(e,t){if(!e)throw Error(`Empty message namespace`);let n=bt(t);if(n.length)throw Error(`Invalid source ${e}: ${n.join(`; `)}`);let r={definitions:t,selected:new Map,active:!0},i=this.sources.get(e);return i||(i=new Set,this.sources.set(e,i)),i.add(r),this.refresh(),r}messageHandle(e,t){return{t:(n,...r)=>{let i=this.format(e,t,n,r[0]);if(typeof i!=`string`)throw Error(`Use rich() for ${e}.${n}`);return i},rich:(n,...r)=>this.format(e,t,n,r[0])}}registerCatalog(e){if(!e.id||this.contributions.has(e.id))throw Error(`Duplicate or empty catalog ID: ${e.id}`);let t={...e,locale:Dt(e.locale)};return this.contributions.set(t.id,t),this.refresh(),()=>{this.contributions.get(t.id)===t&&(this.contributions.delete(t.id),t.loaded?.dispose(),this.refresh())}}matchingCatalogs(){let e=this.isPseudo?[]:Ot(this.current.language).filter(e=>e!==`en`);return[...this.contributions.values()].filter(t=>e.includes(t.locale)).sort((t,n)=>e.indexOf(t.locale)-e.indexOf(n.locale)||(t.id<n.id?-1:+(t.id>n.id)))}refresh(){let e=[];for(let t of this.matchingCatalogs())t.loaded===void 0&&(t.loaded=wt(t,({code:e,message:t,cause:n})=>{this.report(e,t,n)}),t.loaded.ready.then(()=>{this.publish()})),e.push(t.loaded.ready);this.pending=Promise.all(e).then(()=>void 0),this.publish()}publish(){for(let e of this.sources.values())for(let t of e)t.selected.clear();let e=new Map,t=`en`;for(let n of this.matchingCatalogs()){let r=this.sources.get(n.namespace);if(r)for(let[i,a]of Object.entries(n.loaded?.catalog??{})){let o=!1,s=new Set;for(let e of r){let t=yt(e.definitions,{[i]:a});t.length?t.forEach(e=>s.add(e)):(e.selected.set(i,{message:a,locale:n.locale}),o=!0)}if(!o){this.report(`invalid`,`${n.id}: ${[...s].join(`; `)}`);continue}let c=JSON.stringify([n.locale,n.namespace,i]),l=e.get(c);l!==void 0&&this.report(`duplicate`,`${n.locale}/${n.namespace}.${i}: ${n.id} overrides ${l}`),e.set(c,n.id),t=n.locale}}this.resolvedLanguage=t,this.notify()}dateOptions(e){return{...e,...this.current.timeZone===void 0?{}:{timeZone:this.current.timeZone},...this.current.hourCycle===void 0?{}:{hourCycle:this.current.hourCycle,hour12:void 0}}}format(e,t,n,r){let i=t.definitions[n];if(!i)throw Error(`Unknown message: ${e}.${n}`);let a=t.selected.get(n);!a&&t.active&&!this.isPseudo&&!this.current.language.startsWith(`en`)&&this.development&&this.report(`missing`,`${this.current.language}/${e}.${n}: using English`);let o=this.isPseudo?{message:i.message,locale:`en`}:a??{message:i.message,locale:`en`},s=(t,i)=>{let a=JSON.stringify([e,n,t,i,this.isPseudo]),o=this.formats.get(a);if(!o){let e={getNumberFormat:(e,t)=>new Intl.NumberFormat(this.current.formatLocale,t),getDateTimeFormat:(e,t)=>new Intl.DateTimeFormat(this.current.formatLocale,this.dateOptions(t??{})),getPluralRules:(e,t)=>new Intl.PluralRules(e,t)},n=qe(t);this.isPseudo&&(n=St(n,this.current.language===`ar-XB`)),o=new _t(n,i,void 0,{formatters:e}),this.formats.set(a,o)}return o.format(r)};try{return s(o.message,o.locale)}catch(t){if(this.report(`format`,`${e}.${n}: formatting failed`,t),o.message!==i.message)return s(i.message,`en`);throw t}}number(e,t){return new Intl.NumberFormat(this.current.formatLocale,t).format(e)}date(e,t={dateStyle:`medium`}){return new Intl.DateTimeFormat(this.current.formatLocale,this.dateOptions(t)).format(e)}time(e,t={timeStyle:`short`}){return new Intl.DateTimeFormat(this.current.formatLocale,this.dateOptions(t)).format(e)}relativeTime(e,t,n={numeric:`auto`}){return new Intl.RelativeTimeFormat(this.current.formatLocale,n).format(e,t)}list(e,t){return new Intl.ListFormat(this.current.formatLocale,t).format(e)}},Nt=`pi-web-localization`,_=new Mt({development:!1}),Pt=new WeakMap,Ft=new WeakMap;function It(e){let t={},n={};for(let r of Et){let i=`/defaultLocalization/${r}`,a=e.enforcedSettings?.[i],o=e.configSources?.[i];a!==void 0&&(t[r]=a),o!==void 0&&(n[r]=o)}return{enforcedFields:t,sources:n}}function Lt(e,t=_){return Rt(e.effectiveConfig.defaultLocalization??{},It(e),t)}function Rt(e,t,n){let r=kt(e),i=Ft.get(n)??zt(),a=n.setPreferenceDefaults(g({...i,...r}),t);return Pt.set(n,r),a}function zt(e=typeof window>`u`?void 0:window.navigator){let t=e?.languages[0]??e?.language??`en`;return{language:t,formatLocale:t}}function Bt(e,t=_){let n=Pt.get(t),r=t.preferenceDefaults[e]??new Intl.DateTimeFormat().resolvedOptions().timeZone;return{source:n?.[e]===void 0?`browser`:`server`,value:r}}async function Vt(e=_,t=window,n=!1,r={},i={}){let a=zt(t.navigator),o=a,s={};try{let e=t.localStorage.getItem(Nt);e!==null&&(s=kt(JSON.parse(e)))}catch(e){console.warn(`[i18n] Could not restore localization preferences; using browser defaults`,e)}let c=n?new URLSearchParams(t.location.search).get(`pseudoLocale`):null,l=c===`en-XA`||c===`ar-XB`?c:void 0,u=s.language;(s.language===`en-XA`||s.language===`ar-XB`)&&(delete s.language,u=void 0),l!==void 0&&(s={...s,language:l}),Pt.set(e,{}),Ft.set(e,a),e.setPreferenceDefaults(a,{}),e.setPreferenceOverrides({}),e.setPreferenceOverrides(s),await Promise.resolve();let d=e.preferenceRevision,f=()=>{t.document.documentElement.lang=e.language,t.document.documentElement.dir=e.direction;let n=e.preferenceRevision;if(n===d)return;d=n;let r=e.preferenceOverrides,i=r.language===`en-XA`||r.language===`ar-XB`?u??o.language:r.language,a={...r,...i===void 0?{}:{language:i}};try{t.localStorage.setItem(Nt,JSON.stringify(a))}catch(e){console.warn(`[i18n] Could not save localization preferences`,e)}};f();let ee=e.subscribe(f);try{let[t,n]=await Promise.all([r,i]);Rt(t??{},n,e),o=e.preferenceDefaults}catch(e){throw ee(),e}return ee}var Ht=class{constructor(e,t=_,n){this.host=e,this.service=t,this.invalidate=n,e.addController(this)}hostConnected(){this.unsubscribe??=this.service.subscribe(()=>{this.invalidate?.(),this.host.requestUpdate()}),this.invalidate?.(),this.host.requestUpdate()}hostDisconnected(){this.unsubscribe?.(),this.unsubscribe=void 0}},Ut=t(`en`,{}),Wt=`en`,v=(e,t,n)=>Ut(e,t,n);function Gt(e,n){let r=s(n);Ut=t(e,r),Wt=e}function Kt(){return Wt}var qt=(e,t)=>t,Jt=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`,`max`];function Yt(e){return Jt.some(t=>t===e)}function Xt(e){return e===void 0||e===``?`off`:e}function Zt(e,t=qt){let n=Xt(e),r={off:t(`thinking.label.off`,`Off`),minimal:t(`thinking.label.minimal`,`Minimal`),low:t(`thinking.label.low`,`Low`),medium:t(`thinking.label.medium`,`Medium`),high:t(`thinking.label.high`,`High`),xhigh:t(`thinking.label.xhigh`,`Extra high`),max:t(`thinking.label.max`,`Maximum`)};return Yt(n)?r[n]??n:n}function Qt(e,t=qt){switch(e){case`off`:return t(`thinking.description.off`,`No reasoning`);case`minimal`:return t(`thinking.description.minimal`,`Minimal reasoning (about 1k tokens)`);case`low`:return t(`thinking.description.low`,`Light reasoning (about 2k tokens)`);case`medium`:return t(`thinking.description.medium`,`Moderate reasoning (about 8k tokens)`);case`high`:return t(`thinking.description.high`,`Deep reasoning (about 16k tokens)`);case`xhigh`:return t(`thinking.description.xhigh`,`Extra high reasoning (about 32k tokens)`);case`max`:return t(`thinking.description.max`,`Maximum reasoning (about 64k tokens)`);default:return}}function $t(e,t){let n=t.length>=2?t:Jt,r=n.length-1,i=Xt(e),a=n.indexOf(i);return{total:r,filled:a<=0?0:Math.min(a,r)}}function en(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function tn(e){if(!en(e))throw new i(`server.main.b5b69396302e`,`Invalid session defaults`);let t=e,n={};for(let e of[`defaultProvider`,`defaultModel`]){let r=t[e];if(r!==void 0){if(typeof r!=`string`)throw new i(`server.main.d20dbeed752b`,`Invalid {arg0}`,{arg0:e});n[e]=r}}let r=t.defaultThinkingLevel;if(r!==void 0){if(typeof r!=`string`||!Yt(r))throw new i(`server.main.e937d7ab07c7`,`Invalid defaultThinkingLevel`);n.defaultThinkingLevel=r}return n}function nn(e,t){if(e!==`steer`&&e!==`followUp`)throw new i(`configError.defaultStreamingBehavior.invalid`,`PI WEB config defaultStreamingBehavior must be steer or followUp: {source}`,{source:t});return e}var rn=new Set([`language`,`formatLocale`,`timeZone`,`hourCycle`]);function an(e,t=`request`){let n=e=>{throw Error(`PI WEB config defaultLocalization ${e}: ${t}`)};if(!on(e))return n(`must be an object`);let r=e;for(let e of Object.keys(r))rn.has(e)||n(`contains unknown key ${e}`);let i={};for(let e of[`language`,`formatLocale`]){let t=r[e];if(t===void 0)continue;if(typeof t!=`string`||t===``)return n(`${e} must be a valid locale`);let a;try{let r=Intl.getCanonicalLocales(t)[0];if(r===void 0)return n(`${e} must be a valid locale`);a=r}catch{return n(`${e} must be a valid locale`)}let{language:o,region:s}=new Intl.Locale(a);if(o===`en`&&s===`XA`||o===`ar`&&s===`XB`)return n(`${e} pseudo locales are development-only`);i[e]=a}let a=r.timeZone;if(a!==void 0){if(typeof a!=`string`||a===``)return n(`timeZone must be a valid date/time zone`);try{i.timeZone=new Intl.DateTimeFormat(`en`,{timeZone:a}).resolvedOptions().timeZone}catch{return n(`timeZone must be a valid date/time zone`)}}let o=r.hourCycle;if(o!==void 0){if(o!==`h11`&&o!==`h12`&&o!==`h23`&&o!==`h24`)return n(`hourCycle must be h11, h12, h23, or h24`);i.hourCycle=o}return i}function on(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function sn(e,t=`PI WEB config installationName`){if(typeof e!=`string`||e.length>120||cn(e))throw Error(`${t} must be a string of at most 120 characters without control characters`);return e.trim()}function cn(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}var ln=/^[a-z][a-z0-9.-]*$/u,un=new Set([`core`,`themes`]),dn=`machine.`,fn=`pi-web`,pn=`${fn}.`;function mn(e){return ln.test(e)}function hn(e){return e===fn||e.startsWith(pn)}function gn(e){return un.has(e)||e.startsWith(dn)||hn(e)}function _n(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function vn(e,t){if(!_n(e))throw new i(`configError.sessionArchive.object`,`PI WEB config sessionArchive must be an object: {source}`,{source:t});let n=Object.keys(e).find(e=>e!==`directory`);if(n!==void 0)throw new i(`configError.sessionArchive.unknownKey`,`PI WEB config sessionArchive has unknown key {key}: {source}`,{key:JSON.stringify(n),source:t});let r=e.directory;if(r===void 0)return{};if(typeof r!=`string`||r.trim()===``||r.includes(`\0`))throw new i(`configError.sessionArchive.directory`,`PI WEB config sessionArchive.directory must be a non-empty path: {source}`,{source:t});return{directory:r}}var y={sessionsDeleteArchived:`sessions.deleteArchived`,sessionsBulkMutations:`sessions.bulkMutations`,sessionsCleanup:`sessions.cleanup`,sessionsReload:`sessions.reload`,sessionsClearQueue:`sessions.clearQueue`,sessionsQueueMessageActions:`sessions.queueMessageActions`,sessionsPersistedState:`sessions.persistedState`,sessionsNotifications:`sessions.notifications`,sessionsUnread:`sessions.unread`,sessionsAskUser:`sessions.askUser`,promptAttachments:`prompt.attachments`,workspaceFileSuggestions:`workspace.fileSuggestions`,piPackagesManage:`piPackages.manage`,selectedMachineSettings:`settings.selectedMachine`,agentProfileConfig:`settings.agentProfile`,pluginLifecycle:`plugins.lifecycle`,sessionCleanupPinnedExclusions:`sessions.cleanup.pinnedExclusions`,sessionPinsDaemonOwned:`sessions.pins.daemonOwned`,sessionPinsManagementScoped:`sessions.pins.managementScoped`},yn=1e3,bn=32768,xn=8192,Sn=`pi-web.ask.answers`,Cn=1e3,wn=4e3,Tn=4e3,En=1e3,Dn=4e3,On=1e4,kn=new Set([`schemaVersion`,`dir`]);function An(e){if(!Nn(e)||Object.keys(e).some(e=>!kn.has(e)))return;let t=e.schemaVersion,n=e.dir;if(t===2&&typeof n==`string`&&jn(n))return Object.freeze({schemaVersion:2,dir:n})}function jn(e){if(e===``||e!==e.trim()||Mn(e))return!1;let t=e.replace(/\\/g,`/`);return t.startsWith(`/`)||/^[A-Za-z]:\//u.test(t)}function Mn(e){for(let t of e){let e=t.charCodeAt(0);if(e<32||e===127)return!0}return!1}function Nn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Pn(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=Reflect.get(e,`kind`);if(t===`workspaceRemovalCommandFailed`)return{kind:t};let n=Reflect.get(e,`detail`);if(t===`workspaceRemovalFailed`&&typeof n==`string`&&n.length<=4096)return{kind:t,detail:n}}function Fn(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=Reflect.get(e,`kind`),n=Reflect.get(e,`label`),r=Reflect.get(e,`path`);return t===`gitWorktree`&&typeof n==`string`&&typeof r==`string`?Object.freeze({kind:t,label:n,path:r}):void 0}var In=[`forkCancelled`,`forked`,`nameUsage`,`requestExpired`,`reloadActive`,`reloadUnavailable`,`reloaded`,`cloneEmpty`,`cloneCancelled`,`cloned`,`forkEmpty`,`forkSelect`,`treeActive`,`treeEmpty`,`treeUnavailable`,`navigationActive`];function Ln(e){if(!Rn(e)||e.kind!==`commandResult`||!Rn(e.feedback))return;let t=e.feedback,n=t.code;if(typeof n!=`string`)return;let r=In.find(e=>e===n);if(r!==void 0)return{kind:`commandResult`,feedback:{code:r}};switch(n){case`unknown`:case`notImplemented`:if(typeof t.command==`string`)return{kind:`commandResult`,feedback:{code:n,command:t.command}};break;case`named`:if(typeof t.name==`string`)return{kind:`commandResult`,feedback:{code:n,name:t.name}};break;case`reloadFailed`:case`treeFailed`:if(typeof t.detail==`string`)return{kind:`commandResult`,feedback:{code:n,detail:t.detail}};break;case`replacementActive`:if(t.command===`fork`||t.command===`clone`)return{kind:`commandResult`,feedback:{code:n,command:t.command}};break;case`stats`:{let e=t.stats;if(!Rn(e)||typeof e.sessionId!=`string`||!Rn(e.tokens))break;let{totalMessages:r,userMessages:i,assistantMessages:a,toolCalls:o,cost:s}=e,{input:c,output:l,total:u}=e.tokens;if(!b(r)||!b(i)||!b(a)||!b(o)||!b(s)||!b(c)||!b(l)||!b(u))break;return{kind:`commandResult`,feedback:{code:n,stats:{sessionId:e.sessionId,totalMessages:r,userMessages:i,assistantMessages:a,toolCalls:o,cost:s,tokens:{input:c,output:l,total:u}}}}}}}function b(e){return typeof e==`number`&&Number.isFinite(e)}function Rn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function zn(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=Reflect.get(e,`kind`);if(t===`modelAuthRemoved`){let n=Reflect.get(e,`provider`),r=Reflect.get(e,`model`);return typeof n==`string`&&typeof r==`string`?{kind:t,provider:n,model:r}:void 0}if(t===`sessionNamingFailed`){let n=Reflect.get(e,`detail`);return typeof n==`string`?{kind:t,detail:n}:void 0}}var Bn={compactionCancelled:`Compaction cancelled.`,automaticCompactionCancelled:`Automatic compaction cancelled.`,compactionFailed:`Couldn’t compact history. Try again.`};function Vn(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=Reflect.get(e,`kind`);if(t===`compactionCancelled`||t===`automaticCompactionCancelled`||t===`compactionFailed`)return{kind:t}}function Hn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Un(e){return e===`message`||e===`user-message`||e===`assistant-response`||e===`assistant-error`||e===`assistant-aborted`||e===`hidden-custom-message`||e===`compaction-summary`||e===`branch-summary`}function Wn(e){return e===`shell`||e===`model`||e===`thinking-level`||e===`session-name`||e===`label`||e===`custom-entry`||e===`entry`}function x(e,t){return typeof e==`string`&&e.length<=t}function Gn(e){if(!Array.isArray(e)||e.length>720)return;let t=[],n=720;for(let r of e){if(!Hn(r))return;if(r.type===`text`&&x(r.text,n))t.push({type:`text`,text:r.text}),n-=r.text.length;else if(r.type===`image`&&n>0)t.push({type:`image`}),n-=7;else return}return t}function Kn(e){if(!Hn(e))return;let t=e.type;switch(t){case`status`:return Un(e.status)?{type:t,status:e.status}:void 0;case`content`:{let n=Gn(e.parts);return n!==void 0&&Un(e.fallback)?{type:t,parts:n,fallback:e.fallback}:void 0}case`named`:{let n=e.field,r=e.value;return!Wn(n)||r!==void 0&&!x(r,n===`model`?161:80)?void 0:{type:t,field:n,...r===void 0?{}:{value:r}}}case`assistant-tools`:{let n=e.names;if(!Array.isArray(n)||n.length>3)return;let r=[];for(let e of n){if(!x(e,80))return;r.push(e)}return{type:t,names:r}}case`tool-result`:{let n=Gn(e.parts),r=e.isError,i=e.toolName;return n===void 0||typeof r!=`boolean`||i!==void 0&&!x(i,80)?void 0:{type:t,parts:n,isError:r,...i===void 0?{}:{toolName:i}}}case`custom-message`:{let n=Gn(e.parts),r=e.customType;return n===void 0||r!==void 0&&!x(r,80)?void 0:{type:t,parts:n,...r===void 0?{}:{customType:r}}}default:return}}var qn=Object.values(y),Jn=new Set(qn);y.sessionsDeleteArchived,y.sessionsBulkMutations,y.sessionsCleanup,y.sessionsReload,y.sessionsClearQueue,y.sessionsQueueMessageActions,y.sessionsPersistedState,y.sessionsNotifications,y.sessionsUnread,y.sessionsAskUser,y.promptAttachments,y.workspaceFileSuggestions,y.piPackagesManage,y.selectedMachineSettings,y.agentProfileConfig,y.pluginLifecycle,y.sessionCleanupPinnedExclusions,y.sessionPinsDaemonOwned,y.sessionPinsManagementScoped,y.sessionsDeleteArchived,y.sessionsBulkMutations,y.sessionsCleanup,y.sessionsReload,y.sessionsClearQueue,y.sessionsQueueMessageActions,y.sessionsPersistedState,y.sessionsNotifications,y.sessionsUnread,y.sessionsAskUser,y.promptAttachments,y.sessionCleanupPinnedExclusions,y.sessionPinsDaemonOwned,y.sessionPinsManagementScoped,y.sessionsDeleteArchived,y.sessionsBulkMutations,y.sessionsCleanup,y.sessionsReload,y.sessionsClearQueue,y.sessionsQueueMessageActions,y.sessionsPersistedState,y.sessionsNotifications,y.sessionsUnread,y.sessionsAskUser,y.promptAttachments,y.workspaceFileSuggestions,y.piPackagesManage,y.selectedMachineSettings,y.agentProfileConfig,y.pluginLifecycle,y.sessionCleanupPinnedExclusions,y.sessionPinsDaemonOwned,y.sessionPinsManagementScoped;function Yn(e){return typeof e==`string`&&Jn.has(e)}function Xn(e,t){return e?.capabilities?.includes(t)===!0}function Zn(e){if(Array.isArray(e)&&e.every(e=>typeof e==`string`))return e.filter(Yn)}function Qn(e){if(!Array.isArray(e))return;let t=[];for(let n of e){if(!$n(n))continue;let e=n.source,r=n.name,i=n.replacement;(e===`environment`||e===`config`)&&typeof r==`string`&&r!==``&&(i===void 0||typeof i==`string`&&i!==``)&&t.push({source:e,name:r,...i===void 0?{}:{replacement:i}})}return t}function $n(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var er=[`projectId`,`workspaceId`,`sessionId`];function tr(e,t){if(!rr(e))throw Error(`${t} must be an object`);let n=!1;for(let r in e)if(Object.hasOwn(e,r)&&(n=!0,!nr(r)))throw Error(`Unsupported ${t} field: ${r}`);if(!n)throw Error(`${t} must contain at least one of projectId, workspaceId, or sessionId`);let r={};for(let n of er){if(!Object.hasOwn(e,n))continue;let i=e[n];if(typeof i!=`string`||i.length>512||i.trim()===``)throw Error(`${t} ${n} must be a non-empty string of at most 512 characters`);r[n]=i}if(r.projectId!==void 0)return Object.freeze({...r,projectId:r.projectId});if(r.workspaceId!==void 0)return Object.freeze({...r,workspaceId:r.workspaceId});if(r.sessionId!==void 0)return Object.freeze({...r,sessionId:r.sessionId});throw Error(`${t} must contain at least one visibility selector`)}function nr(e){return er.some(t=>t===e)}function rr(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var ir={working:`core:working`,terminal:`core:terminal`,unread:`core:unread`,interventionRequired:`core:intervention-required`};function ar(e){if(!cr(e))return;let t=e.epochId,n=e.revision,r=e.generatedAt,i=or(e.machine),a=or(e.unattributed),o=sr(e.projects),s=sr(e.workspaces);if(typeof t!=`string`||t===``||typeof n!=`number`||!Number.isFinite(n)||typeof r!=`string`||r===``||i===void 0||a===void 0||o===void 0||s===void 0)return;let c={epochId:t,revision:n,machine:i,projects:o,workspaces:s,unattributed:a,generatedAt:r};if(Object.hasOwn(e,`sessions`)){let t=sr(e.sessions,!0);if(t===void 0)return;c.sessions=t}return c}function or(e){if(!cr(e))return;let t=new Map;for(let[n,r]of Object.entries(e))typeof r==`boolean`&&t.set(n,r);return Object.fromEntries(t)}function sr(e,t=!1){if(!cr(e))return;let n=new Map;for(let[r,i]of Object.entries(e)){let e=or(i);if(e===void 0&&t)return;e!==void 0&&n.set(r,e)}return Object.fromEntries(n)}function cr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var lr={compacting:`compacting`,duplicateQueuedMessage:`duplicate queued message ignored`,steeringQueued:`steering queued`,messageQueued:`message queued`,promptAccepted:`prompt accepted`,error:`error`,queuedDuringCompaction:`message queued during compaction`,runningBash:`running bash`,bashComplete:`bash complete`,bashFailed:`bash failed`,summarizingBranch:`summarizing branch`,navigatingTree:`navigating session tree`,branchSummaryAborted:`branch summary aborted`,treeNavigationCancelled:`tree navigation cancelled`,treeNavigated:`session tree navigated`,treeNavigationFailed:`tree navigation failed`,forking:`forking session from entry`,forkCancelled:`fork cancelled`,forked:`session forked`,forkFailed:`fork failed`,reloading:`reloading resources`,reloaded:`resources reloaded`,reloadFailed:`reload failed`,stopped:`stopped`,stopFailed:`stop failed`,extensionError:`extension error`,extensionCallbackFailed:`extension callback failed`,compactionCancelled:`compaction cancelled`,compactionComplete:`compaction complete`,compactionFailed:`compaction failed`,updatingSession:`updating session`,agentRunning:`agent running`,queued:`queued`,active:`active`,idle:`idle`,turnComplete:`turn complete`,messageStarted:`message started`,messageComplete:`message complete`,receivingResponse:`receiving response`,runningTool:`running tool`,toolFailed:`tool failed`,toolComplete:`tool complete`};function ur(e){return Object.hasOwn(lr,e)}function dr(e){if(typeof e!=`object`||!e||!(`kind`in e))return;let{kind:t}=e;if(t===`model`||t===`thinking`||t===`event`)return`value`in e&&typeof e.value==`string`?{kind:t,value:e.value}:void 0;if(typeof t!=`string`||!ur(t))return;let n=`detailKind`in e?e.detailKind:void 0;if(n===void 0||n===`compactionCancelled`||n===`automaticCompactionCancelled`||n===`compactionFailed`)return{kind:t,...n===void 0?{}:{detailKind:n}}}var S=Object.freeze({showSafeStart:`pi-web plugins safe-start show`,bundledOnly:`pi-web plugins safe-start set bundled-only --restart`,noServerPlugins:`pi-web plugins safe-start set none --restart`,clearSafeStart:`pi-web plugins safe-start clear --restart`});function fr(e){if(!mn(e))throw Error(`Invalid PI WEB plugin id: ${e}`);return`pi-web plugins disable ${e} --restart`}function C(e){return typeof e==`object`&&!!e}function w(e){if(!C(e))throw Error(`Expected object response`);return e}function T(e,t){let n=e[t];if(typeof n!=`string`)throw Error(`Expected string field: ${t}`);return n}function E(e,t){let n=e[t];if(n!==void 0){if(typeof n!=`string`)throw Error(`Expected optional string field: ${t}`);return n}}function D(e,t){let n=e[t];if(typeof n!=`number`)throw Error(`Expected number field: ${t}`);return n}function O(e,t){let n=e[t];if(typeof n!=`boolean`)throw Error(`Expected boolean field: ${t}`);return n}function k(e){return t=>{if(!Array.isArray(t))throw Error(`Expected array response`);return t.map(e)}}function pr(e){if(!Array.isArray(e))throw Error(`Expected array response`);return e.map(e=>{if(typeof e==`object`&&e&&`entryId`in e&&e.entryId!==void 0&&typeof e.entryId!=`string`)throw Error(`Expected string field: entryId`);return e})}function A(e,t){if(!Array.isArray(e)||!e.every(e=>typeof e==`string`))throw Error(`Expected string array field: ${t}`);return e}function mr(e){let t=w(e),n=t.leafId;if(n!=null&&typeof n!=`string`)throw Error(`Expected optional string|null field: leafId`);return{messages:pr(t.messages),start:D(t,`start`),total:D(t,`total`),...W(`leafId`,n)}}function hr(e){let t=w(e);return k(gr)(t.machines)}function gr(e){let t=w(e),n=br(t,`kind`),r=E(t,`baseUrl`),i=xr(t,`status`),a=E(t,`statusMessage`);return{id:T(t,`id`),name:T(t,`name`),...W(`nameOverride`,E(t,`nameOverride`)),...W(`reportedName`,E(t,`reportedName`)),kind:n,...r===void 0?{}:{baseUrl:r},createdAt:T(t,`createdAt`),updatedAt:T(t,`updatedAt`),...i===void 0?{}:{status:i},...a===void 0?{}:{statusMessage:a}}}function _r(e){let t=w(e),n=xr(t,`status`),r=E(t,`error`);return{machineId:T(t,`machineId`),ok:O(t,`ok`),checkedAt:T(t,`checkedAt`),...n===void 0?{}:{status:n},...t.web===void 0?{}:{web:Eo(t.web)},...t.sessiond===void 0?{}:{sessiond:Eo(t.sessiond)},...r===void 0?{}:{error:r}}}function vr(e){let t=w(e),n=E(t,`error`);return{machineId:T(t,`machineId`),ok:O(t,`ok`),checkedAt:T(t,`checkedAt`),...W(`packageName`,E(t,`packageName`)),...W(`generatedAt`,E(t,`generatedAt`)),...t.components===void 0?{}:{components:wo(t.components)},...t.capabilities===void 0?{}:{capabilities:Mo(t.capabilities)},...t.deprecatedAgentInputs===void 0?{}:{deprecatedAgentInputs:yr(t.deprecatedAgentInputs)},...n===void 0?{}:{error:n}}}function yr(e){let t=Qn(e);if(t===void 0)throw Error(`Invalid PI WEB deprecated agent inputs`);return t}function br(e,t){let n=T(e,t);if(n!==`local`&&n!==`remote`)throw Error(`Expected machine kind field: ${t}`);return n}function xr(e,t){let n=E(e,t);if(n!==void 0){if(n!==`unknown`&&n!==`online`&&n!==`offline`&&n!==`error`)throw Error(`Expected machine status field: ${t}`);return n}}function Sr(e){let t=w(e);return{id:T(t,`id`),name:T(t,`name`),path:T(t,`path`),createdAt:T(t,`createdAt`)}}function Cr(e){let t=w(e);return Object.freeze({id:T(t,`id`),projectId:T(t,`projectId`),path:T(t,`path`),label:T(t,`label`),isMain:O(t,`isMain`),...W(`branch`,E(t,`branch`)),...W(`isGitRepo`,H(t,`isGitRepo`)),...W(`isGitWorktree`,H(t,`isGitWorktree`)),...W(`provider`,kr(t.provider)),...W(`removal`,Ar(t.removal)),effectiveConfig:Nr(t.effectiveConfig)})}function wr(e){let t=w(e),n=Tr(t.status),r=T(t,`projectId`),i=E(t,`ownerPluginId`);if(n===`provider`&&i===void 0)throw Error(`Provider workspace resolution is missing ownerPluginId`);if(n===`folder`&&i!==void 0)throw Error(`Folder workspace resolution must not include ownerPluginId`);let a=k(Cr)(t.workspaces);if(a.length===0||a.some(e=>e.projectId!==r))throw Error(`Workspace resolution contains invalid project workspaces`);let o=k(Er)(t.diagnostics);return Object.freeze({status:n,projectId:r,...i===void 0?{}:{ownerPluginId:i},workspaces:Object.freeze(a),diagnostics:Object.freeze(o)})}function Tr(e){if(e===`provider`||e===`folder`||e===`degraded`)return e;throw Error(`Invalid workspace provider resolution status`)}function Er(e){let t=w(e),n=E(t,`pluginId`),r=t.pluginIds===void 0?void 0:A(t.pluginIds,`pluginIds`);return Object.freeze({code:Dr(t.code),message:T(t,`message`),tier:Or(t.tier),...n===void 0?{}:{pluginId:n},...r===void 0?{}:{pluginIds:Object.freeze(r)}})}function Dr(e){if(e===`probe-failed`||e===`claim-conflict`||e===`list-failed`)return e;throw Error(`Invalid workspace provider diagnostic code`)}function Or(e){if(e===`primary`||e===`fallback`)return e;throw Error(`Invalid workspace provider diagnostic tier`)}function kr(e){if(e===void 0)return;if(!C(e)||Array.isArray(e))throw Error(`Invalid workspace provider field`);let t=e.capabilities;if(!C(t)||Array.isArray(t))throw Error(`Invalid workspace provider capabilities field`);let n=e.metadata;return Object.freeze({pluginId:T(e,`pluginId`),capabilities:Object.freeze({remove:O(t,`remove`),...W(`request`,H(t,`request`))}),...W(`metadata`,n===void 0?void 0:jr(n,`workspace provider metadata`))})}function Ar(e){if(e!==void 0){if(!C(e)||Array.isArray(e))throw Error(`Invalid workspace removal field`);return Object.freeze({actionLabel:I(e,`actionLabel`),confirmation:I(e,`confirmation`),precondition:I(e,`precondition`),...W(`localization`,Fn(e.localization))})}}function jr(e,t){if(!C(e)||Array.isArray(e))throw Error(`Invalid ${t} field`);return Object.freeze(Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Mr(n,t)])))}function Mr(e,t){if(e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e))return e;if(Array.isArray(e))return Object.freeze(e.map(e=>Mr(e,t)));if(C(e))return jr(e,t);throw Error(`Invalid ${t} field`)}function Nr(e){if(!C(e)||Array.isArray(e))throw Error(`Expected workspace effectiveConfig field`);let t=Ya(e.uploads),n=Xa(e.attachments);return Object.freeze({...W(`uploads`,t===void 0?void 0:Object.freeze({...t})),...W(`attachments`,n===void 0?void 0:Object.freeze({...n}))})}function Pr(e){if(!C(e)||Array.isArray(e))throw Error(`Invalid session metadata field`);return Object.freeze(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,jr(t,`session metadata namespace`)])))}function j(e){let t=w(e),n=E(t,`name`),r=t.metadata===void 0?void 0:Pr(t.metadata),i=B(t.persisted,`persisted`),a=E(t,`parentSessionPath`),o=E(t,`archivedAt`);return{id:T(t,`id`),path:T(t,`path`),cwd:T(t,`cwd`),...i===void 0?{}:{persisted:i},...W(`interventionRequired`,B(t.interventionRequired,`interventionRequired`)),...W(`agentSubsession`,B(t.agentSubsession,`agentSubsession`)),...n===void 0?{}:{name:n},...r===void 0?{}:{metadata:r},created:T(t,`created`),modified:T(t,`modified`),messageCount:D(t,`messageCount`),firstMessage:T(t,`firstMessage`),...a===void 0?{}:{parentSessionPath:a},...W(`agentSubsession`,H(t,`agentSubsession`)),...t.archived===!0?{archived:!0}:{},...o===void 0?{}:{archivedAt:o}}}function Fr(e){let t=w(e);return{configured:O(t,`configured`),authenticated:O(t,`authenticated`)}}function Ir(e){return{path:T(w(e),`path`)}}function Lr(e){let t=w(e);if(t.deleted!==!0)throw Error(`Expected deleted response`);return{deleted:!0,path:T(t,`path`)}}function Rr(e){let t=w(e);return{results:k(zr)(t.results),matchCount:D(t,`matchCount`),truncated:O(t,`truncated`)}}function zr(e){let t=w(e);return{session:j(t.session),matches:k(Br)(t.matches)}}function Br(e){let t=w(e),n=T(t,`role`);if(n!==`user`&&n!==`assistant`)throw Error(`Invalid session content search role`);return{messageIndex:D(t,`messageIndex`),role:n,excerpts:k(Vr)(t.excerpts),occurrenceCount:D(t,`occurrenceCount`)}}function Vr(e){let t=w(e);return{text:T(t,`text`),matchRanges:k(e=>{let t=w(e);return{start:D(t,`start`),length:D(t,`length`)}})(t.matchRanges)}}function Hr(e){if(e!==`info`&&e!==`warning`&&e!==`error`)throw Error(`Invalid session warning severity`);return e}function Ur(e){if(e!==void 0)return{id:T(w(e),`id`)}}function Wr(e){let t=w(e),n=Ur(t.dismiss);return{severity:Hr(t.severity),message:T(t,`message`),...C(t.presentation)&&t.presentation.kind===`anthropicSubscriptionAuth`?{presentation:{kind:`anthropicSubscriptionAuth`}}:{},...W(`source`,E(t,`source`)),...W(`path`,E(t,`path`)),...n===void 0?{}:{dismiss:n}}}function Gr(e){let t=`Recently active in another PI-WEB instance. Avoid working on this session in both instances at once.`;return e.severity===`info`&&e.source===`PI-WEB`&&(e.message===t||e.message===v(`ui.sessionActivity.message`,t))}function Kr(e){let t=w(e);return{value:N(t,`value`,128),label:N(t,`label`,Cn),...W(`detail`,P(t,`detail`,Cn))}}function qr(e){let t=w(e),n=F(t.options,Kr,12,`options`);$r(n.map(e=>e.value),`ask option value`),B(t.allowOther,`allowOther`);let r=B(t.multiple,`multiple`);return{id:N(t,`id`,128),question:N(t,`question`,Cn),...W(`detail`,P(t,`detail`,Cn)),options:n,allowOther:!0,...r===void 0?{}:{multiple:r}}}function Jr(e){let t=w(e),n=F(t.questions,qr,20,`questions`);if(n.length===0)throw Error(`Ask has no questions`);return $r(n.map(e=>e.id),`ask question id`),{askId:N(t,`askId`,128),askedAt:I(t,`askedAt`),questions:n}}function Yr(e){if(e!==`submitted`&&e!==`superseded`&&e!==`cancelled`)throw Error(`Invalid ask close reason`);return e}function Xr(e){let t=w(e),n=qr(t.question),r=F(t.values,Hi,12,`values`),i=new Set(n.options.map(e=>e.value));if(r.some(e=>!i.has(e)))throw Error(`Ask answer selected an option the question never offered`);let a=P(t,`otherText`,wn),o=P(t,`comment`,Tn),s=O(t,`answered`);if(s!==(r.length>0||a!==void 0))throw Error(`Ask answer contradicts its answered flag`);return{question:n,answered:s,values:r,...a===void 0?{}:{otherText:a},...o===void 0?{}:{comment:o}}}function Zr(e){let t=w(e),n=F(t.questions,Xr,20,`questions`),r=L(t,`answeredCount`),i=A(t.unansweredIds,`unansweredIds`),a=n.filter(e=>!e.answered).map(e=>e.question.id);if(r!==n.length-a.length)throw Error(`Ask outcome answered count mismatch`);if(i.length!==a.length||i.some((e,t)=>e!==a[t]))throw Error(`Ask outcome unanswered ids mismatch`);return{askId:N(t,`askId`,128),reason:Yr(t.reason),askedAt:I(t,`askedAt`),closedAt:I(t,`closedAt`),questions:n,answeredCount:r,unansweredIds:i,summary:I(t,`summary`)}}function Qr(e){let t=w(e),n=t.result;if(n!==`closed`&&n!==`stale`)throw Error(`Invalid dialog close result`);let r=t.outcome===void 0?void 0:ci(t.outcome);if(n===`closed`!=(r!==void 0))throw Error(`Dialog close response outcome mismatch`);return{result:n,...r===void 0?{}:{outcome:r},sessionStatus:M(t.sessionStatus)}}function $r(e,t){if(new Set(e).size!==e.length)throw Error(`Duplicate ${t}`)}function ei(e){if(e!==`confirm`&&e!==`select`&&e!==`input`)throw Error(`Invalid extension dialog kind`);return e}function ti(e){if(e!==`answered`&&e!==`cancelled`&&e!==`timeout`&&e!==`aborted`&&e!==`session-ended`)throw Error(`Invalid extension dialog close reason`);return e}function ni(e){if(typeof e==`boolean`||typeof e==`string`&&e.length<=4e3)return e;throw Error(`Invalid extension dialog answer`)}function ri(e){let t=Hi(e);if(t.length>1e3)throw Error(`String field exceeds limit: option`);return t}function ii(e){let t=w(e),n=ei(t.kind),r=t.options===void 0?void 0:F(t.options,ri,24,`options`);if(r!==void 0&&$r(r,`dialog option`),n===`select`&&(r===void 0||r.length===0))throw Error(`Select dialog has no options`);return{dialogId:N(t,`dialogId`,128),kind:n,title:N(t,`title`,En),...W(`message`,P(t,`message`,En)),...r===void 0?{}:{options:r},...W(`placeholder`,P(t,`placeholder`,En)),askedAt:I(t,`askedAt`),...W(`timeoutAt`,li(t,`timeoutAt`)),runScoped:O(t,`runScoped`)}}function ai(e){if(e===void 0)return{};let t=k(ii)(e);return $r(t.map(e=>e.dialogId),`dialog id`),{pendingDialogs:t}}function oi(e){let t=w(e);if(t.type!==`dialog.opened`)throw Error(`Invalid dialog opened event type`);return{type:`dialog.opened`,dialog:ii(t.dialog)}}function si(e){let t=w(e);if(t.type!==`dialog.closed`)throw Error(`Invalid dialog closed event type`);let n=ti(t.reason),r=t.answer===void 0?void 0:ni(t.answer);if(n===`answered`!=(r!==void 0))throw Error(`Dialog closed event answer mismatch`);return{type:`dialog.closed`,dialogId:N(t,`dialogId`,128),reason:n,...r===void 0?{}:{answer:r}}}function ci(e){let t=w(e),n=ti(t.reason),r=t.answer===void 0?void 0:ni(t.answer);if(n===`answered`!=(r!==void 0))throw Error(`Dialog outcome answer mismatch`);return{dialogId:N(t,`dialogId`,128),reason:n,...r===void 0?{}:{answer:r},askedAt:I(t,`askedAt`),closedAt:I(t,`closedAt`)}}function li(e,t){let n=E(e,t);if(n!==void 0){if(n===``)throw Error(`Expected non-empty string field: ${t}`);return n}}function M(e){let t=w(e),n=t.warnings===void 0?void 0:k(Wr)(t.warnings),r=B(t.recentlyActiveElsewhere,`recentlyActiveElsewhere`);return{sessionId:T(t,`sessionId`),...W(`persisted`,B(t.persisted,`persisted`)),recentlyActiveElsewhere:r??n?.some(Gr)??!1,...W(`interventionRequired`,B(t.interventionRequired,`interventionRequired`)),isStreaming:O(t,`isStreaming`),isCompacting:O(t,`isCompacting`),isBashRunning:O(t,`isBashRunning`),pendingMessageCount:D(t,`pendingMessageCount`),queuedMessages:t.queuedMessages===void 0?[]:k(ta)(t.queuedMessages),...W(`queueMessageActionsUnavailable`,E(t,`queueMessageActionsUnavailable`)),...W(`messageCount`,U(t,`messageCount`)),tokens:na(t.tokens),cost:D(t,`cost`),...ia(t.model),...wa(t.contextUsage),...W(`thinkingLevel`,E(t,`thinkingLevel`)),...W(`warnings`,n?.filter(e=>!Gr(e))),...ai(t.pendingDialogs),...W(`suggestedInput`,E(t,`suggestedInput`))}}function ui(e){let t=w(e);return{seq:D(t,`seq`),partial:t.partial??null}}function di(e){let t=w(e);if(t.partial===void 0)throw Error(`Expected field: partial`);return{page:mr(t.page),status:M(t.status),seq:L(t,`seq`),partial:t.partial}}function fi(e){let t=w(e),n=L(t,`catalogRevision`),r=F(t.sessions,Ti,yn,`sessions`);if(Ei(r),Di(r),r.some(e=>e.completionOrder>n))throw Error(`Session unread completion order exceeds catalog revision`);return{catalogId:N(t,`catalogId`,512),catalogRevision:n,sessions:r}}function pi(e){let t=w(e);if(t.type!==`sessions.unread`)throw Error(`Invalid session unread event type`);let n=N(t,`sessionId`,512),r=N(t,`cwd`,bn),i=Oi(t,`catalogRevision`),a=t.unread===null?null:Ti(t.unread);if(a!==null&&(a.sessionId!==n||a.cwd!==r))throw Error(`Session unread event identity mismatch`);if(a!==null&&a.completionOrder>i)throw Error(`Session unread completion order exceeds catalog revision`);return{type:`sessions.unread`,catalogId:N(t,`catalogId`,512),catalogRevision:i,sessionId:n,cwd:r,unread:a}}function mi(e){let t=w(e);if(t.type!==`session.startup`)throw Error(`Invalid session startup event type`);let n=E(t,`startupToken`);if(n===``)throw Error(`Expected non-empty string field: startupToken`);return{type:`session.startup`,...W(`startupToken`,n),activity:hi(t.activity)}}function hi(e){let t=w(e);return{sessionId:I(t,`sessionId`),phase:vi(t,`phase`),label:I(t,`label`),...W(`detail`,E(t,`detail`)),at:I(t,`at`),...W(`startup`,_i(t)),...W(`startupPresentation`,gi(t.startupPresentation)),...W(`runtimePresentation`,dr(t.runtimePresentation))}}function gi(e){if(!C(e))return;let{intent:t,stage:n,catalogRefreshing:r}=e;if(!(t!==`create`&&t!==`open`||n!==`runtime`&&n!==`extensions`||typeof r!=`boolean`))return{intent:t,stage:n,catalogRefreshing:r}}function _i(e){let t=e.startup;if(t!==void 0){if(typeof t!=`boolean`)throw Error(`Expected optional boolean field: startup`);return t}}function vi(e,t){let n=T(e,t);if(n!==`active`&&n!==`idle`&&n!==`error`)throw Error(`Expected session activity phase field: ${t}`);return n}function yi(e){let t=w(e);switch(t.type){case`message.append`:return{type:`message.append`,message:xi(t,`message`)};case`assistant.start`:return{type:`assistant.start`,message:xi(t,`message`)};case`assistant.delta`:return{type:`assistant.delta`,text:T(t,`text`),...W(`streamId`,E(t,`streamId`))};case`assistant.thinking.delta`:return{type:`assistant.thinking.delta`,text:T(t,`text`),...W(`streamId`,E(t,`streamId`))};case`tool.start`:return{type:`tool.start`,toolName:T(t,`toolName`),toolCallId:T(t,`toolCallId`),summary:T(t,`summary`),...W(`args`,t.args)};case`tool.update`:return{type:`tool.update`,toolName:T(t,`toolName`),toolCallId:T(t,`toolCallId`),text:T(t,`text`),...W(`content`,t.content),...W(`details`,t.details)};case`tool.end`:return{type:`tool.end`,toolName:T(t,`toolName`),toolCallId:T(t,`toolCallId`),text:T(t,`text`),isError:O(t,`isError`),...W(`content`,t.content),...W(`details`,t.details)};case`shell.start`:return{type:`shell.start`,command:T(t,`command`),...W(`excludeFromContext`,B(t.excludeFromContext,`excludeFromContext`))};case`shell.chunk`:return{type:`shell.chunk`,chunk:T(t,`chunk`)};case`shell.end`:return{type:`shell.end`,...W(`output`,E(t,`output`)),...W(`exitCode`,Si(t,`exitCode`)),...W(`cancelled`,B(t.cancelled,`cancelled`)),...W(`truncated`,B(t.truncated,`truncated`)),...W(`fullOutputPath`,E(t,`fullOutputPath`)),...W(`isError`,B(t.isError,`isError`))};case`agent.start`:return{type:`agent.start`};case`agent.end`:return{type:`agent.end`};case`message.end`:return{type:`message.end`,...W(`message`,t.message)};case`status.update`:return{type:`status.update`,status:M(t.status)};case`activity.update`:return{type:`activity.update`,activity:hi(t.activity)};case`command.output`:return Ci(t);case`session.error`:return{type:`session.error`,message:T(t,`message`)};case`session.diagnostic`:return{type:`session.diagnostic`,message:T(t,`message`)};case`session.name`:return wi(t);case`session.created`:return{type:`session.created`,session:j(t.session)};case`session.tree.changed`:return{type:`session.tree.changed`};case`pi.event`:return{type:`pi.event`,eventType:T(t,`eventType`)};default:throw Error(`Unsupported session stream event type`)}}function bi(e){let t=w(e);switch(t.type){case`status.update`:return{type:`status.update`,status:M(t.status)};case`activity.update`:return{type:`activity.update`,activity:hi(t.activity)};case`session.name`:return wi(t);case`session.created`:return{type:`session.created`,session:j(t.session)};case`models.changed`:return{type:`models.changed`,revision:L(t,`revision`)};case`workspaces.changed`:return{type:`workspaces.changed`,projectId:I(t,`projectId`)};case`session-pins.changed`:return{type:`session-pins.changed`,projectId:I(t,`projectId`),workspaceId:I(t,`workspaceId`),revision:L(t,`revision`)};case`notices.updated`:return Mi(t);case`machine.status`:return{type:`machine.status`,status:Va(t.status)};default:throw Error(`Unsupported realtime stream event type`)}}function xi(e,t){let n=e[t];if(n===void 0)throw Error(`Expected field: ${t}`);return n}function Si(e,t){let n=e[t];if(n!==void 0){if(n===null)return null;if(typeof n!=`number`)throw Error(`Expected optional number|null field: ${t}`);return n}}function Ci(e){let t=T(e,`level`);if(t!==`info`&&t!==`success`&&t!==`error`)throw Error(`Invalid command output level`);return{type:`command.output`,level:t,message:T(e,`message`),...W(`presentation`,zn(e.presentation))}}function wi(e){return{type:`session.name`,sessionId:I(e,`sessionId`),...W(`name`,E(e,`name`))}}function Ti(e){let t=w(e),n=N(t,`completedAt`,64),r=new Date(n);if(!Number.isFinite(r.getTime())||r.toISOString()!==n)throw Error(`Invalid canonical session unread completion time`);let i=t.messageRange===void 0?void 0:w(t.messageRange),a;if(i!==void 0){let e=L(i,`start`),t=L(i,`end`),n=i.leafId;if(t<e||n!==null&&typeof n!=`string`)throw Error(`Invalid unread message range`);a={start:e,end:t,leafId:n}}return{sessionId:N(t,`sessionId`,512),cwd:N(t,`cwd`,bn),completionOrder:Oi(t,`completionOrder`),completedAt:n,...a===void 0?{}:{messageRange:a}}}function Ei(e){let t=e.map(e=>JSON.stringify([e.sessionId,e.cwd]));if(new Set(t).size!==t.length)throw Error(`Duplicate session unread identity`);let n=e.map(e=>e.completionOrder);if(new Set(n).size!==n.length)throw Error(`Duplicate session unread completion order`)}function Di(e){for(let t=1;t<e.length;t+=1){let n=e[t-1],r=e[t];if(n===void 0||r===void 0||n.completionOrder<=r.completionOrder)throw Error(`Session unread summaries are not newest-first`)}}function N(e,t,n){let r=I(e,t);if(r.length>n)throw Error(`String field exceeds limit: ${t}`);return r}function P(e,t,n){let r=E(e,t);if(r!==void 0){if(r===``)throw Error(`Expected non-empty string field: ${t}`);if(r.length>n)throw Error(`String field exceeds limit: ${t}`);return r}}function Oi(e,t){let n=L(e,t);if(n===0)throw Error(`Expected positive safe integer field: ${t}`);return n}function ki(e){let t=w(e),n=Fi(t.summary),r=F(t.notifications,Ii,100,`notifications`);if(Ui(r),Wi(r),n.retainedCount!==r.length)throw Error(`Notification snapshot retained count mismatch`);if(n.highestSeverity!==Ki(r))throw Error(`Notification snapshot severity mismatch`);let i=Li(t.dismissThrough),a=r[0]?.order??0;if(i.order!==a)throw Error(`Notification snapshot dismiss cutoff mismatch`);if(i.overflowWatermark<n.discardedCount)throw Error(`Notification snapshot overflow cutoff mismatch`);return{daemonInstanceId:I(t,`daemonInstanceId`),catalogRevision:L(t,`catalogRevision`),summary:n,notifications:r,dismissThrough:i}}function Ai(e){let t=w(e);if(t.type!==`notifications.inbox`)throw Error(`Invalid notification inbox event type`);let n=Fi(t.summary),r=Li(t.dismissThrough);if(r.overflowWatermark<n.discardedCount)throw Error(`Notification event overflow cutoff mismatch`);let i=Ri(t.delta);if(i.kind===`cleared`&&!Gi(n))throw Error(`Notification clear event summary mismatch`);if(i.kind===`added`&&n.retainedCount===0)throw Error(`Notification add event summary mismatch`);return{type:`notifications.inbox`,daemonInstanceId:I(t,`daemonInstanceId`),catalogRevision:L(t,`catalogRevision`),summary:n,dismissThrough:r,delta:i}}function ji(e){let t=w(e),n=k(Ni)(t.notices),r=n.map(e=>e.id);if(new Set(r).size!==r.length)throw Error(`Duplicate server notice id`);return{daemonInstanceId:I(t,`daemonInstanceId`),revision:L(t,`revision`),notices:n}}function Mi(e){let t=w(e);if(t.type!==`notices.updated`)throw Error(`Invalid server notice event type`);return{type:`notices.updated`,snapshot:ji(t.snapshot)}}function Ni(e){let t=w(e),n=Pn(t.presentation),r=I(t,`createdAt`);if(!Number.isFinite(Date.parse(r)))throw Error(`Invalid server notice creation time`);let i=E(t,`source`),a=t.context===void 0?void 0:jr(t.context,`server notice context`),o=t.scope===void 0?void 0:tr(t.scope,`server notice scope`);return{id:I(t,`id`),severity:Pi(t.severity),...W(`presentation`,n),message:T(t,`message`),createdAt:r,...W(`source`,i),...W(`scope`,o),...W(`context`,a)}}function Pi(e){if(e!==`info`&&e!==`warning`&&e!==`error`)throw Error(`Invalid server notice severity`);return e}function Fi(e){let t=w(e),n=L(t,`retainedCount`);if(n>100)throw Error(`Notification retained count exceeds limit`);let r=L(t,`discardedCount`),i=Bi(t.highestSeverity);if(n===0!=(i===void 0))throw Error(`Notification summary severity mismatch`);return{sessionId:I(t,`sessionId`),cwd:I(t,`cwd`),inboxRevision:L(t,`inboxRevision`),retainedCount:n,discardedCount:r,...i===void 0?{}:{highestSeverity:i}}}function Ii(e){let t=w(e),n=T(t,`message`);if(new TextEncoder().encode(n).byteLength>8192)throw Error(`Notification message exceeds byte limit`);let r=T(t,`receivedAt`);if(!Number.isFinite(Date.parse(r)))throw Error(`Invalid notification receive time`);let i=L(t,`order`);if(i===0)throw Error(`Invalid notification order`);return{id:I(t,`id`),message:n,...W(`presentation`,Vn(t.presentation)),truncated:O(t,`truncated`),severity:zi(t.severity),receivedAt:r,order:i}}function Li(e){let t=w(e);return{order:L(t,`order`),overflowWatermark:L(t,`overflowWatermark`)}}function Ri(e){let t=w(e);switch(t.kind){case`added`:{let e=E(t,`evictedNotificationId`);return{kind:`added`,notification:Ii(t.notification),...e===void 0?{}:{evictedNotificationId:e}}}case`dismissed`:{let e=F(t.notificationIds,Hi,100,`notificationIds`);if(new Set(e).size!==e.length)throw Error(`Duplicate dismissed notification id`);return{kind:`dismissed`,notificationIds:e}}case`cleared`:return{kind:`cleared`,reason:Vi(t.reason)};case`resync`:return{kind:`resync`};default:throw Error(`Invalid notification inbox delta`)}}function zi(e){if(e!==`info`&&e!==`warning`&&e!==`error`)throw Error(`Invalid notification severity`);return e}function Bi(e){return e===void 0?void 0:zi(e)}function Vi(e){switch(e){case`runtime-close`:case`archive`:case`delete`:case`restore`:case`archive-reconcile`:case`replacement`:case`initialization-failed`:case`service-dispose`:return e;default:throw Error(`Invalid notification clear reason`)}}function F(e,t,n,r){if(!Array.isArray(e))throw Error(`Expected array field: ${r}`);if(e.length>n)throw Error(`Array field exceeds limit: ${r}`);return e.map(t)}function Hi(e){if(typeof e!=`string`||e===``)throw Error(`Expected non-empty string`);return e}function I(e,t){let n=T(e,t);if(n===``)throw Error(`Expected non-empty string field: ${t}`);return n}function L(e,t){let n=e[t];if(typeof n!=`number`||!Number.isSafeInteger(n)||n<0)throw Error(`Expected non-negative safe integer field: ${t}`);return n}function Ui(e){if(new Set(e.map(e=>e.id)).size!==e.length)throw Error(`Duplicate notification id`);if(new Set(e.map(e=>e.order)).size!==e.length)throw Error(`Duplicate notification order`)}function Wi(e){for(let t=1;t<e.length;t+=1){let n=e[t-1],r=e[t];if(n===void 0||r===void 0||n.order<=r.order)throw Error(`Notifications are not newest-first`)}}function Gi(e){return e.retainedCount===0&&e.discardedCount===0}function Ki(e){let t;for(let n of e){if(n.severity===`error`)return`error`;n.severity===`warning`?t=`warning`:t??=`info`}return t}function qi(e){let t=w(e),n=t.skippedBusySessionIds===void 0?void 0:A(t.skippedBusySessionIds,`skippedBusySessionIds`),r=t.skippedPinnedSessionIds===void 0?void 0:A(t.skippedPinnedSessionIds,`skippedPinnedSessionIds`);return{generatedAt:T(t,`generatedAt`),thresholds:Qi(t.thresholds),projects:k($i)(t.projects),totals:ea(t.totals),...n===void 0?{}:{skippedBusySessionIds:n},...r===void 0?{}:{skippedPinnedSessionIds:r}}}function Ji(e){let t=w(e);return{...qi(t),archivedSessionIds:A(t.archivedSessionIds,`archivedSessionIds`),deletedSessionIds:A(t.deletedSessionIds,`deletedSessionIds`)}}function Yi(e){let t=w(e);if(t.archived!==!0)throw Error(`Expected bulk archived response`);return{archived:!0,archivedSessionIds:A(t.archivedSessionIds,`archivedSessionIds`),failures:k(Zi)(t.failures),generatedAt:T(t,`generatedAt`)}}function Xi(e){let t=w(e);if(t.deleted!==!0)throw Error(`Expected bulk deleted response`);return{deleted:!0,deletedSessionIds:A(t.deletedSessionIds,`deletedSessionIds`),failures:k(Zi)(t.failures),generatedAt:T(t,`generatedAt`)}}function Zi(e){let t=w(e);return{sessionId:T(t,`sessionId`),error:T(t,`error`)}}function Qi(e){let t=w(e);return{...W(`archiveIdleDays`,U(t,`archiveIdleDays`)),...W(`deleteArchivedDays`,U(t,`deleteArchivedDays`))}}function $i(e){let t=w(e);return{cwd:T(t,`cwd`),archiveCount:D(t,`archiveCount`),deleteCount:D(t,`deleteCount`)}}function ea(e){let t=w(e);return{archiveCount:D(t,`archiveCount`),deleteCount:D(t,`deleteCount`)}}function ta(e){let t=w(e),n=T(t,`kind`);if(n!==`steer`&&n!==`followUp`)throw Error(`Invalid queued message kind`);return{kind:n,text:T(t,`text`),...W(`hasAttachments`,H(t,`hasAttachments`)),...W(`attachmentCount`,t.attachmentCount===void 0?void 0:L(t,`attachmentCount`))}}function na(e){let t=w(e);return{input:D(t,`input`),output:D(t,`output`),cacheRead:D(t,`cacheRead`),cacheWrite:D(t,`cacheWrite`),total:D(t,`total`)}}function ra(e){let t=w(e);return{...W(`provider`,E(t,`provider`)),...W(`id`,E(t,`id`)),...W(`name`,E(t,`name`)),...W(`contextWindow`,U(t,`contextWindow`)),...W(`reasoning`,t.reasoning)}}function ia(e){return e===void 0?{}:{model:ra(e)}}function aa(e){let t=w(e);return{models:k(ra)(t.models)}}function oa(e){let t=w(e);return{provider:T(t,`provider`),id:T(t,`id`),...W(`name`,E(t,`name`)),...W(`contextWindow`,U(t,`contextWindow`)),...W(`reasoning`,t.reasoning),enabled:O(t,`enabled`),...W(`editable`,H(t,`editable`)),...W(`catalogIndex`,t.catalogIndex===void 0?void 0:L(t,`catalogIndex`))}}function sa(e){let t=w(e);return{models:k(oa)(t.models)}}function ca(e){if(typeof e!=`string`)throw Error(`Invalid thinking level`);return e}function la(e){let t=w(e);return{levels:k(ca)(t.levels)}}function ua(e){if(e!==`oauth`&&e!==`api_key`)throw Error(`Invalid auth type`);return e}function da(e){if(e!==`stored`&&e!==`runtime`&&e!==`environment`&&e!==`fallback`&&e!==`models_json_key`&&e!==`models_json_command`)throw Error(`Invalid auth status source`);return e}function fa(e){let t=w(e),n=t.source===void 0?void 0:da(t.source);return{configured:O(t,`configured`),...W(`source`,n),...W(`label`,E(t,`label`))}}function pa(e){let t=w(e),n=t.loginFlow;if(n!==void 0&&n!==`interactive`)throw Error(`Invalid auth provider login flow`);return{id:T(t,`id`),name:T(t,`name`),authType:ua(t.authType),status:fa(t.status),...n===void 0?{}:{loginFlow:n}}}function ma(e){let t=w(e);return{providers:k(pa)(t.providers)}}function ha(e){let t=w(e);return{servers:k(e=>{let t=w(e);return{name:T(t,`name`),...W(`description`,E(t,`description`))}})(t.servers)}}function R(e){let t=w(e),n=t.target;if(n!==void 0&&n!==`mcp`)throw Error(`Invalid login flow target`);let r=t.mcpMode;if(r!==void 0&&r!==`login`&&r!==`logout`)throw Error(`Invalid MCP authentication mode`);let i={flowId:T(t,`flowId`),providerId:T(t,`providerId`),providerName:T(t,`providerName`),...n===void 0?{}:{target:n},...r===void 0?{}:{mcpMode:r},...W(`cancelRequested`,H(t,`cancelRequested`)),status:ga(t.status),progress:k(e=>{if(typeof e!=`string`)throw Error(`Expected progress item string`);return e})(t.progress),...W(`error`,E(t,`error`)),...W(`auth`,_a(t.auth)),...W(`prompt`,ya(t.prompt)),...W(`select`,xa(t.select)),...W(`info`,Sa(t.info))};if(i.target===`mcp`&&i.auth!==void 0){let e=new URL(i.auth.url);if(e.protocol!==`https:`&&e.protocol!==`http:`)throw Error(`Invalid MCP authorization URL`)}return i}function ga(e){if(e!==`running`&&e!==`complete`&&e!==`error`&&e!==`cancelled`)throw Error(`Invalid OAuth flow status`);return e}function _a(e){if(e===void 0)return;let t=w(e);return{url:T(t,`url`),...W(`instructions`,E(t,`instructions`)),...W(`deviceCode`,va(t.deviceCode))}}function va(e){if(e===void 0)return;let t=w(e);return{userCode:T(t,`userCode`),...W(`intervalSeconds`,U(t,`intervalSeconds`)),...W(`expiresInSeconds`,U(t,`expiresInSeconds`))}}function ya(e){if(e===void 0)return;let t=w(e),n=E(t,`kind`);if(n!==void 0&&n!==`prompt`&&n!==`manual`)throw Error(`Invalid OAuth prompt kind`);let r=t.promptType===void 0&&n!==void 0?n===`manual`?`manual_code`:`text`:ba(t.promptType);return{requestId:T(t,`requestId`),message:T(t,`message`),...W(`kind`,n),promptType:r,...W(`placeholder`,E(t,`placeholder`)),...W(`allowEmpty`,H(t,`allowEmpty`))}}function ba(e){if(e!==`text`&&e!==`secret`&&e!==`manual_code`)throw Error(`Invalid OAuth prompt type`);return e}function xa(e){if(e===void 0)return;let t=w(e);return{requestId:T(t,`requestId`),message:T(t,`message`),options:k(Wo)(t.options)}}function Sa(e){if(e!==void 0)return k(e=>{let t=w(e);return{message:T(t,`message`),...W(`links`,t.links===void 0?void 0:k(Ca)(t.links))}})(e)}function Ca(e){let t=w(e);return{url:T(t,`url`),...W(`label`,E(t,`label`))}}function wa(e){if(e===void 0)return{};let t=w(e);return{contextUsage:{tokens:ns(t,`tokens`),contextWindow:D(t,`contextWindow`),percent:ns(t,`percent`)}}}function Ta(e){let t=w(e),n=T(t,`source`);if(n!==`extension`&&n!==`prompt`&&n!==`skill`&&n!==`builtin`)throw Error(`Invalid command source`);return{name:T(t,`name`),source:n,...W(`description`,E(t,`description`)),...W(`argumentHint`,E(t,`argumentHint`))}}function Ea(e){let t=w(e),n=T(t,`kind`);if(n!==`tracked`&&n!==`untracked`&&n!==`other`)throw Error(`Invalid file kind`);return{path:T(t,`path`),kind:n}}function Da(e){let t=w(e);return{path:T(t,`path`),entries:k(Aa)(t.entries),scannedAt:T(t,`scannedAt`),truncated:O(t,`truncated`)}}function Oa(e){let t=w(e);return{results:k(ka)(t.results)}}function ka(e){let t=w(e),n=T(t,`path`),r=t.tree,i=t.error;if(r===void 0==(i===void 0))throw Error(`File tree batch result must contain exactly one of tree or error`);return r===void 0?{path:n,error:T(t,`error`)}:{path:n,tree:Da(r)}}function Aa(e){let t=w(e),n=T(t,`type`);if(n!==`file`&&n!==`directory`&&n!==`symlink`)throw Error(`Invalid file tree entry type`);return{name:T(t,`name`),path:T(t,`path`),type:n,...W(`size`,U(t,`size`)),...W(`modifiedAt`,E(t,`modifiedAt`))}}function ja(e){let t=w(e),n=T(t,`encoding`);if(n!==`utf8`)throw Error(`Invalid file encoding`);return{path:T(t,`path`),...W(`language`,E(t,`language`)),...W(`mediaType`,Fa(t.mediaType)),...W(`mimeType`,E(t,`mimeType`)),encoding:n,size:D(t,`size`),modifiedAt:T(t,`modifiedAt`),content:T(t,`content`),truncated:O(t,`truncated`),binary:O(t,`binary`)}}function Ma(e){let t=w(e);return{path:T(t,`path`),size:D(t,`size`),modifiedAt:T(t,`modifiedAt`),created:O(t,`created`)}}function Na(e){let t=w(e);return{path:T(t,`path`),existed:O(t,`existed`)}}function Pa(e){let t=w(e);return{fromPath:T(t,`fromPath`),toPath:T(t,`toPath`),size:D(t,`size`),modifiedAt:T(t,`modifiedAt`)}}function Fa(e){if(e!==void 0){if(e!==`image`&&e!==`html`&&e!==`pdf`&&e!==`markdown`)throw Error(`Invalid file media type`);return e}}function Ia(e){let t=w(e);return{id:T(t,`id`),cwd:T(t,`cwd`),name:T(t,`name`),createdAt:T(t,`createdAt`),exited:O(t,`exited`),...W(`exitCode`,U(t,`exitCode`)),...W(`commandRunId`,E(t,`commandRunId`))}}function z(e){let t=w(e);return{id:T(t,`id`),origin:T(t,`origin`),projectId:T(t,`projectId`),workspaceId:T(t,`workspaceId`),terminalId:T(t,`terminalId`),title:T(t,`title`),command:T(t,`command`),status:La(t.status),...W(`exitCode`,U(t,`exitCode`)),createdAt:T(t,`createdAt`),...W(`startedAt`,E(t,`startedAt`)),...W(`completedAt`,E(t,`completedAt`)),metadata:Ra(t.metadata,`metadata`)}}function La(e){if(e!==`queued`&&e!==`running`&&e!==`succeeded`&&e!==`failed`)throw Error(`Invalid terminal command run status`);return e}function Ra(e,t){let n=w(e);return Object.fromEntries(Object.entries(n).map(([e,n])=>{if(typeof n!=`string`)throw Error(`Expected string record field: ${t}.${e}`);return[e,n]}))}function za(e){let t=w(e);return{cwd:T(t,`cwd`),hasSessionActivity:O(t,`hasSessionActivity`),hasTerminalActivity:O(t,`hasTerminalActivity`),updatedAt:T(t,`updatedAt`)}}function Ba(e){let t=w(e);return{workspaces:k(za)(t.workspaces),generatedAt:T(t,`generatedAt`)}}function Va(e){let t=ar(e);if(t===void 0)throw Error(`Expected machine status snapshot`);return t}function Ha(e){let t=w(e);return{path:T(t,`path`),exists:O(t,`exists`),config:Wa(t.config),effectiveConfig:Wa(t.effectiveConfig),envOverrides:to(t.envOverrides),...W(`enforcedSettings`,Ua(t.enforcedSettings)),...W(`configSources`,Ua(t.configSources)),...W(`defaultsConfig`,t.defaultsConfig===void 0?void 0:Wa(t.defaultsConfig)),...W(`defaultsPath`,E(t,`defaultsPath`))}}function Ua(e){if(e===void 0)return;let t=w(e);return Object.fromEntries(Object.entries(t).map(([e,t])=>{if(typeof t!=`string`)throw Error(`Invalid configuration source for ${e}`);return[e,t]}))}function Wa(e){let t=w(e);if(Object.hasOwn(t,`sessionNaming`))throw Error(`Retired PI WEB sessionNaming config field`);return{...W(`host`,E(t,`host`)),...W(`port`,U(t,`port`)),...W(`installationName`,t.installationName===void 0?void 0:sn(t.installationName)),...W(`allowedHosts`,Ka(t.allowedHosts)),...W(`shortcuts`,$a(t.shortcuts)),...W(`defaultTheme`,t.defaultTheme===void 0?void 0:l(t.defaultTheme,`response`)),...W(`defaultStreamingBehavior`,t.defaultStreamingBehavior===void 0?void 0:nn(t.defaultStreamingBehavior,`response`)),...W(`defaultLocalization`,t.defaultLocalization===void 0?void 0:an(t.defaultLocalization,`response`)),...W(`quietMode`,H(t,`quietMode`)),...W(`plugins`,eo(t.plugins)),...W(`basePaths`,Ja(t.basePaths,`basePaths`)),...W(`pathAccess`,qa(t.pathAccess)),...W(`uploads`,Ya(t.uploads)),...W(`attachments`,Xa(t.attachments)),...W(`maxUploadBytes`,U(t,`maxUploadBytes`)),...W(`agent`,Ga(t.agent)),...W(`spawnSessions`,H(t,`spawnSessions`)),...W(`subsessions`,H(t,`subsessions`)),...W(`sessionMessages`,H(t,`sessionMessages`)),...W(`askUser`,H(t,`askUser`)),...W(`environmentFacts`,H(t,`environmentFacts`)),...W(`extensionDialogsTimeoutMs`,U(t,`extensionDialogsTimeoutMs`)),...W(`sessionArchive`,t.sessionArchive===void 0?void 0:vn(t.sessionArchive,`response`))}}function Ga(e){if(e!==void 0){if(!C(e)||Array.isArray(e))throw Error(`Invalid PI WEB agent field`);return{...W(`command`,E(e,`command`)),...W(`dir`,E(e,`dir`))}}}function Ka(e){if(e!==void 0){if(e===!0)return!0;if(Za(e))return e;throw Error(`Invalid PI WEB allowedHosts field`)}}function qa(e){if(e===void 0)return;if(!C(e))throw Error(`Invalid PI WEB pathAccess field`);let t=e.allowedPaths;return{...W(`allowedPaths`,Ja(t,`pathAccess.allowedPaths`))}}function Ja(e,t){if(e!==void 0){if(Qa(e))return e;throw Error(`Invalid PI WEB ${t} field`)}}function Ya(e){if(e!==void 0){if(!C(e)||Array.isArray(e))throw Error(`Invalid PI WEB uploads field`);return{...W(`defaultFolder`,E(e,`defaultFolder`))}}}function Xa(e){if(e!==void 0){if(!C(e)||Array.isArray(e))throw Error(`Invalid PI WEB attachments field`);return{...W(`defaultFolder`,E(e,`defaultFolder`))}}}function Za(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function Qa(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`&&e!==``)}function $a(e){if(e!==void 0){if(!C(e)||Array.isArray(e))throw Error(`Invalid PI WEB shortcuts field`);return Object.fromEntries(Object.entries(e).map(([e,t])=>{if(t!==null&&(typeof t!=`string`||t===``))throw Error(`Invalid PI WEB shortcut field`);return[e,t]}))}}function eo(e){if(e!==void 0){if(!C(e)||Array.isArray(e))throw Error(`Invalid PI WEB plugins field`);return Object.fromEntries(Object.entries(e).map(([e,t])=>{if(!C(t)||Array.isArray(t))throw Error(`Invalid PI WEB plugin config field`);let n=t.enabled;if(n!==void 0&&typeof n!=`boolean`)throw Error(`Invalid PI WEB plugin enabled field`);let r=t.settings;if(r!==void 0&&(!C(r)||Array.isArray(r)))throw Error(`Invalid PI WEB plugin settings field`);return[e,t]}))}}function to(e){let t=w(e);return{host:O(t,`host`),port:O(t,`port`),allowedHosts:O(t,`allowedHosts`),spawnSessions:O(t,`spawnSessions`),subsessions:O(t,`subsessions`),sessionMessages:H(t,`sessionMessages`)??!1,askUser:O(t,`askUser`),agentCommand:H(t,`agentCommand`)??!1,agentDir:H(t,`agentDir`)??!1,...no(t),agentSessionDir:H(t,`agentSessionDir`)??!1}}function no(e){let t=e.agentDirSource;if(t===void 0)return{};if(t!==`pi-web`&&t!==`pi-compatibility`)throw Error(`Invalid PI WEB agentDirSource field`);return{agentDirSource:t}}function ro(e){let t=w(e);return{packages:k(ao)(t.packages),...W(`installableKnownPackages`,oo(t.installableKnownPackages))}}function io(e){let t=w(e),n=E(t,`source`),r=t.scope===void 0?void 0:co(t.scope),i=B(t.removed,`removed`);return{action:lo(t.action),...W(`source`,n),...W(`scope`,r),...W(`removed`,i),packages:k(ao)(t.packages),...W(`installableKnownPackages`,oo(t.installableKnownPackages))}}function ao(e){let t=w(e);return{source:T(t,`source`),scope:co(t.scope),filtered:O(t,`filtered`),...W(`installedPath`,E(t,`installedPath`))}}function oo(e){return e===void 0?void 0:k(so)(e)}function so(e){let t=w(e);return{id:T(t,`id`),label:T(t,`label`),description:T(t,`description`),source:T(t,`source`)}}function co(e){if(e!==`user`&&e!==`project`)throw Error(`Invalid Pi package scope`);return e}function lo(e){if(e!==`install`&&e!==`remove`&&e!==`update`)throw Error(`Invalid Pi package mutation action`);return e}function uo(e){let t=w(e),n=k(fo)(t.plugins);if(t.lifecycleVersion===void 0)return{lifecycleVersion:2,plugins:n,diagnostics:[],serverRuntime:{status:`incompatible`,terminalMode:`required`,restartRequired:!1,message:v(`ui.main.fe09b19a1f40`,`PI WEB does not support plugin lifecycle diagnostics. Update and restart PI WEB, then try again.`),recovery:vo()}};if(t.lifecycleVersion!==2)throw Error(`Unsupported PI WEB plugin lifecycle version`);return{lifecycleVersion:2,plugins:n,diagnostics:k(ho)(t.diagnostics),serverRuntime:go(t.serverRuntime)}}function fo(e){let t=w(e),n=T(t,`id`),r=t.server===void 0?void 0:po(t.server,n),i=E(t,`backendRevision`),a=yo(t.pairedRequestVersion),o=yo(t.pairedChannelVersion);if((a!==void 0||o!==void 0)&&i===void 0)throw Error(`Invalid PI WEB plugin paired capability`);let s=B(t.required,`required`);if(s===!1)throw Error(`Invalid PI WEB required plugin marker`);return{id:n,...s===!0?{required:!0}:{},...W(`module`,E(t,`module`)),...i===void 0?{}:{backendRevision:i},...a===void 0?{}:{pairedRequestVersion:a},...o===void 0?{}:{pairedChannelVersion:o},source:T(t,`source`),scope:bo(t.scope),machineSpecific:B(t.machineSpecific,`machineSpecific`)??!1,enabled:O(t,`enabled`),discovered:B(t.discovered,`discovered`)??!0,conflict:B(t.conflict,`conflict`)??!1,...r===void 0?{}:{server:r}}}function po(e,t){let n=w(e),r=n.state,i=n.phase;if(r!==`active`&&r!==`failed`&&r!==`incompatible`&&r!==`disabled`&&r!==`missing`&&r!==`unknown`)throw Error(`Invalid PI WEB server plugin state`);if(i!==void 0&&i!==`import`&&i!==`activate`&&i!==`validate`&&i!==`start`&&i!==`health`&&i!==`dispose`)throw Error(`Invalid PI WEB server plugin phase`);let a=n.health===void 0?void 0:mo(n.health),o=T(n,`disableCommand`);if(o!==fr(t))throw Error(`Invalid PI WEB server plugin recovery command`);return{state:r,...W(`desiredRevision`,E(n,`desiredRevision`)),...W(`activeRevision`,E(n,`activeRevision`)),...i===void 0?{}:{phase:i},...W(`message`,E(n,`message`)),...a===void 0?{}:{health:a},staleRevision:O(n,`staleRevision`),restartRequired:O(n,`restartRequired`),disableCommand:o}}function mo(e){let t=w(e),n=t.status;if(n!==`healthy`&&n!==`degraded`&&n!==`unhealthy`)throw Error(`Invalid PI WEB server plugin health status`);return{status:n,...W(`message`,E(t,`message`))}}function ho(e){let t=w(e),n=t.kind,r=t.snapshot;if(n!==`conflict`&&n!==`discovery`)throw Error(`Invalid PI WEB plugin diagnostic kind`);if(r!==`desired`&&r!==`active`)throw Error(`Invalid PI WEB plugin diagnostic snapshot`);return{kind:n,snapshot:r,source:T(t,`source`),message:T(t,`message`),...W(`pluginId`,E(t,`pluginId`))}}function go(e){let t=w(e),n=t.status,r=t.terminalMode,i=t.safeStart,a=t.desiredSafeStart;if(n!==`available`&&n!==`unavailable`&&n!==`incompatible`)throw Error(`Invalid PI WEB server-plugin runtime status`);if(r!==`required`&&r!==`recovery-disabled`)throw Error(`Invalid PI WEB Terminal plugin mode`);if(i!==void 0&&i!==`bundled-only`&&i!==`none`)throw Error(`Invalid PI WEB server-plugin safe-start state`);if(a!==void 0&&a!==`off`&&a!==`bundled-only`&&a!==`none`)throw Error(`Invalid desired PI WEB server-plugin safe-start state`);if(n!==`available`&&r===`recovery-disabled`)throw Error(`Unavailable PI WEB runtime cannot declare Terminal recovery mode`);if(i===`none`!=(r===`recovery-disabled`)&&n===`available`)throw Error(`PI WEB Terminal plugin mode does not match safe start`);return{status:n,terminalMode:r,...i===void 0?{}:{safeStart:i},...a===void 0?{}:{desiredSafeStart:a},restartRequired:O(t,`restartRequired`),...W(`message`,E(t,`message`)),recovery:_o(t.recovery)}}function _o(e){let t=w(e),n={showSafeStart:T(t,`showSafeStart`),bundledOnly:T(t,`bundledOnly`),noServerPlugins:T(t,`noServerPlugins`),clearSafeStart:T(t,`clearSafeStart`)};if(n.showSafeStart!==S.showSafeStart||n.bundledOnly!==S.bundledOnly||n.noServerPlugins!==S.noServerPlugins||n.clearSafeStart!==S.clearSafeStart)throw Error(`Invalid PI WEB server plugin recovery commands`);return n}function vo(){return{...S}}function yo(e){if(e!==void 0){if(e!==1)throw Error(`Invalid PI WEB plugin paired capability version`);return 1}}function bo(e){if(e!==`bundled`&&e!==`local`&&e!==`user`&&e!==`project`)throw Error(`Invalid PI WEB plugin scope`);return e}function B(e,t){if(e!==void 0){if(typeof e!=`boolean`)throw Error(`Expected optional boolean field: ${t}`);return e}}function xo(e){let t=w(e);return{packageName:T(t,`packageName`),generatedAt:T(t,`generatedAt`),components:Co(t.components),release:Oo(t.release),commands:ko(t.commands),messages:k(Ao)(t.messages)}}function So(e){let t=w(e);return{packageName:T(t,`packageName`),generatedAt:T(t,`generatedAt`),components:wo(t.components),capabilities:Mo(t.capabilities)}}function Co(e){let t=w(e);return{web:Eo(t.web),sessiond:Eo(t.sessiond)}}function wo(e){let t=w(e);return{web:To(t.web),sessiond:To(t.sessiond)}}function To(e){let t=w(e),n=jo(t.component),r=t.activeAgentProfile,i=r===void 0?void 0:An(r);if(r!==void 0&&(n!==`sessiond`||i===void 0))throw Error(`Invalid active agent profile descriptor`);return{component:n,label:T(t,`label`),...W(`runtimeVersion`,E(t,`runtimeVersion`)),...W(`piVersion`,E(t,`piVersion`)),available:O(t,`available`),capabilities:Mo(t.capabilities),...W(`activeAgentProfile`,i),...W(`deprecatedAgentInputs`,Qn(t.deprecatedAgentInputs)),...W(`error`,E(t,`error`))}}function Eo(e){let t=w(e);return{component:jo(t.component),label:T(t,`label`),...W(`runtimeVersion`,E(t,`runtimeVersion`)),...W(`installedVersion`,E(t,`installedVersion`)),...W(`piVersion`,E(t,`piVersion`)),stale:O(t,`stale`),available:O(t,`available`),...W(`installation`,Do(t.installation)),...W(`error`,E(t,`error`))}}function Do(e){if(e===void 0)return;let t=w(e),n=T(t,`kind`);if(n!==`pi-package`&&n!==`npm-global`&&n!==`local`&&n!==`docker`&&n!==`unknown`)throw Error(`Invalid PI WEB installation kind`);let r=t.scope;if(r!==void 0&&r!==`user`&&r!==`project`)throw Error(`Invalid PI WEB installation scope`);let i=t.dockerMode;if(i!==void 0&&i!==`runtime`&&i!==`dev`)throw Error(`Invalid PI WEB Docker mode`);return{kind:n,...W(`path`,E(t,`path`)),...W(`source`,E(t,`source`)),...r===void 0?{}:{scope:r},...W(`npmRoot`,E(t,`npmRoot`)),...i===void 0?{}:{dockerMode:i}}}function Oo(e){let t=w(e);return{packageName:T(t,`packageName`),...W(`latestVersion`,E(t,`latestVersion`)),updateAvailable:O(t,`updateAvailable`),...W(`checkedAt`,E(t,`checkedAt`)),...t.skipped===!0?{skipped:!0}:{},...W(`error`,E(t,`error`))}}function ko(e){let t=w(e);return{...W(`update`,E(t,`update`)),...W(`restart`,E(t,`restart`)),...W(`restartWeb`,E(t,`restartWeb`)),...W(`restartSessiond`,E(t,`restartSessiond`)),...W(`status`,E(t,`status`))}}function Ao(e){let t=w(e);return{id:T(t,`id`),severity:No(t.severity),title:T(t,`title`),body:T(t,`body`),...W(`command`,E(t,`command`))}}function jo(e){if(e!==`web`&&e!==`sessiond`)throw Error(`Invalid PI WEB service component`);return e}function Mo(e){let t=Zn(e);if(t===void 0)throw Error(`Invalid PI WEB capabilities`);return t}function No(e){if(e!==`info`&&e!==`warning`&&e!==`error`)throw Error(`Invalid PI WEB status severity`);return e}function Po(e){let t=w(e),n=T(t,`type`);if(n===`unsupported`)return{type:n,...W(`presentation`,Ln(t.presentation)),message:T(t,`message`)};if(n===`select`)return{type:n,...W(`presentation`,Ln(t.presentation)),requestId:T(t,`requestId`),title:T(t,`title`),options:k(Wo)(t.options)};if(n===`tree`)return{type:n,tree:Fo(t.tree)};if(n===`done`)return{type:n,...W(`presentation`,Ln(t.presentation)),...W(`message`,E(t,`message`)),...Go(t.session),...W(`promptDraft`,E(t,`promptDraft`))};throw Error(`Invalid command result type`)}function Fo(e){let t=w(e),n=k(Io)(t.nodes),r=new Set(n.map(e=>e.id));if(r.size!==n.length)throw Error(`Duplicate session tree node id`);let i=Vo(t,`activeLeafId`);if(i!==null&&!r.has(i))throw Error(`Invalid session tree activeLeafId`);return{nodes:n,activeLeafId:i,activePathIds:Uo(t.activePathIds,`activePathIds`)}}function Io(e){let t=w(e);return{id:Ho(t,`id`),parentId:Vo(t,`parentId`),kind:Lo(t.kind),summary:T(t,`summary`),...W(`summaryPresentation`,Kn(t.summaryPresentation)),...W(`timestamp`,E(t,`timestamp`)),...W(`label`,E(t,`label`))}}function Lo(e){switch(e){case`user`:case`assistant`:case`tool-result`:case`bash`:case`custom-message`:case`compaction`:case`branch-summary`:case`model-change`:case`thinking-level-change`:case`session-info`:case`label`:case`custom`:case`other`:return e;default:throw Error(`Invalid session tree node kind`)}}function Ro(e){let t=w(e),n=O(t,`cancelled`);if(Object.hasOwn(t,`summaryEntry`))throw Error(`Invalid session tree navigation result field: summaryEntry`);if(n){Bo(t,`editorText`,`session tree cancellation result`);let e=t.aborted;if(e!==void 0&&typeof e!=`boolean`)throw Error(`Expected optional boolean field: aborted`);return{cancelled:n,...e===void 0?{}:{aborted:e}}}return Bo(t,`aborted`,`session tree navigation result`),{cancelled:n,...W(`editorText`,E(t,`editorText`))}}function zo(e){let t=w(e),n=O(t,`cancelled`);return n?(Bo(t,`session`,`session tree fork cancellation result`),Bo(t,`promptDraft`,`session tree fork cancellation result`),{cancelled:n}):{cancelled:n,session:j(t.session),...W(`promptDraft`,E(t,`promptDraft`))}}function Bo(e,t,n){if(Object.hasOwn(e,t))throw Error(`Invalid ${n} field: ${t}`)}function Vo(e,t){let n=e[t];if(n!==null&&typeof n!=`string`)throw Error(`Expected string or null field: ${t}`);if(typeof n==`string`&&n.trim()===``)throw Error(`Expected non-blank string or null field: ${t}`);return n}function Ho(e,t){let n=T(e,t);if(n.trim()===``)throw Error(`Expected non-blank string field: ${t}`);return n}function Uo(e,t){let n=A(e,t);if(n.some(e=>e.trim()===``))throw Error(`Expected non-blank string array field: ${t}`);return n}function Wo(e){let t=w(e);return{value:T(t,`value`),label:T(t,`label`),...W(`description`,E(t,`description`))}}function Go(e){return e===void 0?{}:{session:j(e)}}function V(e){if(w(e).accepted!==!0)throw Error(`Expected accepted response`);return{accepted:!0}}function Ko(e){let t=w(e);return k(qo)(t.attachments)}function qo(e){let t=w(e);return{path:T(t,`path`),mimeType:T(t,`mimeType`),size:D(t,`size`)}}function Jo(e){if(w(e).closed!==!0)throw Error(`Expected closed response`);return{closed:!0}}function Yo(e){if(w(e).aborted!==!0)throw Error(`Expected aborted response`);return{aborted:!0}}function Xo(e){if(w(e).stopped!==!0)throw Error(`Expected stopped response`);return{stopped:!0}}function Zo(e){let t=w(e);if(t.archived!==!0)throw Error(`Expected archived response`);let n=t.sessionIds===void 0?void 0:A(t.sessionIds,`sessionIds`),r=U(t,`archivedCount`),i=U(t,`skippedAlreadyArchivedCount`);return{archived:!0,...n===void 0?{}:{sessionIds:n},...r===void 0?{}:{archivedCount:r},...i===void 0?{}:{skippedAlreadyArchivedCount:i}}}function Qo(e){if(w(e).restored!==!0)throw Error(`Expected restored response`);return{restored:!0}}function $o(e){if(w(e).deleted!==!0)throw Error(`Expected deleted response`);return{deleted:!0}}function es(e){if(w(e).detached!==!0)throw Error(`Expected detached response`);return{detached:!0}}function ts(e){if(w(e).reloaded!==!0)throw Error(`Expected reloaded response`);return{reloaded:!0}}function H(e,t){let n=e[t];if(n!==void 0){if(typeof n!=`boolean`)throw Error(`Invalid PI WEB ${t} field`);return n}}function U(e,t){let n=e[t];if(n!==void 0){if(typeof n!=`number`)throw Error(`Expected optional number field: ${t}`);return n}}function ns(e,t){let n=e[t];if(n===null)return null;if(typeof n!=`number`)throw Error(`Expected number|null field: ${t}`);return n}function W(e,t){return t===void 0?{}:{[e]:t}}function rs(e){let t=w(e),n=t.decision;if(n!==!0&&n!==!1&&n!==null)throw Error(`Invalid workspace trust decision`);return{path:T(t,`path`),decision:n,trusted:O(t,`trusted`)}}function is(e,t){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0&&typeof t==`number`&&Number.isSafeInteger(t)&&t>0?{width:e,height:t}:void 0}var as=`reference`;function os(e){return typeof e==`string`&&/^[0-9a-f]{64}$/u.test(e)}function ss(e,t,n,r){let i=new URLSearchParams({cwd:e.cwd});return n?.limit!==void 0&&i.set(`limit`,String(n.limit)),n?.before!==void 0&&i.set(`before`,String(n.before)),i.set(`media`,as),`api/machines/${encodeURIComponent(r)}/sessions/${encodeURIComponent(e.id)}/${t}?${i.toString()}`}function cs(e,t,n=`local`){return ss(e,`messages`,t,n)}function ls(e,t,n=`local`){return ss(e,`transcript-snapshot`,t,n)}function us(e,t=`local`){return ss(e,`stream-snapshot`,void 0,t)}function ds(e,t=`local`){return ss(e,`events`,void 0,t)}function fs(t,n,r=`local`){let i=new URLSearchParams({cwd:t.cwd}),a=`api/machines/${encodeURIComponent(r)}/sessions/${encodeURIComponent(t.id)}/media/${encodeURIComponent(n)}?${i.toString()}`,o=c(a);return new URL(e(o),o).href}function ps(t,n,r,i){let a=new URLSearchParams({path:r});i?.createDirs===!1&&a.set(`createDirs`,`false`),i?.overwrite===!1&&a.set(`overwrite`,`false`);let o=`api/machines/${encodeURIComponent(i?.machineId??`local`)}`;return c(e(`${o}/projects/${encodeURIComponent(t)}/workspaces/${encodeURIComponent(n)}/file?${a.toString()}`))}function ms(t,n,r,i){let a=new URLSearchParams;a.set(`path`,r),i?.modifiedAt!==void 0&&a.set(`v`,i.modifiedAt),i?.download===!0&&a.set(`download`,`1`);let o=`api/machines/${encodeURIComponent(i?.machineId??`local`)}`;return e(`${o}/projects/${encodeURIComponent(t)}/workspaces/${encodeURIComponent(n)}/file/preview?${a.toString()}`)}function hs(e,t,n,r){return c(ms(e,t,n,r))}function gs(e,t,n,r){return hs(e,t,n,{...r,download:!0})}var G=(e=`local`)=>`api/machines/${encodeURIComponent(e)}`,_s={projectTrust:(e,t=`local`)=>a(`${G(t)}/projects/trust?${new URLSearchParams({path:e})}`,rs),workspaceTrust:(e,t,n=`local`)=>a(`${G(n)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/trust`,rs),setWorkspaceTrust:(e,t,n,r=`local`)=>a(`${G(r)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/trust`,rs,{method:`PUT`,body:JSON.stringify({trusted:n})})};function vs(e,t=`local`){return`${G(t)}/sessions/${encodeURIComponent(e.id)}`}function K(e,t,n=`local`){return`${vs(e,n)}/${t}`}function q(e,t,n=`local`){return`${K(e,t,n)}${bs(e)}`}function ys(e,t=`local`,n){return`${vs(e,t)}${bs(e,n===void 0?{}:{scopeProjectId:n})}`}function bs(e,t={}){return`?${new URLSearchParams({cwd:e.cwd,...t}).toString()}`}function J(e,t={}){return JSON.stringify({cwd:e.cwd,...t})}function xs(e,t){let n={sessions:e.map(({id:e,cwd:t})=>({id:e,cwd:t})),...t===void 0?{}:{scopeProjectId:t}};return JSON.stringify(n)}function Y(e,t){let n=new URLSearchParams;t.projectId!==void 0&&n.set(`projectId`,t.projectId);let r=n.toString();return`${G(t.machineId)}/auth/${e}${r===``?``:`?${r}`}`}function Ss(e){return e===`local`?`api/pi-web/status`:`${G(e)}/pi-web/status`}var Cs={piWebStatus:(e=`local`)=>a(Ss(e),xo),checkForUpdates:(e=`local`)=>a(`${Ss(e)}?refresh=1`,xo,{cache:`no-store`}),piWebRuntime:()=>a(`api/pi-web/runtime`,So)},ws={machines:()=>a(`api/machines`,hr),machine:e=>a(`api/machines/${encodeURIComponent(e)}`,gr),addMachine:e=>a(`api/machines`,gr,{method:`POST`,body:JSON.stringify(e)}),updateMachine:(e,t)=>a(`api/machines/${encodeURIComponent(e)}`,gr,{method:`PATCH`,body:JSON.stringify(t)}),deleteMachine:e=>a(`api/machines/${encodeURIComponent(e)}`,e=>e,{method:`DELETE`}),health:e=>a(`api/machines/${encodeURIComponent(e)}/health`,_r),runtime:(e,t=!1)=>a(`api/machines/${encodeURIComponent(e)}/runtime${t?`?refresh=1`:``}`,vr,t?{cache:`no-store`}:{})};function Ts(e){return e===void 0?`api/config`:`${G(e)}/config`}function Es(e){return e===void 0?`api/plugins`:`${G(e)}/plugins`}var Ds={namingModels:e=>{let t=new URLSearchParams;e.projectId!==void 0&&t.set(`projectId`,e.projectId);let n=t.toString();return a(`${G(e.machineId)}/models${n===``?``:`?${n}`}`,aa)},config:e=>a(Ts(e),Ha),updateConfig:(e,t)=>a(Ts(t),Ha,{method:`PATCH`,body:JSON.stringify(e)}),saveConfig:(e,t)=>a(Ts(t),Ha,{method:`PUT`,body:JSON.stringify({config:e})})},Os={status:()=>a(`api/normal-auth/status`,Fr),setup:e=>a(`api/normal-auth/setup`,V,{method:`POST`,body:JSON.stringify({password:e})}),login:e=>a(`api/normal-auth/login`,V,{method:`POST`,body:JSON.stringify({password:e})}),changePassword:(e,t)=>a(`api/normal-auth/change-password`,V,{method:`POST`,body:JSON.stringify({currentPassword:e,newPassword:t})})},ks={plugins:e=>a(Es(e),uo)};function As(e=``,t){let n=t===void 0?`api/pi-packages`:`${G(t)}/pi-packages`;return e===``?n:`${n}/${e}`}var js={packages:e=>a(As(``,e),ro),install:(e,t)=>{let n={source:e};return a(As(`install`,t),io,{method:`POST`,body:JSON.stringify(n)})},remove:(e,t,n)=>{let r=t===void 0?{source:e}:{source:e,scope:t};return a(As(`remove`,n),io,{method:`POST`,body:JSON.stringify(r)})},update:(e,t)=>{let n=e===void 0?void 0:{source:e};return a(As(`update`,t),io,{method:`POST`,...n===void 0?{}:{body:JSON.stringify(n)}})}},Ms={workspaceActivity:(e=`local`)=>a(`${G(e)}/activity`,Ba)},Ns={machineStatus:(e=`local`)=>a(`${G(e)}/status`,Va)},Ps={snapshot:(e=`local`)=>a(`${G(e)}/notices`,ji,{cache:`no-store`}),dismiss:(e,t,n)=>{let r={daemonInstanceId:t,noticeId:n};return a(`${G(e)}/notices/dismiss`,ji,{method:`POST`,body:JSON.stringify(r)})}},Fs={projects:(e=`local`)=>a(`${G(e)}/projects`,k(Sr)),addProject:(e,t,n,r=`local`)=>a(`${G(r)}/projects`,Sr,{method:`POST`,body:JSON.stringify({path:e,name:t,create:n})}),closeProject:(e,t=`local`)=>a(`${G(t)}/projects/${encodeURIComponent(e)}`,Jo,{method:`DELETE`}),projectDirectories:(e,t=`local`)=>a(`${G(t)}/project-directories?q=${encodeURIComponent(e)}`,k(Ea))};function Is(e,t,n,r,i,o=`local`){let s=new URLSearchParams({path:n});i?.createDirs===!1&&s.set(`createDirs`,`false`),i?.overwrite===!1&&s.set(`overwrite`,`false`);let c=r instanceof Uint8Array,l=c?new Uint8Array(r):new TextEncoder().encode(r);return a(`${G(o)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file?${s.toString()}`,Ma,{method:`PUT`,body:l,headers:{"Content-Type":c?`application/octet-stream`:`text/plain`}})}function Ls(e,t=`local`,n){return a(`${G(t)}/projects/${encodeURIComponent(e)}/workspaces`,t=>{let n=wr(t);if(n.projectId!==e)throw Error(`Workspace resolution project does not match request`);return n},n?.signal===void 0?void 0:{signal:n.signal})}var Rs={workspaceResolution:Ls,workspaces:async(e,t=`local`,n)=>r()===`management`?a(`${G(t)}/projects/${encodeURIComponent(e)}/workspaces`,k(Cr),n?.signal===void 0?void 0:{signal:n.signal}):[...(await Ls(e,t,n)).workspaces],deleteWorkspace:(e,t,n,r=`local`)=>{let i={precondition:n};return a(`${G(r)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}`,e=>e,{method:`DELETE`,body:JSON.stringify(i)})},workspaceTree:(e,t,n=``,r=`local`,i)=>a(`${G(r)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/tree?path=${encodeURIComponent(n)}`,Da,i),workspaceTreeBatch:(e,t,n,r=`local`)=>{let i={paths:[...n]};return a(`${G(r)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/tree/batch`,Oa,{method:`POST`,body:JSON.stringify(i)})},workspaceFile:(e,t,n,r=`local`,i)=>a(`${G(r)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file?path=${encodeURIComponent(n)}`,ja,i),optionalWorkspaceFile:(e,t,n,r=`local`,i)=>u(`${G(r)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file?path=${encodeURIComponent(n)}&optional=true`,ja,i),createWorkspaceFile:(e,t,n,r=`local`)=>Is(e,t,n,new Uint8Array,void 0,r),writeWorkspaceFile:Is,deleteWorkspaceFile:(e,t,n,r=`local`)=>{let i=new URLSearchParams({path:n});return a(`${G(r)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file?${i.toString()}`,Na,{method:`DELETE`})},moveWorkspaceFile:(e,t,n,r,i,o=`local`)=>{let s=new URLSearchParams({fromPath:n,toPath:r});return i?.createDirs===!1&&s.set(`createDirs`,`false`),i?.overwrite===!0&&s.set(`overwrite`,`true`),a(`${G(o)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/file/move?${s.toString()}`,Pa,{method:`POST`})},createWorkspaceDirectory:(e,t,n,r=`local`)=>a(`${G(r)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/directory`,Ir,{method:`POST`,body:JSON.stringify({path:n})}),moveWorkspaceDirectory:(e,t,n,r,i=`local`)=>a(`${G(i)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/directory`,Ir,{method:`PATCH`,body:JSON.stringify({fromPath:n,toPath:r})}),deleteWorkspaceDirectory:(e,t,n,r=`local`)=>a(`${G(r)}/projects/${encodeURIComponent(e)}/workspaces/${encodeURIComponent(t)}/directory?path=${encodeURIComponent(n)}`,Lr,{method:`DELETE`}),downloadWorkspaceFile:(e,t,n,r=`local`)=>qs(e,t,n,r)},zs={sessions:(e,t=`local`,n)=>a(`${G(t)}/sessions?cwd=${encodeURIComponent(e)}`,k(j),n?.signal===void 0?void 0:{signal:n.signal}),search:(e,t,n=`local`)=>a(`${G(n)}/sessions/search?${new URLSearchParams({cwd:e,q:t}).toString()}`,k(j)),searchContent:(e,t,n=`local`,r)=>a(`${G(n)}/sessions/search-content?${new URLSearchParams({cwd:e,q:t}).toString()}`,Rr,r?.signal===void 0?void 0:{signal:r.signal}),unreadCatalog:(e=`local`)=>a(`${G(e)}/sessions/unread`,fi,{cache:`no-store`}),markUnread:(e,t=`local`)=>a(K(e,`unread`,t),fi,{method:`POST`,body:JSON.stringify({cwd:e.cwd})}),acknowledgeUnread:(e,t,n,r=`local`)=>{let i={cwd:e.cwd,catalogId:t,throughCompletionOrder:n};return a(K(e,`unread/acknowledge`,r),fi,{method:`POST`,body:JSON.stringify(i)})},notificationInbox:(e,t=`local`)=>a(q(e,`notifications`,t),ki),dismissNotification:(e,t,n,r=`local`)=>a(K(e,`notifications/dismiss`,r),ki,{method:`POST`,body:J(e,{daemonInstanceId:t,notificationId:n})}),dismissAllNotifications:(e,t,n,r=`local`)=>a(K(e,`notifications/dismiss-all`,r),ki,{method:`POST`,body:J(e,{daemonInstanceId:t,throughOrder:n.order,throughOverflowWatermark:n.overflowWatermark})}),startSession:(e,t=`local`,n)=>a(`${G(t)}/sessions`,j,{method:`POST`,body:JSON.stringify(n===void 0?{cwd:e}:{cwd:e,startupToken:n})}),cleanupPreview:(e,t=`local`)=>a(`${G(t)}/sessions/cleanup/preview`,qi,{method:`POST`,body:JSON.stringify(e)}),cleanup:(e,t=`local`)=>a(`${G(t)}/sessions/cleanup`,Ji,{method:`POST`,body:JSON.stringify(e)}),archiveMany:(e,t=`local`,n)=>a(`${G(t)}/sessions/bulk/archive`,Yi,{method:`POST`,body:xs(e,n)}),deleteArchivedMany:(e,t=`local`,n)=>a(`${G(t)}/sessions/bulk/delete-archived`,Xi,{method:`POST`,body:xs(e,n)}),messages:(e,t,n=`local`)=>a(cs(e,t,n),mr),status:(e,t=`local`)=>a(q(e,`status`,t),M),streamSnapshot:(e,t=`local`)=>a(us(e,t),ui),transcriptSnapshot:(e,t,n=`local`)=>a(ls(e,t,n),di,{...t?.signal===void 0?{}:{signal:t.signal},...t?.timeoutMs===void 0?{}:{timeoutMs:t.timeoutMs}}),models:(e,t=`local`)=>a(q(e,`models`,t),aa),modelCatalog:(e,t=`local`)=>a(q(e,`models/catalog`,t),sa),setModelEnabled:(e,t,n,r,i=`local`)=>a(K(e,`models/enabled`,i),sa,{method:`POST`,body:J(e,{provider:t,modelId:n,enabled:r})}),setModelScope:(e,t,n=`local`)=>a(K(e,`models/scope`,n),sa,{method:`POST`,body:J(e,{mode:t})}),setModel:(e,t,n,r=`local`)=>a(K(e,`model`,r),M,{method:`POST`,body:J(e,{provider:t,modelId:n})}),cycleModel:(e,t,n=`local`)=>a(K(e,`model/cycle`,n),M,{method:`POST`,body:J(e,{direction:t})}),getSessionDefaults:(e,t=`local`)=>a(q(e,`defaults`,t),tn),setSessionDefaults:(e,t,n=`local`)=>a(K(e,`defaults`,n),tn,{method:`POST`,body:J(e,{...t})}),thinkingLevels:(e,t=`local`)=>a(q(e,`thinking-levels`,t),la),setThinkingLevel:(e,t,n=`local`)=>a(K(e,`thinking-level`,n),M,{method:`POST`,body:J(e,{level:t})}),cycleThinkingLevel:(e,t=`local`)=>a(K(e,`thinking-level/cycle`,t),M,{method:`POST`,body:J(e)}),commands:(e,t=`local`)=>a(q(e,`commands`,t),k(Ta)),prompt:(e,t,n,r=`local`,i)=>a(K(e,`prompt`,r),V,{method:`POST`,body:J(e,{text:t,...n===void 0?{}:{streamingBehavior:n},...i!==void 0&&i.length>0?{attachments:i}:{}})}),saveAttachments:(e,t,n=`local`,r)=>a(K(e,`attachments`,n),Ko,{method:`POST`,body:J(e,{attachments:t,...r===void 0?{}:{folder:r}})}),shell:(e,t,n=`local`)=>a(K(e,`shell`,n),V,{method:`POST`,body:J(e,{text:t})}),runCommand:(e,t,n=`local`)=>a(K(e,`commands/run`,n),Po,{method:`POST`,body:J(e,{text:t})}),respondToCommand:(e,t,n,r=`local`)=>a(K(e,`commands/respond`,r),Po,{method:`POST`,body:J(e,{requestId:t,value:n})}),navigateTree:(e,t,n=`local`)=>a(K(e,`tree/navigate`,n),Ro,{method:`POST`,body:J(e,{targetId:t.targetId,expectedLeafId:t.expectedLeafId,summary:t.summary,...t.retainCheckpoint===void 0?{}:{retainCheckpoint:t.retainCheckpoint}})}),forkTree:(e,t,n=`local`)=>Us(e,t,n),abort:(e,t=`local`)=>a(K(e,`abort`,t),Yo,{method:`POST`,body:J(e)}),stop:(e,t=`local`)=>a(K(e,`stop`,t),Xo,{method:`POST`,body:J(e)}),archive:(e,t=`local`,n)=>a(K(e,`archive`,t),Zo,{method:`POST`,body:J(e,n===void 0?{}:{scopeProjectId:n})}),archiveWithDescendants:(e,t=`local`,n)=>a(K(e,`archive-tree`,t),Zo,{method:`POST`,body:J(e,n===void 0?{}:{scopeProjectId:n})}),restore:(e,t=`local`,n)=>a(K(e,`restore`,t),Qo,{method:`POST`,body:J(e,n===void 0?{}:{scopeProjectId:n})}),deleteArchived:(e,t=`local`,n)=>a(ys(e,t,n),$o,{method:`DELETE`}),detachParent:(e,t=`local`)=>a(K(e,`detach-parent`,t),es,{method:`POST`,body:J(e)}),reloadSession:(e,t=`local`)=>a(K(e,`reload`,t),ts,{method:`POST`,body:J(e)}),clearQueue:(e,t=`local`)=>a(K(e,`queue/clear`,t),M,{method:`POST`,body:J(e)}),mutateQueuedMessage:(e,t,n=`local`)=>a(K(e,`queue/message`,n),M,{method:`POST`,body:J(e,{...t})}),dismissWarning:(e,t,n=`local`)=>a(K(e,`warnings/dismiss`,n),M,{method:`POST`,body:J(e,{dismissId:t})}),submitAsk:(e,t,n,r=`local`)=>a(K(e,`ask/submit`,r),M,{method:`POST`,body:J(e,{askId:t,answers:n.answers})}),cancelAsk:(e,t,n=`local`)=>a(K(e,`ask/cancel`,n),M,{method:`POST`,body:J(e,{askId:t})}),answerDialog:(e,t,n,r=`local`)=>a(K(e,`dialogs/answer`,r),Qr,{method:`POST`,body:J(e,{dialogId:t,value:n})}),cancelDialog:(e,t,n=`local`)=>a(K(e,`dialogs/cancel`,n),Qr,{method:`POST`,body:J(e,{dialogId:t})}),authProviders:e=>{let t=new URLSearchParams;e.mode!==void 0&&t.set(`mode`,e.mode),e.authType!==void 0&&t.set(`authType`,e.authType),e.projectId!==void 0&&t.set(`projectId`,e.projectId);let n=t.toString();return a(`${G(e.machineId)}/auth/providers${n===``?``:`?${n}`}`,ma)},saveApiKey:(e,t,n)=>a(Y(`api-key`,n),V,{method:`POST`,body:JSON.stringify({providerId:e,key:t})}),startInteractiveApiKeyLogin:(e,t)=>a(Y(`api-key/interactive`,t),R,{method:`POST`,body:JSON.stringify({providerId:e})}),logoutProvider:(e,t)=>a(Y(`logout`,t),V,{method:`POST`,body:JSON.stringify({providerId:e})}),mcpAuthServers:(e,t=`local`)=>a(q(e,`mcp/auth/servers`,t),ha),startMcpAuth:(e,t,n=`local`,r)=>a(K(e,`mcp/auth`,n),R,{method:`POST`,body:J(e,{mode:t,...r===void 0?{}:{serverName:r}})}),mcpAuthFlow:(e,t=`local`)=>a(`${G(t)}/auth/mcp/${encodeURIComponent(e)}`,R),respondMcpAuthFlow:(e,t,n,r=`local`)=>a(`${G(r)}/auth/mcp/${encodeURIComponent(e)}/respond`,R,{method:`POST`,body:JSON.stringify({requestId:t,value:n})}),cancelMcpAuthFlow:(e,t=`local`)=>a(`${G(t)}/auth/mcp/${encodeURIComponent(e)}/cancel`,R,{method:`POST`}),startOAuthLogin:(e,t)=>a(Y(`oauth`,t),R,{method:`POST`,body:JSON.stringify({providerId:e})}),oauthFlow:(e,t)=>a(Y(`oauth/${encodeURIComponent(e)}`,t),R),respondOAuthFlow:(e,t,n,r)=>a(Y(`oauth/${encodeURIComponent(e)}/respond`,r),R,{method:`POST`,body:JSON.stringify({requestId:t,value:n})}),cancelOAuthFlow:(e,t)=>a(Y(`oauth/${encodeURIComponent(e)}/cancel`,t),R,{method:`POST`})},Bs={runTerminalCommand:(e,t,n=`local`)=>a(`${G(n)}/projects/${encodeURIComponent(t.workspace.projectId)}/workspaces/${encodeURIComponent(t.workspace.id)}/terminal-command-runs`,z,{method:`POST`,body:JSON.stringify({origin:e,title:t.title,command:t.command,metadata:t.metadata??{}})}),listCommandRuns:(e,t=`local`,n)=>a(`${G(t)}/terminal-command-runs${Gs(e)}`,k(z),n?.signal===void 0?void 0:{signal:n.signal}),getCommandRun:(e,t=`local`)=>Vs(e,t),cancelCommandRun:(e,t=`local`)=>a(`${G(t)}/terminal-command-runs/${encodeURIComponent(e)}/cancel`,z,{method:`POST`})};async function Vs(e,t){return u(`${G(t)}/terminal-command-runs/${encodeURIComponent(e)}`,z)}var Hs=class extends Error{constructor(){super(v(`ui.main.8501d1e756a4`,`Fork from the session tree is unavailable. Restart the session daemon to enable it.`)),this.name=`SessionTreeForkUnavailableError`}};async function Us(e,t,r){let i=await fetch(n(K(e,`tree/fork`,r)),{method:`POST`,headers:{"content-type":`application/json`},body:J(e,{entryId:t.entryId,expectedLeafId:t.expectedLeafId,...t.retainCheckpoint===void 0?{}:{retainCheckpoint:t.retainCheckpoint}})});if(!i.ok){let e=await i.json().catch(()=>({}));throw Ws(i.status,e)?new Hs:Error(Ks(e)??i.statusText)}return zo(await i.json())}function Ws(e,t){if(e!==404||!Js(t)||t.statusCode!==404||t.error!==`Not Found`)return!1;let n=t.message;return typeof n==`string`&&/^Route POST:.*\/tree\/fork not found$/i.test(n)}function Gs(e){if(e===void 0)return``;let t=new URLSearchParams;e.projectId!==void 0&&t.set(`projectId`,e.projectId),e.workspaceId!==void 0&&t.set(`workspaceId`,e.workspaceId),e.terminalId!==void 0&&t.set(`terminalId`,e.terminalId),e.statuses!==void 0&&e.statuses.length>0&&t.set(`statuses`,e.statuses.join(`,`)),e.metadata!==void 0&&Object.keys(e.metadata).length>0&&t.set(`metadata`,JSON.stringify(e.metadata));let n=t.toString();return n===``?``:`?${n}`}function Ks(e){if(!Js(e))return;let t=e.error;return typeof t==`string`?t:void 0}async function qs(e,t,n,r){let i=await fetch(gs(e,t,n,{machineId:r}));if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(Ks(e)??i.statusText)}let a=await i.blob(),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o;let c=n.split(`/`).pop();s.download=c===void 0||c===``?`download`:c,document.body.append(s),s.click(),s.remove(),URL.revokeObjectURL(o)}function Js(e){return typeof e==`object`&&!!e}var Ys={files:(e,t,n={})=>{let r=typeof t==`string`,i=r?e:``,o=r?t:e,s=r?n:t,c=new URLSearchParams({q:o});if(s.kind!==void 0&&c.set(`kind`,s.kind),s.mode!==void 0&&c.set(`mode`,s.mode),s.scope!==void 0&&c.set(`scope`,s.scope),(!r||s.workspaceScoped===!0)&&s.projectId!==void 0&&s.workspaceId!==void 0)return a(`${G(s.machineId)}/projects/${encodeURIComponent(s.projectId)}/workspaces/${encodeURIComponent(s.workspaceId)}/files?${c.toString()}`,k(Ea),{signal:s.signal??null});if(!r)throw Error(`File suggestions require a project and workspace`);return c.set(`cwd`,i),a(`${G(s.machineId)}/files?${c.toString()}`,k(Ea),{signal:s.signal??null})}},Xs={...Cs,...ws,...Ps,...Ds,...Os,...ks,...js,...Ms,...Ns,...Fs,..._s,...Rs,...zs,...Ys,...Bs},Zs=`.pi-web/uploads`,Qs=class extends Error{constructor(e=v(`client.workspaceUploads.workspace.upload.cancelled.ac6723`,`Workspace upload cancelled`)){super(e),this.name=`WorkspaceUploadCancelledError`}};function $s(e){return e?.uploads?.defaultFolder??`.pi-web/uploads`}function ec(e,t){return e?.uploads?.defaultFolder??t}function tc(e,t){let n=oc(e,v(`client.workspaceUploads.upload.destination.874cbb`,`Upload destination`),{allowEmpty:!0}),r=oc(t,v(`client.workspaceUploads.upload.filename.9252dd`,`Upload filename`),{allowEmpty:!1});return n===``?r:`${n}/${r}`}function nc(e,t,n,r={}){let i=r.xhrFactory?.()??new XMLHttpRequest,a=!1,o=!1;return{promise:new Promise((s,c)=>{let l=e=>{a||(a=!0,c(e))},u=e=>{a||(a=!0,s(e))};i.open(`PUT`,ps(e,t,n.path,rc(r)),!0),i.responseType=`json`,i.setRequestHeader(`Content-Type`,(n.contentType??n.file.type)||`application/octet-stream`),i.upload.onprogress=e=>{r.onProgress?.(ic(e,n.file.size))},i.onload=()=>{if(i.status>=200&&i.status<300)try{r.onProgress?.({loaded:n.file.size,total:n.file.size,percent:1,lengthComputable:!0}),u(Ma(cc(i)))}catch(e){l(e instanceof Error?e:Error(String(e)))}else l(Error(lc(i)))},i.onerror=()=>{l(Error(v(`client.workspaceUploads.workspace.upload.failed.a87e6b`,`Workspace upload failed`)))},i.onabort=()=>{l(new Qs(o?void 0:v(`client.workspaceUploads.workspace.upload.aborted.58a455`,`Workspace upload aborted`)))},i.send(n.file)}),cancel:()=>{a||(o=!0,i.abort())}}}function rc(e){return{...e.createDirs===void 0?{}:{createDirs:e.createDirs},...e.overwrite===void 0?{}:{overwrite:e.overwrite},...e.machineId===void 0?{}:{machineId:e.machineId}}}function ic(e,t){let n=e.lengthComputable?e.total:t;return{loaded:e.loaded,total:n,percent:ac(e.loaded,n),lengthComputable:e.lengthComputable}}function ac(e,t){return t<=0?e<=0?0:1:Math.max(0,Math.min(1,e/t))}function oc(e,t,n){let r=e.trim();if(r===``){if(n.allowEmpty)return``;throw Error(v(`client.workspaceUploads.must.not.be.empty.b22cd8`,`{value1} must not be empty`,{value1:t}))}if(sc(r))throw Error(v(`client.workspaceUploads.must.be.a.workspace.relative.path.79fcd6`,`{value1} must be a workspace-relative path`,{value1:t}));let i=r.split(/[\\/]+/u).filter(e=>e!==``&&e!==`.`);if(i.length===0){if(n.allowEmpty)return``;throw Error(v(`client.workspaceUploads.must.not.be.empty.b22cd8`,`{value1} must not be empty`,{value1:t}))}if(i.some(e=>e===`..`))throw Error(v(`client.workspaceUploads.must.not.contain.path.traversal.dac533`,`{value1} must not contain path traversal`,{value1:t}));return i.join(`/`)}function sc(e){let t=e.replace(/\\/g,`/`);return t.startsWith(`/`)||/^[A-Za-z]:\//u.test(t)}function cc(e){return e.response!==void 0&&e.response!==null&&e.response!==``?e.response:e.responseText===``?{}:JSON.parse(e.responseText)}function lc(e){let t=uc(e);return dc(t)&&typeof t.error==`string`?t.error:e.statusText||`HTTP ${String(e.status)}`}function uc(e){try{return cc(e)}catch{return}}function dc(e){return typeof e==`object`&&!!e}var fc=262144,pc=8388608,mc=266240,hc=8392704,gc=266240,_c=65536,vc=69632,yc=1e4,bc=2048;Object.freeze([`/paired-plugin-backends/:pluginId/:operation`,`/paired-plugin-backends/:pluginId/projects/:projectId/:operation`,`/paired-plugin-backends/:pluginId/projects/:projectId/workspaces/:workspaceId/:operation`]),Object.freeze([`/paired-plugin-backends/:pluginId/channels/:operation`,`/paired-plugin-backends/:pluginId/projects/:projectId/channels/:operation`,`/paired-plugin-backends/:pluginId/projects/:projectId/workspaces/:workspaceId/channels/:operation`]);var xc=4096;Object.freeze([`/paired-plugin-backends/:pluginId/resources/:operation`,`/paired-plugin-backends/:pluginId/projects/:projectId/resources/:operation`,`/paired-plugin-backends/:pluginId/projects/:projectId/workspaces/:workspaceId/resources/:operation`]);function Sc(e){let t=e.scope,n=e.projectId,r=e.workspaceId;if(t===void 0&&n===void 0&&r===void 0)return{};if(t!==`machine`&&t!==`project`&&t!==`workspace`)throw Error(`Plugin backend scope must be machine, project, or workspace`);for(let e of[n,r])if(e!==void 0&&(typeof e!=`string`||e===``||e.length>512))throw Error(`Plugin backend scope ids must be non-empty strings of at most 512 characters`);if(t===`machine`&&(n!==void 0||r!==void 0))throw Error(`Machine scope cannot contain project or workspace ids`);if(t===`project`&&r!==void 0)throw Error(`Project scope cannot contain a workspace id`);return{scope:t,...typeof n==`string`?{projectId:n}:{},...typeof r==`string`?{workspaceId:r}:{}}}function Cc(e,t){let n=e.workspaceId===void 0?e.projectId===void 0?`machine`:`project`:`workspace`;if(t===void 0)return n;if(n!==`workspace`&&t.scope===void 0)throw Error(`Scoped plugin backend calls require an explicit scope`);if(t.scope!==void 0&&t.scope!==n||t.projectId!==void 0&&t.projectId!==e.projectId||t.workspaceId!==void 0&&t.workspaceId!==e.workspaceId)throw Error(`Plugin backend wire scope does not match route authority`);return n}function wc(e,t=!1){let n=[``,`paired-plugin-backends`,encodeURIComponent(e.pluginId)];return e.projectId!==void 0&&n.push(`projects`,encodeURIComponent(e.projectId)),e.workspaceId!==void 0&&n.push(`workspaces`,encodeURIComponent(e.workspaceId)),t&&n.push(`channels`),n.push(encodeURIComponent(e.operation)),n.join(`/`)}function Tc(e){let t=wc(e),n=t.lastIndexOf(`/`);return`${t.slice(0,n)}/resources${t.slice(n)}`}var Ec=/^[a-z][a-z0-9.-]*$/u,Dc=/^[a-z][a-z0-9.-]*$/u,Oc=64;function kc(e){return e.length<=128&&Ec.test(e)}function Ac(e){if(!kc(e))throw Error(`Plugin backend operation must match ${String(Ec)} and be at most 128 characters`);return e}function jc(e){if(typeof e!=`string`||e===``||e.length>512)throw Error(`Plugin backend revision must be a non-empty string of at most 512 characters`);return e}function X(e,t,n=fc){let r=Uc(e,new Set,t,0);if(Z(JSON.stringify(r))>n)throw Error(`${t} exceeds the ${String(n)} byte limit`);return r}function Mc(e,t,n=fc){if(Z(e)>n)throw Error(`${t} exceeds the ${String(n)} byte limit`);let r;try{r=JSON.parse(e)}catch(e){throw Error(`${t} must be valid JSON`,{cause:e})}return X(r,t,n)}function Nc(e,t,n={}){return Lc({version:1,kind:`open`,...Sc({...n}),revision:jc(e),input:X(t,`Plugin backend channel open input`,fc)},`Plugin backend channel open envelope`,gc)}function Pc(e){return Lc({version:1,kind:`data`,data:X(e,`Plugin backend channel data`,_c)},`Plugin backend channel data envelope`,vc)}function Fc(e){let t=Rc(e,`Plugin backend channel server frame`);if(Bc(t),t.kind===`ready`)return Q(e,vc,`Plugin backend channel ready frame`),Object.freeze({version:1,kind:`ready`});if(t.kind===`data`)return zc(t,e);if(t.kind===`error`)return Q(e,vc,`Plugin backend channel error frame`),Object.freeze({version:1,kind:`error`,code:Vc(t.code),message:Hc(t.message)});throw Error(`Plugin backend channel server frame kind is invalid`)}function Ic(e){if(typeof e!=`string`)throw Error(`Plugin backend channel close reason must be a string`);if(Z(e)>120)throw Error(`Plugin backend channel close reason exceeds the 120 byte limit`);return e}function Z(e){return new TextEncoder().encode(e).byteLength}function Lc(e,t,n){let r=JSON.stringify(e);return Q(r,n,t),r}function Rc(e,t){Q(e,gc,t);let n;try{n=JSON.parse(e)}catch(e){throw Error(`${t} must be valid JSON`,{cause:e})}if(!Gc(n))throw Error(`${t} must be an object`);return n}function zc(e,t){return Q(t,vc,`Plugin backend channel data frame`),Object.freeze({version:1,kind:`data`,data:X(e.data,`Plugin backend channel data`,_c)})}function Bc(e){if(e.version!==1)throw Error(`Plugin backend channel frame version is unsupported`)}function Vc(e){if(typeof e!=`string`||e.length>64||!Dc.test(e))throw Error(`Plugin backend channel error code is invalid`);return e}function Hc(e){if(typeof e!=`string`||e===``)throw Error(`Plugin backend channel error message must be a non-empty string`);if(Z(e)>2048)throw Error(`Plugin backend channel error message exceeds the ${String(bc)} byte limit`);return e}function Q(e,t,n){if(Z(e)>t)throw Error(`${n} exceeds the ${String(t)} byte limit`)}function Uc(e,t,n,r){if(r>Oc)throw Error(`${n} exceeds the maximum JSON depth of ${String(Oc)}`);if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`${n} must contain only finite JSON numbers`);return e}if(Array.isArray(e)){if(t.has(e))throw Error(`${n} must not contain cycles`);t.add(e);let i=e.map(e=>Uc(e,t,n,r+1));return t.delete(e),Object.freeze(i),i}if(!Gc(e))throw Error(`${n} must contain only JSON values`);if(t.has(e))throw Error(`${n} must not contain cycles`);t.add(e);let i={};for(let[a,o]of Object.entries(e))Wc(i,a,Uc(o,t,n,r+1));return t.delete(e),Object.freeze(i)}function Wc(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0})}function Gc(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Kc(e,t){return el(e,t)}function qc(t,r,i){let a=Kc(t,r);return i===void 0?n(a):c(e(a),i)}function Jc(e,t){let n=Kc(e,t),r=n.lastIndexOf(`/`);return`${n.slice(0,r)}/channels${n.slice(r)}`}function Yc(e,t,n){let i=d(Jc(e,t),void 0,r());return n===void 0?o(i):o(i,n)}function Xc(e,t,n){if(!mn(e.pluginId))throw Error(`Invalid PI WEB plugin id: ${e.pluginId}`);if(e.machineId===``)throw Error(`Machine id is required`);if(e.projectId===``||e.workspaceId===``)throw Error(`Scope ids must not be empty`);if(e.workspaceId!==void 0&&e.projectId===void 0)throw Error(`Workspace scope requires a project id`);Cc(e,tl(e));let r=Ac(t),i=jc(e.backendRevision),a=X(n,`Plugin backend resource input`,xc),o=new URLSearchParams({revision:i,input:JSON.stringify(a)});return`api/machines/${encodeURIComponent(e.machineId)}${Tc({...e,operation:r})}?${o.toString()}`}function Zc(t,r,i,a){let o=Xc(t,r,i);return a===void 0?n(o):c(e(o),a)}function Qc(e,t,n,r={}){return nl(e,t,n,r,qc)}function $c(e,t,n,r,i=e=>new WebSocket(e)){if(r.signal?.aborted===!0)return Promise.reject(ol(r.signal));let a=Nc(e.backendRevision,n,tl(e)),o=Yc(e,t),s;try{s=i(o)}catch(e){return Promise.reject(Error(`Plugin backend channel unavailable: ${sl(e)}`,{cause:e}))}let c=!1,l=!1,u=0,d,f=()=>void 0,ee=new Promise(e=>{f=e}),te=Object.freeze({closed:ee,send(e){if(!c||l||s.readyState!==1)throw Error(`Plugin backend channel is not open`);let t=Pc(e),n=Z(t);if(s.bufferedAmount===0&&(u=0),u>=128||s.bufferedAmount+n>1048576){let e=Error(`Plugin backend channel browser queue limit was exceeded`);throw d=Object.freeze({code:`queue-overflow`,message:e.message}),$(s,`Channel queue overflow`),e}try{s.send(t),u+=1}catch(e){throw d=Object.freeze({code:`send-failed`,message:sl(e)}),$(s,`Channel send failed`),e}},close(e=`Channel closed`){$(s,Ic(e))}});return new Promise((e,t)=>{let n=setTimeout(()=>{let e=Error(`Plugin backend channel open timed out after ${String(yc)}ms`);d=Object.freeze({code:`open-timeout`,message:e.message}),t(e),$(s,`Channel open timed out`)},yc),i=()=>{let e=r.signal;if(e===void 0)return;let n=ol(e);c||t(n),d=Object.freeze({code:`cancelled`,message:n.message}),$(s,`Channel cancelled`)};r.signal?.addEventListener(`abort`,i,{once:!0}),s.addEventListener(`open`,()=>{try{s.send(a)}catch(e){t(Error(`Plugin backend channel unavailable: ${sl(e)}`,{cause:e})),$(s,`Channel open failed`)}}),s.addEventListener(`message`,i=>{try{if(typeof i.data!=`string`)throw Error(`Plugin backend channels accept text JSON frames only`);let a=Fc(i.data);if(a.kind===`ready`){if(c)throw Error(`Plugin backend channel sent more than one ready envelope`);c=!0,clearTimeout(n),e(te);return}if(a.kind===`error`){d=Object.freeze({code:a.code,message:a.message}),c||t(Error(a.message)),$(s,`Channel failed`);return}if(!c)throw Error(`Plugin backend channel sent data before ready`);r.onData(a.data)}catch(e){d=Object.freeze({code:`protocol-error`,message:sl(e)}),c||t(e instanceof Error?e:Error(String(e))),$(s,`Channel protocol error`)}}),s.addEventListener(`error`,()=>{d??=Object.freeze({code:`transport-error`,message:`Plugin backend channel transport failed`}),c||t(Error(`Plugin backend channel unavailable`)),$(s,`Channel transport error`)}),s.addEventListener(`close`,e=>{if(l)return;l=!0,clearTimeout(n),r.signal?.removeEventListener(`abort`,i),c||t(Error(d?.message??`Plugin backend channel closed before ready (${String(e.code)})`));let a=d??(e.code===1e3?void 0:Object.freeze({code:`channel-closed`,message:e.reason||`Plugin backend channel closed with code ${String(e.code)}`}));f(Object.freeze({code:e.code,reason:e.reason,wasClean:e.wasClean,...a===void 0?{}:{error:a}}))})})}function el(e,t){if(!mn(e.pluginId))throw Error(`Invalid PI WEB plugin id: ${e.pluginId}`);if(e.machineId===``)throw Error(`Machine id is required`);if(e.projectId===``)throw Error(`Project id is required`);if(e.workspaceId===``)throw Error(`Workspace id is required`);if(e.workspaceId!==void 0&&e.projectId===void 0)throw Error(`Workspace scope requires a project id`);Cc(e,tl(e));let n=Ac(t);return`${e.machineId===`local`?`api`:`api/machines/${encodeURIComponent(e.machineId)}`}${wc({...e,operation:n})}`}function tl(e){return e.scope===void 0?{}:{scope:e.scope,...e.projectId===void 0?{}:{projectId:e.projectId},...e.workspaceId===void 0?{}:{workspaceId:e.workspaceId}}}async function nl(e,t,n,r,i){let a=jc(e.backendRevision),o=X(n,`Plugin backend request input`),s=JSON.stringify({revision:a,input:o,...tl(e)});if(Z(s)>266240)throw Error(`Plugin backend request exceeds the ${String(mc)} byte wire limit`);let c;try{c=await fetch(i(e,t),{method:`POST`,headers:{"content-type":`application/json`},body:s,...r.signal===void 0?{}:{signal:r.signal}})}catch(e){throw r.signal?.aborted===!0?ol(r.signal):Error(`Plugin backend request unavailable: ${sl(e)}`,{cause:e})}let l=await rl(c);if(!c.ok)throw Error(al(l)??`Plugin backend request returned HTTP ${String(c.status)}`);return Mc(l,`Plugin backend response`,pc)}async function rl(e){let t=e.headers.get(`content-length`);if(t!==null&&/^\d+$/u.test(t)&&Number(t)>8392704)throw await e.body?.cancel(),Error(`Plugin backend response exceeds the ${String(hc)} byte wire limit`);if(e.body===null){let t=await e.text();if(Z(t)>8392704)throw il();return t}let n=e.body.getReader(),r=new TextDecoder,i=0,a=``;try{let e=await n.read();for(;!e.done;){if(i+=e.value.byteLength,i>8392704)throw await n.cancel(),il();a+=r.decode(e.value,{stream:!0}),e=await n.read()}return a+r.decode()}finally{n.releaseLock()}}function $(e,t){if(e.readyState===0||e.readyState===1)try{e.close(1e3,Ic(t))}catch{e.close()}}function il(){return Error(`Plugin backend response exceeds the ${String(hc)} byte wire limit`)}function al(e){try{let t=JSON.parse(e);return cl(t)&&typeof t.error==`string`?t.error:void 0}catch{return}}function ol(e){let t=e.reason;return t instanceof Error?t:new DOMException(`Plugin backend request cancelled`,`AbortError`)}function sl(e){return e instanceof Error?e.message:String(e)}function cl(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var ll=`pi-web.terminal`;export{Dn as $,is as A,pi as B,Bs as C,fs as D,ds as E,si as F,dr as G,Ia as H,oi as I,Xn as J,lr as K,Ai as L,Jr as M,bi as N,hs as O,Mi as P,wn as Q,mi as R,zs as S,Rs as T,za as U,z as V,S as W,Sn as X,Bn as Y,Tn as Z,Ps as _,Vt as _t,jc as a,mn as at,ks as b,Tt as bt,$s as c,$t as ct,tc as d,Kt as dt,y as et,Ms as f,Gt as ft,Os as g,Bt as gt,Ns as h,Lt as ht,Qc as i,hn as it,Zr as j,os as k,nc as l,Qt as lt,Ds as m,Ht as mt,$c as n,On as nt,Zs as o,gn as ot,Xs as p,v as pt,ir as q,Zc as r,yn as rt,Qs as s,Yt as st,ll as t,xn as tt,ec as u,Zt as ut,js as v,_ as vt,_s as w,Fs as x,Cs as y,It as yt,yi as z};
|