@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.
@@ -1,120 +1,169 @@
1
- export type IndustrialResourceType =
2
- | 'edgeAgent'
3
- | 'connection'
4
- | 'collectionTask'
5
- | 'collectionPoint'
6
- | 'videoEdge'
7
- | 'videoGateway'
8
- | 'videoDevice'
9
- | 'videoChannel';
1
+ import type { UnsPageOptions } from './uns.js';
10
2
 
11
- export type IndustrialSubscriptionTransport = 'auto' | 'websocket' | 'mqtt';
12
- export type IndustrialControlTransport = 'auto' | 'http' | 'mqtt';
3
+ export type IndustrialPayload = Record<string, unknown>;
4
+ export type IndustrialQuery = Record<string, string | number | boolean | undefined | null>;
5
+ export type IndustrialTaskAction = 'start' | 'stop' | 'restart' | 'run-once';
6
+ export type IndustrialVideoDeviceAction =
7
+ | 'test-connection'
8
+ | 'toggle-enabled'
9
+ | 'sync-channels';
10
+ export type IndustrialVideoPtzAction =
11
+ | 'move'
12
+ | 'stop'
13
+ | 'preset/set'
14
+ | 'preset/goto';
13
15
 
14
- export function getIndustrialProtocolSchema(protocol: string): Promise<Record<string, unknown>>;
15
- export function searchIndustrialResources(
16
- resourceType: IndustrialResourceType | string,
17
- options?: {
18
- protocol?: string;
19
- keyword?: string;
20
- scope?: 'project' | 'enterprise';
21
- selector?: Record<string, unknown>;
22
- page?: number;
23
- pageSize?: number;
24
- page_size?: number;
25
- },
26
- ): Promise<Record<string, unknown>>;
27
- export function getIndustrialResource(
28
- resourceType: IndustrialResourceType | string,
29
- resourceId: string,
30
- ): Promise<Record<string, unknown>>;
31
- export function validateIndustrialChanges(document: Record<string, unknown>): Promise<Record<string, unknown>>;
32
- export function planIndustrialChanges(document: Record<string, unknown>): Promise<Record<string, unknown>>;
33
- export function applyIndustrialChanges(
34
- document: Record<string, unknown>,
35
- options: {
36
- expectedDocumentHash?: string;
37
- expected_document_hash?: string;
38
- expectedPlanHash?: string;
39
- expected_plan_hash?: string;
40
- confirmed: boolean;
41
- impactConfirmed?: boolean;
42
- impact_confirmed?: boolean;
43
- },
44
- ): Promise<Record<string, unknown>>;
45
- export function getIndustrialRuntimeCapabilities(): Promise<Record<string, unknown>>;
46
- export function getIndustrialRealtimeConnection(options: {
47
- pointIds?: string[];
48
- point_ids?: string[];
49
- tagCodes?: string[];
50
- tag_codes?: string[];
51
- transport?: IndustrialSubscriptionTransport;
52
- }): Promise<{
53
- url: string;
54
- authentication: string;
55
- subscribe: {
56
- type: 'subscribe';
57
- transport: IndustrialSubscriptionTransport;
58
- pointIds: string[];
59
- tagCodes: string[];
60
- };
61
- }>;
62
- export function getIndustrialPointCurrent(pointId: string): Promise<Record<string, unknown>>;
63
- export function getIndustrialPointHistory(
16
+ export const IOT_POINT_COLLECTOR: 'IOT_POINT_COLLECTOR';
17
+ export const IOT_VIDEO_DEVICE_COLLECTOR: 'IOT_VIDEO_DEVICE_COLLECTOR';
18
+
19
+ export function listIndustrialCollectors(sourceType: string, options?: UnsPageOptions): Promise<unknown>;
20
+ export function listIndustrialPoints(
21
+ sourceType: string,
22
+ taskId: string,
23
+ options?: UnsPageOptions,
24
+ ): Promise<unknown>;
25
+ export function getIndustrialLatest(
26
+ taskId: string,
64
27
  pointId: string,
65
- options: {
66
- startTime?: string;
67
- start_time?: string;
68
- endTime?: string;
69
- end_time?: string;
70
- page?: number;
71
- pageSize?: number;
72
- page_size?: number;
28
+ options?: {
29
+ tagCode?: string;
30
+ tag_code?: string;
31
+ nodeId?: string;
32
+ node_id?: string;
73
33
  },
74
- ): Promise<Record<string, unknown>>;
75
- export function writeIndustrialPoint(
34
+ ): Promise<unknown>;
35
+ export function getIndustrialVideoStreamOptions(channelId: string): Promise<unknown>;
36
+ export function listIndustrialConnections(query?: IndustrialQuery): Promise<unknown>;
37
+ export function getIndustrialConnection(connectionId: string): Promise<unknown>;
38
+ export function updateIndustrialConnection(
39
+ connectionId: string,
40
+ payload: IndustrialPayload,
41
+ ): Promise<unknown>;
42
+ export function testIndustrialConnection(connectionId: string): Promise<unknown>;
43
+ export function deleteIndustrialConnection(connectionId: string): Promise<unknown>;
44
+ export function listIndustrialTasks(query?: IndustrialQuery): Promise<unknown>;
45
+ export function getIndustrialTask(taskId: string): Promise<unknown>;
46
+ export function getIndustrialTaskStatus(taskId: string): Promise<unknown>;
47
+ export function updateIndustrialTask(
48
+ taskId: string,
49
+ payload: IndustrialPayload,
50
+ ): Promise<unknown>;
51
+ export function deleteIndustrialTask(taskId: string): Promise<unknown>;
52
+ export function runIndustrialTaskAction(
53
+ taskId: string,
54
+ action: IndustrialTaskAction,
55
+ ): Promise<unknown>;
56
+ export function listIndustrialTaskPoints(
57
+ taskId: string,
58
+ query?: IndustrialQuery,
59
+ ): Promise<unknown>;
60
+ export function getIndustrialPoint(taskId: string, pointId: string): Promise<unknown>;
61
+ export function updateIndustrialPoint(
62
+ taskId: string,
76
63
  pointId: string,
77
- value: unknown,
78
- options: {
79
- reason: string;
80
- ticket: string;
81
- transport?: IndustrialControlTransport;
82
- requestId?: string;
83
- request_id?: string;
84
- dryRun?: boolean;
85
- dry_run?: boolean;
86
- confirmed?: boolean;
87
- },
88
- ): Promise<Record<string, unknown>>;
89
- export function getIndustrialVideoStreamOptions(channelId: string): Promise<Record<string, unknown>>;
90
- export function startIndustrialVideoPreview(
64
+ payload: IndustrialPayload,
65
+ ): Promise<unknown>;
66
+ export function deleteIndustrialPoint(taskId: string, pointId: string): Promise<unknown>;
67
+ export function validateIndustrialPoints(
68
+ taskId: string,
69
+ payload: IndustrialPayload,
70
+ ): Promise<unknown>;
71
+ export function testReadIndustrialPoints(
72
+ taskId: string,
73
+ payload: IndustrialPayload,
74
+ ): Promise<unknown>;
75
+ export function writeIndustrialPoints(
76
+ taskId: string,
77
+ payload: IndustrialPayload,
78
+ ): Promise<unknown>;
79
+ export function getIndustrialLatestValues(options?: {
80
+ taskId?: string;
81
+ pointId?: string;
82
+ tagCode?: string;
83
+ }): Promise<unknown>;
84
+ export function getIndustrialHistoryValues(options?: {
85
+ taskId?: string;
86
+ pointId?: string;
87
+ tagCode?: string;
88
+ startTime?: string;
89
+ endTime?: string;
90
+ page?: number;
91
+ pageSize?: number;
92
+ }): Promise<unknown>;
93
+ export function directReadIndustrialValue(payload: {
94
+ taskId: string;
95
+ pointId: string;
96
+ agentId?: string;
97
+ tagCode?: string;
98
+ }): Promise<unknown>;
99
+ export function listIndustrialVideoDevices(query?: IndustrialQuery): Promise<unknown>;
100
+ export function getIndustrialVideoDevice(deviceId: string): Promise<unknown>;
101
+ export function updateIndustrialVideoDevice(
102
+ deviceId: string,
103
+ payload: IndustrialPayload,
104
+ ): Promise<unknown>;
105
+ export function deleteIndustrialVideoDevice(deviceId: string): Promise<unknown>;
106
+ export function runIndustrialVideoDeviceAction(
107
+ deviceId: string,
108
+ action: IndustrialVideoDeviceAction,
109
+ payload?: IndustrialPayload,
110
+ ): Promise<unknown>;
111
+ export function listIndustrialVideoChannels(query?: IndustrialQuery): Promise<unknown>;
112
+ export function getIndustrialVideoChannel(channelId: string): Promise<unknown>;
113
+ export function updateIndustrialVideoChannel(
91
114
  channelId: string,
92
- options: {
93
- confirmed: boolean;
94
- preferredProtocol?: string;
95
- preferred_protocol?: string;
96
- preferredProtocolOrder?: string[];
97
- preferred_protocol_order?: string[];
98
- },
99
- ): Promise<Record<string, unknown>>;
100
- export function stopIndustrialVideoPreview(
115
+ payload: IndustrialPayload,
116
+ ): Promise<unknown>;
117
+ export function deleteIndustrialVideoChannel(channelId: string): Promise<unknown>;
118
+ export function getIndustrialVideoChannelCapabilities(channelId: string): Promise<unknown>;
119
+ export function snapshotIndustrialVideoChannel(
120
+ channelId: string,
121
+ payload?: IndustrialPayload,
122
+ ): Promise<unknown>;
123
+ export function runIndustrialVideoPtz(
101
124
  channelId: string,
102
- options: { confirmed: boolean },
103
- ): Promise<Record<string, unknown>>;
125
+ action: IndustrialVideoPtzAction,
126
+ payload?: IndustrialPayload,
127
+ ): Promise<unknown>;
104
128
 
105
129
  export const industrial: {
106
- protocolSchema: typeof getIndustrialProtocolSchema;
107
- searchResources: typeof searchIndustrialResources;
108
- resource: typeof getIndustrialResource;
109
- validateChanges: typeof validateIndustrialChanges;
110
- planChanges: typeof planIndustrialChanges;
111
- applyChanges: typeof applyIndustrialChanges;
112
- runtimeCapabilities: typeof getIndustrialRuntimeCapabilities;
113
- realtimeConnection: typeof getIndustrialRealtimeConnection;
114
- pointCurrent: typeof getIndustrialPointCurrent;
115
- pointHistory: typeof getIndustrialPointHistory;
116
- writePoint: typeof writeIndustrialPoint;
130
+ IOT_POINT_COLLECTOR: typeof IOT_POINT_COLLECTOR;
131
+ IOT_VIDEO_DEVICE_COLLECTOR: typeof IOT_VIDEO_DEVICE_COLLECTOR;
132
+ collectors: typeof listIndustrialCollectors;
133
+ points: typeof listIndustrialPoints;
134
+ latest: typeof getIndustrialLatest;
117
135
  videoStreamOptions: typeof getIndustrialVideoStreamOptions;
118
- startVideoPreview: typeof startIndustrialVideoPreview;
119
- stopVideoPreview: typeof stopIndustrialVideoPreview;
136
+ listConnections: typeof listIndustrialConnections;
137
+ connection: typeof getIndustrialConnection;
138
+ updateConnection: typeof updateIndustrialConnection;
139
+ testConnection: typeof testIndustrialConnection;
140
+ deleteConnection: typeof deleteIndustrialConnection;
141
+ listTasks: typeof listIndustrialTasks;
142
+ task: typeof getIndustrialTask;
143
+ taskStatus: typeof getIndustrialTaskStatus;
144
+ updateTask: typeof updateIndustrialTask;
145
+ deleteTask: typeof deleteIndustrialTask;
146
+ runTaskAction: typeof runIndustrialTaskAction;
147
+ listTaskPoints: typeof listIndustrialTaskPoints;
148
+ point: typeof getIndustrialPoint;
149
+ updatePoint: typeof updateIndustrialPoint;
150
+ deletePoint: typeof deleteIndustrialPoint;
151
+ validatePoints: typeof validateIndustrialPoints;
152
+ testReadPoints: typeof testReadIndustrialPoints;
153
+ writePoints: typeof writeIndustrialPoints;
154
+ latestValues: typeof getIndustrialLatestValues;
155
+ historyValues: typeof getIndustrialHistoryValues;
156
+ directRead: typeof directReadIndustrialValue;
157
+ listVideoDevices: typeof listIndustrialVideoDevices;
158
+ videoDevice: typeof getIndustrialVideoDevice;
159
+ updateVideoDevice: typeof updateIndustrialVideoDevice;
160
+ deleteVideoDevice: typeof deleteIndustrialVideoDevice;
161
+ runVideoDeviceAction: typeof runIndustrialVideoDeviceAction;
162
+ listVideoChannels: typeof listIndustrialVideoChannels;
163
+ videoChannel: typeof getIndustrialVideoChannel;
164
+ updateVideoChannel: typeof updateIndustrialVideoChannel;
165
+ deleteVideoChannel: typeof deleteIndustrialVideoChannel;
166
+ videoChannelCapabilities: typeof getIndustrialVideoChannelCapabilities;
167
+ snapshotVideoChannel: typeof snapshotIndustrialVideoChannel;
168
+ runVideoPtz: typeof runIndustrialVideoPtz;
120
169
  };
@@ -1 +1 @@
1
- import{ApiError as t}from"./shared.js";import{authHeaders as e,refreshRuntimeConfig as r,runtimeConfig as n,shouldRefreshUserToken as i}from"./runtime.js";function o(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>null!=t))}function a(t,e){return`/projects/${encodeURIComponent(t.projectId)}${e}`}async function s(a,s,{body:c,config:d}={}){let u=d||await n();for(let n=0;n<2;n+=1)try{const r=await fetch(new URL(`${u.baseUrl}/api/v1${s}`),{method:a,headers:e(u,void 0===c?void 0:"application/json"),body:void 0===c?void 0:JSON.stringify(o(c))}),n=await r.text();let i=null;try{i=n?JSON.parse(n):null}catch{throw new t(n||`platform industrial API returned ${r.status}`,{status:r.status,details:n})}if(!r.ok||i&&void 0!==i.code&&0!==i.code||!1===i?.success)throw new t(i?.message||n||"platform industrial API failed",{status:r.status,code:"number"==typeof i?.code?i.code:void 0,details:i});return i&&"object"==typeof i?i.data:i}catch(t){if(0===n&&i(t)){u=await r(u);continue}throw t}throw new t("platform industrial API failed")}export async function getIndustrialProtocolSchema(t){const e=await n();return s("GET",a(e,`/industrial/protocols/${encodeURIComponent(t)}/schema`),{config:e})}export async function searchIndustrialResources(t,e={}){const r=await n();return s("POST",a(r,"/industrial/resources/search"),{body:{resourceType:t,protocol:e.protocol,keyword:e.keyword,scope:e.scope||"project",selector:e.selector||{},page:e.page??1,pageSize:e.pageSize??e.page_size??20},config:r})}export async function getIndustrialResource(t,e){const r=await n();return s("GET",a(r,`/industrial/resources/${encodeURIComponent(t)}/${encodeURIComponent(e)}`),{config:r})}async function c(t,e){const r=await n();return s("POST",a(r,`/industrial/changes/${t}`),{body:{document:e},config:r})}export function validateIndustrialChanges(t){return c("validate",t)}export function planIndustrialChanges(t){return c("plan",t)}export async function applyIndustrialChanges(t,e={}){const r=String(e.expectedDocumentHash??e.expected_document_hash??"").trim(),i=String(e.expectedPlanHash??e.expected_plan_hash??"").trim();if(!0!==e.confirmed)throw new TypeError("industrial changes apply requires explicit confirmation");if(!r||!i)throw new TypeError("industrial changes apply requires document and plan hashes");const o=await n();return s("POST",a(o,"/industrial/changes/apply"),{body:{document:t,expectedDocumentHash:r,expectedPlanHash:i,confirmed:!0,impactConfirmed:!0===e.impactConfirmed||!0===e.impact_confirmed},config:o})}export async function getIndustrialRuntimeCapabilities(){const t=await n();return s("GET",a(t,"/industrial/runtime/capabilities"),{config:t})}export async function getIndustrialRealtimeConnection(t={}){const e=(t.pointIds||t.point_ids||[]).map(String).map(t=>t.trim()).filter(Boolean),r=(t.tagCodes||t.tag_codes||[]).map(String).map(t=>t.trim()).filter(Boolean);if(0===e.length&&0===r.length)throw new TypeError("pointIds or tagCodes must be provided");const i=await n(),o=new URL(i.baseUrl);return o.protocol="https:"===o.protocol?"wss:":"ws:",o.pathname=`/api/v1${a(i,"/industrial/runtime/points/realtime")}`,o.search="",o.hash="",{url:o.toString(),authentication:"use platform session or Authorization header",subscribe:{type:"subscribe",transport:t.transport||"auto",pointIds:e,tagCodes:r}}}function d(t,e,r){return a(t,`/industrial/runtime/points/${encodeURIComponent(e)}/${r}`)}export async function getIndustrialPointCurrent(t){const e=await n();return s("GET",d(e,t,"current"),{config:e})}export async function getIndustrialPointHistory(t,e={}){const r=await n();return s("POST",d(r,t,"history"),{body:{startTime:e.startTime??e.start_time,endTime:e.endTime??e.end_time,page:e.page??1,pageSize:e.pageSize??e.page_size??100},config:r})}export async function writeIndustrialPoint(t,e,r={}){const i=String(r.reason||"").trim(),o=String(r.ticket||"").trim(),a=!0===r.dryRun||!0===r.dry_run;if(!a&&!0!==r.confirmed)throw new TypeError("industrial point write requires explicit confirmation");if(!i||!o)throw new TypeError("industrial point write requires reason and ticket");const c=await n();return s("POST",d(c,t,"write"),{body:{value:e,transport:r.transport||"auto",reason:i,ticket:o,requestId:r.requestId??r.request_id,dryRun:a,confirmed:!0===r.confirmed},config:c})}async function u(t,e,r,i){const o=await n();return s(t,a(o,`/industrial/runtime/video/channels/${encodeURIComponent(e)}/${r}`),{body:i,config:o})}export function getIndustrialVideoStreamOptions(t){return u("GET",t,"stream-options")}export function startIndustrialVideoPreview(t,e={}){if(!0!==e.confirmed)throw new TypeError("industrial video preview start requires explicit confirmation");return u("POST",t,"preview/start",{preferredProtocol:e.preferredProtocol??e.preferred_protocol??"http-flv",preferredProtocolOrder:e.preferredProtocolOrder??e.preferred_protocol_order??["http-flv","webrtc","hls"],confirmed:!0})}export function stopIndustrialVideoPreview(t,e={}){if(!0!==e.confirmed)throw new TypeError("industrial video preview stop requires explicit confirmation");return u("POST",t,"preview/stop",{confirmed:!0})}export const industrial={protocolSchema:getIndustrialProtocolSchema,searchResources:searchIndustrialResources,resource:getIndustrialResource,validateChanges:validateIndustrialChanges,planChanges:planIndustrialChanges,applyChanges:applyIndustrialChanges,runtimeCapabilities:getIndustrialRuntimeCapabilities,realtimeConnection:getIndustrialRealtimeConnection,pointCurrent:getIndustrialPointCurrent,pointHistory:getIndustrialPointHistory,writePoint:writeIndustrialPoint,videoStreamOptions:getIndustrialVideoStreamOptions,startVideoPreview:startIndustrialVideoPreview,stopVideoPreview:stopIndustrialVideoPreview};
1
+ import{getUnsIotLatest as t,getUnsIotVideoStreamOptions as e,listUnsIotCollectors as n,listUnsIotPoints as i}from"./uns.js";import{authHeaders as o,refreshRuntimeConfig as s,runtimeConfig as r,shouldRefreshUserToken as a}from"./runtime.js";import{ApiError as d}from"./shared.js";export const IOT_POINT_COLLECTOR="IOT_POINT_COLLECTOR";export const IOT_VIDEO_DEVICE_COLLECTOR="IOT_VIDEO_DEVICE_COLLECTOR";const u=new Set(["start","stop","restart","run-once"]),l=new Set(["test-connection","toggle-enabled","sync-channels"]),c=new Set(["move","stop","preset/set","preset/goto"]);function I(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>null!=t))}function p(t){return encodeURIComponent(String(t))}async function T(t,e,{body:n,query:i}={}){let u=await r({requireProject:!1});for(let r=0;r<2;r+=1)try{const s=new URL(`${u.baseUrl}/api/v1/industrial${e}`);for(const[t,e]of Object.entries(I(i||{})))s.searchParams.set(t,String(e));const r=await fetch(s,{method:t,headers:o(u,void 0===n?null:"application/json"),body:void 0===n?void 0:JSON.stringify(n)}),a=await r.text();let l=null;try{l=a?JSON.parse(a):null}catch{throw new d(a||`platform industrial API returned ${r.status}`,{status:r.status,details:a})}if(!r.ok||void 0!==l?.code&&0!==l.code||!1===l?.success)throw new d(l?.message||a||"platform industrial API failed",{status:r.status,code:"number"==typeof l?.code?l.code:void 0,details:l});return l&&"object"==typeof l?l.data:l}catch(t){if(0===r&&a(t)){u=await s(u);continue}throw t}throw new d("platform industrial API failed")}function f(t,e,n){if(!e.has(t))throw new TypeError(`unsupported ${n} ${JSON.stringify(t)}; expected one of: ${[...e].sort().join(", ")}`)}export function listIndustrialCollectors(t,e={}){return n(t,e)}export function listIndustrialPoints(t,e,n={}){return i(t,e,n)}export function getIndustrialLatest(e,n,i={}){return t(e,n,i)}export function getIndustrialVideoStreamOptions(t){return e(t)}export function listIndustrialConnections(t={}){return T("GET","/connections",{query:t})}export function getIndustrialConnection(t){return T("GET",`/connections/${p(t)}`)}export function updateIndustrialConnection(t,e){return T("PUT",`/connections/${p(t)}`,{body:e})}export function testIndustrialConnection(t){return T("POST",`/connections/${p(t)}/test`,{body:{}})}export function deleteIndustrialConnection(t){return T("DELETE",`/connections/${p(t)}`)}export function listIndustrialTasks(t={}){return T("GET","/collection/tasks",{query:t})}export function getIndustrialTask(t){return T("GET",`/collection/tasks/${p(t)}`)}export function getIndustrialTaskStatus(t){return T("GET",`/collection/tasks/${p(t)}/status`)}export function updateIndustrialTask(t,e){return T("PUT",`/collection/tasks/${p(t)}`,{body:e})}export function deleteIndustrialTask(t){return T("DELETE",`/collection/tasks/${p(t)}`)}export function runIndustrialTaskAction(t,e){return f(e,u,"task action"),T("POST",`/collection/tasks/${p(t)}/${e}`,{body:{}})}export function listIndustrialTaskPoints(t,e={}){return T("GET",`/collection/tasks/${p(t)}/points`,{query:e})}export function getIndustrialPoint(t,e){return T("GET",`/collection/tasks/${p(t)}/points/${p(e)}`)}export function updateIndustrialPoint(t,e,n){return T("PUT",`/collection/tasks/${p(t)}/points/${p(e)}`,{body:n})}export function deleteIndustrialPoint(t,e){return T("DELETE",`/collection/tasks/${p(t)}/points/${p(e)}`)}export function validateIndustrialPoints(t,e){return T("POST",`/collection/tasks/${p(t)}/points/validate`,{body:e})}export function testReadIndustrialPoints(t,e){return T("POST",`/collection/tasks/${p(t)}/points/test-read`,{body:e})}export function writeIndustrialPoints(t,e){return T("POST",`/collection/tasks/${p(t)}/points/write`,{body:e})}export function getIndustrialLatestValues(t={}){return T("GET","/values/latest",{query:{taskId:t.taskId,pointId:t.pointId,tagCode:t.tagCode}})}export function getIndustrialHistoryValues(t={}){return T("GET","/values/history",{query:{taskId:t.taskId,pointId:t.pointId,tagCode:t.tagCode,startTime:t.startTime,endTime:t.endTime,page:t.page??1,pageSize:t.pageSize??100}})}export function directReadIndustrialValue(t){return T("POST","/values/direct-read",{body:t})}export function listIndustrialVideoDevices(t={}){return T("GET","/video/devices",{query:t})}export function getIndustrialVideoDevice(t){return T("GET",`/video/devices/${p(t)}`)}export function updateIndustrialVideoDevice(t,e){return T("PUT",`/video/devices/${p(t)}`,{body:e})}export function deleteIndustrialVideoDevice(t){return T("DELETE",`/video/devices/${p(t)}`)}export function runIndustrialVideoDeviceAction(t,e,n={}){return f(e,l,"video device action"),T("POST",`/video/devices/${p(t)}/${e}`,{body:n})}export function listIndustrialVideoChannels(t={}){return T("GET","/video/channels",{query:t})}export function getIndustrialVideoChannel(t){return T("GET",`/video/channels/${p(t)}`)}export function updateIndustrialVideoChannel(t,e){return T("PUT",`/video/channels/${p(t)}`,{body:e})}export function deleteIndustrialVideoChannel(t){return T("DELETE",`/video/channels/${p(t)}`)}export function getIndustrialVideoChannelCapabilities(t){return T("GET",`/video/channels/${p(t)}/capabilities`)}export function snapshotIndustrialVideoChannel(t,e={}){return T("POST",`/video/channels/${p(t)}/snapshot`,{body:e})}export function runIndustrialVideoPtz(t,e,n={}){return f(e,c,"video PTZ action"),T("POST",`/video/channels/${p(t)}/ptz/${e}`,{body:n})}export const industrial={IOT_POINT_COLLECTOR:IOT_POINT_COLLECTOR,IOT_VIDEO_DEVICE_COLLECTOR:IOT_VIDEO_DEVICE_COLLECTOR,collectors:listIndustrialCollectors,points:listIndustrialPoints,latest:getIndustrialLatest,videoStreamOptions:getIndustrialVideoStreamOptions,listConnections:listIndustrialConnections,connection:getIndustrialConnection,updateConnection:updateIndustrialConnection,testConnection:testIndustrialConnection,deleteConnection:deleteIndustrialConnection,listTasks:listIndustrialTasks,task:getIndustrialTask,taskStatus:getIndustrialTaskStatus,updateTask:updateIndustrialTask,deleteTask:deleteIndustrialTask,runTaskAction:runIndustrialTaskAction,listTaskPoints:listIndustrialTaskPoints,point:getIndustrialPoint,updatePoint:updateIndustrialPoint,deletePoint:deleteIndustrialPoint,validatePoints:validateIndustrialPoints,testReadPoints:testReadIndustrialPoints,writePoints:writeIndustrialPoints,latestValues:getIndustrialLatestValues,historyValues:getIndustrialHistoryValues,directRead:directReadIndustrialValue,listVideoDevices:listIndustrialVideoDevices,videoDevice:getIndustrialVideoDevice,updateVideoDevice:updateIndustrialVideoDevice,deleteVideoDevice:deleteIndustrialVideoDevice,runVideoDeviceAction:runIndustrialVideoDeviceAction,listVideoChannels:listIndustrialVideoChannels,videoChannel:getIndustrialVideoChannel,updateVideoChannel:updateIndustrialVideoChannel,deleteVideoChannel:deleteIndustrialVideoChannel,videoChannelCapabilities:getIndustrialVideoChannelCapabilities,snapshotVideoChannel:snapshotIndustrialVideoChannel,runVideoPtz:runIndustrialVideoPtz};
package/dist/runtime.js CHANGED
@@ -1 +1 @@
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)}
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,requireProject:n=!0,useCurrentUser:o=!1}={}){const s=env("LICOS_OWNER_PROJECT_ID"),c=env("LICOS_OWNER_WORKSPACE_ID"),i=env("LICOS_OWNER_USER_ID"),I=env("LICOS_PROJECT_ID")||s||env("AGENT_PROJECT_ID");if(n&&!I)throw new e("LICOS_PROJECT_ID or AGENT_PROJECT_ID is not configured");const a=platformBaseUrl(),_=env("LICOS_CURRENT_USER_ID"),u=env("LICOS_USER_ID")||i||env("AGENT_USER_ID"),d=o&&_?_:u,O=await t(a,d);return{baseUrl:a,projectId:I,environment:projectEnvironment(r),token:O,workspaceId:env("LICOS_WORKSPACE_ID")||c||env("AGENT_WORKSPACE_ID"),userId:d,ownerProjectId:s||I,ownerWorkspaceId:c,ownerOrgId:env("LICOS_OWNER_ORG_ID"),ownerUserId:i||d,ownerProjectType:env("LICOS_OWNER_PROJECT_TYPE"),ownerApplicationType:env("LICOS_OWNER_APPLICATION_TYPE"),runtimeEnv:env("LICOS_RUNTIME_ENV"),currentUserId:_,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)}