Compare commits

...

3 Commits

Author SHA1 Message Date
Adrian Lyjak 78d6800b6b Avoid using window deployment name on localhost, as that is conventional to default ot public. Optionally read deployment name from env vars as well 2025-07-21 11:28:15 -04:00
Adrian Lyjak 8b51db3bd8 add changeset 2025-07-18 19:37:40 -04:00
Adrian Lyjak 749e0f10cd feat: default to _public agent data 2025-07-18 19:30:14 -04:00
2 changed files with 26 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/cloud": patch
---
Default to \_public agent url id
+21 -6
View File
@@ -33,7 +33,7 @@ export class AgentClient<T = unknown> {
apiKey = getEnv("LLAMA_CLOUD_API_KEY"),
baseUrl = "https://api.cloud.llamaindex.ai/",
collection = "default",
agentUrlId = "default",
agentUrlId = "_public",
}: {
apiKey?: string;
baseUrl?: string;
@@ -127,7 +127,7 @@ export class AgentClient<T = unknown> {
}
/**
* List agent data
* Search agent data
*/
async search(
options: SearchAgentDataOptions,
@@ -275,7 +275,8 @@ export interface AgentDataClientOptions<T = unknown> {
collection?: string;
}
/**
* Create a new AsyncAgentDataClient instance
* Create a new AsyncAgentDataClient instance. Does it's best to infer an agent url id from environment.
* Pass in the window url and/or env to infer the agent url id from them.
* @param options - The options for the client
* @returns A new AgentClient instance
*/
@@ -283,20 +284,34 @@ export function createAgentDataClient<T = unknown>({
apiKey,
baseUrl,
windowUrl,
env,
agentUrlId,
collection = "default",
}: {
apiKey?: string;
baseUrl?: string;
windowUrl?: string;
env?: Record<string, string>;
agentUrlId?: string;
collection?: string;
} = {}): AgentClient<T> {
if (env && !agentUrlId) {
agentUrlId =
env.LLAMA_DEPLOY_DEPLOYMENT_NAME ||
env.NEXT_PUBLIC_LLAMA_DEPLOY_DEPLOYMENT_NAME ||
env.VITE_LLAMA_DEPLOY_DEPLOYMENT_NAME;
}
if (windowUrl && !agentUrlId) {
try {
const path = new URL(windowUrl).pathname;
// /deployments/<agent-url-id>/ui/ -> ["", "deployments", "<agent-url-id>", "ui"]
agentUrlId = path.split("/")[2];
const url = new URL(windowUrl);
const path = url.pathname;
const isLocalhost = // local agents should default to _public, otherwise a full deployment is required
url.hostname.includes("localhost") ||
url.hostname.includes("127.0.0.1");
if (path.startsWith("/deployments/") && !isLocalhost) {
// /deployments/<agent-url-id>/ui/ -> ["", "deployments", "<agent-url-id>", "ui"]
agentUrlId = path.split("/")[2];
}
} catch (error) {
console.warn(
"Failed to infer agent url id from window url, falling back to default",