@jant/core 0.8.1 → 0.9.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/dist/{app--uxnaIRV.js → app-B3P2N2vM.js} +1346 -310
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/_assets/{client-auth-begiT1tq.js → client-auth-CeGBe0qG.js} +1 -1
- package/dist/client/_assets/{client-BT6kpcuG.js → client-nByuF0Ct.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/node.js +2 -2
- package/package.json +1 -1
- package/src/__tests__/helpers/cursor-walk.ts +37 -7
- package/src/app.tsx +4 -0
- package/src/lib/__tests__/discover.test.ts +24 -0
- package/src/lib/__tests__/thread-fold.test.ts +43 -0
- package/src/lib/api-posts.ts +110 -2
- package/src/lib/api-public-posts.ts +263 -0
- package/src/lib/api-threads.ts +207 -0
- package/src/lib/discover.ts +34 -0
- package/src/lib/thread-fold.ts +83 -41
- package/src/lib/thread-query.ts +143 -0
- package/src/middleware/cors.ts +8 -1
- package/src/middleware/deprecation.ts +48 -0
- package/src/routes/api/__tests__/mcp.test.ts +143 -0
- package/src/routes/api/__tests__/posts.test.ts +78 -0
- package/src/routes/api/__tests__/public-access.test.ts +5 -0
- package/src/routes/api/__tests__/search.test.ts +104 -0
- package/src/routes/api/__tests__/threads.test.ts +115 -0
- package/src/routes/api/posts.ts +15 -104
- package/src/routes/api/public/__tests__/threads.test.ts +363 -0
- package/src/routes/api/public/archive.ts +82 -81
- package/src/routes/api/public/posts.ts +97 -298
- package/src/routes/api/public/threads.ts +141 -0
- package/src/routes/api/search.ts +31 -2
- package/src/routes/api/threads.ts +128 -0
- package/src/routes/auth/__tests__/setup-discover.test.ts +29 -1
- package/src/routes/auth/__tests__/setup-page.test.tsx +59 -1
- package/src/routes/auth/setup.tsx +48 -9
- package/src/routes/pages/__tests__/search.test.ts +58 -0
- package/src/routes/pages/search.tsx +3 -1
- package/src/services/__tests__/search.test.ts +211 -0
- package/src/services/__tests__/thread.test.ts +495 -0
- package/src/services/index.ts +4 -0
- package/src/services/mcp.ts +217 -57
- package/src/services/post.ts +222 -43
- package/src/services/search.ts +77 -66
- package/src/services/thread.ts +392 -0
- package/src/types/constants.ts +25 -0
- package/src/ui/feed/ThreadPreview.tsx +9 -14
- package/src/ui/feed/__tests__/thread-preview.test.ts +18 -22
- package/src/ui/feed/thread-preview-state.ts +0 -35
package/src/services/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
type SmartCollectionService,
|
|
27
27
|
} from "./smart-collection.js";
|
|
28
28
|
import { createSearchService, type SearchService } from "./search.js";
|
|
29
|
+
import { createThreadService, type ThreadService } from "./thread.js";
|
|
29
30
|
import { createNavItemService, type NavItemService } from "./navigation.js";
|
|
30
31
|
import { createAuthService, type AuthService } from "./auth.js";
|
|
31
32
|
import { createApiTokenService, type ApiTokenService } from "./api-token.js";
|
|
@@ -58,6 +59,7 @@ export interface Services {
|
|
|
58
59
|
site: SiteService;
|
|
59
60
|
paths: PathService;
|
|
60
61
|
posts: PostService;
|
|
62
|
+
threads: ThreadService;
|
|
61
63
|
customUrls: CustomUrlService;
|
|
62
64
|
media: MediaService;
|
|
63
65
|
uploads: UploadSessionService;
|
|
@@ -135,6 +137,7 @@ export function createServices(
|
|
|
135
137
|
site,
|
|
136
138
|
paths,
|
|
137
139
|
posts,
|
|
140
|
+
threads: createThreadService({ posts, collections }),
|
|
138
141
|
customUrls: createCustomUrlService(db, siteId, paths, databaseSchema),
|
|
139
142
|
media,
|
|
140
143
|
uploads: createUploadSessionService(db, siteId, media, databaseSchema),
|
|
@@ -193,6 +196,7 @@ export type { SettingsService } from "./settings.js";
|
|
|
193
196
|
export type { SiteService } from "./site.js";
|
|
194
197
|
export type { PathService } from "./path.js";
|
|
195
198
|
export type { PostService, PostFilters, PostDeleteDeps } from "./post.js";
|
|
199
|
+
export type { ThreadService } from "./thread.js";
|
|
196
200
|
export type { CustomUrlService } from "./custom-url.js";
|
|
197
201
|
export type {
|
|
198
202
|
SmartCollectionService,
|
package/src/services/mcp.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
CollectionDescriptionValueSchema,
|
|
4
4
|
CollectionIdSchema,
|
|
5
5
|
CollectionSortOrderSchema,
|
|
6
|
+
ContentLanguageSchema,
|
|
6
7
|
CreateCollectionSchema,
|
|
7
8
|
CreatePostApiSchema,
|
|
8
9
|
FormatSchema,
|
|
@@ -15,7 +16,9 @@ import {
|
|
|
15
16
|
COLLECTION_SORT_ORDERS,
|
|
16
17
|
FORMATS,
|
|
17
18
|
STATUSES,
|
|
19
|
+
THREAD_SORTS,
|
|
18
20
|
VISIBILITIES,
|
|
21
|
+
type Post,
|
|
19
22
|
} from "../types.js";
|
|
20
23
|
import type { AppConfig } from "../types/config.js";
|
|
21
24
|
import type { StorageDriver } from "../lib/storage.js";
|
|
@@ -25,8 +28,14 @@ import {
|
|
|
25
28
|
buildEditableSettingsResponse,
|
|
26
29
|
partitionEditableSettingUpdates,
|
|
27
30
|
} from "../lib/api-settings.js";
|
|
28
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
apiPostListOrder,
|
|
33
|
+
loadApiPostResponse,
|
|
34
|
+
loadApiPostResponses,
|
|
35
|
+
} from "../lib/api-posts.js";
|
|
29
36
|
import { toSearchApiResult } from "../lib/api-search.js";
|
|
37
|
+
import { loadApiThreadResponses } from "../lib/api-threads.js";
|
|
38
|
+
import { parseThreadSelection } from "../lib/thread-query.js";
|
|
30
39
|
import {
|
|
31
40
|
ConfigurationError,
|
|
32
41
|
ExternalServiceError,
|
|
@@ -140,6 +149,68 @@ const AddCollectionThreadToolSchema = z.object({
|
|
|
140
149
|
|
|
141
150
|
const RemoveCollectionThreadToolSchema = AddCollectionThreadToolSchema;
|
|
142
151
|
|
|
152
|
+
/**
|
|
153
|
+
* The filter dimensions `jant_threads_list` takes, spelled as the HTTP API
|
|
154
|
+
* and the archive spell them. They reach the same registry parser as a query
|
|
155
|
+
* string would, so the vocabularies can't drift.
|
|
156
|
+
*/
|
|
157
|
+
const THREAD_FILTER_TOOL_PROPERTIES = {
|
|
158
|
+
format: { type: "string", enum: [...FORMATS] },
|
|
159
|
+
collection: {
|
|
160
|
+
type: "string",
|
|
161
|
+
description: "Collection slug, or several comma-separated",
|
|
162
|
+
},
|
|
163
|
+
year: { type: "integer", description: "Publication year (UTC)" },
|
|
164
|
+
media: {
|
|
165
|
+
type: "string",
|
|
166
|
+
description:
|
|
167
|
+
"any, none, or comma-separated kinds: image, video, audio, text, document",
|
|
168
|
+
},
|
|
169
|
+
title: { type: "string", enum: ["any", "none"] },
|
|
170
|
+
replies: { type: "string", enum: ["any", "none"] },
|
|
171
|
+
visibility: {
|
|
172
|
+
type: "string",
|
|
173
|
+
enum: ["public", "featured", "hidden", "private"],
|
|
174
|
+
},
|
|
175
|
+
} as const;
|
|
176
|
+
|
|
177
|
+
const ListThreadsToolSchema = z.object({
|
|
178
|
+
cursor: z.string().optional(),
|
|
179
|
+
limit: z.coerce.number().int().min(1).max(100).optional().default(20),
|
|
180
|
+
status: StatusSchema.optional(),
|
|
181
|
+
sort: z.enum(THREAD_SORTS).optional(),
|
|
182
|
+
fold: z.boolean().optional(),
|
|
183
|
+
lang: ContentLanguageSchema.optional(),
|
|
184
|
+
format: z.string().optional(),
|
|
185
|
+
collection: z.string().optional(),
|
|
186
|
+
year: z.number().int().optional(),
|
|
187
|
+
media: z.string().optional(),
|
|
188
|
+
title: z.string().optional(),
|
|
189
|
+
replies: z.string().optional(),
|
|
190
|
+
visibility: z.string().optional(),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const LIST_THREADS_OWN_PARAMS = [
|
|
194
|
+
"cursor",
|
|
195
|
+
"limit",
|
|
196
|
+
"status",
|
|
197
|
+
"sort",
|
|
198
|
+
"fold",
|
|
199
|
+
"lang",
|
|
200
|
+
] as const;
|
|
201
|
+
|
|
202
|
+
const GetThreadToolSchema = z.object({
|
|
203
|
+
id: PostIdSchema,
|
|
204
|
+
fold: z.boolean().optional(),
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const ListThreadPostsToolSchema = z.object({
|
|
208
|
+
id: PostIdSchema,
|
|
209
|
+
cursor: z.string().optional(),
|
|
210
|
+
limit: z.coerce.number().int().min(1).max(100).optional().default(100),
|
|
211
|
+
status: StatusSchema.optional(),
|
|
212
|
+
});
|
|
213
|
+
|
|
143
214
|
const mcpTools: McpToolDefinition[] = [
|
|
144
215
|
{
|
|
145
216
|
name: "jant_posts_list",
|
|
@@ -157,8 +228,9 @@ const mcpTools: McpToolDefinition[] = [
|
|
|
157
228
|
},
|
|
158
229
|
async execute(args, context) {
|
|
159
230
|
const input = ListPostsToolSchema.parse(args ?? {});
|
|
231
|
+
const status = input.status ?? "published";
|
|
160
232
|
const { posts, nextCursor } = await context.services.posts.listPage(
|
|
161
|
-
{ format: input.format, status
|
|
233
|
+
{ format: input.format, status, ...apiPostListOrder(status) },
|
|
162
234
|
{ cursor: input.cursor, limit: input.limit },
|
|
163
235
|
);
|
|
164
236
|
|
|
@@ -211,6 +283,136 @@ const mcpTools: McpToolDefinition[] = [
|
|
|
211
283
|
return content;
|
|
212
284
|
},
|
|
213
285
|
},
|
|
286
|
+
{
|
|
287
|
+
name: "jant_threads_list",
|
|
288
|
+
description:
|
|
289
|
+
"List Threads (a root post and its replies), each with its post count. Takes the archive's filters; sort is activity (default), published, updated, oldest, or rating. Set fold to include the replies the homepage shows. Pass nextCursor back as cursor for the next page.",
|
|
290
|
+
inputSchema: {
|
|
291
|
+
type: "object",
|
|
292
|
+
properties: {
|
|
293
|
+
cursor: { type: "string" },
|
|
294
|
+
limit: { type: "integer", minimum: 1, maximum: 100, default: 20 },
|
|
295
|
+
status: { type: "string", enum: [...STATUSES] },
|
|
296
|
+
sort: { type: "string", enum: [...THREAD_SORTS] },
|
|
297
|
+
fold: { type: "boolean" },
|
|
298
|
+
lang: { type: "string", description: "BCP 47 content language" },
|
|
299
|
+
...THREAD_FILTER_TOOL_PROPERTIES,
|
|
300
|
+
},
|
|
301
|
+
additionalProperties: false,
|
|
302
|
+
},
|
|
303
|
+
async execute(args, context) {
|
|
304
|
+
const input = ListThreadsToolSchema.parse(args ?? {});
|
|
305
|
+
const filterArgs = Object.fromEntries(
|
|
306
|
+
Object.entries(input).filter(
|
|
307
|
+
([key, value]) =>
|
|
308
|
+
value !== undefined &&
|
|
309
|
+
!(LIST_THREADS_OWN_PARAMS as readonly string[]).includes(key),
|
|
310
|
+
),
|
|
311
|
+
);
|
|
312
|
+
const parsed = await parseThreadSelection(
|
|
313
|
+
(key) => {
|
|
314
|
+
const value = filterArgs[key];
|
|
315
|
+
return value === undefined ? undefined : String(value);
|
|
316
|
+
},
|
|
317
|
+
Object.keys(filterArgs),
|
|
318
|
+
{
|
|
319
|
+
allow: [],
|
|
320
|
+
audience: "author",
|
|
321
|
+
loadCollections: () => context.services.collections.list(),
|
|
322
|
+
},
|
|
323
|
+
);
|
|
324
|
+
if (parsed.kind === "empty") {
|
|
325
|
+
return { threads: [], nextCursor: null };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const { threads, nextCursor } =
|
|
329
|
+
await context.services.threads.listThreads(
|
|
330
|
+
{
|
|
331
|
+
audience: "author",
|
|
332
|
+
status: input.status,
|
|
333
|
+
selection: parsed.selection,
|
|
334
|
+
lang: input.lang,
|
|
335
|
+
sort: input.sort,
|
|
336
|
+
fold: input.fold,
|
|
337
|
+
},
|
|
338
|
+
{ cursor: input.cursor, limit: input.limit },
|
|
339
|
+
);
|
|
340
|
+
return {
|
|
341
|
+
threads: await loadApiThreadResponses(context, threads),
|
|
342
|
+
nextCursor,
|
|
343
|
+
};
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: "jant_threads_get",
|
|
348
|
+
description:
|
|
349
|
+
"Get the Thread any post belongs to: its root and post count, and with fold the replies the homepage shows.",
|
|
350
|
+
inputSchema: {
|
|
351
|
+
type: "object",
|
|
352
|
+
properties: {
|
|
353
|
+
id: {
|
|
354
|
+
type: "string",
|
|
355
|
+
description: "TypeID of any post in the Thread",
|
|
356
|
+
},
|
|
357
|
+
fold: { type: "boolean" },
|
|
358
|
+
},
|
|
359
|
+
required: ["id"],
|
|
360
|
+
additionalProperties: false,
|
|
361
|
+
},
|
|
362
|
+
async execute(args, context) {
|
|
363
|
+
const input = GetThreadToolSchema.parse(args ?? {});
|
|
364
|
+
const root = await context.services.threads.findRoot(
|
|
365
|
+
{ id: input.id },
|
|
366
|
+
"author",
|
|
367
|
+
);
|
|
368
|
+
if (!root) {
|
|
369
|
+
throw new NotFoundError("Thread");
|
|
370
|
+
}
|
|
371
|
+
const summaries = await context.services.threads.summarize([root], {
|
|
372
|
+
fold: input.fold,
|
|
373
|
+
});
|
|
374
|
+
const [thread] = await loadApiThreadResponses(context, summaries);
|
|
375
|
+
return thread;
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
name: "jant_threads_list_posts",
|
|
380
|
+
description:
|
|
381
|
+
"List the posts of the Thread any post belongs to, root first, in Thread order. Pass nextCursor back as cursor for the next page.",
|
|
382
|
+
inputSchema: {
|
|
383
|
+
type: "object",
|
|
384
|
+
properties: {
|
|
385
|
+
id: {
|
|
386
|
+
type: "string",
|
|
387
|
+
description: "TypeID of any post in the Thread",
|
|
388
|
+
},
|
|
389
|
+
cursor: { type: "string" },
|
|
390
|
+
limit: { type: "integer", minimum: 1, maximum: 100, default: 100 },
|
|
391
|
+
status: { type: "string", enum: [...STATUSES] },
|
|
392
|
+
},
|
|
393
|
+
required: ["id"],
|
|
394
|
+
additionalProperties: false,
|
|
395
|
+
},
|
|
396
|
+
async execute(args, context) {
|
|
397
|
+
const input = ListThreadPostsToolSchema.parse(args ?? {});
|
|
398
|
+
const root = await context.services.threads.findRoot(
|
|
399
|
+
{ id: input.id },
|
|
400
|
+
"author",
|
|
401
|
+
);
|
|
402
|
+
if (!root) {
|
|
403
|
+
throw new NotFoundError("Thread");
|
|
404
|
+
}
|
|
405
|
+
const { posts, nextCursor } = await context.services.threads.listPosts(
|
|
406
|
+
root.id,
|
|
407
|
+
{ audience: "author", status: input.status },
|
|
408
|
+
{ cursor: input.cursor, limit: input.limit },
|
|
409
|
+
);
|
|
410
|
+
return {
|
|
411
|
+
posts: await serializePosts(posts, context),
|
|
412
|
+
nextCursor,
|
|
413
|
+
};
|
|
414
|
+
},
|
|
415
|
+
},
|
|
214
416
|
{
|
|
215
417
|
name: "jant_posts_create",
|
|
216
418
|
description:
|
|
@@ -826,7 +1028,8 @@ const mcpTools: McpToolDefinition[] = [
|
|
|
826
1028
|
},
|
|
827
1029
|
{
|
|
828
1030
|
name: "jant_search_posts",
|
|
829
|
-
description:
|
|
1031
|
+
description:
|
|
1032
|
+
"Search published posts, including private ones. Each result carries its visibility.",
|
|
830
1033
|
inputSchema: {
|
|
831
1034
|
type: "object",
|
|
832
1035
|
properties: {
|
|
@@ -838,21 +1041,25 @@ const mcpTools: McpToolDefinition[] = [
|
|
|
838
1041
|
},
|
|
839
1042
|
async execute(args, context) {
|
|
840
1043
|
const input = SearchPostsToolSchema.parse(args ?? {});
|
|
1044
|
+
// MCP is the author's tool, so private posts match. Each result says
|
|
1045
|
+
// which visibility it has, so an agent can tell before linking one.
|
|
841
1046
|
const results = await context.services.search.search(input.query, {
|
|
842
1047
|
limit: input.limit,
|
|
843
1048
|
status: ["published"],
|
|
1049
|
+
includePrivate: true,
|
|
844
1050
|
});
|
|
845
1051
|
|
|
846
1052
|
return {
|
|
847
1053
|
count: results.length,
|
|
848
1054
|
query: input.query,
|
|
849
|
-
results: results.map((result) =>
|
|
850
|
-
toSearchApiResult(
|
|
1055
|
+
results: results.map((result) => ({
|
|
1056
|
+
...toSearchApiResult(
|
|
851
1057
|
result.post,
|
|
852
1058
|
result.snippet,
|
|
853
1059
|
context.appConfig.sitePathPrefix,
|
|
854
1060
|
),
|
|
855
|
-
|
|
1061
|
+
visibility: result.post.visibility,
|
|
1062
|
+
})),
|
|
856
1063
|
};
|
|
857
1064
|
},
|
|
858
1065
|
},
|
|
@@ -1281,46 +1488,15 @@ async function uploadMediaFromBase64(
|
|
|
1281
1488
|
return serializeMedia(media, context.appConfig);
|
|
1282
1489
|
}
|
|
1283
1490
|
|
|
1284
|
-
|
|
1491
|
+
function serializePosts(
|
|
1285
1492
|
posts: Awaited<ReturnType<Services["posts"]["list"]>>,
|
|
1286
1493
|
context: McpToolContext,
|
|
1287
1494
|
) {
|
|
1288
|
-
|
|
1289
|
-
return [];
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
const postIds = posts.map((post) => post.id);
|
|
1293
|
-
const [mediaMap, collectionMap] = await Promise.all([
|
|
1294
|
-
context.services.media.getByPostIds(postIds),
|
|
1295
|
-
context.services.collections.getCollectionsByPostIds(postIds),
|
|
1296
|
-
]);
|
|
1297
|
-
|
|
1298
|
-
return posts.map((post) =>
|
|
1299
|
-
toApiPost(post, {
|
|
1300
|
-
attachments: serializeAttachments(
|
|
1301
|
-
mediaMap.get(post.id) ?? [],
|
|
1302
|
-
context.appConfig,
|
|
1303
|
-
),
|
|
1304
|
-
collectionIds: (collectionMap.get(post.id) ?? []).map(
|
|
1305
|
-
(collection) => collection.id,
|
|
1306
|
-
),
|
|
1307
|
-
}),
|
|
1308
|
-
);
|
|
1495
|
+
return loadApiPostResponses(context, posts, { collectionIds: true });
|
|
1309
1496
|
}
|
|
1310
1497
|
|
|
1311
|
-
|
|
1312
|
-
post:
|
|
1313
|
-
context: McpToolContext,
|
|
1314
|
-
) {
|
|
1315
|
-
const [mediaList, threadCollections] = await Promise.all([
|
|
1316
|
-
context.services.media.getByPostId(post.id),
|
|
1317
|
-
context.services.collections.getCollectionsByPostId(post.id),
|
|
1318
|
-
]);
|
|
1319
|
-
|
|
1320
|
-
return toApiPost(post, {
|
|
1321
|
-
attachments: serializeAttachments(mediaList, context.appConfig),
|
|
1322
|
-
collectionIds: threadCollections.map((collection) => collection.id),
|
|
1323
|
-
});
|
|
1498
|
+
function serializePost(post: Post, context: McpToolContext) {
|
|
1499
|
+
return loadApiPostResponse(context, post, { collectionIds: true });
|
|
1324
1500
|
}
|
|
1325
1501
|
|
|
1326
1502
|
function serializeMedia(
|
|
@@ -1331,19 +1507,3 @@ function serializeMedia(
|
|
|
1331
1507
|
) {
|
|
1332
1508
|
return toApiMedia(media, appConfig);
|
|
1333
1509
|
}
|
|
1334
|
-
|
|
1335
|
-
function serializeAttachments(
|
|
1336
|
-
mediaList: Awaited<ReturnType<Services["media"]["getByPostId"]>>,
|
|
1337
|
-
appConfig: AppConfig,
|
|
1338
|
-
) {
|
|
1339
|
-
return mediaList.map((media) =>
|
|
1340
|
-
toApiAttachment(
|
|
1341
|
-
media,
|
|
1342
|
-
appConfig.r2PublicUrl,
|
|
1343
|
-
appConfig.imageTransformUrl,
|
|
1344
|
-
appConfig.s3PublicUrl,
|
|
1345
|
-
appConfig.localPublicUrl,
|
|
1346
|
-
appConfig.sitePathPrefix,
|
|
1347
|
-
),
|
|
1348
|
-
);
|
|
1349
|
-
}
|