@mx-space/api-client 1.11.1 → 1.12.0
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/controllers/ai.ts +61 -0
- package/controllers/index.ts +4 -0
- package/controllers/post.ts +2 -1
- package/dist/index.cjs +47 -4
- package/dist/index.d.cts +102 -3
- package/dist/index.d.ts +102 -3
- package/dist/index.global.js +45 -4
- package/dist/index.js +46 -4
- package/models/ai.ts +8 -0
- package/models/index.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
+
import type { IController } from '~/interfaces/controller'
|
|
3
|
+
import type { IRequestHandler } from '~/interfaces/request'
|
|
4
|
+
import type { HTTPClient } from '../core'
|
|
5
|
+
import type { AISummaryModel } from '../models/ai'
|
|
6
|
+
|
|
7
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
8
|
+
|
|
9
|
+
declare module '../core/client' {
|
|
10
|
+
interface HTTPClient<
|
|
11
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
12
|
+
ResponseWrapper = unknown,
|
|
13
|
+
> {
|
|
14
|
+
ai: AIController<ResponseWrapper>
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @support core >= 5.6.0
|
|
20
|
+
*/
|
|
21
|
+
export class AIController<ResponseWrapper> implements IController {
|
|
22
|
+
base = 'ai'
|
|
23
|
+
name = 'ai'
|
|
24
|
+
|
|
25
|
+
constructor(private client: HTTPClient) {
|
|
26
|
+
autoBind(this)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
30
|
+
return this.client.proxy(this.base)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getSummary({
|
|
34
|
+
articleId,
|
|
35
|
+
lang = 'zh-CN',
|
|
36
|
+
onlyDb,
|
|
37
|
+
}: {
|
|
38
|
+
articleId: string
|
|
39
|
+
lang?: string
|
|
40
|
+
onlyDb?: boolean
|
|
41
|
+
}) {
|
|
42
|
+
return this.proxy.summaries.article(articleId).get<AISummaryModel>({
|
|
43
|
+
params: {
|
|
44
|
+
lang,
|
|
45
|
+
onlyDb,
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async generateSummary(articleId: string, lang = 'zh-CN', token = '') {
|
|
51
|
+
return this.proxy('generate-summary').post<AISummaryModel>({
|
|
52
|
+
params: {
|
|
53
|
+
token,
|
|
54
|
+
},
|
|
55
|
+
data: {
|
|
56
|
+
lang,
|
|
57
|
+
refId: articleId,
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
package/controllers/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AckController } from './ack'
|
|
2
2
|
import { ActivityController } from './activity'
|
|
3
3
|
import { AggregateController } from './aggregate'
|
|
4
|
+
import { AIController } from './ai'
|
|
4
5
|
import { CategoryController } from './category'
|
|
5
6
|
import { CommentController } from './comment'
|
|
6
7
|
import { LinkController } from './link'
|
|
@@ -22,6 +23,7 @@ import { TopicController } from './topic'
|
|
|
22
23
|
import { UserController } from './user'
|
|
23
24
|
|
|
24
25
|
export const allControllers = [
|
|
26
|
+
AIController,
|
|
25
27
|
AckController,
|
|
26
28
|
ActivityController,
|
|
27
29
|
AggregateController,
|
|
@@ -43,6 +45,7 @@ export const allControllers = [
|
|
|
43
45
|
]
|
|
44
46
|
|
|
45
47
|
export const allControllerNames = [
|
|
48
|
+
'ai',
|
|
46
49
|
'ack',
|
|
47
50
|
'activity',
|
|
48
51
|
'aggregate',
|
|
@@ -69,6 +72,7 @@ export const allControllerNames = [
|
|
|
69
72
|
] as const
|
|
70
73
|
|
|
71
74
|
export {
|
|
75
|
+
AIController,
|
|
72
76
|
AckController,
|
|
73
77
|
ActivityController,
|
|
74
78
|
AggregateController,
|
package/controllers/post.ts
CHANGED
|
@@ -45,7 +45,7 @@ export class PostController<ResponseWrapper> implements IController {
|
|
|
45
45
|
* @returns
|
|
46
46
|
*/
|
|
47
47
|
getList(page = 1, perPage = 10, options: PostListOptions = {}) {
|
|
48
|
-
const { select, sortBy, sortOrder, year } = options
|
|
48
|
+
const { select, sortBy, sortOrder, year, truncate } = options
|
|
49
49
|
return this.proxy.get<PaginateResult<PostModel>>({
|
|
50
50
|
params: {
|
|
51
51
|
page,
|
|
@@ -54,6 +54,7 @@ export class PostController<ResponseWrapper> implements IController {
|
|
|
54
54
|
sortBy,
|
|
55
55
|
sortOrder,
|
|
56
56
|
year,
|
|
57
|
+
truncate,
|
|
57
58
|
},
|
|
58
59
|
})
|
|
59
60
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// index.ts
|
|
21
21
|
var api_client_exports = {};
|
|
22
22
|
__export(api_client_exports, {
|
|
23
|
+
AIController: () => AIController,
|
|
23
24
|
AckController: () => AckController,
|
|
24
25
|
ActivityController: () => ActivityController,
|
|
25
26
|
AggregateController: () => AggregateController,
|
|
@@ -111,17 +112,19 @@ var camelcaseKeys = (obj) => {
|
|
|
111
112
|
}
|
|
112
113
|
if (isPlainObject(obj)) {
|
|
113
114
|
return Object.keys(obj).reduce((result, key) => {
|
|
114
|
-
|
|
115
|
+
const nextKey = isMongoId(key) ? key : camelcase(key);
|
|
116
|
+
result[nextKey] = camelcaseKeys(obj[key]);
|
|
115
117
|
return result;
|
|
116
118
|
}, {});
|
|
117
119
|
}
|
|
118
120
|
return obj;
|
|
119
121
|
};
|
|
120
122
|
function camelcase(str) {
|
|
121
|
-
return str.replace(/([-_][a-z])/gi, ($1) => {
|
|
123
|
+
return str.replace(/^_+/, "").replace(/([-_][a-z])/gi, ($1) => {
|
|
122
124
|
return $1.toUpperCase().replace("-", "").replace("_", "");
|
|
123
125
|
});
|
|
124
126
|
}
|
|
127
|
+
var isMongoId = (id) => id.length === 24 && /^[0-9a-fA-F]{24}$/.test(id);
|
|
125
128
|
|
|
126
129
|
// utils/path.ts
|
|
127
130
|
var resolveFullPath = (endpoint, path) => {
|
|
@@ -294,6 +297,42 @@ var AggregateController = class {
|
|
|
294
297
|
}
|
|
295
298
|
};
|
|
296
299
|
|
|
300
|
+
// controllers/ai.ts
|
|
301
|
+
var AIController = class {
|
|
302
|
+
constructor(client) {
|
|
303
|
+
this.client = client;
|
|
304
|
+
this.base = "ai";
|
|
305
|
+
this.name = "ai";
|
|
306
|
+
autoBind(this);
|
|
307
|
+
}
|
|
308
|
+
get proxy() {
|
|
309
|
+
return this.client.proxy(this.base);
|
|
310
|
+
}
|
|
311
|
+
async getSummary({
|
|
312
|
+
articleId,
|
|
313
|
+
lang = "zh-CN",
|
|
314
|
+
onlyDb
|
|
315
|
+
}) {
|
|
316
|
+
return this.proxy.summaries.article(articleId).get({
|
|
317
|
+
params: {
|
|
318
|
+
lang,
|
|
319
|
+
onlyDb
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
async generateSummary(articleId, lang = "zh-CN", token = "") {
|
|
324
|
+
return this.proxy("generate-summary").post({
|
|
325
|
+
params: {
|
|
326
|
+
token
|
|
327
|
+
},
|
|
328
|
+
data: {
|
|
329
|
+
lang,
|
|
330
|
+
refId: articleId
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
297
336
|
// core/error.ts
|
|
298
337
|
var RequestError = class extends Error {
|
|
299
338
|
constructor(message, status, path, raw) {
|
|
@@ -595,7 +634,7 @@ var PostController = class {
|
|
|
595
634
|
* @returns
|
|
596
635
|
*/
|
|
597
636
|
getList(page = 1, perPage = 10, options = {}) {
|
|
598
|
-
const { select, sortBy, sortOrder, year } = options;
|
|
637
|
+
const { select, sortBy, sortOrder, year, truncate } = options;
|
|
599
638
|
return this.proxy.get({
|
|
600
639
|
params: {
|
|
601
640
|
page,
|
|
@@ -603,7 +642,8 @@ var PostController = class {
|
|
|
603
642
|
select: select?.join(" "),
|
|
604
643
|
sortBy,
|
|
605
644
|
sortOrder,
|
|
606
|
-
year
|
|
645
|
+
year,
|
|
646
|
+
truncate
|
|
607
647
|
}
|
|
608
648
|
});
|
|
609
649
|
}
|
|
@@ -867,6 +907,7 @@ var UserController = class {
|
|
|
867
907
|
|
|
868
908
|
// controllers/index.ts
|
|
869
909
|
var allControllers = [
|
|
910
|
+
AIController,
|
|
870
911
|
AckController,
|
|
871
912
|
ActivityController,
|
|
872
913
|
AggregateController,
|
|
@@ -887,6 +928,7 @@ var allControllers = [
|
|
|
887
928
|
UserController
|
|
888
929
|
];
|
|
889
930
|
var allControllerNames = [
|
|
931
|
+
"ai",
|
|
890
932
|
"ack",
|
|
891
933
|
"activity",
|
|
892
934
|
"aggregate",
|
|
@@ -1210,6 +1252,7 @@ var SubscribeTypeToBitMap = {
|
|
|
1210
1252
|
var api_client_default = createClient;
|
|
1211
1253
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1212
1254
|
0 && (module.exports = {
|
|
1255
|
+
AIController,
|
|
1213
1256
|
AckController,
|
|
1214
1257
|
ActivityController,
|
|
1215
1258
|
AggregateController,
|
package/dist/index.d.cts
CHANGED
|
@@ -691,6 +691,105 @@ declare class AggregateController<ResponseWrapper> implements IController {
|
|
|
691
691
|
}>;
|
|
692
692
|
}
|
|
693
693
|
|
|
694
|
+
interface AISummaryModel {
|
|
695
|
+
id: string;
|
|
696
|
+
created: string;
|
|
697
|
+
summary: string;
|
|
698
|
+
hash: string;
|
|
699
|
+
refId: string;
|
|
700
|
+
lang: string;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
declare module '../core/client' {
|
|
704
|
+
interface HTTPClient<T extends IRequestAdapter = IRequestAdapter, ResponseWrapper = unknown> {
|
|
705
|
+
ai: AIController<ResponseWrapper>;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* @support core >= 5.6.0
|
|
710
|
+
*/
|
|
711
|
+
declare class AIController<ResponseWrapper> implements IController {
|
|
712
|
+
private client;
|
|
713
|
+
base: string;
|
|
714
|
+
name: string;
|
|
715
|
+
constructor(client: HTTPClient);
|
|
716
|
+
get proxy(): IRequestHandler<ResponseWrapper>;
|
|
717
|
+
getSummary({ articleId, lang, onlyDb, }: {
|
|
718
|
+
articleId: string;
|
|
719
|
+
lang?: string;
|
|
720
|
+
onlyDb?: boolean;
|
|
721
|
+
}): Promise<AISummaryModel & {
|
|
722
|
+
$raw: ResponseWrapper extends {
|
|
723
|
+
data: infer T;
|
|
724
|
+
} ? ResponseWrapper : ResponseWrapper extends unknown ? {
|
|
725
|
+
[i: string]: any;
|
|
726
|
+
data: (ResponseWrapper extends unknown ? {
|
|
727
|
+
[key: string]: any;
|
|
728
|
+
data: AISummaryModel;
|
|
729
|
+
} : ResponseWrapper extends {
|
|
730
|
+
data: AISummaryModel;
|
|
731
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
732
|
+
data: AISummaryModel;
|
|
733
|
+
}) extends infer T_1 ? T_1 extends (ResponseWrapper extends unknown ? {
|
|
734
|
+
[key: string]: any;
|
|
735
|
+
data: AISummaryModel;
|
|
736
|
+
} : ResponseWrapper extends {
|
|
737
|
+
data: AISummaryModel;
|
|
738
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
739
|
+
data: AISummaryModel;
|
|
740
|
+
}) ? T_1 extends unknown ? {
|
|
741
|
+
id: string;
|
|
742
|
+
created: string;
|
|
743
|
+
summary: string;
|
|
744
|
+
hash: string;
|
|
745
|
+
ref_id: string;
|
|
746
|
+
lang: string;
|
|
747
|
+
} : T_1 : never : never;
|
|
748
|
+
} : ResponseWrapper;
|
|
749
|
+
$request: {
|
|
750
|
+
[k: string]: string;
|
|
751
|
+
path: string;
|
|
752
|
+
method: string;
|
|
753
|
+
};
|
|
754
|
+
$serialized: AISummaryModel;
|
|
755
|
+
}>;
|
|
756
|
+
generateSummary(articleId: string, lang?: string, token?: string): Promise<AISummaryModel & {
|
|
757
|
+
$raw: ResponseWrapper extends {
|
|
758
|
+
data: infer T;
|
|
759
|
+
} ? ResponseWrapper : ResponseWrapper extends unknown ? {
|
|
760
|
+
[i: string]: any;
|
|
761
|
+
data: (ResponseWrapper extends unknown ? {
|
|
762
|
+
[key: string]: any;
|
|
763
|
+
data: AISummaryModel;
|
|
764
|
+
} : ResponseWrapper extends {
|
|
765
|
+
data: AISummaryModel;
|
|
766
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
767
|
+
data: AISummaryModel;
|
|
768
|
+
}) extends infer T_1 ? T_1 extends (ResponseWrapper extends unknown ? {
|
|
769
|
+
[key: string]: any;
|
|
770
|
+
data: AISummaryModel;
|
|
771
|
+
} : ResponseWrapper extends {
|
|
772
|
+
data: AISummaryModel;
|
|
773
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
774
|
+
data: AISummaryModel;
|
|
775
|
+
}) ? T_1 extends unknown ? {
|
|
776
|
+
id: string;
|
|
777
|
+
created: string;
|
|
778
|
+
summary: string;
|
|
779
|
+
hash: string;
|
|
780
|
+
ref_id: string;
|
|
781
|
+
lang: string;
|
|
782
|
+
} : T_1 : never : never;
|
|
783
|
+
} : ResponseWrapper;
|
|
784
|
+
$request: {
|
|
785
|
+
[k: string]: string;
|
|
786
|
+
path: string;
|
|
787
|
+
method: string;
|
|
788
|
+
};
|
|
789
|
+
$serialized: AISummaryModel;
|
|
790
|
+
}>;
|
|
791
|
+
}
|
|
792
|
+
|
|
694
793
|
declare module '../core/client' {
|
|
695
794
|
interface HTTPClient<T extends IRequestAdapter = IRequestAdapter, ResponseWrapper = unknown> {
|
|
696
795
|
category: CategoryController<ResponseWrapper>;
|
|
@@ -1700,8 +1799,8 @@ declare class UserController<ResponseWrapper> implements IController {
|
|
|
1700
1799
|
}>;
|
|
1701
1800
|
}
|
|
1702
1801
|
|
|
1703
|
-
declare const allControllers: (typeof AckController | typeof ActivityController | typeof AggregateController | typeof CategoryController | typeof CommentController | typeof LinkController | typeof NoteController | typeof PageController | typeof PostController | typeof ProjectController | typeof RecentlyController | typeof SayController | typeof SearchController | typeof ServerlessController | typeof SnippetController | typeof SubscribeController | typeof TopicController | typeof UserController)[];
|
|
1704
|
-
declare const allControllerNames: readonly ["ack", "activity", "aggregate", "category", "comment", "link", "note", "page", "post", "project", "topic", "recently", "say", "search", "snippet", "serverless", "subscribe", "user", "friend", "master", "shorthand"];
|
|
1802
|
+
declare const allControllers: (typeof AckController | typeof ActivityController | typeof AggregateController | typeof AIController | typeof CategoryController | typeof CommentController | typeof LinkController | typeof NoteController | typeof PageController | typeof PostController | typeof ProjectController | typeof RecentlyController | typeof SayController | typeof SearchController | typeof ServerlessController | typeof SnippetController | typeof SubscribeController | typeof TopicController | typeof UserController)[];
|
|
1803
|
+
declare const allControllerNames: readonly ["ai", "ack", "activity", "aggregate", "category", "comment", "link", "note", "page", "post", "project", "topic", "recently", "say", "search", "snippet", "serverless", "subscribe", "user", "friend", "master", "shorthand"];
|
|
1705
1804
|
|
|
1706
1805
|
declare enum SnippetType {
|
|
1707
1806
|
JSON = "json",
|
|
@@ -1727,4 +1826,4 @@ interface SnippetModel<T = unknown> extends BaseModel {
|
|
|
1727
1826
|
*/
|
|
1728
1827
|
declare const camelcaseKeys: <T = any>(obj: any) => T;
|
|
1729
1828
|
|
|
1730
|
-
export { AckController, ActivityController, type ActivityPresence, AdminExtraModel, AggregateController, type AggregateRoot, type AggregateRootWithTheme, type AggregateStat, type AggregateTop, type AggregateTopNote, type AggregateTopPost, AlgoliaSearchOptionsModel, BackupOptionsModel, BaiduSearchOptionsModel, type BaseCommentIndexModel, type BaseModel, CategoryController, type CategoryEntries, type CategoryModel, CategoryType, type CategoryWithChildrenModel, CollectionRefTypes, CommentController, type CommentDto, type CommentModel, CommentOptionsModel, type CommentRef, CommentState, type Coordinate, type Count, EnumPageType, HTTPClient, type IConfig, type IConfigKeys, IRequestAdapter, type Image, LinkController, type LinkModel, LinkState, LinkType, MailOptionsModel, type ModelWithLiked, NoteController, type NoteModel, type NoteWrappedPayload, type NoteWrappedWithLikedPayload, PageController, type PageModel, type Pager, type PaginateResult, PostController, type PostModel, ProjectController, type ProjectModel, type RecentActivities, type RecentComment, type RecentLike, type RecentNote, type RecentPost, type RecentRecent, RecentlyAttitudeEnum, RecentlyAttitudeResultEnum, RecentlyController, type RecentlyModel, type RecentlyRefType, RecentlyRefTypes, RequestError, type RoomOmittedNote, type RoomOmittedPage, type RoomOmittedPost, type RoomsData, SayController, type SayModel, SearchController, SeoOptionModel, ServerlessController, SnippetController, type SnippetModel, SnippetType, SubscribeAllBit, SubscribeController, SubscribeNoteCreateBit, SubscribePostCreateBit, SubscribeRecentCreateBit, SubscribeSayCreateBit, type SubscribeType, SubscribeTypeToBitMap, type TLogin, type TagModel, type TextBaseModel, type TimelineData, TimelineType, TopicController, type TopicModel, type Url, UrlOptionModel, UserController, type UserModel, allControllerNames, allControllers, createClient, createClient as default, camelcaseKeys as simpleCamelcaseKeys };
|
|
1829
|
+
export { AIController, type AISummaryModel, AckController, ActivityController, type ActivityPresence, AdminExtraModel, AggregateController, type AggregateRoot, type AggregateRootWithTheme, type AggregateStat, type AggregateTop, type AggregateTopNote, type AggregateTopPost, AlgoliaSearchOptionsModel, BackupOptionsModel, BaiduSearchOptionsModel, type BaseCommentIndexModel, type BaseModel, CategoryController, type CategoryEntries, type CategoryModel, CategoryType, type CategoryWithChildrenModel, CollectionRefTypes, CommentController, type CommentDto, type CommentModel, CommentOptionsModel, type CommentRef, CommentState, type Coordinate, type Count, EnumPageType, HTTPClient, type IConfig, type IConfigKeys, IRequestAdapter, type Image, LinkController, type LinkModel, LinkState, LinkType, MailOptionsModel, type ModelWithLiked, NoteController, type NoteModel, type NoteWrappedPayload, type NoteWrappedWithLikedPayload, PageController, type PageModel, type Pager, type PaginateResult, PostController, type PostModel, ProjectController, type ProjectModel, type RecentActivities, type RecentComment, type RecentLike, type RecentNote, type RecentPost, type RecentRecent, RecentlyAttitudeEnum, RecentlyAttitudeResultEnum, RecentlyController, type RecentlyModel, type RecentlyRefType, RecentlyRefTypes, RequestError, type RoomOmittedNote, type RoomOmittedPage, type RoomOmittedPost, type RoomsData, SayController, type SayModel, SearchController, SeoOptionModel, ServerlessController, SnippetController, type SnippetModel, SnippetType, SubscribeAllBit, SubscribeController, SubscribeNoteCreateBit, SubscribePostCreateBit, SubscribeRecentCreateBit, SubscribeSayCreateBit, type SubscribeType, SubscribeTypeToBitMap, type TLogin, type TagModel, type TextBaseModel, type TimelineData, TimelineType, TopicController, type TopicModel, type Url, UrlOptionModel, UserController, type UserModel, allControllerNames, allControllers, createClient, createClient as default, camelcaseKeys as simpleCamelcaseKeys };
|
package/dist/index.d.ts
CHANGED
|
@@ -691,6 +691,105 @@ declare class AggregateController<ResponseWrapper> implements IController {
|
|
|
691
691
|
}>;
|
|
692
692
|
}
|
|
693
693
|
|
|
694
|
+
interface AISummaryModel {
|
|
695
|
+
id: string;
|
|
696
|
+
created: string;
|
|
697
|
+
summary: string;
|
|
698
|
+
hash: string;
|
|
699
|
+
refId: string;
|
|
700
|
+
lang: string;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
declare module '@mx-space/api-client' {
|
|
704
|
+
interface HTTPClient<T extends IRequestAdapter = IRequestAdapter, ResponseWrapper = unknown> {
|
|
705
|
+
ai: AIController<ResponseWrapper>;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* @support core >= 5.6.0
|
|
710
|
+
*/
|
|
711
|
+
declare class AIController<ResponseWrapper> implements IController {
|
|
712
|
+
private client;
|
|
713
|
+
base: string;
|
|
714
|
+
name: string;
|
|
715
|
+
constructor(client: HTTPClient);
|
|
716
|
+
get proxy(): IRequestHandler<ResponseWrapper>;
|
|
717
|
+
getSummary({ articleId, lang, onlyDb, }: {
|
|
718
|
+
articleId: string;
|
|
719
|
+
lang?: string;
|
|
720
|
+
onlyDb?: boolean;
|
|
721
|
+
}): Promise<AISummaryModel & {
|
|
722
|
+
$raw: ResponseWrapper extends {
|
|
723
|
+
data: infer T;
|
|
724
|
+
} ? ResponseWrapper : ResponseWrapper extends unknown ? {
|
|
725
|
+
[i: string]: any;
|
|
726
|
+
data: (ResponseWrapper extends unknown ? {
|
|
727
|
+
[key: string]: any;
|
|
728
|
+
data: AISummaryModel;
|
|
729
|
+
} : ResponseWrapper extends {
|
|
730
|
+
data: AISummaryModel;
|
|
731
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
732
|
+
data: AISummaryModel;
|
|
733
|
+
}) extends infer T_1 ? T_1 extends (ResponseWrapper extends unknown ? {
|
|
734
|
+
[key: string]: any;
|
|
735
|
+
data: AISummaryModel;
|
|
736
|
+
} : ResponseWrapper extends {
|
|
737
|
+
data: AISummaryModel;
|
|
738
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
739
|
+
data: AISummaryModel;
|
|
740
|
+
}) ? T_1 extends unknown ? {
|
|
741
|
+
id: string;
|
|
742
|
+
created: string;
|
|
743
|
+
summary: string;
|
|
744
|
+
hash: string;
|
|
745
|
+
ref_id: string;
|
|
746
|
+
lang: string;
|
|
747
|
+
} : T_1 : never : never;
|
|
748
|
+
} : ResponseWrapper;
|
|
749
|
+
$request: {
|
|
750
|
+
[k: string]: string;
|
|
751
|
+
path: string;
|
|
752
|
+
method: string;
|
|
753
|
+
};
|
|
754
|
+
$serialized: AISummaryModel;
|
|
755
|
+
}>;
|
|
756
|
+
generateSummary(articleId: string, lang?: string, token?: string): Promise<AISummaryModel & {
|
|
757
|
+
$raw: ResponseWrapper extends {
|
|
758
|
+
data: infer T;
|
|
759
|
+
} ? ResponseWrapper : ResponseWrapper extends unknown ? {
|
|
760
|
+
[i: string]: any;
|
|
761
|
+
data: (ResponseWrapper extends unknown ? {
|
|
762
|
+
[key: string]: any;
|
|
763
|
+
data: AISummaryModel;
|
|
764
|
+
} : ResponseWrapper extends {
|
|
765
|
+
data: AISummaryModel;
|
|
766
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
767
|
+
data: AISummaryModel;
|
|
768
|
+
}) extends infer T_1 ? T_1 extends (ResponseWrapper extends unknown ? {
|
|
769
|
+
[key: string]: any;
|
|
770
|
+
data: AISummaryModel;
|
|
771
|
+
} : ResponseWrapper extends {
|
|
772
|
+
data: AISummaryModel;
|
|
773
|
+
} ? ResponseWrapper : Omit<ResponseWrapper, "data"> & {
|
|
774
|
+
data: AISummaryModel;
|
|
775
|
+
}) ? T_1 extends unknown ? {
|
|
776
|
+
id: string;
|
|
777
|
+
created: string;
|
|
778
|
+
summary: string;
|
|
779
|
+
hash: string;
|
|
780
|
+
ref_id: string;
|
|
781
|
+
lang: string;
|
|
782
|
+
} : T_1 : never : never;
|
|
783
|
+
} : ResponseWrapper;
|
|
784
|
+
$request: {
|
|
785
|
+
[k: string]: string;
|
|
786
|
+
path: string;
|
|
787
|
+
method: string;
|
|
788
|
+
};
|
|
789
|
+
$serialized: AISummaryModel;
|
|
790
|
+
}>;
|
|
791
|
+
}
|
|
792
|
+
|
|
694
793
|
declare module '@mx-space/api-client' {
|
|
695
794
|
interface HTTPClient<T extends IRequestAdapter = IRequestAdapter, ResponseWrapper = unknown> {
|
|
696
795
|
category: CategoryController<ResponseWrapper>;
|
|
@@ -1700,8 +1799,8 @@ declare class UserController<ResponseWrapper> implements IController {
|
|
|
1700
1799
|
}>;
|
|
1701
1800
|
}
|
|
1702
1801
|
|
|
1703
|
-
declare const allControllers: (typeof AckController | typeof ActivityController | typeof AggregateController | typeof CategoryController | typeof CommentController | typeof LinkController | typeof NoteController | typeof PageController | typeof PostController | typeof ProjectController | typeof RecentlyController | typeof SayController | typeof SearchController | typeof ServerlessController | typeof SnippetController | typeof SubscribeController | typeof TopicController | typeof UserController)[];
|
|
1704
|
-
declare const allControllerNames: readonly ["ack", "activity", "aggregate", "category", "comment", "link", "note", "page", "post", "project", "topic", "recently", "say", "search", "snippet", "serverless", "subscribe", "user", "friend", "master", "shorthand"];
|
|
1802
|
+
declare const allControllers: (typeof AckController | typeof ActivityController | typeof AggregateController | typeof AIController | typeof CategoryController | typeof CommentController | typeof LinkController | typeof NoteController | typeof PageController | typeof PostController | typeof ProjectController | typeof RecentlyController | typeof SayController | typeof SearchController | typeof ServerlessController | typeof SnippetController | typeof SubscribeController | typeof TopicController | typeof UserController)[];
|
|
1803
|
+
declare const allControllerNames: readonly ["ai", "ack", "activity", "aggregate", "category", "comment", "link", "note", "page", "post", "project", "topic", "recently", "say", "search", "snippet", "serverless", "subscribe", "user", "friend", "master", "shorthand"];
|
|
1705
1804
|
|
|
1706
1805
|
declare enum SnippetType {
|
|
1707
1806
|
JSON = "json",
|
|
@@ -1727,4 +1826,4 @@ interface SnippetModel<T = unknown> extends BaseModel {
|
|
|
1727
1826
|
*/
|
|
1728
1827
|
declare const camelcaseKeys: <T = any>(obj: any) => T;
|
|
1729
1828
|
|
|
1730
|
-
export { AckController, ActivityController, type ActivityPresence, AdminExtraModel, AggregateController, type AggregateRoot, type AggregateRootWithTheme, type AggregateStat, type AggregateTop, type AggregateTopNote, type AggregateTopPost, AlgoliaSearchOptionsModel, BackupOptionsModel, BaiduSearchOptionsModel, type BaseCommentIndexModel, type BaseModel, CategoryController, type CategoryEntries, type CategoryModel, CategoryType, type CategoryWithChildrenModel, CollectionRefTypes, CommentController, type CommentDto, type CommentModel, CommentOptionsModel, type CommentRef, CommentState, type Coordinate, type Count, EnumPageType, HTTPClient, type IConfig, type IConfigKeys, IRequestAdapter, type Image, LinkController, type LinkModel, LinkState, LinkType, MailOptionsModel, type ModelWithLiked, NoteController, type NoteModel, type NoteWrappedPayload, type NoteWrappedWithLikedPayload, PageController, type PageModel, type Pager, type PaginateResult, PostController, type PostModel, ProjectController, type ProjectModel, type RecentActivities, type RecentComment, type RecentLike, type RecentNote, type RecentPost, type RecentRecent, RecentlyAttitudeEnum, RecentlyAttitudeResultEnum, RecentlyController, type RecentlyModel, type RecentlyRefType, RecentlyRefTypes, RequestError, type RoomOmittedNote, type RoomOmittedPage, type RoomOmittedPost, type RoomsData, SayController, type SayModel, SearchController, SeoOptionModel, ServerlessController, SnippetController, type SnippetModel, SnippetType, SubscribeAllBit, SubscribeController, SubscribeNoteCreateBit, SubscribePostCreateBit, SubscribeRecentCreateBit, SubscribeSayCreateBit, type SubscribeType, SubscribeTypeToBitMap, type TLogin, type TagModel, type TextBaseModel, type TimelineData, TimelineType, TopicController, type TopicModel, type Url, UrlOptionModel, UserController, type UserModel, allControllerNames, allControllers, createClient, createClient as default, camelcaseKeys as simpleCamelcaseKeys };
|
|
1829
|
+
export { AIController, type AISummaryModel, AckController, ActivityController, type ActivityPresence, AdminExtraModel, AggregateController, type AggregateRoot, type AggregateRootWithTheme, type AggregateStat, type AggregateTop, type AggregateTopNote, type AggregateTopPost, AlgoliaSearchOptionsModel, BackupOptionsModel, BaiduSearchOptionsModel, type BaseCommentIndexModel, type BaseModel, CategoryController, type CategoryEntries, type CategoryModel, CategoryType, type CategoryWithChildrenModel, CollectionRefTypes, CommentController, type CommentDto, type CommentModel, CommentOptionsModel, type CommentRef, CommentState, type Coordinate, type Count, EnumPageType, HTTPClient, type IConfig, type IConfigKeys, IRequestAdapter, type Image, LinkController, type LinkModel, LinkState, LinkType, MailOptionsModel, type ModelWithLiked, NoteController, type NoteModel, type NoteWrappedPayload, type NoteWrappedWithLikedPayload, PageController, type PageModel, type Pager, type PaginateResult, PostController, type PostModel, ProjectController, type ProjectModel, type RecentActivities, type RecentComment, type RecentLike, type RecentNote, type RecentPost, type RecentRecent, RecentlyAttitudeEnum, RecentlyAttitudeResultEnum, RecentlyController, type RecentlyModel, type RecentlyRefType, RecentlyRefTypes, RequestError, type RoomOmittedNote, type RoomOmittedPage, type RoomOmittedPost, type RoomsData, SayController, type SayModel, SearchController, SeoOptionModel, ServerlessController, SnippetController, type SnippetModel, SnippetType, SubscribeAllBit, SubscribeController, SubscribeNoteCreateBit, SubscribePostCreateBit, SubscribeRecentCreateBit, SubscribeSayCreateBit, type SubscribeType, SubscribeTypeToBitMap, type TLogin, type TagModel, type TextBaseModel, type TimelineData, TimelineType, TopicController, type TopicModel, type Url, UrlOptionModel, UserController, type UserModel, allControllerNames, allControllers, createClient, createClient as default, camelcaseKeys as simpleCamelcaseKeys };
|
package/dist/index.global.js
CHANGED
|
@@ -47,17 +47,19 @@
|
|
|
47
47
|
}
|
|
48
48
|
if (isPlainObject(obj)) {
|
|
49
49
|
return Object.keys(obj).reduce((result, key) => {
|
|
50
|
-
|
|
50
|
+
const nextKey = isMongoId(key) ? key : camelcase(key);
|
|
51
|
+
result[nextKey] = camelcaseKeys(obj[key]);
|
|
51
52
|
return result;
|
|
52
53
|
}, {});
|
|
53
54
|
}
|
|
54
55
|
return obj;
|
|
55
56
|
};
|
|
56
57
|
function camelcase(str) {
|
|
57
|
-
return str.replace(/([-_][a-z])/gi, ($1) => {
|
|
58
|
+
return str.replace(/^_+/, "").replace(/([-_][a-z])/gi, ($1) => {
|
|
58
59
|
return $1.toUpperCase().replace("-", "").replace("_", "");
|
|
59
60
|
});
|
|
60
61
|
}
|
|
62
|
+
var isMongoId = (id) => id.length === 24 && /^[0-9a-fA-F]{24}$/.test(id);
|
|
61
63
|
|
|
62
64
|
// utils/path.ts
|
|
63
65
|
var resolveFullPath = (endpoint, path) => {
|
|
@@ -230,6 +232,42 @@
|
|
|
230
232
|
}
|
|
231
233
|
};
|
|
232
234
|
|
|
235
|
+
// controllers/ai.ts
|
|
236
|
+
var AIController = class {
|
|
237
|
+
constructor(client) {
|
|
238
|
+
this.client = client;
|
|
239
|
+
this.base = "ai";
|
|
240
|
+
this.name = "ai";
|
|
241
|
+
autoBind(this);
|
|
242
|
+
}
|
|
243
|
+
get proxy() {
|
|
244
|
+
return this.client.proxy(this.base);
|
|
245
|
+
}
|
|
246
|
+
async getSummary({
|
|
247
|
+
articleId,
|
|
248
|
+
lang = "zh-CN",
|
|
249
|
+
onlyDb
|
|
250
|
+
}) {
|
|
251
|
+
return this.proxy.summaries.article(articleId).get({
|
|
252
|
+
params: {
|
|
253
|
+
lang,
|
|
254
|
+
onlyDb
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
async generateSummary(articleId, lang = "zh-CN", token = "") {
|
|
259
|
+
return this.proxy("generate-summary").post({
|
|
260
|
+
params: {
|
|
261
|
+
token
|
|
262
|
+
},
|
|
263
|
+
data: {
|
|
264
|
+
lang,
|
|
265
|
+
refId: articleId
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
233
271
|
// core/error.ts
|
|
234
272
|
var RequestError = class extends Error {
|
|
235
273
|
constructor(message, status, path, raw) {
|
|
@@ -531,7 +569,7 @@
|
|
|
531
569
|
* @returns
|
|
532
570
|
*/
|
|
533
571
|
getList(page = 1, perPage = 10, options = {}) {
|
|
534
|
-
const { select, sortBy, sortOrder, year } = options;
|
|
572
|
+
const { select, sortBy, sortOrder, year, truncate } = options;
|
|
535
573
|
return this.proxy.get({
|
|
536
574
|
params: {
|
|
537
575
|
page,
|
|
@@ -539,7 +577,8 @@
|
|
|
539
577
|
select: select?.join(" "),
|
|
540
578
|
sortBy,
|
|
541
579
|
sortOrder,
|
|
542
|
-
year
|
|
580
|
+
year,
|
|
581
|
+
truncate
|
|
543
582
|
}
|
|
544
583
|
});
|
|
545
584
|
}
|
|
@@ -803,6 +842,7 @@
|
|
|
803
842
|
|
|
804
843
|
// controllers/index.ts
|
|
805
844
|
var allControllers = [
|
|
845
|
+
AIController,
|
|
806
846
|
AckController,
|
|
807
847
|
ActivityController,
|
|
808
848
|
AggregateController,
|
|
@@ -823,6 +863,7 @@
|
|
|
823
863
|
UserController
|
|
824
864
|
];
|
|
825
865
|
var allControllerNames = [
|
|
866
|
+
"ai",
|
|
826
867
|
"ack",
|
|
827
868
|
"activity",
|
|
828
869
|
"aggregate",
|
package/dist/index.js
CHANGED
|
@@ -45,17 +45,19 @@ var camelcaseKeys = (obj) => {
|
|
|
45
45
|
}
|
|
46
46
|
if (isPlainObject(obj)) {
|
|
47
47
|
return Object.keys(obj).reduce((result, key) => {
|
|
48
|
-
|
|
48
|
+
const nextKey = isMongoId(key) ? key : camelcase(key);
|
|
49
|
+
result[nextKey] = camelcaseKeys(obj[key]);
|
|
49
50
|
return result;
|
|
50
51
|
}, {});
|
|
51
52
|
}
|
|
52
53
|
return obj;
|
|
53
54
|
};
|
|
54
55
|
function camelcase(str) {
|
|
55
|
-
return str.replace(/([-_][a-z])/gi, ($1) => {
|
|
56
|
+
return str.replace(/^_+/, "").replace(/([-_][a-z])/gi, ($1) => {
|
|
56
57
|
return $1.toUpperCase().replace("-", "").replace("_", "");
|
|
57
58
|
});
|
|
58
59
|
}
|
|
60
|
+
var isMongoId = (id) => id.length === 24 && /^[0-9a-fA-F]{24}$/.test(id);
|
|
59
61
|
|
|
60
62
|
// utils/path.ts
|
|
61
63
|
var resolveFullPath = (endpoint, path) => {
|
|
@@ -228,6 +230,42 @@ var AggregateController = class {
|
|
|
228
230
|
}
|
|
229
231
|
};
|
|
230
232
|
|
|
233
|
+
// controllers/ai.ts
|
|
234
|
+
var AIController = class {
|
|
235
|
+
constructor(client) {
|
|
236
|
+
this.client = client;
|
|
237
|
+
this.base = "ai";
|
|
238
|
+
this.name = "ai";
|
|
239
|
+
autoBind(this);
|
|
240
|
+
}
|
|
241
|
+
get proxy() {
|
|
242
|
+
return this.client.proxy(this.base);
|
|
243
|
+
}
|
|
244
|
+
async getSummary({
|
|
245
|
+
articleId,
|
|
246
|
+
lang = "zh-CN",
|
|
247
|
+
onlyDb
|
|
248
|
+
}) {
|
|
249
|
+
return this.proxy.summaries.article(articleId).get({
|
|
250
|
+
params: {
|
|
251
|
+
lang,
|
|
252
|
+
onlyDb
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
async generateSummary(articleId, lang = "zh-CN", token = "") {
|
|
257
|
+
return this.proxy("generate-summary").post({
|
|
258
|
+
params: {
|
|
259
|
+
token
|
|
260
|
+
},
|
|
261
|
+
data: {
|
|
262
|
+
lang,
|
|
263
|
+
refId: articleId
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
231
269
|
// core/error.ts
|
|
232
270
|
var RequestError = class extends Error {
|
|
233
271
|
constructor(message, status, path, raw) {
|
|
@@ -529,7 +567,7 @@ var PostController = class {
|
|
|
529
567
|
* @returns
|
|
530
568
|
*/
|
|
531
569
|
getList(page = 1, perPage = 10, options = {}) {
|
|
532
|
-
const { select, sortBy, sortOrder, year } = options;
|
|
570
|
+
const { select, sortBy, sortOrder, year, truncate } = options;
|
|
533
571
|
return this.proxy.get({
|
|
534
572
|
params: {
|
|
535
573
|
page,
|
|
@@ -537,7 +575,8 @@ var PostController = class {
|
|
|
537
575
|
select: select?.join(" "),
|
|
538
576
|
sortBy,
|
|
539
577
|
sortOrder,
|
|
540
|
-
year
|
|
578
|
+
year,
|
|
579
|
+
truncate
|
|
541
580
|
}
|
|
542
581
|
});
|
|
543
582
|
}
|
|
@@ -801,6 +840,7 @@ var UserController = class {
|
|
|
801
840
|
|
|
802
841
|
// controllers/index.ts
|
|
803
842
|
var allControllers = [
|
|
843
|
+
AIController,
|
|
804
844
|
AckController,
|
|
805
845
|
ActivityController,
|
|
806
846
|
AggregateController,
|
|
@@ -821,6 +861,7 @@ var allControllers = [
|
|
|
821
861
|
UserController
|
|
822
862
|
];
|
|
823
863
|
var allControllerNames = [
|
|
864
|
+
"ai",
|
|
824
865
|
"ack",
|
|
825
866
|
"activity",
|
|
826
867
|
"aggregate",
|
|
@@ -1143,6 +1184,7 @@ var SubscribeTypeToBitMap = {
|
|
|
1143
1184
|
// index.ts
|
|
1144
1185
|
var api_client_default = createClient;
|
|
1145
1186
|
export {
|
|
1187
|
+
AIController,
|
|
1146
1188
|
AckController,
|
|
1147
1189
|
ActivityController,
|
|
1148
1190
|
AggregateController,
|
package/models/ai.ts
ADDED
package/models/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mx-space/api-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A api client for mx-space server@next",
|
|
6
6
|
"author": "Innei",
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
"tsup": "8.0.2",
|
|
58
58
|
"umi-request": "1.4.0",
|
|
59
59
|
"vite": "^5.1.7",
|
|
60
|
-
"vitest": "
|
|
60
|
+
"vitest": "1.5.2"
|
|
61
61
|
}
|
|
62
62
|
}
|