@engenty/wizards-runtime 0.16.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/apps/runtime/dist/agents/studio-assistant.js +13 -6
  2. package/apps/runtime/dist/assistant/knows.js +15 -2
  3. package/apps/runtime/dist/broker/call.js +16 -3
  4. package/apps/runtime/dist/broker/grant.js +25 -1
  5. package/apps/runtime/dist/broker/index.js +2 -2
  6. package/apps/runtime/dist/broker/log.js +30 -11
  7. package/apps/runtime/dist/broker/rwx.js +14 -2
  8. package/apps/runtime/dist/broker/send.js +84 -32
  9. package/apps/runtime/dist/connectors/space-connections.js +47 -2
  10. package/apps/runtime/dist/docs/dev/broker.md +72 -26
  11. package/apps/runtime/dist/docs/dev/plugins/space.md +13 -2
  12. package/apps/runtime/dist/docs/user-guide/capabilities.md +51 -7
  13. package/apps/runtime/dist/docs/user-guide/connectors.md +6 -3
  14. package/apps/runtime/dist/docs/user-guide/protocol.md +30 -4
  15. package/apps/runtime/dist/docs/user-guide/together.md +4 -4
  16. package/apps/runtime/dist/elements/knowledge.js +16 -12
  17. package/apps/runtime/dist/engine/steps.js +3 -2
  18. package/apps/runtime/dist/index.js +8 -0
  19. package/apps/runtime/dist/live/hub.js +17 -3
  20. package/apps/runtime/dist/live/origin.js +6 -4
  21. package/apps/runtime/dist/live/views.js +38 -7
  22. package/apps/runtime/dist/models.js +18 -0
  23. package/apps/runtime/dist/prompts/tools.md +1 -1
  24. package/apps/runtime/dist/routes/api.js +2 -2
  25. package/apps/runtime/dist/routes/broker.js +59 -20
  26. package/apps/runtime/dist/routes/live.js +4 -2
  27. package/apps/runtime/dist/routes/studio.js +13 -2
  28. package/apps/runtime/dist/services/api.js +4 -2
  29. package/apps/runtime/dist/services/errors.js +1 -0
  30. package/apps/runtime/dist/services/knowledge.js +93 -27
  31. package/apps/runtime/dist/services/members-studio.js +22 -2
  32. package/apps/runtime/dist/services/space-categories.js +83 -5
  33. package/apps/runtime/dist/services/space-index.js +77 -21
  34. package/apps/runtime/dist/services/space-origin.js +28 -11
  35. package/apps/runtime/dist/services/work-ai.js +15 -5
  36. package/apps/runtime/dist/sharing/jobs.js +2 -0
  37. package/apps/runtime/dist/sync/hub.js +17 -3
  38. package/apps/runtime/dist/texts.js +6 -4
  39. package/apps/runtime/dist/tools/index.js +13 -7
  40. package/apps/runtime/dist/tools/web-search.js +36 -0
  41. package/apps/web/dist/assets/{AboutDialog-BCcD8hKm.js → AboutDialog-B2Xmxyj4.js} +1 -1
  42. package/apps/web/dist/assets/{BlockEditor-DgaUm2pR.js → BlockEditor-D0HoUSih.js} +1 -1
  43. package/apps/web/dist/assets/CapabilitiesPage-C1th2cZE.js +2 -0
  44. package/apps/web/dist/assets/{ChangelogDialog-B08elwyr.js → ChangelogDialog-BIrJbAKi.js} +1 -1
  45. package/apps/web/dist/assets/{CodeEditor-BiyOk_SC.js → CodeEditor-DUVcXI5P.js} +1 -1
  46. package/apps/web/dist/assets/{EditorPage-EMFTHEYD.js → EditorPage-56sIqEfF.js} +1 -1
  47. package/apps/web/dist/assets/{FlowPreview-DF_6TvZ0.js → FlowPreview-BIag8_Be.js} +1 -1
  48. package/apps/web/dist/assets/{LangSwitch-Ba4OWLzJ.js → LangSwitch-CJ00IgaO.js} +1 -1
  49. package/apps/web/dist/assets/{Marketplace-DqziLf66.js → Marketplace-D7-ot9Dz.js} +2 -2
  50. package/apps/web/dist/assets/{NewWizardChannels-CsIGp0nZ.js → NewWizardChannels-DI3SQ4iS.js} +1 -1
  51. package/apps/web/dist/assets/{NewWizardPage-CzQAkKMy.js → NewWizardPage-CytheHxX.js} +1 -1
  52. package/apps/web/dist/assets/{OnboardingPage-B9gr2OX5.js → OnboardingPage-_91Pa8Ad.js} +1 -1
  53. package/apps/web/dist/assets/{PreviewPane-DSOV3o-1.js → PreviewPane-BDsYm-_K.js} +2 -2
  54. package/apps/web/dist/assets/ProtocolSection-D_zaxHEL.js +1 -0
  55. package/apps/web/dist/assets/{PublicRunner-BVs8-Vu3.js → PublicRunner-CEgXSk3r.js} +1 -1
  56. package/apps/web/dist/assets/{ReadOnly--4CIJCDD.js → ReadOnly-CWf5x74a.js} +1 -1
  57. package/apps/web/dist/assets/SettingsPage-Dr8SDk-L.js +2 -0
  58. package/apps/web/dist/assets/{SetupPage-9Zk-KUGA.js → SetupPage-B68n0l4I.js} +1 -1
  59. package/apps/web/dist/assets/{SharePage-D_Ab0gjr.js → SharePage-DfznN7ar.js} +1 -1
  60. package/apps/web/dist/assets/{SkillEditor-DvtameHg.js → SkillEditor-BIcIczRc.js} +1 -1
  61. package/apps/web/dist/assets/{Skills-Cf1Kl4Fy.js → Skills-CN4QE7Kx.js} +1 -1
  62. package/apps/web/dist/assets/{SpacePage-CyqVzX9b.js → SpacePage-DiVTwhnJ.js} +2 -2
  63. package/apps/web/dist/assets/{UpdateCheck-DweZBVP6.js → UpdateCheck-QhBI3rlQ.js} +2 -2
  64. package/apps/web/dist/assets/changelog-a_CuplMX.js +1 -0
  65. package/apps/web/dist/assets/{code-editor-B1RbFTAZ.js → code-editor-DkPo1C-L.js} +2 -2
  66. package/apps/web/dist/assets/{host-CKS5U5Vg.js → host-D6H6Z9Jp.js} +6 -6
  67. package/apps/web/dist/assets/i18n-BaPKbQ1s.js +55 -0
  68. package/apps/web/dist/assets/{index-w-3J3ZJ9.css → index-CCUG6Vnh.css} +1 -1
  69. package/apps/web/dist/assets/{index-Ckcn5vy7.js → index-De0Wb42y.js} +3 -3
  70. package/apps/web/dist/assets/{read-aloud-Bq88XUHC.js → read-aloud-CnFwDSGD.js} +1 -1
  71. package/apps/web/dist/assets/{runners-DvYVe9Dt.js → runners-0sTPbWzr.js} +1 -1
  72. package/apps/web/dist/assets/{session-D2bjiA3P.js → session-BMiUrqHg.js} +1 -1
  73. package/apps/web/dist/assets/{theme-CNJIC2be.js → theme-CkNTe-_Z.js} +1 -1
  74. package/apps/web/dist/assets/{ui-Mplfhz_Z.js → ui-DAk_vjrL.js} +1 -1
  75. package/apps/web/dist/assets/{useMutation-8QRM-z4M.js → useMutation-isHfB33W.js} +1 -1
  76. package/apps/web/dist/assets/{viewers-CEocUV_2.js → viewers-ijNZHJFG.js} +2 -2
  77. package/apps/web/dist/index.html +12 -12
  78. package/apps/web/dist/mcp/flow.html +2 -2
  79. package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +7 -2
  80. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +13 -1
  81. package/node_modules/@engenty/wizards-shared/dist/connectors.js +8 -0
  82. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +12 -0
  83. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +12 -0
  84. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +3 -0
  85. package/node_modules/@engenty/wizards-shared/dist/run.js +6 -0
  86. package/node_modules/@engenty/wizards-shared/dist/spaces.d.ts +3 -2
  87. package/node_modules/@engenty/wizards-shared/dist/spaces.js +12 -3
  88. package/package.json +1 -1
  89. package/plugin/.claude-plugin/plugin.json +1 -1
  90. package/plugin/plugin.json +1 -1
  91. package/apps/web/dist/assets/CapabilitiesPage-DuJJV1ll.js +0 -2
  92. package/apps/web/dist/assets/SettingsPage-z2u8lSe2.js +0 -2
  93. package/apps/web/dist/assets/changelog-C85v9OWg.js +0 -1
  94. package/apps/web/dist/assets/connection-sign-in-CaVvh5GQ.js +0 -1
  95. package/apps/web/dist/assets/i18n-Bymk5Ev-.js +0 -55
