@nextclaw/kernel 0.18.0 → 0.18.2

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
@@ -1267,6 +1267,8 @@ var ContextCompactionSummaryGenerationService = class {
1267
1267
  model: input.params.model,
1268
1268
  maxTokens: input.params.maxTokens,
1269
1269
  messages: input.messages,
1270
+ requestId: input.params.requestId,
1271
+ sessionId: input.params.sessionId,
1270
1272
  signal: input.params.signal,
1271
1273
  thinkingLevel: "off"
1272
1274
  });
@@ -1698,6 +1700,8 @@ var ContextCompactionPreflightService = class {
1698
1700
  maxTokens,
1699
1701
  messages,
1700
1702
  model: pending.model,
1703
+ requestId: pending.serviceMessageId,
1704
+ sessionId: pending.sessionId,
1701
1705
  signal,
1702
1706
  targetSummaryTokens
1703
1707
  });
@@ -4146,6 +4150,15 @@ var AppPackageManager = class {
4146
4150
  }
4147
4151
  });
4148
4152
  };
4153
+ resolvePrimaryPanelId = async (appId) => {
4154
+ try {
4155
+ const app = await this.getPackage(appId);
4156
+ return app.enabled ? app.primaryPanelId : void 0;
4157
+ } catch (error) {
4158
+ if (isAppPackageError(error) && error.code === "APP_PACKAGE_NOT_FOUND") return;
4159
+ throw error;
4160
+ }
4161
+ };
4149
4162
  inspectDependencies = async (appId) => await this.installationService.withAppOperation(appId, async () => await this.dependencyCoordinator.inspect(appId));
4150
4163
  verifyDependencies = async (appId) => await this.installationService.withAppOperation(appId, async () => await this.dependencyCoordinator.verify(appId));
4151
4164
  setupDependencies = async (appId) => {
@@ -8376,19 +8389,30 @@ var LlmProviderManager = class {
8376
8389
  };
8377
8390
  chat = async (params) => {
8378
8391
  const route = this.resolveRoute(params.model ?? null);
8379
- return (route ? this.getOrCreateProvider(route) : this.missingProvider).chat({
8380
- ...params,
8392
+ const provider = route ? this.getOrCreateProvider(route) : this.missingProvider;
8393
+ const { requestId, sessionId, ...providerParams } = params;
8394
+ return provider.chat({
8395
+ ...providerParams,
8381
8396
  model: route?.model ?? params.model,
8382
- messages: this.prepareMessagesForProvider(route, params.messages)
8397
+ messages: this.prepareMessagesForProvider(route, params.messages),
8398
+ requestHeaders: this.buildRequestHeaders(route, {
8399
+ requestId,
8400
+ sessionId
8401
+ })
8383
8402
  });
8384
8403
  };
8385
8404
  chatStream = async function* (params) {
8386
8405
  const route = this.resolveRoute(params.model ?? null);
8387
8406
  const provider = route ? this.getOrCreateProvider(route) : this.missingProvider;
8407
+ const { requestId, sessionId, ...providerParams } = params;
8388
8408
  for await (const event of provider.chatStream({
8389
- ...params,
8409
+ ...providerParams,
8390
8410
  model: route?.model ?? params.model,
8391
- messages: this.prepareMessagesForProvider(route, params.messages)
8411
+ messages: this.prepareMessagesForProvider(route, params.messages),
8412
+ requestHeaders: this.buildRequestHeaders(route, {
8413
+ requestId,
8414
+ sessionId
8415
+ })
8392
8416
  })) yield event;
8393
8417
  };
8394
8418
  testConnection = async (input) => {
@@ -8600,6 +8624,16 @@ var LlmProviderManager = class {
8600
8624
  })
8601
8625
  });
8602
8626
  };
8627
+ buildRequestHeaders = (route, context) => {
8628
+ if (route?.providerName !== "opencode") return;
8629
+ const sessionId = context.sessionId?.trim();
8630
+ const requestId = context.requestId?.trim();
8631
+ if (!sessionId && !requestId) return;
8632
+ return {
8633
+ ...sessionId ? { "x-opencode-session": sessionId } : {},
8634
+ ...requestId ? { "x-opencode-request": requestId } : {}
8635
+ };
8636
+ };
8603
8637
  buildCacheKey = (route) => {
8604
8638
  const routeProvider = route.provider;
8605
8639
  return [
@@ -10061,6 +10095,47 @@ function isPanelAppAssetTokenClaims(value) {
10061
10095
  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
10096
  }
10063
10097
  //#endregion
10098
+ //#region src/services/panel-app-entry-resolver.service.ts
10099
+ var PanelAppEntryResolverService = class {
10100
+ constructor(params) {
10101
+ this.params = params;
10102
+ }
10103
+ list = async () => {
10104
+ const workspacePath = this.params.getWorkspacePath();
10105
+ const panelsPath = this.params.getPanelsPath(workspacePath);
10106
+ const sources = await this.params.listSources();
10107
+ const appState = await this.params.loadState();
10108
+ return {
10109
+ workspacePath,
10110
+ panelsPath,
10111
+ entries: (await Promise.all(sources.map(({ source, packageSource }) => this.params.buildEntry(source, appState.apps[encodePanelAppId(source.sourceName)] ?? {}, packageSource, appState.mainSidebarAppIds)))).sort(this.params.compareEntries),
10112
+ unavailablePackages: await this.params.listPackageComponentDiagnostics?.() ?? []
10113
+ };
10114
+ };
10115
+ get = async (id) => {
10116
+ const resolved = await this.params.resolveSourceByIdOrAppId(id);
10117
+ const appState = await this.params.loadState();
10118
+ return await this.params.buildEntry(resolved.source, appState.apps[encodePanelAppId(resolved.source.sourceName)] ?? {}, resolved.packageSource, appState.mainSidebarAppIds);
10119
+ };
10120
+ resolveDisplayTarget = async (id) => {
10121
+ try {
10122
+ return await this.get(id);
10123
+ } catch (error) {
10124
+ this.rethrowUnexpectedResolutionError(error);
10125
+ }
10126
+ const primaryPanelId = await this.params.resolvePackagePrimaryPanelId?.(id);
10127
+ if (primaryPanelId) try {
10128
+ return await this.get(primaryPanelId);
10129
+ } catch (error) {
10130
+ this.rethrowUnexpectedResolutionError(error);
10131
+ }
10132
+ throw new PanelAppError("PANEL_APP_NOT_FOUND", "panel app not found");
10133
+ };
10134
+ rethrowUnexpectedResolutionError = (error) => {
10135
+ if (!isPanelAppError(error) || error.code !== "PANEL_APP_NOT_FOUND" && error.code !== "PANEL_APP_INVALID_ID") throw error;
10136
+ };
10137
+ };
10138
+ //#endregion
10064
10139
  //#region src/stores/panel-app-state.store.ts
10065
10140
  const PANEL_APP_STATE_FILE = ".panel-apps.state.json";
10066
10141
  const PANEL_APP_STATE_VERSION = 2;
@@ -11076,6 +11151,7 @@ var PanelAppManager = class {
11076
11151
  sourceService = new PanelAppSourceService();
11077
11152
  packageStateManager;
11078
11153
  entryPresenter;
11154
+ entryResolver;
11079
11155
  removalService;
11080
11156
  constructor(params) {
11081
11157
  this.params = params;
@@ -11105,25 +11181,21 @@ var PanelAppManager = class {
11105
11181
  createAssetBaseHref: this.createAssetBaseHref,
11106
11182
  isClientGranted: this.isPanelAppClientGranted
11107
11183
  });
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
- };
11184
+ this.entryResolver = new PanelAppEntryResolverService({
11185
+ getWorkspacePath: this.getWorkspacePath,
11186
+ getPanelsPath: this.getPanelsPath,
11187
+ listSources: this.packageStateManager.listSources,
11188
+ listPackageComponentDiagnostics: params.listPackageComponentDiagnostics,
11189
+ resolveSourceByIdOrAppId: this.packageStateManager.resolveSourceByIdOrAppId,
11190
+ loadState: async () => await this.createStateStore(this.getPanelsPath(this.getWorkspacePath())).load(),
11191
+ buildEntry: this.entryPresenter.build,
11192
+ compareEntries: this.entryPresenter.compare,
11193
+ resolvePackagePrimaryPanelId: params.resolvePackagePrimaryPanelId
11194
+ });
11195
+ }
11196
+ listPanelApps = async () => await this.entryResolver.list();
11197
+ getPanelApp = async (id) => await this.entryResolver.get(id);
11198
+ resolvePanelAppDisplayTarget = async (id) => await this.entryResolver.resolveDisplayTarget(id);
11127
11199
  getPanelAppContent = async (id, sourcePath) => {
11128
11200
  try {
11129
11201
  const resolved = sourcePath ? await readPanelAppContentSourceByIdOrPath({
@@ -18206,6 +18278,8 @@ var SessionTitleService = class {
18206
18278
  model: typeof metadata.preferred_model === "string" ? metadata.preferred_model : typeof metadata.model === "string" ? metadata.model : void 0,
18207
18279
  maxTokens: 160,
18208
18280
  thinkingLevel: "off",
18281
+ sessionId,
18282
+ requestId: lastMessage.id,
18209
18283
  signal,
18210
18284
  messages: [{
18211
18285
  role: "system",
@@ -23565,6 +23639,8 @@ var ProviderManagerNcpLLMApi = class {
23565
23639
  model,
23566
23640
  ...thinkingLevel ? { thinkingLevel } : {},
23567
23641
  maxTokens: input.max_tokens,
23642
+ sessionId: options?.sessionId,
23643
+ requestId: options?.requestId,
23568
23644
  signal: options?.signal
23569
23645
  })) {
23570
23646
  if (event.type === "delta") {
@@ -24552,15 +24628,6 @@ const createSelfUpdateContextProvider = () => staticBlock([
24552
24628
  "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
24629
  `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
24630
  ]);
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
24631
  const createMessagingContextProvider = () => staticBlock([
24565
24632
  "## Messaging",
24566
24633
  "- Reply normally in the current conversation; routing to its source channel is automatic.",
@@ -25243,7 +25310,6 @@ var ContextProviderContribution = class extends Contribution$1 {
25243
25310
  createSafetyContextProvider(),
25244
25311
  createCliQuickReferenceContextProvider(),
25245
25312
  createSelfUpdateContextProvider(),
25246
- createReplyTagsContextProvider(),
25247
25313
  createMessagingContextProvider(),
25248
25314
  createMemoryRecallContextProvider(),
25249
25315
  createSilentRepliesContextProvider(),
@@ -26580,9 +26646,10 @@ function createShowContentEventPayload(request, context) {
26580
26646
  };
26581
26647
  }
26582
26648
  var ShowContentDisplayTool = class {
26583
- constructor(eventBus, spec) {
26649
+ constructor(eventBus, spec, resolvePanelAppDisplayTarget) {
26584
26650
  this.eventBus = eventBus;
26585
26651
  this.spec = spec;
26652
+ this.resolvePanelAppDisplayTarget = resolvePanelAppDisplayTarget;
26586
26653
  }
26587
26654
  get name() {
26588
26655
  return this.spec.name;
@@ -26594,7 +26661,27 @@ var ShowContentDisplayTool = class {
26594
26661
  return this.spec.parameters;
26595
26662
  }
26596
26663
  execute = async (args, context) => {
26597
- const request = this.spec.normalize(args);
26664
+ let request = this.spec.normalize(args);
26665
+ if (request.target.type === "panel_app" && !request.target.payload.path && this.resolvePanelAppDisplayTarget) {
26666
+ const appId = await this.resolvePanelAppDisplayTarget(request.target.payload.appId);
26667
+ if (!appId) return {
26668
+ ok: false,
26669
+ error: {
26670
+ code: "PANEL_APP_NOT_FOUND",
26671
+ message: "panel app not found"
26672
+ }
26673
+ };
26674
+ request = {
26675
+ ...request,
26676
+ target: {
26677
+ ...request.target,
26678
+ payload: {
26679
+ ...request.target.payload,
26680
+ appId
26681
+ }
26682
+ }
26683
+ };
26684
+ }
26598
26685
  this.eventBus.emit(eventKeys$1.uiShowContent, createShowContentEventPayload(request, context), { source: "kernel" });
26599
26686
  const resourceUri = request.target.type === "panel_app" ? createPanelAppResourceUri(request.target.payload.appId, request.target.payload.path) : void 0;
26600
26687
  return {
@@ -26683,7 +26770,7 @@ const SHOW_CONTENT_TOOL_SPECS = [
26683
26770
  properties: {
26684
26771
  appId: {
26685
26772
  type: "string",
26686
- description: "Installed Panel App id to show."
26773
+ description: "Installed App id or Panel component id to show. An App id opens its primary Panel."
26687
26774
  },
26688
26775
  path: {
26689
26776
  type: "string",
@@ -26709,16 +26796,24 @@ const SHOW_CONTENT_TOOL_SPECS = [
26709
26796
  normalize: normalizeShowPanelAppArgs
26710
26797
  }
26711
26798
  ];
26712
- function createShowContentTools(eventBus) {
26713
- return SHOW_CONTENT_TOOL_SPECS.map((spec) => new ShowContentDisplayTool(eventBus, spec));
26799
+ function createShowContentTools(eventBus, resolvePanelAppDisplayTarget) {
26800
+ return SHOW_CONTENT_TOOL_SPECS.map((spec) => new ShowContentDisplayTool(eventBus, spec, resolvePanelAppDisplayTarget));
26714
26801
  }
26715
26802
  //#endregion
26716
26803
  //#region src/contributions/tool-provider/providers/show-content-tool.provider.ts
26717
26804
  var ShowContentToolProvider = class {
26718
- constructor(eventBus) {
26805
+ constructor(eventBus, panelAppManager) {
26719
26806
  this.eventBus = eventBus;
26807
+ this.panelAppManager = panelAppManager;
26720
26808
  }
26721
- provide = () => createShowContentTools(this.eventBus);
26809
+ provide = () => createShowContentTools(this.eventBus, async (id) => {
26810
+ try {
26811
+ return (await this.panelAppManager.resolvePanelAppDisplayTarget(id)).appId;
26812
+ } catch (error) {
26813
+ if (isPanelAppError(error) && error.code === "PANEL_APP_NOT_FOUND") return;
26814
+ throw error;
26815
+ }
26816
+ });
26722
26817
  };
26723
26818
  //#endregion
26724
26819
  //#region src/tools/inbox-delivery.tools.ts
@@ -27803,7 +27898,7 @@ var ToolProviderContribution = class extends Contribution$1 {
27803
27898
  return [
27804
27899
  new StructuredResultToolProvider(),
27805
27900
  new ResourceToolProvider(this.kernel.systemObjectReferenceManager),
27806
- new ShowContentToolProvider(this.kernel.eventBus),
27901
+ new ShowContentToolProvider(this.kernel.eventBus, this.kernel.panelAppManager),
27807
27902
  new InboxDeliveryToolProvider(this.kernel.inboxDeliveryManager),
27808
27903
  new ObservationToolProvider(this.kernel.observations),
27809
27904
  new DesktopToolProvider(runContextService, this.kernel.extensions.getDesktopHost()),
@@ -27946,6 +28041,17 @@ var PlannedRestartRecoveryManager = class {
27946
28041
  return this.result("error", operationId);
27947
28042
  }
27948
28043
  };
28044
+ recoverFromSupervisor = async () => {
28045
+ try {
28046
+ const readResult = await this.readManifest();
28047
+ if (readResult.status === "missing") return this.result("none");
28048
+ if (readResult.status === "invalid") return this.result("invalid");
28049
+ return await this.recover(readResult.manifest.operationId);
28050
+ } catch (error) {
28051
+ console.error(`[planned-restart-recovery] failed to inspect supervisor manifest: ${String(error)}`);
28052
+ return this.result("error");
28053
+ }
28054
+ };
27949
28055
  continueClaimedRuns = async (manifest) => {
27950
28056
  const result = this.result("recovered", manifest.operationId);
27951
28057
  for (const run of manifest.runs) try {
@@ -29401,6 +29507,7 @@ var NextclawKernel = class {
29401
29507
  ingress: this.ingress,
29402
29508
  listPackageComponentSources: this.appPackageManager.listActiveComponentSources,
29403
29509
  listPackageComponentDiagnostics: async () => (await this.appPackageManager.listActiveComponentSourcesWithDiagnostics()).unavailablePackages,
29510
+ resolvePackagePrimaryPanelId: this.appPackageManager.resolvePrimaryPanelId,
29404
29511
  capabilityGrantManager: this.capabilityGrants
29405
29512
  });
29406
29513
  this.preferenceManager = new PreferenceManager({ storePath: resolveKernelPreferenceStorePath(options) });