@kmlckj/licos-platform-sdk 0.6.7 → 0.6.9

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 CHANGED
@@ -21,6 +21,8 @@ Database CRUD helpers call the runtime database data plane only. Tooling helpers
21
21
  can fetch platform schema metadata for ORM export. The SDK does not expose
22
22
  service deletion APIs.
23
23
 
24
+ `database.table(name)` is a query builder. Use it for `select` queries only.
25
+
24
26
  ```js
25
27
  import { database } from '@kmlckj/licos-platform-sdk';
26
28
 
@@ -33,63 +35,89 @@ const rows = await database
33
35
  .execute();
34
36
  ```
35
37
 
36
- ORM export is a tooling helper. It fetches platform schema metadata and returns
37
- source text; it does not use direct database credentials.
38
+ Use top-level helpers for mutations:
38
39
 
39
40
  ```js
40
41
  import { database } from '@kmlckj/licos-platform-sdk';
41
42
 
42
- const source = await database.exportOrm({ language: 'typescript', orm: 'drizzle' });
43
- ```
44
-
45
- Studio project database management is exposed through `studioDatabase` for
46
- server-side tooling flows. Use it for tables, rows, controlled SQL, migrations,
47
- sync, and backup. Do not import it into browser/client bundles.
48
-
49
- ```js
50
- import { studioDatabase } from '@kmlckj/licos-platform-sdk';
51
-
52
- await studioDatabase.createTable('users', {
53
- columns: [{ name: 'email', type: 'text', nullable: false }],
54
- });
55
-
56
- const schema = await studioDatabase.getSchema({ environment: 'dev' });
57
- ```
58
-
59
- ## Object Storage
60
-
61
- ```js
62
- import { storage } from '@kmlckj/licos-platform-sdk';
63
-
43
+ const inserted = await database.insert('todos', {
44
+ row: { title: 'Call customer', done: false },
45
+ returning: true,
46
+ });
47
+
48
+ await database.updateRows('todos', {
49
+ filters: [{ field: 'id', op: 'eq', value: inserted.data?.[0]?.id }],
50
+ values: { done: true },
51
+ });
52
+
53
+ await database.deleteRows('todos', {
54
+ filters: [{ field: 'done', op: 'eq', value: true }],
55
+ });
56
+ ```
57
+
58
+ Do not call `.table('todos').insert(...)`, `.table('todos').updateRows(...)`,
59
+ or `.table('todos').deleteRows(...)`; those methods do not exist on the query
60
+ builder.
61
+
62
+ ORM export is a tooling helper. It fetches platform schema metadata and returns
63
+ source text; it does not use direct database credentials.
64
+
65
+ ```js
66
+ import { database } from '@kmlckj/licos-platform-sdk';
67
+
68
+ const source = await database.exportOrm({ language: 'typescript', orm: 'drizzle' });
69
+ ```
70
+
71
+ Studio project database management is exposed through `studioDatabase` for
72
+ server-side tooling flows. Use it for tables, rows, controlled SQL, migrations,
73
+ sync, and backup. Do not import it into browser/client bundles. Do not put
74
+ schema creation or migration logic in normal project runtime request handlers;
75
+ run those operations from LICOS agent/tooling flows before the app starts.
76
+
77
+ ```js
78
+ import { studioDatabase } from '@kmlckj/licos-platform-sdk';
79
+
80
+ await studioDatabase.createTable('users', {
81
+ columns: [{ name: 'email', type: 'text', nullable: false }],
82
+ });
83
+
84
+ const schema = await studioDatabase.getSchema({ environment: 'dev' });
85
+ ```
86
+
87
+ ## Object Storage
88
+
89
+ ```js
90
+ import { storage } from '@kmlckj/licos-platform-sdk';
91
+
64
92
  await storage.createFolder('reports');
65
93
  const file = await storage.uploadFile('/tmp/report.pdf');
66
94
  const link = await storage.shareUrl(file.id);
67
95
  ```
68
96
 
69
97
  `uploadFile` limits each file to 20 MiB.
70
-
71
- The browser entry does not export object storage helpers because runtime tokens
72
- must not be bundled into public frontend code.
73
-
74
- ## Knowledge
75
-
76
- Knowledge helpers import project documents and run semantic retrieval through
77
- the LICOS Knowledge API. Search without dataset filters retrieves from all
78
- accessible datasets. Use dataset IDs or names only when the user explicitly
79
- targets a specific knowledge base.
80
-
81
- ```js
82
- import { knowledge } from '@kmlckj/licos-platform-sdk';
83
-
84
- await knowledge.addText('FAQ content', {
85
- datasetName: 'project_docs',
86
- name: 'faq.txt',
87
- });
88
-
89
- const results = await knowledge.search('How do I reset my password?', {
90
- topK: 5,
91
- });
92
- ```
93
-
94
- The browser entry does not export knowledge helpers because runtime tokens must
95
- not be bundled into public frontend code.
98
+
99
+ The browser entry does not export object storage helpers because runtime tokens
100
+ must not be bundled into public frontend code.
101
+
102
+ ## Knowledge
103
+
104
+ Knowledge helpers import project documents and run semantic retrieval through
105
+ the LICOS Knowledge API. Search without dataset filters retrieves from all
106
+ accessible datasets. Use dataset IDs or names only when the user explicitly
107
+ targets a specific knowledge base.
108
+
109
+ ```js
110
+ import { knowledge } from '@kmlckj/licos-platform-sdk';
111
+
112
+ await knowledge.addText('FAQ content', {
113
+ datasetName: 'project_docs',
114
+ name: 'faq.txt',
115
+ });
116
+
117
+ const results = await knowledge.search('How do I reset my password?', {
118
+ topK: 5,
119
+ });
120
+ ```
121
+
122
+ The browser entry does not export knowledge helpers because runtime tokens must
123
+ not be bundled into public frontend code.
package/dist/index.d.ts CHANGED
@@ -4,218 +4,239 @@ export class PlatformSdkError extends Error {
4
4
  details?: unknown;
5
5
  }
6
6
 
