akanjs 3.2.0-rc.11 → 3.2.0-rc.13
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/ARCHITECTURE.md +17 -17
- package/CHANGELOG.md +24 -0
- package/base/base.ts +2 -1
- package/client/clientRuntime.ts +1 -0
- package/client/cn.ts +2 -2
- package/client/csrTypes.ts +2 -0
- package/client/frameConfig.ts +1 -0
- package/client/index.ts +249 -26
- package/client/locale.ts +1 -0
- package/client/route/RouteDefinition.ts +24 -7
- package/client/route/routeArgs.ts +7 -0
- package/client/router.ts +12 -2
- package/client/rscNavigation.ts +1 -0
- package/common/CodeTranscript.ts +1 -1
- package/constant/constantRegistry.ts +4 -8
- package/constant/crystalize.ts +1 -2
- package/constant/getDefault.ts +1 -1
- package/constant/immerify.ts +1 -1
- package/constant/index.ts +78 -21
- package/constant/purify.ts +4 -9
- package/constant/serialize.ts +4 -2
- package/constant/types.ts +1 -0
- package/constant/via.ts +1 -2
- package/dictionary/locale.ts +1 -1
- package/document/databaseRegistry.ts +2 -1
- package/document/documentSchema.ts +1 -0
- package/document/filterMeta.ts +4 -1
- package/document/into.ts +2 -1
- package/document/loaderInfo.ts +2 -1
- package/document/types.ts +1 -1
- package/fetch/client/fetchClient.ts +3 -3
- package/fetch/client/httpClient.ts +2 -0
- package/fetch/client/wsClient.ts +1 -0
- package/package.json +1 -1
- package/server/akanApp.ts +103 -1270
- package/server/akanServer.ts +1 -1
- package/server/console.ts +3 -2
- package/server/gateway/childSupervisor.ts +325 -0
- package/server/gateway/devHostChannel.ts +40 -0
- package/server/gateway/gatewayChildren.ts +135 -0
- package/server/gateway/gatewayConfig.ts +182 -0
- package/server/gateway/gatewayHttpProxy.ts +231 -0
- package/server/gateway/gatewayLogging.ts +111 -0
- package/server/gateway/gatewayRooms.ts +134 -0
- package/server/gateway/gatewayStatus.ts +116 -0
- package/server/gateway/gatewayStatusPage.ts +54 -0
- package/server/gateway/gatewayWebSocketRelay.ts +149 -0
- package/server/index.ts +257 -17
- package/server/logging/logControlSocket.ts +42 -3
- package/server/mcp/McpDispatcher.ts +6 -24
- package/server/rscClient.tsx +14 -8
- package/server/sitemap.ts +1 -0
- package/service/injectInfo.ts +2 -1
- package/service/predefinedAdaptor/sql/driver/bunSqlite.ts +3 -3
- package/service/predefinedAdaptor/sql/driver/postgres.ts +1 -1
- package/service/serviceRegistry.ts +1 -0
- package/signal/SignalFailure.ts +21 -0
- package/signal/agentTurnStream.ts +5 -2
- package/signal/index.ts +298 -30
- package/signal/resolveFieldContext.ts +34 -0
- package/signal/serializer/fetch.serializer.ts +7 -10
- package/signal/signalContext.ts +4 -31
- package/signal/trace.ts +3 -0
- package/store/baseSt.ts +1 -0
- package/store/index.ts +125 -18
- package/store/stateBuilder.ts +2 -0
- package/types/base/base.d.ts +2 -1
- package/types/client/clientRuntime.d.ts +1 -0
- package/types/client/cn.d.ts +2 -2
- package/types/client/csrTypes.d.ts +2 -0
- package/types/client/frameConfig.d.ts +1 -0
- package/types/client/index.d.ts +25 -26
- package/types/client/locale.d.ts +1 -0
- package/types/client/route/RouteDefinition.d.ts +2 -2
- package/types/client/route/routeArgs.d.ts +6 -0
- package/types/client/router.d.ts +2 -1
- package/types/client/rscNavigation.d.ts +1 -0
- package/types/common/CodeTranscript.d.ts +1 -1
- package/types/constant/constantRegistry.d.ts +3 -1
- package/types/constant/crystalize.d.ts +1 -1
- package/types/constant/getDefault.d.ts +1 -1
- package/types/constant/immerify.d.ts +1 -1
- package/types/constant/index.d.ts +21 -21
- package/types/constant/purify.d.ts +2 -1
- package/types/constant/serialize.d.ts +1 -1
- package/types/constant/types.d.ts +1 -0
- package/types/dictionary/base.dictionary.d.ts +1 -1
- package/types/dictionary/dictionary.d.ts +8 -8
- package/types/dictionary/locale.d.ts +1 -1
- package/types/document/databaseRegistry.d.ts +2 -1
- package/types/document/documentSchema.d.ts +1 -0
- package/types/document/filterMeta.d.ts +4 -1
- package/types/document/into.d.ts +1 -1
- package/types/document/loaderInfo.d.ts +2 -1
- package/types/document/types.d.ts +1 -1
- package/types/fetch/client/fetchClient.d.ts +2 -1
- package/types/fetch/client/httpClient.d.ts +2 -0
- package/types/fetch/client/wsClient.d.ts +1 -0
- package/types/server/akanApp.d.ts +2 -20
- package/types/server/console.d.ts +3 -2
- package/types/server/gateway/childSupervisor.d.ts +33 -0
- package/types/server/gateway/devHostChannel.d.ts +13 -0
- package/types/server/gateway/gatewayChildren.d.ts +47 -0
- package/types/server/gateway/gatewayConfig.d.ts +82 -0
- package/types/server/gateway/gatewayHttpProxy.d.ts +22 -0
- package/types/server/gateway/gatewayLogging.d.ts +16 -0
- package/types/server/gateway/gatewayRooms.d.ts +22 -0
- package/types/server/gateway/gatewayStatus.d.ts +62 -0
- package/types/server/gateway/gatewayStatusPage.d.ts +9 -0
- package/types/server/gateway/gatewayWebSocketRelay.d.ts +17 -0
- package/types/server/index.d.ts +17 -17
- package/types/server/logging/rotatingLogWriter.d.ts +1 -1
- package/types/server/sitemap.d.ts +1 -0
- package/types/service/injectInfo.d.ts +2 -1
- package/types/service/predefinedAdaptor/sql/driver/bunSqlite.d.ts +1 -14
- package/types/service/predefinedAdaptor/sql/driver/postgres.d.ts +0 -8
- package/types/service/serviceRegistry.d.ts +1 -0
- package/types/signal/SignalFailure.d.ts +1 -0
- package/types/signal/agentTurnStream.d.ts +1 -0
- package/types/signal/index.d.ts +31 -30
- package/types/signal/resolveFieldContext.d.ts +15 -0
- package/types/signal/serializer/fetch.serializer.d.ts +3 -1
- package/types/signal/signalContext.d.ts +1 -13
- package/types/signal/trace.d.ts +3 -0
- package/types/store/baseSt.d.ts +1 -0
- package/types/store/index.d.ts +17 -17
- package/types/store/stateBuilder.d.ts +2 -0
- package/types/ui/Agent/Chat.d.ts +5 -2
- package/types/ui/Agent/ChatHeader.d.ts +13 -0
- package/types/ui/Agent/ChatPendingCards.d.ts +23 -0
- package/types/ui/Reference/origin.d.ts +1 -0
- package/types/ui/overlayLayer.d.ts +6 -1
- package/types/vendor/@akanjs/native/packages/cli/src/lib/project.d.ts +4 -0
- package/types/vendor/@akanjs/native/packages/desktop/src/relaunch.d.ts +1 -0
- package/types/vendor/@akanjs/native/plugins/external-view/src/index.d.ts +14 -10
- package/types/vendor/use-agentic/failureCode.d.ts +4 -0
- package/types/vendor/use-agentic/types.d.ts +6 -0
- package/types/webkit/CsrGuards.d.ts +2 -0
- package/ui/Agent/Chat.tsx +96 -116
- package/ui/Agent/ChatHeader.tsx +59 -0
- package/ui/Agent/ChatPendingCards.tsx +49 -0
- package/ui/Agent/fetchRunner.ts +8 -1
- package/ui/BottomSheet.tsx +1 -1
- package/ui/Dialog/LegacyModal.tsx +1 -1
- package/ui/Dialog/Modal.tsx +1 -1
- package/ui/Popconfirm.tsx +1 -1
- package/ui/Reference/origin.ts +1 -0
- package/ui/overlayLayer.ts +22 -1
- package/vendor/@akanjs/native/CHANGELOG.md +6 -1
- package/vendor/@akanjs/native/native/desktop/src/external.rs +213 -111
- package/vendor/@akanjs/native/native/desktop/src/lib.rs +12 -4
- package/vendor/@akanjs/native/native/desktop/src/linux/external.rs +275 -0
- package/vendor/@akanjs/native/native/desktop/src/linux/mod.rs +1 -0
- package/vendor/@akanjs/native/packages/cli/src/lib/native-plugins.ts +5 -3
- package/vendor/@akanjs/native/packages/cli/src/lib/project.ts +25 -1
- package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +2 -2
- package/vendor/@akanjs/native/packages/desktop/src/host.ts +2 -2
- package/vendor/@akanjs/native/packages/desktop/src/relaunch.ts +8 -3
- package/vendor/@akanjs/native/plugins/app/src/desktop.ts +2 -2
- package/vendor/@akanjs/native/plugins/autostart/src/desktop.ts +2 -1
- package/vendor/@akanjs/native/plugins/external-view/native-plugin.json +4 -1
- package/vendor/@akanjs/native/plugins/external-view/src/index.ts +14 -10
- package/vendor/use-agentic/AgentSession.ts +11 -11
- package/vendor/use-agentic/CHANGELOG.md +6 -0
- package/vendor/use-agentic/Compaction.ts +2 -1
- package/vendor/use-agentic/ToolRunner.ts +3 -15
- package/vendor/use-agentic/Transcript.ts +6 -3
- package/vendor/use-agentic/WIRE.md +12 -1
- package/vendor/use-agentic/failureCode.ts +44 -0
- package/vendor/use-agentic/httpRunner.ts +14 -3
- package/vendor/use-agentic/types.ts +6 -0
- package/webkit/CsrGuards.ts +7 -2
- package/webkit/useLocation.ts +3 -2
|
@@ -6,14 +6,7 @@ import {
|
|
|
6
6
|
type ImageResultValue,
|
|
7
7
|
PrimitiveRegistry,
|
|
8
8
|
} from "akanjs/base";
|
|
9
|
-
import {
|
|
10
|
-
FailureCode,
|
|
11
|
-
interpolateTranslation,
|
|
12
|
-
isGuardRefusal,
|
|
13
|
-
Logger,
|
|
14
|
-
MCP_FAILURE_META,
|
|
15
|
-
type McpFailure,
|
|
16
|
-
} from "akanjs/common";
|
|
9
|
+
import { interpolateTranslation, isGuardRefusal, Logger, MCP_FAILURE_META, type McpFailure } from "akanjs/common";
|
|
17
10
|
import { agentRead, ConstantRegistry, mask } from "akanjs/constant";
|
|
18
11
|
import { DictionaryLookup } from "akanjs/dictionary";
|
|
19
12
|
import { NoDocumentError } from "akanjs/document";
|
|
@@ -88,10 +81,10 @@ export class McpDispatcher {
|
|
|
88
81
|
|
|
89
82
|
const refusal = (status === 401 || status === 403) && isGuardRefusal(error);
|
|
90
83
|
if (refusal && !req.headers.get("authorization")) throw new McpAuthRequiredError();
|
|
91
|
-
const failure = McpDispatcher.#failure(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
);
|
|
84
|
+
const failure = McpDispatcher.#failure(this.#message(error, status, exposed.refName), {
|
|
85
|
+
code: SignalFailure.codeOf(error, status),
|
|
86
|
+
statusCode: status || 500,
|
|
87
|
+
});
|
|
95
88
|
const restorable = forView ? McpDispatcher.#restorable(error, status) : null;
|
|
96
89
|
return restorable ? { ...failure, _meta: { ...failure._meta, [MCP_APP_META.error]: restorable } } : failure;
|
|
97
90
|
}
|
|
@@ -110,7 +103,7 @@ export class McpDispatcher {
|
|
|
110
103
|
return images ? { images } : { error: "The server failed to complete this request.", code: crashed };
|
|
111
104
|
} catch (error) {
|
|
112
105
|
const status = McpDispatcher.#statusOf(error);
|
|
113
|
-
return { error: this.#message(error, status, exposed.refName), code:
|
|
106
|
+
return { error: this.#message(error, status, exposed.refName), code: SignalFailure.codeOf(error, status) };
|
|
114
107
|
}
|
|
115
108
|
}
|
|
116
109
|
|
|
@@ -216,17 +209,6 @@ export class McpDispatcher {
|
|
|
216
209
|
return "The server failed to complete this request.";
|
|
217
210
|
}
|
|
218
211
|
|
|
219
|
-
static #codeOf(error: unknown, status: number | undefined): McpFailure {
|
|
220
|
-
if (!status) return McpDispatcher.#crashed;
|
|
221
|
-
const byStatus = { code: AkanError.codeOfStatus(status), statusCode: status };
|
|
222
|
-
if (isGuardRefusal(error)) return byStatus;
|
|
223
|
-
const wire = isExceptionLike(error) ? (error.toJSON() as { error?: unknown; code?: unknown }) : {};
|
|
224
|
-
if (FailureCode.isKey(wire.error)) return { code: wire.error, statusCode: status };
|
|
225
|
-
if (AkanError.is(error) && FailureCode.isToken(error.code)) return { code: error.code, statusCode: status };
|
|
226
|
-
if (status < 500 && FailureCode.isToken(wire.code)) return { code: wire.code, statusCode: status };
|
|
227
|
-
return byStatus;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
212
|
static #statusOf(error: unknown): number | undefined {
|
|
231
213
|
if (isExceptionLike(error)) return error.statusCode;
|
|
232
214
|
if (AkanError.is(error)) return SignalFailure.generalized(error).statusCode;
|
package/server/rscClient.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createElement, type ReactNode, startTransition, type Usable, use, useLayoutEffect, useState } from "react";
|
|
2
2
|
import { hydrateRoot } from "react-dom/client";
|
|
3
3
|
import { createFromReadableStream } from "react-server-dom-webpack/client.browser";
|
|
4
|
+
import { AkanError } from "../base/akanError";
|
|
4
5
|
import { csrLocation } from "../client/csrLocation";
|
|
5
6
|
import { DictionaryAsset } from "../client/dictionaryAsset";
|
|
6
7
|
import type {} from "../client/rscNavigation";
|
|
@@ -84,16 +85,16 @@ type RscFetchResult =
|
|
|
84
85
|
const MAX_RSC_CACHE_ENTRIES = 32;
|
|
85
86
|
let documentNavigationFallbackInFlight = false;
|
|
86
87
|
|
|
87
|
-
class RscRedirectNavigationStarted extends
|
|
88
|
+
class RscRedirectNavigationStarted extends AkanError<"rscRedirectStarted"> {
|
|
88
89
|
constructor(readonly location: string) {
|
|
89
|
-
super("[rscClient] RSC redirect navigation started");
|
|
90
|
+
super("rscRedirectStarted", "[rscClient] RSC redirect navigation started", { statusCode: 303 });
|
|
90
91
|
this.name = "RscRedirectNavigationStarted";
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
class RscRouteNotFound extends
|
|
95
|
+
class RscRouteNotFound extends AkanError<"routeNotFound"> {
|
|
95
96
|
constructor(readonly href: string) {
|
|
96
|
-
super(`[rscClient] no route at ${href}
|
|
97
|
+
super("routeNotFound", `[rscClient] no route at ${href}`, { statusCode: 404 });
|
|
97
98
|
this.name = "RscRouteNotFound";
|
|
98
99
|
}
|
|
99
100
|
}
|
|
@@ -160,7 +161,8 @@ function commitRscPatchNavigation({
|
|
|
160
161
|
requestScroll?: () => void;
|
|
161
162
|
}): boolean {
|
|
162
163
|
const patchThenable = patch.patchedNode.thenable;
|
|
163
|
-
if (!patchThenable)
|
|
164
|
+
if (!patchThenable)
|
|
165
|
+
throw new AkanError("invalidRscResponse", "[rscClient] validated RSC patch is missing a thenable");
|
|
164
166
|
const preparedHeadPatch = prepareAkanHeadSnapshotPatch(patch.headSnapshot, target);
|
|
165
167
|
if (!preparedHeadPatch) return false;
|
|
166
168
|
|
|
@@ -265,7 +267,8 @@ async function fetchRsc(
|
|
|
265
267
|
dictionaryReady,
|
|
266
268
|
]);
|
|
267
269
|
if (patchResult.status === "patched") {
|
|
268
|
-
if (!patchResult.headSnapshot)
|
|
270
|
+
if (!patchResult.headSnapshot)
|
|
271
|
+
throw new AkanError("invalidRscResponse", "[rscClient] validated RSC patch is missing a head snapshot");
|
|
269
272
|
return {
|
|
270
273
|
type: "patched",
|
|
271
274
|
tree: patchResult.tree,
|
|
@@ -283,7 +286,10 @@ async function fetchRsc(
|
|
|
283
286
|
}
|
|
284
287
|
const res = responseResult.response;
|
|
285
288
|
const stream = getRscPayloadStream(res);
|
|
286
|
-
if (!stream)
|
|
289
|
+
if (!stream)
|
|
290
|
+
throw new AkanError("rscFetchFailed", `[rscClient] RSC fetch failed ${res.status} ${res.statusText}`, {
|
|
291
|
+
statusCode: 502,
|
|
292
|
+
});
|
|
287
293
|
const nodeRef: { current?: RscCacheNode } = {};
|
|
288
294
|
const handleRedirect = (redirect: RscRedirectRow) => {
|
|
289
295
|
const node = nodeRef.current;
|
|
@@ -677,7 +683,7 @@ function Root(): ReactNode {
|
|
|
677
683
|
});
|
|
678
684
|
if (fallback.type === "redirected") return;
|
|
679
685
|
if (fallback.type === "not-found") throw new RscRouteNotFound(target);
|
|
680
|
-
if (fallback.type === "patched") throw new
|
|
686
|
+
if (fallback.type === "patched") throw new AkanError("invalidRscResponse", "[rscClient] fallback is a patch");
|
|
681
687
|
nextNode = fallback.node;
|
|
682
688
|
notFound = !!fallback.notFound;
|
|
683
689
|
} else {
|
package/server/sitemap.ts
CHANGED
|
@@ -30,6 +30,7 @@ export function createDefaultSitemapUrls({ origin, basePath, entries, i18n }: De
|
|
|
30
30
|
return paths.map((pathname) => `${normalizedOrigin}${pathname}`);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/** @deprecated Ignores `basePaths`; use `getSitemapBasePath(pathname, basePaths, headerBasePath) !== undefined`. */
|
|
33
34
|
export function isSitemapPath(pathname: string, basePaths: readonly string[]): boolean {
|
|
34
35
|
return normalizePathname(pathname) === "/sitemap.xml";
|
|
35
36
|
}
|
package/service/injectInfo.ts
CHANGED
|
@@ -16,10 +16,11 @@ import type {
|
|
|
16
16
|
ServerSignalCls,
|
|
17
17
|
SliceCls,
|
|
18
18
|
} from "akanjs/signal";
|
|
19
|
-
import type { Adaptor, AdaptorCls
|
|
19
|
+
import type { Adaptor, AdaptorCls } from "./adapt";
|
|
20
20
|
import { InjectError } from "./injectError";
|
|
21
21
|
import { LiveSyncHub } from "./liveSyncHub";
|
|
22
22
|
import type { CacheAdaptor, CacheSetOptions, CacheValue } from "./predefinedAdaptor";
|
|
23
|
+
import type { Service, ServiceCls } from "./serve";
|
|
23
24
|
|
|
24
25
|
export type InjectType = "database" | "service" | "use" | "signal" | "plug" | "env" | "memory";
|
|
25
26
|
|
|
@@ -7,11 +7,11 @@ export type SqliteWriteTurn = () => Promise<void> | null;
|
|
|
7
7
|
/** The connection a read from the calling context runs on; `null` for the one the statement was prepared on. */
|
|
8
8
|
export type SqliteReader = () => Database | null;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const openTurn: SqliteWriteTurn = () => null;
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const ownConnection: SqliteReader = () => null;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
class BunSqliteStatement implements AkanSqlStatement {
|
|
15
15
|
readonly #reads: boolean;
|
|
16
16
|
#onReader: Statement | null = null;
|
|
17
17
|
constructor(
|
|
@@ -11,7 +11,7 @@ import { toPostgresSql } from "../values";
|
|
|
11
11
|
|
|
12
12
|
const prepared = { prepare: true } as const;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
class PostgresStatement implements AkanSqlStatement {
|
|
15
15
|
constructor(
|
|
16
16
|
private readonly client: Sql | TransactionSql,
|
|
17
17
|
private readonly sql: string,
|
|
@@ -3,6 +3,7 @@ import { applyMixins } from "akanjs/common";
|
|
|
3
3
|
import type { AdaptorCls } from "./adapt";
|
|
4
4
|
import type { ServiceCls } from "./serve";
|
|
5
5
|
|
|
6
|
+
/** @deprecated Nothing in akanjs registers into it or reads it; removed in a later minor. */
|
|
6
7
|
export class ServiceRegistry {
|
|
7
8
|
static #database = new Map<string, ServiceCls>();
|
|
8
9
|
static #plain = new Map<string, ServiceCls>();
|
package/signal/SignalFailure.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { AkanError } from "akanjs/base";
|
|
2
|
+
import { FailureCode, isGuardRefusal } from "akanjs/common";
|
|
3
|
+
import { type ExceptionLike, isExceptionLike } from "./exception";
|
|
2
4
|
|
|
3
5
|
export class SignalFailure {
|
|
4
6
|
static readonly message = "Internal Server Error";
|
|
@@ -25,6 +27,25 @@ export class SignalFailure {
|
|
|
25
27
|
return { error: AkanError.reasonOf(statusCode), statusCode, code: error.code };
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
static codeOf(error: unknown, status: number | undefined): string {
|
|
31
|
+
if (!status) return AkanError.codeOfStatus(500);
|
|
32
|
+
const byStatus = AkanError.codeOfStatus(status);
|
|
33
|
+
if (isGuardRefusal(error)) return byStatus;
|
|
34
|
+
const wire = isExceptionLike(error) ? SignalFailure.#wireOf(error) : {};
|
|
35
|
+
if (FailureCode.isKey(wire.error)) return wire.error;
|
|
36
|
+
if (AkanError.is(error) && FailureCode.isToken(error.code)) return error.code;
|
|
37
|
+
if (status < 500 && FailureCode.isToken(wire.code)) return wire.code;
|
|
38
|
+
return byStatus;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static #wireOf(error: ExceptionLike): { error?: unknown; code?: unknown } {
|
|
42
|
+
try {
|
|
43
|
+
return error.toJSON() as { error?: unknown; code?: unknown };
|
|
44
|
+
} catch {
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
28
49
|
static body<Extra extends Record<string, unknown> = Record<string, never>>(
|
|
29
50
|
error: unknown,
|
|
30
51
|
extra: Extra = {} as Extra,
|
|
@@ -23,13 +23,16 @@ export class AgentTurnStream {
|
|
|
23
23
|
/** A domain `Err`'s `data` travels with its key, or the chat could not fill the text's placeholders. */
|
|
24
24
|
static failure(error: unknown): {
|
|
25
25
|
message: string;
|
|
26
|
+
code: string;
|
|
26
27
|
data?: Record<string, string | number>;
|
|
27
28
|
overflow?: { limit?: number };
|
|
28
29
|
} {
|
|
30
|
+
const status = isExceptionLike(error) ? error.statusCode : SignalFailure.generalized(error).statusCode;
|
|
31
|
+
const code = SignalFailure.codeOf(error, status);
|
|
29
32
|
|
|
30
33
|
if (!isExceptionLike(error)) {
|
|
31
34
|
const detail = error instanceof Error ? error.message : String(error);
|
|
32
|
-
return { message: SignalFailure.detailed ? detail : SignalFailure.message };
|
|
35
|
+
return { message: SignalFailure.detailed ? detail : SignalFailure.message, code };
|
|
33
36
|
}
|
|
34
37
|
const message = error instanceof Error ? error.message : String(error);
|
|
35
38
|
const raw = (error as { data?: unknown } | null)?.data;
|
|
@@ -38,7 +41,7 @@ export class AgentTurnStream {
|
|
|
38
41
|
|
|
39
42
|
const overflow =
|
|
40
43
|
message === "agent.error.contextOverflow" ? (typeof data?.limit === "number" ? { limit: data.limit } : {}) : null;
|
|
41
|
-
return { message, ...(data ? { data } : {}), ...(overflow ? { overflow } : {}) };
|
|
44
|
+
return { message, code, ...(data ? { data } : {}), ...(overflow ? { overflow } : {}) };
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
static response(run: RunTurn): Response {
|
package/signal/index.ts
CHANGED
|
@@ -12,35 +12,303 @@ export {
|
|
|
12
12
|
type AgentUsageHook,
|
|
13
13
|
type AgentUsageReport,
|
|
14
14
|
} from "akanjs/service";
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
export {
|
|
16
|
+
type AgentBaseVerb,
|
|
17
|
+
type AgentCandidate,
|
|
18
|
+
AgentCatalogue,
|
|
19
|
+
type AgentCatalogueOptions,
|
|
20
|
+
type AgentOrigin,
|
|
21
|
+
type AgentRefusal,
|
|
22
|
+
type AgentUndescribed,
|
|
23
|
+
} from "./agent";
|
|
24
|
+
export { Agent, AgentEndpoint, AgentInternal, agent } from "./agent.signal";
|
|
25
|
+
export { AgentStop, AgentTurn, AgentTurnDocument, agentTurnConstant, agentTurnDocument } from "./agentTurn";
|
|
26
|
+
export { AgentTurnStream } from "./agentTurnStream";
|
|
27
|
+
export { Base, BaseEndpoint, BaseInternal, base, fetch, getSerializedSignal } from "./base.signal";
|
|
20
28
|
export { CrossSiteGuard, type CrossSiteOption } from "./CrossSiteGuard";
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
export {
|
|
30
|
+
type Endpoint,
|
|
31
|
+
type EndpointCls,
|
|
32
|
+
type EndpointDictArgShape,
|
|
33
|
+
type EndpointDictShape,
|
|
34
|
+
endpoint,
|
|
35
|
+
sliceEndpoint,
|
|
36
|
+
} from "./endpoint";
|
|
37
|
+
export { EndpointErrorContract } from "./endpointErrorContract";
|
|
38
|
+
export {
|
|
39
|
+
type ArgInfo,
|
|
40
|
+
type BuildEndpoint,
|
|
41
|
+
buildEndpoint,
|
|
42
|
+
type EndpInfoArgNames,
|
|
43
|
+
type EndpInfoArgs,
|
|
44
|
+
type EndpInfoClientReturns,
|
|
45
|
+
type EndpInfoInternalArgs,
|
|
46
|
+
type EndpInfoNullable,
|
|
47
|
+
type EndpInfoReqType,
|
|
48
|
+
type EndpInfoReturnRef,
|
|
49
|
+
type EndpInfoServerArgs,
|
|
50
|
+
type EndpInfoServerReturns,
|
|
51
|
+
type EndpInfoSrvs,
|
|
52
|
+
type EndpointArgProps,
|
|
53
|
+
type EndpointBuilder,
|
|
54
|
+
EndpointInfo,
|
|
55
|
+
type EndpointInfoParts,
|
|
56
|
+
type EndpointType,
|
|
57
|
+
type InternalArgInfo,
|
|
58
|
+
type InternalArgProps,
|
|
59
|
+
type ReturnInfo,
|
|
60
|
+
} from "./endpointInfo";
|
|
61
|
+
export { EndpointRateLimit, type RateLimitBudget, type RateLimitSetting } from "./endpointRateLimit";
|
|
62
|
+
export { Exception, type ExceptionLike, isExceptionLike, type StatusException } from "./exception";
|
|
63
|
+
export { type Guard, type GuardCls, type GuardScope, guard, guardOf, refusesAgents } from "./guard";
|
|
64
|
+
export { AgentRelayAccess, None, Public } from "./guards";
|
|
65
|
+
export { type InterceptorCls, intercept } from "./intercept";
|
|
66
|
+
export { type Internal, type InternalCls, internal } from "./internal";
|
|
67
|
+
export {
|
|
68
|
+
CallerAccount,
|
|
69
|
+
type InternalArg,
|
|
70
|
+
type InternalArgCls,
|
|
71
|
+
Ip,
|
|
72
|
+
Machine,
|
|
73
|
+
type MachineIdentity,
|
|
74
|
+
Req,
|
|
75
|
+
Res,
|
|
76
|
+
Ws,
|
|
77
|
+
} from "./internalArg";
|
|
78
|
+
export {
|
|
79
|
+
type BuildInternal,
|
|
80
|
+
buildInternal,
|
|
81
|
+
type InternalBuilder,
|
|
82
|
+
InternalInfo,
|
|
83
|
+
type InternalInfoDefaultArgs,
|
|
84
|
+
type InternalInfoInternalArgs,
|
|
85
|
+
type InternalInfoNullable,
|
|
86
|
+
type InternalInfoParts,
|
|
87
|
+
type InternalInfoReqType,
|
|
88
|
+
type InternalInfoReturns,
|
|
89
|
+
type InternalInfoServerArgs,
|
|
90
|
+
type InternalInfoServerReturns,
|
|
91
|
+
type InternalInfoSrvs,
|
|
92
|
+
} from "./internalInfo";
|
|
93
|
+
export {
|
|
94
|
+
MCP_APP_META,
|
|
95
|
+
MCP_LEGACY_PRIOR_VERSION,
|
|
96
|
+
MCP_LEGACY_VERSION,
|
|
97
|
+
MCP_META_CLIENT_CAPABILITIES,
|
|
98
|
+
MCP_META_CLIENT_INFO,
|
|
99
|
+
MCP_META_PREFIX,
|
|
100
|
+
MCP_META_PROTOCOL_VERSION,
|
|
101
|
+
MCP_META_SERVER_INFO,
|
|
102
|
+
MCP_MODERN_VERSION,
|
|
103
|
+
MCP_SCREEN_REFUSAL,
|
|
104
|
+
MCP_SUPPORTED_VERSIONS,
|
|
105
|
+
MCP_UI_EXTENSION,
|
|
106
|
+
MCP_UI_LEGACY_RESOURCE_URI,
|
|
107
|
+
MCP_UI_MIME_TYPE,
|
|
108
|
+
type McpAppSnapshotRecord,
|
|
109
|
+
McpDocument,
|
|
110
|
+
type McpDocumentOptions,
|
|
111
|
+
type McpEra,
|
|
112
|
+
McpErrorCode,
|
|
113
|
+
type McpErrorCodeValue,
|
|
114
|
+
type McpExposedEndpoint,
|
|
115
|
+
type McpImageContent,
|
|
116
|
+
type McpJsonRpcMessage,
|
|
117
|
+
type McpJsonRpcRequest,
|
|
118
|
+
type McpJsonRpcResponse,
|
|
119
|
+
type McpListingCost,
|
|
120
|
+
type McpOutputSchemaMode,
|
|
121
|
+
McpProgress,
|
|
122
|
+
type McpProgressOption,
|
|
123
|
+
type McpProgressReport,
|
|
124
|
+
type McpPrompt,
|
|
125
|
+
type McpPromptArgument,
|
|
126
|
+
type McpProtocolVersion,
|
|
127
|
+
type McpRefusal,
|
|
128
|
+
type McpResource,
|
|
129
|
+
type McpResourceContents,
|
|
130
|
+
type McpResourceTarget,
|
|
131
|
+
type McpResourceTemplate,
|
|
132
|
+
type McpSignalCost,
|
|
133
|
+
type McpTextContent,
|
|
134
|
+
type McpTool,
|
|
135
|
+
type McpToolAnnotations,
|
|
136
|
+
type McpToolResult,
|
|
137
|
+
type McpToolUiMeta,
|
|
138
|
+
type McpUiVisibility,
|
|
139
|
+
type McpUndescribed,
|
|
140
|
+
McpUriTemplate,
|
|
141
|
+
type Msg,
|
|
142
|
+
type PagePromptEntry,
|
|
143
|
+
type PagePromptRecord,
|
|
144
|
+
type PagePromptRefusal,
|
|
145
|
+
type PagePromptRoute,
|
|
146
|
+
type PagePromptRun,
|
|
147
|
+
type PagePromptRunInput,
|
|
148
|
+
type PagePromptSource,
|
|
149
|
+
type PagePromptVisibleInput,
|
|
150
|
+
type PromptAnnotations,
|
|
151
|
+
type PromptBinaryContent,
|
|
152
|
+
type PromptContent,
|
|
153
|
+
type PromptEmbeddedResourceContent,
|
|
154
|
+
PromptError,
|
|
155
|
+
type PromptErrorCode,
|
|
156
|
+
type PromptFileSource,
|
|
157
|
+
type PromptMessage,
|
|
158
|
+
type PromptModel,
|
|
159
|
+
type PromptResourceLinkContent,
|
|
160
|
+
type PromptResult,
|
|
161
|
+
type PromptRole,
|
|
162
|
+
type PromptTextContent,
|
|
163
|
+
} from "./mcp";
|
|
164
|
+
export { Logging, type Middleware, type MiddlewareCls, middleware, Timeout } from "./middleware";
|
|
165
|
+
export { createOpenApiDocument, type OpenApiDocument, type OpenApiDocumentOptions } from "./openapi";
|
|
166
|
+
export { ResolveFieldContext } from "./resolveFieldContext";
|
|
35
167
|
export { SignalFailure } from "./SignalFailure";
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export
|
|
45
|
-
export
|
|
46
|
-
|
|
168
|
+
export {
|
|
169
|
+
type JsonSchema,
|
|
170
|
+
JsonSchemaBuilder,
|
|
171
|
+
type JsonSchemaBuilderOptions,
|
|
172
|
+
type JsonSchemaFace,
|
|
173
|
+
type JsonSchemaModelOptions,
|
|
174
|
+
type JsonSchemaRelations,
|
|
175
|
+
} from "./schema";
|
|
176
|
+
export { FetchSerializer } from "./serializer";
|
|
177
|
+
export {
|
|
178
|
+
type ServerSignal,
|
|
179
|
+
type ServerSignalCls,
|
|
180
|
+
type ServerSignalClsStatics,
|
|
181
|
+
type ServerSignalMethods,
|
|
182
|
+
serverSignal,
|
|
183
|
+
type TypedServerSignalCls,
|
|
184
|
+
} from "./serverSignal";
|
|
185
|
+
export {
|
|
186
|
+
HttpExecutionContext,
|
|
187
|
+
type HttpPeerResolver,
|
|
188
|
+
SignalContext,
|
|
189
|
+
type SignalTransportType,
|
|
190
|
+
type WebSocketEventType,
|
|
191
|
+
WebSocketExecutionContext,
|
|
192
|
+
} from "./signalContext";
|
|
193
|
+
export { SignalContractError, type SignalContractErrorCode } from "./signalContractError";
|
|
194
|
+
export { SignalDeclarationError, type SignalDeclarationErrorCode } from "./signalDeclarationError";
|
|
195
|
+
export { DatabaseSignal, ServiceSignal, SignalRegistry } from "./signalRegistry";
|
|
196
|
+
export {
|
|
197
|
+
type ResolvedSliceCrud,
|
|
198
|
+
type ResolvedSliceMcp,
|
|
199
|
+
type Slice,
|
|
200
|
+
type SliceCls,
|
|
201
|
+
type SliceDictArgShape,
|
|
202
|
+
type SliceDictShape,
|
|
203
|
+
slice,
|
|
204
|
+
} from "./slice";
|
|
205
|
+
export {
|
|
206
|
+
buildSlice,
|
|
207
|
+
type LiveSliceOption,
|
|
208
|
+
type ResolvedLiveSliceOption,
|
|
209
|
+
type SliceBuilder,
|
|
210
|
+
SliceInfo,
|
|
211
|
+
type SliceInfoArgNames,
|
|
212
|
+
type SliceInfoArgs,
|
|
213
|
+
type SliceInfoFilter,
|
|
214
|
+
type SliceInfoFull,
|
|
215
|
+
type SliceInfoInput,
|
|
216
|
+
type SliceInfoInsight,
|
|
217
|
+
type SliceInfoInternalArgs,
|
|
218
|
+
type SliceInfoLight,
|
|
219
|
+
type SliceInfoParts,
|
|
220
|
+
type SliceInfoRefName,
|
|
221
|
+
type SliceInfoServerArgs,
|
|
222
|
+
type SliceInfoSrvs,
|
|
223
|
+
} from "./sliceInfo";
|
|
224
|
+
export {
|
|
225
|
+
type CanonicalLineMode,
|
|
226
|
+
getCanonicalLineMode,
|
|
227
|
+
getCurrentTrace,
|
|
228
|
+
getFlightThresholdMs,
|
|
229
|
+
getTraceSnapshot,
|
|
230
|
+
isDebugHeaderAllowed,
|
|
231
|
+
isFlightRecorderEnabled,
|
|
232
|
+
isLocalDevRuntime,
|
|
233
|
+
isLogContextEnabled,
|
|
234
|
+
isTraceEnabled,
|
|
235
|
+
runTraced,
|
|
236
|
+
runWithTrace,
|
|
237
|
+
SignalTrace,
|
|
238
|
+
type SpanRecord,
|
|
239
|
+
setCanonicalLineMode,
|
|
240
|
+
setFlightRecorderEnabled,
|
|
241
|
+
setFlightThresholdMs,
|
|
242
|
+
setLogContextEnabled,
|
|
243
|
+
setTraceEnabled,
|
|
244
|
+
type TraceMode,
|
|
245
|
+
type TraceOrigin,
|
|
246
|
+
type TraceOutcome,
|
|
247
|
+
traceAggregator,
|
|
248
|
+
traceCache,
|
|
249
|
+
traceDataLoaderBatch,
|
|
250
|
+
traceDbQuery,
|
|
251
|
+
traceSpan,
|
|
252
|
+
} from "./trace";
|
|
253
|
+
export {
|
|
254
|
+
type ArgType,
|
|
255
|
+
argTypes,
|
|
256
|
+
type CnstCapitalizedRefName,
|
|
257
|
+
type CnstDefault,
|
|
258
|
+
type CnstDefaultInput,
|
|
259
|
+
type CnstDefaultState,
|
|
260
|
+
type CnstFull,
|
|
261
|
+
type CnstInput,
|
|
262
|
+
type CnstInsight,
|
|
263
|
+
type CnstLight,
|
|
264
|
+
type CnstOf,
|
|
265
|
+
type CnstPurifiedInput,
|
|
266
|
+
type CnstRefName,
|
|
267
|
+
type CnstStateInsight,
|
|
268
|
+
type CnstStateLight,
|
|
269
|
+
type DbDoc,
|
|
270
|
+
type DbFilter,
|
|
271
|
+
type DbOf,
|
|
272
|
+
type DbQuery,
|
|
273
|
+
type DbSort,
|
|
274
|
+
type EndpointErrorKey,
|
|
275
|
+
type EndpointErrors,
|
|
276
|
+
type HttpMutationMethod,
|
|
277
|
+
type LiveEndpointOption,
|
|
278
|
+
type LiveEventPayload,
|
|
279
|
+
type SerializedArg,
|
|
280
|
+
type SerializedEndpoint,
|
|
281
|
+
type SerializedFilter,
|
|
282
|
+
type SerializedReturns,
|
|
283
|
+
type SerializedSignal,
|
|
284
|
+
type SerializedSignalMcp,
|
|
285
|
+
type SerializedSlice,
|
|
286
|
+
type SignalOption,
|
|
287
|
+
type SignalType,
|
|
288
|
+
type SlceCnstCapitalizedRefName,
|
|
289
|
+
type SlceCnstDefault,
|
|
290
|
+
type SlceCnstDefaultInput,
|
|
291
|
+
type SlceCnstDefaultState,
|
|
292
|
+
type SlceCnstFull,
|
|
293
|
+
type SlceCnstInput,
|
|
294
|
+
type SlceCnstInsight,
|
|
295
|
+
type SlceCnstLight,
|
|
296
|
+
type SlceCnstPurifiedInput,
|
|
297
|
+
type SlceCnstRefName,
|
|
298
|
+
type SlceCnstStateInsight,
|
|
299
|
+
type SlceCnstStateLight,
|
|
300
|
+
type SlceDbFilter,
|
|
301
|
+
type SlceDbQuery,
|
|
302
|
+
type SlceDbSort,
|
|
303
|
+
type SlceSrv,
|
|
304
|
+
type SrvMap,
|
|
305
|
+
type SrvOf,
|
|
306
|
+
type SrvRefName,
|
|
307
|
+
type WebsocketAuthAck,
|
|
308
|
+
type WebsocketMessageData,
|
|
309
|
+
type WebsocketPublishData,
|
|
310
|
+
type WebsocketReqData,
|
|
311
|
+
type WebsocketResData,
|
|
312
|
+
type WebsocketRoomCursor,
|
|
313
|
+
type WebsocketSubscribeAck,
|
|
314
|
+
} from "./types";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Internal } from "./internal";
|
|
2
|
+
import type { InternalInfo } from "./internalInfo";
|
|
3
|
+
import type { SignalContext } from "./signalContext";
|
|
4
|
+
import { SignalContractError } from "./signalContractError";
|
|
5
|
+
|
|
6
|
+
export class ResolveFieldContext {
|
|
7
|
+
signalContext: SignalContext | null;
|
|
8
|
+
internalInfo: InternalInfo<"resolveField">;
|
|
9
|
+
internal: Internal;
|
|
10
|
+
parent: unknown;
|
|
11
|
+
constructor(
|
|
12
|
+
parent: unknown,
|
|
13
|
+
{
|
|
14
|
+
signalContext,
|
|
15
|
+
internalInfo,
|
|
16
|
+
internal,
|
|
17
|
+
}: { signalContext: SignalContext | null; internalInfo: InternalInfo<"resolveField">; internal: Internal },
|
|
18
|
+
) {
|
|
19
|
+
this.signalContext = signalContext;
|
|
20
|
+
this.internalInfo = internalInfo;
|
|
21
|
+
this.internal = internal;
|
|
22
|
+
this.parent = parent;
|
|
23
|
+
}
|
|
24
|
+
async exec() {
|
|
25
|
+
if (!this.internalInfo.execFn) throw new SignalContractError("noHandler", "Exec function is not set");
|
|
26
|
+
const internalArgs = await Promise.all(
|
|
27
|
+
this.internalInfo.internalArgs.map((arg) =>
|
|
28
|
+
this.signalContext ? (new arg.argRef().getArg(this.signalContext) ?? null) : null,
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
const result = await this.internalInfo.execFn.call(this.internal, this.parent, ...internalArgs);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -3,12 +3,13 @@ import { Logger } from "akanjs/common";
|
|
|
3
3
|
import { ConstantRegistry, type ConstantType } from "akanjs/constant";
|
|
4
4
|
import { type FilterArgInfo, getFilterArgInfos, getFilterMeta } from "akanjs/document";
|
|
5
5
|
import type { LiveRegistry } from "akanjs/service";
|
|
6
|
+
import type { EndpointCls } from "../endpoint";
|
|
7
|
+
import type { ArgInfo, EndpointArgProps, EndpointInfo } from "../endpointInfo";
|
|
8
|
+
import { type GuardCls, refusesAgents } from "../guard";
|
|
9
|
+
import { SignalDeclarationError } from "../signalDeclarationError";
|
|
10
|
+
import type { ResolvedSliceCrud, SliceCls } from "../slice";
|
|
11
|
+
import type { SliceInfo } from "../sliceInfo";
|
|
6
12
|
import type {
|
|
7
|
-
ArgInfo,
|
|
8
|
-
EndpointArgProps,
|
|
9
|
-
EndpointCls,
|
|
10
|
-
EndpointInfo,
|
|
11
|
-
ResolvedSliceCrud,
|
|
12
13
|
SerializedArg,
|
|
13
14
|
SerializedEndpoint,
|
|
14
15
|
SerializedFilter,
|
|
@@ -16,11 +17,7 @@ import type {
|
|
|
16
17
|
SerializedSignal,
|
|
17
18
|
SerializedSignalMcp,
|
|
18
19
|
SerializedSlice,
|
|
19
|
-
|
|
20
|
-
SliceInfo,
|
|
21
|
-
} from "akanjs/signal";
|
|
22
|
-
import { type GuardCls, refusesAgents } from "../guard";
|
|
23
|
-
import { SignalDeclarationError } from "../signalDeclarationError";
|
|
20
|
+
} from "../types";
|
|
24
21
|
|
|
25
22
|
export class FetchSerializer {
|
|
26
23
|
static logger = new Logger("FetchSerializer");
|