@tbox-dev-js/sdk 0.1.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.
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @tbox/sdk — ResourceSchema 类型体系
3
+ *
4
+ * 用 JSON Schema 风格统一描述所有 API 资源的入参、出参和元信息,
5
+ * 端侧可据此动态渲染表单、校验参数、生成配置。
6
+ *
7
+ * 设计原则:
8
+ * - 对齐 JSON Schema Draft 7 的 property 描述格式
9
+ * - 每个 API 操作(Operation)独立描述入参 + 出参 schema
10
+ * - 所有资源通过 ResourceDefinition 统一注册
11
+ * - 支持嵌套子资源(如 knowledge.documents)
12
+ */
13
+ /** Supported JSON Schema types */
14
+ export type SchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'file';
15
+ /** Single property descriptor — aligned with JSON Schema property format */
16
+ export interface PropertySchema {
17
+ /** JSON Schema type */
18
+ type: SchemaType;
19
+ /** Human-readable description */
20
+ description: string;
21
+ /** Whether this field is required */
22
+ required?: boolean;
23
+ /** Default value */
24
+ default?: unknown;
25
+ /** Allowed values (enum constraint) */
26
+ enum?: unknown[];
27
+ /** For array type: schema of each item */
28
+ items?: PropertySchema | ObjectSchema;
29
+ /** For object type: nested properties */
30
+ properties?: Record<string, PropertySchema>;
31
+ /** Display format hint for UI rendering (e.g. "textarea", "select", "file-upload") */
32
+ format?: string;
33
+ /** Example value for documentation */
34
+ example?: unknown;
35
+ /** Minimum value (for number/integer) */
36
+ minimum?: number;
37
+ /** Maximum value (for number/integer) */
38
+ maximum?: number;
39
+ /** Min length (for string/array) */
40
+ minLength?: number;
41
+ /** Max length (for string/array) */
42
+ maxLength?: number;
43
+ /** Regex pattern (for string) */
44
+ pattern?: string;
45
+ }
46
+ /** Object schema — a collection of named properties */
47
+ export interface ObjectSchema {
48
+ type: 'object';
49
+ description?: string;
50
+ properties: Record<string, PropertySchema>;
51
+ required?: string[];
52
+ }
53
+ /** HTTP method */
54
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
55
+ /** Content type for request body */
56
+ export type ContentType = 'application/json' | 'multipart/form-data' | 'none';
57
+ /** Complete description of a single API operation */
58
+ export interface OperationSchema {
59
+ /** Operation identifier (e.g. "list", "retrieve", "create", "update") */
60
+ operationId: string;
61
+ /** Human-readable summary */
62
+ summary: string;
63
+ /** Detailed description */
64
+ description?: string;
65
+ /** HTTP method */
66
+ method: HttpMethod;
67
+ /** API path (relative to baseURL) */
68
+ path: string;
69
+ /** Request content type */
70
+ contentType: ContentType;
71
+ /** Input parameters schema */
72
+ params: ObjectSchema;
73
+ /** Response data schema (the unwrapped business data, not the raw envelope) */
74
+ response: ObjectSchema;
75
+ /** Tags for grouping/filtering */
76
+ tags?: string[];
77
+ }
78
+ /** Complete definition of a resource module */
79
+ export interface ResourceDefinition {
80
+ /** Resource name (e.g. "knowledge", "plugins", "chat") */
81
+ name: string;
82
+ /** Human-readable display name */
83
+ displayName: string;
84
+ /** Resource description */
85
+ description: string;
86
+ /** API operations provided by this resource */
87
+ operations: OperationSchema[];
88
+ /** Nested sub-resources (e.g. knowledge.documents) */
89
+ subResources?: ResourceDefinition[];
90
+ }
91
+ /** Registry that holds all resource definitions */
92
+ export declare class SchemaRegistry {
93
+ private resources;
94
+ /** Register a resource definition */
95
+ register(definition: ResourceDefinition): void;
96
+ /** Get a resource definition by name */
97
+ get(name: string): ResourceDefinition | undefined;
98
+ /** Get all registered resource definitions */
99
+ list(): ResourceDefinition[];
100
+ /** Get a specific operation by resource name and operation ID */
101
+ getOperation(resourceName: string, operationId: string): OperationSchema | undefined;
102
+ /** Export all schemas as a plain JSON-serializable object */
103
+ toJSON(): Record<string, ResourceDefinition>;
104
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @tbox/sdk — TboxAPI 入口类
3
+ *
4
+ * SDK 的唯一入口,继承 APIClient,通过属性访问子模块。
5
+ * 内置 SchemaRegistry,自动注册所有资源的 JSON Schema 定义。
6
+ */
7
+ import { APIClient } from './core';
8
+ import type { ClientOptions } from './core';
9
+ import { Knowledge } from './resources/knowledge/index';
10
+ import { SchemaRegistry } from './schema';
11
+ export declare class TboxAPI extends APIClient {
12
+ /** Knowledge base management (list, retrieve, documents.create, documents.update). */
13
+ readonly knowledge: Knowledge;
14
+ /** Schema registry — JSON Schema definitions for all resources, available for client-side parsing. */
15
+ readonly schemas: SchemaRegistry;
16
+ constructor(options: ClientOptions);
17
+ }