@ycodium-ai/plugin-im 0.2.2976 → 0.2.2978

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/README.md CHANGED
@@ -13,11 +13,11 @@ actions check the connection, copy a diagnostic reference (`IM-CONN-…`), and f
13
13
  Lark guide scope repair. Chats (private or group) are not configured on the card;
14
14
  they pick their own project:
15
15
 
16
- - **Connect a Lark bot** (Beta) is a button on top of the card (web and desktop; mobile
17
- fills rows by hand). One scan, then the plugin creates the Lark app through the developer
16
+ - **Connect a Lark bot** (Beta) is a button below the bot list in the settings section (web,
17
+ desktop and mobile). One scan, then the plugin creates the Lark app through the developer
18
18
  console, publishes it visible to the scanner only, and adds a Lark row with the credentials
19
19
  saved as secrets and the scanner as the only allowed person: no draft, no Save. It relies on
20
- non-public console interfaces and may break; the dialog then shows the step list with the
20
+ non-public console interfaces and may break; the inline panel then shows the step list with the
21
21
  failed step marked. See `src/lark/setup/`.
22
22
  - **Access mode** (per bot): `allowlist` (default) or `open`. `allowlist` admits only
23
23
  the people on the allow list; `open` admits any sender the platform can identify.
@@ -251,7 +251,7 @@ waits in the same per-chat queue as typed messages. Another platform opts in by
251
251
  implementing the optional `panel` surface on its adapter (`src/adapter.ts`).
252
252
 
253
253
  The **Reply language** setting (Chinese by default, or English) picks the
254
- language of everything the bot says itself. The settings card follows the
254
+ language of everything the bot says itself. The settings section follows the
255
255
  interface language instead. The copy lives in `locales/en.json` and
256
256
  `locales/zh-CN.json`; Chinese shortcut commands only work in Chinese.
257
257
 
@@ -278,20 +278,26 @@ secrets stay until you clear them.
278
278
 
279
279
  ## Surfaces
280
280
 
281
- - **Web / Desktop** — Settings → Plugins → Chat. The bots table is the
282
- settings card this package registers.
283
- - **Mobile** — the same settings card, without platform option icons (mobile
284
- has no plugin icon pipeline).
281
+ - **Web / Desktop / Mobile** — Settings → Plugins, the **Chat** section. The plugin draws it
282
+ itself in the `settings.section` seat (`src/ui/`); on mobile the same bundle runs in a WebView.
283
+ The settings card this package registers is declaration-only (`presentation: "hidden"`): the
284
+ host draws no form for it, and reads it to know which cell holds a proxy and which hold passwords.
285
285
  - Chat replies themselves go to Telegram, WeCom, or Lark, not into a Ycodium
286
286
  page.
287
287
 
288
288
  ## Source layout
289
289
 
290
- `src/index.ts` only assembles: it builds the adapters, registers the settings card, builds the
290
+ `src/index.ts` only assembles: it builds the adapters, registers the settings card and the settings commands, builds the
291
291
  shared core and wires the feature modules together. Everything else is one module per
292
292
  responsibility, each receiving a small `core` object (a few host capabilities, the reply
293
293
  language, the saved-state mirror) plus an explicit `deps` object, never the whole `ctx`:
294
294
 
295
+ - `settingsContract` (what the settings commands and the UI share: command names, wire shapes,
296
+ which column applies to a row, the reply-language options; pure data and functions only, it is
297
+ bundled into the browser UI), `settingsView` (the redacted read view and the write transforms
298
+ for the bots table and the delivery targets table),
299
+ `settingsCommands`, `settingsUpdater` (the one read-modify-write entry for the plugin's own
300
+ config), `ui/` (the settings section)
295
301
  - `botConfig` (settings card, reading bots, chat keys, allow-list), `core` (state mirror and
296
302
  persistence, delivery, bot and chat lookup), `connections` (one long connection per bot)
297
303
  - `inbound` (per-bot message handlers), `chatQueue` (per-chat serial queue), `commands`,
@@ -301,8 +307,8 @@ language, the saved-state mirror) plus an explicit `deps` object, never the whol
301
307
  `notifications`, `acknowledgements`, `panelWiring` (with `panelController`)
302
308
  - `lark/setup/` (the scan flow): `setupFlow` (the engine; running shows one progress line, the
303
309
  step list is sent only on failure, success returns the credentials instead of emitting `done`),
304
- `setupCommands` (the card action and the `larkSetup.start` stream; saves the bot, then emits
305
- `done`), `saveBot` (the pure `bots`-table upsert), `consoleClient`/`qrLogin`/`fakeConsole` and
310
+ `setupCommands` (the `larkSetup.session` stream, each item a cumulative snapshot so the UI keeps
311
+ the QR code while status lines follow; saves the bot, then emits `done`), `saveBot` (the pure `bots`-table upsert), `consoleClient`/`qrLogin`/`fakeConsole` and
306
312
  friends
307
313
 
308
314
  ## Developing
@@ -319,6 +325,6 @@ UNLICENSED.
319
325
 
320
326
  按 botId+targetId 投递(提案 [0068](../../docs/internals/proposals/0068-im-proactive-delivery.md)):
321
327
 
