@dbx-tools/cli 0.9.60 → 0.9.61

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 (39) hide show
  1. package/README.md +64 -17
  2. package/bin/dbx-genie.ts +13 -0
  3. package/index.ts +13 -1
  4. package/lib/bin/dbx-genie.d.ts +2 -0
  5. package/lib/bin/dbx-genie.js +10 -0
  6. package/lib/index.d.ts +13 -1
  7. package/lib/index.js +10 -2
  8. package/lib/src/auth/cli.js +13 -2
  9. package/lib/src/auth/options.d.ts +4 -0
  10. package/lib/src/auth/options.js +5 -1
  11. package/lib/src/cli.js +8 -4
  12. package/lib/src/genie-code/cli.d.ts +19 -0
  13. package/lib/src/genie-code/cli.js +36 -0
  14. package/lib/src/genie-code/config.d.ts +38 -0
  15. package/lib/src/genie-code/config.js +111 -0
  16. package/lib/src/genie-code/install.d.ts +21 -0
  17. package/lib/src/genie-code/install.js +69 -0
  18. package/lib/src/genie-code/options.d.ts +7 -0
  19. package/lib/src/genie-code/options.js +7 -0
  20. package/lib/src/genie-code/runner.d.ts +21 -0
  21. package/lib/src/genie-code/runner.js +90 -0
  22. package/lib/src/genie-code/runtime.d.ts +48 -0
  23. package/lib/src/genie-code/runtime.js +162 -0
  24. package/lib/src/model-gateway/cli.js +3 -3
  25. package/lib/src/model-gateway/server.d.ts +3 -0
  26. package/lib/src/model-gateway/server.js +36 -6
  27. package/lib/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +40 -18
  29. package/src/auth/cli.ts +11 -1
  30. package/src/auth/options.ts +4 -0
  31. package/src/cli.ts +13 -2
  32. package/src/genie-code/cli.ts +58 -0
  33. package/src/genie-code/config.ts +161 -0
  34. package/src/genie-code/install.ts +103 -0
  35. package/src/genie-code/options.ts +14 -0
  36. package/src/genie-code/runner.ts +106 -0
  37. package/src/genie-code/runtime.ts +212 -0
  38. package/src/model-gateway/cli.ts +6 -2
  39. package/src/model-gateway/server.ts +37 -5
@@ -4,15 +4,17 @@
4
4
  * @module
5
5
  */
6
6
 
7
+ import { createHash, timingSafeEqual } from "node:crypto";
7
8
  import { createApp, server } from "@databricks/appkit";
8
- import { modelGateway } from "@dbx-tools/appkit-model-gateway/plugin";
9
- import { sendHealth } from "@dbx-tools/appkit-model-gateway/routes";
9
+ import { ModelGateway } from "@dbx-tools/appkit-model-gateway";
10
+ import { sendHealth, sendInference, sendModels } from "@dbx-tools/appkit-model-gateway/routes";
10
11
  import { workspaceClient } from "@dbx-tools/databricks";
11
12
  import {
12
13
  resolveModelGatewayOptions,
13
14
  type ModelGatewayOptions,
14
15
  type ResolvedModelGatewayOptions,
15
16
  } from "@dbx-tools/shared-model-gateway/options";
17
+ import type express from "express";
16
18
 
17
19
  type AppKitServerOptions = NonNullable<Parameters<typeof server>[0]>;
18
20
 
@@ -29,22 +31,52 @@ function appKitServerOptions(options: ResolvedModelGatewayOptions): AppKitServer
29
31
  };
30
32
  }
31
33
 
34
+ /** Require one bearer token without retaining or logging request credentials. */
35
+ export function gatewayBearerMiddleware(token: string): express.RequestHandler {
36
+ const expected = createHash("sha256").update(token).digest();
37
+ return (request, response, next) => {
38
+ const authorization = request.header("authorization");
39
+ const match = /^Bearer\s+(.+)$/i.exec(authorization ?? "");
40
+ const actual = createHash("sha256")
41
+ .update(match?.[1] ?? "")
42
+ .digest();
43
+ if (match && timingSafeEqual(actual, expected)) {
44
+ next();
45
+ return;
46
+ }
47
+ response
48
+ .status(401)
49
+ .setHeader("www-authenticate", "Bearer")
50
+ .json({
51
+ error: {
52
+ message: "Invalid or missing model-gateway bearer token.",
53
+ type: "authentication_error",
54
+ code: "invalid_bearer_token",
55
+ },
56
+ });
57
+ };
58
+ }
59
+
32
60
  /** Start the foreground model gateway and keep its AppKit server active. */
33
61
  export async function startModelGateway(options: ModelGatewayOptions = {}): Promise<void> {
34
62
  const resolved = resolveModelGatewayOptions(options);
63
+ const gateway = new ModelGateway();
35
64
  const client = await workspaceClient.createWorkspaceClient({
36
65
  ...(resolved.profile ? { profile: resolved.profile } : {}),
37
66
  });
38
67
  await createApp({
39
68
  client,
40
- plugins: [modelGateway(), server(appKitServerOptions(resolved))],
69
+ plugins: [server(appKitServerOptions(resolved))],
41
70
  onPluginsReady(appkit) {
42
71
  appkit.server.extend((application) => {
72
+ if (resolved.bearerToken) {
73
+ application.use(gatewayBearerMiddleware(resolved.bearerToken));
74
+ }
43
75
  application.get("/api/healthz", (_request, response) => {
44
76
  sendHealth(response);
45
77
  });
46
78
  application.get("/v1/models", (request, response) => {
47
- void appkit.modelGateway.models(request, response);
79
+ void sendModels(gateway, request, response);
48
80
  });
49
81
  for (const [path, protocol] of [
50
82
  ["/v1/chat/completions", "openai-chat"],
@@ -53,7 +85,7 @@ export async function startModelGateway(options: ModelGatewayOptions = {}): Prom
53
85
  ["/v1/embeddings", "openai-embeddings"],
54
86
  ] as const) {
55
87
  application.post(path, (request, response) => {
56
- void appkit.modelGateway.inference(protocol, request, response);
88
+ void sendInference(gateway, protocol, request, response);
57
89
  });
58
90
  }
59
91
  });