Repository navigation
The TypeScript SDK uploads a file and follows its ingest job - #281
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ons; the helpers type on TypeScript 5.6 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ll; the wait's timers are documented Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… per helper Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…entType is tested Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…at can leave Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #157
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
The TypeScript SDK sends a file for the server's extractor to parse:
loom.knowledge.uploadposts its bytes,loom.knowledge.waitForIngestfollows the ingest job until it ends, andloom.knowledge.ingestFiledoes both aroundknowledge.ingest, from Node or a browser (Blob,File).Why
The issue moves every client onto the upload and ingest path. #280 gave the Python SDK and the CLIs that path. In the TypeScript SDK,
knowledge.ingest,ingest_statusandingest_cancelwere typed, butPOST /v1/knowledge.uploadtakes a raw body outside the op registry, so a TypeScript caller (a Node service, or a web app holding aFile) still had to write that request by hand: the query parameters, the sha256 and the credential.Design
src/transport.ts):postBytes(path, query, data)posts raw bytes asapplication/octet-streamto{baseUrl}/v1/{path}?{query}.ratelimitMaxWaitS, and the retry policy.Uint8Array, so the published types still compile on TypeScript 5.6 (the package's floor);tscpasses on 5.6.3 and 5.9.3.src/files.ts), merged intoloom.knowledgebeside its generated ops:upload(scope, data, filename, { contentType })takes aUint8Array, anArrayBufferor aBlob. It computes the sha256 with Web Crypto, which Node 20+ and browsers provide on https pages and localhost; where it is missing (a browser page on plain http) the upload goes without one, which the server accepts (it checks only a hash it is sent).waitForIngest(scope, ingestionId, { timeoutMs, pollMs, signal })polls until the job isready,partial,failedorcancelled. A job not found returns at once. PasttimeoutMs(600 s by default) it throwsTimeoutError, naming the state the job is in. Between polls it sleeps on real timers (not aTransport's injectedsleep) with the transport's sleep helper, which an abort cuts short and which leaves no listener behind, so an abort surfaces as the transport'saborted by callererror, as it does during a request.ingestFile({ ...knowledge.ingest fields, data, filename })uploads, ingests, and waits (or not, withwait: false). Its title defaults to the file name less its extension, as the CLI and the Python SDK title it.waitTimeoutMsbounds the wait;callcarries the upload's and the ingest's request options (a longertimeoutMsfor a large file over a slow link, a retry policy, a request id), andcall.signalalso stops the wait.INGEST_DONEand the types are exported. The method names follow the Python SDK's (upload,wait_for_ingest,ingest_file), camel-cased.LoomClient["knowledge"]isGroupClient<"knowledge"> & KnowledgeFiles, attached in the constructor;loom.group("knowledge")stays the ops alone, as its type says; every other group is unchanged.docs/reference/typescript-sdk.md, a type-checked example in the package README (upload,ingestandwaitForIngestnamed as its steps), and the knowledge page's paragraph on the SDK helpers now names both SDKs.Alternatives considered:
loom.filesclient (likeloom.account). The Python SDK has these onknowledge, and the upload's id feedsknowledge.ingest, so the knowledge group is where a caller looks.fetchcalled directly infiles.ts. That would bypass the credential provider, pacing and logging the transport owns.Scope and risk
ops.tsis unchanged.Compatibility, rollout and rollback
/v1/knowledge.uploadand the ingest ops. An older one answers404, raised asNotFound.Tests
src/files.test.ts(15 tests):loom.knowledgetakes and answers (type-level; the repository's test inventory requires a test of each export);Blob, anArrayBufferand a view of part of a shared buffer each send just their bytes;RateLimited;waitForIngestpolls until the job ends, returns at once for a job not found, throwsTimeoutErrornaming the state, and stops at an abort mid-sleep with the transport's error;INGEST_DONEnames the four end states;ingestFileuploads (itscontentTypereaching the upload), ingests and waits with the stem as its title, and sends none ofdata,filenameorcontentTypetoknowledge.ingest;ingestFile's answer is typed bywait: the status, the job, or either for awaitthat is not a literal (a type-level test);ingestFile's wait stops atcall.signal's abort and throwsTimeoutErrorpastwaitTimeoutMs;wait: falsereturns the job, a title given is kept, andcall's request id reaches both the upload and the ingest (the server keeps the id as a trace label only, so one id on both requests is fine).INGEST_DONE).test/integ/live.test.ts: against a server and its ClickHouse, the upload answers its format and size, andingestFile({ wait: false })queues a job thatknowledge.ingest_statusfinds, with its file name and source. All 5 live tests pass. Against a server whose upload cap was set to 1,000 bytes, a 200 kB and a 50 MB upload from the built package each answered413 PAYLOAD_TOO_LARGEafter one send (the refusal arrives as an answer, not a dropped connection, so it is not resent).npm run check(lint, type-check, version, the README's examples type-checked, 259 unit tests) andnpm run check:dist(build, dist tests, publint, attw) pass, as CI runs them.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. Checked: the helpers against a real server, the failure paths in the unit tests above, and a review at every push.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code