akanjs 3.1.0-rc.8 → 3.1.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.
- package/CHANGELOG.md +547 -0
- package/README.ko.md +2 -2
- package/README.md +2 -2
- package/client/cookie.ts +5 -0
- package/client/csrLocation.ts +17 -72
- package/client/csrTypes.ts +19 -4
- package/client/href.ts +8 -0
- package/client/makePageProto.tsx +3 -2
- package/client/route/PageDefinition.ts +103 -10
- package/client/route/RouteDefinition.ts +44 -3
- package/client/route/RouteGuards.ts +64 -0
- package/client/route/index.ts +1 -0
- package/client/route/resolveRouteModule.ts +8 -0
- package/client/route/routeArgs.ts +9 -0
- package/client/router.ts +51 -2
- package/client/translator.ts +16 -0
- package/client/viewportMeta.ts +23 -8
- package/common/Logger.ts +6 -4
- package/common/authCookie.ts +13 -0
- package/common/authToken.ts +1 -12
- package/common/codeAgentWire.ts +8 -1
- package/common/index.ts +2 -8
- package/common/routeConvention.ts +2 -0
- package/constant/inputParser.ts +1 -1
- package/dictionary/base.dictionary.ts +11 -0
- package/document/database.ts +3 -0
- package/document/documentQuery.ts +21 -0
- package/document/into.ts +2 -0
- package/document/liveRowScope.ts +4 -8
- package/document/noDocumentError.ts +6 -1
- package/document/queryEvaluator.ts +5 -8
- package/fetch/appScope.ts +54 -0
- package/fetch/client/fetchClient.ts +46 -29
- package/fetch/client/httpClient.ts +38 -10
- package/fetch/client/sliceInitHandle.ts +2 -3
- package/fetch/client/wsClient.ts +3 -1
- package/fetch/fetchType/endpointFetch.type.ts +11 -9
- package/fetch/index.ts +1 -0
- package/index.ts +2 -0
- package/package.json +32 -22
- package/server/akanApp.ts +12 -3
- package/server/akanServer.ts +10 -5
- package/server/index.ts +1 -0
- package/server/mcp/McpApps.ts +44 -50
- package/server/mcp/McpDispatcher.ts +3 -3
- package/server/mcp/McpPages.ts +93 -19
- package/server/mcp/McpRouter.ts +14 -11
- package/server/memoryLimit.ts +4 -0
- package/server/migration/docPath.ts +121 -0
- package/server/migration/index.ts +15 -0
- package/server/migration/migrationChangeLog.ts +86 -0
- package/server/migration/migrationChanges.ts +70 -0
- package/server/migration/migrationCommand.ts +179 -0
- package/server/migration/migrationContext.ts +53 -0
- package/server/migration/migrationDefinition.ts +87 -0
- package/server/migration/migrationError.ts +45 -0
- package/server/migration/migrationLedger.ts +172 -0
- package/server/migration/migrationLock.ts +103 -0
- package/server/migration/migrationParams.ts +122 -0
- package/server/migration/migrationPulse.ts +39 -0
- package/server/migration/migrationRunner.ts +525 -0
- package/server/migration/migrationScope.ts +93 -0
- package/server/migration/migrationTable.ts +258 -0
- package/server/migration/migrations.ts +57 -0
- package/server/ops/migrateJobs.ts +145 -0
- package/server/ops/opsCommand.ts +30 -1
- package/server/ops/opsRoute.ts +39 -7
- package/server/ops/opsToken.ts +7 -2
- package/server/resolver/CascadeRunner.ts +15 -2
- package/server/resolver/database.resolver.ts +4 -0
- package/server/resolver/service.resolver.ts +3 -0
- package/server/resolver/signal.resolver.ts +41 -31
- package/server/routeElementComposer.tsx +33 -6
- package/server/routeState.ts +1 -0
- package/server/routeTreeBuilder.ts +5 -0
- package/server/rscClient.tsx +67 -22
- package/server/rscClientFetch.ts +8 -3
- package/server/rscNavigationState.ts +2 -2
- package/server/rscPagePrompts.ts +66 -16
- package/server/rscScrollRestoration.ts +21 -8
- package/server/rscWorker.tsx +79 -32
- package/server/rscWorkerHost.ts +12 -1
- package/server/tunnel/TunnelAgent.ts +2 -1
- package/server/webRouter.ts +33 -27
- package/service/agent.service.ts +21 -1
- package/service/endpointCacheKeys.ts +35 -0
- package/service/index.ts +1 -0
- package/service/liveSyncHub.ts +2 -1
- package/service/predefinedAdaptor/anthropicLlm.ts +37 -17
- package/service/predefinedAdaptor/database.adaptor.ts +98 -25
- package/service/predefinedAdaptor/documentTransfer.ts +50 -0
- package/service/predefinedAdaptor/endpointCacheControl.adaptor.ts +19 -0
- package/service/predefinedAdaptor/index.ts +1 -0
- package/service/predefinedAdaptor/llm.adaptor.ts +7 -0
- package/service/predefinedAdaptor/openaiDialect.ts +53 -17
- package/service/predefinedAdaptor/openaiLlm.ts +1 -1
- package/service/predefinedAdaptor/solidQueue.adaptor.ts +30 -9
- package/service/predefinedAdaptor/sql/MigrationTables.ts +90 -0
- package/service/predefinedAdaptor/sql/QueryCompiler.ts +16 -14
- package/service/predefinedAdaptor/sql/RawDocumentTable.ts +200 -0
- package/service/predefinedAdaptor/sql/SqlDocumentStore.ts +218 -44
- package/service/predefinedAdaptor/sql/SqliteInsightSession.ts +4 -1
- package/service/predefinedAdaptor/sql/dialect/postgres.ts +13 -3
- package/service/predefinedAdaptor/sql/dialect/sqlite.ts +13 -2
- package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +4 -5
- package/service/predefinedAdaptor/sql/types.ts +22 -1
- package/service/predefinedAdaptor/sql/values.ts +19 -0
- package/service/predefinedAdaptor/storage.adaptor.ts +19 -0
- package/service/serviceModule.ts +3 -0
- package/service/types.ts +1 -0
- package/signal/TaggedJson.ts +26 -4
- package/signal/endpointCache.ts +16 -6
- package/signal/exception.ts +4 -1
- package/signal/mcp/mcpProtocol.ts +7 -0
- package/signal/mcp/pagePrompt.ts +18 -1
- package/signal/signalContext.ts +7 -10
- package/store/action.ts +181 -73
- package/store/agent/ScreenImage.ts +166 -0
- package/store/agent/StoreSurfaceSource.ts +41 -2
- package/store/agent/index.ts +2 -1
- package/store/databaseStateNames.ts +1 -0
- package/store/formUploadOf.ts +41 -0
- package/store/index.ts +1 -0
- package/store/liveInsert.ts +5 -1
- package/store/sliceKeys.ts +1 -0
- package/store/state.ts +15 -3
- package/store/stateBuilder.ts +7 -1
- package/store/storeInstance.ts +22 -4
- package/types/client/csrLocation.d.ts +3 -7
- package/types/client/csrTypes.d.ts +22 -3
- package/types/client/href.d.ts +3 -0
- package/types/client/route/PageDefinition.d.ts +21 -4
- package/types/client/route/RouteDefinition.d.ts +4 -0
- package/types/client/route/RouteGuards.d.ts +15 -0
- package/types/client/route/index.d.ts +1 -0
- package/types/client/route/resolveRouteModule.d.ts +2 -0
- package/types/client/route/routeArgs.d.ts +5 -0
- package/types/client/route/routeBuilders.d.ts +1 -1
- package/types/client/router.d.ts +9 -1
- package/types/client/translator.d.ts +2 -0
- package/types/common/authCookie.d.ts +5 -0
- package/types/common/authToken.d.ts +0 -5
- package/types/common/codeAgentWire.d.ts +7 -0
- package/types/common/index.d.ts +2 -1
- package/types/dictionary/base.dictionary.d.ts +1 -1
- package/types/dictionary/dictionary.d.ts +8 -8
- package/types/document/database.d.ts +3 -0
- package/types/document/documentQuery.d.ts +1 -0
- package/types/document/into.d.ts +2 -0
- package/types/document/noDocumentError.d.ts +6 -1
- package/types/fetch/appScope.d.ts +18 -0
- package/types/fetch/client/fetchClient.d.ts +1 -1
- package/types/fetch/fetchType/endpointFetch.type.d.ts +1 -1
- package/types/fetch/index.d.ts +1 -0
- package/types/index.d.ts +5 -0
- package/types/server/akanServer.d.ts +10 -5
- package/types/server/index.d.ts +1 -0
- package/types/server/mcp/McpApps.d.ts +14 -8
- package/types/server/mcp/McpPages.d.ts +6 -3
- package/types/server/migration/docPath.d.ts +20 -0
- package/types/server/migration/index.d.ts +15 -0
- package/types/server/migration/migrationChangeLog.d.ts +27 -0
- package/types/server/migration/migrationChanges.d.ts +27 -0
- package/types/server/migration/migrationCommand.d.ts +33 -0
- package/types/server/migration/migrationContext.d.ts +28 -0
- package/types/server/migration/migrationDefinition.d.ts +42 -0
- package/types/server/migration/migrationError.d.ts +15 -0
- package/types/server/migration/migrationLedger.d.ts +51 -0
- package/types/server/migration/migrationLock.d.ts +34 -0
- package/types/server/migration/migrationParams.d.ts +41 -0
- package/types/server/migration/migrationPulse.d.ts +15 -0
- package/types/server/migration/migrationRunner.d.ts +93 -0
- package/types/server/migration/migrationScope.d.ts +42 -0
- package/types/server/migration/migrationTable.d.ts +52 -0
- package/types/server/migration/migrations.d.ts +12 -0
- package/types/server/migration.d.ts +1 -0
- package/types/server/ops/migrateJobs.d.ts +36 -0
- package/types/server/ops/opsCommand.d.ts +10 -1
- package/types/server/ops/opsRoute.d.ts +4 -1
- package/types/server/ops/opsToken.d.ts +3 -0
- package/types/server/routeElementComposer.d.ts +10 -1
- package/types/server/routeState.d.ts +1 -0
- package/types/server/rscClientFetch.d.ts +2 -0
- package/types/server/rscNavigationState.d.ts +1 -1
- package/types/server/rscPagePrompts.d.ts +3 -1
- package/types/server/rscScrollRestoration.d.ts +2 -0
- package/types/server/rscWorkerHost.d.ts +2 -1
- package/types/server/webRouter.d.ts +3 -0
- package/types/service/agent.service.d.ts +2 -0
- package/types/service/endpointCacheKeys.d.ts +8 -0
- package/types/service/index.d.ts +1 -0
- package/types/service/predefinedAdaptor/anthropicLlm.d.ts +9 -4
- package/types/service/predefinedAdaptor/database.adaptor.d.ts +21 -2
- package/types/service/predefinedAdaptor/documentTransfer.d.ts +1 -0
- package/types/service/predefinedAdaptor/endpointCacheControl.adaptor.d.ts +9 -0
- package/types/service/predefinedAdaptor/index.d.ts +1 -0
- package/types/service/predefinedAdaptor/llm.adaptor.d.ts +7 -0
- package/types/service/predefinedAdaptor/openaiDialect.d.ts +20 -5
- package/types/service/predefinedAdaptor/solidQueue.adaptor.d.ts +1 -0
- package/types/service/predefinedAdaptor/sql/MigrationTables.d.ts +17 -0
- package/types/service/predefinedAdaptor/sql/QueryCompiler.d.ts +0 -1
- package/types/service/predefinedAdaptor/sql/RawDocumentTable.d.ts +38 -0
- package/types/service/predefinedAdaptor/sql/SqlDocumentStore.d.ts +1 -0
- package/types/service/predefinedAdaptor/sql/dialect/postgres.d.ts +2 -1
- package/types/service/predefinedAdaptor/sql/dialect/sqlite.d.ts +3 -1
- package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +2 -2
- package/types/service/predefinedAdaptor/sql/types.d.ts +26 -0
- package/types/service/predefinedAdaptor/sql/values.d.ts +1 -0
- package/types/service/predefinedAdaptor/storage.adaptor.d.ts +8 -0
- package/types/service/types.d.ts +1 -0
- package/types/signal/exception.d.ts +4 -1
- package/types/signal/mcp/mcpProtocol.d.ts +6 -0
- package/types/signal/mcp/pagePrompt.d.ts +16 -0
- package/types/signal/signalContext.d.ts +0 -2
- package/types/store/action.d.ts +2 -0
- package/types/store/agent/ScreenImage.d.ts +27 -0
- package/types/store/agent/StoreSurfaceSource.d.ts +1 -1
- package/types/store/agent/index.d.ts +2 -1
- package/types/store/databaseStateNames.d.ts +1 -0
- package/types/store/formUploadOf.d.ts +9 -0
- package/types/store/index.d.ts +1 -0
- package/types/store/liveInsert.d.ts +3 -1
- package/types/store/sliceKeys.d.ts +1 -0
- package/types/store/state.d.ts +10 -4
- package/types/store/stateBuilder.d.ts +1 -0
- package/types/ui/Agent/Composer.d.ts +2 -0
- package/types/ui/Agent/Menu.d.ts +2 -0
- package/types/ui/CsrImage.d.ts +2 -0
- package/types/ui/Image.d.ts +3 -1
- package/types/ui/Layout/FrameSlotPortal.d.ts +1 -1
- package/types/ui/Load/sliceClaim.d.ts +28 -0
- package/types/ui/Model/Edit.d.ts +3 -2
- package/types/ui/Model/editSeed.d.ts +4 -0
- package/types/ui/System/App.d.ts +17 -0
- package/types/ui/System/index.d.ts +2 -0
- package/types/ui/recipe/badgeRecipe.d.ts +2 -2
- package/types/ui/recipe/buttonRecipe.d.ts +2 -2
- package/types/ui/sliceNamesOf.d.ts +2 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/compat.d.ts +6 -0
- package/types/vendor/@akanjs/native/packages/cli/src/lib/toolchains.d.ts +2 -2
- package/types/vendor/use-agentic/Compaction.d.ts +3 -1
- package/types/vendor/use-agentic/Reference.d.ts +7 -2
- package/types/vendor/use-agentic/ToolOutput.d.ts +6 -1
- package/types/vendor/use-agentic/ToolReturn.d.ts +18 -0
- package/types/vendor/use-agentic/Transcript.d.ts +7 -0
- package/types/vendor/use-agentic/index.d.ts +1 -0
- package/types/vendor/use-agentic/types.d.ts +6 -0
- package/types/webkit/CsrGuards.d.ts +25 -0
- package/types/webkit/CsrRouteTable.d.ts +6 -0
- package/types/webkit/CsrStack.d.ts +7 -0
- package/types/webkit/McpAppBoot.d.ts +32 -0
- package/types/webkit/McpAppBridge.d.ts +10 -1
- package/types/webkit/McpAppFetchBridge.d.ts +3 -1
- package/types/webkit/McpAppView.d.ts +4 -1
- package/types/webkit/PageNotFound.d.ts +5 -0
- package/types/webkit/RenderLayer.d.ts +1 -3
- package/types/webkit/index.d.ts +1 -0
- package/types/webkit/useDebounce.d.ts +1 -1
- package/ui/Agent/Chat.tsx +1 -0
- package/ui/Agent/Composer.tsx +2 -0
- package/ui/Agent/Menu.tsx +5 -1
- package/ui/Agent/agentSessionOf.ts +15 -8
- package/ui/Agent/mentionDraft.ts +2 -3
- package/ui/Agent/useReferenceMenu.ts +1 -0
- package/ui/Agent/useSlashMenu.ts +1 -0
- package/ui/CsrImage.tsx +3 -1
- package/ui/Dialog/LegacyModal.tsx +7 -5
- package/ui/Dialog/Modal.tsx +7 -4
- package/ui/Field/Collection.tsx +2 -1
- package/ui/Image.tsx +4 -4
- package/ui/Layout/BottomInset.tsx +2 -11
- package/ui/Layout/FrameSlotPortal.tsx +1 -3
- package/ui/Layout/Navbar.tsx +7 -22
- package/ui/Layout/TopInset.tsx +3 -4
- package/ui/Load/Units.tsx +34 -12
- package/ui/Load/sliceClaim.ts +164 -0
- package/ui/Model/Edit.tsx +22 -3
- package/ui/Model/EditModal.tsx +22 -6
- package/ui/Model/LoadStore.tsx +1 -1
- package/ui/Model/NewWrapper_Client.tsx +1 -1
- package/ui/Model/ViewEditModal.tsx +9 -3
- package/ui/Model/editSeed.ts +28 -0
- package/ui/System/App.tsx +43 -0
- package/ui/System/CSR.tsx +1 -10
- package/ui/System/Client.tsx +3 -0
- package/ui/System/index.tsx +3 -0
- package/ui/Tab/Provider.tsx +6 -8
- package/ui/styles.css +10 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeBridge.swift +3 -2
- package/vendor/@akanjs/native/packages/cli/src/lib/compat.ts +6 -2
- package/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.ts +1 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/toolchains.ts +1 -1
- package/vendor/@akanjs/native/packages/cli/src/lib/updates.ts +3 -3
- package/vendor/@akanjs/native/plugins/sqlite/src/desktop.ts +10 -5
- package/vendor/@akanjs/native/plugins/updates/src/desktop.ts +45 -15
- package/vendor/use-agentic/CHANGELOG.md +31 -0
- package/vendor/use-agentic/Compaction.ts +38 -7
- package/vendor/use-agentic/Reference.ts +14 -10
- package/vendor/use-agentic/ToolOutput.ts +25 -3
- package/vendor/use-agentic/ToolReturn.ts +32 -0
- package/vendor/use-agentic/ToolRunner.ts +15 -13
- package/vendor/use-agentic/Transcript.ts +38 -2
- package/vendor/use-agentic/WIRE.md +20 -0
- package/vendor/use-agentic/index.ts +1 -0
- package/vendor/use-agentic/types.ts +6 -0
- package/webkit/CsrGuards.ts +112 -0
- package/webkit/CsrRouteTable.ts +71 -16
- package/webkit/CsrStack.ts +47 -1
- package/webkit/McpAppAgent.ts +14 -2
- package/webkit/McpAppBoot.tsx +129 -0
- package/webkit/McpAppBridge.ts +30 -6
- package/webkit/McpAppFetchBridge.ts +8 -2
- package/webkit/McpAppView.ts +39 -28
- package/webkit/PageNotFound.tsx +24 -0
- package/webkit/RenderLayer.tsx +106 -30
- package/webkit/bootCsr.tsx +4 -43
- package/webkit/index.ts +1 -0
- package/webkit/useCsrValues.ts +66 -6
- package/webkit/useDebounce.ts +23 -14
- package/webkit/useEscapeKey.tsx +1 -1
- package/webkit/useLocation.ts +21 -19
- package/types/webkit/EmbeddedLayout.d.ts +0 -10
- package/webkit/EmbeddedLayout.tsx +0 -82
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
ServiceSignal,
|
|
21
21
|
} from "akanjs/signal";
|
|
22
22
|
import { agentTurnConstant } from "../agentTurn";
|
|
23
|
+
import { AppScope } from "../appScope";
|
|
23
24
|
import type { ClientSignal, FetchClientType, FetchSignalInput, MergeAllFetchTypes, SliceMeta } from "../fetchType";
|
|
24
25
|
import {
|
|
25
26
|
claimRequestQuery,
|
|
@@ -30,7 +31,7 @@ import {
|
|
|
30
31
|
import type { GetSliceMetaObjFromDatabaseSignals } from "../types";
|
|
31
32
|
import { FetchHandle } from "./fetchHandle";
|
|
32
33
|
import { HttpClient } from "./httpClient";
|
|
33
|
-
import type
|
|
34
|
+
import { type ErrorConstructor, type RestoredError, restoreRemoteError } from "./remoteError";
|
|
34
35
|
import { SliceInitHandle } from "./sliceInitHandle";
|
|
35
36
|
import { expandQueryArgs, normalizeQueryArgs } from "./sliceQueryArgs";
|
|
36
37
|
import { WsClient, type WsClientOptions } from "./wsClient";
|
|
@@ -440,8 +441,8 @@ export class FetchClient {
|
|
|
440
441
|
const payload = claim.owned ? response : FetchClient.#deepCopy(response);
|
|
441
442
|
return parseReturn(payload, { crystalize: option?.crystalize ?? true });
|
|
442
443
|
};
|
|
443
|
-
case "mutation":
|
|
444
|
-
|
|
444
|
+
case "mutation": {
|
|
445
|
+
const send = async (...argData: unknown[]) => {
|
|
445
446
|
const { option, argMap, url } = requestOf(argData);
|
|
446
447
|
const bridge = this.#bridgeOf(option?.origin);
|
|
447
448
|
if (bridge)
|
|
@@ -458,6 +459,12 @@ export class FetchClient {
|
|
|
458
459
|
});
|
|
459
460
|
return parseReturn(response, { crystalize: option?.crystalize ?? true });
|
|
460
461
|
};
|
|
462
|
+
|
|
463
|
+
return (...argData: unknown[]) => {
|
|
464
|
+
this.#refuseInApp(key);
|
|
465
|
+
return send(...argData);
|
|
466
|
+
};
|
|
467
|
+
}
|
|
461
468
|
default:
|
|
462
469
|
throw new Error(`Unsupported endpoint type: ${endpoint.type}`);
|
|
463
470
|
}
|
|
@@ -476,6 +483,7 @@ export class FetchClient {
|
|
|
476
483
|
const parseReturn = this.#makeReturnParser(endpoint.returns);
|
|
477
484
|
const wrappedListeners = new WeakMap<(data: unknown) => void, (data: unknown) => void>();
|
|
478
485
|
return (...argData: unknown[]) => {
|
|
486
|
+
this.#refuseInApp(key);
|
|
479
487
|
|
|
480
488
|
if (FetchClient.bridged) return () => undefined;
|
|
481
489
|
const args = argData.slice(0, roomArgLength);
|
|
@@ -507,6 +515,7 @@ export class FetchClient {
|
|
|
507
515
|
const msgArgLength = msgArgs.length;
|
|
508
516
|
const serializerMap = this.#makeArgSerializer(endpoint.args);
|
|
509
517
|
return (...argData: unknown[]) => {
|
|
518
|
+
this.#refuseInApp(key);
|
|
510
519
|
if (FetchClient.bridged) return;
|
|
511
520
|
const args = argData.slice(0, msgArgLength);
|
|
512
521
|
const fetchPolicy = argData[msgArgLength] as FetchPolicy | undefined;
|
|
@@ -536,6 +545,12 @@ export class FetchClient {
|
|
|
536
545
|
}
|
|
537
546
|
}
|
|
538
547
|
|
|
548
|
+
#refuseInApp(endpoint: string) {
|
|
549
|
+
const app = AppScope.current();
|
|
550
|
+
if (app)
|
|
551
|
+
throw restoreRemoteError({ error: "base.error.mutationInApp", data: { app, endpoint } }, 400, this.ErrorCls);
|
|
552
|
+
}
|
|
553
|
+
|
|
539
554
|
#bridgeOf(origin?: string) {
|
|
540
555
|
return origin || this.#foreign ? null : FetchClient.bridge;
|
|
541
556
|
}
|
|
@@ -707,32 +722,34 @@ export class FetchClient {
|
|
|
707
722
|
);
|
|
708
723
|
}
|
|
709
724
|
|
|
710
|
-
this.#setHandlerFactory(
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
725
|
+
this.#setHandlerFactory(names.addModelFiles, () => {
|
|
726
|
+
const upload = async (fileList: FileList | File[], parentId?: string, option?: FetchPolicy) => {
|
|
727
|
+
|
|
728
|
+
if (this.#bridgeOf())
|
|
729
|
+
throw new Error("File upload is unavailable in an MCP App view: its host relays tool calls, not files.");
|
|
730
|
+
const cap = resolveFileUploadCapability(this.serializedSignal);
|
|
731
|
+
const endpoint = cap ? this.serializedSignal[cap.refName]?.endpoint[cap.endpointKey] : undefined;
|
|
732
|
+
if (!cap || !endpoint)
|
|
733
|
+
throw new Error(
|
|
734
|
+
"File upload is not configured. Mark an upload mutation with { fileUpload: true } (e.g. shared FileEndpoint.addFiles).",
|
|
735
|
+
);
|
|
736
|
+
const { fields, buildMetas } = fileUploadContract;
|
|
737
|
+
const formData = new FormData();
|
|
738
|
+
for (let i = 0; i < fileList.length; i++) formData.append(fields.files, fileList[i]);
|
|
739
|
+
formData.append(fields.metas, JSON.stringify(buildMetas(fileList)));
|
|
740
|
+
formData.append(fields.type, refName);
|
|
741
|
+
if (parentId) formData.append(fields.parentId, parentId);
|
|
742
|
+
const url = FetchClient.makeHttpUrl(cap.endpointKey, endpoint, cap.prefix, new Map());
|
|
743
|
+
return await this.http.post(url, formData, {
|
|
744
|
+
headers: this.#makeRequestHeaders(option),
|
|
745
|
+
baseUrl: this.#baseUrlOf(endpoint),
|
|
746
|
+
});
|
|
747
|
+
};
|
|
748
|
+
return ((fileList: FileList | File[], parentId?: string, option?: FetchPolicy) => {
|
|
749
|
+
this.#refuseInApp(names.addModelFiles);
|
|
750
|
+
return upload(fileList, parentId, option);
|
|
751
|
+
}) as FetchHandler;
|
|
752
|
+
});
|
|
736
753
|
}
|
|
737
754
|
|
|
738
755
|
#makeModelObjFn(refName: string, callerKey: string) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { Backoff, isRecord, type RetryPolicy } from "akanjs/common";
|
|
1
|
+
import { Backoff, isRecord, Logger, type RetryPolicy } from "akanjs/common";
|
|
2
2
|
import type { HttpMutationMethod, SerializedArg } from "akanjs/signal";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type ErrorConstructor,
|
|
5
|
+
type ErrorResponsePayload,
|
|
6
|
+
type RestoredError,
|
|
7
|
+
restoreRemoteError,
|
|
8
|
+
} from "./remoteError";
|
|
4
9
|
|
|
5
10
|
export interface HttpClientOptions {
|
|
6
11
|
headers?: Record<string, string>;
|
|
@@ -42,6 +47,7 @@ const transportDetailLimit = 200;
|
|
|
42
47
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
43
48
|
|
|
44
49
|
export class HttpClient {
|
|
50
|
+
static readonly #logger = new Logger("HttpClient");
|
|
45
51
|
readonly baseUrl: string;
|
|
46
52
|
#headers: Record<string, string>;
|
|
47
53
|
#timeout?: number | false;
|
|
@@ -166,11 +172,11 @@ export class HttpClient {
|
|
|
166
172
|
|
|
167
173
|
async #requestOnce<Returns>(url: string, init: RequestInit, deadline: number): Promise<Returns> {
|
|
168
174
|
const res = await this.#fetch(url, this.#withDeadline(init, deadline));
|
|
169
|
-
const body = await this.#readBody(res);
|
|
175
|
+
const body = await this.#readBody(url, res);
|
|
170
176
|
if (res.ok) return body as Returns;
|
|
171
177
|
|
|
172
178
|
if (res.status in transportErrorKeyMap && !HttpClient.#namesErrorKey(body))
|
|
173
|
-
throw this.#transportError(res, JSON.stringify(body));
|
|
179
|
+
throw this.#transportError(url, res, JSON.stringify(body));
|
|
174
180
|
throw this.#restoreError(body, res.status);
|
|
175
181
|
}
|
|
176
182
|
|
|
@@ -197,21 +203,21 @@ export class HttpClient {
|
|
|
197
203
|
if (error instanceof Error && error.name === "TimeoutError")
|
|
198
204
|
throw this.#restoreError({ error: transportErrorKeyMap[408], data: { status: 408 } }, 408);
|
|
199
205
|
if (error instanceof Error && error.name === "AbortError") throw error;
|
|
200
|
-
throw this.#
|
|
206
|
+
throw this.#transportFailure(url, { error: serverUnreachableKey, details: String(error) }, 503);
|
|
201
207
|
}
|
|
202
208
|
}
|
|
203
209
|
|
|
204
|
-
async #readBody(res: Response) {
|
|
210
|
+
async #readBody(url: string, res: Response) {
|
|
205
211
|
if (jsonContentType.test(res.headers.get("content-type") ?? "")) {
|
|
206
212
|
try {
|
|
207
213
|
return (await res.json()) as unknown;
|
|
208
214
|
} catch (error) {
|
|
209
|
-
throw this.#transportError(res, String(error));
|
|
215
|
+
throw this.#transportError(url, res, String(error));
|
|
210
216
|
}
|
|
211
217
|
}
|
|
212
218
|
const raw = await res.text();
|
|
213
219
|
const parsed = HttpClient.#parseJson(raw);
|
|
214
|
-
if (parsed === undefined) throw this.#transportError(res, raw);
|
|
220
|
+
if (parsed === undefined) throw this.#transportError(url, res, raw);
|
|
215
221
|
return parsed;
|
|
216
222
|
}
|
|
217
223
|
|
|
@@ -223,11 +229,33 @@ export class HttpClient {
|
|
|
223
229
|
}
|
|
224
230
|
}
|
|
225
231
|
|
|
226
|
-
#transportError(res: Response, detail: string): RestoredError {
|
|
232
|
+
#transportError(url: string, res: Response, detail: string): RestoredError {
|
|
227
233
|
const { status } = res;
|
|
228
234
|
const error = transportErrorKeyMap[status as keyof typeof transportErrorKeyMap] ?? unexpectedResponseKey;
|
|
229
235
|
const data = status === 429 ? { status, seconds: HttpClient.#retryAfterSeconds(res) } : { status };
|
|
230
|
-
return this.#
|
|
236
|
+
return this.#transportFailure(url, { error, data, details: detail.slice(0, transportDetailLimit) }, status);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
#transportFailure(url: string, body: ErrorResponsePayload, status: number): RestoredError {
|
|
240
|
+
if (typeof window === "undefined")
|
|
241
|
+
HttpClient.#logger.warn(`${body.error} from ${HttpClient.#originAndPath(url)}: ${JSON.stringify(body.details)}`);
|
|
242
|
+
const error = this.#restoreError(body, status);
|
|
243
|
+
const toJSON = error.toJSON?.bind(error);
|
|
244
|
+
if (toJSON)
|
|
245
|
+
error.toJSON = () => {
|
|
246
|
+
const { details: _local, ...wire } = toJSON();
|
|
247
|
+
return wire;
|
|
248
|
+
};
|
|
249
|
+
return error;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
static #originAndPath(url: string) {
|
|
253
|
+
try {
|
|
254
|
+
const { origin, pathname } = new URL(url);
|
|
255
|
+
return `${origin}${pathname}`;
|
|
256
|
+
} catch {
|
|
257
|
+
return url.split("?")[0];
|
|
258
|
+
}
|
|
231
259
|
}
|
|
232
260
|
|
|
233
261
|
static #retryAfterSeconds(res: Response): number {
|
|
@@ -63,9 +63,8 @@ export class SliceInitHandle {
|
|
|
63
63
|
|
|
64
64
|
#serverInitOf(modelObjList: BaseObject[], modelObjInsight: BaseInsight | null) {
|
|
65
65
|
const { refName, capRefName, sliceName, argLength, queryArgs, page, limit, sort } = this.#input;
|
|
66
|
-
const lastPage =
|
|
67
|
-
? Math.max(Math.floor((modelObjInsight.count - 1) /
|
|
68
|
-
: 1;
|
|
66
|
+
const lastPage =
|
|
67
|
+
modelObjInsight?.count && limit > 0 ? Math.max(Math.floor((modelObjInsight.count - 1) / limit) + 1, 1) : 1;
|
|
69
68
|
this.#serverInit ??= {
|
|
70
69
|
refName,
|
|
71
70
|
sliceName,
|
package/fetch/client/wsClient.ts
CHANGED
|
@@ -302,7 +302,9 @@ export class WsClient {
|
|
|
302
302
|
if (Date.now() - this.#lastInboundAt > websocketHeartbeatContract.silenceMs) {
|
|
303
303
|
this.logger.warn(`WebSocket is silent, reconnecting`);
|
|
304
304
|
this.#stopHeartbeat();
|
|
305
|
-
|
|
305
|
+
|
|
306
|
+
if ("terminate" in ws) (ws as unknown as Bun.WebSocket).terminate();
|
|
307
|
+
else ws.close();
|
|
306
308
|
return;
|
|
307
309
|
}
|
|
308
310
|
ws.send(JSON.stringify(websocketHeartbeatContract.makeRequest()));
|
|
@@ -14,15 +14,17 @@ import type {
|
|
|
14
14
|
SliceCls,
|
|
15
15
|
} from "akanjs/signal";
|
|
16
16
|
|
|
17
|
-
type ExtendedEndpointReturn<ClientReturns, Full, Light, Insight> =
|
|
18
|
-
?
|
|
19
|
-
:
|
|
20
|
-
? Full
|
|
21
|
-
:
|
|
22
|
-
?
|
|
23
|
-
:
|
|
24
|
-
?
|
|
25
|
-
: ClientReturns
|
|
17
|
+
type ExtendedEndpointReturn<ClientReturns, Full, Light, Insight> = unknown extends ClientReturns
|
|
18
|
+
? ClientReturns
|
|
19
|
+
: ClientReturns extends (infer R)[]
|
|
20
|
+
? ExtendedEndpointReturn<R, Full, Light, Insight>[]
|
|
21
|
+
: Full extends ClientReturns
|
|
22
|
+
? Full
|
|
23
|
+
: Light extends ClientReturns
|
|
24
|
+
? Light
|
|
25
|
+
: Insight extends ClientReturns
|
|
26
|
+
? Insight
|
|
27
|
+
: ClientReturns;
|
|
26
28
|
|
|
27
29
|
type EndpointClientReturns<E, SlceCls extends SliceCls | never> = [SlceCls] extends [never]
|
|
28
30
|
? EndpInfoClientReturns<E>
|
package/fetch/index.ts
CHANGED
package/index.ts
CHANGED
|
@@ -601,6 +601,8 @@ export interface AppInfo {
|
|
|
601
601
|
readonly service: Map<string, Set<string>>;
|
|
602
602
|
readonly scalar: Map<string, Set<string>>;
|
|
603
603
|
readonly file: FileConventionScanSets;
|
|
604
|
+
/** `script/migration/*.ts` by id, each with its source's sha256. */
|
|
605
|
+
readonly migrations: readonly { id: string; checksum: string }[];
|
|
604
606
|
getLibs(): string[];
|
|
605
607
|
getLibInfos(): Map<string, LibInfo>;
|
|
606
608
|
getDatabaseModules(): string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akanjs",
|
|
3
|
-
"version": "3.1.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"sourceType": "module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -225,34 +225,44 @@
|
|
|
225
225
|
"types": "./types/server/hmr/runtimeMetadataFile.d.ts",
|
|
226
226
|
"import": "./server/hmr/runtimeMetadataFile.ts",
|
|
227
227
|
"default": "./server/hmr/runtimeMetadataFile.ts"
|
|
228
|
+
},
|
|
229
|
+
"./server/migration/migrationCommand": {
|
|
230
|
+
"types": "./types/server/migration/migrationCommand.d.ts",
|
|
231
|
+
"import": "./server/migration/migrationCommand.ts",
|
|
232
|
+
"default": "./server/migration/migrationCommand.ts"
|
|
233
|
+
},
|
|
234
|
+
"./server/migration/migrationError": {
|
|
235
|
+
"types": "./types/server/migration/migrationError.d.ts",
|
|
236
|
+
"import": "./server/migration/migrationError.ts",
|
|
237
|
+
"default": "./server/migration/migrationError.ts"
|
|
228
238
|
}
|
|
229
239
|
},
|
|
230
240
|
"dependencies": {
|
|
231
|
-
"@lexical/plain-text": "^0.
|
|
241
|
+
"@lexical/plain-text": "^0.52.0",
|
|
232
242
|
"@noble/ciphers": "^2.4.0",
|
|
233
|
-
"dayjs": "^1.11.
|
|
234
|
-
"immer": "^11.1.
|
|
235
|
-
"lexical": "^0.
|
|
236
|
-
"tailwind-merge": "^3.
|
|
237
|
-
"tailwind-variants": "^3.3.
|
|
243
|
+
"dayjs": "^1.11.23",
|
|
244
|
+
"immer": "^11.1.21",
|
|
245
|
+
"lexical": "^0.52.0",
|
|
246
|
+
"tailwind-merge": "^3.7.0",
|
|
247
|
+
"tailwind-variants": "^3.3.1"
|
|
238
248
|
},
|
|
239
249
|
"peerDependencies": {
|
|
240
|
-
"@happy-dom/global-registrator": "^
|
|
241
|
-
"@playwright/test": "^1.
|
|
242
|
-
"@react-spring/web": "^10.1.
|
|
250
|
+
"@happy-dom/global-registrator": "^21.0.3",
|
|
251
|
+
"@playwright/test": "^1.64.1",
|
|
252
|
+
"@react-spring/web": "^10.1.2",
|
|
243
253
|
"@use-gesture/react": "^10.3.1",
|
|
244
|
-
"bullmq": "^5.
|
|
254
|
+
"bullmq": "^5.81.5",
|
|
245
255
|
"chance": "^1.1.13",
|
|
246
|
-
"firebase": "^
|
|
247
|
-
"happy-dom": "^
|
|
248
|
-
"ioredis": "^5.
|
|
256
|
+
"firebase": "^13.0.0",
|
|
257
|
+
"happy-dom": "^21.0.3",
|
|
258
|
+
"ioredis": "^5.11.1",
|
|
249
259
|
"postgres": "^3.4.9",
|
|
250
|
-
"protobufjs": "^8.
|
|
251
|
-
"react": "19.3.
|
|
252
|
-
"react-dom": "19.3.
|
|
253
|
-
"react-icons": "^5.
|
|
260
|
+
"protobufjs": "^8.8.1",
|
|
261
|
+
"react": "19.3.1",
|
|
262
|
+
"react-dom": "19.3.1",
|
|
263
|
+
"react-icons": "^5.7.0",
|
|
254
264
|
"react-refresh": "^0.19.0",
|
|
255
|
-
"react-server-dom-webpack": "
|
|
265
|
+
"react-server-dom-webpack": "19.3.1",
|
|
256
266
|
"react-spring": "^10.0.4",
|
|
257
267
|
"scheduler": "^0.28.0",
|
|
258
268
|
"tailwind-scrollbar": "^4.0.2",
|
|
@@ -321,14 +331,14 @@
|
|
|
321
331
|
}
|
|
322
332
|
},
|
|
323
333
|
"devDependencies": {
|
|
324
|
-
"@biomejs/biome": "2.5.
|
|
325
|
-
"@types/bun": "^1.4.
|
|
334
|
+
"@biomejs/biome": "2.5.14",
|
|
335
|
+
"@types/bun": "^1.4.4"
|
|
326
336
|
},
|
|
327
337
|
"bun": {
|
|
328
338
|
"platform": "bun"
|
|
329
339
|
},
|
|
330
340
|
"engines": {
|
|
331
|
-
"bun": ">=1.4.
|
|
341
|
+
"bun": ">=1.4.4"
|
|
332
342
|
},
|
|
333
343
|
"main": "./index.ts"
|
|
334
344
|
}
|
package/server/akanApp.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { LogHub } from "./logging/logHub";
|
|
|
19
19
|
import { LogStreamRoute } from "./logging/logStreamRoute";
|
|
20
20
|
import { RotatingLogWriter } from "./logging/rotatingLogWriter";
|
|
21
21
|
import { AppInfo } from "./ops/appInfo";
|
|
22
|
+
import type { OpsHost } from "./ops/opsCommand";
|
|
22
23
|
import type { OpsRoute } from "./ops/opsRoute";
|
|
23
24
|
import { ProcessMetricsCollector } from "./processMetricsCollector";
|
|
24
25
|
import { HostAllowlist } from "./routing/hostAllowlist";
|
|
@@ -108,7 +109,7 @@ export class AkanApp {
|
|
|
108
109
|
readonly #devHosted = process.env.AKAN_COMMAND_TYPE === "start";
|
|
109
110
|
readonly #healthTimeoutMs = AkanApp.#parseHealthTimeoutMs();
|
|
110
111
|
readonly #upstreamWaitMs = AkanApp.#parseUpstreamWaitMs();
|
|
111
|
-
/** Child stderr is bundler/runtime noise
|
|
112
|
+
/** Child stderr is mostly bundler/runtime noise, kept to the log file; with none it may be a crash's only trace. */
|
|
112
113
|
readonly #printChildStderr = process.env.AKAN_CHILD_STDERR === "1";
|
|
113
114
|
readonly #serverPath: string;
|
|
114
115
|
readonly #artifactDir: string;
|
|
@@ -238,7 +239,9 @@ export class AkanApp {
|
|
|
238
239
|
async start() {
|
|
239
240
|
if (process.argv[2] === "ops") {
|
|
240
241
|
const { OpsCommand } = await import("./ops/opsCommand");
|
|
241
|
-
process.exit(
|
|
242
|
+
process.exit(
|
|
243
|
+
await OpsCommand.run(process.argv.slice(3), { importServer: async () => await this.#importServer() }),
|
|
244
|
+
);
|
|
242
245
|
}
|
|
243
246
|
if (this.#solo) return await this.#startSolo();
|
|
244
247
|
if (SelfExec.carried)
|
|
@@ -274,6 +277,12 @@ export class AkanApp {
|
|
|
274
277
|
});
|
|
275
278
|
}
|
|
276
279
|
|
|
280
|
+
async #importServer() {
|
|
281
|
+
Object.assign(process.env, this.#childEnv(0, this.#getRole(0)), { AKAN_COMMAND_TYPE: "script" });
|
|
282
|
+
resetEnvCache();
|
|
283
|
+
return (await import(this.#serverPath)) as Awaited<ReturnType<OpsHost["importServer"]>>;
|
|
284
|
+
}
|
|
285
|
+
|
|
277
286
|
async #startSolo() {
|
|
278
287
|
const role = this.#getRole(0);
|
|
279
288
|
|
|
@@ -1328,7 +1337,7 @@ export class AkanApp {
|
|
|
1328
1337
|
return;
|
|
1329
1338
|
}
|
|
1330
1339
|
const prefixedLine = `[child:${idx} ${role}] [${type}] ${line}`;
|
|
1331
|
-
if (type === "stdout" || this.#printChildStderr) process[type].write(prefixedLine);
|
|
1340
|
+
if (type === "stdout" || this.#printChildStderr || !this.#logWriter) process[type].write(prefixedLine);
|
|
1332
1341
|
this.#logWriter?.write(`${idx}-${role}`, AkanApp.#stripAnsi(prefixedLine));
|
|
1333
1342
|
}
|
|
1334
1343
|
|
package/server/akanServer.ts
CHANGED
|
@@ -66,7 +66,10 @@ export interface AkanServerProps extends AkanLibProps {
|
|
|
66
66
|
|
|
67
67
|
export interface AkanServerOptions {
|
|
68
68
|
openapi?: boolean;
|
|
69
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* `/mcp` is mounted by default, on an edge server only when asked for here or by `AKAN_MCP=true`; `false` takes it
|
|
71
|
+
* off, and the object form carries the rest of its settings.
|
|
72
|
+
*/
|
|
70
73
|
mcp?: boolean | McpServerOption;
|
|
71
74
|
/** Boot only these modules and what they reach; omitted or empty mounts every enabled module. */
|
|
72
75
|
modules?: string[];
|
|
@@ -107,13 +110,15 @@ export interface McpServerOption {
|
|
|
107
110
|
/** Characters a page prompt may attach before its lists are cut; 60,000 by default. `AKAN_MCP_PROMPT_BUDGET`. */
|
|
108
111
|
promptBudget?: number;
|
|
109
112
|
/**
|
|
110
|
-
* MCP Apps:
|
|
111
|
-
*
|
|
113
|
+
* MCP Apps: each `.app()` is a read-only tool whose result a host speaking the extension draws with that app's own
|
|
114
|
+
* view, and a `.prompt()` page a text tool; an endpoint kept off the shelf by `mcp: false` stays callable by a view.
|
|
115
|
+
* `false` publishes no page tools. `true` by default. `AKAN_MCP_APPS`.
|
|
112
116
|
*/
|
|
113
117
|
apps?: boolean;
|
|
114
118
|
/**
|
|
115
|
-
* Speak the modern `2026-07-28` revision (`server/discover`) beside the legacy ones. On unless
|
|
116
|
-
* since claude.ai renders a view only for a server it reached through `initialize`.
|
|
119
|
+
* Speak the modern `2026-07-28` revision (`server/discover`) beside the legacy ones. On unless the build serves views
|
|
120
|
+
* and a page declares `.app()`, since claude.ai renders a view only for a server it reached through `initialize`.
|
|
121
|
+
* `AKAN_MCP_MODERN`.
|
|
117
122
|
*/
|
|
118
123
|
modern?: boolean;
|
|
119
124
|
}
|
package/server/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./decorators";
|
|
|
8
8
|
export * from "./devtools";
|
|
9
9
|
export type { ChangeBatch, ChangeKind } from "./hmr/wsHub";
|
|
10
10
|
export * from "./machine";
|
|
11
|
+
export * from "./migration";
|
|
11
12
|
export * from "./nativeFile";
|
|
12
13
|
export * from "./oauth";
|
|
13
14
|
export * from "./processMetricsCollector";
|
package/server/mcp/McpApps.ts
CHANGED
|
@@ -14,23 +14,29 @@ import {
|
|
|
14
14
|
import type { PagePromptEntry, PagePromptRecord, PagePromptRun } from "../../signal/mcp/pagePrompt";
|
|
15
15
|
import { McpAppShell } from "./McpAppShell";
|
|
16
16
|
|
|
17
|
-
/** The
|
|
17
|
+
/** The single-file view each `.app()` boots from, read from the build that serves the web. */
|
|
18
18
|
export interface McpAppShellSource {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/** `null` when this build has no view for the app. */
|
|
20
|
+
read(app: string): Promise<string | null>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface McpAppsOption {
|
|
24
|
+
/** Every write the view sends is refused before it leaves, as the deployment lists no write to relay it to. */
|
|
25
|
+
readOnly?: boolean;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
export class McpApps {
|
|
25
29
|
static readonly scheme = "ui://";
|
|
26
|
-
|
|
27
|
-
static readonly rootSegment = "app";
|
|
28
30
|
static readonly #tokenClaims = new Set(["iss", "aud", "exp", "nbf", "iat", "jti", "client_id", "scope"]);
|
|
31
|
+
|
|
32
|
+
static readonly #appUri = /^ui:\/\/([^/]+)\/apps\/([A-Za-z0-9_-]{1,64})$/;
|
|
29
33
|
|
|
30
34
|
readonly #shell: McpAppShellSource | null;
|
|
35
|
+
readonly #readOnly: boolean;
|
|
31
36
|
|
|
32
|
-
constructor(shell: McpAppShellSource | null) {
|
|
37
|
+
constructor(shell: McpAppShellSource | null, { readOnly = false }: McpAppsOption = {}) {
|
|
33
38
|
this.#shell = shell;
|
|
39
|
+
this.#readOnly = readOnly;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
get rendersUi() {
|
|
@@ -53,18 +59,19 @@ export class McpApps {
|
|
|
53
59
|
]),
|
|
54
60
|
);
|
|
55
61
|
const required = entry.arguments.filter((arg) => arg.required).map((arg) => arg.name);
|
|
62
|
+
const inputSchema = {
|
|
63
|
+
type: "object" as const,
|
|
64
|
+
properties,
|
|
65
|
+
...(required.length ? { required } : {}),
|
|
66
|
+
additionalProperties: false,
|
|
67
|
+
};
|
|
68
|
+
const tool = { name: entry.name, description: entry.description, inputSchema };
|
|
69
|
+
|
|
70
|
+
if (entry.kind === "prompt") return { ...tool, annotations: { readOnlyHint: false, openWorldHint: false } };
|
|
56
71
|
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
type: "object",
|
|
61
|
-
properties,
|
|
62
|
-
...(required.length ? { required } : {}),
|
|
63
|
-
additionalProperties: false,
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
annotations: { readOnlyHint: false, openWorldHint: false },
|
|
67
|
-
...(this.#shell ? { _meta: this.#toolMetaOf(this.uriOf(this.#basePathOf(entry.pattern))) } : {}),
|
|
72
|
+
...tool,
|
|
73
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
74
|
+
...(this.#shell ? { _meta: this.#toolMetaOf(this.uriOf(entry.name)) } : {}),
|
|
68
75
|
};
|
|
69
76
|
}
|
|
70
77
|
|
|
@@ -74,30 +81,30 @@ export class McpApps {
|
|
|
74
81
|
|
|
75
82
|
resourcesOf(entries: PagePromptEntry[]): McpResource[] {
|
|
76
83
|
if (!this.#shell) return [];
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
return entries
|
|
85
|
+
.filter((entry) => entry.kind === "app")
|
|
86
|
+
.map((entry) => ({
|
|
87
|
+
uri: this.uriOf(entry.name),
|
|
88
|
+
name: entry.name,
|
|
89
|
+
description: entry.description,
|
|
90
|
+
mimeType: MCP_UI_MIME_TYPE,
|
|
91
|
+
}));
|
|
85
92
|
}
|
|
86
93
|
|
|
87
|
-
uriOf(
|
|
88
|
-
|
|
89
|
-
return basePath ? `${root}/${basePath}` : root;
|
|
94
|
+
uriOf(app: string) {
|
|
95
|
+
return `${McpApps.scheme}${getEnv().appName.toLowerCase()}/apps/${app}`;
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
async read(uri: string, origin: string): Promise<McpResourceContents | null> {
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
if (!shell ||
|
|
96
|
-
const html = await shell.read(
|
|
99
|
+
const match = McpApps.#appUri.exec(uri);
|
|
100
|
+
const app = match?.[1]?.toLowerCase() === getEnv().appName.toLowerCase() ? match[2] : undefined;
|
|
101
|
+
if (!this.#shell || !app) return null;
|
|
102
|
+
const html = await this.#shell.read(app);
|
|
97
103
|
return html ? McpAppShell.contentsOf(uri, html, origin) : null;
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
resultOf(
|
|
107
|
+
entry: PagePromptEntry,
|
|
101
108
|
run: Extract<PagePromptRun, { ok: true }>,
|
|
102
109
|
messages: PromptMessage[],
|
|
103
110
|
webOrigin: string,
|
|
@@ -107,14 +114,15 @@ export class McpApps {
|
|
|
107
114
|
const href = `${url.pathname}${url.search}`;
|
|
108
115
|
const content: PromptContent[] = [
|
|
109
116
|
...messages.map((message) => message.content),
|
|
110
|
-
{ type: "text", text: `Open
|
|
117
|
+
{ type: "text", text: `Open the full screen: ${webOrigin}${href}` },
|
|
111
118
|
];
|
|
112
|
-
if (!this.#shell || !forView) return { content, isError: false };
|
|
119
|
+
if (entry.kind === "prompt" || !this.#shell || !forView) return { content, isError: false };
|
|
113
120
|
const _meta = {
|
|
114
121
|
[MCP_APP_META.snapshot]: McpApps.#snapshotOf(run.records),
|
|
115
122
|
[MCP_APP_META.account]: forView.account,
|
|
123
|
+
...(this.#readOnly ? { [MCP_APP_META.readOnly]: true } : {}),
|
|
116
124
|
};
|
|
117
|
-
return { content, structuredContent: { href }, _meta, isError: false };
|
|
125
|
+
return { content, structuredContent: { href, ...run.route }, _meta, isError: false };
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
static accountOf(req: Request): Record<string, unknown> | null {
|
|
@@ -128,20 +136,6 @@ export class McpApps {
|
|
|
128
136
|
}
|
|
129
137
|
}
|
|
130
138
|
|
|
131
|
-
#basePathOf(pattern: string) {
|
|
132
|
-
const [, , segment] = pattern.split("/");
|
|
133
|
-
return segment && this.#shell?.basePaths.includes(segment) ? segment : "";
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
#basePathOfUri(uri: string) {
|
|
137
|
-
const match = /^ui:\/\/([^/]+)\/([^?#]*)$/i.exec(uri);
|
|
138
|
-
if (!match || match[1]?.toLowerCase() !== getEnv().appName.toLowerCase()) return null;
|
|
139
|
-
const [root, basePath, ...rest] = (match[2] ?? "").split("/");
|
|
140
|
-
if (root !== McpApps.rootSegment || rest.length) return null;
|
|
141
|
-
if (!basePath) return "";
|
|
142
|
-
return this.#shell?.basePaths.includes(basePath) ? basePath : null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
139
|
static #snapshotOf(records: PagePromptRecord[]): McpAppSnapshotRecord[] {
|
|
146
140
|
return records.flatMap(({ key, args, value }) => (value === undefined ? [] : [{ key, args, value }]));
|
|
147
141
|
}
|
|
@@ -72,7 +72,8 @@ export class McpDispatcher {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
static #restorable(error: unknown, status: number | undefined) {
|
|
75
|
-
if (!status || status >= 500
|
|
75
|
+
if (!status || status >= 500) return null;
|
|
76
|
+
if (status === 401 || status === 403) return { statusCode: status };
|
|
76
77
|
return isExceptionLike(error) ? error.toJSON() : null;
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -169,8 +170,7 @@ export class McpDispatcher {
|
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
static #statusOf(error: unknown): number | undefined {
|
|
172
|
-
if (isExceptionLike(error) || error instanceof McpArgumentError
|
|
173
|
-
return error.statusCode;
|
|
173
|
+
if (isExceptionLike(error) || error instanceof McpArgumentError) return error.statusCode;
|
|
174
174
|
return undefined;
|
|
175
175
|
}
|
|
176
176
|
|