@nextclaw/server 0.12.26-beta.3 → 0.12.26-beta.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/index.js CHANGED
@@ -11,7 +11,7 @@ import { ConfigSchema, DEFAULT_WORKSPACE_PATH, buildConfigSchema, createAgentPro
11
11
  import { homedir } from "node:os";
12
12
  import { findBuiltinProviderByName, listBuiltinProviders } from "@nextclaw/runtime";
13
13
  import { McpInstalledViewService } from "@nextclaw/mcp";
14
- import { isPanelAppError } from "@nextclaw/kernel";
14
+ import { isPanelAppError, isServiceAppError } from "@nextclaw/kernel";
15
15
  import { serveStatic } from "hono/serve-static";
16
16
  //#region src/features/auth/utils/auth-bridge.utils.ts
17
17
  const REMOTE_BRIDGE_DIR = join(getDataDir(), "remote");
@@ -4009,7 +4009,7 @@ var RuntimeUpdateRoutesController = class {
4009
4009
  //#endregion
4010
4010
  //#region src/features/panel-apps/controllers/panel-apps.controller.ts
4011
4011
  function statusForPanelAppError(code) {
4012
- return code === "PANEL_APP_NOT_FOUND" ? 404 : 400;
4012
+ return code === "PANEL_APP_NOT_FOUND" || code === "PANEL_APP_BRIDGE_SESSION_NOT_FOUND" ? 404 : 400;
4013
4013
  }
4014
4014
  var PanelAppsRoutesController = class {
4015
4015
  constructor(panelAppManager) {
@@ -4052,6 +4052,165 @@ var PanelAppsRoutesController = class {
4052
4052
  throw error;
4053
4053
  }
4054
4054
  };
4055
+ getPanelAppBridgeScript = () => {
4056
+ return new Response(this.panelAppManager.getPanelAppBridgeScript(), { headers: {
4057
+ "content-type": "application/javascript; charset=utf-8",
4058
+ "cache-control": "no-store"
4059
+ } });
4060
+ };
4061
+ createBridgeSession = async (c) => {
4062
+ const body = await readJson(c.req.raw);
4063
+ if (!body.ok || !isRecord$1(body.data) || typeof body.data.panelAppId !== "string" || typeof body.data.tabId !== "string") return c.json(err("INVALID_PANEL_APP_BRIDGE_SESSION", "invalid bridge session request"), 400);
4064
+ try {
4065
+ const session = await this.panelAppManager.createPanelAppBridgeSession({
4066
+ id: body.data.panelAppId,
4067
+ tabId: body.data.tabId
4068
+ });
4069
+ return c.json(ok({
4070
+ id: session.id,
4071
+ token: session.token,
4072
+ panelAppId: session.panelAppId,
4073
+ tabId: session.tabId,
4074
+ expiresAt: session.expiresAt
4075
+ }));
4076
+ } catch (error) {
4077
+ if (isPanelAppError(error)) return c.json(err(error.code, error.message), statusForPanelAppError(error.code));
4078
+ throw error;
4079
+ }
4080
+ };
4081
+ deleteBridgeSession = (c) => {
4082
+ this.panelAppManager.deletePanelAppBridgeSession(c.req.param("token"));
4083
+ return c.json(ok({ deleted: true }));
4084
+ };
4085
+ };
4086
+ //#endregion
4087
+ //#region src/features/service-apps/controllers/service-apps.controller.ts
4088
+ const PANEL_BRIDGE_SESSION_HEADER = "x-nextclaw-panel-bridge-session";
4089
+ function statusForServiceAppError(code) {
4090
+ switch (code) {
4091
+ case "AUTHORIZATION_REQUIRED": return 401;
4092
+ case "SERVICE_APP_ACTION_NOT_DECLARED": return 403;
4093
+ case "SERVICE_APP_ACTION_NOT_FOUND":
4094
+ case "SERVICE_APP_NOT_FOUND": return 404;
4095
+ default: return 400;
4096
+ }
4097
+ }
4098
+ var ServiceAppsRoutesController = class {
4099
+ constructor(params) {
4100
+ this.params = params;
4101
+ }
4102
+ listServiceApps = async (c) => {
4103
+ return c.json(ok(await this.params.serviceAppManager.listServiceApps()));
4104
+ };
4105
+ getServiceApp = async (c) => {
4106
+ try {
4107
+ return c.json(ok(await this.params.serviceAppManager.getServiceApp(c.req.param("appId"))));
4108
+ } catch (error) {
4109
+ return this.handleServiceAppError(c, error);
4110
+ }
4111
+ };
4112
+ listServiceActions = async (c) => {
4113
+ try {
4114
+ const bridgeSession = this.readOptionalBridgeSession(c);
4115
+ const appId = c.req.query("appId")?.trim();
4116
+ const actions = await this.params.serviceAppManager.listServiceActions(bridgeSession ? {
4117
+ caller: bridgeSession.caller,
4118
+ appId,
4119
+ declaredActions: bridgeSession.declaredActions
4120
+ } : { appId });
4121
+ return c.json(ok({ actions }));
4122
+ } catch (error) {
4123
+ return this.handleServiceAppError(c, error);
4124
+ }
4125
+ };
4126
+ discoverServiceAppActions = async (c) => {
4127
+ try {
4128
+ const actions = await this.params.serviceAppManager.discoverServiceAppActions(c.req.param("appId"));
4129
+ return c.json(ok({ actions }));
4130
+ } catch (error) {
4131
+ return this.handleServiceAppError(c, error);
4132
+ }
4133
+ };
4134
+ invokeServiceAction = async (c) => {
4135
+ const body = await readJson(c.req.raw);
4136
+ if (!body.ok || body.data !== void 0 && !isRecord$1(body.data)) return c.json(err("INVALID_SERVICE_ACTION_REQUEST", "invalid service action request"), 400);
4137
+ try {
4138
+ const bridgeSession = this.requireBridgeSession(c);
4139
+ const payload = await this.params.serviceAppManager.invokeServiceAction(c.req.param("actionId"), {
4140
+ caller: bridgeSession.caller,
4141
+ declaredActions: bridgeSession.declaredActions,
4142
+ input: isRecord$1(body.data.input) ? body.data.input : {}
4143
+ });
4144
+ return c.json(ok(payload));
4145
+ } catch (error) {
4146
+ return this.handleServiceAppError(c, error);
4147
+ }
4148
+ };
4149
+ grantServiceAction = async (c) => {
4150
+ try {
4151
+ const bridgeSession = this.requireBridgeSession(c);
4152
+ const payload = await this.params.serviceAppManager.grantServiceAction(c.req.param("actionId"), {
4153
+ caller: bridgeSession.caller,
4154
+ declaredActions: bridgeSession.declaredActions
4155
+ });
4156
+ return c.json(ok(payload));
4157
+ } catch (error) {
4158
+ return this.handleServiceAppError(c, error);
4159
+ }
4160
+ };
4161
+ listServiceActionGrants = async (c) => {
4162
+ return c.json(ok({ grants: await this.params.serviceAppManager.listServiceActionGrants() }));
4163
+ };
4164
+ revokeServiceAction = async (c) => {
4165
+ try {
4166
+ const bridgeSession = this.requireBridgeSession(c);
4167
+ await this.params.serviceAppManager.revokeServiceAction(bridgeSession.caller, c.req.param("actionId"));
4168
+ return c.json(ok({ revoked: true }));
4169
+ } catch (error) {
4170
+ return this.handleServiceAppError(c, error);
4171
+ }
4172
+ };
4173
+ revokeServiceActionGrant = async (c) => {
4174
+ const caller = this.readCallerQuery(c);
4175
+ if (!caller) return c.json(err("INVALID_SERVICE_ACTION_CALLER", "invalid service action caller"), 400);
4176
+ try {
4177
+ await this.params.serviceAppManager.revokeServiceAction(caller, c.req.param("actionId"));
4178
+ return c.json(ok({ revoked: true }));
4179
+ } catch (error) {
4180
+ return this.handleServiceAppError(c, error);
4181
+ }
4182
+ };
4183
+ restartServiceApp = async (c) => {
4184
+ try {
4185
+ return c.json(ok(await this.params.serviceAppManager.restartServiceApp(c.req.param("appId"))));
4186
+ } catch (error) {
4187
+ return this.handleServiceAppError(c, error);
4188
+ }
4189
+ };
4190
+ requireBridgeSession = (c) => {
4191
+ const token = c.req.raw.headers.get(PANEL_BRIDGE_SESSION_HEADER)?.trim();
4192
+ if (!token) throw new Error("panel app bridge session is required");
4193
+ return this.params.panelAppManager.resolvePanelAppBridgeSession(token);
4194
+ };
4195
+ readOptionalBridgeSession = (c) => {
4196
+ const token = c.req.raw.headers.get(PANEL_BRIDGE_SESSION_HEADER)?.trim();
4197
+ return token ? this.params.panelAppManager.resolvePanelAppBridgeSession(token) : null;
4198
+ };
4199
+ readCallerQuery = (c) => {
4200
+ const surface = c.req.query("surface");
4201
+ const appId = c.req.query("appId")?.trim();
4202
+ if (surface !== "panel-app" || !appId) return null;
4203
+ return {
4204
+ surface,
4205
+ appId
4206
+ };
4207
+ };
4208
+ handleServiceAppError = (c, error) => {
4209
+ if (isServiceAppError(error)) return c.json(err(error.code, error.message), statusForServiceAppError(error.code));
4210
+ if (isPanelAppError(error)) return c.json(err(error.code, error.message), 404);
4211
+ if (error instanceof Error && error.message === "panel app bridge session is required") return c.json(err("PANEL_APP_BRIDGE_SESSION_REQUIRED", error.message), 401);
4212
+ throw error;
4213
+ };
4055
4214
  };
4056
4215
  //#endregion
4057
4216
  //#region src/app/utils/ncp-session-event-stream.utils.ts
@@ -4368,6 +4527,10 @@ function createUiRouteControllers(options, authService, marketplaceBaseUrl) {
4368
4527
  ncpSession: new NcpSessionRoutesController(options),
4369
4528
  ncpAsset: new NcpAssetRoutesController(options),
4370
4529
  panelApps: new PanelAppsRoutesController(options.kernel.panelAppManager),
4530
+ serviceApps: new ServiceAppsRoutesController({
4531
+ panelAppManager: options.kernel.panelAppManager,
4532
+ serviceAppManager: options.kernel.serviceAppManager
4533
+ }),
4371
4534
  serverPath: new ServerPathRoutesController(),
4372
4535
  remote: remoteAccess ? new RemoteRoutesController(remoteAccess) : null,
4373
4536
  runtimeControl: runtimeControl ? new RuntimeControlRoutesController(runtimeControl) : null,
@@ -4440,7 +4603,7 @@ var UiRouteRegistry = class {
4440
4603
  ]]);
4441
4604
  };
