@ultrst-armada/kloks 2.0.5 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/package.json +71 -1
  2. package/packages/backend/dist/{chunk-IRNQXVYA.js → chunk-23LS4LWC.js} +2 -2
  3. package/packages/backend/dist/chunk-3UZFKB4M.js +28 -0
  4. package/packages/backend/dist/chunk-5GW5PJWQ.js +96 -0
  5. package/packages/backend/dist/chunk-5SXOQAAX.js +41 -0
  6. package/packages/backend/dist/chunk-5UVJDX7Q.js +44 -0
  7. package/packages/backend/dist/chunk-6BL5DXFZ.js +43 -0
  8. package/packages/backend/dist/{chunk-Z2CT2MJ2.js → chunk-6I7I4C6H.js} +1 -1
  9. package/packages/backend/dist/{chunk-TRP76UR2.js → chunk-DJ457D5D.js} +1 -1
  10. package/packages/backend/dist/{chunk-WYEVA4RC.js → chunk-DTPCWHQJ.js} +1 -1
  11. package/packages/backend/dist/{chunk-XKUWLO2M.js → chunk-ENMIBY2V.js} +2 -2
  12. package/packages/backend/dist/chunk-EQFZX3JT.js +63 -0
  13. package/packages/backend/dist/chunk-FKK23J2A.js +363 -0
  14. package/packages/backend/dist/{chunk-BRNWUIH5.js → chunk-GTKW4IGC.js} +1 -1
  15. package/packages/backend/dist/chunk-HRJCGJTR.js +261 -0
  16. package/packages/backend/dist/chunk-IKDYKRVH.js +51 -0
  17. package/packages/backend/dist/chunk-JGR6BJVX.js +74 -0
  18. package/packages/backend/dist/chunk-NFK6YFTA.js +157 -0
  19. package/packages/backend/dist/chunk-NZWCPJDJ.js +82 -0
  20. package/packages/backend/dist/chunk-OT2PSPBK.js +74 -0
  21. package/packages/backend/dist/chunk-QYWVZBI6.js +54 -0
  22. package/packages/backend/dist/{chunk-ICVDGH2I.js → chunk-U7T65YUP.js} +5 -5
  23. package/packages/backend/dist/chunk-YFMHT77Z.js +58 -0
  24. package/packages/backend/dist/client-JXGCPWEA.js +7 -0
  25. package/packages/backend/dist/index.d.ts +1 -0
  26. package/packages/backend/dist/index.js +118 -9
  27. package/packages/backend/dist/krnl-services.js +6 -6
  28. package/packages/backend/dist/node.d.ts +1 -0
  29. package/packages/backend/dist/node.js +79 -43
  30. package/packages/backend/dist/provider-services/capacity.d.ts +2 -0
  31. package/packages/backend/dist/provider-services/client.d.ts +18 -0
  32. package/packages/backend/dist/provider-services/cloudflare.d.ts +6 -0
  33. package/packages/backend/dist/provider-services/facades.d.ts +44 -0
  34. package/packages/backend/dist/provider-services/gemini.d.ts +8 -0
  35. package/packages/backend/dist/provider-services/google/cloud-run.d.ts +1 -0
  36. package/packages/backend/dist/provider-services/google/cloud-run.js +9 -0
  37. package/packages/backend/dist/provider-services/google/cloud-shell.d.ts +1 -0
  38. package/packages/backend/dist/provider-services/google/cloud-shell.js +9 -0
  39. package/packages/backend/dist/provider-services/google/cloud-storage.d.ts +1 -0
  40. package/packages/backend/dist/provider-services/google/cloud-storage.js +9 -0
  41. package/packages/backend/dist/provider-services/google/drive.d.ts +4 -0
  42. package/packages/backend/dist/provider-services/google/drive.js +20 -0
  43. package/packages/backend/dist/provider-services/google/gemini.d.ts +2 -0
  44. package/packages/backend/dist/provider-services/google/gemini.js +10 -0
  45. package/packages/backend/dist/provider-services/google/index.d.ts +3 -0
  46. package/packages/backend/dist/provider-services/google/index.js +17 -0
  47. package/packages/backend/dist/provider-services/google/vertex-ai.d.ts +1 -0
  48. package/packages/backend/dist/provider-services/google/vertex-ai.js +9 -0
  49. package/packages/backend/dist/provider-services/index.d.ts +11 -0
  50. package/packages/backend/dist/provider-services/index.js +118 -0
  51. package/packages/backend/dist/provider-services/node.d.ts +4 -0
  52. package/packages/backend/dist/provider-services/node.js +40 -0
  53. package/packages/backend/dist/provider-services/operations.d.ts +28 -0
  54. package/packages/backend/dist/provider-services/operations.test.d.ts +1 -0
  55. package/packages/backend/dist/provider-services/provider-services.test.d.ts +1 -0
  56. package/packages/backend/dist/provider-services/registry.d.ts +16 -0
  57. package/packages/backend/dist/provider-services/storage/backblaze-b2.d.ts +7 -0
  58. package/packages/backend/dist/provider-services/storage/backblaze-b2.js +8 -0
  59. package/packages/backend/dist/provider-services/storage/contract.d.ts +45 -0
  60. package/packages/backend/dist/provider-services/storage/dropbox.d.ts +3 -0
  61. package/packages/backend/dist/provider-services/storage/dropbox.js +12 -0
  62. package/packages/backend/dist/provider-services/storage/github.d.ts +4 -0
  63. package/packages/backend/dist/provider-services/storage/github.js +12 -0
  64. package/packages/backend/dist/provider-services/storage/google-drive.d.ts +4 -0
  65. package/packages/backend/dist/provider-services/storage/index.d.ts +7 -0
  66. package/packages/backend/dist/provider-services/storage/node.d.ts +2 -0
  67. package/packages/backend/dist/provider-services/storage/node.js +17 -0
  68. package/packages/backend/dist/provider-services/storage/service.d.ts +27 -0
  69. package/packages/backend/dist/provider-services/storage/storage-contract.test.d.ts +1 -0
  70. package/packages/backend/dist/provider-services/storage-facades.d.ts +55 -0
  71. package/packages/backend/dist/provider-services/storage-node.d.ts +11 -0
  72. package/packages/backend/dist/provider-services/storage-providers.d.ts +30 -0
  73. package/packages/backend/dist/provider-services/storage-providers.test.d.ts +1 -0
  74. package/packages/backend/dist/provider-services/storage.d.ts +3 -0
  75. package/packages/backend/dist/provider-services/storage.js +29 -0
  76. package/packages/backend/dist/provider-services/types.d.ts +61 -0
  77. package/packages/backend/dist/provider-services/vercel.d.ts +13 -0
  78. package/packages/backend/dist/services/node.js +5 -5
  79. package/packages/backend/dist/srkl/index.js +4 -4
  80. package/packages/backend/dist/workspace/node.js +6 -6
  81. package/packages/backend/dist/{workspaceFileCore-UURQPP62.js → workspaceFileCore-RQO7YMRD.js} +3 -3
  82. package/packages/backend/package.json +71 -1
  83. package/packages/state-graph/dist/browser.js +16 -16
  84. package/packages/state-graph/dist/index.js +16 -16
  85. package/packages/backend/dist/{chunk-FSOOAU6G.js → chunk-TOLAWKAY.js} +4 -4
  86. package/packages/state-graph/dist/{chunk-YUJC367F.js → chunk-UKTICGGV.js} +3 -3
