@kmlckj/licos-platform-sdk 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -119,94 +119,114 @@ const results = await knowledge.search('How do I reset my password?', {
119
119
  });
120
120
  ```
121
121
 
122
- The browser entry does not export knowledge helpers because runtime tokens must
123
- not be bundled into public frontend code.
124
-
125
- ## Unified Namespace (UNS)
126
-
127
- UNS helpers expose the same Schema, resource discovery, validation, plan,
128
- apply, binding, data, point, video, and enterprise path APIs as the Python
129
- platform SDK. They are server-only and derive the trusted project scope from
130
- the injected runtime identity.
131
-
132
- ```js
133
- import { uns } from '@kmlckj/licos-platform-sdk';
134
-
135
- const schema = await uns.schemaCurrent();
136
- const checked = await uns.validate(document);
137
- const reviewedPlan = await uns.plan(document);
138
-
139
- await uns.apply(document, {
140
- expectedDocumentHash: reviewedPlan.documentHash,
141
- expectedPlanHash: reviewedPlan.planHash,
142
- confirmed: true,
143
- });
144
- ```
145
-
146
- Use a `UNSChangeSet` for an isolated structural change. Review the dedicated
147
- plan and pass both hashes back unchanged. Destructive or replacement actions
148
- also require `impactConfirmed: true`.
149
-
150
- ```js
151
- const changes = await uns.planChanges(changeSet);
152
- await uns.applyChanges(changeSet, {
153
- expectedDocumentHash: changes.documentHash,
154
- expectedPlanHash: changes.planHash,
155
- confirmed: true,
156
- impactConfirmed: true,
157
- });
158
- ```
159
-
160
- Use `uns.openPath(path)` when business code targets an existing enterprise UNS
161
- path without creating or changing `UNS.json`:
162
-
163
- ```js
164
- const temperature = uns.openPath('project:/production-line/temperature');
165
- const current = await temperature.pointCurrent();
166
- ```
167
-
168
- Realtime point consumers obtain the server-side WebSocket endpoint through the
169
- authorized project runtime API. Create one upstream connection per returned
170
- `nodeCode`; do not derive or hardcode a DataFactory address:
171
-
172
- ```js
173
- const realtime = await uns.pointRealtimeConfig('TEMP_01');
174
- // Connect to realtime.websocketUrl and register with realtime.nodeCode.
175
- ```
176
-
177
- Resource apply, data writes, point writes, and video controls require explicit
178
- confirmation. Data deletion accepts the exact rows returned by a prior query
179
- and also requires explicit confirmation. Point writes require a reason and ticket. The browser entry
180
- does not export UNS helpers.
122
+ The browser entry does not export knowledge helpers because runtime tokens must
123
+ not be bundled into public frontend code.
181
124
 
182
- ## Direct Industrial Integration
125
+ ### Enterprise knowledge
183
126
 
184
- The server-only `industrial` facade manages collection and video resources
185
- without creating DataFactory UNS nodes. Use it only when the user explicitly
186
- selects direct collector integration; UNS failures must not trigger this mode.
127
+ Enterprise knowledge is a separate, enterprise-user-only resource model. The
128
+ platform derives tenant scope and permissions from the current user token; do
129
+ not pass tenant IDs from application code.
187
130
 
188
131
  ```js
189
- import { industrial } from '@kmlckj/licos-platform-sdk';
132
+ import { enterpriseKnowledge } from '@kmlckj/licos-platform-sdk';
190
133
 
