@nextclaw/kernel 0.18.0 → 0.18.1

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
@@ -4146,6 +4146,15 @@ var AppPackageManager = class {
4146
4146
  }
4147
4147
  });
4148
4148
  };
4149
+ resolvePrimaryPanelId = async (appId) => {
4150
+ try {
4151
+ const app = await this.getPackage(appId);
4152
+ return app.enabled ? app.primaryPanelId : void 0;
4153
+ } catch (error) {
4154
+ if (isAppPackageError(error) && error.code === "APP_PACKAGE_NOT_FOUND") return;
4155
+ throw error;
4156
+ }
4157
+ };
4149
4158
  inspectDependencies = async (appId) => await this.installationService.withAppOperation(appId, async () => await this.dependencyCoordinator.inspect(appId));
4150
4159
  verifyDependencies = async (appId) => await this.installationService.withAppOperation(appId, async () => await this.dependencyCoordinator.verify(appId));
4151
4160
  setupDependencies = async (appId) => {
@@ -10061,6 +10070,47 @@ function isPanelAppAssetTokenClaims(value) {
10061
10070
  return typeof value === "object" && value !== null && "panelAppId" in value && "sourceName" in value && "sourcePath" in value && "expiresAt" in value && "nonce" in value && typeof value.panelAppId === "string" && typeof value.sourceName === "string" && typeof value.sourcePath === "string" && typeof value.expiresAt === "number" && typeof value.nonce === "string";
10062
10071
  }
10063
10072
  //#endregion
10073
+ //#region src/services/panel-app-entry-resolver.service.ts
10074
+ var PanelAppEntryResolverService = class {
10075
+ constructor(params) {
10076
+ this.params = params;
10077
+ }
10078
+ list = async () => {
10079
+ const workspacePath = this.params.getWorkspacePath();
10080
+ const panelsPath = this.params.getPanelsPath(workspacePath);
10081
+ const sources = await this.params.listSources();
10082
+ const appState = await this.params.loadState();
10083
+ return {
10084
+ workspacePath,
10085
+ panelsPath,
10086
+ entries: (await Promise.all(sources.map(({ source, packageSource }) => this.params.buildEntry(source, appState.apps[encodePanelAppId(source.sourceName)] ?? {}, packageSource, appState.mainSidebarAppIds)))).sort(this.params.compareEntries),
10087
+ unavailablePackages: await this.params.listPackageComponentDiagnostics?.() ?? []
10088
+ };
10089
+ };
10090
+ get = async (id) => {
10091
+ const resolved = await this.params.resolveSourceByIdOrAppId(id);
10092
+ const appState = await this.params.loadState();
10093
+ return await this.params.buildEntry(resolved.source, appState.apps[encodePanelAppId(resolved.source.sourceName)] ?? {}, resolved.packageSource, appState.mainSidebarAppIds);
10094
+ };
10095
+ resolveDisplayTarget = async (id) => {
10096
+ try {
10097
+ return await this.get(id);
10098
+ } catch (error) {
10099
+ this.rethrowUnexpectedResolutionError(error);
10100
+ }
10101
+ const primaryPanelId = await this.params.resolvePackagePrimaryPanelId?.(id);
10102
+ if (primaryPanelId) try {
10103
+ return await this.get(primaryPanelId);
10104
+ } catch (error) {
10105
+ this.rethrowUnexpectedResolutionError(error);
10106
+ }
10107
+ throw new PanelAppError("PANEL_APP_NOT_FOUND", "panel app not found");
10108
+ };
10109
+ rethrowUnexpectedResolutionError = (error) => {
10110
+ if (!isPanelAppError(error) || error.code !== "PANEL_APP_NOT_FOUND" && error.code !== "PANEL_APP_INVALID_ID") throw error;
10111
+ };
10112
+ };
10113
+ //#endregion
10064
10114
  //#region src/stores/panel-app-state.store.ts
10065
10115
  const PANEL_APP_STATE_FILE = ".panel-apps.state.json";
10066
10116
  const PANEL_APP_STATE_VERSION = 2;
@@ -11076,6 +11126,7 @@ var PanelAppManager = class {
11076
11126
  sourceService = new PanelAppSourceService();
11077
11127
  packageStateManager;
11078
11128
  entryPresenter;
11129
+ entryResolver;
11079
11130
  removalService;
11080
11131
  constructor(params) {
11081
11132
  this.params = params;
@@ -11105,25 +11156,21 @@ var PanelAppManager = class {
11105
11156
  createAssetBaseHref: this.createAssetBaseHref,
11106
11157
  isClientGranted: this.isPanelAppClientGranted
11107
11158
  });
11108
- }
11109
- listPanelApps = async () => {
11110
- const workspacePath = this.getWorkspacePath();
11111
- const panelsPath = this.getPanelsPath(workspacePath);
11112
- const sources = await this.packageStateManager.listSources();
11113
- const appState = await this.createStateStore(panelsPath).load();
11114
- return {
11115
- workspacePath,
11116
- panelsPath,
11117
- entries: (await Promise.all(sources.map(({ source, packageSource }) => this.entryPresenter.build(source, appState.apps[encodePanelAppId(source.sourceName)] ?? {}, packageSource, appState.mainSidebarAppIds)))).sort(this.entryPresenter.compare),
11118
- unavailablePackages: await this.params.listPackageComponentDiagnostics?.() ?? []
11119
- };
11120
- };
11121
- getPanelApp = async (id) => {
11122
- const panelsPath = this.getPanelsPath(this.getWorkspacePath());
11123
- const resolved = await this.packageStateManager.resolveSourceByIdOrAppId(id);
11124
- const appState = await this.createStateStore(panelsPath).load();
11125
- return await this.entryPresenter.build(resolved.source, appState.apps[encodePanelAppId(resolved.source.sourceName)] ?? {}, resolved.packageSource, appState.mainSidebarAppIds);
11126
- };
11159
+ this.entryResolver = new PanelAppEntryResolverService({
11160
+ getWorkspacePath: this.getWorkspacePath,
11161
+ getPanelsPath: this.getPanelsPath,
11162
+ listSources: this.packageStateManager.listSources,
11163
+ listPackageComponentDiagnostics: params.listPackageComponentDiagnostics,
11164
+ resolveSourceByIdOrAppId: this.packageStateManager.resolveSourceByIdOrAppId,
11165
+ loadState: async () => await this.createStateStore(this.getPanelsPath(this.getWorkspacePath())).load(),
11166
+ buildEntry: this.entryPresenter.build,
11167
+ compareEntries: this.entryPresenter.compare,
11168
+ resolvePackagePrimaryPanelId: params.resolvePackagePrimaryPanelId
11169
+ });
11170
+ }
11171
+ listPanelApps = async () => await this.entryResolver.list();
11172
+ getPanelApp = async (id) => await this.entryResolver.get(id);
11173
+ resolvePanelAppDisplayTarget = async (id) => await this.entryResolver.resolveDisplayTarget(id);
11127
11174
  getPanelAppContent = async (id, sourcePath) => {
11128
11175
  try {
11129
11176
  const resolved = sourcePath ? await readPanelAppContentSourceByIdOrPath({
@@ -24552,15 +24599,6 @@ const createSelfUpdateContextProvider = () => staticBlock([
24552
24599
  "Only when a transitional config write is needed, read config.get and config.schema first, copy legal values exactly, use the minimal config.patch, then verify with config.get. Do not guess paths or enum values.",
24553
24600
  `If a config change requires restart, tell the user to run \`${APP_NAME.toLowerCase()} restart\` in an external terminal. Do not run it from the active agent session.`
24554
24601
  ]);
24555
- const createReplyTagsContextProvider = () => staticBlock([
24556
- "## Reply Tags",
24557
- "To request a native reply/quote on supported surfaces, include one tag in your reply:",
24558
- "- Reply tags must be the very first token in the message (no leading text/newlines): [[reply_to_current]] your reply.",
24559
- "- [[reply_to_current]] replies to the triggering message.",
24560
- "- Prefer [[reply_to_current]]. Use [[reply_to:<id>]] only when an id was explicitly provided (e.g. by the user or a tool).",
24561
- "Whitespace inside the tag is allowed (e.g. [[ reply_to_current ]] / [[ reply_to: 123 ]]).",
24562
- "Tags are stripped before sending; support depends on the current channel config."
24563
- ]);
24564
24602
  const createMessagingContextProvider = () => staticBlock([
24565
24603
  "## Messaging",
24566
24604
  "- Reply normally in the current conversation; routing to its source channel is automatic.",
@@ -25243,7 +25281,6 @@ var ContextProviderContribution = class extends Contribution$1 {
25243
25281
  createSafetyContextProvider(),
25244
25282
  createCliQuickReferenceContextProvider(),
25245
25283
  createSelfUpdateContextProvider(),
25246
- createReplyTagsContextProvider(),
25247
25284
  createMessagingContextProvider(),
25248
25285
  createMemoryRecallContextProvider(),
25249
25286
  createSilentRepliesContextProvider(),
@@ -26580,9 +26617,10 @@ function createShowContentEventPayload(request, context) {
26580
26617
  };
26581
26618
  }
26582
26619
  var ShowContentDisplayTool = class {
26583
- constructor(eventBus, spec) {
26620
+ constructor(eventBus, spec, resolvePanelAppDisplayTarget) {
26584
26621
  this.eventBus = eventBus;
26585
26622
  this.spec = spec;
26623
+ this.resolvePanelAppDisplayTarget = resolvePanelAppDisplayTarget;
26586
26624
  }
26587
26625
  get name() {
26588
26626
  return this.spec.name;
@@ -26594,7 +26632,27 @@ var ShowContentDisplayTool = class {
26594
26632
  return this.spec.parameters;
26595
26633
  }
26596
26634
  execute = async (args, context) => {
26597
- const request = this.spec.normalize(args);
26635
+ let request = this.spec.normalize(args);
26636
+ if (request.target.type === "panel_app" && !request.target.payload.path && this.resolvePanelAppDisplayTarget) {
26637
+ const appId = await this.resolvePanelAppDisplayTarget(request.target.payload.appId);
26638
+ if (!appId) return {
26639
+ ok: false,
26640
+ error: {
26641
+ code: "PANEL_APP_NOT_FOUND",
26642
+ message: "panel app not found"
26643
+ }
26644
+ };
26645
+ request = {
26646
+ ...request,
26647
+ target: {
26648
+ ...request.target,
26649
+ payload: {
26650
+ ...request.target.payload,
26651
+ appId
26652
+ }
26653
+ }
26654
+ };
26655
+ }
26598
26656
  this.eventBus.emit(eventKeys$1.uiShowContent, createShowContentEventPayload(request, context), { source: "kernel" });
26599
26657
  const resourceUri = request.target.type === "panel_app" ? createPanelAppResourceUri(request.target.payload.appId, request.target.payload.path) : void 0;
26600
26658
  return {
@@ -26683,7 +26741,7 @@ const SHOW_CONTENT_TOOL_SPECS = [
26683
26741
  properties: {
26684
26742
  appId: {
26685
26743
  type: "string",
26686
- description: "Installed Panel App id to show."
26744
+ description: "Installed App id or Panel component id to show. An App id opens its primary Panel."
26687
26745
  },
26688
26746
  path: {
26689
26747
  type: "string",
@@ -26709,16 +26767,24 @@ const SHOW_CONTENT_TOOL_SPECS = [
26709
26767
  normalize: normalizeShowPanelAppArgs
26710
26768
  }
26711
26769
  ];
26712
- function createShowContentTools(eventBus) {
26713
- return SHOW_CONTENT_TOOL_SPECS.map((spec) => new ShowContentDisplayTool(eventBus, spec));
26770
+ function createShowContentTools(eventBus, resolvePanelAppDisplayTarget) {
26771
+ return SHOW_CONTENT_TOOL_SPECS.map((spec) => new ShowContentDisplayTool(eventBus, spec, resolvePanelAppDisplayTarget));
26714
26772
  }
26715
26773
  //#endregion
26716
26774
  //#region src/contributions/tool-provider/providers/show-content-tool.provider.ts
26717
26775
  var ShowContentToolProvider = class {
26718
- constructor(eventBus) {
26776
+ constructor(eventBus, panelAppManager) {
26719
26777
  this.eventBus = eventBus;
26778
+ this.panelAppManager = panelAppManager;
26720
26779
  }
26721
- provide = () => createShowContentTools(this.eventBus);
26780
+ provide = () => createShowContentTools(this.eventBus, async (id) => {
26781
+ try {
26782
+ return (await this.panelAppManager.resolvePanelAppDisplayTarget(id)).appId;
26783
+ } catch (error) {
26784
+ if (isPanelAppError(error) && error.code === "PANEL_APP_NOT_FOUND") return;
26785
+ throw error;
26786
+ }
26787
+ });
26722
26788
  };
26723
26789
  //#endregion
26724
26790
  //#region src/tools/inbox-delivery.tools.ts
@@ -27803,7 +27869,7 @@ var ToolProviderContribution = class extends Contribution$1 {
27803
27869
  return [
27804
27870
  new StructuredResultToolProvider(),
27805
27871
  new ResourceToolProvider(this.kernel.systemObjectReferenceManager),
27806
- new ShowContentToolProvider(this.kernel.eventBus),
27872
+ new ShowContentToolProvider(this.kernel.eventBus, this.kernel.panelAppManager),
27807
27873
  new InboxDeliveryToolProvider(this.kernel.inboxDeliveryManager),
27808
27874
  new ObservationToolProvider(this.kernel.observations),
27809
27875
  new DesktopToolProvider(runContextService, this.kernel.extensions.getDesktopHost()),
@@ -27946,6 +28012,17 @@ var PlannedRestartRecoveryManager = class {
27946
28012
  return this.result("error", operationId);
27947
28013
  }
27948
28014
  };
28015
+ recoverFromSupervisor = async () => {
28016
+ try {
28017
+ const readResult = await this.readManifest();
28018
+ if (readResult.status === "missing") return this.result("none");
28019
+ if (readResult.status === "invalid") return this.result("invalid");
28020
+ return await this.recover(readResult.manifest.operationId);
28021
+ } catch (error) {
28022
+ console.error(`[planned-restart-recovery] failed to inspect supervisor manifest: ${String(error)}`);
28023
+ return this.result("error");
28024
+ }
28025
+ };
27949
28026
  continueClaimedRuns = async (manifest) => {
27950
28027
  const result = this.result("recovered", manifest.operationId);
27951
28028
  for (const run of manifest.runs) try {
@@ -29401,6 +29478,7 @@ var NextclawKernel = class {
29401
29478
  ingress: this.ingress,
29402
29479
  listPackageComponentSources: this.appPackageManager.listActiveComponentSources,
29403
29480
  listPackageComponentDiagnostics: async () => (await this.appPackageManager.listActiveComponentSourcesWithDiagnostics()).unavailablePackages,
29481
+ resolvePackagePrimaryPanelId: this.appPackageManager.resolvePrimaryPanelId,
29404
29482
  capabilityGrantManager: this.capabilityGrants
29405
29483
  });
29406
29484
  this.preferenceManager = new PreferenceManager({ storePath: resolveKernelPreferenceStorePath(options) });