4442
4605
  register = () => {
4443
- const { agents, app, auth, config, cron, ncpAsset, ncpSession, panelApps, remote, runtimeControl, runtimeUpdate, serverPath } = this.controllers;
4606
+ const { agents, app, auth, config, cron, ncpAsset, ncpSession, panelApps, serviceApps, remote, runtimeControl, runtimeUpdate, serverPath } = this.controllers;
4444
4607
  this.mountRoutes([
4445
4608
  [
4446
4609
  "get",
@@ -4656,6 +4819,21 @@ var UiRouteRegistry = class {
4656
4819
  "/api/panel-apps",
4657
4820
  panelApps.list
4658
4821
  ],
4822
+ [
4823
+ "get",
4824
+ "/api/panel-app-bridge.js",
4825
+ panelApps.getPanelAppBridgeScript
4826
+ ],
4827
+ [
4828
+ "post",
4829
+ "/api/panel-app-bridge-sessions",
4830
+ panelApps.createBridgeSession
4831
+ ],
4832
+ [
4833
+ "delete",
4834
+ "/api/panel-app-bridge-sessions/:token",
4835
+ panelApps.deleteBridgeSession
4836
+ ],
4659
4837
  [
4660
4838
  "patch",
4661
4839
  "/api/panel-apps/:id/preferences",
@@ -4671,6 +4849,56 @@ var UiRouteRegistry = class {
4671
4849
  "/api/panel-apps/:id/content",
4672
4850
  panelApps.getPanelAppContent
4673
4851
  ],
4852
+ [
4853
+ "get",
4854
+ "/api/service-apps",
4855
+ serviceApps.listServiceApps
4856
+ ],
4857
+ [
4858
+ "post",
4859
+ "/api/service-apps/:appId/restart",
4860
+ serviceApps.restartServiceApp
4861
+ ],
4862
+ [
4863
+ "post",
4864
+ "/api/service-apps/:appId/actions/discover",
4865
+ serviceApps.discoverServiceAppActions
4866
+ ],
4867
+ [
4868
+ "get",
4869
+ "/api/service-apps/:appId",
4870
+ serviceApps.getServiceApp
4871
+ ],
4872
+ [
4873
+ "get",
4874
+ "/api/service-actions",
4875
+ serviceApps.listServiceActions
4876
+ ],
4877
+ [
4878
+ "post",
4879
+ "/api/service-actions/:actionId/invoke",
4880
+ serviceApps.invokeServiceAction
4881
+ ],
4882
+ [
4883
+ "post",
4884
+ "/api/service-actions/:actionId/grant",
4885
+ serviceApps.grantServiceAction
4886
+ ],
4887
+ [
4888
+ "delete",
4889
+ "/api/service-actions/:actionId/grant",
4890
+ serviceApps.revokeServiceAction
4891
+ ],
4892
+ [
4893
+ "get",
4894
+ "/api/service-action-grants",
4895
+ serviceApps.listServiceActionGrants
4896
+ ],
4897
+ [
4898
+ "delete",
4899
+ "/api/service-action-grants/:actionId",
4900
+ serviceApps.revokeServiceActionGrant
4901
+ ],
4674
4902
  [
4675
4903
  "get",
4676
4904
  "/api/server-paths/browse",
@@ -5001,6 +5229,6 @@ async function startUiServer(gateway) {
5001
5229
  };
5002
5230
  }
5003
5231
  //#endregion
5004
- export { ConfigRoutesController, PanelAppsRoutesController, RuntimeControlRoutesController, buildConfigMeta, buildConfigSchemaView, buildConfigView, createCustomProvider, createUiRouter, deleteCustomProvider, ensureUiBridgeSecret, executeConfigAction, getUiBridgeSecretPath, loadConfigOrDefault, readUiBridgeSecret, startUiServer, testProviderConnection, updateChannel, updateModel, updateProvider, updateRuntime, updateSearch, updateSecrets };
5232
+ export { ConfigRoutesController, PanelAppsRoutesController, RuntimeControlRoutesController, ServiceAppsRoutesController, buildConfigMeta, buildConfigSchemaView, buildConfigView, createCustomProvider, createUiRouter, deleteCustomProvider, ensureUiBridgeSecret, executeConfigAction, getUiBridgeSecretPath, loadConfigOrDefault, readUiBridgeSecret, startUiServer, testProviderConnection, updateChannel, updateModel, updateProvider, updateRuntime, updateSearch, updateSecrets };
5005
5233
 
5006
5234
  //# sourceMappingURL=index.js.map