191
- const points = await industrial.searchResources('collectionPoint', {
192
- scope: 'project',
193
- keyword: 'temperature',
134
+ const tree = await enterpriseKnowledge.tree({
135
+ includeTypes: ['STANDARD', 'GRAPH', 'OBJECT_STORAGE'],
194
136
  });
195
137
 
196
- const current = await industrial.pointCurrent(points.items[0].id);
197
- const realtime = await industrial.realtimeConnection({
198
- pointIds: [points.items[0].id],
199
- transport: 'websocket',
200
- });
138
+ const validation = await enterpriseKnowledge.validateReferences(
139
+ ['knowledge-source-id'],
140
+ { requiredCapability: 'retrieve' },
141
+ );
142
+
143
+ if (validation.valid) {
144
+ const evidence = await enterpriseKnowledge.retrieve(
145
+ '设备停机前必须完成哪些检查?',
146
+ ['knowledge-source-id'],
147
+ );
148
+ }
149
+
150
+ await enterpriseKnowledge.uploadDocumentChunked(
151
+ 'knowledge-source-id',
152
+ '/workspace/projects/manual.pdf',
153
+ );
154
+ ```
155
+
156
+ The API covers folders, knowledge-base lifecycle, resource audits, document
157
+ listing and chunk inspection, resumable uploads, processing tasks, retrieval,
158
+ and object-storage knowledge bases. Temporary document/object URLs must be
159
+ obtained with `getDocumentOriginalUrl` or `getObjectDownloadUrl`; do not build
160
+ storage URLs manually.
161
+
162
+ ## Unified Namespace (UNS)
163
+
164
+ UNS helpers use the platform UNS Modeling module. Isolation follows the tenant
165
+ UNS directory hierarchy rather than a project-local namespace. The helpers are
166
+ server-only and use the injected platform identity.
167
+
168
+ ```js
169
+ import { uns } from '@kmlckj/licos-platform-sdk';
170
+
171
+ const schema = await uns.provisioningSchema();
172
+ const capabilities = await uns.provisioningCapabilities();
173
+ await uns.validate(document);
174
+ await uns.plan(document);
175
+ const created = await uns.submit(document, { idempotencyKey: stableRequestId });
176
+ const result = await uns.waitJob(created.jobId);
177
+ const operations = await uns.operations(created.jobId);
178
+ ```
179
+
180
+ Always fetch schema and capabilities before generating a provisioning document.
181
+ Use the fixed flow `validate -> plan -> submit -> wait -> operations`.
182
+ Provisioning is asynchronous; only a terminal job status determines the result.
183
+
184
+ ```js
185
+ const nodes = await uns.listNodes();
186
+ const latest = await uns.nodeLatest(nodes[0].id);
187
+ const history = await uns.nodeHistory(nodes[0].id, { limit: 100 });
188
+ const realtime = await uns.realtimeConnection();
201
189
  ```
202
190
 
203
- Realtime subscription defaults to upstream WebSocket and supports explicitly
204
- selected MQTT. Point control defaults to HTTP and supports explicitly selected
205
- MQTT. Neither direction silently falls back. Resource writes use a reviewed
206
- `IndustrialChangeSet`; point and video writes require independent confirmation.
207
- The browser entry does not export industrial helpers or external credentials.
191
+ The realtime URL contains a short-lived platform ticket, not a user token.
192
+ Nodes, templates, and labels expose direct CRUD APIs. The SDK also exposes the
193
+ node schemas, JSON definition inference, reverse modeling metadata, attachments,
194
+ and the four documented IoT source queries:
208
195
 
209
- ## OAuth2 Application Management
196
+ ```js
197
+ const fileSchema = await uns.nodeSchema('file');
198
+ const definition = await uns.inferDefinition({ temperature: 23.5 });
199
+ const schemas = await uns.listReverseSchemas();
200
+ const attachments = await uns.uploadAttachments(nodes[0].id, [
201
+ { name: 'manual.pdf', data: manualBytes, contentType: 'application/pdf' },
202
+ ]);
203
+ const collectors = await uns.listCollectors('IOT_POINT_COLLECTOR');
204
+ const points = await uns.listPoints('IOT_POINT_COLLECTOR', collectors.records[0].id);
205
+ const current = await uns.sourceLatest(collectors.records[0].id, points.records[0].id);
206
+ ```
207
+
208
+ The browser entry does not export UNS helpers.
209
+
210
+ ## Industrial IoT Source Queries
211
+
212
+ The server-only `industrial` facade exposes the documented UNS IoT source
213
+ queries.
214
+
215
+ ```js
216
+ import { industrial } from '@kmlckj/licos-platform-sdk';
217
+
218
+ const collectors = await industrial.collectors(industrial.IOT_POINT_COLLECTOR);
219
+ const points = await industrial.points(
220
+ industrial.IOT_POINT_COLLECTOR,
221
+ collectors.records[0].id,
222
+ );
223
+ const current = await industrial.latest(collectors.records[0].id, points.records[0].id);
224
+ ```
225
+
226
+ Create or update collectors and video resources through the UNS provisioning
227
+ flow. The browser entry does not export industrial helpers.
228
+
229
+ ## OAuth2 Application Management
210
230
 
211
231
  OAuth2 management is available only from trusted Node runtime code. It uses the
212
232
  current project owner's platform identity and is not exported by the browser
@@ -0,0 +1 @@
1
+ import{createHash as e}from"node:crypto";import{createReadStream as t}from"node:fs";import{open as n,readFile as r,stat as o}from"node:fs/promises";import s from"node:path";import{ApiError as a}from"./shared.js";import{authHeaders as i,refreshRuntimeConfig as d,runtimeConfig as c,shouldRefreshUserToken as p}from"./runtime.js";export const DEFAULT_ENTERPRISE_KNOWLEDGE_CHUNK_SIZE=8388608;export const MIN_ENTERPRISE_KNOWLEDGE_CHUNK_SIZE=5242880;export const MAX_ENTERPRISE_KNOWLEDGE_CHUNK_SIZE=104857600;function l(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>null!=e))}function u(e,t){const n=String(e??"").trim();if(!n)throw new TypeError(`${t} is required`);return n}function g(e){return Array.isArray(e)?e.join(","):e}function f(e,t,n={}){const r=new URL(`${e.baseUrl}/api/v1/knowledge/enterprise${t}`);for(const[e,t]of Object.entries(l(n)))Array.isArray(t)?t.forEach(t=>r.searchParams.append(e,String(t))):r.searchParams.set(e,String(t));return r}async function m(){return c({useCurrentUser:!0})}async function w(e){const t=await e.text();let n=null;if(t)try{n=JSON.parse(t)}catch{if(!e.ok)throw new a(t,{status:e.status});throw new a("enterprise knowledge API returned invalid JSON",{status:e.status,details:t})}if(!e.ok)throw new a(n?.message||t||`enterprise knowledge API returned ${e.status}`,{status:e.status,code:"number"==typeof n?.code?n.code:void 0,details:n});if(!n||"object"!=typeof n)return n;if(void 0!==n.code&&0!==n.code||!1===n.success)throw new a(n.message||"enterprise knowledge API failed",{status:e.status,code:"number"==typeof n.code?n.code:void 0,details:n});return n.data}async function y(e,t,{params:n,body:r}={}){let o=await m();for(let s=0;s<2;s+=1)try{const s=await fetch(f(o,t,n),{method:e,headers:i(o,void 0===r?void 0:"application/json"),body:void 0===r?void 0:JSON.stringify(l(r))});return await w(s)}catch(e){if(0===s&&p(e)){o=await d(o);continue}throw e}throw new a("enterprise knowledge API failed")}async function E(e,t){let n=await m();for(let r=0;r<2;r+=1)try{const r=await fetch(f(n,e),{method:"POST",headers:i(n),body:t()});return await w(r)}catch(e){if(0===r&&p(e)){n=await d(n);continue}throw e}throw new a("enterprise knowledge upload failed")}async function h(e,t){let n=await m();for(let r=0;r<2;r+=1){const o=f(n,e,t);try{const e=await fetch(o,{method:"GET",headers:i(n),redirect:"manual"});if([301,302,303,307,308].includes(e.status)){const t=e.headers.get("location");if(!t)throw new a("enterprise knowledge download response has no redirect URL",{status:e.status});return new URL(t,o).toString()}throw await w(e),new a("enterprise knowledge download response has no redirect URL",{status:e.status})}catch(e){if(0===r&&p(e)){n=await d(n);continue}throw e}}throw new a("enterprise knowledge download URL failed")}function _(e){return{".csv":"text/csv",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".json":"application/json",".md":"text/markdown",".pdf":"application/pdf",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}[s.extname(e).toLowerCase()]||"application/octet-stream"}async function b(e,t={}){if("string"==typeof e){const n=await o(e);if(!n.isFile())throw new TypeError(`upload input is not a file: ${e}`);const r=t.fileName||t.file_name||s.basename(e);return{path:e,fileName:r,contentType:t.contentType||t.content_type||_(r),size:n.size}}let n;if(e instanceof Blob)n=Buffer.from(await e.arrayBuffer());else{if(!(Buffer.isBuffer(e)||e instanceof Uint8Array))throw new TypeError("upload input must be a file path, Blob, Buffer, or Uint8Array");n=Buffer.from(e)}const r=t.fileName||t.file_name||e.name||"upload.bin";return{data:n,fileName:r,contentType:t.contentType||t.content_type||e.type||_(r),size:n.length}}async function K(e){return e.data??r(e.path)}async function T(n){const r=e("sha256");return n.data?(r.update(n.data),r.digest("hex")):(await new Promise((e,o)=>{const s=t(n.path);s.on("data",e=>r.update(e)),s.on("error",o),s.on("end",e)}),r.digest("hex"))}function k(e,t){return new Blob([t],{type:e.contentType})}export async function enterpriseKnowledgeTree(e={}){return y("GET","/tree",{params:{include_types:g(e.includeTypes??e.include_types)}})}export async function searchEnterpriseKnowledgeBases(e,t={}){return y("GET","/search",{params:{q:u(e,"query"),include_types:g(t.includeTypes??t.include_types),page:t.page,page_size:t.pageSize??t.page_size}})}export async function validateEnterpriseKnowledgeReferences(e,t={}){if(!Array.isArray(e)||0===e.length)throw new TypeError("knowledgeBaseIds is required");return y("POST","/references/validate",{body:{knowledge_base_ids:e.map(String),required_capability:t.requiredCapability??t.required_capability??"retrieve"}})}export async function retrieveEnterpriseKnowledge(e,t){if(!Array.isArray(t)||0===t.length)throw new TypeError("sourceIds is required");return y("POST","/retrieve",{body:{query:u(e,"query"),source_ids:t.map(String)}})}export async function listEnterpriseKnowledgeFolders(e={}){return y("GET","/folders",{params:{parent_id:e.parentId??e.parent_id,include_children:e.includeChildren??e.include_children,q:e.query??e.q,page:e.page,page_size:e.pageSize??e.page_size}})}export async function getEnterpriseKnowledgeFolder(e){return y("GET",`/folders/${encodeURIComponent(u(e,"folderId"))}`)}export async function createEnterpriseKnowledgeFolder(e,t={}){return y("POST","/folders",{body:{parent_id:t.parentId??t.parent_id,name:u(e,"name"),description:t.description}})}export async function deleteEnterpriseKnowledgeFolder(e,t={}){return y("DELETE",`/folders/${encodeURIComponent(u(e,"folderId"))}`,{body:{reason:t.reason,hard_delete:t.hardDelete??t.hard_delete,confirm_name:t.confirmName??t.confirm_name}})}export async function listEnterpriseFolderKnowledgeBases(e,t={}){return y("GET",`/folders/${encodeURIComponent(u(e,"folderId"))}/knowledge-bases`,{params:{include_children:t.includeChildren??t.include_children,include_types:g(t.includeTypes??t.include_types),q:t.query??t.q,page:t.page,page_size:t.pageSize??t.page_size}})}export async function createEnterpriseKnowledgeBase(e,t={}){return y("POST","/knowledge-bases",{body:{folder_id:t.folderId??t.folder_id,name:u(e,"name"),description:t.description,knowledge_type:t.knowledgeType??t.knowledge_type??"STANDARD"}})}export async function getEnterpriseKnowledgeBase(e){return y("GET",`/knowledge-bases/${encodeURIComponent(u(e,"sourceId"))}`)}export async function deleteEnterpriseKnowledgeBase(e,t={}){return y("DELETE",`/knowledge-bases/${encodeURIComponent(u(e,"sourceId"))}`,{body:{reason:t.reason,hard_delete:t.hardDelete??t.hard_delete,confirm_name:t.confirmName??t.confirm_name}})}export async function listEnterpriseKnowledgeResourceAudits(e={}){return y("GET","/resource-audits",{params:{operation:e.operation,resource_kind:e.resourceKind??e.resource_kind,resource_id:e.resourceId??e.resource_id,knowledge_type:e.knowledgeType??e.knowledge_type,q:e.query??e.q,page:e.page,page_size:e.pageSize??e.page_size}})}export async function listEnterpriseKnowledgeDocuments(e,t={}){return y("GET","/documents",{params:{source_id:u(e,"sourceId"),page:t.page,page_size:t.pageSize??t.page_size,q:t.query??t.q,status:t.status,document_id:t.documentId??t.document_id}})}export async function getEnterpriseKnowledgeDocument(e){return y("GET",`/documents/${encodeURIComponent(u(e,"documentId"))}`)}export async function listEnterpriseKnowledgeDocumentChunks(e,t={}){return y("GET",`/documents/${encodeURIComponent(u(e,"documentId"))}/chunks`,{params:{page:t.page,page_size:t.pageSize??t.page_size,q:t.query??t.q}})}export async function getEnterpriseKnowledgeDocumentOriginalUrl(e,t={}){return h(`/documents/${encodeURIComponent(u(e,"documentId"))}/original`,{download:t.download??!1})}export async function batchDeleteEnterpriseKnowledgeDocuments(e,t,n={}){if(!Array.isArray(t)||0===t.length)throw new TypeError("documentIds is required");return y("POST","/documents/batch-delete",{body:{source_id:u(e,"sourceId"),document_ids:t.map(String),operator:n.operator,reason:n.reason}})}export async function uploadEnterpriseKnowledgeDocument(e,t,n={}){const r=await b(t,n),o=await K(r);return E("/documents/upload-async",()=>{const t=new FormData;return t.append("source_id",u(e,"sourceId")),t.append("file",k(r,o),r.fileName),t})}export async function initEnterpriseKnowledgeDocumentUpload(e,t){return y("POST","/documents/chunked-upload/init",{body:{source_id:u(e,"sourceId"),file_name:u(t.fileName??t.file_name,"fileName"),content_type:u(t.contentType??t.content_type,"contentType"),file_size:t.fileSize??t.file_size,chunk_size:t.chunkSize??t.chunk_size,fingerprint:u(t.fingerprint,"fingerprint")}})}export async function getEnterpriseKnowledgeDocumentUpload(e){return y("GET",`/documents/chunked-upload/${encodeURIComponent(u(e,"sessionId"))}`)}export async function uploadEnterpriseKnowledgeDocumentPart(e,t,n){const r=Buffer.from(n);return E(`/documents/chunked-upload/${encodeURIComponent(u(e,"sessionId"))}/parts`,()=>{const e=new FormData;return e.append("part_number",String(t)),e.append("chunk",new Blob([r],{type:"application/octet-stream"}),`part-${t}.bin`),e})}export async function completeEnterpriseKnowledgeDocumentUpload(e){return y("POST","/documents/chunked-upload/complete",{body:{session_id:u(e,"sessionId")}})}export async function uploadEnterpriseKnowledgeDocumentChunked(e,t,r={}){const o=await b(t,r),s=r.chunkSize??r.chunk_size??8388608;if(s<5242880||s>104857600)throw new RangeError("chunkSize must be between 5 MiB and 100 MiB");if(o.size<=0)throw new RangeError("upload file must not be empty");const i=await initEnterpriseKnowledgeDocumentUpload(e,{fileName:o.fileName,contentType:o.contentType,fileSize:o.size,chunkSize:s,fingerprint:r.fingerprint||await T(o)}),d=i?.session_id;if(!d)throw new a("enterprise knowledge upload init returned no session_id");const c=new Set((i.uploaded_part_numbers||[]).map(Number)),p=Number(i.total_chunks||Math.ceil(o.size/s)),l=o.path?await n(o.path,"r"):null;try{for(let e=1;e<=p;e+=1){if(c.has(e))continue;const t=(e-1)*s,n=Math.min(s,o.size-t);let r;if(l){r=Buffer.allocUnsafe(n);const{bytesRead:o}=await l.read(r,0,n,t);if(o!==n)throw new a(`failed to read upload part ${e}`)}else r=o.data.subarray(t,t+n);await uploadEnterpriseKnowledgeDocumentPart(d,e,r)}}finally{await(l?.close())}return completeEnterpriseKnowledgeDocumentUpload(d)}export async function getEnterpriseKnowledgeUploadTask(e){return y("GET",`/tasks/${encodeURIComponent(u(e,"taskId"))}`)}export async function listEnterpriseKnowledgeUploadTasks(e,t={}){return y("GET","/tasks",{params:{source_id:u(e,"sourceId"),page:t.page,page_size:t.pageSize??t.page_size,status:t.status,q:t.query??t.q}})}export async function getEnterpriseObjectStorageContract(){return y("GET","/object-storage/contract")}export async function queryEnterpriseKnowledgeObjects(e,t={}){return y("POST",`/object-storage/${encodeURIComponent(u(e,"sourceId"))}/objects/query`,{body:{prefix:t.prefix,q:t.query??t.q,page:t.page,page_size:t.pageSize??t.page_size}})}export async function uploadEnterpriseKnowledgeObjects(e,t,n={}){if(!Array.isArray(t)||0===t.length)throw new TypeError("inputs is required");const r=await Promise.all(t.map(e=>b(e))),o=await Promise.all(r.map(K)),s=n.objectKeys??n.object_keys??[];if(s.length>0&&s.length!==r.length)throw new TypeError("objectKeys must have the same item count as inputs");const a=n.metadataJson??n.metadata_json??n.metadata;return E(`/object-storage/${encodeURIComponent(u(e,"sourceId"))}/objects/upload-async`,()=>{const e=new FormData;return r.forEach((t,n)=>{e.append("files",k(t,o[n]),t.fileName)}),s.forEach(t=>e.append("objectKeys",String(t))),void 0!==n.prefix&&e.append("prefix",String(n.prefix)),void 0!==a&&e.append("metadataJson","string"==typeof a?a:JSON.stringify(a)),e})}export async function getEnterpriseKnowledgeObject(e,t){return y("POST",`/object-storage/${encodeURIComponent(u(e,"sourceId"))}/objects/detail`,{body:{objectKey:u(t,"objectKey")}})}export async function getEnterpriseKnowledgeObjectDownloadUrl(e,t,n={}){return h(`/object-storage/${encodeURIComponent(u(e,"sourceId"))}/objects/download`,{object_key:u(t,"objectKey"),inline:n.inline??!1})}export async function deleteEnterpriseKnowledgeObject(e,t){return y("POST",`/object-storage/${encodeURIComponent(u(e,"sourceId"))}/objects/delete`,{body:{objectKey:u(t,"objectKey")}})}export async function getEnterpriseKnowledgeObjectUploadTask(e){return y("GET",`/object-storage/tasks/${encodeURIComponent(u(e,"taskId"))}`)}export const enterpriseKnowledge={tree:enterpriseKnowledgeTree,searchKnowledgeBases:searchEnterpriseKnowledgeBases,validateReferences:validateEnterpriseKnowledgeReferences,retrieve:retrieveEnterpriseKnowledge,listFolders:listEnterpriseKnowledgeFolders,getFolder:getEnterpriseKnowledgeFolder,createFolder:createEnterpriseKnowledgeFolder,deleteFolder:deleteEnterpriseKnowledgeFolder,listFolderKnowledgeBases:listEnterpriseFolderKnowledgeBases,createKnowledgeBase:createEnterpriseKnowledgeBase,getKnowledgeBase:getEnterpriseKnowledgeBase,deleteKnowledgeBase:deleteEnterpriseKnowledgeBase,listResourceAudits:listEnterpriseKnowledgeResourceAudits,listDocuments:listEnterpriseKnowledgeDocuments,getDocument:getEnterpriseKnowledgeDocument,listDocumentChunks:listEnterpriseKnowledgeDocumentChunks,getDocumentOriginalUrl:getEnterpriseKnowledgeDocumentOriginalUrl,batchDeleteDocuments:batchDeleteEnterpriseKnowledgeDocuments,uploadDocument:uploadEnterpriseKnowledgeDocument,initDocumentUpload:initEnterpriseKnowledgeDocumentUpload,getDocumentUpload:getEnterpriseKnowledgeDocumentUpload,uploadDocumentPart:uploadEnterpriseKnowledgeDocumentPart,completeDocumentUpload:completeEnterpriseKnowledgeDocumentUpload,uploadDocumentChunked:uploadEnterpriseKnowledgeDocumentChunked,getUploadTask:getEnterpriseKnowledgeUploadTask,listUploadTasks:listEnterpriseKnowledgeUploadTasks,getObjectStorageContract:getEnterpriseObjectStorageContract,queryObjects:queryEnterpriseKnowledgeObjects,uploadObjects:uploadEnterpriseKnowledgeObjects,getObject:getEnterpriseKnowledgeObject,getObjectDownloadUrl:getEnterpriseKnowledgeObjectDownloadUrl,deleteObject:deleteEnterpriseKnowledgeObject,getObjectUploadTask:getEnterpriseKnowledgeObjectUploadTask};
package/dist/index.d.ts CHANGED
@@ -20,16 +20,20 @@ export interface RuntimeConfig {
20
20
  ownerUserId?: string;
21
21
  ownerProjectType?: string;
22
22
  ownerApplicationType?: string;
23
- runtimeEnv?: string;
24
- currentUserId?: string;
25
- currentUserOrgId?: string;
26
- }
23
+ runtimeEnv?: string;
24
+ currentUserId?: string;
25
+ currentUserOrgId?: string;
26
+ }
27
27
 
28
- export function runtimeConfig(options?: { environmentOverrideEnv?: string }): Promise<RuntimeConfig>;
28
+ export function runtimeConfig(options?: {
29
+ environmentOverrideEnv?: string;
30
+ requireProject?: boolean;
31
+ useCurrentUser?: boolean;
32
+ }): Promise<RuntimeConfig>;
29
33
  export function authHeaders(config: RuntimeConfig, contentType?: string): Record<string, string>;
30
34
 
31
- export * from './uns.js';
32
- export * from './industrial.js';
35
+ export * from './uns.js';
36
+ export * from './industrial.js';
33
37
 
34
38
  export type OAuthLoginAudience = 'ALL' | 'OWNER_TENANT';
35
39
 
@@ -382,7 +386,7 @@ export function listDocuments(datasetId: string, options?: { page?: number; size
382
386
  export function deleteDocuments(datasetId: string, documentIds: string[]): Promise<void>;
383
387
  export function search(query: string, options?: SearchKnowledgeOptions): Promise<KnowledgeSearchResult>;
384
388
 
385
- export const knowledge: {
389
+ export const knowledge: {
386
390
  DataSourceType: typeof DataSourceType;
387
391
  ChunkConfig: typeof ChunkConfig;
388
392
  KnowledgeDocument: typeof KnowledgeDocument;
@@ -399,10 +403,312 @@ export const knowledge: {
399
403
  addUrl: typeof addUrl;
400
404
  listDocuments: typeof listDocuments;
401
405
  deleteDocuments: typeof deleteDocuments;
402
- search: typeof search;
403
- };
404
-
405
- export interface DatabaseFilter {
406
+ search: typeof search;
407
+ };
408
+
409
+ export type EnterpriseKnowledgeType = 'STANDARD' | 'GRAPH' | 'OBJECT_STORAGE';
410
+ export type EnterpriseKnowledgeCapability = 'retrieve' | 'upload' | 'list_files' | 'batch_delete_files';
411
+ export type EnterpriseKnowledgeFileInput = string | Blob | Buffer | Uint8Array;
412
+
413
+ export interface EnterpriseKnowledgePageOptions {
414
+ page?: number;
415
+ pageSize?: number;
416
+ page_size?: number;
417
+ }
418
+
419
+ export interface EnterpriseKnowledgeFilterOptions extends EnterpriseKnowledgePageOptions {
420
+ query?: string;
421
+ q?: string;
422
+ }
423
+
424
+ export interface EnterpriseKnowledgeTypesOptions {
425
+ includeTypes?: EnterpriseKnowledgeType[] | string;
426
+ include_types?: EnterpriseKnowledgeType[] | string;
427
+ }
428
+
429
+ export interface EnterpriseKnowledgeDeleteOptions {
430
+ reason?: string;
431
+ hardDelete?: boolean;
432
+ hard_delete?: boolean;
433
+ confirmName?: string;
434
+ confirm_name?: string;
435
+ }
436
+
437
+ export interface EnterpriseKnowledgeUploadOptions {
438
+ fileName?: string;
439
+ file_name?: string;
440
+ contentType?: string;
441
+ content_type?: string;
442
+ }
443
+
444
+ export interface EnterpriseKnowledgeChunkedUploadOptions extends EnterpriseKnowledgeUploadOptions {
445
+ chunkSize?: number;
446
+ chunk_size?: number;
447
+ fingerprint?: string;
448
+ }
449
+
450
+ export interface EnterpriseKnowledgeTreeNode {
451
+ id?: string;
452
+ parent_id?: string;
453
+ node_type?: string;
454
+ name?: string;
455
+ protected?: boolean;
456
+ deletable?: boolean;
457
+ knowledge_base_id?: string;
458
+ knowledge_type?: EnterpriseKnowledgeType | string;
459
+ capabilities?: {
460
+ retrieve?: boolean;
461
+ upload?: boolean;
462
+ list_files?: boolean;
463
+ batch_delete_files?: boolean;
464
+ };
465
+ children?: EnterpriseKnowledgeTreeNode[];
466
+ [key: string]: unknown;
467
+ }
468
+
469
+ export interface EnterpriseKnowledgeTreeResponse {
470
+ status?: string;
471
+ data?: {
472
+ tenant_id?: string;
473
+ permission_scope?: string;
474
+ nodes?: EnterpriseKnowledgeTreeNode[];
475
+ };
476
+ [key: string]: unknown;
477
+ }
478
+
479
+ export interface EnterpriseKnowledgeReferenceValidation {
480
+ valid?: boolean;
481
+ required_capability?: EnterpriseKnowledgeCapability | string;
482
+ items?: Array<{
483
+ knowledge_base_id?: string;
484
+ name?: string;
485
+ knowledge_type?: EnterpriseKnowledgeType | string;
486
+ valid?: boolean;
487
+ code?: string;
488
+ message?: string;
489
+ [key: string]: unknown;
490
+ }>;
491
+ [key: string]: unknown;
492
+ }
493
+
494
+ export interface EnterpriseKnowledgeUploadSession {
495
+ session_id?: string;
496
+ source_id?: string;
497
+ file_name?: string;
498
+ content_type?: string;
499
+ file_size?: number;
500
+ chunk_size?: number;
501
+ total_chunks?: number;
502
+ uploaded_chunks?: number;
503
+ uploaded_part_numbers?: number[];
504
+ fingerprint?: string;
505
+ status?: string;
506
+ expires_at?: string;
507
+ [key: string]: unknown;
508
+ }
509
+
510
+ export function enterpriseKnowledgeTree(
511
+ options?: EnterpriseKnowledgeTypesOptions,
512
+ ): Promise<EnterpriseKnowledgeTreeResponse>;
513
+ export function searchEnterpriseKnowledgeBases(
514
+ query: string,
515
+ options?: EnterpriseKnowledgeTypesOptions & EnterpriseKnowledgePageOptions,
516
+ ): Promise<Record<string, unknown>>;
517
+ export function validateEnterpriseKnowledgeReferences(
518
+ knowledgeBaseIds: string[],
519
+ options?: {
520
+ requiredCapability?: EnterpriseKnowledgeCapability;
521
+ required_capability?: EnterpriseKnowledgeCapability;
522
+ },
523
+ ): Promise<EnterpriseKnowledgeReferenceValidation>;
524
+ export function retrieveEnterpriseKnowledge(
525
+ query: string,
526
+ sourceIds: string[],
527
+ ): Promise<Record<string, unknown>>;
528
+ export function listEnterpriseKnowledgeFolders(
529
+ options?: EnterpriseKnowledgeFilterOptions & {
530
+ parentId?: string;
531
+ parent_id?: string;
532
+ includeChildren?: boolean;
533
+ include_children?: boolean;
534
+ },
535
+ ): Promise<Record<string, unknown>>;
536
+ export function getEnterpriseKnowledgeFolder(folderId: string): Promise<Record<string, unknown>>;
537
+ export function createEnterpriseKnowledgeFolder(
538
+ name: string,
539
+ options?: { parentId?: string; parent_id?: string; description?: string },
540
+ ): Promise<Record<string, unknown>>;
541
+ export function deleteEnterpriseKnowledgeFolder(
542
+ folderId: string,
543
+ options?: EnterpriseKnowledgeDeleteOptions,
544
+ ): Promise<Record<string, unknown>>;
545
+ export function listEnterpriseFolderKnowledgeBases(
546
+ folderId: string,
547
+ options?: EnterpriseKnowledgeFilterOptions &
548
+ EnterpriseKnowledgeTypesOptions & {
549
+ includeChildren?: boolean;
550
+ include_children?: boolean;
551
+ },
552
+ ): Promise<Record<string, unknown>>;
553
+ export function createEnterpriseKnowledgeBase(
554
+ name: string,
555
+ options?: {
556
+ folderId?: string;
557
+ folder_id?: string;
558
+ description?: string;
559
+ knowledgeType?: EnterpriseKnowledgeType;
560
+ knowledge_type?: EnterpriseKnowledgeType;
561
+ },
562
+ ): Promise<Record<string, unknown>>;
563
+ export function getEnterpriseKnowledgeBase(sourceId: string): Promise<Record<string, unknown>>;
564
+ export function deleteEnterpriseKnowledgeBase(
565
+ sourceId: string,
566
+ options?: EnterpriseKnowledgeDeleteOptions,
567
+ ): Promise<Record<string, unknown>>;
568
+ export function listEnterpriseKnowledgeResourceAudits(
569
+ options?: EnterpriseKnowledgeFilterOptions & {
570
+ operation?: string;
571
+ resourceKind?: 'FOLDER' | 'KNOWLEDGE_BASE' | 'OBJECT_STORAGE' | string;
572
+ resource_kind?: 'FOLDER' | 'KNOWLEDGE_BASE' | 'OBJECT_STORAGE' | string;
573
+ resourceId?: string;
574
+ resource_id?: string;
575
+ knowledgeType?: EnterpriseKnowledgeType;
576
+ knowledge_type?: EnterpriseKnowledgeType;
577
+ },
578
+ ): Promise<Record<string, unknown>>;
579
+ export function listEnterpriseKnowledgeDocuments(
580
+ sourceId: string,
581
+ options?: EnterpriseKnowledgeFilterOptions & {
582
+ status?: string;
583
+ documentId?: string;
584
+ document_id?: string;
585
+ },
586
+ ): Promise<Record<string, unknown>>;
587
+ export function getEnterpriseKnowledgeDocument(documentId: string): Promise<Record<string, unknown>>;
588
+ export function listEnterpriseKnowledgeDocumentChunks(
589
+ documentId: string,
590
+ options?: EnterpriseKnowledgeFilterOptions,
591
+ ): Promise<Record<string, unknown>>;
592
+ export function getEnterpriseKnowledgeDocumentOriginalUrl(
593
+ documentId: string,
594
+ options?: { download?: boolean },
595
+ ): Promise<string>;
596
+ export function batchDeleteEnterpriseKnowledgeDocuments(
597
+ sourceId: string,
598
+ documentIds: string[],
599
+ options?: { operator?: string; reason?: string },
600
+ ): Promise<Record<string, unknown>>;
601
+ export function uploadEnterpriseKnowledgeDocument(
602
+ sourceId: string,
603
+ input: EnterpriseKnowledgeFileInput,
604
+ options?: EnterpriseKnowledgeUploadOptions,
605
+ ): Promise<Record<string, unknown>>;
606
+ export function initEnterpriseKnowledgeDocumentUpload(
607
+ sourceId: string,
608
+ options: {
609
+ fileName?: string;
610
+ file_name?: string;
611
+ contentType?: string;
612
+ content_type?: string;
613
+ fileSize?: number;
614
+ file_size?: number;
615
+ chunkSize?: number;
616
+ chunk_size?: number;
617
+ fingerprint: string;
618
+ },
619
+ ): Promise<EnterpriseKnowledgeUploadSession>;
620
+ export function getEnterpriseKnowledgeDocumentUpload(
621
+ sessionId: string,
622
+ ): Promise<EnterpriseKnowledgeUploadSession>;
623
+ export function uploadEnterpriseKnowledgeDocumentPart(
624
+ sessionId: string,
625
+ partNumber: number,
626
+ chunk: Buffer | Uint8Array,
627
+ ): Promise<Record<string, unknown>>;
628
+ export function completeEnterpriseKnowledgeDocumentUpload(
629
+ sessionId: string,
630
+ ): Promise<Record<string, unknown>>;
631
+ export function uploadEnterpriseKnowledgeDocumentChunked(
632
+ sourceId: string,
633
+ input: EnterpriseKnowledgeFileInput,
634
+ options?: EnterpriseKnowledgeChunkedUploadOptions,
635
+ ): Promise<Record<string, unknown>>;
636
+ export function getEnterpriseKnowledgeUploadTask(taskId: string): Promise<Record<string, unknown>>;
637
+ export function listEnterpriseKnowledgeUploadTasks(
638
+ sourceId: string,
639
+ options?: EnterpriseKnowledgeFilterOptions & { status?: string },
640
+ ): Promise<Record<string, unknown>>;
641
+ export function getEnterpriseObjectStorageContract(): Promise<Record<string, unknown>>;
642
+ export function queryEnterpriseKnowledgeObjects(
643
+ sourceId: string,
644
+ options?: EnterpriseKnowledgeFilterOptions & { prefix?: string },
645
+ ): Promise<Record<string, unknown>>;
646
+ export function uploadEnterpriseKnowledgeObjects(
647
+ sourceId: string,
648
+ inputs: EnterpriseKnowledgeFileInput[],
649
+ options?: {
650
+ objectKeys?: string[];
651
+ object_keys?: string[];
652
+ prefix?: string;
653
+ metadata?: Record<string, unknown> | string;
654
+ metadataJson?: Record<string, unknown> | string;
655
+ metadata_json?: Record<string, unknown> | string;
656
+ },
657
+ ): Promise<Record<string, unknown>>;
658
+ export function getEnterpriseKnowledgeObject(
659
+ sourceId: string,
660
+ objectKey: string,
661
+ ): Promise<Record<string, unknown>>;
662
+ export function getEnterpriseKnowledgeObjectDownloadUrl(
663
+ sourceId: string,
664
+ objectKey: string,
665
+ options?: { inline?: boolean },
666
+ ): Promise<string>;
667
+ export function deleteEnterpriseKnowledgeObject(
668
+ sourceId: string,
669
+ objectKey: string,
670
+ ): Promise<Record<string, unknown>>;
671
+ export function getEnterpriseKnowledgeObjectUploadTask(
672
+ taskId: string,
673
+ ): Promise<Record<string, unknown>>;
674
+
675
+ export const enterpriseKnowledge: {
676
+ tree: typeof enterpriseKnowledgeTree;
677
+ searchKnowledgeBases: typeof searchEnterpriseKnowledgeBases;
678
+ validateReferences: typeof validateEnterpriseKnowledgeReferences;
679
+ retrieve: typeof retrieveEnterpriseKnowledge;
680
+ listFolders: typeof listEnterpriseKnowledgeFolders;
681
+ getFolder: typeof getEnterpriseKnowledgeFolder;
682
+ createFolder: typeof createEnterpriseKnowledgeFolder;
683
+ deleteFolder: typeof deleteEnterpriseKnowledgeFolder;
684
+ listFolderKnowledgeBases: typeof listEnterpriseFolderKnowledgeBases;
685
+ createKnowledgeBase: typeof createEnterpriseKnowledgeBase;
686
+ getKnowledgeBase: typeof getEnterpriseKnowledgeBase;
687
+ deleteKnowledgeBase: typeof deleteEnterpriseKnowledgeBase;
688
+ listResourceAudits: typeof listEnterpriseKnowledgeResourceAudits;
689
+ listDocuments: typeof listEnterpriseKnowledgeDocuments;
690
+ getDocument: typeof getEnterpriseKnowledgeDocument;
691
+ listDocumentChunks: typeof listEnterpriseKnowledgeDocumentChunks;
692
+ getDocumentOriginalUrl: typeof getEnterpriseKnowledgeDocumentOriginalUrl;
693
+ batchDeleteDocuments: typeof batchDeleteEnterpriseKnowledgeDocuments;
694
+ uploadDocument: typeof uploadEnterpriseKnowledgeDocument;
695
+ initDocumentUpload: typeof initEnterpriseKnowledgeDocumentUpload;
696
+ getDocumentUpload: typeof getEnterpriseKnowledgeDocumentUpload;
697
+ uploadDocumentPart: typeof uploadEnterpriseKnowledgeDocumentPart;
698
+ completeDocumentUpload: typeof completeEnterpriseKnowledgeDocumentUpload;
699
+ uploadDocumentChunked: typeof uploadEnterpriseKnowledgeDocumentChunked;
700
+ getUploadTask: typeof getEnterpriseKnowledgeUploadTask;
701
+ listUploadTasks: typeof listEnterpriseKnowledgeUploadTasks;
702
+ getObjectStorageContract: typeof getEnterpriseObjectStorageContract;
703
+ queryObjects: typeof queryEnterpriseKnowledgeObjects;
704
+ uploadObjects: typeof uploadEnterpriseKnowledgeObjects;
705
+ getObject: typeof getEnterpriseKnowledgeObject;
706
+ getObjectDownloadUrl: typeof getEnterpriseKnowledgeObjectDownloadUrl;
707
+ deleteObject: typeof deleteEnterpriseKnowledgeObject;
708
+ getObjectUploadTask: typeof getEnterpriseKnowledgeObjectUploadTask;
709
+ };
710
+
711
+ export interface DatabaseFilter {
406
712
  field: string;
407
713
  op: 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'not_in' | 'is_null' | 'is_not_null' | 'like' | 'ilike' | string;
408
714
  value?: unknown;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{PlatformSdkError,ConfigurationError,ApiError}from"./shared.js";export{runtimeConfig,authHeaders}from"./runtime.js";export*from"./database.js";export*from"./knowledge.js";export*from"./industrial.js";export*from"./oauth.js";export*from"./oauth-runtime.js";export*from"./storage.js";export*from"./uns.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"./enterprise-knowledge.js";export*from"./knowledge.js";export*from"./industrial.js";export*from"./oauth.js";export*from"./oauth-runtime.js";export*from"./storage.js";export*from"./uns.js";export{studioDatabase}from"./studio-database.js";