@@ -417,12 +417,17 @@ export interface PluginSpaceData {
417
417
  list(space: string): Promise<PluginSpaceItem[]>;
418
418
  /**
419
419
  * The space's own pages (not a wizard's), whoever wrote them, with their Markdown: for a
420
- * plugin that reads what the space knows. `parent`: only the pages under that page.
420
+ * plugin that reads what the space knows. `parent`: only the pages under that page. Only the
421
+ * pages its reader may read by the space's rules: whom the plugin was called for (a step's or
422
+ * a chat's person or guest, an HTTP route's person, the runtime itself in a job) and the plugin.
421
423
  */
422
424
  readPages(space: string, opts?: {
423
425
  parent?: string;
424
426
  }): Promise<PluginSpacePage[]>;
425
- /** The space's files of a kind (`document` when left out), newest first. */
427
+ /**
428
+ * The space's files of a kind (`document` when left out), newest first. Documents only as far
429
+ * as the reader may read them, as `readPages`.
430
+ */
426
431
  files(space: string, kind?: "logo" | "asset" | "document" | "pattern" | "picture"): Promise<PluginSpaceFile[]>;
427
432
  /** One file of the space with its bytes: a price list someone dropped into Knowledge. */
428
433
  readFile(space: string, fileId: string): Promise<PluginSpaceFile & {
@@ -89,7 +89,7 @@ export type CriticalKind = (typeof CRITICAL_KINDS)[number];
89
89
  * Why the broker did not run a call (the runtime's broker/call.ts `Refusal`), as the log's
90
90
  * `result` and „Was darf …?“ name it. The Protokoll page has words for each one.
91
91
  */
92
- export declare const BROKER_REFUSALS: readonly ["not_connected", "no_action", "not_in_grant", "denied", "declined", "nobody", "needs_approval", "ai_step_writes", "not_allowed_recipient", "run_limit", "day_limit"];
92
+ export declare const BROKER_REFUSALS: readonly ["not_connected", "no_action", "not_in_grant", "denied", "declined", "nobody", "needs_approval", "ai_step_writes", "not_allowed_recipient", "channel_not_fixed", "run_limit", "day_limit"];
93
93
  export type BrokerRefusal = (typeof BROKER_REFUSALS)[number];
94
94
  /** A person of the organization, as Fähigkeiten › Protokoll names them and „Was darf …?“ offers them. */
95
95
  export interface ProtocolPerson {
@@ -205,6 +205,8 @@ export interface BrokerAnswer {
205
205
  reason: string;
206
206
  refused?: BrokerRefusal;
207
207
  admins?: true;
208
+ /** A guest's post from a fixed step: it runs only to the channel the published step fixes. */
209
+ fixedChannel?: true;
208
210
  }
209
211
  /** What an action does, as the rules see it. */
210
212
  export declare const CONNECTION_ACTION_KINDS: readonly ["read", "write", "destructive", "send"];
@@ -244,6 +246,8 @@ export interface SpaceConnectionView {
244
246
  actions: string[];
245
247
  /** The plugin that set it up, where one did. */
246
248
  plugin: string | null;
249
+ /** That plugin by name, as the runtime carries it; its id where it is not loaded. */
250
+ pluginName?: string | null;
247
251
  /** A `space` sign-in: the account as the provider names it; null until an admin signed in. */
248
252
  account: {
249
253
  label: string;
@@ -262,6 +266,14 @@ export interface SpaceConnectionView {
262
266
  /** A `person` sign-in: how many people signed in; never who. */
263
267
  signedIn: number;
264
268
  }
269
+ /**
270
+ * Whether guests reach a connection: it is for everyone and signs in as the space. Where each
271
+ * person signs in a guest has no sign-in of their own, whatever the audience says.
272
+ */
273
+ export declare function reachedByGuests(c: {
274
+ audience: ConnectionAudience;
275
+ signIn: ConnectionSignIn;
276
+ }): boolean;
265
277
  /** A field an `api_key` connector asks for when someone signs in. */
266
278
  export interface ConnectorKeyField {
267
279
  key: string;
@@ -30,6 +30,7 @@ export const BROKER_REFUSALS = [
30
30
  "needs_approval",
31
31
  "ai_step_writes",
32
32
  "not_allowed_recipient",
33
+ "channel_not_fixed",
33
34
  "run_limit",
34
35
  "day_limit",
35
36
  ];
@@ -50,3 +51,10 @@ export const CONNECTION_LIMITS = {
50
51
  /** Connections one space may hold. */
51
52
  perSpace: 200,
52
53
  };
54
+ /**
55
+ * Whether guests reach a connection: it is for everyone and signs in as the space. Where each
56
+ * person signs in a guest has no sign-in of their own, whatever the audience says.
57
+ */
58
+ export function reachedByGuests(c) {
59
+ return c.audience === "all" && c.signIn === "space";
60
+ }
@@ -177,6 +177,12 @@ export declare const FEATURES: {
177
177
  readonly label: "Pictures in Wissen by what they show";
178
178
  readonly hint: "Pictures and PDF pages are embedded as pictures where the embedding model takes them (EmbeddingGemma 2), so a search finds a photo by what it shows (docs/plans/media-and-files.md).";
179
179
  };
180
+ readonly gatewaySearch: {
181
+ readonly kind: "release";
182
+ readonly default: false;
183
+ readonly label: "Web search through the gateway";
184
+ readonly hint: "web_search through the gateway's /v1/web/search for every model and client, in place of the model's own search. On once the gateway has its provider's key.";
185
+ };
180
186
  readonly dateien: {
181
187
  readonly kind: "release";
182
188
  readonly default: false;
@@ -195,4 +201,10 @@ export declare const FEATURES: {
195
201
  readonly label: "Own API keys";
196
202
  readonly hint: "The organization puts its providers' keys into the cloud studio instead of running on credits.";
197
203
  };
204
+ readonly personSignIn: {
205
+ readonly kind: "plan";
206
+ readonly default: true;
207
+ readonly label: "Each person signs in to a connection";
208
+ readonly hint: "A space's connection may have each person sign in with their own account. Without it a connection signs in as the space.";
209
+ };
198
210
  };
@@ -169,6 +169,12 @@ export const FEATURES = {
169
169
  label: "Pictures in Wissen by what they show",
170
170
  hint: "Pictures and PDF pages are embedded as pictures where the embedding model takes them (EmbeddingGemma 2), so a search finds a photo by what it shows (docs/plans/media-and-files.md).",
171
171
  },
172
+ gatewaySearch: {
173
+ kind: "release",
174
+ default: false,
175
+ label: "Web search through the gateway",
176
+ hint: "web_search through the gateway's /v1/web/search for every model and client, in place of the model's own search. On once the gateway has its provider's key.",
177
+ },
172
178
  dateien: {
173
179
  kind: "release",
174
180
  default: false,
@@ -187,4 +193,10 @@ export const FEATURES = {
187
193
  label: "Own API keys",
188
194
  hint: "The organization puts its providers' keys into the cloud studio instead of running on credits.",
189
195
  },
196
+ personSignIn: {
197
+ kind: "plan",
198
+ default: true,
199
+ label: "Each person signs in to a connection",
200
+ hint: "A space's connection may have each person sign in with their own account. Without it a connection signs in as the space.",
201
+ },
190
202
  };
@@ -396,6 +396,9 @@ declare const NOTES_EN: {
396
396
  readonly connectionEachPersonSignsIn: "Each person signs in to this connection themselves.";
397
397
  readonly connectionSignsInAsSpace: "This connection signs in as the space. Its admins sign it in.";
398
398
  readonly connectionNotForYou: "This connection is not open to you.";
399
+ readonly personSignInNotInPlan: "The {plan} plan doesn’t include each person signing in. A connection signs in as the space.";
400
+ readonly personSignInNotInOrganizationPlan: "Your organization’s plan doesn’t include each person signing in. A connection signs in as the space.";
401
+ readonly pluginConnectionSignsInAsSpace: "A plugin uses this connection. It signs in as the space.";
399
402
  readonly connectorSignsIn: "{name} is connected by signing in, not with keys.";
400
403
  readonly connectorTakesKeys: "{name} takes keys, not a sign-in.";
401
404
  readonly notFound: "This doesn’t exist or was deleted.";
@@ -222,6 +222,9 @@ const NOTES_EN = {
222
222
  connectionEachPersonSignsIn: "Each person signs in to this connection themselves.",
223
223
  connectionSignsInAsSpace: "This connection signs in as the space. Its admins sign it in.",
224
224
  connectionNotForYou: "This connection is not open to you.",
225
+ personSignInNotInPlan: "The {plan} plan doesn’t include each person signing in. A connection signs in as the space.",
226
+ personSignInNotInOrganizationPlan: "Your organization’s plan doesn’t include each person signing in. A connection signs in as the space.",
227
+ pluginConnectionSignsInAsSpace: "A plugin uses this connection. It signs in as the space.",
225
228
  connectorSignsIn: "{name} is connected by signing in, not with keys.",
226
229
  connectorTakesKeys: "{name} takes keys, not a sign-in.",
227
230
  notFound: "This doesn’t exist or was deleted.",
@@ -615,6 +618,9 @@ const NOTES_DE = {
615
618
  connectionEachPersonSignsIn: "Bei dieser Verbindung meldet sich jede Person selbst an.",
616
619
  connectionSignsInAsSpace: "Diese Verbindung meldet sich als Space an. Die Admins melden sie an.",
617
620
  connectionNotForYou: "Diese Verbindung steht dir nicht offen.",
621
+ personSignInNotInPlan: "Im Paket {plan} meldet sich nicht jede Person selbst an. Eine Verbindung meldet sich als Space an.",
622
+ personSignInNotInOrganizationPlan: "Im Paket deiner Organisation meldet sich nicht jede Person selbst an. Eine Verbindung meldet sich als Space an.",
623
+ pluginConnectionSignsInAsSpace: "Ein Plugin nutzt diese Verbindung. Sie meldet sich als Space an.",
618
624
  connectorSignsIn: "{name} wird per Anmeldung verbunden, nicht mit Keys.",
619
625
  connectorTakesKeys: "{name} nimmt Keys, keine Anmeldung.",
620
626
  notFound: "Das gibt es nicht oder nicht mehr.",
@@ -60,8 +60,9 @@ export declare const PAGE_LIMITS: {
60
60
  /** A page's address: lower-case letters a–z, digits and hyphens, not at the start or end. */
61
61
  export declare const PAGE_SLUG: RegExp;
62
62
  /**
63
- * Addresses a public space never takes on `<team>.wizards.page`: the client portal's
64
- * (docs/plans/client-portal.md). The Manage-App keeps the same word reserved.
63
+ * Addresses a public space never takes on `<team>.wizards.page`: the client portal's, the portal
64
+ * app's health check and the visitors' routes (docs/plans/org-page.md). The Manage-App keeps the
65
+ * same words reserved.
65
66
  */
66
67
  export declare const RESERVED_PAGE_SLUGS: readonly string[];
67
68
  /** A name as a page address: `Müller & Söhne GmbH` → `mueller-soehne-gmbh`. */
@@ -91,10 +91,19 @@ export const PAGE_LIMITS = { slug: 48, title: 80, headline: 160, intro: 600 };
91
91
  /** A page's address: lower-case letters a–z, digits and hyphens, not at the start or end. */
92
92
  export const PAGE_SLUG = /^[a-z0-9](?:[a-z0-9-]{0,46}[a-z0-9])?$/;
93
93
  /**
94
- * Addresses a public space never takes on `<team>.wizards.page`: the client portal's
95
- * (docs/plans/client-portal.md). The Manage-App keeps the same word reserved.
94
+ * Addresses a public space never takes on `<team>.wizards.page`: the client portal's, the portal
95
+ * app's health check and the visitors' routes (docs/plans/org-page.md). The Manage-App keeps the
96
+ * same words reserved.
96
97
  */
97
- export const RESERVED_PAGE_SLUGS = ["portal"];
98
+ export const RESERVED_PAGE_SLUGS = [
99
+ "portal",
100
+ "health",
101
+ "chat",
102
+ "kontakt",
103
+ "contact",
104
+ "termin",
105
+ "booking",
106
+ ];
98
107
  /** A name as a page address: `Müller & Söhne GmbH` → `mueller-soehne-gmbh`. */
99
108
  export function pageSlugOf(name) {
100
109
  return (name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engenty/wizards-runtime",
3
- "version": "0.16.2",
3
+ "version": "0.17.0",
4
4
  "description": "Make a wish. Get your wizard. It guides you step by step. Let AI do the work. Runs on your machine, on the AI subscription you already have. The runtime, which `npx wizards` installs.",
5
5
  "license": "FSL-1.1-MIT AND CC-BY-4.0",
6
6
  "homepage": "https://engenty.ai",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wizards",
3
3
  "displayName": "engenty wizards",
4
- "version": "0.16.2",
4
+ "version": "0.17.0",
5
5
  "description": "Build page-by-page AI wizards that people open on a shared link — designed, tested and published from Claude Code — run your published ones in the chat, and keep them in a pane beside it.",
6
6
  "author": {
7
7
  "name": "engenty"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "engenty-wizards",
4
- "version": "0.16.2",
4
+ "version": "0.17.0",
5
5
  "description": "Build page-by-page AI wizards that people open on a shared link, test and publish them from the chat, and run your published ones here.",
6
6
  "author": {
7
7
  "name": "engenty",
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SkillEditor-DvtameHg.js","assets/rolldown-runtime-hePW80VL.js","assets/jsx-runtime-BNakU3Ej.js","assets/ui-Mplfhz_Z.js","assets/preload-helper-DpV6A1kQ.js","assets/marked.esm-DQ7XA7AC.js","assets/i18n-Bymk5Ev-.js","assets/useMutation-8QRM-z4M.js","assets/Skills-Cf1Kl4Fy.js","assets/circle-check-DDLzlcXP.js","assets/upload-CAlHC232.js","assets/code-xml-S4IFi5Jc.js","assets/scroll-text-BEnPzQEi.js","assets/eye-TJSuiHHO.js","assets/code-editor-B1RbFTAZ.js","assets/dist-CQpLJoQZ.js","assets/w3c-keyname-BOAvb0qz.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$t as r,Cn as i,Q as a,S as o,Tn as s,Vr as c,X as l,Yn as u,Zn as d,an as f,cr as p,en as m,g as h,gr as g,hn as _,hr as v,ln as y,lr as b,mr as x,nn as S,on as C,or as w,pn as T,pr as E,rn as D,tn as O,un as k}from"./ui-Mplfhz_Z.js";import{t as A}from"./useMutation-8QRM-z4M.js";import{t as j}from"./preload-helper-DpV6A1kQ.js";import{d as M,i as N,u as P}from"./marked.esm-DQ7XA7AC.js";import{In as ee,Qn as te,_n as ne,a as re,fn as F,l as ie,m as ae,p as I,pn as oe,t as se,vn as ce}from"./host-CKS5U5Vg.js";import{a as le,f as ue,o as de,r as fe,s as L}from"./Skills-Cf1Kl4Fy.js";import{n as R}from"./volume-2-BqlBtCIJ.js";import{i as z,n as B,o as pe,r as me,s as he,t as V}from"./connection-sign-in-CaVvh5GQ.js";import{t as H}from"./scroll-text-BEnPzQEi.js";import{b as ge,d as U,n as _e,u as W}from"./session-D2bjiA3P.js";import{n as G,s as K}from"./i18n-Bymk5Ev-.js";import{a as ve,c as ye,d as be,f as xe,i as Se,m as Ce,p as we,r as Te,u as q}from"./UpdateCheck-DweZBVP6.js";var Ee={name:`compass`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16.24 7.76-1.804 5.411a2 2 0 0 1-1.265 1.265L7.76 16.24l1.804-5.411a2 2 0 0 1 1.265-1.265z`,key:`9ktpf1`}]]};Ee.node;var De=M(Ee),J=e(t(),1),Oe=[`admins`,`members`,`all`],ke=[`read`,`write`,`destructive`,`send`],Ae=[`allow`,`ask`,`deny`],je={name:80,perSpace:200},Y=e(n(),1),X=e=>[`space-connections`,e];function Me(e){return g({enabled:!!e,queryKey:X(e),queryFn:()=>a.get(`/api/studio/spaces/${e}/connections`)})}function Ne(e){return g({enabled:!!e,queryKey:l.connectors(e),queryFn:()=>a.get(`/api/studio/spaces/${e}/connectors`)})}function Pe(e,t,n){let r=new Set(t.map(e=>e.connectorId));return e.filter(e=>e.sourceKind===`builtin`&&!r.has(e.id)&&(e.usable||n))}var Z={admins:`connection.audience.admins`,members:`connection.audience.members`,all:`connection.audience.all`},Fe={admins:`connection.audience.adminsHint`,members:`connection.audience.membersHint`,all:`connection.audience.allHint`},Ie={read:`connection.kind.read`,write:`connection.kind.write`,destructive:`connection.kind.destructive`,send:`connection.kind.send`},Le={read:`connection.kind.readHint`,write:`connection.kind.writeHint`,destructive:`connection.kind.destructiveHint`,send:`connection.kind.sendHint`},Re={allow:`connection.outcome.allow`,ask:`connection.outcome.ask`,deny:`connection.outcome.deny`},ze={space:`connection.signIn.space`,person:`connection.signIn.person`},Be={space:`connection.signIn.spaceHint`,person:`connection.signIn.personHint`},Ve=e=>new Intl.DateTimeFormat(G,{dateStyle:`medium`}).format(new Date(e));function He(e){let t=Math.round((Date.parse(e)-Date.now())/1e3),n=new Intl.RelativeTimeFormat(G,{numeric:`auto`});for(let[e,r]of[[`day`,86400],[`hour`,3600],[`minute`,60]])if(Math.abs(t)>=r)return n.format(Math.round(t/r),e);return n.format(0,`minute`)}function Q(e){let t=e.connector?.name??e.connectorId;return e.name===t?e.name:`${t} · ${e.name}`}function Ue(e){return e.signIn===`space`?e.account?K(`connection.asSpaceAccount`,{label:e.account.label}):K(`connection.asSpaceNotYet`):K(`connection.eachPersonCount`,{n:e.signedIn})}function We(e){return e.lastUsedAt?K(`connection.lastUsed`,{when:He(e.lastUsedAt)}):K(`connection.neverUsed`)}function Ge(e){let t=e.toLowerCase().replace(/^https?:\/\//,``).split(`/`)[0].split(`.`);return t.length>1?t[t.length-2]:t[0]}function Ke(e,t){if(!e)return null;let n=t.find(t=>t.id===e);if(n)return{connectorId:n.id};let r=t.find(t=>t.domain&&t.domain===e.toLowerCase());if(r)return{connectorId:r.id};let i=Ge(e),a=t.find(e=>e.sourceKind===`builtin`&&(e.id===i||e.id.endsWith(`-${i}`)||e.name.toLowerCase()===i));return a?{connectorId:a.id}:e.includes(`.`)?{domain:e}:null}function qe({name:e,large:t}){return(0,Y.jsx)(`span`,{"aria-hidden":`true`,className:_(`flex shrink-0 items-center justify-center rounded-lg bg-paper-2 font-semibold text-ink-2`,t?`size-12 text-[0.9375rem]`:`size-9 text-[0.75rem]`),children:_e(e)||`?`})}function Je(){let[e,t]=p(),{space:n}=W(),r=U(),{narrow:i}=we(),a=c(),o=n?.id??``,s=e.get(`show`),l=e.get(`setup`),u=r&&!n?.readOnly,d=Me(o),f=Ne(o),m=d.data?.connections??[],h=m.find(e=>e.id===s)??null;be(h?Q(h):null),me((0,J.useCallback)(()=>{a.invalidateQueries({queryKey:[`space-connections`]}),a.invalidateQueries({queryKey:[`person-sign-ins`]})},[a])),(0,J.useEffect)(()=>{i||I().scrollTo({top:0})},[i,s]);let g=e=>i?t({show:e}):t(e===`all`?{}:{show:e},{replace:!0});return(0,Y.jsx)(Y.Fragment,{children:n?(0,Y.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:h?(0,Y.jsx)(Qe,{connection:h,connector:f.data?.find(e=>e.id===h.connectorId),writable:u,onGone:()=>g(`all`)},h.id):(0,Y.jsx)(Ye,{spaceId:n.id,connections:m,loading:d.isPending,error:d.error,connectors:f.data??[],writable:u,setup:l,onOpen:g,onSetUp:e=>{t({setup:e},{replace:!i}),i||I().scrollTo({top:0,behavior:`smooth`})},onSetUpDone:()=>t({},{replace:!0})})}):null})}function Ye({spaceId:e,connections:t,loading:n,error:i,connectors:a,writable:s,setup:c,onOpen:l,onSetUp:u,onSetUpDone:d}){let f=F(`unsetConnectors`),p=(0,J.useRef)(null),h=c&&a.length?Ke(c,a):null,g=h&&`domain`in h?h.domain:null;(0,J.useEffect)(()=>{g&&p.current?.scrollIntoView({block:`start`,behavior:`smooth`})},[g]);let v=Pe(a,t,f);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(o,{title:K(`capabilities.connectors`),hint:K(`capabilities.connectors.hint`),plain:!0,action:s&&c===null?(0,Y.jsxs)(r,{size:`sm`,onClick:()=>u(``),children:[(0,Y.jsx)(N,{className:`size-4`}),` `,K(`capabilities.connectors.add`)]}):null,children:[s&&c!==null?(0,Y.jsx)(Ze,{spaceId:e,connectors:a,initial:h&&`connectorId`in h?h.connectorId:``,onCancel:d,onDone:l},h&&`connectorId`in h?h.connectorId:`new`):null,(0,Y.jsx)(`h3`,{className:`px-1 pt-2 font-display font-semibold text-base`,children:K(`capabilities.inSpace`)}),i?(0,Y.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:i.message}):t.length?(0,Y.jsx)(m,{className:`flex flex-col divide-y divide-border-soft p-0`,children:t.map(e=>(0,Y.jsx)(Xe,{connection:e,onOpen:()=>l(e.id)},e.id))}):n?null:(0,Y.jsx)(m,{children:(0,Y.jsx)(D,{children:K(s?`capabilities.connectors.noneAdmin`:`capabilities.connectors.none`)})})]}),v.length?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 px-1`,children:[(0,Y.jsx)(`h3`,{className:`font-semibold text-[0.875rem]`,children:K(`capabilities.connectors.builtin`)}),(0,Y.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(s?`capabilities.connectors.builtinHint`:`capabilities.connectors.builtinHintMember`)}),(0,Y.jsx)(`ul`,{className:`flex flex-wrap gap-1.5`,children:v.map(e=>(0,Y.jsx)(`li`,{children:s&&e.usable?(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),title:K(`capabilities.connectors.setUpNamed`,{name:e.name}),className:`inline-flex h-8 items-center gap-1.5 rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-2 transition hover:bg-paper-3 hover:text-ink`,children:[(0,Y.jsx)(N,{className:`size-3.5`,"aria-hidden":`true`}),e.name]}):(0,Y.jsx)(`span`,{title:e.missingSetup??void 0,className:_(`inline-flex h-8 items-center rounded-full bg-paper-2 px-3 text-[0.8125rem] text-ink-3`,!e.usable&&`opacity-60`),children:e.name})},e.id))})]}):null,(0,Y.jsx)(`div`,{ref:p,className:`scroll-mt-6`,children:(0,Y.jsx)(o,{title:K(`capabilities.connectors.more`),hint:K(`capabilities.connectors.moreHint`),children:(0,Y.jsx)(he,{spaceId:e,readOnly:!s,embedded:!0,onSetUp:s?u:void 0,domain:g})})})]})}function Xe({connection:e,onOpen:t}){let n=c(),r=z(`/api/studio/connections/${encodeURIComponent(e.id)}/my-sign-in`,()=>n.invalidateQueries({queryKey:X(e.spaceId)})),i=Object.values(e.rules).includes(`ask`),a=e.signIn===`person`;return(0,Y.jsxs)(`div`,{className:`px-3.5 py-3 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:t,className:`-my-1 -ml-1 flex min-w-0 flex-1 items-center gap-3 rounded-lg p-1 text-left transition hover:bg-paper-2`,children:[(0,Y.jsx)(qe,{name:e.connector?.name??e.connectorId}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`truncate text-[0.9375rem]`,children:Q(e)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[a?(0,Y.jsx)(ne,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}):(0,Y.jsx)(te,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,Y.jsxs)(`span`,{className:`truncate`,children:[Ue(e),` · `,We(e)]})]})]}),(0,Y.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 max-sm:hidden`,children:[i?(0,Y.jsx)(O,{tone:`warn`,children:K(`connection.outcome.ask`)}):null,(0,Y.jsx)(O,{children:K(Z[e.audience])})]})]}),a?(0,Y.jsx)(V,{s:r,auth:e.connector?.auth,signedIn:!!e.mySignIn}):null]}),a?(0,Y.jsx)(B,{s:r,fields:e.connector?.fields??[],signedIn:!!e.mySignIn,confirmText:K(`konto.connectionSignOutConfirm`,{name:Q(e)}),className:`ml-12`}):null]})}function Ze({spaceId:e,connectors:t,initial:n,onCancel:i,onDone:o}){let s=c(),l=t.filter(e=>e.usable),[u,d]=(0,J.useState)(l.some(e=>e.id===n)?n:``),p=l.find(e=>e.id===u),[h,g]=(0,J.useState)(p?.name??``),[_,v]=(0,J.useState)(p?.auth===`oauth2`?`person`:`space`),[b,x]=(0,J.useState)(`members`),S=A({mutationFn:()=>a.post(`/api/studio/spaces/${e}/connections`,{connectorId:u,name:h.trim()||p?.name,signIn:_,audience:b}),onSuccess:async t=>{await s.invalidateQueries({queryKey:X(e)}),await s.invalidateQueries({queryKey:[`person-sign-ins`]}),o(t.id)}});return(0,Y.jsx)(m,{className:`p-3.5 sm:p-5`,children:(0,Y.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),u&&S.mutate()},className:`flex flex-col gap-5`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`font-display font-semibold text-base`,children:K(`capabilities.connectors.add`)}),(0,Y.jsx)(`p`,{className:`mt-1 text-[0.8125rem] text-ink-3`,children:K(`connection.setupHint`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(C,{children:K(`connection.connector`)}),(0,Y.jsx)(y,{value:u,onChange:e=>{let t=l.find(t=>t.id===e);(!h.trim()||h===p?.name)&&g(t?.name??``),d(e)},placeholder:K(`connection.connectorPick`),options:l.map(e=>({value:e.id,label:e.name}))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(C,{hint:K(`connection.nameHint`),children:K(`connection.name`)}),(0,Y.jsx)(f,{value:h,maxLength:je.name,placeholder:K(`connection.namePlaceholder`),onChange:e=>g(e.target.value)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(C,{hint:K(Be[_]),children:K(`connection.signIn`)}),(0,Y.jsx)(T,{label:K(`connection.signIn`),value:_,onChange:v,options:[`space`,`person`].map(e=>({id:e,label:K(ze[e])}))}),(0,Y.jsx)(`p`,{className:`mt-2 text-[0.75rem] text-ink-3`,children:K(`connection.signInFixed`)})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(C,{hint:K(Fe[b]),children:K(`connection.audience`)}),(0,Y.jsx)(T,{label:K(`connection.audience`),value:b,onChange:x,options:Oe.map(e=>({id:e,label:K(Z[e])}))})]}),S.error?(0,Y.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:S.error.message}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(r,{type:`submit`,busy:S.isPending,disabled:!u,children:K(`capabilities.connectors.setUp`)}),(0,Y.jsx)(r,{type:`button`,variant:`ghost`,onClick:i,children:K(`orgSettings.cancel`)})]})]})})}function Qe({connection:e,connector:t,writable:n,onGone:i}){let o=c(),s=X(e.spaceId),l=()=>o.invalidateQueries({queryKey:s}),[u,d]=(0,J.useState)(e.name),[p,h]=(0,J.useState)(!1),g=`/api/studio/connections/${encodeURIComponent(e.id)}`,_=A({mutationFn:e=>a.patch(g,e),onSuccess:e=>{o.setQueryData(s,t=>t&&{connections:t.connections.map(t=>t.id===e.id?e:t)}),o.invalidateQueries({queryKey:[`person-sign-ins`]})}}),v=A({mutationFn:()=>a.del(g),onSuccess:async()=>{await l(),o.invalidateQueries({queryKey:[`person-sign-ins`]}),i()}}),y=z(`${g}/sign-in`,l),b=z(`${g}/my-sign-in`,l),x=()=>{let t=u.trim();t&&t!==e.name?_.mutate({name:t}):d(e.name)},S=e.connector?.name??e.connectorId,C=e.connector?.fields??[],w=e.setUpByName?K(`konto.connectionSetUpBy`,{name:e.setUpByName,when:Ve(e.setUpAt)}):K(`konto.connectionSetUpAt`,{when:Ve(e.setUpAt)}),E=n=>(t?.actions??[]).filter(e=>e.group===n).filter(t=>!e.actions.length||e.actions.includes(t.id));return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 px-1`,children:[(0,Y.jsx)(qe,{name:S,large:!0}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h2`,{className:`font-display font-semibold text-lg leading-tight`,children:S}),e.connector?.description?(0,Y.jsx)(`p`,{className:`mt-1 line-clamp-2 text-[0.875rem] text-ink-3`,children:e.connector.description}):null]})]}),(0,Y.jsxs)(m,{className:`flex flex-col gap-5 p-3.5 sm:p-5`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1`,children:[n?(0,Y.jsx)(f,{"aria-label":K(`connection.name`),className:`max-w-sm font-semibold`,value:u,maxLength:je.name,onChange:e=>d(e.target.value),onBlur:x,onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),x())}}):(0,Y.jsx)(`b`,{className:`text-[0.9375rem]`,children:e.name}),(0,Y.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:n?w:K(`connection.adminsManage`)})]}),(0,Y.jsx)($,{label:K(`connection.signIn`),children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.875rem]`,children:[e.signIn===`space`?(0,Y.jsx)(te,{className:`size-4 text-ink-3`,"aria-hidden":`true`}):(0,Y.jsx)(ne,{className:`size-4 text-ink-3`,"aria-hidden":`true`}),K(ze[e.signIn])]}),(0,Y.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:K(Be[e.signIn])})]})}),e.signIn===`space`?(0,Y.jsx)($,{label:K(`connection.account`),children:(0,Y.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsx)(`span`,{className:`text-[0.875rem]`,children:e.account?K(`connection.accountSignedIn`,{label:e.account.label}):K(n?`connection.accountNotYetAdmin`:`connection.accountNotYet`)}),n?(0,Y.jsx)(V,{s:y,auth:e.connector?.auth,signedIn:!!e.account}):null]}),n?(0,Y.jsx)(B,{s:y,fields:C,signedIn:!!e.account,confirmText:K(`connection.signOutSpaceConfirm`,{name:Q(e)})}):null]})}):(0,Y.jsx)($,{label:K(`connection.people`),children:(0,Y.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsxs)(`span`,{className:`text-[0.875rem]`,children:[K(`connection.peopleSignedIn`,{n:e.signedIn}),` · `,e.mySignIn?K(`connection.youSignedIn`,{label:e.mySignIn.label}):K(`connection.youNotYet`)]}),(0,Y.jsx)(V,{s:b,auth:e.connector?.auth,signedIn:!!e.mySignIn})]}),(0,Y.jsx)(B,{s:b,fields:C,signedIn:!!e.mySignIn,confirmText:K(`konto.connectionSignOutConfirm`,{name:Q(e)})})]})}),(0,Y.jsx)($,{label:K(`connection.audience`),children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[n?(0,Y.jsx)(`div`,{children:(0,Y.jsx)(T,{label:K(`connection.audience`),value:e.audience,onChange:e=>_.mutate({audience:e}),options:Oe.map(e=>({id:e,label:K(Z[e])}))})}):(0,Y.jsx)(`span`,{children:(0,Y.jsx)(O,{children:K(Z[e.audience])})}),(0,Y.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:K(Fe[e.audience])})]})}),(0,Y.jsx)(`div`,{className:`border-border-soft border-t`}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(`h3`,{className:`font-semibold text-[0.875rem]`,children:K(`connection.rules`)}),ke.map(t=>{let r=E(t);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-4`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-[0.875rem]`,children:K(Ie[t])}),(0,Y.jsx)(`div`,{className:`text-[0.8125rem] text-ink-3`,children:K(Le[t])}),r.length?(0,Y.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[0.6875rem] text-ink-4`,children:r.map(e=>e.id).join(` · `)}):null]}),(0,Y.jsx)(`div`,{className:`shrink-0`,children:n?(0,Y.jsx)(T,{label:K(Ie[t]),value:e.rules[t],onChange:n=>_.mutate({rules:{...e.rules,[t]:n}}),options:Ae.map(e=>({id:e,label:K(Re[e])}))}):(0,Y.jsx)(O,{tone:e.rules[t]===`ask`?`warn`:`neutral`,children:K(Re[e.rules[t]])})})]},t)}),(0,Y.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:K(n?`connection.askHint`:`connection.askHintMember`)})]}),_.error?(0,Y.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:_.error.message}):null]}),(0,Y.jsx)(m,{className:`flex flex-col gap-1 p-3.5 sm:p-5`,children:(0,Y.jsx)($,{label:K(`connection.use`),children:(0,Y.jsx)(`span`,{className:`text-[0.875rem]`,children:We(e)})})}),n?(0,Y.jsxs)(`div`,{className:`px-1`,children:[p?(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-lg bg-paper p-3 text-[0.875rem] ring-1 ring-border-soft`,children:[(0,Y.jsx)(`p`,{className:`min-w-48 flex-1`,children:K(`connection.removeConfirm`,{name:Q(e)})}),(0,Y.jsx)(r,{variant:`ghost`,onClick:()=>h(!1),children:K(`orgSettings.cancel`)}),(0,Y.jsx)(r,{variant:`danger`,busy:v.isPending,onClick:()=>v.mutate(),children:K(`connection.remove`)})]}):(0,Y.jsx)(r,{variant:`danger`,size:`sm`,onClick:()=>h(!0),children:K(`connection.remove`)}),v.error?(0,Y.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-rose`,children:v.error.message}):null]}):null]})}function $({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[11rem_minmax(0,1fr)] sm:gap-4`,children:[(0,Y.jsx)(`span`,{className:`pt-0.5 text-[0.8125rem] text-ink-3`,children:e}),t]})}var $e=[`discover.example1`,`discover.example2`,`discover.example3`],et=(e,t)=>t===void 0?[`discover`,e]:[`discover`,e,t];function tt(){let[e,t]=p(),n=e.get(`q`)??``,[r,i]=(0,J.useState)(n);return(0,J.useEffect)(()=>i(e=>e.trim()===n.trim()?e:n),[n]),(0,J.useEffect)(()=>{let e=r.trim();if(e===n.trim())return;let i=setTimeout(()=>t(t=>{let n=new URLSearchParams(t);return e?n.set(`q`,e):n.delete(`q`),n},{replace:!0}),350);return()=>clearTimeout(i)},[r,n,t]),[r,i,n.trim()]}function nt({asked:e,onExample:t}){let{space:n}=W(),i=U(),o=F(`skills`),u=c(),[d,f]=(0,J.useState)(null),p=n?.id??``,m=g({queryKey:et(p,e),queryFn:()=>a.get(`/api/studio/spaces/${p}/discover?q=${encodeURIComponent(e)}`),enabled:!!p&&e.length>=2,staleTime:6e4}),h=e=>{u.setQueriesData({queryKey:et(p)},t=>t&&{...t,skills:t.skills.map(t=>t.ref===e?{...t,added:!0}:t)}),u.invalidateQueries({queryKey:l.skills(p)})},_=A({mutationFn:e=>a.post(`/api/studio/spaces/${p}/skills/registry`,{ref:e,mode:`demand`}),onSuccess:(e,t)=>h(t)}),v=m.data,y=v&&!v.skills.length&&!v.connectors.length&&!v.errors.skills&&!v.errors.connectors;return n?(0,Y.jsxs)(Y.Fragment,{children:[e.length<2?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 px-1 text-[0.875rem] text-ink-3`,children:[(0,Y.jsx)(`p`,{children:K(`discover.start`)}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:$e.map(e=>(0,Y.jsxs)(r,{variant:`secondary`,size:`sm`,onClick:()=>t(K(e)),children:[(0,Y.jsx)(s,{className:`size-3.5`}),` `,K(e)]},e))})]}):m.error?(0,Y.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:m.error.message}):v?y?(0,Y.jsx)(`p`,{className:`px-1 text-[0.875rem] text-ink-3`,children:K(`discover.none`,{q:e})}):(0,Y.jsxs)(Y.Fragment,{children:[o?(0,Y.jsx)(rt,{title:K(`space.skills`),count:v.skills.length,error:v.errors.skills,empty:K(`discover.groupNone`,{directory:`skills.sh`}),children:v.skills.map(e=>(0,Y.jsx)(ot,{hit:e,adding:_.isPending&&_.variables===e.ref,failed:_.isError&&_.variables===e.ref?_.error:null,onLook:()=>f(e.ref),onAdd:()=>_.mutate(e.ref)},e.ref))}):null,(0,Y.jsx)(rt,{title:K(`capabilities.connectors`),count:v.connectors.length,error:v.errors.connectors,empty:K(`discover.groupNone`,{directory:`integrations.sh`}),children:v.connectors.map(e=>(0,Y.jsx)(st,{hit:e,admin:i},e.domain))})]}):(0,Y.jsx)(`div`,{className:`flex justify-center py-16`,children:(0,Y.jsx)(k,{className:`size-5`})}),(0,Y.jsx)(S,{open:d!==null,onClose:()=>f(null),wide:!0,height:`tall`,title:K(`skills.registryTitle`),children:d?(0,Y.jsx)(fe,{spaceId:p,skillRef:d,onAdded:()=>{h(d),f(null)}},d):null})]}):null}function rt({title:e,count:t,error:n,empty:r,children:i}){return(0,Y.jsxs)(`section`,{className:`flex flex-col gap-2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2 px-1`,children:[(0,Y.jsx)(`h2`,{className:`font-display font-semibold text-lg leading-tight`,children:e}),t?(0,Y.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:t}):null]}),n?(0,Y.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:n}):t?(0,Y.jsx)(m,{className:`divide-y divide-border-soft`,children:i}):(0,Y.jsx)(`p`,{className:`px-1 text-[0.875rem] text-ink-3`,children:r})]})}function it({icon:e,name:t,mono:n,chip:r,line:i,source:a,error:o,children:s}){return(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 px-3 py-3 sm:flex-nowrap`,children:[(0,Y.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-lg bg-paper-2 text-ink-3`,children:(0,Y.jsx)(e,{className:`size-4`})}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1 max-sm:basis-[calc(100%-3.25rem)]`,children:[(0,Y.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:n?`font-medium font-mono text-[0.8125rem]`:`font-medium`,children:t}),r]}),i?(0,Y.jsx)(`span`,{className:`mt-0.5 block truncate text-[0.8125rem] text-ink-2`,children:i}):null,(0,Y.jsx)(`span`,{className:`mt-0.5 block truncate text-[0.75rem] text-ink-3`,children:a}),o?(0,Y.jsx)(`span`,{className:`mt-1 block text-[0.8125rem] text-rose`,children:o}):null]}),(0,Y.jsx)(`span`,{className:`flex shrink-0 items-center gap-2 max-sm:ml-[3.25rem]`,children:s})]})}function at(){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.8125rem] text-moss`,children:[(0,Y.jsx)(P,{className:`size-4`}),` `,K(`capabilities.inSpace`)]})}function ot({hit:e,adding:t,failed:n,onLook:i,onAdd:a}){return(0,Y.jsxs)(it,{icon:H,name:e.name,mono:!0,chip:e.official?(0,Y.jsx)(O,{tone:`live`,icon:(0,Y.jsx)(ue,{className:`size-3`}),children:K(`skills.official`)}):(0,Y.jsx)(O,{tone:`warn`,children:K(`skills.unchecked`)}),error:n?.message,source:[`skills.sh`,e.source,K(`skills.installs`,{n:e.installs.toLocaleString(G)})].join(` · `),children:[(0,Y.jsx)(r,{variant:`ghost`,size:`sm`,onClick:i,children:K(`skills.open`)}),e.added?(0,Y.jsx)(at,{}):(0,Y.jsx)(r,{variant:`secondary`,size:`sm`,busy:t,onClick:a,children:K(`skills.add`)})]})}function st({hit:e,admin:t}){let n=x(),i=e.kinds.map(e=>e===`mcp`?`MCP`:`OpenAPI`);return(0,Y.jsx)(it,{icon:R,name:e.name,line:e.description||void 0,source:[`integrations.sh`,e.domain,...i].join(` · `),children:e.setUp?(0,Y.jsx)(at,{}):t?(0,Y.jsx)(r,{variant:`secondary`,size:`sm`,onClick:()=>n(`/capabilities/connectors?setup=${encodeURIComponent(e.domain)}`),children:K(`discover.setUp`)}):null})}var ct={skills:4,connections:5};function lt(){let{space:e}=W(),t=U(),n=x(),r=F(`skills`),i=F(`unsetConnectors`),[a,c]=p(),l=a.get(`tab`)===`discover`?`discover`:`space`,[u,d,f]=tt(),h=e?.id??``,g=L(r?e?.id:void 0),_=Me(h),v=Ne(h);if(!e)return null;let y=t&&!e.readOnly,b=u.trim().toLowerCase(),S=g.data?.skills??[],C=_.data?.connections??[],E=S.filter(e=>e.mode!==`off`).sort((e,t)=>e.mode===t.mode?0:e.mode===`always`?-1:1),O=b?S.filter(e=>e.name.includes(b)||e.description.toLowerCase().includes(b)):E,k=b?C.filter(e=>`${e.name} ${e.connector?.name??e.connectorId}`.toLowerCase().includes(b)):C,A=Pe(v.data??[],C,i),j=e=>c(t=>{let n=new URLSearchParams(t);return e===`discover`?n.set(`tab`,`discover`):n.delete(`tab`),n},{replace:!0});return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-9 pb-20`,children:[(0,Y.jsx)(o,{title:K(`nav.capabilities`),hint:K(`capabilities.overview.hint`),plain:!0,action:(0,Y.jsx)(ft,{entries:[...r&&!g.data?.readOnly?[{icon:H,label:K(`capabilities.overview.addSkill`),hint:K(`capabilities.overview.addSkillHint`),to:`/capabilities/skills`}]:[],...y?[{icon:R,label:K(`capabilities.overview.addConnection`),hint:K(`capabilities.overview.addConnectionHint`),to:`/capabilities/connectors?setup=`}]:[],{icon:De,label:K(`capabilities.discover`),hint:K(`capabilities.overview.discoverHint`),to:`/capabilities/overview?tab=discover`}]}),children:(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Y.jsx)(T,{value:l,onChange:j,options:[{id:`space`,label:K(`capabilities.inSpace`)},{id:`discover`,label:K(`capabilities.discover`)}],label:K(`nav.capabilities`)}),(0,Y.jsxs)(`form`,{className:`flex h-10 min-w-0 flex-1 basis-60 items-center gap-2 rounded-full border border-input bg-card px-4 focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,onSubmit:e=>{e.preventDefault(),l===`space`&&b&&!O.length&&!k.length&&j(`discover`)},children:[(0,Y.jsx)(s,{className:`size-4 shrink-0 text-ink-3`}),(0,Y.jsx)(`input`,{type:`search`,value:u,"aria-label":K(l===`discover`?`discover.searchLabel`:`capabilities.overview.search`),placeholder:K(l===`discover`?`discover.search`:`capabilities.overview.search`),onChange:e=>d(e.target.value),className:`min-w-0 flex-1 bg-transparent text-[0.875rem] text-ink outline-none placeholder:text-ink-4`})]})]})}),(0,Y.jsx)(`div`,{className:`flex animate-rise flex-col gap-9`,children:l===`discover`?(0,Y.jsx)(nt,{asked:f,onExample:d}):(0,Y.jsxs)(Y.Fragment,{children:[r?(0,Y.jsx)(ut,{icon:H,title:K(`space.skills`),all:S.length,to:`/capabilities/skills`,children:g.error?(0,Y.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:g.error.message}):O.length?(0,Y.jsx)(`div`,{className:`grid gap-2.5 sm:grid-cols-2`,children:O.slice(0,ct.skills).map(e=>(0,Y.jsx)(dt,{skill:e,onOpen:()=>n(`/capabilities/skills?show=k:${e.id}`)},e.id))}):g.isPending?null:(0,Y.jsx)(m,{children:(0,Y.jsx)(D,{children:b?K(`capabilities.overview.nothing`,{q:u.trim()}):K(`capabilities.overview.noSkills`)})})}):null,(0,Y.jsxs)(ut,{icon:R,title:K(`capabilities.connectors`),all:C.length,to:`/capabilities/connectors`,children:[_.error?(0,Y.jsx)(`p`,{className:`px-1 text-[0.875rem] text-rose`,children:_.error.message}):k.length?(0,Y.jsx)(m,{className:`flex flex-col divide-y divide-border-soft p-0`,children:k.slice(0,ct.connections).map(e=>(0,Y.jsx)(Xe,{connection:e,onOpen:()=>n(`/capabilities/connectors?show=${encodeURIComponent(e.id)}`)},e.id))}):_.isPending?null:(0,Y.jsx)(m,{children:(0,Y.jsx)(D,{children:b?K(`capabilities.overview.nothing`,{q:u.trim()}):K(`capabilities.overview.noConnections`)})}),A.length&&!b?(0,Y.jsxs)(`p`,{className:`px-1 text-[0.8125rem] text-ink-3`,children:[K(`capabilities.connectors.builtin`),`:`,` `,A.map((e,t)=>(0,Y.jsxs)(`span`,{children:[t?` · `:null,y&&e.usable?(0,Y.jsx)(w,{to:`/capabilities/connectors?setup=${encodeURIComponent(e.id)}`,className:`text-ink-2 hover:text-ink hover:underline`,children:e.name}):(0,Y.jsx)(`span`,{className:`text-ink-2`,children:e.name})]},e.id))]}):null]})]})},l)]})}function ut({icon:e,title:t,all:n,to:r,children:i}){return(0,Y.jsxs)(`section`,{className:`flex flex-col gap-2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-1`,children:[(0,Y.jsxs)(`h3`,{className:`flex items-center gap-2 font-semibold text-[0.9375rem]`,children:[(0,Y.jsx)(e,{className:`size-4 text-ember-strong`,"aria-hidden":`true`}),t]}),(0,Y.jsxs)(w,{to:r,className:`inline-flex items-center gap-0.5 text-[0.8125rem] text-ink-3 transition hover:text-ink`,children:[K(`capabilities.overview.all`,{n}),(0,Y.jsx)(u,{className:`size-3.5`,"aria-hidden":`true`})]})]}),i]})}function dt({skill:e,onOpen:t}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:t,className:`flex min-w-0 flex-col gap-1.5 rounded-xl bg-card px-4 py-3 text-left shadow-soft ring-1 ring-border-soft transition hover:ring-border`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:_(`truncate font-medium font-mono text-[0.8125rem]`,e.mode===`off`&&`text-ink-3`),children:e.name}),(0,Y.jsx)(O,{tone:e.mode===`always`?`live`:`neutral`,children:K(`skills.mode.${e.mode}`)})]}),(0,Y.jsx)(`span`,{className:`line-clamp-2 text-[0.8125rem] text-ink-2`,children:e.description}),(0,Y.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-[0.75rem] text-ink-3`,children:[(0,Y.jsx)(de,{skill:e}),e.runScripts?K(`capabilities.overview.scripts`):null]})]})}function ft({entries:e}){let[t,n]=(0,J.useState)(!1),i=(0,J.useRef)(null);return(0,J.useEffect)(()=>{if(!t)return;let e=e=>{i.current?.contains(e.target)||n(!1)},r=e=>e.key===`Escape`&&n(!1);return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,r),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,r)}},[t]),(0,Y.jsxs)(`div`,{className:`relative`,ref:i,children:[(0,Y.jsxs)(r,{size:`sm`,"aria-haspopup":`menu`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,Y.jsx)(N,{className:`size-4`}),` `,K(`skills.add`),(0,Y.jsx)(d,{className:`-mr-1 size-4`})]}),t?(0,Y.jsx)(`div`,{role:`menu`,className:`absolute top-10 right-0 z-50 w-72 animate-rise rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border-soft`,children:e.map(e=>(0,Y.jsxs)(w,{to:e.to,role:`menuitem`,onClick:()=>n(!1),className:`flex w-full items-start gap-2.5 rounded-lg px-2.5 py-2 text-left transition hover:bg-accent`,children:[(0,Y.jsx)(e.icon,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,Y.jsxs)(`span`,{className:`min-w-0`,children:[(0,Y.jsx)(`span`,{className:`block font-medium text-[0.875rem]`,children:e.label}),(0,Y.jsx)(`span`,{className:`block text-[0.8125rem] text-ink-3`,children:e.hint})]})]},e.to))}):null]})}var pt=(0,J.lazy)(()=>j(()=>import(`./SkillEditor-DvtameHg.js`).then(e=>({default:e.SkillEditor})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])));function mt(){let[e,t]=p(),{space:n}=W(),r=re(),{narrow:i}=we(),a=e.get(`show`),s=a?.startsWith(`k:`)?a:null,c=L(n?.id),l=ie(`skills`,r).filter(e=>e.plugin);be(c.data?.skills.find(e=>`k:${e.id}`===s)?.name??null),(0,J.useEffect)(()=>{i||I().scrollTo({top:0})},[i,s]);let u=e=>i?t({show:e}):t(e===`all`?{}:{show:e},{replace:!0});return(0,Y.jsx)(Y.Fragment,{children:n?(0,Y.jsx)(`div`,{className:`flex flex-col gap-9 pb-20`,children:s?(0,Y.jsx)(J.Suspense,{fallback:null,children:(0,Y.jsx)(pt,{skillId:s.slice(2),onGone:()=>u(`all`),onOpen:u,filesFirst:!0},s)}):c.data?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(le,{spaceId:n.id,data:c.data,onOpen:u,heading:K(`capabilities.inSpace`)}),l.flatMap(e=>e.sections).map(e=>r.spaceSections.find(t=>t.id===e.id)).filter(e=>e!==void 0).map(e=>(0,Y.jsx)(h,{id:e.id,children:(0,Y.jsx)(o,{title:e.label(),hint:e.hint?.(),plain:!0,children:(0,Y.jsx)(se,{of:e,children:(0,Y.jsx)(e.component,{})})})},e.serial))]}):c.error?(0,Y.jsx)(`p`,{className:`text-[0.875rem] text-rose`,children:c.error.message}):null}):null})}var ht=[{id:`overview`,label:`capabilities.overview`,icon:ee,element:lt,menu:!1},{id:`skills`,label:`space.skills`,icon:H,element:mt,feature:`skills`,menu:!1},{id:`connectors`,label:`capabilities.connectors`,icon:R,element:Je,menu:!1},{id:`protocol`,label:`capabilities.protocol`,icon:i,element:pe,admins:!0,menu:!1}];function gt(e,t=!0){return ht.filter(n=>n.element&&(!n.feature||e(n.feature))&&(t||!n.admins))}function _t(){let[e,t]=(0,J.useState)(null);return(0,J.useEffect)(()=>{let e=I(),n=()=>t(e.clientHeight);n();let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[]),e}function vt(){let e=F(`capabilities`),t=oe(),{section:n}=v(),[r]=p(),i=x(),a=E(),{space:o,loading:s}=W(),c=xe(),[l,u]=(0,J.useState)(null),[d,f]=(0,J.useState)(null),[m,h]=(0,J.useState)(null),g=gt(e=>ge(t,e),U()),y=g.find(e=>e.id===n),S=L(g.some(e=>e.id===`skills`)?o?.id:void 0),C=Me(o?.id??``),w={skills:S.data?.skills.length,connectors:C.data?.connections.length},T=g.map(e=>({id:e.id,label:K(e.label),icon:e.icon,to:e.menu===!1&&c?`/capabilities/${e.id}?show=page`:`/capabilities/${e.id}`,count:w[e.id]})),O=T.find(e=>e.id===y?.id),k=r.get(`show`)||r.has(`setup`)?2:1,A=y&&y.menu!==!1&&m!==y.id?1:0,j=Ce(A),M=Ce(k),N=(0,J.useMemo)(()=>({slot:l,narrow:c,setDetail:f}),[l,c]),P=_t();if(ae([{label:K(`nav.capabilities`),to:`/capabilities`},...O?[{label:O.label,to:O.to}]:[],...O&&d?[{label:d}]:[]]),!e)return(0,Y.jsx)(b,{to:`/`,replace:!0});if(n===`discover`){let e=new URLSearchParams(a.search);return e.set(`tab`,`discover`),(0,Y.jsx)(b,{to:{pathname:`/capabilities/overview`,search:`?${e}`},replace:!0})}if(!y&&g[0])return(0,Y.jsx)(b,{to:{pathname:`/capabilities/${g[0].id}`,search:a.search},replace:!0});let ee=y?.element;return(0,Y.jsx)(ye.Provider,{value:N,children:(0,Y.jsx)(`div`,{className:`animate-rise`,children:(0,Y.jsxs)(`div`,{className:`grid gap-6 md:grid-cols-[10.5rem_minmax(0,1fr)] md:gap-5 lg:grid-cols-[15rem_minmax(0,1fr)] lg:gap-10`,children:[(0,Y.jsxs)(`aside`,{className:_(`menu-scroll min-w-0 md:sticky md:top-6 md:self-start md:overflow-y-auto md:overscroll-contain`,c&&k===2&&`hidden`,c&&M===`back`&&q(`back`)),style:!c&&P?{maxHeight:P-48,paddingBottom:`var(--assistant-dock, 0px)`}:void 0,children:[(0,Y.jsx)(Se,{title:K(`nav.capabilities`),open:A===1?O??null:null,onBack:g.length>1?()=>h(y?.id??null):void 0,root:{icon:ce,label:K(`nav.capabilities`),onOpen:()=>i(c?`/capabilities/overview?show=page`:`/capabilities/overview`),current:y?.id===`overview`}}),(0,Y.jsx)(`div`,{className:_(q(j)),children:A===0?(0,Y.jsx)(ve,{entries:T.filter(e=>e.id!==`overview`),current:O,onPick:e=>{h(null),y?.menu===!1&&i(e.to)}}):(0,Y.jsx)(`div`,{ref:u})},A)]}),(0,Y.jsxs)(`div`,{className:_(`min-w-0`,c&&k<2&&`hidden`,c&&M===`deeper`&&q(`deeper`)),children:[c&&O?(0,Y.jsx)(`div`,{className:`mb-3`,children:(0,Y.jsx)(Te,{label:O.label,onBack:()=>i(O.to)})}):null,ee?(0,Y.jsx)(ee,{}):null,o||s?null:(0,Y.jsx)(D,{children:K(`settings.noSpace`)})]})]})})})}export{vt as CapabilitiesPage};