@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 +98 -78
- package/dist/enterprise-knowledge.js +1 -0
- package/dist/index.d.ts +318 -12
- package/dist/index.js +1 -1
- package/dist/industrial.d.ts +158 -109
- package/dist/industrial.js +1 -1
- package/dist/runtime.js +1 -1
- package/dist/uns.d.ts +162 -157
- package/dist/uns.js +1 -1
- package/package.json +4 -1
package/dist/industrial.d.ts
CHANGED
|
@@ -1,120 +1,169 @@
|
|
|
1
|
-
|
|
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
|
|
12
|
-
export type
|
|
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
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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<
|
|
75
|
-
export function
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
): Promise<
|
|
100
|
-
export function
|
|
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
|
-
|
|
103
|
-
|
|
125
|
+
action: IndustrialVideoPtzAction,
|
|
126
|
+
payload?: IndustrialPayload,
|
|
127
|
+
): Promise<unknown>;
|
|
104
128
|
|
|
105
129
|
export const industrial: {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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
|
};
|
package/dist/industrial.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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
|
|
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)}
|