SDK-Updates for Javascript #332
Conversation
Codex reviewThe PR mostly improves JavaScript example coverage, but it introduces one safety issue around reused index names and a couple of example reliability/documentation problems. The strongest concern is that the new shared |
There was a problem hiding this comment.
Pull request overview
Updates the examples/javascript/ workspace to align with newer @moss-dev/moss behavior and to make the TypeScript examples easier to run and verify (scripts, docs, and expanded runnable sample flows).
Changes:
- Bumped
@moss-dev/mossto^1.3.1and added missing npm scripts for running key samples. - Enhanced example scripts (
cached_load_sample.ts,session_sample.ts,comprehensive_sample.ts) with more complete runnable demonstrations (auto-refresh, session docs retrieval, metadata-filter query, SessionIndex demo). - Rewrote
examples/javascript/README.mdand added.env.templateto document setup, per-sample commands, and troubleshooting.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/javascript/package.json | Bumps @moss-dev/moss and adds runnable sample scripts. |
| examples/javascript/package-lock.json | Locks dependency updates to @moss-dev/moss@1.3.1 / @moss-dev/moss-core@0.19.1. |
| examples/javascript/cached_load_sample.ts | Turns the auto-refresh section into runnable code and exports the sample function. |
| examples/javascript/session_sample.ts | Expands the session demo to include getDocs() and improved logging; exports the sample function. |
| examples/javascript/comprehensive_sample.ts | Adds metadata-filter querying and a SessionIndex demo; updates step numbering and cleanup behavior. |
| examples/javascript/README.md | Full rewrite with a quick-reference table and per-sample verification steps. |
| examples/javascript/.env.template | New env template documenting required variables for the examples. |
Files not reviewed (1)
- examples/javascript/package-lock.json: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| # Required by: load-and-query, cached-load, custom-auth | ||
| # Used as session name by: session, session-cache, session-custom-auth | ||
| # Used as the index to CREATE (then delete) by: comprehensive, custom-embedding | ||
| MOSS_INDEX_NAME=your_index_name_here |
There was a problem hiding this comment.
BLOCKING The template uses one MOSS_INDEX_NAME both for existing indexes and for samples that create/delete an index:
MOSS_INDEX_NAME=your_index_name_herecustom_embedding_sample.ts deletes MOSS_INDEX_NAME in its finally block, even if createIndex() failed because that name already existed. A user who fills this with a real index for load-and-query can lose that index by running npm run custom-embedding. Split this into non-destructive and destructive names, e.g. MOSS_EXISTING_INDEX_NAME and MOSS_DEMO_INDEX_NAME, or have destructive samples generate timestamped names and delete only after successful creation.
| // content updates over time (e.g. a live knowledge base). | ||
| console.log("\nReloading with auto-refresh enabled (polls every 60 s)..."); | ||
| start = performance.now(); | ||
| await client.loadIndex(indexName, { |
There was a problem hiding this comment.
CONSIDER Once auto-refresh starts, any error before the reload at line 102 leaves the background poller running and the sample can hang after logging the error:
await client.loadIndex(indexName, {
cachePath: CACHE_DIR,
autoRefresh: true,
pollingIntervalInSeconds: 60,
});Wrap the auto-refresh section in try/finally and stop it in the finally with await client.loadIndex(indexName, { cachePath: CACHE_DIR }) after the auto-refresh load succeeds.
| | --- | --- | | ||
| | `Cannot find module '@moss-dev/moss'` | Run `npm install` | | ||
| | `Missing environment variables` | Copy `.env.template` → `.env` and fill in values | | ||
| | `index does not exist` | Create one first via `npm run comprehensive`, or use the Moss dashboard | |
There was a problem hiding this comment.
CONSIDER This troubleshooting advice points users at a command that cannot leave behind an index:
| `index does not exist` | Create one first via `npm run comprehensive`, or use the Moss dashboard |comprehensive_sample.ts creates a timestamped index and deletes it in finally, so running it will not fix MOSS_INDEX_NAME for load-and-query, cached-load, or custom-auth. Point this row to the dashboard or to a dedicated sample/script that creates a persistent index with the requested name.
Changes done in this PR
package.json — bumped @moss-dev/moss to ^1.3.1; added 4 missing npm scripts: load-and-query, custom-auth, custom-embedding, comprehensive
cached_load_sample.ts — replaced the autoRefresh comment block with actual runnable code: shows loading with autoRefresh: true + pollingIntervalInSeconds, and how to stop it by reloading without the option
session_sample.ts — added a getDocs() call to show the full session API surface; added session.modelId to the open log; added (Ctrl+C to exit) on the final line
comprehensive_sample.ts — trimmed the multi-paragraph JSDoc header; added Step 9 (metadata filter query using $and/$eq/$in); added Step 13 (SessionIndex demo — addDocs/query/pushIndex entirely in-memory); renumbered subsequent steps accordingly
README.md — full rewrite: added a quick-reference table (which samples need an existing index, which create their own), per-sample testing guide with exact commands and what output to verify, troubleshooting table
.env.template — new file; documents all 4 env vars with notes on which samples need each one