@ultrst-armada/kloks 2.2.4 → 2.2.6

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.
Files changed (80) hide show
  1. package/.krusbl-release-attestation.json +8 -0
  2. package/package.json +7 -2
  3. package/packages/aiko/dist/index.d.ts +37 -1
  4. package/packages/aiko/dist/index.js +101 -3
  5. package/packages/backend/dist/ai-inference/index.js +1 -1
  6. package/packages/backend/dist/ai-inference/inferenceExecutor.test.d.ts +1 -0
  7. package/packages/backend/dist/ai-models/index.js +2 -2
  8. package/packages/backend/dist/ai-routing/index.js +3 -3
  9. package/packages/backend/dist/auth/OidcBff.d.ts +50 -0
  10. package/packages/backend/dist/auth/OidcBff.test.d.ts +1 -0
  11. package/packages/backend/dist/auth/OidcBffEnv.d.ts +23 -0
  12. package/packages/backend/dist/auth/index.d.ts +2 -0
  13. package/packages/backend/dist/auth/index.js +6 -1
  14. package/packages/backend/dist/{chunk-F6CHRGJ6.js → chunk-2DVRZKOK.js} +2 -2
  15. package/packages/backend/dist/{chunk-YZNQA3FU.js → chunk-3V5B2BOP.js} +1 -1
  16. package/packages/backend/dist/{chunk-UVNKDM7N.js → chunk-4BCTI7BL.js} +1 -1
  17. package/packages/backend/dist/{chunk-WPN3SMIT.js → chunk-4LRMJIJ4.js} +1 -1
  18. package/packages/backend/dist/{chunk-DMBDZHJF.js → chunk-4NTZRTRY.js} +1 -1
  19. package/packages/backend/dist/{chunk-X57LLCAQ.js → chunk-5S5CDQXD.js} +5 -1
  20. package/packages/backend/dist/{chunk-PECE5QKV.js → chunk-5SKQBVYU.js} +2 -2
  21. package/packages/backend/dist/{chunk-NIP22V2G.js → chunk-E2I7D52V.js} +22 -1
  22. package/packages/backend/dist/chunk-FFYTCLFC.js +93 -0
  23. package/packages/backend/dist/{chunk-SR3DALCH.js → chunk-FGZA6PDX.js} +4 -4
  24. package/packages/backend/dist/{chunk-7RSTNQT2.js → chunk-H47NEPYG.js} +7 -7
  25. package/packages/backend/dist/{chunk-5E6JRFUH.js → chunk-HX5TN27Y.js} +294 -4
  26. package/packages/backend/dist/{chunk-PT6J6UEU.js → chunk-LMAU62ZG.js} +4 -4
  27. package/packages/backend/dist/{chunk-FKK23J2A.js → chunk-LN274IE5.js} +63 -12
  28. package/packages/backend/dist/{chunk-GCTQY24J.js → chunk-MK4ZRBFI.js} +7 -6
  29. package/packages/backend/dist/{chunk-K5LKAEBJ.js → chunk-OJCSPAFE.js} +1 -1
  30. package/packages/backend/dist/chunk-SEKPSCWP.js +350 -0
  31. package/packages/backend/dist/{chunk-N7OUR5R5.js → chunk-YDGW7PXM.js} +1 -1
  32. package/packages/backend/dist/{chunk-KQ6IWV3F.js → chunk-YTJTF7LS.js} +2 -2
  33. package/packages/backend/dist/client/index.js +2 -2
  34. package/packages/backend/dist/{client-5SGUJCV5.js → client-S4R4MZ6K.js} +2 -2
  35. package/packages/backend/dist/connectivity/FrontendSession.d.ts +1 -0
  36. package/packages/backend/dist/connectivity/FrontendSession.dispose.test.d.ts +1 -0
  37. package/packages/backend/dist/connectivity/HTTPTransport.d.ts +1 -0
  38. package/packages/backend/dist/connectivity/HTTPTransport.operation.test.d.ts +1 -0
  39. package/packages/backend/dist/connectivity/InProcessExecutor.session.test.d.ts +1 -0
  40. package/packages/backend/dist/connectivity/RemoteExecutor.error.test.d.ts +1 -0
  41. package/packages/backend/dist/connectivity/facadeInvocation.adversarial_replay.test.d.ts +1 -0
  42. package/packages/backend/dist/connectivity/facadeInvocation.d.ts +101 -0
  43. package/packages/backend/dist/connectivity/facadeInvocation.oneUseLuthContract.test.d.ts +1 -0
  44. package/packages/backend/dist/connectivity/facadeInvocation.test.d.ts +1 -0
  45. package/packages/backend/dist/connectivity/index.d.ts +2 -0
  46. package/packages/backend/dist/connectivity/index.js +8 -4
  47. package/packages/backend/dist/index.js +26 -14
  48. package/packages/backend/dist/krnl-ai-services.js +6 -6
  49. package/packages/backend/dist/krnl-services.js +2 -2
  50. package/packages/backend/dist/node.js +66 -57
  51. package/packages/backend/dist/provider-services/compute-operations.d.ts +24 -0
  52. package/packages/backend/dist/provider-services/compute-operations.test.d.ts +1 -0
  53. package/packages/backend/dist/provider-services/google/cloud-run.js +1 -1
  54. package/packages/backend/dist/provider-services/google/cloud-shell.js +1 -1
  55. package/packages/backend/dist/provider-services/google/cloud-storage.js +1 -1
  56. package/packages/backend/dist/provider-services/google/drive.js +1 -1
  57. package/packages/backend/dist/provider-services/google/gemini.js +3 -3
  58. package/packages/backend/dist/provider-services/google/index.js +3 -3
  59. package/packages/backend/dist/provider-services/google/vertex-ai.js +1 -1
  60. package/packages/backend/dist/provider-services/index.d.ts +1 -0
  61. package/packages/backend/dist/provider-services/index.js +19 -11
  62. package/packages/backend/dist/provider-services/node.js +11 -11
  63. package/packages/backend/dist/provider-services/storage/dropbox.js +4 -4
  64. package/packages/backend/dist/provider-services/storage/github.js +4 -4
  65. package/packages/backend/dist/provider-services/storage/node.js +7 -7
  66. package/packages/backend/dist/provider-services/storage.js +6 -6
  67. package/packages/backend/package.json +1 -1
  68. package/packages/client/dist/auth.d.ts +1 -1
  69. package/packages/client/dist/auth.js +5 -1
  70. package/packages/client/dist/{chunk-ATLIA7AJ.js → chunk-WYC7RG32.js} +5 -1
  71. package/packages/client/dist/index.d.ts +1 -1
  72. package/packages/client/dist/index.js +5 -1
  73. package/packages/client/package.json +1 -1
  74. package/packages/state-graph/dist/browser.js +24 -24
  75. package/packages/state-graph/dist/index.js +24 -24
  76. package/packages/backend/dist/chunk-5SXOQAAX.js +0 -41
  77. package/packages/backend/dist/chunk-JQKKMUCT.js +0 -0
  78. package/packages/backend/dist/{chunk-R4B3KPHY.js → chunk-5CZUAEAD.js} +5 -5
  79. package/packages/backend/dist/{chunk-LMWXONZG.js → chunk-EREYT3WJ.js} +3 -3
  80. package/packages/state-graph/dist/{chunk-UKTICGGV.js → chunk-YUJC367F.js} +3 -3
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  failoverExecutionEngine
3
- } from "./chunk-PT6J6UEU.js";
3
+ } from "./chunk-LMAU62ZG.js";
4
4
  import {
5
- modelCatalog
6
- } from "./chunk-LMWXONZG.js";
5
+ aiProviderService
6
+ } from "./chunk-SLR6SIEU.js";
7
7
  import {
8
8
  toolManagerService
9
9
  } from "./chunk-U4HUGPRH.js";
