Make agent URLs configurable and update quickstart docs#1148
Make agent URLs configurable and update quickstart docs#1148zeroasterisk wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the quickstart documentation to use specific demo commands and introduces environment variable support for configuring agent URLs in the Lit client samples. The review feedback suggests using distinct ports in the documentation examples to avoid confusion and adding optional chaining when accessing environment variables in TypeScript to improve robustness and adhere to style guidelines.
docs/quickstart.md
Outdated
| export VITE_RESTAURANT_AGENT_URL="http://localhost:8000" | ||
| export VITE_CONTACTS_AGENT_URL="http://localhost:8000" |
There was a problem hiding this comment.
The example shows both agents using the same port (8000). Since these are typically separate processes, it is clearer to show them on different ports to avoid potential port conflicts for users trying to run both demos simultaneously.
| export VITE_RESTAURANT_AGENT_URL="http://localhost:8000" | |
| export VITE_CONTACTS_AGENT_URL="http://localhost:8000" | |
| export VITE_RESTAURANT_AGENT_URL="http://localhost:8000" | |
| export VITE_CONTACTS_AGENT_URL="http://localhost:8001" |
| "Just a moment...", | ||
| ], | ||
| serverUrl: "http://localhost:10003", | ||
| serverUrl: (import.meta as any).env.VITE_CONTACTS_AGENT_URL || "http://localhost:10003", |
There was a problem hiding this comment.
Accessing (import.meta as any).env without optional chaining can cause a runtime error if env is undefined (e.g., in certain test environments or non-Vite builds). Adding optional chaining makes the code more robust. Additionally, while any is used here to bypass missing type definitions for import.meta.env, it is generally discouraged in TypeScript per standard style guides.
| serverUrl: (import.meta as any).env.VITE_CONTACTS_AGENT_URL || "http://localhost:10003", | |
| serverUrl: (import.meta as any).env?.VITE_CONTACTS_AGENT_URL || "http://localhost:10003", |
References
- The TypeScript style guide generally discourages the use of the
anytype to maintain type safety and prevent runtime errors. (link)
| "Almost there...", | ||
| ], | ||
| serverUrl: "http://localhost:10002", | ||
| serverUrl: (import.meta as any).env.VITE_RESTAURANT_AGENT_URL || "http://localhost:10002", |
There was a problem hiding this comment.
Using (import.meta as any).env without optional chaining can cause a runtime error if env is undefined. Adding optional chaining makes the code more resilient. Also, avoiding any is preferred for better type safety.
| serverUrl: (import.meta as any).env.VITE_RESTAURANT_AGENT_URL || "http://localhost:10002", | |
| serverUrl: (import.meta as any).env?.VITE_RESTAURANT_AGENT_URL || "http://localhost:10002", |
References
- The TypeScript style guide generally discourages the use of the
anytype to maintain type safety and prevent runtime errors. (link)
74559bc to
1244dc1
Compare
ditman
left a comment
There was a problem hiding this comment.
Small change, please try not to use as any, instead, define the type that you expect for ImportMeta!
| "Just a moment...", | ||
| ], | ||
| serverUrl: "http://localhost:10003", | ||
| serverUrl: (import.meta as any).env?.VITE_CONTACTS_AGENT_URL || "http://localhost:10003", |
There was a problem hiding this comment.
The contacts sample is gone from the shell app, this is not needed anymore!
| "Almost there...", | ||
| ], | ||
| serverUrl: "http://localhost:10002", | ||
| serverUrl: (import.meta as any).env?.VITE_RESTAURANT_AGENT_URL || "http://localhost:10002", |
There was a problem hiding this comment.
Please, don't do as any here. Maybe define an ImportMeta and ImportMetaEnv types (as described here).
Also, when have you found yourself needing this? I normally start the demos with npm run demo:blah and that has all the batteries included!
This PR addresses onboarding friction by making agent URLs configurable via env vars and updating the quickstart documentation.