@acontext/acontext 0.0.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.
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ /**
3
+ * Support for constructing session messages.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AcontextMessage = exports.AcontextMessageSchema = exports.MessagePart = exports.MessagePartSchema = void 0;
7
+ exports.buildAcontextMessage = buildAcontextMessage;
8
+ const zod_1 = require("zod");
9
+ exports.MessagePartSchema = zod_1.z.object({
10
+ type: zod_1.z.string(),
11
+ text: zod_1.z.string().nullable().optional(),
12
+ meta: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable().optional(),
13
+ file_field: zod_1.z.string().nullable().optional(),
14
+ });
15
+ class MessagePart {
16
+ constructor(data) {
17
+ this.type = data.type;
18
+ this.text = data.text ?? null;
19
+ this.meta = data.meta ?? null;
20
+ this.file_field = data.file_field ?? null;
21
+ }
22
+ static textPart(text, options) {
23
+ return new MessagePart({
24
+ type: 'text',
25
+ text,
26
+ meta: options?.meta ?? null,
27
+ });
28
+ }
29
+ static fileFieldPart(fileField, options) {
30
+ return new MessagePart({
31
+ type: 'file',
32
+ file_field: fileField,
33
+ meta: options?.meta ?? null,
34
+ });
35
+ }
36
+ toJSON() {
37
+ return {
38
+ type: this.type,
39
+ text: this.text ?? null,
40
+ meta: this.meta ?? null,
41
+ file_field: this.file_field ?? null,
42
+ };
43
+ }
44
+ }
45
+ exports.MessagePart = MessagePart;
46
+ exports.AcontextMessageSchema = zod_1.z.object({
47
+ role: zod_1.z.enum(['user', 'assistant', 'system']),
48
+ parts: zod_1.z.array(exports.MessagePartSchema),
49
+ meta: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable().optional(),
50
+ });
51
+ class AcontextMessage {
52
+ constructor(data) {
53
+ this.role = data.role;
54
+ this.parts = data.parts.map((p) => p instanceof MessagePart ? p : new MessagePart(p));
55
+ this.meta = data.meta ?? null;
56
+ }
57
+ toJSON() {
58
+ return {
59
+ role: this.role,
60
+ parts: this.parts.map((p) => p.toJSON()),
61
+ meta: this.meta ?? null,
62
+ };
63
+ }
64
+ }
65
+ exports.AcontextMessage = AcontextMessage;
66
+ function buildAcontextMessage(options) {
67
+ if (!['user', 'assistant', 'system'].includes(options.role)) {
68
+ throw new Error("role must be one of {'user', 'assistant', 'system'}");
69
+ }
70
+ const normalizedParts = options.parts.map((part) => {
71
+ if (part instanceof MessagePart) {
72
+ return part;
73
+ }
74
+ if (typeof part === 'string') {
75
+ return MessagePart.textPart(part);
76
+ }
77
+ if (typeof part === 'object' && part !== null) {
78
+ if (!('type' in part)) {
79
+ throw new Error("mapping message parts must include a 'type'");
80
+ }
81
+ return new MessagePart(part);
82
+ }
83
+ throw new TypeError('unsupported message part type');
84
+ });
85
+ return new AcontextMessage({
86
+ role: options.role,
87
+ parts: normalizedParts,
88
+ meta: options.meta ?? null,
89
+ });
90
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Block endpoints.
3
+ */
4
+ import { RequesterProtocol } from '../client-types';
5
+ import { Block } from '../types';
6
+ export declare class BlocksAPI {
7
+ private requester;
8
+ constructor(requester: RequesterProtocol);
9
+ list(spaceId: string, options?: {
10
+ parentId?: string | null;
11
+ blockType?: string | null;
12
+ }): Promise<Block[]>;
13
+ create(spaceId: string, options: {
14
+ blockType: string;
15
+ parentId?: string | null;
16
+ title?: string | null;
17
+ props?: Record<string, unknown> | null;
18
+ }): Promise<Block>;
19
+ delete(spaceId: string, blockId: string): Promise<void>;
20
+ getProperties(spaceId: string, blockId: string): Promise<Block>;
21
+ updateProperties(spaceId: string, blockId: string, options: {
22
+ title?: string | null;
23
+ props?: Record<string, unknown> | null;
24
+ }): Promise<void>;
25
+ move(spaceId: string, blockId: string, options: {
26
+ parentId?: string | null;
27
+ sort?: number | null;
28
+ }): Promise<void>;
29
+ updateSort(spaceId: string, blockId: string, options: {
30
+ sort: number;
31
+ }): Promise<void>;
32
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * Block endpoints.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BlocksAPI = void 0;
7
+ const types_1 = require("../types");
8
+ class BlocksAPI {
9
+ constructor(requester) {
10
+ this.requester = requester;
11
+ }
12
+ async list(spaceId, options) {
13
+ const params = {};
14
+ if (options?.parentId !== undefined && options?.parentId !== null) {
15
+ params.parent_id = options.parentId;
16
+ }
17
+ if (options?.blockType !== undefined && options?.blockType !== null) {
18
+ params.type = options.blockType;
19
+ }
20
+ const data = await this.requester.request('GET', `/space/${spaceId}/block`, {
21
+ params: Object.keys(params).length > 0 ? params : undefined,
22
+ });
23
+ return Array.isArray(data) ? data.map((item) => types_1.BlockSchema.parse(item)) : [];
24
+ }
25
+ async create(spaceId, options) {
26
+ const payload = { type: options.blockType };
27
+ if (options.parentId !== undefined && options.parentId !== null) {
28
+ payload.parent_id = options.parentId;
29
+ }
30
+ if (options.title !== undefined && options.title !== null) {
31
+ payload.title = options.title;
32
+ }
33
+ if (options.props !== undefined && options.props !== null) {
34
+ payload.props = options.props;
35
+ }
36
+ const data = await this.requester.request('POST', `/space/${spaceId}/block`, {
37
+ jsonData: payload,
38
+ });
39
+ return types_1.BlockSchema.parse(data);
40
+ }
41
+ async delete(spaceId, blockId) {
42
+ await this.requester.request('DELETE', `/space/${spaceId}/block/${blockId}`);
43
+ }
44
+ async getProperties(spaceId, blockId) {
45
+ const data = await this.requester.request('GET', `/space/${spaceId}/block/${blockId}/properties`);
46
+ return types_1.BlockSchema.parse(data);
47
+ }
48
+ async updateProperties(spaceId, blockId, options) {
49
+ const payload = {};
50
+ if (options.title !== undefined && options.title !== null) {
51
+ payload.title = options.title;
52
+ }
53
+ if (options.props !== undefined && options.props !== null) {
54
+ payload.props = options.props;
55
+ }
56
+ if (Object.keys(payload).length === 0) {
57
+ throw new Error('title or props must be provided');
58
+ }
59
+ await this.requester.request('PUT', `/space/${spaceId}/block/${blockId}/properties`, {
60
+ jsonData: payload,
61
+ });
62
+ }
63
+ async move(spaceId, blockId, options) {
64
+ const payload = {};
65
+ if (options.parentId !== undefined && options.parentId !== null) {
66
+ payload.parent_id = options.parentId;
67
+ }
68
+ if (options.sort !== undefined && options.sort !== null) {
69
+ payload.sort = options.sort;
70
+ }
71
+ if (Object.keys(payload).length === 0) {
72
+ throw new Error('parentId or sort must be provided');
73
+ }
74
+ await this.requester.request('PUT', `/space/${spaceId}/block/${blockId}/move`, {
75
+ jsonData: payload,
76
+ });
77
+ }
78
+ async updateSort(spaceId, blockId, options) {
79
+ await this.requester.request('PUT', `/space/${spaceId}/block/${blockId}/sort`, {
80
+ jsonData: { sort: options.sort },
81
+ });
82
+ }
83
+ }
84
+ exports.BlocksAPI = BlocksAPI;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Disk and artifact endpoints.
3
+ */
4
+ import { RequesterProtocol } from '../client-types';
5
+ import { FileUpload } from '../uploads';
6
+ import { Artifact, Disk, GetArtifactResp, ListArtifactsResp, ListDisksOutput, UpdateArtifactResp } from '../types';
7
+ export declare class DisksAPI {
8
+ artifacts: DiskArtifactsAPI;
9
+ private requester;
10
+ constructor(requester: RequesterProtocol);
11
+ list(options?: {
12
+ limit?: number | null;
13
+ cursor?: string | null;
14
+ timeDesc?: boolean | null;
15
+ }): Promise<ListDisksOutput>;
16
+ create(): Promise<Disk>;
17
+ delete(diskId: string): Promise<void>;
18
+ }
19
+ export declare class DiskArtifactsAPI {
20
+ private requester;
21
+ constructor(requester: RequesterProtocol);
22
+ upsert(diskId: string, options: {
23
+ file: FileUpload | [string, Buffer | NodeJS.ReadableStream] | [string, Buffer | NodeJS.ReadableStream, string | null];
24
+ filePath?: string | null;
25
+ meta?: Record<string, unknown> | null;
26
+ }): Promise<Artifact>;
27
+ get(diskId: string, options: {
28
+ filePath: string;
29
+ filename: string;
30
+ withPublicUrl?: boolean | null;
31
+ withContent?: boolean | null;
32
+ expire?: number | null;
33
+ }): Promise<GetArtifactResp>;
34
+ update(diskId: string, options: {
35
+ filePath: string;
36
+ filename: string;
37
+ meta: Record<string, unknown>;
38
+ }): Promise<UpdateArtifactResp>;
39
+ delete(diskId: string, options: {
40
+ filePath: string;
41
+ filename: string;
42
+ }): Promise<void>;
43
+ list(diskId: string, options?: {
44
+ path?: string | null;
45
+ }): Promise<ListArtifactsResp>;
46
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /**
3
+ * Disk and artifact endpoints.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DiskArtifactsAPI = exports.DisksAPI = void 0;
7
+ const uploads_1 = require("../uploads");
8
+ const utils_1 = require("../utils");
9
+ const types_1 = require("../types");
10
+ class DisksAPI {
11
+ constructor(requester) {
12
+ this.requester = requester;
13
+ this.artifacts = new DiskArtifactsAPI(requester);
14
+ }
15
+ async list(options) {
16
+ const params = (0, utils_1.buildParams)({
17
+ limit: options?.limit ?? null,
18
+ cursor: options?.cursor ?? null,
19
+ time_desc: options?.timeDesc ?? null,
20
+ });
21
+ const data = await this.requester.request('GET', '/disk', {
22
+ params: Object.keys(params).length > 0 ? params : undefined,
23
+ });
24
+ return types_1.ListDisksOutputSchema.parse(data);
25
+ }
26
+ async create() {
27
+ const data = await this.requester.request('POST', '/disk');
28
+ return types_1.DiskSchema.parse(data);
29
+ }
30
+ async delete(diskId) {
31
+ await this.requester.request('DELETE', `/disk/${diskId}`);
32
+ }
33
+ }
34
+ exports.DisksAPI = DisksAPI;
35
+ class DiskArtifactsAPI {
36
+ constructor(requester) {
37
+ this.requester = requester;
38
+ }
39
+ async upsert(diskId, options) {
40
+ const upload = (0, uploads_1.normalizeFileUpload)(options.file);
41
+ const files = {
42
+ file: upload.asFormData(),
43
+ };
44
+ const form = {};
45
+ if (options.filePath) {
46
+ form.file_path = options.filePath;
47
+ }
48
+ if (options.meta !== undefined && options.meta !== null) {
49
+ form.meta = JSON.stringify(options.meta);
50
+ }
51
+ const data = await this.requester.request('POST', `/disk/${diskId}/artifact`, {
52
+ data: Object.keys(form).length > 0 ? form : undefined,
53
+ files,
54
+ });
55
+ return types_1.ArtifactSchema.parse(data);
56
+ }
57
+ async get(diskId, options) {
58
+ const fullPath = `${options.filePath.replace(/\/$/, '')}/${options.filename}`;
59
+ const params = (0, utils_1.buildParams)({
60
+ file_path: fullPath,
61
+ with_public_url: options.withPublicUrl ?? null,
62
+ with_content: options.withContent ?? null,
63
+ expire: options.expire ?? null,
64
+ });
65
+ const data = await this.requester.request('GET', `/disk/${diskId}/artifact`, {
66
+ params,
67
+ });
68
+ return types_1.GetArtifactRespSchema.parse(data);
69
+ }
70
+ async update(diskId, options) {
71
+ const fullPath = `${options.filePath.replace(/\/$/, '')}/${options.filename}`;
72
+ const payload = {
73
+ file_path: fullPath,
74
+ meta: JSON.stringify(options.meta),
75
+ };
76
+ const data = await this.requester.request('PUT', `/disk/${diskId}/artifact`, {
77
+ jsonData: payload,
78
+ });
79
+ return types_1.UpdateArtifactRespSchema.parse(data);
80
+ }
81
+ async delete(diskId, options) {
82
+ const fullPath = `${options.filePath.replace(/\/$/, '')}/${options.filename}`;
83
+ const params = { file_path: fullPath };
84
+ await this.requester.request('DELETE', `/disk/${diskId}/artifact`, {
85
+ params,
86
+ });
87
+ }
88
+ async list(diskId, options) {
89
+ const params = {};
90
+ if (options?.path !== undefined && options?.path !== null) {
91
+ params.path = options.path;
92
+ }
93
+ const data = await this.requester.request('GET', `/disk/${diskId}/artifact/ls`, {
94
+ params: Object.keys(params).length > 0 ? params : undefined,
95
+ });
96
+ return types_1.ListArtifactsRespSchema.parse(data);
97
+ }
98
+ }
99
+ exports.DiskArtifactsAPI = DiskArtifactsAPI;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Resource API exports
3
+ */
4
+ export * from './spaces';
5
+ export * from './sessions';
6
+ export * from './disks';
7
+ export * from './blocks';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * Resource API exports
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ __exportStar(require("./spaces"), exports);
21
+ __exportStar(require("./sessions"), exports);
22
+ __exportStar(require("./disks"), exports);
23
+ __exportStar(require("./blocks"), exports);
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Sessions endpoints.
3
+ */
4
+ import { RequesterProtocol } from '../client-types';
5
+ import { AcontextMessage } from '../messages';
6
+ import { FileUpload } from '../uploads';
7
+ import { GetMessagesOutput, GetTasksOutput, ListSessionsOutput, Message, Session } from '../types';
8
+ export type MessageBlob = AcontextMessage | Record<string, unknown>;
9
+ export declare class SessionsAPI {
10
+ private requester;
11
+ constructor(requester: RequesterProtocol);
12
+ list(options?: {
13
+ spaceId?: string | null;
14
+ notConnected?: boolean | null;
15
+ limit?: number | null;
16
+ cursor?: string | null;
17
+ timeDesc?: boolean | null;
18
+ }): Promise<ListSessionsOutput>;
19
+ create(options?: {
20
+ spaceId?: string | null;
21
+ configs?: Record<string, unknown>;
22
+ }): Promise<Session>;
23
+ delete(sessionId: string): Promise<void>;
24
+ updateConfigs(sessionId: string, options: {
25
+ configs: Record<string, unknown>;
26
+ }): Promise<void>;
27
+ getConfigs(sessionId: string): Promise<Session>;
28
+ connectToSpace(sessionId: string, options: {
29
+ spaceId: string;
30
+ }): Promise<void>;
31
+ getTasks(sessionId: string, options?: {
32
+ limit?: number | null;
33
+ cursor?: string | null;
34
+ timeDesc?: boolean | null;
35
+ }): Promise<GetTasksOutput>;
36
+ sendMessage(sessionId: string, blob: MessageBlob, options?: {
37
+ format?: 'acontext' | 'openai' | 'anthropic';
38
+ fileField?: string | null;
39
+ file?: FileUpload | null;
40
+ }): Promise<Message>;
41
+ getMessages(sessionId: string, options?: {
42
+ limit?: number | null;
43
+ cursor?: string | null;
44
+ withAssetPublicUrl?: boolean | null;
45
+ format?: 'acontext' | 'openai' | 'anthropic';
46
+ timeDesc?: boolean | null;
47
+ }): Promise<GetMessagesOutput>;
48
+ }
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ /**
3
+ * Sessions endpoints.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SessionsAPI = void 0;
7
+ const messages_1 = require("../messages");
8
+ const utils_1 = require("../utils");
9
+ const types_1 = require("../types");
10
+ class SessionsAPI {
11
+ constructor(requester) {
12
+ this.requester = requester;
13
+ }
14
+ async list(options) {
15
+ const params = {};
16
+ if (options?.spaceId) {
17
+ params.space_id = options.spaceId;
18
+ }
19
+ Object.assign(params, (0, utils_1.buildParams)({
20
+ not_connected: options?.notConnected ?? null,
21
+ limit: options?.limit ?? null,
22
+ cursor: options?.cursor ?? null,
23
+ time_desc: options?.timeDesc ?? null,
24
+ }));
25
+ const data = await this.requester.request('GET', '/session', {
26
+ params: Object.keys(params).length > 0 ? params : undefined,
27
+ });
28
+ return types_1.ListSessionsOutputSchema.parse(data);
29
+ }
30
+ async create(options) {
31
+ const payload = {};
32
+ if (options?.spaceId) {
33
+ payload.space_id = options.spaceId;
34
+ }
35
+ if (options?.configs !== undefined) {
36
+ payload.configs = options.configs;
37
+ }
38
+ const data = await this.requester.request('POST', '/session', {
39
+ jsonData: Object.keys(payload).length > 0 ? payload : undefined,
40
+ });
41
+ return types_1.SessionSchema.parse(data);
42
+ }
43
+ async delete(sessionId) {
44
+ await this.requester.request('DELETE', `/session/${sessionId}`);
45
+ }
46
+ async updateConfigs(sessionId, options) {
47
+ const payload = { configs: options.configs };
48
+ await this.requester.request('PUT', `/session/${sessionId}/configs`, {
49
+ jsonData: payload,
50
+ });
51
+ }
52
+ async getConfigs(sessionId) {
53
+ const data = await this.requester.request('GET', `/session/${sessionId}/configs`);
54
+ return types_1.SessionSchema.parse(data);
55
+ }
56
+ async connectToSpace(sessionId, options) {
57
+ const payload = { space_id: options.spaceId };
58
+ await this.requester.request('POST', `/session/${sessionId}/connect_to_space`, {
59
+ jsonData: payload,
60
+ });
61
+ }
62
+ async getTasks(sessionId, options) {
63
+ const params = (0, utils_1.buildParams)({
64
+ limit: options?.limit ?? null,
65
+ cursor: options?.cursor ?? null,
66
+ time_desc: options?.timeDesc ?? null,
67
+ });
68
+ const data = await this.requester.request('GET', `/session/${sessionId}/task`, {
69
+ params: Object.keys(params).length > 0 ? params : undefined,
70
+ });
71
+ return types_1.GetTasksOutputSchema.parse(data);
72
+ }
73
+ async sendMessage(sessionId, blob, options) {
74
+ const format = options?.format ?? 'openai';
75
+ if (!['acontext', 'openai', 'anthropic'].includes(format)) {
76
+ throw new Error("format must be one of {'acontext', 'openai', 'anthropic'}");
77
+ }
78
+ if (options?.file && !options?.fileField) {
79
+ throw new Error('fileField is required when file is provided');
80
+ }
81
+ const payload = {
82
+ format,
83
+ };
84
+ if (format === 'acontext') {
85
+ if (blob instanceof messages_1.AcontextMessage) {
86
+ payload.blob = blob.toJSON();
87
+ }
88
+ else {
89
+ // Try to parse as AcontextMessageInput
90
+ // MessageBlob can be Record<string, unknown>, which may not match AcontextMessageInput exactly
91
+ const message = new messages_1.AcontextMessage(blob);
92
+ payload.blob = message.toJSON();
93
+ }
94
+ }
95
+ else {
96
+ payload.blob = blob;
97
+ }
98
+ if (options?.file && options?.fileField) {
99
+ const formData = {
100
+ payload: JSON.stringify(payload),
101
+ };
102
+ const files = {
103
+ [options.fileField]: options.file.asFormData(),
104
+ };
105
+ const data = await this.requester.request('POST', `/session/${sessionId}/messages`, {
106
+ data: formData,
107
+ files,
108
+ });
109
+ return types_1.MessageSchema.parse(data);
110
+ }
111
+ else {
112
+ const data = await this.requester.request('POST', `/session/${sessionId}/messages`, {
113
+ jsonData: payload,
114
+ });
115
+ return types_1.MessageSchema.parse(data);
116
+ }
117
+ }
118
+ async getMessages(sessionId, options) {
119
+ const params = {};
120
+ if (options?.format !== undefined) {
121
+ params.format = options.format;
122
+ }
123
+ Object.assign(params, (0, utils_1.buildParams)({
124
+ limit: options?.limit ?? null,
125
+ cursor: options?.cursor ?? null,
126
+ with_asset_public_url: options?.withAssetPublicUrl ?? null,
127
+ time_desc: options?.timeDesc ?? null,
128
+ }));
129
+ const data = await this.requester.request('GET', `/session/${sessionId}/messages`, {
130
+ params: Object.keys(params).length > 0 ? params : undefined,
131
+ });
132
+ return types_1.GetMessagesOutputSchema.parse(data);
133
+ }
134
+ }
135
+ exports.SessionsAPI = SessionsAPI;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Spaces endpoints.
3
+ */
4
+ import { RequesterProtocol } from '../client-types';
5
+ import { ListSpacesOutput, Space } from '../types';
6
+ export declare class SpacesAPI {
7
+ private requester;
8
+ constructor(requester: RequesterProtocol);
9
+ list(options?: {
10
+ limit?: number | null;
11
+ cursor?: string | null;
12
+ timeDesc?: boolean | null;
13
+ }): Promise<ListSpacesOutput>;
14
+ create(options?: {
15
+ configs?: Record<string, unknown>;
16
+ }): Promise<Space>;
17
+ delete(spaceId: string): Promise<void>;
18
+ updateConfigs(spaceId: string, options: {
19
+ configs: Record<string, unknown>;
20
+ }): Promise<void>;
21
+ getConfigs(spaceId: string): Promise<Space>;
22
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Spaces endpoints.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SpacesAPI = void 0;
7
+ const utils_1 = require("../utils");
8
+ const types_1 = require("../types");
9
+ class SpacesAPI {
10
+ constructor(requester) {
11
+ this.requester = requester;
12
+ }
13
+ async list(options) {
14
+ const params = (0, utils_1.buildParams)({
15
+ limit: options?.limit ?? null,
16
+ cursor: options?.cursor ?? null,
17
+ time_desc: options?.timeDesc ?? null,
18
+ });
19
+ const data = await this.requester.request('GET', '/space', {
20
+ params: Object.keys(params).length > 0 ? params : undefined,
21
+ });
22
+ return types_1.ListSpacesOutputSchema.parse(data);
23
+ }
24
+ async create(options) {
25
+ const payload = {};
26
+ if (options?.configs !== undefined) {
27
+ payload.configs = options.configs;
28
+ }
29
+ const data = await this.requester.request('POST', '/space', {
30
+ jsonData: Object.keys(payload).length > 0 ? payload : undefined,
31
+ });
32
+ return types_1.SpaceSchema.parse(data);
33
+ }
34
+ async delete(spaceId) {
35
+ await this.requester.request('DELETE', `/space/${spaceId}`);
36
+ }
37
+ async updateConfigs(spaceId, options) {
38
+ const payload = { configs: options.configs };
39
+ await this.requester.request('PUT', `/space/${spaceId}/configs`, {
40
+ jsonData: payload,
41
+ });
42
+ }
43
+ async getConfigs(spaceId) {
44
+ const data = await this.requester.request('GET', `/space/${spaceId}/configs`);
45
+ return types_1.SpaceSchema.parse(data);
46
+ }
47
+ }
48
+ exports.SpacesAPI = SpacesAPI;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Type definitions for block resources.
3
+ */
4
+ import { z } from 'zod';
5
+ export declare const BlockSchema: z.ZodType<Block>;
6
+ export type Block = {
7
+ id: string;
8
+ space_id: string;
9
+ type: string;
10
+ parent_id?: string | null;
11
+ title: string;
12
+ props: Record<string, unknown>;
13
+ sort: number;
14
+ is_archived: boolean;
15
+ created_at: string;
16
+ updated_at: string;
17
+ children?: Block[] | null;
18
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * Type definitions for block resources.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BlockSchema = void 0;
7
+ const zod_1 = require("zod");
8
+ exports.BlockSchema = zod_1.z.lazy(() => zod_1.z.object({
9
+ id: zod_1.z.string(),
10
+ space_id: zod_1.z.string(),
11
+ type: zod_1.z.string(),
12
+ parent_id: zod_1.z.string().nullable().optional(),
13
+ title: zod_1.z.string(),
14
+ props: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
15
+ sort: zod_1.z.number(),
16
+ is_archived: zod_1.z.boolean(),
17
+ created_at: zod_1.z.string(),
18
+ updated_at: zod_1.z.string(),
19
+ children: zod_1.z.array(exports.BlockSchema).nullable().optional(),
20
+ }));