Skip to content

SDK-Updates for Javascript #332

Open
CoderOMaster wants to merge 5 commits into
mainfrom
keshav/js-sdk
Open

SDK-Updates for Javascript #332
CoderOMaster wants to merge 5 commits into
mainfrom
keshav/js-sdk

Conversation

@CoderOMaster

@CoderOMaster CoderOMaster commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codex review

The 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 .env guidance can lead users to delete an existing index when running the custom embedding sample.

Comment thread examples/javascript/session_sample.ts
Comment thread examples/javascript/comprehensive_sample.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/moss to ^1.3.1 and 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.md and added .env.template to 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.

Comment thread examples/javascript/session_sample.ts Outdated
Comment thread examples/javascript/README.md Outdated
Comment thread examples/javascript/README.md Outdated
CoderOMaster and others added 3 commits July 1, 2026 23:06
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_here

custom_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, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants