@literary-universe/sdk 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -15
- package/dist/cjs/generated.d.ts +54 -1
- package/dist/cjs/generated.js +4 -1
- package/dist/cjs/index.d.ts +16 -1
- package/dist/cjs/index.js +46 -27
- package/dist/cjs/mcp.d.ts +20 -0
- package/dist/cjs/mcp.js +624 -0
- package/dist/cjs/project.d.ts +38 -5
- package/dist/cjs/project.js +258 -29
- package/dist/esm/generated.d.ts +54 -1
- package/dist/esm/generated.js +3 -0
- package/dist/esm/index.d.ts +16 -1
- package/dist/esm/index.js +47 -28
- package/dist/esm/mcp.d.ts +20 -0
- package/dist/esm/mcp.js +619 -0
- package/dist/esm/project.d.ts +38 -5
- package/dist/esm/project.js +257 -30
- package/package.json +25 -5
- package/schema.graphql +36 -1
package/README.md
CHANGED
|
@@ -10,29 +10,27 @@ Read the [documentation in our feedback knowledge base](https://literaryuniverse
|
|
|
10
10
|
for Literary Universe help. This README describes the SDK's current API contract.
|
|
11
11
|
Report SDK bugs in [this repository](https://github.com/LiteraryUniverse/sdk-typescript/issues).
|
|
12
12
|
|
|
13
|
-
The client uses the deployment's `/graphql` endpoint. The core client has no runtime dependencies and exports ESM and CommonJS builds. Local image preparation uses the optional Sharp dependency through the `/images` entry point. Node
|
|
13
|
+
The client uses the deployment's `/graphql` endpoint. The core client has no runtime dependencies and exports ESM and CommonJS builds. Local image preparation uses the optional Sharp dependency through the `/images` entry point; `/project` manages a folder of chapter files, and `/mcp` registers the API as tools on an MCP server through the optional `@modelcontextprotocol/sdk` and `zod` peers. Node 26 or later and Bun are targets; see CI and local verification for tested versions. `/graphql` sends no CORS headers, so code running on another origin, including an Obsidian plugin, must pass a `fetch` that is not subject to CORS, for example one built on Obsidian's `requestUrl`.
|
|
14
14
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
17
|
-
The
|
|
18
|
-
|
|
17
|
+
The package is published to npm as
|
|
18
|
+
[`@literary-universe/sdk`](https://www.npmjs.com/package/@literary-universe/sdk)
|
|
19
|
+
under the MIT license. It needs Node 26 or later, or Bun:
|
|
19
20
|
|
|
20
21
|
```sh
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
npm pack
|
|
22
|
+
npm install @literary-universe/sdk
|
|
23
|
+
# or
|
|
24
|
+
bun add @literary-universe/sdk
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
npm install /path/to/sdk-typescript/literary-universe-sdk-0.1.0.tgz
|
|
31
|
-
```
|
|
27
|
+
The optional entry points need their own peers in your application:
|
|
28
|
+
`npm install sharp@0.35.5` for `/images`, and
|
|
29
|
+
`npm install @modelcontextprotocol/sdk zod` for `/mcp`.
|
|
32
30
|
|
|
33
|
-
The package includes its schema, generated types and image policy.
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
The package includes its schema, generated types and image policy. To build it
|
|
32
|
+
from source instead, clone this repository and run `npm ci && npm pack`; that
|
|
33
|
+
does not require the Literary Universe monorepo.
|
|
36
34
|
|
|
37
35
|
## Quickstart
|
|
38
36
|
|
|
@@ -222,6 +220,14 @@ const saved = await client.saveDraft(input)
|
|
|
222
220
|
const before = await client.draftRecovery({ id: chapterId, recoveryId: saved.recoveryId })
|
|
223
221
|
```
|
|
224
222
|
|
|
223
|
+
The input takes exactly one of `content` (Tiptap JSON) and `markdown`, a string in
|
|
224
|
+
the form the draft's `markdown` field returns; the server converts it with the
|
|
225
|
+
editor's own Markdown extension. Content without a Markdown form (ruby, play
|
|
226
|
+
nodes, text alignment, initial letters, emoji, video and work cards, see
|
|
227
|
+
`MARKDOWN_LOSSY_TYPES` in /project) round-trips only through `content`; a
|
|
228
|
+
`markdown` save of such a draft fails with MARKDOWN_UNSUPPORTED. createChapter
|
|
229
|
+
accepts `markdown` the same way.
|
|
230
|
+
|
|
225
231
|
Retry an interrupted save with the same input and operation ID. A reused ID with
|
|
226
232
|
changed input yields IDEMPOTENCY_CONFLICT; a changed draft yields VERSION_CONFLICT.
|
|
227
233
|
The mutation changes body representations/counters only. Titles, notes, financial
|
|
@@ -309,6 +315,48 @@ supported credential kind; the provider interface leaves room for deliberate
|
|
|
309
315
|
OAuth support later. Client names are bounded reported metadata for server audit.
|
|
310
316
|
There are no automatic telemetry providers or exporters.
|
|
311
317
|
|
|
318
|
+
## Local projects
|
|
319
|
+
|
|
320
|
+
```ts
|
|
321
|
+
import { pullLocalProject, localProjectStatus, pushLocalProject, refreshLocalProject }
|
|
322
|
+
from '@literary-universe/sdk/project'
|
|
323
|
+
|
|
324
|
+
await pullLocalProject(client, { directory: 'my-story', baseUrl, storyId })
|
|
325
|
+
localProjectStatus('my-story') // [{ id, language, file, version, changed, source, pending }]
|
|
326
|
+
await pushLocalProject(client, { directory: 'my-story', baseUrl })
|
|
327
|
+
await refreshLocalProject(client, { directory: 'my-story', baseUrl }) // { added, updated, removed }
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
A pull writes every draft twice: `chapters/chapter-<id>.<lang>.json` holds the
|
|
331
|
+
Tiptap document and `chapters/<seq>-<slug>.<lang>.md` mirrors it as Markdown.
|
|
332
|
+
`seq` is the chapter sequence zero-padded to three digits and `slug` the title
|
|
333
|
+
lower-cased with runs of other characters turned into hyphens, at most 60
|
|
334
|
+
characters, `chapter` when nothing is left, numbered `-2`, `-3` on a collision.
|
|
335
|
+
The Markdown file starts with YAML frontmatter (`id`, `title`, `language`,
|
|
336
|
+
`version`, `editable`) followed by a blank line and the body; only the body is
|
|
337
|
+
hashed and sent. A chapter whose content has no Markdown form gets
|
|
338
|
+
`editable: false` and a `# Edit chapters/chapter-<id>.<lang>.json instead` line
|
|
339
|
+
under the frontmatter; a legacy chapter the server has no Markdown form for yet
|
|
340
|
+
(`content` and `markdown` null) gets `editable: false` and a line asking to open
|
|
341
|
+
it once in the web editor and refresh. The manifest `.lu/project.json` stays at version 1;
|
|
342
|
+
manifests without the `markdown` entry still load and gain the mirror on the
|
|
343
|
+
next save.
|
|
344
|
+
|
|
345
|
+
`localProjectStatus` reports `source` per chapter: `none`, `json`, `markdown` or
|
|
346
|
+
`both`. A push sends `content` for `json` and `markdown` for `markdown`, then
|
|
347
|
+
rewrites both files from the server's normalized draft. A chapter changed in
|
|
348
|
+
both files fails locally with AMBIGUOUS_CHANGE, a Markdown edit of a chapter
|
|
349
|
+
marked `editable: false` with MARKDOWN_UNSUPPORTED; nothing is sent for either.
|
|
350
|
+
Revert one file to the manifest form to continue. Pending intents record which
|
|
351
|
+
form was sent and replay unchanged after an interruption.
|
|
352
|
+
|
|
353
|
+
`refreshLocalProject` re-pulls every chapter of an existing project. It refuses
|
|
354
|
+
with LOCAL_CHANGES while any chapter is changed or pending; otherwise it rewrites
|
|
355
|
+
files and manifest, renames Markdown mirrors whose title or sequence changed,
|
|
356
|
+
deletes the files of chapters the server no longer has, and reports the chapter
|
|
357
|
+
IDs added, updated and removed. `pullLocalProject` with `refresh: true` is the
|
|
358
|
+
same call.
|
|
359
|
+
|
|
312
360
|
## Images
|
|
313
361
|
|
|
314
362
|
Install the existing supported image engine with `npm install sharp@0.35.5` in a
|
|
@@ -397,3 +445,73 @@ The monorepo provides a local storage fixture: run
|
|
|
397
445
|
the isolated Meteor test server with that settings file, and stop both owned
|
|
398
446
|
processes after verification. The fixture uses synthetic credentials and checks
|
|
399
447
|
real S3 transport without contacting Backblaze. It is not a production server.
|
|
448
|
+
|
|
449
|
+
## MCP server
|
|
450
|
+
|
|
451
|
+
`@literary-universe/sdk/mcp` registers the authoring API as tools on a
|
|
452
|
+
`McpServer` from `@modelcontextprotocol/sdk` (install it and `zod` in the host;
|
|
453
|
+
the core client does not load them). The CLI's `lu mcp` and the hosted
|
|
454
|
+
`https://literaryuniverse.com/mcp` endpoint use it.
|
|
455
|
+
|
|
456
|
+
```ts
|
|
457
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
458
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
459
|
+
import { readFile } from 'node:fs/promises'
|
|
460
|
+
import { LiteraryUniverseClient } from '@literary-universe/sdk'
|
|
461
|
+
import { registerLiteraryUniverseTools } from '@literary-universe/sdk/mcp'
|
|
462
|
+
|
|
463
|
+
const token = process.env.LU_TOKEN
|
|
464
|
+
const client = token ? new LiteraryUniverseClient({ baseUrl, token }) : null
|
|
465
|
+
const server = new McpServer({ name: 'literary-universe', version: '0.2.0' })
|
|
466
|
+
registerLiteraryUniverseTools(server, { client: () => client, readLocalFile: readFile })
|
|
467
|
+
await server.connect(new StdioServerTransport())
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
`client` is called per tool call so a host can refresh credentials; `null` makes
|
|
471
|
+
every tool that needs an account answer `Not signed in to Literary Universe`.
|
|
472
|
+
Tools are grouped in categories; `tools` selects categories and/or tool names
|
|
473
|
+
(`'all'` for every tool) and replaces the default selection, which leaves out
|
|
474
|
+
`publish`: `account`, `stories` (`list-stories`, `get-story`, `list-chapters`,
|
|
475
|
+
`get-chapter-draft`), `stories-write` (`save-chapter-draft`, `create-chapter`,
|
|
476
|
+
`update-story`, `set-story-visibility`, `rename-chapter`, `reorder-chapters`,
|
|
477
|
+
`remove-chapter`), `publish` (`publish-chapter`, which does nothing without
|
|
478
|
+
`confirm: true`), `universes`, `universes-write`, `images` (`set-cover` only with
|
|
479
|
+
`readLocalFile`) and `docs` (`search-lu-docs`, `fetch-lu-docs`, usable without
|
|
480
|
+
login; they read the site's `llms.txt` pages and help articles under `docsBaseUrl`). `selectTools`
|
|
481
|
+
validates a selection without a server. Every tool carries a title, a zod input
|
|
482
|
+
schema and the four MCP annotations; results carry `structuredContent` and a
|
|
483
|
+
text form; API errors come back as `isError` text `CODE: message (request id)`,
|
|
484
|
+
with the input schema appended for BAD_USER_INPUT. Resources `lu://story/{id}`
|
|
485
|
+
and `lu://chapter/{id}/draft` return the same data as the tools.
|
|
486
|
+
|
|
487
|
+
## Blog pages and menus
|
|
488
|
+
|
|
489
|
+
`client.blogPages({blogId, first?, after?})` lists private pages, including drafts
|
|
490
|
+
and translations, sorted by ID. Use the last returned ID as `after` and stop on a
|
|
491
|
+
short or empty batch. `client.blogMenus({blogId})` returns the three stored menu
|
|
492
|
+
locations. Both return documents with `id`, opaque `version`, and JSON `data`.
|
|
493
|
+
They require `blog:read` and management access to that blog.
|
|
494
|
+
|
|
495
|
+
`client.mutateBlog(input)` requires `blog:write`. Its `action` is `savePage`,
|
|
496
|
+
`translatePage`, `publishPage`, `saveMenu` or `translateMenu`. Supply `blogId`,
|
|
497
|
+
`operationId` and `expectedVersion` on every request. Use null for a new page or
|
|
498
|
+
menu and the latest returned version for edits. Keep the full request unchanged
|
|
499
|
+
when retrying a lost response; the SDK preserves it on transport retries.
|
|
500
|
+
Organization keys may manage only their own enabled organization blog. Restricted
|
|
501
|
+
story/universe keys cannot access blogs. The deployment's author write rollout
|
|
502
|
+
must also permit writes.
|
|
503
|
+
|
|
504
|
+
```ts
|
|
505
|
+
const page = await client.mutateBlog({
|
|
506
|
+
blogId: 'BLOG_ID', action: 'savePage', operationId: 'author-page-1',
|
|
507
|
+
expectedVersion: null, page: {title: 'Author', slug: 'author', language: 'en'},
|
|
508
|
+
})
|
|
509
|
+
await client.mutateBlog({
|
|
510
|
+
blogId: 'BLOG_ID', action: 'publishPage', pageId: page.id,
|
|
511
|
+
operationId: 'author-publish-1', expectedVersion: page.version, published: true,
|
|
512
|
+
})
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
Edits to published pages and saved menus are live immediately. A stale version
|
|
516
|
+
fails with `VERSION_CONFLICT`; read again and review the changes. System pages,
|
|
517
|
+
deletions, unpublishing and homepage changes remain web-editor actions.
|
package/dist/cjs/generated.d.ts
CHANGED
|
@@ -20,13 +20,17 @@ export type AuthorDraftSaveInput = {
|
|
|
20
20
|
language?: string | null | undefined;
|
|
21
21
|
expectedVersion: string;
|
|
22
22
|
operationId: string | number;
|
|
23
|
-
content
|
|
23
|
+
/** Tiptap JSON. Provide exactly one of content and markdown. */
|
|
24
|
+
content?: JsonValue | null | undefined;
|
|
25
|
+
/** Markdown converted on the server with the editor's own Markdown extension. Provide exactly one of content and markdown. Rejected with MARKDOWN_UNSUPPORTED if the stored draft has nodes, marks or attributes Markdown cannot preserve; use content instead. */
|
|
26
|
+
markdown?: string | null | undefined;
|
|
24
27
|
};
|
|
25
28
|
export type AuthorChapterCreateInput = {
|
|
26
29
|
storyId: string | number;
|
|
27
30
|
operationId: string | number;
|
|
28
31
|
title?: string | null | undefined;
|
|
29
32
|
content?: JsonValue | null | undefined;
|
|
33
|
+
markdown?: string | null | undefined;
|
|
30
34
|
isAIGenerated?: boolean | null | undefined;
|
|
31
35
|
};
|
|
32
36
|
export type AuthorPublicationAudience = 'BETA' | 'READERS';
|
|
@@ -140,6 +144,20 @@ export type AuthorStoryUpdateInput = {
|
|
|
140
144
|
/** Another universe needs edit rights on it; null makes the story standalone. */
|
|
141
145
|
universeId?: string | number | null | undefined;
|
|
142
146
|
};
|
|
147
|
+
export type AuthorBlogMutationInput = {
|
|
148
|
+
blogId: string | number;
|
|
149
|
+
operationId: string;
|
|
150
|
+
expectedVersion?: string | null | undefined;
|
|
151
|
+
action: string;
|
|
152
|
+
pageId?: string | number | null | undefined;
|
|
153
|
+
location?: string | null | undefined;
|
|
154
|
+
language?: string | null | undefined;
|
|
155
|
+
page?: JsonValue | null | undefined;
|
|
156
|
+
published?: boolean | null | undefined;
|
|
157
|
+
items?: Array<JsonValue> | null | undefined;
|
|
158
|
+
settings?: JsonValue | null | undefined;
|
|
159
|
+
entries?: JsonValue | null | undefined;
|
|
160
|
+
};
|
|
143
161
|
export type LuIdentityQueryVariables = Exact<{
|
|
144
162
|
[key: string]: never;
|
|
145
163
|
}>;
|
|
@@ -787,6 +805,38 @@ export type LuImagePolicyQueryVariables = Exact<{
|
|
|
787
805
|
export type LuImagePolicyQuery = {
|
|
788
806
|
result: JsonValue;
|
|
789
807
|
};
|
|
808
|
+
export type LuBlogPagesQueryVariables = Exact<{
|
|
809
|
+
blogId: string | number;
|
|
810
|
+
first?: number | null | undefined;
|
|
811
|
+
after?: string | number | null | undefined;
|
|
812
|
+
}>;
|
|
813
|
+
export type LuBlogPagesQuery = {
|
|
814
|
+
result: Array<{
|
|
815
|
+
id: string;
|
|
816
|
+
version: string;
|
|
817
|
+
data: JsonValue;
|
|
818
|
+
}>;
|
|
819
|
+
};
|
|
820
|
+
export type LuBlogMenusQueryVariables = Exact<{
|
|
821
|
+
blogId: string | number;
|
|
822
|
+
}>;
|
|
823
|
+
export type LuBlogMenusQuery = {
|
|
824
|
+
result: Array<{
|
|
825
|
+
id: string;
|
|
826
|
+
version: string;
|
|
827
|
+
data: JsonValue;
|
|
828
|
+
}>;
|
|
829
|
+
};
|
|
830
|
+
export type LuMutateBlogMutationVariables = Exact<{
|
|
831
|
+
input: AuthorBlogMutationInput;
|
|
832
|
+
}>;
|
|
833
|
+
export type LuMutateBlogMutation = {
|
|
834
|
+
result: {
|
|
835
|
+
id: string;
|
|
836
|
+
version: string;
|
|
837
|
+
data: JsonValue;
|
|
838
|
+
};
|
|
839
|
+
};
|
|
790
840
|
export declare const LuIdentityDocument: "query LuIdentity {\n result: apiIdentity {\n version\n kind\n userId\n organizationId\n credentialId\n scopes\n expiresAt\n resourceRestrictions {\n universeIds\n storyIds\n }\n deploymentUrl\n environment\n limits {\n defaultPageSize\n maxPageSize\n maxRequestBytes\n maxDraftBytes\n maxResponseBytes\n }\n }\n}";
|
|
791
841
|
export declare const LuProfileDocument: "query LuProfile {\n result: apiIdentity {\n userId\n username\n }\n}";
|
|
792
842
|
export declare const LuStoriesDocument: "query LuStories($first: Int, $after: String) {\n result: authorStories(first: $first, after: $after) {\n nodes {\n id\n title\n slug\n language\n universeId\n organizationId\n createdAt\n updatedAt\n publishedAt\n privateAt\n state\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n}";
|
|
@@ -818,4 +868,7 @@ export declare const LuDeleteEncyclopediaEntryDocument: "mutation LuDeleteEncycl
|
|
|
818
868
|
export declare const LuSeriesDocument: "query LuSeries($universeId: ID!) {\n result: authorSeries(universeId: $universeId) {\n id\n universeId\n title\n version\n storyIds\n updatedAt\n }\n}";
|
|
819
869
|
export declare const LuSaveSeriesDocument: "mutation LuSaveSeries($input: AuthorSeriesSaveInput!) {\n result: saveAuthorSeries(input: $input) {\n id\n universeId\n title\n version\n storyIds\n updatedAt\n }\n}";
|
|
820
870
|
export declare const LuImagePolicyDocument: "query LuImagePolicy {\n result: authorImagePolicy\n}";
|
|
871
|
+
export declare const LuBlogPagesDocument: "query LuBlogPages($blogId: ID!, $first: Int, $after: ID) {\n result: authorBlogPages(blogId: $blogId, first: $first, after: $after) {\n id\n version\n data\n }\n}";
|
|
872
|
+
export declare const LuBlogMenusDocument: "query LuBlogMenus($blogId: ID!) {\n result: authorBlogMenus(blogId: $blogId) {\n id\n version\n data\n }\n}";
|
|
873
|
+
export declare const LuMutateBlogDocument: "mutation LuMutateBlog($input: AuthorBlogMutationInput!) {\n result: mutateAuthorBlog(input: $input) {\n id\n version\n data\n }\n}";
|
|
821
874
|
export {};
|
package/dist/cjs/generated.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LuImagePolicyDocument = exports.LuSaveSeriesDocument = exports.LuSeriesDocument = exports.LuDeleteEncyclopediaEntryDocument = exports.LuSetEncyclopediaEntryPublicationDocument = exports.LuTranslateEncyclopediaEntryDocument = exports.LuUpdateEncyclopediaEntryDocument = exports.LuCreateEncyclopediaEntryDocument = exports.LuEncyclopediaEntryDocument = exports.LuEncyclopediaEntriesDocument = exports.LuUpdateUniverseDocument = exports.LuReorderChaptersDocument = exports.LuRemoveChapterDocument = exports.LuRenameChapterDocument = exports.LuSetStoryVisibilityDocument = exports.LuUpdateStoryDocument = exports.LuUpdateUniverseTranslationDocument = exports.LuCreateUniverseTranslationDocument = exports.LuPublishChapterDocument = exports.LuCreateChapterDocument = exports.LuDraftRecoveryDocument = exports.LuValidateDraftDocument = exports.LuSaveDraftDocument = exports.LuDraftDocument = exports.LuChaptersDocument = exports.LuUniverseDocument = exports.LuUniversesDocument = exports.LuStoryDocument = exports.LuStoriesDocument = exports.LuProfileDocument = exports.LuIdentityDocument = void 0;
|
|
3
|
+
exports.LuMutateBlogDocument = exports.LuBlogMenusDocument = exports.LuBlogPagesDocument = exports.LuImagePolicyDocument = exports.LuSaveSeriesDocument = exports.LuSeriesDocument = exports.LuDeleteEncyclopediaEntryDocument = exports.LuSetEncyclopediaEntryPublicationDocument = exports.LuTranslateEncyclopediaEntryDocument = exports.LuUpdateEncyclopediaEntryDocument = exports.LuCreateEncyclopediaEntryDocument = exports.LuEncyclopediaEntryDocument = exports.LuEncyclopediaEntriesDocument = exports.LuUpdateUniverseDocument = exports.LuReorderChaptersDocument = exports.LuRemoveChapterDocument = exports.LuRenameChapterDocument = exports.LuSetStoryVisibilityDocument = exports.LuUpdateStoryDocument = exports.LuUpdateUniverseTranslationDocument = exports.LuCreateUniverseTranslationDocument = exports.LuPublishChapterDocument = exports.LuCreateChapterDocument = exports.LuDraftRecoveryDocument = exports.LuValidateDraftDocument = exports.LuSaveDraftDocument = exports.LuDraftDocument = exports.LuChaptersDocument = exports.LuUniverseDocument = exports.LuUniversesDocument = exports.LuStoryDocument = exports.LuStoriesDocument = exports.LuProfileDocument = exports.LuIdentityDocument = void 0;
|
|
4
4
|
exports.LuIdentityDocument = "query LuIdentity {\n result: apiIdentity {\n version\n kind\n userId\n organizationId\n credentialId\n scopes\n expiresAt\n resourceRestrictions {\n universeIds\n storyIds\n }\n deploymentUrl\n environment\n limits {\n defaultPageSize\n maxPageSize\n maxRequestBytes\n maxDraftBytes\n maxResponseBytes\n }\n }\n}";
|
|
5
5
|
exports.LuProfileDocument = "query LuProfile {\n result: apiIdentity {\n userId\n username\n }\n}";
|
|
6
6
|
exports.LuStoriesDocument = "query LuStories($first: Int, $after: String) {\n result: authorStories(first: $first, after: $after) {\n nodes {\n id\n title\n slug\n language\n universeId\n organizationId\n createdAt\n updatedAt\n publishedAt\n privateAt\n state\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n}";
|
|
@@ -32,3 +32,6 @@ exports.LuDeleteEncyclopediaEntryDocument = "mutation LuDeleteEncyclopediaEntry(
|
|
|
32
32
|
exports.LuSeriesDocument = "query LuSeries($universeId: ID!) {\n result: authorSeries(universeId: $universeId) {\n id\n universeId\n title\n version\n storyIds\n updatedAt\n }\n}";
|
|
33
33
|
exports.LuSaveSeriesDocument = "mutation LuSaveSeries($input: AuthorSeriesSaveInput!) {\n result: saveAuthorSeries(input: $input) {\n id\n universeId\n title\n version\n storyIds\n updatedAt\n }\n}";
|
|
34
34
|
exports.LuImagePolicyDocument = "query LuImagePolicy {\n result: authorImagePolicy\n}";
|
|
35
|
+
exports.LuBlogPagesDocument = "query LuBlogPages($blogId: ID!, $first: Int, $after: ID) {\n result: authorBlogPages(blogId: $blogId, first: $first, after: $after) {\n id\n version\n data\n }\n}";
|
|
36
|
+
exports.LuBlogMenusDocument = "query LuBlogMenus($blogId: ID!) {\n result: authorBlogMenus(blogId: $blogId) {\n id\n version\n data\n }\n}";
|
|
37
|
+
exports.LuMutateBlogDocument = "mutation LuMutateBlog($input: AuthorBlogMutationInput!) {\n result: mutateAuthorBlog(input: $input) {\n id\n version\n data\n }\n}";
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AuthorChapterCreateInput, type AuthorChapterPublishInput, type AuthorChapterRemoveInput, type AuthorChapterRenameInput, type AuthorChapterReorderInput, type AuthorDraftSaveInput, type AuthorEncyclopediaEntryCreateInput, type AuthorEncyclopediaEntryTranslationInput, type AuthorSeriesSaveInput, type LuChaptersQueryVariables, type LuCreateUniverseTranslationMutationVariables, type LuDeleteEncyclopediaEntryMutationVariables, type LuDraftQueryVariables, type LuDraftRecoveryQueryVariables, type LuEncyclopediaEntriesQueryVariables, type LuEncyclopediaEntryQueryVariables, type LuSeriesQueryVariables, type LuSetEncyclopediaEntryPublicationMutationVariables, type LuSetStoryVisibilityMutationVariables, type LuStoriesQueryVariables, type LuStoryQueryVariables, type LuUniverseQueryVariables, type LuUniversesQueryVariables, type LuUpdateEncyclopediaEntryMutationVariables, type LuUpdateStoryMutationVariables, type LuUpdateUniverseMutationVariables, type LuUpdateUniverseTranslationMutationVariables } from './generated.js';
|
|
1
|
+
import { type AuthorBlogMutationInput, type AuthorChapterCreateInput, type AuthorChapterPublishInput, type AuthorChapterRemoveInput, type AuthorChapterRenameInput, type AuthorChapterReorderInput, type AuthorDraftSaveInput, type AuthorEncyclopediaEntryCreateInput, type AuthorEncyclopediaEntryTranslationInput, type AuthorSeriesSaveInput, type LuBlogMenusQueryVariables, type LuBlogPagesQueryVariables, type LuChaptersQueryVariables, type LuCreateUniverseTranslationMutationVariables, type LuDeleteEncyclopediaEntryMutationVariables, type LuDraftQueryVariables, type LuDraftRecoveryQueryVariables, type LuEncyclopediaEntriesQueryVariables, type LuEncyclopediaEntryQueryVariables, type LuSeriesQueryVariables, type LuSetEncyclopediaEntryPublicationMutationVariables, type LuSetStoryVisibilityMutationVariables, type LuStoriesQueryVariables, type LuStoryQueryVariables, type LuUniverseQueryVariables, type LuUniversesQueryVariables, type LuUpdateEncyclopediaEntryMutationVariables, type LuUpdateStoryMutationVariables, type LuUpdateUniverseMutationVariables, type LuUpdateUniverseTranslationMutationVariables } from './generated.js';
|
|
2
2
|
export type * from './generated.js';
|
|
3
3
|
export type { JsonValue } from './json.js';
|
|
4
4
|
import type { ImagePolicy, ImagePurpose } from './imagePolicy.js';
|
|
@@ -493,6 +493,21 @@ export declare class LiteraryUniverseClient {
|
|
|
493
493
|
counters: import("./json.js").JsonValue | null;
|
|
494
494
|
};
|
|
495
495
|
}>;
|
|
496
|
+
blogPages(input: LuBlogPagesQueryVariables, options?: RequestOptions): Promise<{
|
|
497
|
+
id: string;
|
|
498
|
+
version: string;
|
|
499
|
+
data: import("./json.js").JsonValue;
|
|
500
|
+
}[]>;
|
|
501
|
+
blogMenus(input: LuBlogMenusQueryVariables, options?: RequestOptions): Promise<{
|
|
502
|
+
id: string;
|
|
503
|
+
version: string;
|
|
504
|
+
data: import("./json.js").JsonValue;
|
|
505
|
+
}[]>;
|
|
506
|
+
mutateBlog(input: AuthorBlogMutationInput, options?: RequestOptions): Promise<{
|
|
507
|
+
id: string;
|
|
508
|
+
version: string;
|
|
509
|
+
data: import("./json.js").JsonValue;
|
|
510
|
+
}>;
|
|
496
511
|
createChapter(input: AuthorChapterCreateInput, options?: RequestOptions): Promise<{
|
|
497
512
|
id: string;
|
|
498
513
|
storyId: string;
|
package/dist/cjs/index.js
CHANGED
|
@@ -169,6 +169,15 @@ class LiteraryUniverseClient {
|
|
|
169
169
|
saveDraft(input, options) {
|
|
170
170
|
return this.read(generated_js_1.LuSaveDraftDocument, 'LuSaveDraft', { input }, options);
|
|
171
171
|
}
|
|
172
|
+
blogPages(input, options) {
|
|
173
|
+
return this.read(generated_js_1.LuBlogPagesDocument, 'LuBlogPages', input, options);
|
|
174
|
+
}
|
|
175
|
+
blogMenus(input, options) {
|
|
176
|
+
return this.read(generated_js_1.LuBlogMenusDocument, 'LuBlogMenus', input, options);
|
|
177
|
+
}
|
|
178
|
+
mutateBlog(input, options) {
|
|
179
|
+
return this.read(generated_js_1.LuMutateBlogDocument, 'LuMutateBlog', { input }, options);
|
|
180
|
+
}
|
|
172
181
|
createChapter(input, options) {
|
|
173
182
|
return this.read(generated_js_1.LuCreateChapterDocument, 'LuCreateChapter', { input }, options);
|
|
174
183
|
}
|
|
@@ -320,33 +329,7 @@ class LiteraryUniverseClient {
|
|
|
320
329
|
? Number(retryHeader)
|
|
321
330
|
: Math.max(0, Math.ceil((Date.parse(retryHeader) - Date.now()) / 1000))
|
|
322
331
|
: undefined;
|
|
323
|
-
const
|
|
324
|
-
let bytes = 0;
|
|
325
|
-
const chunks = [];
|
|
326
|
-
if (reader) {
|
|
327
|
-
try {
|
|
328
|
-
while (true) {
|
|
329
|
-
const chunk = await reader.read();
|
|
330
|
-
if (chunk.done)
|
|
331
|
-
break;
|
|
332
|
-
bytes += chunk.value.byteLength;
|
|
333
|
-
if (bytes > MAX_RESPONSE_BYTES) {
|
|
334
|
-
await reader.cancel();
|
|
335
|
-
throw new LiteraryUniverseApiError('PAYLOAD_TOO_LARGE', 'API response exceeds the read size limit', headerId, response.status);
|
|
336
|
-
}
|
|
337
|
-
chunks.push(chunk.value);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
finally {
|
|
341
|
-
reader.releaseLock();
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
const body = new Uint8Array(bytes);
|
|
345
|
-
let offset = 0;
|
|
346
|
-
for (const chunk of chunks) {
|
|
347
|
-
body.set(chunk, offset);
|
|
348
|
-
offset += chunk.byteLength;
|
|
349
|
-
}
|
|
332
|
+
const body = await readResponseBytes(response, headerId);
|
|
350
333
|
let envelope;
|
|
351
334
|
try {
|
|
352
335
|
envelope = JSON.parse(new TextDecoder().decode(body));
|
|
@@ -402,6 +385,42 @@ class LiteraryUniverseClient {
|
|
|
402
385
|
}
|
|
403
386
|
}
|
|
404
387
|
exports.LiteraryUniverseClient = LiteraryUniverseClient;
|
|
388
|
+
const tooLarge = (response, requestId) => new LiteraryUniverseApiError('PAYLOAD_TOO_LARGE', 'API response exceeds the read size limit', requestId, response.status);
|
|
389
|
+
/** Streams when the body has a reader; a polyfilled Response without one is read whole. */
|
|
390
|
+
async function readResponseBytes(response, requestId) {
|
|
391
|
+
if (typeof response.body?.getReader !== 'function') {
|
|
392
|
+
const whole = new Uint8Array(await response.arrayBuffer());
|
|
393
|
+
if (whole.byteLength > MAX_RESPONSE_BYTES)
|
|
394
|
+
throw tooLarge(response, requestId);
|
|
395
|
+
return whole;
|
|
396
|
+
}
|
|
397
|
+
const reader = response.body.getReader();
|
|
398
|
+
let bytes = 0;
|
|
399
|
+
const chunks = [];
|
|
400
|
+
try {
|
|
401
|
+
while (true) {
|
|
402
|
+
const chunk = await reader.read();
|
|
403
|
+
if (chunk.done)
|
|
404
|
+
break;
|
|
405
|
+
bytes += chunk.value.byteLength;
|
|
406
|
+
if (bytes > MAX_RESPONSE_BYTES) {
|
|
407
|
+
await reader.cancel();
|
|
408
|
+
throw tooLarge(response, requestId);
|
|
409
|
+
}
|
|
410
|
+
chunks.push(chunk.value);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
finally {
|
|
414
|
+
reader.releaseLock();
|
|
415
|
+
}
|
|
416
|
+
const body = new Uint8Array(bytes);
|
|
417
|
+
let offset = 0;
|
|
418
|
+
for (const chunk of chunks) {
|
|
419
|
+
body.set(chunk, offset);
|
|
420
|
+
offset += chunk.byteLength;
|
|
421
|
+
}
|
|
422
|
+
return body;
|
|
423
|
+
}
|
|
405
424
|
/** REST routes answer `{ error }`; a JSON 404 there is a missing resource, not a wrong mount. */
|
|
406
425
|
function restEnvelope(parsed, status) {
|
|
407
426
|
const { error } = parsed;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { type LiteraryUniverseClient } from './index.js';
|
|
3
|
+
export type McpToolOptions = {
|
|
4
|
+
/** The signed-in client, or null when the agent is not logged in. */
|
|
5
|
+
client: () => LiteraryUniverseClient | null;
|
|
6
|
+
/** Categories and/or tool names to register; 'all' for every tool. Defaults to DEFAULT_TOOL_SELECTION. */
|
|
7
|
+
tools?: readonly string[];
|
|
8
|
+
docsBaseUrl?: string;
|
|
9
|
+
fetch?: typeof globalThis.fetch;
|
|
10
|
+
/** Enables set-cover from a local path; stdio servers only. */
|
|
11
|
+
readLocalFile?: (path: string) => Promise<Uint8Array>;
|
|
12
|
+
};
|
|
13
|
+
export declare const TOOL_CATEGORIES: Record<string, readonly string[]>;
|
|
14
|
+
export declare const DEFAULT_TOOL_SELECTION: readonly string[];
|
|
15
|
+
/** Expands categories and tool names into tool names; throws on an unknown entry. */
|
|
16
|
+
export declare function selectTools(selection: readonly string[] | undefined): string[];
|
|
17
|
+
/** Registers the selected tools and the story/draft resources on an MCP server. */
|
|
18
|
+
export declare function registerLiteraryUniverseTools(server: McpServer, options: McpToolOptions): {
|
|
19
|
+
registered: string[];
|
|
20
|
+
};
|