7
- export class ConfigurationError extends PlatformSdkError {}
8
- export class ApiError extends PlatformSdkError {}
9
-
10
- export const DataSourceType: {
11
- TEXT: 0;
12
- URL: 1;
13
- URI: 2;
14
- };
15
-
16
- export type KnowledgeDataSourceType = 0 | 1 | 2 | 'text' | 'url' | 'uri' | 'raw' | 'content' | 'web' | 'file' | 'source_file_id';
17
-
18
- export interface KnowledgeChunkConfig {
19
- separator?: string;
20
- maxTokens?: number;
21
- max_tokens?: number;
22
- removeExtraSpaces?: boolean;
23
- remove_extra_spaces?: boolean;
24
- removeUrlsEmails?: boolean;
25
- remove_urls_emails?: boolean;
26
- }
27
-
28
- export class ChunkConfig {
29
- separator: string;
30
- max_tokens: number;
31
- remove_extra_spaces: boolean;
32
- remove_urls_emails: boolean;
33
- constructor(options?: KnowledgeChunkConfig);
34
- }
35
-
36
- export interface KnowledgeDocumentOptions {
37
- source?: KnowledgeDataSourceType;
38
- source_type?: KnowledgeDataSourceType;
39
- raw_data?: string;
40
- content?: string;
41
- text?: string;
42
- url?: string;
43
- web_url?: string;
44
- uri?: string;
45
- source_file_id?: string;
46
- name?: string;
47
- file_type?: string;
48
- update_rule?: Record<string, unknown>;
49
- }
50
-
51
- export class KnowledgeDocument {
52
- constructor(options?: KnowledgeDocumentOptions);
53
- }
54
-
55
- export interface KnowledgeDataset {
56
- name?: string;
57
- description?: string;
58
- status?: number;
59
- dataset_id?: string;
60
- space_id?: string;
61
- doc_count?: number;
62
- slice_count?: number;
63
- search_method?: string;
64
- supported_search_methods?: string[];
65
- [key: string]: unknown;
66
- }
67
-
68
- export interface ListDatasetsOptions {
69
- name?: string;
70
- spaceId?: string;
71
- space_id?: string;
72
- formatType?: number;
73
- format_type?: number;
74
- pageSize?: number;
75
- page_size?: number;
76
- pageNum?: number;
77
- page_num?: number;
78
- }
79
-
80
- export interface CreateDatasetOptions {
81
- description?: string;
82
- spaceId?: string;
83
- space_id?: string;
84
- config?: Record<string, unknown>;
85
- formatType?: number;
86
- format_type?: number;
87
- sourceType?: string;
88
- source_type?: string;
89
- engineType?: string;
90
- engine_type?: string;
91
- accessScope?: string;
92
- access_scope?: string;
93
- multimodalEnabled?: boolean;
94
- multimodal_enabled?: boolean;
95
- graphEnabled?: boolean;
96
- graph_enabled?: boolean;
97
- embeddingModel?: string;
98
- embedding_model?: string;
99
- embeddingDim?: number;
100
- embedding_dim?: number;
101
- chunkingStrategy?: Record<string, unknown>;
102
- chunking_strategy?: Record<string, unknown>;
103
- processingProfile?: Record<string, unknown>;
104
- processing_profile?: Record<string, unknown>;
105
- }
106
-
107
- export interface AddDocumentsOptions {
108
- datasetId?: string;
109
- dataset_id?: string;
110
- datasetName?: string;
111
- dataset_name?: string;
112
- chunkConfig?: KnowledgeChunkConfig | ChunkConfig | Record<string, unknown>;
113
- chunk_config?: KnowledgeChunkConfig | ChunkConfig | Record<string, unknown>;
114
- formatType?: number;
115
- format_type?: number;
116
- batchId?: string;
117
- batch_id?: string;
118
- batchName?: string;
119
- batch_name?: string;
120
- processingProfile?: Record<string, unknown>;
121
- processing_profile?: Record<string, unknown>;
122
- chunkingStrategy?: Record<string, unknown>;
123
- chunking_strategy?: Record<string, unknown>;
124
- name?: string;
125
- }
126
-
127
- export interface SearchKnowledgeOptions {
128
- datasetId?: string;
129
- dataset_id?: string;
130
- datasetIds?: string[];
131
- dataset_ids?: string[];
132
- datasetName?: string;
133
- dataset_name?: string;
134
- datasetNames?: string[];
135
- dataset_names?: string[];
136
- topK?: number;
137
- top_k?: number;
138
- minScore?: number;
139
- min_score?: number;
140
- candidateTopK?: number;
141
- candidate_top_k?: number;
142
- searchMethod?: string;
143
- search_method?: string;
144
- enableRerank?: boolean;
145
- enable_rerank?: boolean;
146
- needCitation?: boolean;
147
- need_citation?: boolean;
148
- needTrace?: boolean;
149
- need_trace?: boolean;
150
- }
151
-
152
- export interface KnowledgeDocumentInfo {
153
- id?: string;
154
- sourceId?: string;
155
- name?: string;
156
- contentType?: string;
157
- fileSize?: number;
158
- status?: string;
159
- errorMessage?: string;
160
- chunkCount?: number;
161
- createdAt?: string;
162
- [key: string]: unknown;
163
- }
164
-
165
- export interface KnowledgeSearchResult {
166
- segment_infos?: Array<{
167
- content?: string;
168
- score?: number;
169
- metadata?: Record<string, unknown>;
170
- segment_id?: string;
171
- dataset_id?: string;
172
- document_id?: string;
173
- document_name?: string;
174
- [key: string]: unknown;
175
- }>;
176
- citations?: unknown[];
177
- request_id?: string;
178
- dataset_ids?: string[];
179
- route_trace?: Record<string, unknown>;
180
- [key: string]: unknown;
181
- }
182
-
183
- export function runtime(): Promise<Record<string, unknown>>;
184
- export function modelCatalog(): Promise<Record<string, unknown>>;
185
- export function listDatasets(options?: ListDatasetsOptions): Promise<{ total_count?: number; dataset_list?: KnowledgeDataset[]; [key: string]: unknown }>;
186
- export function getDataset(datasetId: string): Promise<KnowledgeDataset>;
187
- export function createDataset(name: string, options?: CreateDatasetOptions): Promise<KnowledgeDataset>;
188
- export function deleteDataset(datasetId: string): Promise<void>;
189
- export function findDatasetByName(name: string): Promise<KnowledgeDataset | null>;
190
- export function ensureDataset(name: string, options?: CreateDatasetOptions): Promise<KnowledgeDataset>;
191
- export function addDocuments(documents: KnowledgeDocumentOptions[], options?: AddDocumentsOptions): Promise<{ document_infos?: KnowledgeDocumentInfo[]; [key: string]: unknown }>;
192
- export function addText(content: string, options?: AddDocumentsOptions): Promise<{ document_infos?: KnowledgeDocumentInfo[]; [key: string]: unknown }>;
193
- export function addUrl(url: string, options?: AddDocumentsOptions): Promise<{ document_infos?: KnowledgeDocumentInfo[]; [key: string]: unknown }>;
194
- export function listDocuments(datasetId: string, options?: { page?: number; size?: number }): Promise<{ total?: number; document_infos?: KnowledgeDocumentInfo[]; [key: string]: unknown }>;
195
- export function deleteDocuments(datasetId: string, documentIds: string[]): Promise<void>;
196
- export function search(query: string, options?: SearchKnowledgeOptions): Promise<KnowledgeSearchResult>;
197
-
198
- export const knowledge: {
199
- DataSourceType: typeof DataSourceType;
200
- ChunkConfig: typeof ChunkConfig;
201
- KnowledgeDocument: typeof KnowledgeDocument;
202
- runtime: typeof runtime;
203
- modelCatalog: typeof modelCatalog;
204
- listDatasets: typeof listDatasets;
205
- getDataset: typeof getDataset;
206
- createDataset: typeof createDataset;
207
- deleteDataset: typeof deleteDataset;
208
- findDatasetByName: typeof findDatasetByName;
209
- ensureDataset: typeof ensureDataset;
210
- addDocuments: typeof addDocuments;
211
- addText: typeof addText;
212
- addUrl: typeof addUrl;
213
- listDocuments: typeof listDocuments;
214
- deleteDocuments: typeof deleteDocuments;
215
- search: typeof search;
216
- };
217
-
218
- export interface DatabaseFilter {
7
+ export class ConfigurationError extends PlatformSdkError {}
8
+ export class ApiError extends PlatformSdkError {}
9
+
10
+ export interface RuntimeConfig {
11
+ baseUrl: string;
12
+ projectId: string;
13
+ workspaceId?: string;
14
+ userId?: string;
15
+ token?: string;
16
+ environment: string;
17
+ ownerProjectId?: string;
18
+ ownerWorkspaceId?: string;
19
+ ownerOrgId?: string;
20
+ ownerUserId?: string;
21
+ ownerProjectType?: string;
22
+ ownerApplicationType?: string;
23
+ runtimeEnv?: string;
24
+ currentUserId?: string;
25
+ currentUserOrgId?: string;
26
+ }
27
+
28
+ export function runtimeConfig(options?: { environmentOverrideEnv?: string }): Promise<RuntimeConfig>;
29
+ export function authHeaders(config: RuntimeConfig, contentType?: string): Record<string, string>;
30
+
31
+ export const DataSourceType: {
32
+ TEXT: 0;
33
+ URL: 1;
34
+ URI: 2;
35
+ };
36
+
37
+ export type KnowledgeDataSourceType = 0 | 1 | 2 | 'text' | 'url' | 'uri' | 'raw' | 'content' | 'web' | 'file' | 'source_file_id';
38
+
39
+ export interface KnowledgeChunkConfig {
40
+ separator?: string;
41
+ maxTokens?: number;
42
+ max_tokens?: number;
43
+ removeExtraSpaces?: boolean;
44
+ remove_extra_spaces?: boolean;
45
+ removeUrlsEmails?: boolean;
46
+ remove_urls_emails?: boolean;
47
+ }
48
+
49
+ export class ChunkConfig {
50
+ separator: string;
51
+ max_tokens: number;
52
+ remove_extra_spaces: boolean;
53
+ remove_urls_emails: boolean;
54
+ constructor(options?: KnowledgeChunkConfig);
55
+ }
56
+
57
+ export interface KnowledgeDocumentOptions {
58
+ source?: KnowledgeDataSourceType;
59
+ source_type?: KnowledgeDataSourceType;
60
+ raw_data?: string;
61
+ content?: string;
62
+ text?: string;
63
+ url?: string;
64
+ web_url?: string;
65
+ uri?: string;
66
+ source_file_id?: string;
67
+ name?: string;
68
+ file_type?: string;
69
+ update_rule?: Record<string, unknown>;
70
+ }
71
+
72
+ export class KnowledgeDocument {
73
+ constructor(options?: KnowledgeDocumentOptions);
74
+ }
75
+
76
+ export interface KnowledgeDataset {
77
+ name?: string;
78
+ description?: string;
79
+ status?: number;
80
+ dataset_id?: string;
81
+ space_id?: string;
82
+ doc_count?: number;
83
+ slice_count?: number;
84
+ search_method?: string;
85
+ supported_search_methods?: string[];
86
+ [key: string]: unknown;
87
+ }
88
+
89
+ export interface ListDatasetsOptions {
90
+ name?: string;
91
+ spaceId?: string;
92
+ space_id?: string;
93
+ formatType?: number;
94
+ format_type?: number;
95
+ pageSize?: number;
96
+ page_size?: number;
97
+ pageNum?: number;
98
+ page_num?: number;
99
+ }
100
+
101
+ export interface CreateDatasetOptions {
102
+ description?: string;
103
+ spaceId?: string;
104
+ space_id?: string;
105
+ config?: Record<string, unknown>;
106
+ formatType?: number;
107
+ format_type?: number;
108
+ sourceType?: string;
109
+ source_type?: string;
110
+ engineType?: string;
111
+ engine_type?: string;
112
+ accessScope?: string;
113
+ access_scope?: string;
114
+ multimodalEnabled?: boolean;
115
+ multimodal_enabled?: boolean;
116
+ graphEnabled?: boolean;
117
+ graph_enabled?: boolean;
118
+ embeddingModel?: string;
119
+ embedding_model?: string;
120
+ embeddingDim?: number;
121
+ embedding_dim?: number;
122
+ chunkingStrategy?: Record<string, unknown>;
123
+ chunking_strategy?: Record<string, unknown>;
124
+ processingProfile?: Record<string, unknown>;
125
+ processing_profile?: Record<string, unknown>;
126
+ }
127
+
128
+ export interface AddDocumentsOptions {
129
+ datasetId?: string;
130
+ dataset_id?: string;
131
+ datasetName?: string;
132
+ dataset_name?: string;
133
+ chunkConfig?: KnowledgeChunkConfig | ChunkConfig | Record<string, unknown>;
134
+ chunk_config?: KnowledgeChunkConfig | ChunkConfig | Record<string, unknown>;
135
+ formatType?: number;
136
+ format_type?: number;
137
+ batchId?: string;
138
+ batch_id?: string;
139
+ batchName?: string;
140
+ batch_name?: string;
141
+ processingProfile?: Record<string, unknown>;
142
+ processing_profile?: Record<string, unknown>;
143
+ chunkingStrategy?: Record<string, unknown>;
144
+ chunking_strategy?: Record<string, unknown>;
145
+ name?: string;
146
+ }
147
+
148
+ export interface SearchKnowledgeOptions {
149
+ datasetId?: string;
150
+ dataset_id?: string;
151
+ datasetIds?: string[];
152
+ dataset_ids?: string[];
153
+ datasetName?: string;
154
+ dataset_name?: string;
155
+ datasetNames?: string[];
156
+ dataset_names?: string[];
157
+ topK?: number;
158
+ top_k?: number;
159
+ minScore?: number;
160
+ min_score?: number;
161
+ candidateTopK?: number;
162
+ candidate_top_k?: number;
163
+ searchMethod?: string;
164
+ search_method?: string;
165
+ enableRerank?: boolean;
166
+ enable_rerank?: boolean;
167
+ needCitation?: boolean;
168
+ need_citation?: boolean;
169
+ needTrace?: boolean;
170
+ need_trace?: boolean;
171
+ }
172
+
173
+ export interface KnowledgeDocumentInfo {
174
+ id?: string;
175
+ sourceId?: string;
176
+ name?: string;
177
+ contentType?: string;
178
+ fileSize?: number;
179
+ status?: string;
180
+ errorMessage?: string;
181
+ chunkCount?: number;
182
+ createdAt?: string;
183
+ [key: string]: unknown;
184
+ }
185
+
186
+ export interface KnowledgeSearchResult {
187
+ segment_infos?: Array<{
188
+ content?: string;
189
+ score?: number;
190
+ metadata?: Record<string, unknown>;
191
+ segment_id?: string;
192
+ dataset_id?: string;
193
+ document_id?: string;
194
+ document_name?: string;
195
+ [key: string]: unknown;
196
+ }>;
197
+ citations?: unknown[];
198
+ request_id?: string;
199
+ dataset_ids?: string[];
200
+ route_trace?: Record<string, unknown>;
201
+ [key: string]: unknown;
202
+ }
203
+
204
+ export function runtime(): Promise<Record<string, unknown>>;
205
+ export function modelCatalog(): Promise<Record<string, unknown>>;
206
+ export function listDatasets(options?: ListDatasetsOptions): Promise<{ total_count?: number; dataset_list?: KnowledgeDataset[]; [key: string]: unknown }>;
207
+ export function getDataset(datasetId: string): Promise<KnowledgeDataset>;
208
+ export function createDataset(name: string, options?: CreateDatasetOptions): Promise<KnowledgeDataset>;
209
+ export function deleteDataset(datasetId: string): Promise<void>;
210
+ export function findDatasetByName(name: string): Promise<KnowledgeDataset | null>;
211
+ export function ensureDataset(name: string, options?: CreateDatasetOptions): Promise<KnowledgeDataset>;
212
+ export function addDocuments(documents: KnowledgeDocumentOptions[], options?: AddDocumentsOptions): Promise<{ document_infos?: KnowledgeDocumentInfo[]; [key: string]: unknown }>;
213
+ export function addText(content: string, options?: AddDocumentsOptions): Promise<{ document_infos?: KnowledgeDocumentInfo[]; [key: string]: unknown }>;
214
+ export function addUrl(url: string, options?: AddDocumentsOptions): Promise<{ document_infos?: KnowledgeDocumentInfo[]; [key: string]: unknown }>;
215
+ export function listDocuments(datasetId: string, options?: { page?: number; size?: number }): Promise<{ total?: number; document_infos?: KnowledgeDocumentInfo[]; [key: string]: unknown }>;
216
+ export function deleteDocuments(datasetId: string, documentIds: string[]): Promise<void>;
217
+ export function search(query: string, options?: SearchKnowledgeOptions): Promise<KnowledgeSearchResult>;
218
+
219
+ export const knowledge: {
220
+ DataSourceType: typeof DataSourceType;
221
+ ChunkConfig: typeof ChunkConfig;
222
+ KnowledgeDocument: typeof KnowledgeDocument;
223
+ runtime: typeof runtime;
224
+ modelCatalog: typeof modelCatalog;
225
+ listDatasets: typeof listDatasets;
226
+ getDataset: typeof getDataset;
227
+ createDataset: typeof createDataset;
228
+ deleteDataset: typeof deleteDataset;
229
+ findDatasetByName: typeof findDatasetByName;
230
+ ensureDataset: typeof ensureDataset;
231
+ addDocuments: typeof addDocuments;
232
+ addText: typeof addText;
233
+ addUrl: typeof addUrl;
234
+ listDocuments: typeof listDocuments;
235
+ deleteDocuments: typeof deleteDocuments;
236
+ search: typeof search;
237
+ };
238
+
239
+ export interface DatabaseFilter {
219
240
  field: string;
220
241
  op: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'not_in' | 'is_null' | 'is_not_null' | 'like' | 'ilike' | string;
221
242
  value?: unknown;
@@ -342,10 +363,10 @@ export function generateOrm(schemaPayload: DatabaseSchema, options: GenerateOrmO
342
363
  export function exportOrm(options: GenerateOrmOptions): Promise<string>;
343
364
  export function table(name: string): TableQuery;
344
365
 
345
- export const database: {
346
- query: typeof query;
347
- single: typeof single;
348
- maybeSingle: typeof maybeSingle;
366
+ export const database: {
367
+ query: typeof query;
368
+ single: typeof single;
369
+ maybeSingle: typeof maybeSingle;
349
370
  aggregate: typeof aggregate;
350
371
  insert: typeof insert;
351
372
  updateRows: typeof updateRows;
@@ -356,85 +377,85 @@ export const database: {
356
377
  getSchema: typeof getSchema;
357
378
  defaultOrm: typeof defaultOrm;
358
379
  generateOrm: typeof generateOrm;
359
- exportOrm: typeof exportOrm;
360
- table: typeof table;
361
- };
362
-
363
- export interface StudioDatabaseColumn {
364
- originalName?: string;
365
- name?: string;
366
- type?: string;
367
- defaultValue?: string | null;
368
- primaryKey?: boolean;
369
- nullable?: boolean;
370
- unique?: boolean;
371
- array?: boolean;
372
- checkExpression?: string;
373
- [key: string]: unknown;
374
- }
375
-
376
- export interface StudioDatabaseTableOptions {
377
- envScope?: 'dev' | 'prod' | string;
378
- schema?: string;
379
- description?: string;
380
- columns?: StudioDatabaseColumn[];
381
- }
382
-
383
- export interface StudioDatabaseRowOptions {
384
- envScope?: 'dev' | 'prod' | string;
385
- schema?: string;
386
- rowId?: string;
387
- rowIndex?: number;
388
- rowIds?: string[];
389
- rowIndexes?: number[];
390
- }
391
-
392
- export interface StudioDatabaseSyncOptions {
393
- sourceScope?: 'dev' | 'prod' | string;
394
- targetScope?: 'dev' | 'prod' | string;
395
- tables?: string[];
396
- sourceProjectId?: string;
397
- targetProjectId?: string;
398
- }
399
-
400
- export interface StudioDatabaseControlOptions {
401
- environment?: 'dev' | 'prod' | string;
402
- }
403
-
404
- export const studioDatabase: {
405
- getDatabase(options?: { envScope?: string }): Promise<Record<string, unknown>>;
406
- createDefaultDatabase(options?: { envScope?: string }): Promise<Record<string, unknown>>;
407
- deleteDatabase(options?: { envScope?: string }): Promise<void>;
408
- listTables(options?: { envScope?: string; keyword?: string }): Promise<Record<string, unknown>[]>;
409
- createTable(tableName: string, options?: StudioDatabaseTableOptions): Promise<Record<string, unknown>>;
410
- updateTable(tableName: string, options?: StudioDatabaseTableOptions & { newTableName?: string }): Promise<Record<string, unknown>>;
411
- deleteTable(tableName: string, options?: Pick<StudioDatabaseTableOptions, 'envScope' | 'schema'>): Promise<void>;
412
- addColumn(tableName: string, options: StudioDatabaseTableOptions & { name: string; type: string; defaultValue?: string | null; array?: boolean; primaryKey?: boolean; nullable?: boolean; unique?: boolean; checkExpression?: string }): Promise<Record<string, unknown>>;
413
- getTableData(tableName: string, options?: Pick<StudioDatabaseTableOptions, 'envScope' | 'schema'>): Promise<Record<string, unknown>>;
414
- insertRow(tableName: string, values: Record<string, unknown>, options?: Pick<StudioDatabaseTableOptions, 'envScope' | 'schema'>): Promise<Record<string, unknown>>;
415
- updateRow(tableName: string, values: Record<string, unknown>, options?: StudioDatabaseRowOptions): Promise<Record<string, unknown>>;
416
- deleteRows(tableName: string, options?: StudioDatabaseRowOptions): Promise<Record<string, unknown>>;
417
- executeSql(sqlText: string, options?: { envScope?: string }): Promise<Record<string, unknown>>;
418
- sqlHistory(options?: { envScope?: string }): Promise<Record<string, unknown>[]>;
419
- exportBackup(options?: { envScope?: string }): Promise<Record<string, unknown>>;
420
- importBackup(backup: Record<string, unknown>, options?: { envScope?: string }): Promise<Record<string, unknown>>;
421
- sync(options?: StudioDatabaseSyncOptions): Promise<Record<string, unknown>>;
422
- syncProject(sourceProjectId: string, targetProjectId: string, options?: StudioDatabaseSyncOptions): Promise<Record<string, unknown>>;
423
- ensureDatabase(options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
424
- getSchema(options?: StudioDatabaseControlOptions): Promise<DatabaseSchema>;
425
- getConfig(options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
426
- controlSql(sqlText: string, options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
427
- explainSql(sqlText: string, options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
428
- validateSchema(schema: DatabaseSchema, options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
429
- diffSchema(schema: DatabaseSchema, options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
430
- listMigrations(options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>[]>;
431
- createMigration(options: StudioDatabaseControlOptions & { title: string; statements?: string[]; schema?: DatabaseSchema; dryRun?: boolean }): Promise<Record<string, unknown>>;
432
- getMigration(migrationId: string): Promise<Record<string, unknown>>;
433
- };
434
-
435
- export interface StorageSummary {
436
- workspaceId?: string;
437
- projectId?: string;
380
+ exportOrm: typeof exportOrm;
381
+ table: typeof table;
382
+ };
383
+
384
+ export interface StudioDatabaseColumn {
385
+ originalName?: string;
386
+ name?: string;
387
+ type?: string;
388
+ defaultValue?: string | null;
389
+ primaryKey?: boolean;
390
+ nullable?: boolean;
391
+ unique?: boolean;
392
+ array?: boolean;
393
+ checkExpression?: string;
394
+ [key: string]: unknown;
395
+ }
396
+
397
+ export interface StudioDatabaseTableOptions {
398
+ envScope?: 'dev' | 'prod' | string;
399
+ schema?: string;
400
+ description?: string;
401
+ columns?: StudioDatabaseColumn[];
402
+ }
403
+
404
+ export interface StudioDatabaseRowOptions {
405
+ envScope?: 'dev' | 'prod' | string;
406
+ schema?: string;
407
+ rowId?: string;
408
+ rowIndex?: number;
409
+ rowIds?: string[];
410
+ rowIndexes?: number[];
411
+ }
412
+
413
+ export interface StudioDatabaseSyncOptions {
414
+ sourceScope?: 'dev' | 'prod' | string;
415
+ targetScope?: 'dev' | 'prod' | string;
416
+ tables?: string[];
417
+ sourceProjectId?: string;
418
+ targetProjectId?: string;
419
+ }
420
+
421
+ export interface StudioDatabaseControlOptions {
422
+ environment?: 'dev' | 'prod' | string;
423
+ }
424
+
425
+ export const studioDatabase: {
426
+ getDatabase(options?: { envScope?: string }): Promise<Record<string, unknown>>;
427
+ createDefaultDatabase(options?: { envScope?: string }): Promise<Record<string, unknown>>;
428
+ deleteDatabase(options?: { envScope?: string }): Promise<void>;
429
+ listTables(options?: { envScope?: string; keyword?: string }): Promise<Record<string, unknown>[]>;
430
+ createTable(tableName: string, options?: StudioDatabaseTableOptions): Promise<Record<string, unknown>>;
431
+ updateTable(tableName: string, options?: StudioDatabaseTableOptions & { newTableName?: string }): Promise<Record<string, unknown>>;
432
+ deleteTable(tableName: string, options?: Pick<StudioDatabaseTableOptions, 'envScope' | 'schema'>): Promise<void>;
433
+ addColumn(tableName: string, options: StudioDatabaseTableOptions & { name: string; type: string; defaultValue?: string | null; array?: boolean; primaryKey?: boolean; nullable?: boolean; unique?: boolean; checkExpression?: string }): Promise<Record<string, unknown>>;
434
+ getTableData(tableName: string, options?: Pick<StudioDatabaseTableOptions, 'envScope' | 'schema'>): Promise<Record<string, unknown>>;
435
+ insertRow(tableName: string, values: Record<string, unknown>, options?: Pick<StudioDatabaseTableOptions, 'envScope' | 'schema'>): Promise<Record<string, unknown>>;
436
+ updateRow(tableName: string, values: Record<string, unknown>, options?: StudioDatabaseRowOptions): Promise<Record<string, unknown>>;
437
+ deleteRows(tableName: string, options?: StudioDatabaseRowOptions): Promise<Record<string, unknown>>;
438
+ executeSql(sqlText: string, options?: { envScope?: string }): Promise<Record<string, unknown>>;
439
+ sqlHistory(options?: { envScope?: string }): Promise<Record<string, unknown>[]>;
440
+ exportBackup(options?: { envScope?: string }): Promise<Record<string, unknown>>;
441
+ importBackup(backup: Record<string, unknown>, options?: { envScope?: string }): Promise<Record<string, unknown>>;
442
+ sync(options?: StudioDatabaseSyncOptions): Promise<Record<string, unknown>>;
443
+ syncProject(sourceProjectId: string, targetProjectId: string, options?: StudioDatabaseSyncOptions): Promise<Record<string, unknown>>;
444
+ ensureDatabase(options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
445
+ getSchema(options?: StudioDatabaseControlOptions): Promise<DatabaseSchema>;
446
+ getConfig(options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
447
+ controlSql(sqlText: string, options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
448
+ explainSql(sqlText: string, options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
449
+ validateSchema(schema: DatabaseSchema, options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
450
+ diffSchema(schema: DatabaseSchema, options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>>;
451
+ listMigrations(options?: StudioDatabaseControlOptions): Promise<Record<string, unknown>[]>;
452
+ createMigration(options: StudioDatabaseControlOptions & { title: string; statements?: string[]; schema?: DatabaseSchema; dryRun?: boolean }): Promise<Record<string, unknown>>;
453
+ getMigration(migrationId: string): Promise<Record<string, unknown>>;
454
+ };
455
+
456
+ export interface StorageSummary {
457
+ workspaceId?: string;
458
+ projectId?: string;
438
459
  scope?: string;
439
460
  bucketName?: string;
440
461
  usedSizeBytes?: number;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{PlatformSdkError,ConfigurationError,ApiError}from"./shared.js";export*from"./database.js";export*from"./knowledge.js";export*from"./storage.js";export{studioDatabase}from"./studio-database.js";
1
+ export{PlatformSdkError,ConfigurationError,ApiError}from"./shared.js";export{runtimeConfig,authHeaders}from"./runtime.js";export*from"./database.js";export*from"./knowledge.js";export*from"./storage.js";export{studioDatabase}from"./studio-database.js";
package/dist/runtime.js CHANGED
@@ -1 +1 @@
1
- import{ConfigurationError as e}from"./shared.js";const t=new Map;export function env(e){const t=process.env[e];if("string"!=typeof t)return;return t.trim()||void 0}function n(e,t,n){const r=env(e);if(r)return`http://${r}:${env(t)||n}`}export function platformBaseUrl(){const t=env("LICOS_PLATFORM_API_BASE_URL")||n("AIOS_PLATFORM_SERVICE_HOST","AIOS_PLATFORM_SERVICE_PORT","9100")||n("LICOS_PLATFORM_SERVICE_HOST","LICOS_PLATFORM_SERVICE_PORT","9100")||n("PLATFORM_SERVICE_HOST","PLATFORM_SERVICE_PORT","9100");if(!t)throw new e("LICOS_PLATFORM_API_BASE_URL is not configured");return function(e){let t=e.trim().replace(/\/+$/,"");return t.endsWith("/api/v1")&&(t=t.slice(0,-7)),t.replace(/\/+$/,"")}(t)}export function projectEnvironment(e){const t=((e?env(e):void 0)||"").toLowerCase();if("dev"===t||"prod"===t)return t;const n=(env("LICOS_PROJECT_ENV")||env("AGENT_ENV")||"").toLowerCase();return["prod","production","release"].includes(n)?"prod":"dev"}async function r(n,r,{forceRefresh:o=!1}={}){const s=String(r||"").trim();if(!s)throw new e("project owner user ID is not configured");const i=env("LICOS_AI_AGENT_TOKEN");if(!i)throw new e("platform runtime identity is unavailable");const c=`${n}\n${s}\n${i}`;if(t.has(c)){const e=t.get(c);if(!o)return e;if(e&&"function"==typeof e.then)return e}const a=fetch(`${n}/api/v1/internal/auth/ai-user-token`,{method:"POST",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},body:JSON.stringify({userId:s})}).then(async n=>{const r=await n.text();let o=null;try{o=r?JSON.parse(r):null}catch(t){const o=new e("parse AI user token exchange response failed");throw o.status=n.status,o.details=r,o}if(!n.ok){const t=o?.message||r||`AI user token exchange returned ${n.status}`,s=new e(t);throw s.status=n.status,s.details=o,s}const s=function(t){if(!t||"object"!=typeof t)throw new e("AI user token exchange response is not an object");if(void 0!==t.code&&0!==t.code||!1===t.success){const n=new e(t.message||"AI user token exchange failed");throw n.code="number"==typeof t.code?t.code:void 0,n.details=t,n}const n=t.data,r="string"==typeof n?n.trim():String(n?.accessToken||n?.access_token||n?.token||"").trim();if(!r){const n=new e("AI user token exchange response missing accessToken");throw n.details=t,n}return r}(o);return t.set(c,s),s});t.set(c,a);try{return await a}catch(e){throw t.delete(c),e}}export function clearTokenCacheForTests(){t.clear()}export function shouldRefreshUserToken(e){return 401===e?.status||10002===e?.code}export async function refreshRuntimeConfig(e){return{...e,token:await r(e.baseUrl,e.userId,{forceRefresh:!0})}}export async function runtimeConfig({environmentOverrideEnv:t}={}){const n=env("LICOS_PROJECT_ID")||env("AGENT_PROJECT_ID");if(!n)throw new e("LICOS_PROJECT_ID or AGENT_PROJECT_ID is not configured");const o=platformBaseUrl(),s=env("LICOS_USER_ID")||env("AGENT_USER_ID"),i=await r(o,s);return{baseUrl:o,projectId:n,environment:projectEnvironment(t),token:i,workspaceId:env("LICOS_WORKSPACE_ID")||env("AGENT_WORKSPACE_ID"),userId:s}}export function authHeaders(e,t="application/json"){const n={Authorization:`Bearer ${e.token}`};return t&&(n["Content-Type"]=t),e.workspaceId&&(n["X-Workspace-Id"]=e.workspaceId),e.userId&&(n["X-User-Id"]=e.userId),n}
1
+ import{ConfigurationError as e}from"./shared.js";const r=new Map;export function env(e){const r=process.env[e];if("string"!=typeof r)return;return r.trim()||void 0}function n(e,r,n){const t=env(e);if(t)return`http://${t}:${env(r)||n}`}export function platformBaseUrl(){const r=env("LICOS_PLATFORM_API_BASE_URL")||n("AIOS_PLATFORM_SERVICE_HOST","AIOS_PLATFORM_SERVICE_PORT","9100")||n("LICOS_PLATFORM_SERVICE_HOST","LICOS_PLATFORM_SERVICE_PORT","9100")||n("PLATFORM_SERVICE_HOST","PLATFORM_SERVICE_PORT","9100");if(!r)throw new e("LICOS_PLATFORM_API_BASE_URL is not configured");return function(e){let r=e.trim().replace(/\/+$/,"");return r.endsWith("/api/v1")&&(r=r.slice(0,-7)),r.replace(/\/+$/,"")}(r)}export function projectEnvironment(e){const r=((e?env(e):void 0)||"").toLowerCase();if("dev"===r||"prod"===r)return r;const n=(env("LICOS_PROJECT_ENV")||env("AGENT_ENV")||"").toLowerCase();return["prod","production","release"].includes(n)?"prod":"dev"}async function t(n,t,{forceRefresh:o=!1}={}){const s=String(t||"").trim();if(!s)throw new e("project owner user ID is not configured");const c=env("LICOS_AI_AGENT_TOKEN");if(!c)throw new e("platform runtime identity is unavailable");const i=`${n}\n${s}\n${c}`;if(r.has(i)){const e=r.get(i);if(!o)return e;if(e&&"function"==typeof e.then)return e}const I=fetch(`${n}/api/v1/internal/auth/ai-user-token`,{method:"POST",headers:{Authorization:`Bearer ${c}`,"Content-Type":"application/json"},body:JSON.stringify({userId:s})}).then(async n=>{const t=await n.text();let o=null;try{o=t?JSON.parse(t):null}catch(r){const o=new e("parse AI user token exchange response failed");throw o.status=n.status,o.details=t,o}if(!n.ok){const r=o?.message||t||`AI user token exchange returned ${n.status}`,s=new e(r);throw s.status=n.status,s.details=o,s}const s=function(r){if(!r||"object"!=typeof r)throw new e("AI user token exchange response is not an object");if(void 0!==r.code&&0!==r.code||!1===r.success){const n=new e(r.message||"AI user token exchange failed");throw n.code="number"==typeof r.code?r.code:void 0,n.details=r,n}const n=r.data,t="string"==typeof n?n.trim():String(n?.accessToken||n?.access_token||n?.token||"").trim();if(!t){const n=new e("AI user token exchange response missing accessToken");throw n.details=r,n}return t}(o);return r.set(i,s),s});r.set(i,I);try{return await I}catch(e){throw r.delete(i),e}}export function clearTokenCacheForTests(){r.clear()}export function shouldRefreshUserToken(e){return 401===e?.status||10002===e?.code}export async function refreshRuntimeConfig(e){return{...e,token:await t(e.baseUrl,e.userId,{forceRefresh:!0})}}export async function runtimeConfig({environmentOverrideEnv:r}={}){const n=env("LICOS_OWNER_PROJECT_ID"),o=env("LICOS_OWNER_WORKSPACE_ID"),s=env("LICOS_OWNER_USER_ID"),c=env("LICOS_PROJECT_ID")||n||env("AGENT_PROJECT_ID");if(!c)throw new e("LICOS_PROJECT_ID or AGENT_PROJECT_ID is not configured");const i=platformBaseUrl(),I=env("LICOS_USER_ID")||s||env("AGENT_USER_ID"),a=await t(i,I);return{baseUrl:i,projectId:c,environment:projectEnvironment(r),token:a,workspaceId:env("LICOS_WORKSPACE_ID")||o||env("AGENT_WORKSPACE_ID"),userId:I,ownerProjectId:n||c,ownerWorkspaceId:o,ownerOrgId:env("LICOS_OWNER_ORG_ID"),ownerUserId:s||I,ownerProjectType:env("LICOS_OWNER_PROJECT_TYPE"),ownerApplicationType:env("LICOS_OWNER_APPLICATION_TYPE"),runtimeEnv:env("LICOS_RUNTIME_ENV"),currentUserId:env("LICOS_CURRENT_USER_ID"),currentUserOrgId:env("LICOS_CURRENT_USER_ORG_ID")}}export function authHeaders(e,r="application/json"){const n={Authorization:`Bearer ${e.token}`};return r&&(n["Content-Type"]=r),e.workspaceId&&(n["X-Workspace-Id"]=e.workspaceId),e.userId&&(n["X-User-Id"]=e.userId),o(n,"X-Licos-Current-User-Id",e.currentUserId),o(n,"X-Licos-Current-Org-Id",e.currentUserOrgId),o(n,"current_user_id",e.currentUserId),o(n,"current_user_org_id",e.currentUserOrgId),o(n,"X-Licos-Runtime-Env",e.runtimeEnv),o(n,"X-Runtime-Env",e.runtimeEnv),o(n,"runtime_env",e.runtimeEnv),o(n,"owner_project_type",e.ownerProjectType),o(n,"owner_application_type",e.ownerApplicationType),e.ownerProjectId&&(o(n,"X-Licos-Owner-Project-Id",e.ownerProjectId),o(n,"X-Licos-Owner-Workspace-Id",e.ownerWorkspaceId),o(n,"X-Licos-Owner-Org-Id",e.ownerOrgId),o(n,"X-Licos-Owner-User-Id",e.ownerUserId),o(n,"owner_project_id",e.ownerProjectId),o(n,"owner_workspace_id",e.ownerWorkspaceId),o(n,"owner_org_id",e.ownerOrgId),o(n,"owner_user_id",e.ownerUserId),o(n,"X-Project-Id",e.ownerProjectId),o(n,"X-Workspace-Id",e.ownerWorkspaceId),o(n,"X-Tenant-Id",e.ownerOrgId),o(n,"X-User-Id",e.ownerUserId)),n}function o(e,r,n){if("string"!=typeof n)return;const t=n.trim();t&&(e[r]=t)}
package/package.json CHANGED
@@ -1,48 +1,48 @@
1
1
  {
2
2
  "name": "@kmlckj/licos-platform-sdk",
3
- "version": "0.6.7",
3
+ "version": "0.6.9",
4
4
  "description": "LICOS platform SDK package shell for browser and Node runtimes",
5
- "author": "kmlckj",
6
- "type": "module",
7
- "main": "./dist/index.js",
8
- "browser": "./dist/browser.js",
9
- "types": "./dist/index.d.ts",
10
- "typesVersions": {
11
- "*": {
12
- "browser": [
13
- "dist/browser.d.ts"
14
- ]
15
- }
16
- },
17
- "exports": {
18
- ".": {
19
- "browser": {
20
- "types": "./dist/browser.d.ts",
21
- "default": "./dist/browser.js"
22
- },
23
- "types": "./dist/index.d.ts",
24
- "import": "./dist/index.js",
25
- "default": "./dist/index.js"
26
- },
27
- "./browser": {
28
- "types": "./dist/browser.d.ts",
29
- "import": "./dist/browser.js",
30
- "default": "./dist/browser.js"
31
- }
32
- },
33
- "files": [
34
- "dist",
35
- "README.md"
36
- ],
37
- "scripts": {
38
- "build": "node build.mjs",
39
- "prepack": "npm run build",
40
- "test": "node --test"
41
- },
42
- "devDependencies": {
43
- "terser": "5.48.0"
44
- },
45
- "license": "MIT",
5
+ "author": "kmlckj",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "browser": "./dist/browser.js",
9
+ "types": "./dist/index.d.ts",
10
+ "typesVersions": {
11
+ "*": {
12
+ "browser": [
13
+ "dist/browser.d.ts"
14
+ ]
15
+ }
16
+ },
17
+ "exports": {
18
+ ".": {
19
+ "browser": {
20
+ "types": "./dist/browser.d.ts",
21
+ "default": "./dist/browser.js"
22
+ },
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./browser": {
28
+ "types": "./dist/browser.d.ts",
29
+ "import": "./dist/browser.js",
30
+ "default": "./dist/browser.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "README.md"
36
+ ],
37
+ "scripts": {
38
+ "build": "node build.mjs",
39
+ "prepack": "npm run build",
40
+ "test": "node --test"
41
+ },
42
+ "devDependencies": {
43
+ "terser": "5.48.0"
44
+ },
45
+ "license": "MIT",
46
46
  "publishConfig": {
47
47
  "access": "public",
48
48
  "registry": "https://registry.npmjs.org"