# TypeScript source SDK

The TypeScript SDK wraps the installed Yapwing CLI. It uses the same project
lock, inspected revisions and retry-safe operation IDs as a command-line
call. It does not evaluate a project file or rewrite JSON behind the app.

The SDK source is private and is not distributed as a public npm package.
Use the [bundled CLI](/docs/cli) when you do not have source access.
For a checkout containing the SDK, follow the build and test instructions in
the [SDK source API](/docs/sdk-source) before importing
`@yapwing/project`.

## Inspect and apply

```ts
import { ProjectClient } from "@yapwing/project";

const client = new ProjectClient("/absolute/My-video.yapwing");
const { snapshot } = await client.inspect();
const word = snapshot.renderPlan.words.find(unit => unit.kind === "word");
if (!word) throw new Error("Wait for transcription, then inspect again.");

const request = client.request(snapshot, "remove-word-unique-id", [
  { type: "cut_units", unitIds: [word.id] },
]);
await client.check(request);
const { receipt } = await client.apply(request);
console.log(receipt.committedRevision);
```

Replace the project path and keep the request's operation ID until success is
known. Reusing that ID with a different request fails. A new edit needs a new
ID and a fresh snapshot.

The client also exposes project initialization, import, collection,
transcription, export, paged library reads, analysis and prepared-source
linking, library `search` and read-only `preview` renders. The
[SDK source API](/docs/sdk-source) documents each method's options;
the [project and command format](/docs/project-format) defines the request and
response types.

Set `YAPWING_CLI` to the installed CLI's absolute path when it is not on
`PATH`. A CLI built from source also needs the core and speech paths described
in `docs/development.md` of the checkout.
