@query-farm/vgi 0.50.0 → 0.51.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 (40) hide show
  1. package/dist/functions/aggregate.d.ts +25 -21
  2. package/dist/functions/execution-cache.d.ts +11 -0
  3. package/dist/functions/storage-cf-do.d.ts +38 -0
  4. package/dist/functions/storage-seal.d.ts +27 -0
  5. package/dist/functions/storage.d.ts +49 -1
  6. package/dist/functions/table-buffering.d.ts +30 -0
  7. package/dist/http/fetch.d.ts +7 -0
  8. package/dist/index.core.d.ts +3 -2
  9. package/dist/index.js +749 -384
  10. package/dist/index.js.map +20 -18
  11. package/dist/protocol/dispatch.d.ts +9 -0
  12. package/dist/protocol/handlers/aggregate.d.ts +1 -1
  13. package/dist/protocol/handlers/catalog/shared.d.ts +10 -0
  14. package/dist/protocol/handlers/function.d.ts +2 -0
  15. package/dist/protocol/handlers/table-buffering.d.ts +1 -1
  16. package/dist/protocol/types.d.ts +8 -0
  17. package/dist/serve-entry.d.ts +16 -2
  18. package/dist/serve-entry.js +1034 -526
  19. package/dist/serve-entry.js.map +20 -18
  20. package/dist/worker-cf-entry.js +2713 -2217
  21. package/dist/worker-cf-entry.js.map +26 -24
  22. package/package.json +1 -1
  23. package/src/functions/aggregate.ts +101 -152
  24. package/src/functions/copy-from.ts +2 -2
  25. package/src/functions/execution-cache.ts +59 -0
  26. package/src/functions/storage-cf-do.ts +152 -22
  27. package/src/functions/storage-seal.ts +208 -0
  28. package/src/functions/storage.ts +120 -3
  29. package/src/functions/table-buffering.ts +91 -15
  30. package/src/functions/table-in-out.ts +3 -1
  31. package/src/functions/table.ts +4 -4
  32. package/src/http/fetch.ts +9 -0
  33. package/src/index.core.ts +3 -1
  34. package/src/protocol/dispatch.ts +12 -2
  35. package/src/protocol/handlers/aggregate.ts +123 -82
  36. package/src/protocol/handlers/catalog/shared.ts +20 -0
  37. package/src/protocol/handlers/function.ts +38 -11
  38. package/src/protocol/handlers/table-buffering.ts +44 -32
  39. package/src/protocol/types.ts +8 -0
  40. package/src/serve-entry.ts +33 -3
@@ -89,8 +89,12 @@ export interface ServeVgiWorkerOptions extends HostingOptions {
89
89
  port?: number | undefined;
90
90
  /** Bind address. Iroh bridge mode defaults to loopback; otherwise Bun's default. */
91
91
  hostname?: string | undefined;
92
- /** Overrides `$VGI_SIGNING_KEY`. 32 bytes. */
93
- signingKey?: Uint8Array | undefined;
92
+ /**
93
+ * Overrides `$VGI_SIGNING_KEY`: 32 bytes, or the same 64-hex-character string
94
+ * the env var takes. A string's UTF-8 bytes are also the storage-seal ikm
95
+ * (see {@link resolveStorageSealKey}); bytes are used unchanged.
96
+ */
97
+ signingKey?: Uint8Array | string | undefined;
94
98
  /**
95
99
  * Optional root key for secret ATTACH options (encrypted inside
96
100
  * `attach_opaque_data` for `attachOptions()`). Defaults to the signing key.
@@ -194,6 +198,27 @@ export function resolveSigningKey(
194
198
  return crypto.getRandomValues(new Uint8Array(SIGNING_KEY_BYTES));
195
199
  }
196
200
 
201
+ /**
202
+ * The ikm for sealed framework storage payloads (cross-SDK v1): the UTF-8 bytes
203
+ * of the signing key *as configured* -- an explicit string option, else the raw
204
+ * `$VGI_SIGNING_KEY` value, unmodified, exactly as vgi-python and vgi-java read
205
+ * it -- so one deployment key derives one payload key in every SDK. Explicit
206
+ * bytes are used unchanged; a generated key's bytes are used as-is (it is
207
+ * process-local anyway). Only the storage seal uses this; state tokens and
208
+ * opaque-data envelopes keep the hex-decoded key.
209
+ */
210
+ export function resolveStorageSealKey(
211
+ explicit: Uint8Array | string | undefined,
212
+ env: ServeEnv,
213
+ resolvedSigningKey: Uint8Array,
214
+ ): Uint8Array {
215
+ if (typeof explicit === "string") return new TextEncoder().encode(explicit);
216
+ if (explicit) return explicit;
217
+ const raw = env.VGI_SIGNING_KEY;
218
+ if (raw && raw.trim()) return new TextEncoder().encode(raw);
219
+ return resolvedSigningKey;
220
+ }
221
+
197
222
  function resolvePort(explicit: number | undefined, env: ServeEnv): number {
198
223
  if (explicit !== undefined) return explicit;
199
224
  const raw = env.PORT?.trim();
@@ -228,7 +253,11 @@ export function createVgiWorkerFetch(
228
253
  opts: ServeVgiWorkerOptions,
229
254
  ): (req: Request) => Promise<Response> {
230
255
  const env = opts.env ?? (process.env as ServeEnv);
231
- const signingKey = resolveSigningKey(opts.signingKey, env);
256
+ const signingKey = resolveSigningKey(
257
+ typeof opts.signingKey === "string" ? parseSigningKeyHex(opts.signingKey) : opts.signingKey,
258
+ env,
259
+ );
260
+ const storageSealKey = resolveStorageSealKey(opts.signingKey, env, signingKey);
232
261
  // Explicit option or `$VGI_SIGNING_KEY`: a key that survives a restart.
233
262
  // The generated fallback never enables attach tickets.
234
263
  const signingKeyConfigured = opts.signingKey !== undefined || !!env.VGI_SIGNING_KEY?.trim();
@@ -250,6 +279,7 @@ export function createVgiWorkerFetch(
250
279
  protocol: { registry: opts.registry, catalogInterface: opts.catalogInterface, attachSecretKey: opts.attachSecretKey },
251
280
  signingKey,
252
281
  signingKeyConfigured,
282
+ storageSealKey,
253
283
  tokenTtl,
254
284
  prefix: opts.prefix ?? "",
255
285
  serverId: opts.serverId ?? opts.name,