322
- - 设置里可配投递目标,并 **opt-in** 开启本机 HTTP(**只听 `127.0.0.1`**,可选 Bearer token)。
323
- - `POST /v1/delivery/messages` 体为 `{ botId, targetId, text }`;`botId` 是机器人表行 id。
328
+ - 设置分区里可配投递目标(每个目标一块:选机器人、填目标 id 与平台聊天 id),并 **opt-in** 开启本机 HTTP(**只听 `127.0.0.1`**,可选 Bearer token)。
329
+ - `POST /v1/delivery/messages` 体为 `{ botId, targetId, text }`;`botId` 是机器人表行 id,设置里选机器人的下拉在名字后面的括号里显示它。
324
330
  - **不要**用 `network.serve` 当这条入站口;同 Host 插件互调另走 typed RPC(尚未做)。
package/assets/ui.js ADDED
@@ -0,0 +1,201 @@
1
+ var rn=window.__ycodiumPluginHost.react;var{Activity:vn,Children:Sn,Component:bn,Fragment:pn,Profiler:wn,PureComponent:In,StrictMode:hn,Suspense:Cn,__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE:xn,__COMPILER_RUNTIME:kn,act:Rn,cache:Tn,cacheSignal:Nn,captureOwnerStack:Pn,cloneElement:An,createContext:z,createElement:me,createRef:En,forwardRef:On,isValidElement:_n,lazy:Bn,memo:Ln,startTransition:Vn,unstable_useCacheRefresh:Fn,use:$,useActionState:Dn,useCallback:Kn,useContext:Mn,useDebugValue:Gn,useDeferredValue:Un,useEffect:we,useEffectEvent:Hn,useId:zn,useImperativeHandle:$n,useInsertionEffect:qn,useLayoutEffect:Yn,useMemo:T,useOptimistic:Wn,useReducer:jn,useRef:E,useState:p,useSyncExternalStore:Qn,useTransition:Jn,version:Zn}=rn;var q=(e,n)=>{let t=e[n];return typeof t=="string"?t.trim():""};var Ie="settings.view",he="settings.saveBot",Ce="settings.removeBot",xe="settings.saveGeneral",ke="settings.saveTarget",Re="settings.removeTarget",Te="larkSetup.session",D={labelKey:"setup.action.label",descriptionKey:"setup.action.description",badgeKey:"setup.action.badge",warningKey:"setup.action.warning"},Ne={checkConnection:"im.settings.checkConnection",copyDiagnostics:"im.settings.copyDiagnostics",larkRepair:"im.settings.larkRepair"},Pe=[{id:"checkConnection",labelKey:"rowAction.checkConnection.label",descriptionKey:"rowAction.checkConnection.description"},{id:"copyDiagnostics",labelKey:"rowAction.copyDiagnostics.label",descriptionKey:"rowAction.copyDiagnostics.description"},{id:"larkRepair",labelKey:"rowAction.larkRepair.label",descriptionKey:"rowAction.larkRepair.description",platform:"lark"}],on="lark",Y=[{value:"zh-CN",labelKey:"settings.language.zhCN"},{value:"en",labelKey:"settings.language.en"}],ln="botId",W=e=>q(e,"platform")||on,Ae=(e,n)=>{let t=e.showWhen;if(t===void 0)return!0;let r=t.key==="platform"?W(n):q(n,t.key);return t.equals.includes(r)},Ee=(e,n,t)=>e.map(r=>r.key===ln?{...r,kind:"select",options:n.map(l=>({value:l.rowId,label:`${q(l.values,"displayName")||t(l.platform)} (${l.rowId})`}))}:r),Oe=(e,n)=>{switch(n.kind){case"qr":{let{expired:t,...r}=e,l=n.expiresAt===void 0?{payload:n.payload}:{payload:n.payload,expiresAt:n.expiresAt};return{...r,qr:l}}case"status":{let t=n.params===void 0?{statusKey:n.statusKey}:{statusKey:n.statusKey,params:n.params};if(n.expired!==!0)return{...e,status:t};let{qr:r,...l}=e;return{...l,status:t,expired:!0}}case"steps":return{...e,steps:n.steps};case"done":case"failed":{let{status:t,...r}=e;return{...r,result:n}}}};var{jsx:i,jsxs:d,Fragment:x}=window.__ycodiumPluginHost.jsxRuntime;var _e=z(null);function Be(e){return i(_e,{value:e.bridge,children:e.children})}var an=new Set(["Collapsible","CollapsiblePanel","CollapsibleTrigger"]);function f(e){let n=t=>{let o=$(_e)?.ui?.[e];return o===void 0?an.has(e)?me("div",{className:t.className},t.children):null:me(o,t)};return n.displayName=e,n}var y=f("Button"),O=f("Input"),_=f("Label"),Le=f("Switch"),j=f("Select"),Q=f("SelectTrigger"),K=f("SelectValue"),J=f("SelectPopup"),Z=f("SelectItem"),Ve=f("StatusPill"),Fe=f("EmptyInline"),X=f("Alert"),De=f("AlertAction"),ee=f("AlertDescription"),Ke=f("Collapsible"),Me=f("CollapsibleTrigger"),Ge=f("CollapsiblePanel"),N=f("Spinner"),Ue=f("QRCodeSvg"),He=f("ProxyChoiceSelect");var ne=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ze=e=>ne(e)&&Array.isArray(e.bots)&&Array.isArray(e.targets)&&ne(e.delivery),$e=e=>ne(e)&&ze(e.view)&&Array.isArray(e.columns)&&Array.isArray(e.targetColumns)&&Array.isArray(e.proxies)?e:null,M=async(e,n,t,r)=>{try{let l=await e.commands.invoke(n,t,r);return ne(l)&&l.ok===!0&&ze(l.view)?l.view:null}catch{return null}},qe=(e,n)=>n.isPending?e.phase==="asked"?{...e,phase:"refetching"}:e:n.view!==null&&!n.failed?e.phase==="refetching"||JSON.stringify(n.view)===JSON.stringify(e.view)?null:e:e.phase==="asked"?e:{...e,phase:"asked"},k=e=>e==null||e.length===0?{}:{environmentId:e},ge=e=>JSON.stringify(e),G=(e,n)=>n===null?e:`${e}:${n}`,ye=e=>JSON.stringify([e.replyLanguage,e.delivery]);function B(e,n,t){if(n!==void 0&&n.length>0)return e(n);if(t!==void 0&&t.length>0)return t}function Ye(e,n){return n.length===0?null:n.map(t=>e(t==="required"?"settingsSection.issue.required":"settingsSection.issue.format")).join(" ")}function P(e,n,t){return`im-${(e??"here").replace(/[^A-Za-z0-9_-]/g,"")}-${n}-${t}`}function U(e,n,t){let r=[n?`${e}-issue`:null,t?`${e}-hint`:null].filter(l=>l!==null);return r.length===0?void 0:r.join(" ")}function R(e){return d("div",{className:e.span===!0?"im-field im-span":"im-field",children:[i(_,{htmlFor:e.id,children:e.label}),e.children,e.issue?i("p",{id:`${e.id}-issue`,className:"im-small im-issue",role:"alert",children:e.issue}):null,e.description===void 0?null:i("p",{id:`${e.id}-hint`,className:"im-hint im-small im-muted",children:e.description})]})}function te(e){let n=e.stored&&e.value===""&&!e.clearing?e.savedPlaceholder:e.placeholder;return d("div",{className:"im-secret",children:[i(O,{id:e.id,type:"password",value:e.value,placeholder:n,disabled:e.disabled,autoComplete:"new-password","aria-invalid":e.invalid?!0:void 0,"aria-describedby":e.describedBy,onChange:t=>e.onChange(t.target.value)}),e.stored?i(y,{variant:"ghost",size:"sm","aria-pressed":e.clearing,disabled:e.disabled,onClick:e.onToggleClear,children:e.clearing?e.undoLabel:e.clearLabel}):null]})}function ie(e){let n=e.saving||e.busy===!0;return!e.dirty&&!e.saving&&!e.failed?null:d("div",{className:"im-span",children:[e.dirty||e.saving?d("div",{className:"im-actions",children:[d(y,{variant:e.solid?"default":"outline",disabled:n||!e.dirty,onClick:e.onSave,children:[e.saving?i(N,{}):null,e.saveLabel]}),e.dirty&&!n?i(y,{variant:"ghost",size:"sm",onClick:e.onRevert,children:e.revertLabel}):null]}):null,e.failed?i("p",{className:"im-small im-issue",role:"alert",children:e.failedLabel}):null]})}async function re(e,n,t){try{await e.writeClipboard(n),e.notify(t("settingsSection.copied"),"success")}catch{e.notify(t("settingsSection.copyFailed"),"warning")}}var sn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function oe(e){let n=T(()=>k(e.environmentId),[e.environmentId]),t=e.bridge.commands.useSubscription(e.command,e.payload,n),r=T(()=>sn(t.data)?e.items==="snapshots"?t.data:Oe({},t.data):{},[t.data,e.items]),l=r.result,o=E(null),a=e.onSettled;we(()=>{l===void 0||o.current===t.data||(o.current=t.data,a?.(l))},[l,t.data,a]);let s=e.t,g=l===void 0&&t.error===null&&!t.isUnavailable;return d("div",{className:"im-flow im-span",children:[t.isUnavailable||t.error!==null?i(X,{variant:"error",layout:"inline",children:i(ee,{children:s("settingsSection.action.failedToRun")})}):null,r.qr===void 0?null:i("div",{className:"im-qr",children:i(Ue,{value:r.qr.payload,size:176,marginSize:2,title:s("settingsSection.action.qrTitle")})}),r.status===void 0?null:d("p",{className:"im-inline im-medium",children:[g?i(N,{}):null,i("span",{children:s(r.status.statusKey,r.status.params)})]}),g&&r.status===void 0&&r.qr===void 0?d("p",{className:"im-inline im-medium",children:[i(N,{}),i("span",{children:s("settingsSection.action.running")})]}):null,r.steps===void 0?null:i("ul",{className:"im-steps im-small",children:r.steps.map(v=>d("li",{"data-state":v.state,children:[i("span",{children:s(v.labelKey)}),i("span",{className:"im-muted",children:s(`settingsSection.step.${v.state}`)})]},v.id))}),l===void 0?null:i(dn,{result:l,bridge:e.bridge,t:s}),d("div",{className:"im-actions",children:[l?.kind==="failed"||r.expired===!0||t.error!==null?i(y,{variant:"ghost",size:"sm",onClick:t.refresh,children:s("settingsSection.retry")}):null,i(y,{variant:"ghost",size:"sm",onClick:e.onClose,children:s(l===void 0?"settingsSection.cancel":"settingsSection.action.close")})]})]})}function dn(e){let{result:n,t}=e,r=n.kind==="done"?n.messageKey===void 0?t("settingsSection.action.done"):t(n.messageKey):t(n.reasonKey,n.params),l=n.kind==="done"?(n.warnings??[]).map(o=>t(o.key,o.params)):n.detail===void 0?[]:[n.detail];return d("div",{className:"im-result",children:[i("p",{className:n.kind==="failed"?"im-medium im-issue":"im-medium",role:"status",children:r}),l.length===0?null:d(x,{children:[i("pre",{className:"im-detail im-small",children:l.join(`
2
+
3
+ `)}),i("div",{className:"im-actions",children:i(y,{variant:"ghost",size:"sm",onClick:()=>{re(e.bridge,l.join(`
4
+
5
+ `),t)},children:t("settingsSection.copy")})})]})]})}function le(e){return i("section",{className:"im-block",children:d(Ke,{className:"im-collapse",defaultOpen:e.defaultOpen,children:[d("div",{className:"im-head",children:[d(Me,{className:"im-toggle",children:[i("span",{className:"im-chevron","aria-hidden":"true"}),i("span",{className:"im-title im-medium",children:e.title}),e.meta]}),e.actions]}),e.notice,i(Ge,{children:i("div",{className:"im-panel",children:e.children})})]})})}function We(e){let n=e.columns.filter(t=>Ae(t,e.values));return d(x,{children:[n.map(t=>i(cn,{column:t,scope:e.scope,environmentId:e.environmentId,proxies:e.proxies,values:e.values,secrets:e.secrets,clearSecrets:e.clearSecrets,storedSecrets:e.storedSecrets,issues:e.issues,disabled:e.disabled,t:e.t,onValue:e.onValue,onSecret:e.onSecret,onToggleClear:e.onToggleClear},t.key)),e.publicFields.map(t=>i(mn,{field:t,scope:e.scope,environmentId:e.environmentId,bridge:e.bridge,t:e.t},t.key))]})}function cn(e){let n=e.column,t=P(e.environmentId,e.scope,n.key),r=B(e.t,n.labelKey,n.label)??n.key,l=B(e.t,n.descriptionKey,n.description),o=B(e.t,n.placeholderKey,n.placeholder),a=Ye(e.t,e.issues.filter(g=>g.column===n.key).map(g=>g.code)),s=U(t,a!==null,l!==void 0);return n.kind==="password"?i(R,{id:t,label:r,description:l,issue:a,children:i(te,{id:t,value:e.secrets[n.key]??"",stored:e.storedSecrets[n.key]===!0,clearing:e.clearSecrets.includes(n.key),disabled:e.disabled,invalid:a!==null,describedBy:s,placeholder:o,savedPlaceholder:e.t("settingsSection.secret.saved"),clearLabel:e.t("settingsSection.secret.clear"),undoLabel:e.t("settingsSection.secret.clearUndo"),onChange:g=>{g!==(e.secrets[n.key]??"")&&e.onSecret(n.key,g)},onToggleClear:()=>e.onToggleClear(n.key)})}):n.kind==="select"?i(un,{column:n,id:t,label:r,description:l,issue:a,described:s,values:e.values,disabled:e.disabled,t:e.t,onValue:e.onValue}):n.kind==="proxy"?i("div",{className:"im-field",children:i(He,{id:t,label:r,hint:l,value:e.values[n.key]??"",proxies:e.proxies,disabled:e.disabled,onChange:g=>{g!==(e.values[n.key]??"")&&e.onValue(n.key,g)},children:a===null?null:i("p",{id:`${t}-issue`,className:"im-small im-issue",role:"alert",children:a})})}):i(R,{id:t,label:r,description:l,issue:a,children:i(O,{id:t,type:"text",value:e.values[n.key]??"",placeholder:o,disabled:e.disabled,"aria-invalid":a!==null?!0:void 0,"aria-describedby":s,onChange:g=>{let v=g.target.value;v!==(e.values[n.key]??"")&&e.onValue(n.key,v)}})})}function un(e){let n=e.values[e.column.key]??"",t=e.column.options??[],r=t.find(o=>o.value===n),l=n===""?void 0:r===void 0?n:B(e.t,r.labelKey,r.label)??r.value;return i(R,{id:e.id,label:e.label,description:e.description,issue:e.issue,children:d(j,{className:"im-wide",value:n===""?null:n,disabled:e.disabled,onValueChange:o=>{let a=o??"";a!==n&&e.onValue(e.column.key,a)},children:[i(Q,{id:e.id,"aria-invalid":e.issue!==null?!0:void 0,"aria-describedby":e.described,children:l===void 0?i(K,{placeholder:e.t("settingsSection.select.default")}):i(K,{children:l})}),i(J,{children:t.map(o=>o.value===""?null:i(Z,{value:o.value,children:B(e.t,o.labelKey,o.label)??o.value},o.value))})]})})}function mn(e){let n=P(e.environmentId,`${e.scope}-pub`,e.field.key);return d("div",{className:"im-field im-span",children:[i(_,{children:e.t(`settingsSection.publicField.${e.field.key}`)}),d("div",{className:"im-inline",children:[i("span",{id:n,className:"im-public-value im-small",children:e.field.value}),e.field.copyable?i(y,{variant:"ghost",size:"sm",onClick:()=>{re(e.bridge,e.field.value,e.t)},children:e.t("settingsSection.copy")}):null]})]})}function je(e){let n={};for(let[o,a]of Object.entries(e.values))(e.baseline[o]??"")!==a&&(n[o]=a);let t={};for(let[o,a]of Object.entries(e.secrets))a!==""&&(t[o]=a);let r=[];for(let o of e.clearSecrets)Object.hasOwn(t,o)||r.includes(o)||r.push(o);return e.rowId===void 0||Object.keys(n).length>0||Object.keys(t).length>0||r.length>0?{changed:!0,edit:{...e.rowId===void 0?{}:{rowId:e.rowId},values:n,...Object.keys(t).length>0?{secrets:t}:{},...r.length>0?{clearSecrets:r}:{}}}:{changed:!1}}function gn(e){let n=e.trim();if(!/^\d+$/.test(n))return null;let t=Number(n);return!Number.isInteger(t)||t<1||t>65535?null:t}function Qe(e){let n={};e.replyLanguage!==e.baseline.replyLanguage&&(n.replyLanguage=e.replyLanguage),e.enabled!==e.baseline.enabled&&(n.deliveryHttpEnabled=e.enabled);let t=!1;if(e.enabled){let r=gn(e.port);r===null?t=!0:r!==e.baseline.port&&(n.deliveryHttpPort=r),e.token!==""?n.deliveryHttpToken=e.token:e.clearToken&&e.baseline.hasToken&&(n.clearDeliveryHttpToken=!0)}return t?{changed:!0,invalidPort:!0}:Object.keys(n).length===0?{changed:!1}:{changed:!0,invalidPort:!1,payload:n}}var Je=z({activeId:null,activate:()=>{}});function Ze(e){return i(Je,{value:{activeId:e.activeId,activate:e.activate},children:e.children})}function ae(e){let n=$(Je);return{chosen:n.activeId===e,activate:()=>n.activate(e)}}function se(e,n){return{signature:n,values:{...e?.values??{}},secrets:{},clearSecrets:[],saving:!1,failed:!1,confirming:!1,removing:!1,removeFailed:!1}}function fe(e){let{kind:n,row:t}=e,r=t===null?n.newSlot:ge(t),l=ae(G(n.newSlot,t?.rowId??null)),o=E(0),[a,s]=p(()=>se(t,r));a.signature!==r&&(o.current+=1,s(se(t,r)));let g=je({...t===null?{}:{rowId:t.rowId},baseline:t?.values??{},values:a.values,secrets:a.secrets,clearSecrets:a.clearSecrets}),v=g.changed,w=t===null||!t.configured,I=a.saving||a.removing;function h(c){l.activate(),s(m=>({...c(m),failed:!1}))}function C(){if(!g.changed||I)return;l.activate();let c=g.edit,m=++o.current;s(u=>({...u,saving:!0,failed:!1})),M(e.bridge,n.saveCommand,c,k(e.environmentId)).then(u=>{if(o.current!==m)return;if(u===null){s(L=>({...L,saving:!1,failed:!0}));return}let b=t===null?void 0:n.rows(u).find(L=>L.rowId===t.rowId);b!==void 0&&s(se(b,ge(b))),e.onSaved(u)})}function A(){if(t===null){e.onDiscard();return}let c=t.rowId,m=++o.current;s(u=>({...u,removing:!0,removeFailed:!1})),M(e.bridge,n.removeCommand,{rowId:c},k(e.environmentId)).then(u=>{if(o.current===m){if(u===null){s(b=>({...b,removing:!1,removeFailed:!0,confirming:!0}));return}e.onSaved(u)}})}return i(le,{title:e.title(a.values),defaultOpen:w,meta:d(x,{children:[e.meta?.(a.values),i(Ve,{tone:w?"attention":"success",children:e.t(w?"settingsSection.status.incomplete":"settingsSection.status.ready")})]}),actions:a.confirming?d("div",{className:"im-actions",children:[i(y,{variant:"ghost",size:"sm",disabled:a.removing||a.saving,onClick:A,children:e.t(n.removeConfirmKey)}),i(y,{variant:"ghost",size:"sm",disabled:a.removing||a.saving,onClick:()=>s(c=>({...c,confirming:!1})),children:e.t("settingsSection.cancel")})]}):i(y,{variant:"ghost",size:"sm",disabled:I,onClick:()=>s(c=>({...c,confirming:!0,removeFailed:!1})),children:e.t("settingsSection.remove")}),notice:d(x,{children:[a.confirming&&t!==null&&n.removeHintKey!==void 0?i("p",{className:"im-small im-muted",children:e.t(n.removeHintKey)}):null,a.removeFailed?i("p",{className:"im-small im-issue",role:"alert",children:e.t(n.removeFailedKey)}):null]}),children:d("div",{className:"im-form",children:[i(We,{scope:`${n.newSlot}-${t?.rowId??"new"}`,environmentId:e.environmentId,columns:e.columns,proxies:e.proxies,values:a.values,secrets:a.secrets,clearSecrets:a.clearSecrets,storedSecrets:t?.secrets??{},issues:t?.issues??[],publicFields:t?.publicFields??[],disabled:I,bridge:e.bridge,t:e.t,onValue:(c,m)=>h(u=>({...u,values:{...u.values,[c]:m}})),onSecret:(c,m)=>h(u=>({...u,secrets:{...u.secrets,[c]:m}})),onToggleClear:c=>h(m=>({...m,clearSecrets:m.clearSecrets.includes(c)?m.clearSecrets.filter(u=>u!==c):[...m.clearSecrets,c]}))}),e.extra?.({dirty:v,frozen:I}),i(ie,{dirty:v,saving:a.saving,busy:a.removing,solid:l.chosen&&v,failed:a.failed,saveLabel:e.t("settingsSection.save"),revertLabel:e.t("settingsSection.revert"),failedLabel:e.t("settingsSection.saveFailed"),onSave:C,onRevert:()=>{o.current+=1,s(se(t,r))}})]})})}var de={newSlot:"im-new-row",saveCommand:he,removeCommand:Ce,rows:e=>e.bots,removeConfirmKey:"settingsSection.removeConfirm",removeHintKey:"settingsSection.removeHint",removeFailedKey:"settingsSection.removeFailed"},ce={newSlot:"im-new-target",saveCommand:ke,removeCommand:Re,rows:e=>e.targets,removeConfirmKey:"settingsSection.target.removeConfirm",removeFailedKey:"settingsSection.target.removeFailed"};function ve(e){let{bot:n,t}=e,[r,l]=p(null);return i(fe,{...e,kind:de,row:n,title:o=>{let a=(o.displayName??"").trim();return a.length>0?a:t(`platform.${W(o)}`)},meta:o=>i("span",{className:"im-small im-muted",children:t(`platform.${W(o)}`)}),extra:({dirty:o,frozen:a})=>n===null?null:d(x,{children:[d("div",{className:"im-span",children:[i("div",{className:"im-actions",children:Pe.filter(s=>s.platform===void 0||s.platform===n.platform).map(s=>i(y,{variant:"ghost",size:"sm",disabled:o||a,title:t(s.descriptionKey),onClick:()=>l({id:s.id,payload:{rowId:n.rowId}}),children:t(s.labelKey)},s.id))}),o?i("p",{className:"im-small im-muted",children:t("settingsSection.action.saveFirst")}):null]}),r===null?null:i(oe,{bridge:e.bridge,command:Ne[r.id],payload:r.payload,items:"latest",environmentId:e.environmentId,t,onClose:()=>l(null)},r.id)]})})}function Se(e){let{t:n}=e;return i(fe,{...e,kind:ce,row:e.target,title:t=>{let r=(t.name??"").trim()||(t.targetId??"").trim();return r.length>0?r:n("settingsSection.target.untitled")}})}var yn="im-general";function ue(e,n){return{signature:n,replyLanguage:e.replyLanguage,enabled:e.delivery.enabled,port:String(e.delivery.port),token:"",clearToken:!1,saving:!1,failed:!1}}function Xe(e){let n=e.view,t=ye(n),r=ae(yn),l=E(0),[o,a]=p(()=>ue(n,t));o.signature!==t&&(l.current+=1,a(ue(n,t)));let s=Qe({baseline:{replyLanguage:n.replyLanguage,enabled:n.delivery.enabled,port:n.delivery.port,hasToken:n.delivery.hasToken},replyLanguage:o.replyLanguage,enabled:o.enabled,port:o.port,token:o.token,clearToken:o.clearToken}),g=s.changed,v=s.changed&&s.invalidPort,w=P(e.environmentId,"general","port"),I=P(e.environmentId,"general","token"),h=P(e.environmentId,"general","language");function C(c){r.activate(),a(m=>({...m,...c,failed:!1}))}function A(){if(!s.changed||o.saving)return;if(r.activate(),s.invalidPort){a(u=>({...u,failed:!0}));return}let c=s.payload,m=++l.current;a(u=>({...u,saving:!0,failed:!1})),M(e.bridge,xe,c,k(e.environmentId)).then(u=>{if(l.current===m){if(u===null){a(b=>({...b,saving:!1,failed:!0}));return}a(ue(u,ye(u))),e.onSaved(u)}})}return i(le,{title:e.t("settingsSection.general"),defaultOpen:!1,children:d("div",{className:"im-form",children:[i(R,{id:h,label:e.t("settings.language.label"),description:e.t("settings.language.description"),children:d(j,{className:"im-wide",value:o.replyLanguage,disabled:o.saving,onValueChange:c=>{let m=Y.find(u=>u.value===c);m===void 0||m.value===o.replyLanguage||C({replyLanguage:m.value})},children:[i(Q,{id:h,"aria-describedby":`${h}-hint`,children:i(K,{children:Y.filter(c=>c.value===o.replyLanguage).map(c=>e.t(c.labelKey))})}),i(J,{children:Y.map(c=>i(Z,{value:c.value,children:e.t(c.labelKey)},c.value))})]})}),d("div",{className:"im-field",children:[d(_,{className:"im-inline",children:[i("span",{className:"im-medium",children:e.t("settings.deliveryHttp.enabled.label")}),i(Le,{checked:o.enabled,disabled:o.saving,onCheckedChange:c=>{c!==o.enabled&&C({enabled:c})}})]}),i("p",{className:"im-small im-muted",children:e.t("settings.deliveryHttp.enabled.description")})]}),o.enabled?i(R,{id:w,label:e.t("settings.deliveryHttp.port.label"),description:e.t("settings.deliveryHttp.port.description"),issue:v?e.t("settingsSection.issue.format"):null,children:i(O,{id:w,type:"number",value:o.port,disabled:o.saving,"aria-invalid":v?!0:void 0,"aria-describedby":U(w,v,!0),onChange:c=>{c.target.value!==o.port&&C({port:c.target.value})}})}):null,o.enabled?i(R,{id:I,label:e.t("settings.deliveryHttp.token.label"),description:e.t("settings.deliveryHttp.token.description"),children:i(te,{id:I,value:o.token,stored:n.delivery.hasToken,clearing:o.clearToken,disabled:o.saving,invalid:!1,describedBy:U(I,!1,!0),savedPlaceholder:e.t("settingsSection.secret.saved"),clearLabel:e.t("settingsSection.secret.clear"),undoLabel:e.t("settingsSection.secret.clearUndo"),onChange:c=>{c!==o.token&&C({token:c})},onToggleClear:()=>C({clearToken:!o.clearToken})})}):null,i(ie,{dirty:g,saving:o.saving,solid:r.chosen&&g,failed:o.failed,saveLabel:e.t("settingsSection.save"),revertLabel:e.t("settingsSection.revert"),failedLabel:e.t("settingsSection.saveFailed"),onSave:A,onRevert:()=>{l.current+=1,a(ue(n,t))}})]})})}var en=`
6
+ .im-settings {
7
+ box-sizing: border-box;
8
+ color: var(--foreground);
9
+ display: flex;
10
+ flex-direction: column;
11
+ gap: 0.75rem;
12
+ min-width: 0;
13
+ }
14
+ .im-settings .im-pending {
15
+ display: flex;
16
+ justify-content: center;
17
+ padding: 1.5rem 0;
18
+ }
19
+ .im-settings p {
20
+ margin: 0;
21
+ }
22
+ .im-settings .im-heading {
23
+ margin: 0;
24
+ font-weight: 600;
25
+ }
26
+ .im-settings .im-block {
27
+ box-sizing: border-box;
28
+ display: flex;
29
+ flex-direction: column;
30
+ gap: 0.5rem;
31
+ min-width: 0;
32
+ padding: 0.75rem;
33
+ border: 1px solid var(--border);
34
+ border-radius: var(--control-radius);
35
+ background: var(--card);
36
+ }
37
+ .im-settings .im-collapse {
38
+ display: flex;
39
+ flex-direction: column;
40
+ gap: 0.5rem;
41
+ min-width: 0;
42
+ }
43
+ .im-settings .im-head {
44
+ display: flex;
45
+ flex-wrap: wrap;
46
+ align-items: center;
47
+ gap: 0.5rem;
48
+ min-width: 0;
49
+ }
50
+ .im-settings .im-toggle {
51
+ display: flex;
52
+ flex: 1 1 12rem;
53
+ flex-wrap: wrap;
54
+ align-items: center;
55
+ gap: 0.5rem;
56
+ min-width: 0;
57
+ margin: 0;
58
+ padding: 0;
59
+ border: 0;
60
+ background: transparent;
61
+ color: inherit;
62
+ font: inherit;
63
+ text-align: start;
64
+ cursor: pointer;
65
+ }
66
+ .im-settings .im-chevron {
67
+ flex: none;
68
+ width: 0.4rem;
69
+ height: 0.4rem;
70
+ border-right: 1px solid currentColor;
71
+ border-bottom: 1px solid currentColor;
72
+ transform: rotate(-45deg);
73
+ }
74
+ .im-settings .im-toggle[data-panel-open] .im-chevron {
75
+ transform: rotate(45deg);
76
+ }
77
+ .im-settings .im-title {
78
+ flex: 1 1 auto;
79
+ min-width: 0;
80
+ overflow: hidden;
81
+ text-overflow: ellipsis;
82
+ white-space: nowrap;
83
+ font-weight: 600;
84
+ }
85
+ .im-settings .im-panel {
86
+ display: flex;
87
+ flex-direction: column;
88
+ gap: 0.75rem;
89
+ padding-top: 0.75rem;
90
+ }
91
+ .im-settings .im-form {
92
+ display: grid;
93
+ grid-template-columns: minmax(0, 1fr);
94
+ gap: 0.75rem;
95
+ }
96
+ .im-settings .im-field {
97
+ display: flex;
98
+ flex-direction: column;
99
+ align-items: stretch;
100
+ gap: 0.25rem;
101
+ min-width: 0;
102
+ }
103
+ .im-settings .im-field > * {
104
+ width: 100%;
105
+ min-width: 0;
106
+ }
107
+ .im-settings .im-secret,
108
+ .im-settings .im-inline,
109
+ .im-settings .im-actions {
110
+ display: flex;
111
+ flex-wrap: wrap;
112
+ align-items: center;
113
+ gap: 0.5rem;
114
+ min-width: 0;
115
+ }
116
+ .im-settings .im-secret > :first-child,
117
+ .im-settings .im-inline > :first-child {
118
+ flex: 1 1 12rem;
119
+ min-width: 0;
120
+ }
121
+ .im-settings .im-secret > :not(:first-child),
122
+ .im-settings .im-inline > :not(:first-child) {
123
+ flex: none;
124
+ }
125
+ .im-settings .im-public-value {
126
+ min-width: 0;
127
+ overflow-wrap: anywhere;
128
+ }
129
+ .im-settings .im-small {
130
+ font-size: var(--ui-text-sm);
131
+ line-height: var(--ui-leading-sm);
132
+ }
133
+ .im-settings .im-medium {
134
+ font-size: var(--ui-text-md);
135
+ line-height: var(--ui-leading-md);
136
+ }
137
+ .im-settings .im-muted {
138
+ color: var(--muted-foreground);
139
+ }
140
+ .im-settings .im-issue {
141
+ color: var(--destructive-foreground);
142
+ }
143
+ .im-settings .im-wide {
144
+ width: 100%;
145
+ }
146
+ .im-settings .im-flow,
147
+ .im-settings .im-result {
148
+ display: flex;
149
+ flex-direction: column;
150
+ gap: 0.5rem;
151
+ min-width: 0;
152
+ }
153
+ .im-settings .im-flow {
154
+ padding-top: 0.75rem;
155
+ border-top: 1px solid var(--border);
156
+ }
157
+ .im-settings .im-qr {
158
+ align-self: flex-start;
159
+ line-height: 0;
160
+ }
161
+ .im-settings .im-steps {
162
+ display: flex;
163
+ flex-direction: column;
164
+ gap: 0.25rem;
165
+ margin: 0;
166
+ padding: 0;
167
+ list-style: none;
168
+ }
169
+ .im-settings .im-steps li {
170
+ display: flex;
171
+ justify-content: space-between;
172
+ gap: 0.75rem;
173
+ }
174
+ .im-settings .im-steps li[data-state="failed"] {
175
+ color: var(--destructive-foreground);
176
+ }
177
+ .im-settings .im-detail {
178
+ margin: 0;
179
+ padding: 0.5rem;
180
+ border: 1px solid var(--border);
181
+ border-radius: var(--control-radius);
182
+ font-family: inherit;
183
+ white-space: pre-wrap;
184
+ overflow-wrap: anywhere;
185
+ }
186
+ .im-settings .im-badge {
187
+ margin-inline-start: 0.375rem;
188
+ padding: 0 0.375rem;
189
+ border: 1px solid var(--border);
190
+ border-radius: var(--control-radius);
191
+ color: var(--muted-foreground);
192
+ }
193
+ @media (min-width: 640px) {
194
+ .im-settings .im-form {
195
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
196
+ }
197
+ .im-settings .im-span {
198
+ grid-column: 1 / -1;
199
+ }
200
+ }
201
+ `;var nn={};function tn(e){let n=e.bridge.i18n.usePluginTranslation(),t=T(()=>k(e.environmentId),[e.environmentId]),r=e.bridge.commands.useQuery(Ie,nn,t),l=T(()=>$e(r.data),[r.data]),[o,a]=p(null),[s,g]=p(null),[v,w]=p(!1),[I,h]=p(!1),[C,A]=p(!1),[c,m]=p(null);if(l!==null&&l!==o&&a(l),s!==null){let S=qe(s,{view:l?.view??null,isPending:r.isPending,failed:r.error!==null});S!==s&&g(S)}let u=s?.view??l?.view??o?.view??null,b=l??o,L=l===null&&r.data!==null&&!r.isPending,pe=T(()=>Ee(b?.targetColumns??[],u?.bots??[],S=>n(`platform.${S}`)),[b,u,n]);function V(S){g({view:S,phase:"asked"}),r.refresh()}function H(){g(null),r.refresh()}let F;return r.isUnavailable?F=i(be,{variant:"warning",message:n("settingsSection.unavailable"),retryLabel:n("settingsSection.retry"),onRetry:H}):u===null&&r.isPending?F=i("div",{className:"im-pending",children:i(N,{size:"md"})}):u===null||b===null?F=i(be,{variant:"error",message:n("settingsSection.loadFailed"),retryLabel:n("settingsSection.retry"),onRetry:H}):F=d(Ze,{activeId:c,activate:m,children:[r.error!==null||L?i(be,{variant:"error",message:n("settingsSection.loadFailed"),retryLabel:n("settingsSection.retry"),onRetry:H}):null,i(Xe,{view:u,environmentId:e.environmentId,bridge:e.bridge,t:n,onSaved:V}),u.bots.map(S=>i(ve,{bot:S,columns:b.columns,proxies:b.proxies,environmentId:e.environmentId,bridge:e.bridge,t:n,onSaved:V,onDiscard:()=>{}},S.rowId)),v?i(ve,{bot:null,columns:b.columns,proxies:b.proxies,environmentId:e.environmentId,bridge:e.bridge,t:n,onSaved:S=>{w(!1),V(S)},onDiscard:()=>w(!1)},de.newSlot):null,u.bots.length===0&&!v?i(Fe,{title:n("settingsSection.empty")}):null,d("div",{className:"im-actions",children:[i(y,{variant:"outline",disabled:v,onClick:()=>{w(!0),m(G(de.newSlot,null))},children:n("settingsSection.addBot")}),d(y,{variant:"outline",disabled:C,onClick:()=>A(!0),children:[n(D.labelKey),i("span",{className:"im-badge im-small",children:n(D.badgeKey)})]})]}),i("p",{className:"im-small im-muted",children:n(D.warningKey)}),C?d("section",{className:"im-block",children:[i("p",{className:"im-small im-muted",children:n(D.descriptionKey)}),i(oe,{bridge:e.bridge,command:Te,payload:nn,items:"snapshots",environmentId:e.environmentId,t:n,onSettled:S=>{S.kind==="done"&&H()},onClose:()=>A(!1)})]}):null,i("h3",{className:"im-heading im-medium",children:n("settings.deliveryTargets.label")}),i("p",{className:"im-small im-muted",children:n("settingsSection.target.description")}),u.targets.map(S=>i(Se,{target:S,columns:pe,proxies:b.proxies,environmentId:e.environmentId,bridge:e.bridge,t:n,onSaved:V,onDiscard:()=>{}},S.rowId)),I?i(Se,{target:null,columns:pe,proxies:b.proxies,environmentId:e.environmentId,bridge:e.bridge,t:n,onSaved:S=>{h(!1),V(S)},onDiscard:()=>h(!1)},ce.newSlot):null,i("div",{className:"im-actions",children:i(y,{variant:"outline",disabled:I,onClick:()=>{h(!0),m(G(ce.newSlot,null))},children:n("settingsSection.target.add")})})]}),i(Be,{bridge:e.bridge,children:d("div",{className:"im-settings",children:[i("style",{children:en}),i("h2",{className:"im-heading im-medium",children:n("settings.title")}),F]})})}function be(e){return d(X,{variant:e.variant,layout:"inline",children:[i(ee,{children:e.message}),i(De,{children:i(y,{variant:"ghost",size:"sm",onClick:e.onRetry,children:e.retryLabel})})]})}function fn(e){return{slots:[{name:"settings.section",order:20,component(n){return i(tn,{bridge:e,environmentId:n.environmentId??null},n.environmentId??"")}}]}}export{fn as default};