Skip to content

Commit a46c002

Browse files
authored
feat: support scoping by project id (#11)
1 parent 4256101 commit a46c002

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

test-proj/ui/src/lib/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ import { EXTRACTED_DATA_COLLECTION } from "./config";
1111

1212
const platformToken = import.meta.env.VITE_LLAMA_CLOUD_API_KEY;
1313
const apiBaseUrl = import.meta.env.VITE_LLAMA_CLOUD_BASE_URL;
14+
const projectId = import.meta.env.VITE_LLAMA_CLOUD_PROJECT_ID;
1415

1516
// Configure the platform client
1617
cloudApiClient.setConfig({
1718
baseUrl: apiBaseUrl,
1819
headers: {
20+
// optionally use a backend API token scoped to a project. For local development,
1921
...(platformToken && { authorization: `Bearer ${platformToken}` }),
22+
// This header is required for requests to correctly scope to the agent's project
23+
// when authenticating with a user cookie
24+
...(projectId && { "Project-Id": projectId }),
2025
},
2126
});
2227

test-proj/ui/vite.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import path from "path";
66
export default defineConfig(({}) => {
77
const deploymentId = process.env.LLAMA_DEPLOY_NEXTJS_DEPLOYMENT_NAME;
88
const basePath = `/deployments/${deploymentId}/ui`;
9+
const projectId = process.env.LLAMA_DEPLOY_PROJECT_ID;
910

1011
return {
1112
plugins: [react()],
@@ -30,6 +31,10 @@ export default defineConfig(({}) => {
3031
"import.meta.env.VITE_LLAMA_DEPLOY_DEPLOYMENT_NAME":
3132
JSON.stringify(deploymentId),
3233
"import.meta.env.VITE_LLAMA_DEPLOY_BASE_PATH": JSON.stringify(basePath),
34+
...(projectId && {
35+
"import.meta.env.VITE_LLAMA_CLOUD_PROJECT_ID":
36+
JSON.stringify(projectId),
37+
}),
3338
},
3439
};
3540
});

ui/src/lib/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ import { EXTRACTED_DATA_COLLECTION } from "./config";
1111

1212
const platformToken = import.meta.env.VITE_LLAMA_CLOUD_API_KEY;
1313
const apiBaseUrl = import.meta.env.VITE_LLAMA_CLOUD_BASE_URL;
14+
const projectId = import.meta.env.VITE_LLAMA_CLOUD_PROJECT_ID;
1415

1516
// Configure the platform client
1617
cloudApiClient.setConfig({
1718
baseUrl: apiBaseUrl,
1819
headers: {
20+
// optionally use a backend API token scoped to a project. For local development,
1921
...(platformToken && { authorization: `Bearer ${platformToken}` }),
22+
// This header is required for requests to correctly scope to the agent's project
23+
// when authenticating with a user cookie
24+
...(projectId && { "Project-Id": projectId }),
2025
},
2126
});
2227

ui/vite.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import path from "path";
66
export default defineConfig(({}) => {
77
const deploymentId = process.env.LLAMA_DEPLOY_NEXTJS_DEPLOYMENT_NAME;
88
const basePath = `/deployments/${deploymentId}/ui`;
9+
const projectId = process.env.LLAMA_DEPLOY_PROJECT_ID;
910

1011
return {
1112
plugins: [react()],
@@ -30,6 +31,10 @@ export default defineConfig(({}) => {
3031
"import.meta.env.VITE_LLAMA_DEPLOY_DEPLOYMENT_NAME":
3132
JSON.stringify(deploymentId),
3233
"import.meta.env.VITE_LLAMA_DEPLOY_BASE_PATH": JSON.stringify(basePath),
34+
...(projectId && {
35+
"import.meta.env.VITE_LLAMA_CLOUD_PROJECT_ID":
36+
JSON.stringify(projectId),
37+
}),
3338
},
3439
};
3540
});

0 commit comments

Comments
 (0)