@k2b/cloud 0.48.0 → 0.50.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/package.json +3 -3
- package/src/_internal/app-access-resources.ts +2 -1
- package/src/_internal/app-capabilities.ts +73 -0
- package/src/_internal/app-event-catalog.ts +1 -1
- package/src/_internal/app-queries.ts +1 -1
- package/src/_internal/application-package.ts +2 -1
- package/src/_internal/capabilities.ts +17 -2
- package/src/_internal/define-app.ts +2 -0
- package/src/ai/app-skill-store.ts +2 -1
- package/src/ai/app-skills.ts +2 -1
- package/src/ai/approvals.ts +2 -1
- package/src/ai/chat-tasks.ts +2 -1
- package/src/ai/credentials.ts +2 -1
- package/src/ai/dictation-runtime.ts +1 -1
- package/src/ai/dictations.ts +1 -1
- package/src/ai/files-store.ts +2 -1
- package/src/ai/inference-calls.ts +2 -1
- package/src/ai/map-store.ts +1 -1
- package/src/ai/map-tool.ts +1 -1
- package/src/ai/memories.ts +1 -1
- package/src/ai/memory-learning-runs.ts +1 -1
- package/src/ai/memory-learning.ts +1 -1
- package/src/ai/memory-workflow-evidence.ts +1 -1
- package/src/ai/message-queue.ts +2 -1
- package/src/ai/migrate.ts +1 -1
- package/src/ai/model-access-migrate.ts +1 -1
- package/src/ai/model-access.ts +1 -1
- package/src/ai/model-catalog.ts +1 -1
- package/src/ai/model-delete.ts +1 -1
- package/src/ai/model-usage.ts +2 -1
- package/src/ai/open-questions.ts +1 -1
- package/src/ai/openai-api-slots.ts +2 -1
- package/src/ai/prefs.ts +2 -1
- package/src/ai/projects.ts +2 -1
- package/src/ai/provider-connections.ts +1 -1
- package/src/ai/quota-limits.ts +2 -1
- package/src/ai/quota-provider.ts +2 -1
- package/src/ai/quota-report.ts +2 -1
- package/src/ai/quotas-migrate.ts +2 -1
- package/src/ai/quotas.ts +2 -1
- package/src/ai/request-headers.ts +2 -1
- package/src/ai/review-content.ts +2 -1
- package/src/ai/skill-search.ts +2 -1
- package/src/ai/skills.ts +2 -1
- package/src/ai/store.ts +2 -1
- package/src/ai/structured-runs.ts +2 -1
- package/src/ai/tool-audit.ts +2 -1
- package/src/ai/turn-timing.ts +1 -1
- package/src/ai/usage.ts +2 -1
- package/src/ai/web-provenance.ts +2 -1
- package/src/api/admin-ai-quotas.ts +1 -1
- package/src/api/admin-ai.ts +1 -1
- package/src/api/admin-app-keys.ts +47 -3
- package/src/api/admin-core-settings.ts +1 -1
- package/src/api/admin-outgoing-mail.ts +1 -1
- package/src/api/app-bootstrap.ts +23 -1
- package/src/api/app-events.ts +1 -1
- package/src/api/auth.ts +1 -1
- package/src/api/authenticate-app-request.ts +129 -0
- package/src/api/capabilities.ts +79 -5
- package/src/api/index.ts +2 -0
- package/src/api/me.ts +1 -1
- package/src/api/search.bench.ts +1 -1
- package/src/app-pwa/service.ts +2 -1
- package/src/app-pwa/transaction.ts +4 -2
- package/src/capabilities/claims.ts +2 -1
- package/src/capabilities/executions.ts +8 -4
- package/src/capabilities/geo-client.ts +1 -1
- package/src/capabilities/migrate.ts +3 -1
- package/src/capabilities/resource-readers.ts +2 -2
- package/src/capabilities/server-invoke.ts +45 -18
- package/src/capabilities/server.ts +2 -1
- package/src/cli/admin/app-keys.ts +25 -3
- package/src/config/env.ts +4 -4
- package/src/contracts/capabilities.ts +15 -2
- package/src/contracts/outgoing-mail.ts +1 -1
- package/src/events/app-event-delivery.ts +1 -1
- package/src/events/live-delivery.ts +2 -1
- package/src/runtime/bootstrap-protocol.ts +11 -4
- package/src/runtime/clients.ts +6 -2
- package/src/server/index.ts +1 -0
- package/src/server/ratelimit.ts +1 -1
- package/src/server/services/access.ts +2 -1
- package/src/services/account-category-policy.ts +1 -1
- package/src/services/account-lifecycle/audit.ts +1 -1
- package/src/services/account-lifecycle/index.ts +1 -1
- package/src/services/account-lifecycle/ipa-backfill.ts +2 -1
- package/src/services/accounts/app.ts +1 -1
- package/src/services/accounts/avatar.ts +1 -1
- package/src/services/accounts/base-group.ts +1 -1
- package/src/services/accounts/directory-shares.ts +1 -1
- package/src/services/accounts/duplicate-emails.ts +1 -1
- package/src/services/accounts/entities.ts +2 -1
- package/src/services/accounts/group-sql.ts +2 -1
- package/src/services/accounts/groups.ts +1 -1
- package/src/services/accounts/identities.ts +13 -11
- package/src/services/accounts/ipa-data.ts +1 -1
- package/src/services/accounts/local-groups.ts +2 -1
- package/src/services/accounts/machine-group-management.ts +2 -1
- package/src/services/accounts/posix.ts +13 -12
- package/src/services/accounts/request-policy.ts +2 -1
- package/src/services/accounts/switching.ts +1 -1
- package/src/services/accounts/users.ts +2 -1
- package/src/services/announcements/index.ts +1 -1
- package/src/services/app-access-management.ts +2 -1
- package/src/services/app-access.ts +2 -1
- package/src/services/app-admin-facts.ts +11 -3
- package/src/services/app-approval.ts +34 -30
- package/src/services/app-bootstrap.ts +104 -21
- package/src/services/app-details.ts +3 -2
- package/src/services/app-events/accept.ts +5 -5
- package/src/services/app-events/admin.ts +15 -15
- package/src/services/app-events/declarations.ts +6 -3
- package/src/services/app-events/deliver.ts +6 -6
- package/src/services/app-events.ts +3 -2
- package/src/services/app-keys.ts +42 -11
- package/src/services/approvals/content.ts +1 -1
- package/src/services/approvals/index.ts +2 -1
- package/src/services/approvals/list.ts +1 -1
- package/src/services/approvals/migrate.ts +1 -1
- package/src/services/audit/index.ts +2 -1
- package/src/services/auth-flows/ipa.ts +1 -1
- package/src/services/auth-flows/magic-link.ts +1 -1
- package/src/services/auth-flows/password-reset.ts +1 -1
- package/src/services/auth-flows/proxy-return.ts +1 -1
- package/src/services/geo/admin.ts +13 -12
- package/src/services/geo/identity.ts +46 -0
- package/src/services/geo/ledger.ts +118 -106
- package/src/services/geo/migrate.ts +2 -1
- package/src/services/geo/route-chain.ts +3 -3
- package/src/services/geo/service.ts +4 -24
- package/src/services/geoip/index.ts +5 -5
- package/src/services/geoip/store.ts +24 -21
- package/src/services/help/index.ts +2 -1
- package/src/services/help/store.ts +2 -1
- package/src/services/identity/app-request.ts +44 -0
- package/src/services/identity/constants.ts +1 -0
- package/src/services/identity/index.ts +1 -0
- package/src/services/identity/invocation-actor.ts +2 -1
- package/src/services/identity/invocation-token.ts +112 -0
- package/src/services/identity/key-ring.ts +2 -2
- package/src/services/identity/resource-readers.ts +1 -1
- package/src/services/identity/routes.ts +11 -3
- package/src/services/identity/runtime-config.ts +14 -3
- package/src/services/identity/workload-auth.ts +2 -0
- package/src/services/identity/workload-runtime.ts +1 -1
- package/src/services/ipa/groups.ts +1 -1
- package/src/services/ipa/profile.ts +1 -1
- package/src/services/ipa/search.ts +1 -1
- package/src/services/ipa/sync.ts +1 -1
- package/src/services/ipa/users.ts +1 -1
- package/src/services/known-browsers.ts +2 -1
- package/src/services/legal-consent.ts +1 -1
- package/src/services/logging/index.ts +6 -3
- package/src/services/logging/trace.ts +1 -1
- package/src/services/logging/web-vitals.ts +1 -1
- package/src/services/mandates/index.ts +2 -1
- package/src/services/notifications/batches.ts +1 -1
- package/src/services/notifications/browser.ts +1 -1
- package/src/services/notifications/catalog.ts +1 -1
- package/src/services/notifications/dispatcher.ts +1 -1
- package/src/services/notifications/index.ts +1 -1
- package/src/services/notifications/observability.ts +2 -1
- package/src/services/notifications/platform.ts +1 -1
- package/src/services/notifications/quiet.ts +1 -1
- package/src/services/notifications/user.ts +1 -1
- package/src/services/oauth-tokens.ts +1 -1
- package/src/services/outbox.ts +15 -14
- package/src/services/outgoing-mail/admin.ts +1 -1
- package/src/services/outgoing-mail/dispatcher.ts +1 -1
- package/src/services/outgoing-mail/drain.ts +2 -1
- package/src/services/outgoing-mail/enqueue.ts +2 -1
- package/src/services/outgoing-mail/messages.ts +2 -1
- package/src/services/outgoing-mail/retention.ts +1 -1
- package/src/services/outgoing-mail/send.ts +1 -1
- package/src/services/outgoing-mail/store.ts +2 -1
- package/src/services/panel-context-consent.ts +32 -28
- package/src/services/providers/local/auth.ts +1 -1
- package/src/services/providers/local/users.ts +1 -1
- package/src/services/pwa-devices.ts +2 -1
- package/src/services/rail-preferences.ts +16 -12
- package/src/services/rail-shortcuts.ts +12 -10
- package/src/services/request-cache-redis.ts +3 -3
- package/src/services/service-account-credentials.ts +2 -1
- package/src/services/service-accounts.ts +2 -1
- package/src/services/session/index.ts +2 -1
- package/src/services/session/user.ts +2 -1
- package/src/services/settings/index.ts +1 -1
- package/src/services/settings/store.ts +1 -1
- package/src/services/settings/versions.ts +2 -1
- package/src/services/weather/forecast.ts +2 -1
- package/src/services/weather/locations.ts +1 -1
- package/src/services/weather/migrate.ts +2 -1
- package/src/services/weather/short-id.ts +2 -1
- package/src/services/webauthn.ts +1 -1
- package/src/shared-text/documents.ts +2 -2
- package/src/ssr/compact-shell.browser-harness.ts +2 -0
- package/src/workflows/ai/store.ts +2 -1
- package/src/workflows/store/budget.ts +2 -1
- package/src/workflows/store/definitions.ts +2 -1
- package/src/workflows/store/events.ts +2 -1
- package/src/workflows/store/observability.ts +2 -1
- package/src/workflows/store/retention.ts +2 -1
- package/src/workflows/store/runs.ts +2 -1
- package/src/workflows/store/transaction.ts +2 -1
- package/src/workflows/store/worker.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k2b/cloud",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "Application platform library for independently deployed Hono and SolidJS services behind a dynamic gateway.",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"@tailwindcss/typography": "0.5.20",
|
|
132
132
|
"@k2b/nessi": "0.18.0",
|
|
133
133
|
"@k2b/ssr": "0.20.2",
|
|
134
|
-
"@k2b/ui": "0.
|
|
134
|
+
"@k2b/ui": "0.39.0",
|
|
135
135
|
"@k2b/stdlib": "0.30.0",
|
|
136
136
|
"@k2b/sync": "7.0.1",
|
|
137
137
|
"@nats-io/jetstream": "3.4.0",
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
"hash-wasm": "4.12.0",
|
|
164
164
|
"@types/sanitize-html": "2.16.1",
|
|
165
165
|
"@types/web-push": "3.6.4",
|
|
166
|
-
"@k2b/editor": "0.
|
|
166
|
+
"@k2b/editor": "0.3.0"
|
|
167
167
|
},
|
|
168
168
|
"devDependencies": {
|
|
169
169
|
"@babel/core": "8.0.6",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "node:util";
|
|
2
|
-
import {
|
|
2
|
+
import type { SQL } from "bun";
|
|
3
3
|
import { waitWithin } from "../api/fanout";
|
|
4
4
|
import type { AppMeta } from "../contracts/app";
|
|
5
5
|
import { type AppAccessDeclaration, type AppAccessRule, AppAccessRuleSchema, type ResourceAppAccessAdapter } from "../contracts/app-access";
|
|
6
|
+
import { sql } from "../runtime/clients";
|
|
6
7
|
import type { RequestAuthority } from "../server/middleware/auth";
|
|
7
8
|
import { coreOrigin } from "../services/identity/core-origin";
|
|
8
9
|
import { invocationAuthorityFromRequest } from "../services/identity/invocation-authority";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { CAPABILITY_MAX_REQUEST_BYTES } from "../contracts/capabilities";
|
|
3
|
+
import { resolveLocale } from "../server/locale";
|
|
4
|
+
import { getActiveAppKey } from "../services/app-keys";
|
|
5
|
+
import { verifyAppCapabilityInvocation } from "../services/identity/invocation-token";
|
|
6
|
+
import { get } from "../services/settings";
|
|
7
|
+
import { readBoundedJson } from "./bounded-json";
|
|
8
|
+
import { type CompiledCapabilities, invokeCompiledCapability, serializeCapabilityProviderResult } from "./capabilities";
|
|
9
|
+
import { withCapabilityRequestTimeout } from "./capability-timeout";
|
|
10
|
+
|
|
11
|
+
/** Separate from ordinary auth: application authority never becomes a grant-bearing person. */
|
|
12
|
+
export const createAppCapabilityRoutes = (compiled: CompiledCapabilities) => {
|
|
13
|
+
const router = new Hono();
|
|
14
|
+
for (const kind of ["query", "action"] as const) {
|
|
15
|
+
router.post(`/${kind === "query" ? "queries" : "actions"}/:capabilityId`, (c) =>
|
|
16
|
+
withCapabilityRequestTimeout(c, kind, async () => {
|
|
17
|
+
const operation = (kind === "query" ? compiled.queries : compiled.actions).get(c.req.param("capabilityId"));
|
|
18
|
+
const deny = () => c.json({ code: "FORBIDDEN", message: "A permitted signed app capability invocation is required" }, 403);
|
|
19
|
+
if (!operation?.manifest.appPermission || operation.manifest.stream) return deny();
|
|
20
|
+
const body = await readBoundedJson(c.req.raw, CAPABILITY_MAX_REQUEST_BYTES);
|
|
21
|
+
if (
|
|
22
|
+
!body.ok ||
|
|
23
|
+
!body.data ||
|
|
24
|
+
typeof body.data !== "object" ||
|
|
25
|
+
Array.isArray(body.data) ||
|
|
26
|
+
Object.keys(body.data).length !== 1 ||
|
|
27
|
+
!("input" in body.data)
|
|
28
|
+
)
|
|
29
|
+
return c.json({ code: "VALIDATION_FAILED", message: "Expected a bounded input object" }, 400);
|
|
30
|
+
const token = c.req.header("authorization")?.match(/^Bearer (\S+)$/)?.[1];
|
|
31
|
+
if (!token) return deny();
|
|
32
|
+
try {
|
|
33
|
+
const claims = await verifyAppCapabilityInvocation(token, {
|
|
34
|
+
appId: compiled.manifest.appId,
|
|
35
|
+
kind,
|
|
36
|
+
capabilityId: operation.manifest.localId,
|
|
37
|
+
schemaHash: operation.manifest.schemaHash,
|
|
38
|
+
permission: operation.manifest.appPermission,
|
|
39
|
+
input: body.data.input,
|
|
40
|
+
});
|
|
41
|
+
if (!claims) return deny();
|
|
42
|
+
const locale = resolveLocale(c.req.raw.headers, await get<string>("app.locale"));
|
|
43
|
+
if (!(await getActiveAppKey({ appId: claims.sub, keyId: claims.key_id }))) return deny();
|
|
44
|
+
const result = await invokeCompiledCapability({
|
|
45
|
+
compiled,
|
|
46
|
+
kind,
|
|
47
|
+
localId: operation.manifest.localId,
|
|
48
|
+
input: body.data.input,
|
|
49
|
+
expectedSchemaHash: claims.schema_hash,
|
|
50
|
+
context: {
|
|
51
|
+
actor: { kind: "app", appId: claims.sub, keyId: claims.key_id },
|
|
52
|
+
accessSubject: { type: "none" },
|
|
53
|
+
user: null,
|
|
54
|
+
locale,
|
|
55
|
+
requestId: claims.request_id,
|
|
56
|
+
origin: "app",
|
|
57
|
+
signal: c.req.raw.signal,
|
|
58
|
+
...(c.req.header("idempotency-key") ? { idempotencyKey: c.req.header("idempotency-key") } : {}),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
const response = serializeCapabilityProviderResult(result);
|
|
62
|
+
return new Response(response.body, {
|
|
63
|
+
status: response.status,
|
|
64
|
+
headers: { "content-type": "application/json", "cache-control": "no-store" },
|
|
65
|
+
});
|
|
66
|
+
} catch {
|
|
67
|
+
return c.json({ code: "APP_UNAVAILABLE", message: "App invocation verification unavailable" }, 503);
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return router;
|
|
73
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import type { CapabilityEventCatalogEntry, CapabilityManifest } from "../contracts/capabilities";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
3
|
|
|
4
4
|
export type CatalogSubscription = CapabilityEventCatalogEntry["subscribers"][number] & { eventType: string; version: number };
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import { Hono } from "hono";
|
|
3
2
|
import { CAPABILITY_MAX_REQUEST_BYTES } from "../contracts/capabilities";
|
|
3
|
+
import { sql } from "../runtime/clients";
|
|
4
4
|
import { resolveLocale } from "../server/locale";
|
|
5
5
|
import { verifyAppQueryInvocation } from "../services/identity/invocation-token";
|
|
6
6
|
import { get } from "../services/settings";
|
|
@@ -133,6 +133,7 @@ const TYPE_FIELDS = {
|
|
|
133
133
|
access: true,
|
|
134
134
|
} satisfies DefinedFields<CapabilityResourceTypeDefinition>;
|
|
135
135
|
const QUERY_FIELDS = {
|
|
136
|
+
app: true,
|
|
136
137
|
appOnly: true,
|
|
137
138
|
title: true,
|
|
138
139
|
description: true,
|
|
@@ -144,6 +145,7 @@ const QUERY_FIELDS = {
|
|
|
144
145
|
run: true,
|
|
145
146
|
} satisfies DefinedFields<CapabilityQueryDefinition>;
|
|
146
147
|
const ACTION_FIELDS = {
|
|
148
|
+
app: true,
|
|
147
149
|
title: true,
|
|
148
150
|
description: true,
|
|
149
151
|
input: true,
|
|
@@ -682,6 +684,11 @@ const compileOperationSchemas = (definition: QueryDefinition | CapabilityActionD
|
|
|
682
684
|
) {
|
|
683
685
|
throw new Error(`${label} input field "idempotencyKey" is reserved for capability transports`);
|
|
684
686
|
}
|
|
687
|
+
if (definition.app !== undefined) {
|
|
688
|
+
assertDefinedFields(definition.app, { permission: true, run: true }, `${label} app`);
|
|
689
|
+
if (typeof definition.app.run !== "function") throw new Error(`${label} app.run must be a function`);
|
|
690
|
+
if (definition.stream) throw new Error(`${label} app calls cannot use streams`);
|
|
691
|
+
}
|
|
685
692
|
const resultZodSchema = capabilityResultSchema(definition.data);
|
|
686
693
|
const dataSchema = projectSchema(definition.data, `${label} data`, "output");
|
|
687
694
|
return {
|
|
@@ -691,6 +698,7 @@ const compileOperationSchemas = (definition: QueryDefinition | CapabilityActionD
|
|
|
691
698
|
schemaHash: capabilityHash({
|
|
692
699
|
inputSchema,
|
|
693
700
|
dataSchema,
|
|
701
|
+
...(definition.app ? { appPermission: definition.app.permission } : {}),
|
|
694
702
|
...("appOnly" in definition && definition.appOnly !== undefined ? { appOnly: definition.appOnly } : {}),
|
|
695
703
|
...(definition.stream ? { stream: { direction: definition.stream.direction, maxBytes: definition.stream.maxBytes } } : {}),
|
|
696
704
|
}),
|
|
@@ -843,6 +851,7 @@ export const compileCapabilities = (
|
|
|
843
851
|
inputSchema: schemas.inputSchema,
|
|
844
852
|
dataSchema: schemas.dataSchema,
|
|
845
853
|
schemaHash: schemas.schemaHash,
|
|
854
|
+
...(definition.app ? { appPermission: definition.app.permission } : {}),
|
|
846
855
|
...(definition.stream ? { stream: { direction: definition.stream.direction, maxBytes: definition.stream.maxBytes } } : {}),
|
|
847
856
|
openWorld: definition.openWorld,
|
|
848
857
|
universalSearch: normalizeSearchTags(definition, label),
|
|
@@ -927,6 +936,7 @@ export const compileCapabilities = (
|
|
|
927
936
|
inputSchema: schemas.inputSchema,
|
|
928
937
|
dataSchema: schemas.dataSchema,
|
|
929
938
|
schemaHash: schemas.schemaHash,
|
|
939
|
+
...(definition.app ? { appPermission: definition.app.permission } : {}),
|
|
930
940
|
...(definition.stream ? { stream: { direction: definition.stream.direction, maxBytes: definition.stream.maxBytes } } : {}),
|
|
931
941
|
destructive: definition.destructive,
|
|
932
942
|
openWorld: definition.openWorld,
|
|
@@ -1280,6 +1290,7 @@ const assertUsableOperation = (operation: CapabilityQueryManifest | CapabilityAc
|
|
|
1280
1290
|
const expectedSchemaHash = capabilityHash({
|
|
1281
1291
|
inputSchema: operation.inputSchema,
|
|
1282
1292
|
dataSchema: operation.dataSchema,
|
|
1293
|
+
...(operation.appPermission ? { appPermission: operation.appPermission } : {}),
|
|
1283
1294
|
...("appOnly" in operation && operation.appOnly !== undefined ? { appOnly: operation.appOnly } : {}),
|
|
1284
1295
|
...(operation.stream ? { stream: operation.stream } : {}),
|
|
1285
1296
|
});
|
|
@@ -1782,9 +1793,13 @@ export const invokeCompiledCapability = async (params: {
|
|
|
1782
1793
|
let invoked: CapabilityInvocationResult<unknown>;
|
|
1783
1794
|
if (isAppCapabilityContext(context)) {
|
|
1784
1795
|
const definition = operation.definition;
|
|
1785
|
-
if (
|
|
1796
|
+
if (definition.app && context.actor.keyId) {
|
|
1797
|
+
invoked = await definition.app.run(input.data, context);
|
|
1798
|
+
} else if (params.kind === "query" && "appOnly" in definition && definition.appOnly === true) {
|
|
1799
|
+
invoked = await definition.run(input.data, context);
|
|
1800
|
+
} else {
|
|
1786
1801
|
return { ok: false, error: { code: "FORBIDDEN", message: "App caller is not allowed", status: 403 } };
|
|
1787
|
-
|
|
1802
|
+
}
|
|
1788
1803
|
} else {
|
|
1789
1804
|
if (operation.definition.appOnly) return { ok: false, error: { code: "FORBIDDEN", message: "App authority required", status: 403 } };
|
|
1790
1805
|
invoked = await operation.definition.run(input.data, context);
|
|
@@ -13,6 +13,7 @@ import { registerPageSwap } from "../ssr/page-swap";
|
|
|
13
13
|
import { preloadPanelConsent } from "../ssr/panel-consent";
|
|
14
14
|
import { appAccessManagementPath } from "./app-access-path";
|
|
15
15
|
import { bindResourceAppAccess, RESOURCE_ACCESS_PATH } from "./app-access-resources";
|
|
16
|
+
import { createAppCapabilityRoutes } from "./app-capabilities";
|
|
16
17
|
import { createAppQueryRoutes } from "./app-queries";
|
|
17
18
|
import { registerApplicationPackage, resolveApplicationPackage } from "./application-package";
|
|
18
19
|
import { invokeCapabilityStream } from "./capability-streams";
|
|
@@ -956,6 +957,7 @@ export const defineApp = <
|
|
|
956
957
|
|
|
957
958
|
if (compiledCapabilities) {
|
|
958
959
|
server.route("/api/_internal/capabilities/v1/app-queries", createAppQueryRoutes(compiledCapabilities));
|
|
960
|
+
server.route("/api/_internal/capabilities/v1/app-capabilities", createAppCapabilityRoutes(compiledCapabilities));
|
|
959
961
|
const invoke = async (c: Context<AuthContext>, kind: "query" | "action" | "review") =>
|
|
960
962
|
withCapabilityRequestTimeout(c, kind, async () => {
|
|
961
963
|
// Framework-owned endpoints run before the app's settings middleware,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SQL, TransactionSQL } from "bun";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { appAudienceRoles } from "../_internal/app-roles";
|
|
4
4
|
import { APP_REGISTRY_TTL_MS } from "../_internal/registry";
|
|
5
5
|
import type { AppRegistryEntry } from "../contracts/registry";
|
|
6
|
+
import { sql } from "../runtime/clients";
|
|
6
7
|
import { logger } from "../services/logging";
|
|
7
8
|
import { toPgTextArray } from "../services/postgres";
|
|
8
9
|
import { type AppSkillDefinition, parseStoredAppSkill } from "./app-skills";
|
package/src/ai/app-skills.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { sql } from "../runtime/clients";
|
|
3
4
|
import { logger } from "../services/logging";
|
|
4
5
|
import { AI_SKILL_CATALOG_MAX_CHARS, aiSkillCatalogChars } from "./skill-catalog";
|
|
5
6
|
import { type AiSkillContent, canonicalHash, contentHash, validateSkillContent } from "./skill-content";
|
package/src/ai/approvals.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
2
|
import type { AccessSubject } from "../contracts/shared";
|
|
3
|
+
import { sql } from "../runtime/clients";
|
|
3
4
|
import type { RequestActor } from "../server/middleware/auth";
|
|
4
5
|
import { type AuditActor, type AuditRecordParams, audit } from "../services/audit";
|
|
5
6
|
import { toPgTextArray } from "../services/postgres";
|
package/src/ai/chat-tasks.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Message } from "@k2b/nessi";
|
|
2
|
-
import {
|
|
2
|
+
import type { SQL } from "bun";
|
|
3
3
|
import { getCapability } from "../_internal/registry";
|
|
4
4
|
import { type CapabilityActionPolicy, capabilityActionPolicy } from "../contracts/capabilities";
|
|
5
|
+
import { sql } from "../runtime/clients";
|
|
5
6
|
import { logger } from "../services/logging";
|
|
6
7
|
import {
|
|
7
8
|
createMandate,
|
package/src/ai/credentials.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import { lazySync } from "../_internal/process-sync";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
3
|
import { get as getUser } from "../services/accounts/users";
|
|
4
4
|
import { logger, trace } from "../services/logging";
|
|
5
5
|
import { superviseRuntimeTask } from "../services/runtime-lifecycle";
|
package/src/ai/dictations.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
3
|
import { inspectAiAudio } from "./audio-format";
|
|
4
4
|
import { createUniqueAiFileInTransaction } from "./files-store";
|
|
5
5
|
import { AiSaveConversationDraftInputSchema } from "./http";
|
package/src/ai/files-store.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
2
3
|
import { stripImageMetadata } from "../services/image-metadata";
|
|
3
4
|
import { AiFileVersionConflict, AiFileWriteError, aiFileContentVersion } from "./file-content-version";
|
|
4
5
|
import { isAiImage } from "./file-media-type";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
2
3
|
import type { AccessSubject } from "../server/services/access";
|
|
3
4
|
import { aiBudgetUnits, aiCostDecimal, aiCostUnits, aiDecimalUnits, hasBillableAiPricing } from "../shared/ai-costs";
|
|
4
5
|
import { AiQuotaError, aiQuotas, quotaWindow } from "./quotas";
|
package/src/ai/map-store.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
3
|
import { toPgTextArray } from "../services/postgres";
|
|
4
4
|
import type { AiMap, AiMapCommand } from "./map-contracts";
|
|
5
5
|
import { AiMapSchema, aiMapToolResult } from "./map-contracts";
|
package/src/ai/map-tool.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import type { CapabilityCaller } from "../capabilities/server";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
3
|
import { resolveAiCapabilityActor } from "./capability-execution";
|
|
4
4
|
import { AiMapToolInputSchema, AiMapToolResultSchema, aiMapToolResult } from "./map-contracts";
|
|
5
5
|
import { executeStoredAiMap } from "./map-execution";
|
package/src/ai/memories.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { sql } from "bun";
|
|
3
2
|
import { z } from "zod";
|
|
4
3
|
import { CloudResourceRefSchema } from "../contracts/capabilities";
|
|
4
|
+
import { sql } from "../runtime/clients";
|
|
5
5
|
import { coreSettings } from "../services";
|
|
6
6
|
import { logger } from "../services/logging";
|
|
7
7
|
import { normalizeLocale } from "../shared/locale";
|
package/src/ai/message-queue.ts
CHANGED
package/src/ai/migrate.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import { CapabilityActionReviewDataSchema } from "../contracts/capabilities";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
3
|
import { APPROVAL_MAX_WAIT_MS, approvalAssurance, approvalScopeFromToolName, approvals, migrateApprovals } from "../services/approvals";
|
|
4
4
|
import { migrateChatTaskReasons } from "./chat-task-reasons-migrate";
|
|
5
5
|
import { migrateAiMaps } from "./map-store";
|
package/src/ai/model-access.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import type { AccessEntry, Principal, ServiceAccountKind } from "../contracts/shared";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
3
|
import { type AccessSubject, buildAccessPrincipalCondition, createAccess } from "../server/services/access";
|
|
4
4
|
import { toPgTextArray } from "../services/postgres";
|
|
5
5
|
import type { AiModelAccessDraft } from "../shared/ai-models";
|
package/src/ai/model-catalog.ts
CHANGED
package/src/ai/model-delete.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
3
|
import { recursiveGroupIdsSubquery } from "../services/accounts/group-sql";
|
|
4
4
|
import { toPgTextArray } from "../services/postgres";
|
|
5
5
|
import { type AiDeleteModelInput, type AiModel, type AiModelSlot, type AiProvider, aiReplacementProblem } from "../shared/ai-models";
|
package/src/ai/model-usage.ts
CHANGED
package/src/ai/open-questions.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import { z } from "zod";
|
|
3
2
|
import { APPROVALS_PAGE_SIZE } from "../contracts/approvals";
|
|
4
3
|
import { CapabilityActionReviewPresentationSchema, CapabilitySemanticLinkSchema } from "../contracts/capabilities";
|
|
4
|
+
import { sql } from "../runtime/clients";
|
|
5
5
|
import { openRequests } from "../services/approvals/content";
|
|
6
6
|
import { logger } from "../services/logging";
|
|
7
7
|
import { reviewShortText, toolActionCard, toolBlockReview } from "./chat/action-card";
|
package/src/ai/prefs.ts
CHANGED
package/src/ai/projects.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SQL, SQLQuery } from "bun";
|
|
2
2
|
import type { CloudResourceRef } from "../contracts/capabilities";
|
|
3
3
|
import { AuthenticatedPrincipalSchema, type ServiceAccountKind } from "../contracts/shared";
|
|
4
|
+
import { sql } from "../runtime/clients";
|
|
4
5
|
import {
|
|
5
6
|
buildAccessPrincipalCondition,
|
|
6
7
|
createAccess,
|
package/src/ai/quota-limits.ts
CHANGED
package/src/ai/quota-provider.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { setTimeout as delay } from "node:timers/promises";
|
|
2
2
|
import { estimateTokens, type Provider } from "@k2b/nessi";
|
|
3
|
-
import { sql } from "
|
|
3
|
+
import { sql } from "../runtime/clients";
|
|
4
|
+
|
|
4
5
|
import type { AccessSubject } from "../server/services/access";
|
|
5
6
|
import { logger } from "../services/logging";
|
|
6
7
|
import type { AiResolvedModelRef } from "../shared/ai-models";
|
package/src/ai/quota-report.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { sql } from "
|
|
1
|
+
import { sql } from "../runtime/clients";
|
|
2
|
+
|
|
2
3
|
import { resolveDisplayNames } from "../server/services/access";
|
|
3
4
|
import { recursiveGroupIdsSubquery } from "../services/accounts/group-sql";
|
|
4
5
|
import { toPgTextArray } from "../services/postgres";
|
package/src/ai/quotas-migrate.ts
CHANGED
package/src/ai/quotas.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
2
3
|
import { type AccessSubject, buildAccessPrincipalCondition } from "../server/services/access";
|
|
3
4
|
import { hasBillableAiPricing } from "../shared/ai-costs";
|
|
4
5
|
import { type AiQuotaConfig, AiQuotaConfigSchema, type AiQuotaIdentity, type AiQuotaSnapshot } from "../shared/ai-quotas";
|
package/src/ai/review-content.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
2
|
import { capabilityRequestHash } from "../capabilities/claims";
|
|
3
3
|
import { parseStoredReviewContent } from "../capabilities/review-storage";
|
|
4
4
|
import { CAPABILITY_MAX_REVIEW_CONTENT_BYTES, type CapabilityActionReviewPresentation } from "../contracts/capabilities";
|
|
5
|
+
import { sql } from "../runtime/clients";
|
|
5
6
|
import type { AiStoredActionReview } from "./action-review";
|
|
6
7
|
|
|
7
8
|
export type ReviewContentLocation = { conversationId: string; turnId: string; callId: string };
|
package/src/ai/skill-search.ts
CHANGED
package/src/ai/skills.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SQL, SQLQuery } from "bun";
|
|
2
2
|
import { listApps } from "../_internal/registry";
|
|
3
3
|
import { AuthenticatedPrincipalSchema, type ServiceAccountKind } from "../contracts/shared";
|
|
4
|
+
import { sql } from "../runtime/clients";
|
|
4
5
|
import type { RequestAuthority } from "../server/middleware/auth";
|
|
5
6
|
import {
|
|
6
7
|
buildAccessPrincipalCondition,
|
package/src/ai/store.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { DoneReason, InboundEvent, LoopAggregate, Message, SessionStore, StoreEntry } from "@k2b/nessi";
|
|
2
2
|
import type { Usage } from "@k2b/nessi/ai";
|
|
3
|
-
import {
|
|
3
|
+
import type { SQL } from "bun";
|
|
4
4
|
import { capabilityRequestHash } from "../capabilities/claims";
|
|
5
5
|
import { restoreReviewSnapshot, serializeReviewSnapshot } from "../capabilities/review-storage";
|
|
6
6
|
import { type CapabilityActionReviewPresentation, CapabilityActionReviewPresentationSchema } from "../contracts/capabilities";
|
|
7
|
+
import { sql } from "../runtime/clients";
|
|
7
8
|
import { logger } from "../services/logging";
|
|
8
9
|
import { toPgTextArray } from "../services/postgres";
|
|
9
10
|
import { AI_TOOL_CHECK_STALE_MS, type AiActionCheck, type AiStoredActionReview } from "./action-review";
|
package/src/ai/tool-audit.ts
CHANGED
package/src/ai/turn-timing.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LoopAggregate, OutboundEvent } from "@k2b/nessi";
|
|
2
|
-
import { sql } from "
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
3
|
|
|
4
4
|
export type TimingInterval = { start: number; end: number };
|
|
5
5
|
const union = (intervals: TimingInterval[]): TimingInterval[] => {
|
package/src/ai/usage.ts
CHANGED
package/src/ai/web-provenance.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { domainToUnicode } from "node:url";
|
|
2
|
-
import { sql } from "
|
|
2
|
+
import { sql } from "../runtime/clients";
|
|
3
|
+
|
|
3
4
|
import { toPgTextArray } from "../services/postgres";
|
|
4
5
|
|
|
5
6
|
/** The longest address web_extract and fetch_file accept; a longer one can never be read, so it is never recorded. */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { sql } from "bun";
|
|
2
1
|
import { Hono, type MiddlewareHandler } from "hono";
|
|
3
2
|
import { AiBackgroundCostError, backgroundCostState, releaseBackgroundCostStop } from "../ai/inference-calls";
|
|
4
3
|
import { quotaAdminConfig, quotaReport } from "../ai/quota-report";
|
|
5
4
|
import { AiQuotaError, aiQuotas } from "../ai/quotas";
|
|
6
5
|
import { readAiSettingsState } from "../ai/settings";
|
|
6
|
+
import { sql } from "../runtime/clients";
|
|
7
7
|
import { type AuthContext, auth, v } from "../server";
|
|
8
8
|
import { hasBillableAiPricing } from "../shared/ai-costs";
|
|
9
9
|
import {
|