10
10
  import {
11
11
  inferenceExecutor
12
- } from "./chunk-GCTQY24J.js";
12
+ } from "./chunk-MK4ZRBFI.js";
13
+ import {
14
+ modelCatalog
15
+ } from "./chunk-EREYT3WJ.js";
13
16
  import {
14
17
  keyStore
15
18
  } from "./chunk-P7H6TIEA.js";
16
- import {
17
- aiProviderService
18
- } from "./chunk-SLR6SIEU.js";
19
19
 
20
20
  // src/krnl-ai-services.ts
21
21
  import {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CallbackRegistry,
3
3
  EventBus
4
- } from "./chunk-NIP22V2G.js";
4
+ } from "./chunk-E2I7D52V.js";
5
5
 
6
6
  // src/connectivity/BackendContract.ts
7
7
  function createEmptyContract(version = "1.0.0") {
@@ -676,6 +676,9 @@ var InProcessExecutor = class {
676
676
  }
677
677
  async delegate(delegation) {
678
678
  if (delegation.callbackHandle) {
679
+ if (typeof delegation.sessionId !== "string" || !delegation.sessionId.trim()) {
680
+ throw new Error("[InProcessExecutor] Delegated callback requires caller session identity.");
681
+ }
679
682
  return await this.callbackRegistry.invoke(
680
683
  delegation.callbackHandle,
681
684
  [delegation.payload],
@@ -716,9 +719,9 @@ var RemoteExecutor = class {
716
719
  initCallbackListener() {
717
720
  this.transport.onMessage(async (msg) => {
718
721
  if (msg.type === "CALLBACK_REQUEST" && msg.payload) {
719
- const { handle, args } = msg.payload;
722
+ const { handle: handle2, args } = msg.payload;
720
723
  try {
721
- const result = await this.callbackRegistry.invoke(handle, args, this.sessionId);
724
+ const result = await this.callbackRegistry.invoke(handle2, args, this.sessionId);
722
725
  await this.transport.send({
723
726
  id: `cb-res-${Date.now()}`,
724
727
  type: "CALLBACK_RESULT",
@@ -783,11 +786,17 @@ var RemoteExecutor = class {
783
786
  async delegate(delegation) {
784
787
  const msg = this.prepareMessage("COMMAND", `${delegation.target}.${delegation.operation}`, delegation);
785
788
  const res = await this.transport.request(msg);
789
+ if (res.type === "ERROR") {
790
+ throw new Error(res.error?.message || `Delegation "${delegation.target}.${delegation.operation}" failed.`);
791
+ }
786
792
  return res.payload;
787
793
  }
788
794
  async submitJob(job) {
789
795
  const msg = this.prepareMessage("JOB_SUBMIT", `jobs.submit`, job);
790
796
  const res = await this.transport.request(msg);
797
+ if (res.type === "ERROR") {
798
+ throw new Error(res.error?.message || "Remote job submission failed.");
799
+ }
791
800
  return res.payload;
792
801
  }
793
802
  getSessionId() {
@@ -801,6 +810,285 @@ var RemoteExecutor = class {
801
810
  }
802
811
  };
803
812
 
813
+ // src/connectivity/facadeInvocation.ts
814
+ var FacadeInvocationDenied = class extends Error {
815
+ constructor(code, status = 403) {
816
+ super(code);
817
+ this.code = code;
818
+ this.status = status;
819
+ this.name = "FacadeInvocationDenied";
820
+ }
821
+ code;
822
+ status;
823
+ };
824
+ var handle = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
825
+ var validId = (value) => typeof value === "string" && handle.test(value) && !value.includes("..") && !value.includes("__proto__") && !value.includes("constructor") && !value.includes("prototype");
826
+ var own = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
827
+ var fail = (code, status = 403) => {
828
+ throw new FacadeInvocationDenied(code, status);
829
+ };
830
+ function assertInvocation(request) {
831
+ if (!request || typeof request !== "object" || Array.isArray(request)) fail("MALFORMED_HANDLE", 400);
832
+ if (Object.keys(request).some((key) => !["operationId", "version", "targetWorkspaceId", "invocationId", "input"].includes(key))) fail("UNTRUSTED_CLAIMS", 400);
833
+ if (![request.operationId, request.version, request.targetWorkspaceId, request.invocationId].every(validId)) fail("MALFORMED_HANDLE", 400);
834
+ if (!own(request, "input")) fail("MALFORMED_INPUT", 400);
835
+ }
836
+ function assertDescriptor(operation) {
837
+ if (!operation || !validId(operation.id) || !validId(operation.version) || !validId(operation.targetWorkspaceId) || typeof operation.name !== "string" || operation.name.length > 160) return false;
838
+ if (operation.kind === "static") return validId(operation.serviceId) && validId(operation.serviceOperation);
839
+ return operation.kind === "workflow" && validId(operation.workflowId);
840
+ }
841
+ function sameCallerIdentity(before, after) {
842
+ return before.principalId === after.principalId && before.sessionId === after.sessionId && before.sourceAppId === after.sourceAppId && before.sourceWorkspaceId === after.sourceWorkspaceId && before.audience === after.audience && before.invoker.kind === after.invoker.kind && before.invoker.id === after.invoker.id && before.depth === after.depth && before.chain.length === after.chain.length && before.chain.every((id, index) => id === after.chain[index]);
843
+ }
844
+ function sameDispatchReference(before, after) {
845
+ return before.id === after.id && before.version === after.version && before.targetWorkspaceId === after.targetWorkspaceId && before.kind === after.kind && (before.kind === "workflow" ? before.workflowId === after.workflowId : before.serviceId === after.serviceId && before.serviceOperation === after.serviceOperation);
846
+ }
847
+ function parseJson(body) {
848
+ return body.json().catch(() => fail("MALFORMED_JSON", 400));
849
+ }
850
+ function createFacadeInvocationBoundary(options) {
851
+ if (!validId(options.targetAppId)) throw new Error("Invalid target application identity");
852
+ for (const name of [
853
+ "verifyLuthCredential",
854
+ "revalidateLuthCaller",
855
+ "listCurrentOperations",
856
+ "authorize",
857
+ "deploymentEligible",
858
+ "consumeInvocation",
859
+ "invokePublishedWorkflow",
860
+ "delegateCredential"
861
+ ]) {
862
+ if (typeof options[name] !== "function") throw new Error(`Missing required facade authority: ${name}`);
863
+ }
864
+ async function callerFor(credential) {
865
+ if (!credential || typeof credential !== "string") fail("AUTH_REQUIRED", 401);
866
+ const caller = await options.verifyLuthCredential(credential, options.targetAppId);
867
+ if (!caller || !validId(caller.principalId) || !validId(caller.sourceAppId) || !validId(caller.sourceWorkspaceId) || !validId(caller.sessionId) || caller.audience !== options.targetAppId || !validId(caller.invoker?.id) || !["user", "app-agent", "endpoint-agent", "workflow-agent"].includes(caller.invoker.kind) || !Array.isArray(caller.chain) || caller.chain.length < 1 || caller.chain.some((id) => !validId(id)) || !Number.isSafeInteger(caller.depth) || caller.depth < 0 || !Number.isSafeInteger(caller.maxDepth) || caller.maxDepth < 1 || !Number.isSafeInteger(caller.remainingCalls) || caller.remainingCalls < 1 || !Number.isFinite(caller.deadlineAt) || !Number.isFinite(caller.expiresAt) || caller.expiresAt <= Date.now()) fail("AUTH_INVALID", 401);
868
+ if (caller.chain.includes(options.targetAppId) && caller.chain.at(-1) !== options.targetAppId) fail("APP_CYCLE");
869
+ if (caller.depth >= caller.maxDepth) fail("DEPTH_EXCEEDED", 429);
870
+ if (Date.now() >= caller.deadlineAt) fail("DEADLINE_EXCEEDED", 408);
871
+ return caller;
872
+ }
873
+ async function discover(credential, workspaceId, transport) {
874
+ const caller = await callerFor(credential);
875
+ if (!validId(workspaceId)) fail("INVALID_WORKSPACE", 400);
876
+ const rows = await options.listCurrentOperations(workspaceId);
877
+ const visible = [];
878
+ for (const op of rows) {
879
+ if (!assertDescriptor(op) || op.targetWorkspaceId !== workspaceId) continue;
880
+ const decision = { caller, operation: op, transport };
881
+ if (!await options.deploymentEligible(decision) || !await options.authorize(decision, "discover")) continue;
882
+ visible.push({ id: op.id, version: op.version, name: op.name, kind: op.kind, targetWorkspaceId: op.targetWorkspaceId });
883
+ }
884
+ return visible;
885
+ }
886
+ async function invoke(credential, request, transport, parentSignal) {
887
+ assertInvocation(request);
888
+ const verified = await callerFor(credential);
889
+ const caller = {
890
+ ...verified,
891
+ invoker: { ...verified.invoker },
892
+ chain: [...verified.chain]
893
+ };
894
+ const current = await options.listCurrentOperations(request.targetWorkspaceId);
895
+ const operation = current.find((op) => assertDescriptor(op) && op.id === request.operationId && op.targetWorkspaceId === request.targetWorkspaceId && op.version === request.version);
896
+ if (!operation) fail("OPERATION_UNAVAILABLE", 404);
897
+ const decision = { caller, operation, transport };
898
+ if (!await options.deploymentEligible(decision)) fail("DEPLOYMENT_UNAVAILABLE", 503);
899
+ if (!await options.authorize(decision, "invoke", request.input)) fail("ACCESS_DENIED");
900
+ if (!await options.consumeInvocation(caller, request.invocationId)) fail("REPLAY_OR_BUDGET_EXHAUSTED", 409);
901
+ const controller = new AbortController();
902
+ const deadline = Math.min(caller.deadlineAt, caller.expiresAt, Date.now() + 3e4);
903
+ const remaining = deadline - Date.now();
904
+ if (remaining <= 0) fail("DEADLINE_EXCEEDED", 408);
905
+ const abort = () => controller.abort();
906
+ parentSignal?.addEventListener("abort", abort, { once: true });
907
+ if (parentSignal?.aborted) controller.abort();
908
+ let timer;
909
+ let timedOut = false;
910
+ const abortError = () => new FacadeInvocationDenied(timedOut ? "DEADLINE_EXCEEDED" : "CANCELLED", 408);
911
+ try {
912
+ const stopped = new Promise((_, reject) => {
913
+ controller.signal.addEventListener("abort", () => reject(abortError()), { once: true });
914
+ timer = setTimeout(() => {
915
+ timedOut = true;
916
+ controller.abort();
917
+ }, remaining);
918
+ if (controller.signal.aborted) reject(abortError());
919
+ });
920
+ const work = async () => {
921
+ if (operation.kind === "workflow") {
922
+ return options.invokePublishedWorkflow({ workspaceId: operation.targetWorkspaceId, workflowId: operation.workflowId, version: operation.version }, request.input, controller.signal);
923
+ }
924
+ const services = options.facade.services;
925
+ if (!own(services, operation.serviceId)) fail("OPERATION_UNAVAILABLE", 404);
926
+ const service = services[operation.serviceId];
927
+ if (typeof service?.execute !== "function") fail("OPERATION_UNAVAILABLE", 404);
928
+ return service.execute(operation.serviceOperation, request.input, { signal: controller.signal, transport });
929
+ };
930
+ const output = await Promise.race([work(), stopped]);
931
+ const currentCaller = await options.revalidateLuthCaller(caller, options.targetAppId);
932
+ if (!currentCaller || !currentCaller.invoker || !Array.isArray(currentCaller.chain) || !Number.isFinite(currentCaller.expiresAt) || currentCaller.expiresAt <= Date.now() || !Number.isFinite(currentCaller.deadlineAt) || currentCaller.deadlineAt <= Date.now() || currentCaller.audience !== options.targetAppId) fail("AUTH_INVALID", 401);
933
+ if (!sameCallerIdentity(caller, currentCaller)) fail("CALLER_CHANGED", 401);
934
+ const currentOperations = await options.listCurrentOperations(request.targetWorkspaceId);
935
+ if (!currentOperations.some((op) => assertDescriptor(op) && sameDispatchReference(operation, op))) {
936
+ fail("OPERATION_REVOKED", 403);
937
+ }
938
+ const currentDecision = { caller: currentCaller, operation, transport };
939
+ if (!await options.deploymentEligible(currentDecision)) fail("DEPLOYMENT_UNAVAILABLE", 503);
940
+ if (!await options.authorize(currentDecision, "output", output)) fail("ACCESS_REVOKED");
941
+ if (controller.signal.aborted) throw abortError();
942
+ return { output, replyTo: { ...currentCaller.invoker }, invocationId: request.invocationId };
943
+ } finally {
944
+ if (timer) clearTimeout(timer);
945
+ parentSignal?.removeEventListener("abort", abort);
946
+ controller.abort();
947
+ }
948
+ }
949
+ async function delegate(credential, targetAppId, request, dispatch, signal) {
950
+ assertInvocation(request);
951
+ const caller = await callerFor(credential);
952
+ if (!validId(targetAppId)) fail("INVALID_TARGET", 400);
953
+ if (caller.chain.includes(targetAppId) && caller.chain.at(-1) !== targetAppId) fail("APP_CYCLE");
954
+ if (caller.depth + 1 >= caller.maxDepth || caller.remainingCalls <= 1) fail("BUDGET_EXCEEDED", 429);
955
+ const controller = new AbortController();
956
+ let timer;
957
+ let timedOut = false;
958
+ const abortError = () => new FacadeInvocationDenied(timedOut ? "DEADLINE_EXCEEDED" : "CANCELLED", 408);
959
+ const abort = () => controller.abort();
960
+ signal?.addEventListener("abort", abort, { once: true });
961
+ if (signal?.aborted) controller.abort();
962
+ try {
963
+ const remaining = Math.min(caller.deadlineAt, caller.expiresAt, Date.now() + 3e4) - Date.now();
964
+ if (remaining <= 0) fail("DEADLINE_EXCEEDED", 408);
965
+ const stopped = new Promise((_, reject) => {
966
+ controller.signal.addEventListener("abort", () => reject(abortError()), { once: true });
967
+ timer = setTimeout(() => {
968
+ timedOut = true;
969
+ controller.abort();
970
+ }, remaining);
971
+ if (controller.signal.aborted) reject(abortError());
972
+ });
973
+ const forward = async () => {
974
+ if (controller.signal.aborted) throw abortError();
975
+ const delegated = await options.delegateCredential(caller, targetAppId, request.invocationId, controller.signal);
976
+ if (controller.signal.aborted) throw abortError();
977
+ if (!delegated) fail("DELEGATION_DENIED");
978
+ return dispatch(delegated, request, controller.signal);
979
+ };
980
+ return await Promise.race([forward(), stopped]);
981
+ } finally {
982
+ if (timer) clearTimeout(timer);
983
+ signal?.removeEventListener("abort", abort);
984
+ controller.abort();
985
+ }
986
+ }
987
+ const bearer = (request) => {
988
+ const value = request.headers.get("Authorization");
989
+ const match = /^Bearer ([^\s]+)$/.exec(value ?? "");
990
+ if (!match) fail("AUTH_REQUIRED", 401);
991
+ return match[1];
992
+ };
993
+ const errorResponse = (error) => {
994
+ const denied = error instanceof FacadeInvocationDenied ? error : new FacadeInvocationDenied("INTERNAL_ERROR", 500);
995
+ return Response.json({ error: denied.code }, { status: denied.status, headers: { "Cache-Control": "no-store" } });
996
+ };
997
+ async function http(request) {
998
+ try {
999
+ const path = new URL(request.url).pathname;
1000
+ const credential = bearer(request);
1001
+ if (path === "/api/crossapp/operations" && request.method === "GET") {
1002
+ return Response.json({ operations: await discover(credential, new URL(request.url).searchParams.get("workspace") ?? "", "http") }, { headers: { "Cache-Control": "no-store" } });
1003
+ }
1004
+ if (path === "/api/crossapp/invoke" && request.method === "POST") {
1005
+ return Response.json(await invoke(credential, await parseJson(request), "http", request.signal), { headers: { "Cache-Control": "no-store" } });
1006
+ }
1007
+ return errorResponse(new FacadeInvocationDenied("NOT_FOUND", 404));
1008
+ } catch (error) {
1009
+ return errorResponse(error);
1010
+ }
1011
+ }
1012
+ async function mcp(request) {
1013
+ let id = null;
1014
+ try {
1015
+ const credential = bearer(request);
1016
+ const body = await parseJson(request);
1017
+ if (!body || typeof body !== "object" || Array.isArray(body) || body.jsonrpc !== "2.0" || typeof body.method !== "string") fail("INVALID_MCP_REQUEST", 400);
1018
+ id = body.id ?? null;
1019
+ if (body.method !== "tools/list" && body.method !== "tools/call") await callerFor(credential);
1020
+ if (body.method === "notifications/initialized" && body.id === void 0) {
1021
+ return new Response(null, { status: 202 });
1022
+ }
1023
+ if (body.id === void 0 || typeof body.id !== "string" && typeof body.id !== "number") {
1024
+ fail("INVALID_MCP_REQUEST", 400);
1025
+ }
1026
+ if (body.method === "initialize") {
1027
+ return Response.json({ jsonrpc: "2.0", id, result: {
1028
+ protocolVersion: "2025-06-18",
1029
+ capabilities: { tools: { listChanged: false } },
1030
+ serverInfo: { name: "kloks-backend-facade", version: "1.0.0" }
1031
+ } }, { headers: { "Cache-Control": "no-store" } });
1032
+ }
1033
+ if (body.method === "tools/list") {
1034
+ const workspace = body.params?.workspaceId;
1035
+ if (typeof workspace !== "string") throw new FacadeInvocationDenied("INVALID_WORKSPACE", 400);
1036
+ const operations = await discover(credential, workspace, "mcp");
1037
+ return Response.json({ jsonrpc: "2.0", id, result: { tools: operations.map((op) => ({
1038
+ name: op.id,
1039
+ description: op.name,
1040
+ inputSchema: {
1041
+ type: "object",
1042
+ properties: {
1043
+ version: { type: "string", const: op.version },
1044
+ targetWorkspaceId: { type: "string", const: op.targetWorkspaceId },
1045
+ invocationId: { type: "string", minLength: 1, maxLength: 128 },
1046
+ input: {}
1047
+ },
1048
+ required: ["version", "targetWorkspaceId", "invocationId", "input"],
1049
+ additionalProperties: false
1050
+ },
1051
+ _meta: { version: op.version, targetWorkspaceId: op.targetWorkspaceId }
1052
+ })) } }, { headers: { "Cache-Control": "no-store" } });
1053
+ }
1054
+ if (body.method === "tools/call") {
1055
+ const params = body.params;
1056
+ let invocation;
1057
+ if (typeof params?.name === "string") {
1058
+ const args = params.arguments;
1059
+ if (!args || typeof args !== "object" || Array.isArray(args) || Object.keys(args).some((key) => !["version", "targetWorkspaceId", "invocationId", "input"].includes(key)) || own(params, "invocation")) fail("INVALID_MCP_REQUEST", 400);
1060
+ const values = args;
1061
+ invocation = {
1062
+ operationId: params.name,
1063
+ version: values.version,
1064
+ targetWorkspaceId: values.targetWorkspaceId,
1065
+ invocationId: values.invocationId,
1066
+ input: values.input
1067
+ };
1068
+ } else {
1069
+ invocation = params?.invocation;
1070
+ }
1071
+ const result = await invoke(credential, invocation, "mcp", request.signal);
1072
+ const output = result.output ?? null;
1073
+ const structuredContent = output && typeof output === "object" && !Array.isArray(output) ? output : { value: output };
1074
+ return Response.json({ jsonrpc: "2.0", id, result: {
1075
+ content: [{ type: "text", text: JSON.stringify(output) }],
1076
+ structuredContent,
1077
+ isError: false
1078
+ } }, { headers: { "Cache-Control": "no-store" } });
1079
+ }
1080
+ return Response.json({ jsonrpc: "2.0", id, error: { code: -32601, message: "Method not found" } }, { status: 404 });
1081
+ } catch (error) {
1082
+ const denied = error instanceof FacadeInvocationDenied ? error : new FacadeInvocationDenied("INTERNAL_ERROR", 500);
1083
+ return Response.json(
1084
+ { jsonrpc: "2.0", id, error: { code: denied.status, message: denied.code } },
1085
+ { status: denied.status, headers: { "Cache-Control": "no-store" } }
1086
+ );
1087
+ }
1088
+ }
1089
+ return { discover, invoke, delegate, http, mcp };
1090
+ }
1091
+
804
1092
  export {
805
1093
  createEmptyContract,
806
1094
  BackendRegistry,
@@ -812,5 +1100,7 @@ export {
812
1100
  HealthMonitor,
813
1101
  LoadBalancer,
814
1102
  InProcessExecutor,
815
- RemoteExecutor
1103
+ RemoteExecutor,
1104
+ FacadeInvocationDenied,
1105
+ createFacadeInvocationBoundary
816
1106
  };
@@ -1,13 +1,13 @@
1
+ import {
2
+ aiProviderService
3
+ } from "./chunk-SLR6SIEU.js";
1
4
  import {
2
5
  modelCatalog,
3
6
  modelHealthService
4
- } from "./chunk-LMWXONZG.js";
7
+ } from "./chunk-EREYT3WJ.js";
5
8
  import {
6
9
  keyStore
7
10
  } from "./chunk-P7H6TIEA.js";
8
- import {
9
- aiProviderService
10
- } from "./chunk-SLR6SIEU.js";
11
11
 
12
12
  // src/ai-routing/metricsLogger.ts
13
13
  var MetricsLogger = class {
@@ -12,6 +12,19 @@ var definitions = [
12
12
  usageImplemented: true,
13
13
  docsUrl: "https://developers.cloudflare.com/api/"
14
14
  },
15
+ {
16
+ id: "cloudflare-containers",
17
+ parentId: "cloudflare",
18
+ name: "Cloudflare Containers (Workers Paid)",
19
+ category: "cloud",
20
+ status: "catalogued",
21
+ credentialModes: ["api-token"],
22
+ capabilities: ["containers"],
23
+ renewal: "monthly",
24
+ apiImplemented: false,
25
+ usageImplemented: false,
26
+ docsUrl: "https://developers.cloudflare.com/containers/"
27
+ },
15
28
  {
16
29
  id: "vercel",
17
30
  name: "Vercel",
@@ -24,6 +37,19 @@ var definitions = [
24
37
  usageImplemented: true,
25
38
  docsUrl: "https://vercel.com/docs/rest-api"
26
39
  },
40
+ {
41
+ id: "vercel-sandbox",
42
+ parentId: "vercel",
43
+ name: "Vercel Sandbox",
44
+ category: "cloud",
45
+ status: "catalogued",
46
+ credentialModes: ["api-token"],
47
+ capabilities: ["sandboxes"],
48
+ renewal: "monthly",
49
+ apiImplemented: false,
50
+ usageImplemented: false,
51
+ docsUrl: "https://vercel.com/docs/vercel-sandbox"
52
+ },
27
53
  {
28
54
  id: "google",
29
55
  name: "Google",
@@ -68,11 +94,11 @@ var definitions = [
68
94
  parentId: "google",
69
95
  name: "Google Cloud Run",
70
96
  category: "cloud",
71
- status: "catalogued",
97
+ status: "ready",
72
98
  credentialModes: ["oauth2"],
73
- capabilities: ["services", "deployments"],
99
+ capabilities: ["list-services"],
74
100
  renewal: "monthly",
75
- apiImplemented: false,
101
+ apiImplemented: true,
76
102
  usageImplemented: false,
77
103
  docsUrl: "https://cloud.google.com/run/docs"
78
104
  },
@@ -215,11 +241,11 @@ var definitions = [
215
241
  id: "render",
216
242
  name: "Render",
217
243
  category: "deployment",
218
- status: "catalogued",
244
+ status: "ready",
219
245
  credentialModes: ["api-key"],
220
- capabilities: ["services", "deployments"],
246
+ capabilities: ["list-services"],
221
247
  renewal: "monthly",
222
- apiImplemented: false,
248
+ apiImplemented: true,
223
249
  usageImplemented: false,
224
250
  docsUrl: "https://render.com/docs/free"
225
251
  },
@@ -227,13 +253,38 @@ var definitions = [
227
253
  id: "railway",
228
254
  name: "Railway",
229
255
  category: "deployment",
256
+ status: "ready",
257
+ credentialModes: ["api-token"],
258
+ capabilities: ["account-identity"],
259
+ renewal: "monthly",
260
+ apiImplemented: true,
261
+ usageImplemented: false,
262
+ docsUrl: "https://docs.railway.com/pricing/plans"
263
+ },
264
+ {
265
+ id: "koyeb",
266
+ name: "Koyeb Free Instance",
267
+ category: "cloud",
230
268
  status: "catalogued",
231
269
  credentialModes: ["api-token"],
232
- capabilities: ["projects", "deployments"],
270
+ capabilities: ["instances", "services"],
271
+ renewal: "ongoing",
272
+ apiImplemented: false,
273
+ usageImplemented: false,
274
+ docsUrl: "https://www.koyeb.com/docs"
275
+ },
276
+ {
277
+ id: "google-compute-engine",
278
+ parentId: "google",
279
+ name: "Google Compute Engine",
280
+ category: "cloud",
281
+ status: "catalogued",
282
+ credentialModes: ["oauth2"],
283
+ capabilities: ["instances"],
233
284
  renewal: "monthly",
234
285
  apiImplemented: false,
235
286
  usageImplemented: false,
236
- docsUrl: "https://docs.railway.com/pricing/plans"
287
+ docsUrl: "https://cloud.google.com/compute/docs"
237
288
  },
238
289
  {
239
290
  id: "oracle-cloud",
@@ -261,13 +312,13 @@ var definitions = [
261
312
  },
262
313
  {
263
314
  id: "fly",
264
- name: "Fly.io (one-time trial)",
315
+ name: "Fly.io (nonrenewable trial)",
265
316
  category: "cloud",
266
- status: "excluded",
317
+ status: "ready",
267
318
  credentialModes: ["api-token"],
268
- capabilities: ["machines"],
319
+ capabilities: ["list-apps"],
269
320
  renewal: "trial",
270
- apiImplemented: false,
321
+ apiImplemented: true,
271
322
  usageImplemented: false,
272
323
  docsUrl: "https://fly.io/docs/about/free-trial/"
273
324
  },
@@ -77,7 +77,7 @@ var PROVIDER_BASE_URLS = {
77
77
  };
78
78
  async function executeGoogleInference(modelId, apiKey, prompt, options) {
79
79
  const normModel = modelId.startsWith("models/") ? modelId.replace("models/", "") : modelId;
80
- const url = `https://generativelanguage.googleapis.com/v1beta/models/${normModel}:generateContent?key=${apiKey}`;
80
+ const url = `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(normModel)}:generateContent`;
81
81
  const reqBody = {
82
82
  contents: [{ parts: [{ text: prompt }] }]
83
83
  };
@@ -92,7 +92,7 @@ async function executeGoogleInference(modelId, apiKey, prompt, options) {
92
92
  }
93
93
  const res = await fetch(url, {
94
94
  method: "POST",
95
- headers: { "Content-Type": "application/json" },
95
+ headers: { "Content-Type": "application/json", "x-goog-api-key": apiKey.trim() },
96
96
  body: JSON.stringify(reqBody),
97
97
  signal: options?.signal
98
98
  });
@@ -118,15 +118,16 @@ async function executeGoogleInference(modelId, apiKey, prompt, options) {
118
118
  async function performInference(providerId, modelId, apiKey, prompt, options) {
119
119
  const start = Date.now();
120
120
  const normModel = modelId.startsWith("models/") ? modelId.replace("models/", "") : modelId;
121
+ if (!apiKey || !apiKey.trim()) {
122
+ throw new Error(`[${providerId.toUpperCase()} AUTH]: Missing API key for ${providerId}`);
123
+ }
121
124
  if (providerId === "google") {
122
125
  const res2 = await executeGoogleInference(normModel, apiKey, prompt, options);
123
126
  res2.durationMs = Date.now() - start;
124
127
  return res2;
125
128
  }
126
- if (!apiKey || apiKey.trim().length === 0) {
127
- throw new Error(`[${providerId.toUpperCase()} AUTH]: Missing API key for ${providerId}`);
128
- }
129
- const baseUrl = PROVIDER_BASE_URLS[providerId] || "https://api.groq.com/openai/v1";
129
+ const baseUrl = Object.hasOwn(PROVIDER_BASE_URLS, providerId) ? PROVIDER_BASE_URLS[providerId] : void 0;
130
+ if (!baseUrl) throw new Error(`Unsupported AI inference provider: ${providerId}`);
130
131
  const reqBody = {
131
132
  model: normModel,
132
133
  messages: options?.messages || [{ role: "user", content: prompt }],
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createCanonicalStorageService
3
- } from "./chunk-KQ6IWV3F.js";
3
+ } from "./chunk-YTJTF7LS.js";
4
4
 
5
5
  // src/provider-services/storage-node.ts
6
6
  import { createService, createServiceDefinition } from "@ultrst-armada/krnl";