-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.ts
More file actions
93 lines (88 loc) · 2.63 KB
/
index.ts
File metadata and controls
93 lines (88 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import "reflect-metadata";
import {
agent,
analytics,
createApp,
files,
genie,
server,
} from "@databricks/appkit";
import { WorkspaceClient } from "@databricks/sdk-experimental";
import { demoTools } from "./agent-tools";
import { lakebaseExamples } from "./lakebase-examples-plugin";
import { reconnect } from "./reconnect-plugin";
import { telemetryExamples } from "./telemetry-example-plugin";
function createMockClient() {
const client = new WorkspaceClient({
host: "http://localhost",
token: "e2e",
authType: "pat",
});
client.currentUser.me = async () => ({ id: "e2e-test-user" });
return client;
}
createApp({
plugins: [
server({ autoStart: false }),
reconnect(),
telemetryExamples(),
analytics({}),
genie({
spaces: { demo: process.env.DATABRICKS_GENIE_SPACE_ID ?? "placeholder" },
}),
lakebaseExamples(),
files(),
agent({
model: process.env.DATABRICKS_MODEL || "databricks-claude-sonnet-4-5",
systemPrompt:
"You are a helpful assistant. Use tools when appropriate — for example, use get_weather for weather questions, and get_current_time for time queries.",
tools: [demoTools.weatherTool],
}),
],
...(process.env.APPKIT_E2E_TEST && { client: createMockClient() }),
}).then(async (appkit) => {
// Add tools after app creation
await appkit.agent.addTools([demoTools.timeTool]);
appkit.server
.extend((app) => {
// Rewrite to use standard Databricks Apps convention: /invocations at root
app.post("/invocations", (req, res) => {
req.url = "/api/agent";
app(req, res);
});
app.get("/sp", (_req, res) => {
appkit.analytics
.query("SELECT * FROM samples.nyctaxi.trips;")
.then((result) => {
console.log(result[0]);
res.json(result);
})
.catch((error) => {
console.error("Error:", error);
res.status(500).json({
error: error.message,
errorCode: error.errorCode,
statusCode: error.statusCode,
});
});
});
app.get("/obo", (req, res) => {
appkit.analytics
.asUser(req)
.query("SELECT * FROM samples.nyctaxi.trips;")
.then((result) => {
console.log(result[0]);
res.json(result);
})
.catch((error) => {
console.error("OBO Error:", error);
res.status(500).json({
error: error.message,
errorCode: error.errorCode,
statusCode: error.statusCode,
});
});
});
})
.start();
});