@@ -0,0 +1,74 @@
1
+ import {
2
+ UnsupportedStorageOperation,
3
+ normalizeStoragePath
4
+ } from "./chunk-5UVJDX7Q.js";
5
+ import {
6
+ b2DownloadFile,
7
+ b2ListBuckets,
8
+ b2ListFileNames,
9
+ b2UploadFile2 as b2UploadFile
10
+ } from "./chunk-I6T64MLT.js";
11
+
12
+ // src/provider-services/storage/backblaze-b2.ts
13
+ function createBackblazeB2StorageService(creds) {
14
+ if (!creds.keyId?.trim() || !creds.applicationKey?.trim())
15
+ throw new Error("Backblaze application key and key ID required");
16
+ const splitPath = (path) => {
17
+ const [bucket, ...rest] = normalizeStoragePath(path).split("/");
18
+ if (!bucket) throw new Error("Backblaze bucket is required");
19
+ return { bucket, file: rest.join("/") };
20
+ };
21
+ return {
22
+ providerId: "backblaze-b2",
23
+ capabilities: Object.freeze({ list: true, read: true, write: true, delete: false }),
24
+ async list(path = "", cursor) {
25
+ if (cursor) throw new Error("B2 native adapter does not provide continuation tokens");
26
+ if (!normalizeStoragePath(path)) {
27
+ const buckets = await b2ListBuckets(creds.keyId, creds.applicationKey);
28
+ return { entries: buckets.map((b) => ({
29
+ id: b.bucketId,
30
+ name: b.bucketName,
31
+ path: "/" + b.bucketName,
32
+ kind: "bucket"
33
+ })), nextCursor: null, complete: true };
34
+ }
35
+ const { bucket, file } = splitPath(path);
36
+ const items = await b2ListFileNames(creds.keyId, creds.applicationKey, bucket, file);
37
+ if (items.length >= 1e3)
38
+ throw new Error("B2 listing might be truncated; refusing to report an incomplete list");
39
+ return { entries: items.map((item) => ({
40
+ id: item.fileId,
41
+ name: item.fileName.split("/").pop() || item.fileName,
42
+ path: "/" + bucket + "/" + item.fileName,
43
+ kind: "file",
44
+ size: item.contentLength
45
+ })), nextCursor: null, complete: true };
46
+ },
47
+ async read(path) {
48
+ const { bucket, file } = splitPath(path);
49
+ if (!file) throw new Error("Backblaze file path is required");
50
+ const data = await b2DownloadFile(creds.keyId, creds.applicationKey, bucket, file);
51
+ if (!data) throw new Error("Backblaze file not found");
52
+ return data;
53
+ },
54
+ async write(path, data, contentType) {
55
+ const { bucket, file } = splitPath(path);
56
+ if (!file) throw new Error("Backblaze file path is required");
57
+ await b2UploadFile(
58
+ creds.keyId,
59
+ creds.applicationKey,
60
+ bucket,
61
+ file,
62
+ data,
63
+ contentType || "application/octet-stream"
64
+ );
65
+ },
66
+ async delete() {
67
+ throw new UnsupportedStorageOperation("backblaze-b2", "delete");
68
+ }
69
+ };
70
+ }
71
+
72
+ export {
73
+ createBackblazeB2StorageService
74
+ };
@@ -0,0 +1,157 @@
1
+ import {
2
+ createProviderClient
3
+ } from "./chunk-YFMHT77Z.js";
4
+
5
+ // src/provider-services/cloudflare.ts
6
+ var QUERY = `query WorkersToday($account: string, $start: string, $end: string) {
7
+ viewer { accounts(filter: { accountTag: $account }) {
8
+ workersInvocationsAdaptive(
9
+ limit: 1000, filter: { datetime_geq: $start, datetime_leq: $end }
10
+ ) { sum { requests } }
11
+ } }
12
+ }`;
13
+ function utcBounds(now) {
14
+ const start = new Date(now);
15
+ start.setUTCHours(0, 0, 0, 0);
16
+ return {
17
+ start: start.toISOString(),
18
+ end: now.toISOString(),
19
+ resetAt: new Date(start.getTime() + 864e5).toISOString()
20
+ };
21
+ }
22
+ async function fetchCloudflareCapacity(connection, plan, now = /* @__PURE__ */ new Date(), transport = fetch) {
23
+ const capturedAt = now.toISOString();
24
+ const snapshot = {
25
+ providerId: "cloudflare",
26
+ serviceId: "cloudflare",
27
+ accountId: connection.accountId,
28
+ capturedAt,
29
+ metrics: [],
30
+ coverage: "unavailable"
31
+ };
32
+ if (!/^[a-f0-9]{32}$/i.test(connection.accountScope || "")) {
33
+ return { ...snapshot, error: "A specific Cloudflare account tag is required" };
34
+ }
35
+ if (plan !== "free") {
36
+ return { ...snapshot, error: "Paid usage requires a separately configured spending policy" };
37
+ }
38
+ try {
39
+ const { start, end, resetAt } = utcBounds(now);
40
+ const client = createProviderClient(connection, transport);
41
+ const response = await client.request({
42
+ method: "POST",
43
+ path: "/client/v4/graphql",
44
+ body: { query: QUERY, variables: { account: connection.accountScope, start, end } }
45
+ });
46
+ const body = response.data;
47
+ const groups = body?.data?.viewer?.accounts?.[0]?.workersInvocationsAdaptive;
48
+ if (body.errors?.length || !Array.isArray(groups) || groups.length >= 1e3)
49
+ return { ...snapshot, error: "Cloudflare analytics failed or exceeded the query window" };
50
+ const values = groups.map((item) => item.sum?.requests);
51
+ if (values.some((v) => typeof v !== "number" || !Number.isFinite(v) || v < 0))
52
+ return { ...snapshot, error: "Cloudflare analytics request values are malformed" };
53
+ const used = values.reduce((sum, value) => sum + value, 0);
54
+ return {
55
+ ...snapshot,
56
+ coverage: "complete",
57
+ metrics: [{
58
+ id: "workers_daily_requests",
59
+ label: "Workers requests / UTC day",
60
+ used,
61
+ limit: 1e5,
62
+ unit: "requests",
63
+ window: "day",
64
+ source: "provider",
65
+ enforceable: true,
66
+ resetAt
67
+ }]
68
+ };
69
+ } catch {
70
+ return { ...snapshot, error: "Cloudflare analytics could not be retrieved" };
71
+ }
72
+ }
73
+
74
+ // src/provider-services/vercel.ts
75
+ async function fetchVercelCapacity(connection, options, now = /* @__PURE__ */ new Date(), transport = fetch) {
76
+ const capturedAt = now.toISOString();
77
+ const snapshot = {
78
+ providerId: "vercel",
79
+ serviceId: "vercel",
80
+ accountId: connection.accountId,
81
+ capturedAt,
82
+ metrics: [],
83
+ coverage: "unavailable"
84
+ };
85
+ if (!Number.isFinite(Date.parse(options.windowStart)) || !Number.isFinite(Date.parse(options.windowEnd)) || Date.parse(options.windowEnd) <= Date.parse(options.windowStart)) {
86
+ return { ...snapshot, error: "Valid usage window boundaries are required" };
87
+ }
88
+ if (options.plan !== "hobby")
89
+ return { ...snapshot, error: "Paid plan budgets are account-specific and require provider billing data" };
90
+ try {
91
+ const client = createProviderClient(connection, transport);
92
+ const { data } = await client.request({
93
+ path: "/v2/usage",
94
+ query: {
95
+ type: "requests",
96
+ from: options.windowStart,
97
+ to: options.windowEnd,
98
+ ...connection.accountScope ? { teamId: connection.accountScope } : {}
99
+ }
100
+ });
101
+ if (!Array.isArray(data?.data))
102
+ return { ...snapshot, error: "Vercel usage payload did not contain verified daily rows" };
103
+ const rows = data.data;
104
+ const sum = (keys) => {
105
+ if (!rows.every((row) => keys.every((key) => row[key] === void 0 || typeof row[key] === "number" && Number.isFinite(row[key]) && row[key] >= 0)))
106
+ return null;
107
+ if (!rows.some((row) => keys.some((key) => row[key] !== void 0))) return null;
108
+ return rows.reduce((total, row) => total + keys.reduce((n, key) => n + (row[key] || 0), 0), 0);
109
+ };
110
+ const enforced = !!options.billingWindowVerified && !!options.resetAt && Date.parse(options.resetAt) > now.getTime();
111
+ const metric = (id, label, used, limit, unit) => ({
112
+ id,
113
+ label,
114
+ used,
115
+ limit,
116
+ unit,
117
+ window: "billing",
118
+ resetAt: options.resetAt || null,
119
+ enforceable: enforced,
120
+ source: used === null ? "unavailable" : "provider"
121
+ });
122
+ const inv = sum([
123
+ "function_invocation_successful_count",
124
+ "function_invocation_error_count",
125
+ "function_invocation_timeout_count"
126
+ ]);
127
+ const memory = sum([
128
+ "function_execution_successful_gb_hours",
129
+ "function_execution_error_gb_hours",
130
+ "function_execution_timeout_gb_hours"
131
+ ]);
132
+ const cpuMs = sum(["fluid_active_cpu_ms"]);
133
+ const metrics = [
134
+ metric("function_invocations", "Function invocations", inv, 1e6, "count"),
135
+ metric("provisioned_memory", "Provisioned memory", memory, 360, "GB-hours"),
136
+ metric(
137
+ "active_cpu",
138
+ "Active CPU",
139
+ cpuMs === null ? null : cpuMs / 1e3,
140
+ 4 * 3600,
141
+ "seconds"
142
+ )
143
+ ];
144
+ return {
145
+ ...snapshot,
146
+ metrics,
147
+ coverage: enforced && metrics.every((m) => m.source === "provider") ? "complete" : "partial"
148
+ };
149
+ } catch {
150
+ return { ...snapshot, error: "Vercel usage could not be retrieved" };
151
+ }
152
+ }
153
+
154
+ export {
155
+ fetchCloudflareCapacity,
156
+ fetchVercelCapacity
157
+ };
@@ -0,0 +1,82 @@
1
+ import {
2
+ listGitHubRepositories,
3
+ listGitHubRepositoryContents
4
+ } from "./chunk-5GW5PJWQ.js";
5
+ import {
6
+ UnsupportedStorageOperation,
7
+ normalizeStoragePath
8
+ } from "./chunk-5UVJDX7Q.js";
9
+
10
+ // src/provider-services/storage/github.ts
11
+ function splitRepo(path) {
12
+ const parts = normalizeStoragePath(path).split("/");
13
+ if (parts.length < 2 || !parts[0] || !parts[1]) throw new Error("GitHub path must start with owner/repository");
14
+ return { owner: parts[0], repo: parts[1], file: parts.slice(2).join("/") };
15
+ }
16
+ function toEntry(value, prefix) {
17
+ return {
18
+ id: value.sha || value.path,
19
+ name: value.name,
20
+ path: "/" + prefix + "/" + value.path,
21
+ kind: value.type === "dir" ? "folder" : "file",
22
+ ...typeof value.size === "number" ? { size: value.size } : {}
23
+ };
24
+ }
25
+ function createGitHubStorageService(connection, transport = fetch) {
26
+ if (connection.providerId !== "github") throw new Error("GitHub connection required");
27
+ const capabilities = Object.freeze({ list: true, read: true, write: false, delete: false });
28
+ return {
29
+ providerId: "github",
30
+ capabilities,
31
+ async list(path = "", cursor) {
32
+ const normalized = normalizeStoragePath(path);
33
+ if (!normalized) {
34
+ const page = cursor ? Number(cursor) : 1;
35
+ if (!Number.isSafeInteger(page) || page < 1 || page > 1e4) throw new Error("Invalid GitHub cursor");
36
+ const repos = await listGitHubRepositories(connection, transport, page);
37
+ return {
38
+ entries: repos.map((repo2) => ({
39
+ id: String(repo2.id),
40
+ name: repo2.full_name.split("/").pop(),
41
+ path: "/" + repo2.full_name,
42
+ kind: "repository"
43
+ })),
44
+ nextCursor: repos.length === 100 ? String(page + 1) : null,
45
+ complete: repos.length < 100
46
+ };
47
+ }
48
+ if (cursor) throw new Error("GitHub directory listings do not support cursors");
49
+ const { owner, repo, file } = splitRepo(normalized);
50
+ const values = await listGitHubRepositoryContents(connection, owner, repo, file, transport);
51
+ if (!Array.isArray(values)) throw new Error("GitHub path is not a directory");
52
+ if (values.length >= 1e3) throw new Error("GitHub directory exceeds contents API limit");
53
+ return {
54
+ entries: values.map((v) => toEntry(v, owner + "/" + repo)),
55
+ nextCursor: null,
56
+ complete: true
57
+ };
58
+ },
59
+ async read(path) {
60
+ const { owner, repo, file } = splitRepo(path);
61
+ if (!file) throw new Error("GitHub file path required");
62
+ const data = await listGitHubRepositoryContents(connection, owner, repo, file, transport);
63
+ if (!data || typeof data !== "object" || Array.isArray(data))
64
+ throw new Error("GitHub file metadata missing");
65
+ const result = data;
66
+ if (result.type !== "file" || result.encoding !== "base64" || typeof result.content !== "string")
67
+ throw new Error("GitHub contents API did not supply file bytes");
68
+ const binary = atob(result.content.replace(/\s/g, ""));
69
+ return Uint8Array.from(binary, (c) => c.charCodeAt(0));
70
+ },
71
+ async write() {
72
+ throw new UnsupportedStorageOperation("github", "write");
73
+ },
74
+ async delete() {
75
+ throw new UnsupportedStorageOperation("github", "delete");
76
+ }
77
+ };
78
+ }
79
+
80
+ export {
81
+ createGitHubStorageService
82
+ };
@@ -0,0 +1,74 @@
1
+ import {
2
+ continueDropboxFolder,
3
+ listDropboxFolder
4
+ } from "./chunk-5GW5PJWQ.js";
5
+ import {
6
+ normalizeStoragePath
7
+ } from "./chunk-5UVJDX7Q.js";
8
+
9
+ // src/provider-services/storage/dropbox.ts
10
+ function toDropboxPath(path) {
11
+ const normalized = normalizeStoragePath(path);
12
+ return normalized ? "/" + normalized : "";
13
+ }
14
+ async function contentRequest(connection, path, method, transport, content, mimeType = "application/octet-stream") {
15
+ if (connection.providerId !== "dropbox" || !connection.credential || !connection.accountId)
16
+ throw new Error("Authorized Dropbox connection required");
17
+ const target = toDropboxPath(path);
18
+ if (!target) throw new Error("Dropbox file path required");
19
+ const headers = {
20
+ Authorization: "Bearer " + connection.credential,
21
+ "Dropbox-API-Arg": JSON.stringify(method === "download" ? { path: target } : { path: target, mode: "add", autorename: false, mute: true })
22
+ };
23
+ if (method === "upload") headers["Content-Type"] = mimeType;
24
+ const response = await transport("https://content.dropboxapi.com/2/files/" + method, {
25
+ method: "POST",
26
+ headers,
27
+ body: method === "upload" ? typeof content === "string" ? content : new Uint8Array(content || new Uint8Array()) : void 0,
28
+ redirect: "error",
29
+ signal: AbortSignal.timeout(2e4)
30
+ });
31
+ if (!response.ok) throw new Error("Dropbox " + method + " HTTP " + response.status);
32
+ return response;
33
+ }
34
+ function createDropboxStorageService(connection, transport = fetch) {
35
+ if (connection.providerId !== "dropbox") throw new Error("Dropbox connection required");
36
+ return {
37
+ providerId: "dropbox",
38
+ capabilities: Object.freeze({ list: true, read: true, write: true, delete: true }),
39
+ async list(path = "", cursor) {
40
+ const value = cursor ? await continueDropboxFolder(connection, cursor, transport) : await listDropboxFolder(connection, toDropboxPath(path), transport);
41
+ return {
42
+ entries: value.entries.map((e) => ({
43
+ id: e.id || e.path_lower || e.name,
44
+ name: e.name,
45
+ path: e.path_lower || (toDropboxPath(path) || "") + "/" + e.name,
46
+ kind: e[".tag"] === "folder" ? "folder" : "file"
47
+ })),
48
+ nextCursor: value.has_more ? value.cursor : null,
49
+ complete: !value.has_more
50
+ };
51
+ },
52
+ async read(path) {
53
+ const response = await contentRequest(connection, path, "download", transport);
54
+ return new Uint8Array(await response.arrayBuffer());
55
+ },
56
+ async write(path, bytes, contentType) {
57
+ await contentRequest(connection, path, "upload", transport, bytes, contentType);
58
+ },
59
+ async delete(path) {
60
+ const target = toDropboxPath(path);
61
+ if (!target) throw new Error("Refusing to delete the Dropbox root");
62
+ const { createProviderClient } = await import("./client-JXGCPWEA.js");
63
+ await createProviderClient(connection, transport).request({
64
+ path: "/2/files/delete_v2",
65
+ method: "POST",
66
+ body: { path: target }
67
+ });
68
+ }
69
+ };
70
+ }
71
+
72
+ export {
73
+ createDropboxStorageService
74
+ };
@@ -0,0 +1,54 @@
1
+ import {
2
+ createCanonicalStorageService
3
+ } from "./chunk-IKDYKRVH.js";
4
+
5
+ // src/provider-services/storage-node.ts
6
+ import { createService, createServiceDefinition } from "@ultrst-armada/krnl";
7
+ var definition = createServiceDefinition({
8
+ id: "kloks.external.storage",
9
+ name: "Canonical Storage Provider Service",
10
+ version: "1.0.0",
11
+ operations: {
12
+ list: {
13
+ id: "storage.list",
14
+ name: "list",
15
+ handler: (input) => createCanonicalStorageService(input.config).list(input.path, input.cursor)
16
+ },
17
+ read: {
18
+ id: "storage.read",
19
+ name: "read",
20
+ handler: (input) => createCanonicalStorageService(input.config).read(input.path)
21
+ },
22
+ write: {
23
+ id: "storage.write",
24
+ name: "write",
25
+ handler: (input) => createCanonicalStorageService(input.config).write(input.path, input.data, input.contentType)
26
+ },
27
+ delete: {
28
+ id: "storage.delete",
29
+ name: "delete",
30
+ handler: (input) => createCanonicalStorageService(input.config).delete(input.path)
31
+ }
32
+ }
33
+ });
34
+ var instance = createService(definition);
35
+ var CanonicalStorageProviderService = {
36
+ id: definition.id,
37
+ name: definition.name,
38
+ version: definition.version,
39
+ runtime: "server",
40
+ deployment: "local",
41
+ definition,
42
+ get telemetry() {
43
+ return instance.telemetry;
44
+ },
45
+ createInstance: () => createService(definition),
46
+ execute: async (operation, input) => {
47
+ await instance.start();
48
+ return instance.call(operation, input);
49
+ }
50
+ };
51
+
52
+ export {
53
+ CanonicalStorageProviderService
54
+ };
@@ -2,7 +2,7 @@ import {
2
2
  getPrimarySrklDeploymentUrl,
3
3
  getSrklAccounts,
4
4
  srklListBackblazeBuckets
5
- } from "./chunk-TRP76UR2.js";
5
+ } from "./chunk-DJ457D5D.js";
6
6
  import {
7
7
  formatCanonicalWorkspaceFolderName,
8
8
  sanitizeWorkspaceName
@@ -13,13 +13,13 @@ import {
13
13
  findUserWorkspace,
14
14
  getWorkspaces,
15
15
  updateWorkspace
16
- } from "./chunk-IRNQXVYA.js";
16
+ } from "./chunk-23LS4LWC.js";
17
17
  import {
18
18
  deleteWorkspaceFile,
19
19
  listWorkspaceFiles,
20
20
  readWorkspaceFile,
21
21
  writeWorkspaceFile
22
- } from "./chunk-BRNWUIH5.js";
22
+ } from "./chunk-GTKW4IGC.js";
23
23
  import {
24
24
  completeGoogleDriveAuthorization,
25
25
  createBackblazeStorageConnection,
@@ -43,7 +43,7 @@ import {
43
43
  testBackblazeCredentials,
44
44
  testGoogleDriveConnectionForUser,
45
45
  writeGoogleDriveFileForConnection
46
- } from "./chunk-FSOOAU6G.js";
46
+ } from "./chunk-TOLAWKAY.js";
47
47
  import {
48
48
  loginSystemUser,
49
49
  resolveUserFromToken
@@ -165,7 +165,7 @@ async function listUserWorkspaceStorageFiles(input) {
165
165
  }
166
166
  async function deleteUserWorkspaceStorageFolder(input) {
167
167
  const context = await resolveWorkspaceContext(input, makeQuery(input.env));
168
- const { deleteWorkspaceFolder } = await import("./workspaceFileCore-UURQPP62.js");
168
+ const { deleteWorkspaceFolder } = await import("./workspaceFileCore-RQO7YMRD.js");
169
169
  await deleteWorkspaceFolder(context.workspace, context.connection, input.env);
170
170
  }
171
171
 
@@ -0,0 +1,58 @@
1
+ import {
2
+ getProviderService,
3
+ resolveProviderServiceId
4
+ } from "./chunk-FKK23J2A.js";
5
+
6
+ // src/provider-services/client.ts
7
+ var origins = {
8
+ cloudflare: "https://api.cloudflare.com",
9
+ vercel: "https://api.vercel.com",
10
+ google: "https://www.googleapis.com",
11
+ "google-gemini": "https://generativelanguage.googleapis.com",
12
+ "google-drive": "https://www.googleapis.com",
13
+ github: "https://api.github.com",
14
+ gitlab: "https://gitlab.com",
15
+ dropbox: "https://api.dropboxapi.com"
16
+ };
17
+ function createProviderClient(connection, transport = fetch) {
18
+ const id = resolveProviderServiceId(connection.providerId);
19
+ const definition = getProviderService(id);
20
+ const origin = origins[id];
21
+ if (!origin || definition?.status !== "ready" || !definition.apiImplemented)
22
+ throw new Error("Provider API integration is not implemented: " + id);
23
+ if (!connection.accountId || !connection.credential?.trim())
24
+ throw new Error("A vault account and credential are required");
25
+ async function request(options) {
26
+ if (!options.path.startsWith("/") || options.path.startsWith("//") || options.path.includes("\\") || options.path.includes("#"))
27
+ throw new Error("Only provider-relative API paths are permitted");
28
+ const target = new URL(options.path, origin);
29
+ if (target.origin !== origin || /(?:^|\/)\.\.(?:\/|$)/.test(decodeURIComponent(target.pathname)))
30
+ throw new Error("Provider URL crossed the allowed origin");
31
+ for (const [key, value] of Object.entries(options.query || {}))
32
+ target.searchParams.set(key, String(value));
33
+ const headers = { Accept: "application/json" };
34
+ const secret = connection.credential.trim();
35
+ if (id === "google-gemini") headers["x-goog-api-key"] = secret;
36
+ else headers.Authorization = "Bearer " + secret;
37
+ if (id === "github") {
38
+ headers.Accept = "application/vnd.github+json";
39
+ headers["X-GitHub-Api-Version"] = "2022-11-28";
40
+ }
41
+ if (options.body !== void 0) headers["Content-Type"] = "application/json";
42
+ const response = await transport(target.toString(), {
43
+ method: options.method || "GET",
44
+ headers,
45
+ body: options.body === void 0 ? void 0 : JSON.stringify(options.body),
46
+ redirect: "error",
47
+ signal: AbortSignal.timeout(options.timeoutMs ?? 1e4)
48
+ });
49
+ if (!response.ok) throw new Error("Provider " + id + " returned HTTP " + response.status);
50
+ const data = await response.json();
51
+ return { data, status: response.status, headers: response.headers };
52
+ }
53
+ return { providerId: id, request };
54
+ }
55
+
56
+ export {
57
+ createProviderClient
58
+ };
@@ -0,0 +1,7 @@
1
+ import {
2
+ createProviderClient
3
+ } from "./chunk-YFMHT77Z.js";
4
+ import "./chunk-FKK23J2A.js";
5
+ export {
6
+ createProviderClient
7
+ };
@@ -7,3 +7,4 @@ export * from './connectivity/index.js';
7
7
  export * from './services/index.js';
8
8
  export * from './resolver/index.js';
9
9
  export type { Runtime, Deployment, FunctionSet, ServiceFacade, OrchestrationFn, BackendFacade, ServiceRegistryRecord, } from './architecture/types.js';
10
+ export * from './provider-services/index.js';